From 9d7b550441c1392c229f4eedafbbdf6a14afc2cf Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 19 Sep 2017 19:45:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 73 ++++++++++-- bi/core.js | 53 ++++++++ dist/base.js | 73 ++++++++++-- dist/bundle.js | 126 ++++++++++++++++++-- dist/core.js | 53 ++++++++ src/base/richeditor/niceditor/niceditor.js | 33 ++++- src/base/richeditor/plugins/button.param.js | 40 ++++++- src/core/var.js | 53 ++++++++ 8 files changed, 476 insertions(+), 28 deletions(-) diff --git a/bi/base.js b/bi/base.js index 610b6bf78..8b721b6e7 100644 --- a/bi/base.js +++ b/bi/base.js @@ -16346,7 +16346,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** } this.instanceDoc = document.defaultView; this.elm.element.on('mousedown', BI.bind(this.selected, this)); - this.elm.element.on('keypress', BI.bind(this.keyDown, this)); + this.elm.element.on('keydown', BI.bind(this.keyDown, this)); this.elm.element.on('focus', BI.bind(this.selected, this)); this.elm.element.on('blur', BI.bind(this.blur, this)); this.elm.element.on('keyup', BI.bind(this.selected, this)); @@ -16406,6 +16406,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** this.savedSel = this.getSel(); }, + setFocus: function (el) { + try { + el.focus(); + } catch (e) { + + } + if (!window.getSelection) { + var rng; + try { + el.focus(); + } catch (e) { + + } + rng = document.selection.createRange(); + rng.moveStart('character', -el.innerText.length); + var text = rng.text; + for (var i = 0; i < el.innerText.length; i++) { + if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) { + result = i + 1; + } + } + } else { + var range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } + }, + restoreRng: function () { if (this.savedRange) { this.selRng(this.savedRange, this.savedSel); @@ -16740,14 +16771,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { }); this.param.on(BI.Button.EVENT_CHANGE, function () { var sel = $(o.editor.selectedInstance.selElm()); - var param = "参数" - if (o.editor.instance.getElm().element.find(sel).length <= 0) { - o.editor.instance.getElm().element.append(param); + var param = $("参数").mousedown(function (e) { + e.stopEvent(); + return false; + }); + var wrapper = o.editor.instance.getElm().element; + if (wrapper.find(sel).length <= 0) { + wrapper.append(param); return; } var ln = sel.closest("a"); if (ln.length === 0) { - sel.after(param) + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel.parent().after(param) + } else { + sel.after(param) + } } }); }, @@ -16759,10 +16798,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { key: function (e) { var o = this.options; + var instance = o.editor.selectedInstance; + var wrapper = instance.getElm().element; + var sel = $(instance.selElm()); + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel = sel.parent(); + } + if (BI.Key[e.keyCode]) { + if (sel.attr("data-type") === "param") { + var span = $("").text(BI.Key[e.keyCode]); + if (sel.text() !== BI.Key[e.keyCode]) { + sel.after(span); + sel.text(sel.attr("data-value")); + } else { + sel.after(span); + sel.destroy(); + } + instance.setFocus(span[0]); + } + } if (e.keyCode === BI.KeyCode.BACKSPACE) { - var sel = $(o.editor.selectedInstance.selElm()).parent(); if (sel.attr("data-type") === "param") { - sel.destroy(); + if (sel.text() !== sel.attr("data-value")) { + sel.destroy(); + } } } } diff --git a/bi/core.js b/bi/core.js index c17e6fce5..b10c868e2 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4134,6 +4134,59 @@ _.extend(BI, { emptyFn: function () { }, empty: null, + Key: { + "48": "0", + "49": "1", + "50": "2", + "51": "3", + "52": "4", + "53": "5", + "54": "6", + "55": "7", + "56": "8", + "57": "9", + "65": "a", + "66": "b", + "67": "c", + "68": "d", + "69": "e", + "70": "f", + "71": "g", + "72": "h", + "73": "i", + "74": "j", + "75": "k", + "76": "l", + "77": "m", + "78": "n", + "79": "o", + "80": "p", + "81": "q", + "82": "r", + "83": "s", + "84": "t", + "85": "u", + "86": "v", + "87": "w", + "88": "x", + "89": "y", + "90": "z", + "96": "0", + "97": "1", + "98": "2", + "99": "3", + "100": "4", + "101": "5", + "102": "6", + "103": "7", + "104": "8", + "105": "9", + "106": "*", + "107": "+", + "109": "-", + "110": ".", + "111": "/" + }, KeyCode: { BACKSPACE: 8, COMMA: 188, diff --git a/dist/base.js b/dist/base.js index 426cdc33a..516807807 100644 --- a/dist/base.js +++ b/dist/base.js @@ -16346,7 +16346,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** } this.instanceDoc = document.defaultView; this.elm.element.on('mousedown', BI.bind(this.selected, this)); - this.elm.element.on('keypress', BI.bind(this.keyDown, this)); + this.elm.element.on('keydown', BI.bind(this.keyDown, this)); this.elm.element.on('focus', BI.bind(this.selected, this)); this.elm.element.on('blur', BI.bind(this.blur, this)); this.elm.element.on('keyup', BI.bind(this.selected, this)); @@ -16406,6 +16406,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** this.savedSel = this.getSel(); }, + setFocus: function (el) { + try { + el.focus(); + } catch (e) { + + } + if (!window.getSelection) { + var rng; + try { + el.focus(); + } catch (e) { + + } + rng = document.selection.createRange(); + rng.moveStart('character', -el.innerText.length); + var text = rng.text; + for (var i = 0; i < el.innerText.length; i++) { + if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) { + result = i + 1; + } + } + } else { + var range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } + }, + restoreRng: function () { if (this.savedRange) { this.selRng(this.savedRange, this.savedSel); @@ -16740,14 +16771,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { }); this.param.on(BI.Button.EVENT_CHANGE, function () { var sel = $(o.editor.selectedInstance.selElm()); - var param = "参数" - if (o.editor.instance.getElm().element.find(sel).length <= 0) { - o.editor.instance.getElm().element.append(param); + var param = $("参数").mousedown(function (e) { + e.stopEvent(); + return false; + }); + var wrapper = o.editor.instance.getElm().element; + if (wrapper.find(sel).length <= 0) { + wrapper.append(param); return; } var ln = sel.closest("a"); if (ln.length === 0) { - sel.after(param) + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel.parent().after(param) + } else { + sel.after(param) + } } }); }, @@ -16759,10 +16798,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { key: function (e) { var o = this.options; + var instance = o.editor.selectedInstance; + var wrapper = instance.getElm().element; + var sel = $(instance.selElm()); + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel = sel.parent(); + } + if (BI.Key[e.keyCode]) { + if (sel.attr("data-type") === "param") { + var span = $("").text(BI.Key[e.keyCode]); + if (sel.text() !== BI.Key[e.keyCode]) { + sel.after(span); + sel.text(sel.attr("data-value")); + } else { + sel.after(span); + sel.destroy(); + } + instance.setFocus(span[0]); + } + } if (e.keyCode === BI.KeyCode.BACKSPACE) { - var sel = $(o.editor.selectedInstance.selElm()).parent(); if (sel.attr("data-type") === "param") { - sel.destroy(); + if (sel.text() !== sel.attr("data-value")) { + sel.destroy(); + } } } } diff --git a/dist/bundle.js b/dist/bundle.js index 2e9d8216f..796b8f6e1 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -25045,6 +25045,59 @@ _.extend(BI, { emptyFn: function () { }, empty: null, + Key: { + "48": "0", + "49": "1", + "50": "2", + "51": "3", + "52": "4", + "53": "5", + "54": "6", + "55": "7", + "56": "8", + "57": "9", + "65": "a", + "66": "b", + "67": "c", + "68": "d", + "69": "e", + "70": "f", + "71": "g", + "72": "h", + "73": "i", + "74": "j", + "75": "k", + "76": "l", + "77": "m", + "78": "n", + "79": "o", + "80": "p", + "81": "q", + "82": "r", + "83": "s", + "84": "t", + "85": "u", + "86": "v", + "87": "w", + "88": "x", + "89": "y", + "90": "z", + "96": "0", + "97": "1", + "98": "2", + "99": "3", + "100": "4", + "101": "5", + "102": "6", + "103": "7", + "104": "8", + "105": "9", + "106": "*", + "107": "+", + "109": "-", + "110": ".", + "111": "/" + }, KeyCode: { BACKSPACE: 8, COMMA: 188, @@ -45152,7 +45205,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** } this.instanceDoc = document.defaultView; this.elm.element.on('mousedown', BI.bind(this.selected, this)); - this.elm.element.on('keypress', BI.bind(this.keyDown, this)); + this.elm.element.on('keydown', BI.bind(this.keyDown, this)); this.elm.element.on('focus', BI.bind(this.selected, this)); this.elm.element.on('blur', BI.bind(this.blur, this)); this.elm.element.on('keyup', BI.bind(this.selected, this)); @@ -45212,6 +45265,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** this.savedSel = this.getSel(); }, + setFocus: function (el) { + try { + el.focus(); + } catch (e) { + + } + if (!window.getSelection) { + var rng; + try { + el.focus(); + } catch (e) { + + } + rng = document.selection.createRange(); + rng.moveStart('character', -el.innerText.length); + var text = rng.text; + for (var i = 0; i < el.innerText.length; i++) { + if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) { + result = i + 1; + } + } + } else { + var range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } + }, + restoreRng: function () { if (this.savedRange) { this.selRng(this.savedRange, this.savedSel); @@ -45546,14 +45630,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { }); this.param.on(BI.Button.EVENT_CHANGE, function () { var sel = $(o.editor.selectedInstance.selElm()); - var param = "参数" - if (o.editor.instance.getElm().element.find(sel).length <= 0) { - o.editor.instance.getElm().element.append(param); + var param = $("参数").mousedown(function (e) { + e.stopEvent(); + return false; + }); + var wrapper = o.editor.instance.getElm().element; + if (wrapper.find(sel).length <= 0) { + wrapper.append(param); return; } var ln = sel.closest("a"); if (ln.length === 0) { - sel.after(param) + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel.parent().after(param) + } else { + sel.after(param) + } } }); }, @@ -45565,10 +45657,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { key: function (e) { var o = this.options; + var instance = o.editor.selectedInstance; + var wrapper = instance.getElm().element; + var sel = $(instance.selElm()); + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel = sel.parent(); + } + if (BI.Key[e.keyCode]) { + if (sel.attr("data-type") === "param") { + var span = $("").text(BI.Key[e.keyCode]); + if (sel.text() !== BI.Key[e.keyCode]) { + sel.after(span); + sel.text(sel.attr("data-value")); + } else { + sel.after(span); + sel.destroy(); + } + instance.setFocus(span[0]); + } + } if (e.keyCode === BI.KeyCode.BACKSPACE) { - var sel = $(o.editor.selectedInstance.selElm()).parent(); if (sel.attr("data-type") === "param") { - sel.destroy(); + if (sel.text() !== sel.attr("data-value")) { + sel.destroy(); + } } } } diff --git a/dist/core.js b/dist/core.js index c4fc62cd4..542814184 100644 --- a/dist/core.js +++ b/dist/core.js @@ -24994,6 +24994,59 @@ _.extend(BI, { emptyFn: function () { }, empty: null, + Key: { + "48": "0", + "49": "1", + "50": "2", + "51": "3", + "52": "4", + "53": "5", + "54": "6", + "55": "7", + "56": "8", + "57": "9", + "65": "a", + "66": "b", + "67": "c", + "68": "d", + "69": "e", + "70": "f", + "71": "g", + "72": "h", + "73": "i", + "74": "j", + "75": "k", + "76": "l", + "77": "m", + "78": "n", + "79": "o", + "80": "p", + "81": "q", + "82": "r", + "83": "s", + "84": "t", + "85": "u", + "86": "v", + "87": "w", + "88": "x", + "89": "y", + "90": "z", + "96": "0", + "97": "1", + "98": "2", + "99": "3", + "100": "4", + "101": "5", + "102": "6", + "103": "7", + "104": "8", + "105": "9", + "106": "*", + "107": "+", + "109": "-", + "110": ".", + "111": "/" + }, KeyCode: { BACKSPACE: 8, COMMA: 188, diff --git a/src/base/richeditor/niceditor/niceditor.js b/src/base/richeditor/niceditor/niceditor.js index 8a7031e02..35566cf1a 100644 --- a/src/base/richeditor/niceditor/niceditor.js +++ b/src/base/richeditor/niceditor/niceditor.js @@ -125,7 +125,7 @@ } this.instanceDoc = document.defaultView; this.elm.element.on('mousedown', BI.bind(this.selected, this)); - this.elm.element.on('keypress', BI.bind(this.keyDown, this)); + this.elm.element.on('keydown', BI.bind(this.keyDown, this)); this.elm.element.on('focus', BI.bind(this.selected, this)); this.elm.element.on('blur', BI.bind(this.blur, this)); this.elm.element.on('keyup', BI.bind(this.selected, this)); @@ -185,6 +185,37 @@ this.savedSel = this.getSel(); }, + setFocus: function (el) { + try { + el.focus(); + } catch (e) { + + } + if (!window.getSelection) { + var rng; + try { + el.focus(); + } catch (e) { + + } + rng = document.selection.createRange(); + rng.moveStart('character', -el.innerText.length); + var text = rng.text; + for (var i = 0; i < el.innerText.length; i++) { + if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) { + result = i + 1; + } + } + } else { + var range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } + }, + restoreRng: function () { if (this.savedRange) { this.selRng(this.savedRange, this.savedSel); diff --git a/src/base/richeditor/plugins/button.param.js b/src/base/richeditor/plugins/button.param.js index a242020bb..9d94716a9 100644 --- a/src/base/richeditor/plugins/button.param.js +++ b/src/base/richeditor/plugins/button.param.js @@ -26,14 +26,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { }); this.param.on(BI.Button.EVENT_CHANGE, function () { var sel = $(o.editor.selectedInstance.selElm()); - var param = "参数" - if (o.editor.instance.getElm().element.find(sel).length <= 0) { - o.editor.instance.getElm().element.append(param); + var param = $("参数").mousedown(function (e) { + e.stopEvent(); + return false; + }); + var wrapper = o.editor.instance.getElm().element; + if (wrapper.find(sel).length <= 0) { + wrapper.append(param); return; } var ln = sel.closest("a"); if (ln.length === 0) { - sel.after(param) + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel.parent().after(param) + } else { + sel.after(param) + } } }); }, @@ -45,10 +53,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, { key: function (e) { var o = this.options; + var instance = o.editor.selectedInstance; + var wrapper = instance.getElm().element; + var sel = $(instance.selElm()); + if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) { + sel = sel.parent(); + } + if (BI.Key[e.keyCode]) { + if (sel.attr("data-type") === "param") { + var span = $("").text(BI.Key[e.keyCode]); + if (sel.text() !== BI.Key[e.keyCode]) { + sel.after(span); + sel.text(sel.attr("data-value")); + } else { + sel.after(span); + sel.destroy(); + } + instance.setFocus(span[0]); + } + } if (e.keyCode === BI.KeyCode.BACKSPACE) { - var sel = $(o.editor.selectedInstance.selElm()).parent(); if (sel.attr("data-type") === "param") { - sel.destroy(); + if (sel.text() !== sel.attr("data-value")) { + sel.destroy(); + } } } } diff --git a/src/core/var.js b/src/core/var.js index c5885ed84..ee2334e2e 100644 --- a/src/core/var.js +++ b/src/core/var.js @@ -15,6 +15,59 @@ _.extend(BI, { emptyFn: function () { }, empty: null, + Key: { + "48": "0", + "49": "1", + "50": "2", + "51": "3", + "52": "4", + "53": "5", + "54": "6", + "55": "7", + "56": "8", + "57": "9", + "65": "a", + "66": "b", + "67": "c", + "68": "d", + "69": "e", + "70": "f", + "71": "g", + "72": "h", + "73": "i", + "74": "j", + "75": "k", + "76": "l", + "77": "m", + "78": "n", + "79": "o", + "80": "p", + "81": "q", + "82": "r", + "83": "s", + "84": "t", + "85": "u", + "86": "v", + "87": "w", + "88": "x", + "89": "y", + "90": "z", + "96": "0", + "97": "1", + "98": "2", + "99": "3", + "100": "4", + "101": "5", + "102": "6", + "103": "7", + "104": "8", + "105": "9", + "106": "*", + "107": "+", + "109": "-", + "110": ".", + "111": "/" + }, KeyCode: { BACKSPACE: 8, COMMA: 188, From 4dd721cad60bcce100f43c3474e82e73b1447048 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 19 Sep 2017 21:49:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 340 ++++++++++++++---- dist/base.js | 340 ++++++++++++++---- dist/bundle.js | 340 ++++++++++++++---- dist/bundle.min.js | 76 ++-- ...ton.richeditor.js => action.richeditor.js} | 11 +- .../richeditor/bar/action.richeditor.param.js | 111 ++++++ src/base/richeditor/niceditor/niceditor.js | 22 +- src/base/richeditor/plugins/button.param.js | 53 +-- src/third/jquery.splendid.textchange.js | 145 ++++++++ 9 files changed, 1136 insertions(+), 302 deletions(-) rename src/base/richeditor/bar/{button.richeditor.js => action.richeditor.js} (87%) create mode 100644 src/base/richeditor/bar/action.richeditor.param.js create mode 100644 src/third/jquery.splendid.textchange.js diff --git a/bi/base.js b/bi/base.js index 8b721b6e7..864689b66 100644 --- a/bi/base.js +++ b/bi/base.js @@ -200,6 +200,150 @@ } }));/** + * jQuery "splendid textchange" plugin + * http://benalpert.com/2013/06/18/a-near-perfect-oninput-shim-for-ie-8-and-9.html + * + * (c) 2013 Ben Alpert, released under the MIT license + */ + +(function($) { + + var testNode = document.createElement("input"); + var isInputSupported = "oninput" in testNode && + (!("documentMode" in document) || document.documentMode > 9); + + var hasInputCapabilities = function(elem) { + // The HTML5 spec lists many more types than `text` and `password` on + // which the input event is triggered but none of them exist in IE 8 or + // 9, so we don't check them here. + // TODO: