Browse Source

Merge pull request #142486 in DEC/fineui from master to feature/x

* commit '700c69b9dbd679e056da2eb478eadc8a4731f91b':
  KERNEL-12408:base中eslint的修改
  KERNEL-12408:base中eslint的修改
master
superman 2 years ago
parent
commit
cfcca854b2
  1. 4
      src/base/combination/combo.js
  2. 6
      src/base/combination/switcher.js
  3. 6
      src/base/pager/pager.js
  4. 25
      src/base/single/__test__/text.test.js
  5. 11
      src/base/single/a/__test__/a.test.js
  6. 7
      src/base/single/a/a.js
  7. 19
      src/base/single/bar/bar.loading.js
  8. 18
      src/base/single/button/buttons/__test__/button.test.js
  9. 13
      src/base/single/button/buttons/button.icon.js
  10. 11
      src/base/single/button/buttons/button.image.js
  11. 18
      src/base/single/button/buttons/button.js
  12. 7
      src/base/single/button/buttons/button.text.js
  13. 17
      src/base/single/button/listitem/blankiconicontextitem.js
  14. 17
      src/base/single/button/listitem/blankicontexticonitem.js
  15. 15
      src/base/single/button/listitem/blankicontextitem.js
  16. 15
      src/base/single/button/listitem/icontexticonitem.js
  17. 13
      src/base/single/button/listitem/icontextitem.js
  18. 13
      src/base/single/button/listitem/texticonitem.js
  19. 9
      src/base/single/button/listitem/textitem.js
  20. 14
      src/base/single/editor/editor.textarea.js
  21. 128
      src/base/single/input/file.js

4
src/base/combination/combo.js

@ -95,7 +95,7 @@
element: this, element: this,
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [ items: [
{ el: this.combo, } { el: this.combo }
], ],
})))); }))));
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
@ -160,7 +160,7 @@
this._assertPopupViewRender(); this._assertPopupViewRender();
this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW); this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW);
// popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下
this.popupView.css({ left: -999999999, top: -99999999, }); this.popupView.css({ left: -999999999, top: -99999999 });
this.popupView.visible(); this.popupView.visible();
BI.each(needHideWhenAnotherComboOpen, function (i, combo) { BI.each(needHideWhenAnotherComboOpen, function (i, combo) {
if (i !== self.getName()) { if (i !== self.getName()) {

6
src/base/combination/switcher.js

@ -65,7 +65,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{ el: this.switcher, } { el: this.switcher }
], ],
}); });
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
@ -138,7 +138,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
if (!this._created) { if (!this._created) {
this.popupView = BI.createWidget(o.popup, { this.popupView = BI.createWidget(o.popup, {
type: "bi.button_group", type: "bi.button_group",
element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({ container: this, }, o.masker)), element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({ container: this }, o.masker)),
cls: "switcher-popup", cls: "switcher-popup",
layouts: [{ layouts: [{
type: "bi.vertical", type: "bi.vertical",
@ -159,7 +159,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
element: this, element: this,
items: [ items: [
{ el: this.popupView, } { el: this.popupView }
], ],
}); });
} }

6
src/base/pager/pager.js

@ -158,14 +158,14 @@ BI.Pager = BI.inherit(BI.Widget, {
view.push((function () { view.push((function () {
if (BI.isKey(next)) { if (BI.isKey(next)) {
if (pages === false) { if (pages === false) {
return { text: next, value: "next", disabled: o.hasNext(curr) === false, }; return { text: next, value: "next", disabled: o.hasNext(curr) === false };
} }
return (dict.flow && curr === pages) return (dict.flow && curr === pages)
? ?
{ text: next, value: "next", disabled: true, } { text: next, value: "next", disabled: true }
: :
{ text: next, value: "next", disabled: !(curr !== pages && next || dict.flow), }; { text: next, value: "next", disabled: !(curr !== pages && next || dict.flow) };
} }
return { return {

25
src/base/single/__test__/text.test.js

@ -2,13 +2,12 @@
* Created by windy on 2018/01/23. * Created by windy on 2018/01/23.
*/ */
describe("TextTest", function () { describe("TextTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
it("setText", function () { it("setText", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text" type: "bi.text",
}); });
text.setText("AAA"); text.setText("AAA");
expect(text.element.text()).to.equal("AAA"); expect(text.element.text()).to.equal("AAA");
@ -20,7 +19,7 @@ describe("TextTest", function () {
*/ */
it("setStyle", function () { it("setStyle", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text" type: "bi.text",
}); });
text.setStyle({ "color": "red" }); text.setStyle({ "color": "red" });
expect(text.element.getStyle("color")).to.equal("rgb(255, 0, 0)"); expect(text.element.getStyle("color")).to.equal("rgb(255, 0, 0)");
@ -34,7 +33,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "AAA", text: "AAA",
highLight: true highLight: true,
}); });
expect(text.element.getStyle("color")).to.equal("rgb(54, 133, 242)"); expect(text.element.getStyle("color")).to.equal("rgb(54, 133, 242)");
text.destroy(); text.destroy();
@ -47,7 +46,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
keyword: "A" keyword: "A",
}); });
expect(text.element.children(".bi-keyword-red-mark").length).to.not.equal(0); expect(text.element.children(".bi-keyword-red-mark").length).to.not.equal(0);
text.destroy(); text.destroy();
@ -61,7 +60,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "AAA", text: "AAA",
highLight: true highLight: true,
}); });
text.unHighLight(); text.unHighLight();
expect(text.element.getStyle("color")).to.not.equal("rgb(54, 133, 242)"); expect(text.element.getStyle("color")).to.not.equal("rgb(54, 133, 242)");
@ -75,7 +74,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
keyword: "A" keyword: "A",
}); });
text.unRedMark(); text.unRedMark();
expect(text.element.children(".bi-keyword-red-mark").length).to.equal(0); expect(text.element.children(".bi-keyword-red-mark").length).to.equal(0);
@ -103,7 +102,7 @@ describe("TextTest", function () {
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
vgap: 10, vgap: 10,
hgap: 10 hgap: 10,
}); });
expect(text.element.css("padding")).to.equal("10px"); expect(text.element.css("padding")).to.equal("10px");
text.destroy(); text.destroy();
@ -129,7 +128,7 @@ describe("TextTest", function () {
type: "bi.text", type: "bi.text",
text: "我是A", text: "我是A",
lineHeight: 12, lineHeight: 12,
height: 24 height: 24,
}); });
expect(text.element.css("height")).to.equal("24px"); expect(text.element.css("height")).to.equal("24px");
expect(text.element.css("line-height")).to.equal("12px"); expect(text.element.css("line-height")).to.equal("12px");
@ -145,7 +144,7 @@ describe("TextTest", function () {
text: "我是A", text: "我是A",
handler: function () { handler: function () {
text.setText("handler"); text.setText("handler");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
text.text.element.click(); text.text.element.click();
@ -162,7 +161,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "", text: "",
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal(""); expect(text.element.text()).to.equal("");
text.destroy(); text.destroy();
@ -174,7 +173,7 @@ describe("TextTest", function () {
it("text的value属性1", function () { it("text的value属性1", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal("aaaa"); expect(text.element.text()).to.equal("aaaa");
text.destroy(); text.destroy();
@ -187,7 +186,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: null, text: null,
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal(""); expect(text.element.text()).to.equal("");
text.destroy(); text.destroy();

11
src/base/single/a/__test__/a.test.js

@ -2,16 +2,15 @@
* Created by windy on 2018/01/23. * Created by windy on 2018/01/23.
*/ */
describe("ALinkTest", function () { describe("ALinkTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
it("A初始化测试", function () { it("A初始化测试", function () {
var a = BI.Test.createWidget({ var a = BI.Test.createWidget({
type: "bi.a", type: "bi.a",
text: "CCC" text: "CCC",
}); });
expect(a.element.is('a')).to.equal(true); expect(a.element.is("a")).to.equal(true);
a.destroy(); a.destroy();
}); });
@ -23,10 +22,10 @@ describe("ALinkTest", function () {
type: "bi.a", type: "bi.a",
text: "DDD", text: "DDD",
el: { el: {
type: "bi.label" type: "bi.label",
} },
}); });
expect(a.element.is('a') && a.element.hasClass("bi-label")).to.equal(true); expect(a.element.is("a") && a.element.hasClass("bi-label")).to.equal(true);
a.destroy(); a.destroy();
}); });
}); });

7
src/base/single/a/a.js

@ -9,12 +9,13 @@
BI.A = BI.inherit(BI.Text, { BI.A = BI.inherit(BI.Text, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.A.superclass._defaultConfig.apply(this, arguments); var conf = BI.A.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-a display-block", baseCls: (conf.baseCls || "") + " bi-a display-block",
href: "", href: "",
target: "_blank", target: "_blank",
el: null, el: null,
tagName: "a" tagName: "a",
}); });
}, },
@ -24,10 +25,10 @@ BI.A = BI.inherit(BI.Text, {
this.element.attr({ href: o.href, target: o.target }); this.element.attr({ href: o.href, target: o.target });
if (o.el) { if (o.el) {
BI.createWidget(o.el, { BI.createWidget(o.el, {
element: this element: this,
}); });
} }
} },
}); });
BI.shortcut("bi.a", BI.A); BI.shortcut("bi.a", BI.A);

