;(function($) { /* * ui.dropdownchecklist * * Copyright (c) 2008-2009 Adrian Tosca * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * */ // The dropdown check list jQuery plugin transforms a regular select html element into a dropdown check list. $.widget("ui.dropdownchecklist", { // Creates the drop container that keeps the items and appends it to the document _appendDropContainer: function() { var wrapper = $("
"); // the container is wrapped in a div wrapper.addClass("ui-dropdownchecklist-dropcontainer-wrapper"); // initially hidden wrapper.css({ position: 'absolute', left: "-3300", top: "-3300px", width: '3000px', height: '3000px' }); var container = $("
"); // the actual container container.addClass("ui-dropdownchecklist-dropcontainer") .css("overflow-y", "auto"); container.addClass("ui-dropdownchecklist-dropcontainer") .css("width", this.options.width); wrapper.append(container); $(document.body).append(wrapper); //wrapper.insertAfter(this.sourceSelect); // flag that tells if the drop container is shown or not wrapper.drop = false; return wrapper; }, _isDropDownKeyShortcut: function(e) { return e.altKey && ($.ui.keyCode.DOWN == (e.keyCode || e.which));// Alt + Down Arrow }, _isDroDownCloseKey: function(e) { return $.ui.keyCode.ESCAPE == (e.keyCode || e.which); }, _handleKeyboard: function(e) { var self = this; if (self._isDropDownKeyShortcut(e)) { e.stopPropagation(); self._toggleDropContainer(); self.dropWrapper.find("input:first").focus(); } else if (self.dropWrapper.drop && self._isDroDownCloseKey(e)) { self._toggleDropContainer(); } }, // Creates the control that will replace the source select and appends it to the document // The control resembles a regular select with single selection _appendControl: function() { var self = this, sourceSelect = this.sourceSelect; // the controls is wrapped in a span with inline-block display var wrapper = $(""); wrapper.addClass("ui-dropdownchecklist-wrapper"); wrapper.css({ display: "inline-block", cursor: "default" }); // the actual control, can be styled to set the border and drop right image var control = $(""); control.addClass("ui-dropdownchecklist"); control.css({ display: "inline-block" }); control.attr("tabIndex", 0); control.keyup(function(e) {self._handleKeyboard(e)}); wrapper.append(control); // the text container keeps the control text that is build from the selected (checked) items var textContainer = $(""); textContainer.addClass("ui-dropdownchecklist-text") textContainer.css({ display: "inline-block", overflow: "hidden" }); control.append(textContainer); // add the hover styles to the control wrapper.hover(function() { if (!self.disabled) { control.toggleClass("ui-dropdownchecklist-hover") } }, function() { if (!self.disabled) { control.toggleClass("ui-dropdownchecklist-hover") } }); // clicking on the control toggles the drop container wrapper.click(function(event) { if (!self.disabled) { event.stopPropagation(); self._toggleDropContainer(); } }) wrapper.insertAfter(sourceSelect); return wrapper; }, // Creates a drop item that coresponds to an option element in the source select _createDropItem: function(index, value, text, checked, disabled, indent) { var self = this; // the item contains a div that contains a checkbox input and a span for text // the div var item = $("
"); item.addClass("ui-dropdownchecklist-item"); item.css({whiteSpace: "nowrap"}); if( this.options.itemwidth){ item.css({width: this.options.itemwidth+"px"}); } var checkedString = checked ? ' checked="checked"' : ''; var disabledString = disabled ? ' disabled="disabled"' : ''; var idBase = (self.sourceSelect.attr("id") || "ddcl"); var id = idBase + index; var checkBox; if (self.initialMultiple) { // the checkbox checkBox = $(''); } else { // the radiobutton checkBox = $(''); } checkBox = checkBox.attr("index", index).val(value); item.append(checkBox); // the text var label = $("