/** * Markup редактор * * @module ls/editor * * @license GNU General Public License, version 2 * @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com} * @author Denis Shakhov */ var ls = ls || {}; ls.editor = ls.editor || {}; ls.editor.markup = (function($) { "use strict"; /** * Дефолтные опции */ var defaults = { sets: { default: { onShiftEnter: {keepDefault:false, replaceWith:'
\n'}, onCtrlEnter: {keepDefault:false, openWith:'\n

', closeWith:'

'}, onTab: {keepDefault:false, replaceWith:' '}, markupSet: [ {name:'H4', className:'editor-h4', openWith:'

', closeWith:'

' }, {name:'H5', className:'editor-h5', openWith:'
', closeWith:'
' }, {name:'H6', className:'editor-h6', openWith:'
', closeWith:'
' }, {separator:'---------------' }, {name: ls.lang.get('panel_b'), className:'editor-bold', key:'B', openWith:'(!(|!|)!)', closeWith:'(!(|!|)!)' }, {name: ls.lang.get('panel_i'), className:'editor-italic', key:'I', openWith:'(!(|!|)!)', closeWith:'(!(|!|)!)' }, {name: ls.lang.get('panel_s'), className:'editor-stroke', key:'S', openWith:'', closeWith:'' }, {name: ls.lang.get('panel_u'), className:'editor-underline', key:'U', openWith:'', closeWith:'' }, {name: ls.lang.get('panel_quote'), className:'editor-quote', key:'Q', replaceWith: function(m) { if (m.selectionOuter) return '
'+m.selectionOuter+'
'; else if (m.selection) return '
'+m.selection+'
'; else return '
' } }, {name: ls.lang.get('panel_code'), className:'editor-code', openWith:'<(!(code|!|codeline)!)>', closeWith:'' }, {separator:'---------------' }, {name: ls.lang.get('panel_list'), className:'editor-ul', openWith:'
  • ', closeWith:'
  • ', multiline: true, openBlockWith:'' }, {name: ls.lang.get('panel_list'), className:'editor-ol', openWith:'
  • ', closeWith:'
  • ', multiline: true, openBlockWith:'
      \n', closeBlockWith:'\n
    ' }, {name: ls.lang.get('panel_list_li'), className:'editor-li', openWith:'
  • ', closeWith:'
  • ' }, {separator:'---------------' }, {name: ls.lang.get('panel_image'), className:'editor-picture', key:'P', beforeInsert: function(h) { jQuery('#modal-image-upload').modal('show'); } }, {name: ls.lang.get('panel_video'), className:'editor-video', replaceWith:'' }, {name: ls.lang.get('panel_url'), className:'editor-link', key:'L', openWith:'', closeWith:'', placeHolder:'Your text to link...' }, {name: ls.lang.get('panel_user'), className:'editor-user', replaceWith:'' }, {separator:'---------------' }, {name: ls.lang.get('panel_clear_tags'), className:'editor-clean', replaceWith: function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } }, {name: ls.lang.get('panel_cut'), className:'editor-cut', replaceWith: function(markitup) { if (markitup.selection) return ''; else return '' }} ] }, light: { onShiftEnter: {keepDefault:false, replaceWith:'
    \n'}, onTab: {keepDefault:false, replaceWith:' '}, markupSet: [ {name: ls.lang.get('panel_b'), className:'editor-bold', key:'B', openWith:'(!(|!|)!)', closeWith:'(!(|!|)!)' }, {name: ls.lang.get('panel_i'), className:'editor-italic', key:'I', openWith:'(!(|!|)!)', closeWith:'(!(|!|)!)' }, {name: ls.lang.get('panel_s'), className:'editor-stroke', key:'S', openWith:'', closeWith:'' }, {name: ls.lang.get('panel_u'), className:'editor-underline', key:'U', openWith:'', closeWith:'' }, {separator:'---------------' }, {name: ls.lang.get('panel_quote'), className:'editor-quote', key:'Q', replaceWith: function(m) { if (m.selectionOuter) return '
    '+m.selectionOuter+'
    '; else if (m.selection) return '
    '+m.selection+'
    '; else return '
    ' } }, {name: ls.lang.get('panel_code'), className:'editor-code', openWith:'<(!(code|!|codeline)!)>', closeWith:'' }, {name: ls.lang.get('panel_image'), className:'editor-picture', key:'P', beforeInsert: function(h) { jQuery('#modal-image-upload').modal('show'); } }, {name: ls.lang.get('panel_url'), className:'editor-link', key:'L', openWith:'', closeWith:'', placeHolder:'Your text to link...' }, {name: ls.lang.get('panel_user'), className:'editor-user', replaceWith:'' }, {separator:'---------------' }, {name: ls.lang.get('panel_clear_tags'), className:'editor-clean', replaceWith: function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } } ] } } }; /** * Инициализация * */ this.init = function(element, set) { var self = this; this.options = $.extend({}, defaults); element.markItUp(this.options.sets[set]); // Справка по разметке редактора $('.js-editor-help-toggle').on('click', function (e) { $(this).parent().next().toggle(); e.preventDefault(); }); $('.js-editor-help').each(function () { var oEditorHelp = $(this), oTargetForm = $('#' + oEditorHelp.data('form-id')); oEditorHelp.find('.js-tags-help-link').on('click', function (e) { if ($(this).data('insert')) { var sTag = $(this).data('insert'); } else { var sTag = $(this).text(); } $.markItUp({ target: oTargetForm, replaceWith: sTag }); e.preventDefault(); }); }); }; /** * Вставка ссылки загруженного изображения в редактор * * @param {String} sUrl Ссылка * @param {String} sAlign Выравнивание * @param {String} sTitle Описание */ this.insertImageUrlToEditor = function(sUrl, sAlign, sTitle) { sAlign = sAlign == 'center' ? 'class="image-center"' : 'align="' + sAlign + '"'; $.markItUp({ replaceWith: '' }); }; return this; }).call(ls.editor.markup || {},jQuery);