From 4c2f95617ac80ebc78c96a5527f695ce2c9a3323 Mon Sep 17 00:00:00 2001 From: Len Kranendonk Date: Fri, 9 May 2003 12:50:39 +0000 Subject: [PATCH] Added MS-Word cleanup --- www/extras/htmlArea/editor.js | 118 ++++++++++++++++++++++++- www/extras/htmlArea/images/ed_word.gif | Bin 0 -> 660 bytes 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 www/extras/htmlArea/images/ed_word.gif diff --git a/www/extras/htmlArea/editor.js b/www/extras/htmlArea/editor.js index ca7c216fe..7d8109f34 100644 --- a/www/extras/htmlArea/editor.js +++ b/www/extras/htmlArea/editor.js @@ -42,7 +42,7 @@ this.toolbar = [ ['fontsize'], // ['fontstyle'], // ['linebreak'], - ['undo','redo','find','separator'], + ['undo','redo','word','find','separator'], ['bold','italic','underline','separator'], ['strikethrough','subscript','superscript','separator'], ['justifyleft','justifycenter','justifyright','separator'], @@ -85,6 +85,7 @@ this.fontstyles = [ // make sure these exist in the header of page the conte this.btnList = { // buttonName: commandID, title, onclick, image, + "word": ['word', 'MS-Word cleanup', 'editor_action(this.id)', 'ed_word.gif'], "undo": ['Undo', 'Undo Ctrl+z', 'editor_action(this.id)', 'ed_undo.gif'], "redo": ['Redo', 'Redo Ctrl+y', 'editor_action(this.id)', 'ed_redo.gif'], "find": ['Find', 'Find', 'editor_action(this.id)', 'ed_find.gif'], @@ -350,6 +351,64 @@ function editor_action(button_id) { else if (cmdID == 'custom3') { // insert some text editor_insertHTML(objname, "It's easy to add buttons that insert text!"); } + else if (cmdID == 'word') { + var oTags = editdoc.all.tags("SPAN"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + oTags[i].outerHTML = oTags[i].innerHTML; + } +} + +oTags = editdoc.all.tags("FONT"); +if (oTags != null) { +for (var i = oTags.length - 1; i >= 0; i--) { +oTags[i].outerHTML = oTags[i].innerHTML; +} +} + + oTags = editdoc.all.tags("P"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); + } +} + oTags = editdoc.all.tags("H1"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); +} +} + oTags = editdoc.all.tags("H2"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); +} +} + oTags = editdoc.all.tags("H3"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); +} +} + oTags = editdoc.all.tags("H4"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); +} +} + oTags = editdoc.all.tags("OL"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); +} +} + oTags = editdoc.all.tags("UL"); + if (oTags != null) { + for (var i = oTags.length - 1; i >= 0; i--) { + cleanEmptyTag(oTags[i]); } +} +} + // // END OF CUSTOM BUTTONS @@ -471,6 +530,63 @@ function editor_action(button_id) { editor_event(objname); } +/* ---------------------------------------------------------------------- *\ + Function : MS-Word clean-up + Description : replace textarea with wysiwyg editor + Usage : editor_generate("textarea_id",[height],[width]); + Arguments : objname - ID of textarea to replace + w - width of wysiwyg editor + h - height of wysiwyg editor +\* ---------------------------------------------------------------------- */ +function cleanEmptyTag(oElem) { +if (oElem.hasChildNodes) { +var tmp = oElem +for (var k = tmp.children.length; k >= 0; k--) { +if (tmp.children[k] != null) { +cleanEmptyTag(tmp.children[k]); +} +} + +} + +var oAttribs = oElem.attributes; +if (oAttribs != null) { +for (var j = oAttribs.length - 1; j >=0; j--) { +var oAttrib = oAttribs[j]; +if (oAttrib.nodeValue != null) { +oAttribs.removeNamedItem('class') +} + } + } + oElem.style.cssText = ''; +if (oElem.innerHTML == '' || oElem.innerHTML == ' ') { +oElem.outerHTML = ''; } +} + +function cleanTable(oElem) { + oElem.style.cssText = ''; + var oAttribs = oElem.attributes; + if (oAttribs != null) { + for (var j = oAttribs.length - 1; j >=0; j--) { + var oAttrib = oAttribs[j]; + if (oAttrib.nodeValue != null) { + oAttribs.removeNamedItem('class') + } + } + } + var oTR = oElem.rows; + if (oTR != null) { + for (var r = oTR.length - 1; r >= 0; r--) { + oTR[r].style.cssText = ''; + } + } + var oTD = oElem.cells; + if (oTD != null) { + for (var t = oTD.length - 1; t >= 0; t--) { + oTD[t].style.cssText = ''; + } + } +} /* ---------------------------------------------------------------------- *\ Function : editor_event Description : called everytime an editor event occurs diff --git a/www/extras/htmlArea/images/ed_word.gif b/www/extras/htmlArea/images/ed_word.gif new file mode 100644 index 0000000000000000000000000000000000000000..500f8ee0a3f0e5ae21fe957c5f76fa88db38b6e2 GIT binary patch literal 660 zcmW-eTS!v@9LE30{<^6hb2%N#G;2B&M5ENDT`2RCQDStXBhsANYBlDWHrMXX+flcv zbLgyGYE!TkJ(L>Az(gv-2WzXqs8&JNOF4Y0r?vW?etZulM-7Z&1F8?GJTYWyC&E^H@bUG~nR;e_QnYp93 z_F-CDv&Yj%)5CmzD@Ez-c1KgwfLQ!hB)aYO&dX%uD%GQghFO{(s;YVb&_>hq4C6p_ zA{qgD2!cc$M|3evcyJ@Y1jD>XR01#nS13wtG}-~`WU}?VJl*v44*e*8yg{oVkQ(4 z3Itw66Ts<}m1h+dDw0f;%kQtP`2mIilp>MR>-{Mb=}ab*P$&$AAoM=~u>B7b00zhj zGyMAmSV5D)+}7UF*~N5fwcS>O7QkXN_gea6?2bPDsPm>ndrdQ{*NmAt@tY#Hl5s?- zxJIvYyE@pho1^yBCo6NNbTf1ML32sb$djowWy2U~U?vIve8y4MLwhvOiB zaY0ZTXtRst_o{;vhs(BQm8V2b2Qx~O`O#w;uU@mPrt+h2#Y9O7Ih>ncJW2b$KkZH3 kf6V#&bE}1jijB`-To+feA_#tdf4Ugj*|!#xVi5NI1!g4fmjD0& literal 0 HcmV?d00001