19
src/base/single/bar/bar.loading.js

@ -6,10 +6,11 @@
BI.LoadingBar = BI.inherit(BI.Single, { BI.LoadingBar = BI.inherit(BI.Single, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.LoadingBar.superclass._defaultConfig.apply(this, arguments); var conf = BI.LoadingBar.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-loading-bar bi-tips", baseCls: (conf.baseCls || "") + " bi-loading-bar bi-tips",
height: 30, height: 30,
handler: BI.emptyFn handler: BI.emptyFn,
}); });
}, },
@ -20,7 +21,7 @@ BI.LoadingBar = BI.inherit(BI.Single, {
cls: "loading-text bi-list-item-simple", cls: "loading-text bi-list-item-simple",
text: BI.i18nText("BI-Load_More"), text: BI.i18nText("BI-Load_More"),
width: 120, width: 120,
handler: this.options.handler handler: this.options.handler,
}); });
this.loaded.on(BI.Controller.EVENT_CHANGE, function (type) { this.loaded.on(BI.Controller.EVENT_CHANGE, function (type) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -30,26 +31,26 @@ BI.LoadingBar = BI.inherit(BI.Single, {
type: "bi.layout", type: "bi.layout",
width: this.options.height, width: this.options.height,
height: this.options.height, height: this.options.height,
cls: "loading-background cursor-default" cls: "loading-background cursor-default",
}); });
var loaded = BI.createWidget({ var loaded = BI.createWidget({
type: "bi.center_adapt", type: "bi.center_adapt",
items: [this.loaded] items: [this.loaded],
}); });
var loading = BI.createWidget({ var loading = BI.createWidget({
type: "bi.center_adapt", type: "bi.center_adapt",
items: [this.loading] items: [this.loading],
}); });
this.cardLayout = BI.createWidget({ this.cardLayout = BI.createWidget({
type: "bi.card", type: "bi.card",
element: this, element: this,
items: [{ items: [{
el: loaded, el: loaded,
cardName: "loaded" cardName: "loaded",
}, { }, {
el: loading, el: loading,
cardName: "loading" cardName: "loading",
}] }],
}); });
this.invisible(); this.invisible();
}, },
@ -74,7 +75,7 @@ BI.LoadingBar = BI.inherit(BI.Single, {
setLoading: function () { setLoading: function () {
this._reset(); this._reset();
this.cardLayout.showCardByName("loading"); this.cardLayout.showCardByName("loading");
} },
}); });
BI.shortcut("bi.loading_bar", BI.LoadingBar); BI.shortcut("bi.loading_bar", BI.LoadingBar);

18
src/base/single/button/buttons/__test__/button.test.js

