/*! * jquery selectbox plugin 0.2 * download from http://www.sucaijiayuan.com */ (function ($, undefined) { var prop_name = 'selectbox', false = false, true = true; 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 = $("
", { "id": "sbholder_" + inst.uid, "class": inst.settings.classholder, "tabindex": $target.attr("tabindex") }); sbselector = $("", { "id": "sbselector_" + inst.uid, "href": "#", "class": inst.settings.classselector, "click": function (e) { e.preventdefault(); closeothers.apply($(this), []); var uid = $(this).attr("id").split("_")[1]; if (self._state[uid]) { self._closeselectbox(target); } else { self._openselectbox(target); } } }); sbtoggle = $("", { "id": "sbtoggle_" + inst.uid, "href": "#", "class": inst.settings.classtoggle, "click": function (e) { e.preventdefault(); closeothers.apply($(this), []); var uid = $(this).attr("id").split("_")[1]; if (self._state[uid]) { self._closeselectbox(target); } else { self._openselectbox(target); } } }); sbtoggle.appendto(sbholder); sboptions = $("