Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/02/2010, 16:47
rrecarte
 
Fecha de Ingreso: agosto-2008
Mensajes: 367
Antigüedad: 15 años, 8 meses
Puntos: 5
Respuesta: limitar textarea

}

// find a as parent element
lin = this.findParent("a", range);

// check if parent is found
var update = (lin == null) ? false : true;
if(!update) {
lin = doc.createElement("a");
}

// set the attributes
WYSIWYG_Core.setAttribute(lin, "href", href);
WYSIWYG_Core.setAttribute(lin, "class", styleClass);
WYSIWYG_Core.setAttribute(lin, "className", styleClass);
WYSIWYG_Core.setAttribute(lin, "target", target);
WYSIWYG_Core.setAttribute(lin, "name", name);
WYSIWYG_Core.setAttribute(lin, "style", style);

// on update exit here
if(update) { return; }

// Check if IE or Mozilla (other)
if (WYSIWYG_Core.isMSIE) {
range.select();
lin.innerHTML = range.htmlText;
range.pasteHTML(lin.outerHTML);
}
else {
var node = range.startContainer;
var pos = range.startOffset;
if(node.nodeType != 3) { node = node.childNodes[pos]; }
if(node.tagName)
lin.appendChild(node);
else
lin.innerHTML = sel;
this.insertNodeAtSelection(lin, n);
}
},

/**
* Strips any HTML added by word
*
* @param {String} n The editor identifier (the textarea's ID)
*/
removeFormat: function(n) {

if ( !confirm(this.config[n].RemoveFormatConfMessage) ) { return; }
var doc = this.getEditorWindow(n).document;
var str = doc.body.innerHTML;

str = str.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi, '');
str = str.replace(/<span[^>]*>/gi, '');
str = str.replace(/<\/span[^>]*>/gi, '');
str = str.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi, '');
str = str.replace(/<p[^>]*>/gi, '');
str = str.replace(/<\/p[^>]*>/gi, '');
str = str.replace(/<h([^>])[0-9]>(&nbsp;)*\s*<\/h>/gi, '');
str = str.replace(/<h[^>][0-9]>/gi, '');
str = str.replace(/<\/h[^>][0-9]>/gi, '');
str = str.replace (/<B [^>]*>/ig, '<b>');

// var repl_i1 = /<I[^>]*>/ig;
// str = str.replace (repl_i1, '<i>');

str = str.replace (/<DIV[^>]*>/ig, '');
str = str.replace (/<\/DIV>/gi, '');
str = str.replace (/<[\/\w?]+:[^>]*>/ig, '');
str = str.replace (/(&nbsp;){2,}/ig, '&nbsp;');
str = str.replace (/<STRONG>/ig, '');
str = str.replace (/<\/STRONG>/ig, '');
str = str.replace (/<TT>/ig, '');
str = str.replace (/<\/TT>/ig, '');
str = str.replace (/<FONT [^>]*>/ig, '');
str = str.replace (/<\/FONT>/ig, '');
str = str.replace (/STYLE=\"[^\"]*\"/ig, '');
str = str.replace(/<([\w]+) class=([^ |>]*)([^>]*)/gi, '<$1$3');
str = str.replace(/<([\w]+) style="([^"]*)"([^>]*)/gi, '<$1$3');
str = str.replace(/width=([^ |>]*)([^>]*)/gi, '');
str = str.replace(/classname=([^ |>]*)([^>]*)/gi, '');
str = str.replace(/align=([^ |>]*)([^>]*)/gi, '');
str = str.replace(/valign=([^ |>]*)([^>]*)/gi, '');
str = str.replace(/<\\?\??xml[^>]>/gi, '');
str = str.replace(/<\/?\w+:[^>]*>/gi, '');
str = str.replace(/<st1:.*?>/gi, '');
str = str.replace(/o:/gi, '');

str = str.replace(/<!--([^>])*>(&nbsp;)*\s*<\/-->/gi, '');
str = str.replace(/<!--[^>]*>/gi, '');
str = str.replace(/<\/--[^>]*>/gi, '');

doc.body.innerHTML = str;
},

