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.

703 lines
32 KiB

  1. /**
  2. * @package uForum
  3. * @file images/wyzz.js
  4. * @version $Id$
  5. * @copyright 2009(c) The Mouse Whisperer
  6. * @author The Mouse Whisperer
  7. * @modified PioDer <pioder@wp.pl>
  8. * @link http://pioder.gim2przemysl.int.pl/
  9. * @license GNU GPL v3
  10. **/
  11. // Editor Width and Height
  12. wyzzW = 600;
  13. wyzzH = 200;
  14. image_path = skin_path + 'images/';// 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","help");
  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.65"; // 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. // New code for additional browser support
  41. if (navigator.userAgent.indexOf('Safari') !=-1)
  42. {
  43. browserName = "Safari";
  44. }
  45. if (navigator.userAgent.indexOf('Chrome') !=-1)
  46. {
  47. browserName = "Chrome";
  48. }
  49. if (navigator.userAgent.indexOf('Firefox') !=-1)
  50. {
  51. browserName = "Firefox";
  52. }
  53. nlBefore = new Array("div","p","li","h1","h2","h3","h4","h5","h6","hr","ul","ol");
  54. function h2x(node,inPre) { // we will pass the node containing the Wyzz-generated html
  55. var xout = '';
  56. var i;
  57. var j;
  58. // for each child of the node
  59. for(i=0;i<node.childNodes.length;i++) {
  60. if(node.childNodes[i].parentNode && String(node.tagName).toLowerCase() != String(node.childNodes[i].parentNode.tagName).toLowerCase()) continue;
  61. // alert('Nodes: '+ node.childNodes.length);
  62. switch(node.childNodes[i].nodeType) {
  63. case 1: { // for element nodes
  64. // get tag name
  65. var tagname = String(node.childNodes[i].tagName).toLowerCase();
  66. if(tagname == '') break;
  67. if((indexOf(nlBefore,tagname)!=-1)&&(!inPre)) { // this tag needs line break before it
  68. xout += '\n';
  69. }
  70. xout += '<' + tagname;
  71. var atts = node.childNodes[i].attributes;
  72. var attvalue;
  73. for(j=0;j<atts.length;j++) { // for each attribute
  74. var attname = atts[j].nodeName.toLowerCase();
  75. if(!atts[j].specified) continue;
  76. var validatt = true;
  77. switch(attname) {
  78. case "style": attvalue = node.childNodes[i].style.cssText; break;
  79. case "class": attvalue = node.childNodes[i].className; break;
  80. case "name": attvalue = node.childNodes[i].name; break;
  81. default:
  82. try {
  83. attvalue = node.childNodes[i].getAttribute(attname,2);
  84. } catch(e) {
  85. validatt = false;
  86. }
  87. }
  88. if(validatt) {
  89. if(!(tagname=='li' && attname == 'value')) {
  90. xout += ' '+attname + '="' + fixatt(attvalue) + '"';
  91. }
  92. }
  93. }
  94. if(tagname == 'img' && attname == 'alt') {
  95. xout += ' alt=""';
  96. }
  97. if(node.childNodes[i].canHaveChildren||node.childNodes[i].hasChildNodes()) {
  98. xout += '>';
  99. xout += h2x(node.childNodes[i],tagname=='pre'?true:false);
  100. xout += '</' + tagname + '>';
  101. } else {
  102. if(tagname == 'style'||tagname == 'title'||tagname=='script'||tagname=='textarea'||tagname=='a') {
  103. xout += '>';
  104. var innertext;
  105. if(tagname=='script') {
  106. innertext = node.childNodes[i].text;
  107. } else {
  108. innertext = node.childNodes[i].innerHTML;
  109. }
  110. if(tagname=='style') {
  111. innertext = String(innertext).replace(/[\n]+/g,'\n');
  112. }
  113. xout += innertext + '</' + tagname + '>';
  114. } else {
  115. xout += '/>';
  116. }
  117. }
  118. break;
  119. }
  120. // else if(node.childNodes[i].nodeType == 2) { // for attribute nodes
  121. // }
  122. case 3: { // for text nodes
  123. if(!inPre) { // don't change inside a <pre> tag
  124. if(node.childNodes[i] != '\n') {
  125. xout += fixents(fixtext(node.childNodes[i].nodeValue));
  126. }
  127. } else {
  128. xout += node.childNodes[i].nodeValue;
  129. break;
  130. }
  131. }
  132. default:
  133. break;
  134. }
  135. }
  136. return xout;
  137. }
  138. function fixents(text) {
  139. var i;
  140. 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"};
  141. var new_text = '';
  142. var temp = new RegExp();
  143. temp.compile("[a]|[^a]", "g");
  144. var parts = text.match(temp);
  145. if (!parts) return text;
  146. for (i=0; i<parts.length; i++) {
  147. var c_code = parseInt(parts[i].charCodeAt());
  148. if (ents[c_code]) {
  149. new_text += "&"+ents[c_code]+";";
  150. } else new_text += parts[i];
  151. }
  152. return new_text;
  153. }
  154. function fixtext(text) {
  155. var temptext = String(text).replace(/\&lt;/g,"#h2x_lt").replace(/\&gt;/g,"#h2x_gt");
  156. temptext = temptext.replace(/\n{2,}/g,"\n").replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\u00A0/g,"&nbsp;");
  157. return temptext.replace(/#h2x_lt/g,"&alt;").replace(/#h2x_gt/g,"&gt;");
  158. }
  159. function fixatt(text) {
  160. var temptext = String(text).replace(/\&lt;/g,"#h2x_lt").replace(/\&gt;/g,"#h2x_gt");
  161. temptext = temptext.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
  162. return temptext.replace(/#h2x_lt/g,"&alt;").replace(/#h2x_gt/g,"&gt;");
  163. }
  164. function indexOf(thisarray, value)
  165. {
  166. var i;
  167. for (i=0; i < thisarray.length; i++) {
  168. if (thisarray[i] == value) {
  169. return i;
  170. }
  171. }
  172. return -1;
  173. }
  174. // Color picker - here we make an array of all websafe colors
  175. // If you want to limit the colors available to users (e.g. to fit in with
  176. // a site design) then use a restricted array of colors
  177. // e.g. var buttonColors = new Array("336699","66abff", .... etc
  178. var buttonColors = new Array(216);
  179. // Colors - replace this function with your own if you have special requirements for colors
  180. function getColorArray() {
  181. // Color code table
  182. c = new Array('00', '33', '66', '99', 'cc', 'ff');
  183. var count = 0;
  184. // Iterate red
  185. for (r = 0; r < 6; r++)
  186. {
  187. // Iterate green
  188. for (g = 0; g < 6; g++)
  189. {
  190. // Iterate blue
  191. for (b = 0; b < 6; b++)
  192. {
  193. // Get RGB color
  194. buttonColors[count] = c[r] + c[g] + c[b];
  195. count++;
  196. }
  197. }
  198. }
  199. }
  200. getColorArray();
  201. /* Emulates insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() three functions
  202. so they work with Netscape 6/Mozilla - By Thor Larholm me@jscript.dk */
  203. if(typeof HTMLElement!='undefined'){
  204. if(typeof HTMLElement.insertAdjacentHTML=='undefined'){
  205. HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
  206. switch(where){
  207. case 'beforeBegin':
  208. this.parentNode.insertBefore(parsedNode,this);
  209. break;
  210. case 'afterBegin':
  211. this.insertBefore(parsedNode,this.firstChild);
  212. break;
  213. case 'beforeEnd':
  214. this.appendChild(parsedNode);
  215. break;
  216. case 'afterEnd':
  217. if(this.nextSibling){
  218. this.parentNode.insertBefore(parsedNode,this.nextSibling);
  219. }else{
  220. this.parentNode.appendChild(parsedNode);
  221. }
  222. break;
  223. }
  224. };
  225. }
  226. if(typeof HTMLElement.insertAdjacentHTML=='undefined'){
  227. HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){
  228. var r=this.ownerDocument.createRange();
  229. r.setStartBefore(this);
  230. var parsedHTML=r.createContextualFragment(htmlStr);
  231. this.insertAdjacentElement(where,parsedHTML);
  232. };
  233. }
  234. if(typeof HTMLElement.insertAdjacentText=='undefined'){
  235. HTMLElement.prototype.insertAdjacentText=function(where,txtStr){
  236. var parsedText=document.createTextNode(txtStr);
  237. this.insertAdjacentElement(where,parsedText);
  238. };
  239. }
  240. }
  241. function closeColorPicker(thisid) {
  242. document.getElementById(thisid).style.display = "none";
  243. }
  244. // the hyperlink dialog
  245. function insertLink(n) {
  246. var newWindow = 'blank';
  247. var linkurl = '';
  248. var linktitle = '';
  249. var targetText = grabSelectedText(n);
  250. var linkurl = prompt(editor_lng2);
  251. var linktitle = prompt(editor_lng3);
  252. if(newWindow==''||linkurl==''||linktitle=='') {
  253. alert();
  254. insertLink(n);
  255. } else {
  256. var hyperLink = '<a href="' + linkurl + '" target="_' + newWindow + '" title="' + linktitle + '" class="fsmall">' + linktitle + '</a>';
  257. insertHTML(hyperLink, n);
  258. }
  259. }
  260. function insertImage(n) {
  261. alert(n);
  262. var imgurl = prompt(editor_lng4);
  263. var imgtitle = 'image';
  264. var theImage = '<img src="' + imgurl + '" title="' + imgtitle + '" alt="' + imgtitle + '" />';
  265. insertHTML(theImage, n); }
  266. function insertSmile(imgurl, imgtitle) {
  267. if(mode==0) {
  268. alert(editor_lng1);
  269. } else {
  270. var n = 'textedit';
  271. var theImage = '<img src="' + imgurl + '" title="' + imgtitle + '" alt="' + imgtitle + '" >';
  272. insertHTML(theImage, n); } }
  273. function make_wyzz(textareaID) {
  274. // Hide the textarea
  275. document.getElementById(textareaID).style.display = 'none';
  276. // get textareaID
  277. var n = textareaID;
  278. // Toolbars width is 2 pixels wider than the editor
  279. toolbarWidth = parseFloat(wyzzW) + 2;
  280. var toolbar = '';
  281. // We only generate toolbar 1 if toolbarCount is set to 2
  282. if(toolbarCount == 2) {
  283. // Generate WYSIWYG toolbar
  284. toolbar = '<table cellpadding="0" cellspacing="0" border="0" class="toolbar" style="width:' + toolbarWidth + 'px;"><tr>';
  285. // Output buttons for toolbar
  286. var colNumbers = 0;
  287. for (btn in buttonName) {
  288. colNumbers ++;
  289. if(buttonName[btn] == "separator") {
  290. toolbar += '<td class="separator">&nbsp;</td>';
  291. } else {
  292. 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>';
  293. }
  294. }
  295. toolbar += '<td>&nbsp;</td></tr></table>';
  296. }
  297. // Generate WYSIWYG toolbar2
  298. var toolbar2 = '<table cellpadding="0" cellspacing="0" border="0" class="toolbar" style="width:' + toolbarWidth + 'px;"><tr>';
  299. // Output buttons for toolbar2
  300. var colNumbers = 0;
  301. for (btn in buttonName2) {
  302. colNumbers ++;
  303. if(buttonName2[btn] == "separator") {
  304. toolbar2 += '<td class="separator">&nbsp;</td>';
  305. } else {
  306. 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>';
  307. }
  308. }
  309. toolbar2 += '<td>&nbsp;</td></tr>';
  310. // the foreground color picker
  311. var swatchcount = 0;
  312. toolbar2 += '<tr><td colspan=' + colNumbers + '>';
  313. toolbar2 += '<div id="colorpicker' + n + '" class="colorpicker" style="display:none">';
  314. for (clr in buttonColors) {
  315. toolbar2 += '<a href="#" title="#' + buttonColors[clr] + '" alt="#' + buttonColors[clr] + '" "class="colorButton" onClick="formatTextColor(\'' + buttonColors[clr] + '\',\'' + n + '\');" style="background: #' + buttonColors[clr] + '">&nbsp;</a>';
  316. swatchcount++;
  317. if(swatchcount%18==0) {
  318. toolbar2 += '<br>';
  319. }
  320. }
  321. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'colorpicker' + n + '\')"></div>';
  322. // the background color picker
  323. toolbar2 += '<div id="colorbackpicker' + n + '" class="colorpicker" style="display:none">';
  324. for (clr in buttonColors) {
  325. toolbar2 += '<a href="#" title="#' + buttonColors[clr] + '" alt="#' + buttonColors[clr] + '" class="colorButton" onClick="formatBackColor(\'' + buttonColors[clr] + '\',\'' + n + '\');" style="background: #' + buttonColors[clr] + '">&nbsp;</a>';
  326. swatchcount++;
  327. if(swatchcount%18==0) {
  328. toolbar2 += '<br>';
  329. }
  330. }
  331. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'colorbackpicker' + n + '\')"></div>';
  332. // the font picker
  333. toolbar2 += '<div id="fontpicker' + n + '" class="fontpicker" style="display:none">';
  334. for (fnt in myFonts) {
  335. 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>';
  336. toolbar2 += '<br>';
  337. }
  338. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'fontpicker' + n + '\')"></div>';
  339. // the special character picker
  340. toolbar2 += '<div id="specialpicker' + n + '" class="specialpicker" style="display:none"><table><tr>';
  341. var charcount = 0;
  342. for (chr in specialChars) {
  343. toolbar2 += '<td><a href="#" onClick="formatSpecialChar(\'' + specialChars[chr] + '\',\'' + n + '\');">' + specialChars[chr] + '</a>&nbsp;</td>';
  344. charcount++;
  345. if(charcount%10==0) {
  346. toolbar2 += '</tr><tr>';
  347. }
  348. }
  349. toolbar2 += '</tr></table><br><img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'specialpicker' + n + '\')"></div>';
  350. // the header picker
  351. toolbar2 += '<div id="headerpicker' + n + '" class="headerpicker" style="display:none">';
  352. for (hdr in Headers) {
  353. 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>';
  354. toolbar2 += '<br>';
  355. }
  356. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'headerpicker' + n + '\')"></div>';
  357. // Add extra popups here
  358. // The help/about box
  359. // The copyright and link must remain unaltered
  360. toolbar2 += '<div id="helpbox' + n + '" class="helpbox" style="display:none">';
  361. toolbar2 += '<div class="help"><h4>Wyzz v' + version + '</h4><br>Running on ' + browserName + '<br>&copy; 2009 <a href="http://www.wyzz.info" target=_blank>www.wyzz.info</a><br><br></div>';
  362. toolbar2 += '<img class="closebutton" src="' + image_path + 'wyzz/close.gif" border=0 onclick="closeColorPicker(\'helpbox' + n + '\')"></div></td></tr></table>';
  363. // Create iframe for editor
  364. 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'
  365. + '<iframe frameborder="0" id="wysiwyg' + n + '"></iframe>\n'
  366. + '</td></tr></table>\n';
  367. // Insert toolbar after the textArea
  368. document.getElementById(n).insertAdjacentHTML("afterEnd", toolbar + toolbar2 + iframe);
  369. // Give the iframe the required height and width
  370. document.getElementById("wysiwyg" + n).style.height = wyzzH + "px";
  371. document.getElementById("wysiwyg" + n).style.width = wyzzW + "px";
  372. // Pass the textarea's existing text into the editor
  373. var content = document.getElementById(n).value;
  374. var doc = document.getElementById("wysiwyg" + n).contentWindow.document;
  375. // Write the textarea's content into the iframe
  376. doc.open();
  377. if (browserName == "Microsoft Internet Explorer") {
  378. doc.write('<link rel="stylesheet" media="screen" type="text/css" href="' + editstyle + '"/>' + content);
  379. } else {
  380. doc.write('<html><head><link rel="stylesheet" type="text/css" href="' + editstyle + '"/></head><body>' + content + '<br /></body></html>');
  381. }
  382. doc.close();
  383. if (browserName == "Microsoft Internet Explorer") {
  384. // Make the iframe editable
  385. doc.body.contentEditable = true;
  386. } else {
  387. // Make the iframe editable
  388. doc.designMode = "on";
  389. }
  390. // Update the textarea with content in WYSIWYG when user submits form
  391. if (browserName == "Microsoft Internet Explorer"||browserName == "Opera") {
  392. for (var idx=0; idx < document.forms.length; idx++) {
  393. document.forms[idx].attachEvent('onsubmit', function() { updateTextArea(n); });
  394. }
  395. } else {
  396. for (var idx=0; idx < document.forms.length; idx++) {
  397. document.forms[idx].addEventListener('submit',function OnSumbmit() { updateTextArea(n); }, true);
  398. }
  399. }
  400. }
  401. function formatTextColor(color, n, selected) {
  402. if (browserName == "Microsoft Internet Explorer"||browserName == "Chrome") { color = '#' + color; }
  403. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('forecolor', false, color);
  404. document.getElementById('colorpicker' + n).style.display = "none";
  405. }
  406. function formatBackColor(color, n, selected) {
  407. if (browserName == "Microsoft Internet Explorer"||browserName == "Chrome") { color = '#' + color; }
  408. if (browserName == "Microsoft Internet Explorer") {
  409. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('backcolor', false, color);
  410. } else {
  411. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('hilitecolor', false, color);
  412. }
  413. document.getElementById('colorbackpicker' + n).style.display = "none";
  414. }
  415. function formatFontName(fontname, n, selected) {
  416. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('fontName', false, fontname);
  417. document.getElementById('fontpicker' + n).style.display = "none";
  418. }
  419. function formatSpecialChar(charname, n, selected) {
  420. insertHTML(charname, n);
  421. document.getElementById('specialpicker' + n).style.display = "none";
  422. }
  423. function formatHeader(headername, n, selected) {
  424. document.getElementById('wysiwyg' + n).contentWindow.document.execCommand('formatBlock', false, '<'+headername+'>');
  425. document.getElementById('headerpicker' + n).style.display = "none";
  426. }
  427. function formatText(id, n, selected) {
  428. if(mode==0&&id!='htmlmode') {
  429. alert(editor_lng1);
  430. } else {
  431. // When user clicks button make sure it always targets correct textarea
  432. document.getElementById("wysiwyg" + n).contentWindow.focus();
  433. if(id=="upsize") {
  434. var currentFontSize = document.getElementById("wysiwyg"+n).contentWindow.document.queryCommandValue("FontSize");
  435. if(currentFontSize == ''||!currentFontSize) currentFontSize = 3; // fudge for FF
  436. if(currentFontSize < 7) {
  437. var newFontSize = parseInt(currentFontSize) + 1;
  438. } else {
  439. var newFontSize = currentFontSize;
  440. }
  441. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, newFontSize);
  442. }
  443. else if(id=="downsize") {
  444. var currentFontSize = document.getElementById("wysiwyg"+n).contentWindow.document.queryCommandValue("FontSize");
  445. if(currentFontSize > 1) {
  446. var newFontSize = currentFontSize - 1;
  447. } else {
  448. var newFontSize = currentFontSize;
  449. }
  450. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand("FontSize", false, newFontSize);
  451. }
  452. else if(id=="forecolor"){
  453. if(document.getElementById('colorpicker' + n).style.display == ""){
  454. document.getElementById('colorpicker' + n).style.display = "none";
  455. } else {
  456. document.getElementById('colorpicker' + n).style.display = "";
  457. }
  458. }
  459. else if(id=="backcolor"){
  460. if(document.getElementById('colorbackpicker' + n).style.display == ""){
  461. document.getElementById('colorbackpicker' + n).style.display = "none";
  462. } else {
  463. document.getElementById('colorbackpicker' + n).style.display = "";
  464. }
  465. }
  466. else if(id=="font"){
  467. if(document.getElementById('fontpicker' + n).style.display == ""){
  468. document.getElementById('fontpicker' + n).style.display = "none";
  469. } else {
  470. document.getElementById('fontpicker' + n).style.display = "";
  471. }
  472. }
  473. else if(id=="specialchar"){
  474. if(document.getElementById('specialpicker' + n).style.display == ""){
  475. document.getElementById('specialpicker' + n).style.display = "none";
  476. } else {
  477. document.getElementById('specialpicker' + n).style.display = "";
  478. }
  479. }
  480. else if(id=="headers"){
  481. if(document.getElementById('headerpicker' + n).style.display == ""){
  482. document.getElementById('headerpicker' + n).style.display = "none";
  483. } else {
  484. document.getElementById('headerpicker' + n).style.display = "";
  485. }
  486. }
  487. else if(id=="htmlmode"){
  488. var getDoc = document.getElementById("wysiwyg" + n).contentWindow.document;
  489. if(mode == 1) {
  490. if(navigator.appName == "Microsoft Internet Explorer"||browserName == "Opera") {
  491. var iHTML = getDoc.body.innerHTML;
  492. getDoc.body.innerText = iHTML;
  493. } else {
  494. var html = document.createTextNode(getDoc.body.innerHTML);
  495. getDoc.body.innerHTML = "";
  496. getDoc.body.appendChild(html);
  497. }
  498. getDoc.body.style.fontSize = "12px";
  499. getDoc.body.style.fontFamily = "Courier New";
  500. mode = 0;
  501. } else {
  502. if(navigator.appName == "Microsoft Internet Explorer"||browserName == "Opera") {
  503. var iText = getDoc.body.innerText;
  504. getDoc.body.innerHTML = iText;
  505. } else {
  506. var html = getDoc.body.ownerDocument.createRange();
  507. html.selectNodeContents(getDoc.body);
  508. getDoc.body.innerHTML = html.toString();
  509. }
  510. mode = 1;
  511. }
  512. }
  513. else if(id=="help"){
  514. if(document.getElementById('helpbox' + n).style.display == ""){
  515. document.getElementById('helpbox' + n).style.display = "none";
  516. } else {
  517. document.getElementById('helpbox' + n).style.display = "";
  518. }
  519. }
  520. else if(id=="link"){
  521. if (browserName == "Microsoft Internet Explorer") {
  522. var target = confirm('Should this link open in a new window?\n\nOK = Open in NEW Window\nCancel = Open in THIS window');
  523. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand('createLink',true,' ');
  524. if(target == true)
  525. {
  526. document.getElementById("wysiwyg" + n).contentWindow.document.selection.createRange().parentElement().target="_blank";
  527. }
  528. } else {
  529. insertLink(n);
  530. }
  531. }
  532. else if(id=="insertimage") {
  533. if (browserName == "Microsoft Internet Explorer") {
  534. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, true, null);
  535. } else {
  536. insertImage(n);
  537. }
  538. }
  539. else {
  540. document.getElementById("wysiwyg" + n).contentWindow.document.execCommand(id, false, null);
  541. }
  542. }
  543. }
  544. function insertHTML(html, n) {
  545. if (browserName == "Microsoft Internet Explorer") {
  546. document.getElementById('wysiwyg' + n).contentWindow.document.selection.createRange().pasteHTML(html);
  547. }
  548. else {
  549. var div = document.getElementById('wysiwyg' + n).contentWindow.document.createElement("span");
  550. div.innerHTML = html;
  551. var node = insertNodeAtSelection(div, n);
  552. }
  553. }
  554. function insertNodeAtSelection(insertNode, n) {
  555. // get current selection
  556. var sel = document.getElementById('wysiwyg' + n).contentWindow.getSelection();
  557. // get the first range of the selection (there's almost always only one range)
  558. var range = sel.getRangeAt(0);
  559. // deselect everything
  560. sel.removeAllRanges();
  561. // remove content of current selection from document
  562. range.deleteContents();
  563. // get location of current selection
  564. var container = range.startContainer;
  565. var pos = range.startOffset;
  566. // make a new range for the new selection
  567. range = document.createRange();
  568. if (container.nodeType==3 && insertNode.nodeType==3) {
  569. // if we insert text in a textnode, do optimized insertion
  570. container.insertData(pos, insertNode.nodeValue);
  571. // put cursor after inserted text
  572. range.setEnd(container, pos+insertNode.length);
  573. range.setStart(container, pos+insertNode.length);
  574. } else {
  575. var afterNode;
  576. if (container.nodeType==3) {
  577. // when inserting into a textnode we create 2 new textnodes and put the insertNode in between
  578. var textNode = container;
  579. container = textNode.parentNode;
  580. var text = textNode.nodeValue;
  581. // text before the split
  582. var textBefore = text.substr(0,pos);
  583. // text after the split
  584. var textAfter = text.substr(pos);
  585. var beforeNode = document.createTextNode(textBefore);
  586. afterNode = document.createTextNode(textAfter);
  587. // insert the 3 new nodes before the old one
  588. container.insertBefore(afterNode, textNode);
  589. container.insertBefore(insertNode, afterNode);
  590. container.insertBefore(beforeNode, insertNode);
  591. // remove the old node
  592. container.removeChild(textNode);
  593. } else {
  594. // else simply insert the node
  595. afterNode = container.childNodes[pos];
  596. container.insertBefore(insertNode, afterNode);
  597. }
  598. range.setEnd(afterNode, 0);
  599. range.setStart(afterNode, 0);
  600. }
  601. sel.addRange(range);
  602. }
  603. function updateTextArea(n) {
  604. if(xhtml_out == 1) {
  605. document.getElementById(n).value = h2x(document.getElementById("wysiwyg" + n).contentWindow.document.body);
  606. } else {
  607. document.getElementById(n).value = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML;
  608. }
  609. }
  610. function grabSelectedText(n){
  611. var selectedText = '';
  612. // for IE
  613. if (browserName == "Microsoft Internet Explorer"||browserName == "Opera") {
  614. var theText = document.getElementById("wysiwyg" + n).contentWindow.document.selection;
  615. if(theText.type =='Text') {
  616. var newText = theText.createRange();
  617. selectedText = newText.text;
  618. }
  619. }
  620. // for Mozilla/Netscape
  621. else {
  622. var selectedText = document.getElementById("wysiwyg" + n).contentWindow.document.getSelection();
  623. }
  624. return selectedText;
  625. }