/*! * jQuery Selectbox plugin 0.2 * * Copyright 2011-2012, Dimitar Ivanov (http://www.bulgaria-web-developers.com/projects/javascript/selectbox/) * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. * * Date: Tue Jul 17 19:58:36 2012 +0300 */ (function ($, undefined) { var PROP_NAME = 'selectbox', FALSE = false, TRUE = true; /** * Selectbox manager. * Use the singleton instance of this class, $.selectbox, to interact with the select box. * Settings for (groups of) select boxes are maintained in an instance object, * allowing multiple different settings on the same page */ function Selectbox() { this._state = []; this._defaults = { // Global defaults for all the select box instances classHolder: "sbHolder", classHolderDisabled: "sbHolderDisabled", classSelector: "sbSelector", classOptions: "sbOptions", classGroup: "sbGroup", classSub: "sbSub", classDisabled: "sbDisabled", classToggleOpen: "sbToggleOpen", classToggle: "sbToggle", classFocus: "sbFocus", speed: 200, effect: "slide", // "slide" or "fade" onChange: null, //Define a callback function when the selectbox is changed onOpen: null, //Define a callback function when the selectbox is open onClose: null //Define a callback function when the selectbox is closed }; } $.extend(Selectbox.prototype, { /** * Is the first field in a jQuery collection open as a selectbox * * @param {Object} target * @return {Boolean} */ _isOpenSelectbox: function (target) { if (!target) { return FALSE; } var inst = this._getInst(target); return inst.isOpen; }, /** * Is the first field in a jQuery collection disabled as a selectbox * * @param {HTMLElement} target * @return {Boolean} */ _isDisabledSelectbox: function (target) { if (!target) { return FALSE; } var inst = this._getInst(target); return inst.isDisabled; }, /** * Attach the select box to a jQuery selection. * * @param {HTMLElement} target * @param {Object} settings */ _attachSelectbox: function (target, settings) { if (this._getInst(target)) { return FALSE; } var $target = $(target), self = this, inst = self._newInst($target), sbHolder, sbSelector, sbToggle, sbOptions, s = FALSE, optGroup = $target.find("optgroup"), opts = $target.find("option"), olen = opts.length; $target.attr("sb", inst.uid); $.extend(inst.settings, self._defaults, settings); self._state[inst.uid] = FALSE; $target.hide(); function closeOthers() { var key, sel, uid = this.attr("id").split("_")[1]; for (key in self._state) { if (key !== uid) { if (self._state.hasOwnProperty(key)) { sel = $("select[sb='" + key + "']")[0]; if (sel) { self._closeSelectbox(sel); } } } } } sbHolder = $("