/**
* Display an iframe instead of the textarea.
*
* @private
* @param {String} n The editor identifier (the textarea's ID)
* @param {Object} settings Object which holds the settings
*/
_display: function(n, settings) {

// Get the textarea element
var textarea = $(n);

// Validate if textarea exists
if(textarea == null) {
alert("No textarea found with the given identifier (ID: " + n + ").");
return;
}

// Validate browser compatiblity
if(!WYSIWYG_Core.isBrowserCompatible()) {
if(this.config[n].NoValidBrowserMessage != "") { alert(this.config[n].NoValidBrowserMessage); }
return;
}

// Load settings in config array, use the textarea id as identifier
if(typeof(settings) != "object") {
this.config[n] = new this.Settings();
}
else {
this.config[n] = settings;
}

// Hide the textarea
textarea.style.display = "none";

// Override the width and height of the editor with the
// size given by the style attributes width and height
if(textarea.style.width) {
this.config[n].Width = textarea.style.width;
}
if(textarea.style.height) {
this.config[n].Height = textarea.style.height
}

// determine the width + height
var currentWidth = this.config[n].Width;
var currentHeight = this.config[n].Height;

// Calculate the width + height of the editor
var ifrmWidth = "100%";
var ifrmHeight = "100%";
if(currentWidth.search(/%/) == -1) {
ifrmWidth = currentWidth;
ifrmHeight = currentHeight;
}

// Create iframe which will be used for rich text editing
var iframe = '<table cellpadding="0" cellspacing="0" border="0" style="width:' + currentWidth + '; height:' + currentHeight + ';" class="tableTextareaEditor"><tr><td valign="top">\n'
+ '<iframe frameborder="0" id="wysiwyg' + n + '" class="iframeText" style="width:' + ifrmWidth + ';height:' + ifrmHeight + ';"></iframe>\n'
+ '</td></tr></table>\n';

// Insert after the textArea both toolbar one and two
textarea.insertAdjacentHTML("afterEnd", iframe);

// Pass the textarea's existing text over to the content variable
var content = textarea.value;
var doc = this.getEditorWindow(n).document;

// Replace all \n with <br>
if(this.config[n].ReplaceLineBreaks) {
content = content.replace(/(\r\n)|(\n)/ig, "<br>");
}

// Write the textarea's content into the iframe
doc.open();
doc.write(content);
doc.close();

// Set default style of the editor window
WYSIWYG_Core.setAttribute(doc.body, "style", this.config[n].DefaultStyle);
},

/**
* Replace the given textarea with wysiwyg editor
*
* @private
* @param {String} n The editor identifier (the textarea's ID)
* @param {Object} settings Object which holds the settings
*/
_generate: function(n, settings) {

// Get the textarea element
var textarea = $(n);
// Validate if textarea exists
if(textarea == null) {
alert("No textarea found with the given identifier (ID: " + n + ").");
return;
}

// Validate browser compatiblity
if(!WYSIWYG_Core.isBrowserCompatible()) {
if(this.config[n].NoValidBrowserMessage != "") { alert(this.config[n].NoValidBrowserMessage); }
return;
}

// Hide the textarea
textarea.style.display = 'none';

// Override the width and height of the editor with the
// size given by the style attributes width and height
if(textarea.style.width) {
this.config[n].Width = textarea.style.width;
}
if(textarea.style.height) {
this.config[n].Height = textarea.style.height
}

// determine the width + height
var currentWidth = this.config[n].Width;
var currentHeight = this.config[n].Height;

// Calculate the width + height of the editor
var toolbarWidth = currentWidth;
var ifrmWidth = "100%";
var ifrmHeight = "100%";
if(currentWidth.search(/%/) == -1) {
toolbarWidth = currentWidth.replace(/px/gi, "");
toolbarWidth = (parseFloat(toolbarWidth) + 2) + "px";
ifrmWidth = currentWidth;
ifrmHeight = currentHeight;
}

// Generate the WYSIWYG Table
// This table holds the toolbars and the iframe as the editor
var editor = "";
editor += '<div id="wysiwyg_div_' + n + '" style="width:' + currentWidth +';">';
editor += '<table border="0" cellpadding="0" cellspacing="0" class="tableTextareaEditor" id="wysiwyg_table_' + n + '" style="width:' + currentWidth + '; height:' + currentHeight + ';">';
editor += '<tr><td style="height:22px;vertical-align:top;">';

// Output all command buttons that belong to toolbar one
for (var j = 0; j < this.config[n].Toolbar.length;j++) {
if(this.config[n].Toolbar[j] && this.config[n].Toolbar[j].length > 0) {
var toolbar = this.config[n].Toolbar[j];

// Generate WYSIWYG toolbar one
editor += '<table border="0" cellpadding="0" cellspacing="0" class="toolbar1" style="width:100%;" id="toolbar' + j + '_' + n + '">';
editor += '<tr><td style="width:6px;"><img src="' + this.config[n].ImagesDir + 'seperator2.gif" alt="" hspace="3"></td>';

// Interate over the toolbar element
for (var i = 0; i < toolbar.length;i++) {
var id = toolbar[i];
if (toolbar[i]) {
if(typeof (this.config[n].DropDowns[id]) != "undefined") {
var dropdown = this.config[n].DropDowns[id];
editor += '<td style="width: ' + dropdown.width + ';">';
// write the drop down content
editor += this.writeDropDown(n, id);
editor += '</td>';
}
else {

// Get the values of the Button from the global ToolbarList object
var buttonObj = this.ToolbarList[toolbar[i]];
if(buttonObj) {
var buttonID = buttonObj[0];
var buttonTitle = buttonObj[1];
var buttonImage = this.config[n].ImagesDir + buttonObj[2];
var buttonImageRollover = this.config[n].ImagesDir + buttonObj[3];

if (toolbar[i] == "seperator") {
editor += '<td style="width: 12px;" align="center">';
editor += '<img src="' + buttonImage + '" border=0 unselectable="on" width="2" height="18" hspace="2" unselectable="on">';
editor += '</td>';
}
// View Source button
else if (toolbar[i] == "viewSource"){
editor += '<td style="width: 22px;">';