?? editor.js
字號:
/******************************************************************************
team Board - modify for Team's daymoon
Copyright 2005-2006 team studio. (http://www.team5.cn)
*******************************************************************************/
var editbox = editwin = editdoc = null;
var cursor = -1;
var stack = new Array();
function expandoptions(id)
{
var a = document.getElementById(id);
if(a.style.display=='')
{
a.style.display='none';
}
else
{
a.style.display='';
}
}
function cloneObj(oClone, oParent, count) {
if(oParent.childNodes.length < count) {
var newNode = oClone.cloneNode(true);
oParent.appendChild(newNode);
return true;
}
return false;
}
function delObj(oParent, count) {
if(oParent.childNodes.length > count) {
oParent.removeChild(oParent.lastChild);
return true;
}
return false;
}
function setfileid(maxup){
str='';
if(!document.getElementById("upcount").value){
document.getElementById("upcount").value=1;
}
if(document.getElementById("upcount").value > maxup){
alert('您最多只能同時上傳 '+maxup+' 個文件!');
document.getElementById("upcount").value = maxup;
setfileid();
}
else
{
for(i=1;i<=document.getElementById("upcount").value;i++)
str+='<div id="divfileItem" style="padding-top:4px"> 上傳附件: <input type="file" name="fileitemid'+i+'" size="60" onBlur=this.className="colorblur"; onfocus=this.className="colorfocus"; class="colorblur"></div>';
document.getElementById("divfileItem").innerHTML=str;
}
}
function clonePoll(maxpoll){
if(!cloneObj(document.getElementById('divPollItem'), document.getElementById('polloptions') ,maxpoll)){
alert('投票項不能多于 ' + maxpoll + ' 個');
}
document.all("pollitemid")[document.all('pollitemid').length-1].value = "";
}
function newEditor(mode, initialtext) {
wysiwyg = parseInt(mode);
if(!(is_ie || is_moz || (is_opera && opera.version() >= 9))) {
allowswitcheditor = wysiwyg = 0;
}
var bbcodemode = $('bbcodemode');
var wysiwygmode = $('wysiwygmode');
bbcodemode.className = wysiwyg ? 'editor_switcher' : 'editor_switcher_highlight';
wysiwygmode.className = wysiwyg ? 'editor_switcher_highlight' : 'editor_switcher';
if(!allowswitcheditor) {
$(editorid + '_switcher').style.display = 'none';
}
$(editorid + '_cmd_table').disabled = wysiwyg ? false : true;
if(wysiwyg) {
if($(editorid + '_iframe')) {
editbox = $(editorid + '_iframe');
} else {
var iframe = document.createElement('iframe');
editbox = textobj.parentNode.appendChild(iframe);
editbox.id = editorid + '_iframe';
}
editwin = editbox.contentWindow;
editdoc = editwin.document;
writeEditorContents(isUndefined(initialtext) ? textobj.value : initialtext);
} else {
editbox = textobj;
editwin = textobj;
editdoc = textobj;
if(!isUndefined(initialtext)) {
writeEditorContents(initialtext);
}
addSnapshot(textobj.value);
}
setEditorEvents();
}
function writeEditorContents(text) {
if(wysiwyg) {
if(text == '' && is_moz) {
text = '<br />';
}
if(editdoc && editdoc.initialized) {
editdoc.body.innerHTML = text;
} else {
editdoc.designMode = 'on';
editdoc = editwin.document;
editdoc.open('text/html', 'replace');
editdoc.write(text);
editdoc.close();
editdoc.body.contentEditable = true;
editdoc.initialized = true;
}
} else {
textobj.value = text;
}
setEditorStyle();
}
function getEditorContents() {
return wysiwyg ? editdoc.body.innerHTML : editdoc.value;
}
function setEditorStyle() {
if(wysiwyg) {
textobj.style.display = 'none';
editbox.style.display = '';
if(is_moz || is_opera) {
for(var ss = 0; ss < document.styleSheets.length; ss++) {
if(document.styleSheets[ss].cssRules.length <= 0) {
continue;
}
for(var i = 0; i < document.styleSheets[ss].cssRules.length; i++) {
if(document.styleSheets[ss].cssRules[i].selectorText == '.wysiwyg') {
var newss = editdoc.createElement('style');
newss.type = 'text/css';
newss.innerHTML = document.styleSheets[ss].cssRules[i].cssText + ' p { margin: 0px; }';
editdoc.documentElement.childNodes[0].appendChild(newss);
editdoc.body.style.fontSize = document.styleSheets[ss].cssRules[i].style.fontSize;
editdoc.body.style.fontFamily = document.styleSheets[ss].cssRules[i].style.fontFamily;
}
}
}
editbox.style.border = '0px';
} else if(is_ie) {
if(document.styleSheets['css']) {
editdoc.createStyleSheet().cssText = document.styleSheets['css'].cssText + ' p { margin: 0px; }';
editdoc.body.className = 'wysiwyg';
}
editdoc.body.style.border = '0px';
}
editbox.style.width = textobj.style.width;
editbox.style.height = textobj.style.height;
editdoc.body.style.backgroundColor = '#FFFFFF';
} else {
var iframe = textobj.parentNode.getElementsByTagName('iframe')[0];
if(iframe) {
textobj.style.display = '';
textobj.style.width = iframe.style.width;
textobj.style.height = iframe.style.height;
iframe.style.display = 'none';
}
}
}
function setEditorEvents() {
if(wysiwyg) {
if(is_moz || is_opera) {
editdoc.addEventListener('mouseup', function(e) {setContext(); popupmenu.hide();}, true);
editdoc.addEventListener('keyup', function(e) {setContext();}, true);
editwin.addEventListener('focus', function(e) {this.hasfocus = true;}, true);
editwin.addEventListener('blur', function(e) {this.hasfocus = false;}, true);
editwin.addEventListener('keydown', function(e) {ctlent(e);}, true);
} else {
editdoc.onmouseup = function(e) {setContext(); popupmenu.hide();};
editdoc.onkeyup = function(e) {setContext();};
if(editdoc.attachEvent) {
editdoc.body.attachEvent("onkeydown", ctlent);
}
}
}
editwin.onfocus = function(e) {this.hasfocus = true;};
editwin.onblur = function(e) {this.hasfocus = false;};
}
function alipays(){
var arr = showModalDialog("images/common/alipay.htm", "", "dialogWidth:22em; dialogHeight:35em; status:0;help:0");
if (arr != null){
insertText(arr);
return false;
}
}
function forswf()
{
var arr = showModalDialog("images/common/swf.htm", "", "dialogWidth:30em; dialogHeight:10em; status:0; help:0");
if (arr != null){
var ss;
ss=arr.split("*")
path=ss[0];
row=ss[1];
col=ss[2];
var string;
string="[flash="+row+","+col+"]"+path+"[/flash]"
insertText(string);
}
else return false;;
}
function forwmv()
{
var arr = showModalDialog("images/common/wmv.htm", "", "dialogWidth:30em; dialogHeight:14em; status:0; help:0");
if (arr != null){
var ss;
ss=arr.split("*")
path=ss[0];
autostart=ss[1];
width=ss[2];
height=ss[3];
ran=rand();
var string;
string="[MP="+ width +","+ height +","+ autostart +"]"+ path +"[/MP]";
insertText(string);
}
else return false;
}
function rand() {
return parseInt((1000)*Math.random()+1);
}
function forrm()
{
var arr = showModalDialog("images/common/rm.htm", "", "dialogWidth:30em; dialogHeight:14em; status:0; help:0");
if (arr != null)
{
var ss;
ss = arr.split("*")
path = ss[0];
row = ss[1];
col = ss[2];
autostart = ss[3];
ran = rand();
var string;
string = "[RM="+ row +","+ col +","+ autostart +"]"+ path +"[/RM]";
insertText(string);
}
else return false;
}
function wrapTags(tagname, useoption, selection) {
if(tagname=='code') {
applyFormat('removeformat');
}
if(isUndefined(selection)) {
var selection = getSel();
if(selection === false) {
selection = '';
} else {
selection += '';
}
}
if(useoption === true) {
var option = showPrompt(construct_phrase(lang['enter_tag_option'], ('[' + tagname + ']')), '');
if(option = verifyPrompt(option)) {
var opentag = '[' + tagname + '=' + option + ']';
} else {
return false;
}
} else if(useoption !== false) {
var opentag = '[' + tagname + '=' + useoption + ']';
} else {
var opentag = '[' + tagname + ']';
}
var closetag = '[/' + tagname + ']';
var text = opentag + selection + closetag;
insertText(text, mb_strlen(opentag), mb_strlen(closetag));
return false;
}
function applyFormat(cmd, dialog, argument) {
if(wysiwyg) {
editdoc.execCommand(cmd, (isUndefined(dialog) ? false : dialog), (isUndefined(argument) ? true : argument));
return false;
}
switch(cmd) {
case 'bold':
case 'italic':
case 'underline':
wrapTags(cmd.substr(0, 1), false);
break;
case 'justifyleft':
case 'justifycenter':
case 'justifyright':
wrapTags('align', cmd.substr(7));
break;
case 'indent':
wrapTags(cmd, false);
break;
case 'fontname':
wrapTags('font', argument);
break;
case 'fontsize':
wrapTags('size', argument);
break;
case 'forecolor':
wrapTags('color', argument);
break;
case 'createlink':
var sel = getSel();
if(sel) {
wrapTags('url', argument);
} else {
wrapTags('url', argument, argument);
}
break;
case 'insertimage':
wrapTags('img', false, argument);
break;
}
}
function customTags(tagname, params) {
applyFormat('removeformat');
if(custombbcodes[tagname].indexOf(']') == -1) {
custombbcodes[tagname] = '[' + tagname + '][/' + tagname + ']';
}
if(params == 1) {
var selection = getSel();
if(selection === false) {
selection = '';
} else {
selection += '';
}
var opentag = '[' + tagname + ']';
var closetag = '[/' + tagname + ']';
var text = opentag + selection + closetag;
selection == '' ? insertText(custombbcodes[tagname], mb_strlen('[' + tagname + ']'), mb_strlen('[/' + tagname + ']')) : insertText(text, mb_strlen(opentag), mb_strlen(closetag));
} else {
insertText(custombbcodes[tagname], custombbcodes[tagname].indexOf(']') + 1, mb_strlen('[/' + tagname + ']'));
}
return false;
}
function webcode(cmd, arg) {
if(cmd != 'redo') {
addSnapshot(getEditorContents());
}
checkFocus();
if(in_array(cmd, ['quote', 'code'])) {
var ret = wrapTags(cmd, false);
} else if(cmd.substr(0, 6) == 'custom') {
var ret = customTags(cmd.substr(8), cmd.substr(6, 1));
} else if(!wysiwyg && cmd == 'removeformat') {
var simplestrip = new Array('b', 'i', 'u');
var complexstrip = new Array('font', 'color', 'size');
var str = getSel();
if(str === false) {
return;
}
for(var tag in simplestrip) {
str = stripSimple(simplestrip[tag], str);
}
for(var tag in complexstrip) {
str = stripComplex(complexstrip[tag], str);
}
insertText(str);
} else if(!wysiwyg && cmd == 'undo') {
addSnapshot(getEditorContents());
moveCursor(-1);
if((str = getSnapshot()) !== false) {
editdoc.value = str;
}
} else if(!wysiwyg && cmd == 'redo') {
moveCursor(1);
if((str = getSnapshot()) !== false) {
editdoc.value = str;
}
} else if(!wysiwyg && in_array(cmd, ['insertorderedlist', 'insertunorderedlist'])) {
var listtype = cmd == 'insertorderedlist' ? '1' : '';
var opentag = '[list' + (listtype ? ('=' + listtype) : '') + ']\n';
var closetag = '[/list]';
if(txt = getSel()) {
var regex = new RegExp('([\r\n]+|^[\r\n]*)(?!\\[\\*\\]|\\[\\/?list)(?=[^\r\n])', 'gi');
txt = opentag + trim(txt).replace(regex, '$1[*]') + '\n' + closetag;
insertText(txt, mb_strlen(txt), 0);
} else {
insertText(opentag + closetag, opentag.length, closetag.length);
while(listvalue = prompt(lang['enter_list_item'], '')) {
if(is_opera && opera.version() > 8) {
listvalue = '\n' + '[*]' + listvalue;
insertText(listvalue, mb_strlen(listvalue) + 1, 0);
} else {
listvalue = '[*]' + listvalue + '\n';
insertText(listvalue, mb_strlen(listvalue), 0);
}
}
}
} else if(!wysiwyg && cmd == 'outdent') {
var sel = getSel();
sel = stripSimple('indent', sel, 1);
insertText(sel);
} else if(cmd == 'createlink') {
if(wysiwyg) {
if(is_moz || is_opera) {
var url = showPrompt(lang['enter_link_url'], 'http://');
if((url = verifyPrompt(url)) !== false) {
if(getSel()) {
applyFormat('unlink');
applyFormat('createlink', is_ie, (isUndefined(url) ? true : url));
} else {
insertText('<a href="' + url + '">' + url + '</a>');
}
}
} else {
applyFormat('createlink', is_ie, (isUndefined(url) ? true : url));
}
} else {
promptLink('url', lang['enter_link_url'], 'http://');
}
} else if(!wysiwyg && cmd == 'unlink') {
var sel = getSel();
sel = stripSimple('url', sel);
sel = stripComplex('url', sel);
insertText(sel);
} else if(cmd == 'email') {
if(wysiwyg) {
var email = showPrompt(lang['enter_email_link'], '');
email = verifyPrompt(email);
if(email === false) {
applyFormat('unlink');
} else {
var selection = getSel();
insertText('<a href="mailto:' + email + '">' + (selection ? selection : email) + '</a>', (selection ? true : false));
}
} else {
promptLink('email', lang['enter_email_link'], '');
}
} else if(cmd == 'insertimage') {
var img = showPrompt(lang['enter_image_url'], 'http://');
if(img = verifyPrompt(img)) {
return applyFormat('insertimage', false, img);
} else {
return false;
}
} else if(cmd == 'table') {
if(wysiwyg) {
if(isUndefined(rows)) {
var rows = showPrompt(lang['enter_table_rows'], '2');
}
if(rows != 'null' && isUndefined(columns)) {
var columns = showPrompt(lang['enter_table_columns'], '2');
}
if(!isUndefined(columns) && columns != 'null') {
rows = /^[-\+]?\d+$/.test(rows) && rows > 0 && rows <= 30 ? rows : 2;
columns = /^[-\+]?\d+$/.test(columns) && columns > 0 && columns <= 30 ? columns : 2;
var html = '<table cellspacing="1" cellpadding="4" width="50%" align="center" style="background: ' + BORDERCOLOR + '">';
for (var row = 0; row < rows; row++) {
html += '<tr bgcolor="' + ALTBG2 + '">\n';
for (col = 0; col < columns; col++) {
html += '<td> </td>\n';
}
html+= '</tr>\n';
}
html += '</table>\n';
insertText(html);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -