From: Radek Czajka Date: Tue, 3 Aug 2010 09:32:09 +0000 (+0200) Subject: better auto-correction X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/852ff1985a45be4a885e7b9f96ce7ef0b5d50c96?hp=--cc better auto-correction --- 852ff1985a45be4a885e7b9f96ce7ef0b5d50c96 diff --git a/apps/toolbar/fixtures/initial_data.yaml b/apps/toolbar/fixtures/initial_data.yaml index 723732d2..c7b5af60 100644 --- a/apps/toolbar/fixtures/initial_data.yaml +++ b/apps/toolbar/fixtures/initial_data.yaml @@ -38,8 +38,8 @@ model: toolbar.buttongroup pk: 17 - fields: - group: [14, 12] accesskey: a + group: [14, 12] label: akapit link: '' params: '{"tag": "akap"}' @@ -49,8 +49,8 @@ model: toolbar.button pk: 39 - fields: - group: [14] accesskey: '' + group: [14] label: akapit cd. link: '' params: '{"tag": "akap_cd"}' @@ -60,8 +60,8 @@ model: toolbar.button pk: 40 - fields: - group: [14] accesskey: d + group: [14] label: akapit dialogowy link: '' params: '{"tag": "akap_dialog"}' @@ -71,8 +71,8 @@ model: toolbar.button pk: 41 - fields: - group: [1] accesskey: '' + group: [1] label: akt link: '' params: '{"tag": "akt"}' @@ -82,8 +82,8 @@ model: toolbar.button pk: 14 - fields: - group: [13] accesskey: '' + group: [13] label: autor link: '' params: '{"tag": "autor_utworu"}' @@ -93,24 +93,25 @@ model: toolbar.button pk: 32 - fields: - group: [2] accesskey: '' + group: [2] label: Podstawowa link: '' params: '[["fulltextregexp", {"exprs": [["\ufeff", ""], ["$[\\s]*\\d+[\\s]*^", - ""], ["-\\s*^", ""], ["\\,\\.\\.|\\.\\,\\.|\\.\\.\\,", "..."]]}], ["lineregexp", - {"exprs": [["^\\s+|\\s+$", ""], ["\\s+", " "], ["(,,)\\s+|\\s+(\")", "$1"], - ["(\\d)[\u2014-](\\d)", "$1--$2"], ["[\u2014]", "---"], ["<(/?)P([aert])", - "<$1p$2"], ["([^\\.])(\\s*)\u2193" link: '' params: '[]' @@ -653,8 +664,8 @@ model: toolbar.button pk: 76 - fields: - group: [15] accesskey: '' + group: [15] label: "tytu\u0142 dzie\u0142a" link: '' params: '{"tag": "tytul_dziela"}' @@ -664,8 +675,8 @@ model: toolbar.button pk: 92 - fields: - group: [15] accesskey: '' + group: [15] label: "tytu\u0142 dzie\u0142a typ 1" link: '' params: '{"tag": "tytul_dziela", "attrs": {"typ": "1"}}' @@ -675,8 +686,8 @@ model: toolbar.button pk: 45 - fields: - group: [27] accesskey: '' + group: [27] label: uwaga link: '' params: '{"tag": "uwaga"}' @@ -686,8 +697,8 @@ model: toolbar.button pk: 51 - fields: - group: [14, 17] accesskey: '' + group: [14, 17] label: wers akap. link: '' params: '{"tag": "wers_akap"}' @@ -697,8 +708,8 @@ model: toolbar.button pk: 83 - fields: - group: [12, 17] accesskey: '' + group: [12, 17] label: wers cd. link: '' params: '{"tag": "wers_cd"}' @@ -708,8 +719,8 @@ model: toolbar.button pk: 85 - fields: - group: [12, 17] accesskey: w + group: [12, 17] label: "wers mocno wci\u0119ty" link: '' params: '{"tag": "wers_wciety", "attrs": {"typ": ""}}' @@ -719,8 +730,8 @@ model: toolbar.button pk: 84 - fields: - group: [12, 17] accesskey: q + group: [12, 17] label: "wers wci\u0119ty" link: '' params: '{"tag": "wers_wciety", "attrs": {"typ": "1"}}' @@ -730,8 +741,8 @@ model: toolbar.button pk: 91 - fields: - group: [15] accesskey: '' + group: [15] label: www link: '' params: '{"tag": "www"}' @@ -741,8 +752,8 @@ model: toolbar.button pk: 48 - fields: - group: [15] accesskey: '' + group: [15] label: "wyr\xF3\u017Cnienie" link: '' params: '{"tag": "wyroznienie"}' @@ -752,8 +763,8 @@ model: toolbar.button pk: 44 - fields: - group: [11] accesskey: '' + group: [11] label: wywiad link: '' params: '{"tag": "wywiad"}' @@ -763,8 +774,8 @@ model: toolbar.button pk: 25 - fields: - group: [21] accesskey: '' + group: [21] label: "wywiad odpowied\u017A" link: '' params: '{"tag": "wywiad_odp"}' @@ -774,8 +785,8 @@ model: toolbar.button pk: 73 - fields: - group: [21] accesskey: '' + group: [21] label: wywiad pytanie link: '' params: '{"tag": "wywiad_pyt"}' @@ -785,21 +796,8 @@ model: toolbar.button pk: 72 - fields: - group: [2] accesskey: '' - label: "Zamie\u0144 dywiz" - link: '' - params: '{"exprs": [["(\\s)-(\\s)", "$1---$2"], ["^(\\s*)-(\\s)", "$1---$2"], - ["(\\s)-(\\s*)$", "$1---$2"], ["(\\d)[\u2014\u2013\u2010-](\\d)", "$1--$2"], - ["\u2014\u2013\u2010", "---"]]}' - scriptlet: lineregexp - slug: zamien_dywiz - tooltip: "Zamienia '\u2014' na '---', oraz '1\u20142' na '1--2'." - model: toolbar.button - pk: 2 -- fields: group: [16] - accesskey: '' label: "zast\u0119pnik wersu" link: '' params: '{"tag": "zastepnik_wersu"}' @@ -892,4 +890,3 @@ \r\n\r\n\r\n\r\n\r\n\r\n\r\npanel.fireEvent('contentChanged');"} model: toolbar.scriptlet pk: insert_stanza - diff --git a/redakcja/static/js/button_scripts.js b/redakcja/static/js/button_scripts.js index 2a585dc5..4aa0c95a 100644 --- a/redakcja/static/js/button_scripts.js +++ b/redakcja/static/js/button_scripts.js @@ -48,9 +48,8 @@ function ScriptletCenter() { this.scriptlets = {}; - this.scriptlets['insert_tag'] = function(context, params, done) + this.scriptlets['insert_tag'] = function(context, params, text, move_forward, done) { - var text = this.XMLEditorSelectedText(context); var start_tag = '<'+params.tag; var move_cursor = false; @@ -95,18 +94,14 @@ function ScriptletCenter() } } - this.XMLEditorReplaceSelectedText(context, output); - - try { - if (move_cursor) { - this.XMLEditorMoveCursorForward(context, params.tag.length+2); - } - } catch(e) {} + if (move_cursor) { + move_forward += params.tag.length+2; + } - done(); + done(output, move_forward); }.bind(this); - this.scriptlets['lineregexp'] = function(context, params, done) { + this.scriptlets['lineregexp'] = function(context, params, text, move_forward, done) { var self = this; var exprs = $.map(params.exprs, function(expr) { @@ -120,8 +115,7 @@ function ScriptletCenter() }); var partial = true; - var text = this.XMLEditorSelectedText(context); - if(!text) return done(); + if(!text) done(text, move_forward); var changed = 0; var lines = text.split('\n'); @@ -138,15 +132,15 @@ function ScriptletCenter() if(old_line != line) changed += 1; return line; }, function(newlines) { - if(changed > 0) { - self.XMLEditorReplaceSelectedText(context, newlines.join('\n') ); - }; + if(changed > 0) { + text = newlines.join('\n'); + }; - done(); + done(text, move_forward); }); }.bind(this); - this.scriptlets['fulltextregexp'] = function(context, params, done) { + this.scriptlets['fulltextregexp'] = function(context, params, text, move_forward, done) { var self = this; var exprs = $.map(params.exprs, function(expr) { @@ -160,47 +154,39 @@ function ScriptletCenter() }; }); - var text = this.XMLEditorSelectedText(context); - if(!text) return done(); + if(!text) done(text, move_forward); var original = text;$ nblck_each(exprs, function(expr, index) { $progress.html(600 + index); text = text.replace(expr.rx, expr.repl); }, function() { - if( original != text) { - self.XMLEditorReplaceSelectedText(context, text); - } - - done(); + done(text, move_forward); }); }.bind(this); - this.scriptlets['macro'] = function(context, params, done) { + this.scriptlets['macro'] = function(context, params, text, move_forward, done) { var self = this; var i = 0; - function next() { + function next(text, move_forward) { if (i < params.length) { var e = params[i]; i = i + 1; - self.scriptlets[e[0]](context, e[1], next); + self.scriptlets[e[0]](context, e[1], text, move_forward, next); } else { - done(); + done(text, move_forward); } }; - next(); + next(text, move_forward); }.bind(this); - this.scriptlets['lowercase'] = function(context, params, done) + this.scriptlets['lowercase'] = function(context, params, text, move_forward, done) { - var text = this.XMLEditorSelectedText(context); - - if(!text) return; + if(!text) done(text, move_forward); - var repl = ''; var lcase = text.toLowerCase(); var ucase = text.toUpperCase(); @@ -214,18 +200,14 @@ function ScriptletCenter() return ''; } }); - repl = words.join(' '); + text = words.join(' '); } - if(repl != text) this.XMLEditorReplaceSelectedText(context, repl); - - done(); + done(text, move_forward); }.bind(this); - this.scriptlets["insert_stanza"] = function(context, params, done) { - var text = this.XMLEditorSelectedText(context); - + this.scriptlets["insert_stanza"] = function(context, params, text, move_forward, done) { if(text) { var verses = text.split('\n'); text = ''; var buf = ''; var ebuf = ''; @@ -243,14 +225,12 @@ function ScriptletCenter() } } text = text + buf + '\n' + ebuf; - this.XMLEditorReplaceSelectedText(context, text); } - - if (!text) { - this.XMLEditorMoveCursorForward(context, params.tag.length + 2); + else { + move_forward += params.tag.length + 2; } - done(); + done(text, move_forward); }.bind(this); } @@ -267,10 +247,20 @@ ScriptletCenter.prototype.callInteractive = function(opts) { $.blockUI({message: $progress, showOverlay: false}); - self.scriptlets[opts.action](opts.context, opts.extra, function(){ + var input = self.XMLEditorSelectedText(opts.context); + self.scriptlets[opts.action](opts.context, opts.extra, input, 0, function(output, move_forward){ /*if(timer) clearTimeout(timer); else */ + if (input != output) { + self.XMLEditorReplaceSelectedText(opts.context, output) + } + if (move_forward) { + try { + self.XMLEditorMoveCursorForward(opts.context, move_forward) + } + catch(e) {} + } $.unblockUI(); // done }); }