diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..02444b3 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,56 @@ +module.exports = function(grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + jshint: { + files: ['Gruntfile.js', 'src/javascripts/jquery.selectBoxIt.js'], + options: { + globals: { + jQuery: true, + console: false, + module: true, + document: true + }, + sub: true + } + }, + concat: { + dist: { + src: ['src/javascripts/jquery.selectBoxIt.core.js', 'src/javascripts/jquery.selectBoxIt.ariaAccessibility.js', 'src/javascripts/jquery.selectBoxIt.copyAttributes.js', 'src/javascripts/jquery.selectBoxIt.destroy.js', 'src/javascripts/jquery.selectBoxIt.disable.js', 'src/javascripts/jquery.selectBoxIt.dynamicPositioning.js', 'src/javascripts/jquery.selectBoxIt.enable.js', 'src/javascripts/jquery.selectBoxIt.keyboardNavigation.js', 'src/javascripts/jquery.selectBoxIt.keyboardSearch.js', 'src/javascripts/jquery.selectBoxIt.mobile.js', 'src/javascripts/jquery.selectBoxIt.selectOption.js', 'src/javascripts/jquery.selectBoxIt.setOption.js', 'src/javascripts/jquery.selectBoxIt.setOptions.js', 'src/javascripts/jquery.selectBoxIt.wait.js', 'src/javascripts/jquery.selectBoxIt.endClosure.js'], + dest: 'src/javascripts/jquery.selectBoxIt.js' + } + }, + uglify: { + my_target: { + files: { + 'src/javascripts/jquery.selectBoxIt.min.js': ['src/javascripts/jquery.selectBoxIt.js'] + } + }, + options: { + banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + + '<%= grunt.template.today("yyyy-mm-dd") %> \n' + + '<%= pkg.homepage ? "* " + pkg.homepage : "" %>\n' + + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>*/\n' + } + }, + jasmine: { + customRunner: { + src: 'src/javascripts/jquery.selectBoxIt.js', + options: { + specs: 'test/spec/selectBoxItSpec.js', + helpers: ['libs/jquery/jquery.js', 'libs/jqueryUI/jquery-ui.js', 'libs/jasmine/jasmine-jquery.js'] + } + } + } + }); + + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-jasmine'); + grunt.registerTask('test', ['concat', 'jshint', 'jasmine']); + grunt.registerTask('build', ['uglify']); + grunt.registerTask('default', ['test', 'build']); + +}; \ No newline at end of file diff --git a/libs/jasmine/jasmine-jquery-1.3.1.js b/libs/jasmine/jasmine-jquery.js similarity index 100% rename from libs/jasmine/jasmine-jquery-1.3.1.js rename to libs/jasmine/jasmine-jquery.js diff --git a/libs/jquery/jquery-1.8.0.min.js b/libs/jquery/jquery.js similarity index 100% rename from libs/jquery/jquery-1.8.0.min.js rename to libs/jquery/jquery.js diff --git a/libs/jqueryUI/jquery-ui-1.9.1.custom.min.js b/libs/jqueryUI/jquery-ui.js similarity index 100% rename from libs/jqueryUI/jquery-ui-1.9.1.custom.min.js rename to libs/jqueryUI/jquery-ui.js diff --git a/package.json b/package.json index 16a5265..29d7a09 100755 --- a/package.json +++ b/package.json @@ -22,10 +22,12 @@ "url": "http://www.gregfranko.com/jQuery.selectBoxIt.js//blob/master/LICENSE-MIT" } ], - "dependencies": { - "grunt": "0.3.17", - "grunt-jasmine-task": "0.2.3", - "temporary": "0.0.5" + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-concat": "~0.2.0", + "grunt-contrib-uglify": "~0.2.0", + "grunt-contrib-jshint": "~0.3.0", + "grunt-contrib-jasmine": "~0.4.2" }, "scripts": { "test": "grunt travis --verbose" diff --git a/src/javascripts/jquery.selectBoxIt.core.js b/src/javascripts/jquery.selectBoxIt.core.js index 714500a..1b8086d 100755 --- a/src/javascripts/jquery.selectBoxIt.core.js +++ b/src/javascripts/jquery.selectBoxIt.core.js @@ -624,6 +624,12 @@ }); + self.list.css({ + + "min-width": self.dropdown.width() + + }); + } // Dynamically adds the `max-width` and `line-height` CSS styles of the dropdown list text element @@ -1396,10 +1402,7 @@ // If the default text option is set and the current drop down option is not disabled if ((defaultText && self.options["html"] ? self.dropdownText.html() === defaultText: self.dropdownText.text() === defaultText) && self.selectBox.val() === elem.attr("data-val")) { - // Updates the dropdown list value - self._setText(self.dropdownText, currentText); - - self.dropdownText.trigger("internal-change"); + self.triggerEvent("change"); } @@ -1648,7 +1651,7 @@ var self = this, // Finds the currently option index - currentIndex = self.options["showFirstOption"] ? self.currentFocus : ((self.currentFocus - 1) >= 0 ? self.currentFocus: 0 ); + currentIndex = self.options["showFirstOption"] ? self.currentFocus : ((self.currentFocus - 1) >= 0 ? self.currentFocus: 0); // Triggers the custom option-click event on the original select box and passes the select box option self.selectBox.trigger(eventName, { "elem": self.selectBox.eq(currentIndex), "dropdown-elem": self.listItems.eq(self.currentFocus) }); diff --git a/src/javascripts/jquery.selectBoxIt.js b/src/javascripts/jquery.selectBoxIt.js old mode 100755 new mode 100644 index 13ddd79..f5121ca --- a/src/javascripts/jquery.selectBoxIt.js +++ b/src/javascripts/jquery.selectBoxIt.js @@ -624,6 +624,12 @@ }); + self.list.css({ + + "min-width": self.dropdown.width() + + }); + } // Dynamically adds the `max-width` and `line-height` CSS styles of the dropdown list text element @@ -1396,10 +1402,7 @@ // If the default text option is set and the current drop down option is not disabled if ((defaultText && self.options["html"] ? self.dropdownText.html() === defaultText: self.dropdownText.text() === defaultText) && self.selectBox.val() === elem.attr("data-val")) { - // Updates the dropdown list value - self._setText(self.dropdownText, currentText); - - self.dropdownText.trigger("internal-change"); + self.triggerEvent("change"); } @@ -1648,7 +1651,7 @@ var self = this, // Finds the currently option index - currentIndex = self.options["showFirstOption"] ? self.currentFocus : ((self.currentFocus - 1) >= 0 ? self.currentFocus: 0 ); + currentIndex = self.options["showFirstOption"] ? self.currentFocus : ((self.currentFocus - 1) >= 0 ? self.currentFocus: 0); // Triggers the custom option-click event on the original select box and passes the select box option self.selectBox.trigger(eventName, { "elem": self.selectBox.eq(currentIndex), "dropdown-elem": self.listItems.eq(self.currentFocus) }); diff --git a/src/javascripts/jquery.selectBoxIt.min.js b/src/javascripts/jquery.selectBoxIt.min.js index 0a57385..a4fe0fb 100755 --- a/src/javascripts/jquery.selectBoxIt.min.js +++ b/src/javascripts/jquery.selectBoxIt.min.js @@ -1,4 +1,4 @@ -/*! jquery Selectboxit - v3.3.0 - 2013-03-22 +/*! jquery.selectBoxIt - v3.3.0 - 2013-04-20 * http://www.selectboxit.com -* Copyright (c) 2013 Greg Franko; Licensed MIT */ -(function(e){"use strict";e(window.jQuery,window,document)})(function(e,t,n,r){"use strict";e.widget("selectBox.selectBoxIt",{VERSION:"3.3.0",options:{showEffect:"none",showEffectOptions:{},showEffectSpeed:"medium",hideEffect:"none",hideEffectOptions:{},hideEffectSpeed:"medium",showFirstOption:!0,defaultText:"",defaultIcon:"",downArrowIcon:"",theme:"default",keydownOpen:!0,isMobile:function(){var e=navigator.userAgent||navigator.vendor||t.opera;return/iPhone|iPod|iPad|Android|BlackBerry|Opera Mini|IEMobile/.test(e)},"native":!1,aggressiveChange:!1,selectWhenHidden:!0,viewport:e(t),similarSearch:!1,copyAttributes:["title","rel"],copyClasses:"button",nativeMousedown:!1,customShowHideEvent:!1,autoWidth:!0,html:!0},getThemes:function(){var t=this,n=e(t.element).attr("data-theme")||"c";return{bootstrap:{focus:"active",hover:"",disabled:"disabled",arrow:"caret",button:"btn",list:"dropdown-menu",container:"bootstrap",open:"open"},jqueryui:{focus:"ui-state-focus",hover:"ui-state-hover",disabled:"ui-state-disabled",arrow:"ui-icon ui-icon-triangle-1-s",button:"ui-widget ui-state-default",list:"ui-widget ui-widget-content",container:"jqueryui",open:"selectboxit-open"},jquerymobile:{focus:"ui-btn-down-"+n,hover:"ui-btn-hover-"+n,disabled:"ui-disabled",arrow:"ui-icon ui-icon-arrow-d ui-icon-shadow",button:"ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-up-"+n,list:"ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-up-"+n,container:"jquerymobile",open:"selectboxit-open"},"default":{focus:"selectboxit-focus",hover:"selectboxit-hover",disabled:"selectboxit-disabled",arrow:"selectboxit-default-arrow",button:"selectboxit-btn",list:"selectboxit-list",container:"selectboxit-container",open:"selectboxit-open"}}},_create:function(){var t=this;if(!t.element.is("select"))return;return t.element.hide(),t.originalElem=t.element[0],t.selectBox=t.element,t.selectItems=t.element.find("option"),t.firstSelectItem=t.selectItems.slice(0,1),t.documentHeight=e(n).height(),t.theme=t.getThemes()[t.options.theme]||t.getThemes()["default"],t.currentFocus=0,t.blur=!0,t.textArray=[],t.currentIndex=0,t.currentText="",t.flipped=!1,t._createDropdownButton()._createUnorderedList()._copyAttributes()._replaceSelectBox()._addClasses(t.theme)._eventHandlers(),t.originalElem.disabled&&t.disable&&t.disable(),t._ariaAccessibility&&t._ariaAccessibility(),t._mobile&&t._mobile(),t.options["native"]&&this._applyNativeSelect(),t.triggerEvent("create"),t},_createDropdownButton:function(){var t=this,n=t.originalElem.id||"",r=t.options.copyClasses,i=t.selectBox.attr("class")||"";return t.dropdownText=e("",{id:n&&n+"SelectBoxItText","class":"selectboxit-text",unselectable:"on",text:t.firstSelectItem.text()}).attr("data-val",t.originalElem.value),t.dropdownImageContainer=e("",{"class":"selectboxit-option-icon-container"}),t.dropdownImage=e("",{id:n&&n+"SelectBoxItDefaultIcon","class":"selectboxit-default-icon",unselectable:"on"}),t.dropdown=e("",{id:n&&n+"SelectBoxIt","class":"selectboxit "+(r==="button"?i:""),name:t.originalElem.name,tabindex:t.selectBox.attr("tabindex")||"0",unselectable:"on"}).append(t.dropdownImageContainer.append(t.dropdownImage)).append(t.dropdownText),t.dropdownContainer=e("",{id:n&&n+"SelectBoxItContainer","class":"selectboxit-container "+(r==="container"?i:"")}).append(t.dropdown),t},_createUnorderedList:function(){var t=this,n,r,i,s,o,u,a,f="",l=t.originalElem.id||"",c=e("
    ",{id:l&&l+"SelectBoxItOptions","class":"selectboxit-options",tabindex:-1}),h,p;t.options.showFirstOption||(t.selectItems=t.selectBox.find("option").slice(1)),t.selectItems.each(function(l){r="",i="",n=e(this).prop("disabled"),s=e(this).data("icon")||"",o=e(this).data("iconurl")||"",u=o?"selectboxit-option-icon-url":"",a=o?"style=\"background-image:url('"+o+"');\"":"",h=e(this).attr("data-text"),p=h?h:e(this).text(),e(this).parent().is("optgroup")&&(r="selectboxit-optgroup-option",e(this).index()===0&&(i=''+e(this).parent().first().attr("label")+"")),f+=i+'
  • "+(t.options.html?p:t.htmlEscape(p))+"
  • ",t.textArray[l]=n?"":p,this.selected&&(t._setText(t.dropdownText,p),t.currentFocus=l)});if((t.options.defaultText||t.selectBox.data("text"))&&!t.selectBox.find("option[selected]").length){var d=t.options.defaultText||t.selectBox.data("text");t._setText(t.dropdownText,d),t.options.defaultText=d}return c.append(f),t.list=c,t.dropdownContainer.append(t.list),t.listItems=t.list.find("li"),t.listItems.first().addClass("selectboxit-option-first"),t.listItems.last().addClass("selectboxit-option-last"),t.list.find("li[data-disabled='true']").not(".optgroupHeader").addClass(t.theme.disabled),t.dropdownImage.addClass(t.selectBox.data("icon")||t.options.defaultIcon||t.listItems.eq(t.currentFocus).find("i").attr("class")),t.dropdownImage.attr("style",t.listItems.eq(t.currentFocus).find("i").attr("style")),t},_replaceSelectBox:function(){var t=this,n,r=t.originalElem.id||"";return t.selectBox.css("display","none").after(t.dropdownContainer),n=t.dropdown.height(),t.downArrow=e("",{id:r&&r+"SelectBoxItArrow","class":"selectboxit-arrow",unselectable:"on"}),t.downArrowContainer=e("",{id:r&&r+"SelectBoxItArrowContainer","class":"selectboxit-arrow-container",unselectable:"on"}).append(t.downArrow),t.dropdown.append(t.downArrowContainer),t.listItems.removeClass("selectboxit-selected").eq(t.currentFocus).addClass("selectboxit-selected"),t.dropdownImageContainer.width()||t.dropdownImageContainer.remove(),t.options.autoWidth&&t.dropdown.css({width:"auto"}).css({width:t.list.outerWidth(!0)+t.downArrowContainer.outerWidth(!0)+t.dropdownImage.outerWidth(!0)}),t.dropdownText.css({"max-width":t.dropdownContainer.width()-(t.downArrowContainer.outerWidth(!0)+t.dropdownImage.outerWidth(!0))}),t},_scrollToView:function(e){var t=this,n=t.listItems.eq(t.currentFocus),r=t.list.scrollTop(),i=n.height(),s=n.position().top,o=Math.abs(s),u=t.list.height(),a;return e==="search"?u-s/g,">")},triggerEvent:function(e){var t=this,n=t.options.showFirstOption?t.currentFocus:t.currentFocus-1>=0?t.currentFocus:0;return t.selectBox.trigger(e,{elem:t.selectBox.eq(n),"dropdown-elem":t.listItems.eq(t.currentFocus)}),t},_copyAttributes:function(){var e=this;return e._addSelectBoxAttributes&&e._addSelectBoxAttributes(),e}});var i=e.selectBox.selectBoxIt.prototype;i._ariaAccessibility=function(){var t=this;return t.dropdown.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":t.list.attr("id"),"aria-activedescendant":t.listItems.eq(t.currentFocus).attr("id"),"aria-label":e("label[for='"+t.originalElem.id+"']").text()||"","aria-live":"assertive"}).bind({"disable.selectBoxIt":function(){t.dropdown.attr("aria-disabled","true")},"enable.selectBoxIt":function(){t.dropdown.attr("aria-disabled","false")}}),t.list.attr({role:"listbox","aria-hidden":"true"}),t.listItems.attr({role:"option"}),t.selectBox.bind({"change.selectBoxIt":function(){t.dropdownText.attr("aria-label",t.originalElem.value)},"open.selectBoxIt":function(){t.list.attr("aria-hidden","false"),t.dropdown.attr("aria-expanded","true")},"close.selectBoxIt":function(){t.list.attr("aria-hidden","true"),t.dropdown.attr("aria-expanded","false")}}),t},i._addSelectBoxAttributes=function(){var t=this;return t._addAttributes(t.selectBox.prop("attributes"),t.dropdown),t.selectItems.each(function(n){t._addAttributes(e(this).prop("attributes"),t.listItems.eq(n))}),t},e.selectBox.selectBoxIt.prototype._addAttributes=function(t,n){var r=this,i=r.options.copyAttributes;return t.length&&e.each(t,function(t,r){var s=r.name.toLowerCase(),o=r.value;o!=="null"&&(e.inArray(s,i)!==-1||s.indexOf("data")!==-1)&&n.attr(s,o)}),r},i.destroy=function(t){var n=this;return n._destroySelectBoxIt(),e.Widget.prototype.destroy.call(n),n._callbackSupport(t),n},i._destroySelectBoxIt=function(){var t=this;return t.dropdown.unbind(".selectBoxIt").undelegate(".selectBoxIt"),e.contains(t.dropdownContainer[0],t.originalElem)&&t.dropdownContainer.before(t.selectBox),t.dropdownContainer.remove(),t.selectBox.removeAttr("style").show(),t.triggerEvent("destroy"),t},i.disable=function(t){var n=this;return n.options.disabled||(n.close(),n.selectBox.attr("disabled","disabled"),n.dropdown.removeAttr("tabindex").addClass(n.theme.disabled),e.Widget.prototype.disable.call(n),n.triggerEvent("disable")),n._callbackSupport(t),n},i.disableOption=function(t,n){var r=this,i,s,o,u=e.type(t);return u==="number"&&(r.close(),i=r.selectBox.find("option").eq(t),r.triggerEvent("disable-option"),i.attr("disabled","disabled"),r.listItems.eq(t).attr("data-disabled","true").addClass(r.theme.disabled),r.currentFocus===t&&(s=r.listItems.eq(r.currentFocus).nextAll("li").not("[data-disabled='true']").first().length,o=r.listItems.eq(r.currentFocus).prevAll("li").not("[data-disabled='true']").first().length,s?r.moveDown():o?r.moveUp():r.disable())),r._callbackSupport(n),r},i._isDisabled=function(e){var t=this;return t.originalElem.disabled&&t.disable(),t},i._dynamicPositioning=function(){var t=this,n=t.dropdown.offset().top,r=t.list.data("max-height")||t.list.outerHeight(),i=t.dropdown.outerHeight(),s=t.options.viewport,o=s.height(),u=e.isWindow(s.get(0))?s.scrollTop():s.offset().top,a=n+i+r<=o+u,f=!a;t.list.data("max-height")||t.list.data("max-height",t.list.outerHeight());if(!f)t.list.css("max-height",r),t.list.css("top","auto");else if(t.dropdown.offset().top-u>=r)t.list.css("max-height",r),t.list.css("top",t.dropdown.position().top-t.list.outerHeight());else{var l=Math.abs(n+i+r-(o+u)),c=Math.abs(t.dropdown.offset().top-u-r);l",{id:o&&o+"SelectBoxItText","class":"selectboxit-text",unselectable:"on",text:e.firstSelectItem.text()}).attr("data-val",e.originalElem.value),e.dropdownImageContainer=t("",{"class":"selectboxit-option-icon-container"}),e.dropdownImage=t("",{id:o&&o+"SelectBoxItDefaultIcon","class":"selectboxit-default-icon",unselectable:"on"}),e.dropdown=t("",{id:o&&o+"SelectBoxIt","class":"selectboxit "+("button"===s?i:""),name:e.originalElem.name,tabindex:e.selectBox.attr("tabindex")||"0",unselectable:"on"}).append(e.dropdownImageContainer.append(e.dropdownImage)).append(e.dropdownText),e.dropdownContainer=t("",{id:o&&o+"SelectBoxItContainer","class":"selectboxit-container "+("container"===s?i:"")}).append(e.dropdown),e},_createUnorderedList:function(){var e,o,s,i,n,r,a,l,d,c=this,u="",p=c.originalElem.id||"",h=t("
      ",{id:p&&p+"SelectBoxItOptions","class":"selectboxit-options",tabindex:-1});if(c.options.showFirstOption||(c.selectItems=c.selectBox.find("option").slice(1)),c.selectItems.each(function(p){o="",s="",e=t(this).prop("disabled"),i=t(this).data("icon")||"",n=t(this).data("iconurl")||"",r=n?"selectboxit-option-icon-url":"",a=n?"style=\"background-image:url('"+n+"');\"":"",l=t(this).attr("data-text"),d=l?l:t(this).text(),t(this).parent().is("optgroup")&&(o="selectboxit-optgroup-option",0===t(this).index()&&(s=''+t(this).parent().first().attr("label")+"")),u+=s+'
    • "+(c.options.html?d:c.htmlEscape(d))+"
    • ",c.textArray[p]=e?"":d,this.selected&&(c._setText(c.dropdownText,d),c.currentFocus=p)}),(c.options.defaultText||c.selectBox.data("text"))&&!c.selectBox.find("option[selected]").length){var f=c.options.defaultText||c.selectBox.data("text");c._setText(c.dropdownText,f),c.options.defaultText=f}return h.append(u),c.list=h,c.dropdownContainer.append(c.list),c.listItems=c.list.find("li"),c.listItems.first().addClass("selectboxit-option-first"),c.listItems.last().addClass("selectboxit-option-last"),c.list.find("li[data-disabled='true']").not(".optgroupHeader").addClass(c.theme.disabled),c.dropdownImage.addClass(c.selectBox.data("icon")||c.options.defaultIcon||c.listItems.eq(c.currentFocus).find("i").attr("class")),c.dropdownImage.attr("style",c.listItems.eq(c.currentFocus).find("i").attr("style")),c},_replaceSelectBox:function(){var e,o=this,s=o.originalElem.id||"";return o.selectBox.css("display","none").after(o.dropdownContainer),e=o.dropdown.height(),o.downArrow=t("",{id:s&&s+"SelectBoxItArrow","class":"selectboxit-arrow",unselectable:"on"}),o.downArrowContainer=t("",{id:s&&s+"SelectBoxItArrowContainer","class":"selectboxit-arrow-container",unselectable:"on"}).append(o.downArrow),o.dropdown.append(o.downArrowContainer),o.listItems.removeClass("selectboxit-selected").eq(o.currentFocus).addClass("selectboxit-selected"),o.dropdownImageContainer.width()||o.dropdownImageContainer.remove(),o.options.autoWidth&&(o.dropdown.css({width:"auto"}).css({width:o.list.outerWidth(!0)+o.downArrowContainer.outerWidth(!0)+o.dropdownImage.outerWidth(!0)}),o.list.css({"min-width":o.dropdown.width()})),o.dropdownText.css({"max-width":o.dropdownContainer.width()-(o.downArrowContainer.outerWidth(!0)+o.dropdownImage.outerWidth(!0))}),o},_scrollToView:function(t){var e=this,o=e.listItems.eq(e.currentFocus),s=e.list.scrollTop(),i=o.height(),n=o.position().top,r=Math.abs(n),a=e.list.height();return"search"===t?i>a-n?e.list.scrollTop(s+(n-(a-i))):-1>n&&e.list.scrollTop(n-i):"up"===t?-1>n&&e.list.scrollTop(s-r):"down"===t&&i>a-n&&e.list.scrollTop(s+(r-a+i)),e},_callbackSupport:function(e){var o=this;return t.isFunction(e)&&e.call(o,o.dropdown),o},_setText:function(t,e){var o=this;return o.options.html?t.html(e):t.text(e),o},open:function(t){var e=this,o=e.options.showEffect,s=e.options.showEffectSpeed,i=e.options.showEffectOptions,n=e.options["native"],r=e.options.isMobile();return e.listItems.length?(n||r||this.list.is(":visible")||(e.triggerEvent("open"),e._dynamicPositioning&&e._dynamicPositioning(),"none"===o?e.list.show():"show"===o?e.list.show(s):"slideDown"===o?e.list.slideDown(s):"fadeIn"===o?e.list.fadeIn(s):e.list.show(o,i,s),e.list.promise().done(function(){e._scrollToView("search")})),e._callbackSupport(t),e):e},close:function(t){var e=this,o=e.options.hideEffect,s=e.options.hideEffectSpeed,i=e.options.hideEffectOptions,n=e.options["native"],r=e.options.isMobile();return n||r||!this.list.is(":visible")||(e.triggerEvent("close"),"none"===o?e.list.hide():"hide"===o?e.list.hide(s):"slideUp"===o?e.list.slideUp(s):"fadeOut"===o?e.list.fadeOut(s):e.list.hide(o,i,s)),e._callbackSupport(t),e},toggle:function(){var t=this,e=t.list.is(":visible");e?t.close():e||t.open()},_keyMappings:{38:"up",40:"down",13:"enter",8:"backspace",9:"tab",32:"space",27:"esc"},_keydownMethods:function(){var t=this,e=t.list.is(":visible")||!t.options.keydownOpen;return{down:function(){t.moveDown&&e&&t.moveDown()},up:function(){t.moveUp&&e&&t.moveUp()},enter:function(){var e=t.list.find("li."+t.focusClass);e.length||(e=t.listItems.first()),t._update(e),t.list.is(":visible")&&t.close(),t.triggerEvent("enter")},tab:function(){t.triggerEvent("tab-blur"),t.close()},backspace:function(){t.triggerEvent("backspace")},esc:function(){t.close()}}},_eventHandlers:function(){var e,o,s=this,i=s.options.nativeMousedown,n=s.options.customShowHideEvent;return this.dropdown.bind({"click.selectBoxIt":function(){s.dropdown.trigger("focus",!0),s.originalElem.disabled||(s.triggerEvent("click"),i||n||s.toggle())},"mousedown.selectBoxIt":function(){t(this).data("mdown",!0),s.triggerEvent("mousedown"),i&&!n&&s.toggle()},"mouseup.selectBoxIt":function(){s.triggerEvent("mouseup")},"blur.selectBoxIt":function(){s.blur&&(s.triggerEvent("blur"),s.list.is(":visible")&&s.close())},"focus.selectBoxIt":function(e,o){var i=t(this).data("mdown");t(this).removeData("mdown"),i||o||setTimeout(function(){s.triggerEvent("tab-focus")},0),o||s.triggerEvent("focus")},"keydown.selectBoxIt":function(t){var e=s._keyMappings[t.keyCode],o=s._keydownMethods()[e];o&&(o(),!s.options.keydownOpen||"up"!==e&&"down"!==e||s.open()),o&&"tab"!==e&&t.preventDefault()},"keypress.selectBoxIt":function(t){var e=t.charCode||t.keyCode,o=String.fromCharCode(e);s.search&&s.search(o,!0,!0),32===e&&t.preventDefault()},"mouseenter.selectBoxIt":function(){s.triggerEvent("mouseenter")},"mouseleave.selectBoxIt":function(){s.triggerEvent("mouseleave")}}),s.list.bind({"mouseover.selectBoxIt":function(){s.blur=!1},"mouseout.selectBoxIt":function(){s.blur=!0},"focusin.selectBoxIt":function(){s.dropdown.trigger("focus",!0)}}).delegate("li","click.selectBoxIt",function(){s._update(t(this)),s.triggerEvent("option-click"),"false"===t(this).attr("data-disabled")&&s.close()}).delegate("li","focusin.selectBoxIt",function(){s.listItems.not(t(this)).removeAttr("data-active"),t(this).attr("data-active","");var e=s.list.is(":hidden");(s.options.searchWhenHidden&&e||s.options.aggressiveChange||e&&s.options.selectWhenHidden)&&s._update(t(this))}).delegate("li","mouseup.selectBoxIt",function(){i&&!n&&(s._update(t(this)),s.triggerEvent("option-mouseup"),"false"===t(this).attr("data-disabled")&&s.close())}),s.selectBox.bind({"change.selectBoxIt, internal-change.selectBoxIt":function(t,i){var n;i||(n=s.list.find('li[data-val="'+s.originalElem.value+'"]'),n.length&&(s.listItems.eq(s.currentFocus).removeClass(s.focusClass),s.currentFocus=+n.attr("id"))),n=s.listItems.eq(s.currentFocus),e=n.attr("data-text"),o=e?e:n.find("a").text(),s._setText(s.dropdownText,o),s.dropdownText.attr("data-val",s.originalElem.value),n.find("i").attr("class")&&(s.dropdownImage.attr("class",n.find("i").attr("class")).addClass("selectboxit-default-icon"),s.dropdownImage.attr("style",n.find("i").attr("style"))),s.triggerEvent("changed")},"disable.selectBoxIt":function(){s.dropdown.addClass(s.theme.disabled)},"enable.selectBoxIt":function(){s.dropdown.removeClass(s.theme.disabled)}}),s},_update:function(t){var e,o,s=this,i=s.options.defaultText||s.selectBox.attr("data-text");"false"===t.attr("data-disabled")&&(e=s.listItems.eq(s.currentFocus).attr("data-text"),o=e?e:s.listItems.eq(s.currentFocus).text(),(i&&s.options.html?s.dropdownText.html()===i:s.dropdownText.text()===i)&&s.selectBox.val()===t.attr("data-val")?s.triggerEvent("change"):(s.selectBox.val(t.attr("data-val")),s.currentFocus=+t.attr("id"),s.originalElem.value!==s.dropdownText.attr("data-val")&&s.triggerEvent("change")))},_addClasses:function(e){var o=this,s=e.focus,i=e.hover,n=e.button,r=e.list,a=e.arrow,l=e.container,d=e.open;return o.focusClass=s,o.openClass=d,o.selectedClass="selectboxit-selected",o.downArrow.addClass(o.selectBox.data("downarrow")||o.options.downArrowIcon||a),o.dropdownContainer.addClass(l),o.dropdown.addClass(n),o.list.addClass(r),o.listItems.bind({"focusin.selectBoxIt":function(){t(this).addClass(s)},"blur.selectBoxIt":function(){t(this).removeClass(s)}}),o.selectBox.bind({"open.selectBoxIt":function(){var t,e=o.list.find("li[data-val='"+o.dropdownText.attr("data-val")+"']");e.length||(e=0===o.currentFocus&&!o.options.showFirstOption&&o.listItems.eq(0).hasClass(o.theme.disabled)?o.listItems.not("[data-disabled=true]").first():o.listItems.first()),o.currentFocus=+e.attr("id"),t=o.listItems.eq(o.currentFocus),o.dropdown.addClass(d),o.dropdown.removeClass(i).addClass(s),o.listItems.removeClass(o.selectedClass),o.listItems.removeAttr("data-active").not(t).removeClass(s),t.addClass(s).addClass(o.selectedClass)},"close.selectBoxIt":function(){o.dropdown.removeClass(d)},"blur.selectBoxIt":function(){o.dropdown.removeClass(s)},"mouseenter.selectBoxIt":function(){o.dropdown.addClass(i)},"mouseleave.selectBoxIt":function(){o.dropdown.removeClass(i)}}),o.listItems.bind({"mouseenter.selectBoxIt":function(){"false"===t(this).attr("data-disabled")&&(o.listItems.removeAttr("data-active"),t(this).addClass(s).attr("data-active",""),o.listItems.not(t(this)).removeClass(s),t(this).addClass(s),o.currentFocus=+t(this).attr("id"))},"mouseleave.selectBoxIt":function(){"false"===t(this).attr("data-disabled")&&(o.listItems.not(t(this)).removeClass(s).removeAttr("data-active"),t(this).addClass(s),o.currentFocus=+t(this).attr("id"))}}),o},refresh:function(t){var e=this;return e._destroySelectBoxIt&&(e._destroySelectBoxIt()._create(!0)._callbackSupport(t),e.triggerEvent("refresh")),e},htmlEscape:function(t){return(t+"").replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")},triggerEvent:function(t){var e=this,o=e.options.showFirstOption?e.currentFocus:e.currentFocus-1>=0?e.currentFocus:0;return e.selectBox.trigger(t,{elem:e.selectBox.eq(o),"dropdown-elem":e.listItems.eq(e.currentFocus)}),e},_copyAttributes:function(){var t=this;return t._addSelectBoxAttributes&&t._addSelectBoxAttributes(),t}});var s=t.selectBox.selectBoxIt.prototype;s._ariaAccessibility=function(){var e=this;return e.dropdown.attr({role:"combobox","aria-autocomplete":"list","aria-expanded":"false","aria-owns":e.list.attr("id"),"aria-activedescendant":e.listItems.eq(e.currentFocus).attr("id"),"aria-label":t("label[for='"+e.originalElem.id+"']").text()||"","aria-live":"assertive"}).bind({"disable.selectBoxIt":function(){e.dropdown.attr("aria-disabled","true")},"enable.selectBoxIt":function(){e.dropdown.attr("aria-disabled","false")}}),e.list.attr({role:"listbox","aria-hidden":"true"}),e.listItems.attr({role:"option"}),e.selectBox.bind({"change.selectBoxIt":function(){e.dropdownText.attr("aria-label",e.originalElem.value)},"open.selectBoxIt":function(){e.list.attr("aria-hidden","false"),e.dropdown.attr("aria-expanded","true")},"close.selectBoxIt":function(){e.list.attr("aria-hidden","true"),e.dropdown.attr("aria-expanded","false")}}),e},s._addSelectBoxAttributes=function(){var e=this;return e._addAttributes(e.selectBox.prop("attributes"),e.dropdown),e.selectItems.each(function(o){e._addAttributes(t(this).prop("attributes"),e.listItems.eq(o))}),e},t.selectBox.selectBoxIt.prototype._addAttributes=function(e,o){var s=this,i=s.options.copyAttributes;return e.length&&t.each(e,function(e,s){var n=s.name.toLowerCase(),r=s.value;"null"===r||-1===t.inArray(n,i)&&-1===n.indexOf("data")||o.attr(n,r)}),s},s.destroy=function(e){var o=this;return o._destroySelectBoxIt(),t.Widget.prototype.destroy.call(o),o._callbackSupport(e),o},s._destroySelectBoxIt=function(){var e=this;return e.dropdown.unbind(".selectBoxIt").undelegate(".selectBoxIt"),t.contains(e.dropdownContainer[0],e.originalElem)&&e.dropdownContainer.before(e.selectBox),e.dropdownContainer.remove(),e.selectBox.removeAttr("style").show(),e.triggerEvent("destroy"),e},s.disable=function(e){var o=this;return o.options.disabled||(o.close(),o.selectBox.attr("disabled","disabled"),o.dropdown.removeAttr("tabindex").addClass(o.theme.disabled),t.Widget.prototype.disable.call(o),o.triggerEvent("disable")),o._callbackSupport(e),o},s.disableOption=function(e,o){var s,i,n,r=this,a=t.type(e);return"number"===a&&(r.close(),s=r.selectBox.find("option").eq(e),r.triggerEvent("disable-option"),s.attr("disabled","disabled"),r.listItems.eq(e).attr("data-disabled","true").addClass(r.theme.disabled),r.currentFocus===e&&(i=r.listItems.eq(r.currentFocus).nextAll("li").not("[data-disabled='true']").first().length,n=r.listItems.eq(r.currentFocus).prevAll("li").not("[data-disabled='true']").first().length,i?r.moveDown():n?r.moveUp():r.disable())),r._callbackSupport(o),r},s._isDisabled=function(){var t=this;return t.originalElem.disabled&&t.disable(),t},s._dynamicPositioning=function(){var e=this,o=e.dropdown.offset().top,s=e.list.data("max-height")||e.list.outerHeight(),i=e.dropdown.outerHeight(),n=e.options.viewport,r=n.height(),a=t.isWindow(n.get(0))?n.scrollTop():n.offset().top,l=r+a>=o+i+s,d=!l;if(e.list.data("max-height")||e.list.data("max-height",e.list.outerHeight()),d)if(e.dropdown.offset().top-a>=s)e.list.css("max-height",s),e.list.css("top",e.dropdown.position().top-e.list.outerHeight());else{var c=Math.abs(o+i+s-(r+a)),u=Math.abs(e.dropdown.offset().top-a-s);u>c?(e.list.css("max-height",s-c-i/2),e.list.css("top","auto")):(e.list.css("max-height",s-u-i/2),e.list.css("top",e.dropdown.position().top-e.list.outerHeight()))}else e.list.css("max-height",s),e.list.css("top","auto");return e},s.enable=function(e){var o=this;return o.options.disabled&&(o.triggerEvent("enable"),o.selectBox.removeAttr("disabled"),o.dropdown.attr("tabindex",0).removeClass(o.theme.disabled),t.Widget.prototype.enable.call(o),o._callbackSupport(e)),o},s.enableOption=function(e,o){var s,i=this,n=t.type(e);return"number"===n&&(s=i.selectBox.find("option").eq(e),i.triggerEvent("enable-option"),s.removeAttr("disabled"),i.listItems.eq(e).attr("data-disabled","false").removeClass(i.theme.disabled)),i._callbackSupport(o),i},s.moveDown=function(t){var e=this;e.currentFocus+=1;var o="true"===e.listItems.eq(e.currentFocus).attr("data-disabled")?!0:!1,s=e.listItems.eq(e.currentFocus).nextAll("li").not("[data-disabled='true']").first().length;if(e.currentFocus===e.listItems.length)e.currentFocus-=1;else{if(o&&s)return e.listItems.eq(e.currentFocus-1).blur(),e.moveDown(),undefined;o&&!s?e.currentFocus-=1:(e.listItems.eq(e.currentFocus-1).blur().end().eq(e.currentFocus).focusin(),e._scrollToView("down"),e.triggerEvent("moveDown"))}return e._callbackSupport(t),e},s.moveUp=function(t){var e=this;e.currentFocus-=1;var o="true"===e.listItems.eq(e.currentFocus).attr("data-disabled")?!0:!1,s=e.listItems.eq(e.currentFocus).prevAll("li").not("[data-disabled='true']").first().length;if(-1===e.currentFocus)e.currentFocus+=1;else{if(o&&s)return e.listItems.eq(e.currentFocus+1).blur(),e.moveUp(),undefined;o&&!s?e.currentFocus+=1:(e.listItems.eq(this.currentFocus+1).blur().end().eq(e.currentFocus).focusin(),e._scrollToView("up"),e.triggerEvent("moveUp"))}return e._callbackSupport(t),e},s._setCurrentSearchOption=function(t){var e=this;return(e.options.aggressiveChange||e.options.selectWhenHidden||e.listItems.eq(t).is(":visible"))&&e.listItems.eq(t).data("disabled")!==!0&&(e.listItems.eq(e.currentFocus).blur(),e.currentIndex=t,e.currentFocus=t,e.listItems.eq(e.currentFocus).focusin(),e._scrollToView("search"),e.triggerEvent("search")),e},s._searchAlgorithm=function(t,e){var o,s,i,n,r=this,a=!1,l=r.textArray,d=r.currentText;for(o=t,i=l.length;i>o;o+=1){for(n=l[o],s=0;i>s;s+=1)-1!==l[s].search(e)&&(a=!0,s=i);if(a||(r.currentText=r.currentText.charAt(r.currentText.length-1).replace(/[|()\[{.+*?$\\]/g,"\\$0"),d=r.currentText),e=RegExp(d,"gi"),3>d.length){if(e=RegExp(d.charAt(0),"gi"),-1!==n.charAt(0).search(e))return r._setCurrentSearchOption(o),(n.substring(0,d.length).toLowerCase()!==d.toLowerCase()||r.options.similarSearch)&&(r.currentIndex+=1),!1}else if(-1!==n.search(e))return r._setCurrentSearchOption(o),!1;if(n.toLowerCase()===r.currentText.toLowerCase())return r._setCurrentSearchOption(o),r.currentText="",!1}return!0},s.search=function(t,e,o){var s=this;o?s.currentText+=t.replace(/[|()\[{.+*?$\\]/g,"\\$0"):s.currentText=t.replace(/[|()\[{.+*?$\\]/g,"\\$0");var i=s._searchAlgorithm(s.currentIndex,RegExp(s.currentText,"gi"));return i&&s._searchAlgorithm(0,s.currentText),s._callbackSupport(e),s},s._applyNativeSelect=function(){var t,e,o,s=this;s.dropdownContainer.append(s.selectBox),s.selectBox.css({display:"block",width:s.dropdown.outerWidth(),height:s.dropdown.outerHeight(),opacity:"0",position:"absolute",top:"0",left:"0",cursor:"pointer","z-index":"999999",margin:s.dropdown.css("margin"),padding:"0","-webkit-appearance":"menulist-button"}).bind({"changed.selectBoxIt":function(){t=s.selectBox.find("option").filter(":selected"),e=t.attr("data-text"),o=e?e:t.text(),s._setText(s.dropdownText,o),s.list.find('li[data-val="'+t.val()+'"]').find("i").attr("class")&&s.dropdownImage.attr("class",s.list.find('li[data-val="'+t.val()+'"]').find("i").attr("class")).addClass("selectboxit-default-icon")}})},s._mobile=function(){var t=this;return t.options.isMobile()&&t._applyNativeSelect(),this},s.selectOption=function(e,o){var s=this,i=t.type(e);return"number"===i?s.selectBox.val(s.selectBox.find("option").eq(e).val()).change():"string"===i&&s.selectBox.val(e).change(),s._callbackSupport(o),s},s.setOption=function(e,o,s){var i=this,n=i.listItems.eq(0);return"showFirstOption"!==e||o?"showFirstOption"===e&&o?n.show():"defaultIcon"===e&&o?i.dropdownImage.attr("class",o+" selectboxit-arrow"):"downArrowIcon"===e&&o?i.downArrow.attr("class",o+" selectboxit-arrow"):"defaultText"===e&&i._setText(i.dropdownText,o):n.hide(),t.Widget.prototype._setOption.apply(i,arguments),i._callbackSupport(s),i},s.setOptions=function(e,o){var s=this,i=s.listItems.eq(0);return t.Widget.prototype._setOptions.apply(s,arguments),s.options.showFirstOption?i.show():i.hide(),s.options.defaultIcon&&s.dropdownImage.attr("class",s.options.defaultIcon+" selectboxit-arrow"),s.options.downArrowIcon&&s.downArrow.attr("class",s.options.downArrowIcon+" selectboxit-arrow"),s.options.defaultText&&s._setText(s.dropdownText,s.options.defaultText),s._callbackSupport(o),s},s.wait=function(t,e){var o=this,s=this.returnTimeout(t);return s.then(function(){o._callbackSupport(e)}),o},s.returnTimeout=function(e){return t.Deferred(function(t){setTimeout(t.resolve,e)})}}); \ No newline at end of file diff --git a/src/stylesheets/jquery.selectBoxIt.css b/src/stylesheets/jquery.selectBoxIt.css index ad7fff3..a31cf94 100755 --- a/src/stylesheets/jquery.selectBoxIt.css +++ b/src/stylesheets/jquery.selectBoxIt.css @@ -62,7 +62,7 @@ -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; - cursor: not-allowed; + cursor: default; } /* Button Text */ @@ -81,8 +81,8 @@ .selectboxit-container .selectboxit-options { -moz-box-sizing: border-box; box-sizing: border-box; - min-width: 100%; /* Minimum Width of the dropdown list box options */ - *width: 100%; + min-width: 220px; /* Minimum Width of the dropdown list box options */ + *width: 220px; margin: 0; padding: 0; list-style: none; diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 3cc25ad..b1b5ee8 100755 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -9,12 +9,12 @@ - - + + - +