editor.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. // *** smc_Editor class.
  2. function smc_Editor(oOptions)
  3. {
  4. this.opt = oOptions;
  5. // Create some links to the editor object.
  6. this.oTextHandle = null;
  7. this.sCurrentText = 'sText' in this.opt ? this.opt.sText : '';
  8. // How big?
  9. this.sEditWidth = 'sEditWidth' in this.opt ? this.opt.sEditWidth : '70%';
  10. this.sEditHeight = 'sEditHeight' in this.opt ? this.opt.sEditHeight : '150px';
  11. this.showDebug = false;
  12. this.bRichTextEnabled = 'bWysiwyg' in this.opt && this.opt.bWysiwyg;
  13. // This doesn't work on Opera as they cannot restore focus after clicking a BBC button.
  14. this.bRichTextPossible = !this.opt.bRichEditOff && ((is_ie5up && !is_ie50) || is_ff || is_opera95up || is_safari || is_chrome) && !(is_iphone || is_android);
  15. this.oFrameHandle = null;
  16. this.oFrameDocument = null;
  17. this.oFrameWindow = null;
  18. // These hold the breadcrumb.
  19. this.oBreadHandle = null;
  20. this.oResizerElement = null;
  21. // Kinda holds all the useful stuff.
  22. this.aKeyboardShortcuts = new Array();
  23. // This tracks the cursor position on IE to avoid refocus problems.
  24. this.cursorX = 0;
  25. this.cursorY = 0;
  26. // This is all the elements that can have a simple execCommand.
  27. this.oSimpleExec = {
  28. b: 'bold',
  29. u: 'underline',
  30. i: 'italic',
  31. s: 'strikethrough',
  32. left: 'justifyleft',
  33. center: 'justifycenter',
  34. right: 'justifyright',
  35. hr: 'inserthorizontalrule',
  36. list: 'insertunorderedlist',
  37. orderlist: 'insertorderedlist',
  38. sub: 'subscript',
  39. sup: 'superscript',
  40. indent: 'indent',
  41. outdent: 'outdent'
  42. }
  43. // Codes to call a private function
  44. this.oSmfExec = {
  45. unformat: 'removeFormatting',
  46. toggle: 'toggleView'
  47. }
  48. // Any special breadcrumb mappings to ensure we show a consistant tag name.
  49. this.breadCrumbNameTags = {
  50. strike: 's',
  51. strong: 'b',
  52. em: 'i'
  53. }
  54. this.aBreadCrumbNameStyles = [
  55. {
  56. sStyleType: 'text-decoration',
  57. sStyleValue: 'underline',
  58. sBbcTag: 'u'
  59. },
  60. {
  61. sStyleType: 'text-decoration',
  62. sStyleValue: 'line-through',
  63. sBbcTag: 's'
  64. },
  65. {
  66. sStyleType: 'text-align',
  67. sStyleValue: 'left',
  68. sBbcTag: 'left'
  69. },
  70. {
  71. sStyleType: 'text-align',
  72. sStyleValue: 'center',
  73. sBbcTag: 'center'
  74. },
  75. {
  76. sStyleType: 'text-align',
  77. sStyleValue: 'right',
  78. sBbcTag: 'right'
  79. },
  80. {
  81. sStyleType: 'font-weight',
  82. sStyleValue: 'bold',
  83. sBbcTag: 'b'
  84. },
  85. {
  86. sStyleType: 'font-style',
  87. sStyleValue: 'italic',
  88. sBbcTag: 'i'
  89. }
  90. ];
  91. // All the fonts in the world.
  92. this.aFontFaces = [
  93. 'Arial',
  94. 'Arial Black',
  95. 'Impact',
  96. 'Verdana',
  97. 'Times New Roman',
  98. 'Georgia',
  99. 'Andale Mono',
  100. 'Trebuchet MS',
  101. 'Comic Sans MS'
  102. ];
  103. // Font maps (HTML => CSS size)
  104. this.aFontSizes = [
  105. 0,
  106. 8,
  107. 10,
  108. 12,
  109. 14,
  110. 18,
  111. 24,
  112. 36
  113. ];
  114. // Color maps! (hex => name)
  115. this.oFontColors = {
  116. black: '#000000',
  117. red: '#ff0000',
  118. yellow: '#ffff00',
  119. pink: '#ffc0cb',
  120. green: '#008000',
  121. orange: '#ffa500',
  122. purple: '#800080',
  123. blue: '#0000ff',
  124. beige: '#f5f5dc',
  125. brown: '#a52a2a',
  126. teal: '#008080',
  127. navy: '#000080',
  128. maroon: '#800000',
  129. limegreen: '#32cd32'
  130. }
  131. this.sFormId = 'sFormId' in this.opt ? this.opt.sFormId : 'postmodify';
  132. this.iArrayPosition = smf_editorArray.length;
  133. // Current resize state.
  134. this.osmc_EditorCurrentResize = {};
  135. this.init();
  136. }
  137. smc_Editor.prototype.init = function()
  138. {
  139. // Define the event wrapper functions.
  140. var oCaller = this;
  141. this.aEventWrappers = {
  142. editorKeyUp: function(oEvent) {return oCaller.editorKeyUp(oEvent);},
  143. shortcutCheck: function(oEvent) {return oCaller.shortcutCheck(oEvent);},
  144. editorBlur: function(oEvent) {return oCaller.editorBlur(oEvent);},
  145. editorFocus: function(oEvent) {return oCaller.editorFocus(oEvent);},
  146. startResize: function(oEvent) {return oCaller.startResize(oEvent);},
  147. resizeOverDocument: function(oEvent) {return oCaller.resizeOverDocument(oEvent);},
  148. endResize: function(oEvent) {return oCaller.endResize(oEvent);},
  149. resizeOverIframe: function(oEvent) {return oCaller.resizeOverIframe(oEvent);}
  150. };
  151. // Set the textHandle.
  152. this.oTextHandle = document.getElementById(this.opt.sUniqueId);
  153. // Ensure the currentText is set correctly depending on the mode.
  154. if (this.sCurrentText == '' && !this.bRichTextEnabled)
  155. this.sCurrentText = getInnerHTML(this.oTextHandle).php_unhtmlspecialchars();
  156. // Only try to do this if rich text is supported.
  157. if (this.bRichTextPossible)
  158. {
  159. // Make the iframe itself, stick it next to the current text area, and give it an ID.
  160. this.oFrameHandle = document.createElement('iframe');
  161. this.oFrameHandle.src = 'about:blank';
  162. this.oFrameHandle.id = 'html_' + this.opt.sUniqueId;
  163. this.oFrameHandle.className = 'rich_editor_frame';
  164. this.oFrameHandle.style.display = 'none';
  165. this.oFrameHandle.style.margin = '0px';
  166. this.oFrameHandle.tabIndex = this.oTextHandle.tabIndex;
  167. this.oTextHandle.parentNode.appendChild(this.oFrameHandle);
  168. // Create some handy shortcuts.
  169. this.oFrameDocument = this.oFrameHandle.contentDocument ? this.oFrameHandle.contentDocument : ('contentWindow' in this.oFrameHandle ? this.oFrameHandle.contentWindow.document : this.oFrameHandle.document);
  170. this.oFrameWindow = 'contentWindow' in this.oFrameHandle ? this.oFrameHandle.contentWindow : this.oFrameHandle.document.parentWindow;
  171. // Create the debug window... and stick this under the main frame - make it invisible by default.
  172. this.oBreadHandle = document.createElement('div');
  173. this.oBreadHandle.id = 'bread_' . uid;
  174. this.oBreadHandle.style.visibility = 'visible';
  175. this.oBreadHandle.style.display = 'none';
  176. this.oFrameHandle.parentNode.appendChild(this.oBreadHandle);
  177. // Size the iframe dimensions to something sensible.
  178. this.oFrameHandle.style.width = this.sEditWidth;
  179. this.oFrameHandle.style.height = this.sEditHeight;
  180. this.oFrameHandle.style.visibility = 'visible';
  181. // Only bother formatting the debug window if debug is enabled.
  182. if (this.showDebug)
  183. {
  184. this.oBreadHandle.style.width = this.sEditWidth;
  185. this.oBreadHandle.style.height = '20px';
  186. this.oBreadHandle.className = 'windowbg2';
  187. this.oBreadHandle.style.border = '1px black solid';
  188. this.oBreadHandle.style.display = '';
  189. }
  190. // Populate the editor with nothing by default.
  191. if (!is_opera95up)
  192. {
  193. this.oFrameDocument.open();
  194. this.oFrameDocument.write('');
  195. this.oFrameDocument.close();
  196. }
  197. // Right to left mode?
  198. if (this.opt.bRTL)
  199. {
  200. this.oFrameDocument.dir = "rtl";
  201. this.oFrameDocument.body.dir = "rtl";
  202. }
  203. // Mark it as editable...
  204. if (this.oFrameDocument.body.contentEditable)
  205. this.oFrameDocument.body.contentEditable = true;
  206. else
  207. {
  208. this.oFrameHandle.style.display = '';
  209. this.oFrameDocument.designMode = 'on';
  210. this.oFrameHandle.style.display = 'none';
  211. }
  212. // Now we need to try and style the editor - internet explorer allows us to do the whole lot.
  213. if (document.styleSheets['editor_css'] || document.styleSheets['editor_ie_css'])
  214. {
  215. var oMyStyle = this.oFrameDocument.createElement('style');
  216. this.oFrameDocument.documentElement.firstChild.appendChild(oMyStyle);
  217. oMyStyle.styleSheet.cssText = document.styleSheets['editor_ie_css'] ? document.styleSheets['editor_ie_css'].cssText : document.styleSheets['editor_css'].cssText;
  218. }
  219. // Otherwise we seem to have to try to rip out each of the styles one by one!
  220. else if (document.styleSheets.length)
  221. {
  222. var bFoundSomething = false;
  223. // First we need to find the right style sheet.
  224. for (var i = 0, iNumStyleSheets = document.styleSheets.length; i < iNumStyleSheets; i++)
  225. {
  226. // Start off looking for the right style sheet.
  227. if (!document.styleSheets[i].href || document.styleSheets[i].href.indexOf('editor') < 1)
  228. continue;
  229. // Firefox won't allow us to get a CSS file which ain't in the right URL.
  230. try
  231. {
  232. if (document.styleSheets[i].cssRules.length < 1)
  233. continue;
  234. }
  235. catch (e)
  236. {
  237. continue;
  238. }
  239. // Manually try to find the rich_editor class.
  240. for (var r = 0, iNumRules = document.styleSheets[i].cssRules.length; r < iNumRules; r++)
  241. {
  242. // Got the main editor?
  243. if (document.styleSheets[i].cssRules[r].selectorText == '.rich_editor')
  244. {
  245. // Set some possible styles.
  246. if (document.styleSheets[i].cssRules[r].style.color)
  247. this.oFrameDocument.body.style.color = document.styleSheets[i].cssRules[r].style.color;
  248. if (document.styleSheets[i].cssRules[r].style.backgroundColor)
  249. this.oFrameDocument.body.style.backgroundColor = document.styleSheets[i].cssRules[r].style.backgroundColor;
  250. if (document.styleSheets[i].cssRules[r].style.fontSize)
  251. this.oFrameDocument.body.style.fontSize = document.styleSheets[i].cssRules[r].style.fontSize;
  252. if (document.styleSheets[i].cssRules[r].style.fontFamily)
  253. this.oFrameDocument.body.style.fontFamily = document.styleSheets[i].cssRules[r].style.fontFamily;
  254. if (document.styleSheets[i].cssRules[r].style.border)
  255. this.oFrameDocument.body.style.border = document.styleSheets[i].cssRules[r].style.border;
  256. bFoundSomething = true;
  257. }
  258. // The frame?
  259. else if (document.styleSheets[i].cssRules[r].selectorText == '.rich_editor_frame')
  260. {
  261. if (document.styleSheets[i].cssRules[r].style.border)
  262. this.oFrameHandle.style.border = document.styleSheets[i].cssRules[r].style.border;
  263. }
  264. }
  265. }
  266. // Didn't find it?
  267. if (!bFoundSomething)
  268. {
  269. // Do something that is better than nothing.
  270. this.oFrameDocument.body.style.color = 'black';
  271. this.oFrameDocument.body.style.backgroundColor = 'white';
  272. this.oFrameDocument.body.style.fontSize = '78%';
  273. this.oFrameDocument.body.style.fontFamily = '"Verdana", "Arial", "Helvetica", "sans-serif"';
  274. this.oFrameDocument.body.style.border = 'none';
  275. this.oFrameHandle.style.border = '1px solid #808080';
  276. if (is_opera)
  277. this.oFrameDocument.body.style.height = '99%';
  278. }
  279. }
  280. // Apply the class...
  281. this.oFrameDocument.body.className = 'rich_editor';
  282. // Set the frame padding/margin inside the editor.
  283. this.oFrameDocument.body.style.padding = '1px';
  284. this.oFrameDocument.body.style.margin = '0';
  285. // Listen for input.
  286. this.oFrameDocument.instanceRef = this;
  287. this.oFrameHandle.instanceRef = this;
  288. this.oTextHandle.instanceRef = this;
  289. // Attach addEventListener for those browsers that don't support it.
  290. createEventListener(this.oFrameHandle);
  291. createEventListener(this.oFrameDocument);
  292. createEventListener(this.oTextHandle);
  293. createEventListener(window);
  294. createEventListener(document);
  295. // Attach functions to the key and mouse events.
  296. this.oFrameDocument.addEventListener('keyup', this.aEventWrappers.editorKeyUp, true);
  297. this.oFrameDocument.addEventListener('mouseup', this.aEventWrappers.editorKeyUp, true);
  298. this.oFrameDocument.addEventListener('keydown', this.aEventWrappers.shortcutCheck, true);
  299. this.oTextHandle.addEventListener('keydown', this.aEventWrappers.shortcutCheck, true);
  300. if (is_ie)
  301. {
  302. this.oFrameDocument.addEventListener('blur', this.aEventWrappers.editorBlur, true);
  303. this.oFrameDocument.addEventListener('focus', this.aEventWrappers.editorFocus, true);
  304. }
  305. // Show the iframe only if wysiwyrg is on - and hide the text area.
  306. this.oTextHandle.style.display = this.bRichTextEnabled ? 'none' : '';
  307. this.oFrameHandle.style.display = this.bRichTextEnabled ? '' : 'none';
  308. this.oBreadHandle.style.display = this.bRichTextEnabled ? '' : 'none';
  309. }
  310. // If we can't do advanced stuff then just do the basics.
  311. else
  312. {
  313. // Cannot have WYSIWYG anyway!
  314. this.bRichTextEnabled = false;
  315. // We need some of the event handlers.
  316. createEventListener(this.oTextHandle);
  317. createEventListener(window);
  318. createEventListener(document);
  319. }
  320. // Make sure we set the message mode correctly.
  321. document.getElementById(this.opt.sUniqueId + '_mode').value = this.bRichTextEnabled ? 1 : 0;
  322. // Show the resizer.
  323. if (document.getElementById(this.opt.sUniqueId + '_resizer') && (!is_opera || is_opera95up) && !(is_chrome && !this.bRichTextEnabled))
  324. {
  325. // Currently nothing is being resized...I assume!
  326. window.smf_oCurrentResizeEditor = null;
  327. this.oResizerElement = document.getElementById(this.opt.sUniqueId + '_resizer');
  328. this.oResizerElement.style.display = '';
  329. createEventListener(this.oResizerElement);
  330. this.oResizerElement.addEventListener('mousedown', this.aEventWrappers.startResize, false);
  331. }
  332. // Set the text - if WYSIWYG is enabled that is.
  333. if (this.bRichTextEnabled)
  334. {
  335. this.insertText(this.sCurrentText, true);
  336. // Better make us the focus!
  337. this.setFocus();
  338. }
  339. // Finally, register shortcuts.
  340. this.registerDefaultShortcuts();
  341. this.updateEditorControls();
  342. }
  343. // Return the current text.
  344. smc_Editor.prototype.getText = function(bPrepareEntities, bModeOverride)
  345. {
  346. var bCurMode = typeof(bModeOverride) != 'undefined' ? bModeOverride : this.bRichTextEnabled;
  347. if (!bCurMode || this.oFrameDocument == null)
  348. {
  349. var sText = this.oTextHandle.value;
  350. if (bPrepareEntities)
  351. sText = sText.replace(/</g, '#smlt#').replace(/>/g, '#smgt#').replace(/&/g, '#smamp#');
  352. }
  353. else
  354. {
  355. var sText = this.oFrameDocument.body.innerHTML;
  356. if (bPrepareEntities)
  357. sText = sText.replace(/&lt;/g, '#smlt#').replace(/&gt;/g, '#smgt#').replace(/&amp;/g, '#smamp#');
  358. }
  359. // Clean it up - including removing semi-colons.
  360. if (bPrepareEntities)
  361. sText = sText.replace(/&nbsp;/g, ' ').replace(/;/g, '#smcol#');
  362. // Return it.
  363. return sText;
  364. }
  365. // Return the current text.
  366. smc_Editor.prototype.unprotectText = function(sText)
  367. {
  368. var bCurMode = typeof(bModeOverride) != 'undefined' ? bModeOverride : this.bRichTextEnabled;
  369. // This restores smlt, smgt and smamp into boring entities, to unprotect against XML'd information like quotes.
  370. sText = sText.replace(/#smlt#/g, '&lt;').replace(/#smgt#/g, '&gt;').replace(/#smamp#/g, '&amp;');
  371. // Return it.
  372. return sText;
  373. }
  374. smc_Editor.prototype.editorKeyUp = function()
  375. {
  376. // Rebuild the breadcrumb.
  377. this.updateEditorControls();
  378. }
  379. smc_Editor.prototype.editorBlur = function()
  380. {
  381. if (!is_ie)
  382. return;
  383. // Need to do something here.
  384. }
  385. smc_Editor.prototype.editorFocus = function()
  386. {
  387. if (!is_ie)
  388. return;
  389. // Need to do something here.
  390. }
  391. // Rebuild the breadcrumb etc - and set things to the correct context.
  392. smc_Editor.prototype.updateEditorControls = function()
  393. {
  394. // Everything else is specific to HTML mode.
  395. if (!this.bRichTextEnabled)
  396. {
  397. // Set none of the buttons active.
  398. if (this.opt.oBBCBox)
  399. this.opt.oBBCBox.setActive([]);
  400. return;
  401. }
  402. var aCrumb = new Array();
  403. var aAllCrumbs = new Array();
  404. var iMaxLength = 6;
  405. // What is the current element?
  406. var oCurTag = this.getCurElement();
  407. var i = 0;
  408. while (typeof(oCurTag) == 'object' && oCurTag != null && oCurTag.nodeName.toLowerCase() != 'body' && i < iMaxLength)
  409. {
  410. aCrumb[i++] = oCurTag;
  411. oCurTag = oCurTag.parentNode;
  412. }
  413. // Now print out the tree.
  414. var sTree = '';
  415. var sCurFontName = '';
  416. var sCurFontSize = '';
  417. var sCurFontColor = '';
  418. for (var i = 0, iNumCrumbs = aCrumb.length; i < iNumCrumbs; i++)
  419. {
  420. var sCrumbName = aCrumb[i].nodeName.toLowerCase();
  421. // Does it have an alternative name?
  422. if (sCrumbName in this.breadCrumbNameTags)
  423. sCrumbName = this.breadCrumbNameTags[sCrumbName];
  424. // Don't bother with this...
  425. else if (sCrumbName == 'p')
  426. continue;
  427. // A link?
  428. else if (sCrumbName == 'a')
  429. {
  430. var sUrlInfo = aCrumb[i].getAttribute('href');
  431. sCrumbName = 'url';
  432. if (typeof(sUrlInfo) == 'string')
  433. {
  434. if (sUrlInfo.substr(0, 3) == 'ftp')
  435. sCrumbName = 'ftp';
  436. else if (sUrlInfo.substr(0, 6) == 'mailto')
  437. sCrumbName = 'email';
  438. }
  439. }
  440. else if (sCrumbName == 'span' || sCrumbName == 'div')
  441. {
  442. if (aCrumb[i].style)
  443. {
  444. for (var j = 0, iNumStyles = this.aBreadCrumbNameStyles.length; j < iNumStyles; j++)
  445. {
  446. // Do we have a font?
  447. if (aCrumb[i].style.fontFamily && aCrumb[i].style.fontFamily != '' && sCurFontName == '')
  448. {
  449. sCurFontName = aCrumb[i].style.fontFamily;
  450. sCrumbName = 'face';
  451. }
  452. // ... or a font size?
  453. if (aCrumb[i].style.fontSize && aCrumb[i].style.fontSize != '' && sCurFontSize == '')
  454. {
  455. sCurFontSize = aCrumb[i].style.fontSize;
  456. sCrumbName = 'size';
  457. }
  458. // ... even color?
  459. if (aCrumb[i].style.color && aCrumb[i].style.color != '' && sCurFontColor == '')
  460. {
  461. sCurFontColor = aCrumb[i].style.color;
  462. if (in_array(sCurFontColor, this.oFontColors))
  463. sCurFontColor = array_search(sCurFontColor, this.oFontColors);
  464. sCrumbName = 'color';
  465. }
  466. if (this.aBreadCrumbNameStyles[j].sStyleType == 'text-align' && aCrumb[i].style.textAlign && aCrumb[i].style.textAlign == this.aBreadCrumbNameStyles[j].sStyleValue)
  467. sCrumbName = this.aBreadCrumbNameStyles[j].sBbcTag;
  468. else if (this.aBreadCrumbNameStyles[j].sStyleType == 'text-decoration' && aCrumb[i].style.textDecoration && aCrumb[i].style.textDecoration == this.aBreadCrumbNameStyles[j].sStyleValue)
  469. sCrumbName = this.aBreadCrumbNameStyles[j].sBbcTag;
  470. else if (this.aBreadCrumbNameStyles[j].sStyleType == 'font-weight' && aCrumb[i].style.fontWeight && aCrumb[i].style.fontWeight == this.aBreadCrumbNameStyles[j].sStyleValue)
  471. sCrumbName = this.aBreadCrumbNameStyles[j].sBbcTag;
  472. else if (this.aBreadCrumbNameStyles[j].sStyleType == 'font-style' && aCrumb[i].style.fontStyle && aCrumb[i].style.fontStyle == this.aBreadCrumbNameStyles[j].sStyleValue)
  473. sCrumbName = this.aBreadCrumbNameStyles[j].sBbcTag;
  474. }
  475. }
  476. }
  477. // Do we have a font?
  478. else if (sCrumbName == 'font')
  479. {
  480. if (aCrumb[i].getAttribute('face') && sCurFontName == '')
  481. {
  482. sCurFontName = aCrumb[i].getAttribute('face').toLowerCase();
  483. sCrumbName = 'face';
  484. }
  485. if (aCrumb[i].getAttribute('size') && sCurFontSize == '')
  486. {
  487. sCurFontSize = aCrumb[i].getAttribute('size');
  488. sCrumbName = 'size';
  489. }
  490. if (aCrumb[i].getAttribute('color') && sCurFontColor == '')
  491. {
  492. sCurFontColor = aCrumb[i].getAttribute('color');
  493. if (in_array(sCurFontColor, this.oFontColors))
  494. sCurFontColor = array_search(sCurFontColor, this.oFontColors);
  495. sCrumbName = 'color';
  496. }
  497. // Something else - ignore.
  498. if (sCrumbName == 'font')
  499. continue;
  500. }
  501. sTree += (i != 0 ? '&nbsp;<strong>&gt;</strong>' : '') + '&nbsp;' + sCrumbName;
  502. aAllCrumbs[aAllCrumbs.length] = sCrumbName;
  503. }
  504. // Since we're in WYSIWYG state, show the toggle button as active.
  505. aAllCrumbs[aAllCrumbs.length] = 'toggle';
  506. this.opt.oBBCBox.setActive(aAllCrumbs);
  507. // Try set the font boxes correct.
  508. this.opt.oBBCBox.setSelect('sel_face', sCurFontName);
  509. this.opt.oBBCBox.setSelect('sel_size', sCurFontSize);
  510. this.opt.oBBCBox.setSelect('sel_color', sCurFontColor);
  511. if (this.showDebug)
  512. setInnerHTML(this.oBreadHandle, sTree);
  513. }
  514. // Set the HTML content to be that of the text box - if we are in wysiwyg mode.
  515. smc_Editor.prototype.doSubmit = function()
  516. {
  517. if (this.bRichTextEnabled)
  518. this.oTextHandle.value = this.oFrameDocument.body.innerHTML;
  519. }
  520. // Populate the box with text.
  521. smc_Editor.prototype.insertText = function(sText, bClear, bForceEntityReverse, iMoveCursorBack)
  522. {
  523. if (bForceEntityReverse)
  524. sText = this.unprotectText(sText);
  525. // Erase it all?
  526. if (bClear)
  527. {
  528. if (this.bRichTextEnabled)
  529. {
  530. // This includes a work around for FF to get the cursor to show!
  531. this.oFrameDocument.body.innerHTML = sText;
  532. // If FF trick the cursor into coming back!
  533. if (is_ff || is_opera)
  534. {
  535. // For some entirely unknown reason FF3 Beta 2 and some Opera versions
  536. // require this.
  537. this.oFrameDocument.body.contentEditable = false;
  538. this.oFrameDocument.designMode = 'off';
  539. this.oFrameDocument.designMode = 'on';
  540. }
  541. }
  542. else
  543. this.oTextHandle.value = sText;
  544. }
  545. else
  546. {
  547. this.setFocus();
  548. if (this.bRichTextEnabled)
  549. {
  550. // IE croaks if you have an image selected and try to insert!
  551. if ('selection' in this.oFrameDocument && this.oFrameDocument.selection.type != 'Text' && this.oFrameDocument.selection.type != 'None' && this.oFrameDocument.selection.clear)
  552. this.oFrameDocument.selection.clear();
  553. var oRange = this.getRange();
  554. if (oRange.pasteHTML)
  555. {
  556. oRange.pasteHTML(sText);
  557. // Do we want to move the cursor back at all?
  558. if (iMoveCursorBack)
  559. oRange.moveEnd('character', -iMoveCursorBack);
  560. oRange.select();
  561. }
  562. else
  563. {
  564. // If the cursor needs to be positioned, insert the last fragment first.
  565. if (typeof(iMoveCursorBack) != 'undefined' && iMoveCursorBack > 0 && sText.length > iMoveCursorBack)
  566. {
  567. var oSelection = this.getSelect(false, false);
  568. var oRange = oSelection.getRangeAt(0);
  569. oRange.insertNode(this.oFrameDocument.createTextNode(sText.substr(sText.length - iMoveCursorBack)));
  570. }
  571. this.smf_execCommand('inserthtml', false, typeof(iMoveCursorBack) == 'undefined' ? sText : sText.substr(0, sText.length - iMoveCursorBack));
  572. }
  573. }
  574. else
  575. {
  576. replaceText(sText, this.oTextHandle);
  577. }
  578. }
  579. }
  580. // Special handler for WYSIWYG.
  581. smc_Editor.prototype.smf_execCommand = function(sCommand, bUi, sValue)
  582. {
  583. return this.oFrameDocument.execCommand(sCommand, bUi, sValue);
  584. }
  585. smc_Editor.prototype.insertSmiley = function(oSmileyProperties)
  586. {
  587. // In text mode we just add it in as we always did.
  588. if (!this.bRichTextEnabled)
  589. this.insertText(' ' + oSmileyProperties.sCode);
  590. // Otherwise we need to do a whole image...
  591. else
  592. {
  593. var iUniqueSmileyId = 1000 + Math.floor(Math.random() * 100000);
  594. this.insertText('<img src="' + oSmileyProperties.sSrc + '" id="smiley_' + iUniqueSmileyId + '_' + oSmileyProperties.sSrc.replace(/^.*\//, '') + '" onresizestart="return false;" align="bottom" alt="" title="' + oSmileyProperties.sDescription.php_htmlspecialchars() + '" style="padding: 0 3px 0 3px;" />');
  595. }
  596. }
  597. smc_Editor.prototype.handleButtonClick = function (oButtonProperties)
  598. {
  599. this.setFocus();
  600. // A special SMF function?
  601. if (oButtonProperties.sCode in this.oSmfExec)
  602. this[this.oSmfExec[oButtonProperties.sCode]]();
  603. else
  604. {
  605. // In text this is easy...
  606. if (!this.bRichTextEnabled)
  607. {
  608. // Replace?
  609. if (!('sAfter' in oButtonProperties) || oButtonProperties.sAfter == null)
  610. replaceText(oButtonProperties.sBefore.replace(/\\n/g, '\n'), this.oTextHandle)
  611. // Surround!
  612. else
  613. surroundText(oButtonProperties.sBefore.replace(/\\n/g, '\n'), oButtonProperties.sAfter.replace(/\\n/g, '\n'), this.oTextHandle)
  614. }
  615. else
  616. {
  617. // Is it easy?
  618. if (oButtonProperties.sCode in this.oSimpleExec)
  619. this.smf_execCommand(this.oSimpleExec[oButtonProperties.sCode], false, null);
  620. // A link?
  621. else if (oButtonProperties.sCode == 'url' || oButtonProperties.sCode == 'email' || oButtonProperties.sCode == 'ftp')
  622. this.insertLink(oButtonProperties.sCode);
  623. // Maybe an image?
  624. else if (oButtonProperties.sCode == 'img')
  625. this.insertImage();
  626. // Everything else means doing something ourselves.
  627. else if ('sBefore' in oButtonProperties)
  628. this.insertCustomHTML(oButtonProperties.sBefore.replace(/\\n/g, '\n'), oButtonProperties.sAfter.replace(/\\n/g, '\n'));
  629. }
  630. }
  631. this.updateEditorControls();
  632. // Finally set the focus.
  633. this.setFocus();
  634. }
  635. // Changing a select box?
  636. smc_Editor.prototype.handleSelectChange = function (oSelectProperties)
  637. {
  638. this.setFocus();
  639. var sValue = oSelectProperties.oSelect.value;
  640. if (sValue == '')
  641. return true;
  642. // Changing font face?
  643. if (oSelectProperties.sName == 'sel_face')
  644. {
  645. // Not in HTML mode?
  646. if (!this.bRichTextEnabled)
  647. {
  648. sValue = sValue.replace(/"/, '');
  649. surroundText('[font=' + sValue + ']', '[/font]', this.oTextHandle);
  650. oSelectProperties.oSelect.selectedIndex = 0;
  651. }
  652. else
  653. {
  654. if (is_webkit)
  655. this.smf_execCommand('styleWithCSS', false, true);
  656. this.smf_execCommand('fontname', false, sValue);
  657. }
  658. }
  659. // Font size?
  660. else if (oSelectProperties.sName == 'sel_size')
  661. {
  662. // Are we in boring mode?
  663. if (!this.bRichTextEnabled)
  664. {
  665. surroundText('[size=' + this.aFontSizes[sValue] + 'pt]', '[/size]', this.oTextHandle);
  666. oSelectProperties.oSelect.selectedIndex = 0;
  667. }
  668. else
  669. this.smf_execCommand('fontsize', false, sValue);
  670. }
  671. // Or color even?
  672. else if (oSelectProperties.sName == 'sel_color')
  673. {
  674. // Are we in boring mode?
  675. if (!this.bRichTextEnabled)
  676. {
  677. surroundText('[color=' + sValue + ']', '[/color]', this.oTextHandle);
  678. oSelectProperties.oSelect.selectedIndex = 0;
  679. }
  680. else
  681. this.smf_execCommand('forecolor', false, sValue);
  682. }
  683. this.updateEditorControls();
  684. return true;
  685. }
  686. // Put in some custom HTML.
  687. smc_Editor.prototype.insertCustomHTML = function(sLeftTag, sRightTag)
  688. {
  689. var sSelection = this.getSelect(true, true);
  690. if (sSelection.length == 0)
  691. sSelection = '';
  692. // Are we overwriting?
  693. if (sRightTag == '')
  694. this.insertText(sLeftTag);
  695. // If something was selected, replace and position cursor at the end of it.
  696. else if (sSelection.length > 0)
  697. this.insertText(sLeftTag + sSelection + sRightTag, false, false, 0);
  698. // Wrap the tags around the cursor position.
  699. else
  700. this.insertText(sLeftTag + sRightTag, false, false, sRightTag.length);
  701. }
  702. // Insert a URL link.
  703. smc_Editor.prototype.insertLink = function(sType)
  704. {
  705. if (sType == 'email')
  706. var sPromptText = oEditorStrings['prompt_text_email'];
  707. else if (sType == 'ftp')
  708. var sPromptText = oEditorStrings['prompt_text_ftp'];
  709. else
  710. var sPromptText = oEditorStrings['prompt_text_url'];
  711. // IE has a nice prompt for this - others don't.
  712. if (sType != 'email' && sType != 'ftp' && is_ie)
  713. this.smf_execCommand('createlink', true, 'http://');
  714. else
  715. {
  716. // Ask them where to link to.
  717. var sText = prompt(sPromptText, sType == 'email' ? '' : (sType == 'ftp' ? 'ftp://' : 'http://'));
  718. if (!sText)
  719. return;
  720. if (sType == 'email' && sText.indexOf('mailto:') != 0)
  721. sText = 'mailto:' + sText;
  722. // Check if we have text selected and if not force us to have some.
  723. var oCurText = this.getSelect(true, true);
  724. if (oCurText.toString().length != 0)
  725. {
  726. this.smf_execCommand('unlink');
  727. this.smf_execCommand('createlink', false, sText);
  728. }
  729. else
  730. this.insertText('<a href="' + sText + '">' + sText + '</a>');
  731. }
  732. }
  733. smc_Editor.prototype.insertImage = function(sSrc)
  734. {
  735. if (!sSrc)
  736. {
  737. sSrc = prompt(oEditorStrings['prompt_text_img'], 'http://');
  738. if (!sSrc || sSrc.length < 10)
  739. return;
  740. }
  741. this.smf_execCommand('insertimage', false, sSrc);
  742. }
  743. smc_Editor.prototype.getSelect = function(bWantText, bWantHTMLText)
  744. {
  745. if (is_ie && 'selection' in this.oFrameDocument)
  746. {
  747. // Just want plain text?
  748. if (bWantText && !bWantHTMLText)
  749. return this.oFrameDocument.selection.createRange().text;
  750. // We want the HTML flavoured variety?
  751. else if (bWantHTMLText)
  752. return this.oFrameDocument.selection.createRange().htmlText;
  753. return this.oFrameDocument.selection;
  754. }
  755. // This is mainly Firefox.
  756. if ('getSelection' in this.oFrameWindow)
  757. {
  758. // Plain text?
  759. if (bWantText && !bWantHTMLText)
  760. return this.oFrameWindow.getSelection().toString();
  761. // HTML is harder - currently using: http://www.faqts.com/knowledge_base/view.phtml/aid/32427
  762. else if (bWantHTMLText)
  763. {
  764. var oSelection = this.oFrameWindow.getSelection();
  765. if (oSelection.rangeCount > 0)
  766. {
  767. var oRange = oSelection.getRangeAt(0);
  768. var oClonedSelection = oRange.cloneContents();
  769. var oDiv = this.oFrameDocument.createElement('div');
  770. oDiv.appendChild(oClonedSelection);
  771. return oDiv.innerHTML;
  772. }
  773. else
  774. return '';
  775. }
  776. // Want the whole object then.
  777. return this.oFrameWindow.getSelection();
  778. }
  779. // If we're here it's not good.
  780. return this.oFrameDocument.getSelection();
  781. }
  782. smc_Editor.prototype.getRange = function()
  783. {
  784. // Get the current selection.
  785. var oSelection = this.getSelect();
  786. if (!oSelection)
  787. return null;
  788. if (is_ie && oSelection.createRange)
  789. return oSelection.createRange();
  790. return oSelection.rangeCount == 0 ? null : oSelection.getRangeAt(0);
  791. }
  792. // Get the current element.
  793. smc_Editor.prototype.getCurElement = function()
  794. {
  795. var oRange = this.getRange();
  796. if (!oRange)
  797. return null;
  798. if (is_ie)
  799. {
  800. if (oRange.item)
  801. return oRange.item(0);
  802. else
  803. return oRange.parentElement();
  804. }
  805. else
  806. {
  807. var oElement = oRange.commonAncestorContainer;
  808. return this.getParentElement(oElement);
  809. }
  810. }
  811. smc_Editor.prototype.getParentElement = function(oNode)
  812. {
  813. if (oNode.nodeType == 1)
  814. return oNode;
  815. for (var i = 0; i < 50; i++)
  816. {
  817. if (!oNode.parentNode)
  818. break;
  819. oNode = oNode.parentNode;
  820. if (oNode.nodeType == 1)
  821. return oNode;
  822. }
  823. return null;
  824. }
  825. // Remove formatting for the selected text.
  826. smc_Editor.prototype.removeFormatting = function()
  827. {
  828. // Do both at once.
  829. if (this.bRichTextEnabled)
  830. {
  831. this.smf_execCommand('removeformat');
  832. this.smf_execCommand('unlink');
  833. }
  834. // Otherwise do a crude move indeed.
  835. else
  836. {
  837. // Get the current selection first.
  838. if (this.oTextHandle.caretPos)
  839. var sCurrentText = this.oTextHandle.caretPos.text;
  840. else if ('selectionStart' in this.oTextHandle)
  841. var sCurrentText = this.oTextHandle.value.substr(this.oTextHandle.selectionStart, (this.oTextHandle.selectionEnd - this.oTextHandle.selectionStart));
  842. else
  843. return;
  844. // Do bits that are likely to have attributes.
  845. sCurrentText = sCurrentText.replace(RegExp("\\[/?(url|img|iurl|ftp|email|img|color|font|size|list|bdo).*?\\]", "g"), '');
  846. // Then just anything that looks like BBC.
  847. sCurrentText = sCurrentText.replace(RegExp("\\[/?[A-Za-z]+\\]", "g"), '');
  848. replaceText(sCurrentText, this.oTextHandle);
  849. }
  850. }
  851. // Toggle wysiwyg/normal mode.
  852. smc_Editor.prototype.toggleView = function(bView)
  853. {
  854. if (!this.bRichTextPossible)
  855. {
  856. alert(oEditorStrings['wont_work']);
  857. return false;
  858. }
  859. // Overriding or alternating?
  860. if (typeof(bView) == 'undefined')
  861. bView = !this.bRichTextEnabled;
  862. this.requestParsedMessage(bView);
  863. return true;
  864. }
  865. // Request the message in a different form.
  866. smc_Editor.prototype.requestParsedMessage = function(bView)
  867. {
  868. // Replace with a force reload.
  869. if (!window.XMLHttpRequest)
  870. {
  871. alert(oEditorStrings['func_disabled']);
  872. return;
  873. }
  874. // Get the text.
  875. var sText = this.getText(true, !bView).replace(/&#/g, "&#38;#").php_to8bit().php_urlencode();
  876. this.tmpMethod = sendXMLDocument;
  877. this.tmpMethod(smf_prepareScriptUrl(smf_scripturl) + 'action=jseditor;view=' + (bView ? 1 : 0) + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';xml', 'message=' + sText, this.onToggleDataReceived);
  878. delete tmpMethod;
  879. }
  880. smc_Editor.prototype.onToggleDataReceived = function(oXMLDoc)
  881. {
  882. var sText = '';
  883. for (var i = 0; i < oXMLDoc.getElementsByTagName('message')[0].childNodes.length; i++)
  884. sText += oXMLDoc.getElementsByTagName('message')[0].childNodes[i].nodeValue;
  885. // What is this new view we have?
  886. this.bRichTextEnabled = oXMLDoc.getElementsByTagName('message')[0].getAttribute('view') != '0';
  887. if (this.bRichTextEnabled)
  888. {
  889. this.oFrameHandle.style.display = '';
  890. if (this.showDebug)
  891. this.oBreadHandle.style.display = '';
  892. this.oTextHandle.style.display = 'none';
  893. }
  894. else
  895. {
  896. sText = sText.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
  897. this.oFrameHandle.style.display = 'none';
  898. this.oBreadHandle.style.display = 'none';
  899. this.oTextHandle.style.display = '';
  900. }
  901. // First we focus.
  902. this.setFocus();
  903. this.insertText(sText, true);
  904. // Record the new status.
  905. document.getElementById(this.opt.sUniqueId + '_mode').value = this.bRichTextEnabled ? '1' : '0';
  906. // Rebuild the bread crumb!
  907. this.updateEditorControls();
  908. }
  909. // Set the focus for the editing window.
  910. smc_Editor.prototype.setFocus = function(force_both)
  911. {
  912. if (!this.bRichTextEnabled)
  913. this.oTextHandle.focus();
  914. else if (is_ff || is_opera)
  915. this.oFrameHandle.focus();
  916. else
  917. this.oFrameWindow.focus();
  918. }
  919. // Start up the spellchecker!
  920. smc_Editor.prototype.spellCheckStart = function()
  921. {
  922. if (!spellCheck)
  923. return false;
  924. // If we're in HTML mode we need to get the non-HTML text.
  925. if (this.bRichTextEnabled)
  926. {
  927. var sText = escape(this.getText(true, 1).php_to8bit());
  928. this.tmpMethod = sendXMLDocument;
  929. this.tmpMethod(smf_prepareScriptUrl(smf_scripturl) + 'action=jseditor;view=0;' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';xml', 'message=' + sText, this.onSpellCheckDataReceived);
  930. delete tmpMethod;
  931. }
  932. // Otherwise start spellchecking right away.
  933. else
  934. spellCheck(this.sFormId, this.opt.sUniqueId);
  935. return true;
  936. }
  937. // This contains the spellcheckable text.
  938. smc_Editor.prototype.onSpellCheckDataReceived = function(oXMLDoc)
  939. {
  940. var sText = '';
  941. for (var i = 0; i < oXMLDoc.getElementsByTagName('message')[0].childNodes.length; i++)
  942. sText += oXMLDoc.getElementsByTagName('message')[0].childNodes[i].nodeValue;
  943. sText = sText.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
  944. this.oTextHandle.value = sText;
  945. spellCheck(this.sFormId, this.opt.sUniqueId);
  946. }
  947. // Function called when the Spellchecker is finished and ready to pass back.
  948. smc_Editor.prototype.spellCheckEnd = function()
  949. {
  950. // If HTML edit put the text back!
  951. if (this.bRichTextEnabled)
  952. {
  953. var sText = escape(this.getText(true, 0).php_to8bit());
  954. this.tmpMethod = sendXMLDocument;
  955. this.tmpMethod(smf_prepareScriptUrl(smf_scripturl) + 'action=jseditor;view=1;' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';xml', 'message=' + sText, smf_editorArray[this.iArrayPosition].onSpellCheckCompleteDataReceived);
  956. delete tmpMethod;
  957. }
  958. else
  959. this.setFocus();
  960. }
  961. // The corrected text.
  962. smc_Editor.prototype.onSpellCheckCompleteDataReceived = function(oXMLDoc)
  963. {
  964. var sText = '';
  965. for (var i = 0; i < oXMLDoc.getElementsByTagName('message')[0].childNodes.length; i++)
  966. sText += oXMLDoc.getElementsByTagName('message')[0].childNodes[i].nodeValue;
  967. this.insertText(sText, true);
  968. this.setFocus();
  969. }
  970. smc_Editor.prototype.resizeTextArea = function(newHeight, newWidth, is_change)
  971. {
  972. // Work out what the new height is.
  973. if (is_change)
  974. {
  975. // We'll assume pixels but may not be.
  976. newHeight = this._calculateNewDimension(this.oTextHandle.style.height, newHeight);
  977. if (newWidth)
  978. newWidth = this._calculateNewDimension(this.oTextHandle.style.width, newWidth);
  979. }
  980. // Do the HTML editor - but only if it's enabled!
  981. if (this.bRichTextPossible)
  982. {
  983. this.oFrameHandle.style.height = newHeight;
  984. if (newWidth)
  985. this.oFrameHandle.style.width = newWidth;
  986. }
  987. // Do the text box regardless!
  988. this.oTextHandle.style.height = newHeight;
  989. if (newWidth)
  990. this.oTextHandle.style.width = newWidth;
  991. }
  992. // A utility instruction to save repetition when trying to work out what to change on a height/width.
  993. smc_Editor.prototype._calculateNewDimension = function(old_size, change_size)
  994. {
  995. // We'll assume pixels but may not be.
  996. changeReg = change_size.toString().match(/(-)?(\d+)(\D*)/);
  997. curReg = old_size.toString().match(/(\d+)(\D*)/);
  998. if (!changeReg[3])
  999. changeReg[3] = 'px';
  1000. if (changeReg[1] == '-')
  1001. changeReg[2] = 0 - changeReg[2];
  1002. // Both the same type?
  1003. if (changeReg[3] == curReg[2])
  1004. {
  1005. new_size = parseInt(changeReg[2]) + parseInt(curReg[1]);
  1006. if (new_size < 50)
  1007. new_size = 50;
  1008. new_size = new_size.toString() + changeReg[3];
  1009. }
  1010. // Is the change a percentage?
  1011. else if (changeReg[3] == '%')
  1012. new_size = (parseInt(curReg[1]) + parseInt((parseInt(changeReg[2]) * parseInt(curReg[1])) / 100)).toString() + 'px';
  1013. // Otherwise just guess!
  1014. else
  1015. new_size = (parseInt(curReg[1]) + (parseInt(changeReg[2]) / 10)).toString() + '%';
  1016. return new_size;
  1017. }
  1018. // Register default keyboard shortcuts.
  1019. smc_Editor.prototype.registerDefaultShortcuts = function()
  1020. {
  1021. if (is_ff)
  1022. {
  1023. this.registerShortcut('b', 'ctrl', 'b');
  1024. this.registerShortcut('u', 'ctrl', 'u');
  1025. this.registerShortcut('i', 'ctrl', 'i');
  1026. this.registerShortcut('p', 'alt', 'preview');
  1027. this.registerShortcut('s', 'alt', 'submit');
  1028. }
  1029. }
  1030. // Register a keyboard shortcut.
  1031. smc_Editor.prototype.registerShortcut = function(sLetter, sModifiers, sCodeName)
  1032. {
  1033. if (!sCodeName)
  1034. return;
  1035. var oNewShortcut = {
  1036. code : sCodeName,
  1037. key: sLetter.toUpperCase().charCodeAt(0),
  1038. alt : false,
  1039. ctrl : false
  1040. };
  1041. var aSplitModifiers = sModifiers.split(',');
  1042. for(var i = 0, n = aSplitModifiers.length; i < n; i++)
  1043. if (aSplitModifiers[i] in oNewShortcut)
  1044. oNewShortcut[aSplitModifiers[i]] = true;
  1045. this.aKeyboardShortcuts[this.aKeyboardShortcuts.length] = oNewShortcut;
  1046. }
  1047. // Check whether the key has triggered a shortcut?
  1048. smc_Editor.prototype.checkShortcut = function(oEvent)
  1049. {
  1050. // To be a shortcut it needs to be one of these, duh!
  1051. if (!oEvent.altKey && !oEvent.ctrlKey)
  1052. return false;
  1053. var sReturnCode = false;
  1054. // Let's take a look at each of our shortcuts shall we?
  1055. for (var i = 0, n = this.aKeyboardShortcuts.length; i < n; i++)
  1056. {
  1057. // Found something?
  1058. if (oEvent.altKey == this.aKeyboardShortcuts[i].alt && oEvent.ctrlKey == this.aKeyboardShortcuts[i].ctrl && oEvent.keyCode == this.aKeyboardShortcuts[i].key)
  1059. sReturnCode = this.aKeyboardShortcuts[i].code;
  1060. }
  1061. return sReturnCode;
  1062. }
  1063. // The actual event check for the above!
  1064. smc_Editor.prototype.shortcutCheck = function(oEvent)
  1065. {
  1066. var sFoundCode = this.checkShortcut(oEvent);
  1067. // Run it and exit.
  1068. if (typeof(sFoundCode) == 'string' && sFoundCode != '')
  1069. {
  1070. var bCancelEvent = false;
  1071. if (sFoundCode == 'submit')
  1072. {
  1073. // So much to do!
  1074. var oForm = document.getElementById(this.sFormId);
  1075. submitThisOnce(oForm);
  1076. submitonce(oForm);
  1077. smc_saveEntities(oForm.name, ['subject', this.opt.sUniqueId, 'guestname', 'evtitle', 'question']);
  1078. oForm.submit();
  1079. bCancelEvent = true;
  1080. }
  1081. else if (sFoundCode == 'preview')
  1082. {
  1083. previewPost();
  1084. bCancelEvent = true;
  1085. }
  1086. else
  1087. bCancelEvent = this.opt.oBBCBox.emulateClick(sFoundCode);
  1088. if (bCancelEvent)
  1089. {
  1090. if (is_ie && oEvent.cancelBubble)
  1091. oEvent.cancelBubble = true;
  1092. else if (oEvent.stopPropagation)
  1093. {
  1094. oEvent.stopPropagation();
  1095. oEvent.preventDefault();
  1096. }
  1097. return false;
  1098. }
  1099. }
  1100. return true;
  1101. }
  1102. // This is the method called after clicking the resize bar.
  1103. smc_Editor.prototype.startResize = function(oEvent)
  1104. {
  1105. if ('event' in window)
  1106. oEvent = window.event;
  1107. if (!oEvent || window.smf_oCurrentResizeEditor != null)
  1108. return true;
  1109. window.smf_oCurrentResizeEditor = this.iArrayPosition;
  1110. var aCurCoordinates = smf_mousePose(oEvent);
  1111. this.osmc_EditorCurrentResize.old_y = aCurCoordinates[1];
  1112. this.osmc_EditorCurrentResize.old_rel_y = null;
  1113. this.osmc_EditorCurrentResize.cur_height = parseInt(this.oTextHandle.style.height);
  1114. // Set the necessary events for resizing.
  1115. var oResizeEntity = is_ie ? document : window;
  1116. oResizeEntity.addEventListener('mousemove', this.aEventWrappers.resizeOverDocument, false);
  1117. if (this.bRichTextPossible)
  1118. this.oFrameDocument.addEventListener('mousemove', this.aEventWrappers.resizeOverIframe, false);
  1119. document.addEventListener('mouseup', this.aEventWrappers.endResize, true);
  1120. if (this.bRichTextPossible)
  1121. this.oFrameDocument.addEventListener('mouseup', this.aEventWrappers.endResize, true);
  1122. return false;
  1123. }
  1124. // This is kind of a cheat, as it only works over the IFRAME.
  1125. smc_Editor.prototype.resizeOverIframe = function(oEvent)
  1126. {
  1127. if ('event' in window)
  1128. oEvent = window.event;
  1129. if (!oEvent || window.smf_oCurrentResizeEditor == null)
  1130. return true;
  1131. var newCords = smf_mousePose(oEvent);
  1132. if (this.osmc_EditorCurrentResize.old_rel_y == null)
  1133. this.osmc_EditorCurrentResize.old_rel_y = newCords[1];
  1134. else
  1135. {
  1136. var iNewHeight = newCords[1] - this.osmc_EditorCurrentResize.old_rel_y + this.osmc_EditorCurrentResize.cur_height;
  1137. if (iNewHeight < 0)
  1138. this.endResize();
  1139. else
  1140. this.resizeTextArea(iNewHeight + 'px', 0, false);
  1141. }
  1142. return false;
  1143. }
  1144. // This resizes an editor.
  1145. smc_Editor.prototype.resizeOverDocument = function (oEvent)
  1146. {
  1147. if ('event' in window)
  1148. oEvent = window.event;
  1149. if (!oEvent || window.smf_oCurrentResizeEditor == null)
  1150. return true;
  1151. var newCords = smf_mousePose(oEvent);
  1152. var iNewHeight = newCords[1] - this.osmc_EditorCurrentResize.old_y + this.osmc_EditorCurrentResize.cur_height;
  1153. if (iNewHeight < 0)
  1154. this.endResize();
  1155. else
  1156. this.resizeTextArea(iNewHeight + 'px', 0, false);
  1157. return false;
  1158. }
  1159. smc_Editor.prototype.endResize = function (oEvent)
  1160. {
  1161. if ('event' in window)
  1162. oEvent = window.event;
  1163. if (window.smf_oCurrentResizeEditor == null)
  1164. return true;
  1165. window.smf_oCurrentResizeEditor = null;
  1166. // Remove the event...
  1167. var oResizeEntity = is_ie ? document : window;
  1168. oResizeEntity.removeEventListener('mousemove', this.aEventWrappers.resizeOverDocument, false);
  1169. if (this.bRichTextPossible)
  1170. this.oFrameDocument.removeEventListener('mousemove', this.aEventWrappers.resizeOverIframe, false);
  1171. document.removeEventListener('mouseup', this.aEventWrappers.endResize, true);
  1172. if (this.bRichTextPossible)
  1173. this.oFrameDocument.removeEventListener('mouseup', this.aEventWrappers.endResize, true);
  1174. return false;
  1175. }
  1176. // *** smc_SmileyBox class.
  1177. function smc_SmileyBox(oOptions)
  1178. {
  1179. this.opt = oOptions;
  1180. this.oSmileyRowsContent = {};
  1181. this.oSmileyPopupWindow = null;
  1182. this.init();
  1183. }
  1184. smc_SmileyBox.prototype.init = function ()
  1185. {
  1186. // Get the HTML content of the smileys visible on the post screen.
  1187. this.getSmileyRowsContent('postform');
  1188. // Inject the HTML.
  1189. setInnerHTML(document.getElementById(this.opt.sContainerDiv), this.opt.sSmileyBoxTemplate.easyReplace({
  1190. smileyRows: this.oSmileyRowsContent.postform,
  1191. moreSmileys: this.opt.oSmileyLocations.popup.length == 0 ? '' : this.opt.sMoreSmileysTemplate.easyReplace({
  1192. moreSmileysId: this.opt.sUniqueId + '_addMoreSmileys'
  1193. })
  1194. }));
  1195. // Initialize the smileys.
  1196. this.initSmileys('postform', document);
  1197. // Initialize the [more] button.
  1198. if (this.opt.oSmileyLocations.popup.length > 0)
  1199. {
  1200. var oMoreLink = document.getElementById(this.opt.sUniqueId + '_addMoreSmileys');
  1201. oMoreLink.instanceRef = this;
  1202. oMoreLink.onclick = function () {
  1203. this.instanceRef.handleShowMoreSmileys();
  1204. return false;
  1205. }
  1206. }
  1207. }
  1208. // Loop through the smileys to setup the HTML.
  1209. smc_SmileyBox.prototype.getSmileyRowsContent = function (sLocation)
  1210. {
  1211. // If it's already defined, don't bother.
  1212. if (sLocation in this.oSmileyRowsContent)
  1213. return;
  1214. this.oSmileyRowsContent[sLocation] = '';
  1215. for (var iSmileyRowIndex = 0, iSmileyRowCount = this.opt.oSmileyLocations[sLocation].length; iSmileyRowIndex < iSmileyRowCount; iSmileyRowIndex++)
  1216. {
  1217. var sSmileyRowContent = '';
  1218. for (var iSmileyIndex = 0, iSmileyCount = this.opt.oSmileyLocations[sLocation][iSmileyRowIndex].length; iSmileyIndex < iSmileyCount; iSmileyIndex++)
  1219. sSmileyRowContent += this.opt.sSmileyTemplate.easyReplace({
  1220. smileySource: this.opt.oSmileyLocations[sLocation][iSmileyRowIndex][iSmileyIndex].sSrc.php_htmlspecialchars(),
  1221. smileyDescription: this.opt.oSmileyLocations[sLocation][iSmileyRowIndex][iSmileyIndex].sDescription.php_htmlspecialchars(),
  1222. smileyCode: this.opt.oSmileyLocations[sLocation][iSmileyRowIndex][iSmileyIndex].sCode.php_htmlspecialchars(),
  1223. smileyId: this.opt.sUniqueId + '_' + sLocation + '_' + iSmileyRowIndex.toString() + '_' + iSmileyIndex.toString()
  1224. });
  1225. this.oSmileyRowsContent[sLocation] += this.opt.sSmileyRowTemplate.easyReplace({
  1226. smileyRow: sSmileyRowContent
  1227. });
  1228. }
  1229. }
  1230. smc_SmileyBox.prototype.initSmileys = function (sLocation, oDocument)
  1231. {
  1232. for (var iSmileyRowIndex = 0, iSmileyRowCount = this.opt.oSmileyLocations[sLocation].length; iSmileyRowIndex < iSmileyRowCount; iSmileyRowIndex++)
  1233. {
  1234. for (var iSmileyIndex = 0, iSmileyCount = this.opt.oSmileyLocations[sLocation][iSmileyRowIndex].length; iSmileyIndex < iSmileyCount; iSmileyIndex++)
  1235. {
  1236. var oSmiley = oDocument.getElementById(this.opt.sUniqueId + '_' + sLocation + '_' + iSmileyRowIndex.toString() + '_' + iSmileyIndex.toString());
  1237. oSmiley.instanceRef = this;
  1238. oSmiley.style.cursor = 'pointer';
  1239. oSmiley.onclick = function () {
  1240. this.instanceRef.clickHandler(this);
  1241. return false;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. smc_SmileyBox.prototype.clickHandler = function (oSmileyImg)
  1247. {
  1248. // Dissect the id...
  1249. var aMatches = oSmileyImg.id.match(/([^_]+)_(\d+)_(\d+)$/);
  1250. if (aMatches.length != 4)
  1251. return false;
  1252. // ...to determine its exact smiley properties.
  1253. var sLocation = aMatches[1];
  1254. var iSmileyRowIndex = aMatches[2];
  1255. var iSmileyIndex = aMatches[3];
  1256. var oProperties = this.opt.oSmileyLocations[sLocation][iSmileyRowIndex][iSmileyIndex];
  1257. if ('sClickHandler' in this.opt)
  1258. eval(this.opt.sClickHandler + '(oProperties)');
  1259. return false;
  1260. }
  1261. smc_SmileyBox.prototype.handleShowMoreSmileys = function ()
  1262. {
  1263. // Focus the window if it's already opened.
  1264. if (this.oSmileyPopupWindow != null && 'closed' in this.oSmileyPopupWindow && !this.oSmileyPopupWindow.closed)
  1265. {
  1266. this.oSmileyPopupWindow.focus();
  1267. return;
  1268. }
  1269. // Get the smiley HTML.
  1270. this.getSmileyRowsContent('popup');
  1271. // Open the popup.
  1272. this.oSmileyPopupWindow = window.open('about:blank', this.opt.sUniqueId + '_addMoreSmileysPopup', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=220,resizable=yes');
  1273. // Paste the template in the popup.
  1274. this.oSmileyPopupWindow.document.open('text/html', 'replace');
  1275. this.oSmileyPopupWindow.document.write(this.opt.sMoreSmileysPopupTemplate.easyReplace({
  1276. smileyRows: this.oSmileyRowsContent.popup,
  1277. moreSmileysCloseLinkId: this.opt.sUniqueId + '_closeMoreSmileys'
  1278. }));
  1279. this.oSmileyPopupWindow.document.close();
  1280. // Initialize the smileys that are in the popup window.
  1281. this.initSmileys('popup', this.oSmileyPopupWindow.document);
  1282. // Add a function to the close window button.
  1283. var aCloseLink = this.oSmileyPopupWindow.document.getElementById(this.opt.sUniqueId + '_closeMoreSmileys');
  1284. aCloseLink.instanceRef = this;
  1285. aCloseLink.onclick = function () {
  1286. this.instanceRef.oSmileyPopupWindow.close();
  1287. return false;
  1288. }
  1289. }
  1290. // *** smc_BBCButtonBox class.
  1291. function smc_BBCButtonBox(oOptions)
  1292. {
  1293. this.opt = oOptions;
  1294. this.init();
  1295. }
  1296. smc_BBCButtonBox.prototype.init = function ()
  1297. {
  1298. var sBbcContent = '';
  1299. for (var iButtonRowIndex = 0, iRowCount = this.opt.aButtonRows.length; iButtonRowIndex < iRowCount; iButtonRowIndex++)
  1300. {
  1301. var sRowContent = '';
  1302. var bPreviousWasDivider = false;
  1303. for (var iButtonIndex = 0, iButtonCount = this.opt.aButtonRows[iButtonRowIndex].length; iButtonIndex < iButtonCount; iButtonIndex++)
  1304. {
  1305. var oCurButton = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1306. switch (oCurButton.sType)
  1307. {
  1308. case 'button':
  1309. if (oCurButton.bEnabled)
  1310. {
  1311. sRowContent += this.opt.sButtonTemplate.easyReplace({
  1312. buttonId: this.opt.sUniqueId.php_htmlspecialchars() + '_button_' + iButtonRowIndex.toString() + '_' + iButtonIndex.toString(),
  1313. buttonSrc: oCurButton.sImage.php_htmlspecialchars(),
  1314. buttonDescription: oCurButton.sDescription.php_htmlspecialchars()
  1315. });
  1316. bPreviousWasDivider = false;
  1317. }
  1318. break;
  1319. case 'divider':
  1320. if (!bPreviousWasDivider)
  1321. sRowContent += this.opt.sDividerTemplate;
  1322. bPreviousWasDivider = true;
  1323. break;
  1324. case 'select':
  1325. var sOptions = '';
  1326. // Fighting javascript's idea of order in a for loop... :P
  1327. if ('' in oCurButton.oOptions)
  1328. sOptions = '<option value="">' + oCurButton.oOptions[''].php_htmlspecialchars() + '</option>';
  1329. for (var sSelectValue in oCurButton.oOptions)
  1330. // we've been through this before
  1331. if (sSelectValue != '')
  1332. sOptions += '<option value="' + sSelectValue.php_htmlspecialchars() + '">' + oCurButton.oOptions[sSelectValue].php_htmlspecialchars() + '</option>';
  1333. sRowContent += this.opt.sSelectTemplate.easyReplace({
  1334. selectName: oCurButton.sName,
  1335. selectId: this.opt.sUniqueId.php_htmlspecialchars() + '_select_' + iButtonRowIndex.toString() + '_' + iButtonIndex.toString(),
  1336. selectOptions: sOptions
  1337. });
  1338. bPreviousWasDivider = false;
  1339. break;
  1340. }
  1341. }
  1342. sBbcContent += this.opt.sButtonRowTemplate.easyReplace({
  1343. buttonRow: sRowContent
  1344. });
  1345. }
  1346. var oBbcContainer = document.getElementById(this.opt.sContainerDiv);
  1347. setInnerHTML(oBbcContainer, sBbcContent);
  1348. for (var iButtonRowIndex = 0, iRowCount = this.opt.aButtonRows.length; iButtonRowIndex < iRowCount; iButtonRowIndex++)
  1349. {
  1350. for (var iButtonIndex = 0, iButtonCount = this.opt.aButtonRows[iButtonRowIndex].length; iButtonIndex < iButtonCount; iButtonIndex++)
  1351. {
  1352. var oCurControl = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1353. switch (oCurControl.sType)
  1354. {
  1355. case 'button':
  1356. if (!oCurControl.bEnabled)
  1357. break;
  1358. oCurControl.oImg = document.getElementById(this.opt.sUniqueId.php_htmlspecialchars() + '_button_' + iButtonRowIndex.toString() + '_' + iButtonIndex.toString());
  1359. oCurControl.oImg.style.cursor = 'pointer';
  1360. if ('sButtonBackgroundImage' in this.opt)
  1361. oCurControl.oImg.style.backgroundImage = 'url(' + this.opt.sButtonBackgroundImage + ')';
  1362. oCurControl.oImg.instanceRef = this;
  1363. oCurControl.oImg.onmouseover = function () {
  1364. this.instanceRef.handleButtonMouseOver(this);
  1365. };
  1366. oCurControl.oImg.onmouseout = function () {
  1367. this.instanceRef.handleButtonMouseOut(this);
  1368. };
  1369. oCurControl.oImg.onclick = function () {
  1370. this.instanceRef.handleButtonClick(this);
  1371. };
  1372. oCurControl.oImg.bIsActive = false;
  1373. oCurControl.oImg.bHover = false;
  1374. break;
  1375. case 'select':
  1376. oCurControl.oSelect = document.getElementById(this.opt.sUniqueId.php_htmlspecialchars() + '_select_' + iButtonRowIndex.toString() + '_' + iButtonIndex.toString());
  1377. oCurControl.oSelect.instanceRef = this;
  1378. oCurControl.oSelect.onchange = oCurControl.onchange = function () {
  1379. this.instanceRef.handleSelectChange(this);
  1380. }
  1381. break;
  1382. }
  1383. }
  1384. }
  1385. }
  1386. smc_BBCButtonBox.prototype.handleButtonMouseOver = function (oButtonImg)
  1387. {
  1388. oButtonImg.bHover = true;
  1389. this.updateButtonStatus(oButtonImg);
  1390. }
  1391. smc_BBCButtonBox.prototype.handleButtonMouseOut = function (oButtonImg)
  1392. {
  1393. oButtonImg.bHover = false;
  1394. this.updateButtonStatus(oButtonImg);
  1395. }
  1396. smc_BBCButtonBox.prototype.updateButtonStatus = function (oButtonImg)
  1397. {
  1398. var sNewURL = '';
  1399. if (oButtonImg.bHover && oButtonImg.bIsActive && 'sActiveButtonBackgroundImageHover' in this.opt)
  1400. sNewURL = 'url(' + this.opt.sActiveButtonBackgroundImageHover + ')';
  1401. else if (!oButtonImg.bHover && oButtonImg.bIsActive && 'sActiveButtonBackgroundImage' in this.opt)
  1402. sNewURL = 'url(' + this.opt.sActiveButtonBackgroundImage + ')';
  1403. else if (oButtonImg.bHover && 'sButtonBackgroundImageHover' in this.opt)
  1404. sNewURL = 'url(' + this.opt.sButtonBackgroundImageHover + ')';
  1405. else if ('sButtonBackgroundImage' in this.opt)
  1406. sNewURL = 'url(' + this.opt.sButtonBackgroundImage + ')';
  1407. if (oButtonImg.style.backgroundImage != sNewURL)
  1408. oButtonImg.style.backgroundImage = sNewURL;
  1409. }
  1410. smc_BBCButtonBox.prototype.handleButtonClick = function (oButtonImg)
  1411. {
  1412. // Dissect the id attribute...
  1413. var aMatches = oButtonImg.id.match(/(\d+)_(\d+)$/);
  1414. if (aMatches.length != 3)
  1415. return false;
  1416. // ...so that we can point to the exact button.
  1417. var iButtonRowIndex = aMatches[1];
  1418. var iButtonIndex = aMatches[2];
  1419. var oProperties = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1420. oProperties.bIsActive = oButtonImg.bIsActive;
  1421. if ('sButtonClickHandler' in this.opt)
  1422. eval(this.opt.sButtonClickHandler + '(oProperties)');
  1423. return false;
  1424. }
  1425. smc_BBCButtonBox.prototype.handleSelectChange = function (oSelectControl)
  1426. {
  1427. // Dissect the id attribute...
  1428. var aMatches = oSelectControl.id.match(/(\d+)_(\d+)$/);
  1429. if (aMatches.length != 3)
  1430. return false;
  1431. // ...so that we can point to the exact button.
  1432. var iButtonRowIndex = aMatches[1];
  1433. var iButtonIndex = aMatches[2];
  1434. var oProperties = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1435. if ('sSelectChangeHandler' in this.opt)
  1436. eval(this.opt.sSelectChangeHandler + '(oProperties)');
  1437. return true;
  1438. }
  1439. smc_BBCButtonBox.prototype.setActive = function (aButtons)
  1440. {
  1441. for (var iButtonRowIndex = 0, iRowCount = this.opt.aButtonRows.length; iButtonRowIndex < iRowCount; iButtonRowIndex++)
  1442. {
  1443. for (var iButtonIndex = 0, iButtonCount = this.opt.aButtonRows[iButtonRowIndex].length; iButtonIndex < iButtonCount; iButtonIndex++)
  1444. {
  1445. var oCurControl = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1446. if (oCurControl.sType == 'button' && oCurControl.bEnabled)
  1447. {
  1448. oCurControl.oImg.bIsActive = in_array(oCurControl.sCode, aButtons);
  1449. this.updateButtonStatus(oCurControl.oImg);
  1450. }
  1451. }
  1452. }
  1453. }
  1454. smc_BBCButtonBox.prototype.emulateClick = function (sCode)
  1455. {
  1456. for (var iButtonRowIndex = 0, iRowCount = this.opt.aButtonRows.length; iButtonRowIndex < iRowCount; iButtonRowIndex++)
  1457. {
  1458. for (var iButtonIndex = 0, iButtonCount = this.opt.aButtonRows[iButtonRowIndex].length; iButtonIndex < iButtonCount; iButtonIndex++)
  1459. {
  1460. var oCurControl = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1461. if (oCurControl.sType == 'button' && oCurControl.sCode == sCode)
  1462. {
  1463. eval(this.opt.sButtonClickHandler + '(oCurControl)');
  1464. return true;
  1465. }
  1466. }
  1467. }
  1468. return false;
  1469. }
  1470. smc_BBCButtonBox.prototype.setSelect = function (sSelectName, sValue)
  1471. {
  1472. if (!('sButtonClickHandler' in this.opt))
  1473. return;
  1474. for (var iButtonRowIndex = 0, iRowCount = this.opt.aButtonRows.length; iButtonRowIndex < iRowCount; iButtonRowIndex++)
  1475. {
  1476. for (var iButtonIndex = 0, iButtonCount = this.opt.aButtonRows[iButtonRowIndex].length; iButtonIndex < iButtonCount; iButtonIndex++)
  1477. {
  1478. var oCurControl = this.opt.aButtonRows[iButtonRowIndex][iButtonIndex];
  1479. if (oCurControl.sType == 'select' && oCurControl.sName == sSelectName)
  1480. oCurControl.oSelect.value = sValue;
  1481. }
  1482. }
  1483. }