if (typeof _editor_url == "string") { _editor_url = _editor_url.replace(/\x2f*$/, '/'); } else { alert("WARNING: _editor_url is not set! "); _editor_url = ''; } if (typeof _editor_lang == "string") { _editor_lang = _editor_lang.toLowerCase(); } else { _editor_lang = "en"; } function HTMLArea(textarea, config) { if (HTMLArea.checkSupportedBrowser()) { if (typeof config == "undefined") { this.config = new HTMLArea.Config(); } else { this.config = config; } this._htmlArea = null; this._textArea = textarea; this._editMode = "wysiwyg"; this.plugins = {}; this._timerToolbar = null; this._timerUndo = setInterval(function() { if(editor._doc) editor._undoTakeSnapshot(); }, this.config.undoTimeout); this._undoQueue = new Array(); this._undoPos = -1; this._customUndo = true; this._mdoc = document; this.doctype = ''; } }; (function() { var scripts = HTMLArea._scripts = [ _editor_url + "htea_public.js.php?sid=1", _editor_url + "dialog.js", _editor_url + "popupwin.js", _editor_url + "lang/" + _editor_lang + ".js" ]; var head = document.getElementsByTagName("head")[0]; // start from 1, htea_public.js.php is already loaded for (var i = 1; i < scripts.length; ++i) { var script = document.createElement("script"); script.src = scripts[i]; head.appendChild(script); } })(); HTMLArea.RE_tagName = /(<\/|<)\s*([^ \t\n>]+)/ig; HTMLArea.RE_doctype = /()\n?/i; HTMLArea.RE_head = /
((.|\n)*?)<\/head>/i; HTMLArea.RE_body = /((.|\n)*?)<\/body>/i; HTMLArea.Config = function () { this.version = "3.0"; this.width = "auto"; this.height = "auto"; this.statusBar = true; this.undoSteps = 30; this.undoTimeout = 500; this.sizeIncludesToolbar = true; this.fullPage = false; this.pageStyle = ""; this.killWordOnPaste = true; this.baseURL = document.baseURI || document.URL; if (this.baseURL && this.baseURL.match(/(.*)\/([^\/]+)/)) this.baseURL = RegExp.$1 + "/"; this.imgURL = "images/"; this.popupURL = "showups/"; this.toolbar = [ [ "fontname", "space", "fontsize", "space", "bold", "italic", "underline", "strikethrough", "separator", "subscript", "superscript", "separator", "copy", "cut", "paste", "space", "undo", "redo", "separator" ], [ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator", "lefttoright", "righttoleft", "separator", "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator", "forecolor", "hilitecolor", "separator", "bullet", "inserthorizontalrule", "pagebreak", "createlink", "separator", "inserttable", "htmlmode", "separator" ], ]; this.fontname = { "Arial": 'arial,helvetica,sans-serif', "Tahoma": 'tahoma,arial,helvetica,sans-serif', "Times New Roman": 'times new roman,times,serif', "WingDings": 'wingdings' }; this.fontsize = { "1 (8 pt)": "1", "2 (10 pt)": "2", "3 (12 pt)": "3", "4 (14 pt)": "4", "5 (18 pt)": "5", "6 (24 pt)": "6", "7 (36 pt)": "7" }; this.formatblock = { "Heading 1": "h1", "Heading 2": "h2", "Heading 3": "h3", "Heading 4": "h4", "Heading 5": "h5", "Heading 6": "h6", "Normal": "p", "Address": "address", "Formatted": "pre" }; this.customSelects = {}; function cut_copy_paste(e, cmd, obj) { e.execCommand(cmd); }; this.btnList = { bold: [ "Bold", "ed_format_bold.gif", false, function(e) {e.execCommand("bold");} ], italic: [ "Italic", "ed_format_italic.gif", false, function(e) {e.execCommand("italic");} ], underline: [ "Underline", "ed_format_underline.gif", false, function(e) {e.execCommand("underline");} ], strikethrough: [ "Strikethrough", "ed_format_strike.gif", false, function(e) {e.execCommand("strikethrough");} ], subscript: [ "Subscript", "ed_format_sub.gif", false, function(e) {e.execCommand("subscript");} ], superscript: [ "Superscript", "ed_format_sup.gif", false, function(e) {e.execCommand("superscript");} ], justifyleft: [ "Justify Left", "ed_align_left.gif", false, function(e) {e.execCommand("justifyleft");} ], justifycenter: [ "Justify Center", "ed_align_center.gif", false, function(e) {e.execCommand("justifycenter");} ], justifyright: [ "Justify Right", "ed_align_right.gif", false, function(e) {e.execCommand("justifyright");} ], justifyfull: [ "Justify Full", "ed_align_justify.gif", false, function(e) {e.execCommand("justifyfull");} ], insertorderedlist: [ "Ordered List", "ed_list_num.gif", false, function(e) {e.execCommand("insertorderedlist");} ], insertunorderedlist: [ "Bulleted List", "ed_list_bullet.gif", false, function(e) {e.execCommand("insertunorderedlist");} ], outdent: [ "Decrease Indent", "ed_indent_less.gif", false, function(e) {e.execCommand("outdent");} ], indent: [ "Increase Indent", "ed_indent_more.gif", false, function(e) {e.execCommand("indent");} ], forecolor: [ "Font Color", "ed_color_fg.gif", false, function(e) {e.execCommand("forecolor");} ], hilitecolor: [ "Background Color", "ed_color_bg.gif", false, function(e) {e.execCommand("hilitecolor");} ], inserthorizontalrule: [ "Horizontal Rule", "ed_hr.gif", false, function(e) {e.execCommand("inserthorizontalrule");} ], createlink: [ "Insert Web Link", "ed_link.gif", false, function(e) {e.execCommand("createlink", true);} ], createintlink: [ "Insert Link to site documents", "ed_int_link.gif", false, function(e) {e.execCommand("createintlink", true);} ], createbookmark: [ "Insert Bookmark", "ed_bookmark.gif", false, function(e) {e.execCommand("createbookmark", true);} ], createsitelink: [ "Insert Link to Site Forms & Pages", "ed_site_link.gif", false, function(e) {e.execCommand("createsitelink", true);} ], insertimage: [ "Insert/Modify Image", "ed_image.gif", false, function(e) {e.execCommand("insertimage");} ], insertflash: [ "Insert/Modify Flash", "ed_flash.gif", false, function(e) {e.execCommand("insertflash");} ], inserttable: [ "Insert Table", "insert_table.gif", false, function(e) {e.execCommand("inserttable");} ], inserttemplate: [ "Insert Template", "insert_template.gif", false, function(e) {e.execCommand("inserttemplate");} ], htmlmode: [ "Toggle HTML Source", "ed_html.gif", true, function(e) {e.execCommand("htmlmode");} ], popupeditor: [ "Enlarge Editor", "fullscreen_maximize.gif", true, function(e) {e.execCommand("popupeditor");} ], about: [ "About this editor", "ed_about.gif", true, function(e) {e.execCommand("about");} ], showhelp: [ "Help using editor", "ed_help.gif", true, function(e) {e.execCommand("showhelp");} ], undo: [ "Undoes your last action", "ed_undo.gif", false, function(e) {e.execCommand("undo");} ], redo: [ "Redoes your last action", "ed_redo.gif", false, function(e) {e.execCommand("redo");} ], cut: [ "Cut selection", "ed_cut.gif", false, cut_copy_paste ], copy: [ "Copy selection", "ed_copy.gif", false, cut_copy_paste ], paste: [ "Paste from clipboard", "ed_paste.gif", false, cut_copy_paste ], lefttoright: [ "Direction left to right", "ed_left_to_right.gif", false, function(e) {e.execCommand("lefttoright");} ], righttoleft: [ "Direction right to left", "ed_right_to_left.gif", false, function(e) {e.execCommand("righttoleft");} ], bullet: [ "Insert bullet", "ed_bullet.gif", false, function(e) {e.insertHTML("• "); } ] }; for (var i in this.btnList) { var btn = this.btnList[i]; btn[1] = _editor_url + this.imgURL + btn[1]; if (typeof HTMLArea.internatt.tooltips[i] != "undefined") { btn[0] = HTMLArea.internatt.tooltips[i]; } } }; HTMLArea.Config.prototype.registerButton = function(id, tooltip, image, textMode, action, context) { var the_id; if (typeof id == "string") { the_id = id; } else if (typeof id == "object") { the_id = id.id; } else { alert("ERROR [HTMLArea.Config::registerButton]:\ninvalid arguments"); return false; } if (typeof this.customSelects[the_id] != "undefined") { } if (typeof this.btnList[the_id] != "undefined") { } switch (typeof id) { case "string": this.btnList[id] = [ tooltip, image, textMode, action, context ]; break; case "object": this.btnList[id.id] = [ id.tooltip, id.image, id.textMode, id.action, id.context ]; break; } }; HTMLArea.Config.prototype.registerDropdown = function(object) { if (typeof this.customSelects[object.id] != "undefined") { } if (typeof this.btnList[object.id] != "undefined") { } this.customSelects[object.id] = object; }; HTMLArea.Config.prototype.hideSomeButtons = function(remove) { var toolbar = this.toolbar; for (var i in toolbar) { var line = toolbar[i]; for (var j = line.length; --j >= 0; ) { if (remove.indexOf(" " + line[j] + " ") >= 0) { var len = 1; if (/separator|space/.test(line[j + 1])) { len = 2; } line.splice(j, len); } } } }; HTMLArea.replaceAll = function(config) { var tas = document.getElementsByTagName("textarea"); for (var i = tas.length; i > 0; (new HTMLArea(tas[--i], config)).generate()); }; HTMLArea.replace = function(id, config) { var ta = HTMLArea.getElementById("textarea", id); return ta ? (new HTMLArea(ta, config)).generate() : null; }; HTMLArea.prototype._createToolbar = function () { var editor = this; var toolbar = document.createElement("div"); this._toolbar = toolbar; toolbar.className = "toolbar"; toolbar.unselectable = "1"; var tb_row = null; var tb_objects = new Object(); this._toolbarObjects = tb_objects; function newLine() { var table = document.createElement("table"); table.border = "0px"; table.cellSpacing = "0px"; table.cellPadding = "0px"; toolbar.appendChild(table); var tb_body = document.createElement("tbody"); table.appendChild(tb_body); tb_row = document.createElement("tr"); tb_body.appendChild(tb_row); }; newLine(); function setButtonStatus(id, newval) { var oldval = this[id]; var el = this.element; if (oldval != newval) { switch (id) { case "enabled": if (newval) { HTMLArea._removeClass(el, "buttonDisabled"); el.disabled = false; } else { HTMLArea._addClass(el, "buttonDisabled"); el.disabled = true; } break; case "active": if (newval) { HTMLArea._addClass(el, "buttonPressed"); } else { HTMLArea._removeClass(el, "buttonPressed"); } break; } this[id] = newval; } }; function createSelect(txt) { var options = null; var el = null; var cmd = null; var customSelects = editor.config.customSelects; var context = null; switch (txt) { case "fontsize": case "fontname": case "formatblock": options = editor.config[txt]; cmd = txt; break; default: cmd = txt; var dropdown = customSelects[cmd]; if (typeof dropdown != "undefined") { options = dropdown.options; context = dropdown.context; } else { alert("ERROR [createSelect]:\nCan't find the requested dropdown definition"); } break; } if (options) { el = document.createElement("select"); var obj = { name : txt, element : el, enabled : true, text : false, cmd : cmd, state : setButtonStatus, context : context }; tb_objects[txt] = obj; for (var i in options) { var op = document.createElement("option"); op.appendChild(document.createTextNode(i)); op.value = options[i]; el.appendChild(op); } HTMLArea._addEvent(el, "change", function () { editor._comboSelected(el, txt); }); } return el; }; function createButton(txt) { var el = null; var btn = null; switch (txt) { case "separator": el = document.createElement("div"); el.className = "separator"; break; case "space": el = document.createElement("div"); el.className = "space"; break; case "linebreak": newLine(); return false; case "textindicator": el = document.createElement("div"); el.appendChild(document.createTextNode("A")); el.className = "indicator"; el.title = HTMLArea.internatt.tooltips.textindicator; var obj = { name : txt, element : el, enabled : true, active : false, text : false, cmd : "textindicator", state : setButtonStatus }; tb_objects[txt] = obj; break; default: btn = editor.config.btnList[txt]; } if (!el && btn) { el = document.createElement("div"); el.title = btn[0]; el.className = "button"; var obj = { name : txt, // the button name (i.e. 'bold') element : el, // the UI element (DIV) enabled : true, // is it enabled? active : false, // is it pressed? text : btn[2], // enabled in text mode? cmd : btn[3], // the command ID state : setButtonStatus, // for changing state context : btn[4] || null // enabled in a certain context? }; tb_objects[txt] = obj; HTMLArea._addEvent(el, "mouseover", function () { if (obj.enabled) { HTMLArea._addClass(el, "buttonHover"); } }); HTMLArea._addEvent(el, "mouseout", function () { if (obj.enabled) with (HTMLArea) { _removeClass(el, "buttonHover"); _removeClass(el, "buttonActive"); (obj.active) && _addClass(el, "buttonPressed"); } }); HTMLArea._addEvent(el, "mousedown", function (ev) { if (obj.enabled) with (HTMLArea) { _addClass(el, "buttonActive"); _removeClass(el, "buttonPressed"); _stopEvent(is_ie ? window.event : ev); } }); HTMLArea._addEvent(el, "click", function (ev) { if (obj.enabled) with (HTMLArea) { _removeClass(el, "buttonActive"); _removeClass(el, "buttonHover"); obj.cmd(editor, obj.name, obj); _stopEvent(is_ie ? window.event : ev); } }); var img = document.createElement("img"); img.src = btn[1]; img.style.width = "18px"; img.style.height = "18px"; el.appendChild(img); } else if (!el) { el = createSelect(txt); } if (el) { var tb_cell = document.createElement("td"); tb_row.appendChild(tb_cell); tb_cell.appendChild(el); } else { alert("FIXME: Unknown toolbar item: " + txt); } return el; }; var first = true; for (var i in this.config.toolbar) { if (!first) { createButton("linebreak"); } else { first = false; } var group = this.config.toolbar[i]; for (var j in group) { var code = group[j]; if (/^([IT])\[(.*?)\]/.test(code)) { var l7ed = RegExp.$1 == "I"; // localized? var label = RegExp.$2; if (l7ed) { label = HTMLArea.internatt.custom[label]; } var tb_cell = document.createElement("td"); tb_row.appendChild(tb_cell); tb_cell.className = "label"; tb_cell.innerHTML = label; } else { createButton(code); } } } this._htmlArea.appendChild(toolbar); }; HTMLArea.prototype._createStatusBar = function() { var statusbar = document.createElement("div"); statusbar.className = "statusBar"; this._htmlArea.appendChild(statusbar); this._statusBar = statusbar; div = document.createElement("span"); div.className = "statusBarTree"; div.innerHTML = HTMLArea.internatt.meseg["Path"] + ": "; this._statusBarTree = div; this._statusBar.appendChild(div); if (!this.config.statusBar) { statusbar.style.display = "none"; } }; HTMLArea.prototype.generate = function () { var editor = this; // we'll need "this" in some nested functions var textarea = this._textArea; if (typeof textarea == "string") { this._textArea = textarea = HTMLArea.getElementById("textarea", textarea); } this._ta_size = { w: textarea.offsetWidth, h: textarea.offsetHeight }; textarea.style.display = "none"; var htmlarea = document.createElement("div"); htmlarea.className = "htmlarea"; this._htmlArea = htmlarea; textarea.parentNode.insertBefore(htmlarea, textarea); if (textarea.form) { var f = textarea.form; if (typeof f.onsubmit == "function") { var funcref = f.onsubmit; if (typeof f.__msh_prevOnSubmit == "undefined") { f.__msh_prevOnSubmit = []; } f.__msh_prevOnSubmit.push(funcref); } f.onsubmit = function() { editor._textArea.value = editor.getHTML(); var a = this.__msh_prevOnSubmit; if (typeof a != "undefined") { for (var i in a) { a[i](); } } }; } window.onunload = function() { editor._textArea.value = editor.getHTML(); }; this._createToolbar(); var iframe = document.createElement("iframe"); htmlarea.appendChild(iframe); this._iframe = iframe; this._createStatusBar(); if (!HTMLArea.is_ie) { iframe.style.borderWidth = "1px"; } var height = (this.config.height == "auto" ? (this._ta_size.h + "px") : this.config.height); height = parseInt(height); var width = (this.config.width == "auto" ? (this._ta_size.w + "px") : this.config.width); width = parseInt(width); if (!HTMLArea.is_ie) { height -= 2; width -= 2; } iframe.style.width = width + "px"; if (this.config.sizeIncludesToolbar) { height -= this._toolbar.offsetHeight; height -= this._statusBar.offsetHeight; } if (height < 0) { height = 0; } iframe.style.height = height + "px"; textarea.style.width = iframe.style.width; textarea.style.height = iframe.style.height; function initIframe() { var doc = editor._iframe.contentWindow.document; if (!doc) { if (HTMLArea.is_gecko) { setTimeout(initIframe, 100); return false; } else { alert("ERROR: IFRAME can't be initialized."); } } if (HTMLArea.is_gecko) { doc.designMode = "on"; } editor._doc = doc; if (!editor.config.fullPage) { doc.open(); var html = "\n"; html += "\n"; if (editor.config.baseURL) html += ']*TEXT-ALIGN: justify[^>]*>/gi,'
').
replace(/ style=\"[^>]*\"/gi,'').
replace(/ align=[^\s|>]*/gi,'');
D = D.replace(/]*>/gi,'').
replace(/]*>/gi,'').
replace(/ ]*>/gi,' ').
replace(/<\/?h[1-6][^>]*>/gi,' ');
this.setHTML(D);
this.updateToolbar();
}
};
HTMLArea.prototype.forceRedraw = function() {
this._doc.body.style.visibility = "hidden";
this._doc.body.style.visibility = "visible";
};
HTMLArea.prototype.focusEditor = function() {
switch (this._editMode) {
case "wysiwyg" : this._iframe.contentWindow.focus(); break;
case "textmode": this._textArea.focus(); break;
default : alert("ERROR: mode " + this._editMode + " is not defined");
}
return this._doc;
};
HTMLArea.prototype._undoTakeSnapshot = function() {
var curTime = (new Date()).getTime();
var newOne = true;
if (this._undoPos >= this.config.undoSteps) {
this._undoQueue.shift();
--this._undoPos;
}
if (this._undoPos < 0 ||
this._undoQueue[this._undoPos].time < curTime - this.config.undoTimeout)
++this._undoPos;
else
newOne = false;
var txt = this.getInnerHTML();
if (newOne){
if (this._undoPos == 0 || this._undoQueue[this._undoPos - 1].text != txt){
this._undoQueue[this._undoPos] = { text: txt, time: curTime };
this._undoQueue.length = this._undoPos + 1;
} else
this._undoPos--;
} else {
if (this._undoQueue[this._undoPos].text != txt){
this._undoQueue[this._undoPos].text = txt;
this._undoQueue.length = this._undoPos + 1;
}
}
};
HTMLArea.prototype.undo = function() {
if (this._undoPos > 0){
this._undoTakeSnapshot();
this.setHTML(this._undoQueue[--this._undoPos].text);
}
};
HTMLArea.prototype.redo = function() {
if (this._undoPos < this._undoQueue.length - 1){
this._undoTakeSnapshot();
if (this._undoPos < this._undoQueue.length - 1)
this.setHTML(this._undoQueue[++this._undoPos].text);
}
};
HTMLArea.prototype.updateToolbar = function(noStatus) {
var doc = this._doc;
var text = (this._editMode == "textmode");
var ancestors = null;
if (!text) {
ancestors = this.getAllAncestors();
if (this.config.statusBar && !noStatus) {
this._statusBarTree.innerHTML = HTMLArea.internatt.meseg["Path"] + ": "; // clear
for (var i = ancestors.length; --i >= 0;) {
var el = ancestors[i];
if (!el) {
continue;
}
var a = document.createElement("a");
a.href = "#";
a.el = el;
a.editor = this;
a.onclick = function() {
this.blur();
this.editor.selectNodeContents(this.el);
this.editor.updateToolbar(true);
return false;
};
a.oncontextmenu = function() {
this.blur();
var info = "Inline style:\n\n";
info += this.el.style.cssText.split(/;\s*/).join(";\n");
alert(info);
return false;
};
var txt = el.tagName.toLowerCase();
a.title = el.style.cssText;
if (el.id) {
txt += "#" + el.id;
}
if (el.className) {
txt += "." + el.className;
}
a.appendChild(document.createTextNode(txt));
this._statusBarTree.appendChild(a);
if (i != 0) {
this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb)));
}
}
}
}
for (var i in this._toolbarObjects) {
var btn = this._toolbarObjects[i];
var cmd = i;
var inContext = true;
if (btn.context && !text) {
inContext = false;
var context = btn.context;
var attrs = [];
if (/(.*)\[(.*?)\]/.test(context)) {
context = RegExp.$1;
attrs = RegExp.$2.split(",");
}
context = context.toLowerCase();
var match = (context == "*");
for (var k in ancestors) {
if (!ancestors[k]) {
continue;
}
if (match || (ancestors[k].tagName.toLowerCase() == context)) {
inContext = true;
for (var ka in attrs) {
if (!eval("ancestors[k]." + attrs[ka])) {
inContext = false;
break;
}
}
if (inContext) {
break;
}
}
}
}
btn.state("enabled", (!text || btn.text) && inContext);
if (typeof cmd == "function") {
continue;
}
var dropdown = this.config.customSelects[cmd];
if ((!text || btn.text) && (typeof dropdown != "undefined")) {
dropdown.refresh(this);
continue;
}
switch (cmd) {
case "fontname":
case "fontsize":
case "formatblock":
if (!text) try {
var value = ("" + doc.queryCommandValue(cmd)).toLowerCase();
if (!value) {
break;
}
var options = this.config[cmd];
var k = 0;
for (var j in options) {
if ((j.toLowerCase() == value) ||
(options[j].substr(0, value.length).toLowerCase() == value)) {
btn.element.selectedIndex = k;
break;
}
++k;
}
} catch(e) {};
break;
case "textindicator":
if (!text) {
try {with (btn.element.style) {
backgroundColor = HTMLArea._makeColor(
doc.queryCommandValue(HTMLArea.is_ie ? "backcolor" : "hilitecolor"));
if (/transparent/i.test(backgroundColor)) {
backgroundColor = HTMLArea._makeColor(doc.queryCommandValue("backcolor"));
}
color = HTMLArea._makeColor(doc.queryCommandValue("forecolor"));
fontFamily = doc.queryCommandValue("fontname");
fontWeight = doc.queryCommandState("bold") ? "bold" : "normal";
fontStyle = doc.queryCommandState("italic") ? "italic" : "normal";
}} catch (e) {
}
}
break;
case "htmlmode": btn.state("active", text); break;
case "lefttoright":
case "righttoleft":
var el = this.getParentElement();
break;
default:
try {
btn.state("active", (!text && doc.queryCommandState(cmd)));
} catch (e) {}
}
}
this._undoTakeSnapshot();
for (var i in this.plugins) {
var plugin = this.plugins[i].instance;
if (typeof plugin.onUpdateToolbar == "function")
plugin.onUpdateToolbar();
}
};
HTMLArea.prototype.insertNodeAtSelection = function(toBeInserted) {
if (!HTMLArea.is_ie) {
var sel = this._getSelection();
var range = this._createRange(sel);
sel.removeAllRanges();
range.deleteContents();
var node = range.startContainer;
var pos = range.startOffset;
switch (node.nodeType) {
case 3:
if (toBeInserted.nodeType == 3) {
node.insertData(pos, toBeInserted.data);
range = this._createRange();
range.setEnd(node, pos + toBeInserted.length);
range.setStart(node, pos + toBeInserted.length);
sel.addRange(range);
} else {
node = node.splitText(pos);
var selnode = toBeInserted;
if (toBeInserted.nodeType == 11 ) {
selnode = selnode.firstChild;
}
node.parentNode.insertBefore(toBeInserted, node);
this.selectNodeContents(selnode);
this.updateToolbar();
}
break;
case 1:
var selnode = toBeInserted;
if (toBeInserted.nodeType == 11 ) {
selnode = selnode.firstChild;
}
node.insertBefore(toBeInserted, node.childNodes[pos]);
this.selectNodeContents(selnode);
this.updateToolbar();
break;
}
} else {
return null;
}
};
HTMLArea.prototype.getParentElement = function() {
var sel = this._getSelection();
var range = this._createRange(sel);
if (HTMLArea.is_ie) {
switch (sel.type) {
case "Text":
case "None":
return range.parentElement();
case "Control":
return range.item(0);
default:
return this._doc.body;
}
} else try {
var p = range.commonAncestorContainer;
if (!range.collapsed && range.startContainer == range.endContainer &&
range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes())
p = range.startContainer.childNodes[range.startOffset];
while (p.nodeType == 3) {
p = p.parentNode;
}
return p;
} catch (e) {
return null;
}
};
HTMLArea.prototype.getAllAncestors = function() {
var p = this.getParentElement();
var a = [];
while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
a.push(p);
p = p.parentNode;
}
a.push(this._doc.body);
return a;
};
HTMLArea.prototype.selectNodeContents = function(node, pos) {
this.focusEditor();
this.forceRedraw();
var range;
var collapsed = (typeof pos != "undefined");
if (HTMLArea.is_ie) {
range = this._doc.body.createTextRange();
range.moveToElementText(node);
(collapsed) && range.collapse(pos);
range.select();
} else {
var sel = this._getSelection();
range = this._doc.createRange();
range.selectNodeContents(node);
(collapsed) && range.collapse(pos);
sel.removeAllRanges();
sel.addRange(range);
}
};
HTMLArea.prototype.insertHTML = function(html) {
var sel = this._getSelection();
var range = this._createRange(sel);
if (HTMLArea.is_ie) {
range.pasteHTML(html);
} else {
var fragment = this._doc.createDocumentFragment();
var div = this._doc.createElement("div");
div.innerHTML = html;
while (div.firstChild) {
fragment.appendChild(div.firstChild);
}
var node = this.insertNodeAtSelection(fragment);
}
};
HTMLArea.prototype.surroundHTML = function(startTag, endTag) {
var html = this.getSelection();
this.insertHTML(startTag + html + endTag);
};
HTMLArea.prototype.getSelection = function() {
var sel = this._getSelection();
var range = this._createRange(sel);
var existing = null;
if (HTMLArea.is_ie) {
existing = range.htmlText;
} else {
existing = HTMLArea.getHTML(range.cloneContents(), false, this);
}
return existing;
};
HTMLArea.prototype.hasSelectedText = function() {
return this.getSelection() != '';
};
HTMLArea.prototype._createLink = function(link) {
var editor = this;
var outparam = null;
if (typeof link == "undefined") {
link = this.getParentElement();
if (link && !/^a$/i.test(link.tagName))
link = null;
}
if (link) outparam = {
f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"),
f_title : link.title,
f_target : link.target
};
this._popupDialog("link.html", function(param) {
if (!param)
return false;
var a = link;
if (!a) {
editor._doc.execCommand("createlink", false, param.f_href);
a = editor.getParentElement();
var sel = editor._getSelection();
var range = editor._createRange(sel);
if (!HTMLArea.is_ie) {
a = range.startContainer;
if (!/^a$/i.test(a.tagName))
a = a.nextSibling;
}
} else a.href = param.f_href.trim();
if (!/^a$/i.test(a.tagName))
return false;
a.target = param.f_target.trim();
a.title = param.f_title.trim();
editor.selectNodeContents(a);
editor.updateToolbar();
//alert('test'+a.target);
}, outparam);
};
HTMLArea.prototype._createintLink = function(link) {//AWT_UP:+
var editor = this;
var outparam = null;
if (typeof link == "undefined") {
link = this.getParentElement();
if (link && !/^a$/i.test(link.tagName))
link = null;
}
if (link) outparam = {
f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"),
f_title : link.title,
f_target : link.target
};
this._popupDialog("intlink.php?sid=1", function(param) {
if (!param)
return false;
var a = link;
if (!a) {
editor._doc.execCommand("createlink", false, param.f_href);
a = editor.getParentElement();
var sel = editor._getSelection();
var range = editor._createRange(sel);
if (!HTMLArea.is_ie) {
a = range.startContainer;
if (!/^a$/i.test(a.tagName))
a = a.nextSibling;
}
} else a.href = param.f_href.trim();
if (!/^a$/i.test(a.tagName))
return false;
a.target = param.f_target.trim();
a.title = param.f_title.trim();
editor.selectNodeContents(a);
editor.updateToolbar();
}, outparam);
};
HTMLArea.prototype._createsiteLink = function(link) {//AWT_UP:+
var editor = this;
var outparam = null;
if (typeof link == "undefined") {
link = this.getParentElement();
if (link && !/^a$/i.test(link.tagName))
link = null;
}
if (link) outparam = {
f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"),
f_title : link.title,
f_target : link.target
};
this._popupDialog("sitelink.php?sid=1", function(param) {
if (!param)
return false;
var a = link;
if (!a) {
editor._doc.execCommand("createlink", false, param.f_href);
a = editor.getParentElement();
var sel = editor._getSelection();
var range = editor._createRange(sel);
if (!HTMLArea.is_ie) {
a = range.startContainer;
if (!/^a$/i.test(a.tagName))
a = a.nextSibling;
}
} else a.href = param.f_href.trim();
if (!/^a$/i.test(a.tagName))
return false;
a.target = param.f_target.trim();
a.title = param.f_title.trim();
editor.selectNodeContents(a);
editor.updateToolbar();
}, outparam);
};
HTMLArea.prototype._createbookmark = function(link) {//AWT_UP:+
var editor = this;
var outparam = null;
if (typeof link == "undefined") {
link = this.getParentElement();
if (link && !/^a$/i.test(link.tagName))
link = null;
}
if (link) outparam = {
f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href")
};
this._popupDialog("bookmark.php?sid=1", function(param) {
if (!param)
return false;
var a = link;
if (!a) {
editor._doc.execCommand("createbookmark", false, param.f_href);
a = editor.getParentElement();
} else a.href = param.f_href.trim();
if (!/^a$/i.test(a.tagName))
return false;
editor.selectNodeContents(a);
editor.updateToolbar();
}, outparam);
};
HTMLArea.prototype._insertImage = function(image) {//AWT_UP:#
var editor = this;
var outparam = null;
if (typeof image == "undefined") {
image = this.getParentElement();
if (image && !/^img$/i.test(image.tagName))
image = null;
}
if (image) outparam = {
f_url : HTMLArea.is_ie ? editor.stripBaseURL(image.src) : image.getAttribute("src"),
f_alt : image.alt,
f_border : image.border,
f_align : image.align,
f_vert : image.vspace,
f_horiz : image.hspace
};
this._popupDialog("insert_image.php?sid=1", function(param) {
if (!param) {
return false;
}
var img = image;
if (!img) {
var sel = editor._getSelection();
var range = editor._createRange(sel);
editor._doc.execCommand("insertimage", false, param.f_url);
if (HTMLArea.is_ie) {
img = range.parentElement();
if (img.tagName.toLowerCase() != "img") {
img = img.previousSibling;
}
} else {
img = range.startContainer.previousSibling;
}
} else {
img.src = param.f_url;
}
for (field in param) {
var value = param[field];
switch (field) {
case "f_alt" : img.alt = value; break;
case "f_border" : img.border = parseInt(value || "0"); break;
case "f_align" : img.align = value; break;
case "f_vert" : img.vspace = parseInt(value || "0"); break;
case "f_horiz" : img.hspace = parseInt(value || "0"); break;
}
}
}, outparam);
};
HTMLArea.prototype._insertFlash = function(image) {//AWT_UP:#
var editor = this;
var outparam = null;
if (typeof image == "undefined") {
image = this.getParentElement();
if (image && !/^img$/i.test(image.tagName))
image = null;
}
if (image) outparam = {
f_url : HTMLArea.is_ie ? editor.stripBaseURL(image.src) : image.getAttribute("src"),
f_alt : image.alt,
f_border : image.border,
f_align : image.align,
f_vert : image.vspace,
f_horiz : image.hspace
};
this._popupDialog("insert_flash.php?sid=1", function(param) {
if (!param) {
return false;
}
var img = image;
if (!img) {
var sel = editor._getSelection();
var range = editor._createRange(sel);
editor._doc.execCommand("insertflash", false, param.f_url);
if (HTMLArea.is_ie) {
img = range.parentElement();
if (img.tagName.toLowerCase() != "img") {
img = img.previousSibling;
}
} else {
img = range.startContainer.previousSibling;
}
} else {
img.src = param.f_url;
}
for (field in param) {
var value = param[field];
switch (field) {
case "f_alt" : img.alt = value; break;
case "f_border" : img.border = parseInt(value || "0"); break;
case "f_align" : img.align = value; break;
case "f_vert" : img.vspace = parseInt(value || "0"); break;
case "f_horiz" : img.hspace = parseInt(value || "0"); break;
}
}
}, outparam);
};
HTMLArea.prototype._insertTable = function() {
var sel = this._getSelection();
var range = this._createRange(sel);
var editor = this;
this._popupDialog("insert_table.html", function(param) {
if (!param) {
return false;
}
var doc = editor._doc;
var table = doc.createElement("table");
for (var field in param) {
var value = param[field];
if (!value) {
continue;
}
switch (field) {
case "f_width" : table.style.width = value + param["f_unit"]; break;
case "f_align" : table.align = value; break;
case "f_border" : table.border = parseInt(value); break;
case "f_spacing" : table.cellspacing = parseInt(value); break;
case "f_padding" : table.cellpadding = parseInt(value); break;
}
}
var tbody = doc.createElement("tbody");
table.appendChild(tbody);
for (var i = 0; i < param["f_rows"]; ++i) {
var tr = doc.createElement("tr");
tbody.appendChild(tr);
for (var j = 0; j < param["f_cols"]; ++j) {
var td = doc.createElement("td");
tr.appendChild(td);
(HTMLArea.is_gecko) && td.appendChild(doc.createElement("br"));
}
}
if (HTMLArea.is_ie) {
range.pasteHTML(table.outerHTML);
} else {
editor.insertNodeAtSelection(table);
}
return true;
}, null);
};
HTMLArea.prototype._insertTemplate = function() {
var yekta_text = 'يكتاوب دستاورد سالها پژوهش و تجربه براي برپايي پايگاههاي اينترنتي در محيطهاي علمي و دانشگاهي است. فرآيندهاي مختلف دانشگاهي پس از بررسي و بهينهسازي به افزونهها ياماژولهاي موجود در مجموعه يكتاوب تبديل گرديدهاند و محصول نهايي بارها در بوته آزمايش سنجيده شده است.';
var sel = this._getSelection();
var range = this._createRange(sel);
var editor = this; // for nested functions
this._popupDialog("insert_template.html", function(param) {
if (!param) { // user must have pressed Cancel
return false;
}
var doc = editor._doc;
if(param["text_tpls"]=='t1')
{
range.pasteHTML(' چرا يكتاوب بهترين انتخاب براي دانشگاه ها است؟ '+yekta_text+' پايگاههاي مرتبط با برنامه يكتاوب : مجموعه مديريت يكپارچه پايگاههاي اينتترنتي : www.yektaweb.com جزيره دانش ايران : بانك بزرگ مقالات فارسي در دنياي وب : www.jazirehdanesh.com]*>/gi,'
');
D = D.replace(//gi,'').
replace(/<\/b>/gi,'');
D = D.replace(//gi,'').
replace(/<\/em>/gi,'');
D = D.replace(/<\?xml:[^>]*>/g, ''). // Word xml
replace(/<\/?st1:[^>]*>/g,''). // Word SmartTags
replace(/<\/?[a-z]\:[^>]*>/g,''). // All other funny Word non-HTML stuff
replace(/<\/?font[^>]*>/gi,''). // Disable if you want to keep font formatting
replace(/<\/?span[^>]*>/gi,' ').
replace(/<\/?div[^>]*>/gi,' ').
replace(/<\/?pre[^>]*>/gi,' ').
replace(/
');
}
if(param["text_tpls"]=='t2')
{
range.pasteHTML('
'+yekta_text+'
');
}
if(param["text_tpls"]=='t3')
{
range.pasteHTML(''+yekta_text+' '+yekta_text+'
');
}
if(param["text_tpls"]=='t4')
{
range.pasteHTML('
');
}
if(param["text_tpls"]=='t5')
{
range.pasteHTML('');
}
if(param["text_tpls"]=='t6')
{
range.pasteHTML('




متن دلخواه خود را در اينجا بنويسيد متن دلخواه خود را در اينجا بنويسيد