How to use Ke method in backstopjs

Best JavaScript code snippet using backstopjs

kindeditor.js

Source:kindeditor.js Github

copy

Full Screen

1/*******************************************************************************2* KindEditor - WYSIWYG HTML Editor for Internet3* Copyright (C) 2006-2010 Longhao Luo4*5* @author Roddy <luolonghao@gmail.com>6* @site http://www.kindsoft.net/7* @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)8* @version 3.5.1 (2010-07-18)9*******************************************************************************/10(function (undefined) {11var KE = {};12KE.version = '3.5.1 (2010-07-18)';13KE.scriptPath = (function() {14 var elements = document.getElementsByTagName('script');15 for (var i = 0, len = elements.length; i < len; i++) {16 if (elements[i].src && elements[i].src.match(/kindeditor[\w\-\.]*\.js/)) {17 return elements[i].src.substring(0, elements[i].src.lastIndexOf('/') + 1);18 }19 }20 return '';21})();22KE.browser = (function() {23 var ua = navigator.userAgent.toLowerCase();24 return {25 VERSION: ua.match(/(msie|firefox|webkit|opera)[\/:\s](\d+)/) ? RegExp.$2 : '0',26 IE: (ua.indexOf('msie') > -1 && ua.indexOf('opera') == -1),27 GECKO: (ua.indexOf('gecko') > -1 && ua.indexOf('khtml') == -1),28 WEBKIT: (ua.indexOf('applewebkit') > -1),29 OPERA: (ua.indexOf('opera') > -1)30 };31})();32KE.setting = {33 wyswygMode : true,34 loadStyleMode : true,35 resizeMode : 2,36 filterMode : false,37 autoSetDataMode : true,38 shadowMode : true,39 urlType : '',40 skinType : 'default',41 newlineTag : 'p',42 dialogAlignType : 'page',43 cssPath : '',44 skinsPath : KE.scriptPath === '' ? '' : KE.scriptPath + 'skins/',45 pluginsPath : KE.scriptPath === '' ? '' : KE.scriptPath + 'plugins/',46 minWidth : 200,47 minHeight : 100,48 minChangeSize : 5,49 toolbarLineHeight : 24,50 statusbarHeight : 11,51 items : [52 'source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',53 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',54 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',55 'superscript', '|', 'selectall', '-',56 'title', 'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold',57 'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image',58 'flash', 'media', 'advtable', 'hr', 'emoticons', 'link', 'unlink', '|', 'about'59 ],60 colorTable : [61 ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],62 ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],63 ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],64 ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']65 ],66 noEndTags : ['br', 'hr', 'img', 'area', 'col', 'embed', 'input', 'param'],67 inlineTags : ['b', 'del', 'em', 'font', 'i', 'span', 'strike', 'strong', 'sub', 'sup', 'u'],68 endlineTags : [69 'br', 'hr', 'table', 'tbody', 'td', 'tr', 'th', 'div', 'p', 'ol', 'ul',70 'li', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'script', 'style', 'marquee'71 ],72 htmlTags : {73 font : ['color', 'size', 'face', '.background-color'],74 span : [75 '.color', '.background-color', '.font-size', '.font-family', '.background',76 '.font-weight', '.font-style', '.text-decoration', '.vertical-align'77 ],78 div : [79 'align', '.border', '.margin', '.padding', '.text-align', '.color',80 '.background-color', '.font-size', '.font-family', '.font-weight', '.background',81 '.font-style', '.text-decoration', '.vertical-align', '.margin-left'82 ],83 table: [84 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',85 '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',86 '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',87 '.width', '.height'88 ],89 'td,th': [90 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',91 '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',92 '.font-style', '.text-decoration', '.vertical-align', '.background'93 ],94 a : ['href', 'target', 'name'],95 embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', '/'],96 img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height', '/'],97 hr : ['/'],98 br : ['/'],99 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [100 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',101 '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'102 ],103 'tbody,tr,strong,b,sub,sup,em,i,u,strike' : []104 },105 mediaTypes : {106 rm : 'audio/x-pn-realaudio-plugin',107 flash : 'application/x-shockwave-flash',108 media : 'video/x-ms-asf-plugin'109 }110};111KE.g = {};112KE.plugin = {};113KE.$ = function(id, doc){114 var doc = doc || document;115 return doc.getElementById(id);116};117KE.$$ = function(name, doc){118 var doc = doc || document;119 return doc.createElement(name);120};121KE.event = {122 add : function(el, type, fn, id) {123 if (el.addEventListener){124 el.addEventListener(type, fn, false);125 } else if (el.attachEvent){126 el.attachEvent('on' + type, fn);127 }128 if (id !== undefined) {129 KE.g[id].eventStack.push({130 el : el,131 type : type,132 fn : fn133 });134 }135 },136 remove : function(el, type, fn, id) {137 if (el.removeEventListener){138 el.removeEventListener(type, fn, false);139 } else if (el.detachEvent){140 el.detachEvent('on' + type, fn);141 }142 if (id !== undefined) {143 var stack = KE.g[id].eventStack;144 for (var i = 0, len = stack.length; i < len; i++) {145 var item = stack[i];146 if (item && el === item.el && type === item.type && fn === item.fn) {147 delete stack[i];148 }149 }150 }151 },152 stop : function(e) {153 if (e.preventDefault) e.preventDefault();154 if (e.stopPropagation) e.stopPropagation();155 if (e.cancelBubble !== undefined) e.cancelBubble = true;156 if (e.returnValue !== undefined) e.returnValue = false;157 },158 bind : function(el, type, fn, id) {159 this.add(el, type, function(e) {160 fn(e);161 KE.event.stop(e);162 return false;163 }, id);164 },165 input : function(el, func, id) {166 this.add(el, 'keyup', function(e) {167 if (!e.ctrlKey && !e.altKey && (e.keyCode < 16 || e.keyCode > 18) && e.keyCode != 116) {168 func(e);169 KE.event.stop(e);170 return false;171 }172 }, id);173 function handler (e) {174 window.setTimeout(function() {175 func(e);176 }, 1);177 }178 var newElement = (el.nodeName == '#document') ? el.body : el;179 this.add(newElement, 'paste', handler, id);180 this.add(newElement, 'cut', handler, id);181 },182 ctrl : function(el, key, func, id) {183 key = key.toString().match(/^\d{2,}$/) ? key : key.toUpperCase().charCodeAt(0);184 this.add(el, 'keydown', function(e) {185 if (e.ctrlKey && e.keyCode == key && !e.shiftKey && !e.altKey) {186 func(e);187 KE.event.stop(e);188 return false;189 }190 }, id);191 },192 ready : function(func, win, doc, id) {193 var win = win || window;194 var doc = doc || document;195 var loaded = false;196 var readyFunc = function() {197 if (loaded) return;198 loaded = true;199 func();200 };201 if (doc.addEventListener) {202 this.add(doc, "DOMContentLoaded", readyFunc, id);203 } else if (doc.attachEvent){204 this.add(doc, "readystatechange", function() {205 if (doc.readyState == "complete") readyFunc();206 }, id);207 if ( doc.documentElement.doScroll && typeof win.frameElement === "undefined" ) {208 var ieReadyFunc = function() {209 if (loaded) return;210 try {211 doc.documentElement.doScroll("left");212 } catch(e) {213 window.setTimeout(ieReadyFunc, 0);214 return;215 }216 readyFunc();217 };218 ieReadyFunc();219 }220 }221 this.add(win, 'load', readyFunc, id);222 }223};224KE.each = function(obj, func) {225 for (var key in obj) {226 if (obj.hasOwnProperty(key)) func(key, obj[key]);227 }228};229KE.eachNode = function(node, func) {230 var walkNodes = function(parent) {231 if (KE.util.getNodeType(parent) != 1) return true;232 var n = parent.firstChild;233 while (n) {234 var next = n.nextSibling;235 if (!func(n)) return false;236 if (!walkNodes(n)) return false;237 n = next;238 }239 return true;240 };241 walkNodes(node);242};243KE.selection = function(doc) {244 this.sel = null;245 this.range = null;246 this.keRange = null;247 this.isControl = false;248 var win = doc.parentWindow || doc.defaultView;249 this.init = function() {250 var sel = win.getSelection ? win.getSelection() : doc.selection;251 var range;252 try {253 if (sel.rangeCount > 0) range = sel.getRangeAt(0);254 else range = sel.createRange();255 } catch(e) {}256 if (!range) range = KE.util.createRange(doc);257 this.sel = sel;258 this.range = range;259 var startNode, startPos, endNode, endPos;260 if (KE.browser.IE) {261 if (range.item) {262 this.isControl = true;263 var el = range.item(0);264 startNode = endNode = el;265 startPos = endPos = 0;266 } else {267 this.isControl = false;268 var getStartEnd = function(isStart) {269 var pointRange = range.duplicate();270 pointRange.collapse(isStart);271 var parentNode = pointRange.parentElement();272 var nodes = parentNode.childNodes;273 if (nodes.length == 0) return {node: parentNode, pos: 0};274 var startNode;275 var endElement;276 var startPos = 0;277 var isEnd = false;278 var testRange = range.duplicate();279 KE.util.moveToElementText(testRange, parentNode);280 for (var i = 0, len = nodes.length; i < len; i++) {281 var node = nodes[i];282 var cmp = testRange.compareEndPoints('StartToStart', pointRange);283 if (cmp > 0) {284 isEnd = true;285 } else if (cmp == 0) {286 if (node.nodeType == 1) {287 var keRange = new KE.range(doc);288 keRange.selectTextNode(node);289 return {node: keRange.startNode, pos: 0};290 } else {291 return {node: node, pos: 0};292 }293 }294 if (node.nodeType == 1) {295 var nodeRange = range.duplicate();296 KE.util.moveToElementText(nodeRange, node);297 testRange.setEndPoint('StartToEnd', nodeRange);298 if (isEnd) startPos += nodeRange.text.length;299 else startPos = 0;300 } else if (node.nodeType == 3) {301 testRange.moveStart('character', node.nodeValue.length);302 startPos += node.nodeValue.length;303 }304 if (!isEnd) startNode = node;305 }306 if (!isEnd && startNode.nodeType == 1) {307 var startNode = parentNode.lastChild;308 return {node: startNode, pos: startNode.nodeType == 1 ? 1 : startNode.nodeValue.length};309 }310 testRange = range.duplicate();311 KE.util.moveToElementText(testRange, parentNode);312 testRange.setEndPoint('StartToEnd', pointRange);313 startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;314 return {node: startNode, pos: startPos};315 };316 var start = getStartEnd(true);317 var end = getStartEnd(false);318 startNode = start.node;319 startPos = start.pos;320 endNode = end.node;321 endPos = end.pos;322 }323 } else {324 startNode = range.startContainer;325 startPos = range.startOffset;326 endNode = range.endContainer;327 endPos = range.endOffset;328 if (startNode.nodeType == 1 && typeof startNode.childNodes[startPos] != 'undefined') {329 startNode = startNode.childNodes[startPos];330 startPos = 0;331 }332 if (endNode.nodeType == 1) {333 endPos = endPos == 0 ? 1 : endPos;334 if (typeof endNode.childNodes[endPos - 1] != 'undefined') {335 endNode = endNode.childNodes[endPos - 1];336 endPos = (endNode.nodeType == 1) ? 0 : endNode.nodeValue.length;337 }338 }339 this.isControl = (startNode.nodeType == 1 && startNode === endNode && range.startOffset + 1 == range.endOffset);340 if (startNode.nodeType == 1 && endNode.nodeType == 3 && endPos == 0 && endNode.previousSibling) {341 var node = endNode.previousSibling;342 while (node) {343 if (node === startNode) {344 endNode = startNode;345 break;346 }347 if (node.childNodes.length != 1) break;348 node = node.childNodes[0];349 }350 }351 if (range.collapsed) {352 var keRange = new KE.range(doc);353 keRange.setTextStart(startNode, startPos);354 endNode = keRange.startNode;355 endPos = keRange.startPos;356 }357 }358 var keRange = new KE.range(doc);359 keRange.setTextStart(startNode, startPos);360 keRange.setTextEnd(endNode, endPos);361 this.keRange = keRange;362 };363 this.init();364 this.addRange = function(keRange) {365 if (KE.browser.GECKO && KE.browser.VERSION < 3) return;366 this.keRange = keRange;367 if (KE.browser.IE) {368 var getEndRange = function(isStart) {369 var range = KE.util.createRange(doc);370 var node = isStart ? keRange.startNode : keRange.endNode;371 if (node.nodeType == 1) {372 KE.util.moveToElementText(range, node);373 range.collapse(isStart);374 } else if (node.nodeType == 3) {375 range = KE.util.getNodeStartRange(doc, node);376 var pos = isStart ? keRange.startPos : keRange.endPos;377 range.moveStart('character', pos);378 }379 return range;380 }381 if (!this.range.item) {382 var node = keRange.startNode;383 if (node == keRange.endNode && KE.util.getNodeType(node) == 1 && KE.util.getNodeTextLength(node) == 0) {384 var temp = doc.createTextNode(" ");385 node.appendChild(temp);386 KE.util.moveToElementText(this.range, node);387 this.range.collapse(false);388 this.range.select();389 node.removeChild(temp);390 } else {391 if (node.nodeType == 3 && keRange.collapsed()) {392 this.range = getEndRange(true);393 this.range.collapse(true);394 } else {395 this.range.setEndPoint('StartToStart', getEndRange(true));396 this.range.setEndPoint('EndToStart', getEndRange(false));397 }398 this.range.select();399 }400 }401 } else {402 var getNodePos = function(node) {403 var pos = 0;404 while (node) {405 node = node.previousSibling;406 pos++;407 }408 return --pos;409 };410 var range = new KE.range(doc);411 range.setTextStart(keRange.startNode, keRange.startPos);412 range.setTextEnd(keRange.endNode, keRange.endPos);413 var startNode = range.startNode;414 var endNode = range.endNode;415 if (KE.util.getNodeType(startNode) == 88) {416 this.range.setStart(startNode.parentNode, getNodePos(range.startNode));417 } else {418 this.range.setStart(startNode, range.startPos);419 }420 if (KE.util.getNodeType(endNode) == 88) {421 this.range.setEnd(endNode.parentNode, getNodePos(range.endNode) + 1);422 } else {423 this.range.setEnd(endNode, range.endPos);424 }425 this.sel.removeAllRanges();426 this.sel.addRange(this.range);427 }428 };429 this.focus = function() {430 if (KE.browser.IE && this.range != null) this.range.select();431 }432};433KE.range = function(doc) {434 this.startNode = null;435 this.startPos = null;436 this.endNode = null;437 this.endPos = null;438 this.getParentElement = function() {439 var scanParent = function(node, func) {440 while (node && (!node.tagName || node.tagName.toLowerCase() != 'body')) {441 node = node.parentNode;442 if (func(node)) return;443 }444 }445 var nodeList = [];446 scanParent(this.startNode, function(node) {447 nodeList.push(node);448 });449 var parentNode;450 scanParent(this.endNode, function(node) {451 if (KE.util.inArray(node, nodeList)) {452 parentNode = node;453 return true;454 }455 });456 return parentNode ? parentNode : doc.body;457 };458 this.getNodeList = function() {459 var self = this;460 var parentNode = this.getParentElement();461 var nodeList = [];462 var isStarted = false;463 if (parentNode == self.startNode) isStarted = true;464 if (isStarted) nodeList.push(parentNode);465 KE.eachNode(parentNode, function(node) {466 if (node == self.startNode) isStarted = true;467 var range = new KE.range(doc);468 range.selectTextNode(node);469 var cmp = range.comparePoints('START_TO_END', self);470 if (cmp > 0) {471 return false;472 } else if (cmp == 0) {473 if (range.startNode !== range.endNode || range.startPos !== range.endPos) return false;474 }475 if (isStarted) nodeList.push(node);476 return true;477 });478 return nodeList;479 };480 this.comparePoints = function(how, range) {481 var compareNodes = function(nodeA, posA, nodeB, posB) {482 var cmp;483 if (KE.browser.IE) {484 var getStartRange = function(node, pos, isStart) {485 var range = KE.util.createRange(doc);486 var type = KE.util.getNodeType(node);487 if (type == 1) {488 KE.util.moveToElementText(range, node);489 range.collapse(isStart);490 } else if (type == 3) {491 range = KE.util.getNodeStartRange(doc, node);492 range.moveStart('character', pos);493 range.collapse(true);494 }495 return range;496 }497 var rangeA, rangeB;498 if (how == 'START_TO_START' || how == 'START_TO_END') rangeA = getStartRange(nodeA, posA, true);499 else rangeA = getStartRange(nodeA, posA, false);500 if (how == 'START_TO_START' || how == 'END_TO_START') rangeB = getStartRange(nodeB, posB, true);501 else rangeB = getStartRange(nodeB, posB, false);502 return rangeA.compareEndPoints('StartToStart', rangeB);503 } else {504 var rangeA = KE.util.createRange(doc);505 rangeA.selectNode(nodeA);506 if (how == 'START_TO_START' || how == 'START_TO_END') rangeA.collapse(true);507 else rangeA.collapse(false);508 var rangeB = KE.util.createRange(doc);509 rangeB.selectNode(nodeB);510 if (how == 'START_TO_START' || how == 'END_TO_START') rangeB.collapse(true);511 else rangeB.collapse(false);512 if (rangeA.compareBoundaryPoints(Range.START_TO_START, rangeB) > 0) {513 cmp = 1;514 } else if (rangeA.compareBoundaryPoints(Range.START_TO_START, rangeB) == 0) {515 if (posA > posB) cmp = 1;516 else if (posA == posB) cmp = 0;517 else cmp = -1;518 } else {519 cmp = -1;520 }521 }522 return cmp;523 }524 if (how == 'START_TO_START') return compareNodes(this.startNode, this.startPos, range.startNode, range.startPos);525 if (how == 'START_TO_END') return compareNodes(this.startNode, this.startPos, range.endNode, range.endPos);526 if (how == 'END_TO_START') return compareNodes(this.endNode, this.endPos, range.startNode, range.startPos);527 if (how == 'END_TO_END') return compareNodes(this.endNode, this.endPos, range.endNode, range.endPos);528 };529 this.collapsed = function() {530 return (this.startNode === this.endNode && this.startPos === this.endPos);531 };532 this.collapse = function(toStart) {533 if (toStart) {534 this.setEnd(this.startNode, this.startPos);535 } else {536 this.setStart(this.endNode, this.endPos);537 }538 };539 this.setTextStart = function(node, pos) {540 var textNode = node;541 KE.eachNode(node, function(n) {542 if (KE.util.getNodeType(n) == 3 && n.nodeValue.length > 0 || KE.util.getNodeType(n) == 88) {543 textNode = n;544 pos = 0;545 return false;546 }547 return true;548 });549 this.setStart(textNode, pos);550 };551 this.setStart = function(node, pos) {552 this.startNode = node;553 this.startPos = pos;554 if (this.endNode === null) {555 this.endNode = node;556 this.endPos = pos;557 }558 };559 this.setTextEnd = function(node, pos) {560 var textNode = node;561 KE.eachNode(node, function(n) {562 if (KE.util.getNodeType(n) == 3 && n.nodeValue.length > 0 || KE.util.getNodeType(n) == 88) {563 textNode = n;564 pos = KE.util.getNodeType(n) == 3 ? n.nodeValue.length : 0;565 }566 return true;567 });568 this.setEnd(textNode, pos);569 };570 this.setEnd = function(node, pos) {571 this.endNode = node;572 this.endPos = pos;573 if (this.startNode === null) {574 this.startNode = node;575 this.startPos = pos;576 }577 };578 this.selectNode = function(node) {579 this.setStart(node, 0);580 this.setEnd(node, node.nodeType == 1 ? 0 : node.nodeValue.length);581 };582 this.selectTextNode = function(node) {583 this.setTextStart(node, 0);584 this.setTextEnd(node, node.nodeType == 1 ? 0 : node.nodeValue.length);585 };586 this.extractContents = function(isDelete) {587 isDelete = (isDelete === undefined) ? true : isDelete;588 var thisRange = this;589 var startNode = this.startNode;590 var startPos = this.startPos;591 var endNode = this.endNode;592 var endPos = this.endPos;593 var extractTextNode = function(node, startPos, endPos) {594 var length = node.nodeValue.length;595 var cloneNode = node.cloneNode(true);596 var centerNode = cloneNode.splitText(startPos);597 centerNode.splitText(endPos - startPos);598 if (isDelete) {599 var center = node;600 if (startPos > 0) center = node.splitText(startPos);601 if (endPos < length) center.splitText(endPos - startPos);602 center.parentNode.removeChild(center);603 }604 return centerNode;605 };606 var noEndTagHash = KE.util.arrayToHash(KE.setting.noEndTags);607 var isStarted = false;608 var isEnd = false;609 var extractNodes = function(parent, frag) {610 if (KE.util.getNodeType(parent) != 1) return true;611 var node = parent.firstChild;612 while (node) {613 if (node == startNode) isStarted = true;614 if (node == endNode) isEnd = true;615 var nextNode = node.nextSibling;616 var type = node.nodeType;617 if (type == 1) {618 var range = new KE.range(doc);619 range.selectNode(node);620 var cmp = range.comparePoints('END_TO_END', thisRange);621 if (isStarted && (cmp < 0 || (cmp == 0 && noEndTagHash[node.nodeName.toLowerCase()] !== undefined))) {622 var cloneNode = node.cloneNode(true);623 frag.appendChild(cloneNode);624 if (isDelete) {625 node.parentNode.removeChild(node);626 }627 } else {628 var childFlag = node.cloneNode(false);629 if (noEndTagHash[childFlag.nodeName.toLowerCase()] === undefined) {630 frag.appendChild(childFlag);631 if (!extractNodes(node, childFlag)) return false;632 }633 }634 } else if (type == 3) {635 if (isStarted) {636 var textNode;637 if (node == startNode && node == endNode) {638 textNode = extractTextNode(node, startPos, endPos);639 frag.appendChild(textNode);640 return false;641 } else if (node == startNode) {642 textNode = extractTextNode(node, startPos, node.nodeValue.length);643 frag.appendChild(textNode);644 } else if (node == endNode) {645 textNode = extractTextNode(node, 0, endPos);646 frag.appendChild(textNode);647 return false;648 } else {649 textNode = extractTextNode(node, 0, node.nodeValue.length);650 frag.appendChild(textNode);651 }652 }653 }654 node = nextNode;655 if (isEnd) return false;656 }657 if (frag.innerHTML.replace(/<.*?>/g, '') === '' && frag.parentNode) {658 frag.parentNode.removeChild(frag);659 }660 return true;661 }662 var parentNode = this.getParentElement();663 var docFrag = parentNode.cloneNode(false);664 extractNodes(parentNode, docFrag);665 return docFrag;666 };667 this.cloneContents = function() {668 return this.extractContents(false);669 };670 this.getText = function() {671 var html = this.cloneContents().innerHTML;672 return html.replace(/<.*?>/g, "");673 };674};675KE.cmd = function(id) {676 this.doc = KE.g[id].iframeDoc;677 this.keSel = KE.g[id].keSel;678 this.keRange = KE.g[id].keRange;679 this.mergeAttributes = function(el, attr) {680 for (var i = 0, len = attr.length; i < len; i++) {681 KE.each(attr[i], function(key, value) {682 if (key.charAt(0) == '.') {683 var jsKey = KE.util.getJsKey(key.substr(1));684 el.style[jsKey] = value;685 } else {686 if (KE.browser.IE && KE.browser.VERSION < 8 && key == 'class') key = 'className';687 el.setAttribute(key, value);688 }689 });690 }691 return el;692 };693 this.wrapTextNode = function(node, startPos, endPos, element, attributes) {694 var length = node.nodeValue.length;695 var isFull = (startPos == 0 && endPos == length);696 var range = new KE.range(this.doc);697 range.selectTextNode(node.parentNode);698 if (isFull &&699 node.parentNode.tagName == element.tagName &&700 range.comparePoints('END_TO_END', this.keRange) <= 0 &&701 range.comparePoints('START_TO_START', this.keRange) >= 0) {702 this.mergeAttributes(node.parentNode, attributes);703 return node;704 } else {705 var el = element.cloneNode(true);706 if (isFull) {707 var cloneNode = node.cloneNode(true);708 el.appendChild(cloneNode);709 node.parentNode.replaceChild(el, node);710 return cloneNode;711 } else {712 var centerNode = node;713 if (startPos < endPos) {714 if (startPos > 0) centerNode = node.splitText(startPos);715 if (endPos < length) centerNode.splitText(endPos - startPos);716 var cloneNode = centerNode.cloneNode(true);717 el.appendChild(cloneNode);718 centerNode.parentNode.replaceChild(el, centerNode);719 return cloneNode;720 } else {721 if (startPos < length) {722 centerNode = node.splitText(startPos);723 centerNode.parentNode.insertBefore(el, centerNode);724 } else {725 if (centerNode.nextSibling) {726 centerNode.parentNode.insertBefore(el, centerNode.nextSibling);727 } else {728 centerNode.parentNode.appendChild(el);729 }730 }731 return el;732 }733 }734 }735 };736 this.wrap = function(tagName, attributes) {737 attributes = attributes || [];738 var self = this;739 this.keSel.focus();740 var element = KE.$$(tagName, this.doc);741 this.mergeAttributes(element, attributes);742 var keRange = this.keRange;743 var startNode = keRange.startNode;744 var startPos = keRange.startPos;745 var endNode = keRange.endNode;746 var endPos = keRange.endPos;747 var parentNode = keRange.getParentElement();748 if (KE.util.inMarquee(parentNode)) return;749 var isStarted = false;750 KE.eachNode(parentNode, function(node) {751 if (node == startNode) isStarted = true;752 if (node.nodeType == 1) {753 if (node == startNode && node == endNode) {754 if (KE.util.inArray(node.tagName.toLowerCase(), KE.g[id].noEndTags)) {755 if (startPos > 0) node.parentNode.appendChild(element);756 else node.parentNode.insertBefore(element, node);757 } else {758 node.appendChild(element);759 }760 keRange.selectNode(element);761 return false;762 } else if (node == startNode) {763 keRange.setStart(node, 0);764 } else if (node == endNode) {765 keRange.setEnd(node, 0);766 return false;767 }768 } else if (node.nodeType == 3) {769 if (isStarted) {770 if (node == startNode && node == endNode) {771 var rangeNode = self.wrapTextNode(node, startPos, endPos, element, attributes);772 keRange.selectNode(rangeNode);773 return false;774 } else if (node == startNode) {775 var rangeNode = self.wrapTextNode(node, startPos, node.nodeValue.length, element, attributes);776 keRange.setStart(rangeNode, 0);777 } else if (node == endNode) {778 var rangeNode = self.wrapTextNode(node, 0, endPos, element, attributes);779 keRange.setEnd(rangeNode, rangeNode.nodeType == 1 ? 0 : rangeNode.nodeValue.length);780 return false;781 } else {782 self.wrapTextNode(node, 0, node.nodeValue.length, element, attributes);783 }784 }785 }786 return true;787 });788 this.keSel.addRange(keRange);789 };790 this.getTopParent = function(tagNames, node) {791 var parent = null;792 while (node) {793 node = node.parentNode;794 if (KE.util.inArray(node.tagName.toLowerCase(), tagNames)) {795 parent = node;796 } else {797 break;798 }799 }800 return parent;801 };802 this.splitNodeParent = function(parent, node, pos) {803 var leftRange = new KE.range(this.doc);804 leftRange.selectNode(parent.firstChild);805 leftRange.setEnd(node, pos);806 var leftFrag = leftRange.extractContents();807 parent.parentNode.insertBefore(leftFrag, parent);808 return {left : leftFrag, right : parent};809 };810 this.remove = function(tags) {811 var self = this;812 var keRange = this.keRange;813 var startNode = keRange.startNode;814 var startPos = keRange.startPos;815 var endNode = keRange.endNode;816 var endPos = keRange.endPos;817 this.keSel.focus();818 if (KE.util.inMarquee(keRange.getParentElement())) return;819 var isCollapsed = (keRange.getText().replace(/\s+/g, '') === '');820 if (isCollapsed && !KE.browser.IE) return;821 var tagNames = [];822 KE.each(tags, function(key, val) {823 if (key != '*') tagNames.push(key);824 });825 var startParent = this.getTopParent(tagNames, startNode);826 var endParent = this.getTopParent(tagNames, endNode);827 if (startParent) {828 var startFrags = this.splitNodeParent(startParent, startNode, startPos);829 keRange.setStart(startFrags.right, 0);830 if (startNode == endNode && KE.util.getNodeTextLength(startFrags.right) > 0) {831 keRange.selectNode(startFrags.right);832 var range = new KE.range(this.doc);833 range.selectTextNode(startFrags.left);834 if (startPos > 0) endPos -= range.endNode.nodeValue.length;835 range.selectTextNode(startFrags.right);836 endNode = range.startNode;837 }838 }839 if (isCollapsed) {840 var node = keRange.startNode;841 if (node.nodeType == 1) {842 if (node.nodeName.toLowerCase() == 'br') return;843 keRange.selectNode(node);844 } else {845 return;846 }847 } else if (endParent) {848 var endFrags = this.splitNodeParent(endParent, endNode, endPos);849 keRange.setEnd(endFrags.left, 0);850 if (startParent == endParent) {851 keRange.setStart(endFrags.left, 0);852 }853 }854 var removeAttr = function(node, attr) {855 if (attr.charAt(0) == '.') {856 var jsKey = KE.util.getJsKey(attr.substr(1));857 node.style[jsKey] = '';858 } else {859 if (KE.browser.IE && KE.browser.VERSION < 8 && attr == 'class') attr = 'className';860 node.removeAttribute(attr);861 }862 };863 var nodeList = keRange.getNodeList();864 keRange.setTextStart(keRange.startNode, keRange.startPos);865 keRange.setTextEnd(keRange.endNode, keRange.endPos);866 for (var i = 0, length = nodeList.length; i < length; i++) {867 var node = nodeList[i];868 if (node.nodeType == 1) {869 var tagName = node.tagName.toLowerCase();870 if (tags[tagName]) {871 var attr = tags[tagName];872 for (var j = 0, len = attr.length; j < len; j++) {873 if (attr[j] == '*') {874 KE.util.removeParent(node);875 break;876 } else {877 removeAttr(node, attr[j]);878 var attrs = [];879 if (node.outerHTML) {880 attrHash = KE.util.getAttrList(node.outerHTML);881 KE.each(attrHash, function(key, val) {882 attrs.push({883 name : key,884 value : val885 });886 });887 } else {888 attrs = node.attributes;889 }890 if (attrs.length == 0) {891 KE.util.removeParent(node);892 break;893 } else if (attrs[0].name == 'style' && attrs[0].value === '') {894 KE.util.removeParent(node);895 break;896 }897 }898 }899 }900 if (tags['*']) {901 var attr = tags['*'];902 for (var j = 0, len = attr.length; j < len; j++) {903 removeAttr(node, attr[j]);904 }905 }906 }907 }908 try {909 this.keSel.addRange(keRange);910 } catch(e) {}911 };912};913KE.format = {914 getUrl : function(url, mode, host, pathname) {915 if (!mode) return url;916 mode = mode.toLowerCase();917 if (!KE.util.inArray(mode, ['absolute', 'relative', 'domain'])) return url;918 host = host || location.protocol + '//' + location.host;919 if (pathname === undefined) {920 var m = location.pathname.match(/^(\/.*)\//);921 pathname = m ? m[1] : '';922 }923 var matches = url.match(/^(\w+:\/\/[^\/]*)/);924 if (matches) {925 if (matches[1] !== host) return url;926 } else if (url.match(/^\w+:/)) {927 return url;928 }929 var getRealPath = function(path) {930 var parts = path.split('/');931 paths = [];932 for (var i = 0, len = parts.length; i < len; i++) {933 var part = parts[i];934 if (part == '..') {935 if (paths.length > 0) paths.pop();936 } else if (part !== '' && part != '.') {937 paths.push(part);938 }939 }940 return '/' + paths.join('/');941 };942 if (url.match(/^\//)) {943 url = host + getRealPath(url.substr(1));944 } else if (!url.match(/^\w+:\/\//)) {945 url = host + getRealPath(pathname + '/' + url);946 }947 if (mode == 'relative') {948 var getRelativePath = function(path, depth) {949 if (url.substr(0, path.length) === path) {950 var arr = [];951 for (var i = 0; i < depth; i++) {952 arr.push('..');953 }954 var prefix = '.';955 if (arr.length > 0) prefix += '/' + arr.join('/');956 if (pathname == '/') prefix += '/';957 return prefix + url.substr(path.length);958 } else {959 var m = path.match(/^(.*)\//);960 if (m) {961 return getRelativePath(m[1], ++depth);962 }963 }964 };965 url = getRelativePath(host + pathname, 0).substr(2);966 } else if (mode == 'absolute') {967 if (url.substr(0, host.length) === host) {968 url = url.substr(host.length);969 }970 }971 return url;972 },973 getHtml : function(html, htmlTags, urlType) {974 var isFilter = htmlTags ? true : false;975 html = html.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3){976 return $1 + $2.replace(/<br[^>]*>/ig, '\n') + $3;977 });978 var htmlTagHash = {};979 var fontSizeHash = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];980 if (isFilter) {981 KE.each(htmlTags, function(key, val) {982 var arr = key.split(',');983 for (var i = 0, len = arr.length; i < len; i++) htmlTagHash[arr[i]] = KE.util.arrayToHash(val);984 });985 }986 var noEndTagHash = KE.util.arrayToHash(KE.setting.noEndTags);987 var inlineTagHash = KE.util.arrayToHash(KE.setting.inlineTags);988 var endlineTagHash = KE.util.arrayToHash(KE.setting.endlineTags);989 var re = /((?:\r\n|\n|\r)*)<(\/)?([\w-:]+)((?:\s+|(?:\s+[\w-:]+)|(?:\s+[\w-:]+=[^\s"'<>]+)|(?:\s+[\w-:]+="[^"]*")|(?:\s+[\w-:]+='[^']*'))*)(\/)?>((?:\r\n|\n|\r)*)/g;990 html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {991 var startNewline = $1 || '';992 var startSlash = $2 || '';993 var tagName = $3.toLowerCase();994 var attr = $4 || '';995 var endSlash = $5 ? ' ' + $5 : '';996 var endNewline = $6 || '';997 if (isFilter && typeof htmlTagHash[tagName] == "undefined") return '';998 if (endSlash === '' && typeof noEndTagHash[tagName] != "undefined") endSlash = ' /';999 if (tagName in endlineTagHash) {1000 if (startSlash || endSlash) endNewline = '\n';1001 } else {1002 if (endNewline) endNewline = ' ';1003 }1004 if (tagName !== 'script' && tagName !== 'style') {1005 startNewline = '';1006 }1007 if (tagName === 'font') {1008 var style = {}, styleStr = '';1009 attr = attr.replace(/\s*([\w-:]+)=([^\s"'<>]+|"[^"]*"|'[^']*')/g, function($0, $1, $2) {1010 var key = $1.toLowerCase();1011 var val = $2 || '';1012 val = val.replace(/^["']|["']$/g, '');1013 if (key === 'color') {1014 style['color'] = val;1015 return ' ';1016 }1017 if (key === 'size') {1018 style['font-size'] = fontSizeHash[parseInt(val) - 1] || '';1019 return ' ';1020 }1021 if (key === 'face') {1022 style['font-family'] = val;1023 return ' ';1024 }1025 if (key === 'style') {1026 styleStr = val;1027 return ' ';1028 }1029 return $0;1030 });1031 if (styleStr && !/;$/.test(styleStr)) styleStr += ';';1032 KE.each(style, function(key, val) {1033 if (val !== '') { 1034 if (/\s/.test(val)) val = "'" + val + "'";1035 styleStr += key + ':' + val + ';';1036 }1037 });1038 if (styleStr) attr += ' style="' + styleStr + '"';1039 tagName = 'span';1040 }1041 if (attr !== '') {1042 attr = attr.replace(/\s*([\w-:]+)=([^\s"'<>]+|"[^"]*"|'[^']*')/g, function($0, $1, $2) {1043 var key = $1.toLowerCase();1044 var val = $2 || '';1045 if (isFilter) {1046 if (key.charAt(0) === "." || (key !== "style" && typeof htmlTagHash[tagName][key] == "undefined")) return ' ';1047 }1048 if (val === '') {1049 val = '""';1050 } else {1051 if (key === "style") {1052 val = val.substr(1, val.length - 2);1053 val = val.replace(/\s*([^\s]+?)\s*:(.*?)(;|$)/g, function($0, $1, $2) {1054 var k = $1.toLowerCase();1055 if (isFilter) {1056 if (typeof htmlTagHash[tagName]['style'] == "undefined" && typeof htmlTagHash[tagName]['.' + k] == "undefined") return '';1057 }1058 var v = KE.util.trim($2);1059 v = KE.util.rgbToHex(v);1060 return k + ':' + v + ';';1061 });1062 val = KE.util.trim(val);1063 if (val === '') return '';1064 val = '"' + val + '"';1065 }1066 if (KE.util.inArray(key, ['src', 'href'])) {1067 if (val.charAt(0) === '"') {1068 val = val.substr(1, val.length - 2);1069 }1070 val = KE.format.getUrl(val, urlType);1071 }1072 if (val.charAt(0) !== '"') val = '"' + val + '"';1073 }1074 return ' ' + key + '=' + val + ' ';1075 });1076 attr = attr.replace(/\s+(checked|selected|disabled|readonly)(\s+|$)/ig, function($0, $1) {1077 var key = $1.toLowerCase();1078 if (isFilter) {1079 if (key.charAt(0) === "." || typeof htmlTagHash[tagName][key] == "undefined") return ' ';1080 }1081 return ' ' + key + '="' + key + '"' + ' ';1082 });1083 attr = KE.util.trim(attr);1084 attr = attr.replace(/\s+/g, ' ');1085 if (attr) attr = ' ' + attr;1086 return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;1087 } else {1088 return startNewline + '<' + startSlash + tagName + endSlash + '>' + endNewline;1089 }1090 });1091 if (!KE.browser.IE) {1092 html = html.replace(/<p><br\s+\/>\n<\/p>/ig, '<p>&nbsp;</p>');1093 html = html.replace(/<br\s+\/>\n<\/p>/ig, '</p>');1094 }1095 var reg = KE.setting.inlineTags.join('|');1096 var trimHtml = function(inHtml) {1097 var outHtml = inHtml.replace(new RegExp('<(' + reg + ')[^>]*><\\/(' + reg + ')>', 'ig'), function($0, $1, $2) {1098 if ($1 == $2) return '';1099 else return $0;1100 });1101 if (inHtml !== outHtml) outHtml = trimHtml(outHtml);1102 return outHtml;1103 };1104 return KE.util.trim(trimHtml(html));1105 }1106};1107KE.addClass = function(el, className) {1108 if (typeof el == 'object') {1109 var cls = el.className;1110 if (cls) {1111 if ((' ' + cls + ' ').indexOf(' ' + className + ' ') < 0) {1112 el.className = cls + ' ' + className;1113 }1114 } else {1115 el.className = className;1116 }1117 } else if (typeof el == 'string') {1118 if (/\s+class\s*=/.test(el)) {1119 el = el.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {1120 if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {1121 return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;1122 } else {1123 return $0;1124 }1125 });1126 } else {1127 el = el.substr(0, el.length - 1) + ' class="' + className + '">';1128 }1129 }1130 return el;1131};1132KE.removeClass = function(el, className) {1133 var cls = el.className || '';1134 cls = ' ' + cls + ' ';1135 className = ' ' + className + ' ';1136 if (cls.indexOf(className) >= 0) {1137 cls = KE.util.trim(cls.replace(new RegExp(className, 'ig'), ''));1138 if (cls === '') {1139 var key = el.getAttribute('class') ? 'class' : 'className';1140 el.removeAttribute(key);1141 } else {1142 el.className = cls;1143 }1144 }1145 return el;1146};1147KE.getComputedStyle = function(el, key) {1148 var doc = el.ownerDocument,1149 win = doc.parentWindow || doc.defaultView,1150 jsKey = KE.util.getJsKey(key),1151 val = '';1152 if (win.getComputedStyle) {1153 var style = win.getComputedStyle(el, null);1154 val = style[jsKey] || style.getPropertyValue(key) || el.style[jsKey];1155 } else if (el.currentStyle) {1156 val = el.currentStyle[jsKey] || el.style[jsKey];1157 }1158 return val;1159};1160KE.getCommonAncestor = function(keSel, tagName) {1161 var range = keSel.range,1162 keRange = keSel.keRange,1163 startNode = keRange.startNode,1164 endNode = keRange.endNode;1165 if (KE.util.inArray(tagName, ['table', 'td', 'tr'])) {1166 if (KE.browser.IE) {1167 if (range.item) {1168 if (range.item(0).nodeName.toLowerCase() === tagName) {1169 startNode = endNode = range.item(0);1170 }1171 } else {1172 var rangeA = range.duplicate();1173 rangeA.collapse(true);1174 var rangeB = range.duplicate();1175 rangeB.collapse(false);1176 startNode = rangeA.parentElement();1177 endNode = rangeB.parentElement();1178 }1179 } else {1180 var rangeA = range.cloneRange();1181 rangeA.collapse(true);1182 var rangeB = range.cloneRange();1183 rangeB.collapse(false);1184 startNode = rangeA.startContainer;1185 endNode = rangeB.startContainer;1186 }1187 }1188 function find(node) {1189 while (node) {1190 if (node.nodeType == 1) {1191 if (node.tagName.toLowerCase() === tagName) return node;1192 }1193 node = node.parentNode;1194 }1195 return null;1196 };1197 var start = find(startNode),1198 end = find(endNode);1199 if (start && end && start === end) {1200 return start;1201 }1202 return null;1203};1204KE.queryCommandValue = function(doc, cmd) {1205 cmd = cmd.toLowerCase();1206 function commandValue() {1207 var val = doc.queryCommandValue(cmd);1208 if (typeof val !== 'string') val = '';1209 return val;1210 }1211 var val = '';1212 if (cmd === 'fontname') {1213 val = commandValue();1214 val = val.replace(/['"]/g, '');1215 } else if (cmd === 'formatblock') {1216 val = commandValue();1217 if (val === '') {1218 var keSel = new KE.selection(doc);1219 var el = KE.getCommonAncestor(keSel, 'h1');1220 if (!el) el = KE.getCommonAncestor(keSel, 'h2');1221 if (!el) el = KE.getCommonAncestor(keSel, 'h3');1222 if (!el) el = KE.getCommonAncestor(keSel, 'h4');1223 if (!el) el = KE.getCommonAncestor(keSel, 'p');1224 if (el) val = el.nodeName;1225 }1226 if (val === 'Normal') val = 'p';1227 } else if (cmd === 'fontsize') {1228 var keSel = new KE.selection(doc);1229 var el = KE.getCommonAncestor(keSel, 'span');1230 if (el) val = KE.getComputedStyle(el, 'font-size');1231 } else if (cmd === 'textcolor') {1232 var keSel = new KE.selection(doc);1233 var el = KE.getCommonAncestor(keSel, 'span');1234 if (el) val = KE.getComputedStyle(el, 'color');1235 val = KE.util.rgbToHex(val);1236 if (val === '') val = 'default';1237 } else if (cmd === 'bgcolor') {1238 var keSel = new KE.selection(doc);1239 var el = KE.getCommonAncestor(keSel, 'span');1240 if (el) val = KE.getComputedStyle(el, 'background-color');1241 val = KE.util.rgbToHex(val);1242 if (val === '') val = 'default';1243 }1244 return val.toLowerCase();1245};1246KE.util = {1247 getDocumentElement : function(doc) {1248 doc = doc || document;1249 return (doc.compatMode != "CSS1Compat") ? doc.body : doc.documentElement;1250 },1251 getDocumentHeight : function(doc) {1252 var el = this.getDocumentElement(doc);1253 return Math.max(el.scrollHeight, el.clientHeight);1254 },1255 getDocumentWidth : function(doc) {1256 var el = this.getDocumentElement(doc);1257 return Math.max(el.scrollWidth, el.clientWidth);1258 },1259 createTable : function(doc) {1260 var table = KE.$$('table', doc);1261 table.cellPadding = 0;1262 table.cellSpacing = 0;1263 table.border = 0;1264 return {table: table, cell: table.insertRow(0).insertCell(0)};1265 },1266 loadStyle : function(path) {1267 var link = KE.$$('link');1268 link.setAttribute('type', 'text/css');1269 link.setAttribute('rel', 'stylesheet');1270 link.setAttribute('href', path);1271 document.getElementsByTagName("head")[0].appendChild(link);1272 },1273 getAttrList : function(tag) {1274 var re = /\s+(?:([\w-:]+)|(?:([\w-:]+)=([\w-:]+))|(?:([\w-:]+)="([^"]*)")|(?:([\w-:]+)='([^']*)'))(?=(?:\s|\/|>)+)/g;1275 var arr, key, val, list = {};1276 while ((arr = re.exec(tag))) {1277 key = arr[1] || arr[2] || arr[4] || arr[6];1278 val = arr[1] || (arr[2] ? arr[3] : (arr[4] ? arr[5] : arr[7]));1279 list[key] = val;1280 }1281 return list;1282 },1283 inArray : function(str, arr) {1284 for (var i = 0; i < arr.length; i++) {if (str == arr[i]) return true;}1285 return false;1286 },1287 trim : function(str) {1288 return str.replace(/^\s+|\s+$/g, "");1289 },1290 getJsKey : function(key) {1291 var arr = key.split('-');1292 key = '';1293 for (var i = 0, len = arr.length; i < len; i++) {1294 key += (i > 0) ? arr[i].charAt(0).toUpperCase() + arr[i].substr(1) : arr[i];1295 }1296 return key;1297 },1298 arrayToHash : function(arr) {1299 var hash = {};1300 for (var i = 0, len = arr.length; i < len; i++) hash[arr[i]] = 1;1301 return hash;1302 },1303 escape : function(str) {1304 str = str.replace(/&/g, '&amp;');1305 str = str.replace(/</g, '&lt;');1306 str = str.replace(/>/g, '&gt;');1307 str = str.replace(/"/g, '&quot;');1308 return str;1309 },1310 unescape : function(str) {1311 str = str.replace(/&lt;/g, '<');1312 str = str.replace(/&gt;/g, '>');1313 str = str.replace(/&quot;/g, '"');1314 str = str.replace(/&amp;/g, '&');1315 return str;1316 },1317 getScrollPos : function() {1318 var x, y;1319 if (KE.browser.IE || KE.browser.OPERA) {1320 var el = this.getDocumentElement();1321 x = el.scrollLeft;1322 y = el.scrollTop;1323 } else {1324 x = window.scrollX;1325 y = window.scrollY;1326 }1327 return {x : x, y : y};1328 },1329 getElementPos : function(el) {1330 var x = 0, y = 0;1331 if (el.getBoundingClientRect) {1332 var box = el.getBoundingClientRect();1333 var pos = this.getScrollPos();1334 x = box.left + pos.x;1335 y = box.top + pos.y;1336 } else {1337 x = el.offsetLeft;1338 y = el.offsetTop;1339 var parent = el.offsetParent;1340 while (parent) {1341 x += parent.offsetLeft;1342 y += parent.offsetTop;1343 parent = parent.offsetParent;1344 }1345 }1346 return {x : x, y : y};1347 },1348 getCoords : function(ev) {1349 ev = ev || window.event;1350 return {1351 x : ev.clientX,1352 y : ev.clientY1353 };1354 },1355 setOpacity : function(el, opacity) {1356 if (typeof el.style.opacity == "undefined") {1357 el.style.filter = (opacity == 100) ? "" : "alpha(opacity=" + opacity + ")";1358 } else {1359 el.style.opacity = (opacity == 100) ? "" : "0." + opacity.toString();1360 }1361 },1362 getIframeDoc : function(iframe) {1363 return iframe.contentDocument || iframe.contentWindow.document;1364 },1365 rgbToHex : function(str) {1366 function hex(s) {1367 s = parseInt(s).toString(16);1368 return s.length > 1 ? s : '0' + s;1369 };1370 return str.replace(/rgb\s*?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?\)/ig,1371 function($0, $1, $2, $3) {1372 return '#' + hex($1) + hex($2) + hex($3);1373 }1374 );1375 },1376 parseJson : function (text) {1377 var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;1378 cx.lastIndex = 0;1379 if (cx.test(text)) {1380 text = text.replace(cx, function (a) {1381 return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);1382 });1383 }1384 if (/^[\],:{}\s]*$/.1385 test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').1386 replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').1387 replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {1388 return eval('(' + text + ')');1389 }1390 throw 'JSON parse error';1391 },1392 createRange : function(doc) {1393 return doc.createRange ? doc.createRange() : doc.body.createTextRange();1394 },1395 getNodeType : function(node) {1396 return (node.nodeType == 1 && KE.util.inArray(node.tagName.toLowerCase(), KE.setting.noEndTags)) ? 88 : node.nodeType;1397 },1398 inMarquee : function(node) {1399 var n = node;1400 while (n) {1401 if (n.nodeName.toLowerCase() === 'marquee') return true;1402 n = n.parentNode;1403 }1404 return false;1405 },1406 moveToElementText : function (range, el) {1407 if (!this.inMarquee(el)) range.moveToElementText(el);1408 },1409 getNodeTextLength : function(node) {1410 var type = KE.util.getNodeType(node);1411 if (type == 1) {1412 var html = node.innerHTML;1413 return html.replace(/<.*?>/ig, "").length;1414 } else if (type == 3) {1415 return node.nodeValue.length;1416 }1417 },1418 getNodeStartRange : function(doc, node) {1419 var range = KE.util.createRange(doc);1420 var type = node.nodeType;1421 if (type == 1) {1422 KE.util.moveToElementText(range, node);1423 return range;1424 } else if (type == 3) {1425 var offset = 0;1426 var sibling = node.previousSibling;1427 while (sibling) {1428 if (sibling.nodeType == 1) {1429 var nodeRange = KE.util.createRange(doc);1430 KE.util.moveToElementText(nodeRange, sibling);1431 range.setEndPoint('StartToEnd', nodeRange);1432 range.moveStart('character', offset);1433 return range;1434 } else if (sibling.nodeType == 3) {1435 offset += sibling.nodeValue.length;1436 }1437 sibling = sibling.previousSibling;1438 }1439 KE.util.moveToElementText(range, node.parentNode);1440 range.moveStart('character', offset);1441 return range;1442 }1443 },1444 removeParent : function(parent) {1445 if (parent.hasChildNodes) {1446 var node = parent.firstChild;1447 while (node) {1448 var nextNode = node.nextSibling;1449 parent.parentNode.insertBefore(node, parent);1450 node = nextNode;1451 }1452 }1453 parent.parentNode.removeChild(parent);1454 },1455 pluginLang : function(pluginName, doc) {1456 KE.each(KE.lang.plugins[pluginName], function (key, val) {1457 var span = KE.$('lang.' + key, doc);1458 if (span) {1459 span.parentNode.insertBefore(doc.createTextNode(val), span);1460 span.parentNode.removeChild(span);1461 }1462 });1463 },1464 drag : function(id, mousedownObj, moveObj, func) {1465 var g = KE.g[id];1466 mousedownObj.onmousedown = function(e) {1467 var self = this;1468 e = e || window.event;1469 var pos = KE.util.getCoords(e);1470 var objTop = parseInt(moveObj.style.top);1471 var objLeft = parseInt(moveObj.style.left);1472 var objWidth = moveObj.style.width;1473 var objHeight = moveObj.style.height;1474 if (objWidth.match(/%$/)) objWidth = moveObj.offsetWidth + 'px';1475 if (objHeight.match(/%$/)) objHeight = moveObj.offsetHeight + 'px';1476 objWidth = parseInt(objWidth);1477 objHeight = parseInt(objHeight);1478 var mouseTop = pos.y;1479 var mouseLeft = pos.x;1480 var scrollPos = KE.util.getScrollPos();1481 var scrollTop = scrollPos.y;1482 var scrollLeft = scrollPos.x;1483 var dragFlag = true;1484 function moveListener(e) {1485 if (dragFlag) {1486 var pos = KE.util.getCoords(e);1487 var scrollPos = KE.util.getScrollPos();1488 var top = parseInt(pos.y - mouseTop - scrollTop + scrollPos.y);1489 var left = parseInt(pos.x - mouseLeft - scrollLeft + scrollPos.x);1490 func(objTop, objLeft, objWidth, objHeight, top, left);1491 }1492 }1493 var iframePos = KE.util.getElementPos(g.iframe);1494 function iframeMoveListener(e) {1495 if (dragFlag) {1496 var pos = KE.util.getCoords(e, g.iframeDoc);1497 var top = parseInt(iframePos.y + pos.y - mouseTop - scrollTop);1498 var left = parseInt(iframePos.x + pos.x - mouseLeft - scrollLeft);1499 func(objTop, objLeft, objWidth, objHeight, top, left);1500 }1501 }1502 var selectListener = function() { return false; };1503 function upListener(e) {1504 dragFlag = false;1505 if (self.releaseCapture) self.releaseCapture();1506 KE.event.remove(document, 'mousemove', moveListener);1507 KE.event.remove(document, 'mouseup', upListener);1508 KE.event.remove(g.iframeDoc, 'mousemove', iframeMoveListener);1509 KE.event.remove(g.iframeDoc, 'mouseup', upListener);1510 KE.event.remove(document, 'selectstart', selectListener);1511 KE.event.stop(e);1512 return false;1513 }1514 KE.event.add(document, 'mousemove', moveListener);1515 KE.event.add(document, 'mouseup', upListener);1516 KE.event.add(g.iframeDoc, 'mousemove', iframeMoveListener);1517 KE.event.add(g.iframeDoc, 'mouseup', upListener);1518 KE.event.add(document, 'selectstart', selectListener);1519 if (self.setCapture) self.setCapture();1520 KE.event.stop(e);1521 return false;1522 };1523 },1524 resize : function(id, width, height, isCheck, isResizeWidth) {1525 isResizeWidth = (typeof isResizeWidth == "undefined") ? true : isResizeWidth;1526 var g = KE.g[id];1527 if (!g.container) return;1528 if (isCheck && (parseInt(width) <= g.minWidth || parseInt(height) <= g.minHeight)) return;1529 if (isResizeWidth) g.container.style.width = width;1530 g.container.style.height = height;1531 var diff = parseInt(height) - g.toolbarHeight - g.statusbarHeight;1532 if (diff >= 0) {1533 g.iframe.style.height = diff + 'px';1534 g.newTextarea.style.height = (((KE.browser.IE && KE.browser.VERSION < 8) || document.compatMode != 'CSS1Compat') ? diff - 2 : diff) + 'px';1535 }1536 },1537 hideLoadingPage : function(id) {1538 var stack = KE.g[id].dialogStack;1539 var dialog = stack[stack.length - 1];1540 dialog.loading.style.display = 'none';1541 dialog.iframe.style.display = '';1542 },1543 showLoadingPage : function(id) {1544 var stack = KE.g[id].dialogStack;1545 var dialog = stack[stack.length - 1];1546 dialog.loading.style.display = '';1547 dialog.iframe.style.display = 'none';1548 },1549 setDefaultPlugin : function(id) {1550 var items = [1551 'selectall', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',1552 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',1553 'superscript', 'bold', 'italic', 'underline', 'strikethrough'1554 ];1555 var shortcuts = {1556 bold : 'B',1557 italic : 'I',1558 underline : 'U'1559 };1560 for (var i = 0; i < items.length; i++) {1561 var item = items[i],1562 plugin = {};1563 if (item in shortcuts) {1564 plugin.init = (function(item) {1565 return function(id) {1566 KE.event.ctrl(KE.g[id].iframeDoc, shortcuts[item], function(e) {1567 KE.plugin[item].click(id);1568 KE.util.focus(id);1569 }, id);1570 };1571 })(item);1572 }1573 plugin.click = (function(item) {1574 return function(id) {1575 KE.util.execCommand(id, item, null);1576 };1577 })(item);1578 KE.plugin[item] = plugin;1579 }1580 },1581 getFullHtml : function(id) {1582 var html = '<html>';1583 html += '<head>';1584 html += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';1585 html += '<title>KindEditor</title>';1586 html += '<link href="' + KE.g[id].skinsPath + 'common/editor.css?ver=' + escape(KE.version) + '" rel="stylesheet" type="text/css" />';1587 var cssPath = KE.g[id].cssPath;1588 if (typeof cssPath == 'string') cssPath = [cssPath];1589 for (var i = 0, len = cssPath.length; i < len; i++) {1590 if (cssPath[i] !== '') html += '<link href="' + cssPath[i] + '" rel="stylesheet" type="text/css" />';1591 }1592 html += '</head>';1593 html += '<body class="ke-content"></body>';1594 html += '</html>';1595 return html;1596 },1597 getMediaType : function(src) {1598 if (src.match(/\.(rm|rmvb)(\?|$)/i)) return 'rm';1599 else if (src.match(/\.(swf|flv)(\?|$)/i)) return 'flash';1600 else return 'media';1601 },1602 getMediaImage : function(id, type, attrs) {1603 var width = attrs.width;1604 var height = attrs.height;1605 type = type || this.getMediaType(attrs.src);1606 var srcTag = this.getMediaEmbed(attrs);1607 var style = '';1608 if (width > 0) style += 'width:' + width + 'px;';1609 if (height > 0) style += 'height:' + height + 'px;';1610 var className = 'ke-' + type;1611 var html = '<img class="' + className + '" src="' + KE.g[id].skinsPath + 'common/blank.gif" ';1612 if (style !== '') html += 'style="' + style + '" ';1613 html += 'kesrctag="' + escape(srcTag) + '" alt="" />';1614 return html;1615 },1616 getMediaEmbed : function(attrs) {1617 var html = '<embed ';1618 KE.each(attrs, function(key, val) {1619 html += key + '="' + val + '" ';1620 });1621 html += '/>';1622 return html;1623 },1624 execGetHtmlHooks : function(id, html) {1625 var hooks = KE.g[id].getHtmlHooks;1626 for (var i = 0, len = hooks.length; i < len; i++) {1627 html = hooks[i](html);1628 }1629 return html;1630 },1631 execSetHtmlHooks : function(id, html) {1632 var hooks = KE.g[id].setHtmlHooks;1633 for (var i = 0, len = hooks.length; i < len; i++) {1634 html = hooks[i](html);1635 }1636 return html;1637 },1638 execOnchangeHandler : function(id) {1639 var handlers = KE.g[id].onchangeHandlerStack;1640 for (var i = 0, len = handlers.length; i < len; i++) {1641 handlers[i]();1642 }1643 },1644 toData : function(id, srcData) {1645 var g = KE.g[id];1646 var html = this.execGetHtmlHooks(id, srcData);1647 html = html.replace(/^\s*<br[^>]*>\s*$/ig, '');1648 html = html.replace(/^\s*<p>\s*&nbsp;\s*<\/p>\s*$/ig, '');1649 if (g.filterMode) {1650 return KE.format.getHtml(html, g.htmlTags, g.urlType);1651 } else {1652 return KE.format.getHtml(html, null, g.urlType);1653 }1654 },1655 getData : function(id, wyswygMode) {1656 var g = KE.g[id];1657 wyswygMode = (wyswygMode === undefined) ? g.wyswygMode : wyswygMode;1658 if (!wyswygMode) {1659 this.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, g.newTextarea.value));1660 }1661 return this.toData(id, g.iframeDoc.body.innerHTML);1662 },1663 getSrcData : function(id) {1664 var g = KE.g[id];1665 if (!g.wyswygMode) {1666 this.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, g.newTextarea.value));1667 }1668 return g.iframeDoc.body.innerHTML;1669 },1670 getPureData : function(id) {1671 return this.extractText(this.getData(id));1672 },1673 extractText : function(str) {1674 str = str.replace(/<(?!img|embed).*?>/ig, '');1675 str = str.replace(/&nbsp;/ig, ' ');1676 return str;1677 },1678 isEmpty : function(id) {1679 return this.getPureData(id).replace(/\r\n|\n|\r/, '').replace(/^\s+|\s+$/, '') === '';1680 },1681 setData : function(id) {1682 var g = KE.g[id];1683 if (g.srcTextarea) g.srcTextarea.value = this.getData(id);1684 },1685 focus : function(id) {1686 var g = KE.g[id];1687 if (g.wyswygMode) {1688 g.iframeWin.focus();1689 } else {1690 g.newTextarea.focus();1691 }1692 },1693 click : function(id, cmd) {1694 this.focus(id);1695 KE.hideMenu(id);1696 KE.plugin[cmd].click(id);1697 },1698 selection : function(id) {1699 if (!KE.browser.IE || !KE.g[id].keRange) {1700 this.setSelection(id);1701 }1702 },1703 setSelection : function(id) {1704 var g = KE.g[id];1705 var keSel = new KE.selection(g.iframeDoc);1706 if (!KE.browser.IE || keSel.range.item || keSel.range.parentElement().ownerDocument === g.iframeDoc) {1707 g.keSel = keSel;1708 g.keRange = g.keSel.keRange;1709 g.sel = g.keSel.sel;1710 g.range = g.keSel.range;1711 }1712 },1713 select : function(id) {1714 if (KE.browser.IE && KE.g[id].wyswygMode && KE.g[id].range) KE.g[id].range.select();1715 },1716 execCommand : function(id, cmd, value) {1717 KE.util.focus(id);1718 KE.util.select(id);1719 try {1720 KE.g[id].iframeDoc.execCommand(cmd, false, value);1721 } catch(e) {}1722 KE.toolbar.updateState(id);1723 KE.util.execOnchangeHandler(id);1724 },1725 innerHtml : function(el, html) {1726 if (KE.browser.IE) {1727 el.innerHTML = '<img id="__ke_temp_tag__" width="0" height="0" />' + html;1728 var temp = KE.$('__ke_temp_tag__', el.ownerDocument);1729 if (temp) temp.parentNode.removeChild(temp);1730 } else {1731 el.innerHTML = html;1732 }1733 },1734 pasteHtml : function(id, html, isStart) {1735 var g = KE.g[id];1736 var imgStr = '<img id="__ke_temp_tag__" width="0" height="0" />';1737 if (isStart) html = imgStr + html;1738 else html += imgStr;1739 if (KE.browser.IE) {1740 if (g.range.item) g.range.item(0).outerHTML = html;1741 else g.range.pasteHTML(html);1742 } else {1743 g.range.deleteContents();1744 var frag = g.range.createContextualFragment(html);1745 g.range.insertNode(frag);1746 }1747 var node = KE.$('__ke_temp_tag__', g.iframeDoc);1748 var blank = g.iframeDoc.createTextNode('');1749 node.parentNode.replaceChild(blank, node);1750 g.keRange.selectNode(blank);1751 g.keSel.addRange(g.keRange);1752 },1753 insertHtml : function(id, html) {1754 if (html === '') return;1755 var g = KE.g[id];1756 if (!g.wyswygMode) return;1757 if (!g.range) return;1758 html = this.execSetHtmlHooks(id, html);1759 if (KE.browser.IE) {1760 this.select(id);1761 if (g.range.item) {1762 try {1763 g.range.item(0).outerHTML = html;1764 } catch(e) {1765 var el = g.range.item(0);1766 var parent = el.parentNode;1767 parent.removeChild(el);1768 if (parent.nodeName.toLowerCase() != 'body') parent = parent.parentNode;1769 this.innerHtml(parent, html + parent.innerHTML);1770 }1771 } else {1772 g.range.pasteHTML(html);1773 }1774 } else if (KE.browser.GECKO && KE.browser.VERSION < 3) {1775 this.execCommand(id, 'inserthtml', html);1776 return;1777 } else {1778 this.pasteHtml(id, html);1779 }1780 KE.util.execOnchangeHandler(id);1781 },1782 setFullHtml : function(id, html) {1783 var g = KE.g[id];1784 if (!KE.browser.IE && html === '') html = '<br />';1785 var html = KE.util.execSetHtmlHooks(id, html);1786 this.innerHtml(g.iframeDoc.body, html);1787 if (!g.wyswygMode) g.newTextarea.value = KE.util.getData(id, true);1788 KE.util.execOnchangeHandler(id);1789 },1790 selectImageWebkit : function(id, e, isSelection) {1791 if (KE.browser.WEBKIT) {1792 var target = e.srcElement || e.target;1793 if (target.tagName.toLowerCase() == 'img') {1794 if (isSelection) KE.util.selection(id);1795 var range = KE.g[id].keRange;1796 range.selectNode(target);1797 KE.g[id].keSel.addRange(range);1798 }1799 }1800 },1801 addTabEvent : function(id) {1802 KE.event.add(KE.g[id].iframeDoc, 'keydown', function(e) {1803 if (e.keyCode == 9) {1804 KE.util.setSelection(id);1805 KE.util.insertHtml(id, '&nbsp;&nbsp;&nbsp;&nbsp;');1806 KE.event.stop(e);1807 return false;1808 }1809 }, id);1810 },1811 addContextmenuEvent : function(id) {1812 var g = KE.g[id];1813 if (g.contextmenuItems.length == 0) return;1814 KE.event.add(g.iframeDoc, 'contextmenu', function(e){1815 KE.hideMenu(id);1816 KE.util.setSelection(id);1817 KE.util.selectImageWebkit(id, e, false);1818 var maxWidth = 0;1819 var items = [];1820 for (var i = 0, len = g.contextmenuItems.length; i < len; i++) {1821 var item = g.contextmenuItems[i];1822 if (item === '-') {1823 items.push(item);1824 } else if (item.cond && item.cond(id)) {1825 items.push(item);1826 if (item.options) {1827 var width = parseInt(item.options.width) || 0;1828 if (width > maxWidth) maxWidth = width;1829 }1830 }1831 prevItem = item;1832 }1833 while (items.length > 0 && items[0] === '-') {1834 items.shift();1835 }1836 while (items.length > 0 && items[items.length - 1] === '-') {1837 items.pop();1838 }1839 var prevItem = null;1840 for (var i = 0, len = items.length; i < len; i++) {1841 if (items[i] === '-' && prevItem === '-') delete items[i];1842 prevItem = items[i] || null;1843 }1844 if (items.length > 0) {1845 var menu = new KE.menu({1846 id : id,1847 event : e,1848 type : 'contextmenu',1849 width : maxWidth1850 });1851 for (var i = 0, len = items.length; i < len; i++) {1852 var item = items[i];1853 if (!item) continue;1854 if (item === '-') {1855 if (i < len - 1) menu.addSeparator();1856 } else {1857 menu.add(item.text, (function(item) {1858 return function() {1859 item.click(id, menu);1860 };1861 })(item), item.options);1862 }1863 }1864 menu.show();1865 KE.event.stop(e);1866 return false;1867 }1868 return true;1869 }, id);1870 },1871 addNewlineEvent : function(id) {1872 var g = KE.g[id];1873 if (KE.browser.IE && g.newlineTag.toLowerCase() != 'br') return;1874 if (KE.browser.GECKO && KE.browser.VERSION < 3 && g.newlineTag.toLowerCase() != 'p') return;1875 if (KE.browser.OPERA) return;1876 KE.event.add(g.iframeDoc, 'keydown', function(e) {1877 if (e.keyCode != 13 || e.shiftKey || e.ctrlKey || e.altKey) return true;1878 KE.util.setSelection(id);1879 var parent = g.keRange.getParentElement();1880 if (KE.util.inMarquee(parent)) return;1881 var tagName = parent.tagName.toLowerCase();1882 if (g.newlineTag.toLowerCase() == 'br') {1883 if (!KE.util.inArray(tagName, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li'])) {1884 KE.util.pasteHtml(id, '<br />');1885 var nextNode = g.keRange.startNode.nextSibling;1886 if (KE.browser.IE) {1887 if (!nextNode) KE.util.pasteHtml(id, '<br />', true);1888 } else if (KE.browser.WEBKIT) {1889 if (!nextNode) {1890 KE.util.pasteHtml(id, '<br />', true);1891 } else {1892 var range = new KE.range(g.iframeDoc);1893 range.selectNode(nextNode.parentNode);1894 range.setStart(nextNode, 0);1895 if (range.cloneContents().innerHTML.replace(/<(?!img|embed).*?>/ig, '') === '') {1896 KE.util.pasteHtml(id, '<br />', true);1897 }1898 }1899 }1900 KE.event.stop(e);1901 return false;1902 }1903 } else {1904 if (!KE.util.inArray(tagName, ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'div', 'li'])) {1905 KE.util.execCommand(id, 'formatblock', '<P>');1906 }1907 }1908 return true;1909 }, id);1910 }1911};1912KE.layout = {1913 hide : function(id) {1914 var g = KE.g[id];1915 KE.hideMenu(id);1916 var stack = g.dialogStack;1917 while (stack.length > 0) {1918 var dialog = stack[stack.length - 1];1919 dialog.hide();1920 }1921 g.maskDiv.style.display = 'none';1922 }1923};1924KE.hideMenu = function(id) {1925 var g = KE.g[id];1926 g.hideDiv.innerHTML = '';1927 g.hideDiv.style.display = 'none';1928};1929KE.colorpicker = function(arg) {1930 var wrapper;1931 var x = arg.x || 0;1932 var y = arg.y || 0;1933 var z = arg.z || 0;1934 var colors = arg.colors || KE.setting.colorTable;1935 var doc = arg.doc || document;1936 var onclick = arg.onclick;1937 var selectedColor = (arg.selectedColor || '').toLowerCase();1938 function init() {1939 wrapper = KE.$$('div');1940 wrapper.className = 'ke-colorpicker';1941 wrapper.style.top = y + 'px';1942 wrapper.style.left = x + 'px';1943 wrapper.style.zIndex = z;1944 }1945 init.call(this);1946 this.remove = function() {1947 doc.body.removeChild(wrapper);1948 };1949 this.getElement = function() {1950 function addAttr(cell, color, cls) {1951 if (selectedColor === color.toLowerCase()) cls += ' ke-colorpicker-cell-selected';1952 cell.className = cls;1953 cell.title = color || KE.lang['noColor'];1954 cell.onmouseover = function() { this.className = cls + ' ke-colorpicker-cell-on'; };1955 cell.onmouseout = function() { this.className = cls; };1956 cell.onclick = function() { onclick(color); };1957 if (color) {1958 var div = KE.$$('div');1959 div.className = 'ke-colorpicker-cell-color';1960 div.style.backgroundColor = color;1961 cell.appendChild(div);1962 } else {1963 cell.innerHTML = KE.lang['noColor'];1964 }1965 }1966 var table = KE.$$('table');1967 table.className = 'ke-colorpicker-table';1968 table.cellPadding = 0;1969 table.cellSpacing = 0;1970 table.border = 0;1971 var row = table.insertRow(0),1972 cell = row.insertCell(0);1973 cell.colSpan = colors[0].length;1974 addAttr(cell, '', 'ke-colorpicker-cell-top');1975 for (var i = 0; i < colors.length; i++) {1976 var row = table.insertRow(i + 1);1977 for (var j = 0; j < colors[i].length; j++) {1978 var color = colors[i][j],1979 cell = row.insertCell(j);1980 addAttr(cell, color, 'ke-colorpicker-cell');1981 }1982 }1983 return table;1984 };1985 this.create = function() {1986 wrapper.appendChild(this.getElement());1987 KE.event.bind(wrapper, 'click', function(e){});1988 KE.event.bind(wrapper, 'mousedown', function(e){});1989 doc.body.appendChild(wrapper);1990 };1991};1992KE.menu = function(arg){1993 function getPos(width, height) {1994 var id = arg.id;1995 var x = 0;1996 var y = 0;1997 if (this.type == 'menu') {1998 var obj = KE.g[id].toolbarIcon[arg.cmd];1999 var pos = KE.util.getElementPos(obj[0]);2000 x = pos.x;2001 y = pos.y + obj[0].offsetHeight;2002 } else {2003 var pos = KE.util.getCoords(arg.event);2004 var iframePos = KE.util.getElementPos(KE.g[id].iframe);2005 x = pos.x + iframePos.x;2006 y = pos.y + iframePos.y + 5;2007 }2008 if (width > 0 || height > 0) {2009 var scrollPos = KE.util.getScrollPos();2010 var docEl = KE.util.getDocumentElement();2011 var maxLeft = scrollPos.x + docEl.clientWidth - width - 2;2012 if (x > maxLeft) x = maxLeft;2013 }2014 return {x : x, y : y};2015 };2016 function init() {2017 var width = arg.width;2018 this.type = (arg.type && arg.type == 'contextmenu') ? arg.type : 'menu';2019 var div = KE.$$('div');2020 div.className = 'ke-' + this.type;2021 div.setAttribute('name', arg.cmd);2022 var pos = getPos.call(this, 0, 0);2023 div.style.top = pos.y + 'px';2024 div.style.left = pos.x + 'px';2025 if (arg.width) div.style.width = (/^\d+$/.test(width)) ? width + 'px' : width;2026 KE.event.bind(div, 'click', function(e){}, arg.id);2027 KE.event.bind(div, 'mousedown', function(e){}, arg.id);2028 this.div = div;2029 };2030 init.call(this);2031 this.add = function(html, event, options) {2032 var height, iconHtml, checked = false;2033 if (options !== undefined) {2034 height = options.height;2035 iconHtml = options.iconHtml;2036 checked = options.checked;2037 }2038 var self = this;2039 var cDiv = KE.$$('div');2040 cDiv.className = 'ke-' + self.type + '-item';2041 if (height) cDiv.style.height = height;2042 var left = KE.$$('div');2043 left.className = 'ke-' + this.type + '-left';2044 var center = KE.$$('div');2045 center.className = 'ke-' + self.type + '-center';2046 if (height) center.style.height = height;2047 var right = KE.$$('div');2048 right.className = 'ke-' + this.type + '-right';2049 if (height) right.style.lineHeight = height;2050 cDiv.onmouseover = function() {2051 this.className = 'ke-' + self.type + '-item ke-' + self.type + '-item-on';2052 center.className = 'ke-' + self.type + '-center ke-' + self.type + '-center-on';2053 };2054 cDiv.onmouseout = function() {2055 this.className = 'ke-' + self.type + '-item';2056 center.className = 'ke-' + self.type + '-center';2057 };2058 cDiv.onclick = event;2059 cDiv.appendChild(left);2060 cDiv.appendChild(center);2061 cDiv.appendChild(right);2062 if (checked) {2063 KE.util.innerHtml(left, '<span class="ke-common-icon ke-common-icon-url ke-icon-checked"></span>');2064 } else {2065 if (iconHtml) KE.util.innerHtml(left, iconHtml);2066 }2067 KE.util.innerHtml(right, html);2068 this.append(cDiv);2069 };2070 this.addSeparator = function() {2071 var div = KE.$$('div');2072 div.className = 'ke-' + this.type + '-separator';2073 this.append(div);2074 };2075 this.append = function(el) {2076 this.div.appendChild(el);2077 };2078 this.insert = function(html) {2079 KE.util.innerHtml(this.div, html);2080 };2081 this.hide = function() {2082 KE.hideMenu(arg.id);2083 };2084 this.show = function() {2085 this.hide();2086 var id = arg.id;2087 KE.g[id].hideDiv.style.display = '';2088 KE.g[id].hideDiv.appendChild(this.div);2089 var pos = getPos.call(this, this.div.clientWidth, this.div.clientHeight);2090 this.div.style.top = pos.y + 'px';2091 this.div.style.left = pos.x + 'px';2092 };2093 this.picker = function(color) {2094 var colorTable = KE.g[arg.id].colorTable;2095 var picker = new KE.colorpicker({2096 colors : colorTable,2097 onclick : function(color) { KE.plugin[arg.cmd].exec(arg.id, color); },2098 selectedColor : color2099 });2100 this.append(picker.getElement());2101 this.show();2102 };2103};2104KE.dialog = function(arg){2105 var self = this;2106 this.widthMargin = 30;2107 this.heightMargin = 100;2108 this.zIndex = 19811214;2109 this.width = arg.width;2110 this.height = arg.height;2111 var minTop, minLeft;2112 function setLimitNumber() {2113 var docEl = KE.util.getDocumentElement();2114 var pos = KE.util.getScrollPos();2115 minTop = pos.y;2116 minLeft = pos.x;2117 }2118 function init() {2119 this.beforeHide = arg.beforeHide;2120 this.afterHide = arg.afterHide;2121 this.beforeShow = arg.beforeShow;2122 this.afterShow = arg.afterShow;2123 this.ondrag = arg.ondrag;2124 }2125 init.call(this);2126 function getPos() {2127 var width = this.width + this.widthMargin;2128 var height = this.height + this.heightMargin;2129 var id = arg.id;2130 var g = KE.g[id];2131 var x = 0, y = 0;2132 if (g.dialogAlignType == 'page') {2133 var el = KE.util.getDocumentElement();2134 var scrollPos = KE.util.getScrollPos();2135 x = Math.round(scrollPos.x + (el.clientWidth - width) / 2);2136 y = Math.round(scrollPos.y + (el.clientHeight - height) / 2);2137 } else {2138 var pos = KE.util.getElementPos(KE.g[id].container);2139 var el = g.container;2140 var xDiff = Math.round(el.clientWidth / 2) - Math.round(width / 2);2141 var yDiff = Math.round(el.clientHeight / 2) - Math.round(height / 2);2142 x = xDiff < 0 ? pos.x : pos.x + xDiff;2143 y = yDiff < 0 ? pos.y : pos.y + yDiff;2144 }2145 x = x < 0 ? 0 : x;2146 y = y < 0 ? 0 : y;2147 return {x : x, y : y};2148 };2149 this.resize = function(width, height) {2150 if (width) this.width = width;2151 if (height) this.height = height;2152 this.hide();2153 this.show();2154 };2155 this.hide = function() {2156 if (this.beforeHide) this.beforeHide(id);2157 var id = arg.id;2158 var stack = KE.g[id].dialogStack;2159 if (stack[stack.length - 1] != this) return;2160 var dialog = stack.pop();2161 var iframe = dialog.iframe;2162 iframe.src = 'javascript:false';2163 iframe.parentNode.removeChild(iframe);2164 document.body.removeChild(this.div);2165 if (stack.length < 1) {2166 KE.g[id].maskDiv.style.display = 'none';2167 }2168 KE.event.remove(window, 'resize', setLimitNumber);2169 KE.event.remove(window, 'scroll', setLimitNumber);2170 if (this.afterHide) this.afterHide(id);2171 KE.util.focus(id);2172 };2173 this.show = function() {2174 if (this.beforeShow) this.beforeShow(id);2175 var self = this;2176 var id = arg.id;2177 var div = KE.$$('div');2178 div.className = 'ke-dialog';2179 KE.event.bind(div, 'click', function(e){}, id);2180 KE.event.bind(div, 'mousedown', function(e){}, id);2181 var stack = KE.g[id].dialogStack;2182 if (stack.length > 0) {2183 this.zIndex = stack[stack.length - 1].zIndex + 1;2184 }2185 div.style.zIndex = this.zIndex;2186 var pos = getPos.call(this);2187 div.style.top = pos.y + 'px';2188 div.style.left = pos.x + 'px';2189 var contentCell;2190 if (KE.g[id].shadowMode) {2191 var table = KE.$$('table');2192 table.className = 'ke-dialog-table';2193 table.cellPadding = 0;2194 table.cellSpacing = 0;2195 table.border = 0;2196 var rowNames = ['t', 'm', 'b'];2197 var colNames = ['l', 'c', 'r'];2198 for (var i = 0, len = 3; i < len; i++) {2199 var row = table.insertRow(i);2200 for (var j = 0, l = 3; j < l; j++) {2201 var cell = row.insertCell(j);2202 cell.className = 'ke-' + rowNames[i] + colNames[j];2203 if (i == 1 && j == 1) contentCell = cell;2204 else cell.innerHTML = '<span class="ke-dialog-empty"></span>';2205 }2206 }2207 div.appendChild(table);2208 } else {2209 KE.addClass(div, 'ke-dialog-no-shadow');2210 contentCell = div;2211 }2212 var titleDiv = KE.$$('div');2213 titleDiv.className = 'ke-dialog-title';2214 titleDiv.innerHTML = arg.title;2215 var span = KE.$$('span');2216 span.className = 'ke-dialog-close';2217 if (KE.g[id].shadowMode) KE.addClass(span, 'ke-dialog-close-shadow');2218 else KE.addClass(span, 'ke-dialog-close-no-shadow');2219 span.alt = KE.lang['close'];2220 span.title = KE.lang['close'];2221 span.onclick = function () {2222 self.hide();2223 KE.util.select(id);2224 };2225 titleDiv.appendChild(span);2226 setLimitNumber();2227 KE.event.add(window, 'resize', setLimitNumber);2228 KE.event.add(window, 'scroll', setLimitNumber);2229 KE.util.drag(id, titleDiv, div, function(objTop, objLeft, objWidth, objHeight, top, left) {2230 if (self.ondrag) self.ondrag(id);2231 setLimitNumber();2232 top = objTop + top;2233 left = objLeft + left;2234 if (top < minTop) top = minTop;2235 if (left < minLeft) left = minLeft;2236 div.style.top = top + 'px';2237 div.style.left = left + 'px';2238 });2239 contentCell.appendChild(titleDiv);2240 var bodyDiv = KE.$$('div');2241 bodyDiv.className = 'ke-dialog-body';2242 var loadingTable = KE.util.createTable();2243 loadingTable.table.className = 'ke-loading-table';2244 loadingTable.table.style.width = this.width + 'px';2245 loadingTable.table.style.height = this.height + 'px';2246 var loadingImg = KE.$$('span');2247 loadingImg.className = 'ke-loading-img';2248 loadingTable.cell.appendChild(loadingImg);2249 var iframe = (KE.g[id].dialogStack.length == 0 && KE.g[id].dialog) ? KE.g[id].dialog : KE.$$('iframe');2250 if (arg.useFrameCSS) {2251 iframe.className = 'ke-dialog-iframe ke-dialog-iframe-border';2252 } else {2253 iframe.className = 'ke-dialog-iframe';2254 }2255 iframe.setAttribute("frameBorder", "0");2256 iframe.style.width = this.width + 'px';2257 iframe.style.height = this.height + 'px';2258 iframe.style.display = 'none';2259 bodyDiv.appendChild(iframe);2260 bodyDiv.appendChild(loadingTable.table);2261 contentCell.appendChild(bodyDiv);2262 var bottomDiv = KE.$$('div');2263 bottomDiv.className = 'ke-dialog-bottom';2264 var noButton = null;2265 var yesButton = null;2266 var previewButton = null;2267 if (arg.previewButton) {2268 previewButton = KE.$$('input');2269 previewButton.className = 'ke-button ke-dialog-preview';2270 previewButton.type = 'button';2271 previewButton.name = 'previewButton';2272 previewButton.value = arg.previewButton;2273 previewButton.onclick = function() {2274 var stack = KE.g[id].dialogStack;2275 if (stack[stack.length - 1] == self) {2276 KE.plugin[arg.cmd].preview(id);2277 }2278 };2279 bottomDiv.appendChild(previewButton);2280 }2281 if (arg.yesButton) {2282 yesButton = KE.$$('input');2283 yesButton.className = 'ke-button ke-dialog-yes';2284 yesButton.type = 'button';2285 yesButton.name = 'yesButton';2286 yesButton.value = arg.yesButton;2287 yesButton.onclick = function() {2288 var stack = KE.g[id].dialogStack;2289 if (stack[stack.length - 1] == self) {2290 KE.plugin[arg.cmd].exec(id);2291 }2292 };2293 bottomDiv.appendChild(yesButton);2294 }2295 if (arg.noButton) {2296 noButton = KE.$$('input');2297 noButton.className = 'ke-button ke-dialog-no';2298 noButton.type = 'button';2299 noButton.name = 'noButton';2300 noButton.value = arg.noButton;2301 noButton.onclick = function () {2302 self.hide();2303 KE.util.select(id);2304 };2305 bottomDiv.appendChild(noButton);2306 }2307 if (arg.yesButton || arg.noButton || arg.previewButton) {2308 contentCell.appendChild(bottomDiv);2309 }2310 document.body.appendChild(div);2311 window.focus();2312 if (yesButton) yesButton.focus();2313 else if (noButton) noButton.focus();2314 if (arg.html !== undefined) {2315 var dialogDoc = KE.util.getIframeDoc(iframe);2316 var html = KE.util.getFullHtml(id);2317 dialogDoc.open();2318 dialogDoc.write(html);2319 dialogDoc.close();2320 KE.util.innerHtml(dialogDoc.body, arg.html);2321 } else if (arg.url !== undefined) {2322 iframe.src = arg.url;2323 } else {2324 var param = 'id=' + escape(id) + '&ver=' + escape(KE.version);2325 if (arg.file === undefined) {2326 iframe.src = KE.g[id].pluginsPath + arg.cmd + '.html?' + param;2327 } else {2328 param = (/\?/.test(arg.file) ? '&' : '?') + param;2329 iframe.src = KE.g[id].pluginsPath + arg.file + param;2330 }2331 }2332 KE.g[id].maskDiv.style.width = KE.util.getDocumentWidth() + 'px';2333 KE.g[id].maskDiv.style.height = KE.util.getDocumentHeight() + 'px';2334 KE.g[id].maskDiv.style.display = 'block';2335 this.iframe = iframe;2336 this.loading = loadingTable.table;2337 this.noButton = noButton;2338 this.yesButton = yesButton;2339 this.previewButton = previewButton;2340 this.div = div;2341 KE.g[id].dialogStack.push(this);2342 KE.g[id].dialog = iframe;2343 KE.g[id].yesButton = yesButton;2344 KE.g[id].noButton = noButton;2345 KE.g[id].previewButton = previewButton;2346 if (!arg.loadingMode) KE.util.hideLoadingPage(id);2347 if (this.afterShow) this.afterShow(id);2348 if (KE.g[id].afterDialogCreate) KE.g[id].afterDialogCreate(id);2349 };2350};2351KE.toolbar = {2352 updateState : function(id) {2353 var cmdList = [2354 'justifyleft', 'justifycenter', 'justifyright',2355 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript','superscript',2356 'bold', 'italic', 'underline', 'strikethrough'2357 ];2358 for (var i = 0; i < cmdList.length; i++) {2359 var cmd = cmdList[i];2360 var state = false;2361 try {2362 state = KE.g[id].iframeDoc.queryCommandState(cmd);2363 } catch(e) {}2364 if (state) {2365 KE.toolbar.select(id, cmd);2366 } else {2367 KE.toolbar.unselect(id, cmd);2368 }2369 }2370 },2371 isSelected : function(id, cmd) {2372 if (KE.plugin[cmd] && KE.plugin[cmd].isSelected) return true;2373 else return false;2374 },2375 select : function(id, cmd) {2376 if (KE.g[id].toolbarIcon[cmd]) {2377 var a = KE.g[id].toolbarIcon[cmd][0];2378 a.className = 'ke-icon ke-icon-selected';2379 a.onmouseover = null;2380 a.onmouseout = null;2381 }2382 },2383 unselect : function(id, cmd) {2384 if (KE.g[id].toolbarIcon[cmd]) {2385 var a = KE.g[id].toolbarIcon[cmd][0];2386 a.className = 'ke-icon';2387 a.onmouseover = function(){ this.className = 'ke-icon ke-icon-on'; };2388 a.onmouseout = function(){ this.className = 'ke-icon'; };2389 }2390 },2391 _setAttr : function(id, a, cmd) {2392 a.className = 'ke-icon';2393 a.href = 'javascript:;';2394 a.onclick = function(e) {2395 e = e || window.event;2396 var div = KE.g[id].hideDiv.firstChild;2397 if (div && div.getAttribute('name') == cmd) {2398 KE.hideMenu(id);2399 } else {2400 KE.util.click(id, cmd);2401 }2402 if (e.preventDefault) e.preventDefault();2403 if (e.stopPropagation) e.stopPropagation();2404 if (e.cancelBubble !== undefined) e.cancelBubble = true;2405 return false;2406 };2407 a.onmouseover = function(){ this.className = 'ke-icon ke-icon-on'; };2408 a.onmouseout = function(){ this.className = 'ke-icon'; };2409 a.hidefocus = true;2410 a.title = KE.lang[cmd];2411 },2412 able : function(id, arr) {2413 var self = this;2414 KE.each(KE.g[id].toolbarIcon, function(cmd, obj) {2415 if (!KE.util.inArray(cmd, arr)) {2416 var a = obj[0];2417 var span = obj[1];2418 self._setAttr(id, a, cmd);2419 KE.util.setOpacity(span, 100);2420 }2421 });2422 },2423 disable : function(id, arr) {2424 KE.each(KE.g[id].toolbarIcon, function(cmd, obj) {2425 if (!KE.util.inArray(cmd, arr)) {2426 var a = obj[0];2427 var span = obj[1];2428 a.className = 'ke-icon ke-icon-disabled';2429 KE.util.setOpacity(span, 50);2430 a.onclick = null;2431 a.onmouseover = null;2432 a.onmouseout = null;2433 }2434 });2435 },2436 create : function(id) {2437 var self = this;2438 var defaultItemHash = KE.util.arrayToHash(KE.setting.items);2439 KE.g[id].toolbarIcon = [];2440 var tableObj = KE.util.createTable();2441 var toolbar = tableObj.table;2442 toolbar.className = 'ke-toolbar';2443 toolbar.oncontextmenu = function() { return false; };2444 toolbar.onmousedown = function() { return false; };2445 toolbar.onmousemove = function() { return false; };2446 var toolbarCell = tableObj.cell;2447 var length = KE.g[id].items.length;2448 var cellNum = 0;2449 var row;2450 KE.g[id].toolbarHeight = KE.g[id].toolbarLineHeight;2451 for (var i = 0; i < length; i++) {2452 var cmd = KE.g[id].items[i];2453 if (i == 0 || cmd == '-') {2454 var table = KE.util.createTable().table;2455 table.className = 'ke-toolbar-table';2456 row = table.insertRow(0);2457 cellNum = 0;2458 toolbarCell.appendChild(table);2459 if (cmd == '-') {2460 KE.g[id].toolbarHeight += KE.g[id].toolbarLineHeight;2461 continue;2462 }2463 }2464 var cell = row.insertCell(cellNum);2465 cell.hideforcus = true;2466 cellNum++;2467 if (cmd == '|') {2468 var div = KE.$$('div');2469 div.className = 'ke-toolbar-separator';2470 cell.appendChild(div);2471 continue;2472 }2473 var a = KE.$$('a');2474 self._setAttr(id, a, cmd);2475 var span = KE.$$('span');2476 if (typeof defaultItemHash[cmd] == 'undefined') {2477 span.className = 'ke-common-icon ke-icon-' + cmd;2478 } else {2479 span.className = 'ke-common-icon ke-common-icon-url ke-icon-' + cmd;2480 }2481 a.appendChild(span);2482 cell.appendChild(a);2483 KE.g[id].toolbarIcon[cmd] = [a, span];2484 if (KE.toolbar.isSelected(id, cmd)) KE.toolbar.select(id, cmd);2485 }2486 return toolbar;2487 }2488};2489KE.history = {2490 addStackData : function(stack, data) {2491 var prev = '';2492 if (stack.length > 0) {2493 prev = stack[stack.length - 1];2494 }2495 if (stack.length == 0 || data !== prev) stack.push(data);2496 },2497 add : function(id, minChangeSize) {2498 var g = KE.g[id];2499 var html = KE.util.getSrcData(id);2500 if (g.undoStack.length > 0) {2501 var prevHtml = g.undoStack[g.undoStack.length - 1];2502 if (Math.abs(html.length - prevHtml.length) < minChangeSize) return;2503 }2504 this.addStackData(g.undoStack, html);2505 },2506 undo : function(id) {2507 var g = KE.g[id];2508 if (g.undoStack.length == 0) return;2509 var html = KE.util.getSrcData(id);2510 this.addStackData(g.redoStack, html);2511 var prevHtml = g.undoStack.pop();2512 if (html === prevHtml && g.undoStack.length > 0) {2513 prevHtml = g.undoStack.pop();2514 }2515 prevHtml = KE.util.toData(id, prevHtml);2516 if (g.wyswygMode) {2517 KE.util.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, prevHtml));2518 } else {2519 g.newTextarea.value = prevHtml;2520 }2521 },2522 redo : function(id) {2523 var g = KE.g[id];2524 if (g.redoStack.length == 0) return;2525 var html = KE.util.getSrcData(id);2526 this.addStackData(g.undoStack, html);2527 var nextHtml = g.redoStack.pop();2528 nextHtml = KE.util.toData(id, nextHtml);2529 if (g.wyswygMode) {2530 KE.util.innerHtml(g.iframeDoc.body, KE.util.execSetHtmlHooks(id, nextHtml));2531 } else {2532 g.newTextarea.value = nextHtml;2533 }2534 }2535};2536KE.readonly = function(id, isReadonly) {2537 isReadonly = isReadonly == undefined ? true : isReadonly;2538 var g = KE.g[id];2539 if (KE.browser.IE) g.iframeDoc.body.contentEditable = isReadonly ? 'false' : 'true';2540 else g.iframeDoc.designMode = isReadonly ? 'off' : 'on';2541};2542KE.focus = function(id, position) {2543 position = (position || '').toLowerCase();2544 if (!KE.g[id].container) return;2545 KE.util.focus(id);2546 if (position === 'end') {2547 KE.util.setSelection(id);2548 if (!KE.g[id].sel) return; //issue #120: Sometimes Firefox does not get selection2549 var sel = KE.g[id].keSel,2550 range = KE.g[id].keRange,2551 doc = KE.g[id].iframeDoc;2552 range.selectTextNode(doc.body);2553 range.collapse(false);2554 sel.addRange(range);2555 }2556};2557KE.html = function(id, val) {2558 if (val === undefined) {2559 return KE.util.getData(id);2560 } else {2561 if (!KE.g[id].container) return;2562 KE.util.setFullHtml(id, val);2563 KE.focus(id, 'end');2564 }2565};2566KE.text = function(id, val) {2567 if (val === undefined) {2568 val = KE.html(id);2569 val = val.replace(/<.*?>/ig, '');2570 val = val.replace(/&nbsp;/ig, ' ');2571 val = KE.util.trim(val);2572 return val;2573 } else {2574 KE.html(id, KE.util.escape(val));2575 }2576};2577KE.insertHtml = function(id, val) {2578 if (!KE.g[id].container) return;2579 var range = KE.g[id].range;2580 if (!range) {2581 KE.appendHtml(id, val);2582 } else {2583 KE.focus(id);2584 KE.util.selection(id);2585 KE.util.insertHtml(id, val);2586 }2587};2588KE.appendHtml = function(id, val) {2589 KE.html(id, KE.html(id) + val);2590 KE.focus(id, 'end');2591};2592KE.isEmpty = function(id) {2593 return KE.util.isEmpty(id);2594};2595KE.selectedHtml = function(id) {2596 var range = KE.g[id].range;2597 if (!range) return '';2598 var html = '';2599 if (KE.browser.IE) {2600 if (range.item) {2601 html = range.item(0).outerHTML;2602 } else {2603 html = range.htmlText;2604 }2605 } else {2606 var temp = KE.$$('div', KE.g[id].iframeDoc);2607 temp.appendChild(range.cloneContents());2608 html = temp.innerHTML;2609 }2610 return KE.util.toData(id, html);2611};2612KE.count = function(id, mode) {2613 mode = (mode || 'html').toLowerCase();2614 if (mode === 'html') {2615 return KE.html(id).length;2616 } else if (mode === 'text') {2617 var data = KE.util.getPureData(id);2618 data = data.replace(/<(?:img|embed).*?>/ig, 'K');2619 data = data.replace(/\r\n|\n|\r/g, '');2620 data = KE.util.trim(data);2621 return data.length;2622 }2623 return 0;2624};2625KE.remove = function(id, mode) {2626 var g = KE.g[id];2627 if (!g.container) return false;2628 mode = (typeof mode == "undefined") ? 0 : mode;2629 KE.util.setData(id);2630 var container = g.container;2631 var eventStack = g.eventStack;2632 for (var i = 0, len = eventStack.length; i < len; i++) {2633 var item = eventStack[i];2634 if (item) KE.event.remove(item.el, item.type, item.fn, id);2635 }2636 g.iframeDoc.src = 'javascript:false';2637 g.iframe.parentNode.removeChild(g.iframe);2638 if (mode == 1) {2639 document.body.removeChild(container);2640 } else {2641 var srcTextarea = g.srcTextarea;2642 srcTextarea.parentNode.removeChild(container);2643 if (mode == 0) srcTextarea.style.display = '';2644 }2645 document.body.removeChild(g.hideDiv);2646 document.body.removeChild(g.maskDiv);2647 g.container = null;2648 g.dialogStack = [];2649 g.contextmenuItems = [];2650 g.getHtmlHooks = [];2651 g.setHtmlHooks = [];2652 g.onchangeHandlerStack = [];2653 g.eventStack = [];2654};2655KE.create = function(id, mode) {2656 if (KE.g[id].beforeCreate) KE.g[id].beforeCreate(id);2657 if (KE.browser.IE && KE.browser.VERSION < 7) try { document.execCommand('BackgroundImageCache', false, true); }catch(e){}2658 var srcTextarea = KE.$(id) || document.getElementsByName(id)[0];2659 mode = (typeof mode == "undefined") ? 0 : mode;2660 if (mode == 0 && KE.g[id].container) return;2661 var width = KE.g[id].width || srcTextarea.style.width || srcTextarea.offsetWidth + 'px';2662 var height = KE.g[id].height || srcTextarea.style.height || srcTextarea.offsetHeight + 'px';2663 var tableObj = KE.util.createTable();2664 var container = tableObj.table;2665 container.className = 'ke-container';2666 container.style.width = width;2667 container.style.height = height;2668 var toolbarOuter = tableObj.cell;2669 toolbarOuter.className = 'ke-toolbar-outer';2670 var textareaOuter = container.insertRow(1).insertCell(0);2671 textareaOuter.className = 'ke-textarea-outer';2672 tableObj = KE.util.createTable();2673 var textareaTable = tableObj.table;2674 textareaTable.className = 'ke-textarea-table';2675 var textareaCell = tableObj.cell;2676 textareaOuter.appendChild(textareaTable);2677 var bottomOuter = container.insertRow(2).insertCell(0);2678 bottomOuter.className = 'ke-bottom-outer';2679 srcTextarea.style.display = 'none';2680 if (mode == 1) document.body.appendChild(container);2681 else srcTextarea.parentNode.insertBefore(container, srcTextarea);2682 var toolbarTable = KE.toolbar.create(id);2683 toolbarTable.style.height = KE.g[id].toolbarHeight + 'px';2684 toolbarOuter.appendChild(toolbarTable);2685 var iframe = KE.g[id].iframe || KE.$$('iframe');2686 iframe.className = 'ke-iframe';2687 iframe.setAttribute("frameBorder", "0");2688 var newTextarea = KE.$$('textarea');2689 newTextarea.className = 'ke-textarea';2690 newTextarea.style.display = 'none';2691 KE.g[id].container = container;2692 KE.g[id].iframe = iframe;2693 KE.g[id].newTextarea = newTextarea;2694 KE.util.resize(id, width, height);2695 textareaCell.appendChild(iframe);2696 textareaCell.appendChild(newTextarea);2697 var bottom = KE.$$('table');2698 bottom.className = 'ke-bottom';2699 bottom.cellPadding = 0;2700 bottom.cellSpacing = 0;2701 bottom.border = 0;2702 bottom.style.height = KE.g[id].statusbarHeight + 'px';2703 var row = bottom.insertRow(0);2704 var bottomLeft = row.insertCell(0);2705 bottomLeft.className = 'ke-bottom-left';2706 var leftImg = KE.$$('span');2707 leftImg.className = 'ke-bottom-left-img';2708 if (KE.g[id].config.resizeMode == 0 || mode == 1) {2709 bottomLeft.style.cursor = 'default';2710 leftImg.style.visibility = 'hidden';2711 }2712 bottomLeft.appendChild(leftImg);2713 var bottomRight = row.insertCell(1);2714 bottomRight.className = 'ke-bottom-right';2715 var rightImg = KE.$$('span');2716 rightImg.className = 'ke-bottom-right-img';2717 if (KE.g[id].config.resizeMode == 0 || mode == 1) {2718 bottomRight.style.cursor = 'default';2719 rightImg.style.visibility = 'hidden';2720 } else if (KE.g[id].config.resizeMode == 1) {2721 bottomRight.style.cursor = 's-resize';2722 rightImg.style.visibility = 'hidden';2723 }2724 bottomRight.appendChild(rightImg);2725 bottomOuter.appendChild(bottom);2726 var hideDiv = KE.$$('div');2727 hideDiv.className = 'ke-reset';2728 hideDiv.style.display = 'none';2729 var maskDiv = KE.$$('div');2730 maskDiv.className = 'ke-mask';2731 KE.util.setOpacity(maskDiv, 50);2732 KE.event.bind(maskDiv, 'click', function(e){}, id);2733 KE.event.bind(maskDiv, 'mousedown', function(e){}, id);2734 document.body.appendChild(hideDiv);2735 document.body.appendChild(maskDiv);2736 KE.util.setDefaultPlugin(id);2737 var iframeWin = iframe.contentWindow;2738 var iframeDoc = KE.util.getIframeDoc(iframe);2739 if (!KE.browser.IE || KE.browser.VERSION < 8) iframeDoc.designMode = 'on';2740 var html = KE.util.getFullHtml(id);2741 iframeDoc.open();2742 iframeDoc.write(html);2743 iframeDoc.close();2744 if (!KE.g[id].wyswygMode) {2745 newTextarea.value = KE.util.execSetHtmlHooks(id, srcTextarea.value);2746 newTextarea.style.display = 'block';2747 iframe.style.display = 'none';2748 KE.toolbar.disable(id, ['source', 'fullscreen']);2749 KE.toolbar.select(id, 'source');2750 }2751 function hideMenu() {2752 KE.hideMenu(id);2753 }2754 function updateToolbar() {2755 KE.toolbar.updateState(id);2756 }2757 if (KE.browser.WEBKIT) {2758 KE.event.add(iframeDoc, 'click', function(e) {2759 KE.util.selectImageWebkit(id, e, true);2760 }, id);2761 }2762 if (KE.browser.IE) {2763 KE.event.add(iframeDoc, 'keydown', function(e) {2764 if (e.keyCode == 8) {2765 var range = KE.g[id].range;2766 if (range.item) {2767 var item = range.item(0);2768 item.parentNode.removeChild(item);2769 KE.util.execOnchangeHandler(id);2770 KE.event.stop(id);2771 return false;2772 }2773 }2774 }, id);2775 }2776 KE.event.add(iframeDoc, 'click', hideMenu, id);2777 KE.event.add(iframeDoc, 'click', updateToolbar, id);2778 KE.event.input(iframeDoc, updateToolbar, id);2779 KE.event.bind(newTextarea, 'click', hideMenu, id);2780 KE.event.add(document, 'click', hideMenu, id);2781 KE.g[id].toolbarTable = toolbarTable;2782 KE.g[id].textareaTable = textareaTable;2783 KE.g[id].srcTextarea = srcTextarea;2784 KE.g[id].bottom = bottom;2785 KE.g[id].hideDiv = hideDiv;2786 KE.g[id].maskDiv = maskDiv;2787 KE.g[id].iframeWin = iframeWin;2788 KE.g[id].iframeDoc = iframeDoc;2789 KE.g[id].width = width;2790 KE.g[id].height = height;2791 KE.util.drag(id, bottomRight, container, function(objTop, objLeft, objWidth, objHeight, top, left) {2792 if (KE.g[id].resizeMode == 2) KE.util.resize(id, (objWidth + left) + 'px', (objHeight + top) + 'px', true);2793 else if (KE.g[id].resizeMode == 1) KE.util.resize(id, objWidth + 'px', (objHeight + top) + 'px', true, false);2794 });2795 KE.util.drag(id, bottomLeft, container, function(objTop, objLeft, objWidth, objHeight, top, left) {2796 if (KE.g[id].resizeMode > 0) KE.util.resize(id, objWidth + 'px', (objHeight + top) + 'px', true, false);2797 });2798 KE.each(KE.plugin, function(cmd, plugin) {2799 if (plugin.init) plugin.init(id);2800 });2801 KE.g[id].getHtmlHooks.push(function(html) {2802 return html.replace(/(<[^>]*)kesrc="([^"]+)"([^>]*>)/ig, function(full, start, src, end) {2803 full = full.replace(/(\s+(?:href|src)=")[^"]+(")/i, '$1' + src + '$2');2804 full = full.replace(/\s+kesrc="[^"]+"/i, '');2805 return full;2806 });2807 });2808 KE.g[id].setHtmlHooks.push(function(html) {2809 return html.replace(/(<[^>]*)(href|src)="([^"]+)"([^>]*>)/ig, function(full, start, key, src, end) {2810 if (full.match(/\skesrc="[^"]+"/i)) return full;2811 full = start + key + '="' + src + '"' + ' kesrc="' + src + '"' + end;2812 return full;2813 });2814 });2815 KE.util.addContextmenuEvent(id);2816 KE.util.addNewlineEvent(id);2817 KE.util.addTabEvent(id);2818 function setSelectionHandler() {2819 KE.util.setSelection(id);2820 }2821 KE.event.input(iframeDoc, setSelectionHandler, id);2822 KE.event.add(iframeDoc, 'mouseup', setSelectionHandler, id);2823 KE.event.add(document, 'mousedown', setSelectionHandler, id);2824 KE.onchange(id, function(id) {2825 if (KE.g[id].autoSetDataMode) {2826 KE.util.setData(id);2827 if (KE.g[id].afterSetData) KE.g[id].afterSetData(id);2828 }2829 KE.history.add(id, KE.g[id].minChangeSize);2830 });2831 if (KE.browser.IE && KE.browser.VERSION > 7) KE.readonly(id, false);2832 KE.util.setFullHtml(id, srcTextarea.value);2833 KE.history.add(id, 0);2834 if (mode > 0) KE.util.focus(id);2835 if (KE.g[id].afterCreate) KE.g[id].afterCreate(id);2836};2837KE.onchange = function(id, func) {2838 var g = KE.g[id];2839 function handler() {2840 func(id);2841 };2842 g.onchangeHandlerStack.push(handler);2843 KE.event.input(g.iframeDoc, handler, id);2844 KE.event.input(g.newTextarea, handler, id);2845 KE.event.add(g.iframeDoc, 'mouseup', function(e) {2846 window.setTimeout(function() {2847 func(id);2848 }, 0);2849 }, id);2850};2851KE.init = function(args) {2852 var g = KE.g[args.id] = args;2853 g.config = {};2854 g.undoStack = [];2855 g.redoStack = [];2856 g.dialogStack = [];2857 g.contextmenuItems = [];2858 g.getHtmlHooks = [];2859 g.setHtmlHooks = [];2860 g.onchangeHandlerStack = [];2861 g.eventStack = [];2862 KE.each(KE.setting, function(key, val) {2863 g[key] = (typeof args[key] == 'undefined') ? val : args[key];2864 g.config[key] = g[key];2865 });2866 if (g.loadStyleMode) KE.util.loadStyle(g.skinsPath + g.skinType + '.css');2867}2868KE.show = function(args) {2869 KE.init(args);2870 KE.event.ready(function() { KE.create(args.id); });2871};2872if (window.KE === undefined) window.KE = KE;2873window.KindEditor = KE;2874})();2875(function (KE, undefined) {2876KE.langType = 'zh_CN';2877KE.lang = {2878 source : 'HTML代码',2879 undo : '后退(Ctrl+Z)',2880 redo : '前进(Ctrl+Y)',2881 cut : '剪切(Ctrl+X)',2882 copy : '复制(Ctrl+C)',2883 paste : '粘贴(Ctrl+V)',2884 plainpaste : '粘贴为无格式文本',2885 wordpaste : '从Word粘贴',2886 selectall : '全选',2887 justifyleft : '左对齐',2888 justifycenter : '居中',2889 justifyright : '右对齐',2890 justifyfull : '两端对齐',2891 insertorderedlist : '编号',2892 insertunorderedlist : '项目符号',2893 indent : '增加缩进',2894 outdent : '减少缩进',2895 subscript : '下标',2896 superscript : '上标',2897 title : '标题',2898 fontname : '字体',2899 fontsize : '文字大小',2900 textcolor : '文字颜色',2901 bgcolor : '文字背景',2902 bold : '粗体(Ctrl+B)',2903 italic : '斜体(Ctrl+I)',2904 underline : '下划线(Ctrl+U)',2905 strikethrough : '删除线',2906 removeformat : '删除格式',2907 image : '图片',2908 flash : '插入Flash',2909 media : '插入多媒体',2910 table : '插入表格',2911 hr : '插入横线',2912 emoticons : '插入表情',2913 link : '超级链接',2914 unlink : '取消超级链接',2915 fullscreen : '全屏显示',2916 about : '关于',2917 print : '打印',2918 fileManager : '浏览服务器',2919 advtable : '表格',2920 yes : '确定',2921 no : '取消',2922 close : '关闭',2923 editImage : '图片属性',2924 deleteImage : '删除图片',2925 editLink : '超级链接属性',2926 deleteLink : '取消超级链接',2927 tableprop : '表格属性',2928 tableinsert : '插入表格',2929 tabledelete : '删除表格',2930 tablecolinsertleft : '左侧插入列',2931 tablecolinsertright : '右侧插入列',2932 tablerowinsertabove : '上方插入行',2933 tablerowinsertbelow : '下方插入行',2934 tablecoldelete : '删除列',2935 tablerowdelete : '删除行',2936 noColor : '无颜色',2937 invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",2938 invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",2939 invalidWidth : "宽度必须为数字。",2940 invalidHeight : "高度必须为数字。",2941 invalidBorder : "边框必须为数字。",2942 invalidUrl : "请输入有效的URL地址。",2943 invalidRows : '行数为必选项,只允许输入大于0的数字。',2944 invalidCols : '列数为必选项,只允许输入大于0的数字。',2945 invalidPadding : '边距必须为数字。',2946 invalidSpacing : '间距必须为数字。',2947 invalidBorder : '边框必须为数字。',2948 pleaseInput : "请输入内容。",2949 invalidJson : '服务器发生故障。',2950 cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',2951 copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',2952 pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。'2953};2954var plugins = KE.lang.plugins = {};2955plugins.about = {2956 version : KE.version,2957 title : 'HTML可视化编辑器'2958};2959plugins.plainpaste = {2960 comment : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。'2961};2962plugins.wordpaste = {2963 comment : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。'2964};2965plugins.link = {2966 url : 'URL地址',2967 linkType : '打开类型',2968 newWindow : '新窗口',2969 selfWindow : '当前窗口'2970};2971plugins.flash = {2972 url : 'Flash地址',2973 width : '宽度',2974 height : '高度'2975};2976plugins.media = {2977 url : '媒体文件地址',2978 width : '宽度',2979 height : '高度',2980 autostart : '自动播放'2981};2982plugins.image = {2983 remoteImage : '远程图片',2984 localImage : '本地上传',2985 remoteUrl : '图片地址',2986 localUrl : '图片地址',2987 size : '图片大小',2988 width : '宽',2989 height : '高',2990 resetSize : '重置大小',2991 align : '对齐方式',2992 defaultAlign : '默认方式',2993 leftAlign : '左对齐',2994 rightAlign : '右对齐',2995 imgTitle : '图片说明',2996 viewServer : '浏览...'2997};2998plugins.file_manager = {2999 emptyFolder : '空文件夹',3000 moveup : '移到上一级文件夹',3001 viewType : '显示方式:',3002 viewImage : '缩略图',3003 listImage : '详细信息',3004 orderType : '排序方式:',3005 fileName : '名称',3006 fileSize : '大小',3007 fileType : '类型'3008};3009plugins.advtable = {3010 cells : '单元格数',3011 rows : '行数',3012 cols : '列数',3013 size : '表格大小',3014 width : '宽度',3015 height : '高度',3016 percent : '%',3017 px : 'px',3018 space : '边距间距',3019 padding : '边距',3020 spacing : '间距',3021 align : '对齐方式',3022 alignDefault : '默认',3023 alignLeft : '左对齐',3024 alignCenter : '居中',3025 alignRight : '右对齐',3026 border : '表格边框',3027 borderWidth : '边框',3028 borderColor : '颜色',3029 backgroundColor : '背景颜色'3030};3031plugins.title = {3032 h1 : '标题 1',3033 h2 : '标题 2',3034 h3 : '标题 3',3035 h4 : '标题 4',3036 p : '正 文'3037};3038plugins.fontname = {3039 fontName : {3040 'SimSun' : '宋体',3041 'NSimSun' : '新宋体',3042 'FangSong_GB2312' : '仿宋_GB2312',3043 'KaiTi_GB2312' : '楷体_GB2312',3044 'SimHei' : '黑体',3045 'Microsoft YaHei' : '微软雅黑',3046 'Arial' : 'Arial',3047 'Arial Black' : 'Arial Black',3048 'Times New Roman' : 'Times New Roman',3049 'Courier New' : 'Courier New',3050 'Tahoma' : 'Tahoma',3051 'Verdana' : 'Verdana'3052 }3053};3054})(KindEditor);3055(function (KE, undefined) {3056KE.plugin['about'] = {3057 click : function(id) {3058 KE.util.selection(id);3059 var dialog = new KE.dialog({3060 id : id,3061 cmd : 'about',3062 file : 'about.html',3063 width : 300,3064 height : 70,3065 loadingMode : true,3066 title : KE.lang['about'],3067 noButton : KE.lang['close']3068 });3069 dialog.show();3070 }3071};3072KE.plugin['undo'] = {3073 init : function(id) {3074 KE.event.ctrl(KE.g[id].iframeDoc, 'Z', function(e) {3075 KE.plugin['undo'].click(id);3076 KE.util.focus(id);3077 }, id);3078 KE.event.ctrl(KE.g[id].newTextarea, 'Z', function(e) {3079 KE.plugin['undo'].click(id);3080 KE.util.focus(id);3081 }, id);3082 },3083 click : function(id) {3084 KE.history.undo(id);3085 KE.util.execOnchangeHandler(id);3086 }3087};3088KE.plugin['redo'] = {3089 init : function(id) {3090 KE.event.ctrl(KE.g[id].iframeDoc, 'Y', function(e) {3091 KE.plugin['redo'].click(id);3092 KE.util.focus(id);3093 }, id);3094 KE.event.ctrl(KE.g[id].newTextarea, 'Y', function(e) {3095 KE.plugin['redo'].click(id);3096 KE.util.focus(id);3097 }, id);3098 },3099 click : function(id) {3100 KE.history.redo(id);3101 KE.util.execOnchangeHandler(id);3102 }3103};3104KE.plugin['cut'] = {3105 click : function(id) {3106 try {3107 if (!KE.g[id].iframeDoc.queryCommandSupported('cut')) throw 'e';3108 } catch(e) {3109 alert(KE.lang.cutError);3110 return;3111 }3112 KE.util.execCommand(id, 'cut', null);3113 }3114};3115KE.plugin['copy'] = {3116 click : function(id) {3117 try {3118 if (!KE.g[id].iframeDoc.queryCommandSupported('copy')) throw 'e';3119 } catch(e) {3120 alert(KE.lang.copyError);3121 return;3122 }3123 KE.util.execCommand(id, 'copy', null);3124 }3125};3126KE.plugin['paste'] = {3127 click : function(id) {3128 try {3129 if (!KE.g[id].iframeDoc.queryCommandSupported('paste')) throw 'e';3130 } catch(e) {3131 alert(KE.lang.pasteError);3132 return;3133 }3134 KE.util.execCommand(id, 'paste', null);3135 }3136};3137KE.plugin['plainpaste'] = {3138 click : function(id) {3139 KE.util.selection(id);3140 this.dialog = new KE.dialog({3141 id : id,3142 cmd : 'plainpaste',3143 file : 'plainpaste.html',3144 width : 450,3145 height : 300,3146 loadingMode : true,3147 title : KE.lang['plainpaste'],3148 yesButton : KE.lang['yes'],3149 noButton : KE.lang['no']3150 });3151 this.dialog.show();3152 },3153 exec : function(id) {3154 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3155 var html = KE.$('textArea', dialogDoc).value;3156 html = KE.util.escape(html);3157 html = html.replace(/ /g, '&nbsp;');3158 html = html.replace(/\r\n|\n|\r/g, "<br />$&");3159 KE.util.insertHtml(id, html);3160 this.dialog.hide();3161 KE.util.focus(id);3162 }3163};3164KE.plugin['wordpaste'] = {3165 click : function(id) {3166 KE.util.selection(id);3167 this.dialog = new KE.dialog({3168 id : id,3169 cmd : 'wordpaste',3170 file : 'wordpaste.html',3171 width : 450,3172 height : 300,3173 loadingMode : true,3174 title : KE.lang['wordpaste'],3175 yesButton : KE.lang['yes'],3176 noButton : KE.lang['no']3177 });3178 this.dialog.show();3179 },3180 exec : function(id) {3181 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3182 var wordIframe = KE.$('wordIframe', dialogDoc);3183 var str = KE.util.getIframeDoc(wordIframe).body.innerHTML;3184 str = str.replace(/<meta(\n|.)*?>/ig, "");3185 str = str.replace(/<!(\n|.)*?>/ig, "");3186 str = str.replace(/<style[^>]*>(\n|.)*?<\/style>/ig, "");3187 str = str.replace(/<script[^>]*>(\n|.)*?<\/script>/ig, "");3188 str = str.replace(/<w:[^>]+>(\n|.)*?<\/w:[^>]+>/ig, "");3189 str = str.replace(/<xml>(\n|.)*?<\/xml>/ig, "");3190 str = str.replace(/\r\n|\n|\r/ig, "");3191 str = KE.util.execGetHtmlHooks(id, str);3192 str = KE.format.getHtml(str, KE.g[id].htmlTags, KE.g[id].urlType);3193 KE.util.insertHtml(id, str);3194 this.dialog.hide();3195 KE.util.focus(id);3196 }3197};3198KE.plugin['fullscreen'] = {3199 click : function(id) {3200 var g = KE.g[id];3201 var self = this;3202 var resetSize = function() {3203 var el = KE.util.getDocumentElement();3204 g.width = el.clientWidth + 'px';3205 g.height = el.clientHeight + 'px';3206 };3207 var windowSize = '';3208 var resizeListener = function() {3209 if (!self.isSelected) return;3210 var el = KE.util.getDocumentElement();3211 var size = [el.clientWidth, el.clientHeight].join('');3212 if (windowSize != size) {3213 windowSize = size;3214 resetSize();3215 KE.util.resize(id, g.width, g.height);3216 }3217 }3218 if (this.isSelected) {3219 this.isSelected = false;3220 KE.util.setData(id);3221 KE.remove(id, 1);3222 g.width = this.width;3223 g.height = this.height;3224 KE.create(id, 2);3225 document.body.parentNode.style.overflow = 'auto';3226 KE.event.remove(window, 'resize', resizeListener);3227 g.resizeMode = g.config.resizeMode;3228 KE.toolbar.unselect(id, "fullscreen");3229 } else {3230 this.isSelected = true;3231 this.width = g.container.style.width;3232 this.height = g.container.style.height;3233 KE.util.setData(id);3234 KE.remove(id, 2);3235 document.body.parentNode.style.overflow = 'hidden';3236 resetSize();3237 KE.create(id, 1);3238 var pos = KE.util.getScrollPos();3239 var div = g.container;3240 div.style.position = 'absolute';3241 div.style.left = pos.x + 'px';3242 div.style.top = pos.y + 'px';3243 div.style.zIndex = 19811211;3244 KE.event.add(window, 'resize', resizeListener);3245 g.resizeMode = 0;3246 KE.toolbar.select(id, "fullscreen");3247 }3248 }3249};3250KE.plugin['bgcolor'] = {3251 click : function(id) {3252 KE.util.selection(id);3253 var color = KE.queryCommandValue(KE.g[id].iframeDoc, 'bgcolor');3254 this.menu = new KE.menu({3255 id : id,3256 cmd : 'bgcolor'3257 });3258 this.menu.picker(color);3259 },3260 exec : function(id, value) {3261 var cmd = new KE.cmd(id);3262 if (value == '') {3263 cmd.remove({3264 'span' : ['.background-color']3265 });3266 } else {3267 cmd.wrap('span', [{'.background-color': value}]);3268 }3269 KE.util.execOnchangeHandler(id);3270 this.menu.hide();3271 KE.util.focus(id);3272 }3273};3274KE.plugin['fontname'] = {3275 click : function(id) {3276 var fontName = KE.lang.plugins.fontname.fontName;3277 var cmd = 'fontname';3278 KE.util.selection(id);3279 var menu = new KE.menu({3280 id : id,3281 cmd : cmd,3282 width : 1503283 });3284 var font = KE.queryCommandValue(KE.g[id].iframeDoc, cmd);3285 KE.each(fontName, function(key, value) {3286 var html = '<span class="ke-reset" style="font-family: ' + key + ';">' + value + '</span>';3287 menu.add(3288 html,3289 function() { KE.plugin[cmd].exec(id, key); },3290 { checked : (font === key.toLowerCase() || font === value.toLowerCase()) }3291 );3292 });3293 menu.show();3294 this.menu = menu;3295 },3296 exec : function(id, value) {3297 var cmd = new KE.cmd(id);3298 cmd.wrap('span', [{'.font-family': value}]);3299 KE.util.execOnchangeHandler(id);3300 this.menu.hide();3301 KE.util.focus(id);3302 }3303};3304KE.plugin['fontsize'] = {3305 click : function(id) {3306 var fontSize = ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'];3307 var cmd = 'fontsize';3308 KE.util.selection(id);3309 var size = KE.queryCommandValue(KE.g[id].iframeDoc, 'fontsize');3310 var menu = new KE.menu({3311 id : id,3312 cmd : cmd,3313 width : 1203314 });3315 for (var i = 0, len = fontSize.length; i < len; i++) {3316 var value = fontSize[i];3317 var html = '<span class="ke-reset" style="font-size: ' + value + ';">' + value + '</span>';3318 menu.add(3319 html,3320 (function(value) {3321 return function() {3322 KE.plugin[cmd].exec(id, value);3323 };3324 })(value),3325 {3326 height : (parseInt(value) + 12) + 'px',3327 checked : (size === value)3328 }3329 );3330 }3331 menu.show();3332 this.menu = menu;3333 },3334 exec : function(id, value) {3335 var cmd = new KE.cmd(id);3336 cmd.wrap('span', [{'.font-size': value}]);3337 KE.util.execOnchangeHandler(id);3338 this.menu.hide();3339 KE.util.focus(id);3340 }3341};3342KE.plugin['hr'] = {3343 click : function(id) {3344 KE.util.selection(id);3345 KE.util.insertHtml(id, '<hr />');3346 KE.util.focus(id);3347 }3348};3349KE.plugin['print'] = {3350 click : function(id) {3351 KE.util.selection(id);3352 KE.g[id].iframeWin.print();3353 }3354};3355KE.plugin['removeformat'] = {3356 click : function(id) {3357 KE.util.selection(id);3358 var cmd = new KE.cmd(id);3359 var tags = {3360 '*' : ['class', 'style']3361 };3362 for (var i = 0, len = KE.g[id].inlineTags.length; i < len; i++) {3363 tags[KE.g[id].inlineTags[i]] = ['*'];3364 }3365 cmd.remove(tags);3366 KE.util.execOnchangeHandler(id);3367 KE.toolbar.updateState(id);3368 KE.util.focus(id);3369 }3370};3371KE.plugin['source'] = {3372 click : function(id) {3373 var g = KE.g[id];3374 if (!g.wyswygMode) {3375 KE.util.setFullHtml(id, g.newTextarea.value);3376 g.iframe.style.display = 'block';3377 g.newTextarea.style.display = 'none';3378 KE.toolbar.able(id, ['source', 'fullscreen']);3379 g.wyswygMode = true;3380 this.isSelected = false;3381 KE.toolbar.unselect(id, "source");3382 } else {3383 KE.hideMenu(id);3384 g.newTextarea.value = KE.util.getData(id);3385 g.iframe.style.display = 'none';3386 g.newTextarea.style.display = 'block';3387 KE.toolbar.disable(id, ['source', 'fullscreen']);3388 g.wyswygMode = false;3389 this.isSelected = true;3390 KE.toolbar.select(id, "source");3391 }3392 KE.util.focus(id);3393 }3394};3395KE.plugin['textcolor'] = {3396 click : function(id) {3397 KE.util.selection(id);3398 var color = KE.queryCommandValue(KE.g[id].iframeDoc, 'textcolor');3399 this.menu = new KE.menu({3400 id : id,3401 cmd : 'textcolor'3402 });3403 this.menu.picker(color);3404 },3405 exec : function(id, value) {3406 var cmd = new KE.cmd(id);3407 if (value == '') {3408 cmd.remove({3409 'span' : ['.color'],3410 'font' : ['color']3411 });3412 } else {3413 cmd.wrap('span', [{'.color': value}]);3414 }3415 KE.util.execOnchangeHandler(id);3416 this.menu.hide();3417 KE.util.focus(id);3418 }3419};3420KE.plugin['title'] = {3421 click : function(id) {3422 var lang = KE.lang.plugins.title;3423 var title = {3424 'H1' : lang.h1,3425 'H2' : lang.h2,3426 'H3' : lang.h3,3427 'H4' : lang.h4,3428 'P' : lang.p3429 };3430 var sizeHash = {3431 'H1' : 28,3432 'H2' : 24,3433 'H3' : 18,3434 'H4' : 14,3435 'P' : 123436 };3437 var cmd = 'title';3438 KE.util.selection(id);3439 var block = KE.queryCommandValue(KE.g[id].iframeDoc, 'formatblock');3440 var menu = new KE.menu({3441 id : id,3442 cmd : cmd,3443 width : (KE.langType == 'en' ? 200 : 150)3444 });3445 KE.each(title, function(key, value) {3446 var style = 'font-size:' + sizeHash[key] + 'px;'3447 if (key !== 'P') style += 'font-weight:bold;';3448 var html = '<span class="ke-reset" style="' + style + '">' + value + '</span>';3449 menu.add(html, function() {3450 KE.plugin[cmd].exec(id, '<' + key + '>'); },3451 {3452 height : (sizeHash[key] + 12) + 'px',3453 checked : (block === key.toLowerCase() || block === value.toLowerCase() )3454 }3455 );3456 });3457 menu.show();3458 this.menu = menu;3459 },3460 exec : function(id, value) {3461 KE.util.select(id);3462 KE.util.execCommand(id, 'formatblock', value);3463 this.menu.hide();3464 KE.util.focus(id);3465 }3466};3467KE.plugin['emoticons'] = {3468 click : function(id) {3469 var self = this,3470 cmd = 'emoticons',3471 rows = 5,3472 cols = 9,3473 total = 135,3474 startNum = 0,3475 cells = rows * cols,3476 pages = Math.ceil(total / cells),3477 colsHalf = Math.floor(cols / 2),3478 g = KE.g[id],3479 path = g.pluginsPath + 'emoticons/',3480 allowPreview = (g.allowPreviewEmoticons === undefined) ? true : g.allowPreviewEmoticons;3481 KE.util.selection(id);3482 var wrapperDiv = KE.$$('div');3483 wrapperDiv.className = 'ke-plugin-emoticons-wrapper';3484 var previewDiv, previewImg;3485 if (allowPreview) {3486 previewDiv = KE.$$('div');3487 previewDiv.className = 'ke-plugin-emoticons-preview';3488 previewDiv.style.right = 0;3489 var previewImg = KE.$$('img');3490 previewImg.className = 'ke-reset';3491 previewImg.src = path + '0.gif';3492 previewImg.border = 0;3493 previewDiv.appendChild(previewImg);3494 wrapperDiv.appendChild(previewDiv);3495 }3496 function createEmoticonsTable(pageNum) {3497 var table = KE.$$('table');3498 if (previewDiv) {3499 table.onmouseover = function() { previewDiv.style.display = 'block'; };3500 table.onmouseout = function() { previewDiv.style.display = 'none'; };3501 }3502 table.className = 'ke-plugin-emoticons-table';3503 table.cellPadding = 0;3504 table.cellSpacing = 0;3505 table.border = 0;3506 var num = (pageNum - 1) * cells + startNum;3507 for (var i = 0; i < rows; i++) {3508 var row = table.insertRow(i);3509 for (var j = 0; j < cols; j++) {3510 var cell = row.insertCell(j);3511 cell.className = 'ke-plugin-emoticons-cell';3512 if (previewDiv) {3513 cell.onmouseover = (function(j, num) {3514 return function() {3515 if (j > colsHalf) {3516 previewDiv.style.left = 0;3517 previewDiv.style.right = '';3518 } else {3519 previewDiv.style.left = '';3520 previewDiv.style.right = 0;3521 }3522 previewImg.src = path + num + '.gif';;3523 this.className = 'ke-plugin-emoticons-cell ke-plugin-emoticons-cell-on';3524 };3525 })(j, num);3526 } else {3527 cell.onmouseover = function() {3528 this.className = 'ke-plugin-emoticons-cell ke-plugin-emoticons-cell-on';3529 };3530 }3531 cell.onmouseout = function() { this.className = 'ke-plugin-emoticons-cell'; };3532 cell.onclick = (function(num) {3533 return function() {3534 self.exec(id, num);3535 return false;3536 };3537 })(num);3538 var span = KE.$$('span');3539 span.className = 'ke-plugin-emoticons-img';3540 span.style.backgroundPosition = '-' + (24 * num) + 'px 0px';3541 cell.appendChild(span);3542 num++;3543 }3544 }3545 return table;3546 }3547 var table = createEmoticonsTable(1);3548 wrapperDiv.appendChild(table);3549 var pageDiv = KE.$$('div');3550 pageDiv.className = 'ke-plugin-emoticons-page';3551 wrapperDiv.appendChild(pageDiv);3552 function createPageTable(currentPageNum) {3553 for (var pageNum = 1; pageNum <= pages; pageNum++) {3554 if (currentPageNum !== pageNum) {3555 var a = KE.$$('a');3556 a.href = 'javascript:;';3557 a.innerHTML = '[' + pageNum + ']';3558 a.onclick = (function(pageNum) {3559 return function() {3560 wrapperDiv.removeChild(table);3561 var newTable = createEmoticonsTable(pageNum);3562 wrapperDiv.insertBefore(newTable, pageDiv);3563 table = newTable;3564 pageDiv.innerHTML = '';3565 createPageTable(pageNum);3566 return false;3567 };3568 })(pageNum);3569 pageDiv.appendChild(a);3570 } else {3571 pageDiv.appendChild(document.createTextNode('[' + pageNum + ']'));3572 }3573 pageDiv.appendChild(document.createTextNode(' '));3574 }3575 }3576 createPageTable(1);3577 var menu = new KE.menu({3578 id : id,3579 cmd : cmd3580 });3581 menu.append(wrapperDiv);3582 menu.show();3583 this.menu = menu;3584 },3585 exec : function(id, num) {3586 var src = KE.g[id].pluginsPath + 'emoticons/' + num + '.gif';3587 var html = '<img src="' + src + '" kesrc="' + src + '" border="0" alt="" />';3588 KE.util.insertHtml(id, html);3589 this.menu.hide();3590 KE.util.focus(id);3591 }3592};3593KE.plugin['flash'] = {3594 init : function(id) {3595 var self = this;3596 KE.g[id].getHtmlHooks.push(function(html) {3597 return html.replace(/<img[^>]*class="?ke-flash"?[^>]*>/ig, function(imgStr) {3598 var width = imgStr.match(/style="[^"]*;?\s*width:\s*(\d+)/i) ? RegExp.$1 : 0;3599 var height = imgStr.match(/style="[^"]*;?\s*height:\s*(\d+)/i) ? RegExp.$1 : 0;3600 width = width || (imgStr.match(/width="([^"]+)"/i) ? RegExp.$1 : 0);3601 height = height || (imgStr.match(/height="([^"]+)"/i) ? RegExp.$1 : 0);3602 if (imgStr.match(/kesrctag="([^"]+)"/i)) {3603 var attrs = KE.util.getAttrList(unescape(RegExp.$1));3604 attrs.width = width || attrs.width || 0;3605 attrs.height = height || attrs.height || 0;3606 attrs.kesrc = attrs.src;3607 return KE.util.getMediaEmbed(attrs);3608 }3609 });3610 });3611 KE.g[id].setHtmlHooks.push(function(html) {3612 return html.replace(/<embed[^>]*type="application\/x-shockwave-flash"[^>]*>(?:<\/embed>)?/ig, function($0) {3613 var src = $0.match(/\s+src="([^"]+)"/i) ? RegExp.$1 : '';3614 if ($0.match(/\s+kesrc="([^"]+)"/i)) src = RegExp.$1;3615 var width = $0.match(/\s+width="([^"]+)"/i) ? RegExp.$1 : 0;3616 var height = $0.match(/\s+height="([^"]+)"/i) ? RegExp.$1 : 0;3617 var attrs = KE.util.getAttrList($0);3618 attrs.src = src;3619 attrs.width = width;3620 attrs.height = height;3621 return KE.util.getMediaImage(id, 'flash', attrs);3622 });3623 });3624 },3625 click : function(id) {3626 KE.util.selection(id);3627 this.dialog = new KE.dialog({3628 id : id,3629 cmd : 'flash',3630 file : 'flash.html',3631 width : 400,3632 height : 140,3633 loadingMode : true,3634 title : KE.lang['flash'],3635 yesButton : KE.lang['yes'],3636 noButton : KE.lang['no']3637 });3638 this.dialog.show();3639 },3640 check : function(id, url, width, height) {3641 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3642 if (!url.match(/^.{3,}$/)) {3643 alert(KE.lang['invalidUrl']);3644 KE.$('url', dialogDoc).focus();3645 return false;3646 }3647 if (!width.match(/^\d*$/)) {3648 alert(KE.lang['invalidWidth']);3649 KE.$('width', dialogDoc).focus();3650 return false;3651 }3652 if (!height.match(/^\d*$/)) {3653 alert(KE.lang['invalidHeight']);3654 KE.$('height', dialogDoc).focus();3655 return false;3656 }3657 return true;3658 },3659 exec : function(id) {3660 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3661 var url = KE.$('url', dialogDoc).value;3662 var width = KE.$('width', dialogDoc).value;3663 var height = KE.$('height', dialogDoc).value;3664 if (!this.check(id, url, width, height)) return false;3665 var html = KE.util.getMediaImage(id, 'flash', {3666 src : url,3667 type : KE.g[id].mediaTypes['flash'],3668 width : width,3669 height : height,3670 quality : 'high'3671 });3672 KE.util.insertHtml(id, html);3673 this.dialog.hide();3674 KE.util.focus(id);3675 }3676};3677KE.plugin['image'] = {3678 getSelectedNode : function(id) {3679 var g = KE.g[id];3680 var startNode = g.keRange.startNode;3681 var endNode = g.keRange.endNode;3682 if (!KE.browser.WEBKIT && !g.keSel.isControl) return;3683 if (startNode.nodeType != 1) return;3684 if (startNode.tagName.toLowerCase() != 'img') return;3685 if (startNode != endNode) return;3686 if (!startNode.className.match(/^ke-\w+/i)) return startNode;3687 },3688 init : function(id) {3689 var self = this;3690 var g = KE.g[id];3691 g.contextmenuItems.push({3692 text : KE.lang['editImage'],3693 click : function(id, menu) {3694 KE.util.select(id);3695 menu.hide();3696 self.click(id);3697 },3698 cond : function(id) {3699 return self.getSelectedNode(id);3700 },3701 options : {3702 width : '150px',3703 iconHtml : '<span class="ke-common-icon ke-common-icon-url ke-icon-image"></span>'3704 }3705 });3706 g.contextmenuItems.push({3707 text : KE.lang['deleteImage'],3708 click : function(id, menu) {3709 KE.util.select(id);3710 menu.hide();3711 var img = self.getSelectedNode(id);3712 img.parentNode.removeChild(img);3713 KE.util.execOnchangeHandler(id);3714 },3715 cond : function(id) {3716 return self.getSelectedNode(id);3717 },3718 options : {3719 width : '150px'3720 }3721 });3722 g.contextmenuItems.push('-');3723 },3724 click : function(id) {3725 KE.util.selection(id);3726 this.dialog = new KE.dialog({3727 id : id,3728 cmd : 'image',3729 file : 'image/image.html',3730 width : 400,3731 height : 220,3732 loadingMode : true,3733 title : KE.lang['image'],3734 yesButton : KE.lang['yes'],3735 noButton : KE.lang['no']3736 });3737 this.dialog.show();3738 },3739 check : function(id) {3740 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3741 var type = KE.$('type', dialogDoc).value;3742 var width = KE.$('imgWidth', dialogDoc).value;3743 var height = KE.$('imgHeight', dialogDoc).value;3744 var title = KE.$('imgTitle', dialogDoc).value;3745 var urlBox;3746 if (type == 2) {3747 urlBox = KE.$('imgFile', dialogDoc);3748 } else {3749 urlBox = KE.$('url', dialogDoc);3750 }3751 if (!urlBox.value.match(/\.(jpg|jpeg|gif|bmp|png)(\s|\?|$)/i)) {3752 alert(KE.lang['invalidImg']);3753 urlBox.focus();3754 return false;3755 }3756 if (!width.match(/^\d*$/)) {3757 alert(KE.lang['invalidWidth']);3758 KE.$('imgWidth', dialogDoc).focus();3759 return false;3760 }3761 if (!height.match(/^\d*$/)) {3762 alert(KE.lang['invalidHeight']);3763 KE.$('imgHeight', dialogDoc).focus();3764 return false;3765 }3766 return true;3767 },3768 exec : function(id) {3769 var self = this;3770 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3771 var type = KE.$('type', dialogDoc).value;3772 var width = KE.$('imgWidth', dialogDoc).value;3773 var height = KE.$('imgHeight', dialogDoc).value;3774 var title = KE.$('imgTitle', dialogDoc).value;3775 var alignElements = dialogDoc.getElementsByName('align');3776 var align = '';3777 for (var i = 0, len = alignElements.length; i < len; i++) {3778 if (alignElements[i].checked) {3779 align = alignElements[i].value;3780 break;3781 }3782 }3783 if (!this.check(id)) return false;3784 if (type == 2) {3785 KE.$('editorId', dialogDoc).value = id;3786 var uploadIframe = KE.$('uploadIframe', dialogDoc);3787 KE.util.showLoadingPage(id);3788 var onloadFunc = function() {3789 KE.event.remove(uploadIframe, 'load', onloadFunc);3790 KE.util.hideLoadingPage(id);3791 var uploadDoc = KE.util.getIframeDoc(uploadIframe);3792 var data = '';3793 try {3794 data = KE.util.parseJson(uploadDoc.body.innerHTML);3795 } catch(e) {3796 alert(KE.lang.invalidJson);3797 }3798 if (typeof data === 'object' && 'error' in data) {3799 if (data.error === 0) {3800 self.insert(id, data.url, title, width, height, 0, align);3801 } else {3802 alert(data.message);3803 return false;3804 }3805 }3806 };3807 KE.event.add(uploadIframe, 'load', onloadFunc);3808 dialogDoc.uploadForm.submit();3809 return;3810 } else {3811 var url = KE.$('url', dialogDoc).value;3812 this.insert(id, url, title, width, height, 0, align);3813 }3814 },3815 insert : function(id, url, title, width, height, border, align) {3816 var html = '<img src="' + url + '" kesrc="' + url + '" ';3817 if (width > 0) html += 'width="' + width + '" ';3818 if (height > 0) html += 'height="' + height + '" ';3819 if (title) html += 'title="' + title + '" ';3820 if (align) html += 'align="' + align + '" ';3821 html += 'alt="' + title + '" ';3822 html += 'border="' + border + '" />';3823 KE.util.insertHtml(id, html);3824 this.dialog.hide();3825 KE.util.focus(id);3826 }3827};3828KE.plugin['link'] = {3829 getSelectedNode : function(id) {3830 return KE.getCommonAncestor(KE.g[id].keSel, 'a');3831 },3832 init : function(id) {3833 var self = this;3834 KE.g[id].contextmenuItems.push({3835 text : KE.lang['editLink'],3836 click : function(id, menu) {3837 KE.util.select(id);3838 menu.hide();3839 self.click(id);3840 },3841 cond : function(id) {3842 return self.getSelectedNode(id);3843 },3844 options : {3845 width : '150px',3846 iconHtml : '<span class="ke-common-icon ke-common-icon-url ke-icon-link"></span>'3847 }3848 });3849 },3850 click : function(id) {3851 KE.util.selection(id);3852 this.dialog = new KE.dialog({3853 id : id,3854 cmd : 'link',3855 file : 'link/link.html',3856 width : 400,3857 height : 90,3858 loadingMode : true,3859 title : KE.lang['link'],3860 yesButton : KE.lang['yes'],3861 noButton : KE.lang['no']3862 });3863 this.dialog.show();3864 },3865 exec : function(id) {3866 var g = KE.g[id];3867 KE.util.select(id);3868 var range = g.keRange;3869 var startNode = range.startNode;3870 var endNode = range.endNode;3871 var iframeDoc = g.iframeDoc;3872 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);3873 var url = KE.$('hyperLink', dialogDoc).value;3874 var target = KE.$('linkType', dialogDoc).value;3875 if (!url.match(/.+/) || url.match(/^\w+:\/\/\/?$/)) {3876 alert(KE.lang['invalidUrl']);3877 KE.$('hyperLink', dialogDoc).focus();3878 return false;3879 }3880 var node = range.getParentElement();3881 while (node) {3882 if (node.tagName.toLowerCase() == 'a' || node.tagName.toLowerCase() == 'body') break;3883 node = node.parentNode;3884 }3885 node = node.parentNode;3886 var isItem;3887 if (KE.browser.IE) {3888 isItem = !!g.range.item;3889 } else {3890 isItem = (startNode.nodeType == 1 && startNode === endNode && startNode.nodeName.toLowerCase() != 'br');3891 }3892 var isEmpty = !isItem;3893 if (!isItem) isEmpty = KE.browser.IE ? g.range.text === '' : g.range.toString() === '';3894 if (isEmpty || KE.util.isEmpty(id)) {3895 var html = '<a href="' + url + '"';3896 if (target) html += ' target="' + target + '"';3897 html += '>' + url + '</a>';3898 KE.util.insertHtml(id, html);3899 } else {3900 iframeDoc.execCommand('createlink', false, '__ke_temp_url__');3901 var arr = node.getElementsByTagName('a');3902 for (var i = 0, l = arr.length; i < l; i++) {3903 if (arr[i].href.match(/\/?__ke_temp_url__$/)) {3904 arr[i].href = url;3905 arr[i].setAttribute('kesrc', url);3906 if (target) arr[i].target = target;3907 else arr[i].removeAttribute('target');3908 }3909 }3910 if (KE.browser.WEBKIT && isItem && startNode.tagName.toLowerCase() == 'img') {3911 var parent = startNode.parentNode;3912 if (parent.tagName.toLowerCase() != 'a') {3913 var a = KE.$$('a', iframeDoc);3914 parent.insertBefore(a, startNode);3915 a.appendChild(startNode);3916 parent = a;3917 }3918 parent.href = url;3919 parent.setAttribute('kesrc', url);3920 if (target) parent.target = target;3921 else parent.removeAttribute('target');3922 g.keSel.addRange(range);3923 }3924 }3925 KE.util.execOnchangeHandler(id);3926 this.dialog.hide();3927 KE.util.focus(id);3928 }3929};3930KE.plugin['unlink'] = {3931 init : function(id) {3932 var self = this;3933 KE.g[id].contextmenuItems.push({3934 text : KE.lang['deleteLink'],3935 click : function(id, menu) {3936 KE.util.select(id);3937 menu.hide();3938 self.click(id);3939 },3940 cond : function(id) {3941 return KE.plugin['link'].getSelectedNode(id);3942 },3943 options : {3944 width : '150px',3945 iconHtml : '<span class="ke-common-icon ke-common-icon-url ke-icon-unlink"></span>'3946 }3947 });3948 KE.g[id].contextmenuItems.push('-');3949 },3950 click : function(id) {3951 var g = KE.g[id];3952 var iframeDoc = g.iframeDoc;3953 KE.util.selection(id);3954 var range = g.keRange;3955 var startNode = range.startNode;3956 var endNode = range.endNode;3957 var isItem = (startNode.nodeType == 1 && startNode === endNode);3958 var isEmpty = !isItem;3959 if (!isItem) isEmpty = KE.browser.IE ? g.range.text === '' : g.range.toString() === '';3960 if (isEmpty) {3961 var linkNode = KE.plugin['link'].getSelectedNode(id);3962 if (!linkNode) return;3963 var range = g.keRange;3964 range.selectTextNode(linkNode);3965 g.keSel.addRange(range);3966 KE.util.select(id);3967 iframeDoc.execCommand('unlink', false, null);3968 if (KE.browser.WEBKIT && startNode.tagName.toLowerCase() == 'img') {3969 var parent = startNode.parentNode;3970 if (parent.tagName.toLowerCase() == 'a') {3971 KE.util.removeParent(parent);3972 g.keSel.addRange(range);3973 }3974 }3975 } else {3976 iframeDoc.execCommand('unlink', false, null);3977 }3978 KE.util.execOnchangeHandler(id);3979 KE.toolbar.updateState(id);3980 KE.util.focus(id);3981 }3982};3983KE.plugin['media'] = {3984 init : function(id) {3985 var self = this;3986 var typeHash = {};3987 KE.each(KE.g[id].mediaTypes, function(key, val) {3988 typeHash[val] = key;3989 });3990 KE.g[id].getHtmlHooks.push(function(html) {3991 return html.replace(/<img[^>]*class="?ke-\w+"?[^>]*>/ig, function($0) {3992 var width = $0.match(/style="[^"]*;?\s*width:\s*(\d+)/i) ? RegExp.$1 : 0;3993 var height = $0.match(/style="[^"]*;?\s*height:\s*(\d+)/i) ? RegExp.$1 : 0;3994 width = width || ($0.match(/width="([^"]+)"/i) ? RegExp.$1 : 0);3995 height = height || ($0.match(/height="([^"]+)"/i) ? RegExp.$1 : 0);3996 if ($0.match(/\s+kesrctag="([^"]+)"/i)) {3997 var attrs = KE.util.getAttrList(unescape(RegExp.$1));3998 attrs.width = width || attrs.width || 0;3999 attrs.height = height || attrs.height || 0;4000 attrs.kesrc = attrs.src;4001 return KE.util.getMediaEmbed(attrs);4002 }4003 });4004 });4005 KE.g[id].setHtmlHooks.push(function(html) {4006 return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function($0, $1) {4007 if (typeof typeHash[$1] == 'undefined') return $0;4008 var src = $0.match(/\s+src="([^"]+)"/i) ? RegExp.$1 : '';4009 if ($0.match(/\s+kesrc="([^"]+)"/i)) src = RegExp.$1;4010 var width = $0.match(/\s+width="([^"]+)"/i) ? RegExp.$1 : 0;4011 var height = $0.match(/\s+height="([^"]+)"/i) ? RegExp.$1 : 0;4012 var attrs = KE.util.getAttrList($0);4013 attrs.src = src;4014 attrs.width = width;4015 attrs.height = height;4016 return KE.util.getMediaImage(id, '', attrs);4017 });4018 });4019 },4020 click : function(id) {4021 KE.util.selection(id);4022 this.dialog = new KE.dialog({4023 id : id,4024 cmd : 'media',4025 file : 'media.html',4026 width : 400,4027 height : 170,4028 loadingMode : true,4029 title : KE.lang['media'],4030 yesButton : KE.lang['yes'],4031 noButton : KE.lang['no']4032 });4033 this.dialog.show();4034 },4035 check : function(id, url, width, height) {4036 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);4037 if (!url.match(/^.{3,}\.(swf|flv|mp3|wav|wma|wmv|mid|avi|mpg|mpeg|asf|rm|rmvb)(\?|$)/i)) {4038 alert(KE.lang['invalidMedia']);4039 KE.$('url', dialogDoc).focus();4040 return false;4041 }4042 if (!width.match(/^\d*$/)) {4043 alert(KE.lang['invalidWidth']);4044 KE.$('width', dialogDoc).focus();4045 return false;4046 }4047 if (!height.match(/^\d*$/)) {4048 alert(KE.lang['invalidHeight']);4049 KE.$('height', dialogDoc).focus();4050 return false;4051 }4052 return true;4053 },4054 exec : function(id) {4055 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);4056 var url = KE.$('url', dialogDoc).value;4057 var width = KE.$('width', dialogDoc).value;4058 var height = KE.$('height', dialogDoc).value;4059 if (!this.check(id, url, width, height)) return false;4060 var autostart = KE.$('autostart', dialogDoc).checked ? 'true' : 'false';4061 var html = KE.util.getMediaImage(id, '', {4062 src : url,4063 type : KE.g[id].mediaTypes[KE.util.getMediaType(url)],4064 width : width,4065 height : height,4066 autostart : autostart,4067 loop : 'true'4068 });4069 KE.util.insertHtml(id, html);4070 this.dialog.hide();4071 KE.util.focus(id);4072 }4073};4074KE.plugin['advtable'] = {4075 getSelectedTable : function(id) {4076 return KE.getCommonAncestor(KE.g[id].keSel, 'table');4077 },4078 getSelectedRow : function(id) {4079 return KE.getCommonAncestor(KE.g[id].keSel, 'tr');4080 },4081 getSelectedCell : function(id) {4082 return KE.getCommonAncestor(KE.g[id].keSel, 'td');4083 },4084 tableprop : function(id) {4085 this.click(id);4086 },4087 tableinsert : function(id) {4088 this.click(id, 'insert');4089 },4090 tabledelete : function(id) {4091 var table = this.getSelectedTable(id);4092 table.parentNode.removeChild(table);4093 },4094 tablecolinsert : function(id, offset) {4095 var table = this.getSelectedTable(id),4096 cell = this.getSelectedCell(id),4097 index = cell.cellIndex + offset;4098 for (var i = 0, len = table.rows.length; i < len; i++) {4099 var newCell = table.rows[i].insertCell(index);4100 newCell.innerHTML = '&nbsp;';4101 }4102 },4103 tablecolinsertleft : function(id) {4104 this.tablecolinsert(id, 0);4105 },4106 tablecolinsertright : function(id) {4107 this.tablecolinsert(id, 1);4108 },4109 tablerowinsert : function(id, offset) {4110 var table = this.getSelectedTable(id),4111 row = this.getSelectedRow(id),4112 newRow = table.insertRow(row.rowIndex + offset);4113 for (var i = 0, len = row.cells.length; i < len; i++) {4114 var cell = newRow.insertCell(i);4115 cell.innerHTML = '&nbsp;';4116 }4117 },4118 tablerowinsertabove : function(id) {4119 this.tablerowinsert(id, 0);4120 },4121 tablerowinsertbelow : function(id) {4122 this.tablerowinsert(id, 1);4123 },4124 tablecoldelete : function(id) {4125 var table = this.getSelectedTable(id);4126 var cell = this.getSelectedCell(id);4127 for (var i = 0, len = table.rows.length; i < len; i++) {4128 table.rows[i].deleteCell(cell.cellIndex);4129 }4130 },4131 tablerowdelete : function(id) {4132 var table = this.getSelectedTable(id);4133 var row = this.getSelectedRow(id);4134 table.deleteRow(row.rowIndex);4135 },4136 init : function(id) {4137 var self = this;4138 var zeroborder = 'ke-zeroborder';4139 var tableCmds = 'prop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,coldelete,rowdelete,insert,delete'.split(',');4140 for (var i = 0, len = tableCmds.length; i < len; i++) {4141 var name = 'table' + tableCmds[i];4142 KE.g[id].contextmenuItems.push({4143 text : KE.lang[name],4144 click : (function(name) {4145 return function(id, menu) {4146 KE.util.select(id);4147 menu.hide();4148 if (self[name] !== undefined) self[name](id);4149 if (!/prop/.test(name)) {4150 KE.util.execOnchangeHandler(id);4151 }4152 };4153 })(name),4154 cond : (function(name) {4155 if (KE.util.inArray(name, ['tableprop', 'tabledelete'])) {4156 return function(id) {4157 return self.getSelectedTable(id);4158 };4159 } else {4160 return function(id) {4161 return self.getSelectedCell(id);4162 };4163 }4164 })(name),4165 options : {4166 width : '170px',4167 iconHtml : '<span class="ke-common-icon ke-common-icon-url ke-icon-' + name + '"></span>'4168 }4169 });4170 }4171 KE.g[id].contextmenuItems.push('-');4172 KE.g[id].setHtmlHooks.push(function(html) {4173 return html.replace(/<table([^>]*)>/ig, function($0, $1) {4174 if ($1.match(/\s+border=["']?(\d*)["']?/ig)) {4175 var border = RegExp.$1;4176 if ($1.indexOf(zeroborder) < 0 && (border === '' || border === '0')) {4177 return KE.addClass($0, zeroborder);4178 } else {4179 return $0;4180 }4181 } else {4182 return KE.addClass($0, zeroborder);4183 }4184 });4185 });4186 },4187 click : function(id, mode) {4188 mode = mode || 'default';4189 var cmd = 'advtable';4190 KE.util.selection(id);4191 this.dialog = new KE.dialog({4192 id : id,4193 cmd : cmd,4194 file : 'advtable/advtable.html?mode=' + mode,4195 width : 420,4196 height : 220,4197 loadingMode : true,4198 title : KE.lang['advtable'],4199 yesButton : KE.lang['yes'],4200 noButton : KE.lang['no']4201 });4202 this.dialog.show();4203 },4204 exec : function(id) {4205 var zeroborder = 'ke-zeroborder';4206 var dialogDoc = KE.util.getIframeDoc(this.dialog.iframe);4207 var modeBox = KE.$('mode', dialogDoc);4208 var rowsBox = KE.$('rows', dialogDoc);4209 var colsBox = KE.$('cols', dialogDoc);4210 var widthBox = KE.$('width', dialogDoc);4211 var heightBox = KE.$('height', dialogDoc);4212 var widthTypeBox = KE.$('widthType', dialogDoc);4213 var heightTypeBox = KE.$('heightType', dialogDoc);4214 var paddingBox = KE.$('padding', dialogDoc);4215 var spacingBox = KE.$('spacing', dialogDoc);4216 var alignBox = KE.$('align', dialogDoc);4217 var borderBox = KE.$('border', dialogDoc);4218 var borderColorBox = KE.$('borderColor', dialogDoc);4219 var backgroundColorBox = KE.$('backgroundColor', dialogDoc);4220 var rows = rowsBox.value;4221 var cols = colsBox.value;4222 var width = widthBox.value;4223 var height = heightBox.value;4224 var widthType = widthTypeBox.value;4225 var heightType = heightTypeBox.value;4226 var padding = paddingBox.value;4227 var spacing = spacingBox.value;4228 var align = alignBox.value;4229 var border = borderBox.value;4230 var borderColor = borderColorBox.innerHTML;4231 var backgroundColor = backgroundColorBox.innerHTML;4232 if (rows == '' || rows == 0 || !rows.match(/^\d*$/)) {4233 alert(KE.lang['invalidRows']);4234 rowsBox.focus();4235 return false;4236 }4237 if (cols == '' || cols == 0 || !cols.match(/^\d*$/)) {4238 alert(KE.lang['invalidCols']);4239 colsBox.focus();4240 return false;4241 }4242 if (!width.match(/^\d*$/)) {4243 alert(KE.lang['invalidWidth']);4244 widthBox.focus();4245 return false;4246 }4247 if (!height.match(/^\d*$/)) {4248 alert(KE.lang['invalidHeight']);4249 heightBox.focus();4250 return false;4251 }4252 if (!padding.match(/^\d*$/)) {4253 alert(KE.lang['invalidPadding']);4254 paddingBox.focus();4255 return false;4256 }4257 if (!spacing.match(/^\d*$/)) {4258 alert(KE.lang['invalidSpacing']);4259 spacingBox.focus();4260 return false;4261 }4262 if (!border.match(/^\d*$/)) {4263 alert(KE.lang['invalidBorder']);4264 borderBox.focus();4265 return false;4266 }4267 if (modeBox.value === 'update') {4268 var table = this.getSelectedTable(id);4269 if (width !== '') {4270 table.style.width = width + widthType;4271 } else if (table.style.width) {4272 table.style.width = '';4273 }4274 if (table.width !== undefined) {4275 table.removeAttribute('width');4276 }4277 if (height !== '') {4278 table.style.height = height + heightType;4279 } else if (table.style.height) {4280 table.style.height = '';4281 }4282 if (table.height !== undefined) {4283 table.removeAttribute('height');4284 }4285 if (backgroundColor !== '') {4286 table.style.backgroundColor = backgroundColor;4287 } else if (table.style.backgroundColor) {4288 table.style.backgroundColor = '';4289 }4290 if (table.bgColor !== undefined) {4291 table.removeAttribute('bgColor');4292 }4293 if (padding !== '') {4294 table.cellPadding = padding;4295 } else {4296 table.removeAttribute('cellPadding');4297 }4298 if (spacing !== '') {4299 table.cellSpacing = spacing;4300 } else {4301 table.removeAttribute('cellSpacing');4302 }4303 if (align !== '') {4304 table.align = align;4305 } else {4306 table.removeAttribute('align');4307 }4308 if (border === '' || border === '0') {4309 KE.addClass(table, zeroborder);4310 } else {4311 KE.removeClass(table, zeroborder);4312 }4313 if (border !== '') {4314 table.setAttribute('border', border);4315 } else {4316 table.removeAttribute('border');4317 }4318 if (borderColor !== '') {4319 table.setAttribute('borderColor', borderColor);4320 } else {4321 table.removeAttribute('borderColor');4322 }4323 KE.util.execOnchangeHandler(id);4324 } else {4325 var style = '';4326 if (width !== '') style += 'width:' + width + widthType + ';';4327 if (height !== '') style += 'height:' + height + heightType + ';';4328 if (backgroundColor !== '') style += 'background-color:' + backgroundColor + ';';4329 var html = '<table';4330 if (style !== '') html += ' style="' + style + '"';4331 if (padding !== '') html += ' cellpadding="' + padding + '"';4332 if (spacing !== '') html += ' cellspacing="' + spacing + '"';4333 if (align !== '') html += ' align="' + align + '"';4334 if (border === '' || border === '0') html += ' class="' + zeroborder + '"';4335 if (border !== '') html += ' border="' + border + '"';4336 if (borderColor !== '') html += ' bordercolor="' + borderColor + '"';4337 html += '>';4338 for (var i = 0; i < rows; i++) {4339 html += '<tr>';4340 for (var j = 0; j < cols; j++) {4341 html += '<td>&nbsp;</td>';4342 }4343 html += '</tr>';4344 }4345 html += '</table>';4346 KE.util.insertHtml(id, html);4347 }4348 this.dialog.hide();4349 KE.util.focus(id);4350 }4351};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 {3 },4 {5 },6 {7 },8 {9 }10 {11 }12 paths: {13 },14 engineOptions: {15 },16};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 {3 },4 {5 }6 {7 }8 paths: {9 },10 engineOptions: {11 },12};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 {3 },4 {5 },6 {7 },8 {9 },10 {11 }12 {13 },14 {15 }16 paths: {17 },18 engineOptions: {19 },

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 {3 }4 {5 }6};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = async (page, scenario) => {2 const hoverSelector = scenario.hoverSelector;3 const clickSelector = scenario.clickSelector;4 if (hoverSelector) {5 await page.waitForSelector(hoverSelector);6 await page.hover(hoverSelector);7 }8 if (clickSelector) {9 await page.waitForSelector(clickSelector);10 await page.click(clickSelector);11 }12 if (postInteractionWait) {13 await page.waitFor(postInteractionWait);14 }15};

Full Screen

Using AI Code Generation

copy

Full Screen

1var args = require('minimist')(process.argv.slice(2));2var casename = args.casename;3var url = args.url;4var ke = require('ke-cli');5var keConfig = require('./backstop.json');6keConfig.scenarios[0].label = casename;7keConfig.scenarios[0].url = url;8keConfig.id = casename;9keConfig.paths.bitmaps_reference = 'tests/backstop_data/bitmaps_reference/'+casename;10keConfig.paths.bitmaps_test = 'tests/backstop_data/bitmaps_test/'+casename;11keConfig.paths.html_report = 'tests/backstop_data/html_report/'+casename;12keConfig.paths.ci_report = 'tests/backstop_data/ci_report/'+casename;13keConfig.scenarios[0].referenceUrl = url;14ke.run(keConfig);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run backstopjs automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful