Respuesta: limitar textarea config: new Array(),
// Create viewTextMode global variable and set to 0
// enabling all toolbar commands while in HTML mode
viewTextMode: new Array(),
// maximized
maximized: new Array(),
/**
* Get the range of the given selection
*
* @param {Selection} sel Selection object
* @return {Range} Range object
*/
getRange: function(sel) {
return sel.createRange ? sel.createRange() : sel.getRangeAt(0);
},
/**
* Return the editor div element
*
* @param {String} n Editor identifier
* @return {HtmlDivElement} Iframe object
*/
getEditorDiv: function(n) {
return $("wysiwyg_div_" + n);
},
/**
* Return the editor table element
*
* @param {String} n Editor identifier
* @return {HtmlTableElement} Iframe object
*/
getEditorTable: function(n) {
return $("wysiwyg_table_" + n);
},
/**
* Get the iframe object of the WYSIWYG editor
*
* @param {String} n Editor identifier
* @return {HtmlIframeElement} Iframe object
*/
getEditor: function(n) {
return $("wysiwyg" + n);
},
/**
* Get editors window element
*
* @param {String} n Editor identifier
* @return {HtmlWindowElement} Html window object
*/
getEditorWindow: function(n) {
return this.getEditor(n).contentWindow;
},
/**
* Attach the WYSIWYG editor to the given textarea element
*
* @param {String} id Textarea identifier (all = all textareas)
* @param {Settings} settings the settings which will be applied to the textarea
*/
attach: function(id, settings) {
if(id != "all") {
this.setSettings(id, settings);
WYSIWYG_Core.includeCSS(this.config[id].CSSFile);
WYSIWYG_Core.addEvent(window, "load", function generateEditor() {WYSIWYG._generate(id, settings);});
}
else {
WYSIWYG_Core.addEvent(window, "load", function generateEditor() {WYSIWYG.attachAll(settings);});
}
},
/**
* Attach the WYSIWYG editor to all textarea elements
*
* @param {Settings} settings Settings to customize the look and feel
*/
attachAll: function(settings) {
var areas = document.getElementsByTagName("textarea");
for(var i=0;i<areas.length;i++) {
var id = areas[i].getAttribute("id");
if(id == null || id == "") continue;
this.setSettings(id, settings);
WYSIWYG_Core.includeCSS(this.config[id].CSSFile);
WYSIWYG._generate(id, settings);
}
},
/**
* Display an iframe instead of the textarea.
* It's used as textarea replacement to display HTML.
*
* @param id Textarea identifier (all = all textareas)
* @param settings the settings which will be applied to the textarea
*/
display: function(id, settings) {
if(id != "all") {
this.setSettings(id, settings);
WYSIWYG_Core.includeCSS(this.config[id].CSSFile);
WYSIWYG_Core.addEvent(window, "load", function displayIframe() {WYSIWYG._display(id, settings);});
}
else {
WYSIWYG_Core.addEvent(window, "load", function displayIframe() {WYSIWYG.displayAll(settings);});
}
},
/**
* Display an iframe instead of the textarea.
* It's apply the iframe to all textareas found in the current document.
*
* @param settings Settings to customize the look and feel
*/
displayAll: function(settings) {
var areas = document.getElementsByTagName("textarea");
for(var i=0;i<areas.length;i++) {
var id = areas[i].getAttribute("id");
if(id == null || id == "") continue;
this.setSettings(id, settings);
WYSIWYG_Core.includeCSS(this.config[id].CSSFile);
WYSIWYG._display(id, settings);
}
},
/**
* Set settings in config array, use the textarea id as identifier
*
* @param n Textarea identifier (all = all textareas)
* @param settings the settings which will be applied to the textarea
*/
setSettings: function(n, settings) {
if(typeof(settings) != "object") {
this.config[n] = new this.Settings();
}
else {
this.config[n] = settings;
}
},
/**
* Insert or modify an image
*
* @param {String} src Source of the image
* @param {Integer} width Width
* @param {Integer} height Height
* @param {String} align Alignment of the image
* @param {String} border Border size
* @param {String} alt Alternativ Text
* @param {Integer} hspace Horizontal Space
* @param {Integer} vspace Vertical Space
* @param {String} n The editor identifier (the textarea's ID)
*/
insertImage: function(src, width, height, align, border, alt, hspace, vspace, n) {
// get editor
var doc = this.getEditorWindow(n).document;
// get selection and range
var sel = this.getSelection(n);
var range = this.getRange(sel);
// the current tag of range
var img = this.findParent("img", range);
// element is not a link
var update = (img == null) ? false : true;
if(!update) {
img = doc.createElement("img");
}
// set the attributes
WYSIWYG_Core.setAttribute(img, "src", src);
WYSIWYG_Core.setAttribute(img, "style", "width:" + width + ";height:" + height);
if(align != "") { WYSIWYG_Core.setAttribute(img, "align", align); } else { img.removeAttribute("align"); }
WYSIWYG_Core.setAttribute(img, "border", border);
WYSIWYG_Core.setAttribute(img, "alt", alt);
WYSIWYG_Core.setAttribute(img, "hspace", hspace);
WYSIWYG_Core.setAttribute(img, "vspace", vspace);
img.removeAttribute("width");
img.removeAttribute("height");
// on update exit here
if(update) { return; }
// Check if IE or Mozilla (other)
if (WYSIWYG_Core.isMSIE) {
range.pasteHTML(img.outerHTML);
}
else {
this.insertNodeAtSelection(img, n);
}
},
/**
* Insert or modify a link
*
* @param {String} href The url of the link
* @param {String} target Target of the link
* @param {String} style Stylesheet of the link
* @param {String} styleClass Stylesheet class of the link
* @param {String} name Name attribute of the link
* @param {String} n The editor identifier (the textarea's ID)
*/
insertLink: function(href, target, style, styleClass, name, n) {
// get editor
var doc = this.getEditorWindow(n).document;
// get selection and range
var sel = this.getSelection(n);
var range = this.getRange(sel);
var lin = null;
// get element from selection
if(WYSIWYG_Core.isMSIE) {
if(sel.type == "Control" && range.length == 1) {
range = this.getTextRange(range(0));
range.select();
}
} |