A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

696 lines
31 KiB

  1. /**
  2. * @package Dynamic Script Forum
  3. * @file wyzz.js
  4. * @version 1.0.x, 19-10-2007, 18:03
  5. * @copyright 2008(c) DSF Team
  6. * @author ------------------
  7. * @link http://dsf.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. // Editor Width and Height
  11. wyzzW = 600;
  12. wyzzH = 200;
  13. image_path = skin_path + 'images/';
  14. // Number of toolbars - must be either 1 or 2
  15. // If set to 1, the first tooolbar (defined in array buttonName below) will be ignored
  16. toolbarCount = 2;
  17. // Edit region stylesheet
  18. editstyle = skin_path + 'wyzz_editarea.css';
  19. // Do we want to try to clean the code to emulate xhtml? 1=Yes, 0=No
  20. xhtml_out = 0;
  21. // Style Sheet
  22. document.write('<link rel="stylesheet" type="text/css" href="'+ skin_path+'wyzz_style.css">\n');
  23. // TOOLBARS ARRAYS
  24. // Order of available commands in toolbar
  25. // Remove from this any buttons not required in your application
  26. var buttonName = new Array("font","headers","separator","bold","italic","underline","strikethrough","separator","cut","copy","paste","separator","subscript","superscript","separator","justifyleft","justifycenter","justifyright","justifyfull","indent","outdent","separator","insertunorderedlist","insertorderedlist","separator","link","insertimage","separator","undo","redo");
  27. // Order of available commands in toolbar2
  28. // Remove from this any buttons not required in your application
  29. var buttonName2 = new Array("specialchar","separator","forecolor","backcolor","separator","inserthorizontalrule","separator","removeformat","separator","upsize","downsize","separator","htmlmode","separator");
  30. var myFonts = new Array("Andale Mono","Georgia","Verdana","Arial","Arial Black","impact","Times New Roman","Courier New","Comic Sans MS","Helvetica","Trebuchet MS","Tahoma");
  31. var specialChars = new Array("&copy;","&reg;","&#153;","&agrave;","&aacute;","&ccedil;","&egrave;","&eacute;","&euml;","&igrave;","&iacute;","&ntilde;","&ograve;","&oacute;","&ouml;","&ugrave;","&uacute;","&uuml;","&pound;","&cent;","&yen;","&euro;","&#147;","&#148;","&laquo;","&raquo;","&#149;","&#151;","&#133;","&para;","&#8224;","&#8225;","&times;","&divide;","&deg;","&plusmn;","&frac14;","&frac12;","&frac34;","&not;","&lt;","&gt;","&Delta;","&lambda;","&Phi;","&Psi;","&Sigma;","&int;","&alpha;","&beta;","&Omega;","&mu;","&pi;","&theta;","&harr;","&infin;","&radic;","&asymp;","&ne;","&equiv;","&le;","&ge;","&iexcl;","&iquest;","&spades;","&clubs;","&hearts;","&diams;");
  32. // DON'T MODIFY BEYOND THIS LINE unless you know what you are doing //////////////
  33. /********************************************************************************/
  34. version = "0.62"; // Please leave this
  35. var Headers = new Array("P","PRE","H1","H2","H3","H4","H5","H6");
  36. // Mode wysiwyg = 1 or sourcecode = 0
  37. mode = 1;
  38. // Get browser
  39. browserName = navigator.appName;
  40. nlBefore = new Array("div","p","li","h1","h2","h3","h4","h5","h6","hr","ul","ol");
  41. function h2x(node,inPre) { // we will pass the node containing the Wyzz-generated html
  42. var xout = '';
  43. var i;
  44. var j;
  45. // for each child of the node
  46. for(i=0;i<node.childNodes.length;i++) {
  47. if(node.childNodes[i].parentNode && String(node.tagName).toLowerCase() != String(node.childNodes[i].parentNode.tagName).toLowerCase()) continue;
  48. // alert('Nodes: '+ node.childNodes.length);
  49. switch(node.childNodes[i].nodeType) {
  50. case 1: { // for element nodes
  51. // get tag name
  52. var tagname = String(node.childNodes[i].tagName).toLowerCase();
  53. if(tagname == '') break;
  54. if((indexOf(nlBefore,tagname)!=-1)&&(!inPre)) { // this tag needs line break before it
  55. xout += '\n';
  56. }
  57. xout += '<' + tagname;
  58. var atts = node.childNodes[i].attributes;
  59. var attvalue;
  60. for(j=0;j<atts.length;j++) { // for each attribute
  61. var attname = atts[j].nodeName.toLowerCase();
  62. if(!atts[j].specified) continue;
  63. var validatt = true;
  64. switch(attname) {
  65. case "style": attvalue = node.childNodes[i].style.cssText; break;
  66. case "class": attvalue = node.childNodes[i].className; break;
  67. case "name": attvalue = node.childNodes[i].name; break;
  68. default:
  69. try {
  70. attvalue = node.childNodes[i].getAttribute(attname,2);
  71. } catch(e) {
  72. validatt = false;
  73. }
  74. }
  75. if(validatt) {
  76. if(!(tagname=='li' && attname == 'value')) {
  77. xout += ' '+attname + '="' + fixatt(attvalue) + '"';
  78. }
  79. }
  80. }
  81. if(tagname == 'img' && attname == 'alt') {
  82. xout += ' alt=""';
  83. }
  84. if(node.childNodes[i].canHaveChildren||node.childNodes[i].hasChildNodes()) {
  85. xout += '>';
  86. xout += h2x(node.childNodes[i],tagname=='pre'?true:false);
  87. xout += '</' + tagname + '>';
  88. } else {
  89. if(tagname == 'style'||tagname == 'title'||tagname=='script'||tagname=='textarea'||tagname=='a') {
  90. xout += '>';
  91. var innertext;
  92. if(tagname=='script') {
  93. innertext = node.childNodes[i].text;
  94. } else {
  95. innertext = node.childNodes[i].innerHTML;
  96. }
  97. if(tagname=='style') {
  98. innertext = String(innertext).replace(/[\n]+/g,'\n');
  99. }
  100. xout += innertext + '</' + tagname + '>';
  101. } else {
  102. xout += '/>';
  103. }
  104. }
  105. break;
  106. }
  107. // else if(node.childNodes[i].nodeType == 2) { // for attribute nodes
  108. // }
  109. case 3: { // for text nodes
  110. if(!inPre) { // don't change inside a <pre> tag
  111. if(node.childNodes[i] != '\n') {
  112. xout += fixents(fixtext(node.childNodes[i].nodeValue));
  113. }
  114. } else {
  115. xout += node.childNodes[i].nodeValue;
  116. break;
  117. }
  118. }
  119. default:
  120. break;
  121. }
  122. }
  123. return xout;
  124. }
  125. function fixents(text) {
  126. var i;
  127. var ents = {8364 : "euro",402 : "fnof",8240 : "permil",352 : "Scaron",338 : "OElig",381 : "#381",8482 : "trade",353 : "scaron",339 : "oelig",382 : "#382",376 : "Yuml",162 : "cent",163 : "pound",164 : "curren",165 : "yen",166 : "brvbar",167 : "sect",168 : "uml",169 : "copy",170 : "ordf",171 : "laquo",172 : "not",173 : "shy",174 : "reg",175 : "macr",176 : "deg",177 : "plusmn",178 : "sup2",179 : "sup3",180 : "acute",181 : "micro",182 : "para",183 : "middot",184 : "cedil",185 : "sup1",186 : "ordm",187 : "raquo",188 : "frac14",189 : "frac12",190 : "frac34",191 : "iquest",192 : "Agrave",193 : "Aacute",194 : "Acirc",195 : "Atilde",196 : "Auml",197 : "Aring",198 : "AElig",199 : "Ccedil",200 : "Egrave",201 : "Eacute",202 : "Ecirc",203 : "Euml",204 : "Igrave",205 : "Iacute",206 : "Icirc",207 : "Iuml",208 : "ETH",209 : "Ntilde",210 : "Ograve",211 : "Oacute",212 : "Ocirc",213 : "Otilde",214 : "Ouml",215 : "times",216 : "Oslash",217 : "Ugrave",218 : "Uacute",219 : "Ucirc",220 : "Uuml",221 : "Yacute",222 : "THORN",223 : "szlig",224 : "agrave",225 : "aacute",226 : "acirc",227 : "atilde",228 : "auml",229 : "aring",230 : "aelig",231 : "ccedil",232 : "egrave",233 : "eacute",234 : "ecirc",235 : "euml",236 : "igrave",237 : "iacute",238 : "icirc",239 : "iuml",240 : "eth",241 : "ntilde",242 : "ograve",243 : "oacute",244 : "ocirc",245 : "otilde",246 : "ouml",247 : "divide",248 : "oslash",249 : "ugrave",250 : "uacute",251 : "ucirc",252 : "uuml",253 : "yacute",254 : "thorn",255 : "yuml",913 : "Alpha",914 : "Beta",915 : "Gamma",916 : "Delta",917 : "Epsilon",918 : "Zeta",919 : "Eta",920 : "Theta",921 : "Iota",922 : "Kappa",923 : "Lambda",924 : "Mu",925 : "Nu",926 : "Xi",927 : "Omicron",928 : "Pi",929 : "Rho", 931 : "Sigma",932 : "Tau",933 : "Upsilon",934 : "Phi",935 : "Chi",936 : "Psi",937 : "Omega",8756 : "there4",8869 : "perp",945 : "alpha",946 : "beta",947 : "gamma",948 : "delta",949 : "epsilon",950 : "zeta",951 : "eta",952 : "theta",953 : "iota",954 : "kappa",955 : "lambda",956 : "mu",957 : "nu",968 : "xi",969 : "omicron",960 : "pi",961 : "rho",962 : "sigmaf",963 : "sigma",964 : "tau",965 : "upsilon",966 : "phi",967 : "chi",968 : "psi",969 : "omega",8254 : "oline",8804 : "le",8260 : "frasl",8734 : "infin",8747 : "int",9827 : "clubs",9830 : "diams",9829 : "hearts",9824 : "spades",8596 : "harr",8592 : "larr",8594 : "rarr",8593 : "uarr",8595 : "darr",8220 : "ldquo",8221 : "rdquo",8222 : "bdquo",8805 : "ge",8733 : "prop",8706 : "part",8226 : "bull",8800 : "ne",8801 : "equiv",8776 : "asymp",8230 : "hellip",8212 : "mdash",8745 : "cap",8746 : "cup",8835 : "sup",8839 : "supe",8834 : "sub",8838 : "sube",8712 : "isin",8715 : "ni",8736 : "ang",8711 : "nabla",8719 : "prod",8730 : "radic",8743 : "and",8744 : "or",8660 : "hArr",8658 : "rArr",9674 : "loz",8721 : "sum",8704 : "forall",8707 : "exist",8216 : "lsquo",8217 : "rsquo",161 : "iexcl",977 : "thetasym",978 : "upsih",982 : "piv",8242 : "prime",8243 : "Prime",8472 : "weierp",8465 : "image",8476 : "real",8501 : "alefsym",8629 : "crarr",8656 : "lArr",8657 : "uArr",8659 : "dArr",8709 : "empty",8713 : "notin",8727 : "lowast",8764 : "sim",8773 : "cong",8836 : "nsub",8853 : "oplus",8855 : "otimes",8901 : "sdot",8968 : "lceil",8969 : "rceil",8970 : "lfloor",8971 : "rfloor",9001 : "lang",9002 : "rang",710 : "circ",732 : "tilde",8194 : "ensp",8195 : "emsp",8201 : "thinsp",8204 : "zwnj",8205 : "zwj",8206 : "lrm",8207 : "rlm",8211 : "ndash",8218 : "sbquo",8224 : "dagger",8225 : "Dagger",8249 : "lsaquo",8250 : "rsaquo"};
  128. var new_text = '';
  129. var temp = new RegExp();
  130. temp.compile("[a]|[^a]", "g");
  131. var parts = text.match(temp);
  132. if (!parts) return text;
  133. for (i=0; i<parts.length; i++) {
  134. var c_code = parseInt(parts[i].charCodeAt());
  135. if (ents[c_code]) {
  136. new_text += "&"+ents[c_code]+";";
  137. } else new_text += parts[i];
  138. }
  139. return new_text;
  140. }
  141. function fixtext(text) {
  142. var temptext = String(text).replace(/\&lt;/g,"#h2x_lt").replace(/\&gt;/g,"#h2x_gt");
  143. temptext = temptext.replace(/\n{2,}/g,"\n").replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\u00A0/g,"&nbsp;");
  144. return temptext.replace(/#h2x_lt/g,"&alt;").replace(/#h2x_gt/g,"&gt;");
  145. }
  146. function fixatt(text) {
  147. var temptext = String(text).replace(/\&lt;/g,"#h2x_lt").replace(/\&gt;/g,"#h2x_gt");
  148. temptext = temptext.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
  149. return temptext.replace(/#h2x_lt/g,"&alt;").replace(/#h2x_gt/g,"&gt;");
  150. }
  151. function indexOf(thisarray, value)
  152. {
  153. var i;
  154. for (i=0; i < thisarray.length; i++) {
  155. if (thisarray[i] == value) {
  156. return i;
  157. }
  158. }
  159. return -1;
  160. }
  161. // Color picker - here we make an array of all websafe colors
  162. // If you want to limit the colors available to users (e.g. to fit in with
  163. // a site design) then use a restricted array of colors
  164. // e.g. var buttonName = new Array("336699","66abff", .... etc
  165. var buttonColors = new Array(216);
  166. // Colors - replace this function with your own if you have special requirements for colors
  167. function getColorArray() {
  168. // Color code table
  169. c = new Array('00', '33', '66', '99', 'cc', 'ff');
  170. var count = 0;
  171. // Iterate red
  172. for (r = 0; r < 6; r++)
  173. {
  174. // Iterate green
  175. for (g = 0; g < 6; g++)
  176. {
  177. // Iterate blue
  178. for (b = 0; b < 6; b++)
  179. {
  180. // Get RGB color
  181. buttonColors[count] = c[r] + c[g] + c[b];
  182. count++;
  183. }
  184. }
  185. }
  186. }
  187. getColorArray();
  188. /* Emulates insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() three functions
  189. so they work with Netscape 6/Mozilla - By Thor Larholm me@jscript.dk */
  190. if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement) {
  191. HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) {
  192. switch (where) {
  193. case 'beforeBegin':
  194. this.parentNode.insertBefore(parsedNode,this)
  195. break;
  196. case 'afterBegin':
  197. this.insertBefore(parsedNode,this.firstChild);
  198. break;
  199. case 'beforeEnd':
  200. this.appendChild(parsedNode);
  201. break;
  202. case 'afterEnd':
  203. if (this.nextSibling) {
  204. this.parentNode.insertBefore(parsedNode,this.nextSibling);
  205. } else {
  206. this.parentNode.appendChild(parsedNode);
  207. break;
  208. }
  209. }
  210. }
  211. HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
  212. var r = this.ownerDocument.createRange();
  213. r.setStartBefore(this);
  214. var parsedHTML = r.createContextualFragment(htmlStr);
  215. this.insertAdjacentElement(where,parsedHTML)
  216. }
  217. HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
  218. var parsedText = document.createTextNode(txtStr)
  219. this.insertAdjacentElement(where,parsedText)
  220. }
  221. }
  222. function closeColorPicker(thisid) {
  223. document.getElementById(thisid).style.display = "none";
  224. }
  225. // the hyperlink dialog
  226. function insertLink(n) {
  227. var newWindow = 'blank';
  228. var linkurl = '';
  229. var linktitle = '';
  230. var targetText = grabSelectedText(n);
  231. var linkurl = prompt(editor_lng2);
  232. var linktitle = prompt(editor_lng3);
  233. if(newWindow==''||linkurl==''||linktitle=='') {
  234. alert();
  235. insertLink(n);
  236. } else {
  237. var hyperLink = '<a href="' + linkurl + '" target="_' + newWindow + '" title="' + linktitle + '" class="fsmall">' + linktitle + '</a>';
  238. insertHTML(hyperLink, n);
  239. }
  240. }
  241. function insertImage(n) {
  242. var imgurl = prompt(editor_lng4);
  243. var imgtitle = 'image';
  244. var theImage = '<img src="' + imgurl + '" title="' + imgtitle + '" alt="' + imgtitle + '" />';
  245. insertHTML(theImage, n); }
  246. function insertSmile(imgurl, imgtitle) {
  247. if(mode==0) {
  248. alert(editor_lng1);
  249. } else {
  250. var n = 'textedit';
  251. var theImage = '<img src="' + imgurl + '" title="' + imgtitle + '" alt="' + imgtitle + '" >';
  252. insertHTML(theImage, n); } }
  253. function make_wyzz(textareaID) {
  254. // Hide the textarea
  255. document.getElementById(textareaID).style.display = 'none';
  256. // get textareaID
  257. var n = textareaID;
  258. // Toolbars width is 2 pixels wider than the editor
  259. toolbarWidth = parseFloat(wyzzW) + 2;
  260. var toolbar = '';
  261. // We only generate toolbar 1 if toolbarCount is set to 2
  262. if(toolbarCount == 2) {
  263. // Generate WYSIWYG toolbar
  264. toolbar = '<table cellpadding="0" cellspacing="0" border="0" class="toolbar" style="width:' + toolbarWidth + 'px;"><tr>';
  265. // Output buttons for toolbar
  266. var colNumbers = 0;
  267. for (btn in buttonName) {
  268. colNumbers ++;
  269. if(buttonName[btn] == "separator") {
  270. toolbar += '<td class="separator">&nbsp;</td>';
  271. } else {
  272. toolbar += '<td style="width: 22px;"><img src="' + image_path + 'wyzz/' +buttonName[btn]+ '.gif" border=0 unselectable="on" title="' +buttonNameLng[btn]+ '" id="' +buttonName[btn]+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'};" onmouseout="if(className==\'buttonOver\'){className=\'button\'};" unselectable="on" width="20" height="20"></td>';
  273. }
  274. }
  275. toolbar += '<td >&nbsp;</td></tr></table>';
  276. }
  277. // Generate WYSIWYG toolbar2
  278. var toolbar2 = '<table cellpadding="0" cellspacing="0" border="0" class="toolbar" style="width:' + toolbarWidth + 'px;"><tr>';
  279. // Output buttons for toolbar2
  280. var colNumbers = 0;
  281. for (btn in buttonName2) {
  282. colNumbers ++;
  283. if(buttonName2[btn] == "separator") {
  284. toolbar2 += '<td class="separator">&nbsp;</td>';
  285. } else {
  286. toolbar2 += '<td style="width: 22px;"><img src="' + image_path + 'wyzz/' +buttonName2[btn]+ '.gif" border=0 unselectable="on" title="' +buttonName2Lng[btn]+ '" id="' +buttonName2[btn]+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'};" onmouseout="if(className==\'buttonOver\'){className=\'button\'};" unselectable="on" width="20" height="20"></td>';
  287. }
  288. }
  289. toolbar2 += '<td>&nbsp;</td></tr>';
  290. // the foreground color picker
  291. var swatchcount = 0;
  292. toolbar2 += '<tr><td colspan=' + colNumbers + '>';
  293. toolbar2 += '<div id="colorpicker' + n + '" class="colorpicker" style="display:none">';
  294. for (clr in buttonColors) {
  295. toolbar2 += '<a href="#" title="#' + buttonColors[clr] + '" alt="#' + buttonColors[clr] + '" "class="colorButton" onClick="formatTextColor(\'' + buttonColors[clr] + '\',\'' + n + '\');" style="background: #' + buttonColors[clr] + '">&nbsp;</a>';
  296. swatchcount++;
  297. if(swatchcount%18==0) {
  298. toolbar2 += '<br>';
  299. }
  300. }
  301. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'colorpicker' + n + '\')"></div>';
  302. // the background color picker
  303. toolbar2 += '<div id="colorbackpicker' + n + '" class="colorpicker" style="display:none">';
  304. for (clr in buttonColors) {
  305. toolbar2 += '<a href="#" title="#' + buttonColors[clr] + '" alt="#' + buttonColors[clr] + '" class="colorButton" onClick="formatBackColor(\'' + buttonColors[clr] + '\',\'' + n + '\');" style="background: #' + buttonColors[clr] + '">&nbsp;</a>';
  306. swatchcount++;
  307. if(swatchcount%18==0) {
  308. toolbar2 += '<br>';
  309. }
  310. }
  311. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'colorbackpicker' + n + '\')"></div>';
  312. // the font picker
  313. toolbar2 += '<div id="fontpicker' + n + '" class="fontpicker" style="display:none">';
  314. for (fnt in myFonts) {
  315. toolbar2 += '<a href="#" class="fontSelect" onClick="formatFontName(\'' + myFonts[fnt] + '\',\'' + n + '\');" style="font-size:14px;padding: 0px 0px 0px 30px;font-family:' + myFonts[fnt] +'">' + myFonts[fnt] +'</a>';
  316. toolbar2 += '<br>';
  317. }
  318. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'fontpicker' + n + '\')"></div>';
  319. // the special character picker
  320. toolbar2 += '<div id="specialpicker' + n + '" class="specialpicker" style="display:none"><table><tr>';
  321. var charcount = 0;
  322. for (chr in specialChars) {
  323. toolbar2 += '<td><a href="#" onClick="formatSpecialChar(\'' + specialChars[chr] + '\',\'' + n + '\');">' + specialChars[chr] + '</a>&nbsp;</td>';
  324. charcount++;
  325. if(charcount%10==0) {
  326. toolbar2 += '</tr><tr>';
  327. }
  328. }
  329. toolbar2 += '</tr></table><br><img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'specialpicker' + n + '\')"></div>';
  330. // the header picker
  331. toolbar2 += '<div id="headerpicker' + n + '" class="headerpicker" style="display:none">';
  332. for (hdr in Headers) {
  333. toolbar2 += '<a href="#" class="headerSelect" onClick="formatHeader(\'' + Headers[hdr] + '\',\'' + n + '\');" style="font-size:14px;padding: 0px 0px 0px 30px;font-family:arial">' + Headers[hdr] +'</a>';
  334. toolbar2 += '<br>';
  335. }
  336. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'headerpicker' + n + '\')"></div>';
  337. // Add extra popups here
  338. // The help/about box
  339. // The copyright and link must remain unaltered
  340. toolbar2 += '<div id="helpbox' + n + '" class="helpbox" style="display:none">';
  341. toolbar2 += '<div class="help"><h4><img src="' + image_path + 'wyzz/wyzzicon.gif" align="middle">Wyzz v' + version + '</h4><br>&copy; 2007 <a href="http://www.wyzz.info" target=_blank>www.wyzz.info</a><br><br></div>';
  342. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'helpbox' + n + '\')"></div></td></tr></table>';
  343. // Create iframe for editor
  344. var iframe = '<table cellpadding="0" cellspacing="0" border="0" style="width:' + wyzzW + 'px; height:' + wyzzH + 'px;border: 1px inset #dddddd;"><tr><td valign="top">\n'
  345. + '<iframe frameborder="0" id="wysiwyg' + n + '"></iframe>\n'
  346. + '</td></tr></table>\n';
  347. // Insert toolbar after the textArea
  348. document.getElementById(n).insertAdjacentHTML("afterEnd", toolbar + toolbar2 + iframe);
  349. // Give the iframe the required height and width
  350. document.getElementById("wysiwyg" + n).style.height = wyzzH + "px";
  351. document.getElementById("wysiwyg" + n).style.width = wyzzW + "px";
  352. // Pass the textarea's existing text into the editor
  353. var content = document.getElementById(n).value;
  354. var doc = document.getElementById("wysiwyg" + n).contentWindow.document;
  355. // Write the textarea's content into the iframe
  356. doc.open();
  357. if (browserName == "Microsoft Internet Explorer") {
  358. doc.write('<link rel="stylesheet" media="screen" type="text/css" href="' + editstyle + '"/>' + content);
  359. } else {
  360. doc.write('<html><head><link rel="stylesheet" type="text/css" href="' + editstyle + '"/></head><body>' + content + '<br /></body></html>');
  361. }
  362. doc.close();
  363. // var browserName = navigator.appName;
  364. if (browserName == "Microsoft Internet Explorer"||browserName == "Opera") {
  365. // Make the iframe editable
  366. doc.body.contentEditable = true;
  367. } else {
  368. // Make the iframe editable
  369. doc.designMode = "on";
  370. }
  371. // Update the textarea with content in WYSIWYG when user submits form
  372. // var browserName = navigator.appName;
  373. if (browserName == "Microsoft Internet Explorer"||browserName == "Opera") {
  374. for (var idx=0; idx < document.forms.length; idx++) {
  375. document.forms[idx].attachEvent('onsubmit', function() { updateTextArea(n); });
  376. }
  377. }
  378. else {
  379. for (var idx=0; idx < document.forms.length; idx++) {
  380. document.forms[idx].addEventListener('submit',function OnSumbmit() { updateTextArea(n); }, true);
  381. }
  382. }
  383. }
  384. function formatTextColor(color, n, selected) {
  385. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('forecolor', false, color);
  386. document.getElementById('colorpicker' + n).style.display = "none";
  387. }
  388. function formatBackColor(color, n, selected) {
  389. if (browserName == "Microsoft Internet Explorer") {
  390. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('backcolor', false, color);
  391. } else {
  392. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('hilitecolor', false, color);
  393. }
  394. document.getElementById('colorbackpicker' + n).style.display = "none";
  395. }
  396. function formatFontName(fontname, n, selected) {
  397. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('fontName', false, fontname);
  398. document.getElementById('fontpicker' + n).style.display = "none";
  399. }
  400. function formatSpecialChar(charname, n, selected) {
  401. insertHTML(charname, n);
  402. document.getElementById('specialpicker' + n).style.display = "none";
  403. }
  404. function formatHeader(headername, n, selected) {
  405. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('formatBlock', false, '<'+headername+'>');
  406. document.getElementById('headerpicker' + n).style.display = "none";
  407. }
  408. function formatText(id, n, selected) {
  409. if(mode==0&&id!='htmlmode') {
  410. alert(editor_lng1);
  411. } else {
  412. // When user clicks button make sure it always targets correct textarea
  413. document.getElementById("wysiwyg" + n).contentWindow.focus();
  414. if(id=="upsize") {
  415. var currentFontSize = document.getElementById("wysiwyg"+n).contentWindow.document.queryCommandValue("FontSize");
  416. if(currentFontSize == ''||!currentFontSize) currentFontSize = 3; // fudge for FF
  417. if(currentFontSize < 7) {
  418. var newFontSize = parseInt(currentFontSize) + 1;
  419. } else {
  420. var newFontSize = currentFontSize;
  421. }
  422. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, newFontSize);
  423. }
  424. else if(id=="downsize") {
  425. var currentFontSize = document.getElementById("wysiwyg"+n).contentWindow.document.queryCommandValue("FontSize");
  426. if(currentFontSize > 1) {
  427. var newFontSize = currentFontSize - 1;
  428. } else {
  429. var newFontSize = currentFontSize;
  430. }
  431. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, newFontSize);
  432. }
  433. else if(id=="forecolor"){
  434. if(document.getElementById('colorpicker' + n).style.display == ""){
  435. document.getElementById('colorpicker' + n).style.display = "none";
  436. } else {
  437. document.getElementById('colorpicker' + n).style.display = "";
  438. }
  439. }
  440. else if(id=="backcolor"){
  441. if(document.getElementById('colorbackpicker' + n).style.display == ""){
  442. document.getElementById('colorbackpicker' + n).style.display = "none";
  443. } else {
  444. document.getElementById('colorbackpicker' + n).style.display = "";
  445. }
  446. }
  447. else if(id=="font"){
  448. if(document.getElementById('fontpicker' + n).style.display == ""){
  449. document.getElementById('fontpicker' + n).style.display = "none";
  450. } else {
  451. document.getElementById('fontpicker' + n).style.display = "";
  452. }
  453. }
  454. else if(id=="specialchar"){
  455. if(document.getElementById('specialpicker' + n).style.display == ""){
  456. document.getElementById('specialpicker' + n).style.display = "none";
  457. } else {
  458. document.getElementById('specialpicker' + n).style.display = "";
  459. }
  460. }
  461. else if(id=="headers"){
  462. if(document.getElementById('headerpicker' + n).style.display == ""){
  463. document.getElementById('headerpicker' + n).style.display = "none";
  464. } else {
  465. document.getElementById('headerpicker' + n).style.display = "";
  466. }
  467. }
  468. else if(id=="htmlmode"){
  469. var getDoc = document.getElementById("wysiwyg" + n).contentWindow.document;
  470. if(mode == 1) {
  471. if(navigator.appName == "Microsoft Internet Explorer"||browserName == "Opera") {
  472. var iHTML = getDoc.body.innerHTML;
  473. getDoc.body.innerText = iHTML;
  474. } else {
  475. var html = document.createTextNode(getDoc.body.innerHTML);
  476. getDoc.body.innerHTML = "";
  477. getDoc.body.appendChild(html);
  478. }
  479. getDoc.body.style.fontSize = "12px";
  480. getDoc.body.style.fontFamily = "Courier New";
  481. mode = 0;
  482. } else {
  483. if(navigator.appName == "Microsoft Internet Explorer"||browserName == "Opera") {
  484. var iText = getDoc.body.innerText;
  485. getDoc.body.innerHTML = iText;
  486. } else {
  487. var html = getDoc.body.ownerDocument.createRange();
  488. html.selectNodeContents(getDoc.body);
  489. getDoc.body.innerHTML = html.toString();
  490. }
  491. mode = 1;
  492. }
  493. }
  494. else if(id=="help"){
  495. if(document.getElementById('helpbox' + n).style.display == ""){
  496. document.getElementById('helpbox' + n).style.display = "none";
  497. } else {
  498. document.getElementById('helpbox' + n).style.display = "";
  499. }
  500. }
  501. else if(id=="link"){
  502. // var browserName = navigator.appName;
  503. if (browserName == "Microsoft Internet Explorer") {
  504. var target = confirm('Should this link open in a new window?\n\nOK = Open in NEW Window\nCancel = Open in THIS window');
  505. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand('createLink',true,' ');
  506. if(target == true)
  507. {
  508. document.getElementById("wysiwyg" + n).contentWindow.document.selection.createRange().parentElement().target="_blank";
  509. }
  510. } else {
  511. insertLink(n);
  512. }
  513. }
  514. else if(id=="insertimage") {
  515. // var browserName = navigator.appName;
  516. if (browserName == "Microsoft Internet Explorer") {
  517. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, true, null);
  518. } else {
  519. insertImage(n);
  520. }
  521. }
  522. else {
  523. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, false, null);
  524. }
  525. }
  526. }
  527. function insertHTML(html, n) {
  528. // var browserName = navigator.appName;
  529. if (browserName == "Microsoft Internet Explorer") {
  530. document.getElementById('wysiwyg' + n).contentWindow.document.selection.createRange().pasteHTML(html);
  531. }
  532. else {
  533. var div = document.getElementById('wysiwyg' + n).contentWindow.document.createElement("span");
  534. div.innerHTML = html;
  535. var node = insertNodeAtSelection(div, n);
  536. }
  537. }
  538. function insertNodeAtSelection(insertNode, n) {
  539. // get current selection
  540. var sel = document.getElementById('wysiwyg' + n).contentWindow.getSelection();
  541. // get the first range of the selection (there's almost always only one range)
  542. var range = sel.getRangeAt(0);
  543. // deselect everything
  544. sel.removeAllRanges();
  545. // remove content of current selection from document
  546. range.deleteContents();
  547. // get location of current selection
  548. var container = range.startContainer;
  549. var pos = range.startOffset;
  550. // make a new range for the new selection
  551. range = document.createRange();
  552. if (container.nodeType==3 && insertNode.nodeType==3) {
  553. // if we insert text in a textnode, do optimized insertion
  554. container.insertData(pos, insertNode.nodeValue);
  555. // put cursor after inserted text
  556. range.setEnd(container, pos+insertNode.length);
  557. range.setStart(container, pos+insertNode.length);
  558. }
  559. else {
  560. var afterNode;
  561. if (container.nodeType==3) {
  562. // when inserting into a textnode we create 2 new textnodes and put the insertNode in between
  563. var textNode = container;
  564. container = textNode.parentNode;
  565. var text = textNode.nodeValue;
  566. // text before the split
  567. var textBefore = text.substr(0,pos);
  568. // text after the split
  569. var textAfter = text.substr(pos);
  570. var beforeNode = document.createTextNode(textBefore);
  571. afterNode = document.createTextNode(textAfter);
  572. // insert the 3 new nodes before the old one
  573. container.insertBefore(afterNode, textNode);
  574. container.insertBefore(insertNode, afterNode);
  575. container.insertBefore(beforeNode, insertNode);
  576. // remove the old node
  577. container.removeChild(textNode);
  578. }
  579. else {
  580. // else simply insert the node
  581. afterNode = container.childNodes[pos];
  582. container.insertBefore(insertNode, afterNode);
  583. }
  584. range.setEnd(afterNode, 0);
  585. range.setStart(afterNode, 0);
  586. }
  587. sel.addRange(range);
  588. }
  589. function updateTextArea(n) {
  590. if(xhtml_out == 1) {
  591. document.getElementById(n).value = h2x(document.getElementById("wysiwyg" + n).contentWindow.document.body);
  592. } else {
  593. document.getElementById(n).value = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML;
  594. }
  595. }
  596. function grabSelectedText(n){
  597. // var browserName = navigator.appName;
  598. var selectedText = '';
  599. // for IE
  600. if (browserName == "Microsoft Internet Explorer"||browserName == "Opera") {
  601. var theText = document.getElementById("wysiwyg" + n).contentWindow.document.selection;
  602. if(theText.type =='Text') {
  603. var newText = theText.createRange();
  604. selectedText = newText.text;
  605. }
  606. }
  607. // for Mozilla/Netscape
  608. else {
  609. var selectedText = document.getElementById("wysiwyg" + n).contentWindow.document.getSelection();
  610. }
  611. return selectedText;
  612. }