/* ! * jQuery Mousewheel 3.1.13 * * Copyright jQuery Foundation and other contributors * Released under the MIT license * http://jquery.org/license */ (function (factory) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define(["../core/jquery"], factory); } else if (typeof exports === "object") { // Node/CommonJS style for Browserify module.exports = factory; } else { // Browser globals factory(jQuery); } }(function ($) { var toFix = ["wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll"], toBind = ( "onwheel" in document || document.documentMode >= 9 ) ? ["wheel"] : ["mousewheel", "DomMouseScroll", "MozMousePixelScroll"], slice = Array.prototype.slice, nullLowestDeltaTimeout, lowestDelta; if ( $.event.fixHooks ) { for ( var i = toFix.length; i; ) { $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; } } var special = $.event.special.mousewheel = { version: "3.1.12", setup: function () { if ( this.addEventListener ) { for ( var i = toBind.length; i; ) { this.addEventListener( toBind[--i], handler, false ); } } else { this.onmousewheel = handler; } }, teardown: function () { if ( this.removeEventListener ) { for ( var i = toBind.length; i; ) { this.removeEventListener( toBind[--i], handler, false ); } } else { this.onmousewheel = null; } }, settings: { adjustOldDeltas: true, // see shouldAdjustOldDeltas() below normalizeOffset: true // calls getBoundingClientRect for each event } }; $.fn.extend({ mousewheel: function (fn) { return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel"); }, unmousewheel: function (fn) { return this.unbind("mousewheel", fn); } }); function handler (event) { var orgEvent = event || _global.event, args = slice.call(arguments, 1), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, offsetX = 0, offsetY = 0; event = $.event.fix(orgEvent); event.type = "mousewheel"; // Old school scrollwheel delta if ( "detail" in orgEvent ) { deltaY = orgEvent.detail * -1; } if ( "wheelDelta" in orgEvent ) { deltaY = orgEvent.wheelDelta; } if ( "wheelDeltaY" in orgEvent ) { deltaY = orgEvent.wheelDeltaY; } if ( "wheelDeltaX" in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; } // Firefox < 17 horizontal scrolling related to DOMMouseScroll event if ( "axis" in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { deltaX = deltaY * -1; deltaY = 0; } // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy delta = deltaY === 0 ? deltaX : deltaY; // New school wheel delta (wheel event) if ( "deltaY" in orgEvent ) { deltaY = orgEvent.deltaY * -1; delta = deltaY; } if ( "deltaX" in orgEvent ) { deltaX = orgEvent.deltaX; if ( deltaY === 0 ) { delta = deltaX * -1; } } // No change actually happened, no reason to go any further if ( deltaY === 0 && deltaX === 0 ) { return; } // Need to convert lines and pages to pixels if we aren't already in pixels // There are three delta modes: // * deltaMode 0 is by pixels, nothing to do // * deltaMode 1 is by lines // * deltaMode 2 is by pages if ( orgEvent.deltaMode === 1 ) { var lineHeight = 40; delta *= lineHeight; deltaY *= lineHeight; deltaX *= lineHeight; } else if ( orgEvent.deltaMode === 2 ) { var pageHeight = 800; delta *= pageHeight; deltaY *= pageHeight; deltaX *= pageHeight; } // Store lowest absolute delta to normalize the delta values absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; // Adjust older deltas if necessary if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { lowestDelta /= 40; } } // Adjust older deltas if necessary if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { // Divide all the things by 40! delta /= 40; deltaX /= 40; deltaY /= 40; } // Get a whole, normalized value for the deltas delta = Math[ delta >= 1 ? "floor" : "ceil" ](delta / lowestDelta); deltaX = Math[ deltaX >= 1 ? "floor" : "ceil" ](deltaX / lowestDelta); deltaY = Math[ deltaY >= 1 ? "floor" : "ceil" ](deltaY / lowestDelta); // Normalise offsetX and offsetY properties if ( special.settings.normalizeOffset && this.getBoundingClientRect ) { var boundingRect = this.getBoundingClientRect(); offsetX = event.clientX - boundingRect.left; offsetY = event.clientY - boundingRect.top; } // Add information to the event object event.deltaX = deltaX; event.deltaY = deltaY; event.deltaFactor = lowestDelta; event.offsetX = offsetX; event.offsetY = offsetY; // Go ahead and set deltaMode to 0 since we converted to pixels // Although this is a little odd since we overwrite the deltaX/Y // properties with normalized deltas. event.deltaMode = 0; // Add event and delta to the front of the arguments args.unshift(event, delta, deltaX, deltaY); // Clearout lowestDelta after sometime to better // handle multiple device types that give different // a different lowestDelta // Ex: trackpad = 3 and mouse wheel = 120 if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); } nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200); return ($.event.dispatch || $.event.handle).apply(this, args); } function nullLowestDelta () { lowestDelta = null; } function shouldAdjustOldDeltas (orgEvent, absDelta) { // If this is an older event and the delta is divisable by 120, // then we are assuming that the browser is treating this as an // older mouse wheel event and that we should divide the deltas // by 40 to try and get a more usable deltaFactor. // Side note, this actually impacts the reported scroll distance // in older browsers and can cause scrolling to be slower than native. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. return special.settings.adjustOldDeltas && orgEvent.type === "mousewheel" && absDelta % 120 === 0; } }));/** * 当没有元素时有提示信息的view * * Created by GUY on 2015/9/8. * @class BI.Pane * @extends BI.Widget * @abstract */ BI.Pane = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Pane.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-pane", tipText: BI.i18nText("BI-No_Selected_Item"), overlap: true, onLoaded: BI.emptyFn }); }, _init: function () { BI.Pane.superclass._init.apply(this, arguments); if (this.__async) { this.loading(); } }, _render: function () { BI.Pane.superclass._render.apply(this, arguments); if (this.__async) { this.loaded(); } }, _assertTip: function () { var o = this.options; if (!this._tipText) { this._tipText = BI.createWidget({ type: "bi.label", cls: "bi-tips", text: o.tipText, height: 25 }); BI.createWidget({ type: "bi.absolute_center_adapt", element: this, items: [this._tipText] }); } }, loading: function () { var self = this, o = this.options; var loadingAnimation = BI.createWidget({ type: "bi.horizontal", cls: "bi-loading-widget" + ((BI.isIE() && BI.getIEVersion() < 10) ? " hack" : ""), height: 30, width: 30, hgap: 5.25, vgap: 2.5, items: [{ type: "bi.layout", cls: "rect1", height: 25, width: 3 }, { type: "bi.layout", cls: "rect2", height: 25, width: 3 }, { type: "bi.layout", cls: "rect3", height: 25, width: 3 }] }); // pane在同步方式下由items决定tipText的显示与否 // loading的异步情况下由loaded后对面板的populate的时机决定 this.setTipVisible(false); if (o.overlap === true) { if (!BI.Layers.has(this.getName())) { BI.createWidget({ type: "bi.absolute_center_adapt", cls: "loading-container", items: [{ el: loadingAnimation }], element: BI.Layers.make(this.getName(), this) }); } BI.Layers.show(self.getName()); } else if (BI.isNull(this._loading)) { this._loading = loadingAnimation; this._loading.element.css("zIndex", 1); BI.createWidget({ type: "bi.absolute_center_adapt", element: this, cls: "loading-container", items: [{ el: this._loading, left: 0, right: 0, top: 0 }] }); } }, loaded: function () { var self = this, o = this.options; BI.Layers.remove(self.getName()); this._loading && this._loading.destroy(); this._loading && (this._loading = null); o.onLoaded(); self.fireEvent(BI.Pane.EVENT_LOADED); }, check: function () { this.setTipVisible(BI.isEmpty(this.options.items)); }, setTipVisible: function (b) { if (b === true) { this._assertTip(); this._tipText.setVisible(true); } else { this._tipText && this._tipText.setVisible(false); } }, populate: function (items) { this.options.items = items || []; this.check(); }, empty: function () { } }); BI.Pane.EVENT_LOADED = "EVENT_LOADED";/** * guy * 这仅仅只是一个超类, 所有简单控件的基类 * 1、类的控制, * 2、title的控制 * 3、文字超过边界显示3个点 * 4、cursor默认pointor * @class BI.Single * @extends BI.Widget * @abstract */ BI.Single = BI.inherit(BI.Widget, { _defaultConfig: function () { var conf = BI.Single.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-single", readonly: false, title: null, warningTitle: null, tipType: null, // success或warning value: null, belowMouse: false // title是否跟随鼠标 }); }, _showToolTip: function (e, opt) { opt || (opt = {}); var self = this, o = this.options; var type = this.getTipType() || (this.isEnabled() ? "success" : "warning"); var title = type === "success" ? this.getTitle() : (this.getWarningTitle() || this.getTitle()); if (BI.isKey(title)) { BI.Tooltips.show(e, this.getName(), title, type, this, opt); if (o.action) { BI.Actions.runAction(o.action, "hover", o, this); } BI.Actions.runGlobalAction("hover", o, this); } }, _hideTooltip: function () { var self = this; var tooltip = BI.Tooltips.get(this.getName()); if (BI.isNotNull(tooltip)) { tooltip.element.fadeOut(200, function () { BI.Tooltips.remove(self.getName()); }); } }, _init: function () { BI.Single.superclass._init.apply(this, arguments); var self = this, o = this.options; if (BI.isKey(o.title) || BI.isKey(o.warningTitle) || BI.isFunction(o.title) || BI.isFunction(o.warningTitle)) { this.enableHover({ belowMouse: o.belowMouse, container: o.container }); } }, enableHover: function (opt) { opt || (opt = {}); var self = this; if (!this._hoverBinded) { this.element.on("mouseenter.title" + this.getName(), function (e) { self._e = e; if (self.getTipType() === "warning" || (BI.isKey(self.getWarningTitle()) && !self.isEnabled())) { self.timeout = BI.delay(function () { self._showToolTip(self._e || e, opt); }, 200); } else if (self.getTipType() === "success" || self.isEnabled()) { self.timeout = BI.delay(function () { self._showToolTip(self._e || e, opt); }, 500); } }); this.element.on("mousemove.title" + this.getName(), function (e) { self._e = e; if (!self.element.__isMouseInBounds__(e)) { if (BI.isNotNull(self.timeout)) { clearTimeout(self.timeout); } self._hideTooltip(); } }); this.element.on("mouseleave.title" + this.getName(), function () { self._e = null; if (BI.isNotNull(self.timeout)) { clearTimeout(self.timeout); } self._hideTooltip(); }); this._hoverBinded = true; } }, disabledHover: function () { // 取消hover事件 if (BI.isNotNull(this.timeout)) { clearTimeout(this.timeout); } this._hideTooltip(); this.element.unbind("mouseenter.title" + this.getName()) .unbind("mousemove.title" + this.getName()) .unbind("mouseleave.title" + this.getName()); this._hoverBinded = false; }, populate: function (items) { this.items = items || []; }, // opt: {container: '', belowMouse: false} setTitle: function (title, opt) { this.options.title = title; if (BI.isKey(title) || BI.isFunction(title)) { this.enableHover(opt); } else { this.disabledHover(); } }, setWarningTitle: function (title, opt) { this.options.warningTitle = title; if (BI.isKey(title) || BI.isFunction(title)) { this.enableHover(opt); } else { this.disabledHover(); } }, getTipType: function () { return this.options.tipType; }, isReadOnly: function () { return !!this.options.readonly; }, getTitle: function () { var title = this.options.title; if(BI.isFunction(title)) { return title(); } return title; }, getWarningTitle: function () { var title = this.options.warningTitle; if(BI.isFunction(title)) { return title(); } return title; }, setValue: function (val) { if (!this.options.readonly) { this.options.value = val; } }, getValue: function () { return this.options.value; }, _unMount: function () { BI.Single.superclass._unMount.apply(this, arguments); BI.Tooltips.remove(this.getName()); } });/** * guy 表示一行数据,通过position来定位位置的数据 * @class BI.Text * @extends BI.Single */ BI.Text = BI.inherit(BI.Single, { _defaultConfig: function () { var conf = BI.Text.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-text", textAlign: "left", whiteSpace: "normal", lineHeight: null, handler: null, // 如果传入handler,表示处理文字的点击事件,不是区域的 hgap: 0, vgap: 0, lgap: 0, rgap: 0, tgap: 0, bgap: 0, text: "", py: "" }); }, _init: function () { BI.Text.superclass._init.apply(this, arguments); var self = this, o = this.options; if (o.hgap + o.lgap > 0) { this.element.css({ "padding-left": o.hgap + o.lgap + "px" }); } if (o.hgap + o.rgap > 0) { this.element.css({ "padding-right": o.hgap + o.rgap + "px" }); } if (o.vgap + o.tgap > 0) { this.element.css({ "padding-top": o.vgap + o.tgap + "px" }); } if (o.vgap + o.bgap > 0) { this.element.css({ "padding-bottom": o.vgap + o.bgap + "px" }); } if (BI.isNumber(o.height)) { this.element.css({lineHeight: o.height + "px"}); } if (BI.isNumber(o.lineHeight)) { this.element.css({lineHeight: o.lineHeight + "px"}); } this.element.css({ textAlign: o.textAlign, whiteSpace: o.whiteSpace }); if (o.handler) { this.text = BI.createWidget({ type: "bi.layout", tagName: "span" }); this.text.element.click(function () { o.handler(self.getValue()); }); BI.createWidget({ type: "bi.default", element: this, items: [this.text] }); } else { this.text = this; } if (BI.isKey(o.text)) { this.setText(o.text); } else if (BI.isKey(o.value)) { this.setText(o.value); } if (BI.isKey(o.keyword)) { this.text.element.__textKeywordMarked__(o.text, o.keyword, o.py); } }, doRedMark: function (keyword) { var o = this.options; this.text.element.__textKeywordMarked__(o.text || o.value, keyword, o.py); }, unRedMark: function () { var o = this.options; this.text.element.__textKeywordMarked__(o.text || o.value, "", o.py); }, doHighLight: function () { this.text.element.addClass("bi-high-light"); }, unHighLight: function () { this.text.element.removeClass("bi-high-light"); }, setValue: function (text) { BI.Text.superclass.setValue.apply(this, arguments); if (!this.isReadOnly()) { this.setText(text); } }, setStyle: function (css) { this.text.element.css(css); }, setText: function (text) { BI.Text.superclass.setText.apply(this, arguments); this.options.text = text; this.text.element.html(BI.htmlEncode(text)); } }); BI.shortcut("bi.text", BI.Text);/** * guy * @class BI.BasicButton * @extends BI.Single * * 一般的button父级 */ BI.BasicButton = BI.inherit(BI.Single, { _defaultConfig: function () { var conf = BI.BasicButton.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-basic-button" + (conf.invalid ? "" : " cursor-pointer"), value: "", text: "", stopEvent: false, stopPropagation: false, selected: false, once: false, // 点击一次选中有效,再点无效 forceSelected: false, // 点击即选中, 选中了就不会被取消,与once的区别是forceSelected不影响事件的触发 forceNotSelected: false, // 无论怎么点击都不会被选中 disableSelected: false, // 使能选中 shadow: false, isShadowShowingOnSelected: false, // 选中状态下是否显示阴影 trigger: null, handler: BI.emptyFn, bubble: null }); }, _init: function () { BI.BasicButton.superclass._init.apply(this, arguments); var opts = this.options; if (opts.selected === true) { BI.nextTick(BI.bind(function () { this.setSelected(opts.selected); }, this)); } BI.nextTick(BI.bind(this.bindEvent, this)); if (opts.shadow) { this._createShadow(); } if (opts.level) { this.element.addClass("button-" + opts.level); } }, _createShadow: function () { var self = this, o = this.options; var assertMask = function () { if (!self.$mask) { self.$mask = BI.createWidget(BI.isObject(o.shadow) ? o.shadow : {}, { type: "bi.layout", cls: "bi-button-mask" }); self.$mask.invisible(); BI.createWidget({ type: "bi.absolute", element: self, items: [{ el: self.$mask, left: 0, right: 0, top: 0, bottom: 0 }] }); } }; this.element.mouseup(function () { if (!self._hover && !o.isShadowShowingOnSelected) { assertMask(); self.$mask.invisible(); } }); this.element.on("mouseenter." + this.getName(), function (e) { if (self.element.__isMouseInBounds__(e)) { if (self.isEnabled() && !self._hover && (o.isShadowShowingOnSelected || !self.isSelected())) { assertMask(); self.$mask.visible(); } } }); this.element.on("mousemove." + this.getName(), function (e) { if (!self.element.__isMouseInBounds__(e)) { if (self.isEnabled() && !self._hover) { assertMask(); self.$mask.invisible(); } } }); this.element.on("mouseleave." + this.getName(), function () { if (self.isEnabled() && !self._hover) { assertMask(); self.$mask.invisible(); } }); }, bindEvent: function () { var self = this; var o = this.options, hand = this.handle(); if (!hand) { return; } hand = hand.element; var triggerArr = (o.trigger || "").split(","); BI.each(triggerArr, function (idx, trigger) { switch (trigger) { case "mouseup": var mouseDown = false; hand.mousedown(function () { mouseDown = true; }); hand.mouseup(function (e) { if (mouseDown === true) { clk(e); } mouseDown = false; ev(e); }); break; case "mousedown": var mouseDown = false; var selected = false; hand.mousedown(function (e) { // if (e.button === 0) { BI.Widget._renderEngine.createElement(document).bind("mouseup." + self.getName(), function (e) { // if (e.button === 0) { if (BI.DOM.isExist(self) && !hand.__isMouseInBounds__(e) && mouseDown === true && !selected) { // self.setSelected(!self.isSelected()); self._trigger(); } mouseDown = false; BI.Widget._renderEngine.createElement(document).unbind("mouseup." + self.getName()); // } }); if (mouseDown === true) { return; } if (self.isSelected()) { selected = true; } else { clk(e); } mouseDown = true; ev(e); // } }); hand.mouseup(function (e) { // if (e.button === 0) { if (BI.DOM.isExist(self) && mouseDown === true && selected === true) { clk(e); } mouseDown = false; selected = false; BI.Widget._renderEngine.createElement(document).unbind("mouseup." + self.getName()); // } }); break; case "dblclick": hand.dblclick(clk); break; case "lclick": var mouseDown = false; var interval; hand.mousedown(function (e) { BI.Widget._renderEngine.createElement(document).bind("mouseup." + self.getName(), function (e) { interval && clearInterval(interval); interval = null; mouseDown = false; BI.Widget._renderEngine.createElement(document).unbind("mouseup." + self.getName()); }); if (mouseDown === true) { return; } if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { return; } interval = setInterval(function () { if (self.isEnabled()) { self.doClick(); } }, 180); mouseDown = true; ev(e); }); break; default: if (o.stopEvent || o.stopPropagation) { hand.mousedown(function (e) { ev(e); }); } hand.click(clk); break; } }); // 之后的300ms点击无效 var onClick = BI.debounce(this._doClick, BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false }); function ev (e) { if (o.stopEvent) { e.stopEvent(); } if (o.stopPropagation) { e.stopPropagation(); } } function clk (e) { ev(e); if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { return; } if (BI.isKey(o.bubble) || BI.isFunction(o.bubble)) { if (BI.isNull(self.combo)) { var popup; BI.createWidget({ type: "bi.absolute", element: self, items: [{ el: { type: "bi.bubble_combo", trigger: "", ref: function () { self.combo = this; }, el: { type: "bi.layout", height: "100%" }, popup: { type: "bi.text_bubble_bar_popup_view", text: getBubble(), ref: function () { popup = this; }, listeners: [{ eventName: BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON, action: function (v) { self.combo.hideView(); if (v) { onClick.apply(self, arguments); } } }] }, listeners: [{ eventName: BI.BubbleCombo.EVENT_BEFORE_POPUPVIEW, action: function () { popup.populate(getBubble()); } }] }, left: 0, right: 0, bottom: 0, top: 0 }] }); } if (self.combo.isViewVisible()) { self.combo.hideView(); } else { self.combo.showView(); } return; } onClick.apply(self, arguments); } function getBubble () { var bubble = self.options.bubble; if (BI.isFunction(bubble)) { return bubble(); } return bubble; } }, _trigger: function () { var o = this.options; if (!this.isEnabled()) { return; } if (!this.isDisableSelected()) { this.isForceSelected() ? this.setSelected(true) : (this.isForceNotSelected() ? this.setSelected(false) : this.setSelected(!this.isSelected())); } if (this.isValid()) { o.handler.call(this, this.getValue(), this); var v = this.getValue(); this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, v, this); this.fireEvent(BI.BasicButton.EVENT_CHANGE, v, this); if (o.action) { BI.Actions.runAction(o.action, "click", o); } BI.Actions.runGlobalAction("click", o); } }, _doClick: function (e) { if (this.isValid()) { this.beforeClick(e); } this._trigger(); if (this.isValid()) { this.doClick(e); } }, beforeClick: function () { }, doClick: function () { }, handle: function () { return this; }, hover: function () { this._hover = true; this.handle().element.addClass("hover"); if (this.options.shadow) { this.$mask && this.$mask.setVisible(true); } }, dishover: function () { this._hover = false; this.handle().element.removeClass("hover"); if (this.options.shadow) { this.$mask && this.$mask.setVisible(false); } }, setSelected: function (b) { var o = this.options; o.selected = b; if (b) { this.handle().element.addClass("active"); } else { this.handle().element.removeClass("active"); } if (o.shadow && !o.isShadowShowingOnSelected) { this.$mask && this.$mask.setVisible(false); } }, isSelected: function () { return this.options.selected; }, isOnce: function () { return this.options.once; }, isForceSelected: function () { return this.options.forceSelected; }, isForceNotSelected: function () { return this.options.forceNotSelected; }, isDisableSelected: function () { return this.options.disableSelected; }, setText: function (text) { this.options.text = text; }, getText: function () { return this.options.text; }, _setEnable: function (enable) { BI.BasicButton.superclass._setEnable.apply(this, arguments); if (enable === true) { this.element.removeClass("base-disabled disabled"); } else if (enable === false) { this.element.addClass("base-disabled disabled"); } if (!enable) { if (this.options.shadow) { this.$mask && this.$mask.setVisible(false); } } }, empty: function () { BI.Widget._renderEngine.createElement(document).unbind("mouseup." + this.getName()); BI.BasicButton.superclass.empty.apply(this, arguments); }, destroy: function () { BI.BasicButton.superclass.destroy.apply(this, arguments); } }); BI.BasicButton.EVENT_CHANGE = "BasicButton.EVENT_CHANGE";/** * 表示一个可以展开的节点, 不仅有选中状态而且有展开状态 * * Created by GUY on 2015/9/9. * @class BI.NodeButton * @extends BI.BasicButton * @abstract */ BI.NodeButton = BI.inherit(BI.BasicButton, { _defaultConfig: function () { var conf = BI.NodeButton.superclass._defaultConfig.apply(this, arguments); return BI.extend( conf, { baseCls: (conf.baseCls || "") + " bi-node", open: false }); }, _init: function () { BI.NodeButton.superclass._init.apply(this, arguments); var self = this; BI.nextTick(function () { self.setOpened(self.isOpened()); }); }, doClick: function () { BI.NodeButton.superclass.doClick.apply(this, arguments); this.setOpened(!this.isOpened()); }, isOnce: function () { return false; }, isOpened: function () { return !!this.options.open; }, setOpened: function (b) { this.options.open = !!b; }, triggerCollapse: function () { if(this.isOpened()) { this.setOpened(false); this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, this.getValue(), this); } }, triggerExpand: function () { if(!this.isOpened()) { this.setOpened(true); this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, this.getValue(), this); } } });/** * guy * tip提示 * zIndex在10亿级别 * @class BI.Tip * @extends BI.Single * @abstract */ BI.Tip = BI.inherit(BI.Single, { _defaultConfig: function () { var conf = BI.Link.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-tip", zIndex: BI.zIndex_tip }); }, _init: function () { BI.Tip.superclass._init.apply(this, arguments); this.element.css({zIndex: this.options.zIndex}); } });/** * Created by GUY on 2015/6/26. * @class BI.ButtonGroup * @extends BI.Widget */ BI.ButtonGroup = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.ButtonGroup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-button-group", behaviors: {}, items: [], value: "", chooseType: BI.Selection.Single, layouts: [{ type: "bi.center", hgap: 0, vgap: 0 }] }); }, _init: function () { BI.ButtonGroup.superclass._init.apply(this, arguments); var o = this.options; var behaviors = {}; BI.each(o.behaviors, function (key, rule) { behaviors[key] = BI.BehaviorFactory.createBehavior(key, { rule: rule }); }); this.behaviors = behaviors; this.populate(o.items); if(BI.isKey(o.value) || BI.isNotEmptyArray(o.value)){ this.setValue(o.value); } }, _createBtns: function (items) { var o = this.options; return BI.createWidgets(BI.createItems(items, { type: "bi.text_button" })); }, _btnsCreator: function (items) { var self = this, args = Array.prototype.slice.call(arguments), o = this.options; var buttons = this._createBtns(items); args[0] = buttons; BI.each(this.behaviors, function (i, behavior) { behavior.doBehavior.apply(behavior, args); }); BI.each(buttons, function (i, btn) { btn.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (type === BI.Events.CLICK) { switch (o.chooseType) { case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: self.setValue(btn.getValue()); break; case BI.ButtonGroup.CHOOSE_TYPE_NONE: self.setValue([]); break; } self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); } else { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); } }); btn.on(BI.Events.DESTROY, function () { BI.remove(self.buttons, btn); }); }); return buttons; }, _packageBtns: function (btns) { var o = this.options; for (var i = o.layouts.length - 1; i > 0; i--) { btns = BI.map(btns, function (k, it) { return BI.extend({}, o.layouts[i], { items: [ BI.extend({}, o.layouts[i].el, { el: it }) ] }); }); } return btns; }, _packageSimpleItems: function (btns) { var o = this.options; return BI.map(o.items, function (i, item) { if (BI.stripEL(item) === item) { return btns[i]; } return BI.extend({}, item, { el: btns[i] }); }); }, _packageItems: function (items, packBtns) { return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); }, _packageLayout: function (items) { var o = this.options, layout = BI.deepClone(o.layouts[0]); var lay = BI.formatEL(layout).el; while (lay && lay.items && !BI.isEmpty(lay.items)) { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; return layout; }, // 如果是一个简单的layout _isSimpleLayout: function () { var o = this.options; return o.layouts.length === 1 && !BI.isArray(o.items[0]); }, doBehavior: function () { var args = Array.prototype.slice.call(arguments); args.unshift(this.buttons); BI.each(this.behaviors, function (i, behavior) { behavior.doBehavior.apply(behavior, args); }); }, prependItems: function (items) { var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); return; } items = this._packageItems(items, this._packageBtns(btns)); this.layouts.prependItems(this._packageLayout(items).items); }, addItems: function (items) { var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(this.buttons, btns); // 如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); return; } items = this._packageItems(items, this._packageBtns(btns)); this.layouts.addItems(this._packageLayout(items).items); }, removeItemAt: function (indexes) { BI.removeAt(this.buttons, indexes); this.layouts.removeItemAt(indexes); }, removeItems: function (values) { values = BI.isArray(values) ? values : [values]; var deleted = []; BI.each(this.buttons, function (i, button) { if (BI.deepContains(values, button.getValue())) { deleted.push(i); } }); BI.removeAt(this.buttons, deleted); this.layouts.removeItemAt(deleted); }, populate: function (items) { items = items || []; this.empty(); this.options.items = items; this.buttons = this._btnsCreator.apply(this, arguments); if (this._isSimpleLayout()) { items = this._packageSimpleItems(this.buttons); } else { items = this._packageItems(items, this._packageBtns(this.buttons)); } this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); }, setNotSelectedValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (BI.deepContains(v, item.getValue())) { item.setSelected && item.setSelected(false); } else { item.setSelected && item.setSelected(true); } }); }, setEnabledValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (BI.deepContains(v, item.getValue())) { item.setEnable(true); } else { item.setEnable(false); } }); }, setValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (BI.deepContains(v, item.getValue())) { item.setSelected && item.setSelected(true); } else { item.setSelected && item.setSelected(false); } }); }, getNotSelectedValue: function () { var v = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !(item.isSelected && item.isSelected())) { v.push(item.getValue()); } }); return v; }, getValue: function () { var v = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } }); return v; }, getAllButtons: function () { return this.buttons; }, getAllLeaves: function () { return this.buttons; }, getSelectedButtons: function () { var btns = []; BI.each(this.buttons, function (i, item) { if (item.isSelected && item.isSelected()) { btns.push(item); } }); return btns; }, getNotSelectedButtons: function () { var btns = []; BI.each(this.buttons, function (i, item) { if (item.isSelected && !item.isSelected()) { btns.push(item); } }); return btns; }, getIndexByValue: function (value) { var index = -1; BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { index = i; return true; } }); return index; }, getNodeById: function (id) { var node; BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.options.id === id) { node = item; return true; } }); return node; }, getNodeByValue: function (value) { var node; BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { node = item; return true; } }); return node; }, empty: function () { BI.ButtonGroup.superclass.empty.apply(this, arguments); this.options.items = []; }, destroy: function () { BI.ButtonGroup.superclass.destroy.apply(this, arguments); this.options.items = []; } }); BI.extend(BI.ButtonGroup, { CHOOSE_TYPE_SINGLE: BI.Selection.Single, CHOOSE_TYPE_MULTI: BI.Selection.Multi, CHOOSE_TYPE_ALL: BI.Selection.All, CHOOSE_TYPE_NONE: BI.Selection.None, CHOOSE_TYPE_DEFAULT: BI.Selection.Default }); BI.ButtonGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.button_group", BI.ButtonGroup);/** * Created by GUY on 2015/8/10. * @class BI.ButtonTree * @extends BI.ButtonGroup */ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { _defaultConfig: function () { return BI.extend(BI.ButtonTree.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-button-tree" }); }, _init: function () { BI.ButtonTree.superclass._init.apply(this, arguments); }, setNotSelectedValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setNotSelectedValue(v); return; } if (BI.deepContains(v, item.getValue())) { item.setSelected(false); } else { item.setSelected(true); } }); }, setEnabledValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (BI.isFunction(item.setEnabledValue)) { item.setEnabledValue(v); return; } if (BI.deepContains(v, item.getValue())) { item.setEnable(true); } else { item.setEnable(false); } }); }, setValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setValue(v); return; } if (BI.deepContains(v, item.getValue())) { item.setSelected(true); } else { item.setSelected(false); } }); }, getNotSelectedValue: function () { var v = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getNotSelectedValue()); return; } if (item.isEnabled() && item.isSelected && !item.isSelected()) { v.push(item.getValue()); } }); return v; }, getValue: function () { var v = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getValue()); return; } if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } }); return v; }, getSelectedButtons: function () { var btns = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getSelectedButtons()); return; } if (item.isSelected && item.isSelected()) { btns.push(item); } }); return btns; }, getNotSelectedButtons: function () { var btns = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getNotSelectedButtons()); return; } if (item.isSelected && !item.isSelected()) { btns.push(item); } }); return btns; }, // 获取所有的叶子节点 getAllLeaves: function () { var leaves = []; BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { leaves = leaves.concat(item.getAllLeaves()); return; } if (item.isEnabled()) { leaves.push(item); } }); return leaves; }, getIndexByValue: function (value) { var index = -1; BI.any(this.buttons, function (i, item) { var vs = item.getValue(); if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { index = i; return true; } }); return index; }, getNodeById: function (id) { var node; BI.any(this.buttons, function (i, item) { if (item.isEnabled()) { if (item.attr("id") === id) { node = item; return true; } else if (BI.isFunction(item.getNodeById)) { if (node = item.getNodeById(id)) { return true; } } } }); return node; }, getNodeByValue: function (value) { var node; BI.any(this.buttons, function (i, item) { if (item.isEnabled()) { if (BI.isFunction(item.getNodeByValue)) { if (node = item.getNodeByValue(value)) { return true; } } else if (item.attr("value") === value) { node = item; return true; } } }); return node; } }); BI.ButtonTree.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.button_tree", BI.ButtonTree);BI.prepares.push(function () { BI.Resizers = new BI.ResizeController(); BI.Layers = new BI.LayerController(); BI.Maskers = new BI.MaskersController(); BI.Bubbles = new BI.BubblesController(); BI.Tooltips = new BI.TooltipsController(); BI.Popovers = new BI.PopoverController(); BI.Broadcasts = new BI.BroadcastController(); BI.StyleLoaders = new BI.StyleLoaderManager(); }); /** * CollectionView * * Created by GUY on 2016/1/15. * @class BI.CollectionView * @extends BI.Widget */ BI.CollectionView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.CollectionView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-collection", // width: 400, //必设 // height: 300, //必设 overflowX: true, overflowY: true, cellSizeAndPositionGetter: BI.emptyFn, horizontalOverscanSize: 0, verticalOverscanSize: 0, scrollLeft: 0, scrollTop: 0, items: [] }); }, _init: function () { BI.CollectionView.superclass._init.apply(this, arguments); var self = this, o = this.options; this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; this._scrollLock = false; this._debounceRelease = BI.debounce(function () { self._scrollLock = false; }, 1000 / 60); this.container = BI.createWidget({ type: "bi.absolute" }); this.element.scroll(function () { if (self._scrollLock === true) { return; } o.scrollLeft = self.element.scrollLeft(); o.scrollTop = self.element.scrollTop(); self._calculateChildrenToRender(); self.fireEvent(BI.CollectionView.EVENT_SCROLL, { scrollLeft: o.scrollLeft, scrollTop: o.scrollTop }); }); BI.createWidget({ type: "bi.vertical", element: this, scrollable: o.overflowX === true && o.overflowY === true, scrolly: o.overflowX === false && o.overflowY === true, scrollx: o.overflowX === true && o.overflowY === false, items: [this.container] }); if (o.items.length > 0) { this._calculateSizeAndPositionData(); this._populate(); } }, mounted: function () { var o = this.options; if (o.scrollLeft !== 0 || o.scrollTop !== 0) { this.element.scrollTop(o.scrollTop); this.element.scrollLeft(o.scrollLeft); } }, _calculateSizeAndPositionData: function () { var o = this.options; var cellMetadata = []; var sectionManager = new BI.SectionManager(); var height = 0; var width = 0; for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || cellMetadatum.width == null || isNaN(cellMetadatum.width) || cellMetadatum.x == null || isNaN(cellMetadatum.x) || cellMetadatum.y == null || isNaN(cellMetadatum.y)) { throw Error(); } height = Math.max(height, cellMetadatum.y + cellMetadatum.height); width = Math.max(width, cellMetadatum.x + cellMetadatum.width); cellMetadatum.index = index; cellMetadata[index] = cellMetadatum; sectionManager.registerCell(cellMetadatum, index); } this._cellMetadata = cellMetadata; this._sectionManager = sectionManager; this._height = height; this._width = width; }, _cellRenderers: function (height, width, x, y) { this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y); return this._cellGroupRenderer(); }, _cellGroupRenderer: function () { var self = this, o = this.options; var rendered = []; BI.each(this._lastRenderedCellIndices, function (i, index) { var cellMetadata = self._sectionManager.getCellMetadata(index); rendered.push(cellMetadata); }); return rendered; }, _calculateChildrenToRender: function () { var self = this, o = this.options; var scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()); var scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()); var left = Math.max(0, scrollLeft - o.horizontalOverscanSize); var top = Math.max(0, scrollTop - o.verticalOverscanSize); var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize); var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize); if (right > 0 && bottom > 0) { // 如果滚动的区间并没有超出渲染的范围 if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) { return; } var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); var renderedCells = [], renderedKeys = {}, renderedWidgets = {}; // 存储所有的left和top var lefts = {}, tops = {}; for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; lefts[datum.x] = datum.x; lefts[datum.x + datum.width] = datum.x + datum.width; tops[datum.y] = datum.y; tops[datum.y + datum.height] = datum.y + datum.height; } lefts = BI.toArray(lefts); tops = BI.toArray(tops); var leftMap = BI.invert(lefts); var topMap = BI.invert(tops); // 存储上下左右四个边界 var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; var assertMinBorder = function (border, offset) { if (border[offset] == null) { border[offset] = Number.MAX_VALUE; } }; var assertMaxBorder = function (border, offset) { if (border[offset] == null) { border[offset] = 0; } }; for (var i = 0, len = childrenToDisplay.length; i < len; i++) { var datum = childrenToDisplay[i]; var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1]; var child; if (index >= 0) { if (datum.width !== this.renderedCells[index]._width) { this.renderedCells[index]._width = datum.width; this.renderedCells[index].el.setWidth(datum.width); } if (datum.height !== this.renderedCells[index]._height) { this.renderedCells[index]._height = datum.height; this.renderedCells[index].el.setHeight(datum.height); } if (this.renderedCells[index]._left !== datum.x) { this.renderedCells[index].el.element.css("left", datum.x + "px"); } if (this.renderedCells[index]._top !== datum.y) { this.renderedCells[index].el.element.css("top", datum.y + "px"); } renderedCells.push(child = this.renderedCells[index]); } else { child = BI.createWidget(BI.extend({ type: "bi.label", width: datum.width, height: datum.height }, o.items[datum.index], { cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), _left: datum.x, _top: datum.y })); renderedCells.push({ el: child, left: datum.x, top: datum.y, _left: datum.x, _top: datum.y, _width: datum.width, _height: datum.height }); } var startTopIndex = topMap[datum.y] | 0; var endTopIndex = topMap[datum.y + datum.height] | 0; for (var k = startTopIndex; k <= endTopIndex; k++) { var t = tops[k]; assertMinBorder(leftBorder, t); assertMaxBorder(rightBorder, t); leftBorder[t] = Math.min(leftBorder[t], datum.x); rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width); } var startLeftIndex = leftMap[datum.x] | 0; var endLeftIndex = leftMap[datum.x + datum.width] | 0; for (var k = startLeftIndex; k <= endLeftIndex; k++) { var l = lefts[k]; assertMinBorder(topBorder, l); assertMaxBorder(bottomBorder, l); topBorder[l] = Math.min(topBorder[l], datum.y); bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height); } renderedKeys[datum.index] = [datum.index, i]; renderedWidgets[i] = child; } // 已存在的, 需要添加的和需要删除的 var existSet = {}, addSet = {}, deleteArray = []; BI.each(renderedKeys, function (i, key) { if (self.renderedKeys[i]) { existSet[i] = key; } else { addSet[i] = key; } }); BI.each(this.renderedKeys, function (i, key) { if (existSet[i]) { return; } if (addSet[i]) { return; } deleteArray.push(key[1]); }); BI.each(deleteArray, function (i, index) { // 性能优化,不调用destroy方法防止触发destroy事件 self.renderedCells[index].el._destroy(); }); var addedItems = []; BI.each(addSet, function (index, key) { addedItems.push(renderedCells[key[1]]); }); this.container.addItems(addedItems); // 拦截父子级关系 this.container._children = renderedWidgets; this.container.attr("items", renderedCells); this.renderedCells = renderedCells; this.renderedKeys = renderedKeys; // Todo 左右比较特殊 var minX = BI.min(leftBorder); var maxX = BI.max(rightBorder); var minY = BI.max(topBorder); var maxY = BI.min(bottomBorder); this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; } }, _getMaxScrollLeft: function () { return Math.max(0, this._width - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0)); }, _getMaxScrollTop: function () { return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); }, _populate: function (items) { var o = this.options; this._reRange(); if (items && items !== this.options.items) { this.options.items = items; this._calculateSizeAndPositionData(); } if (o.items.length > 0) { this.container.setWidth(this._width); this.container.setHeight(this._height); this._calculateChildrenToRender(); // 元素未挂载时不能设置scrollTop try { this.element.scrollTop(o.scrollTop); this.element.scrollLeft(o.scrollLeft); } catch (e) { } } }, setScrollLeft: function (scrollLeft) { if (this.options.scrollLeft === scrollLeft) { return; } this._scrollLock = true; this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getMaxScrollLeft()); this._debounceRelease(); this._calculateChildrenToRender(); this.element.scrollLeft(this.options.scrollLeft); }, setScrollTop: function (scrollTop) { if (this.options.scrollTop === scrollTop) { return; } this._scrollLock = true; this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop()); this._debounceRelease(); this._calculateChildrenToRender(); this.element.scrollTop(this.options.scrollTop); }, setOverflowX: function (b) { var self = this; if (this.options.overflowX !== !!b) { this.options.overflowX = !!b; BI.nextTick(function () { self.element.css({overflowX: b ? "auto" : "hidden"}); }); } }, setOverflowY: function (b) { var self = this; if (this.options.overflowY !== !!b) { this.options.overflowY = !!b; BI.nextTick(function () { self.element.css({overflowY: b ? "auto" : "hidden"}); }); } }, getScrollLeft: function () { return this.options.scrollLeft; }, getScrollTop: function () { return this.options.scrollTop; }, getMaxScrollLeft: function () { return this._getMaxScrollLeft(); }, getMaxScrollTop: function () { return this._getMaxScrollTop(); }, // 重新计算children _reRange: function () { this.renderRange = {}; }, _clearChildren: function () { this.container._children = {}; this.container.attr("items", []); }, restore: function () { BI.each(this.renderedCells, function (i, cell) { cell.el._destroy(); }); this._clearChildren(); this.renderedCells = []; this.renderedKeys = []; this.renderRange = {}; this._scrollLock = false; }, populate: function (items) { if (items && items !== this.options.items) { this.restore(); } this._populate(items); } }); BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; BI.shortcut("bi.collection_view", BI.CollectionView);/** * @class BI.Combo * @extends BI.Widget */ BI.Combo = BI.inherit(BI.Widget, { _defaultConfig: function () { var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-combo", trigger: "click", toggle: true, direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right container: null, // popupview放置的容器,默认为this.element isDefaultInit: false, destroyWhenHide: false, isNeedAdjustHeight: true, // 是否需要高度调整 isNeedAdjustWidth: true, stopEvent: false, stopPropagation: false, adjustLength: 0, // 调整的距离 adjustXOffset: 0, adjustYOffset: 0, hideChecker: BI.emptyFn, offsetStyle: "left", // left,right,center el: {}, popup: {}, comboClass: "bi-combo-popup", hoverClass: "bi-combo-hover" }); }, _init: function () { BI.Combo.superclass._init.apply(this, arguments); var self = this, o = this.options; this._initCombo(); this._initPullDownAction(); this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (self.isEnabled() && self.isValid()) { if (type === BI.Events.EXPAND) { self._popupView(); } if (type === BI.Events.COLLAPSE) { self._hideView(); } if (type === BI.Events.EXPAND) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Combo.EVENT_EXPAND); } if (type === BI.Events.COLLAPSE) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.isViewVisible() && self.fireEvent(BI.Combo.EVENT_COLLAPSE); } if (type === BI.Events.CLICK) { self.fireEvent(BI.Combo.EVENT_TRIGGER_CHANGE, obj); } } }); self.element.on("mouseenter." + self.getName(), function (e) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { self.element.addClass(o.hoverClass); } }); self.element.on("mouseleave." + self.getName(), function (e) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { self.element.removeClass(o.hoverClass); } }); BI.createWidget({ type: "bi.vertical", scrolly: false, element: this, items: [ {el: this.combo} ] }); o.isDefaultInit && (this._assertPopupView()); BI.Resizers.add(this.getName(), BI.bind(function () { if (this.isViewVisible()) { this._hideView(); } }, this)); }, _toggle: function () { this._assertPopupViewRender(); if (this.popupView.isVisible()) { this._hideView(); } else { if (this.isEnabled()) { this._popupView(); } } }, _initPullDownAction: function () { var self = this, o = this.options; var evs = this.options.trigger.split(","); var st = function (e) { if (o.stopEvent) { e.stopEvent(); } if (o.stopPropagation) { e.stopPropagation(); } }; var enterPopup = false; function hide () { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) { self._hideView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); self.fireEvent(BI.Combo.EVENT_COLLAPSE); } self.popupView && self.popupView.element.off("mouseenter." + self.getName()).off("mouseleave." + self.getName()); enterPopup = false; } BI.each(evs, function (i, ev) { switch (ev) { case "hover": self.element.on("mouseenter." + self.getName(), function (e) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { self._popupView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); self.fireEvent(BI.Combo.EVENT_EXPAND); } }); self.element.on("mouseleave." + self.getName(), function (e) { if (self.popupView) { self.popupView.element.on("mouseenter." + self.getName(), function (e) { enterPopup = true; self.popupView.element.on("mouseleave." + self.getName(), function (e) { hide(); }); self.popupView.element.off("mouseenter." + self.getName()); }); BI.defer(function () { if (!enterPopup) { hide(); } }, 50); } }); break; case "click": var debounce = BI.debounce(function (e) { if (self.combo.element.__isMouseInBounds__(e)) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { // if (!o.toggle && self.isViewVisible()) { // return; // } o.toggle ? self._toggle() : self._popupView(); if (self.isViewVisible()) { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); self.fireEvent(BI.Combo.EVENT_EXPAND); } else { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); self.fireEvent(BI.Combo.EVENT_COLLAPSE); } } } }, BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false }); self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) { debounce(e); st(e); }); break; case "click-hover": var debounce = BI.debounce(function (e) { if (self.combo.element.__isMouseInBounds__(e)) { if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { // if (self.isViewVisible()) { // return; // } self._popupView(); if (self.isViewVisible()) { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); self.fireEvent(BI.Combo.EVENT_EXPAND); } } } }, BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false }); self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) { debounce(e); st(e); }); self.element.on("mouseleave." + self.getName(), function (e) { if (self.popupView) { self.popupView.element.on("mouseenter." + self.getName(), function (e) { enterPopup = true; self.popupView.element.on("mouseleave." + self.getName(), function (e) { hide(); }); self.popupView.element.off("mouseenter." + self.getName()); }); BI.defer(function () { if (!enterPopup) { hide(); } }, 50); } }); break; } }); }, _initCombo: function () { this.combo = BI.createWidget(this.options.el, { value: this.options.value }); }, _assertPopupView: function () { var self = this, o = this.options; if (this.popupView == null) { this.popupView = BI.createWidget(this.options.popup, { type: "bi.popup_view", value: o.value }, this); this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (type === BI.Events.CLICK) { self.combo.setValue(self.getValue()); self.fireEvent(BI.Combo.EVENT_CHANGE, value, obj); } self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.popupView.setVisible(false); BI.nextTick(function () { self.fireEvent(BI.Combo.EVENT_AFTER_INIT); }); } }, _assertPopupViewRender: function () { this._assertPopupView(); if (!this._rendered) { BI.createWidget({ type: "bi.vertical", scrolly: false, element: this.options.container || this, items: [ {el: this.popupView} ] }); this._rendered = true; } }, _hideIf: function (e) { // if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) { // return; // } // BI-10290 公式combo双击公式内容会收起 if ((this.element.find(e.target).length > 0) || (this.popupView && this.popupView.element.find(e.target).length > 0) || e.target.className === "CodeMirror-cursor" || BI.Widget._renderEngine.createElement(e.target).closest(".CodeMirror-hints").length > 0) {// BI-9887 CodeMirror的公式弹框需要特殊处理下 return; } var isHide = this.options.hideChecker.apply(this, [e]); if (isHide === false) { return; } this._hideView(); }, _hideView: function () { this.fireEvent(BI.Combo.EVENT_BEFORE_HIDEVIEW); if (this.options.destroyWhenHide === true) { this.popupView && this.popupView.destroy(); this.popupView = null; this._rendered = false; } else { this.popupView && this.popupView.invisible(); } this.element.removeClass(this.options.comboClass); BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); this.fireEvent(BI.Combo.EVENT_AFTER_HIDEVIEW); }, _popupView: function () { this._assertPopupViewRender(); this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW); this.popupView.visible(); this.adjustWidth(); this.adjustHeight(); this.element.addClass(this.options.comboClass); BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); BI.Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this)); this.fireEvent(BI.Combo.EVENT_AFTER_POPUPVIEW); }, adjustWidth: function () { var o = this.options; if (!this.popupView) { return; } if (o.isNeedAdjustWidth === true) { this.resetListWidth(""); var width = this.popupView.element.outerWidth(); var maxW = this.element.outerWidth() || o.width; if (width > maxW + 80) { maxW = maxW + 80; } else if (width > maxW) { maxW = width; } this.resetListWidth(maxW < 100 ? 100 : maxW); } }, adjustHeight: function () { var o = this.options, p = {}; if (!this.popupView) { return; } var isVisible = this.popupView.isVisible(); this.popupView.visible(); switch (o.direction) { case "bottom": case "bottom,right": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "right", "left"], o.offsetStyle); break; case "top": case "top,right": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "right", "left"], o.offsetStyle); break; case "left": case "left,bottom": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "bottom", "top"], o.offsetStyle); break; case "right": case "right,bottom": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "bottom", "top"], o.offsetStyle); break; case "top,left": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "left", "right"], o.offsetStyle); break; case "bottom,left": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "left", "right"], o.offsetStyle); break; case "left,top": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "top", "bottom"], o.offsetStyle); break; case "right,top": p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle); break; case "top,custom": case "custom,top": p = $.getTopAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); break; case "custom,bottom": case "bottom,custom": p = $.getBottomAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight); break; case "left,custom": case "custom,left": p = $.getLeftAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength); delete p.top; delete p.adaptHeight; break; case "custom,right": case "right,custom": p = $.getRightAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength); delete p.top; delete p.adaptHeight; break; } if ("adaptHeight" in p) { this.resetListHeight(p["adaptHeight"]); } if ("left" in p) { this.popupView.element.css({ left: p.left }); } if ("top" in p) { this.popupView.element.css({ top: p.top }); } this.position = p; this.popupView.setVisible(isVisible); }, resetListHeight: function (h) { this._assertPopupView(); this.popupView.resetHeight && this.popupView.resetHeight(h); }, resetListWidth: function (w) { this._assertPopupView(); this.popupView.resetWidth && this.popupView.resetWidth(w); }, populate: function (items) { this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); this.combo.populate.apply(this.combo, arguments); }, _setEnable: function (arg) { BI.Combo.superclass._setEnable.apply(this, arguments); if (arg === true) { this.element.removeClass("base-disabled disabled"); } else if (arg === false) { this.element.addClass("base-disabled disabled"); } !arg && this.element.removeClass(this.options.hoverClass); !arg && this.isViewVisible() && this._hideView(); }, setValue: function (v) { this.combo.setValue(v); if (BI.isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } }, getValue: function () { if (BI.isNull(this.popupView)) { return this.options.popup.value; } else { return this.popupView.getValue(); } }, isViewVisible: function () { return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible(); }, showView: function () { if (this.isEnabled() && this.combo.isEnabled()) { this._popupView(); } }, hideView: function () { this._hideView(); }, getView: function () { return this.popupView; }, getPopupPosition: function () { return this.position; }, toggle: function () { this._toggle(); }, destroy: function () { BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()) .unbind("mousewheel." + this.getName()) .unbind("mouseenter." + this.getName()) .unbind("mousemove." + this.getName()) .unbind("mouseleave." + this.getName()); BI.Resizers.remove(this.getName()); BI.Combo.superclass.destroy.apply(this, arguments); } }); BI.Combo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; BI.Combo.EVENT_CHANGE = "EVENT_CHANGE"; BI.Combo.EVENT_EXPAND = "EVENT_EXPAND"; BI.Combo.EVENT_COLLAPSE = "EVENT_COLLAPSE"; BI.Combo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; BI.Combo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.Combo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; BI.Combo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; BI.Combo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; BI.shortcut("bi.combo", BI.Combo);/** * * 某个可以展开的节点 * * Created by GUY on 2015/9/10. * @class BI.Expander * @extends BI.Widget */ BI.Expander = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Expander.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-expander", trigger: "click", toggle: true, // direction: "bottom", //top,bottom四个方向 isDefaultInit: false, // 是否默认初始化子节点 el: {}, popup: {}, expanderClass: "bi-expander-popup", hoverClass: "bi-expander-hover" }); }, _init: function () { BI.Expander.superclass._init.apply(this, arguments); var self = this, o = this.options; this._expanded = !!o.el.open; this._initExpander(); this._initPullDownAction(); this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (self.isEnabled() && self.isValid()) { if (type === BI.Events.EXPAND) { self._popupView(); } if (type === BI.Events.COLLAPSE) { self._hideView(); } if (type === BI.Events.EXPAND) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Expander.EVENT_EXPAND); } if (type === BI.Events.COLLAPSE) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.isViewVisible() && self.fireEvent(BI.Expander.EVENT_COLLAPSE); } if (type === BI.Events.CLICK) { self.fireEvent(BI.Expander.EVENT_TRIGGER_CHANGE, value, obj); } } }); this.element.hover(function () { if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { self.element.addClass(o.hoverClass); } }, function () { if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { self.element.removeClass(o.hoverClass); } }); BI.createWidget({ type: "bi.vertical", scrolly: false, element: this, items: [ {el: this.expander} ] }); o.isDefaultInit && this._assertPopupView(); if (this.expander.isOpened() === true) { this._popupView(); } }, _toggle: function () { this._assertPopupViewRender(); if (this.popupView.isVisible()) { this._hideView(); } else { if (this.isEnabled()) { this._popupView(); } } }, _initPullDownAction: function () { var self = this, o = this.options; var evs = this.options.trigger.split(","); BI.each(evs, function (i, e) { switch (e) { case "hover": self.element[e](function (e) { if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { self._popupView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander); self.fireEvent(BI.Expander.EVENT_EXPAND); } }, function () { if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid() && o.toggle) { self._hideView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander); self.fireEvent(BI.Expander.EVENT_COLLAPSE); } }); break; case "click": if (e) { self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { if (self.expander.element.__isMouseInBounds__(e)) { if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { o.toggle ? self._toggle() : self._popupView(); if (self.isExpanded()) { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander); self.fireEvent(BI.Expander.EVENT_EXPAND); } else { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander); self.fireEvent(BI.Expander.EVENT_COLLAPSE); } } } }, BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false })); } break; } }); }, _initExpander: function () { this.expander = BI.createWidget(this.options.el); }, _assertPopupView: function () { var self = this, o = this.options; if (this.popupView == null) { this.popupView = BI.createWidget(this.options.popup, { type: "bi.button_group", cls: "expander-popup", layouts: [{ type: "bi.vertical", hgap: 0, vgap: 0 }], value: o.value }, this); this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { // self.setValue(self.getValue()); self.fireEvent(BI.Expander.EVENT_CHANGE, value, obj); } }); this.popupView.setVisible(this.isExpanded()); BI.nextTick(function () { self.fireEvent(BI.Expander.EVENT_AFTER_INIT); }); } }, _assertPopupViewRender: function () { this._assertPopupView(); if (!this._rendered) { BI.createWidget({ type: "bi.vertical", scrolly: false, element: this, items: [ {el: this.popupView} ] }); this._rendered = true; } }, _hideView: function () { this.fireEvent(BI.Expander.EVENT_BEFORE_HIDEVIEW); this._expanded = false; this.expander.setOpened(false); this.popupView && this.popupView.invisible(); this.element.removeClass(this.options.expanderClass); this.fireEvent(BI.Expander.EVENT_AFTER_HIDEVIEW); }, _popupView: function () { this._assertPopupViewRender(); this.fireEvent(BI.Expander.EVENT_BEFORE_POPUPVIEW); this._expanded = true; this.expander.setOpened(true); this.popupView.visible(); this.element.addClass(this.options.expanderClass); this.fireEvent(BI.Expander.EVENT_AFTER_POPUPVIEW); }, populate: function (items) { // this._assertPopupView(); this.popupView && this.popupView.populate.apply(this.popupView, arguments); this.expander.populate.apply(this.expander, arguments); }, _setEnable: function (arg) { BI.Expander.superclass._setEnable.apply(this, arguments); !arg && this.element.removeClass(this.options.hoverClass); !arg && this.isViewVisible() && this._hideView(); }, setValue: function (v) { this.expander.setValue(v); if (BI.isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } }, getValue: function () { if (BI.isNull(this.popupView)) { return this.options.popup.value; } else { return this.popupView.getValue(); } }, isViewVisible: function () { return this.isEnabled() && this.expander.isEnabled() && !!this.popupView && this.popupView.isVisible(); }, isExpanded: function () { return this._expanded; }, showView: function () { if (this.isEnabled() && this.expander.isEnabled()) { this._popupView(); } }, hideView: function () { this._hideView(); }, getView: function () { return this.popupView; }, getAllLeaves: function () { return this.popupView && this.popupView.getAllLeaves(); }, getNodeById: function (id) { if (this.expander.options.id === id) { return this.expander; } return this.popupView && this.popupView.getNodeById(id); }, getNodeByValue: function (value) { if (this.expander.getValue() === value) { return this.expander; } return this.popupView && this.popupView.getNodeByValue(value); }, destroy: function () { BI.Expander.superclass.destroy.apply(this, arguments); } }); BI.Expander.EVENT_EXPAND = "EVENT_EXPAND"; BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE"; BI.Expander.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; BI.Expander.EVENT_CHANGE = "EVENT_CHANGE"; BI.Expander.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; BI.Expander.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.Expander.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; BI.Expander.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; BI.Expander.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; BI.shortcut("bi.expander", BI.Expander);/** * Created by GUY on 2015/8/10. */ BI.ComboGroup = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.ComboGroup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-combo-group bi-list-item", // 以下这些属性对每一个combo都是公用的 trigger: "click,hover", direction: "right", adjustLength: 0, isDefaultInit: false, isNeedAdjustHeight: false, isNeedAdjustWidth: false, el: {type: "bi.text_button", text: "", value: ""}, children: [], popup: { el: { type: "bi.button_tree", chooseType: 0, layouts: [{ type: "bi.vertical" }] } } }); }, _init: function () { BI.ComboGroup.superclass._init.apply(this, arguments); this._populate(this.options.el); }, _populate: function (item) { var self = this, o = this.options; var children = o.children; if (BI.isEmpty(children)) { throw new Error("ComboGroup构造错误"); } BI.each(children, function (i, ch) { var son = BI.formatEL(ch).el.children; ch = BI.formatEL(ch).el; if (!BI.isEmpty(son)) { ch.el = BI.clone(ch); ch.children = son; ch.type = "bi.combo_group"; ch.action = o.action; ch.height = o.height; ch.direction = o.direction; ch.isDefaultInit = o.isDefaultInit; ch.isNeedAdjustHeight = o.isNeedAdjustHeight; ch.isNeedAdjustWidth = o.isNeedAdjustWidth; ch.adjustLength = o.adjustLength; ch.popup = o.popup; } }); this.combo = BI.createWidget({ type: "bi.combo", element: this, container: o.container, height: o.height, trigger: o.trigger, direction: o.direction, isDefaultInit: o.isDefaultInit, isNeedAdjustWidth: o.isNeedAdjustWidth, isNeedAdjustHeight: o.isNeedAdjustHeight, adjustLength: o.adjustLength, el: item, popup: BI.extend({}, o.popup, { el: BI.extend({ items: children }, o.popup.el) }) }); this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { self.fireEvent(BI.ComboGroup.EVENT_CHANGE, obj); } }); }, getValue: function () { return this.combo.getValue(); }, setValue: function (v) { this.combo.setValue(v); } }); BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.VirtualGroup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-virtual-group", items: [], layouts: [{ type: "bi.center", hgap: 0, vgap: 0 }] }); }, render: function () { var o = this.options; this.populate(o.items); if (BI.isKey(o.value)) { this.setValue(o.value); } }, _packageBtns: function (items) { var o = this.options; var map = this.buttonMap = {}; for (var i = o.layouts.length - 1; i > 0; i--) { items = BI.map(items, function (k, it) { var el = BI.stripEL(it); return BI.extend({}, o.layouts[i], { items: [ BI.extend({}, o.layouts[i].el, { el: BI.extend({ ref: function (_ref) { if (BI.isKey(map[el.value])) { map[el.value] = _ref; } } }, el) }) ] }); }); } return items; }, _packageLayout: function (items) { var o = this.options, layout = BI.deepClone(o.layouts[0]); var lay = BI.formatEL(layout).el; while (lay && lay.items && !BI.isEmpty(lay.items)) { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; return layout; }, addItems: function (items) { this.layouts.addItems(items); }, prependItems: function (items) { this.layouts.prependItems(items); }, setValue: function (v) { v = BI.isArray(v) ? v : [v]; BI.each(this.buttonMap, function (key, item) { if (item) { if (v.deepContains(key)) { item.setSelected && item.setSelected(true); } else { item.setSelected && item.setSelected(false); } } }); }, getNotSelectedValue: function () { var v = []; BI.each(this.buttonMap, function (i, item) { if (item) { if (item.isEnabled() && !(item.isSelected && item.isSelected())) { v.push(item.getValue()); } } }); return v; }, getValue: function () { var v = []; BI.each(this.buttonMap, function (i, item) { if (item) { if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } } }); return v; }, populate: function (items) { var self = this; items = items || []; this.options.items = items; items = this._packageBtns(items); if (!this.layouts) { this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); } else { this.layouts.populate(items); } } }); BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.virtual_group", BI.VirtualGroup);/** * 加载控件 * * Created by GUY on 2015/8/31. * @class BI.Loader * @extends BI.Widget */ BI.Loader = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Loader.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-loader", direction: "top", isDefaultInit: true, // 是否默认初始化数据 logic: { dynamic: true, scrolly: true }, // 下面是button_group的属性 el: { type: "bi.button_group" }, items: [], itemsCreator: BI.emptyFn, onLoaded: BI.emptyFn, // 下面是分页信息 count: false, prev: false, next: {}, hasPrev: BI.emptyFn, hasNext: BI.emptyFn }); }, _prevLoad: function () { var self = this, o = this.options; this.prev.setLoading(); o.itemsCreator.apply(this, [{times: --this.times}, function () { self.prev.setLoaded(); self.prependItems.apply(self, arguments); }]); }, _nextLoad: function () { var self = this, o = this.options; this.next.setLoading(); o.itemsCreator.apply(this, [{times: ++this.times}, function () { self.next.setLoaded(); self.addItems.apply(self, arguments); }]); }, _init: function () { BI.Loader.superclass._init.apply(this, arguments); var self = this, o = this.options; if (o.itemsCreator === false) { o.prev = false; o.next = false; } if (o.prev !== false) { this.prev = BI.createWidget(BI.extend({ type: "bi.loading_bar" }, o.prev)); this.prev.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { self._prevLoad(); } }); } this.button_group = BI.createWidget(o.el, { type: "bi.button_group", chooseType: 0, items: o.items, behaviors: {}, layouts: [{ type: "bi.vertical" }] }); this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { self.fireEvent(BI.Loader.EVENT_CHANGE, obj); } }); if (o.next !== false) { this.next = BI.createWidget(BI.extend({ type: "bi.loading_bar" }, o.next)); this.next.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { self._nextLoad(); } }); } BI.createWidget(BI.extend({ element: this }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ scrolly: true }, o.logic, { items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.prev, this.button_group, this.next) })))); o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () { o.isDefaultInit && BI.isEmpty(o.items) && this.populate(); }, this)); if (BI.isNotEmptyArray(o.items)) { this.populate(o.items); } }, hasPrev: function () { var o = this.options; if (BI.isNumber(o.count)) { return this.count < o.count; } return !!o.hasPrev.apply(this, [{ times: this.times, count: this.count }]); }, hasNext: function () { var o = this.options; if (BI.isNumber(o.count)) { return this.count < o.count; } return !!o.hasNext.apply(this, [{ times: this.times, count: this.count }]); }, prependItems: function (items) { this.count += items.length; if (this.next !== false) { if (this.hasPrev()) { this.options.items = this.options.items.concat(items); this.prev.setLoaded(); } else { this.prev.setEnd(); } } this.button_group.prependItems.apply(this.button_group, arguments); }, addItems: function (items) { this.count += items.length; if (BI.isObject(this.next)) { if (this.hasNext()) { this.options.items = this.options.items.concat(items); this.next.setLoaded(); } else { this.next.setEnd(); } } this.button_group.addItems.apply(this.button_group, arguments); }, populate: function (items) { var self = this, o = this.options; if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { o.itemsCreator.apply(this, [{times: 1}, function () { if (arguments.length === 0) { throw new Error("arguments can not be null!!!"); } self.populate.apply(self, arguments); o.onLoaded(); }]); return; } this.options.items = items; this.times = 1; this.count = 0; this.count += items.length; if (BI.isObject(this.next)) { if (this.hasNext()) { this.next.setLoaded(); } else { this.next.invisible(); } } if (BI.isObject(this.prev)) { if (this.hasPrev()) { this.prev.setLoaded(); } else { this.prev.invisible(); } } this.button_group.populate.apply(this.button_group, arguments); }, setNotSelectedValue: function () { this.button_group.setNotSelectedValue.apply(this.button_group, arguments); }, getNotSelectedValue: function () { return this.button_group.getNotSelectedValue(); }, setValue: function () { this.button_group.setValue.apply(this.button_group, arguments); }, getValue: function () { return this.button_group.getValue.apply(this.button_group, arguments); }, getAllButtons: function () { return this.button_group.getAllButtons(); }, getAllLeaves: function () { return this.button_group.getAllLeaves(); }, getSelectedButtons: function () { return this.button_group.getSelectedButtons(); }, getNotSelectedButtons: function () { return this.button_group.getNotSelectedButtons(); }, getIndexByValue: function (value) { return this.button_group.getIndexByValue(value); }, getNodeById: function (id) { return this.button_group.getNodeById(id); }, getNodeByValue: function (value) { return this.button_group.getNodeByValue(value); }, empty: function () { this.button_group.empty(); BI.each([this.prev, this.next], function (i, ob) { ob && ob.setVisible(false); }); }, destroy: function () { BI.Loader.superclass.destroy.apply(this, arguments); } }); BI.Loader.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.loader", BI.Loader);/** * Created by GUY on 2015/6/26. */ BI.Navigation = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { direction: "bottom", // top, bottom, left, right, custom logic: { dynamic: false }, single: false, showIndex: false, tab: false, cardCreator: function (v) { return BI.createWidget(); }, afterCardCreated: BI.emptyFn, afterCardShow: BI.emptyFn }); }, render: function () { var self = this, o = this.options; this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.cardMap = {}; this.showIndex = 0; this.layout = BI.createWidget({ type: "bi.card" }); BI.createWidget(BI.extend({ element: this }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) })))); new BI.ShowListener({ eventObj: this.tab, cardLayout: this.layout, cardNameCreator: function (v) { return self.showIndex + v; }, cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; return card; }, afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardShow: BI.bind(this.afterCardShow, this) }); }, mounted: function () { var o = this.options; if (o.showIndex !== false) { this.setSelect(o.showIndex); } }, _deleteOtherCards: function (currCardName) { var self = this, o = this.options; if (o.single === true) { BI.each(this.cardMap, function (name, card) { if (name !== (currCardName + "")) { self.layout.deleteCardByName(name); delete self.cardMap[name]; } }); } }, afterCardCreated: function (v) { var self = this; this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } }); this.options.afterCardCreated.apply(this, arguments); }, afterCardShow: function (v) { this.showIndex = v; this._deleteOtherCards(v); this.options.afterCardShow.apply(this, arguments); }, populate: function () { var card = this.layout.getShowingCard(); if (card) { return card.populate.apply(card, arguments); } }, _assertCard: function (v) { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); this.afterCardCreated(v); } }, setSelect: function (v) { this._assertCard(v); this.layout.showCardByName(v); this._deleteOtherCards(v); if (this.showIndex !== v) { this.showIndex = v; BI.nextTick(BI.bind(this.afterCardShow, this, v)); } }, getSelect: function () { return this.showIndex; }, getSelectedCard: function () { if (BI.isKey(this.showIndex)) { return this.cardMap[this.showIndex]; } }, /** * @override */ setValue: function (v) { var card = this.layout.getShowingCard(); if (card) { card.setValue(v); } }, /** * @override */ getValue: function () { var card = this.layout.getShowingCard(); if (card) { return card.getValue(); } }, empty: function () { this.layout.deleteAllCard(); this.cardMap = {}; }, destroy: function () { BI.Navigation.superclass.destroy.apply(this, arguments); } }); BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.navigation", BI.Navigation);/** * 搜索逻辑控件 * * Created by GUY on 2015/9/28. * @class BI.Searcher * @extends BI.Widget */ BI.Searcher = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Searcher.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-searcher", lgap: 0, rgap: 0, tgap: 0, bgap: 0, vgap: 0, hgap: 0, isDefaultInit: false, isAutoSearch: true, // 是否自动搜索 isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一 chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, // isAutoSearch为false时启用 onSearch: function (op, callback) { callback([]); }, el: { type: "bi.search_editor" }, popup: { type: "bi.searcher_view" }, adapter: null, masker: { // masker层 offset: {} } }); }, _init: function () { BI.Searcher.superclass._init.apply(this, arguments); var self = this, o = this.options; this.editor = BI.createWidget(o.el, { type: "bi.search_editor" }); BI.createWidget({ type: "bi.vertical", element: this, lgap: o.lgap, rgap: o.rgap, tgap: o.tgap, bgap: o.bgap, vgap: o.vgap, hgap: o.hgap, items: [this.editor] }); o.isDefaultInit && (this._assertPopupView()); var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false }); this.editor.on(BI.Controller.EVENT_CHANGE, function (type) { switch (type) { case BI.Events.STARTEDIT: self._startSearch(); break; case BI.Events.EMPTY: self._stopSearch(); break; case BI.Events.CHANGE: search(); break; case BI.Events.PAUSE: self._pauseSearch(); break; } }); }, _assertPopupView: function () { var self = this, o = this.options; if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { this.popupView = BI.createWidget(o.popup, { type: "bi.searcher_view", chooseType: o.chooseType }); this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { if (o.isAutoSync) { var values = o.adapter && o.adapter.getValue(); if (!obj.isSelected()) { o.adapter && o.adapter.setValue(BI.deepWithout(values, obj.getValue())); } else { switch (o.chooseType) { case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: o.adapter && o.adapter.setValue([obj.getValue()]); break; case BI.ButtonGroup.CHOOSE_TYPE_MULTI: values.push(obj.getValue()); o.adapter && o.adapter.setValue(values); break; } } } self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); } }); BI.nextTick(function () { self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); }); } if (o.masker && !BI.Maskers.has(this.getName())) { BI.Maskers.create(this.getName(), o.adapter, BI.extend({ container: this, render: this.popupView }, o.masker), this); } }, _startSearch: function () { this._assertPopupView(); this._stop = false; this._isSearching = true; this.fireEvent(BI.Searcher.EVENT_START); this.popupView.startSearch && this.popupView.startSearch(); // 搜索前先清空dom // BI.Maskers.get(this.getName()).empty(); BI.nextTick(function (name) { BI.Maskers.show(name); }, this.getName()); }, _pauseSearch: function () { var o = this.options, name = this.getName(); this._stop = true; BI.nextTick(function (name) { BI.Maskers.hide(name); }, this.getName()); if (this._isSearching === true) { this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); this.fireEvent(BI.Searcher.EVENT_PAUSE); } this._isSearching = false; }, _stopSearch: function () { var o = this.options, name = this.getName(); this._stop = true; BI.Maskers.hide(name); if (this._isSearching === true) { this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); this.fireEvent(BI.Searcher.EVENT_STOP); } this._isSearching = false; }, _search: function () { var self = this, o = this.options, keyword = this.editor.getValue(); if (keyword === "" || this._stop) { return; } if (o.isAutoSearch) { var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; var finding = BI.Func.getSearchResult(items, keyword); var match = finding.match, find = finding.find; this.popupView.populate(find, match, keyword); o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); return; } this.popupView.loading && this.popupView.loading(); o.onSearch({ times: 1, keyword: keyword, selectedValues: o.adapter && o.adapter.getValue() }, function (searchResult, matchResult) { if (!self._stop) { var args = [].slice.call(arguments); if (args.length > 0) { args.push(keyword); } BI.Maskers.show(self.getName()); self.popupView.populate.apply(self.popupView, args); o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); self.popupView.loaded && self.popupView.loaded(); self.fireEvent(BI.Searcher.EVENT_SEARCHING); } }); }, setAdapter: function (adapter) { this.options.adapter = adapter; BI.Maskers.remove(this.getName()); }, doSearch: function () { if (this.isSearching()) { this._search(); } }, stopSearch: function () { this._stopSearch();// 先停止搜索,然后再去设置editor为空 // important:停止搜索必须退出编辑状态,这里必须加上try(input框不显示时blur会抛异常) try { this.editor.blur(); } catch (e) { if (!this.editor.blur) { throw new Error("editor没有实现blur方法"); } } finally { this.editor.setValue(""); } }, isSearching: function () { return this._isSearching; }, isViewVisible: function () { return this.editor.isEnabled() && BI.Maskers.isVisible(this.getName()); }, getView: function () { return this.popupView; }, hasMatched: function () { this._assertPopupView(); return this.popupView.hasMatched(); }, adjustHeight: function () { if (BI.Maskers.has(this.getName()) && BI.Maskers.get(this.getName()).isVisible()) { BI.Maskers.show(this.getName()); } }, adjustView: function () { this.isViewVisible() && BI.Maskers.show(this.getName()); }, setValue: function (v) { if (BI.isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } }, getKeyword: function () { return this.editor.getValue(); }, getKeywords: function () { return this.editor.getKeywords(); }, getValue: function () { var o = this.options; if (o.isAutoSync && o.adapter && o.adapter.getValue) { return o.adapter.getValue(); } if (this.isSearching()) { return this.popupView.getValue(); } else if (o.adapter && o.adapter.getValue) { return o.adapter.getValue(); } if (BI.isNull(this.popupView)) { return o.popup.value; } return this.popupView.getValue(); }, populate: function (result, searchResult, keyword) { var o = this.options; this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); if (o.isAutoSync && o.adapter && o.adapter.getValue) { this.popupView.setValue(o.adapter.getValue()); } }, empty: function () { this.popupView && this.popupView.empty(); }, destroy: function () { BI.Maskers.remove(this.getName()); BI.Searcher.superclass.destroy.apply(this, arguments); } }); BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE"; BI.Searcher.EVENT_START = "EVENT_START"; BI.Searcher.EVENT_STOP = "EVENT_STOP"; BI.Searcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.Searcher.EVENT_SEARCHING = "EVENT_SEARCHING"; BI.Searcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; BI.shortcut("bi.searcher", BI.Searcher);/** * * 切换显示或隐藏面板 * * Created by GUY on 2015/11/2. * @class BI.Switcher * @extends BI.Widget */ BI.Switcher = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Switcher.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-switcher", direction: BI.Direction.Top, trigger: "click", toggle: true, el: {}, popup: {}, adapter: null, masker: {}, switcherClass: "bi-switcher-popup", hoverClass: "bi-switcher-hover" }); }, _init: function () { BI.Switcher.superclass._init.apply(this, arguments); var self = this, o = this.options; this._initSwitcher(); this._initPullDownAction(); this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (self.isEnabled() && self.isValid()) { if (type === BI.Events.EXPAND) { self._popupView(); } if (type === BI.Events.COLLAPSE) { self._hideView(); } if (type === BI.Events.EXPAND) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Switcher.EVENT_EXPAND); } if (type === BI.Events.COLLAPSE) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.isViewVisible() && self.fireEvent(BI.Switcher.EVENT_COLLAPSE); } if (type === BI.Events.CLICK) { self.fireEvent(BI.Switcher.EVENT_TRIGGER_CHANGE, value, obj); } } }); this.element.hover(function () { if (self.isEnabled() && self.switcher.isEnabled()) { self.element.addClass(o.hoverClass); } }, function () { if (self.isEnabled() && self.switcher.isEnabled()) { self.element.removeClass(o.hoverClass); } }); BI.createWidget({ type: "bi.vertical", scrolly: false, element: this, items: [ {el: this.switcher} ] }); o.isDefaultInit && (this._assertPopupView()); }, _toggle: function () { this._assertPopupView(); if (this.isExpanded()) { this._hideView(); } else { if (this.isEnabled()) { this._popupView(); } } }, _initPullDownAction: function () { var self = this, o = this.options; var evs = this.options.trigger.split(","); BI.each(evs, function (i, e) { switch (e) { case "hover": self.element[e](function (e) { if (self.isEnabled() && self.switcher.isEnabled()) { self._popupView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher); self.fireEvent(BI.Switcher.EVENT_EXPAND); } }, function () { if (self.isEnabled() && self.switcher.isEnabled() && o.toggle) { self._hideView(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher); self.fireEvent(BI.Switcher.EVENT_COLLAPSE); } }); break; default : if (e) { self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { if (self.switcher.element.__isMouseInBounds__(e)) { if (self.isEnabled() && self.switcher.isEnabled()) { o.toggle ? self._toggle() : self._popupView(); if (self.isExpanded()) { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher); self.fireEvent(BI.Switcher.EVENT_EXPAND); } else { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher); self.fireEvent(BI.Switcher.EVENT_COLLAPSE); } } } }, BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false })); } break; } }); }, _initSwitcher: function () { this.switcher = BI.createWidget(this.options.el, { value: this.options.value }); }, _assertPopupView: function () { var self = this, o = this.options; if (!this._created) { this.popupView = BI.createWidget(o.popup, { type: "bi.button_group", element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({container: this}, o.masker)), cls: "switcher-popup", layouts: [{ type: "bi.vertical", hgap: 0, vgap: 0 }], value: o.value }, this); this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { self.fireEvent(BI.Switcher.EVENT_CHANGE, value, obj); } }); if (o.direction !== BI.Direction.Custom && !o.adapter) { BI.createWidget({ type: "bi.vertical", scrolly: false, element: this, items: [ {el: this.popupView} ] }); } this._created = true; BI.nextTick(function () { self.fireEvent(BI.Switcher.EVENT_AFTER_INIT); }); } }, _hideView: function () { this.fireEvent(BI.Switcher.EVENT_BEFORE_HIDEVIEW); var self = this, o = this.options; o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); BI.nextTick(function () { o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); self.element.removeClass(o.switcherClass); self.fireEvent(BI.Switcher.EVENT_AFTER_HIDEVIEW); }); }, _popupView: function () { var self = this, o = this.options; this._assertPopupView(); this.fireEvent(BI.Switcher.EVENT_BEFORE_POPUPVIEW); o.adapter ? BI.Maskers.show(this.getName()) : self.popupView.setVisible(true); BI.nextTick(function (name) { o.adapter ? BI.Maskers.show(name) : self.popupView.setVisible(true); self.element.addClass(o.switcherClass); self.fireEvent(BI.Switcher.EVENT_AFTER_POPUPVIEW); }, this.getName()); }, populate: function (items) { this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); this.switcher.populate.apply(this.switcher, arguments); }, _setEnable: function (arg) { BI.Switcher.superclass._setEnable.apply(this, arguments); !arg && this.isViewVisible() && this._hideView(); }, setValue: function (v) { this.switcher.setValue(v); if (BI.isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } }, getValue: function () { if (BI.isNull(this.popupView)) { return this.options.popup.value; } else { return this.popupView.getValue(); } }, setAdapter: function (adapter) { this.options.adapter = adapter; BI.Maskers.remove(this.getName()); }, isViewVisible: function () { return this.isEnabled() && this.switcher.isEnabled() && (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); }, isExpanded: function () { return this.isViewVisible(); }, showView: function () { if (this.isEnabled() && this.switcher.isEnabled()) { this._popupView(); } }, hideView: function () { this._hideView(); }, getView: function () { return this.popupView; }, adjustView: function () { this.isViewVisible() && BI.Maskers.show(this.getName()); }, getAllLeaves: function () { return this.popupView && this.popupView.getAllLeaves(); }, getNodeById: function (id) { if (this.switcher.attr("id") === id) { return this.switcher; } return this.popupView && this.popupView.getNodeById(id); }, getNodeByValue: function (value) { if (this.switcher.getValue() === value) { return this.switcher; } return this.popupView && this.popupView.getNodeByValue(value); }, empty: function () { this.popupView && this.popupView.empty(); }, destroy: function () { BI.Switcher.superclass.destroy.apply(this, arguments); } }); BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND"; BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE"; BI.Switcher.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; BI.Switcher.EVENT_CHANGE = "EVENT_CHANGE"; BI.Switcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; BI.Switcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.Switcher.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; BI.Switcher.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; BI.Switcher.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; BI.shortcut("bi.switcher", BI.Switcher);/** * Created by GUY on 2015/6/26. */ BI.Tab = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tab", direction: "top", // top, bottom, left, right, custom single: false, // 是不是单页面 logic: { dynamic: false }, showIndex: false, tab: false, cardCreator: function (v) { return BI.createWidget(); } }); }, render: function () { var self = this, o = this.options; if (BI.isObject(o.tab)) { this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.tab.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); } this.cardMap = {}; this.layout = BI.createWidget({ type: "bi.card" }); BI.createWidget(BI.extend({ element: this }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) })))); var listener = new BI.ShowListener({ eventObj: this.tab, cardLayout: this.layout, cardCreator: function (v) { var card = o.cardCreator.apply(self, arguments); self.cardMap[v] = card; return card; }, afterCardShow: function (v) { self._deleteOtherCards(v); self.curr = v; } }); listener.on(BI.ShowListener.EVENT_CHANGE, function (value) { self.fireEvent(BI.Tab.EVENT_CHANGE, value, self); }); }, _deleteOtherCards: function (currCardName) { var self = this, o = this.options; if (o.single === true) { BI.each(this.cardMap, function (name, card) { if (name !== (currCardName + "")) { self.layout.deleteCardByName(name); delete self.cardMap[name]; } }); } }, _assertCard: function (v) { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); } }, mounted: function () { var o = this.options; if (o.showIndex !== false) { this.setSelect(o.showIndex); } }, setSelect: function (v) { this.tab && this.tab.setValue(v); this._assertCard(v); this.layout.showCardByName(v); this._deleteOtherCards(v); if (this.curr !== v) { this.curr = v; } }, removeTab: function (cardname) { var self = this, o = this.options; BI.any(this.cardMap, function (name, card) { if (BI.isEqual(name, (cardname + ""))) { self.layout.deleteCardByName(name); delete self.cardMap[name]; return true; } }); }, getSelect: function () { return this.curr; }, getSelectedTab: function () { return this.layout.getShowingCard(); }, getTab: function (v) { this._assertCard(v); return this.layout.getCardByName(v); }, setValue: function (v) { var card = this.layout.getShowingCard(); if (card) { card.setValue(v); } }, getValue: function () { var card = this.layout.getShowingCard(); if (card) { return card.getValue(); } }, populate: function () { var card = this.layout.getShowingCard(); if (card) { return card.populate && card.populate.apply(card, arguments); } }, empty: function () { this.layout.deleteAllCard(); this.cardMap = {}; }, destroy: function () { this.cardMap = {}; BI.Tab.superclass.destroy.apply(this, arguments); } }); BI.Tab.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.tab", BI.Tab);/** * 表示当前对象 * * Created by GUY on 2015/9/7. * @class BI.EL * @extends BI.Widget */ BI.EL = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-el", el: {}, layout: {} }); }, _init: function () { BI.EL.superclass._init.apply(this, arguments); var self = this, o = this.options; this.ele = BI.createWidget(o.el); BI.createWidget(o.layout, { type: "bi.adaptive", element: this, items: [this.ele] }); this.ele.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); }, setValue: function (v) { this.ele.setValue(v); }, getValue: function () { return this.ele.getValue(); }, populate: function () { this.ele.populate.apply(this, arguments); } }); BI.shortcut("bi.el", BI.EL);/** * z-index在1亿层级 * 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) * @class BI.Msg */ BI.Msg = function () { var messageShow, $mask, $pop; return { alert: function (title, message, callback) { this._show(false, title, message, callback); }, confirm: function (title, message, callback) { this._show(true, title, message, callback); }, prompt: function (title, message, value, callback, min_width) { // BI.Msg.prompt(title, message, value, callback, min_width); }, toast: function (message, options, context) { options = options || {}; context = context || BI.Widget._renderEngine.createElement("body"); var level = options.level || "normal"; var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; var toast = BI.createWidget({ type: "bi.toast", cls: "bi-message-animate bi-message-leave", level: level, autoClose: autoClose, text: message }); BI.createWidget({ type: "bi.absolute", element: context, items: [{ el: toast, left: "50%", top: 10 }] }); toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); autoClose && BI.delay(function () { toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); BI.delay(function () { toast.destroy(); }, 1000); }, 5000); }, _show: function (hasCancel, title, message, callback) { $mask = BI.Widget._renderEngine.createElement("