diff --git a/plugins/managesieve/codemirror/initeditor.js b/plugins/managesieve/codemirror/initeditor.js deleted file mode 100644 index 315303f09..000000000 --- a/plugins/managesieve/codemirror/initeditor.js +++ /dev/null @@ -1,35 +0,0 @@ -var cmeditor; - -function createErrorElem(msg) -{ - var marker = document.createElement("div"); - marker.style.color = "#822"; - marker.innerHTML = "●"; - marker.title = msg; - return marker; -} - -if (window.rcmail) { - rcmail.addEventListener('init', function(evt) { - var textArea = document.getElementById('rawfiltersettxt'); - if (textArea) { - cmeditor = CodeMirror.fromTextArea(textArea, { - mode: 'sieve', - lineNumbers: true, - gutters: ["CodeMirror-linenumbers", "errorGutter"], - styleActiveLine: true - }); - - // fetching errors from environment and setting the line background - // and a gutter element with the error message accordingly - var errors = rcmail.env.sieve_errors; - if (errors !== undefined) { - errors.forEach(function(err) { - var lineNo = Number(err.line) - 1; - cmeditor.addLineClass(lineNo, 'background', 'line-error'); - cmeditor.setGutterMarker(lineNo, 'errorGutter', createErrorElem(err.msg)); - }); - } - } - }); -} diff --git a/plugins/managesieve/codemirror/overrides.css b/plugins/managesieve/codemirror/overrides.css deleted file mode 100644 index bca349307..000000000 --- a/plugins/managesieve/codemirror/overrides.css +++ /dev/null @@ -1,11 +0,0 @@ -.CodeMirror { - height: 600px; -} - -.CodeMirror-linebackground.line-error { - background-color: #f66; -} - -.errorGutter { - width: 0.8em; -} \ No newline at end of file diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index df3e77fe8..63aa49c10 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -1309,16 +1309,13 @@ class rcube_sieve_engine 'rows' => '15' )); - $out .= $txtarea->show($script_post !== null ? $script_post : ($script !== false ? $script : '')); + $out .= $txtarea->show($script_post !== null ? $script_post : ($script !== false ? rtrim($script) : '')); $this->rc->output->add_gui_object('sievesetrawform', 'filtersetrawform'); $this->plugin->include_stylesheet('codemirror/lib/codemirror.css'); $this->plugin->include_script('codemirror/lib/codemirror.js'); $this->plugin->include_script('codemirror/addon/selection/active-line.js'); $this->plugin->include_script('codemirror/mode/sieve/sieve.js'); - - $this->plugin->include_script('codemirror/initeditor.js'); - $this->plugin->include_stylesheet('codemirror/overrides.css'); if ($script === false) { $this->rc->output->show_message('managesieve.filterunknownerror', 'error'); diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index 2ab8df4b2..fc4d1c01c 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -53,6 +53,7 @@ if (window.rcmail) { } else if (rcmail.gui_objects.sievesetrawform) { rcmail.enable_command('plugin.managesieve-save', true); + sieve_raw_editor_init(); } else { rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); @@ -1025,6 +1026,53 @@ function sieve_form_init() }); } +/*********************************************************/ +/********* RAW editor methods *********/ +/*********************************************************/ + +var cmeditor; + +function cmCreateErrorElem(msg) +{ + var marker = document.createElement("div"); + marker.style.color = "#822"; + marker.innerHTML = "●"; + marker.title = msg; + + return marker; +} + +function cmScrollToError() +{ + var line = $('.CodeMirror-lines .line-error'), + scroll = $('.CodeMirror-scroll'), + h = line.parent(); + + scroll.scrollTop(line.offset().top - scroll.offset().top - Math.round(scroll.height()/2)); +} + +function sieve_raw_editor_init() +{ + var textArea = document.getElementById('rawfiltersettxt'); + if (textArea && !cmeditor) { + cmeditor = CodeMirror.fromTextArea(textArea, { + mode: 'sieve', + lineNumbers: true, + gutters: ["CodeMirror-linenumbers", "errorGutter"], + styleActiveLine: true + }); + + // fetching errors from environment and setting the line background + // and a gutter element with the error message accordingly + $.each(rcmail.env.sieve_errors || [], function(i, err) { + var lineNo = Number(err.line) - 1; + cmeditor.addLineClass(lineNo, 'background', 'line-error'); + cmeditor.setGutterMarker(lineNo, 'errorGutter', cmCreateErrorElem(err.msg)); + if (!i) cmScrollToError(); + }); + } +} + /*********************************************************/ /********* Mail UI methods *********/ diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index d2f1a9c8f..c8241303c 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -240,9 +240,6 @@ class managesieve extends rcube_plugin // load localization $this->add_texts('localization/', array('filters','managefilters')); - // include main js script - $this->include_script('managesieve.js'); - $engine->saveraw(); } diff --git a/plugins/managesieve/skins/classic/managesieve.css b/plugins/managesieve/skins/classic/managesieve.css index c74bd596e..c442f6fd4 100644 --- a/plugins/managesieve/skins/classic/managesieve.css +++ b/plugins/managesieve/skins/classic/managesieve.css @@ -332,14 +332,6 @@ a.button.disabled vertical-align: middle; } -#filter-form #rawfiltersettxt { - width: 98%; - min-height: 400px; - max-width: none; - font-family: monospace; -} - - /* smart multi-row input field */ .listarea { @@ -444,3 +436,47 @@ body.iframe.mail #filter-form #vacationform input.button { margin-left: 10px; } + +/* RAW editor and CodeMirror overrides */ + +.raweditor textarea { + border: none; + border-radius: 0; + max-width: none !important; + box-shadow: none; + font-family: monospace; + width: 99%; + min-height: 300px; + padding-left: 40px; +} + +.raweditor textarea, +.raweditor .CodeMirror { + position: absolute; + top: 34px; + bottom: 45px; + right: 0; + left: 0; + height: auto; + background-color: #fdfdfd; + border-bottom: 1px solid #eee; +} + +.raweditor .CodeMirror-linebackground.line-error { + background-color: #f00; + opacity: 0.4; +} + +.raweditor .errorGutter { + width: 0.8em; +} + +.raweditor #footer { + position: absolute; + bottom: 5px; +} + +body.iframe.raweditor { + min-width: 100px; + overflow: hidden; +} diff --git a/plugins/managesieve/skins/classic/templates/seteditraw.html b/plugins/managesieve/skins/classic/templates/seteditraw.html index 7e6fa47ac..eda50d75e 100644 --- a/plugins/managesieve/skins/classic/templates/seteditraw.html +++ b/plugins/managesieve/skins/classic/templates/seteditraw.html @@ -4,7 +4,7 @@ <roundcube:object name="pagetitle" /> - +
diff --git a/plugins/managesieve/skins/larry/managesieve.css b/plugins/managesieve/skins/larry/managesieve.css index f5f80c52c..7dca4f8c5 100644 --- a/plugins/managesieve/skins/larry/managesieve.css +++ b/plugins/managesieve/skins/larry/managesieve.css @@ -317,14 +317,6 @@ a.button.disabled vertical-align: middle; max-width: 280px; } - -#filter-form #rawfiltersettxt { - width: 98%; - min-height: 400px; - max-width: none; - font-family: monospace; -} - /* revert larry style button */ #filter-form input.button { @@ -455,3 +447,47 @@ body.iframe.mail #filter-form #vacationform input.button { margin-left: 10px; } + +/* RAW editor and CodeMirror overrides */ + +.raweditor textarea { + border: none; + border-radius: 0; + max-width: none !important; + box-shadow: none; + font-family: monospace; + width: 99%; + min-height: 300px; + padding-left: 40px; +} + +.raweditor textarea, +.raweditor .CodeMirror { + position: absolute; + top: 34px; + bottom: 45px; + right: 0; + left: 0; + height: auto; + background-color: #fdfdfd; + border-bottom: 1px solid #eee; +} + +.raweditor .CodeMirror-linebackground.line-error { + background-color: #f00; + opacity: 0.4; +} + +.raweditor .errorGutter { + width: 0.8em; +} + +.raweditor #footer { + position: absolute; + bottom: 5px; +} + +body.iframe.raweditor { + min-width: 100px; + overflow: hidden; +} diff --git a/plugins/managesieve/skins/larry/templates/seteditraw.html b/plugins/managesieve/skins/larry/templates/seteditraw.html index ba1e91ba5..32128de03 100644 --- a/plugins/managesieve/skins/larry/templates/seteditraw.html +++ b/plugins/managesieve/skins/larry/templates/seteditraw.html @@ -4,7 +4,7 @@ <roundcube:object name="pagetitle" /> - +