41 var $name =
'wysiwyg';
50 var $body_type =
'iframe';
59 var $init_onload = TRUE;
68 var $show_status_bar = TRUE;
100 var $height =
'auto';
108 var $relative_href_checks = Array();
116 var $absolute_url_checks = Array();
124 var $textarea_extras =
'';
140 var $_plugins = Array();
148 var $_loaded_plugins = Array();
156 var $_group_open = FALSE;
174 var $dir_attribute =
'';
184 function wysiwyg($name=
'wysiwyg', $web_path=
'')
187 $this->web_path = $web_path;
189 $ROOT_PATH = realpath(dirname(__FILE__)).
'/';
203 global $WYSIWYG_INIT;
204 if (!$WYSIWYG_INIT) {
206 <script type=
"text/javascript">
225 function HTMLArea(textarea, config) {
226 if (HTMLArea.checkSupportedBrowser()) {
227 if (typeof config ==
"undefined") {
228 eval(
"this.config = new HTMLArea.Config_" + textarea +
"();");
230 this.config = config;
233 this._htmlArea = null;
234 this._textArea = textarea;
235 this._uniqueID = textarea;
236 this._editMode =
"wysiwyg";
237 this._initialised =
false;
238 this._timerToolbar = null;
239 this._toolbarObjects = Array();
240 this._toolbarMenus = Array();
247 <script type=
"text/javascript">
249 HTMLArea.prototype._createToolbar =
function () {
252 var toolbar = document.createElement(
"div");
254 if ($this->width !=
'auto') {
255 echo
'toolbar.style.width = "'.$this->width.
'";';
258 var innerToolbar = document.createElement(
"div");
260 var table = document.createElement(
"table");
261 table.border =
"0px";
262 table.cellSpacing =
"1px";
263 table.cellPadding =
"1px";
265 toolbar.appendChild(table);
267 var tb_body = document.createElement(
"tbody");
268 table.appendChild(tb_body);
269 tb_row = document.createElement(
"tr");
270 tb_body.appendChild(tb_row);
271 tb_cell = document.createElement(
"td");
272 tb_row.appendChild(tb_cell);
273 tb_cell.appendChild(innerToolbar);
275 this._toolbar = toolbar;
276 toolbar.className =
"htmlarea-toolbar";
277 toolbar.unselectable =
"1";
278 var tb_objects =
new Object();
279 this._toolbarObjects = tb_objects;
282 function setButtonStatus(
id, newval) {
283 var oldval =
this[id];
284 var el = this.element;
285 var img = el.style.backgroundImage;
286 if (img !=
"" && oldval != newval) {
290 HTMLArea._removeClass(el,
"htmlarea-buttonDisabled");
291 el.style.backgroundImage =
"url(" + editor.imgURL(
"toolbar.png") +
")";
294 HTMLArea._addClass(el,
"htmlarea-buttonDisabled");
295 el.style.backgroundImage =
"url(" + editor.imgURL(
"toolbar_disabled.png") +
")";
301 HTMLArea._addClass(el,
"htmlarea-buttonPressed");
303 HTMLArea._removeClass(el,
"htmlarea-buttonPressed");
312 function createSelect(txt) {
321 sel = document.createElement(
"select");
322 sel.className =
"htmlarea-select";
329 state: setButtonStatus
331 tb_objects[txt] = obj;
332 for (var i in options) {
333 var op = document.createElement(
"option");
334 op.appendChild(document.createTextNode(i));
335 op.value = options[i];
338 el = document.createElement(
"div");
339 el.className =
"htmlarea-select-container";
342 HTMLArea._addEvent(sel,
"change",
function () {
343 editor._comboSelected(sel, txt);
350 function createButton(container, txt) {
356 el = document.createElement(
"div");
357 el2 = document.createElement(
"div");
359 el.className =
"htmlarea-separator";
362 el = document.createElement(
"div");
363 el.className =
"htmlarea-space";
366 el = document.createElement(
"div");
367 el.className =
"htmlarea-space";
371 btn = editor.config.btnList[txt];
375 el = document.createElement(
"div");
377 el.className =
"htmlarea-button";
388 state : setButtonStatus,
389 context : btn[4] || null
391 tb_objects[txt] = obj;
394 HTMLArea._addEvent(el,
"mouseover",
function () {
396 HTMLArea._addClass(el,
"htmlarea-buttonHover");
399 HTMLArea._addEvent(el,
"mouseout",
function () {
400 if (obj.enabled) with (HTMLArea) {
401 _removeClass(el,
"htmlarea-buttonHover");
402 _removeClass(el,
"htmlarea-buttonActive");
403 (obj.active) && _addClass(el,
"htmlarea-buttonPressed");
406 HTMLArea._addEvent(el,
"mousedown",
function (ev) {
407 if (obj.enabled) with (HTMLArea) {
408 _addClass(el,
"htmlarea-buttonActive");
409 _removeClass(el,
"htmlarea-buttonPressed");
410 _stopEvent(is_ie ? window.event : ev);
414 HTMLArea._addEvent(el,
"click",
function (ev) {
415 if (obj.enabled) with (HTMLArea) {
416 _removeClass(el,
"htmlarea-buttonActive");
417 _removeClass(el,
"htmlarea-buttonHover");
418 editor._buttonClicked(txt);
419 _stopEvent(is_ie ? window.event : ev);
423 var buttonID = editor._uniqueID +
"_" + txt;
424 buttonID = buttonID.toLowerCase();
425 el.id = buttonID +
"_span";
426 var btnTop = Math.floor(btn[3] / 5);
427 var btnLeft = ((btn[3] - (btnTop * 5)) * 18);
428 el.style.background =
"url(" + editor.imgURL(
"toolbar.png") +
") scroll -" + btnLeft +
"px -" + (btnTop * 20) +
"px";
429 el.innerHTML =
'<img src="' + editor.imgURL(
"blank.gif") +
'" width="17" height="19" />';
432 el = createSelect(txt);
435 container.appendChild(el);
436 }
else if (txt !=
'addkeyword') {
441 alert(js_translate(
'unknown_toolbar_item', txt));
446 for (var i in this.config.toolbar) {
447 var group = this.config.toolbar[i];
448 for (var j in group) {
450 if (menu.length < 1) {
452 }
else if (menu.length == 1) {
453 createButton(innerToolbar, menu[0]);
455 var div = document.createElement(
"div");
456 editor._toolbar.appendChild(div);
457 div.style.display =
"none";
458 div.style.position =
"absolute";
459 div.className =
"htmlarea-menu";
460 div.id = menu[0] +
"_menu";
462 createButton(innerToolbar, menu[0]);
463 this.config.btnList[menu[0]][0] =
"htmlarea-showmenu-" + menu[0];
465 for (var x in menu) {
466 if (x == 0) {
continue; }
468 var table = document.createElement(
"table");
469 var tb_body = document.createElement(
"tbody");
470 var tb_row = document.createElement(
"tr");
471 var tb_cell = document.createElement(
"td");
472 table.appendChild(tb_body);
473 tb_body.appendChild(tb_row);
474 tb_row.appendChild(tb_cell);
476 table.className =
"htmlarea-menuRow";
477 createButton(tb_cell, menu[x])
479 tb_cell = document.createElement(
"td");
480 tb_cell.className =
"htmlarea-menuText";
481 tb_row.appendChild(tb_cell);
483 var title = document.createTextNode(this.config.btnList[menu[x]][1]);
484 tb_cell.appendChild(title);
486 div.appendChild(table);
488 this._toolbarMenus[div.id] = div;
495 HTMLArea.prototype.updateToolbar =
function(allEnabled, noStatus) {
497 var text = (this._editMode ==
"textmode");
498 var ancestors = null;
499 var htmlareaFound =
false;
502 ancestors = this.getAllAncestors();
503 if (this.config.statusBar && !noStatus) {
504 this._statusBarTree.innerHTML =
'';
505 for (var i = ancestors.length; --i >= 0;) {
506 var el = ancestors[i];
516 var txt = el.tagName.toLowerCase();
521 txt +=
"." + el.className;
527 if (HTMLArea.is_ie &&
this.config.bodyType.toLowerCase() !=
'iframe') {
528 if (el.id ==
"htmlarea") {
529 htmlareaFound =
true;
531 var el = ancestors[i];
534 if (!htmlareaFound) {
continue; }
537 var a = document.createElement(
"a");
541 a.onclick =
function() {
543 this.editor.selectNodeContents(this.el);
544 this.editor.updateToolbar(
true);
547 a.oncontextmenu =
function() {
550 var info =
"Inline style:\n\n";
551 info += this.el.style.cssText.split(/;\s*/).join(
";\n");
555 a.title = el.style.cssText;
557 a.appendChild(document.createTextNode(txt));
558 this._statusBarTree.appendChild(a);
560 this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb)));
566 for (var i in this._toolbarObjects) {
567 var btn = this._toolbarObjects[i];
570 var inContext =
true;
571 if (btn.context && !text) {
573 var context = btn.context;
575 if (/(.*)\[(.*?)\]/.test(context)) {
577 attrs = RegExp.$2.split(
",");
579 context = context.toLowerCase();
580 var match = (context ==
"*");
581 htmlareaFound =
false;
582 for (var k = ancestors.length; --k >= 0;) {
583 var el = ancestors[k];
592 if (HTMLArea.is_ie &&
this.config.bodyType.toLowerCase() !=
'iframe') {
593 if (el.id ==
"htmlarea") {
594 htmlareaFound =
true;
598 if (!htmlareaFound) {
continue; }
601 if (match || (el.tagName.toLowerCase() == context)) {
603 for (var ka in attrs) {
604 if (!eval(
"ancestors[k]." + attrs[ka])) {
609 if (inContext) {
break; }
614 if (typeof cmd ==
"function") {
continue; }
616 if (allEnabled == null) {
617 var btnEnabled = (!text || btn.text) && inContext;
619 var btnEnabled = allEnabled;
621 btn.state(
"enabled", btnEnabled);
623 cmd = cmd.toLowerCase();
628 btn.state(
"active", (!text && doc.queryCommandState(cmd)));
636 HTMLArea.prototype._formSubmit =
function() {
638 var html = this.getHTML();
644 html = this.make_relative_hrefs(html);
645 this._textArea.value = html;
651 <script type=
"text/javascript">
653 HTMLArea.prototype._buttonClicked =
function(txt) {
656 var original_scroll = document.body.scrollTop;
661 document.body.scrollTop = original_scroll;
662 var btn = this.config.btnList[txt];
664 alert(
"FIXME: Unconfigured button!");
668 if (typeof cmd ==
"function") {
669 return cmd(
this, txt);
672 if (/htmlarea-showmenu-/.test(cmd.toLowerCase())) {
673 re =
new RegExp(
"htmlarea-showmenu-");
674 var menuID = cmd.replace(re,
"");
675 var menu = document.getElementById(menuID +
"_menu");
677 if (menu.style.display ==
"none") {
679 for (var x in this._toolbarMenus) {
680 this._toolbarMenus[x].style.display =
"none";
683 menu.style.display =
"block";
685 var buttonID = editor._uniqueID +
"_" + menuID +
"_span";
686 buttonID = buttonID.toLowerCase();
687 var button = document.getElementById(buttonID);
689 if (HTMLArea.is_ie) {
690 menu.style.pixelTop = button.offsetTop + 23;
691 menu.style.pixelLeft = button.offsetLeft;
693 menu.style.top = button.offsetTop + 23;
694 menu.style.left = button.offsetLeft;
697 menu.style.display =
"none";
702 for (var x in this._toolbarMenus) {
703 this._toolbarMenus[x].style.display =
"none";
706 switch (cmd.toLowerCase()) {
709 this._execCommand(btn[0],
false,
"");
713 this.updateToolbar();
715 document.body.scrollTop = original_scroll;
721 HTMLArea.prototype._comboSelected =
function(el, txt) {
723 var value = el.options[el.selectedIndex].value;
727 alert(js_translate(
'combo_box_not_implemented', txt));
734 HTMLArea.prototype._execCommand =
function(cmdID, UI, param) {
735 switch (cmdID.toLowerCase()) {
738 this._doc.execCommand(cmdID, UI, param);
745 HTMLArea.prototype.inline_tags = [
'a',
'abbr',
'acronym',
'b',
'bdo',
'big',
'cite',
'code',
'dfn',
'em',
'font',
'i',
'kbd',
'label',
'q',
's',
'samp',
'select',
'small',
'span',
'strike',
'strong',
'sub',
'sup',
'textarea',
'tt',
'u',
'var'];
748 HTMLArea.prototype.parentBlock =
function(node) {
750 while ( node.parentNode && ( node.nodeType != 1 ||
this.inArray( node.tagName.toLowerCase(), this.inline_tags ) ) ) node = node.parentNode;
755 HTMLArea.prototype.inArray =
function(val, arr) {
757 for (var i=0; i < arr.length; i++)
758 if (val == arr[i])
return true;
763 HTMLArea.prototype.set_dir_attr =
function(val) {
764 this._dir_attr = val;
769 HTMLArea.prototype.traverseChildrenNodes =
function(me, callback) {
771 if ( me.firstChild ) {
772 var myChild = me.firstChild;
775 if ( (retVal=callback(myChild)) != null )
return retVal;
776 if ( (retVal=this.traverseChildrenNodes(myChild, callback)) != null )
return retVal;
777 myChild = myChild.nextSibling;
784 HTMLArea.prototype.containsText =
function(node) {
786 if (node.nodeType == 1 && HTMLArea.prototype.inArray(node.nodeName.toLowerCase(), HTMLArea.prototype.inline_tags) && node.hasChildNodes() && node.firstChild.nodeValue)
return true;
787 else if (node.nodeType == 3 && node.nodeValue !=
'')
return true;
793 HTMLArea.prototype.insertDeepLeft =
function(target, toInsert) {
796 while ( digger.firstChild && digger.firstChild.nodeType == 1 ) digger = digger.firstChild;
797 var refNode = digger.firstChild ? digger.firstChild : null;
799 digger.innerHTML = toInsert;
802 HTMLArea.prototype.isElem =
function(node,type) {
803 return node.nodeName.toLowerCase() == type.toLowerCase();
810 HTMLArea.prototype._editorEvent =
function(ev) {
813 if (ev.type ==
"keypress" && !HTMLArea.is_ie) {
814 var keyCode = ev.keyCode;
815 if (keyCode == 13 && !ev.shiftKey &&
this._iframe.contentWindow.getSelection) {
818 var sel = this._iframe.contentWindow.getSelection();
821 var leftRange = this._doc.createRange();
822 var rightRange = this._doc.createRange();
827 var sAnchorNode = sel.anchorNode;
828 var sFocusNode = sel.focusNode;
829 var sAnchorOffset = sel.anchorOffset;
830 var sFocusOffset = sel.focusOffset;
832 if (sAnchorNode.nodeName ==
'BODY' && sAnchorNode.childNodes[sAnchorOffset]) {
833 sAnchorNode = sAnchorNode.childNodes[sAnchorOffset];
836 while(sAnchorNode.childNodes[0] && sAnchorNode.nodeName !=
'#text')
837 sAnchorNode = sAnchorNode.childNodes[0];
840 if (sFocusNode.nodeName ==
'BODY' && sFocusNode.childNodes[sFocusOffset]) {
841 sFocusNode = sFocusNode.childNodes[sFocusOffset];
844 while(sFocusNode.childNodes[0] && sFocusNode.nodeName !=
'#text')
845 sFocusNode = sFocusNode.childNodes[0];
848 if (sAnchorNode.nodeName !=
'#text') {
849 empty_node = document.createTextNode(
'');
850 if (sAnchorNode.nodeName !=
'BR') {
851 sAnchorNode.appendChild(empty_node);
853 sAnchorNode.parentNode.insertBefore(empty_node, sAnchorNode.nextSibling);
855 sAnchorNode = empty_node;
859 if (sFocusNode.nodeName !=
'#text') {
860 empty_node = document.createTextNode(
'');
861 if (sFocusNode.nodeName !=
'BR') {
862 sFocusNode.appendChild(empty_node);
864 sFocusNode.parentNode.insertBefore(empty_node, sFocusNode.nextSibling);
866 sFocusNode = empty_node;
870 leftRange.setStart(sAnchorNode,sAnchorOffset);
871 rightRange.setStart(sFocusNode,sFocusOffset);
872 leftRange.collapse(
true);
873 rightRange.collapse(
true);
875 var direct = leftRange.compareBoundaryPoints(leftRange.START_TO_END,rightRange);
877 var startNode = (direct<0) ? sAnchorNode : sFocusNode;
878 var startOffset = (direct<0) ? sAnchorOffset : sFocusOffset;
879 var endNode = (direct<0) ? sFocusNode : sAnchorNode;
880 var endOffset = (direct<0) ? sFocusOffset : sAnchorOffset;
884 if (startOffset == endOffset && startNode == endNode && endNode.nodeValue && endNode.nodeValue.length == endOffset && endNode.parentNode &&
this.isElem(endNode.parentNode,
'a') && endNode.parentNode.parentNode) {
886 blank_node = document.createTextNode(
'');
887 endNode.parentNode.parentNode.appendChild(blank_node);
889 startNode = blank_node;
891 endNode = blank_node;
896 var startBlock = this.parentBlock(startNode);
897 var endBlock = this.parentBlock(endNode);
898 var leftParagraphAttributes =
new Array();
899 var rightParagraphAttributes =
new Array();
902 if ( this.isElem(startBlock,
'li') || this.isElem(endBlock,
'li') )
return;
905 var isInsideHeader = this.isElem(startBlock,
'h1') || this.isElem(startBlock,
'h2') || this.isElem(startBlock,
'h3') || this.isElem(startBlock,
'h4') || this.isElem(startBlock,
'h5') || this.isElem(startBlock,
'h6');
906 var headerType = null;
907 if (isInsideHeader) {
908 if (this.isElem(startBlock,
'h1')) headerType =
'h1';
909 else if (this.isElem(startBlock,
'h2')) headerType =
'h2';
910 else if (this.isElem(startBlock,
'h3')) headerType =
'h3';
911 else if (this.isElem(startBlock,
'h4')) headerType =
'h4';
912 else if (this.isElem(startBlock,
'h5')) headerType =
'h5';
913 else if (this.isElem(startBlock,
'h6')) headerType =
'h6';
916 if ( this.isElem(startBlock,
'p') ) {
917 for ( var i=0; i < startBlock.attributes.length; i++ ) {
918 leftParagraphAttributes[ startBlock.attributes[i].nodeName ] = startBlock.attributes[i].nodeValue;
921 if ( this.isElem(endBlock,
'p') ) {
922 for ( var i=0; i < endBlock.attributes.length; i++ ) {
923 rightParagraphAttributes[ endBlock.attributes[i].nodeName ] = endBlock.attributes[i].nodeValue;
926 var choppingStart = startNode;
927 var choppingEnd = endNode;
929 while ( ( choppingStart.previousSibling && !
this.isElem(choppingStart.previousSibling,
'p') ) || ( choppingStart.parentNode && choppingStart.parentNode != startBlock && choppingStart.parentNode.nodeType != 9 ) )
930 choppingStart = choppingStart.previousSibling ? choppingStart.previousSibling : choppingStart.parentNode;
932 while ( ( choppingEnd.nextSibling && !
this.isElem(choppingEnd.nextSibling,
'p') ) || ( choppingEnd.parentNode && choppingEnd.parentNode != endBlock && choppingEnd.parentNode.nodeType != 9 ) )
933 choppingEnd = choppingEnd.nextSibling ? choppingEnd.nextSibling : choppingEnd.parentNode;
936 var leftParagraph = null;
937 var rightParagraph = null;
940 var newParagraph = null;
942 if (!isInsideHeader) {
944 leftParagraph = this._doc.createElement(
'p');
945 rightParagraph = this._doc.createElement(
'p');
947 if (headerType != null) {
949 leftParagraph = this._doc.createElement(headerType);
950 rightParagraph = this._doc.createElement(headerType);
955 newParagraph = this._doc.createElement(
'p')
958 for ( var attrName in leftParagraphAttributes ) {
959 var thisAttr = this._doc.createAttribute(attrName);
960 thisAttr.value = leftParagraphAttributes[attrName];
961 leftParagraph.setAttributeNode(thisAttr);
963 for ( var attrName in rightParagraphAttributes ) {
964 var thisAttr = this._doc.createAttribute(attrName);
965 thisAttr.value = rightParagraphAttributes[attrName];
966 rightParagraph.setAttributeNode(thisAttr);
972 leftRange.setStartBefore(choppingStart);
973 leftRange.setEnd(startNode,startOffset);
974 leftParagraph.appendChild(leftRange.cloneContents());
977 rightRange.setEndAfter(choppingEnd);
978 rightRange.setStart(endNode,endOffset);
979 rightParagraph.appendChild(rightRange.cloneContents());
983 var isLeftParagraphEmpty =
false;
984 var containsData =
false;
985 containsData = this.traverseChildrenNodes(leftParagraph, this.containsText);
987 if ( containsData !=
true ) {
988 this.insertDeepLeft(leftParagraph,
' ');
989 isLeftParagraphEmpty =
true;
994 var isRightParagraphEmpty =
false;
995 containsData =
false;
996 containsData = this.traverseChildrenNodes(rightParagraph, this.containsText);
997 if ( containsData !=
true ) {
998 this.insertDeepLeft(rightParagraph,
' ');
999 isRightParagraphEmpty =
true;
1003 var fullRange = this._doc.createRange();
1005 if (!isInsideHeader) {
1008 if ( !choppingStart.previousSibling &&
this.isElem(choppingStart.parentNode,
'p') ) {
1009 fullRange.setStartBefore(choppingStart.parentNode);
1011 fullRange.setStart(leftRange.startContainer, leftRange.startOffset);
1014 if ( !choppingEnd.nextSibling &&
this.isElem(choppingEnd.parentNode,
'p') ) {
1015 fullRange.setEndAfter(choppingEnd.parentNode);
1017 fullRange.setEnd(rightRange.endContainer, rightRange.endOffset);
1026 fullRange.setStartBefore(choppingStart.parentNode);
1027 fullRange.setEndAfter(choppingEnd.parentNode);
1031 fullRange.deleteContents();
1033 if (isInsideHeader) {
1035 if (!isRightParagraphEmpty) fullRange.insertNode(rightParagraph);
1037 newParagraph.appendChild(document.createTextNode(
""+
'\u00A0'));
1038 fullRange.insertNode(newParagraph);
1040 if (!isLeftParagraphEmpty) fullRange.insertNode(leftParagraph);
1043 var cursorRange = this._doc.createRange();
1044 cursorRange.setStart(newParagraph,0);
1045 cursorRange.collapse(
true);
1046 sel = this._iframe.contentWindow.getSelection();
1047 sel.removeAllRanges();
1048 sel.addRange(cursorRange);
1051 fullRange.insertNode(rightParagraph);
1052 fullRange.insertNode(leftParagraph);
1053 if ( rightParagraph.firstChild ) {
1054 while ( this.inArray(rightParagraph.firstChild && rightParagraph.firstChild.nodeName.toLowerCase(), this.inline_tags) ) rightParagraph = rightParagraph.firstChild;
1055 if ( rightParagraph.firstChild && rightParagraph.firstChild.nodeType == 3 ) rightParagraph = rightParagraph.firstChild;
1058 var cursorRange = this._doc.createRange();
1059 cursorRange.setStart(rightParagraph,0);
1060 cursorRange.collapse(
true);
1061 sel = this._iframe.contentWindow.getSelection();
1062 sel.removeAllRanges();
1063 sel.addRange(cursorRange);
1069 HTMLArea._stopEvent(ev);
1075 var keyEvent = (HTMLArea.is_ie && ev.type ==
"keydown") || (ev.type ==
"keypress");
1076 if (keyEvent && ev.ctrlKey) {
1077 var key = String.fromCharCode(HTMLArea.is_ie ? ev.keyCode : ev.charCode).toLowerCase();
1087 this._execCommand(cmd,
false, value);
1088 HTMLArea._stopEvent(ev);
1094 if (!keyEvent || (keyEvent && ev.ctrlKey)) {
1096 for (var x in this._toolbarMenus) {
1097 this._toolbarMenus[x].style.display =
"none";
1100 setTimeout(
function() {
1101 editor.updateToolbar();
1107 HTMLArea.prototype.getHTML =
function() {
1110 switch (this._editMode) {
1112 if (HTMLArea.is_gecko) {
1113 var html = this._iframe.contentWindow.document.body.ownerDocument.createRange();
1114 html.selectNodeContents(this._iframe.contentWindow.document.body);
1115 retVal = html.toString();
1116 }
else if (HTMLArea.is_ie) {
1117 retVal = this._docContent.innerText;
1121 if (HTMLArea.is_gecko) {
1122 retVal = this._iframe.contentWindow.document.body.innerHTML;
1128 if (HTMLArea.is_ff && retVal.match(/^<br>(\n)*$/) != null) {
1129 retVal = retVal.replace(/^<br>(\n)*$/,
'');
1131 }
else if (HTMLArea.is_ie) {
1132 retVal = this._docContent.innerHTML;
1137 if (SQ_CONF_DEFAULT_CHARACTER_SET !=
'utf-8') {
1138 echo
'retVal = this.replace_entities(retVal);';
1142 var entities_array = {
1146 retVal = this.replace_entities(retVal, entities_array);
1154 alert(js_translate(
'undefined_mode',
'<' + this._editMode +
'>'));
1160 if (this._editMode ==
"textmode") {
1161 retVal = this.make_absolute_urls(retVal);
1163 retVal = this.make_relative_hrefs(retVal);
1171 HTMLArea.prototype.make_relative_hrefs =
function(html_code) {
1173 var html =
new String(html_code);
1178 var current_location = document.location.toString();
1181 current_location = current_location.replace(/([.?+*^$\\\[\]\(\)\{\}|])/gi,
'\\$1');
1182 re =
new RegExp(current_location +
'[/]?',
"gi");
1183 html = html.replace(re,
"");
1186 current_location = current_location.replace(/\&/gi,
"&");
1187 re =
new RegExp(current_location,
"gi");
1188 html = html.replace(re,
"");
1189 for (var i = 0; i < this.config.relativeHrefChecks.length; i++) {
1190 e = this.config.relativeHrefChecks[i][0];
1191 re =
new RegExp(e,
"gi");
1192 html = html.replace(re, this.config.relativeHrefChecks[i][1]);
1196 e =
'http[s]?://<?php echo $_SERVER['HTTP_HOST
'].$_SERVER['PHP_SELF
']?>';
1197 re =
new RegExp(e,
"gi");
1198 html = html.replace(re,
"");
1206 HTMLArea.prototype.make_absolute_urls =
function(html_code) {
1208 var html =
new String(html_code);
1212 for (var i = 0; i < this.config.absoluteUrlChecks.length; i++) {
1213 e = this.config.absoluteUrlChecks[i][0];
1214 re =
new RegExp(e,
"gi");
1215 html = html.replace(re, this.config.absoluteUrlChecks[i][1]);
1224 HTMLArea.prototype.replace_entities =
function(html_code, entities_array) {
1226 if (entities_array == undefined){
1227 var entities_array = {
1474 for(var code in entities_array) {
1475 entity = entities_array[code];
1477 var reg =
new RegExp(
"&#" + code +
";",
"g");
1478 html_code = html_code.replace(reg, entity);
1480 var reg =
new RegExp(String.fromCharCode(code),
"g");
1481 html_code = html_code.replace(reg, entity);
1489 <script type=
"text/javascript" src=
"<?php echo $this->web_path?>core/core.js"></script>
1490 <script type=
"text/javascript" src=
"<?php echo $this->web_path?>core/utility.js"></script>
1491 <script type=
"text/javascript" src=
"<?php echo $this->web_path?>core/htmlarea-lang-en.js"></script>
1492 <script type=
"text/javascript" src=
"<?php echo $this->web_path?>core/dialog.js"></script>
1494 <style type=
"text/css">
1495 @
import url(
"<?php echo $this->web_path?>core/htmlarea.css");
1498 $WYSIWYG_INIT = TRUE;
1506 <script type=
"text/javascript">
1508 if (HTMLArea.is_ie) {
1510 var dom_abbr = document.createElement(
'ABBR');
1514 <textarea
id=
"<?php echo $this->name?>" name=
"<?php echo $this->name?>" <?php echo $this->textarea_extras?>><?php echo htmlentities($this->contents, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET); ?></textarea>
1516 <script type=
"text/javascript">
1517 editor_<?php echo $this->name?> =
new HTMLArea(
"<?php echo $this->name?>");
1518 editor_<?php echo $this->name?>._createToolbar();
1519 editor_<?php echo $this->name?>._createStatusBar();
1520 editor_<?php echo $this->name?>.updateToolbar(
false);
1521 editor_<?php echo $this->name?>.set_dir_attr(
'<?php echo $this->dir_attribute?>');
1523 if ($this->init_onload) {
1525 OtherOnLoad_<?php echo $this->name?> = (window.onload) ? window.onload :
new Function;
1526 window.onload =
function() {
1527 editor_<?php echo $this->name?>.generate();
1528 OtherOnLoad_<?php echo $this->name?>();
1548 if (!isset($_REQUEST[$this->name]))
return FALSE;
1549 $html = $_REQUEST[$this->name];
1552 $html = preg_replace(
'|<HTMLAREA_FORM ([^>]*?)>(.*?)</HTMLAREA_FORM>|is',
'<FORM \\1>\\2</FORM>', $html);
1554 if (!isset($_POST[
'ees_content_no_filter'])) {
1555 for (reset($this->_loaded_plugins); NULL !== ($k = key($this->_loaded_plugins)); next($this->_loaded_plugins)) {
1556 $plugin =& $this->_loaded_plugins[$k];
1557 $plugin->process($html);
1574 function print_config()
1577 <script type=
"text/javascript">
1578 HTMLArea.Config_<?php echo $this->name?> =
function () {
1579 this.version =
"3.0";
1582 this.statusBar = <?php echo ($this->show_status_bar) ?
'true' :
'false'; ?>;
1584 this.width =
"<?php echo $this->width?>";
1585 this.height =
"<?php echo $this->height?>";
1588 this.bodyType =
"<?php echo $this->body_type?>";
1592 this.sizeIncludesToolbar =
true;
1594 this.bodyStyle =
"background-color: #ffffff; font-family: verdana,sans-serif";
1595 this.styleSheet =
"<?php echo $this->stylesheet?>";
1596 this.editorURL =
"";
1599 this.imgURL =
"<?php echo $this->web_path?>images/";
1600 this.pluginURL =
"<?php echo $this->web_path?>plugins/";
1602 this.replaceNextLines = 0;
1603 this.plainTextInput = 0;
1605 this.relativeHrefChecks = Array(
1607 $i = count($this->relative_href_checks);
1608 foreach ($this->relative_href_checks as $find => $replace) {
1609 echo
"Array(\"$find\", \"$replace\")".(($i > 1) ?
',' :
'').
"\n";
1614 this.absoluteUrlChecks = Array(
1616 $i = count($this->absolute_url_checks);
1617 foreach ($this->absolute_url_checks as $find => $replace) {
1618 echo
"Array(\"$find\", \"$replace\")".(($i > 1) ?
',' :
'').
"\n";
1626 if (!empty($this->_plugins)) {
1628 foreach ($this->_plugins as $plugin_group) {
1629 if (!empty($plugin_group)) {
1630 $pre_group_output = $output;
1632 $printed_buttons = FALSE;
1633 foreach ($plugin_group as $name) {
1634 $plugin = $this->_loaded_plugins[$name];
1635 foreach ($plugin->buttons as $id => $button) {
1636 if (isset($button[
'menu_end'])) {
1640 if (isset($button[
'menu_start'])) $output .=
'[ ';
1641 if ($id) $output .=
'["'.$id.
'"], ';
1642 $printed_buttons = TRUE;
1646 if ($printed_buttons) {
1647 $output .=
'["separator"] ],'.
"\n\t\t\t\t\t\t\t";
1649 $output = $pre_group_output;
1653 $output = trim($output,
"\t\n,");
1663 foreach ($this->_loaded_plugins as $name => $plugin) {
1664 foreach ($plugin->buttons as $id => $button) {
1665 if (isset($button[
'menu_end']))
continue;
1666 if (!$button[
'command'])
continue;
1667 $output .=
"$id:".str_repeat(
' ',30 - strlen($id)).
"[\"".$button[
'command'].
"\",".str_repeat(
' ',30 - strlen($button[
'command'])).
"\"".$button[
'tooltip'].
"\",".str_repeat(
' ',30 - strlen($button[
'tooltip'])).
"".$button[
'textmode'].
", ".(($button[
'textmode'] ===
'true') ?
' ' :
'').
"".$button[
'position'].
", \"".$button[
'context'].
"\"],\n\t\t\t\t\t\t";
1670 $output = trim($output,
"\t\n,");
1676 for (var i in this.btnList) {
1677 var btn = this.btnList[i];
1678 if (typeof HTMLArea.I18N.tooltips[i] !=
"undefined") {
1679 btn[1] = HTMLArea.I18N.tooltips[i];
1695 function print_plugin_vars()
1697 foreach ($this->_loaded_plugins as $name => $plugin) {
1698 $plugin->print_plugin_vars();
1710 function print_plugin_shortcuts()
1712 foreach ($this->_loaded_plugins as $name => $plugin) {
1713 $plugin->print_plugin_shortcuts();
1725 function print_plugin_create_select()
1727 foreach ($this->_loaded_plugins as $name => $plugin) {
1728 $plugin->print_plugin_create_select();
1740 function print_plugin_functions()
1742 foreach ($this->_loaded_plugins as $name => $plugin) {
1755 function print_plugin_generic_functions()
1757 foreach ($this->_loaded_plugins as $name => $plugin) {
1758 $plugin->paint_generic();
1770 function print_plugin_button_clicks()
1772 foreach ($this->_loaded_plugins as $name => $plugin) {
1773 $plugin->print_plugin_button_click();
1785 function print_plugin_combo_selected()
1787 foreach ($this->_loaded_plugins as $name => $plugin) {
1788 $plugin->print_plugin_combo_selected();
1800 function print_plugin_button_type()
1802 foreach ($this->_loaded_plugins as $name => $plugin) {
1803 $plugin->print_plugin_button_type();
1815 function print_plugin_update_toolbar()
1817 foreach ($this->_loaded_plugins as $name => $plugin) {
1818 $plugin->print_plugin_update_toolbar();
1830 function print_plugin_exec_commands()
1832 foreach ($this->_loaded_plugins as $name => $plugin) {
1833 $plugin->print_plugin_exec_command();
1845 function print_plugin_pre_get_html()
1847 foreach ($this->_loaded_plugins as $name => $plugin) {
1848 $plugin->print_plugin_pre_get_html();
1860 function print_plugin_get_html()
1862 foreach ($this->_loaded_plugins as $name => $plugin) {
1863 $plugin->print_plugin_get_html();
1875 function print_plugin_form_submit()
1877 foreach ($this->_loaded_plugins as $name => $plugin) {
1878 $plugin->print_plugin_form_submit();
1890 function print_plugin_event_handlers()
1892 foreach ($this->_loaded_plugins as $name => $plugin) {
1893 $plugin->print_plugin_event_handler();
1913 function add_plugin($name)
1916 if (!isset($this->_loaded_plugins[$name])) {
1917 require_once($ROOT_PATH.
'/plugins/'.$name.
'/'.$name.
'.inc');
1918 $this->_loaded_plugins[$name] =
new $name($this);
1922 if ($this->_loaded_plugins[$name]->_show_in_toolbar && !$this->_group_open) {
1923 if (!$this->open_group())
return FALSE;
1927 $groupid = count($this->_plugins) - 1;
1928 $this->_plugins[$groupid][] = $name;
1930 if ($own_group)
return $this->close_group();
1943 function open_group()
1945 if ($this->_group_open)
return FALSE;
1946 $this->_group_open = TRUE;
1947 $new_group = Array();
1948 return array_push($this->_plugins, $new_group);
1960 function close_group()
1962 if (!$this->_group_open)
return FALSE;
1963 $this->_group_open = FALSE;
1978 function plugin_loaded($name)
1980 return isset($this->_loaded_plugins[$name]);
1993 function &get_plugin($name)
1995 if (!isset($this->_loaded_plugins[$name])) {
1999 return $this->_loaded_plugins[$name];
2012 function set_body_type($type=
'iframe')
2014 $this->body_type = $type;
2027 function set_init_onload($init=TRUE)
2029 $this->init_onload = (bool) $init;
2042 function set_show_status_bar($show=TRUE)
2044 $this->show_status_bar = (bool)$show;
2057 function set_width($width=
'auto')
2059 if (is_numeric($width)) $width .=
'px';
2060 $this->width = $width;
2073 function set_height($height=
'auto')
2075 if (is_numeric($height)) $height .=
'px';
2076 $this->height = $height;
2090 function set_textarea_extras($extras=
'')
2092 $this->textarea_extras = trim($extras);
2105 function set_contents($contents)
2107 foreach ($this->_loaded_plugins as $name => $plugin) {
2108 $plugin->set_contents($contents);
2113 $contents = preg_replace(
'|<FORM ([^>]*?)>(.*?)</FORM>|is',
'<HTMLAREA_FORM \\1>\\2</HTMLAREA_FORM>', $contents);
2114 $this->contents = $contents;
2127 function set_stylesheet($stylesheet)
2129 $this->stylesheet = $stylesheet;
2142 function set_dir_attr($dir_attribute)
2144 $this->dir_attribute = $dir_attribute;
2157 function add_relative_href_check($find, $replace)
2159 $find = str_replace(
'\\',
'\\\\\\', $find);
2160 $replace = str_replace(
'\\',
'\\\\\\', $replace);
2161 $this->relative_href_checks[$find] = $replace;
2175 function add_absolute_url_check($find, $replace)
2177 $find = str_replace(
'\\',
'\\\\\\', $find);
2178 $replace = str_replace(
'\\',
'\\\\\\', $replace);
2179 $this->absolute_url_checks[$find] = $replace;