/* Redactor v8.0.1 Updated: August 14, 2012 http://redactorjs.com/ Copyright (c) 2009-2012, Imperavi Inc. License: http://redactorjs.com/license/ Usage: $('#content').redactor(); */ // selection var _0xf6db=["(6(){11 49=24;11 14={50:6(8,10){5 10.58(8)\x2692},57:6(8,10){7(8.58!=12){5 8.58(10)\x2616}46{5 8.57(10)}},55:6(8,18,10,20){7(8===10){5 18\x3C=20}7(14.29(8)\x26\x2614.29(10)){5 14.50(8,10)}7(14.29(8)\x26\x26!14.29(10)){5!14.55(10,20,8,18)}7(!14.57(8,10)){5 14.50(8,10)}7(8.47.85\x3C=18){5 40}7(8.47[18]===10){5 0\x3C=20}5 14.50(8.47[18],10)},29:6(61){5(61!=12?61.93==3:40)},81:6(41){11 62=0;88(41=41.59){62++}5 62}};11 4=49.4=(6(){6 4(2){24.2=2}4.34.31=6(){5 4.31(24.2)};4.34.37=6(){5 4.37(24.2)};4.34.38=6(){5 4.38(24.2)};4.34.45=6(){5 4.45(24.2)};4.34.44=6(){5 4.44(24.2)};4.34.52=6(25,26,23,22){5 4.52(24.2,25,26,23,22)};4.34.51=6(){5 4.51(24.2)};5 4})();7(49.35){4.67=43;4.31=6(2){11 9;5(9=2.35())\x26\x26(9.63!=12)\x26\x26(9.36!=12)};4.37=6(2){11 9;7(!((9=2.35())\x26\x26(9.36!=12))){5 12}5[9.36,9.97]};4.38=6(2){11 9;7(!((9=2.35())\x26\x26(9.63!=12))){5 12}5[9.63,9.91]};4.45=6(2){11 8,10,18,20,27,28;7(!4.31(2)){5 12}27=4.37(2),8=27[0],18=27[1];28=4.38(2),10=28[0],20=28[1];7(14.55(8,18,10,20)){5[8,18]}5[10,20]};4.44=6(2){11 8,10,18,20,27,28;7(!4.31(2)){5 12}27=4.37(2),8=27[0],18=27[1];28=4.38(2),10=28[0],20=28[1];7(14.55(8,18,10,20)){5[10,20]}5[8,18]};4.52=6(2,25,26,23,22){11 9=2.35();7(!9){5}7(23==12){23=25}7(22==12){22=26}7(9.60\x26\x269.79){9.60(25,26);9.79(23,22)}46{54=2.15.56();54.106(25,26);54.107(23,22);71{9.73()}80(41){}9.98(54)}};4.51=6(2){71{11 9=2.35();7(!9){5}9.73()}80(41){}}}46 7(49.15.39){11 69=6(42,32,30){11 19,13,21,33,64;13=42.90(\x2789\x27);19=32.103();19.60(30);64=19.77();88(43){64.86(13,13.59);19.82(13);7(!(19.87((30?\x2766\x27:\x2783\x27),32)\x3E0\x26\x26(13.59!=12))){99}}7(19.87((30?\x2766\x27:\x2783\x27),32)===-1\x26\x2613.84){19.74((30?\x27100\x27:\x2778\x27),32);21=13.84;33=19.101.85}46{21=13.48;33=14.81(13)}13.48.72(13);5[21,33]};11 68=6(42,32,30,21,33){11 36,65,19,13,53;53=0;36=14.29(21)?21:21.47[33];65=14.29(21)?21.48:21;7(14.29(21)){53=33}13=42.90(\x2789\x27);65.86(13,36||12);19=42.76.75();19.82(13);13.48.72(13);32.74((30?\x2766\x27:\x2778\x27),19);5 32[30?\x27105\x27:\x27104\x27](\x27102\x27,53)};4.67=43;4.31=6(2){11 17;2.70();7(!2.15.39){5 40}17=2.15.39.56();5 17\x26\x2617.77().15===2.15};4.45=6(2){11 17;2.70();7(!4.31(2)){5 12}17=2.15.39.56();5 69(2.15,17,43)};4.44=6(2){11 17;2.70();7(!4.31(2)){5 12}17=2.15.39.56();5 69(2.15,17,40)};4.37=6(2){5 4.45(2)};4.38=6(2){5 4.44(2)};4.52=6(2,25,26,23,22){7(23==12){23=25}7(22==12){22=26}11 17=2.15.76.75();68(2.15,17,40,23,22);68(2.15,17,43,25,26);5 17.96()};4.51=6(2){5 2.15.39.95()}}46{4.67=40}}).94(24);","|","split","||win||Selection|return|function|if|n1|sel|n2|var|null|cursorNode|Dom|document||range|o1|cursor|o2|node|foco|focn|this|orgn|orgo|_ref|_ref2|isText|bStart|hasSelection|textRange|offset|prototype|getSelection|anchorNode|getOrigin|getFocus|selection|false|e|doc|true|getEnd|getStart|else|childNodes|parentNode|root|isPreceding|clearSelection|setSelection|textOffset|r|isCursorPreceding|createRange|contains|compareDocumentPosition|previousSibling|collapse|d|k|focusNode|parent|anchorParent|StartToStart|supported|moveBoundary|getBoundary|focus|try|removeChild|removeAllRanges|setEndPoint|createTextRange|body|parentElement|EndToEnd|extend|catch|getChildIndex|moveToElementText|StartToEnd|nextSibling|length|insertBefore|compareEndPoints|while|a|createElement|focusOffset|0x02|nodeType|call|empty|select|anchorOffset|addRange|break|EndToStart|text|character|duplicate|moveEnd|moveStart|setStart|setEnd","replace","","\x5Cw+","\x5Cb","g"];eval(function (p,a,c,k,e,d){e=function (c){return c;} ;if(!_0xf6db[5][_0xf6db[4]](/^/,String)){while(c--){d[c]=k[c]||c;} ;k=[function (e){return d[e];} ];e=function (){return _0xf6db[6];} ;c=1;} ;while(c--){if(k[c]){p=p[_0xf6db[4]]( new RegExp(_0xf6db[7]+e(c)+_0xf6db[7],_0xf6db[8]),k[c]);} ;} ;return p;} (_0xf6db[0],10,108,_0xf6db[3][_0xf6db[2]](_0xf6db[1]),0,{})); if (typeof RELANG === 'undefined') { var RELANG = {}; } var RLANG = { html: 'HTML', video: 'Insert Video...', image: 'Insert Image...', table: 'Table', link: 'Link', link_insert: 'Insert Link ...', unlink: 'Unlink', formatting: 'Formatting', paragraph: 'Paragraph', quote: 'Quote', code: 'Code', header1: 'Header 1', header2: 'Header 2', header3: 'Header 3', header4: 'Header 4', bold: 'Bold', italic: 'Italic', fontcolor: 'Font Color', backcolor: 'Back Color', unorderedlist: 'Unordered List', orderedlist: 'Ordered List', outdent: 'Outdent', indent: 'Indent', cancel: 'Cancel', insert: 'Insert', save: 'Save', _delete: 'Delete', insert_table: 'Insert Table...', insert_row_above: 'Add Row Above', insert_row_below: 'Add Row Below', insert_column_left: 'Add Column Left', insert_column_right: 'Add Column Right', delete_column: 'Delete Column', delete_row: 'Delete Row', delete_table: 'Delete Table', rows: 'Rows', columns: 'Columns', add_head: 'Add Head', delete_head: 'Delete Head', title: 'Title', image_position: 'Position', none: 'None', left: 'Left', right: 'Right', image_web_link: 'Image Web Link', text: 'Text', mailto: 'Email', web: 'URL', video_html_code: 'Video Embed Code', file: 'Insert File...', upload: 'Upload', download: 'Download', choose: 'Choose', or_choose: 'Or choose', drop_file_here: 'Drop file here', align_left: 'Align Left', align_center: 'Align Center', align_right: 'Align Right', align_justify: 'Justify', horizontalrule: 'Insert Horizontal Rule', deleted: 'Deleted', anchor: 'Anchor', link_new_tab: 'Open link in new tab' }; // Plugin jQuery.fn.redactor = function(option) { return this.each(function() { var $obj = $(this); var data = $obj.data('redactor'); if (!data) { $obj.data('redactor', (data = new Redactor(this, option))); } }); }; // Initialization var Redactor = function(element, options) { // Element this.$el = $(element); // Lang if (typeof options !== 'undefined' && typeof options.lang !== 'undefined' && options.lang !== 'en' && typeof RELANG[options.lang] !== 'undefined') { RLANG = RELANG[options.lang]; } // Options this.opts = $.extend({ lang: 'en', direction: 'ltr', // ltr or rtl callback: false, // function keyupCallback: false, // function keydownCallback: false, // function execCommandCallback: false, // function focus: false, autoresize: true, fixed: false, source: true, mobile: true, air: false, wym: false, convertLinks: true, convertDivs: false, autosave: false, // false or url interval: 60, // seconds // ================================================================================= // SLATE FIX: Activeadmin integration imageGetJson: '/admin/redactor/pictures', // url (ex. /folder/images.json ) or false imageUpload: '/admin/redactor/pictures', // url // ================================================================================= imageUploadCallback: false, // function fileUpload: false, // url fileUploadCallback: false, // function uploadCrossDomain: false, uploadFields: false, observeImages: true, overlay: true, // modal overlay allowedTags: ["code", "span", "div", "label", "a", "br", "p", "b", "i", "del", "strike", "img", "video", "audio", "iframe", "object", "embed", "param", "blockquote", "mark", "cite", "small", "ul", "ol", "li", "hr", "dl", "dt", "dd", "sup", "sub", "big", "pre", "code", "figure", "figcaption", "strong", "em", "table", "tr", "td", "th", "tbody", "thead", "tfoot", "h1", "h2", "h3", "h4", "h5", "h6"], buttonsCustom: {}, buttonsAdd: [], //=========================================== // SLATE FIX: fontcolor and backcolor removed buttons: ['html', '|', 'formatting', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'image', 'video', 'file', 'table', 'link', '|', 'alignleft', 'aligncenter', 'alignright', 'justify', '|', 'horizontalrule'], airButtons: ['formatting', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent'], colors: [ '#ffffff', '#000000', '#eeece1', '#1f497d', '#4f81bd', '#c0504d', '#9bbb59', '#8064a2', '#4bacc6', '#f79646', '#ffff00', '#f2f2f2', '#7f7f7f', '#ddd9c3', '#c6d9f0', '#dbe5f1', '#f2dcdb', '#ebf1dd', '#e5e0ec', '#dbeef3', '#fdeada', '#fff2ca', '#d8d8d8', '#595959', '#c4bd97', '#8db3e2', '#b8cce4', '#e5b9b7', '#d7e3bc', '#ccc1d9', '#b7dde8', '#fbd5b5', '#ffe694', '#bfbfbf', '#3f3f3f', '#938953', '#548dd4', '#95b3d7', '#d99694', '#c3d69b', '#b2a2c7', '#b7dde8', '#fac08f', '#f2c314', '#a5a5a5', '#262626', '#494429', '#17365d', '#366092', '#953734', '#76923c', '#5f497a', '#92cddc', '#e36c09', '#c09100', '#7f7f7f', '#0c0c0c', '#1d1b10', '#0f243e', '#244061', '#632423', '#4f6128', '#3f3151', '#31859b', '#974806', '#7f6000'], // private allEmptyHtml: '
', buffer: false, visual: true, // modal windows container modal_file: String() + '', modal_image_edit: String() + '' + '' + '' + '' + '' + '' + ' ', modal_image: String() + '' + '' + ' ' + ' ', modal_link: String() + '' + ' ', modal_table: String() + '' + '' + '' + '' + ' ', modal_video: String() + '' + ' ', toolbar: { html: { title: RLANG.html, func: 'toggle' }, formatting: { title: RLANG.formatting, func: 'show', dropdown: { p: { title: RLANG.paragraph, exec: 'formatblock' }, blockquote: { title: RLANG.quote, exec: 'formatblock', className: 'redactor_format_blockquote' }, pre: { title: RLANG.code, exec: 'formatblock', className: 'redactor_format_pre' }, h1: { title: RLANG.header1, exec: 'formatblock', className: 'redactor_format_h1' }, h2: { title: RLANG.header2, exec: 'formatblock', className: 'redactor_format_h2' }, h3: { title: RLANG.header3, exec: 'formatblock', className: 'redactor_format_h3' }, h4: { title: RLANG.header4, exec: 'formatblock', className: 'redactor_format_h4' } } }, bold: { title: RLANG.bold, exec: 'bold' }, italic: { title: RLANG.italic, exec: 'italic' }, deleted: { title: RLANG.deleted, exec: 'strikethrough' }, unorderedlist: { title: '• ' + RLANG.unorderedlist, exec: 'insertunorderedlist' }, orderedlist: { title: '1. ' + RLANG.orderedlist, exec: 'insertorderedlist' }, outdent: { title: '< ' + RLANG.outdent, exec: 'outdent' }, indent: { title: '> ' + RLANG.indent, exec: 'indent' }, image: { title: RLANG.image, func: 'showImage' }, video: { title: RLANG.video, func: 'showVideo' }, file: { title: RLANG.file, func: 'showFile' }, table: { title: RLANG.table, func: 'show', dropdown: { insert_table: { title: RLANG.insert_table, func: 'showTable' }, separator_drop1: { name: 'separator' }, insert_row_above: { title: RLANG.insert_row_above, func: 'insertRowAbove' }, insert_row_below: { title: RLANG.insert_row_below, func: 'insertRowBelow' }, insert_column_left: { title: RLANG.insert_column_left, func: 'insertColumnLeft' }, insert_column_right: { title: RLANG.insert_column_right, func: 'insertColumnRight' }, separator_drop2: { name: 'separator' }, add_head: { title: RLANG.add_head, func: 'addHead' }, delete_head: { title: RLANG.delete_head, func: 'deleteHead' }, separator_drop3: { name: 'separator' }, delete_column: { title: RLANG.delete_column, func: 'deleteColumn' }, delete_row: { title: RLANG.delete_row, func: 'deleteRow' }, delete_table: { title: RLANG.delete_table, func: 'deleteTable' } } }, link: { title: RLANG.link, func: 'show', dropdown: { link: { title: RLANG.link_insert, func: 'showLink' }, unlink: { title: RLANG.unlink, exec: 'unlink' } } }, fontcolor: { title: RLANG.fontcolor, func: 'show' }, backcolor: { title: RLANG.backcolor, func: 'show' }, alignleft: { exec: 'JustifyLeft', title: RLANG.align_left }, aligncenter: { exec: 'JustifyCenter', title: RLANG.align_center }, alignright: { exec: 'JustifyRight', title: RLANG.align_right }, justify: { exec: 'justifyfull', title: RLANG.align_justify }, horizontalrule: { exec: 'inserthorizontalrule', title: RLANG.horizontalrule } } }, options, this.$el.data()); this.dropdowns = []; // Init this.init(); }; // Functionality Redactor.prototype = { // Initialization init: function() { // get dimensions this.height = this.$el.css('height'); this.width = this.$el.css('width'); // mobile if (this.opts.mobile === false && this.isMobile()) { this.build(true); return false; } // extend buttons if (this.opts.air) { this.opts.buttons = this.opts.airButtons; } else if (this.opts.toolbar !== false) { if (this.opts.source === false) { var index = this.opts.buttons.indexOf('html'); var next = this.opts.buttons[index+1]; this.opts.buttons.splice(index, 1); if (typeof next !== 'undefined' && next === '|') { this.opts.buttons.splice(index, 1); } } $.extend(this.opts.toolbar, this.opts.buttonsCustom); $.each(this.opts.buttonsAdd, $.proxy(function(i,s) { this.opts.buttons.push(s); }, this)); } // construct editor this.build(); // air enable this.enableAir(); // toolbar this.buildToolbar(); // paste if (this.isMobile(true) === false) { this.$editor.bind('paste', $.proxy(function(e) { this.setBuffer(); var frag = this.extractContent(); setTimeout($.proxy(function() { var pastedFrag = this.extractContent(); this.$editor.append(frag); this.restoreSelection(); var html = this.getFragmentHtml(pastedFrag); this.pasteCleanUp(html); }, this), 1); }, this)); } // key handlers this.keyup(); this.keydown(); // autosave if (this.opts.autosave !== false) { this.autoSave(); } // observers this.observeImages(); this.observeTables(); // FF fix if ($.browser.mozilla) { document.execCommand('enableObjectResizing', false, false); document.execCommand('enableInlineTableEditing', false, false); } // focus if (this.opts.focus) { this.$editor.focus(); } // fixed if (this.opts.fixed) { this.observeScroll(); $(document).scroll($.proxy(this.observeScroll, this)); } // callback if (typeof this.opts.callback === 'function') { this.opts.callback(this); } }, shortcuts: function(e, cmd) { e.preventDefault(); this.execCommand(cmd, false); }, keyup: function() { this.$editor.keyup($.proxy(function(e) { var key = e.keyCode || e.which; // callback as you type if (typeof this.opts.keyupCallback === 'function') { this.opts.keyupCallback(this, e); } // if empty if (key === 8 || key === 46) { this.observeImages(); return this.formatEmpty(e); } // new line p if (key === 13 && !e.shiftKey && !e.ctrlKey && !e.metaKey) { return this.formatNewLine(e); } this.syncCode(); }, this)); }, keydown: function() { this.$editor.keydown($.proxy(function(e) { var key = e.keyCode || e.which; var parent = this.getParentNode(); var pre = false; var ctrl = e.ctrlKey || e.metaKey; if (parent && $(parent).get(0).tagName === 'PRE') { pre = true; } // callback keydown if (typeof this.opts.keydownCallback === 'function') { this.opts.keydownCallback(this, e); } if (ctrl) { if (key === 90) { if (this.opts.buffer !== false) { e.preventDefault(); this.getBuffer(); } else { this.shortcuts(e, 'undo'); // Ctrl + z } } else if (key === 90 && e.shiftKey) { this.shortcuts(e, 'redo'); // Ctrl + Shift + z } else if (key === 77) { this.shortcuts(e, 'removeFormat'); // Ctrl + m } else if (key === 66) { this.shortcuts(e, 'bold'); // Ctrl + b } else if (key === 73) { this.shortcuts(e, 'italic'); // Ctrl + i } else if (key === 74) { this.shortcuts(e, 'insertunorderedlist'); // Ctrl + j } else if (key === 75) { this.shortcuts(e, 'insertorderedlist'); // Ctrl + k } else if (key === 76) { this.shortcuts(e, 'superscript'); // Ctrl + l } else if (key === 72) { this.shortcuts(e, 'subscript'); // Ctrl + h } } // clear undo buffer if ( !ctrl && key !== 90) { this.opts.buffer = false; } // enter if (pre === true && key === 13) { e.preventDefault(); this.insertNodeAtCaret(document.createTextNode('\r\n')); } // tab if (!e.shiftKey && key === 9) { if (pre === false) { this.shortcuts(e, 'indent'); // Tab } else { e.preventDefault(); this.insertNodeAtCaret(document.createTextNode('\t')); } } else if (e.shiftKey && key === 9 ) { this.shortcuts(e, 'outdent'); // Shift + tab } // safari shift key + enter if ($.browser.webkit && navigator.userAgent.indexOf('Chrome') === -1) { return this.safariShiftKeyEnter(e, key); } }, this)); }, build: function(mobile) { if (mobile !== true) { // container this.$box = $(''); // air box if (this.opts.air) { this.air = $(''); } // editor this.textareamode = true; if (this.$el.get(0).tagName === 'TEXTAREA') { this.$editor = $(''); } else { this.textareamode = false; this.$editor = this.$el; this.$el = $('').css('height', this.height); } this.$editor.addClass('redactor_editor').attr('contenteditable', true).attr('dir', this.opts.direction); if (this.opts.wym === true) { this.$editor.addClass('redactor_editor_wym'); } if (this.opts.autoresize === false) { this.$editor.css('height', this.height); } // hide textarea this.$el.hide(); // append box and frame var html = ''; if (this.textareamode) { // get html html = this.$el.val(); this.$box.insertAfter(this.$el).append(this.$editor).append(this.$el); } else { // get html html = this.$editor.html(); this.$box.insertAfter(this.$editor).append(this.$el).append(this.$editor); } // conver newlines to p html = this.paragraphy(html); // enable this.$editor.html(html); if (this.textareamode === false) { this.syncCode(); } } else { if (this.$el.get(0).tagName !== 'TEXTAREA') { var html = this.$el.val(); var textarea = $('').css('height', this.height).val(html); this.$el.hide(); this.$el.after(textarea); } } }, enableAir: function() { if (this.opts.air === false) { return false; } this.air.hide(); this.$editor.bind('textselect', $.proxy(function(e) { this.showAir(e); }, this)); this.$editor.bind('textunselect', $.proxy(function() { this.air.hide(); }, this)); }, showAir: function(e) { $('.redactor_air').hide(); var width = this.air.innerWidth(); var left = e.clientX; if ($(document).width() < (left + width)) { left = left - width; } this.air.css({ left: left + 'px', top: (e.clientY + $(document).scrollTop() + 14) + 'px' }).show(); }, syncCode: function() { this.$el.val(this.$editor.html()); }, // API functions setCode: function(html) { this.$editor.html(html).focus(); this.syncCode(); }, getCode: function() { if (this.opts.visual) { return this.$editor.html() } else { return this.$el.val(); } }, insertHtml: function(html) { this.execCommand('inserthtml', html); this.observeImages(); }, destroy: function() { var html = this.getCode(); if (this.textareamode) { this.$box.after(this.$el); this.$box.remove(); this.$el.height(this.height).val(html).show(); } else { this.$box.after(this.$editor); this.$box.remove(); this.$editor.removeClass('redactor_editor').removeClass('redactor_editor_wym').attr('contenteditable', false).html(html).show(); } $('.redactor_air').remove(); for (var i = 0; i < this.dropdowns.length; i++) { this.dropdowns[i].remove(); delete(this.dropdowns[i]); } }, // end API functions // OBSERVERS observeImages: function() { if (this.opts.observeImages === false) { return false; } this.$editor.find('img').each($.proxy(function(i,s) { if ($.browser.msie) { $(s).attr('unselectable', 'on'); } this.resizeImage(s); }, this)); }, observeTables: function() { this.$editor.find('table').click($.proxy(this.tableObserver, this)); }, observeScroll: function() { var scrolltop = $(document).scrollTop(); var boxtop = this.$box.offset().top; if (scrolltop > boxtop) { this.fixed = true; this.$toolbar.css({ position: 'fixed', width: '100%', zIndex: 100 }); } else { this.fixed = false; this.$toolbar.css({ position: 'relative', width: 'auto', zIndex: 1 }); } }, // BUFFER setBuffer: function() { this.saveSelection(); this.opts.buffer = this.$editor.html(); }, getBuffer: function() { if (this.opts.buffer === false) { return false; } this.$editor.html(this.opts.buffer); if (!$.browser.msie) { this.restoreSelection(); } this.opts.buffer = false; }, // EXECCOMMAND execCommand: function(cmd, param) { try { var parent; if (cmd === 'inserthtml' && $.browser.msie) { document.selection.createRange().pasteHTML(param); } else if (cmd === 'formatblock' && $.browser.msie) { document.execCommand(cmd, false, '<' + param + '>'); } else if (cmd === 'unlink') { parent = this.getParentNode(); if ($(parent).get(0).tagName === 'A') { $(parent).replaceWith($(parent).text()); } else { document.execCommand(cmd, false, param); } } else if (cmd === 'formatblock' && param === 'blockquote') { parent = this.getParentNode(); if ($(parent).get(0).tagName === 'BLOCKQUOTE') { document.execCommand(cmd, false, 'p'); } else if ($(parent).get(0).tagName === 'P') { var parent2 = $(parent).parent(); if ($(parent2).get(0).tagName === 'BLOCKQUOTE') { var node = $('
' + $(parent).html() + '
'); $(parent2).replaceWith(node); this.setFocusNode(node.get(0)); } else { document.execCommand(cmd, false, param); } } else { document.execCommand(cmd, false, param); } } else if (cmd === 'formatblock' && param === 'pre') { parent = this.getParentNode(); if ($(parent).get(0).tagName === 'PRE') { $(parent).replaceWith('' + $(parent).text() + '
'); } else { document.execCommand(cmd, false, param); } } else { document.execCommand(cmd, false, param); } this.syncCode(); if (this.oldIE()) { this.$editor.focus(); } if (typeof this.opts.execCommandCallback === 'function') { this.opts.execCommandCallback(this, cmd); } if (this.opts.air) { this.air.hide(); } } catch (e) { } }, // FORMAT NEW LINE formatNewLine: function(e) { if ($.browser.webkit) { var parent = this.getParentNode(); if (parent.nodeName === 'DIV' && parent.className === 'redactor_editor') { e.preventDefault(); var element = $(this.getCurrentNode()); if (element.get(0).tagName === 'DIV' && (element.html() === '' || element.html() === '').append(element.clone().get(0).childNodes);
element.replaceWith(newElement);
newElement.html('
');
this.setFocusNode(newElement.get(0));
this.syncCode();
return false;
}
else
{
this.syncCode();
}
// convert links
if (this.opts.convertLinks)
{
this.$editor.linkify();
}
}
else
{
this.syncCode();
return true;
}
}
else
{
this.syncCode();
return true;
}
},
// SAFARI SHIFT KEY + ENTER
safariShiftKeyEnter: function(e, key)
{
if (e.shiftKey && key === 13)
{
e.preventDefault();
var node1 = $('
');
this.insertNodeAtCaret(node1.get(0));
this.syncCode();
return false;
}
else
{
return true;
}
},
// FORMAT EMPTY
formatEmpty: function(e)
{
var html = $.trim(this.$editor.html());
if ($.browser.mozilla)
{
html = html.replace(/
/i, '');
}
if (html === '')
{
e.preventDefault();
var nodehtml = this.opts.allEmptyHtml;
if ($.browser.mozilla)
{
nodehtml = this.opts.mozillaEmptyHtml;
}
var node = $(nodehtml).get(0);
this.$editor.html(node);
this.setFocusNode(node);
this.syncCode();
return false;
}
else
{
this.syncCode();
}
},
// PARAGRAPHY
paragraphy: function (str)
{
str = $.trim(str);
if (str === '')
{
if (!$.browser.mozilla)
{
return this.opts.allEmptyHtml;
}
else
{
return this.opts.mozillaEmptyHtml;
}
}
// convert div to p
if (this.opts.convertDivs)
{
str = str.replace(/
$2
'); } // inner functions var X = function(x, a, b) { return x.replace(new RegExp(a, 'g'), b); }; var R = function(a, b) { return X(str, a, b); }; // block elements var blocks = '(table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|style|script|object|input|param|p|h[1-6])'; str = '' + str; // first paragraph fix 8.0.1
str += '\n';
R('
\\s*
', '\n\n');
R('(<' + blocks + '[^>]*>)', '\n$1');
R('(' + blocks + '>)', '$1\n\n');
R('\r\n|\r', '\n'); // newlines
R('\n\n+', '\n\n'); // remove duplicates
R('\n?((.|\n)+?)$', '
$1
\n'); // including one at the end R('\\s*?
', ''); // remove empty p R('(
'); R('
([^<]+)\\s*?((div|address|form)[^>]*>)', '
$1
$2'); R('\\s*(?' + blocks + '[^>]*>)\\s*
', '$1'); R('(
\\s*(?' + blocks + '[^>]*>)', '$1'); R('(?' + blocks + '[^>]*>)\\s*
', '$1'); R('(?' + blocks + '[^>]*>)\\s*)((.|\n)*?)', function(m0, m1, m2, m3) { return X(m1, '\\\\([\'\"\\\\])', '$1') + X(X(X(m3, '
', '\n'), '
|