sonata_formatter_js_jquery.markitup_1.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. // ----------------------------------------------------------------------------
  2. // markItUp! Universal MarkUp Engine, JQuery plugin
  3. // v 1.1.x
  4. // Dual licensed under the MIT and GPL licenses.
  5. // ----------------------------------------------------------------------------
  6. // Copyright (C) 2007-2012 Jay Salvat
  7. // http://markitup.jaysalvat.com/
  8. // ----------------------------------------------------------------------------
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. // ----------------------------------------------------------------------------
  27. (function($) {
  28. $.fn.markItUp = function(settings, extraSettings) {
  29. var method, params, options, ctrlKey, shiftKey, altKey; ctrlKey = shiftKey = altKey = false;
  30. if (typeof settings == 'string') {
  31. method = settings;
  32. params = extraSettings;
  33. }
  34. options = { id: '',
  35. nameSpace: '',
  36. root: '',
  37. previewHandler: false,
  38. previewInWindow: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
  39. previewInElement: '',
  40. previewAutoRefresh: true,
  41. previewPosition: 'after',
  42. previewTemplatePath: '~/templates/preview.html',
  43. previewParser: false,
  44. previewParserPath: '',
  45. previewParserVar: 'data',
  46. resizeHandle: true,
  47. beforeInsert: '',
  48. afterInsert: '',
  49. onEnter: {},
  50. onShiftEnter: {},
  51. onCtrlEnter: {},
  52. onTab: {},
  53. markupSet: [ { /* set */ } ]
  54. };
  55. $.extend(options, settings, extraSettings);
  56. // compute markItUp! path
  57. if (!options.root) {
  58. $('script').each(function(a, tag) {
  59. miuScript = $(tag).get(0).src.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
  60. if (miuScript !== null) {
  61. options.root = miuScript[1];
  62. }
  63. });
  64. }
  65. // Quick patch to keep compatibility with jQuery 1.9
  66. var uaMatch = function(ua) {
  67. ua = ua.toLowerCase();
  68. var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
  69. /(webkit)[ \/]([\w.]+)/.exec(ua) ||
  70. /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
  71. /(msie) ([\w.]+)/.exec(ua) ||
  72. ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
  73. [];
  74. return {
  75. browser: match[ 1 ] || "",
  76. version: match[ 2 ] || "0"
  77. };
  78. };
  79. var matched = uaMatch( navigator.userAgent );
  80. var browser = {};
  81. if (matched.browser) {
  82. browser[matched.browser] = true;
  83. browser.version = matched.version;
  84. }
  85. if (browser.chrome) {
  86. browser.webkit = true;
  87. } else if (browser.webkit) {
  88. browser.safari = true;
  89. }
  90. return this.each(function() {
  91. var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
  92. clicked, hash, header, footer, previewWindow, template, iFrame, abort;
  93. $$ = $(this);
  94. textarea = this;
  95. levels = [];
  96. abort = false;
  97. scrollPosition = caretPosition = 0;
  98. caretOffset = -1;
  99. options.previewParserPath = localize(options.previewParserPath);
  100. options.previewTemplatePath = localize(options.previewTemplatePath);
  101. if (method) {
  102. switch(method) {
  103. case 'remove':
  104. remove();
  105. break;
  106. case 'insert':
  107. markup(params);
  108. break;
  109. default:
  110. $.error('Method ' + method + ' does not exist on jQuery.markItUp');
  111. }
  112. return;
  113. }
  114. // apply the computed path to ~/
  115. function localize(data, inText) {
  116. if (inText) {
  117. return data.replace(/("|')~\//g, "$1"+options.root);
  118. }
  119. return data.replace(/^~\//, options.root);
  120. }
  121. // init and build editor
  122. function init() {
  123. id = ''; nameSpace = '';
  124. if (options.id) {
  125. id = 'id="'+options.id+'"';
  126. } else if ($$.attr("id")) {
  127. id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
  128. }
  129. if (options.nameSpace) {
  130. nameSpace = 'class="'+options.nameSpace+'"';
  131. }
  132. $$.wrap('<div '+nameSpace+'></div>');
  133. $$.wrap('<div '+id+' class="markItUp"></div>');
  134. $$.wrap('<div class="markItUpContainer"></div>');
  135. $$.addClass("markItUpEditor");
  136. // add the header before the textarea
  137. header = $('<div class="markItUpHeader"></div>').insertBefore($$);
  138. $(dropMenus(options.markupSet)).appendTo(header);
  139. // add the footer after the textarea
  140. footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
  141. // add the resize handle after textarea
  142. if (options.resizeHandle === true && browser.safari !== true) {
  143. resizeHandle = $('<div class="markItUpResizeHandle"></div>')
  144. .insertAfter($$)
  145. .bind("mousedown.markItUp", function(e) {
  146. var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
  147. mouseMove = function(e) {
  148. $$.css("height", Math.max(20, e.clientY+h-y)+"px");
  149. return false;
  150. };
  151. mouseUp = function(e) {
  152. $("html").unbind("mousemove.markItUp", mouseMove).unbind("mouseup.markItUp", mouseUp);
  153. return false;
  154. };
  155. $("html").bind("mousemove.markItUp", mouseMove).bind("mouseup.markItUp", mouseUp);
  156. });
  157. footer.append(resizeHandle);
  158. }
  159. // listen key events
  160. $$.bind('keydown.markItUp', keyPressed).bind('keyup', keyPressed);
  161. // bind an event to catch external calls
  162. $$.bind("insertion.markItUp", function(e, settings) {
  163. if (settings.target !== false) {
  164. get();
  165. }
  166. if (textarea === $.markItUp.focused) {
  167. markup(settings);
  168. }
  169. });
  170. // remember the last focus
  171. $$.bind('focus.markItUp', function() {
  172. $.markItUp.focused = this;
  173. });
  174. if (options.previewInElement) {
  175. refreshPreview();
  176. }
  177. }
  178. // recursively build header with dropMenus from markupset
  179. function dropMenus(markupSet) {
  180. var ul = $('<ul></ul>'), i = 0;
  181. $('li:hover > ul', ul).css('display', 'block');
  182. $.each(markupSet, function() {
  183. var button = this, t = '', title, li, j;
  184. title = (button.key) ? (button.name||'')+' [Ctrl+'+button.key+']' : (button.name||'');
  185. key = (button.key) ? 'accesskey="'+button.key+'"' : '';
  186. if (button.separator) {
  187. li = $('<li class="markItUpSeparator">'+(button.separator||'')+'</li>').appendTo(ul);
  188. } else {
  189. i++;
  190. for (j = levels.length -1; j >= 0; j--) {
  191. t += levels[j]+"-";
  192. }
  193. li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
  194. .bind("contextmenu.markItUp", function() { // prevent contextmenu on mac and allow ctrl+click
  195. return false;
  196. }).bind('click.markItUp', function(e) {
  197. e.preventDefault();
  198. }).bind("focusin.markItUp", function(){
  199. $$.focus();
  200. }).bind('mouseup', function() {
  201. if (button.call) {
  202. eval(button.call)();
  203. }
  204. setTimeout(function() { markup(button) },1);
  205. return false;
  206. }).bind('mouseenter.markItUp', function() {
  207. $('> ul', this).show();
  208. $(document).one('click', function() { // close dropmenu if click outside
  209. $('ul ul', header).hide();
  210. }
  211. );
  212. }).bind('mouseleave.markItUp', function() {
  213. $('> ul', this).hide();
  214. }).appendTo(ul);
  215. if (button.dropMenu) {
  216. levels.push(i);
  217. $(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
  218. }
  219. }
  220. });
  221. levels.pop();
  222. return ul;
  223. }
  224. // markItUp! markups
  225. function magicMarkups(string) {
  226. if (string) {
  227. string = string.toString();
  228. string = string.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
  229. function(x, a) {
  230. var b = a.split('|!|');
  231. if (altKey === true) {
  232. return (b[1] !== undefined) ? b[1] : b[0];
  233. } else {
  234. return (b[1] === undefined) ? "" : b[0];
  235. }
  236. }
  237. );
  238. // [![prompt]!], [![prompt:!:value]!]
  239. string = string.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
  240. function(x, a) {
  241. var b = a.split(':!:');
  242. if (abort === true) {
  243. return false;
  244. }
  245. value = prompt(b[0], (b[1]) ? b[1] : '');
  246. if (value === null) {
  247. abort = true;
  248. }
  249. return value;
  250. }
  251. );
  252. return string;
  253. }
  254. return "";
  255. }
  256. // prepare action
  257. function prepare(action) {
  258. if ($.isFunction(action)) {
  259. action = action(hash);
  260. }
  261. return magicMarkups(action);
  262. }
  263. // build block to insert
  264. function build(string) {
  265. var openWith = prepare(clicked.openWith);
  266. var placeHolder = prepare(clicked.placeHolder);
  267. var replaceWith = prepare(clicked.replaceWith);
  268. var closeWith = prepare(clicked.closeWith);
  269. var openBlockWith = prepare(clicked.openBlockWith);
  270. var closeBlockWith = prepare(clicked.closeBlockWith);
  271. var multiline = clicked.multiline;
  272. if (replaceWith !== "") {
  273. block = openWith + replaceWith + closeWith;
  274. } else if (selection === '' && placeHolder !== '') {
  275. block = openWith + placeHolder + closeWith;
  276. } else {
  277. string = string || selection;
  278. var lines = [string], blocks = [];
  279. if (multiline === true) {
  280. lines = string.split(/\r?\n/);
  281. }
  282. for (var l = 0; l < lines.length; l++) {
  283. line = lines[l];
  284. var trailingSpaces;
  285. if (trailingSpaces = line.match(/ *$/)) {
  286. blocks.push(openWith + line.replace(/ *$/g, '') + closeWith + trailingSpaces);
  287. } else {
  288. blocks.push(openWith + line + closeWith);
  289. }
  290. }
  291. block = blocks.join("\n");
  292. }
  293. block = openBlockWith + block + closeBlockWith;
  294. return { block:block,
  295. openBlockWith:openBlockWith,
  296. openWith:openWith,
  297. replaceWith:replaceWith,
  298. placeHolder:placeHolder,
  299. closeWith:closeWith,
  300. closeBlockWith:closeBlockWith
  301. };
  302. }
  303. // define markup to insert
  304. function markup(button) {
  305. var len, j, n, i;
  306. hash = clicked = button;
  307. get();
  308. $.extend(hash, { line:"",
  309. root:options.root,
  310. textarea:textarea,
  311. selection:(selection||''),
  312. caretPosition:caretPosition,
  313. ctrlKey:ctrlKey,
  314. shiftKey:shiftKey,
  315. altKey:altKey
  316. }
  317. );
  318. // callbacks before insertion
  319. prepare(options.beforeInsert);
  320. prepare(clicked.beforeInsert);
  321. if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
  322. prepare(clicked.beforeMultiInsert);
  323. }
  324. $.extend(hash, { line:1 });
  325. if ((ctrlKey === true && shiftKey === true)) {
  326. lines = selection.split(/\r?\n/);
  327. for (j = 0, n = lines.length, i = 0; i < n; i++) {
  328. if ($.trim(lines[i]) !== '') {
  329. $.extend(hash, { line:++j, selection:lines[i] } );
  330. lines[i] = build(lines[i]).block;
  331. } else {
  332. lines[i] = "";
  333. }
  334. }
  335. string = { block:lines.join('\n')};
  336. start = caretPosition;
  337. len = string.block.length + ((browser.opera) ? n-1 : 0);
  338. } else if (ctrlKey === true) {
  339. string = build(selection);
  340. start = caretPosition + string.openWith.length;
  341. len = string.block.length - string.openWith.length - string.closeWith.length;
  342. len = len - (string.block.match(/ $/) ? 1 : 0);
  343. len -= fixIeBug(string.block);
  344. } else if (shiftKey === true) {
  345. string = build(selection);
  346. start = caretPosition;
  347. len = string.block.length;
  348. len -= fixIeBug(string.block);
  349. } else {
  350. string = build(selection);
  351. start = caretPosition + string.block.length ;
  352. len = 0;
  353. start -= fixIeBug(string.block);
  354. }
  355. if ((selection === '' && string.replaceWith === '')) {
  356. caretOffset += fixOperaBug(string.block);
  357. start = caretPosition + string.openBlockWith.length + string.openWith.length;
  358. len = string.block.length - string.openBlockWith.length - string.openWith.length - string.closeWith.length - string.closeBlockWith.length;
  359. caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
  360. caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
  361. }
  362. $.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );
  363. if (string.block !== selection && abort === false) {
  364. insert(string.block);
  365. set(start, len);
  366. } else {
  367. caretOffset = -1;
  368. }
  369. get();
  370. $.extend(hash, { line:'', selection:selection });
  371. // callbacks after insertion
  372. if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
  373. prepare(clicked.afterMultiInsert);
  374. }
  375. prepare(clicked.afterInsert);
  376. prepare(options.afterInsert);
  377. // refresh preview if opened
  378. if (previewWindow && options.previewAutoRefresh) {
  379. refreshPreview();
  380. }
  381. // reinit keyevent
  382. shiftKey = altKey = ctrlKey = abort = false;
  383. }
  384. // Substract linefeed in Opera
  385. function fixOperaBug(string) {
  386. if (browser.opera) {
  387. return string.length - string.replace(/\n*/g, '').length;
  388. }
  389. return 0;
  390. }
  391. // Substract linefeed in IE
  392. function fixIeBug(string) {
  393. if (browser.msie) {
  394. return string.length - string.replace(/\r*/g, '').length;
  395. }
  396. return 0;
  397. }
  398. // add markup
  399. function insert(block) {
  400. if (document.selection) {
  401. var newSelection = document.selection.createRange();
  402. newSelection.text = block;
  403. } else {
  404. textarea.value = textarea.value.substring(0, caretPosition) + block + textarea.value.substring(caretPosition + selection.length, textarea.value.length);
  405. }
  406. }
  407. // set a selection
  408. function set(start, len) {
  409. if (textarea.createTextRange){
  410. // quick fix to make it work on Opera 9.5
  411. if (browser.opera && browser.version >= 9.5 && len == 0) {
  412. return false;
  413. }
  414. range = textarea.createTextRange();
  415. range.collapse(true);
  416. range.moveStart('character', start);
  417. range.moveEnd('character', len);
  418. range.select();
  419. } else if (textarea.setSelectionRange ){
  420. textarea.setSelectionRange(start, start + len);
  421. }
  422. textarea.scrollTop = scrollPosition;
  423. textarea.focus();
  424. }
  425. // get the selection
  426. function get() {
  427. textarea.focus();
  428. scrollPosition = textarea.scrollTop;
  429. if (document.selection) {
  430. selection = document.selection.createRange().text;
  431. if (browser.msie) { // ie
  432. var range = document.selection.createRange(), rangeCopy = range.duplicate();
  433. rangeCopy.moveToElementText(textarea);
  434. caretPosition = -1;
  435. while(rangeCopy.inRange(range)) {
  436. rangeCopy.moveStart('character');
  437. caretPosition ++;
  438. }
  439. } else { // opera
  440. caretPosition = textarea.selectionStart;
  441. }
  442. } else { // gecko & webkit
  443. caretPosition = textarea.selectionStart;
  444. selection = textarea.value.substring(caretPosition, textarea.selectionEnd);
  445. }
  446. return selection;
  447. }
  448. // open preview window
  449. function preview() {
  450. if (typeof options.previewHandler === 'function') {
  451. previewWindow = true;
  452. } else if (options.previewInElement) {
  453. previewWindow = $(options.previewInElement);
  454. } else if (!previewWindow || previewWindow.closed) {
  455. if (options.previewInWindow) {
  456. previewWindow = window.open('', 'preview', options.previewInWindow);
  457. $(window).unload(function() {
  458. previewWindow.close();
  459. });
  460. } else {
  461. iFrame = $('<iframe class="markItUpPreviewFrame"></iframe>');
  462. if (options.previewPosition == 'after') {
  463. iFrame.insertAfter(footer);
  464. } else {
  465. iFrame.insertBefore(header);
  466. }
  467. previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
  468. }
  469. } else if (altKey === true) {
  470. if (iFrame) {
  471. iFrame.remove();
  472. } else {
  473. previewWindow.close();
  474. }
  475. previewWindow = iFrame = false;
  476. }
  477. if (!options.previewAutoRefresh) {
  478. refreshPreview();
  479. }
  480. if (options.previewInWindow) {
  481. previewWindow.focus();
  482. }
  483. }
  484. // refresh Preview window
  485. function refreshPreview() {
  486. renderPreview();
  487. }
  488. function renderPreview() {
  489. var phtml;
  490. if (options.previewHandler && typeof options.previewHandler === 'function') {
  491. options.previewHandler( $$.val() );
  492. } else if (options.previewParser && typeof options.previewParser === 'function') {
  493. var data = options.previewParser( $$.val() );
  494. writeInPreview(localize(data, 1) );
  495. } else if (options.previewParserPath !== '') {
  496. $.ajax({
  497. type: 'POST',
  498. dataType: 'text',
  499. global: false,
  500. url: options.previewParserPath,
  501. data: options.previewParserVar+'='+encodeURIComponent($$.val()),
  502. success: function(data) {
  503. writeInPreview( localize(data, 1) );
  504. }
  505. });
  506. } else {
  507. if (!template) {
  508. $.ajax({
  509. url: options.previewTemplatePath,
  510. dataType: 'text',
  511. global: false,
  512. success: function(data) {
  513. writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
  514. }
  515. });
  516. }
  517. }
  518. return false;
  519. }
  520. function writeInPreview(data) {
  521. if (options.previewInElement) {
  522. $(options.previewInElement).html(data);
  523. } else if (previewWindow && previewWindow.document) {
  524. try {
  525. sp = previewWindow.document.documentElement.scrollTop
  526. } catch(e) {
  527. sp = 0;
  528. }
  529. previewWindow.document.open();
  530. previewWindow.document.write(data);
  531. previewWindow.document.close();
  532. previewWindow.document.documentElement.scrollTop = sp;
  533. }
  534. }
  535. // set keys pressed
  536. function keyPressed(e) {
  537. shiftKey = e.shiftKey;
  538. altKey = e.altKey;
  539. ctrlKey = (!(e.altKey && e.ctrlKey)) ? (e.ctrlKey || e.metaKey) : false;
  540. if (e.type === 'keydown') {
  541. if (ctrlKey === true) {
  542. li = $('a[accesskey="'+((e.keyCode == 13) ? '\\n' : String.fromCharCode(e.keyCode))+'"]', header).parent('li');
  543. if (li.length !== 0) {
  544. ctrlKey = false;
  545. setTimeout(function() {
  546. li.triggerHandler('mouseup');
  547. },1);
  548. return false;
  549. }
  550. }
  551. if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
  552. if (ctrlKey === true) { // Enter + Ctrl
  553. ctrlKey = false;
  554. markup(options.onCtrlEnter);
  555. return options.onCtrlEnter.keepDefault;
  556. } else if (shiftKey === true) { // Enter + Shift
  557. shiftKey = false;
  558. markup(options.onShiftEnter);
  559. return options.onShiftEnter.keepDefault;
  560. } else { // only Enter
  561. markup(options.onEnter);
  562. return options.onEnter.keepDefault;
  563. }
  564. }
  565. if (e.keyCode === 9) { // Tab key
  566. if (shiftKey == true || ctrlKey == true || altKey == true) {
  567. return false;
  568. }
  569. if (caretOffset !== -1) {
  570. get();
  571. caretOffset = $$.val().length - caretOffset;
  572. set(caretOffset, 0);
  573. caretOffset = -1;
  574. return false;
  575. } else {
  576. markup(options.onTab);
  577. return options.onTab.keepDefault;
  578. }
  579. }
  580. }
  581. }
  582. function remove() {
  583. $$.unbind(".markItUp").removeClass('markItUpEditor');
  584. $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
  585. $$.data('markItUp', null);
  586. }
  587. init();
  588. });
  589. };
  590. $.fn.markItUpRemove = function() {
  591. return this.each(function() {
  592. $(this).markItUp('remove');
  593. }
  594. );
  595. };
  596. $.markItUp = function(settings) {
  597. var options = { target:false };
  598. $.extend(options, settings);
  599. if (options.target) {
  600. return $(options.target).each(function() {
  601. $(this).focus();
  602. $(this).trigger('insertion', [options]);
  603. });
  604. } else {
  605. $('textarea').trigger('insertion', [options]);
  606. }
  607. };
  608. })(jQuery);