Edit File by line
/home/barbar84/public_h.../wp-inclu.../js/jquery/ui
File: selectmenu.js
/*!
[0] Fix | Delete
* jQuery UI Selectmenu 1.12.1
[1] Fix | Delete
* http://jqueryui.com
[2] Fix | Delete
*
[3] Fix | Delete
* Copyright jQuery Foundation and other contributors
[4] Fix | Delete
* Released under the MIT license.
[5] Fix | Delete
* http://jquery.org/license
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
//>>label: Selectmenu
[9] Fix | Delete
//>>group: Widgets
[10] Fix | Delete
// jscs:disable maximumLineLength
[11] Fix | Delete
//>>description: Duplicates and extends the functionality of a native HTML select element, allowing it to be customizable in behavior and appearance far beyond the limitations of a native select.
[12] Fix | Delete
// jscs:enable maximumLineLength
[13] Fix | Delete
//>>docs: http://api.jqueryui.com/selectmenu/
[14] Fix | Delete
//>>demos: http://jqueryui.com/selectmenu/
[15] Fix | Delete
//>>css.structure: ../../themes/base/core.css
[16] Fix | Delete
//>>css.structure: ../../themes/base/selectmenu.css, ../../themes/base/button.css
[17] Fix | Delete
//>>css.theme: ../../themes/base/theme.css
[18] Fix | Delete
[19] Fix | Delete
( function( factory ) {
[20] Fix | Delete
if ( typeof define === "function" && define.amd ) {
[21] Fix | Delete
[22] Fix | Delete
// AMD. Register as an anonymous module.
[23] Fix | Delete
define( [
[24] Fix | Delete
"jquery",
[25] Fix | Delete
"./menu",
[26] Fix | Delete
"./core"
[27] Fix | Delete
], factory );
[28] Fix | Delete
} else {
[29] Fix | Delete
[30] Fix | Delete
// Browser globals
[31] Fix | Delete
factory( jQuery );
[32] Fix | Delete
}
[33] Fix | Delete
}( function( $ ) {
[34] Fix | Delete
[35] Fix | Delete
return $.widget( "ui.selectmenu", [ $.ui.formResetMixin, {
[36] Fix | Delete
version: "1.12.1",
[37] Fix | Delete
defaultElement: "<select>",
[38] Fix | Delete
options: {
[39] Fix | Delete
appendTo: null,
[40] Fix | Delete
classes: {
[41] Fix | Delete
"ui-selectmenu-button-open": "ui-corner-top",
[42] Fix | Delete
"ui-selectmenu-button-closed": "ui-corner-all"
[43] Fix | Delete
},
[44] Fix | Delete
disabled: null,
[45] Fix | Delete
icons: {
[46] Fix | Delete
button: "ui-icon-triangle-1-s"
[47] Fix | Delete
},
[48] Fix | Delete
position: {
[49] Fix | Delete
my: "left top",
[50] Fix | Delete
at: "left bottom",
[51] Fix | Delete
collision: "none"
[52] Fix | Delete
},
[53] Fix | Delete
width: false,
[54] Fix | Delete
[55] Fix | Delete
// Callbacks
[56] Fix | Delete
change: null,
[57] Fix | Delete
close: null,
[58] Fix | Delete
focus: null,
[59] Fix | Delete
open: null,
[60] Fix | Delete
select: null
[61] Fix | Delete
},
[62] Fix | Delete
[63] Fix | Delete
_create: function() {
[64] Fix | Delete
var selectmenuId = this.element.uniqueId().attr( "id" );
[65] Fix | Delete
this.ids = {
[66] Fix | Delete
element: selectmenuId,
[67] Fix | Delete
button: selectmenuId + "-button",
[68] Fix | Delete
menu: selectmenuId + "-menu"
[69] Fix | Delete
};
[70] Fix | Delete
[71] Fix | Delete
this._drawButton();
[72] Fix | Delete
this._drawMenu();
[73] Fix | Delete
this._bindFormResetHandler();
[74] Fix | Delete
[75] Fix | Delete
this._rendered = false;
[76] Fix | Delete
this.menuItems = $();
[77] Fix | Delete
},
[78] Fix | Delete
[79] Fix | Delete
_drawButton: function() {
[80] Fix | Delete
var icon,
[81] Fix | Delete
that = this,
[82] Fix | Delete
item = this._parseOption(
[83] Fix | Delete
this.element.find( "option:selected" ),
[84] Fix | Delete
this.element[ 0 ].selectedIndex
[85] Fix | Delete
);
[86] Fix | Delete
[87] Fix | Delete
// Associate existing label with the new button
[88] Fix | Delete
this.labels = this.element.labels().attr( "for", this.ids.button );
[89] Fix | Delete
this._on( this.labels, {
[90] Fix | Delete
click: function( event ) {
[91] Fix | Delete
this.button.focus();
[92] Fix | Delete
event.preventDefault();
[93] Fix | Delete
}
[94] Fix | Delete
} );
[95] Fix | Delete
[96] Fix | Delete
// Hide original select element
[97] Fix | Delete
this.element.hide();
[98] Fix | Delete
[99] Fix | Delete
// Create button
[100] Fix | Delete
this.button = $( "<span>", {
[101] Fix | Delete
tabindex: this.options.disabled ? -1 : 0,
[102] Fix | Delete
id: this.ids.button,
[103] Fix | Delete
role: "combobox",
[104] Fix | Delete
"aria-expanded": "false",
[105] Fix | Delete
"aria-autocomplete": "list",
[106] Fix | Delete
"aria-owns": this.ids.menu,
[107] Fix | Delete
"aria-haspopup": "true",
[108] Fix | Delete
title: this.element.attr( "title" )
[109] Fix | Delete
} )
[110] Fix | Delete
.insertAfter( this.element );
[111] Fix | Delete
[112] Fix | Delete
this._addClass( this.button, "ui-selectmenu-button ui-selectmenu-button-closed",
[113] Fix | Delete
"ui-button ui-widget" );
[114] Fix | Delete
[115] Fix | Delete
icon = $( "<span>" ).appendTo( this.button );
[116] Fix | Delete
this._addClass( icon, "ui-selectmenu-icon", "ui-icon " + this.options.icons.button );
[117] Fix | Delete
this.buttonItem = this._renderButtonItem( item )
[118] Fix | Delete
.appendTo( this.button );
[119] Fix | Delete
[120] Fix | Delete
if ( this.options.width !== false ) {
[121] Fix | Delete
this._resizeButton();
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
this._on( this.button, this._buttonEvents );
[125] Fix | Delete
this.button.one( "focusin", function() {
[126] Fix | Delete
[127] Fix | Delete
// Delay rendering the menu items until the button receives focus.
[128] Fix | Delete
// The menu may have already been rendered via a programmatic open.
[129] Fix | Delete
if ( !that._rendered ) {
[130] Fix | Delete
that._refreshMenu();
[131] Fix | Delete
}
[132] Fix | Delete
} );
[133] Fix | Delete
},
[134] Fix | Delete
[135] Fix | Delete
_drawMenu: function() {
[136] Fix | Delete
var that = this;
[137] Fix | Delete
[138] Fix | Delete
// Create menu
[139] Fix | Delete
this.menu = $( "<ul>", {
[140] Fix | Delete
"aria-hidden": "true",
[141] Fix | Delete
"aria-labelledby": this.ids.button,
[142] Fix | Delete
id: this.ids.menu
[143] Fix | Delete
} );
[144] Fix | Delete
[145] Fix | Delete
// Wrap menu
[146] Fix | Delete
this.menuWrap = $( "<div>" ).append( this.menu );
[147] Fix | Delete
this._addClass( this.menuWrap, "ui-selectmenu-menu", "ui-front" );
[148] Fix | Delete
this.menuWrap.appendTo( this._appendTo() );
[149] Fix | Delete
[150] Fix | Delete
// Initialize menu widget
[151] Fix | Delete
this.menuInstance = this.menu
[152] Fix | Delete
.menu( {
[153] Fix | Delete
classes: {
[154] Fix | Delete
"ui-menu": "ui-corner-bottom"
[155] Fix | Delete
},
[156] Fix | Delete
role: "listbox",
[157] Fix | Delete
select: function( event, ui ) {
[158] Fix | Delete
event.preventDefault();
[159] Fix | Delete
[160] Fix | Delete
// Support: IE8
[161] Fix | Delete
// If the item was selected via a click, the text selection
[162] Fix | Delete
// will be destroyed in IE
[163] Fix | Delete
that._setSelection();
[164] Fix | Delete
[165] Fix | Delete
that._select( ui.item.data( "ui-selectmenu-item" ), event );
[166] Fix | Delete
},
[167] Fix | Delete
focus: function( event, ui ) {
[168] Fix | Delete
var item = ui.item.data( "ui-selectmenu-item" );
[169] Fix | Delete
[170] Fix | Delete
// Prevent inital focus from firing and check if its a newly focused item
[171] Fix | Delete
if ( that.focusIndex != null && item.index !== that.focusIndex ) {
[172] Fix | Delete
that._trigger( "focus", event, { item: item } );
[173] Fix | Delete
if ( !that.isOpen ) {
[174] Fix | Delete
that._select( item, event );
[175] Fix | Delete
}
[176] Fix | Delete
}
[177] Fix | Delete
that.focusIndex = item.index;
[178] Fix | Delete
[179] Fix | Delete
that.button.attr( "aria-activedescendant",
[180] Fix | Delete
that.menuItems.eq( item.index ).attr( "id" ) );
[181] Fix | Delete
}
[182] Fix | Delete
} )
[183] Fix | Delete
.menu( "instance" );
[184] Fix | Delete
[185] Fix | Delete
// Don't close the menu on mouseleave
[186] Fix | Delete
this.menuInstance._off( this.menu, "mouseleave" );
[187] Fix | Delete
[188] Fix | Delete
// Cancel the menu's collapseAll on document click
[189] Fix | Delete
this.menuInstance._closeOnDocumentClick = function() {
[190] Fix | Delete
return false;
[191] Fix | Delete
};
[192] Fix | Delete
[193] Fix | Delete
// Selects often contain empty items, but never contain dividers
[194] Fix | Delete
this.menuInstance._isDivider = function() {
[195] Fix | Delete
return false;
[196] Fix | Delete
};
[197] Fix | Delete
},
[198] Fix | Delete
[199] Fix | Delete
refresh: function() {
[200] Fix | Delete
this._refreshMenu();
[201] Fix | Delete
this.buttonItem.replaceWith(
[202] Fix | Delete
this.buttonItem = this._renderButtonItem(
[203] Fix | Delete
[204] Fix | Delete
// Fall back to an empty object in case there are no options
[205] Fix | Delete
this._getSelectedItem().data( "ui-selectmenu-item" ) || {}
[206] Fix | Delete
)
[207] Fix | Delete
);
[208] Fix | Delete
if ( this.options.width === null ) {
[209] Fix | Delete
this._resizeButton();
[210] Fix | Delete
}
[211] Fix | Delete
},
[212] Fix | Delete
[213] Fix | Delete
_refreshMenu: function() {
[214] Fix | Delete
var item,
[215] Fix | Delete
options = this.element.find( "option" );
[216] Fix | Delete
[217] Fix | Delete
this.menu.empty();
[218] Fix | Delete
[219] Fix | Delete
this._parseOptions( options );
[220] Fix | Delete
this._renderMenu( this.menu, this.items );
[221] Fix | Delete
[222] Fix | Delete
this.menuInstance.refresh();
[223] Fix | Delete
this.menuItems = this.menu.find( "li" )
[224] Fix | Delete
.not( ".ui-selectmenu-optgroup" )
[225] Fix | Delete
.find( ".ui-menu-item-wrapper" );
[226] Fix | Delete
[227] Fix | Delete
this._rendered = true;
[228] Fix | Delete
[229] Fix | Delete
if ( !options.length ) {
[230] Fix | Delete
return;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
item = this._getSelectedItem();
[234] Fix | Delete
[235] Fix | Delete
// Update the menu to have the correct item focused
[236] Fix | Delete
this.menuInstance.focus( null, item );
[237] Fix | Delete
this._setAria( item.data( "ui-selectmenu-item" ) );
[238] Fix | Delete
[239] Fix | Delete
// Set disabled state
[240] Fix | Delete
this._setOption( "disabled", this.element.prop( "disabled" ) );
[241] Fix | Delete
},
[242] Fix | Delete
[243] Fix | Delete
open: function( event ) {
[244] Fix | Delete
if ( this.options.disabled ) {
[245] Fix | Delete
return;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
// If this is the first time the menu is being opened, render the items
[249] Fix | Delete
if ( !this._rendered ) {
[250] Fix | Delete
this._refreshMenu();
[251] Fix | Delete
} else {
[252] Fix | Delete
[253] Fix | Delete
// Menu clears focus on close, reset focus to selected item
[254] Fix | Delete
this._removeClass( this.menu.find( ".ui-state-active" ), null, "ui-state-active" );
[255] Fix | Delete
this.menuInstance.focus( null, this._getSelectedItem() );
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
// If there are no options, don't open the menu
[259] Fix | Delete
if ( !this.menuItems.length ) {
[260] Fix | Delete
return;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
this.isOpen = true;
[264] Fix | Delete
this._toggleAttr();
[265] Fix | Delete
this._resizeMenu();
[266] Fix | Delete
this._position();
[267] Fix | Delete
[268] Fix | Delete
this._on( this.document, this._documentClick );
[269] Fix | Delete
[270] Fix | Delete
this._trigger( "open", event );
[271] Fix | Delete
},
[272] Fix | Delete
[273] Fix | Delete
_position: function() {
[274] Fix | Delete
this.menuWrap.position( $.extend( { of: this.button }, this.options.position ) );
[275] Fix | Delete
},
[276] Fix | Delete
[277] Fix | Delete
close: function( event ) {
[278] Fix | Delete
if ( !this.isOpen ) {
[279] Fix | Delete
return;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
this.isOpen = false;
[283] Fix | Delete
this._toggleAttr();
[284] Fix | Delete
[285] Fix | Delete
this.range = null;
[286] Fix | Delete
this._off( this.document );
[287] Fix | Delete
[288] Fix | Delete
this._trigger( "close", event );
[289] Fix | Delete
},
[290] Fix | Delete
[291] Fix | Delete
widget: function() {
[292] Fix | Delete
return this.button;
[293] Fix | Delete
},
[294] Fix | Delete
[295] Fix | Delete
menuWidget: function() {
[296] Fix | Delete
return this.menu;
[297] Fix | Delete
},
[298] Fix | Delete
[299] Fix | Delete
_renderButtonItem: function( item ) {
[300] Fix | Delete
var buttonItem = $( "<span>" );
[301] Fix | Delete
[302] Fix | Delete
this._setText( buttonItem, item.label );
[303] Fix | Delete
this._addClass( buttonItem, "ui-selectmenu-text" );
[304] Fix | Delete
[305] Fix | Delete
return buttonItem;
[306] Fix | Delete
},
[307] Fix | Delete
[308] Fix | Delete
_renderMenu: function( ul, items ) {
[309] Fix | Delete
var that = this,
[310] Fix | Delete
currentOptgroup = "";
[311] Fix | Delete
[312] Fix | Delete
$.each( items, function( index, item ) {
[313] Fix | Delete
var li;
[314] Fix | Delete
[315] Fix | Delete
if ( item.optgroup !== currentOptgroup ) {
[316] Fix | Delete
li = $( "<li>", {
[317] Fix | Delete
text: item.optgroup
[318] Fix | Delete
} );
[319] Fix | Delete
that._addClass( li, "ui-selectmenu-optgroup", "ui-menu-divider" +
[320] Fix | Delete
( item.element.parent( "optgroup" ).prop( "disabled" ) ?
[321] Fix | Delete
" ui-state-disabled" :
[322] Fix | Delete
"" ) );
[323] Fix | Delete
[324] Fix | Delete
li.appendTo( ul );
[325] Fix | Delete
[326] Fix | Delete
currentOptgroup = item.optgroup;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
that._renderItemData( ul, item );
[330] Fix | Delete
} );
[331] Fix | Delete
},
[332] Fix | Delete
[333] Fix | Delete
_renderItemData: function( ul, item ) {
[334] Fix | Delete
return this._renderItem( ul, item ).data( "ui-selectmenu-item", item );
[335] Fix | Delete
},
[336] Fix | Delete
[337] Fix | Delete
_renderItem: function( ul, item ) {
[338] Fix | Delete
var li = $( "<li>" ),
[339] Fix | Delete
wrapper = $( "<div>", {
[340] Fix | Delete
title: item.element.attr( "title" )
[341] Fix | Delete
} );
[342] Fix | Delete
[343] Fix | Delete
if ( item.disabled ) {
[344] Fix | Delete
this._addClass( li, null, "ui-state-disabled" );
[345] Fix | Delete
}
[346] Fix | Delete
this._setText( wrapper, item.label );
[347] Fix | Delete
[348] Fix | Delete
return li.append( wrapper ).appendTo( ul );
[349] Fix | Delete
},
[350] Fix | Delete
[351] Fix | Delete
_setText: function( element, value ) {
[352] Fix | Delete
if ( value ) {
[353] Fix | Delete
element.text( value );
[354] Fix | Delete
} else {
[355] Fix | Delete
element.html( "&#160;" );
[356] Fix | Delete
}
[357] Fix | Delete
},
[358] Fix | Delete
[359] Fix | Delete
_move: function( direction, event ) {
[360] Fix | Delete
var item, next,
[361] Fix | Delete
filter = ".ui-menu-item";
[362] Fix | Delete
[363] Fix | Delete
if ( this.isOpen ) {
[364] Fix | Delete
item = this.menuItems.eq( this.focusIndex ).parent( "li" );
[365] Fix | Delete
} else {
[366] Fix | Delete
item = this.menuItems.eq( this.element[ 0 ].selectedIndex ).parent( "li" );
[367] Fix | Delete
filter += ":not(.ui-state-disabled)";
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
if ( direction === "first" || direction === "last" ) {
[371] Fix | Delete
next = item[ direction === "first" ? "prevAll" : "nextAll" ]( filter ).eq( -1 );
[372] Fix | Delete
} else {
[373] Fix | Delete
next = item[ direction + "All" ]( filter ).eq( 0 );
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
if ( next.length ) {
[377] Fix | Delete
this.menuInstance.focus( event, next );
[378] Fix | Delete
}
[379] Fix | Delete
},
[380] Fix | Delete
[381] Fix | Delete
_getSelectedItem: function() {
[382] Fix | Delete
return this.menuItems.eq( this.element[ 0 ].selectedIndex ).parent( "li" );
[383] Fix | Delete
},
[384] Fix | Delete
[385] Fix | Delete
_toggle: function( event ) {
[386] Fix | Delete
this[ this.isOpen ? "close" : "open" ]( event );
[387] Fix | Delete
},
[388] Fix | Delete
[389] Fix | Delete
_setSelection: function() {
[390] Fix | Delete
var selection;
[391] Fix | Delete
[392] Fix | Delete
if ( !this.range ) {
[393] Fix | Delete
return;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
if ( window.getSelection ) {
[397] Fix | Delete
selection = window.getSelection();
[398] Fix | Delete
selection.removeAllRanges();
[399] Fix | Delete
selection.addRange( this.range );
[400] Fix | Delete
[401] Fix | Delete
// Support: IE8
[402] Fix | Delete
} else {
[403] Fix | Delete
this.range.select();
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
// Support: IE
[407] Fix | Delete
// Setting the text selection kills the button focus in IE, but
[408] Fix | Delete
// restoring the focus doesn't kill the selection.
[409] Fix | Delete
this.button.focus();
[410] Fix | Delete
},
[411] Fix | Delete
[412] Fix | Delete
_documentClick: {
[413] Fix | Delete
mousedown: function( event ) {
[414] Fix | Delete
if ( !this.isOpen ) {
[415] Fix | Delete
return;
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
if ( !$( event.target ).closest( ".ui-selectmenu-menu, #" +
[419] Fix | Delete
$.ui.escapeSelector( this.ids.button ) ).length ) {
[420] Fix | Delete
this.close( event );
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
},
[424] Fix | Delete
[425] Fix | Delete
_buttonEvents: {
[426] Fix | Delete
[427] Fix | Delete
// Prevent text selection from being reset when interacting with the selectmenu (#10144)
[428] Fix | Delete
mousedown: function() {
[429] Fix | Delete
var selection;
[430] Fix | Delete
[431] Fix | Delete
if ( window.getSelection ) {
[432] Fix | Delete
selection = window.getSelection();
[433] Fix | Delete
if ( selection.rangeCount ) {
[434] Fix | Delete
this.range = selection.getRangeAt( 0 );
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
// Support: IE8
[438] Fix | Delete
} else {
[439] Fix | Delete
this.range = document.selection.createRange();
[440] Fix | Delete
}
[441] Fix | Delete
},
[442] Fix | Delete
[443] Fix | Delete
click: function( event ) {
[444] Fix | Delete
this._setSelection();
[445] Fix | Delete
this._toggle( event );
[446] Fix | Delete
},
[447] Fix | Delete
[448] Fix | Delete
keydown: function( event ) {
[449] Fix | Delete
var preventDefault = true;
[450] Fix | Delete
switch ( event.keyCode ) {
[451] Fix | Delete
case $.ui.keyCode.TAB:
[452] Fix | Delete
case $.ui.keyCode.ESCAPE:
[453] Fix | Delete
this.close( event );
[454] Fix | Delete
preventDefault = false;
[455] Fix | Delete
break;
[456] Fix | Delete
case $.ui.keyCode.ENTER:
[457] Fix | Delete
if ( this.isOpen ) {
[458] Fix | Delete
this._selectFocusedItem( event );
[459] Fix | Delete
}
[460] Fix | Delete
break;
[461] Fix | Delete
case $.ui.keyCode.UP:
[462] Fix | Delete
if ( event.altKey ) {
[463] Fix | Delete
this._toggle( event );
[464] Fix | Delete
} else {
[465] Fix | Delete
this._move( "prev", event );
[466] Fix | Delete
}
[467] Fix | Delete
break;
[468] Fix | Delete
case $.ui.keyCode.DOWN:
[469] Fix | Delete
if ( event.altKey ) {
[470] Fix | Delete
this._toggle( event );
[471] Fix | Delete
} else {
[472] Fix | Delete
this._move( "next", event );
[473] Fix | Delete
}
[474] Fix | Delete
break;
[475] Fix | Delete
case $.ui.keyCode.SPACE:
[476] Fix | Delete
if ( this.isOpen ) {
[477] Fix | Delete
this._selectFocusedItem( event );
[478] Fix | Delete
} else {
[479] Fix | Delete
this._toggle( event );
[480] Fix | Delete
}
[481] Fix | Delete
break;
[482] Fix | Delete
case $.ui.keyCode.LEFT:
[483] Fix | Delete
this._move( "prev", event );
[484] Fix | Delete
break;
[485] Fix | Delete
case $.ui.keyCode.RIGHT:
[486] Fix | Delete
this._move( "next", event );
[487] Fix | Delete
break;
[488] Fix | Delete
case $.ui.keyCode.HOME:
[489] Fix | Delete
case $.ui.keyCode.PAGE_UP:
[490] Fix | Delete
this._move( "first", event );
[491] Fix | Delete
break;
[492] Fix | Delete
case $.ui.keyCode.END:
[493] Fix | Delete
case $.ui.keyCode.PAGE_DOWN:
[494] Fix | Delete
this._move( "last", event );
[495] Fix | Delete
break;
[496] Fix | Delete
default:
[497] Fix | Delete
this.menu.trigger( event );
[498] Fix | Delete
preventDefault = false;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function