diff --git a/demo/js/config/core.js b/demo/js/config/core.js index fee558f25..2c5794488 100644 --- a/demo/js/config/core.js +++ b/demo/js/config/core.js @@ -128,6 +128,10 @@ Demo.CORE_CONFIG = [{ pId: 10201, text: "bi.combo(各种位置)", value: "demo.combo2" +}, { + pId: 10201, + text: "bi.combo(內部位置)", + value: "demo.combo3" }, { pId: 10201, text: "bi.expander", diff --git a/demo/js/core/abstract/combination/demo.combo3.js b/demo/js/core/abstract/combination/demo.combo3.js new file mode 100644 index 000000000..614c36ddd --- /dev/null +++ b/demo/js/core/abstract/combination/demo.combo3.js @@ -0,0 +1,75 @@ +Demo.Func = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-func" + }, + + _createEl: function () { + return { + type: "bi.label", + cls:"bi-border", + height: "100%", + text: "点击" + }; + }, + + oneCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 200, + height: 200 + } + } + }); + }, + + twoCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 1000, + height: 200 + } + } + }); + }, + + threeCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 400, + height: 200 + } + } + }); + }, + + render: function () { + return { + type: "bi.grid", + hgap: 10, + vgap: 5, + items: [[this.oneCombo()], [this.twoCombo()], [this.threeCombo()]] + }; + } +}); +BI.shortcut("demo.combo3", Demo.Func); \ No newline at end of file diff --git a/dist/2.0/fineui.ie.js b/dist/2.0/fineui.ie.js index 89f5f86d2..ee5409429 100644 --- a/dist/2.0/fineui.ie.js +++ b/dist/2.0/fineui.ie.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -19759,6 +19759,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -19766,6 +19772,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -19783,12 +19796,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -19994,7 +20016,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20012,6 +20034,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20103,6 +20131,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -38811,7 +38881,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -38869,14 +38942,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39183,6 +39255,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/2.0/fineui.js b/dist/2.0/fineui.js index 3d30da15a..23cad4360 100644 --- a/dist/2.0/fineui.js +++ b/dist/2.0/fineui.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -19759,6 +19759,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -19766,6 +19772,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -19783,12 +19796,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -19994,7 +20016,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20012,6 +20034,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20103,6 +20131,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -39215,7 +39285,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -39273,14 +39346,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39587,6 +39659,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/base.js b/dist/base.js index 7d92f9e22..cc07aab8a 100644 --- a/dist/base.js +++ b/dist/base.js @@ -3324,7 +3324,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -3382,14 +3385,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -3696,6 +3698,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/bundle.ie.js b/dist/bundle.ie.js index 89f5f86d2..ee5409429 100644 --- a/dist/bundle.ie.js +++ b/dist/bundle.ie.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -19759,6 +19759,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -19766,6 +19772,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -19783,12 +19796,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -19994,7 +20016,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20012,6 +20034,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20103,6 +20131,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -38811,7 +38881,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -38869,14 +38942,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39183,6 +39255,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/bundle.js b/dist/bundle.js index 3d30da15a..23cad4360 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -19759,6 +19759,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -19766,6 +19772,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -19783,12 +19796,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -19994,7 +20016,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20012,6 +20034,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20103,6 +20131,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -39215,7 +39285,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -39273,14 +39346,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39587,6 +39659,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/core.js b/dist/core.js index 7469665c8..d3de47fd9 100644 --- a/dist/core.js +++ b/dist/core.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -19759,6 +19759,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -19766,6 +19772,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -19783,12 +19796,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -19994,7 +20016,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20012,6 +20034,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20103,6 +20131,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } diff --git a/dist/demo.js b/dist/demo.js index c1d4359d1..ee568df16 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -3781,6 +3781,10 @@ Demo.COMPONENT_CONFIG = [{ pId: 10201, text: "bi.combo(各种位置)", value: "demo.combo2" +}, { + pId: 10201, + text: "bi.combo(內部位置)", + value: "demo.combo3" }, { pId: 10201, text: "bi.expander", @@ -4864,6 +4868,80 @@ BI.shortcut("demo.combo2", Demo.Func);Demo.Func = BI.inherit(BI.Widget, { props: { baseCls: "demo-func" }, + + _createEl: function () { + return { + type: "bi.label", + cls:"bi-border", + height: "100%", + text: "点击" + }; + }, + + oneCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 200, + height: 200 + } + } + }); + }, + + twoCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 1000, + height: 200 + } + } + }); + }, + + threeCombo: function () { + return BI.createWidget({ + type: "bi.combo", + direction: "right,innerRight", + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, + el: this._createEl(), + popup: { + el: { + type: "bi.layout", + width: 400, + height: 200 + } + } + }); + }, + + render: function () { + return { + type: "bi.grid", + hgap: 10, + vgap: 5, + items: [[this.oneCombo()], [this.twoCombo()], [this.threeCombo()]] + }; + } +}); +BI.shortcut("demo.combo3", Demo.Func);Demo.Func = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-func" + }, render: function () { return { type: "bi.vertical", diff --git a/dist/fineui.ie.js b/dist/fineui.ie.js index 5af7119fe..1da57e9a9 100644 --- a/dist/fineui.ie.js +++ b/dist/fineui.ie.js @@ -10480,8 +10480,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -20004,6 +20004,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -20011,6 +20017,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -20028,12 +20041,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -20239,7 +20261,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20257,6 +20279,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20348,6 +20376,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -39056,7 +39126,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -39114,14 +39187,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39428,6 +39500,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/fineui.js b/dist/fineui.js index 6da181a84..f27b77831 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -10480,8 +10480,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -20004,6 +20004,12 @@ BI.prepares.push(function () { }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -20011,6 +20017,13 @@ BI.prepares.push(function () { }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -20028,12 +20041,21 @@ BI.prepares.push(function () { return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -20239,7 +20261,7 @@ BI.prepares.push(function () { extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -20257,6 +20279,12 @@ BI.prepares.push(function () { case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -20348,6 +20376,48 @@ BI.prepares.push(function () { } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } } @@ -39460,7 +39530,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -39518,14 +39591,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -39832,6 +39904,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/fineui_without_jquery_polyfill.js b/dist/fineui_without_jquery_polyfill.js index c7e60ff04..7d8448731 100644 --- a/dist/fineui_without_jquery_polyfill.js +++ b/dist/fineui_without_jquery_polyfill.js @@ -10235,8 +10235,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); @@ -26656,7 +26656,10 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight + logic: { + dynamic: true + }, container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, @@ -26714,14 +26717,13 @@ BI.Combo = BI.inherit(BI.Widget, { } }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { items: [ - {el: this.combo} + { el: this.combo } ] - }); + })))); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { @@ -27028,6 +27030,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/dist/utils.js b/dist/utils.js index 82e66d7f5..bd64ee335 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -11014,8 +11014,8 @@ if (!_global.BI) { }, createItems: function (data, innerAttr, outerAttr) { - innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr); - outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr); + innerAttr = BI.isArray(innerAttr) ? innerAttr : BI.makeArray(BI.flatten(data).length, innerAttr || {}); + outerAttr = BI.isArray(outerAttr) ? outerAttr : BI.makeArray(BI.flatten(data).length, outerAttr || {}); return BI.map(data, function (i, item) { if (BI.isArray(item)) { return BI.createItems(item, innerAttr, outerAttr); diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index 2cdd40d60..74dded902 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -9,7 +9,7 @@ BI.Combo = BI.inherit(BI.Widget, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight logic: { dynamic: true }, @@ -383,6 +383,9 @@ BI.Combo = BI.inherit(BI.Widget, { case "right,top": p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle); + break; case "top,custom": case "custom,top": p = BI.DOM.getTopAdaptPosition(combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); diff --git a/src/core/platform/web/dom.js b/src/core/platform/web/dom.js index eada8c1be..022c996da 100644 --- a/src/core/platform/web/dom.js +++ b/src/core/platform/web/dom.js @@ -306,6 +306,12 @@ }; }, + getInnerLeftPosition: function (combo, popup, extraWidth) { + return { + left: combo.element.offset().left + (extraWidth || 0) + }; + }, + getRightPosition: function (combo, popup, extraWidth) { var el = combo.element; return { @@ -313,6 +319,13 @@ }; }, + getInnerRightPosition: function (combo, popup, extraWidth) { + var el = combo.element, viewBounds = popup.element.bounds(); + return { + left: el.offset().left + el.outerWidth() - viewBounds.width - (extraWidth || 0) + }; + }, + getTopPosition: function (combo, popup, extraHeight) { return { top: combo.element.offset().top - popup.element.outerHeight() - (extraHeight || 0) @@ -330,12 +343,21 @@ return BI.DOM.getLeftPosition(combo, popup, extraWidth).left >= 0; }, + isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { + var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); + return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; + }, + isRightSpaceEnough: function (combo, popup, extraWidth) { var viewBounds = popup.element.bounds(), windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); return BI.DOM.getRightPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; }, + isInnerRightSpaceEnough: function (combo, popup, extraWidth) { + return BI.DOM.getInnerRightPosition(combo, popup, extraWidth).left >= 0; + }, + isTopSpaceEnough: function (combo, popup, extraHeight) { return BI.DOM.getTopPosition(combo, popup, extraHeight).top >= 0; }, @@ -541,7 +563,7 @@ extraWidth || (extraWidth = 0); extraHeight || (extraHeight = 0); var i, direct; - var leftRight = [], topBottom = []; + var leftRight = [], topBottom = [], innerLeftRight = []; var isNeedAdaptHeight = false, tbFirst = false, lrFirst = false; var left, top, pos, firstDir = directions[0]; for (i = 0; i < directions.length; i++) { @@ -559,6 +581,12 @@ case "bottom": topBottom.push(direct); break; + case "innerLeft": + innerLeftRight.push(direct); + break; + case "innerRight": + innerLeftRight.push(direct); + break; } } for (i = 0; i < directions.length; i++) { @@ -650,6 +678,48 @@ } tbFirst = true; break; + case "innerLeft": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight; + if (BI.DOM.isInnerLeftSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerLeftPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerLeft,top"; + } + if (tbFirst) { + pos.change = "innerLeft"; + } + pos.left = left; + return pos; + } + } + lrFirst = true; + break; + case "innerRight": + if (!isNeedAdaptHeight) { + var tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight; + if (BI.DOM.isInnerRightSpaceEnough(combo, popup, tW)) { + left = BI.DOM.getInnerRightPosition(combo, popup, tW).left; + if (topBottom[0] === "bottom") { + pos = BI.DOM.getTopAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,bottom"; + } else { + pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight); + pos.dir = "innerRight,top"; + } + if (tbFirst) { + pos.change = "innerRight"; + } + pos.left = left; + return pos; + } + } + break; + } }