From 9796eec71b05ffc9cb963ca8e4954d5fd72ff65d Mon Sep 17 00:00:00 2001 From: Butschster Date: Thu, 23 Oct 2014 15:55:11 +0400 Subject: [PATCH] fix issue #295 --- cms/modules/kodicms/media/js/ace.js | 105 ++++++++++++++-------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/cms/modules/kodicms/media/js/ace.js b/cms/modules/kodicms/media/js/ace.js index 422ba8f00..bd272b1ec 100644 --- a/cms/modules/kodicms/media/js/ace.js +++ b/cms/modules/kodicms/media/js/ace.js @@ -1,112 +1,111 @@ cms.plugins.ace = {}; -cms.plugins.ace.switchOn_handler = function( textarea_id, params ) -{ +cms.plugins.ace.switchOn_handler = function (textarea_id, params) { + var editor_id = getSlug(textarea_id) + 'Div'; var textarea = $('#' + textarea_id).hide(); var height = textarea.data('height') ? textarea.data('height') : 300; var mode = textarea.data('mode') ? textarea.data('mode') : 'php'; - var editArea = $('
') + var editArea = $('
') .insertAfter(textarea) .css({ height: height, fontSize: 14 }); - - var editor = ace.edit(getSlug(textarea_id) + 'Div'); + + var editor = ace.edit(editor_id); editor.setValue(textarea.val()); editor.clearSelection(); - editor.getSession().setMode("ace/mode/" + mode); + editor.getSession().setMode("ace/mode/" + mode); editor.getSession().setTabSize(4); editor.getSession().setUseSoftTabs(false); editor.getSession().setUseWrapMode(true); - editor.getSession().on('change', function(){ + editor.getSession().on('change', function () { textarea.val(editor.getSession().getValue()); }); editor.setTheme("ace/theme/textmate"); - + function fullscreen(editArea, editor, height) { - if(!editArea.data('fullscreen') || editArea.data('fullscreen') == 'off') { + if (!editArea.data('fullscreen') || editArea.data('fullscreen') == 'off') { editArea - .css({ - position: 'fixed', - width: '100%', - height: '100%', - top: 0, left: 0 - }) - .data('fullscreen', 'on') - + .css({ + position: 'fixed', + width: '100%', + height: '100%', + top: 0, left: 0 + }) + .data('fullscreen', 'on') + editor.setTheme("ace/theme/monokai"); } else { editor.setTheme("ace/theme/textmate"); editArea - .data('fullscreen', 'off') - .css({ - position: 'relative', - width: 'auto', - height: height, - top: 'auto', left: 'auto' - }); + .data('fullscreen', 'off') + .css({ + position: 'relative', + width: 'auto', + height: height, + top: 'auto', left: 'auto' + }); } } - - if(textarea.data('readonly') == 'on') { + + if (textarea.data('readonly') == 'on') { editor.setReadOnly(true); } else { editor.commands.addCommand({ - bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, - exec: function(editor) { + bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, + exec: function (editor) { $('button[name="continue"]').click(); } }); - + editor.commands.addCommand({ name: 'Full-screen', - bindKey: {win: 'Ctrl-F', mac: 'Command-F'}, - exec: function(editor) { + bindKey: {win: 'Ctrl-F', mac: 'Command-F'}, + exec: function (editor) { fullscreen(editArea, editor, height) } - }); + }); } - + return editor; }; -// Switch off tinymce handler -cms.plugins.ace.switchOff_handler = function( editor, textarea_id ) -{ - $('#' + textarea_id + 'Div').remove(); +cms.plugins.ace.switchOff_handler = function (editor, textarea_id){ + $('#' + getSlug(textarea_id) + 'Div').remove(); } -cms.plugins.ace.exec_handler = function( editor, command, textarea_id, data ) -{ - switch(command) { +cms.plugins.ace.exec_handler = function (editor, command, textarea_id, data){ + var textarea_id = getSlug(textarea_id); + + switch (command) { case 'insert': editor.insert(data); break; case 'changeHeight': $('#' + textarea_id + 'Div') - .css({ - height: data - }); - + .css({ + height: data + }); + editor.resize(); } - + return true; } -$(function(){ +$(function () { cms.filters - .add( 'ace', cms.plugins.ace.switchOn_handler, cms.plugins.ace.switchOff_handler, cms.plugins.ace.exec_handler ); + .add('ace', cms.plugins.ace.switchOn_handler, cms.plugins.ace.switchOff_handler, cms.plugins.ace.exec_handler); - if($('#highlight_content').length > 0) - cms.filters.switchOn( 'highlight_content', 'ace' ); + if ($('#highlight_content').length > 0) + cms.filters.switchOn('highlight_content', 'ace'); }); -cms.init.add(['layout_edit', 'snippet_edit', 'layout_add', 'snippet_add'], function(){ - $(function(){ - if($('#textarea_content').length > 0) - cms.filters.switchOn( 'textarea_content', 'ace', $('#textarea_content').data()); +cms.init.add(['layout_edit', 'snippet_edit', 'layout_add', 'snippet_add'], function () { + $(function () { + if ($('#textarea_content').length > 0) + cms.filters.switchOn('textarea_content', 'ace', $('#textarea_content').data()); }); }) \ No newline at end of file