@ -2,7 +2,6 @@
* Created by windy on 2018/01/23. * Created by windy on 2018/01/23.
*/ */
describe("ButtonTest", function () { describe("ButtonTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -12,7 +11,7 @@ describe("ButtonTest", function () {
text: "CCC", text: "CCC",
handler: function () { handler: function () {
this.setText("click"); this.setText("click");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
button.element.click(); button.element.click();
@ -20,7 +19,6 @@ describe("ButtonTest", function () {
button.destroy(); button.destroy();
done(); done();
}); });
}); });
@ -34,7 +32,7 @@ describe("ButtonTest", function () {
trigger: "mousedown", trigger: "mousedown",
handler: function () { handler: function () {
this.setText("click"); this.setText("click");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
button.element.mousedown(); button.element.mousedown();
@ -42,7 +40,6 @@ describe("ButtonTest", function () {
button.destroy(); button.destroy();
done(); done();
}); });
}); });
/** /**
@ -55,7 +52,7 @@ describe("ButtonTest", function () {
trigger: "mouseup", trigger: "mouseup",
handler: function () { handler: function () {
this.setText("click"); this.setText("click");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
button.element.mousedown(); button.element.mousedown();
@ -64,7 +61,6 @@ describe("ButtonTest", function () {
button.destroy(); button.destroy();
done(); done();
}); });
}); });
/** /**
@ -77,7 +73,7 @@ describe("ButtonTest", function () {
trigger: "dblclick", trigger: "dblclick",
handler: function () { handler: function () {
this.setText("click"); this.setText("click");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
button.element.dblclick(); button.element.dblclick();
@ -85,7 +81,6 @@ describe("ButtonTest", function () {
button.destroy(); button.destroy();
done(); done();
}); });
}); });
/** /**
@ -101,8 +96,8 @@ describe("ButtonTest", function () {
eventName: BI.Button.EVENT_CHANGE, eventName: BI.Button.EVENT_CHANGE,
action: function () { action: function () {
clickNum++; clickNum++;
} },
}] }],
}); });
BI.nextTick(function () { BI.nextTick(function () {
button.element.mousedown(); button.element.mousedown();
@ -112,6 +107,5 @@ describe("ButtonTest", function () {
done(); done();
}, 360); }, 360);
}); });
}); });
}); });

13
src/base/single/button/buttons/button.icon.js

@ -6,6 +6,7 @@
BI.IconButton = BI.inherit(BI.BasicButton, { BI.IconButton = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.IconButton.superclass._defaultConfig.apply(this, arguments); var conf = BI.IconButton.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
_baseCls: (conf._baseCls || "") + " bi-icon-button horizon-center", _baseCls: (conf._baseCls || "") + " bi-icon-button horizon-center",
hgap: 0, hgap: 0,
@ -15,19 +16,19 @@ BI.IconButton = BI.inherit(BI.BasicButton, {
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
iconWidth: null, iconWidth: null,
iconHeight: null iconHeight: null,
}); });
}, },
render: function () { render: function () {
var o = this.options; var o = this.options;
this.element.css({ this.element.css({
textAlign: "center" textAlign: "center",
}); });
this.icon = BI.createWidget({ this.icon = BI.createWidget({
type: "bi.icon", type: "bi.icon",
width: o.iconWidth, width: o.iconWidth,
height: o.iconHeight height: o.iconHeight,
}); });
if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) { if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) {
this.element.css("lineHeight", o.height / BI.pixRatio + BI.pixUnit); this.element.css("lineHeight", o.height / BI.pixRatio + BI.pixUnit);
@ -40,7 +41,7 @@ BI.IconButton = BI.inherit(BI.BasicButton, {
rgap: o.rgap, rgap: o.rgap,
tgap: o.tgap, tgap: o.tgap,
bgap: o.bgap, bgap: o.bgap,
items: [this.icon] items: [this.icon],
}); });
} else { } else {
this.element.css("lineHeight", "1"); this.element.css("lineHeight", "1");
@ -53,7 +54,7 @@ BI.IconButton = BI.inherit(BI.BasicButton, {
rgap: o.rgap, rgap: o.rgap,
tgap: o.tgap, tgap: o.tgap,
bgap: o.bgap, bgap: o.bgap,
items: [this.icon] items: [this.icon],
}); });
} }
}, },
@ -63,7 +64,7 @@ BI.IconButton = BI.inherit(BI.BasicButton, {
if (this.isValid()) { if (this.isValid()) {
this.fireEvent(BI.IconButton.EVENT_CHANGE, this); this.fireEvent(BI.IconButton.EVENT_CHANGE, this);
} }
} },
}); });
BI.IconButton.EVENT_CHANGE = "EVENT_CHANGE"; BI.IconButton.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.icon_button", BI.IconButton); BI.shortcut("bi.icon_button", BI.IconButton);

11
src/base/single/button/buttons/button.image.js

@ -8,11 +8,12 @@
BI.ImageButton = BI.inherit(BI.BasicButton, { BI.ImageButton = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.ImageButton.superclass._defaultConfig.apply(this, arguments); var conf = BI.ImageButton.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-image-button", baseCls: (conf.baseCls || "") + " bi-image-button",
src: "", src: "",
iconWidth: "100%", iconWidth: "100%",
iconHeight: "100%" iconHeight: "100%",
}); });
}, },
@ -22,20 +23,20 @@ BI.ImageButton = BI.inherit(BI.BasicButton, {
type: "bi.img", type: "bi.img",
width: o.iconWidth, width: o.iconWidth,
height: o.iconHeight, height: o.iconHeight,
src: o.src src: o.src,
}); });
if (BI.isNumber(o.iconWidth) || BI.isNumber(o.iconHeight)) { if (BI.isNumber(o.iconWidth) || BI.isNumber(o.iconHeight)) {
BI.createWidget({ BI.createWidget({
type: "bi.center_adapt", type: "bi.center_adapt",
element: this, element: this,
items: [this.image] items: [this.image],
}); });
} else { } else {
BI.createWidget({ BI.createWidget({
type: "bi.adaptive", type: "bi.adaptive",
element: this, element: this,
items: [this.image], items: [this.image],
scrollable: false scrollable: false,
}); });
} }
}, },
@ -80,7 +81,7 @@ BI.ImageButton = BI.inherit(BI.BasicButton, {
if (this.isValid()) { if (this.isValid()) {
this.fireEvent(BI.ImageButton.EVENT_CHANGE, this); this.fireEvent(BI.ImageButton.EVENT_CHANGE, this);
} }
} },
}); });
BI.ImageButton.EVENT_CHANGE = "EVENT_CHANGE"; BI.ImageButton.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.image_button", BI.ImageButton); BI.shortcut("bi.image_button", BI.ImageButton);

18
src/base/single/button/buttons/button.js

@ -16,7 +16,7 @@
BI.Button = BI.inherit(BI.BasicButton, { BI.Button = BI.inherit(BI.BasicButton, {
_const: { _const: {
iconWidth: 18 iconWidth: 18,
}, },
_defaultConfig: function (props) { _defaultConfig: function (props) {
@ -37,7 +37,7 @@
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""), baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""),
attributes: { attributes: {
tabIndex: 1 tabIndex: 1,
}, },
minWidth: clearMinWidth ? 0 : 80, minWidth: clearMinWidth ? 0 : 80,
height: isVertical(props.iconPosition) ? adaptiveHeight : 24, height: isVertical(props.iconPosition) ? adaptiveHeight : 24,
@ -63,7 +63,7 @@
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
iconGap: 0, iconGap: 0,
iconPosition: "left" iconPosition: "left",
}); });
}, },
@ -99,7 +99,7 @@
// 不设置,自定义按钮无法居中 // 不设置,自定义按钮无法居中
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight, iconHeight: o.iconHeight,
invisible: iconInvisible invisible: iconInvisible,
}); });
// 用于 whiteSpace // 用于 whiteSpace
var textWidth = iconInvisible && o.width ? o.width - o.hgap * 2 : null; var textWidth = iconInvisible && o.width ? o.width - o.hgap * 2 : null;
@ -116,14 +116,14 @@
textHeight: textHeight, textHeight: textHeight,
height: lineHeight, height: lineHeight,
value: o.value, value: o.value,
title: null title: null,
}); });
var layoutType = "bi.horizontal"; var layoutType = "bi.horizontal";
var gapContainer = { var gapContainer = {
lgap: o.iconPosition === "left" && o.text ? o.iconGap : 0, lgap: o.iconPosition === "left" && o.text ? o.iconGap : 0,
rgap: o.iconPosition === "right" ? o.iconGap : 0, rgap: o.iconPosition === "right" ? o.iconGap : 0,
tgap: o.iconPosition === "top" ? o.iconGap : 0, tgap: o.iconPosition === "top" ? o.iconGap : 0,
bgap: o.iconPosition === "bottom" ? o.iconGap : 0 bgap: o.iconPosition === "bottom" ? o.iconGap : 0,
}; };
var items = [this.icon, BI.extend({ el: this.text }, gapContainer)]; var items = [this.icon, BI.extend({ el: this.text }, gapContainer)];
if (isVertical(o.iconPosition)) { if (isVertical(o.iconPosition)) {
@ -142,8 +142,8 @@
type: layoutType, type: layoutType,
horizontalAlign: "center", horizontalAlign: "center",
verticalAlign: "middle", verticalAlign: "middle",
items: items items: items,
}] }],
}); });
var classArr = ["block", "clear", "ghost", "plain", "loading", "light"]; var classArr = ["block", "clear", "ghost", "plain", "loading", "light"];
@ -232,7 +232,7 @@
unHighLight: function () { unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
} },
}); });
BI.shortcut("bi.button", BI.Button); BI.shortcut("bi.button", BI.Button);
BI.Button.EVENT_CHANGE = "EVENT_CHANGE"; BI.Button.EVENT_CHANGE = "EVENT_CHANGE";

7
src/base/single/button/buttons/button.text.js

@ -8,6 +8,7 @@
BI.TextButton = BI.inherit(BI.BasicButton, { BI.TextButton = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.TextButton.superclass._defaultConfig.apply(this, arguments); var conf = BI.TextButton.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text-button", baseCls: (conf.baseCls || "") + " bi-text-button",
textAlign: "center", textAlign: "center",
@ -18,7 +19,7 @@ BI.TextButton = BI.inherit(BI.BasicButton, {
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
vgap: 0, vgap: 0,
py: "" py: "",
}); });
}, },
@ -40,7 +41,7 @@ BI.TextButton = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword keyword: o.keyword,
}); });
}, },
@ -83,7 +84,7 @@ BI.TextButton = BI.inherit(BI.BasicButton, {
text = BI.isArray(text) ? text.join(",") : text; text = BI.isArray(text) ? text.join(",") : text;
this.text.setValue(text); this.text.setValue(text);
} }
} },
}); });
BI.TextButton.EVENT_CHANGE = "EVENT_CHANGE"; BI.TextButton.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.text_button", BI.TextButton); BI.shortcut("bi.text_button", BI.TextButton);

17
src/base/single/button/listitem/blankiconicontextitem.js

@ -9,6 +9,7 @@ BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.BlankIconIconTextItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.BlankIconIconTextItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-blank-icon-icon-text-item", baseCls: (conf.baseCls || "") + " bi-blank-icon-icon-text-item",
iconCls1: "", iconCls1: "",
@ -19,7 +20,7 @@ BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -31,21 +32,21 @@ BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
columnSize: [o.blankWidth, o.leftIconWrapperWidth || o.height, o.rightIconWrapperWidth || o.height, "fill"], columnSize: [o.blankWidth, o.leftIconWrapperWidth || o.height, o.rightIconWrapperWidth || o.height, "fill"],
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
width: o.blankWidth width: o.blankWidth,
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls1, cls: o.iconCls1,
width: o.leftIconWrapperWidth || o.height, width: o.leftIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls2, cls: o.iconCls2,
width: o.rightIconWrapperWidth || o.height, width: o.rightIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
@ -60,9 +61,9 @@ BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}] }],
}; };
}, },
@ -111,7 +112,7 @@ BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
unHighLight: function () { unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
} },
}); });
BI.BlankIconIconTextItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.BlankIconIconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.blank_icon_icon_text_item", BI.BlankIconIconTextItem); BI.shortcut("bi.blank_icon_icon_text_item", BI.BlankIconIconTextItem);

17
src/base/single/button/listitem/blankicontexticonitem.js

@ -10,6 +10,7 @@ BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.BlankIconTextIconItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.BlankIconTextIconItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-blank-icon-text-icon-item", baseCls: (conf.baseCls || "") + " bi-blank-icon-text-icon-item",
iconCls1: "", iconCls1: "",
@ -20,7 +21,7 @@ BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -32,14 +33,14 @@ BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
columnSize: [o.blankWidth, o.leftIconWrapperWidth || o.height, "fill", o.rightIconWrapperWidth || o.height], columnSize: [o.blankWidth, o.leftIconWrapperWidth || o.height, "fill", o.rightIconWrapperWidth || o.height],
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
width: o.blankWidth width: o.blankWidth,
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls1, cls: o.iconCls1,
width: o.leftIconWrapperWidth || o.height, width: o.leftIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
@ -54,16 +55,16 @@ BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls2, cls: o.iconCls2,
width: o.rightIconWrapperWidth || o.height, width: o.rightIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}] }],
}; };
}, },
@ -106,7 +107,7 @@ BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
getText: function () { getText: function () {
return this.text.getText(); return this.text.getText();
} },
}); });
BI.BlankIconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.BlankIconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.blank_icon_text_icon_item", BI.BlankIconTextIconItem); BI.shortcut("bi.blank_icon_text_icon_item", BI.BlankIconTextIconItem);

15
src/base/single/button/listitem/blankicontextitem.js

@ -9,6 +9,7 @@ BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.BlankIconTextItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.BlankIconTextItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-blank-icon-text-item", baseCls: (conf.baseCls || "") + " bi-blank-icon-text-item",
blankWidth: 0, blankWidth: 0,
@ -18,7 +19,7 @@ BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -30,14 +31,14 @@ BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
columnSize: [o.blankWidth, o.iconWrapperWidth || o.height, "fill"], columnSize: [o.blankWidth, o.iconWrapperWidth || o.height, "fill"],
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
width: o.blankWidth width: o.blankWidth,
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls, cls: o.iconCls,
width: o.iconWrapperWidth || o.height, width: o.iconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
@ -53,9 +54,9 @@ BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}] }],
}; };
}, },
@ -98,7 +99,7 @@ BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
unHighLight: function () { unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
} },
}); });
BI.BlankIconTextItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.BlankIconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.blank_icon_text_item", BI.BlankIconTextItem); BI.shortcut("bi.blank_icon_text_item", BI.BlankIconTextItem);

15
src/base/single/button/listitem/icontexticonitem.js

@ -10,6 +10,7 @@ BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.IconTextIconItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.IconTextIconItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-icon-text-icon-item", baseCls: (conf.baseCls || "") + " bi-icon-text-icon-item",
iconCls1: "", iconCls1: "",
@ -19,7 +20,7 @@ BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -35,7 +36,7 @@ BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
width: o.leftIconWrapperWidth || o.height, width: o.leftIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
@ -50,16 +51,16 @@ BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls2, cls: o.iconCls2,
width: o.rightIconWrapperWidth || o.height, width: o.rightIconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}] }],
}; };
}, },
@ -102,7 +103,7 @@ BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
getText: function () { getText: function () {
return this.text.getText(); return this.text.getText();
} },
}); });
BI.IconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.IconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.icon_text_icon_item", BI.IconTextIconItem); BI.shortcut("bi.icon_text_icon_item", BI.IconTextIconItem);

13
src/base/single/button/listitem/icontextitem.js

@ -9,6 +9,7 @@ BI.IconTextItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.IconTextItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.IconTextItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-icon-text-item", baseCls: (conf.baseCls || "") + " bi-icon-text-item",
direction: BI.Direction.Left, direction: BI.Direction.Left,
@ -19,7 +20,7 @@ BI.IconTextItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -35,7 +36,7 @@ BI.IconTextItem = BI.inherit(BI.BasicButton, {
width: o.iconWrapperWidth || o.height, width: o.iconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
@ -51,9 +52,9 @@ BI.IconTextItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}] }],
}; };
}, },
@ -96,7 +97,7 @@ BI.IconTextItem = BI.inherit(BI.BasicButton, {
unHighLight: function () { unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
} },
}); });
BI.IconTextItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.IconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.icon_text_item", BI.IconTextItem); BI.shortcut("bi.icon_text_item", BI.IconTextItem);

13
src/base/single/button/listitem/texticonitem.js

@ -10,6 +10,7 @@ BI.TextIconItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.TextIconItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.TextIconItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text-icon-item", baseCls: (conf.baseCls || "") + " bi-text-icon-item",
iconWrapperWidth: null, iconWrapperWidth: null,
@ -19,7 +20,7 @@ BI.TextIconItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -44,16 +45,16 @@ BI.TextIconItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
height: o.height height: o.height,
} },
}, { }, {
type: "bi.icon_label", type: "bi.icon_label",
cls: o.iconCls, cls: o.iconCls,
width: o.iconWrapperWidth || o.height, width: o.iconWrapperWidth || o.height,
height: o.height, height: o.height,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconHeight: o.iconHeight iconHeight: o.iconHeight,
}] }],
}; };
}, },
@ -96,7 +97,7 @@ BI.TextIconItem = BI.inherit(BI.BasicButton, {
unHighLight: function () { unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight.apply(this.text, arguments);
} },
}); });
BI.TextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.TextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.text_icon_item", BI.TextIconItem); BI.shortcut("bi.text_icon_item", BI.TextIconItem);

9
src/base/single/button/listitem/textitem.js

@ -10,6 +10,7 @@ BI.TextItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.TextItem.superclass._defaultConfig.apply(this, arguments); var conf = BI.TextItem.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text-item", baseCls: (conf.baseCls || "") + " bi-text-item",
textAlign: "left", textAlign: "left",
@ -17,7 +18,7 @@ BI.TextItem = BI.inherit(BI.BasicButton, {
textHgap: 0, textHgap: 0,
textVgap: 0, textVgap: 0,
textLgap: 0, textLgap: 0,
textRgap: 0 textRgap: 0,
}); });
}, },
@ -28,7 +29,7 @@ BI.TextItem = BI.inherit(BI.BasicButton, {
element: this, element: this,
textAlign: o.textAlign, textAlign: o.textAlign,
whiteSpace: o.whiteSpace, whiteSpace: o.whiteSpace,
textHeight: o.whiteSpace == "nowrap" ? o.height : o.textHeight, textHeight: o.whiteSpace === "nowrap" ? o.height : o.textHeight,
height: o.height, height: o.height,
hgap: o.textHgap, hgap: o.textHgap,
vgap: o.textVgap, vgap: o.textVgap,
@ -37,7 +38,7 @@ BI.TextItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
keyword: o.keyword, keyword: o.keyword,
py: o.py py: o.py,
}); });
}, },
@ -80,7 +81,7 @@ BI.TextItem = BI.inherit(BI.BasicButton, {
getText: function () { getText: function () {
return this.text.getText(); return this.text.getText();
} },
}); });
BI.TextItem.EVENT_CHANGE = "EVENT_CHANGE"; BI.TextItem.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.text_item", BI.TextItem); BI.shortcut("bi.text_item", BI.TextItem);

14
src/base/single/editor/editor.textarea.js

@ -39,13 +39,13 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
items: [{ items: [{
el: { el: {
type: "bi.adaptive", type: "bi.adaptive",
items: [this.content] items: [this.content],
}, },
left: 4, left: 4,
right: 4, right: 4,
top: 2, top: 2,
bottom: 2 bottom: 2,
}] }],
}); });
this.content.element.on("input propertychange", function (e) { this.content.element.on("input propertychange", function (e) {
@ -139,8 +139,8 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
el: this.watermark, el: this.watermark,
left: 0, left: 0,
top: 0, top: 0,
right: 0 right: 0,
}] }],
}); });
} else { } else {
this.watermark.setText(o.watermark); this.watermark.setText(o.watermark);
@ -221,7 +221,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
this.style = style; this.style = style;
this.element.css(style); this.element.css(style);
this.content.element.css(BI.extend({}, style, { this.content.element.css(BI.extend({}, style, {
color: style.color || BI.DOM.getContrastColor(BI.DOM.isRGBColor(style.backgroundColor) ? BI.DOM.rgb2hex(style.backgroundColor) : style.backgroundColor) color: style.color || BI.DOM.getContrastColor(BI.DOM.isRGBColor(style.backgroundColor) ? BI.DOM.rgb2hex(style.backgroundColor) : style.backgroundColor),
})); }));
}, },
@ -243,7 +243,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
_setEnable: function (b) { _setEnable: function (b) {
BI.TextAreaEditor.superclass._setEnable.apply(this, [b]); BI.TextAreaEditor.superclass._setEnable.apply(this, [b]);
this.content && (this.content.element[0].disabled = !b); this.content && (this.content.element[0].disabled = !b);
} },
}); });
BI.TextAreaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.TextAreaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR";

128
src/base/single/input/file.js

@ -6,24 +6,24 @@
* @extends BI.Single * @extends BI.Single
* @abstract * @abstract
*/ */
(function (document) { ((function (document) {
/** /**
* @description normalize input.files. create if not present, add item method if not present * @description normalize input.files. create if not present, add item method if not present
* @param Object generated wrap object * @param Object generated wrap object
* @return Object the wrap object itself * @return Object the wrap object itself
*/ */
var F = (function (item) { var F = ((function (item) {
return function (input) { return function (input) {
var files = input.files || [input]; var files = input.files || [input];
if (!files.item) { if (!files.item) {
files.item = item; files.item = item;
} }
return files; return files;
}; };
})(function (i) { })(function (i) {
return this[i]; return this[i];
}); }));
var event = { var event = {
@ -37,10 +37,12 @@
add: document.addEventListener ? add: document.addEventListener ?
function (node, name, callback) { function (node, name, callback) {
node.addEventListener(name, callback, false); node.addEventListener(name, callback, false);
return this; return this;
} : } :
function (node, name, callback) { function (node, name, callback) {
node.attachEvent("on" + name, callback); node.attachEvent("on" + name, callback);
return this; return this;
}, },
@ -54,10 +56,12 @@
del: document.removeEventListener ? del: document.removeEventListener ?
function (node, name, callback) { function (node, name, callback) {
node.removeEventListener(name, callback, false); node.removeEventListener(name, callback, false);
return this; return this;
} : } :
function (node, name, callback) { function (node, name, callback) {
node.detachEvent("on" + name, callback); node.detachEvent("on" + name, callback);
return this; return this;
}, },
@ -77,11 +81,16 @@
} }
return false; return false;
} },
}; };
var sendFile = (function (toString) { var sendFile = (function (toString) {
var multipart = function (boundary, name, file) { var split = "onabort.onerror.onloadstart.onprogress".split("."),
length = split.length,
CRLF = "\r\n",
xhr = XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"),
sendFile;
function multipart(boundary, name, file) {
return "--".concat( return "--".concat(
boundary, CRLF, boundary, CRLF,
"Content-Disposition: form-data; name=\"", name, "\"; filename=\"", _global.encodeURIComponent(file.fileName), "\"", CRLF, "Content-Disposition: form-data; name=\"", name, "\"; filename=\"", _global.encodeURIComponent(file.fileName), "\"", CRLF,
@ -90,15 +99,11 @@
file.getAsBinary(), CRLF, file.getAsBinary(), CRLF,
"--", boundary, "--", CRLF "--", boundary, "--", CRLF
); );
}, }
isFunction = function (Function) { function isFunction (Function) {
return toString.call(Function) === "[object Function]"; return toString.call(Function) === "[object Function]";
}, }
split = "onabort.onerror.onloadstart.onprogress".split("."),
length = split.length,
CRLF = "\r\n",
xhr = XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"),
sendFile;
// FireFox 3+, Safari 4 beta (Chrome 2 beta file is buggy and will not work) // FireFox 3+, Safari 4 beta (Chrome 2 beta file is buggy and will not work)
if (xhr.upload || xhr.sendAsBinary) { if (xhr.upload || xhr.sendAsBinary) {
@ -108,6 +113,7 @@
if (isFunction(handler.onerror)) { if (isFunction(handler.onerror)) {
handler.onerror(); handler.onerror();
} }
return; return;
} }
for (var for (var
@ -115,7 +121,7 @@
upload = xhr.upload || { upload = xhr.upload || {
addEventListener: function (event, callback) { addEventListener: function (event, callback) {
this["on" + event] = callback; this["on" + event] = callback;
} },
}, },
i = 0; i = 0;
i < length; i < length;
@ -129,7 +135,7 @@
handler[event](rpe, xhr); handler[event](rpe, xhr);
} }
}; };
})(split[i]), }(split[i])),
false false
); );
} }
@ -187,17 +193,19 @@
rpe.loaded = rpe.total; rpe.loaded = rpe.total;
upload.onprogress(rpe); upload.onprogress(rpe);
if (199 < xhr.status && xhr.status < 400) { if (199 < xhr.status && xhr.status < 400) {
upload["onload"]({}); upload.onload({});
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.file.type.indexOf("image") != -1) { if (handler.file.type.indexOf("image") !== -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
handler.attach_array[current] = attachO; handler.attach_array[current] = attachO;
} else { } else {
upload["onerror"]({}); upload.onerror({});
} }
break; break;
default:
break;
} }
}; };
upload.onloadstart(rpe); upload.onloadstart(rpe);
@ -206,17 +214,19 @@
switch (xhr.readyState) { switch (xhr.readyState) {
case 4: case 4:
var attachO = BI.jsonDecode(xhr.responseText); var attachO = BI.jsonDecode(xhr.responseText);
if (handler.file.type.indexOf("image") != -1) { if (handler.file.type.indexOf("image") !== -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
if (handler.maxLength == 1) { if (handler.maxLength === 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
// handler.attach_array.push(attachO); // handler.attach_array.push(attachO);
} else { } else {
handler.attach_array[current] = attachO; handler.attach_array[current] = attachO;
} }
break; break;
default:
break;
} }
}; };
if (isFunction(upload.onloadstart)) { if (isFunction(upload.onloadstart)) {
@ -235,11 +245,11 @@
form.append("FileData", handler.file); form.append("FileData", handler.file);
xhr.send(form); xhr.send(form);
} }
return handler; return handler;
}; };
} } else {
// Internet Explorer, Opera, others // Internet Explorer, Opera, others
else {
sendFile = function (handler, maxSize, width, height) { sendFile = function (handler, maxSize, width, height) {
var current = handler.current; var current = handler.current;
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"),
@ -251,9 +261,10 @@
if (isFunction(handler.onprogress)) { if (isFunction(handler.onprogress)) {
handler.onprogress(rpe, {}); handler.onprogress(rpe, {});
} }
}, 100) }, 100),
}, },
onload = function () { target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
function onload() {
iframe.onreadystatechange = iframe.onload = iframe.onerror = null; iframe.onreadystatechange = iframe.onload = iframe.onerror = null;
form.parentNode.removeChild(form); form.parentNode.removeChild(form);
form = null; form = null;
@ -262,7 +273,7 @@
try { try {
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML;
var attachO = BI.jsonDecode(responseText); var attachO = BI.jsonDecode(responseText);
if (handler.file.type.indexOf("image") != -1) { if (handler.file.type.indexOf("image") !== -1) {
attachO.attach_type = "image"; attachO.attach_type = "image";
} }
@ -273,7 +284,7 @@
} catch (e) { } catch (e) {
attachO.filename = handler.file.fileName; attachO.filename = handler.file.fileName;
} }
if (handler.maxLength == 1) { if (handler.maxLength === 1) {
handler.attach_array[0] = attachO; handler.attach_array[0] = attachO;
} else { } else {
handler.attach_array[current] = attachO; handler.attach_array[current] = attachO;
@ -286,8 +297,8 @@
if (isFunction(handler.onload)) { if (isFunction(handler.onload)) {
handler.onload(rpe, { responseText: responseText }); handler.onload(rpe, { responseText: responseText });
} }
}, }
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_");
try { // IE < 8 does not accept enctype attribute ... try { // IE < 8 does not accept enctype attribute ...
var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"), var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"),
iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>")); iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>"));
@ -320,8 +331,8 @@
loading: 2, loading: 2,
interactive: 3, interactive: 3,
loaded: 4, loaded: 4,
complete: 4 complete: 4,
}[iframe.readyState] || 1 }[iframe.readyState] || 1,
}); });
} }
}; };
@ -342,13 +353,12 @@
}; };
} }
xhr = null; xhr = null;
return sendFile;
})(Object.prototype.toString);
var sendFiles = function (handler, maxSize, width, height) { return sendFile;
}(Object.prototype.toString));
function sendFiles(handler, maxSize, width, height) {
var length = handler.files.length, var length = handler.files.length,
i = 0,
onload = handler.onload, onload = handler.onload,
onloadstart = handler.onloadstart; onloadstart = handler.onloadstart;
handler.current = 0; handler.current = 0;
@ -401,8 +411,9 @@
} }
}; };
} }
return handler; return handler;
}; }
var r1 = /\.([^.]+)$/; // .png var r1 = /\.([^.]+)$/; // .png
var r2 = /\/([^/]+)$/; // image/png var r2 = /\/([^/]+)$/; // image/png
@ -413,7 +424,7 @@
* @param fileType * @param fileType
* @returns {boolean} * @returns {boolean}
*/ */
var fileTypeValidate = function (fileName, fileType) { function fileTypeValidate(fileName, fileType) {
if (!fileType) { if (!fileType) {
return true; return true;
} }
@ -421,25 +432,29 @@
if (mimes[0] === fileType) { if (mimes[0] === fileType) {
mimes = (fileType + "").split(";"); mimes = (fileType + "").split(";");
} }
return BI.some(mimes, function (index, mime) { return BI.some(mimes, function (index, mime) {
var matches; var matches;
if (matches = mime.match(r1)) { matches = mime.match(r1);
if (matches) {
return fileName.toLowerCase().indexOf(matches[1]) > -1; return fileName.toLowerCase().indexOf(matches[1]) > -1;
} }
if (matches = mime.match(r2)) { matches = mime.match(r2);
if (matches) {
return matches[1] === "*" ? true : fileName.toLowerCase().indexOf(matches[1]) > -1; return matches[1] === "*" ? true : fileName.toLowerCase().indexOf(matches[1]) > -1;
} }
}); });
}; }
BI.File = BI.inherit(BI.Widget, { BI.File = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); var conf = BI.File.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-file display-block", baseCls: (conf.baseCls || "") + " bi-file display-block",
tagName: "input", tagName: "input",
attributes: { attributes: {
type: "file" type: "file",
}, },
name: "", name: "",
url: "", url: "",
@ -452,7 +467,7 @@
}, },
render: function () { render: function () {
var self = this, o = this.options; var o = this.options;
if (o.multiple === true) { if (o.multiple === true) {
this.element.attr("multiple", "multiple"); this.element.attr("multiple", "multiple");
} }
@ -498,7 +513,7 @@
file: this.file, file: this.file,
total: rpe.total, total: rpe.total,
loaded: rpe.loaded, loaded: rpe.loaded,
simulation: rpe.simulation simulation: rpe.simulation,
}); });
}; };
@ -522,12 +537,14 @@
if (200 > xhr.status || xhr.status > 399) { if (200 > xhr.status || xhr.status > 399) {
BI.Msg.toast(BI.i18nText("BI-Upload_File_Error"), { level: "error" }); BI.Msg.toast(BI.i18nText("BI-Upload_File_Error"), { level: "error" });
self.fireEvent(BI.File.EVENT_ERROR); self.fireEvent(BI.File.EVENT_ERROR);
return; return;
} }
var error = BI.some(_wrap.attach_array, function (index, attach) { var error = BI.some(_wrap.attach_array, function (index, attach) {
if (attach.errorCode) { if (attach.errorCode) {
BI.Msg.toast(BI.i18nText(attach.errorMsg), { level: "error" }); BI.Msg.toast(BI.i18nText(attach.errorMsg), { level: "error" });
self.fireEvent(BI.File.EVENT_ERROR, attach); self.fireEvent(BI.File.EVENT_ERROR, attach);
return true; return true;
} }
}); });
@ -548,35 +565,34 @@
var files = F(wrap.dom.input); var files = F(wrap.dom.input);
if (o.maxLength !== -1 && o.maxLength < files.length) { if (o.maxLength !== -1 && o.maxLength < files.length) {
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 2 errorType: 2,
}); });
} else { } else {
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
var item = files.item(i); var item = files.item(i);
var tempFile = item.value || item.name; var tempFile = item.value || item.name;
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), var value = item.fileName || (item.fileName = tempFile.split("\\").pop()),
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
var validateFileType = fileTypeValidate(value, wrap.fileType); var validateFileType = fileTypeValidate(value, wrap.fileType);
if (!validateFileType) { if (!validateFileType) {
// 文件类型不支持 // 文件类型不支持
BI.Msg.toast(o.errorText({ BI.Msg.toast(o.errorText({
errorType: 0, errorType: 0,
file: item file: item,
}) || BI.i18nText("BI-Upload_File_Type_Error", wrap.fileType), { level: "error" }); }) || BI.i18nText("BI-Upload_File_Type_Error", wrap.fileType), { level: "error" });
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 0, errorType: 0,
file: item file: item,
}); });
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { } else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) {
// 文件大小不支持 // 文件大小不支持
BI.Msg.toast(o.errorText({ BI.Msg.toast(o.errorText({
errorType: 1, errorType: 1,
file: item file: item,
}) || BI.i18nText("BI-Upload_File_Size_Error", Math.ceil(wrap.maxSize / 1024 / 1024)), { level: "error" }); }) || BI.i18nText("BI-Upload_File_Size_Error", Math.ceil(wrap.maxSize / 1024 / 1024)), { level: "error" });
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {
errorType: 1, errorType: 1,
file: item file: item,
}); });
} else { } else {
wrap.files.unshift(item); wrap.files.unshift(item);
@ -584,18 +600,19 @@
} }
} }
wrap.files.length > 0 && self.fireEvent(BI.File.EVENT_CHANGE, { wrap.files.length > 0 && self.fireEvent(BI.File.EVENT_CHANGE, {
files: wrap.files files: wrap.files,
}); });
input.value = ""; input.value = "";
wrap.dom.input.parentNode.replaceChild(input, wrap.dom.input); wrap.dom.input.parentNode.replaceChild(input, wrap.dom.input);
wrap.dom.input = input; wrap.dom.input = input;
event.add(wrap.dom.input, "change", arguments.callee); event.add(wrap.dom.input, "change", arguments.callee);
}); });
return wrap; return wrap;
}, },
_wrap: function () { _wrap: function () {
var self = this, o = this.options; var o = this.options;
// be sure input accept multiple files // be sure input accept multiple files
var input = this.element[0]; var input = this.element[0];
if (o.multiple === true) { if (o.multiple === true) {
@ -609,7 +626,7 @@
// DOM namespace // DOM namespace
dom: { dom: {
input: input, // input file input: input, // input file
disabled: false // internal use, checks input file state disabled: false, // internal use, checks input file state
}, },
name: input.name, // name to send for each file ($_FILES[{name}] in the server) name: input.name, // name to send for each file ($_FILES[{name}] in the server)
// maxSize is the maximum amount of bytes for each file // maxSize is the maximum amount of bytes for each file
@ -632,6 +649,7 @@
} }
} }
sendFiles(this, this.maxSize); sendFiles(this, this.maxSize);
return this; return this;
}, },
@ -651,7 +669,7 @@
this.dom.disabled = true; this.dom.disabled = true;
this.dom.input.setAttribute("disabled", "disabled"); this.dom.input.setAttribute("disabled", "disabled");
} }
} },
}); });
}, },
@ -710,7 +728,7 @@
} else { } else {
this.element.attr("disabled", "disabled"); this.element.attr("disabled", "disabled");
} }
} },
}); });
BI.File.EVENT_CHANGE = "EVENT_CHANGE"; BI.File.EVENT_CHANGE = "EVENT_CHANGE";
BI.File.EVENT_UPLOADSTART = "EVENT_UPLOADSTART"; BI.File.EVENT_UPLOADSTART = "EVENT_UPLOADSTART";
@ -718,4 +736,4 @@
BI.File.EVENT_PROGRESS = "EVENT_PROGRESS"; BI.File.EVENT_PROGRESS = "EVENT_PROGRESS";
BI.File.EVENT_UPLOADED = "EVENT_UPLOADED"; BI.File.EVENT_UPLOADED = "EVENT_UPLOADED";
BI.shortcut("bi.file", BI.File); BI.shortcut("bi.file", BI.File);
})(_global.document || {}); })(_global.document || {}));

Loading…
Cancel
Save