From dcd68ab9f6a55d48437a98134c39f78fb83bdc44 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 23 Mar 2017 23:33:56 +0800 Subject: [PATCH] add --- dist/core.js | 71 ++++++++++++++++--- src/core/wrapper/layout.js | 12 ++-- src/core/wrapper/layout/adapt/adapt.center.js | 10 ++- .../wrapper/layout/adapt/adapt.horizontal.js | 10 ++- .../wrapper/layout/adapt/adapt.vertical.js | 10 ++- .../flex/wrapper/flex.wrapper.center.js | 10 ++- .../flex/wrapper/flex.wrapper.horizontal.js | 10 ++- .../wrapper/flex.wrapper.vertical.center.js | 9 +++ 8 files changed, 120 insertions(+), 22 deletions(-) diff --git a/dist/core.js b/dist/core.js index 0ed721a35..f21704bf5 100644 --- a/dist/core.js +++ b/dist/core.js @@ -19357,17 +19357,17 @@ BI.Layout = BI.inherit(BI.Widget, { */ addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.element); + w._mount(); return w; }, prependItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.unshift(item); w.element.prependTo(this.element); + w._mount(); return w; }, @@ -19379,10 +19379,10 @@ BI.Layout = BI.inherit(BI.Widget, { }, prependItems: function (items) { - var self = this; - BI.each(items, function (i, item) { - self.prependItem(item); - }) + items = items || []; + for (var i = items.length - 1; i >= 0; i--) { + this.prependItem(items[i]); + } }, getValue: function () { @@ -25051,9 +25051,17 @@ BI.CenterAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, @@ -25172,9 +25180,17 @@ BI.HorizontalAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, @@ -25459,9 +25475,17 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, @@ -26041,9 +26065,17 @@ BI.FlexCenterLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; }, @@ -26130,9 +26162,17 @@ BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; }, @@ -26219,6 +26259,15 @@ BI.FlexVerticalCenter = BI.inherit(BI.Layout, { var w = this._addElement(this.options.items.length, item); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 79bd7d4a4..4bc18481d 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -100,17 +100,17 @@ BI.Layout = BI.inherit(BI.Widget, { */ addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.element); + w._mount(); return w; }, prependItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.unshift(item); w.element.prependTo(this.element); + w._mount(); return w; }, @@ -122,10 +122,10 @@ BI.Layout = BI.inherit(BI.Widget, { }, prependItems: function (items) { - var self = this; - BI.each(items, function (i, item) { - self.prependItem(item); - }) + items = items || []; + for (var i = items.length - 1; i >= 0; i--) { + this.prependItem(items[i]); + } }, getValue: function () { diff --git a/src/core/wrapper/layout/adapt/adapt.center.js b/src/core/wrapper/layout/adapt/adapt.center.js index d1269d07e..072d929bd 100644 --- a/src/core/wrapper/layout/adapt/adapt.center.js +++ b/src/core/wrapper/layout/adapt/adapt.center.js @@ -109,9 +109,17 @@ BI.CenterAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout/adapt/adapt.horizontal.js b/src/core/wrapper/layout/adapt/adapt.horizontal.js index bc8cc16b6..dbcb42a15 100644 --- a/src/core/wrapper/layout/adapt/adapt.horizontal.js +++ b/src/core/wrapper/layout/adapt/adapt.horizontal.js @@ -108,9 +108,17 @@ BI.HorizontalAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout/adapt/adapt.vertical.js b/src/core/wrapper/layout/adapt/adapt.vertical.js index f6588c063..e4cf6de7a 100644 --- a/src/core/wrapper/layout/adapt/adapt.vertical.js +++ b/src/core/wrapper/layout/adapt/adapt.vertical.js @@ -102,9 +102,17 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$tr); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$tr); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js index 7abf1a554..1f23508c9 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js @@ -42,9 +42,17 @@ BI.FlexCenterLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js index 1ea52dcfc..1aff0d676 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js @@ -72,9 +72,17 @@ BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { addItem: function (item) { var w = this._addElement(this.options.items.length, item); - w._mount(); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js index 4e6cfb417..32da933fd 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js @@ -72,6 +72,15 @@ BI.FlexVerticalCenter = BI.inherit(BI.Layout, { var w = this._addElement(this.options.items.length, item); this.options.items.push(item); w.element.appendTo(this.$wrapper); + w._mount(); + return w; + }, + + prependItem: function (item) { + var w = this._addElement(this.options.items.length, item); + this.options.items.unshift(item); + w.element.appendTo(this.$wrapper); + w._mount(); return w; },