2012-05-16 17:26:31 +00:00
|
|
|
/*!
|
2011-09-01 22:21:09 +00:00
|
|
|
* jQuery UI Selectmenu @VERSION
|
2012-07-16 18:36:01 +00:00
|
|
|
* http://jqueryui.com
|
2011-09-01 22:21:09 +00:00
|
|
|
*
|
2013-01-10 18:16:41 +00:00
|
|
|
* Copyright 2013 jQuery Foundation and other contributors
|
2012-08-11 17:57:17 +00:00
|
|
|
* Released under the MIT license.
|
2011-09-01 22:21:09 +00:00
|
|
|
* http://jquery.org/license
|
|
|
|
*
|
2012-11-29 18:41:20 +00:00
|
|
|
* http://api.jqueryui.com/selectmenu
|
2011-09-01 22:21:09 +00:00
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* jquery.ui.core.js
|
|
|
|
* jquery.ui.widget.js
|
|
|
|
* jquery.ui.position.js
|
|
|
|
* jquery.ui.menu.js
|
|
|
|
*/
|
|
|
|
(function( $, undefined ) {
|
|
|
|
|
|
|
|
$.widget( "ui.selectmenu", {
|
|
|
|
version: "@VERSION",
|
|
|
|
defaultElement: "<select>",
|
|
|
|
options: {
|
2012-12-15 01:21:51 +00:00
|
|
|
appendTo: null,
|
2012-12-19 23:10:06 +00:00
|
|
|
icons: {
|
|
|
|
button: "ui-icon-triangle-1-s"
|
|
|
|
},
|
2011-09-01 22:21:09 +00:00
|
|
|
position: {
|
|
|
|
my: "left top",
|
|
|
|
at: "left bottom",
|
|
|
|
collision: "none"
|
|
|
|
},
|
2012-11-29 19:23:30 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
// callbacks
|
2012-11-29 18:43:36 +00:00
|
|
|
change: null,
|
2011-09-30 19:16:55 +00:00
|
|
|
close: null,
|
2012-11-29 18:43:36 +00:00
|
|
|
focus: null,
|
|
|
|
open: null,
|
|
|
|
select: null
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_create: function() {
|
2012-11-12 22:06:05 +00:00
|
|
|
var selectmenuId = this.element.uniqueId().attr( "id" );
|
|
|
|
this.ids = { id: selectmenuId, button: selectmenuId + "-button", menu: selectmenuId + "-menu" };
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-10-11 23:38:30 +00:00
|
|
|
this._drawButton();
|
|
|
|
this._drawMenu();
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-12-12 16:26:17 +00:00
|
|
|
this._on( document, this._documentClick );
|
2012-02-25 00:43:53 +00:00
|
|
|
|
2012-01-22 12:38:34 +00:00
|
|
|
if ( this.options.disabled ) {
|
2012-01-11 20:20:24 +00:00
|
|
|
this.disable();
|
|
|
|
}
|
2011-09-30 19:16:55 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-10-11 23:38:30 +00:00
|
|
|
_drawButton: function() {
|
2012-11-12 22:06:05 +00:00
|
|
|
var tabindex = this.element.attr( "tabindex" );
|
2012-10-15 21:58:31 +00:00
|
|
|
|
2012-10-25 21:57:36 +00:00
|
|
|
// fix existing label
|
|
|
|
this.label = $( "label[for='" + this.ids.id + "']" ).attr( "for", this.ids.button );
|
|
|
|
this._on( this.label, {
|
2012-11-12 22:06:05 +00:00
|
|
|
"click": function( event ) {
|
2012-10-25 21:57:36 +00:00
|
|
|
this.button.focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-30 19:16:55 +00:00
|
|
|
// hide original select tag
|
2011-10-11 23:24:04 +00:00
|
|
|
this.element.hide();
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
// create button
|
2013-03-07 22:23:10 +00:00
|
|
|
this.button = $( "<span>", {
|
2013-03-07 22:53:15 +00:00
|
|
|
"class": "ui-selectmenu-button ui-widget ui-state-default ui-corner-all",
|
2012-02-23 22:25:03 +00:00
|
|
|
tabindex: ( tabindex ? tabindex : this.options.disabled ? -1 : 0 ),
|
|
|
|
id: this.ids.button,
|
|
|
|
width: this.element.outerWidth(),
|
2012-11-12 22:06:05 +00:00
|
|
|
role: "combobox",
|
|
|
|
"aria-expanded": false,
|
|
|
|
"aria-autocomplete": "list",
|
|
|
|
"aria-owns": this.ids.menu,
|
|
|
|
"aria-haspopup": true
|
2013-03-07 22:53:15 +00:00
|
|
|
})
|
|
|
|
.insertAfter( this.element );
|
2012-02-23 22:32:17 +00:00
|
|
|
|
2012-11-29 19:10:05 +00:00
|
|
|
this.button.prepend( $( "<span>", {
|
2012-12-19 23:10:06 +00:00
|
|
|
"class": "ui-icon " + this.options.icons.button
|
2012-11-12 22:06:05 +00:00
|
|
|
}));
|
2012-02-23 22:32:17 +00:00
|
|
|
|
2012-11-29 19:10:05 +00:00
|
|
|
this.buttonText = $( "<span>", {
|
2013-03-07 22:53:15 +00:00
|
|
|
"class": "ui-selectmenu-text"
|
|
|
|
})
|
|
|
|
.appendTo( this.button );
|
2012-12-14 17:03:49 +00:00
|
|
|
this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-11-29 18:54:10 +00:00
|
|
|
this._on( this.button, this._buttonEvents );
|
|
|
|
this._hoverable( this.button );
|
|
|
|
this._focusable( this.button );
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-10-11 23:38:30 +00:00
|
|
|
_drawMenu: function() {
|
2012-07-17 19:27:26 +00:00
|
|
|
var menuInstance,
|
|
|
|
that = this;
|
2011-11-18 16:14:38 +00:00
|
|
|
|
|
|
|
// create menu portion, append to body
|
2012-11-29 19:10:05 +00:00
|
|
|
this.menu = $( "<ul>", {
|
2012-11-12 22:06:05 +00:00
|
|
|
"aria-hidden": true,
|
|
|
|
"aria-labelledby": this.ids.button,
|
2011-10-12 20:06:18 +00:00
|
|
|
id: this.ids.menu
|
2011-09-24 01:08:03 +00:00
|
|
|
});
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-10-17 20:04:14 +00:00
|
|
|
// wrap menu
|
2012-11-29 19:10:05 +00:00
|
|
|
this.menuWrap = $( "<div>", {
|
2012-11-12 22:06:05 +00:00
|
|
|
"class": "ui-selectmenu-menu",
|
2012-12-19 23:10:06 +00:00
|
|
|
width: this.button.outerWidth()
|
2012-01-22 19:25:27 +00:00
|
|
|
})
|
2011-10-11 23:38:30 +00:00
|
|
|
.append( this.menu )
|
2012-12-15 01:21:51 +00:00
|
|
|
.appendTo( this._appendTo() );
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-27 21:15:23 +00:00
|
|
|
// init menu widget
|
2012-07-17 19:27:26 +00:00
|
|
|
menuInstance = this.menu.menu({
|
2011-10-17 20:03:22 +00:00
|
|
|
select: function( event, ui ) {
|
2012-10-19 22:22:12 +00:00
|
|
|
var item = ui.item.data( "ui-selectmenu-item" );
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-01-26 22:10:35 +00:00
|
|
|
that._select( item, event );
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2011-11-02 18:44:45 +00:00
|
|
|
if ( that.isOpen ) {
|
2011-10-17 20:03:22 +00:00
|
|
|
event.preventDefault();
|
2012-01-27 22:06:53 +00:00
|
|
|
that.close( event );
|
2011-10-17 20:03:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
focus: function( event, ui ) {
|
2012-10-19 22:22:12 +00:00
|
|
|
var item = ui.item.data( "ui-selectmenu-item" );
|
2012-12-12 18:31:39 +00:00
|
|
|
// prevent inital focus from firing and checks if its a newly focused item
|
2013-02-13 21:42:05 +00:00
|
|
|
if ( !that.isOpen && that.focus !== undefined && item.index !== that.focus ) {
|
2012-12-12 18:31:39 +00:00
|
|
|
that._trigger( "focus", event, { item: item } );
|
|
|
|
if ( !that.isOpen ) {
|
|
|
|
that._select( item, event );
|
2012-01-27 21:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
that.focus = item.index;
|
2012-10-15 21:58:31 +00:00
|
|
|
|
2012-12-12 16:39:00 +00:00
|
|
|
// Set ARIA active descendant
|
2013-02-13 22:09:00 +00:00
|
|
|
that.button.attr( "aria-activedescendant", that.menuItems.eq( item.index ).attr( "id" ) );
|
2012-05-24 16:41:32 +00:00
|
|
|
},
|
|
|
|
// set ARIA role
|
2012-11-12 22:06:05 +00:00
|
|
|
role: "listbox"
|
2012-07-17 19:27:26 +00:00
|
|
|
})
|
2013-03-19 19:27:12 +00:00
|
|
|
.menu( "instance" );
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-12-19 23:10:06 +00:00
|
|
|
// adjust border radius
|
|
|
|
this.menu.addClass( "ui-corner-bottom" ).removeClass( "ui-corner-all" );
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-11-10 00:25:30 +00:00
|
|
|
// make sure focus stays on selected item
|
|
|
|
menuInstance.delay = 999999999;
|
2012-02-26 00:50:55 +00:00
|
|
|
// unbind uneeded Menu events
|
2012-07-17 19:27:26 +00:00
|
|
|
menuInstance._off( this.menu, "mouseleave" );
|
2011-09-30 19:16:55 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-30 19:16:55 +00:00
|
|
|
refresh: function() {
|
2011-10-11 23:38:30 +00:00
|
|
|
this.menu.empty();
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-05-24 16:30:39 +00:00
|
|
|
var item,
|
2012-11-12 22:06:05 +00:00
|
|
|
options = this.element.find( "option" );
|
2012-01-27 21:44:43 +00:00
|
|
|
if ( options.length ) {
|
|
|
|
this._readOptions( options );
|
|
|
|
this._renderMenu( this.menu, this.items );
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-01-27 21:44:43 +00:00
|
|
|
this.menu.menu( "refresh" );
|
2013-02-13 22:09:00 +00:00
|
|
|
this.menuItems = this.menu.find( "li" ).not( ".ui-selectmenu-optgroup" ).find( "a" );
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-05-24 16:30:39 +00:00
|
|
|
item = this._getSelectedItem();
|
2012-12-12 18:31:39 +00:00
|
|
|
// make sure menu is selected item aware
|
2012-01-27 22:06:53 +00:00
|
|
|
this.menu.menu( "focus", null, item );
|
2013-02-09 02:24:50 +00:00
|
|
|
this._setAria( item.data( "ui-selectmenu-item" ) );
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-02-15 21:16:18 +00:00
|
|
|
// set disabled state
|
2012-05-16 18:41:24 +00:00
|
|
|
this._setOption( "disabled", this._getCreateOptions().disabled );
|
2012-01-27 21:44:43 +00:00
|
|
|
}
|
2011-11-18 16:14:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
open: function( event ) {
|
2012-11-29 19:23:30 +00:00
|
|
|
if ( this.options.disabled ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-07 18:34:13 +00:00
|
|
|
if ( !this.menuItems ) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2012-02-24 21:39:11 +00:00
|
|
|
|
2012-11-29 19:23:30 +00:00
|
|
|
this.isOpen = true;
|
|
|
|
this._toggleAttr();
|
2013-01-02 18:36:56 +00:00
|
|
|
this.menuWrap.position( $.extend( { of: this.button }, this.options.position ) );
|
2012-11-29 19:23:30 +00:00
|
|
|
|
|
|
|
this._trigger( "open", event );
|
2011-11-18 16:14:38 +00:00
|
|
|
},
|
|
|
|
|
2012-01-27 22:06:53 +00:00
|
|
|
close: function( event ) {
|
2012-12-03 21:58:07 +00:00
|
|
|
if ( !this.isOpen ) {
|
2012-12-03 22:05:09 +00:00
|
|
|
return;
|
2011-09-22 19:20:49 +00:00
|
|
|
}
|
2012-12-09 11:36:35 +00:00
|
|
|
|
2012-11-29 19:57:44 +00:00
|
|
|
this.isOpen = false;
|
|
|
|
this._toggleAttr();
|
2012-12-13 00:12:52 +00:00
|
|
|
|
|
|
|
// check if we have an item to select
|
|
|
|
if ( this.menuItems ) {
|
2013-02-13 22:07:25 +00:00
|
|
|
this.menu.menu( "focus", null, this._getSelectedItem() );
|
2012-12-13 00:12:52 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 19:57:44 +00:00
|
|
|
this._trigger( "close", event );
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-10-17 20:13:36 +00:00
|
|
|
widget: function() {
|
2012-02-21 19:22:13 +00:00
|
|
|
return this.button;
|
|
|
|
},
|
|
|
|
|
|
|
|
menuWidget: function() {
|
|
|
|
return this.menu;
|
2011-10-17 20:13:36 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
_renderMenu: function( ul, items ) {
|
2011-09-28 21:59:23 +00:00
|
|
|
var that = this,
|
2011-09-01 22:21:09 +00:00
|
|
|
currentOptgroup = "";
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
$.each( items, function( index, item ) {
|
2012-05-24 16:30:39 +00:00
|
|
|
if ( item.optgroup !== currentOptgroup ) {
|
2013-01-02 18:52:18 +00:00
|
|
|
$( "<li>", {
|
2012-11-12 22:06:05 +00:00
|
|
|
"class": "ui-selectmenu-optgroup" + ( item.element.parent( "optgroup" ).attr( "disabled" ) ? " ui-state-disabled" : "" ),
|
2012-12-03 22:07:30 +00:00
|
|
|
text: item.optgroup
|
2012-02-25 00:43:53 +00:00
|
|
|
}).appendTo( ul );
|
2011-09-01 22:21:09 +00:00
|
|
|
currentOptgroup = item.optgroup;
|
|
|
|
}
|
2011-09-28 21:59:23 +00:00
|
|
|
that._renderItem( ul, item );
|
2011-09-01 22:21:09 +00:00
|
|
|
});
|
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-10-19 22:22:12 +00:00
|
|
|
_renderItem: function( ul, item ) {
|
2013-01-02 18:52:18 +00:00
|
|
|
var li = $( "<li>" ).data( "ui-selectmenu-item", item ),
|
|
|
|
a = $( "<a>", { href: "#" });
|
2012-12-14 17:03:49 +00:00
|
|
|
|
2011-09-28 22:11:18 +00:00
|
|
|
if ( item.disabled ) {
|
2012-11-12 22:06:05 +00:00
|
|
|
li.addClass( "ui-state-disabled" );
|
2011-11-18 16:14:38 +00:00
|
|
|
}
|
2012-12-14 17:03:49 +00:00
|
|
|
this._setText( a, item.label );
|
|
|
|
|
|
|
|
return li.append( a ).appendTo( ul );
|
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-12-14 17:03:49 +00:00
|
|
|
_setText: function( element, value ) {
|
|
|
|
if ( value ) {
|
|
|
|
element.text( value );
|
|
|
|
} else {
|
|
|
|
element.html( " " );
|
|
|
|
}
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-01-27 22:11:31 +00:00
|
|
|
_move: function( direction, event ) {
|
2012-05-16 18:41:24 +00:00
|
|
|
if ( direction === "first" || direction === "last" ) {
|
2011-12-23 00:34:12 +00:00
|
|
|
// set focus manually for first or last item
|
2012-01-22 19:25:27 +00:00
|
|
|
this.menu.menu( "focus", event, this.menuItems[ direction ]() );
|
2011-12-23 00:34:12 +00:00
|
|
|
} else {
|
|
|
|
// move to and focus next or prev item
|
2012-01-27 22:11:31 +00:00
|
|
|
this.menu.menu( direction, event );
|
2011-12-23 00:34:12 +00:00
|
|
|
}
|
2011-09-24 00:04:06 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-24 02:04:54 +00:00
|
|
|
_getSelectedItem: function() {
|
2013-02-13 22:30:37 +00:00
|
|
|
return this.menuItems.eq( this.element[ 0 ].selectedIndex ).parent( "li" );
|
2011-09-24 02:04:54 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-24 00:04:06 +00:00
|
|
|
_toggle: function( event ) {
|
2011-11-18 16:14:38 +00:00
|
|
|
if ( this.isOpen ) {
|
2011-09-24 00:04:06 +00:00
|
|
|
this.close( event );
|
2011-11-18 16:14:38 +00:00
|
|
|
} else {
|
2011-09-24 00:04:06 +00:00
|
|
|
this.open( event );
|
|
|
|
}
|
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2012-12-12 16:26:17 +00:00
|
|
|
_documentClick: {
|
|
|
|
click: function( event ) {
|
|
|
|
if ( this.isOpen && !$( event.target ).closest( "li.ui-state-disabled, li.ui-selectmenu-optgroup, #" + this.ids.button ).length ) {
|
|
|
|
this.close( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-17 20:03:22 +00:00
|
|
|
_buttonEvents: {
|
2012-11-12 22:06:05 +00:00
|
|
|
focus: function() {
|
2012-02-21 22:41:00 +00:00
|
|
|
// init Menu on first focus
|
|
|
|
this.refresh();
|
2012-10-27 18:49:35 +00:00
|
|
|
// reset focus class as its removed by ui.widget._setOption
|
|
|
|
this.button.addClass( "ui-state-focus" );
|
2012-07-17 19:27:26 +00:00
|
|
|
this._off( this.button, "focus" );
|
2012-02-21 22:41:00 +00:00
|
|
|
},
|
2013-03-07 21:57:49 +00:00
|
|
|
click: function( event ) {
|
2013-03-07 19:10:56 +00:00
|
|
|
this._toggle( event );
|
2011-10-12 00:10:31 +00:00
|
|
|
event.preventDefault();
|
2011-09-30 19:16:55 +00:00
|
|
|
},
|
|
|
|
keydown: function( event ) {
|
2011-12-22 00:51:16 +00:00
|
|
|
var prevDef = true;
|
2012-02-26 02:46:27 +00:00
|
|
|
switch ( event.keyCode ) {
|
2011-09-30 19:16:55 +00:00
|
|
|
case $.ui.keyCode.TAB:
|
2012-02-21 23:29:05 +00:00
|
|
|
case $.ui.keyCode.ESCAPE:
|
2011-11-02 18:44:45 +00:00
|
|
|
if ( this.isOpen ) {
|
2011-10-12 20:14:28 +00:00
|
|
|
this.close( event );
|
|
|
|
}
|
2011-12-22 00:51:16 +00:00
|
|
|
prevDef = false;
|
2011-09-30 19:16:55 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.ENTER:
|
2011-11-02 18:44:45 +00:00
|
|
|
if ( this.isOpen ) {
|
2011-12-23 00:34:12 +00:00
|
|
|
this.menu.menu( "select", event );
|
2011-11-18 16:14:38 +00:00
|
|
|
}
|
2011-09-30 19:16:55 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
if ( event.altKey ) {
|
|
|
|
this._toggle( event );
|
|
|
|
} else {
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "previous", event );
|
2011-09-30 19:16:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
if ( event.altKey ) {
|
|
|
|
this._toggle( event );
|
|
|
|
} else {
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "next", event );
|
2011-09-30 19:16:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-03-07 19:10:56 +00:00
|
|
|
case $.ui.keyCode.SPACE:
|
|
|
|
if ( this.isOpen ) {
|
|
|
|
this.menu.menu( "select", event );
|
2013-03-07 22:23:10 +00:00
|
|
|
} else {
|
|
|
|
this._toggle( event );
|
2013-03-07 19:10:56 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-09-30 19:16:55 +00:00
|
|
|
case $.ui.keyCode.LEFT:
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "previous", event );
|
2011-09-30 19:16:55 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.RIGHT:
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "next", event );
|
2012-01-27 22:11:31 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.HOME:
|
2011-12-22 00:51:16 +00:00
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "first", event );
|
2011-12-22 00:51:16 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2011-12-23 00:34:12 +00:00
|
|
|
this._move( "last", event );
|
2011-09-30 19:16:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-11 23:38:30 +00:00
|
|
|
this.menu.trigger( event );
|
2011-12-22 00:51:16 +00:00
|
|
|
prevDef = false;
|
|
|
|
}
|
|
|
|
if ( prevDef ) {
|
|
|
|
event.preventDefault();
|
2011-09-30 19:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-18 16:14:38 +00:00
|
|
|
},
|
2012-01-27 22:11:31 +00:00
|
|
|
|
|
|
|
_select: function( item, event ) {
|
2012-02-26 02:46:27 +00:00
|
|
|
var oldIndex = this.element[ 0 ].selectedIndex;
|
2012-01-26 22:10:35 +00:00
|
|
|
// change native select element
|
2012-02-26 02:46:27 +00:00
|
|
|
this.element[ 0 ].selectedIndex = item.index;
|
2013-02-08 21:05:26 +00:00
|
|
|
this._setText( this.buttonText, item.label );
|
2013-02-09 02:24:50 +00:00
|
|
|
this._setAria( item );
|
2012-01-26 22:10:35 +00:00
|
|
|
this._trigger( "select", event, { item: item } );
|
|
|
|
|
2012-05-16 18:41:24 +00:00
|
|
|
if ( item.index !== oldIndex ) {
|
2012-01-26 22:10:35 +00:00
|
|
|
this._trigger( "change", event, { item: item } );
|
|
|
|
}
|
|
|
|
},
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2013-02-09 02:24:50 +00:00
|
|
|
_setAria: function( item ) {
|
2013-02-13 22:09:00 +00:00
|
|
|
var link = this.menuItems.eq( item.index ),
|
2013-02-13 22:07:25 +00:00
|
|
|
id = link.attr( "id" );
|
2013-03-01 16:18:03 +00:00
|
|
|
|
2012-01-22 18:19:37 +00:00
|
|
|
// change ARIA attr
|
2013-02-13 22:07:25 +00:00
|
|
|
this.button.attr({
|
|
|
|
"aria-labelledby": id,
|
|
|
|
"aria-activedescendant": id
|
|
|
|
});
|
|
|
|
this.menu.attr( "aria-activedescendant", id );
|
2012-01-12 21:01:49 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
_setOption: function( key, value ) {
|
2012-12-19 23:16:37 +00:00
|
|
|
if ( key === "icons" ) {
|
|
|
|
this.button.find( "span.ui-icon" )
|
|
|
|
.removeClass( this.options.icons.button )
|
|
|
|
.addClass( value.button );
|
|
|
|
}
|
|
|
|
|
2011-11-18 16:15:01 +00:00
|
|
|
this._super( key, value );
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-01 22:21:09 +00:00
|
|
|
if ( key === "appendTo" ) {
|
2012-12-15 01:21:51 +00:00
|
|
|
this.menuWrap.appendTo( this._appendTo() );
|
2011-09-01 22:21:09 +00:00
|
|
|
}
|
2011-09-24 03:29:05 +00:00
|
|
|
if ( key === "disabled" ) {
|
2012-01-11 20:20:24 +00:00
|
|
|
this.menu.menu( "option", "disabled", value );
|
2013-03-19 19:16:22 +00:00
|
|
|
this.button
|
|
|
|
.toggleClass( "ui-state-disabled", !!value )
|
|
|
|
.attr( "aria-disabled", value );
|
|
|
|
|
2011-09-27 19:46:29 +00:00
|
|
|
if ( value ) {
|
|
|
|
this.element.attr( "disabled", "disabled" );
|
2011-10-11 23:38:30 +00:00
|
|
|
this.button.attr( "tabindex", -1 );
|
2011-10-17 20:04:54 +00:00
|
|
|
this.close();
|
2011-09-27 19:46:29 +00:00
|
|
|
} else {
|
|
|
|
this.element.removeAttr( "disabled" );
|
2011-10-12 00:10:31 +00:00
|
|
|
this.button.attr( "tabindex", 0 );
|
2011-09-27 19:46:29 +00:00
|
|
|
}
|
2011-09-24 03:29:05 +00:00
|
|
|
}
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
2012-01-27 22:11:31 +00:00
|
|
|
|
2012-12-15 01:21:51 +00:00
|
|
|
_appendTo: function() {
|
|
|
|
var element = this.options.appendTo;
|
|
|
|
|
|
|
|
if ( element ) {
|
|
|
|
element = element.jquery || element.nodeType ?
|
|
|
|
$( element ) :
|
|
|
|
this.document.find( element ).eq( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !element ) {
|
|
|
|
element = this.element.closest( ".ui-front" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !element.length ) {
|
|
|
|
element = this.document[0].body;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2012-02-25 00:43:53 +00:00
|
|
|
_toggleAttr: function(){
|
2012-12-19 23:10:06 +00:00
|
|
|
this.button.toggleClass( "ui-corner-top", this.isOpen ).toggleClass( "ui-corner-all", !this.isOpen );
|
2012-11-12 22:06:05 +00:00
|
|
|
this.menuWrap.toggleClass( "ui-selectmenu-open", this.isOpen );
|
|
|
|
this.menu.attr( "aria-hidden", !this.isOpen);
|
|
|
|
this.button.attr( "aria-expanded", this.isOpen);
|
2012-01-20 00:30:16 +00:00
|
|
|
},
|
2012-02-26 00:50:55 +00:00
|
|
|
|
2012-01-22 12:38:34 +00:00
|
|
|
_getCreateOptions: function() {
|
2012-11-12 22:06:05 +00:00
|
|
|
return { disabled: !!this.element.attr( "disabled" ) };
|
2012-01-22 12:38:34 +00:00
|
|
|
},
|
2011-09-30 19:51:37 +00:00
|
|
|
|
2012-01-27 21:44:43 +00:00
|
|
|
_readOptions: function( options ) {
|
2011-11-18 16:14:38 +00:00
|
|
|
var data = [];
|
2012-12-03 22:28:06 +00:00
|
|
|
options.each( function( index, item ) {
|
2011-09-30 19:16:55 +00:00
|
|
|
var option = $( item ),
|
|
|
|
optgroup = option.parent( "optgroup" );
|
|
|
|
data.push({
|
|
|
|
element: option,
|
|
|
|
index: index,
|
2012-11-12 22:06:05 +00:00
|
|
|
value: option.attr( "value" ),
|
2012-12-14 17:03:49 +00:00
|
|
|
label: option.text(),
|
2012-05-24 16:30:39 +00:00
|
|
|
optgroup: optgroup.attr( "label" ) || "",
|
2011-09-30 19:16:55 +00:00
|
|
|
disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
|
2011-09-24 02:44:13 +00:00
|
|
|
});
|
2011-09-30 19:16:55 +00:00
|
|
|
});
|
|
|
|
this.items = data;
|
2011-09-01 22:21:09 +00:00
|
|
|
},
|
2011-11-18 16:14:38 +00:00
|
|
|
|
2011-09-24 00:04:06 +00:00
|
|
|
_destroy: function() {
|
2011-10-11 23:38:30 +00:00
|
|
|
this.menuWrap.remove();
|
2013-03-07 22:53:15 +00:00
|
|
|
this.button.remove();
|
2011-10-10 18:08:47 +00:00
|
|
|
this.element.show();
|
2012-10-25 18:55:48 +00:00
|
|
|
this.element.removeUniqueId();
|
2012-10-25 21:57:36 +00:00
|
|
|
this.label.attr( "for", this.ids.id );
|
2011-09-22 22:17:24 +00:00
|
|
|
}
|
2011-09-01 22:21:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}( jQuery ));
|