X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3193141f55df20910cf8ba35f9e669d79c90d3f4..75b7209eaa096a8d3bff42fa83eec838791b6f3a:/platforma/static/js/button_scripts.js?ds=inline diff --git a/platforma/static/js/button_scripts.js b/platforma/static/js/button_scripts.js old mode 100644 new mode 100755 index 40f45f6f..4f93d9bd --- a/platforma/static/js/button_scripts.js +++ b/platforma/static/js/button_scripts.js @@ -1,3 +1,32 @@ +(function() { + var slice = Array.prototype.slice; + + function update(array, args) { + var arrayLength = array.length, length = args.length; + while (length--) array[arrayLength + length] = args[length]; + return array; + }; + + function merge(array, args) { + array = slice.call(array, 0); + return update(array, args); + }; + + Function.prototype.bind = function(context) { + if (arguments.length < 2 && typeof arguments[0] === 'undefined') { + return this; + } + var __method = this; + var args = slice.call(arguments, 1); + return function() { + var a = merge(args, arguments); + return __method.apply(context, a); + } + } + +})(); + + function ScriptletCenter() { this.scriptlets = {}; @@ -6,6 +35,7 @@ function ScriptletCenter() { var text = this.XMLEditorSelectedText(context); var start_tag = '<'+params.tag; + var move_cursor = false; for (var attr in params.attrs) { start_tag += ' '+attr+'="' + params.attrs[attr] + '"'; @@ -39,14 +69,23 @@ function ScriptletCenter() output += token; } else { - output = start_tag + end_tag; + if(params.nocontent) { + output = "<"+params.tag +" />"; + } + else { + output = start_tag + end_tag; + move_cursor = true; + } } this.XMLEditorReplaceSelectedText(context, output); - if (text.length == 0) { - this.XMLEditorMoveCursorForward(context, -params.tag.length-3); - } + try { + if (move_cursor) { + this.XMLEditorMoveCursorForward(context, params.tag.length+2); + } + } catch(e) {} + }.bind(this); this.scriptlets['lineregexp'] = function(context, params) { @@ -188,19 +227,19 @@ function ScriptletCenter() } ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) { - return panel.contentView.editor.selection(); + return panel.selection(); }; ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement) { - panel.contentView.editor.replaceSelection(replacement); + panel.replaceSelection(replacement); // Tell XML view that it's data has changed - panel.contentView.editorDataChanged(); + // panel.contentView.editorDataChanged(); }; ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) { - var pos = panel.contentView.editor.cursorPosition(); - panel.contentView.editor.selectLines(pos.line, pos.character + n); + var pos = panel.cursorPosition(); + panel.selectLines(pos.line, pos.character + n); }; var scriptletCenter;