PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/tdo-mini-forms/tdomf-quicktags.js.php

https://github.com/archives-of-michigan/seekingmichigan.org-Wordpress
PHP | 776 lines | 675 code | 60 blank | 41 comment | 149 complexity | 1e8517b99111dc27165a5a6610200ed2 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * This is a modified copy of Alex King's JS QuickTags.
  4. * 30/10/2007 by Mark Cunningham (http://thedeadone.net)
  5. */
  6. /*
  7. * Mods:
  8. * - Wrapped in PHP (to enable integration and other modifications)
  9. * - Can restrict, dynamically, what tags are supported
  10. * - Can supply a "postfix" so that it can be used with multiple textareas
  11. */
  12. # Tags to restrict
  13. $restrict_tags = false;
  14. if(isset($_REQUEST['allowed_tags'])) {
  15. $restrict_tags = true;
  16. $allowed_tags = strtolower($_REQUEST['allowed_tags']);
  17. }
  18. # Postfix to enable multiple instances on the same page
  19. $postfix = '';
  20. if(isset($_REQUEST['postfix'])){
  21. $postfix = $_REQUEST['postfix'];
  22. }
  23. /* TODO: some way to easily add their own tags, either via widget or UI */
  24. ?>
  25. // JS QuickTags version 1.2
  26. //
  27. // Copyright (c) 2002-2005 Alex King
  28. // http://www.alexking.org/
  29. //
  30. // Licensed under the LGPL license
  31. // http://www.gnu.org/copyleft/lesser.html
  32. //
  33. // **********************************************************************
  34. // This program is distributed in the hope that it will be useful, but
  35. // WITHOUT ANY WARRANTY; without even the implied warranty of
  36. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  37. // **********************************************************************
  38. //
  39. // This JavaScript will insert the tags below at the cursor position in IE and
  40. // Gecko-based browsers (Mozilla, Camino, Firefox, Netscape). For browsers that
  41. // do not support inserting at the cursor position (Safari, OmniWeb) it appends
  42. // the tags to the end of the content.
  43. //
  44. // The variable 'edCanvas' must be defined as the <textarea> element you want
  45. // to be editing in. See the accompanying 'index.html' page for an example.
  46. var edButtons<?php echo $postfix; ?> = new Array();
  47. var edLinks<?php echo $postfix; ?> = new Array();
  48. var edOpenTags<?php echo $postfix; ?> = new Array();
  49. function edButton<?php echo $postfix; ?>(id, display, tagStart, tagEnd, access, open) {
  50. this.id = id; // used to name the toolbar button
  51. this.display = display; // label on button
  52. this.tagStart = tagStart; // open tag
  53. this.tagEnd = tagEnd; // close tag
  54. this.access = access; // set to -1 if tag does not need to be closed
  55. this.open = open; // set to -1 if tag does not need to be closed
  56. }
  57. <?php if(!$restrict_tags || substr_count($allowed_tags,"<strong>") >= 1) { ?>
  58. edButtons<?php echo $postfix; ?>.push(
  59. new edButton<?php echo $postfix; ?>(
  60. 'ed_bold'
  61. ,'Bold'
  62. ,'<strong>'
  63. ,'</strong>'
  64. ,'b'
  65. )
  66. );
  67. <?php } ?>
  68. <?php if(!$restrict_tags || substr_count($allowed_tags,"<em>") >= 1) { ?>
  69. edButtons<?php echo $postfix; ?>.push(
  70. new edButton<?php echo $postfix; ?>(
  71. 'ed_italic'
  72. ,'Italics'
  73. ,'<em>'
  74. ,'</em>'
  75. ,'i'
  76. )
  77. );
  78. <?php } ?>
  79. <?php if(!$restrict_tags || substr_count($allowed_tags,"<a>") >= 1) { ?>
  80. edButtons<?php echo $postfix; ?>.push(
  81. new edButton<?php echo $postfix; ?>(
  82. 'ed_link'
  83. ,'Link'
  84. ,''
  85. ,'</a>'
  86. ,'a'
  87. )
  88. ); // special case
  89. edButtons<?php echo $postfix; ?>.push(
  90. new edButton<?php echo $postfix; ?>(
  91. 'ed_ext_link'
  92. ,'Ext. Link'
  93. ,''
  94. ,'</a>'
  95. ,'e'
  96. )
  97. ); // special case
  98. <?php } ?>
  99. <?php if(!$restrict_tags || substr_count($allowed_tags,"<img>") >= 1) { ?>
  100. edButtons<?php echo $postfix; ?>.push(
  101. new edButton<?php echo $postfix; ?>(
  102. 'ed_img'
  103. ,'Ext. Image'
  104. ,''
  105. ,''
  106. ,'m'
  107. ,-1
  108. )
  109. ); // special case
  110. <?php } ?>
  111. <?php if(!$restrict_tags || substr_count($allowed_tags,"<ul>") >= 1) { ?>
  112. edButtons<?php echo $postfix; ?>.push(
  113. new edButton<?php echo $postfix; ?>(
  114. 'ed_ul'
  115. ,'List'
  116. ,'<ul>\n'
  117. ,'</ul>\n\n'
  118. ,'u'
  119. )
  120. );
  121. <?php } ?>
  122. <?php if(!$restrict_tags || substr_count($allowed_tags,"<ol>") >= 1) { ?>
  123. edButtons<?php echo $postfix; ?>.push(
  124. new edButton<?php echo $postfix; ?>(
  125. 'ed_ol'
  126. ,'Numbered List'
  127. ,'<ol>\n'
  128. ,'</ol>\n\n'
  129. ,'o'
  130. )
  131. );
  132. <?php } ?>
  133. <?php if(!$restrict_tags || substr_count($allowed_tags,"<li>") >= 1) { ?>
  134. edButtons<?php echo $postfix; ?>.push(
  135. new edButton<?php echo $postfix; ?>(
  136. 'ed_li'
  137. ,'List Item'
  138. ,'\t<li>'
  139. ,'</li>\n'
  140. ,'l'
  141. )
  142. );
  143. <?php } ?>
  144. <?php if(!$restrict_tags || substr_count($allowed_tags,"<blockquote>") >= 1) { ?>
  145. edButtons<?php echo $postfix; ?>.push(
  146. new edButton<?php echo $postfix; ?>(
  147. 'ed_block'
  148. ,'Quote'
  149. ,'<blockquote>'
  150. ,'</blockquote>'
  151. ,'q'
  152. )
  153. );
  154. <?php } ?>
  155. var extendedStart<?php echo $postfix; ?> = edButtons<?php echo $postfix; ?>.length;
  156. // below here are the extended buttons
  157. <?php if(!$restrict_tags || substr_count($allowed_tags,"<h1>") >= 1) { ?>
  158. edButtons<?php echo $postfix; ?>.push(
  159. new edButton<?php echo $postfix; ?>(
  160. 'ed_h1'
  161. ,'Heading 1'
  162. ,'<h1>'
  163. ,'</h1>\n\n'
  164. ,'1'
  165. )
  166. );
  167. <?php } ?>
  168. <?php if(!$restrict_tags || substr_count($allowed_tags,"<h2>") >= 1) { ?>
  169. edButtons<?php echo $postfix; ?>.push(
  170. new edButton<?php echo $postfix; ?>(
  171. 'ed_h2'
  172. ,'Heading 2'
  173. ,'<h2>'
  174. ,'</h2>\n\n'
  175. ,'2'
  176. )
  177. );
  178. <?php } ?>
  179. <?php if(!$restrict_tags || substr_count($allowed_tags,"<h3>") >= 1) { ?>
  180. edButtons<?php echo $postfix; ?>.push(
  181. new edButton<?php echo $postfix; ?>(
  182. 'ed_h3'
  183. ,'Heading 3'
  184. ,'<h3>'
  185. ,'</h3>\n\n'
  186. ,'3'
  187. )
  188. );
  189. <?php } ?>
  190. <?php if(!$restrict_tags || substr_count($allowed_tags,"<h4>") >= 1) { ?>
  191. edButtons<?php echo $postfix; ?>.push(
  192. new edButton<?php echo $postfix; ?>(
  193. 'ed_h4'
  194. ,'Heading 4'
  195. ,'<h4>'
  196. ,'</h4>\n\n'
  197. ,'4'
  198. )
  199. );
  200. <?php } ?>
  201. <?php if(!$restrict_tags || substr_count($allowed_tags,"<p>") >= 1) { ?>
  202. edButtons<?php echo $postfix; ?>.push(
  203. new edButton<?php echo $postfix; ?>(
  204. 'ed_p'
  205. ,'Paragraph'
  206. ,'<p>'
  207. ,'</p>\n\n'
  208. ,'p'
  209. )
  210. );
  211. <?php } ?>
  212. <?php if(!$restrict_tags || substr_count($allowed_tags,"<code>") >= 1) { ?>
  213. edButtons<?php echo $postfix; ?>.push(
  214. new edButton<?php echo $postfix; ?>(
  215. 'ed_code'
  216. ,'Code'
  217. ,'<code>'
  218. ,'</code>'
  219. ,'c'
  220. )
  221. );
  222. <?php } ?>
  223. <?php if(!$restrict_tags || substr_count($allowed_tags,"<pre>") >= 1) { ?>
  224. edButtons<?php echo $postfix; ?>.push(
  225. new edButton<?php echo $postfix; ?>(
  226. 'ed_pre'
  227. ,'No formatting'
  228. ,'<pre>'
  229. ,'</pre>'
  230. )
  231. );
  232. <?php } ?>
  233. <?php if(!$restrict_tags || substr_count($allowed_tags,"<dl>") >= 1) { ?>
  234. edButtons<?php echo $postfix; ?>.push(
  235. new edButton<?php echo $postfix; ?>(
  236. 'ed_dl'
  237. ,'Def. List'
  238. ,'<dl>\n'
  239. ,'</dl>\n\n'
  240. )
  241. );
  242. <?php } ?>
  243. <?php if(!$restrict_tags || substr_count($allowed_tags,"<dt>") >= 1) { ?>
  244. edButtons<?php echo $postfix; ?>.push(
  245. new edButton<?php echo $postfix; ?>(
  246. 'ed_dt'
  247. ,'Def. List Item Title'
  248. ,'\t<dt>'
  249. ,'</dt>\n'
  250. )
  251. );
  252. <?php } ?>
  253. <?php if(!$restrict_tags || substr_count($allowed_tags,"<dd>") >= 1) { ?>
  254. edButtons<?php echo $postfix; ?>.push(
  255. new edButton<?php echo $postfix; ?>(
  256. 'ed_dd'
  257. ,'Def. List Item Desc.'
  258. ,'\t<dd>'
  259. ,'</dd>\n'
  260. )
  261. );
  262. <?php } ?>
  263. <?php if(!$restrict_tags || substr_count($allowed_tags,"<table>") >= 1) { ?>
  264. edButtons<?php echo $postfix; ?>.push(
  265. new edButton<?php echo $postfix; ?>(
  266. 'ed_table'
  267. ,'Table'
  268. ,'<table>\n<tbody>'
  269. ,'</tbody>\n</table>\n'
  270. )
  271. );
  272. <?php } ?>
  273. <?php if(!$restrict_tags || substr_count($allowed_tags,"<tr>") >= 1) { ?>
  274. edButtons<?php echo $postfix; ?>.push(
  275. new edButton<?php echo $postfix; ?>(
  276. 'ed_tr'
  277. ,'Table Row'
  278. ,'\t<tr>\n'
  279. ,'\n\t</tr>\n'
  280. )
  281. );
  282. <?php } ?>
  283. <?php if(!$restrict_tags || substr_count($allowed_tags,"<td>") >= 1) { ?>
  284. edButtons<?php echo $postfix; ?>.push(
  285. new edButton<?php echo $postfix; ?>(
  286. 'ed_td'
  287. ,'Table Col.'
  288. ,'\t\t<td>'
  289. ,'</td>\n'
  290. )
  291. );
  292. <?php } ?>
  293. <?php if(!$restrict_tags || substr_count($allowed_tags,"<u>") >= 1) { ?>
  294. edButtons<?php echo $postfix; ?>.push(
  295. new edButton<?php echo $postfix; ?>(
  296. 'ed_under'
  297. ,'Underline'
  298. ,'<u>'
  299. ,'</u>'
  300. )
  301. );
  302. <?php } ?>
  303. <?php if(!$restrict_tags || substr_count($allowed_tags,"<s>") >= 1) { ?>
  304. edButtons<?php echo $postfix; ?>.push(
  305. new edButton<?php echo $postfix; ?>(
  306. 'ed_strike'
  307. ,'Strikethrough'
  308. ,'<s>'
  309. ,'</s>'
  310. )
  311. );
  312. <?php } ?>
  313. <?php if(!$restrict_tags || substr_count($allowed_tags,"<nobr>") >= 1) { ?>
  314. edButtons<?php echo $postfix; ?>.push(
  315. new edButton<?php echo $postfix; ?>(
  316. 'ed_nobr'
  317. ,'No breaks'
  318. ,'<nobr>'
  319. ,'</nobr>'
  320. )
  321. );
  322. <?php } ?>
  323. <?php if(!$restrict_tags || substr_count($allowed_tags,"<center>") >= 1) { ?>
  324. edButtons<?php echo $postfix; ?>.push(
  325. new edButton<?php echo $postfix; ?>(
  326. 'ed_center'
  327. ,'Center'
  328. ,'<center>'
  329. ,'</center>'
  330. )
  331. );
  332. <?php } ?>
  333. <?php if(!$restrict_tags || substr_count($allowed_tags,"<!--more-->") >= 1) { ?>
  334. edButtons<?php echo $postfix; ?>.push(
  335. new edButton<?php echo $postfix; ?>(
  336. 'ed_more'
  337. ,'Read More...'
  338. ,'<!--more-->'
  339. ,''
  340. )
  341. );
  342. <?php } ?>
  343. <?php if(!$restrict_tags
  344. || (substr_count($allowed_tags,"<ol>") >= 1
  345. && substr_count($allowed_tags,"<li>") >= 1
  346. && substr_count($allowed_tags,"<sup>") >= 1
  347. && substr_count($allowed_tags,"<a>") >= 1)) { ?>
  348. edButtons<?php echo $postfix; ?>.push(
  349. new edButton<?php echo $postfix; ?>(
  350. 'ed_footnote'
  351. ,'Footnote'
  352. ,''
  353. ,''
  354. ,'f'
  355. )
  356. );
  357. <?php } ?>
  358. function edLink<?php echo $postfix; ?>(display, URL, newWin) {
  359. this.display = display;
  360. this.URL = URL;
  361. if (!newWin) {
  362. newWin = 0;
  363. }
  364. this.newWin = newWin;
  365. }
  366. edLinks<?php echo $postfix; ?>[edLinks<?php echo $postfix; ?>.length] = new edLink<?php echo $postfix; ?>('alexking.org'
  367. ,'http://www.alexking.org/'
  368. );
  369. function edShowButton<?php echo $postfix; ?>(button, i) {
  370. if (button.access) {
  371. var accesskey = ' accesskey = "' + button.access + '"'
  372. }
  373. else {
  374. var accesskey = '';
  375. }
  376. switch (button.id) {
  377. case 'ed_img':
  378. document.write('<input type="button" id="' + button.id + '" ' + accesskey + ' class="ed_button" onclick="edInsertImage<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>);" value="' + button.display + '" />');
  379. break;
  380. case 'ed_link':
  381. document.write('<input type="button" id="' + button.id + '" ' + accesskey + ' class="ed_button" onclick="edInsertLink<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>, ' + i + ');" value="' + button.display + '" />');
  382. break;
  383. case 'ed_ext_link':
  384. document.write('<input type="button" id="' + button.id + '" ' + accesskey + ' class="ed_button" onclick="edInsertExtLink<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>, ' + i + ');" value="' + button.display + '" />');
  385. break;
  386. case 'ed_footnote':
  387. document.write('<input type="button" id="' + button.id + '" ' + accesskey + ' class="ed_button" onclick="edInsertFootnote<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>);" value="' + button.display + '" />');
  388. break;
  389. default:
  390. document.write('<input type="button" id="' + button.id + '" ' + accesskey + ' class="ed_button" onclick="edInsertTag<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>, ' + i + ');" value="' + button.display + '" />');
  391. break;
  392. }
  393. }
  394. function edShowLinks<?php echo $postfix; ?>() {
  395. var tempStr = '<select onchange="edQuickLink<?php echo $postfix; ?>(this.options[this.selectedIndex].value, this);"><option value="-1" selected>(Quick Links)</option>';
  396. for (i = 0; i < edLinks.length; i++) {
  397. tempStr += '<option value="' + i + '">' + edLinks[i].display + '</option>';
  398. }
  399. tempStr += '</select>';
  400. document.write(tempStr);
  401. }
  402. function edAddTag<?php echo $postfix; ?>(button) {
  403. if (edButtons<?php echo $postfix; ?>[button].tagEnd != '') {
  404. edOpenTags<?php echo $postfix; ?>[edOpenTags<?php echo $postfix; ?>.length] = button;
  405. document.getElementById(edButtons<?php echo $postfix; ?>[button].id).value = '/' + document.getElementById(edButtons<?php echo $postfix; ?>[button].id).value;
  406. }
  407. }
  408. function edRemoveTag<?php echo $postfix; ?>(button) {
  409. for (i = 0; i < edOpenTags<?php echo $postfix; ?>.length; i++) {
  410. if (edOpenTags<?php echo $postfix; ?>[i] == button) {
  411. edOpenTags<?php echo $postfix; ?>.splice(i, 1);
  412. document.getElementById(edButtons<?php echo $postfix; ?>[button].id).value = document.getElementById(edButtons<?php echo $postfix; ?>[button].id).value.replace('/', '');
  413. }
  414. }
  415. }
  416. function edCheckOpenTags<?php echo $postfix; ?>(button) {
  417. var tag = 0;
  418. for (i = 0; i < edOpenTags<?php echo $postfix; ?>.length; i++) {
  419. if (edOpenTags<?php echo $postfix; ?>[i] == button) {
  420. tag++;
  421. }
  422. }
  423. if (tag > 0) {
  424. return true; // tag found
  425. }
  426. else {
  427. return false; // tag not found
  428. }
  429. }
  430. function edCloseAllTags<?php echo $postfix; ?>() {
  431. var count = edOpenTags<?php echo $postfix; ?>.length;
  432. for (o = 0; o < count; o++) {
  433. edInsertTa<?php echo $postfix; ?>g(edCanvas<?php echo $postfix; ?>, edOpenTags<?php echo $postfix; ?>[edOpenTags<?php echo $postfix; ?>.length - 1]);
  434. }
  435. }
  436. function edQuickLink<?php echo $postfix; ?>(i, thisSelect) {
  437. if (i > -1) {
  438. var newWin = '';
  439. if (edLinks<?php echo $postfix; ?>[i].newWin == 1) {
  440. newWin = ' target="_blank"';
  441. }
  442. var tempStr = '<a href="' + edLinks[i].URL + '"' + newWin + '>'
  443. + edLinks<?php echo $postfix; ?>[i].display
  444. + '</a>';
  445. thisSelect.selectedIndex = 0;
  446. edInsertContent<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>, tempStr);
  447. }
  448. else {
  449. thisSelect.selectedIndex = 0;
  450. }
  451. }
  452. function edSpell<?php echo $postfix; ?>(myField) {
  453. var word = '';
  454. if (document.selection) {
  455. myField.focus();
  456. var sel = document.selection.createRange();
  457. if (sel.text.length > 0) {
  458. word = sel.text;
  459. }
  460. }
  461. else if (myField.selectionStart || myField.selectionStart == '0') {
  462. var startPos = myField.selectionStart;
  463. var endPos = myField.selectionEnd;
  464. if (startPos != endPos) {
  465. word = myField.value.substring(startPos, endPos);
  466. }
  467. }
  468. if (word == '') {
  469. word = prompt('Enter a word to look up:', '');
  470. }
  471. if (word != '') {
  472. window.open('http://www.answers.com/' + escape(word));
  473. }
  474. }
  475. function edToolbar<?php echo $postfix; ?>() {
  476. document.write('<div id="ed_toolbar"><span>');
  477. for (i = 0; i < extendedStart<?php echo $postfix; ?>; i++) {
  478. edShowButton<?php echo $postfix; ?>(edButtons<?php echo $postfix; ?>[i], i);
  479. }
  480. if (edShowExtraCookie<?php echo $postfix; ?>()) {
  481. document.write(
  482. '<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags<?php echo $postfix; ?>();" value="Close Tags" />'
  483. + '<input type="button" id="ed_spell" class="ed_button" onclick="edSpell<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>);" value="Dict." />'
  484. + '<input type="button" id="ed_extra_show<?php echo $postfix; ?>" class="ed_button" onclick="edShowExtra<?php echo $postfix; ?>()" value="&raquo;" style="visibility: hidden;" />'
  485. + '</span><br />'
  486. + '<span id="ed_extra_buttons<?php echo $postfix; ?>">'
  487. + '<input type="button" id="ed_extra_hide" class="ed_button" onclick="edHideExtra<?php echo $postfix; ?>();" value="&laquo;" />'
  488. );
  489. }
  490. else {
  491. document.write(
  492. '<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags<?php echo $postfix; ?>();" value="Close Tags" />'
  493. + '<input type="button" id="ed_spell" class="ed_button" onclick="edSpell<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>);" value="Dict." />'
  494. + '<input type="button" id="ed_extra_show<?php echo $postfix; ?>" class="ed_button" onclick="edShowExtra<?php echo $postfix; ?>()" value="&raquo;" />'
  495. + '</span><br />'
  496. + '<span id="ed_extra_buttons<?php echo $postfix; ?>" style="display: none;">'
  497. + '<input type="button" id="ed_extra_hide" class="ed_button" onclick="edHideExtra<?php echo $postfix; ?>();" value="&laquo;" />'
  498. );
  499. }
  500. for (i = extendedStart<?php echo $postfix; ?>; i < edButtons<?php echo $postfix; ?>.length; i++) {
  501. edShowButton<?php echo $postfix; ?>(edButtons<?php echo $postfix; ?>[i], i);
  502. }
  503. document.write('</span>');
  504. // edShowLinks<?php echo $postfix; ?>();
  505. document.write('</div>');
  506. }
  507. function edShowExtra<?php echo $postfix; ?>() {
  508. document.getElementById('ed_extra_show<?php echo $postfix; ?>').style.visibility = 'hidden';
  509. document.getElementById('ed_extra_buttons<?php echo $postfix; ?>').style.display = 'block';
  510. edSetCookie<?php echo $postfix; ?>(
  511. 'js_quicktags_extra'
  512. , 'show'
  513. , new Date("December 31, 2100")
  514. );
  515. }
  516. function edHideExtra<?php echo $postfix; ?>() {
  517. document.getElementById('ed_extra_buttons<?php echo $postfix; ?>').style.display = 'none';
  518. document.getElementById('ed_extra_show<?php echo $postfix; ?>').style.visibility = 'visible';
  519. edSetCookie<?php echo $postfix; ?>(
  520. 'js_quicktags_extra'
  521. , 'hide'
  522. , new Date("December 31, 2100")
  523. );
  524. }
  525. // insertion code
  526. function edInsertTag<?php echo $postfix; ?>(myField, i) {
  527. //IE support
  528. if (document.selection) {
  529. myField.focus();
  530. sel = document.selection.createRange();
  531. if (sel.text.length > 0) {
  532. sel.text = edButtons<?php echo $postfix; ?>[i].tagStart + sel.text + edButtons<?php echo $postfix; ?>[i].tagEnd;
  533. }
  534. else {
  535. if (!edCheckOpenTags<?php echo $postfix; ?>(i) || edButtons<?php echo $postfix; ?>[i].tagEnd == '') {
  536. sel.text = edButtons<?php echo $postfix; ?>[i].tagStart;
  537. edAddTag<?php echo $postfix; ?>(i);
  538. }
  539. else {
  540. sel.text = edButtons<?php echo $postfix; ?>[i].tagEnd;
  541. edRemoveTag<?php echo $postfix; ?>(i);
  542. }
  543. }
  544. myField.focus();
  545. }
  546. //MOZILLA/NETSCAPE support
  547. else if (myField.selectionStart || myField.selectionStart == '0') {
  548. var startPos = myField.selectionStart;
  549. var endPos = myField.selectionEnd;
  550. var cursorPos = endPos;
  551. var scrollTop = myField.scrollTop;
  552. if (startPos != endPos) {
  553. myField.value = myField.value.substring(0, startPos)
  554. + edButtons<?php echo $postfix; ?>[i].tagStart
  555. + myField.value.substring(startPos, endPos)
  556. + edButtons<?php echo $postfix; ?>[i].tagEnd
  557. + myField.value.substring(endPos, myField.value.length);
  558. cursorPos += edButtons<?php echo $postfix; ?>[i].tagStart.length + edButtons<?php echo $postfix; ?>[i].tagEnd.length;
  559. }
  560. else {
  561. if (!edCheckOpenTags<?php echo $postfix; ?>(i) || edButtons<?php echo $postfix; ?>[i].tagEnd == '') {
  562. myField.value = myField.value.substring(0, startPos)
  563. + edButtons<?php echo $postfix; ?>[i].tagStart
  564. + myField.value.substring(endPos, myField.value.length);
  565. edAddTag<?php echo $postfix; ?>(i);
  566. cursorPos = startPos + edButtons<?php echo $postfix; ?>[i].tagStart.length;
  567. }
  568. else {
  569. myField.value = myField.value.substring(0, startPos)
  570. + edButtons<?php echo $postfix; ?>[i].tagEnd
  571. + myField.value.substring(endPos, myField.value.length);
  572. edRemoveTag<?php echo $postfix; ?>(i);
  573. cursorPos = startPos + edButtons<?php echo $postfix; ?>[i].tagEnd.length;
  574. }
  575. }
  576. myField.focus();
  577. myField.selectionStart = cursorPos;
  578. myField.selectionEnd = cursorPos;
  579. myField.scrollTop = scrollTop;
  580. }
  581. else {
  582. if (!edCheckOpenTags<?php echo $postfix; ?>(i) || edButtons<?php echo $postfix; ?>[i].tagEnd == '') {
  583. myField.value += edButtons<?php echo $postfix; ?>[i].tagStart;
  584. edAddTag(i);
  585. }
  586. else {
  587. myField.value += edButtons<?php echo $postfix; ?>[i].tagEnd;
  588. edRemoveTag<?php echo $postfix; ?>(i);
  589. }
  590. myField.focus();
  591. }
  592. }
  593. function edInsertContent<?php echo $postfix; ?>(myField, myValue) {
  594. //IE support
  595. if (document.selection) {
  596. myField.focus();
  597. sel = document.selection.createRange();
  598. sel.text = myValue;
  599. myField.focus();
  600. }
  601. //MOZILLA/NETSCAPE support
  602. else if (myField.selectionStart || myField.selectionStart == '0') {
  603. var startPos = myField.selectionStart;
  604. var endPos = myField.selectionEnd;
  605. var scrollTop = myField.scrollTop;
  606. myField.value = myField.value.substring(0, startPos)
  607. + myValue
  608. + myField.value.substring(endPos, myField.value.length);
  609. myField.focus();
  610. myField.selectionStart = startPos + myValue.length;
  611. myField.selectionEnd = startPos + myValue.length;
  612. myField.scrollTop = scrollTop;
  613. } else {
  614. myField.value += myValue;
  615. myField.focus();
  616. }
  617. }
  618. function edInsertLink<?php echo $postfix; ?>(myField, i, defaultValue) {
  619. if (!defaultValue) {
  620. defaultValue = 'http://';
  621. }
  622. if (!edCheckOpenTags<?php echo $postfix; ?>(i)) {
  623. var URL = prompt('Enter the URL' ,defaultValue);
  624. if (URL) {
  625. edButtons<?php echo $postfix; ?>[i].tagStart = '<a href="' + URL + '">';
  626. edInsertTag<?php echo $postfix; ?>(myField, i);
  627. }
  628. }
  629. else {
  630. edInsertTag<?php echo $postfix; ?>(myField, i);
  631. }
  632. }
  633. function edInsertExtLink<?php echo $postfix; ?>(myField, i, defaultValue) {
  634. if (!defaultValue) {
  635. defaultValue = 'http://';
  636. }
  637. if (!edCheckOpenTags<?php echo $postfix; ?>(i)) {
  638. var URL = prompt('Enter the URL' ,defaultValue);
  639. if (URL) {
  640. edButtons<?php echo $postfix; ?>[i].tagStart = '<a href="' + URL + '" rel="external">';
  641. edInsertTag<?php echo $postfix; ?>(myField, i);
  642. }
  643. }
  644. else {
  645. edInsertTag<?php echo $postfix; ?>(myField, i);
  646. }
  647. }
  648. function edInsertImage<?php echo $postfix; ?>(myField) {
  649. var myValue = prompt('Enter the URL of the image', 'http://');
  650. if (myValue) {
  651. myValue = '<img src="'
  652. + myValue
  653. + '" alt="' + prompt('Enter a description of the image', '')
  654. + '" />';
  655. edInsertContent<?php echo $postfix; ?>(myField, myValue);
  656. }
  657. }
  658. function edInsertFootnote<?php echo $postfix; ?>(myField) {
  659. var note = prompt('Enter the footnote:', '');
  660. if (!note || note == '') {
  661. return false;
  662. }
  663. var now = new Date;
  664. var fnId = 'fn' + now.getTime();
  665. var fnStart = edCanvas<?php echo $postfix; ?>.value.indexOf('<ol class="footnotes">');
  666. if (fnStart != -1) {
  667. var fnStr1 = edCanvas<?php echo $postfix; ?>.value.substring(0, fnStart)
  668. var fnStr2 = edCanvas<?php echo $postfix; ?>.value.substring(fnStart, edCanvas<?php echo $postfix; ?>.value.length)
  669. var count = countInstances(fnStr2, '<li id="') + 1;
  670. }
  671. else {
  672. var count = 1;
  673. }
  674. var count = '<sup><a href="#' + fnId + 'n" id="' + fnId + '" class="footnote">' + count + '</a></sup>';
  675. edInsertContent<?php echo $postfix; ?>(edCanvas<?php echo $postfix; ?>, count);
  676. if (fnStart != -1) {
  677. fnStr1 = edCanvas<?php echo $postfix; ?>.value.substring(0, fnStart + count.length)
  678. fnStr2 = edCanvas<?php echo $postfix; ?>.value.substring(fnStart + count.length, edCanvas<?php echo $postfix; ?>.value.length)
  679. }
  680. else {
  681. var fnStr1 = edCanvas<?php echo $postfix; ?>.value;
  682. var fnStr2 = "\n\n" + '<ol class="footnotes">' + "\n"
  683. + '</ol>' + "\n";
  684. }
  685. var footnote = ' <li id="' + fnId + 'n">' + note + ' [<a href="#' + fnId + '">back</a>]</li>' + "\n"
  686. + '</ol>';
  687. edCanvas<?php echo $postfix; ?>.value = fnStr1 + fnStr2.replace('</ol>', footnote);
  688. }
  689. function countInstances<?php echo $postfix; ?>(string, substr) {
  690. var count = string.split(substr);
  691. return count.length - 1;
  692. }
  693. function edSetCookie<?php echo $postfix; ?>(name, value, expires, path, domain) {
  694. document.cookie= name + "=" + escape(value) +
  695. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  696. ((path) ? "; path=" + path : "") +
  697. ((domain) ? "; domain=" + domain : "");
  698. }
  699. function edShowExtraCookie<?php echo $postfix; ?>() {
  700. var cookies = document.cookie.split(';');
  701. for (var i=0;i < cookies.length; i++) {
  702. var cookieData = cookies[i];
  703. while (cookieData.charAt(0) ==' ') {
  704. cookieData = cookieData.substring(1, cookieData.length);
  705. }
  706. if (cookieData.indexOf('js_quicktags_extra') == 0) {
  707. if (cookieData.substring(19, cookieData.length) == 'show') {
  708. return true;
  709. }
  710. else {
  711. return false;
  712. }
  713. }
  714. }
  715. return false;
  716. }