/** * Yobi, Project Hosting SW * * Copyright 2013 NAVER Corp. * http://yobi.io * * @author Jihan Kim * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @example * var oSelect = new yobi.Dropdown({ * "elContainer": ".btn-group", * "fOnChange" : function(){}, * " * }); * * @require bootstrap-dropdown.js */ (function(ns){ var oNS = $yobi.createNamespace(ns); oNS.container[oNS.name] = function(htOptions){ var htVar = {"sValue":""}; var htElement = {}; function _init(htOptions){ _initElement(htOptions); _attachEvent(); htVar.fOnChange = htOptions.fOnChange; _selectDefault(); } function _initElement(htOptions){ htElement.welContainer = $(htOptions.elContainer); htElement.welSelectedLabel = htElement.welContainer.find(".d-label"); htElement.welList = htElement.welContainer.find(".dropdown-menu"); htElement.waItems = htElement.welList.find("li"); } function _attachEvent(){ htElement.welList.on("click", "li", _onClickItem); htElement.welList.on("mousewheel", _onScrollList); } /** * @param weEvt * @returns {boolean} * @private */ function _onScrollList(weEvt){ if((weEvt.originalEvent.deltaY > 0 && _isScrollEndOfList()) || (weEvt.originalEvent.deltaY < 0 && _isScrollTopOfList())){ weEvt.preventDefault(); weEvt.stopPropagation(); return false; } } /** * @returns {boolean} * @private */ function _isScrollTopOfList(){ return (htElement.welList.scrollTop() === 0); } /** * @returns {boolean} * @private */ function _isScrollEndOfList(){ return (htElement.welList.scrollTop() + htElement.welList.height() === htElement.welList.get(0).scrollHeight); } /** * @param {Wrapped Event} weEvt */ function _onClickItem(weEvt){ // set welTarget to