diff --git a/demo/js/config/core.js b/demo/js/config/core.js index 757617793..4a6131367 100644 --- a/demo/js/config/core.js +++ b/demo/js/config/core.js @@ -141,10 +141,6 @@ Demo.CORE_CONFIG = [{ pId: 10202, text: "bi.layer_popup", value: "demo.layer_popup" -}, { - pId: 10202, - text: "bi.layer_scroll", - value: "demo.layer_scroll" }, { pId: 10202, text: "bi.layer_searcher", diff --git a/demo/js/core/abstract/demo.virtual_group.js b/demo/js/core/abstract/demo.virtual_group.js index 0c746cffa..e07175f60 100644 --- a/demo/js/core/abstract/demo.virtual_group.js +++ b/demo/js/core/abstract/demo.virtual_group.js @@ -18,7 +18,7 @@ Demo.Func = BI.inherit(BI.Widget, { vgap: 20, items: [{ type: "bi.virtual_group", - width: 200, + width: 500, height: 300, ref: function () { self.buttonMap = this; @@ -34,7 +34,9 @@ Demo.Func = BI.inherit(BI.Widget, { type: "bi.button", text: "点击刷新", handler: function () { - self.buttonMap.populate(self._createItems()); + var items = self._createItems(); + items.pop(); + self.buttonMap.populate(items); } }] @@ -69,6 +71,10 @@ Demo.Item = BI.inherit(BI.Widget, { created: function () { console.log("创建了一项"); + }, + + destroyed: function(){ + console.log("删除了一项"); } }); $.shortcut("demo.virtual_group_item", Demo.Item); \ No newline at end of file diff --git a/dist/base.js b/dist/base.js index 9acaf99f9..387e75066 100644 --- a/dist/base.js +++ b/dist/base.js @@ -2672,11 +2672,7 @@ BI.Collection = BI.inherit(BI.Widget, { BI.each(addSet, function (index) { addedItems.push(renderedCells[index]) }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems - }); + this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; }, @@ -14520,7 +14516,7 @@ $.extend(BI, { BI.Grid = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Grid.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-grid", + baseCls: "bi-grid-view", width: 400, height: 300, overflowX: true, @@ -14688,11 +14684,7 @@ BI.Grid = BI.inherit(BI.Widget, { BI.each(addSet, function (index) { addedItems.push(renderedCells[index]) }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems - }); + this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; } @@ -14828,7 +14820,7 @@ BI.FloatBox = BI.inherit(BI.Widget, { }); this._center = BI.createWidget(); this._north = BI.createWidget(); - this.element.draggable({ + this.element.draggable && this.element.draggable({ handle: ".bi-message-title", drag: function (e, ui) { var W = $("body").width(), H = $("body").height(); diff --git a/dist/core.js b/dist/core.js index 0977f781f..ee7845ebb 100644 --- a/dist/core.js +++ b/dist/core.js @@ -19419,7 +19419,7 @@ BI.Layout = BI.inherit(BI.Widget, { return this.element; }, - _addItem: function (index, item) { + _addItemAt: function (index, item) { for (var i = this.options.items.length; i > index; i--) { this._children[this._getChildName(i)] = this._children[this._getChildName(i - 1)]; } @@ -19427,7 +19427,7 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items.splice(index, 0, item); }, - _removeItem: function (index) { + _removeItemAt: function (index) { for (var i = index; i < this.options.items.length - 1; i++) { this._children[this._getChildName(i)] = this._children[this._getChildName(i + 1)]; } @@ -19458,7 +19458,7 @@ BI.Layout = BI.inherit(BI.Widget, { if (index < 0 || index > this.options.items.length) { return; } - this._addItem(index, item); + this._addItemAt(index, item); var w = this._addElement(index, item); if (index > 0) { this._children[this._getChildName(index - 1)].element.after(w.element); @@ -19474,7 +19474,7 @@ BI.Layout = BI.inherit(BI.Widget, { return; } this._children[this._getChildName(index)].destroy(); - this._removeItem(index); + this._removeItemAt(index); }, updateItemAt: function (index, item) { @@ -19498,17 +19498,35 @@ BI.Layout = BI.inherit(BI.Widget, { }, addItems: function (items) { - var self = this; + var self = this, o = this.options; + var fragment = document.createDocumentFragment(); + var added = []; BI.each(items, function (i, item) { - self.addItem(item); + var w = self._addElement(o.items.length, item); + o.items.push(item); + added.push(w); + fragment.appendChild(w.element[0]); + }); + this._getWrapper().append(fragment); + BI.each(added, function (i, w) { + w._mount(); }) }, prependItems: function (items) { items = items || []; + var fragment = document.createDocumentFragment(); + var added = []; for (var i = items.length - 1; i >= 0; i--) { - this.prependItem(items[i]); - } + var w = this._addElement(this.options.items.length, items[i]); + this.options.items.unshift(items[i]); + added.push(w); + fragment.appendChild(w.element[0]); + } + this._getWrapper().prepend(fragment); + BI.each(added, function (i, w) { + w._mount(); + }) }, getValue: function () { @@ -19539,7 +19557,7 @@ BI.Layout = BI.inherit(BI.Widget, { var o = this.options; var items = item.items; var updated = false, i, len; - for (i = 0, len = o.items.length; i < len; i++) { + for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { if (!this._compare(o.items[i], items[i])) { updated = this.updateItemAt(i, items[i]) || updated; } diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 528913284..a09f98796 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -188,11 +188,7 @@ BI.Collection = BI.inherit(BI.Widget, { BI.each(addSet, function (index) { addedItems.push(renderedCells[index]) }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems - }); + this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; }, diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index c95930f6b..461dabe73 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -8,7 +8,7 @@ BI.Grid = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Grid.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-grid", + baseCls: "bi-grid-view", width: 400, height: 300, overflowX: true, @@ -176,11 +176,7 @@ BI.Grid = BI.inherit(BI.Widget, { BI.each(addSet, function (index) { addedItems.push(renderedCells[index]) }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems - }); + this.container.addItems(addedItems); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; } diff --git a/src/base/layer/layer.floatbox.js b/src/base/layer/layer.floatbox.js index 3c7fc8136..ee321cafb 100644 --- a/src/base/layer/layer.floatbox.js +++ b/src/base/layer/layer.floatbox.js @@ -19,7 +19,7 @@ BI.FloatBox = BI.inherit(BI.Widget, { }); this._center = BI.createWidget(); this._north = BI.createWidget(); - this.element.draggable({ + this.element.draggable && this.element.draggable({ handle: ".bi-message-title", drag: function (e, ui) { var W = $("body").width(), H = $("body").height(); diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index b805c7501..424a51e67 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -161,7 +161,7 @@ BI.Layout = BI.inherit(BI.Widget, { return this.element; }, - _addItem: function (index, item) { + _addItemAt: function (index, item) { for (var i = this.options.items.length; i > index; i--) { this._children[this._getChildName(i)] = this._children[this._getChildName(i - 1)]; } @@ -169,7 +169,7 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items.splice(index, 0, item); }, - _removeItem: function (index) { + _removeItemAt: function (index) { for (var i = index; i < this.options.items.length - 1; i++) { this._children[this._getChildName(i)] = this._children[this._getChildName(i + 1)]; } @@ -200,7 +200,7 @@ BI.Layout = BI.inherit(BI.Widget, { if (index < 0 || index > this.options.items.length) { return; } - this._addItem(index, item); + this._addItemAt(index, item); var w = this._addElement(index, item); if (index > 0) { this._children[this._getChildName(index - 1)].element.after(w.element); @@ -216,7 +216,7 @@ BI.Layout = BI.inherit(BI.Widget, { return; } this._children[this._getChildName(index)].destroy(); - this._removeItem(index); + this._removeItemAt(index); }, updateItemAt: function (index, item) { @@ -240,17 +240,35 @@ BI.Layout = BI.inherit(BI.Widget, { }, addItems: function (items) { - var self = this; + var self = this, o = this.options; + var fragment = document.createDocumentFragment(); + var added = []; BI.each(items, function (i, item) { - self.addItem(item); + var w = self._addElement(o.items.length, item); + o.items.push(item); + added.push(w); + fragment.appendChild(w.element[0]); + }); + this._getWrapper().append(fragment); + BI.each(added, function (i, w) { + w._mount(); }) }, prependItems: function (items) { items = items || []; + var fragment = document.createDocumentFragment(); + var added = []; for (var i = items.length - 1; i >= 0; i--) { - this.prependItem(items[i]); + var w = this._addElement(this.options.items.length, items[i]); + this.options.items.unshift(items[i]); + added.push(w); + fragment.appendChild(w.element[0]); } + this._getWrapper().prepend(fragment); + BI.each(added, function (i, w) { + w._mount(); + }) }, getValue: function () { @@ -281,7 +299,7 @@ BI.Layout = BI.inherit(BI.Widget, { var o = this.options; var items = item.items; var updated = false, i, len; - for (i = 0, len = o.items.length; i < len; i++) { + for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { if (!this._compare(o.items[i], items[i])) { updated = this.updateItemAt(i, items[i]) || updated; }