/*******************************************************************************
* KindEditor - WYSIWYG HTML Editor for Internet
* Copyright (C) 2006-2010 Longhao Luo
*
* @author Roddy ]*>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3){
return $1 + $2.replace(/
]*>/ig, '\n') + $3;
});
var htmlTagHash = {};
var fontSizeHash = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
if (isFilter) {
KE.each(htmlTags, function(key, val) {
var arr = key.split(',');
for (var i = 0, len = arr.length; i < len; i++) htmlTagHash[arr[i]] = KE.util.arrayToHash(val);
});
}
var noEndTagHash = KE.util.arrayToHash(KE.setting.noEndTags);
var inlineTagHash = KE.util.arrayToHash(KE.setting.inlineTags);
var endlineTagHash = KE.util.arrayToHash(KE.setting.endlineTags);
var re = /((?:\r\n|\n|\r)*)<(\/)?([\w-:]+)((?:\s+|(?:\s+[\w-:]+)|(?:\s+[\w-:]+=[^\s"'<>]+)|(?:\s+[\w-:]+="[^"]*")|(?:\s+[\w-:]+='[^']*'))*)(\/)?>((?:\r\n|\n|\r)*)/g;
html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
var startNewline = $1 || '';
var startSlash = $2 || '';
var tagName = $3.toLowerCase();
var attr = $4 || '';
var endSlash = $5 ? ' ' + $5 : '';
var endNewline = $6 || '';
if (isFilter && typeof htmlTagHash[tagName] == "undefined") return '';
if (endSlash === '' && typeof noEndTagHash[tagName] != "undefined") endSlash = ' /';
if (tagName in endlineTagHash) {
if (startSlash || endSlash) endNewline = '\n';
} else {
if (endNewline) endNewline = ' ';
}
if (tagName !== 'script' && tagName !== 'style') {
startNewline = '';
}
if (tagName === 'font') {
var style = {}, styleStr = '';
attr = attr.replace(/\s*([\w-:]+)=([^\s"'<>]+|"[^"]*"|'[^']*')/g, function($0, $1, $2) {
var key = $1.toLowerCase();
var val = $2 || '';
val = val.replace(/^["']|["']$/g, '');
if (key === 'color') {
style['color'] = val;
return ' ';
}
if (key === 'size') {
style['font-size'] = fontSizeHash[parseInt(val) - 1] || '';
return ' ';
}
if (key === 'face') {
style['font-family'] = val;
return ' ';
}
if (key === 'style') {
styleStr = val;
return ' ';
}
return $0;
});
if (styleStr && !/;$/.test(styleStr)) styleStr += ';';
KE.each(style, function(key, val) {
if (val !== '') {
if (/\s/.test(val)) val = "'" + val + "'";
styleStr += key + ':' + val + ';';
}
});
if (styleStr) attr += ' style="' + styleStr + '"';
tagName = 'span';
}
if (attr !== '') {
attr = attr.replace(/\s*([\w-:]+)=([^\s"'<>]+|"[^"]*"|'[^']*')/g, function($0, $1, $2) {
var key = $1.toLowerCase();
var val = $2 || '';
if (isFilter) {
if (key.charAt(0) === "." || (key !== "style" && typeof htmlTagHash[tagName][key] == "undefined")) return ' ';
}
if (val === '') {
val = '""';
} else {
if (key === "style") {
val = val.substr(1, val.length - 2);
val = val.replace(/\s*([^\s]+?)\s*:(.*?)(;|$)/g, function($0, $1, $2) {
var k = $1.toLowerCase();
if (isFilter) {
if (typeof htmlTagHash[tagName]['style'] == "undefined" && typeof htmlTagHash[tagName]['.' + k] == "undefined") return '';
}
var v = KE.util.trim($2);
v = KE.util.rgbToHex(v);
return k + ':' + v + ';';
});
val = KE.util.trim(val);
if (val === '') return '';
val = '"' + val + '"';
}
if (KE.util.inArray(key, ['src', 'href'])) {
if (val.charAt(0) === '"') {
val = val.substr(1, val.length - 2);
}
val = KE.format.getUrl(val, urlType);
}
if (val.charAt(0) !== '"') val = '"' + val + '"';
}
return ' ' + key + '=' + val + ' ';
});
attr = attr.replace(/\s+(checked|selected|disabled|readonly)(\s+|$)/ig, function($0, $1) {
var key = $1.toLowerCase();
if (isFilter) {
if (key.charAt(0) === "." || typeof htmlTagHash[tagName][key] == "undefined") return ' ';
}
return ' ' + key + '="' + key + '"' + ' ';
});
attr = KE.util.trim(attr);
attr = attr.replace(/\s+/g, ' ');
if (attr) attr = ' ' + attr;
return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
} else {
return startNewline + '<' + startSlash + tagName + endSlash + '>' + endNewline;
}
});
if (!KE.browser.IE) {
html = html.replace(/
\n<\/p>/ig, '
\n<\/p>/ig, '
\s* \s*<\/p>\s*$/ig, '');
if (g.filterMode) {
return KE.format.getHtml(html, g.htmlTags, g.urlType);
} else {
return KE.format.getHtml(html, null, g.urlType);
}
},
getData : function(id, wyswygMode) {
var g = KE.g[id];
wyswygMode = (wyswygMode === undefined) ? g.wyswygMode : wyswygMode;
if (!wyswygMode) {
this.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, g.newTextarea.value));
}
return this.toData(id, g.iframeDoc.body.innerHTML);
},
getSrcData : function(id) {
var g = KE.g[id];
if (!g.wyswygMode) {
this.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, g.newTextarea.value));
}
return g.iframeDoc.body.innerHTML;
},
getPureData : function(id) {
return this.extractText(this.getData(id));
},
extractText : function(str) {
str = str.replace(/<(?!img|embed).*?>/ig, '');
str = str.replace(/ /ig, ' ');
return str;
},
isEmpty : function(id) {
return this.getPureData(id).replace(/\r\n|\n|\r/, '').replace(/^\s+|\s+$/, '') === '';
},
setData : function(id) {
var g = KE.g[id];
if (g.srcTextarea) g.srcTextarea.value = this.getData(id);
},
focus : function(id) {
var g = KE.g[id];
if (g.wyswygMode) {
g.iframeWin.focus();
} else {
g.newTextarea.focus();
}
},
click : function(id, cmd) {
this.focus(id);
KE.hideMenu(id);
KE.plugin[cmd].click(id);
},
selection : function(id) {
if (!KE.browser.IE || !KE.g[id].keRange) {
this.setSelection(id);
}
},
setSelection : function(id) {
var g = KE.g[id];
var keSel = new KE.selection(g.iframeDoc);
if (!KE.browser.IE || keSel.range.item || keSel.range.parentElement().ownerDocument === g.iframeDoc) {
g.keSel = keSel;
g.keRange = g.keSel.keRange;
g.sel = g.keSel.sel;
g.range = g.keSel.range;
}
},
select : function(id) {
if (KE.browser.IE && KE.g[id].wyswygMode && KE.g[id].range) KE.g[id].range.select();
},
execCommand : function(id, cmd, value) {
KE.util.focus(id);
KE.util.select(id);
try {
KE.g[id].iframeDoc.execCommand(cmd, false, value);
} catch(e) {}
KE.toolbar.updateState(id);
KE.util.execOnchangeHandler(id);
},
innerHtml : function(el, html) {
if (KE.browser.IE) {
el.innerHTML = '' + html;
var temp = KE.$('__ke_temp_tag__', el.ownerDocument);
if (temp) temp.parentNode.removeChild(temp);
} else {
el.innerHTML = html;
}
},
pasteHtml : function(id, html, isStart) {
var g = KE.g[id];
var imgStr = '';
if (isStart) html = imgStr + html;
else html += imgStr;
if (KE.browser.IE) {
if (g.range.item) g.range.item(0).outerHTML = html;
else g.range.pasteHTML(html);
} else {
g.range.deleteContents();
var frag = g.range.createContextualFragment(html);
g.range.insertNode(frag);
}
var node = KE.$('__ke_temp_tag__', g.iframeDoc);
var blank = g.iframeDoc.createTextNode('');
node.parentNode.replaceChild(blank, node);
g.keRange.selectNode(blank);
g.keSel.addRange(g.keRange);
},
insertHtml : function(id, html) {
if (html === '') return;
var g = KE.g[id];
if (!g.wyswygMode) return;
if (!g.range) return;
html = this.execSetHtmlHooks(id, html);
if (KE.browser.IE) {
this.select(id);
if (g.range.item) {
try {
g.range.item(0).outerHTML = html;
} catch(e) {
var el = g.range.item(0);
var parent = el.parentNode;
parent.removeChild(el);
if (parent.nodeName.toLowerCase() != 'body') parent = parent.parentNode;
this.innerHtml(parent, html + parent.innerHTML);
}
} else {
g.range.pasteHTML(html);
}
} else if (KE.browser.GECKO && KE.browser.VERSION < 3) {
this.execCommand(id, 'inserthtml', html);
return;
} else {
this.pasteHtml(id, html);
}
KE.util.execOnchangeHandler(id);
},
setFullHtml : function(id, html) {
var g = KE.g[id];
if (!KE.browser.IE && html === '') html = '
';
var html = KE.util.execSetHtmlHooks(id, html);
this.innerHtml(g.iframeDoc.body, html);
if (!g.wyswygMode) g.newTextarea.value = KE.util.getData(id, true);
KE.util.execOnchangeHandler(id);
},
selectImageWebkit : function(id, e, isSelection) {
if (KE.browser.WEBKIT) {
var target = e.srcElement || e.target;
if (target.tagName.toLowerCase() == 'img') {
if (isSelection) KE.util.selection(id);
var range = KE.g[id].keRange;
range.selectNode(target);
KE.g[id].keSel.addRange(range);
}
}
},
addTabEvent : function(id) {
KE.event.add(KE.g[id].iframeDoc, 'keydown', function(e) {
if (e.keyCode == 9) {
KE.util.setSelection(id);
KE.util.insertHtml(id, ' ');
KE.event.stop(e);
return false;
}
}, id);
},
addContextmenuEvent : function(id) {
var g = KE.g[id];
if (g.contextmenuItems.length == 0) return;
KE.event.add(g.iframeDoc, 'contextmenu', function(e){
KE.hideMenu(id);
KE.util.setSelection(id);
KE.util.selectImageWebkit(id, e, false);
var maxWidth = 0;
var items = [];
for (var i = 0, len = g.contextmenuItems.length; i < len; i++) {
var item = g.contextmenuItems[i];
if (item === '-') {
items.push(item);
} else if (item.cond && item.cond(id)) {
items.push(item);
if (item.options) {
var width = parseInt(item.options.width) || 0;
if (width > maxWidth) maxWidth = width;
}
}
prevItem = item;
}
while (items.length > 0 && items[0] === '-') {
items.shift();
}
while (items.length > 0 && items[items.length - 1] === '-') {
items.pop();
}
var prevItem = null;
for (var i = 0, len = items.length; i < len; i++) {
if (items[i] === '-' && prevItem === '-') delete items[i];
prevItem = items[i] || null;
}
if (items.length > 0) {
var menu = new KE.menu({
id : id,
event : e,
type : 'contextmenu',
width : maxWidth
});
for (var i = 0, len = items.length; i < len; i++) {
var item = items[i];
if (!item) continue;
if (item === '-') {
if (i < len - 1) menu.addSeparator();
} else {
menu.add(item.text, (function(item) {
return function() {
item.click(id, menu);
};
})(item), item.options);
}
}
menu.show();
KE.event.stop(e);
return false;
}
return true;
}, id);
},
addNewlineEvent : function(id) {
var g = KE.g[id];
if (KE.browser.IE && g.newlineTag.toLowerCase() != 'br') return;
if (KE.browser.GECKO && KE.browser.VERSION < 3 && g.newlineTag.toLowerCase() != 'p') return;
if (KE.browser.OPERA) return;
KE.event.add(g.iframeDoc, 'keydown', function(e) {
if (e.keyCode != 13 || e.shiftKey || e.ctrlKey || e.altKey) return true;
KE.util.setSelection(id);
var parent = g.keRange.getParentElement();
if (KE.util.inMarquee(parent)) return;
var tagName = parent.tagName.toLowerCase();
if (g.newlineTag.toLowerCase() == 'br') {
if (!KE.util.inArray(tagName, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li'])) {
KE.util.pasteHtml(id, '
');
var nextNode = g.keRange.startNode.nextSibling;
if (KE.browser.IE) {
if (!nextNode) KE.util.pasteHtml(id, '
', true);
} else if (KE.browser.WEBKIT) {
if (!nextNode) {
KE.util.pasteHtml(id, '
', true);
} else {
var range = new KE.range(g.iframeDoc);
range.selectNode(nextNode.parentNode);
range.setStart(nextNode, 0);
if (range.cloneContents().innerHTML.replace(/<(?!img|embed).*?>/ig, '') === '') {
KE.util.pasteHtml(id, '
', true);
}
}
}
KE.event.stop(e);
return false;
}
} else {
if (!KE.util.inArray(tagName, ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'div', 'li'])) {
KE.util.execCommand(id, 'formatblock', '
');
}
}
return true;
}, id);
}
};
KE.layout = {
hide : function(id) {
var g = KE.g[id];
KE.hideMenu(id);
var stack = g.dialogStack;
while (stack.length > 0) {
var dialog = stack[stack.length - 1];
dialog.hide();
}
g.maskDiv.style.display = 'none';
}
};
KE.hideMenu = function(id) {
var g = KE.g[id];
g.hideDiv.innerHTML = '';
g.hideDiv.style.display = 'none';
};
KE.colorpicker = function(arg) {
var wrapper;
var x = arg.x || 0;
var y = arg.y || 0;
var z = arg.z || 0;
var colors = arg.colors || KE.setting.colorTable;
var doc = arg.doc || document;
var onclick = arg.onclick;
var selectedColor = (arg.selectedColor || '').toLowerCase();
function init() {
wrapper = KE.$$('div');
wrapper.className = 'ke-colorpicker';
wrapper.style.top = y + 'px';
wrapper.style.left = x + 'px';
wrapper.style.zIndex = z;
}
init.call(this);
this.remove = function() {
doc.body.removeChild(wrapper);
};
this.getElement = function() {
function addAttr(cell, color, cls) {
if (selectedColor === color.toLowerCase()) cls += ' ke-colorpicker-cell-selected';
cell.className = cls;
cell.title = color || KE.lang['noColor'];
cell.onmouseover = function() { this.className = cls + ' ke-colorpicker-cell-on'; };
cell.onmouseout = function() { this.className = cls; };
cell.onclick = function() { onclick(color); };
if (color) {
var div = KE.$$('div');
div.className = 'ke-colorpicker-cell-color';
div.style.backgroundColor = color;
cell.appendChild(div);
} else {
cell.innerHTML = KE.lang['noColor'];
}
}
var table = KE.$$('table');
table.className = 'ke-colorpicker-table';
table.cellPadding = 0;
table.cellSpacing = 0;
table.border = 0;
var row = table.insertRow(0),
cell = row.insertCell(0);
cell.colSpan = colors[0].length;
addAttr(cell, '', 'ke-colorpicker-cell-top');
for (var i = 0; i < colors.length; i++) {
var row = table.insertRow(i + 1);
for (var j = 0; j < colors[i].length; j++) {
var color = colors[i][j],
cell = row.insertCell(j);
addAttr(cell, color, 'ke-colorpicker-cell');
}
}
return table;
};
this.create = function() {
wrapper.appendChild(this.getElement());
KE.event.bind(wrapper, 'click', function(e){});
KE.event.bind(wrapper, 'mousedown', function(e){});
doc.body.appendChild(wrapper);
};
};
KE.menu = function(arg){
function getPos(width, height) {
var id = arg.id;
var x = 0;
var y = 0;
if (this.type == 'menu') {
var obj = KE.g[id].toolbarIcon[arg.cmd];
var pos = KE.util.getElementPos(obj[0]);
x = pos.x;
y = pos.y + obj[0].offsetHeight;
} else {
var pos = KE.util.getCoords(arg.event);
var iframePos = KE.util.getElementPos(KE.g[id].iframe);
x = pos.x + iframePos.x;
y = pos.y + iframePos.y + 5;
}
if (width > 0 || height > 0) {
var scrollPos = KE.util.getScrollPos();
var docEl = KE.util.getDocumentElement();
var maxLeft = scrollPos.x + docEl.clientWidth - width - 2;
if (x > maxLeft) x = maxLeft;
}
return {x : x, y : y};
};
function init() {
var width = arg.width;
this.type = (arg.type && arg.type == 'contextmenu') ? arg.type : 'menu';
var div = KE.$$('div');
div.className = 'ke-' + this.type;
div.setAttribute('name', arg.cmd);
var pos = getPos.call(this, 0, 0);
div.style.top = pos.y + 'px';
div.style.left = pos.x + 'px';
if (arg.width) div.style.width = (/^\d+$/.test(width)) ? width + 'px' : width;
KE.event.bind(div, 'click', function(e){}, arg.id);
KE.event.bind(div, 'mousedown', function(e){}, arg.id);
this.div = div;
};
init.call(this);
this.add = function(html, event, options) {
var height, iconHtml, checked = false;
if (options !== undefined) {
height = options.height;
iconHtml = options.iconHtml;
checked = options.checked;
}
var self = this;
var cDiv = KE.$$('div');
cDiv.className = 'ke-' + self.type + '-item';
if (height) cDiv.style.height = height;
var left = KE.$$('div');
left.className = 'ke-' + this.type + '-left';
var center = KE.$$('div');
center.className = 'ke-' + self.type + '-center';
if (height) center.style.height = height;
var right = KE.$$('div');
right.className = 'ke-' + this.type + '-right';
if (height) right.style.lineHeight = height;
cDiv.onmouseover = function() {
this.className = 'ke-' + self.type + '-item ke-' + self.type + '-item-on';
center.className = 'ke-' + self.type + '-center ke-' + self.type + '-center-on';
};
cDiv.onmouseout = function() {
this.className = 'ke-' + self.type + '-item';
center.className = 'ke-' + self.type + '-center';
};
cDiv.onclick = event;
cDiv.appendChild(left);
cDiv.appendChild(center);
cDiv.appendChild(right);
if (checked) {
KE.util.innerHtml(left, '');
} else {
if (iconHtml) KE.util.innerHtml(left, iconHtml);
}
KE.util.innerHtml(right, html);
this.append(cDiv);
};
this.addSeparator = function() {
var div = KE.$$('div');
div.className = 'ke-' + this.type + '-separator';
this.append(div);
};
this.append = function(el) {
this.div.appendChild(el);
};
this.insert = function(html) {
KE.util.innerHtml(this.div, html);
};
this.hide = function() {
KE.hideMenu(arg.id);
};
this.show = function() {
this.hide();
var id = arg.id;
KE.g[id].hideDiv.style.display = '';
KE.g[id].hideDiv.appendChild(this.div);
var pos = getPos.call(this, this.div.clientWidth, this.div.clientHeight);
this.div.style.top = pos.y + 'px';
this.div.style.left = pos.x + 'px';
};
this.picker = function(color) {
var colorTable = KE.g[arg.id].colorTable;
var picker = new KE.colorpicker({
colors : colorTable,
onclick : function(color) { KE.plugin[arg.cmd].exec(arg.id, color); },
selectedColor : color
});
this.append(picker.getElement());
this.show();
};
};
KE.dialog = function(arg){
var self = this;
this.widthMargin = 30;
this.heightMargin = 100;
this.zIndex = 19811214;
this.width = arg.width;
this.height = arg.height;
var minTop, minLeft;
function setLimitNumber() {
var docEl = KE.util.getDocumentElement();
var pos = KE.util.getScrollPos();
minTop = pos.y;
minLeft = pos.x;
}
function init() {
this.beforeHide = arg.beforeHide;
this.afterHide = arg.afterHide;
this.beforeShow = arg.beforeShow;
this.afterShow = arg.afterShow;
this.ondrag = arg.ondrag;
}
init.call(this);
function getPos() {
var width = this.width + this.widthMargin;
var height = this.height + this.heightMargin;
var id = arg.id;
var g = KE.g[id];
var x = 0, y = 0;
if (g.dialogAlignType == 'page') {
var el = KE.util.getDocumentElement();
var scrollPos = KE.util.getScrollPos();
x = Math.round(scrollPos.x + (el.clientWidth - width) / 2);
y = Math.round(scrollPos.y + (el.clientHeight - height) / 2);
} else {
var pos = KE.util.getElementPos(KE.g[id].container);
var el = g.container;
var xDiff = Math.round(el.clientWidth / 2) - Math.round(width / 2);
var yDiff = Math.round(el.clientHeight / 2) - Math.round(height / 2);
x = xDiff < 0 ? pos.x : pos.x + xDiff;
y = yDiff < 0 ? pos.y : pos.y + yDiff;
}
x = x < 0 ? 0 : x;
y = y < 0 ? 0 : y;
return {x : x, y : y};
};
this.resize = function(width, height) {
if (width) this.width = width;
if (height) this.height = height;
this.hide();
this.show();
};
this.hide = function() {
if (this.beforeHide) this.beforeHide(id);
var id = arg.id;
var stack = KE.g[id].dialogStack;
if (stack[stack.length - 1] != this) return;
var dialog = stack.pop();
var iframe = dialog.iframe;
iframe.src = 'javascript:false';
iframe.parentNode.removeChild(iframe);
document.body.removeChild(this.div);
if (stack.length < 1) {
KE.g[id].maskDiv.style.display = 'none';
}
KE.event.remove(window, 'resize', setLimitNumber);
KE.event.remove(window, 'scroll', setLimitNumber);
if (this.afterHide) this.afterHide(id);
KE.util.focus(id);
};
this.show = function() {
if (this.beforeShow) this.beforeShow(id);
var self = this;
var id = arg.id;
var div = KE.$$('div');
div.className = 'ke-dialog';
KE.event.bind(div, 'click', function(e){}, id);
KE.event.bind(div, 'mousedown', function(e){}, id);
var stack = KE.g[id].dialogStack;
if (stack.length > 0) {
this.zIndex = stack[stack.length - 1].zIndex + 1;
}
div.style.zIndex = this.zIndex;
var pos = getPos.call(this);
div.style.top = pos.y + 'px';
div.style.left = pos.x + 'px';
var contentCell;
if (KE.g[id].shadowMode) {
var table = KE.$$('table');
table.className = 'ke-dialog-table';
table.cellPadding = 0;
table.cellSpacing = 0;
table.border = 0;
var rowNames = ['t', 'm', 'b'];
var colNames = ['l', 'c', 'r'];
for (var i = 0, len = 3; i < len; i++) {
var row = table.insertRow(i);
for (var j = 0, l = 3; j < l; j++) {
var cell = row.insertCell(j);
cell.className = 'ke-' + rowNames[i] + colNames[j];
if (i == 1 && j == 1) contentCell = cell;
else cell.innerHTML = '';
}
}
div.appendChild(table);
} else {
KE.addClass(div, 'ke-dialog-no-shadow');
contentCell = div;
}
var titleDiv = KE.$$('div');
titleDiv.className = 'ke-dialog-title';
titleDiv.innerHTML = arg.title;
var span = KE.$$('span');
span.className = 'ke-dialog-close';
if (KE.g[id].shadowMode) KE.addClass(span, 'ke-dialog-close-shadow');
else KE.addClass(span, 'ke-dialog-close-no-shadow');
span.alt = KE.lang['close'];
span.title = KE.lang['close'];
span.onclick = function () {
self.hide();
KE.util.select(id);
};
titleDiv.appendChild(span);
setLimitNumber();
KE.event.add(window, 'resize', setLimitNumber);
KE.event.add(window, 'scroll', setLimitNumber);
KE.util.drag(id, titleDiv, div, function(objTop, objLeft, objWidth, objHeight, top, left) {
if (self.ondrag) self.ondrag(id);
setLimitNumber();
top = objTop + top;
left = objLeft + left;
if (top < minTop) top = minTop;
if (left < minLeft) left = minLeft;
div.style.top = top + 'px';
div.style.left = left + 'px';
});
contentCell.appendChild(titleDiv);
var bodyDiv = KE.$$('div');
bodyDiv.className = 'ke-dialog-body';
var loadingTable = KE.util.createTable();
loadingTable.table.className = 'ke-loading-table';
loadingTable.table.style.width = this.width + 'px';
loadingTable.table.style.height = this.height + 'px';
var loadingImg = KE.$$('span');
loadingImg.className = 'ke-loading-img';
loadingTable.cell.appendChild(loadingImg);
var iframe = (KE.g[id].dialogStack.length == 0 && KE.g[id].dialog) ? KE.g[id].dialog : KE.$$('iframe');
if (arg.useFrameCSS) {
iframe.className = 'ke-dialog-iframe ke-dialog-iframe-border';
} else {
iframe.className = 'ke-dialog-iframe';
}
iframe.setAttribute("frameBorder", "0");
iframe.style.width = this.width + 'px';
iframe.style.height = this.height + 'px';
iframe.style.display = 'none';
bodyDiv.appendChild(iframe);
bodyDiv.appendChild(loadingTable.table);
contentCell.appendChild(bodyDiv);
var bottomDiv = KE.$$('div');
bottomDiv.className = 'ke-dialog-bottom';
var noButton = null;
var yesButton = null;
var previewButton = null;
if (arg.previewButton) {
previewButton = KE.$$('input');
previewButton.className = 'ke-button ke-dialog-preview';
previewButton.type = 'button';
previewButton.name = 'previewButton';
previewButton.value = arg.previewButton;
previewButton.onclick = function() {
var stack = KE.g[id].dialogStack;
if (stack[stack.length - 1] == self) {
KE.plugin[arg.cmd].preview(id);
}
};
bottomDiv.appendChild(previewButton);
}
if (arg.yesButton) {
yesButton = KE.$$('input');
yesButton.className = 'ke-button ke-dialog-yes';
yesButton.type = 'button';
yesButton.name = 'yesButton';
yesButton.value = arg.yesButton;
yesButton.onclick = function() {
var stack = KE.g[id].dialogStack;
if (stack[stack.length - 1] == self) {
KE.plugin[arg.cmd].exec(id);
}
};
bottomDiv.appendChild(yesButton);
}
if (arg.noButton) {
noButton = KE.$$('input');
noButton.className = 'ke-button ke-dialog-no';
noButton.type = 'button';
noButton.name = 'noButton';
noButton.value = arg.noButton;
noButton.onclick = function () {
self.hide();
KE.util.select(id);
};
bottomDiv.appendChild(noButton);
}
if (arg.yesButton || arg.noButton || arg.previewButton) {
contentCell.appendChild(bottomDiv);
}
document.body.appendChild(div);
window.focus();
if (yesButton) yesButton.focus();
else if (noButton) noButton.focus();
if (arg.html !== undefined) {
var dialogDoc = KE.util.getIframeDoc(iframe);
var html = KE.util.getFullHtml(id);
dialogDoc.open();
dialogDoc.write(html);
dialogDoc.close();
KE.util.innerHtml(dialogDoc.body, arg.html);
} else if (arg.url !== undefined) {
iframe.src = arg.url;
} else {
var param = 'id=' + escape(id) + '&ver=' + escape(KE.version);
if (arg.file === undefined) {
iframe.src = KE.g[id].pluginsPath + arg.cmd + '.html?' + param;
} else {
param = (/\?/.test(arg.file) ? '&' : '?') + param;
iframe.src = KE.g[id].pluginsPath + arg.file + param;
}
}
KE.g[id].maskDiv.style.width = KE.util.getDocumentWidth() + 'px';
KE.g[id].maskDiv.style.height = KE.util.getDocumentHeight() + 'px';
KE.g[id].maskDiv.style.display = 'block';
this.iframe = iframe;
this.loading = loadingTable.table;
this.noButton = noButton;
this.yesButton = yesButton;
this.previewButton = previewButton;
this.div = div;
KE.g[id].dialogStack.push(this);
KE.g[id].dialog = iframe;
KE.g[id].yesButton = yesButton;
KE.g[id].noButton = noButton;
KE.g[id].previewButton = previewButton;
if (!arg.loadingMode) KE.util.hideLoadingPage(id);
if (this.afterShow) this.afterShow(id);
if (KE.g[id].afterDialogCreate) KE.g[id].afterDialogCreate(id);
};
};
KE.toolbar = {
updateState : function(id) {
var cmdList = [
'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript','superscript',
'bold', 'italic', 'underline', 'strikethrough'
];
for (var i = 0; i < cmdList.length; i++) {
var cmd = cmdList[i];
var state = false;
try {
state = KE.g[id].iframeDoc.queryCommandState(cmd);
} catch(e) {}
if (state) {
KE.toolbar.select(id, cmd);
} else {
KE.toolbar.unselect(id, cmd);
}
}
},
isSelected : function(id, cmd) {
if (KE.plugin[cmd] && KE.plugin[cmd].isSelected) return true;
else return false;
},
select : function(id, cmd) {
if (KE.g[id].toolbarIcon[cmd]) {
var a = KE.g[id].toolbarIcon[cmd][0];
a.className = 'ke-icon ke-icon-selected';
a.onmouseover = null;
a.onmouseout = null;
}
},
unselect : function(id, cmd) {
if (KE.g[id].toolbarIcon[cmd]) {
var a = KE.g[id].toolbarIcon[cmd][0];
a.className = 'ke-icon';
a.onmouseover = function(){ this.className = 'ke-icon ke-icon-on'; };
a.onmouseout = function(){ this.className = 'ke-icon'; };
}
},
_setAttr : function(id, a, cmd) {
a.className = 'ke-icon';
a.href = 'javascript:;';
a.onclick = function(e) {
e = e || window.event;
var div = KE.g[id].hideDiv.firstChild;
if (div && div.getAttribute('name') == cmd) {
KE.hideMenu(id);
} else {
KE.util.click(id, cmd);
}
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
if (e.cancelBubble !== undefined) e.cancelBubble = true;
return false;
};
a.onmouseover = function(){ this.className = 'ke-icon ke-icon-on'; };
a.onmouseout = function(){ this.className = 'ke-icon'; };
a.hidefocus = true;
a.title = KE.lang[cmd];
},
able : function(id, arr) {
var self = this;
KE.each(KE.g[id].toolbarIcon, function(cmd, obj) {
if (!KE.util.inArray(cmd, arr)) {
var a = obj[0];
var span = obj[1];
self._setAttr(id, a, cmd);
KE.util.setOpacity(span, 100);
}
});
},
disable : function(id, arr) {
KE.each(KE.g[id].toolbarIcon, function(cmd, obj) {
if (!KE.util.inArray(cmd, arr)) {
var a = obj[0];
var span = obj[1];
a.className = 'ke-icon ke-icon-disabled';
KE.util.setOpacity(span, 50);
a.onclick = null;
a.onmouseover = null;
a.onmouseout = null;
}
});
},
create : function(id) {
var self = this;
var defaultItemHash = KE.util.arrayToHash(KE.setting.items);
KE.g[id].toolbarIcon = [];
var tableObj = KE.util.createTable();
var toolbar = tableObj.table;
toolbar.className = 'ke-toolbar';
toolbar.oncontextmenu = function() { return false; };
toolbar.onmousedown = function() { return false; };
toolbar.onmousemove = function() { return false; };
var toolbarCell = tableObj.cell;
var length = KE.g[id].items.length;
var cellNum = 0;
var row;
KE.g[id].toolbarHeight = KE.g[id].toolbarLineHeight;
for (var i = 0; i < length; i++) {
var cmd = KE.g[id].items[i];
if (i == 0 || cmd == '-') {
var table = KE.util.createTable().table;
table.className = 'ke-toolbar-table';
row = table.insertRow(0);
cellNum = 0;
toolbarCell.appendChild(table);
if (cmd == '-') {
KE.g[id].toolbarHeight += KE.g[id].toolbarLineHeight;
continue;
}
}
var cell = row.insertCell(cellNum);
cell.hideforcus = true;
cellNum++;
if (cmd == '|') {
var div = KE.$$('div');
div.className = 'ke-toolbar-separator';
cell.appendChild(div);
continue;
}
var a = KE.$$('a');
self._setAttr(id, a, cmd);
var span = KE.$$('span');
if (typeof defaultItemHash[cmd] == 'undefined') {
span.className = 'ke-common-icon ke-icon-' + cmd;
} else {
span.className = 'ke-common-icon ke-common-icon-url ke-icon-' + cmd;
}
a.appendChild(span);
cell.appendChild(a);
KE.g[id].toolbarIcon[cmd] = [a, span];
if (KE.toolbar.isSelected(id, cmd)) KE.toolbar.select(id, cmd);
}
return toolbar;
}
};
KE.history = {
addStackData : function(stack, data) {
var prev = '';
if (stack.length > 0) {
prev = stack[stack.length - 1];
}
if (stack.length == 0 || data !== prev) stack.push(data);
},
add : function(id, minChangeSize) {
var g = KE.g[id];
var html = KE.util.getSrcData(id);
if (g.undoStack.length > 0) {
var prevHtml = g.undoStack[g.undoStack.length - 1];
if (Math.abs(html.length - prevHtml.length) < minChangeSize) return;
}
this.addStackData(g.undoStack, html);
},
undo : function(id) {
var g = KE.g[id];
if (g.undoStack.length == 0) return;
var html = KE.util.getSrcData(id);
this.addStackData(g.redoStack, html);
var prevHtml = g.undoStack.pop();
if (html === prevHtml && g.undoStack.length > 0) {
prevHtml = g.undoStack.pop();
}
prevHtml = KE.util.toData(id, prevHtml);
if (g.wyswygMode) {
KE.util.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, prevHtml));
} else {
g.newTextarea.value = prevHtml;
}
},
redo : function(id) {
var g = KE.g[id];
if (g.redoStack.length == 0) return;
var html = KE.util.getSrcData(id);
this.addStackData(g.undoStack, html);
var nextHtml = g.redoStack.pop();
nextHtml = KE.util.toData(id, nextHtml);
if (g.wyswygMode) {
KE.util.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, nextHtml));
} else {
g.newTextarea.value = nextHtml;
}
}
};
KE.readonly = function(id, isReadonly) {
isReadonly = isReadonly == undefined ? true : isReadonly;
var g = KE.g[id];
if (KE.browser.IE) g.iframeDoc.body.contentEditable = isReadonly ? 'false' : 'true';
else g.iframeDoc.designMode = isReadonly ? 'off' : 'on';
};
KE.focus = function(id, position) {
position = (position || '').toLowerCase();
if (!KE.g[id].container) return;
KE.util.focus(id);
if (position === 'end') {
KE.util.setSelection(id);
if (!KE.g[id].sel) return; //issue #120: Sometimes Firefox does not get selection
var sel = KE.g[id].keSel,
range = KE.g[id].keRange,
doc = KE.g[id].iframeDoc;
range.selectTextNode(doc.body);
range.collapse(false);
sel.addRange(range);
}
};
KE.html = function(id, val) {
if (val === undefined) {
return KE.util.getData(id);
} else {
if (!KE.g[id].container) return;
KE.util.setFullHtml(id, val);
KE.focus(id, 'end');
}
};
KE.text = function(id, val) {
if (val === undefined) {
val = KE.html(id);
val = val.replace(/<.*?>/ig, '');
val = val.replace(/ /ig, ' ');
val = KE.util.trim(val);
return val;
} else {
KE.html(id, KE.util.escape(val));
}
};
KE.insertHtml = function(id, val) {
if (!KE.g[id].container) return;
var range = KE.g[id].range;
if (!range) {
KE.appendHtml(id, val);
} else {
KE.focus(id);
KE.util.selection(id);
KE.util.insertHtml(id, val);
}
};
KE.appendHtml = function(id, val) {
KE.html(id, KE.html(id) + val);
KE.focus(id, 'end');
};
KE.isEmpty = function(id) {
return KE.util.isEmpty(id);
};
KE.selectedHtml = function(id) {
var range = KE.g[id].range;
if (!range) return '';
var html = '';
if (KE.browser.IE) {
if (range.item) {
html = range.item(0).outerHTML;
} else {
html = range.htmlText;
}
} else {
var temp = KE.$$('div', KE.g[id].iframeDoc);
temp.appendChild(range.cloneContents());
html = temp.innerHTML;
}
return KE.util.toData(id, html);
};
KE.count = function(id, mode) {
mode = (mode || 'html').toLowerCase();
if (mode === 'html') {
return KE.html(id).length;
} else if (mode === 'text') {
var data = KE.util.getPureData(id);
data = data.replace(/<(?:img|embed).*?>/ig, 'K');
data = data.replace(/\r\n|\n|\r/g, '');
data = KE.util.trim(data);
return data.length;
}
return 0;
};
KE.remove = function(id, mode) {
var g = KE.g[id];
if (!g.container) return false;
mode = (typeof mode == "undefined") ? 0 : mode;
KE.util.setData(id);
var container = g.container;
var eventStack = g.eventStack;
for (var i = 0, len = eventStack.length; i < len; i++) {
var item = eventStack[i];
if (item) KE.event.remove(item.el, item.type, item.fn, id);
}
g.iframeDoc.src = 'javascript:false';
g.iframe.parentNode.removeChild(g.iframe);
if (mode == 1) {
document.body.removeChild(container);
} else {
var srcTextarea = g.srcTextarea;
srcTextarea.parentNode.removeChild(container);
if (mode == 0) srcTextarea.style.display = '';
}
document.body.removeChild(g.hideDiv);
document.body.removeChild(g.maskDiv);
g.container = null;
g.dialogStack = [];
g.contextmenuItems = [];
g.getHtmlHooks = [];
g.setHtmlHooks = [];
g.onchangeHandlerStack = [];
g.eventStack = [];
};
KE.create = function(id, mode) {
if (KE.g[id].beforeCreate) KE.g[id].beforeCreate(id);
if (KE.browser.IE && KE.browser.VERSION < 7) try { document.execCommand('BackgroundImageCache', false, true); }catch(e){}
var srcTextarea = KE.$(id) || document.getElementsByName(id)[0];
mode = (typeof mode == "undefined") ? 0 : mode;
if (mode == 0 && KE.g[id].container) return;
var width = KE.g[id].width || srcTextarea.style.width || srcTextarea.offsetWidth + 'px';
var height = KE.g[id].height || srcTextarea.style.height || srcTextarea.offsetHeight + 'px';
var tableObj = KE.util.createTable();
var container = tableObj.table;
container.className = 'ke-container';
container.style.width = width;
container.style.height = height;
var toolbarOuter = tableObj.cell;
toolbarOuter.className = 'ke-toolbar-outer';
var textareaOuter = container.insertRow(1).insertCell(0);
textareaOuter.className = 'ke-textarea-outer';
tableObj = KE.util.createTable();
var textareaTable = tableObj.table;
textareaTable.className = 'ke-textarea-table';
var textareaCell = tableObj.cell;
textareaOuter.appendChild(textareaTable);
var bottomOuter = container.insertRow(2).insertCell(0);
bottomOuter.className = 'ke-bottom-outer';
srcTextarea.style.display = 'none';
if (mode == 1) document.body.appendChild(container);
else srcTextarea.parentNode.insertBefore(container, srcTextarea);
var toolbarTable = KE.toolbar.create(id);
toolbarTable.style.height = KE.g[id].toolbarHeight + 'px';
toolbarOuter.appendChild(toolbarTable);
var iframe = KE.g[id].iframe || KE.$$('iframe');
iframe.className = 'ke-iframe';
iframe.setAttribute("frameBorder", "0");
var newTextarea = KE.$$('textarea');
newTextarea.className = 'ke-textarea';
newTextarea.style.display = 'none';
KE.g[id].container = container;
KE.g[id].iframe = iframe;
KE.g[id].newTextarea = newTextarea;
KE.util.resize(id, width, height);
textareaCell.appendChild(iframe);
textareaCell.appendChild(newTextarea);
var bottom = KE.$$('table');
bottom.className = 'ke-bottom';
bottom.cellPadding = 0;
bottom.cellSpacing = 0;
bottom.border = 0;
bottom.style.height = KE.g[id].statusbarHeight + 'px';
var row = bottom.insertRow(0);
var bottomLeft = row.insertCell(0);
bottomLeft.className = 'ke-bottom-left';
var leftImg = KE.$$('span');
leftImg.className = 'ke-bottom-left-img';
if (KE.g[id].config.resizeMode == 0 || mode == 1) {
bottomLeft.style.cursor = 'default';
leftImg.style.visibility = 'hidden';
}
bottomLeft.appendChild(leftImg);
var bottomRight = row.insertCell(1);
bottomRight.className = 'ke-bottom-right';
var rightImg = KE.$$('span');
rightImg.className = 'ke-bottom-right-img';
if (KE.g[id].config.resizeMode == 0 || mode == 1) {
bottomRight.style.cursor = 'default';
rightImg.style.visibility = 'hidden';
} else if (KE.g[id].config.resizeMode == 1) {
bottomRight.style.cursor = 's-resize';
rightImg.style.visibility = 'hidden';
}
bottomRight.appendChild(rightImg);
bottomOuter.appendChild(bottom);
var hideDiv = KE.$$('div');
hideDiv.className = 'ke-reset';
hideDiv.style.display = 'none';
var maskDiv = KE.$$('div');
maskDiv.className = 'ke-mask';
KE.util.setOpacity(maskDiv, 50);
KE.event.bind(maskDiv, 'click', function(e){}, id);
KE.event.bind(maskDiv, 'mousedown', function(e){}, id);
document.body.appendChild(hideDiv);
document.body.appendChild(maskDiv);
KE.util.setDefaultPlugin(id);
var iframeWin = iframe.contentWindow;
var iframeDoc = KE.util.getIframeDoc(iframe);
if (!KE.browser.IE || KE.browser.VERSION < 8) iframeDoc.designMode = 'on';
var html = KE.util.getFullHtml(id);
iframeDoc.open();
iframeDoc.write(html);
iframeDoc.close();
if (!KE.g[id].wyswygMode) {
newTextarea.value = KE.util.execSetHtmlHooks(id, srcTextarea.value);
newTextarea.style.display = 'block';
iframe.style.display = 'none';
KE.toolbar.disable(id, ['source', 'fullscreen']);
KE.toolbar.select(id, 'source');
}
function hideMenu() {
KE.hideMenu(id);
}
function updateToolbar() {
KE.toolbar.updateState(id);
}
if (KE.browser.WEBKIT) {
KE.event.add(iframeDoc, 'click', function(e) {
KE.util.selectImageWebkit(id, e, true);
}, id);
}
if (KE.browser.IE) {
KE.event.add(iframeDoc, 'keydown', function(e) {
if (e.keyCode == 8) {
var range = KE.g[id].range;
if (range.item) {
var item = range.item(0);
item.parentNode.removeChild(item);
KE.util.execOnchangeHandler(id);
KE.event.stop(id);
return false;
}
}
}, id);
}
KE.event.add(iframeDoc, 'click', hideMenu, id);
KE.event.add(iframeDoc, 'click', updateToolbar, id);
KE.event.input(iframeDoc, updateToolbar, id);
KE.event.bind(newTextarea, 'click', hideMenu, id);
KE.event.add(document, 'click', hideMenu, id);
KE.g[id].toolbarTable = toolbarTable;
KE.g[id].textareaTable = textareaTable;
KE.g[id].srcTextarea = srcTextarea;
KE.g[id].bottom = bottom;
KE.g[id].hideDiv = hideDiv;
KE.g[id].maskDiv = maskDiv;
KE.g[id].iframeWin = iframeWin;
KE.g[id].iframeDoc = iframeDoc;
KE.g[id].width = width;
KE.g[id].height = height;
KE.util.drag(id, bottomRight, container, function(objTop, objLeft, objWidth, objHeight, top, left) {
if (KE.g[id].resizeMode == 2) KE.util.resize(id, (objWidth + left) + 'px', (objHeight + top) + 'px', true);
else if (KE.g[id].resizeMode == 1) KE.util.resize(id, objWidth + 'px', (objHeight + top) + 'px', true, false);
});
KE.util.drag(id, bottomLeft, container, function(objTop, objLeft, objWidth, objHeight, top, left) {
if (KE.g[id].resizeMode > 0) KE.util.resize(id, objWidth + 'px', (objHeight + top) + 'px', true, false);
});
KE.each(KE.plugin, function(cmd, plugin) {
if (plugin.init) plugin.init(id);
});
KE.g[id].getHtmlHooks.push(function(html) {
return html.replace(/(<[^>]*)kesrc="([^"]+)"([^>]*>)/ig, function(full, start, src, end) {
full = full.replace(/(\s+(?:href|src)=")[^"]+(")/i, '$1' + src + '$2');
full = full.replace(/\s+kesrc="[^"]+"/i, '');
return full;
});
});
KE.g[id].setHtmlHooks.push(function(html) {
return html.replace(/(<[^>]*)(href|src)="([^"]+)"([^>]*>)/ig, function(full, start, key, src, end) {
if (full.match(/\skesrc="[^"]+"/i)) return full;
full = start + key + '="' + src + '"' + ' kesrc="' + src + '"' + end;
return full;
});
});
KE.util.addContextmenuEvent(id);
KE.util.addNewlineEvent(id);
KE.util.addTabEvent(id);
function setSelectionHandler() {
KE.util.setSelection(id);
}
KE.event.input(iframeDoc, setSelectionHandler, id);
KE.event.add(iframeDoc, 'mouseup', setSelectionHandler, id);
KE.event.add(document, 'mousedown', setSelectionHandler, id);
KE.onchange(id, function(id) {
if (KE.g[id].autoSetDataMode) {
KE.util.setData(id);
if (KE.g[id].afterSetData) KE.g[id].afterSetData(id);
}
KE.history.add(id, KE.g[id].minChangeSize);
});
if (KE.browser.IE && KE.browser.VERSION > 7) KE.readonly(id, false);
KE.util.setFullHtml(id, srcTextarea.value);
KE.history.add(id, 0);
if (mode > 0) KE.util.focus(id);
if (KE.g[id].afterCreate) KE.g[id].afterCreate(id);
};
KE.onchange = function(id, func) {
var g = KE.g[id];
function handler() {
func(id);
};
g.onchangeHandlerStack.push(handler);
KE.event.input(g.iframeDoc, handler, id);
KE.event.input(g.newTextarea, handler, id);
KE.event.add(g.iframeDoc, 'mouseup', function(e) {
window.setTimeout(function() {
func(id);
}, 0);
}, id);
};
KE.init = function(args) {
var g = KE.g[args.id] = args;
g.config = {};
g.undoStack = [];
g.redoStack = [];
g.dialogStack = [];
g.contextmenuItems = [];
g.getHtmlHooks = [];
g.setHtmlHooks = [];
g.onchangeHandlerStack = [];
g.eventStack = [];
KE.each(KE.setting, function(key, val) {
g[key] = (typeof args[key] == 'undefined') ? val : args[key];
g.config[key] = g[key];
});
if (g.loadStyleMode) KE.util.loadStyle(g.skinsPath + g.skinType + '.css');
}
KE.show = function(args) {
KE.init(args);
KE.event.ready(function() { KE.create(args.id); });
};
if (window.KE === undefined) window.KE = KE;
window.KindEditor = KE;
})();
(function (KE, undefined) {
KE.langType = 'zh_CN';
KE.lang = {
source : 'HTML代码',
undo : '后退(Ctrl+Z)',
redo : '前进(Ctrl+Y)',
cut : '剪切(Ctrl+X)',
copy : '复制(Ctrl+C)',
paste : '粘贴(Ctrl+V)',
plainpaste : '粘贴为无格式文本',
wordpaste : '从Word粘贴',
selectall : '全选',
justifyleft : '左对齐',
justifycenter : '居中',
justifyright : '右对齐',
justifyfull : '两端对齐',
insertorderedlist : '编号',
insertunorderedlist : '项目符号',
indent : '增加缩进',
outdent : '减少缩进',
subscript : '下标',
superscript : '上标',
title : '标题',
fontname : '字体',
fontsize : '文字大小',
textcolor : '文字颜色',
bgcolor : '文字背景',
bold : '粗体(Ctrl+B)',
italic : '斜体(Ctrl+I)',
underline : '下划线(Ctrl+U)',
strikethrough : '删除线',
removeformat : '删除格式',
image : '图片',
flash : '插入Flash',
media : '插入多媒体',
table : '插入表格',
hr : '插入横线',
emoticons : '插入表情',
link : '超级链接',
unlink : '取消超级链接',
fullscreen : '全屏显示',
about : '关于',
print : '打印',
fileManager : '浏览服务器',
advtable : '表格',
yes : '确定',
no : '取消',
close : '关闭',
editImage : '图片属性',
deleteImage : '删除图片',
editLink : '超级链接属性',
deleteLink : '取消超级链接',
tableprop : '表格属性',
tableinsert : '插入表格',
tabledelete : '删除表格',
tablecolinsertleft : '左侧插入列',
tablecolinsertright : '右侧插入列',
tablerowinsertabove : '上方插入行',
tablerowinsertbelow : '下方插入行',
tablecoldelete : '删除列',
tablerowdelete : '删除行',
noColor : '无颜色',
invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
invalidWidth : "宽度必须为数字。",
invalidHeight : "高度必须为数字。",
invalidBorder : "边框必须为数字。",
invalidUrl : "请输入有效的URL地址。",
invalidRows : '行数为必选项,只允许输入大于0的数字。',
invalidCols : '列数为必选项,只允许输入大于0的数字。',
invalidPadding : '边距必须为数字。',
invalidSpacing : '间距必须为数字。',
invalidBorder : '边框必须为数字。',
pleaseInput : "请输入内容。",
invalidJson : '服务器发生故障。',
cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。'
};
var plugins = KE.lang.plugins = {};
plugins.about = {
version : KE.version,
title : 'HTML可视化编辑器'
};
plugins.plainpaste = {
comment : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。'
};
plugins.wordpaste = {
comment : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。'
};
plugins.link = {
url : 'URL地址',
linkType : '打开类型',
newWindow : '新窗口',
selfWindow : '当前窗口'
};
plugins.flash = {
url : 'Flash地址',
width : '宽度',
height : '高度'
};
plugins.media = {
url : '媒体文件地址',
width : '宽度',
height : '高度',
autostart : '自动播放'
};
plugins.image = {
remoteImage : '远程图片',
localImage : '本地上传',
remoteUrl : '图片地址',
localUrl : '图片地址',
size : '图片大小',
width : '宽',
height : '高',
resetSize : '重置大小',
align : '对齐方式',
defaultAlign : '默认方式',
leftAlign : '左对齐',
rightAlign : '右对齐',
imgTitle : '图片说明',
viewServer : '浏览...'
};
plugins.file_manager = {
emptyFolder : '空文件夹',
moveup : '移到上一级文件夹',
viewType : '显示方式:',
viewImage : '缩略图',
listImage : '详细信息',
orderType : '排序方式:',
fileName : '名称',
fileSize : '大小',
fileType : '类型'
};
plugins.advtable = {
cells : '单元格数',
rows : '行数',
cols : '列数',
size : '表格大小',
width : '宽度',
height : '高度',
percent : '%',
px : 'px',
space : '边距间距',
padding : '边距',
spacing : '间距',
align : '对齐方式',
alignDefault : '默认',
alignLeft : '左对齐',
alignCenter : '居中',
alignRight : '右对齐',
border : '表格边框',
borderWidth : '边框',
borderColor : '颜色',
backgroundColor : '背景颜色'
};
plugins.title = {
h1 : '标题 1',
h2 : '标题 2',
h3 : '标题 3',
h4 : '标题 4',
p : '正 文'
};
plugins.fontname = {
fontName : {
'SimSun' : '宋体',
'NSimSun' : '新宋体',
'FangSong_GB2312' : '仿宋_GB2312',
'KaiTi_GB2312' : '楷体_GB2312',
'SimHei' : '黑体',
'Microsoft YaHei' : '微软雅黑',
'Arial' : 'Arial',
'Arial Black' : 'Arial Black',
'Times New Roman' : 'Times New Roman',
'Courier New' : 'Courier New',
'Tahoma' : 'Tahoma',
'Verdana' : 'Verdana'
}
};
})(KindEditor);
(function (KE, undefined) {
KE.plugin['about'] = {
click : function(id) {
KE.util.selection(id);
var dialog = new KE.dialog({
id : id,
cmd : 'about',
file : 'about.html',
width : 300,
height : 70,
loadingMode : true,
title : KE.lang['about'],
noButton : KE.lang['close']
});
dialog.show();
}
};
KE.plugin['undo'] = {
init : function(id) {
KE.event.ctrl(KE.g[id].iframeDoc, 'Z', function(e) {
KE.plugin['undo'].click(id);
KE.util.focus(id);
}, id);
KE.event.ctrl(KE.g[id].newTextarea, 'Z', function(e) {
KE.plugin['undo'].click(id);
KE.util.focus(id);
}, id);
},
click : function(id) {
KE.history.undo(id);
KE.util.execOnchangeHandler(id);
}
};
KE.plugin['redo'] = {
init : function(id) {
KE.event.ctrl(KE.g[id].iframeDoc, 'Y', function(e) {
KE.plugin['redo'].click(id);
KE.util.focus(id);
}, id);
KE.event.ctrl(KE.g[id].newTextarea, 'Y', function(e) {
KE.plugin['redo'].click(id);
KE.util.focus(id);
}, id);
},
click : function(id) {
KE.history.redo(id);
KE.util.execOnchangeHandler(id);
}
};
KE.plugin['cut'] = {
click : function(id) {
try {
if (!KE.g[id].iframeDoc.queryCommandSupported('cut')) throw 'e';
} catch(e) {
alert(KE.lang.cutError);
return;
}
KE.util.execCommand(id, 'cut', null);
}
};
KE.plugin['copy'] = {
click : function(id) {
try {
if (!KE.g[id].iframeDoc.queryCommandSupported('copy')) throw 'e';
} catch(e) {
alert(KE.lang.copyError);
return;
}
KE.util.execCommand(id, 'copy', null);
}
};
KE.plugin['paste'] = {
click : function(id) {
try {
if (!KE.g[id].iframeDoc.queryCommandSupported('paste')) throw 'e';
} catch(e) {
alert(KE.lang.pasteError);
return;
}
KE.util.execCommand(id, 'paste', null);
}
};
KE.plugin['plainpaste'] = {
click : function(id) {
KE.util.selection(id);
this.dialog = new KE.dialog({
id : id,
cmd : 'plainpaste',
file : 'plainpaste.html',
width : 450,
height : 300,
loadingMode : true,
title : KE.lang['plainpaste'],
yesButton : KE.lang['yes'],
noButton : KE.lang['no']
});
this.dialog.show();
},
exec : function(id) {
var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);
var html = KE.$('textArea', dialogDoc).value;
html = KE.util.escape(html);
html = html.replace(/ /g, ' ');
html = html.replace(/\r\n|\n|\r/g, "
$&");
KE.util.insertHtml(id, html);
this.dialog.hide();
KE.util.focus(id);
}
};
KE.plugin['wordpaste'] = {
click : function(id) {
KE.util.selection(id);
this.dialog = new KE.dialog({
id : id,
cmd : 'wordpaste',
file : 'wordpaste.html',
width : 450,
height : 300,
loadingMode : true,
title : KE.lang['wordpaste'],
yesButton : KE.lang['yes'],
noButton : KE.lang['no']
});
this.dialog.show();
},
exec : function(id) {
var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);
var wordIframe = KE.$('wordIframe', dialogDoc);
var str = KE.util.getIframeDoc(wordIframe).body.innerHTML;
str = str.replace(//ig, "");
str = str.replace(//ig, "");
str = str.replace(/