From 159b22a974d2d89f0e6c9f4989feda68e9e717f1 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 7 Dec 2017 14:19:42 +0800 Subject: [PATCH] update --- .eslintrc | 157 ++++++++++++++++++ bi/case.js | 56 +++++-- dist/bundle.js | 56 +++++-- dist/case.js | 56 +++++-- src/case/richeditor/bar/action.richeditor.js | 4 + src/case/richeditor/bar/texttoolbar.js | 28 ++-- .../plugins/combo.backgroundcolorchooser.js | 8 +- .../richeditor/plugins/combo.colorchooser.js | 6 + .../richeditor/plugins/combo.sizechooser.js | 10 +- 9 files changed, 325 insertions(+), 56 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..9d3cbf291d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,157 @@ +{ + "extends": "eslint:recommended", + "rules": { + // 声明 + "no-use-before-define": "error", + //禁止定义前使用 + + // 对象 + "no-dupe-keys": "error", + // 禁止在对象字面量中出现重复的键 + "quote-props": [ + "error", + "as-needed" + ], + // 对象属性只在需要的时候加引号 + + // 字符串 + "quotes": [ + "error", + "double", + { + "allowTemplateLiterals": true + } + ], + // 字符串开头和结束使用双引号 + "no-useless-concat": "error", + // 禁止没有必要的字符拼接 + "no-useless-escape": "error", + // 禁用不必要的转义 + + // 函数 + "no-dupe-args": "error", + // 禁止在 function 定义中出现重复的参数 + "space-before-function-paren": "error", + // 函数括号前必须要有空格 + + // 变量 + "no-undef": "error", + // 禁止使用未声明的变量 + + // 比较运算符 & 相等运算符 + "eqeqeq": "error", + // 使用 === 和 !== 代替 == 和 != + "no-unneeded-ternary": "error", + //禁止可以在有更简单的可替代的表达式时使用三元操作符 + + // 条件 + "default-case": "error", + // 要求 Switch 语句中有 Default 分支 + "no-else-return": "error", + // 如果 if 块中包含了一个 return 语句,else 块就成了多余的了。可以将其内容移至块外 + + // 代码块 + "brace-style": [ + "error", + "1tbs", + { + "allowSingleLine": true + } + ], + // 代码块左括号紧跟上一行结束 + "curly": [ + "error", + "multi-line" + ], + // if、else if、else、for、while强制使用大括号,但允许在单行中省略大括号 + + // 注释 + "spaced-comment": "error", + // 注释前有空格 + + // 空白 + "indent": [ + "error", + 4, + { + "SwitchCase": 1 + } + ], + // 缩进控制4空格 + "no-mixed-spaces-and-tabs": "error", + // 禁止使用 空格 和 tab 混合缩进 + "space-before-blocks": [ + "error", + "always" + ], + // 语句块之前的需要有空格 + "space-infix-ops": ["error", { + "int32Hint": false + }], // 要求中缀操作符周围有空格,设置 int32Hint 选项为 true (默认 false) 允许 a|0 不带空格 + "no-trailing-spaces": ["error", { + "skipBlankLines": true + }], // 禁用行尾空格 + "key-spacing": ["error", { + "afterColon": true + }], // 要求在对象字面量的冒号和值之间存在至少有一个空格 + + + // 逗号 + "comma-style": "error", + // 逗号必须放在行末 + "comma-dangle": [ + "error", + "never" + ], + // 多行对象字面量中要求不要拖尾逗号 + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + //在变量声明、数组字面量、对象字面量、函数参数 和 序列中禁止在逗号前使用空格,要求在逗号后使用一个或多个空格 + + + // 分号 + "semi": "error", + //不得省略语句结束的分号 + "semi-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + //禁止分号周围的空格 + "no-extra-semi": "error", + // 禁用不必要的分号 + + + // 类型转换 + "no-extra-boolean-cast": "error", + // 禁止不必要的布尔类型转换 + + + // 其他最佳实践或规范 + "no-unexpected-multiline": "error", + // 禁止使用令人困惑的多行表达式 + "no-unreachable": "error", + // 禁止在 return、throw、continue 和 break 语句后出现不可达代码 + "valid-typeof": "error", + // 强制 typeof 表达式与有效的字符串进行比较 + "no-new-wrappers": "error" + // 禁止通过 new 操作符使用 String、Number 和 Boolean + }, + "globals": { + "window": true, + "$": true, + "WebUI": true, + "BI": true, + "BICst": true, + "Data": true, + "Fix": true, + "module": true + } +} diff --git a/bi/case.js b/bi/case.js index c043705845..109a4b70c5 100644 --- a/bi/case.js +++ b/bi/case.js @@ -9419,6 +9419,10 @@ BI.RichEditorAction = BI.inherit(BI.Widget, { keydown: function () { }, + hideIf: function (e) { + + }, + activate: function () { }, @@ -9552,7 +9556,7 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { {type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_right_button"}, - {type: "bi.rich_editor_param_button"}, + {type: "bi.rich_editor_param_button"} ], height: 28 }); @@ -9561,22 +9565,28 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { _init: function () { BI.RichEditorTextToolbar.superclass._init.apply(this, arguments); var self = this, o = this.options; + var buttons = BI.createWidgets(BI.map(o.buttons, function (i, btn) { + return BI.extend(btn, { + editor: o.editor + }); + })); + this.element.mousedown(function (e) { + BI.each(buttons, function (i, btn) { + btn.hideIf(e); + }); + }); BI.createWidget({ type: "bi.left", element: this, - items: BI.map(o.buttons, function (i, btn) { - return BI.extend(btn, { - editor: o.editor - }); - }), + items: buttons, hgap: 3, vgap: 3 - }) + }); }, mounted: function () { var self = this; - if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框 + if (BI.isIE9Below()) {// IE8下必须要设置unselectable才能不blur输入框 this.element.mousedown(function () { self._noSelect(self.element[0]); }); @@ -9585,15 +9595,15 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { }, _noSelect: function (element) { - if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { - element.setAttribute('unselectable', 'on'); + if (element.setAttribute && element.nodeName.toLowerCase() != "input" && element.nodeName.toLowerCase() != "textarea") { + element.setAttribute("unselectable", "on"); } for (var i = 0; i < element.childNodes.length; i++) { this._noSelect(element.childNodes[i]); } } }); -BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** +BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. @@ -10281,10 +10291,16 @@ BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { }); }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { } }); -BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser);/** +BI.shortcut("bi.rich_editor_background_color_chooser", BI.RichEditorBackgroundColorChooser);/** * 颜色选择 * * Created by GUY on 2015/11/26. @@ -10320,6 +10336,12 @@ BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { this.colorchooser.setValue(""); } @@ -10396,10 +10418,16 @@ BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, { self.doCommand(val); this.hideView(); this.setValue([]); - }) + }); + }, + + hideIf: function (e) { + if(!this.combo.element.find(e.target).length > 0) { + this.combo.hideView(); + } } }); -BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser);/** +BI.shortcut("bi.rich_editor_size_chooser", BI.RichEditorSizeChooser);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. diff --git a/dist/bundle.js b/dist/bundle.js index e8d882c9d3..b965c4090a 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -70881,6 +70881,10 @@ BI.RichEditorAction = BI.inherit(BI.Widget, { keydown: function () { }, + hideIf: function (e) { + + }, + activate: function () { }, @@ -71014,7 +71018,7 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { {type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_right_button"}, - {type: "bi.rich_editor_param_button"}, + {type: "bi.rich_editor_param_button"} ], height: 28 }); @@ -71023,22 +71027,28 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { _init: function () { BI.RichEditorTextToolbar.superclass._init.apply(this, arguments); var self = this, o = this.options; + var buttons = BI.createWidgets(BI.map(o.buttons, function (i, btn) { + return BI.extend(btn, { + editor: o.editor + }); + })); + this.element.mousedown(function (e) { + BI.each(buttons, function (i, btn) { + btn.hideIf(e); + }); + }); BI.createWidget({ type: "bi.left", element: this, - items: BI.map(o.buttons, function (i, btn) { - return BI.extend(btn, { - editor: o.editor - }); - }), + items: buttons, hgap: 3, vgap: 3 - }) + }); }, mounted: function () { var self = this; - if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框 + if (BI.isIE9Below()) {// IE8下必须要设置unselectable才能不blur输入框 this.element.mousedown(function () { self._noSelect(self.element[0]); }); @@ -71047,15 +71057,15 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { }, _noSelect: function (element) { - if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { - element.setAttribute('unselectable', 'on'); + if (element.setAttribute && element.nodeName.toLowerCase() != "input" && element.nodeName.toLowerCase() != "textarea") { + element.setAttribute("unselectable", "on"); } for (var i = 0; i < element.childNodes.length; i++) { this._noSelect(element.childNodes[i]); } } }); -BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** +BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. @@ -71743,10 +71753,16 @@ BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { }); }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { } }); -BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser);/** +BI.shortcut("bi.rich_editor_background_color_chooser", BI.RichEditorBackgroundColorChooser);/** * 颜色选择 * * Created by GUY on 2015/11/26. @@ -71782,6 +71798,12 @@ BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { this.colorchooser.setValue(""); } @@ -71858,10 +71880,16 @@ BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, { self.doCommand(val); this.hideView(); this.setValue([]); - }) + }); + }, + + hideIf: function (e) { + if(!this.combo.element.find(e.target).length > 0) { + this.combo.hideView(); + } } }); -BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser);/** +BI.shortcut("bi.rich_editor_size_chooser", BI.RichEditorSizeChooser);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. diff --git a/dist/case.js b/dist/case.js index c043705845..109a4b70c5 100644 --- a/dist/case.js +++ b/dist/case.js @@ -9419,6 +9419,10 @@ BI.RichEditorAction = BI.inherit(BI.Widget, { keydown: function () { }, + hideIf: function (e) { + + }, + activate: function () { }, @@ -9552,7 +9556,7 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { {type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_right_button"}, - {type: "bi.rich_editor_param_button"}, + {type: "bi.rich_editor_param_button"} ], height: 28 }); @@ -9561,22 +9565,28 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { _init: function () { BI.RichEditorTextToolbar.superclass._init.apply(this, arguments); var self = this, o = this.options; + var buttons = BI.createWidgets(BI.map(o.buttons, function (i, btn) { + return BI.extend(btn, { + editor: o.editor + }); + })); + this.element.mousedown(function (e) { + BI.each(buttons, function (i, btn) { + btn.hideIf(e); + }); + }); BI.createWidget({ type: "bi.left", element: this, - items: BI.map(o.buttons, function (i, btn) { - return BI.extend(btn, { - editor: o.editor - }); - }), + items: buttons, hgap: 3, vgap: 3 - }) + }); }, mounted: function () { var self = this; - if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框 + if (BI.isIE9Below()) {// IE8下必须要设置unselectable才能不blur输入框 this.element.mousedown(function () { self._noSelect(self.element[0]); }); @@ -9585,15 +9595,15 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { }, _noSelect: function (element) { - if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { - element.setAttribute('unselectable', 'on'); + if (element.setAttribute && element.nodeName.toLowerCase() != "input" && element.nodeName.toLowerCase() != "textarea") { + element.setAttribute("unselectable", "on"); } for (var i = 0; i < element.childNodes.length; i++) { this._noSelect(element.childNodes[i]); } } }); -BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** +BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. @@ -10281,10 +10291,16 @@ BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { }); }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { } }); -BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser);/** +BI.shortcut("bi.rich_editor_background_color_chooser", BI.RichEditorBackgroundColorChooser);/** * 颜色选择 * * Created by GUY on 2015/11/26. @@ -10320,6 +10336,12 @@ BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { this.colorchooser.setValue(""); } @@ -10396,10 +10418,16 @@ BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, { self.doCommand(val); this.hideView(); this.setValue([]); - }) + }); + }, + + hideIf: function (e) { + if(!this.combo.element.find(e.target).length > 0) { + this.combo.hideView(); + } } }); -BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser);/** +BI.shortcut("bi.rich_editor_size_chooser", BI.RichEditorSizeChooser);/** * 富文本编辑器 * * Created by GUY on 2017/9/15. diff --git a/src/case/richeditor/bar/action.richeditor.js b/src/case/richeditor/bar/action.richeditor.js index 99b65bcc3e..316c9b71a3 100644 --- a/src/case/richeditor/bar/action.richeditor.js +++ b/src/case/richeditor/bar/action.richeditor.js @@ -65,6 +65,10 @@ BI.RichEditorAction = BI.inherit(BI.Widget, { keydown: function () { }, + hideIf: function (e) { + + }, + activate: function () { }, diff --git a/src/case/richeditor/bar/texttoolbar.js b/src/case/richeditor/bar/texttoolbar.js index ddf8c76a67..1a5b482dcd 100644 --- a/src/case/richeditor/bar/texttoolbar.js +++ b/src/case/richeditor/bar/texttoolbar.js @@ -19,7 +19,7 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { {type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_right_button"}, - {type: "bi.rich_editor_param_button"}, + {type: "bi.rich_editor_param_button"} ], height: 28 }); @@ -28,22 +28,28 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { _init: function () { BI.RichEditorTextToolbar.superclass._init.apply(this, arguments); var self = this, o = this.options; + var buttons = BI.createWidgets(BI.map(o.buttons, function (i, btn) { + return BI.extend(btn, { + editor: o.editor + }); + })); + this.element.mousedown(function (e) { + BI.each(buttons, function (i, btn) { + btn.hideIf(e); + }); + }); BI.createWidget({ type: "bi.left", element: this, - items: BI.map(o.buttons, function (i, btn) { - return BI.extend(btn, { - editor: o.editor - }); - }), + items: buttons, hgap: 3, vgap: 3 - }) + }); }, mounted: function () { var self = this; - if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框 + if (BI.isIE9Below()) {// IE8下必须要设置unselectable才能不blur输入框 this.element.mousedown(function () { self._noSelect(self.element[0]); }); @@ -52,12 +58,12 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { }, _noSelect: function (element) { - if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { - element.setAttribute('unselectable', 'on'); + if (element.setAttribute && element.nodeName.toLowerCase() != "input" && element.nodeName.toLowerCase() != "textarea") { + element.setAttribute("unselectable", "on"); } for (var i = 0; i < element.childNodes.length; i++) { this._noSelect(element.childNodes[i]); } } }); -BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar); \ No newline at end of file +BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar); \ No newline at end of file diff --git a/src/case/richeditor/plugins/combo.backgroundcolorchooser.js b/src/case/richeditor/plugins/combo.backgroundcolorchooser.js index 7090e5d8d7..1fef1b6c67 100644 --- a/src/case/richeditor/plugins/combo.backgroundcolorchooser.js +++ b/src/case/richeditor/plugins/combo.backgroundcolorchooser.js @@ -37,7 +37,13 @@ BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { }); }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { } }); -BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser); \ No newline at end of file +BI.shortcut("bi.rich_editor_background_color_chooser", BI.RichEditorBackgroundColorChooser); \ No newline at end of file diff --git a/src/case/richeditor/plugins/combo.colorchooser.js b/src/case/richeditor/plugins/combo.colorchooser.js index f4fd163355..773f32fea4 100644 --- a/src/case/richeditor/plugins/combo.colorchooser.js +++ b/src/case/richeditor/plugins/combo.colorchooser.js @@ -34,6 +34,12 @@ BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { }, + hideIf: function (e) { + if(!this.colorchooser.element.find(e.target).length > 0) { + this.colorchooser.hideView(); + } + }, + deactivate: function () { this.colorchooser.setValue(""); } diff --git a/src/case/richeditor/plugins/combo.sizechooser.js b/src/case/richeditor/plugins/combo.sizechooser.js index 196fc27a45..5bd52f54d6 100644 --- a/src/case/richeditor/plugins/combo.sizechooser.js +++ b/src/case/richeditor/plugins/combo.sizechooser.js @@ -70,7 +70,13 @@ BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, { self.doCommand(val); this.hideView(); this.setValue([]); - }) + }); + }, + + hideIf: function (e) { + if(!this.combo.element.find(e.target).length > 0) { + this.combo.hideView(); + } } }); -BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser); \ No newline at end of file +BI.shortcut("bi.rich_editor_size_chooser", BI.RichEditorSizeChooser); \ No newline at end of file