/******************************************************************************* * kindeditor - wysiwyg html editor for internet * copyright (c) 2006-2010 longhao luo * * @author roddy * @site http://www.kindsoft.net/ * @licence lgpl(http://www.opensource.org/licenses/lgpl-license.php) *******************************************************************************/ var ke = {}; ke.version = '3.4.4'; 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 : '粗体', italic : '斜体', underline : '下划线', strikethrough : '删除线', removeformat : '删除格式', image : '图片', flash : '插入flash', media : '插入多媒体', table : '插入表格', hr : '插入横线', emoticons : '插入表情', link : '超级链接', unlink : '取消超级链接', fullscreen : '全屏显示', about : '关于', print : '打印', yes : '确定', no : '取消', close : '关闭', editimage : '图片属性', deleteimage : '删除图片', editlink : '超级链接属性', deletelink : '取消超级链接', 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地址。", pleaseinput : "请输入内容", invalidjson : '服务器发生故障。', cuterror : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(ctrl+x)来完成。', copyerror : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(ctrl+c)来完成。', pasteerror : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(ctrl+v)来完成。' }; ke.scriptpath = (function() { var elements = document.getelementsbytagname('script'); for (var i = 0, len = elements.length; i < len; i++) { if (elements[i].src && elements[i].src.match(/kindeditor[\w\-\.]*\.js/)) { return elements[i].src.substring(0, elements[i].src.lastindexof('/') + 1); } } return ""; })(); ke.browser = (function() { var ua = navigator.useragent.tolowercase(); return { version: ua.match(/(msie|firefox|webkit|opera)[\/:\s](\d+)/) ? regexp.$2 : '0', ie: (ua.indexof('msie') > -1 && ua.indexof('opera') == -1), gecko: (ua.indexof('gecko') > -1 && ua.indexof('khtml') == -1), webkit: (ua.indexof('applewebkit') > -1), opera: (ua.indexof('opera') > -1) }; })(); ke.setting = { wyswygmode : true, loadstylemode : true, resizemode : 2, filtermode : false, urltype : '', skintype : 'default', newlinetag : 'p', dialogaligntype : 'page', csspath : '', skinspath : ke.scriptpath + 'skins/', pluginspath : ke.scriptpath + 'plugins/', minwidth : 200, minheight : 100, minchangesize : 5, items : [ 'source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', '|', 'selectall', '-', 'title', 'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image', 'flash', 'media', 'table', 'hr', 'emoticons', 'link', 'unlink', '|', 'about' ], colortable : [ ["#ffffff","#e5e4e4","#d9d8d8","#c0bdbd","#a7a4a4","#8e8a8b","#827e7f","#767173","#5c585a","#000000"], ["#fefcdf","#fef4c4","#feed9b","#fee573","#ffed43","#f6cc0b","#e0b800","#c9a601","#ad8e00","#8c7301"], ["#ffded3","#ffc4b0","#ff9d7d","#ff7a4e","#ff6600","#e95d00","#d15502","#ba4b01","#a44201","#8d3901"], ["#ffd2d0","#ffbab7","#fe9a95","#ff7a73","#ff483f","#fe2419","#f10b00","#d40a00","#940000","#6d201b"], ["#ffdaed","#ffb7dc","#ffa1d1","#ff84c3","#ff57ac","#fd1289","#ec0078","#d6006d","#bb005f","#9b014f"], ["#fcd6fe","#fbbcff","#f9a1fe","#f784fe","#f564fe","#f546ff","#f328ff","#d801e5","#c001cb","#8f0197"], ["#e2f0fe","#c7e2fe","#add5fe","#92c7fe","#6eb5ff","#48a2ff","#2690fe","#0162f4","#013add","#0021b0"], ["#d3fdff","#acfafd","#7cfaff","#4af7fe","#1de6fe","#01deff","#00cdec","#01b6de","#00a0c2","#0084a0"], ["#edffcf","#dffeaa","#d1fd88","#befa5a","#a8f32a","#8fd80a","#79c101","#3fa701","#307f00","#156200"], ["#d4c89f","#daad88","#c49578","#c2877e","#ac8295","#c0a5c4","#969ac2","#92b7d7","#80adaf","#9ca53b"] ], noendtags : ['br', 'hr', 'img', 'area', 'col', 'embed', 'input', 'param'], inlinetags : ['b', 'del', 'em', 'font', 'i', 'span', 'strike', 'strong', 'sub', 'sup', 'u'], endlinetags : [ 'br', 'hr', 'table', 'tbody', 'td', 'tr', 'th', 'div', 'p', 'ol', 'ul', 'li', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'script', 'style', 'marquee' ], htmltags : { font : ['color', 'size', 'face', '.background-color'], span : ['style'], div : ['class', 'align', 'style'], table: ['class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'style'], 'td,th': ['class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', 'style'], a : ['class', 'href', 'target', 'name', 'style'], embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', 'style', 'align', 'allowscriptaccess', '/'], img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', '/'], hr : ['class', '/'], br : ['/'], 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : ['align', 'style'], 'tbody,tr,strong,b,sub,sup,em,i,u,strike' : [] }, mediatypes : { rm : 'audio/x-pn-realaudio-plugin', flash : 'application/x-shockwave-flash', media : 'video/x-ms-asf-plugin' } }; ke.g = {}; ke.plugin = {}; ke.$ = function(id, doc){ var doc = doc || document; return doc.getelementbyid(id); }; ke.$$ = function(name, doc){ var doc = doc || document; return doc.createelement(name); }; ke.event = { add : function(el, event, listener) { if (el.addeventlistener){ el.addeventlistener(event, listener, false); } else if (el.attachevent){ el.attachevent('on' + event, listener); } }, remove : function(el, event, listener) { if (el.removeeventlistener){ el.removeeventlistener(event, listener, false); } else if (el.detachevent){ el.detachevent('on' + event, listener); } }, input : function(el, func) { this.add(el, 'keyup', function(e) { if (!e.ctrlkey && !e.altkey && (e.keycode < 16 || e.keycode > 18) && e.keycode != 116 && e.keycode < 136) { func(e); if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); return false; } }); function handler (e) { window.settimeout(function() { func(e); }, 1); } var newelement = (el.nodename == '#document') ? el.body : el; this.add(newelement, 'paste', handler); this.add(newelement, 'cut', handler); }, ctrl : function(el, key, func) { key = key.tostring().match(/^\d{2,}$/) ? key : key.touppercase().charcodeat(0); this.add(el, 'keydown', function(e) { if (e.ctrlkey && e.keycode == key && !e.shiftkey && !e.altkey) { func(e); if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); return false; } }); }, ready : function(func, win, doc) { var win = win || window; var doc = doc || document; var loaded = false; var readyfunc = function() { if (loaded) return; loaded = true; func(); }; if (doc.addeventlistener) { this.add(doc, "domcontentloaded", readyfunc); } else if (doc.attachevent){ this.add(doc, "readystatechange", function() { if (doc.readystate == "complete") readyfunc(); }); if ( doc.documentelement.doscroll && typeof win.frameelement === "undefined" ) { var iereadyfunc = function() { if (loaded) return; try { doc.documentelement.doscroll("left"); } catch(e) { window.settimeout(iereadyfunc, 0); return; } readyfunc(); }; iereadyfunc(); } } this.add(win, 'load', readyfunc); } }; ke.each = function(obj, func) { for (var key in obj) { if (obj.hasownproperty(key)) func(key, obj[key]); } }; ke.eachnode = function(node, func) { var walknodes = function(parent) { if (ke.util.getnodetype(parent) != 1) return true; var n = parent.firstchild; while (n) { var next = n.nextsibling; if (!func(n)) return false; if (!walknodes(n)) return false; n = next; } return true; }; walknodes(node); }; ke.selection = function(win, doc) { this.sel = null; this.range = null; this.kerange = null; this.iscontrol = false; this.init = function() { var sel = win.getselection ? win.getselection() : doc.selection; var range; try { if (sel.rangecount > 0) range = sel.getrangeat(0); else range = sel.createrange(); } catch(e) {} if (!range) range = ke.util.createrange(doc); this.sel = sel; this.range = range; var startnode, startpos, endnode, endpos; if (ke.browser.ie) { if (range.item) { this.iscontrol = true; var el = range.item(0); startnode = endnode = el; startpos = endpos = 0; } else { this.iscontrol = false; var getstartend = function(isstart) { var pointrange = range.duplicate(); pointrange.collapse(isstart); var parentnode = pointrange.parentelement(); var nodes = parentnode.childnodes; if (nodes.length == 0) return {node: parentnode, pos: 0}; var startnode; var endelement; var startpos = 0; var isend = false; var testrange = range.duplicate(); ke.util.movetoelementtext(testrange, parentnode); for (var i = 0, len = nodes.length; i < len; i++) { var node = nodes[i]; var cmp = testrange.compareendpoints('starttostart', pointrange); if (cmp > 0) { isend = true; } else if (cmp == 0) { if (node.nodetype == 1) { var kerange = new ke.range(doc); kerange.selecttextnode(node); return {node: kerange.startnode, pos: 0}; } else { return {node: node, pos: 0}; } } if (node.nodetype == 1) { var noderange = range.duplicate(); ke.util.movetoelementtext(noderange, node); testrange.setendpoint('starttoend', noderange); if (isend) startpos += noderange.text.length; else startpos = 0; } else if (node.nodetype == 3) { testrange.movestart('character', node.nodevalue.length); startpos += node.nodevalue.length; } if (!isend) startnode = node; } if (!isend && startnode.nodetype == 1) { var startnode = parentnode.lastchild; return {node: startnode, pos: startnode.nodetype == 1 ? 1 : startnode.nodevalue.length}; } testrange = range.duplicate(); ke.util.movetoelementtext(testrange, parentnode); testrange.setendpoint('starttoend', pointrange); startpos -= testrange.text.replace(/\r\n|\n|\r/g, '').length; return {node: startnode, pos: startpos}; }; var start = getstartend(true); var end = getstartend(false); startnode = start.node; startpos = start.pos; endnode = end.node; endpos = end.pos; } } else { startnode = range.startcontainer; startpos = range.startoffset; endnode = range.endcontainer; endpos = range.endoffset; if (startnode.nodetype == 1 && typeof startnode.childnodes[startpos] != 'undefined') { startnode = startnode.childnodes[startpos]; startpos = 0; } if (endnode.nodetype == 1) { endpos = endpos == 0 ? 1 : endpos; if (typeof endnode.childnodes[endpos - 1] != 'undefined') { endnode = endnode.childnodes[endpos - 1]; endpos = (endnode.nodetype == 1) ? 0 : endnode.nodevalue.length; } } this.iscontrol = (startnode.nodetype == 1 && startnode === endnode && range.startoffset + 1 == range.endoffset); if (startnode.nodetype == 1 && endnode.nodetype == 3 && endpos == 0 && endnode.previoussibling) { var node = endnode.previoussibling; while (node) { if (node === startnode) { endnode = startnode; break; } if (node.childnodes.length != 1) break; node = node.childnodes[0]; } } if (range.collapsed) { var kerange = new ke.range(doc); kerange.settextstart(startnode, startpos); endnode = kerange.startnode; endpos = kerange.startpos; } } var kerange = new ke.range(doc); kerange.settextstart(startnode, startpos); kerange.settextend(endnode, endpos); this.kerange = kerange; }; this.init(); this.addrange = function(kerange) { if (ke.browser.gecko && ke.browser.version < 3) return; this.kerange = kerange; if (ke.browser.ie) { var getendrange = function(isstart) { var range = ke.util.createrange(doc); var node = isstart ? kerange.startnode : kerange.endnode; if (node.nodetype == 1) { ke.util.movetoelementtext(range, node); range.collapse(isstart); } else if (node.nodetype == 3) { range = ke.util.getnodestartrange(doc, node); var pos = isstart ? kerange.startpos : kerange.endpos; range.movestart('character', pos); } return range; } if (!this.range.item) { var node = kerange.startnode; if (node == kerange.endnode && ke.util.getnodetype(node) == 1 && ke.util.getnodetextlength(node) == 0) { var temp = doc.createtextnode(" "); node.appendchild(temp); ke.util.movetoelementtext(this.range, node); this.range.collapse(false); this.range.select(); node.removechild(temp); } else { this.range.setendpoint('starttostart', getendrange(true)); this.range.setendpoint('endtostart', getendrange(false)); this.range.select(); } } } else { var getnodepos = function(node) { var pos = 0; while (node) { node = node.previoussibling; pos++; } return --pos; }; var range = new ke.range(doc); range.settextstart(kerange.startnode, kerange.startpos); range.settextend(kerange.endnode, kerange.endpos); if (ke.util.getnodetype(range.startnode) == 88) { this.range.setstart(range.startnode.parentnode, getnodepos(range.startnode)); } else { this.range.setstart(range.startnode, range.startpos); } if (ke.util.getnodetype(range.endnode) == 88) { this.range.setend(range.endnode.parentnode, getnodepos(range.endnode) + 1); } else { this.range.setend(range.endnode, range.endpos); } this.sel.removeallranges(); this.sel.addrange(this.range); } }; this.focus = function() { if (ke.browser.ie && this.range != null) this.range.select(); } }; ke.range = function(doc) { this.startnode = null; this.startpos = null; this.endnode = null; this.endpos = null; this.getparentelement = function() { var scanparent = function(node, func) { while (node && (!node.tagname || node.tagname.tolowercase() != 'body')) { node = node.parentnode; if (func(node)) return; } } var nodelist = []; scanparent(this.startnode, function(node) { nodelist.push(node); }); var parentnode; scanparent(this.endnode, function(node) { if (ke.util.inarray(node, nodelist)) { parentnode = node; return true; } }); return parentnode ? parentnode : doc.body; }; this.getnodelist = function() { var self = this; var parentnode = this.getparentelement(); var nodelist = []; var isstarted = false; if (parentnode == self.startnode) isstarted = true; if (isstarted) nodelist.push(parentnode); ke.eachnode(parentnode, function(node) { if (node == self.startnode) isstarted = true; var range = new ke.range(doc); range.selecttextnode(node); if (range.comparepoints('start_to_end', self) >= 0) return false; if (isstarted) nodelist.push(node); return true; }); return nodelist; }; this.comparepoints = function(how, range) { var comparenodes = function(nodea, posa, nodeb, posb) { var cmp; if (ke.browser.ie) { var getstartrange = function(node, pos, isstart) { var range = ke.util.createrange(doc); var type = ke.util.getnodetype(node); if (type == 1) { ke.util.movetoelementtext(range, node); range.collapse(isstart); } else if (type == 3) { range = ke.util.getnodestartrange(doc, node); range.movestart('character', pos); range.collapse(true); } return range; } var rangea, rangeb; if (how == 'start_to_start' || how == 'start_to_end') rangea = getstartrange(nodea, posa, true); else rangea = getstartrange(nodea, posa, false); if (how == 'start_to_start' || how == 'end_to_start') rangeb = getstartrange(nodeb, posb, true); else rangeb = getstartrange(nodeb, posb, false); return rangea.compareendpoints('starttostart', rangeb); } else { var rangea = ke.util.createrange(doc); rangea.selectnode(nodea); if (how == 'start_to_start' || how == 'start_to_end') rangea.collapse(true); else rangea.collapse(false); var rangeb = ke.util.createrange(doc); rangeb.selectnode(nodeb); if (how == 'start_to_start' || how == 'end_to_start') rangeb.collapse(true); else rangeb.collapse(false); if (rangea.compareboundarypoints(range.start_to_start, rangeb) > 0) { cmp = 1; } else if (rangea.compareboundarypoints(range.start_to_start, rangeb) == 0) { if (posa > posb) cmp = 1; else if (posa == posb) cmp = 0; else cmp = -1; } else { cmp = -1; } } return cmp; } if (how == 'start_to_start') return comparenodes(this.startnode, this.startpos, range.startnode, range.startpos); if (how == 'start_to_end') return comparenodes(this.startnode, this.startpos, range.endnode, range.endpos); if (how == 'end_to_start') return comparenodes(this.endnode, this.endpos, range.startnode, range.startpos); if (how == 'end_to_end') return comparenodes(this.endnode, this.endpos, range.endnode, range.endpos); }; this.settextstart = function(node, pos) { var textnode = node; ke.eachnode(node, function(n) { if (ke.util.getnodetype(n) == 3 && n.nodevalue.length > 0 || ke.util.getnodetype(n) == 88) { textnode = n; pos = 0; return false; } return true; }); this.setstart(textnode, pos); }; this.setstart = function(node, pos) { this.startnode = node; this.startpos = pos; if (this.endnode === null) { this.endnode = node; this.endpos = pos; } }; this.settextend = function(node, pos) { var textnode = node; ke.eachnode(node, function(n) { if (ke.util.getnodetype(n) == 3 && n.nodevalue.length > 0 || ke.util.getnodetype(n) == 88) { textnode = n; pos = ke.util.getnodetype(n) == 3 ? n.nodevalue.length : 0; } return true; }); this.setend(textnode, pos); }; this.setend = function(node, pos) { this.endnode = node; this.endpos = pos; if (this.startnode === null) { this.startnode = node; this.startpos = pos; } }; this.selectnode = function(node) { this.setstart(node, 0); this.setend(node, node.nodetype == 1 ? 0 : node.nodevalue.length); }; this.selecttextnode = function(node) { this.settextstart(node, 0); this.settextend(node, node.nodetype == 1 ? 0 : node.nodevalue.length); }; this.extractcontents = function(isdelete) { isdelete = (isdelete === false) ? false : true; var thisrange = this; var startnode = this.startnode; var startpos = this.startpos; var endnode = this.endnode; var endpos = this.endpos; var extracttextnode = function(node, startpos, endpos) { var length = node.nodevalue.length; var clonenode = node.clonenode(true); var centernode = clonenode.splittext(startpos); centernode.splittext(endpos - startpos); if (isdelete) { var center = node; if (startpos > 0) center = node.splittext(startpos); if (endpos < length) center.splittext(endpos - startpos); center.parentnode.removechild(center); } return centernode; }; var isstarted = false; var isend = false; var extractnodes = function(parent, frag) { if (ke.util.getnodetype(parent) != 1) return true; var node = parent.firstchild; while (node) { if (node == startnode) isstarted = true; if (node == endnode) isend = true; var nextnode = node.nextsibling; var type = node.nodetype; if (type == 1) { var range = new ke.range(doc); range.selectnode(node); if (isstarted && range.comparepoints('end_to_end', thisrange) < 0) { var clonenode = node.clonenode(true); frag.appendchild(clonenode); if (isdelete) { node.parentnode.removechild(node); } } else { var childflag = node.clonenode(false); frag.appendchild(childflag); if (!extractnodes(node, childflag)) return false; } } else if (type == 3) { if (isstarted) { var textnode; if (node == startnode && node == endnode) { textnode = extracttextnode(node, startpos, endpos); frag.appendchild(textnode); return false; } else if (node == startnode) { textnode = extracttextnode(node, startpos, node.nodevalue.length); frag.appendchild(textnode); } else if (node == endnode) { textnode = extracttextnode(node, 0, endpos); frag.appendchild(textnode); return false; } else { textnode = extracttextnode(node, 0, node.nodevalue.length); frag.appendchild(textnode); } } } node = nextnode; if (isend) return false; } return true; } var parentnode = this.getparentelement(); var docfrag = parentnode.clonenode(false); extractnodes(parentnode, docfrag); return docfrag; }; this.clonecontents = function() { return this.extractcontents(false); }; this.gettext = function() { var html = this.clonecontents().innerhtml; return html.replace(/<.*?>/g, ""); }; }; ke.cmd = function(id) { this.doc = ke.g[id].iframedoc; this.kesel = ke.g[id].kesel; this.kerange = ke.g[id].kerange; this.mergeattributes = function(el, attr) { for (var i = 0, len = attr.length; i < len; i++) { ke.each(attr[i], function(key, value) { if (key.charat(0) == '.') { var jskey = ke.util.getjskey(key.substr(1)); eval('el.style.' + jskey + ' = value;'); } else { el.setattribute(key, value); } }); } return el; }; this.wraptextnode = function(node, startpos, endpos, element, attributes) { var length = node.nodevalue.length; var isfull = (startpos == 0 && endpos == length); var range = new ke.range(this.doc); range.selecttextnode(node.parentnode); if (isfull && node.parentnode.tagname == element.tagname && range.comparepoints('end_to_end', this.kerange) <= 0 && range.comparepoints('start_to_start', this.kerange) >= 0) { this.mergeattributes(node.parentnode, attributes); return node; } else { var el = element.clonenode(true); if (isfull) { var clonenode = node.clonenode(true); el.appendchild(clonenode); node.parentnode.replacechild(el, node); return clonenode; } else { var centernode = node; if (startpos < endpos) { if (startpos > 0) centernode = node.splittext(startpos); if (endpos < length) centernode.splittext(endpos - startpos); var clonenode = centernode.clonenode(true); el.appendchild(clonenode); centernode.parentnode.replacechild(el, centernode); return clonenode; } else { if (startpos < length) { centernode = node.splittext(startpos); centernode.parentnode.insertbefore(el, centernode); } else { if (centernode.nextsibling) { centernode.parentnode.insertbefore(el, centernode.nextsibling); } else { centernode.parentnode.appendchild(el); } } return el; } } } }; this.wrap = function(tagname, attributes) { var self = this; this.kesel.focus(); var element = ke.$$(tagname, this.doc); this.mergeattributes(element, attributes); var kerange = this.kerange; var startnode = kerange.startnode; var startpos = kerange.startpos; var endnode = kerange.endnode; var endpos = kerange.endpos; var parentnode = kerange.getparentelement(); if (ke.util.inmarquee(parentnode)) return; var isstarted = false; ke.eachnode(parentnode, function(node) { if (node == startnode) isstarted = true; if (node.nodetype == 1) { if (node == startnode && node == endnode) { if (ke.util.inarray(node.tagname.tolowercase(), ke.g[id].noendtags)) { if (startpos > 0) node.parentnode.appendchild(element); else node.parentnode.insertbefore(element, node); } else { node.appendchild(element); } kerange.selectnode(element); return false; } else if (node == startnode) { kerange.setstart(node, 0); } else if (node == endnode) { kerange.setend(node, 0); return false; } } else if (node.nodetype == 3) { if (isstarted) { if (node == startnode && node == endnode) { var rangenode = self.wraptextnode(node, startpos, endpos, element, attributes); kerange.selectnode(rangenode); return false; } else if (node == startnode) { var rangenode = self.wraptextnode(node, startpos, node.nodevalue.length, element, attributes); kerange.setstart(rangenode, 0); } else if (node == endnode) { var rangenode = self.wraptextnode(node, 0, endpos, element, attributes); kerange.setend(rangenode, rangenode.nodetype == 1 ? 0 : rangenode.nodevalue.length); return false; } else { self.wraptextnode(node, 0, node.nodevalue.length, element, attributes); } } } return true; }); this.kesel.addrange(kerange); }; this.gettopparent = function(tagnames, node) { var parent = null; while (node) { node = node.parentnode; if (ke.util.inarray(node.tagname.tolowercase(), tagnames)) { parent = node; } else { break; } } return parent; }; this.splitnodeparent = function(parent, node, pos) { var leftrange = new ke.range(this.doc); leftrange.selectnode(parent.firstchild); leftrange.setend(node, pos); var leftfrag = leftrange.extractcontents(); parent.parentnode.insertbefore(leftfrag, parent); return {left : leftfrag, right : parent}; }; this.remove = function(tags) { var kerange = this.kerange; var startnode = kerange.startnode; var startpos = kerange.startpos; var endnode = kerange.endnode; var endpos = kerange.endpos; this.kesel.focus(); if (ke.util.inmarquee(kerange.getparentelement())) return; if (kerange.gettext().replace(/\s+/g, '') === '') return; var tagnames = []; ke.each(tags, function(key, val) { if (key != '*') tagnames.push(key); }); var startparent = this.gettopparent(tagnames, startnode); var endparent = this.gettopparent(tagnames, endnode); if (startparent) { var startfrags = this.splitnodeparent(startparent, startnode, startpos); kerange.setstart(startfrags.right, 0); if (startnode == endnode && ke.util.getnodetextlength(startfrags.right) > 0) { kerange.selectnode(startfrags.right); var range = new ke.range(this.doc); range.selecttextnode(startfrags.left); if (startpos > 0) endpos -= range.endnode.nodevalue.length; range.selecttextnode(startfrags.right); endnode = range.startnode; } } if (endparent) { var endfrags = this.splitnodeparent(endparent, endnode, endpos); this.kerange.setend(endfrags.left, 0); if (startparent == endparent) { kerange.setstart(endfrags.left, 0); } } var removeattr = function(node, attr) { if (attr.charat(0) == '.') { var jskey = ke.util.getjskey(attr.substr(1)); eval('node.style.' + jskey + ' = "";'); } else { node.removeattribute(attr); } }; var nodelist = kerange.getnodelist(); kerange.settextstart(kerange.startnode, kerange.startpos); kerange.settextend(kerange.endnode, kerange.endpos); for (var i = 0, length = nodelist.length; i < length; i++) { var node = nodelist[i]; if (node.nodetype == 1) { var tagname = node.tagname.tolowercase(); if (tags[tagname]) { var attr = tags[tagname]; for (var j = 0, len = attr.length; j < len; j++) { if (attr[j] == '*') { ke.util.removeparent(node); break; } else { removeattr(node, attr[j]); if (node.attributes.length == 0) { ke.util.removeparent(node); break; } else if (node.attributes[0].name == 'style' && node.attributes[0].value === '') { ke.util.removeparent(node); break; } } } } if (tags['*']) { var attr = tags['*']; for (var j = 0, len = attr.length; j < len; j++) { removeattr(node, attr[j]); } } } } try { this.kesel.addrange(kerange); } catch(e) {} }; }; ke.format = { geturl : function(url, mode, host, pathname) { if (!mode) return url; mode = mode.tolowercase(); if (!ke.util.inarray(mode, ['absolute', 'relative', 'domain'])) return url; host = host || location.protocol + '//' + location.host; pathname = pathname || (location.pathname.match(/^(\/.*)\//) ? regexp.$1 : ''); if (url.match(/^(\w+:\/\/[^\/]*)/)) { if (regexp.$1 !== host) return url; } else if (url.match(/^\w+:/)) { return url; } var getrealpath = function(path) { var parts = path.split('/'); paths = []; for (var i = 0, len = parts.length; i < len; i++) { var part = parts[i]; if (part == '..') { if (paths.length > 0) paths.pop(); } else if (part !== '' && part != '.') { paths.push(part); } } return '/' + paths.join('/'); }; if (url.match(/^\//)) { url = host + getrealpath(url.substr(1)); } else if (!url.match(/^\w+:\/\//)) { url = host + getrealpath(pathname + '/' + url); } if (mode == 'relative') { var getrelativepath = function(path, depth) { if (url.substr(0, path.length) === path) { var arr = []; for (var i = 0; i < depth; i++) { arr.push('..'); } var prefix = '.'; if (arr.length > 0) prefix += '/' + arr.join('/'); if (pathname == '/') prefix += '/'; return prefix + url.substr(path.length); } else { if (path.match(/^(.*)\//)) { return getrelativepath(regexp.$1, ++depth); } } }; url = getrelativepath(host + pathname, 0).substr(2); } else if (mode == 'absolute') { if (url.substr(0, host.length) === host) { url = url.substr(host.length); } } return url; }, gethtml : function(html, htmltags, urltype) { var isfilter = htmltags ? true : false; var htmltaghash = {}; 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 (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.tolowercase()); 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; } }); html = html.replace(/\n<\/p>/, '

'); var reg = ke.setting.inlinetags.join('|'); var trimhtml = function(inhtml) { var outhtml = inhtml.replace(new regexp('<(' + reg + ')[^>]*><\\/(' + reg + ')>', 'ig'), function($0, $1, $2) { if ($1 == $2) return ''; else return $0; }); if (inhtml !== outhtml) outhtml = trimhtml(outhtml); return outhtml; }; return ke.util.trim(trimhtml(html)); } }; ke.util = { getdocumentelement : function(doc) { doc = doc || document; return (doc.compatmode != "css1compat") ? doc.body : doc.documentelement; }, getdocumentheight : function(doc) { var el = this.getdocumentelement(doc); return math.max(el.scrollheight, el.clientheight); }, getdocumentwidth : function(doc) { var el = this.getdocumentelement(doc); return math.max(el.scrollwidth, el.clientwidth); }, createtable : function(doc) { var table = ke.$$('table', doc); table.cellpadding = 0; table.cellspacing = 0; table.border = 0; return {table: table, cell: table.insertrow(0).insertcell(0)}; }, loadstyle : function(path) { var link = ke.$$('link'); link.setattribute('type', 'text/css'); link.setattribute('rel', 'stylesheet'); link.setattribute('href', path); document.getelementsbytagname("head")[0].appendchild(link); }, getattrlist : function(tag) { var re = /\s+(?:([\w-:]+)|(?:([\w-:]+)=([\w-:]+))|(?:([\w-:]+)="([^"]*)")|(?:([\w-:]+)='([^']*)'))(?=(?:\s|\/|>)+)/g; var arr, key, val, list = {}; while ((arr = re.exec(tag))) { key = arr[1] || arr[2] || arr[4] || arr[6]; val = arr[1] || (arr[2] ? arr[3] : (arr[4] ? arr[5] : arr[7])); list[key] = val; } return list; }, inarray : function(str, arr) { for (var i = 0; i < arr.length; i++) {if (str == arr[i]) return true;} return false; }, trim : function(str) { return str.replace(/^\s+|\s+$/g, ""); }, getjskey : function(key) { var arr = key.split('-'); key = ''; for (var i = 0, len = arr.length; i < len; i++) { key += (i > 0) ? arr[i].charat(0).touppercase() + arr[i].substr(1) : arr[i]; } return key; }, arraytohash : function(arr) { var hash = {}; for (var i = 0, len = arr.length; i < len; i++) hash[arr[i]] = 1; return hash; }, escape : function(str) { str = str.replace(/&/g, '&'); str = str.replace(//g, '>'); str = str.replace(/"/g, '"'); return str; }, unescape : function(str) { str = str.replace(/</g, '<'); str = str.replace(/>/g, '>'); str = str.replace(/"/g, '"'); str = str.replace(/&/g, '&'); return str; }, getscrollpos : function() { var x, y; if (ke.browser.ie || ke.browser.opera) { var el = this.getdocumentelement(); x = el.scrollleft; y = el.scrolltop; } else { x = window.scrollx; y = window.scrolly; } return {x : x, y : y}; }, getelementpos : function(el) { var x = 0, y = 0; if (el.getboundingclientrect) { var box = el.getboundingclientrect(); var el = this.getdocumentelement(); var pos = this.getscrollpos(); x = box.left + pos.x - el.clientleft; y = box.top + pos.y - el.clienttop; } else { x = el.offsetleft; y = el.offsettop; var parent = el.offsetparent; while (parent) { x += parent.offsetleft; y += parent.offsettop; parent = parent.offsetparent; } } return {x : x, y : y}; }, getcoords : function(ev) { ev = ev || window.event; return { x : ev.clientx, y : ev.clienty }; }, setopacity : function(el, opacity) { if (typeof el.style.opacity == "undefined") { el.style.filter = (opacity == 100) ? "" : "alpha(opacity=" + opacity + ")"; } else { el.style.opacity = (opacity == 100) ? "" : "0." + opacity.tostring(); } }, getiframedoc : function(iframe) { return iframe.contentdocument || iframe.contentwindow.document; }, rgbtohex : function(str) { function hex(s) { s = parseint(s).tostring(16); return s.length > 1 ? s : '0' + s; }; return str.replace(/rgb\s*?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?\)/ig, function($0, $1, $2, $3) { return '#' + hex($1) + hex($2) + hex($3); } ); }, parsejson : function (text) { var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; cx.lastindex = 0; if (cx.test(text)) { text = text.replace(cx, function (a) { return '\\u' + ('0000' + a.charcodeat(0).tostring(16)).slice(-4); }); } if (/^[\],:{}\s]*$/. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fa-f]{4})/g, '@'). replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/g, ']'). replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { return eval('(' + text + ')'); } throw 'json parse error'; }, createrange : function(doc) { return doc.createrange ? doc.createrange() : doc.body.createtextrange(); }, getnodetype : function(node) { return (node.nodetype == 1 && ke.util.inarray(node.tagname.tolowercase(), ke.setting.noendtags)) ? 88 : node.nodetype; }, inmarquee : function(node) { var n = node; while (n) { if (n.nodename.tolowercase() === 'marquee') return true; n = n.parentnode; } return false; }, movetoelementtext : function (range, el) { if (!this.inmarquee(el)) range.movetoelementtext(el); }, getnodetextlength : function(node) { var type = ke.util.getnodetype(node); if (type == 1) { var html = node.innerhtml; return html.replace(/<.*?>/ig, "").length; } else if (type == 3) { return node.nodevalue.length; } }, getnodestartrange : function(doc, node) { var range = ke.util.createrange(doc); var type = node.nodetype; if (type == 1) { ke.util.movetoelementtext(range, node); return range; } else if (type == 3) { var offset = 0; var sibling = node.previoussibling; while (sibling) { if (sibling.nodetype == 1) { var noderange = ke.util.createrange(doc); ke.util.movetoelementtext(noderange, sibling); range.setendpoint('starttoend', noderange); range.movestart('character', offset); return range; } else if (sibling.nodetype == 3) { offset += sibling.nodevalue.length; } sibling = sibling.previoussibling; } ke.util.movetoelementtext(range, node.parentnode); range.movestart('character', offset); return range; } }, removeparent : function(parent) { if (parent.haschildnodes) { var node = parent.firstchild; while (node) { var nextnode = node.nextsibling; parent.parentnode.insertbefore(node, parent); node = nextnode; } } parent.parentnode.removechild(parent); }, drag : function(id, mousedownobj, moveobj, func) { var g = ke.g[id]; mousedownobj.onmousedown = function(e) { e = e || window.event; if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); var pos = ke.util.getcoords(e); var objtop = parseint(moveobj.style.top); var objleft = parseint(moveobj.style.left); var objwidth = moveobj.style.width; var objheight = moveobj.style.height; if (objwidth.match(/%$/)) objwidth = moveobj.offsetwidth + 'px'; if (objheight.match(/%$/)) objheight = moveobj.offsetheight + 'px'; objwidth = parseint(objwidth); objheight = parseint(objheight); var mousetop = pos.y; var mouseleft = pos.x; var scrollpos = ke.util.getscrollpos(); var scrolltop = scrollpos.y; var scrollleft = scrollpos.x; var dragflag = true; var movelistener = function(e) { if (dragflag) { var pos = ke.util.getcoords(e); var scrollpos = ke.util.getscrollpos(); var top = parseint(pos.y - mousetop - scrolltop + scrollpos.y); var left = parseint(pos.x - mouseleft - scrollleft + scrollpos.x); func(objtop, objleft, objwidth, objheight, top, left); } }; var iframepos = ke.util.getelementpos(g.iframe); var iframemovelistener = function(e) { if (dragflag) { var pos = ke.util.getcoords(e, g.iframedoc); var top = parseint(iframepos.y + pos.y - mousetop - scrolltop); var left = parseint(iframepos.x + pos.x - mouseleft - scrollleft); func(objtop, objleft, objwidth, objheight, top, left); } }; var selectlistener = function() { return false; }; var uplistener = function() { dragflag = false; ke.event.remove(document, 'mousemove', movelistener); ke.event.remove(document, 'mouseup', uplistener); ke.event.remove(g.iframedoc, 'mousemove', iframemovelistener); ke.event.remove(g.iframedoc, 'mouseup', uplistener); ke.event.remove(document, 'selectstart', selectlistener); }; ke.event.add(document, 'mousemove', movelistener); ke.event.add(document, 'mouseup', uplistener); ke.event.add(g.iframedoc, 'mousemove', iframemovelistener); ke.event.add(g.iframedoc, 'mouseup', uplistener); ke.event.add(document, 'selectstart', selectlistener); }; }, resize : function(id, width, height, ischeck, isresizewidth) { isresizewidth = (typeof isresizewidth == "undefined") ? true : isresizewidth; var g = ke.g[id]; if (!g.container) return; if (ischeck && (parseint(width) <= g.minwidth || parseint(height) <= g.minheight)) return; if (isresizewidth) g.container.style.width = width; g.container.style.height = height; if (!g.toolbartable.offsetheight) { window.settimeout(function () { ke.util.resize(id, width, height, ischeck, isresizewidth); }, 0); return; } var diff = parseint(height) - g.toolbartable.offsetheight - g.bottom.offsetheight; if (diff >= 0) { g.iframe.style.height = diff + 'px'; g.newtextarea.style.height = (((ke.browser.ie && ke.browser.version < 8) || document.compatmode != 'css1compat') ? diff - 2 : diff) + 'px'; } }, hideloadingpage : function(id) { var stack = ke.g[id].dialogstack; var dialog = stack[stack.length - 1]; dialog.loading.style.display = 'none'; dialog.iframe.style.display = ''; }, showloadingpage : function(id) { var stack = ke.g[id].dialogstack; var dialog = stack[stack.length - 1]; dialog.loading.style.display = ''; dialog.iframe.style.display = 'none'; }, setdefaultplugin : function(id) { var items = [ 'selectall', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'bold', 'italic', 'underline', 'strikethrough' ]; for (var i = 0; i < items.length; i++) { ke.plugin[items[i]] = { click : (function(i) { return function(id) { ke.util.execcommand(id, items[i], null); }; })(i) }; } }, getfullhtml : function(id) { var html = ''; html += ''; html += ''; html += 'kindeditor'; html += ''; var csspath = ke.g[id].csspath; if (typeof csspath == 'string') csspath = [csspath]; for (var i = 0, len = csspath.length; i < len; i++) { if (csspath[i] !== '') html += ''; } html += ''; html += ''; html += ''; return html; }, getmediatype : function(src) { if (src.match(/\.(rm|rmvb)(\?|$)/i)) return 'rm'; else if (src.match(/\.(swf|flv)(\?|$)/i)) return 'flash'; else return 'media'; }, getmediaimage : function(id, type, attrs) { var width = attrs.width; var height = attrs.height; type = type || this.getmediatype(attrs.src); var srctag = this.getmediaembed(attrs); var style = ''; if (width > 0) style += 'width:' + width + 'px;'; if (height > 0) style += 'height:' + height + 'px;'; var classname = 'ke-' + type; var html = ''; return html; }, getmediaembed : function(attrs) { var html = ']*>\s*$/ig, ''); html = html.replace(/^\s*

\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); } }, getsrcdata : function(id) { var g = ke.g[id]; if (!g.wyswygmode) { this.innerhtml(g.iframedoc.body, ke.util.execsethtmlhooks(id, g.newtextarea.value)); } return this.execgethtmlhooks(id, 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) { if (ke.g[id].srctextarea) ke.g[id].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.layout.hide(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.iframewin, 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.history.add(id, false); 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; 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.history.add(id, false); ke.util.execonchangehandler(id); }, setfullhtml : function(id, html) { if (!ke.browser.ie && html === '') html = '
'; var html = ke.util.execsethtmlhooks(id, html); this.innerhtml(ke.g[id].iframedoc.body, html); ke.g[id].newtextarea.value = ke.util.getdata(id, true); ke.history.add(id, false); 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, '    '); if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); return false; } }); }, addcontextmenuevent : function(id) { var g = ke.g[id]; if (g.contextmenuitems.length == 0) return; ke.event.add(g.iframedoc, 'contextmenu', function(e){ ke.util.setselection(id); ke.util.selectimagewebkit(id, e, false); var showflag = false; for (var i = 0, len = g.contextmenuitems.length; i < len; i++) { var item = g.contextmenuitems[i]; if (item.cond(id)) { showflag = true; break; } } if (showflag) { var menu = new ke.menu({ id : id, event : e, type : 'contextmenu', width : 120 }); for (var i = 0, len = g.contextmenuitems.length; i < len; i++) { var item = g.contextmenuitems[i]; if (item.cond(id)) { menu.add(item.text, (function(item) { return function() { item.click(id, menu); }; })(item)); } } menu.show(); if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); return false; } return true; }); }, 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); } } } if (e.preventdefault) e.preventdefault(); if (e.stoppropagation) e.stoppropagation(); 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; }); } }; ke.layout = { hide : function(id) { var g = ke.g[id]; g.dialogstack = []; g.hidediv.innerhtml = ''; g.hidediv.style.display = 'none'; g.maskdiv.style.display = 'none'; } }; ke.menu = function(arg){ this.getpos = function(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}; }; this.init = function() { 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 = this.getpos(0, 0); div.style.top = pos.y + 'px'; div.style.left = pos.x + 'px'; if (arg.width) div.style.width = arg.width + 'px'; this.div = div; }; this.init(); this.add = function(html, event) { var self = this; var cdiv = ke.$$('div'); cdiv.classname = 'ke-' + this.type + '-noselected'; cdiv.onmouseover = function() { this.classname = 'ke-' + self.type + '-selected'; } cdiv.onmouseout = function() { this.classname = 'ke-' + self.type + '-noselected'; } cdiv.onclick = event; ke.util.innerhtml(cdiv, html); this.append(cdiv); }; this.append = function(el) { this.div.appendchild(el); }; this.insert = function(html) { ke.util.innerhtml(this.div, html); }; this.hide = function() { ke.layout.hide(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 = this.getpos(this.div.clientwidth, this.div.clientheight); this.div.style.top = pos.y + 'px'; this.div.style.left = pos.x + 'px'; }; this.picker = function() { var colortable = ke.g[arg.id].colortable; var table = ke.$$('table'); table.classname = 'ke-picker-table'; table.cellpadding = 0; table.cellspacing = 0; table.border = 0; var row = table.insertrow(0); var cell = row.insertcell(0); cell.colspan = colortable[0].length; cell.classname = 'ke-picker-td-top'; cell.title = ke.lang['nocolor']; cell.onmouseover = function() {this.style.bordercolor = '#000000'; }; cell.onmouseout = function() {this.style.bordercolor = '#f0f0ee'; }; cell.onclick = function() { ke.plugin[arg.cmd].exec(arg.id, ''); }; cell.innerhtml = ke.lang['nocolor']; for (var i = 0; i < colortable.length; i++) { var row = table.insertrow(i + 1); for (var j = 0; j < colortable[i].length; j++) { var cell = row.insertcell(j); cell.classname = 'ke-picker-td'; cell.style.backgroundcolor = colortable[i][j]; cell.title = colortable[i][j]; cell.onmouseover = function() {this.style.bordercolor = '#000000'; }; cell.onmouseout = function() {this.style.bordercolor = '#f0f0ee'; }; cell.onclick = (function(i, j) { return function() { ke.plugin[arg.cmd].exec(arg.id, colortable[i][j]); }; })(i, j); cell.innerhtml = ' '; } } this.append(table); this.show(); }; }; ke.dialog = function(arg){ this.widthmargin = 20; this.heightmargin = 90; this.zindex = 19811214; var mintop, minleft, maxtop, maxleft; var setlimitnumber = function() { var width = arg.width + this.widthmargin; var height = arg.height + this.heightmargin; var docel = ke.util.getdocumentelement(); var pos = ke.util.getscrollpos(); mintop = pos.y; minleft = pos.x; maxtop = pos.y + docel.clientheight - height - 2; maxleft = pos.x + docel.clientwidth - width - 2; }; this.getpos = function() { var width = arg.width + this.widthmargin; var height = arg.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.hide = function() { if (arg.beforehide) arg.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); ke.g[id].hidediv.removechild(this.div); if (stack.length < 1) { ke.g[id].hidediv.style.display = 'none'; ke.g[id].maskdiv.style.display = 'none'; } ke.event.remove(window, 'resize', setlimitnumber); ke.event.remove(window, 'scroll', setlimitnumber); if (arg.afterhide) arg.afterhide(id); ke.util.focus(id); }; this.show = function() { if (arg.beforeshow) arg.beforeshow(id); var width = arg.width + this.widthmargin; var height = arg.height + this.heightmargin; var self = this; var id = arg.id; var div = ke.$$('div'); div.classname = 'ke-dialog'; 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 = this.getpos(); div.style.width = width + 'px'; div.style.height = height + 'px'; div.style.top = pos.y + 'px'; div.style.left = pos.x + 'px'; var titlediv = ke.$$('div'); titlediv.classname = 'ke-dialog-title'; titlediv.innerhtml = arg.title; var span = ke.$$('span'); span.classname = "ke-toolbar-close"; span.alt = ke.lang['close']; span.title = ke.lang['close']; span.onclick = function () { self.hide(); }; 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) { top = objtop + top; left = objleft + left; if (top > maxtop) top = maxtop; if (left > maxleft) left = maxleft; if (top < mintop) top = mintop; if (left < minleft) left = minleft; div.style.top = top + 'px'; div.style.left = left + 'px'; }); div.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 = arg.width + 'px'; loadingtable.table.style.height = arg.height + 'px'; loadingtable.cell.align = 'center'; loadingtable.cell.valign = 'middle'; 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'; } iframe.width = arg.width + 'px'; iframe.height = arg.height + 'px'; iframe.setattribute("frameborder", "0"); iframe.style.display = 'none'; bodydiv.appendchild(iframe); bodydiv.appendchild(loadingtable.table); div.appendchild(bodydiv); var bottomdiv = ke.$$('div'); bottomdiv.classname = 'ke-dialog-bottom'; var nobutton = null; var yesbutton = null; var previewbutton = null; 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) { 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.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 || arg.nobutton || arg.previewbutton) { div.appendchild(bottomdiv); } ke.g[id].hidediv.style.display = ''; ke.g[id].hidediv.appendchild(div); window.focus(); if (yesbutton) yesbutton.focus(); else if (nobutton) nobutton.focus(); if (typeof 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 (typeof arg.file == "undefined") { iframe.src = ke.g[id].pluginspath + arg.cmd + '.html?ver=' + ke.version; } else { iframe.src = ke.g[id].pluginspath + arg.file; } } 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 (arg.aftershow) arg.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-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-on"; }; a.onmouseout = function(){ this.classname = "ke-icon"; }; } }, able : 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.util.setopacity(span, 100); a.onclick = (function(cmd) { return function() { ke.util.click(id, cmd); return false; }; })(cmd); a.onmouseover = function(){ this.classname = "ke-icon-on"; }; a.onmouseout = function(){ this.classname = "ke-icon"; }; } }); }, 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-disabled'; ke.util.setopacity(span, 50); a.onclick = null; a.onmouseover = null; a.onmouseout = null; } }); }, create : function(id) { 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; 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 == '-') 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'); a.classname = 'ke-icon'; a.href = 'javascript:;'; a.onclick = (function(cmd) { return function() { var div = ke.g[id].hidediv.firstchild; if (div && div.getattribute('name') == cmd) { ke.layout.hide(id); } else { ke.util.click(id, cmd); } return false; }; })(cmd); a.onmouseover = function(){ this.classname = 'ke-icon-on'; }; a.onmouseout = function(){ this.classname = 'ke-icon'; }; a.hidefocus = true; a.title = ke.lang[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 = { add : function(id, minchangeflag) { var g = ke.g[id]; var html = ke.util.getdata(id); if (g.undostack.length > 0) { var prevhtml = g.undostack[g.undostack.length - 1]; if (html === prevhtml) return; if (minchangeflag && math.abs(html.length - prevhtml.length) < g.minchangesize) return; } g.undostack.push(html); g.redostack = []; }, undo : function(id) { var g = ke.g[id]; if (g.undostack.length == 0) return; var html = ke.util.getdata(id); g.redostack.push(html); var prevhtml = g.undostack.pop(); if (html === prevhtml && g.undostack.length > 0) { prevhtml = g.undostack.pop(); } ke.util.innerhtml(g.iframedoc.body, ke.util.execsethtmlhooks(id, prevhtml)); g.newtextarea.value = ke.util.execgethtmlhooks(id, prevhtml); }, redo : function(id) { var g = ke.g[id]; if (g.redostack.length == 0) return; var html = ke.util.getdata(id); g.undostack.push(html); var nexthtml = g.redostack.pop(); ke.util.innerhtml(g.iframedoc.body, ke.util.execsethtmlhooks(id, nexthtml)); g.newtextarea.value = ke.util.execgethtmlhooks(id, nexthtml); } }; ke.readonly = function(id, isreadonly) { isreadonly = typeof isreadonly == 'undefined' ? true : false; var g = ke.g[id]; if (ke.browser.ie && ke.browser.version > 6) g.iframedoc.body.contenteditable = isreadonly ? 'false' : 'true'; else g.iframedoc.designmode = isreadonly ? 'off' : 'on'; }; ke.remove = function(id, mode) { if (!ke.g[id].container) return false; mode = (typeof mode == "undefined") ? 0 : mode; var container = ke.g[id].container; ke.g[id].iframedoc.src = 'javascript:false'; ke.g[id].iframe.parentnode.removechild(ke.g[id].iframe); if (mode == 1) { document.body.removechild(container); } else { var srctextarea = ke.g[id].srctextarea; srctextarea.parentnode.removechild(container); if (mode == 0) srctextarea.style.display = ''; } document.body.removechild(ke.g[id].hidediv); document.body.removechild(ke.g[id].maskdiv); ke.g[id].container = null; ke.g[id].dialogstack = []; ke.g[id].contextmenuitems = []; ke.g[id].gethtmlhooks = []; ke.g[id].sethtmlhooks = []; ke.g[id].onchangehandlerstack = []; }; 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); toolbarouter.appendchild(toolbartable); var iframe = ke.g[id].iframe || ke.$$('iframe'); iframe.classname = 'ke-iframe'; iframe.setattribute("frameborder", "0"); iframe.style.height = 0; var newtextarea = ke.$$('textarea'); newtextarea.classname = 'ke-textarea'; newtextarea.style.display = 'none'; newtextarea.style.height = 0; textareacell.appendchild(iframe); textareacell.appendchild(newtextarea); var bottom = ke.$$('table'); bottom.classname = 'ke-bottom'; bottom.cellpadding = 0; bottom.cellspacing = 0; bottom.border = 0; var row = bottom.insertrow(0); var bottomleft = row.insertcell(0); bottomleft.classname = 'ke-bottom-left'; if (ke.g[id].config.resizemode == 0 || mode == 1) { bottomleft.style.cursor = 'default'; } var bottomright = row.insertcell(1); bottomright.classname = 'ke-bottom-right'; if (ke.g[id].config.resizemode == 0 || mode == 1) { bottomright.style.cursor = 'default'; } else if (ke.g[id].config.resizemode == 1) { bottomright.style.cursor = 's-resize'; } bottomright.align = 'right'; bottomright.valign = 'bottom'; var span = ke.$$('span'); span.classname = 'ke-bottom-right-img'; if (ke.g[id].config.resizemode == 0 || mode == 1) { span.style.visibility = 'hidden'; } bottomright.appendchild(span); bottomouter.appendchild(bottom); var hidediv = ke.$$('div'); hidediv.style.display = 'none'; var maskdiv = ke.$$('div'); maskdiv.classname = 'ke-mask'; ke.util.setopacity(maskdiv, 50); 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 < 7) iframedoc.designmode = 'on'; var html = ke.util.getfullhtml(id); iframedoc.write(html); 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'); } var hidemenu = function() { ke.layout.hide(id); }; var updatetoolbar = function () { ke.toolbar.updatestate(id); }; var addhistory = function () { ke.history.add(id, true); }; if (ke.browser.webkit) { ke.event.add(iframedoc, 'click', function(e) { ke.util.selectimagewebkit(id, e, true); }); } ke.event.add(iframedoc, 'click', hidemenu); ke.event.add(iframedoc, 'click', updatetoolbar); ke.event.input(iframedoc, addhistory); ke.event.input(iframedoc, updatetoolbar); ke.event.add(newtextarea, 'click', hidemenu); ke.event.input(newtextarea, addhistory); ke.g[id].container = container; ke.g[id].toolbartable = toolbartable; ke.g[id].textareatable = textareatable; ke.g[id].iframe = iframe; ke.g[id].newtextarea = newtextarea; 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.resize(id, width, 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); ke.event.add(iframedoc, 'mouseup', setselectionhandler); ke.event.add(document, 'mousedown', setselectionhandler); ke.onchange(id, function(id) { ke.util.setdata(id); }); if (ke.browser.ie && ke.browser.version > 6) ke.readonly(id, false); window.settimeout(function() { ke.util.setfullhtml(id, srctextarea.value); if (mode > 0) ke.util.focus(id); if (ke.g[id].aftercreate) ke.g[id].aftercreate(id); }, 0); }; ke.onchange = function(id, func) { function handler() { func(id); }; ke.g[id].onchangehandlerstack.push(handler); ke.event.input(ke.g[id].iframedoc, handler); ke.event.input(ke.g[id].newtextarea, handler); }; 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 = []; 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); }); }; ke.plugin['about'] = { click : function(id) { ke.util.selection(id); var dialog = new ke.dialog({ id : id, cmd : 'about', file : 'about.html?id=' + id + '&ver=' + ke.version, 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); }); ke.event.ctrl(ke.g[id].newtextarea, 'z', function(e) { ke.plugin['undo'].click(id); ke.util.focus(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); }); ke.event.ctrl(ke.g[id].newtextarea, 'y', function(e) { ke.plugin['redo'].click(id); ke.util.focus(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?id=' + id + '&ver=' + ke.version, width : 400, 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); ke.layout.hide(id); 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?id=' + id + '&ver=' + ke.version, width : 400, height : 300, loadingmode : true, title : ke.lang['wordpaste'], yesbutton : ke.lang['yes'], nobutton : ke.lang['no'] }); this.dialog.show(); }, exec : function(id) { var htmltags = { font : ['color', 'size', 'face', '.background-color'], span : [ '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align' ], div : [ 'align', '.border', '.margin', '.padding', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight', '.background', '.font-style', '.text-decoration', '.vertical-align', '.margin-left' ], table: [ 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background' ], 'td,th': [ 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.background' ], a : ['href', 'target', 'name'], embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', '/'], img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height', '/'], hr : ['/'], br : ['/'], 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' ], 'tbody,tr,strong,b,sub,sup,em,i,u,strike' : [] }; 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(/]*>(\n|.)*?<\/style>/ig, ""); str = str.replace(/]*>(\n|.)*?<\/script>/ig, ""); str = str.replace(/]+>(\n|.)*?<\/w:[^>]+>/ig, ""); str = str.replace(/(\n|.)*?<\/xml>/ig, ""); str = str.replace(/\r\n|\n|\r/ig, ""); str = ke.util.execgethtmlhooks(id, str); str = ke.format.gethtml(str, htmltags, ke.g[id].urltype); ke.util.inserthtml(id, str); ke.layout.hide(id); ke.util.focus(id); } }; ke.plugin['fullscreen'] = { click : function(id) { var g = ke.g[id]; var self = this; var resetsize = function() { var el = ke.util.getdocumentelement(); g.width = el.clientwidth + 'px'; g.height = el.clientheight + 'px'; }; var windowsize = ''; var resizelistener = function() { if (!self.isselected) return; var el = ke.util.getdocumentelement(); var size = [el.clientwidth, el.clientheight].join(''); if (windowsize != size) { windowsize = size; resetsize(); ke.util.resize(id, g.width, g.height); } } if (this.isselected) { this.isselected = false; ke.remove(id, 1); g.width = this.width; g.height = this.height; ke.create(id, 2); document.body.parentnode.style.overflow = 'auto'; ke.event.remove(window, 'resize', resizelistener); g.resizemode = g.config.resizemode; ke.toolbar.unselect(id, "fullscreen"); } else { this.isselected = true; this.width = g.container.style.width; this.height = g.container.style.height; ke.remove(id, 2); document.body.parentnode.style.overflow = 'hidden'; resetsize(); ke.create(id, 1); var pos = ke.util.getscrollpos(); var div = g.container; div.style.position = 'absolute'; div.style.left = pos.x + 'px'; div.style.top = pos.y + 'px'; div.style.zindex = 19811211; ke.event.add(window, 'resize', resizelistener); g.resizemode = 0; ke.toolbar.select(id, "fullscreen"); } } }; ke.plugin['bgcolor'] = { click : function(id) { ke.util.selection(id); this.menu = new ke.menu({ id : id, cmd : 'bgcolor' }); this.menu.picker(); }, exec : function(id, value) { var cmd = new ke.cmd(id); if (value == '') { cmd.remove({ 'span' : ['.background-color'] }); } else { cmd.wrap('span', [{'.background-color': value}]); } ke.history.add(id, false); ke.util.execonchangehandler(id); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['fontname'] = { click : function(id) { var fontname = { 'simsun' : '宋体', 'simhei' : '黑体', 'fangsong_gb2312' : '仿宋体', 'kaiti_gb2312' : '楷体', 'nsimsun' : '新宋体', 'arial' : 'arial', 'arial black' : 'arial black', 'times new roman' : 'times new roman', 'courier new' : 'courier new', 'tahoma' : 'tahoma', 'verdana' : 'verdana' }; var cmd = 'fontname'; ke.util.selection(id); var menu = new ke.menu({ id : id, cmd : cmd }); ke.each(fontname, function(key, value) { var html = '' + value + ''; menu.add(html, function() { ke.plugin[cmd].exec(id, key); }); }); menu.show(); this.menu = menu; }, exec : function(id, value) { var cmd = new ke.cmd(id); cmd.wrap('span', [{'.font-family': value}]); ke.history.add(id, false); ke.util.execonchangehandler(id); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['fontsize'] = { click : function(id) { var fontsize = ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px']; var cmd = 'fontsize'; ke.util.selection(id); var menu = new ke.menu({ id : id, cmd : cmd }); for (var i = 0, len = fontsize.length; i < len; i++) { var value = fontsize[i]; var html = '' + value + ''; menu.add(html, (function(value) { return function() { ke.plugin[cmd].exec(id, value); }; })(value)); } menu.show(); this.menu = menu; }, exec : function(id, value) { var cmd = new ke.cmd(id); cmd.wrap('span', [{'.font-size': value}]); ke.history.add(id, false); ke.util.execonchangehandler(id); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['hr'] = { click : function(id) { ke.util.selection(id); ke.util.inserthtml(id, '


'); ke.util.focus(id); } }; ke.plugin['print'] = { click : function(id) { ke.util.selection(id); ke.g[id].iframewin.print(); } }; ke.plugin['removeformat'] = { click : function(id) { ke.util.selection(id); var cmd = new ke.cmd(id); var tags = { '*' : ['class', 'style'] }; for (var i = 0, len = ke.g[id].inlinetags.length; i < len; i++) { tags[ke.g[id].inlinetags[i]] = ['*']; } cmd.remove(tags); ke.history.add(id, false); ke.util.execonchangehandler(id); ke.toolbar.updatestate(id); ke.util.focus(id); } }; ke.plugin['source'] = { click : function(id) { var g = ke.g[id]; if (!g.wyswygmode) { ke.util.setfullhtml(id, g.newtextarea.value); g.iframe.style.display = 'block'; g.newtextarea.style.display = 'none'; ke.toolbar.able(id, ['source', 'fullscreen']); g.wyswygmode = true; this.isselected = false; ke.toolbar.unselect(id, "source"); } else { ke.layout.hide(id); g.newtextarea.value = ke.util.getdata(id); g.iframe.style.display = 'none'; g.newtextarea.style.display = 'block'; ke.toolbar.disable(id, ['source', 'fullscreen']); g.wyswygmode = false; this.isselected = true; ke.toolbar.select(id, "source"); } ke.util.focus(id); } }; ke.plugin['textcolor'] = { click : function(id) { ke.util.selection(id); this.menu = new ke.menu({ id : id, cmd : 'textcolor' }); this.menu.picker(); }, exec : function(id, value) { var cmd = new ke.cmd(id); if (value == '') { cmd.remove({ 'span' : ['.color'], 'font' : ['color'] }); } else { cmd.wrap('span', [{'.color': value}]); } ke.history.add(id, false); ke.util.execonchangehandler(id); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['title'] = { click : function(id) { var title = { 'h1' : '标题 1', 'h2' : '标题 2', 'h3' : '标题 3', 'h4' : '标题 4', 'p' : '正 文' }; var cmd = 'title'; ke.util.selection(id); var menu = new ke.menu({ id : id, cmd : cmd }); ke.each(title, function(key, value) { var html = '<' + key + ' style="margin:0px;">' + value + ''; menu.add(html, function() { ke.plugin[cmd].exec(id, '<' + key + '>'); }); }); menu.show(); this.menu = menu; }, exec : function(id, value) { ke.util.select(id); ke.util.execcommand(id, 'formatblock', value); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['emoticons'] = { click : function(id) { var cmd = 'emoticons'; var rows = 9, cells = 15; ke.util.selection(id); var table = ke.$$('table'); table.classname = 'ke-plugin-emoticons-table'; table.cellpadding = 0; table.cellspacing = 2; table.border = 0; var num = 0; for (var i = 0; i < rows; i++) { var row = table.insertrow(i); for (var j = 0; j < cells; j++) { var cell = row.insertcell(j); cell.classname = 'ke-plugin-emoticons-td'; cell.onmouseover = function() {this.style.bordercolor = '#000000'; } cell.onmouseout = function() {this.style.bordercolor = '#f0f0ee'; } cell.onclick = (function(num) { return function() { ke.plugin[cmd].exec(id, num + '.gif'); }; })(num); var span = ke.$$('span'); span.classname = 'ke-plugin-emoticons-span'; span.style.backgroundposition = '-' + (24 * num) + 'px 0px'; cell.appendchild(span); num++; } } var menu = new ke.menu({ id : id, cmd : cmd }); menu.append(table); menu.show(); this.menu = menu; }, exec : function(id, value) { var url = ke.g[id].pluginspath + 'emoticons/' + value; var html = ''; ke.util.inserthtml(id, html); this.menu.hide(); ke.util.focus(id); } }; ke.plugin['flash'] = { init : function(id) { var self = this; ke.g[id].gethtmlhooks.push(function(html) { return html.replace(/]*class="?ke-flash"?[^>]*>/ig, function(imgstr) { var width = imgstr.match(/style="[^"]*;?\s*width:\s*(\d+)/i) ? regexp.$1 : 0; var height = imgstr.match(/style="[^"]*;?\s*height:\s*(\d+)/i) ? regexp.$1 : 0; width = width || (imgstr.match(/width="([^"]+)"/i) ? regexp.$1 : 0); height = height || (imgstr.match(/height="([^"]+)"/i) ? regexp.$1 : 0); if (imgstr.match(/kesrctag="([^"]+)"/i)) { var attrs = ke.util.getattrlist(unescape(regexp.$1)); attrs.width = width || attrs.width || 0; attrs.height = height || attrs.height || 0; attrs.kesrc = attrs.src; return ke.util.getmediaembed(attrs); } }); }); ke.g[id].sethtmlhooks.push(function(html) { return html.replace(/]*type="application\/x-shockwave-flash"[^>]*>(?:<\/embed>)?/ig, function($0) { var src = $0.match(/\s+src="([^"]+)"/i) ? regexp.$1 : ''; if ($0.match(/\s+kesrc="([^"]+)"/i)) src = regexp.$1; var width = $0.match(/\s+width="([^"]+)"/i) ? regexp.$1 : 0; var height = $0.match(/\s+height="([^"]+)"/i) ? regexp.$1 : 0; var attrs = ke.util.getattrlist($0); attrs.src = src; attrs.width = width; attrs.height = height; return ke.util.getmediaimage(id, 'flash', attrs); }); }); }, click : function(id) { ke.util.selection(id); this.dialog = new ke.dialog({ id : id, cmd : 'flash', file : 'flash.html?id=' + id + '&ver=' + ke.version, width : 400, height : 140, loadingmode : true, title : ke.lang['flash'], yesbutton : ke.lang['yes'], nobutton : ke.lang['no'] }); this.dialog.show(); }, check : function(id, url, width, height) { var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); if (!url.match(/^.{3,}$/)) { alert(ke.lang['invalidurl']); ke.$('url', dialogdoc).focus(); return false; } if (!width.match(/^\d*$/)) { alert(ke.lang['invalidwidth']); ke.$('width', dialogdoc).focus(); return false; } if (!height.match(/^\d*$/)) { alert(ke.lang['invalidheight']); ke.$('height', dialogdoc).focus(); return false; } return true; }, exec : function(id) { var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); var url = ke.$('url', dialogdoc).value; var width = ke.$('width', dialogdoc).value; var height = ke.$('height', dialogdoc).value; if (!this.check(id, url, width, height)) return false; var html = ke.util.getmediaimage(id, 'flash', { src : url, type : ke.g[id].mediatypes['flash'], width : width, height : height, quality : 'high' }); ke.util.inserthtml(id, html); ke.layout.hide(id); ke.util.focus(id); } }; ke.plugin['image'] = { getselectednode : function(id) { var g = ke.g[id]; var startnode = g.kerange.startnode; var endnode = g.kerange.endnode; if (!ke.browser.webkit && !g.kesel.iscontrol) return; if (startnode.nodetype != 1) return; if (startnode.tagname.tolowercase() != 'img') return; if (startnode != endnode) return; if (!startnode.classname.match(/^ke-\w+/i)) return startnode; }, init : function(id) { var self = this; var g = ke.g[id]; g.contextmenuitems.push({ text : ke.lang['editimage'], click : function(id, menu) { ke.util.select(id); menu.hide(); self.click(id); }, cond : function(id) { return self.getselectednode(id); } }); g.contextmenuitems.push({ text : ke.lang['deleteimage'], click : function(id, menu) { ke.util.select(id); menu.hide(); var img = self.getselectednode(id); img.parentnode.removechild(img); }, cond : function(id) { return self.getselectednode(id); } }); }, click : function(id) { ke.util.selection(id); this.dialog = new ke.dialog({ id : id, cmd : 'image', file : 'image/image.html?id=' + id + '&ver=' + ke.version, width : 400, height : 230, loadingmode : true, title : ke.lang['image'], yesbutton : ke.lang['yes'], nobutton : ke.lang['no'] }); this.dialog.show(); }, check : function(id) { var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); var type = ke.$('type', dialogdoc).value; var width = ke.$('imgwidth', dialogdoc).value; var height = ke.$('imgheight', dialogdoc).value; var title = ke.$('imgtitle', dialogdoc).value; var urlbox; if (type == 2) { urlbox = ke.$('imgfile', dialogdoc); } else { urlbox = ke.$('url', dialogdoc); } if (!urlbox.value.match(/\.(jpg|jpeg|gif|bmp|png)(\s|$)/i)) { alert(ke.lang['invalidimg']); urlbox.focus(); return false; } if (!width.match(/^\d*$/)) { alert(ke.lang['invalidwidth']); ke.$('imgwidth', dialogdoc).focus(); return false; } if (!height.match(/^\d*$/)) { alert(ke.lang['invalidheight']); ke.$('imgheight', dialogdoc).focus(); return false; } return true; }, exec : function(id) { var self = this; var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); var type = ke.$('type', dialogdoc).value; var width = ke.$('imgwidth', dialogdoc).value; var height = ke.$('imgheight', dialogdoc).value; var title = ke.$('imgtitle', dialogdoc).value; var alignelements = dialogdoc.getelementsbyname('align'); var align = ''; for (var i = 0, len = alignelements.length; i < len; i++) { if (alignelements[i].checked) { align = alignelements[i].value; break; } } if (!this.check(id)) return false; if (type == 2) { ke.$('editorid', dialogdoc).value = id; var uploadiframe = ke.$('uploadiframe', dialogdoc); ke.util.showloadingpage(id); var onloadfunc = function() { ke.event.remove(uploadiframe, 'load', onloadfunc); ke.util.hideloadingpage(id); var uploaddoc = ke.util.getiframedoc(uploadiframe); var data = ''; try { data = ke.util.parsejson(uploaddoc.body.innerhtml); } catch(e) { alert(ke.lang.invalidjson); } if (typeof data === 'object' && 'error' in data) { if (data.error === 0) { self.insert(id, data.url, title, width, height, 0, align); } else { alert(data.message); return false; } } }; ke.event.add(uploadiframe, 'load', onloadfunc); dialogdoc.uploadform.submit(); return; } else { var url = ke.$('url', dialogdoc).value; this.insert(id, url, title, width, height, 0, align); } }, insert : function(id, url, title, width, height, border, align) { //--my js code var myindex = url.indexof("\\"); if(myindex > 1) { url = '\\' + url; } //--my js code var html = ' 0) html += 'width="' + width + '" '; if (height > 0) html += 'height="' + height + '" '; if (title) html += 'title="' + title + '" '; if (align) html += 'align="' + align + '" '; html += 'alt="' + title + '" '; html += 'border="' + border + '" />'; ke.util.inserthtml(id, html); ke.layout.hide(id); ke.util.focus(id); } }; ke.plugin['link'] = { getselectednode : function(id) { var g = ke.g[id]; var range = g.kerange; var startnode = range.startnode; var startpos = range.startpos; var endnode = range.endnode; var endpos = range.endpos; var inlinetaghash = ke.util.arraytohash(g.inlinetags); var findlinknode = function(node) { while (node) { if (node.nodetype == 1) { var tagname = node.tagname.tolowercase(); if (tagname == 'a') return node; } node = node.parentnode; } return null; }; var startlink = findlinknode(startnode); var endlink = findlinknode(endnode); if (startlink && endlink && startlink === endlink) { return startlink; } }, init : function(id) { var self = this; ke.g[id].contextmenuitems.push({ text : ke.lang['editlink'], click : function(id, menu) { ke.util.select(id); menu.hide(); self.click(id); }, cond : function(id) { return self.getselectednode(id); } }); }, click : function(id) { ke.util.selection(id); this.dialog = new ke.dialog({ id : id, cmd : 'link', file : 'link/link.html?id=' + id + '&ver=' + ke.version, width : 400, height : 100, loadingmode : true, title : ke.lang['link'], yesbutton : ke.lang['yes'], nobutton : ke.lang['no'] }); this.dialog.show(); }, exec : function(id) { var g = ke.g[id]; ke.util.select(id); var range = g.kerange; var startnode = range.startnode; var endnode = range.endnode; var iframedoc = g.iframedoc; var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); var url = ke.$('hyperlink', dialogdoc).value; var target = ke.$('linktype', dialogdoc).value; if (!url.match(/.+/) || url.match(/^\w+:\/\/\/?$/)) { alert(ke.lang['invalidurl']); ke.$('hyperlink', dialogdoc).focus(); return false; } var node = range.getparentelement(); while (node) { if (node.tagname.tolowercase() == 'a' || node.tagname.tolowercase() == 'body') break; node = node.parentnode; } node = node.parentnode; var isitem = (startnode.nodetype == 1 && startnode === endnode); var isempty = !isitem; if (!isitem) isempty = ke.browser.ie ? g.range.text === '' : g.range.tostring() === ''; if (isempty || ke.util.isempty(id)) { var html = ''; ke.util.inserthtml(id, html); } else { iframedoc.execcommand('createlink', false, '__ke_temp_url__'); var arr = node.getelementsbytagname('a'); for (var i = 0, l = arr.length; i < l; i++) { if (arr[i].href.match(/\/?__ke_temp_url__$/)) { arr[i].href = url; arr[i].setattribute('kesrc', url); if (target) arr[i].target = target; else arr[i].removeattribute('target'); } } if (ke.browser.webkit && isitem && startnode.tagname.tolowercase() == 'img') { var parent = startnode.parentnode; if (parent.tagname.tolowercase() != 'a') { var a = ke.$$('a', iframedoc); parent.insertbefore(a, startnode); a.appendchild(startnode); parent = a; } parent.href = url; parent.setattribute('kesrc', url); if (target) parent.target = target; else parent.removeattribute('target'); g.kesel.addrange(range); } } ke.history.add(id, false); ke.util.execonchangehandler(id); ke.layout.hide(id); ke.util.focus(id); } }; ke.plugin['unlink'] = { init : function(id) { var self = this; ke.g[id].contextmenuitems.push({ text : ke.lang['deletelink'], click : function(id, menu) { ke.util.select(id); menu.hide(); self.click(id); }, cond : function(id) { return ke.plugin['link'].getselectednode(id); } }); }, click : function(id) { var g = ke.g[id]; var iframedoc = g.iframedoc; ke.util.selection(id); var range = g.kerange; var startnode = range.startnode; var endnode = range.endnode; var isitem = (startnode.nodetype == 1 && startnode === endnode); var isempty = !isitem; if (!isitem) isempty = ke.browser.ie ? g.range.text === '' : g.range.tostring() === ''; if (isempty) { var linknode = ke.plugin['link'].getselectednode(id); if (!linknode) return; var range = g.kerange; range.selecttextnode(linknode); g.kesel.addrange(range); ke.util.select(id); iframedoc.execcommand('unlink', false, null); if (ke.browser.webkit && startnode.tagname.tolowercase() == 'img') { var parent = startnode.parentnode; if (parent.tagname.tolowercase() == 'a') { ke.util.removeparent(parent); g.kesel.addrange(range); } } } else { iframedoc.execcommand('unlink', false, null); } ke.toolbar.updatestate(id); ke.history.add(id, false); ke.util.execonchangehandler(id); ke.util.focus(id); } }; ke.plugin['media'] = { init : function(id) { var self = this; var typehash = {}; ke.each(ke.g[id].mediatypes, function(key, val) { typehash[val] = key; }); ke.g[id].gethtmlhooks.push(function(html) { return html.replace(/]*class="?ke-\w+"?[^>]*>/ig, function($0) { var width = $0.match(/style="[^"]*;?\s*width:\s*(\d+)/i) ? regexp.$1 : 0; var height = $0.match(/style="[^"]*;?\s*height:\s*(\d+)/i) ? regexp.$1 : 0; width = width || ($0.match(/width="([^"]+)"/i) ? regexp.$1 : 0); height = height || ($0.match(/height="([^"]+)"/i) ? regexp.$1 : 0); if ($0.match(/\s+kesrctag="([^"]+)"/i)) { var attrs = ke.util.getattrlist(unescape(regexp.$1)); attrs.width = width || attrs.width || 0; attrs.height = height || attrs.height || 0; attrs.kesrc = attrs.src; return ke.util.getmediaembed(attrs); } }); }); ke.g[id].sethtmlhooks.push(function(html) { return html.replace(/]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function($0, $1) { if (typeof typehash[$1] == 'undefined') return $0; var src = $0.match(/\s+src="([^"]+)"/i) ? regexp.$1 : ''; if ($0.match(/\s+kesrc="([^"]+)"/i)) src = regexp.$1; var width = $0.match(/\s+width="([^"]+)"/i) ? regexp.$1 : 0; var height = $0.match(/\s+height="([^"]+)"/i) ? regexp.$1 : 0; var attrs = ke.util.getattrlist($0); attrs.src = src; attrs.width = width; attrs.height = height; return ke.util.getmediaimage(id, '', attrs); }); }); }, click : function(id) { ke.util.selection(id); this.dialog = new ke.dialog({ id : id, cmd : 'media', file : 'media.html?id=' + id + '&ver=' + ke.version, width : 400, height : 170, loadingmode : true, title : ke.lang['media'], yesbutton : ke.lang['yes'], nobutton : ke.lang['no'] }); this.dialog.show(); }, check : function(id, url, width, height) { var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); if (!url.match(/^.{3,}\.(swf|flv|mp3|wav|wma|wmv|mid|avi|mpg|mpeg|asf|rm|rmvb)(\?|$)/i)) { alert(ke.lang['invalidmedia']); ke.$('url', dialogdoc).focus(); return false; } if (!width.match(/^\d*$/)) { alert(ke.lang['invalidwidth']); ke.$('width', dialogdoc).focus(); return false; } if (!height.match(/^\d*$/)) { alert(ke.lang['invalidheight']); ke.$('height', dialogdoc).focus(); return false; } return true; }, exec : function(id) { var dialogdoc = ke.util.getiframedoc(this.dialog.iframe); var url = ke.$('url', dialogdoc).value; var width = ke.$('width', dialogdoc).value; var height = ke.$('height', dialogdoc).value; if (!this.check(id, url, width, height)) return false; var autostart = ke.$('autostart', dialogdoc).checked ? 'true' : 'false'; var html = ke.util.getmediaimage(id, '', { src : url, type : ke.g[id].mediatypes[ke.util.getmediatype(url)], width : width, height : height, autostart : autostart, loop : 'true' }); ke.util.inserthtml(id, html); ke.layout.hide(id); ke.util.focus(id); } }; ke.plugin['table'] = { click : function(id) { var self = this; var num = 10; var cmd = 'table'; var cellarr = []; ke.util.selection(id); var table = ke.$$('table'); table.cellpadding = 0; table.cellspacing = 0; table.border = 0; table.classname = 'ke-plugin-table-table'; for (var i = 0; i < num; i++) { var row = table.insertrow(i); cellarr[i] = []; for (var j = 0; j < num; j++) { var value = (i + 1) + ',' + (j + 1); var cell = row.insertcell(j); cell.classname = 'ke-plugin-table-td'; var div = ke.$$('div'); div.classname = 'ke-plugin-table-div'; cell.appendchild(div); cellarr[i][j] = div; div.onmouseover = (function(x, y) { return function() { self.locationcell.innerhtml = x + ' by ' + y + ' table'; for (var m = 0; m < num; m++) { for (var n = 0; n < num; n++) { var cell = cellarr[m][n]; if (m < x && n < y) cell.style.backgroundcolor = '#cccccc'; else cell.style.backgroundcolor = '#ffffff'; } } }; })(i + 1, j + 1); div.onclick = (function(value) { return function() { ke.plugin[cmd].exec(id, value); }; })(value); } } var row = table.insertrow(num); var cell = row.insertcell(0); cell.classname = 'ke-plugin-table-td-bottom'; cell.colspan = 10; self.locationcell = cell; var menu = new ke.menu({ id : id, cmd : cmd }); menu.append(table); menu.show(); this.menu = menu; }, exec : function(id, value) { var location = value.split(','); var html = ''; for (var i = 0; i < location[0]; i++) { html += ''; for (var j = 0; j < location[1]; j++) { html += ''; } html += ''; } html += '
 
'; ke.util.inserthtml(id, html); this.menu.hide(); ke.util.focus(id); } };