A tumblelog CMS built on AJAX, PHP and MySQL.

jquery.markitup.js 20KB

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