From 4351130450e7c92d5ebb4632bbd1cf0f595ac294 Mon Sep 17 00:00:00 2001 From: julmis Date: Sun, 14 Dec 2003 14:57:33 +0000 Subject: [PATCH] added wordClean function and new table operations - column sizes are calculated automatically from table width --- lib/editor/htmlarea.php | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/lib/editor/htmlarea.php b/lib/editor/htmlarea.php index 6192f63a56..670f78c139 100644 --- a/lib/editor/htmlarea.php +++ b/lib/editor/htmlarea.php @@ -1319,6 +1319,15 @@ HTMLArea.prototype._insertTable = function() { tbody.appendChild(tr); for (var j = 0; j < param["f_cols"]; ++j) { var td = doc.createElement("td"); + /// Moodle hack + if(param["f_unit"] == "px") { + tdwidth = Math.round(table.width / param["f_cols"]); + } else { + tdwidth = Math.round(100 / param["f_cols"]); + } + td.setAttribute("width",tdwidth + param["f_unit"]); + td.setAttribute("valign","top"); + /// Moodle hack -ends tr.appendChild(td); // Mozilla likes to see something inside the cell. (HTMLArea.is_gecko) && td.appendChild(doc.createElement("br")); @@ -1377,7 +1386,88 @@ HTMLArea.prototype._insertChar = function() { /************************************************************************ * Moodle hack's ends ************************************************************************/ +/// Called when the user Pastes from Ctrl-V; +HTMLArea.prototype._pasteSpecial = function() { + var editor = this; // for nested functions + editor.unPasteSpecial = function () {editor._unPasteSpecial()}; + HTMLArea._addEvent(editor._doc, "keyup",editor.unPasteSpecial); +}; + +/// Called on Ctrl-V keyup; + +HTMLArea.prototype._unPasteSpecial = function() { + var editor = this; + HTMLArea._removeEvent(editor._doc, "keyup",editor.unPasteSpecial); + editor._wordClean(); +}; + +// Word Clean Function; + +HTMLArea.prototype._wordClean = function() { + var D = this.getInnerHTML(); + if (D.indexOf('class=Mso') >= 0 || D.indexOf('mso') >= 0) { + + // make one line + D = D.replace(/\r\n/g, ' '). + replace(/\n/g, ' '). + replace(/\r/g, ' '). + replace(/\ \;/g,' '); + + // keep tags, strip attributes + D = D.replace(/ class=[^\s|>]*/gi,''). + //replace(/

]*TEXT-ALIGN: justify[^>]*>/gi,'

'). + replace(/ style=\"[^>]*\"/gi,''). + replace(/ align=[^\s|>]*/gi,''); + + //clean up tags + D = D.replace(/]*>/gi,''). + replace(/]*>/gi,''). + replace(/

  • ]*>/gi,'
  • '). + replace(/
      ]*>/gi,'
        '); + + // replace outdated tags + D = D.replace(//gi,''). + replace(/<\/b>/gi,''); + + // mozilla doesn't like tags + D = D.replace(//gi,''). + replace(/<\/em>/gi,''); + + // kill unwanted tags + 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(/<\/?h[1-6][^>]*>/gi,' '). + /// Try to remove and stuff + replace(/