Edit File by line
/home/barbar84/public_h.../wp-inclu.../js/jquery/ui
File: button.js
/*!
[0] Fix | Delete
* jQuery UI Button 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: Button
[9] Fix | Delete
//>>group: Widgets
[10] Fix | Delete
//>>description: Enhances a form with themeable buttons.
[11] Fix | Delete
//>>docs: http://api.jqueryui.com/button/
[12] Fix | Delete
//>>demos: http://jqueryui.com/button/
[13] Fix | Delete
//>>css.structure: ../../themes/base/core.css
[14] Fix | Delete
//>>css.structure: ../../themes/base/button.css
[15] Fix | Delete
//>>css.theme: ../../themes/base/theme.css
[16] Fix | Delete
[17] Fix | Delete
( function( factory ) {
[18] Fix | Delete
if ( typeof define === "function" && define.amd ) {
[19] Fix | Delete
[20] Fix | Delete
// AMD. Register as an anonymous module.
[21] Fix | Delete
define( [
[22] Fix | Delete
"jquery",
[23] Fix | Delete
[24] Fix | Delete
// These are only for backcompat
[25] Fix | Delete
// TODO: Remove after 1.12
[26] Fix | Delete
"./controlgroup",
[27] Fix | Delete
"./checkboxradio",
[28] Fix | Delete
[29] Fix | Delete
"./core"
[30] Fix | Delete
], factory );
[31] Fix | Delete
} else {
[32] Fix | Delete
[33] Fix | Delete
// Browser globals
[34] Fix | Delete
factory( jQuery );
[35] Fix | Delete
}
[36] Fix | Delete
}( function( $ ) {
[37] Fix | Delete
[38] Fix | Delete
$.widget( "ui.button", {
[39] Fix | Delete
version: "1.12.1",
[40] Fix | Delete
defaultElement: "<button>",
[41] Fix | Delete
options: {
[42] Fix | Delete
classes: {
[43] Fix | Delete
"ui-button": "ui-corner-all"
[44] Fix | Delete
},
[45] Fix | Delete
disabled: null,
[46] Fix | Delete
icon: null,
[47] Fix | Delete
iconPosition: "beginning",
[48] Fix | Delete
label: null,
[49] Fix | Delete
showLabel: true
[50] Fix | Delete
},
[51] Fix | Delete
[52] Fix | Delete
_getCreateOptions: function() {
[53] Fix | Delete
var disabled,
[54] Fix | Delete
[55] Fix | Delete
// This is to support cases like in jQuery Mobile where the base widget does have
[56] Fix | Delete
// an implementation of _getCreateOptions
[57] Fix | Delete
options = this._super() || {};
[58] Fix | Delete
[59] Fix | Delete
this.isInput = this.element.is( "input" );
[60] Fix | Delete
[61] Fix | Delete
disabled = this.element[ 0 ].disabled;
[62] Fix | Delete
if ( disabled != null ) {
[63] Fix | Delete
options.disabled = disabled;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
this.originalLabel = this.isInput ? this.element.val() : this.element.html();
[67] Fix | Delete
if ( this.originalLabel ) {
[68] Fix | Delete
options.label = this.originalLabel;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
return options;
[72] Fix | Delete
},
[73] Fix | Delete
[74] Fix | Delete
_create: function() {
[75] Fix | Delete
if ( !this.option.showLabel & !this.options.icon ) {
[76] Fix | Delete
this.options.showLabel = true;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
// We have to check the option again here even though we did in _getCreateOptions,
[80] Fix | Delete
// because null may have been passed on init which would override what was set in
[81] Fix | Delete
// _getCreateOptions
[82] Fix | Delete
if ( this.options.disabled == null ) {
[83] Fix | Delete
this.options.disabled = this.element[ 0 ].disabled || false;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
this.hasTitle = !!this.element.attr( "title" );
[87] Fix | Delete
[88] Fix | Delete
// Check to see if the label needs to be set or if its already correct
[89] Fix | Delete
if ( this.options.label && this.options.label !== this.originalLabel ) {
[90] Fix | Delete
if ( this.isInput ) {
[91] Fix | Delete
this.element.val( this.options.label );
[92] Fix | Delete
} else {
[93] Fix | Delete
this.element.html( this.options.label );
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
this._addClass( "ui-button", "ui-widget" );
[97] Fix | Delete
this._setOption( "disabled", this.options.disabled );
[98] Fix | Delete
this._enhance();
[99] Fix | Delete
[100] Fix | Delete
if ( this.element.is( "a" ) ) {
[101] Fix | Delete
this._on( {
[102] Fix | Delete
"keyup": function( event ) {
[103] Fix | Delete
if ( event.keyCode === $.ui.keyCode.SPACE ) {
[104] Fix | Delete
event.preventDefault();
[105] Fix | Delete
[106] Fix | Delete
// Support: PhantomJS <= 1.9, IE 8 Only
[107] Fix | Delete
// If a native click is available use it so we actually cause navigation
[108] Fix | Delete
// otherwise just trigger a click event
[109] Fix | Delete
if ( this.element[ 0 ].click ) {
[110] Fix | Delete
this.element[ 0 ].click();
[111] Fix | Delete
} else {
[112] Fix | Delete
this.element.trigger( "click" );
[113] Fix | Delete
}
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
} );
[117] Fix | Delete
}
[118] Fix | Delete
},
[119] Fix | Delete
[120] Fix | Delete
_enhance: function() {
[121] Fix | Delete
if ( !this.element.is( "button" ) ) {
[122] Fix | Delete
this.element.attr( "role", "button" );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
if ( this.options.icon ) {
[126] Fix | Delete
this._updateIcon( "icon", this.options.icon );
[127] Fix | Delete
this._updateTooltip();
[128] Fix | Delete
}
[129] Fix | Delete
},
[130] Fix | Delete
[131] Fix | Delete
_updateTooltip: function() {
[132] Fix | Delete
this.title = this.element.attr( "title" );
[133] Fix | Delete
[134] Fix | Delete
if ( !this.options.showLabel && !this.title ) {
[135] Fix | Delete
this.element.attr( "title", this.options.label );
[136] Fix | Delete
}
[137] Fix | Delete
},
[138] Fix | Delete
[139] Fix | Delete
_updateIcon: function( option, value ) {
[140] Fix | Delete
var icon = option !== "iconPosition",
[141] Fix | Delete
position = icon ? this.options.iconPosition : value,
[142] Fix | Delete
displayBlock = position === "top" || position === "bottom";
[143] Fix | Delete
[144] Fix | Delete
// Create icon
[145] Fix | Delete
if ( !this.icon ) {
[146] Fix | Delete
this.icon = $( "<span>" );
[147] Fix | Delete
[148] Fix | Delete
this._addClass( this.icon, "ui-button-icon", "ui-icon" );
[149] Fix | Delete
[150] Fix | Delete
if ( !this.options.showLabel ) {
[151] Fix | Delete
this._addClass( "ui-button-icon-only" );
[152] Fix | Delete
}
[153] Fix | Delete
} else if ( icon ) {
[154] Fix | Delete
[155] Fix | Delete
// If we are updating the icon remove the old icon class
[156] Fix | Delete
this._removeClass( this.icon, null, this.options.icon );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
// If we are updating the icon add the new icon class
[160] Fix | Delete
if ( icon ) {
[161] Fix | Delete
this._addClass( this.icon, null, value );
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
this._attachIcon( position );
[165] Fix | Delete
[166] Fix | Delete
// If the icon is on top or bottom we need to add the ui-widget-icon-block class and remove
[167] Fix | Delete
// the iconSpace if there is one.
[168] Fix | Delete
if ( displayBlock ) {
[169] Fix | Delete
this._addClass( this.icon, null, "ui-widget-icon-block" );
[170] Fix | Delete
if ( this.iconSpace ) {
[171] Fix | Delete
this.iconSpace.remove();
[172] Fix | Delete
}
[173] Fix | Delete
} else {
[174] Fix | Delete
[175] Fix | Delete
// Position is beginning or end so remove the ui-widget-icon-block class and add the
[176] Fix | Delete
// space if it does not exist
[177] Fix | Delete
if ( !this.iconSpace ) {
[178] Fix | Delete
this.iconSpace = $( "<span> </span>" );
[179] Fix | Delete
this._addClass( this.iconSpace, "ui-button-icon-space" );
[180] Fix | Delete
}
[181] Fix | Delete
this._removeClass( this.icon, null, "ui-wiget-icon-block" );
[182] Fix | Delete
this._attachIconSpace( position );
[183] Fix | Delete
}
[184] Fix | Delete
},
[185] Fix | Delete
[186] Fix | Delete
_destroy: function() {
[187] Fix | Delete
this.element.removeAttr( "role" );
[188] Fix | Delete
[189] Fix | Delete
if ( this.icon ) {
[190] Fix | Delete
this.icon.remove();
[191] Fix | Delete
}
[192] Fix | Delete
if ( this.iconSpace ) {
[193] Fix | Delete
this.iconSpace.remove();
[194] Fix | Delete
}
[195] Fix | Delete
if ( !this.hasTitle ) {
[196] Fix | Delete
this.element.removeAttr( "title" );
[197] Fix | Delete
}
[198] Fix | Delete
},
[199] Fix | Delete
[200] Fix | Delete
_attachIconSpace: function( iconPosition ) {
[201] Fix | Delete
this.icon[ /^(?:end|bottom)/.test( iconPosition ) ? "before" : "after" ]( this.iconSpace );
[202] Fix | Delete
},
[203] Fix | Delete
[204] Fix | Delete
_attachIcon: function( iconPosition ) {
[205] Fix | Delete
this.element[ /^(?:end|bottom)/.test( iconPosition ) ? "append" : "prepend" ]( this.icon );
[206] Fix | Delete
},
[207] Fix | Delete
[208] Fix | Delete
_setOptions: function( options ) {
[209] Fix | Delete
var newShowLabel = options.showLabel === undefined ?
[210] Fix | Delete
this.options.showLabel :
[211] Fix | Delete
options.showLabel,
[212] Fix | Delete
newIcon = options.icon === undefined ? this.options.icon : options.icon;
[213] Fix | Delete
[214] Fix | Delete
if ( !newShowLabel && !newIcon ) {
[215] Fix | Delete
options.showLabel = true;
[216] Fix | Delete
}
[217] Fix | Delete
this._super( options );
[218] Fix | Delete
},
[219] Fix | Delete
[220] Fix | Delete
_setOption: function( key, value ) {
[221] Fix | Delete
if ( key === "icon" ) {
[222] Fix | Delete
if ( value ) {
[223] Fix | Delete
this._updateIcon( key, value );
[224] Fix | Delete
} else if ( this.icon ) {
[225] Fix | Delete
this.icon.remove();
[226] Fix | Delete
if ( this.iconSpace ) {
[227] Fix | Delete
this.iconSpace.remove();
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
if ( key === "iconPosition" ) {
[233] Fix | Delete
this._updateIcon( key, value );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
// Make sure we can't end up with a button that has neither text nor icon
[237] Fix | Delete
if ( key === "showLabel" ) {
[238] Fix | Delete
this._toggleClass( "ui-button-icon-only", null, !value );
[239] Fix | Delete
this._updateTooltip();
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
if ( key === "label" ) {
[243] Fix | Delete
if ( this.isInput ) {
[244] Fix | Delete
this.element.val( value );
[245] Fix | Delete
} else {
[246] Fix | Delete
[247] Fix | Delete
// If there is an icon, append it, else nothing then append the value
[248] Fix | Delete
// this avoids removal of the icon when setting label text
[249] Fix | Delete
this.element.html( value );
[250] Fix | Delete
if ( this.icon ) {
[251] Fix | Delete
this._attachIcon( this.options.iconPosition );
[252] Fix | Delete
this._attachIconSpace( this.options.iconPosition );
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
this._super( key, value );
[258] Fix | Delete
[259] Fix | Delete
if ( key === "disabled" ) {
[260] Fix | Delete
this._toggleClass( null, "ui-state-disabled", value );
[261] Fix | Delete
this.element[ 0 ].disabled = value;
[262] Fix | Delete
if ( value ) {
[263] Fix | Delete
this.element.blur();
[264] Fix | Delete
}
[265] Fix | Delete
}
[266] Fix | Delete
},
[267] Fix | Delete
[268] Fix | Delete
refresh: function() {
[269] Fix | Delete
[270] Fix | Delete
// Make sure to only check disabled if its an element that supports this otherwise
[271] Fix | Delete
// check for the disabled class to determine state
[272] Fix | Delete
var isDisabled = this.element.is( "input, button" ) ?
[273] Fix | Delete
this.element[ 0 ].disabled : this.element.hasClass( "ui-button-disabled" );
[274] Fix | Delete
[275] Fix | Delete
if ( isDisabled !== this.options.disabled ) {
[276] Fix | Delete
this._setOptions( { disabled: isDisabled } );
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
this._updateTooltip();
[280] Fix | Delete
}
[281] Fix | Delete
} );
[282] Fix | Delete
[283] Fix | Delete
// DEPRECATED
[284] Fix | Delete
if ( $.uiBackCompat !== false ) {
[285] Fix | Delete
[286] Fix | Delete
// Text and Icons options
[287] Fix | Delete
$.widget( "ui.button", $.ui.button, {
[288] Fix | Delete
options: {
[289] Fix | Delete
text: true,
[290] Fix | Delete
icons: {
[291] Fix | Delete
primary: null,
[292] Fix | Delete
secondary: null
[293] Fix | Delete
}
[294] Fix | Delete
},
[295] Fix | Delete
[296] Fix | Delete
_create: function() {
[297] Fix | Delete
if ( this.options.showLabel && !this.options.text ) {
[298] Fix | Delete
this.options.showLabel = this.options.text;
[299] Fix | Delete
}
[300] Fix | Delete
if ( !this.options.showLabel && this.options.text ) {
[301] Fix | Delete
this.options.text = this.options.showLabel;
[302] Fix | Delete
}
[303] Fix | Delete
if ( !this.options.icon && ( this.options.icons.primary ||
[304] Fix | Delete
this.options.icons.secondary ) ) {
[305] Fix | Delete
if ( this.options.icons.primary ) {
[306] Fix | Delete
this.options.icon = this.options.icons.primary;
[307] Fix | Delete
} else {
[308] Fix | Delete
this.options.icon = this.options.icons.secondary;
[309] Fix | Delete
this.options.iconPosition = "end";
[310] Fix | Delete
}
[311] Fix | Delete
} else if ( this.options.icon ) {
[312] Fix | Delete
this.options.icons.primary = this.options.icon;
[313] Fix | Delete
}
[314] Fix | Delete
this._super();
[315] Fix | Delete
},
[316] Fix | Delete
[317] Fix | Delete
_setOption: function( key, value ) {
[318] Fix | Delete
if ( key === "text" ) {
[319] Fix | Delete
this._super( "showLabel", value );
[320] Fix | Delete
return;
[321] Fix | Delete
}
[322] Fix | Delete
if ( key === "showLabel" ) {
[323] Fix | Delete
this.options.text = value;
[324] Fix | Delete
}
[325] Fix | Delete
if ( key === "icon" ) {
[326] Fix | Delete
this.options.icons.primary = value;
[327] Fix | Delete
}
[328] Fix | Delete
if ( key === "icons" ) {
[329] Fix | Delete
if ( value.primary ) {
[330] Fix | Delete
this._super( "icon", value.primary );
[331] Fix | Delete
this._super( "iconPosition", "beginning" );
[332] Fix | Delete
} else if ( value.secondary ) {
[333] Fix | Delete
this._super( "icon", value.secondary );
[334] Fix | Delete
this._super( "iconPosition", "end" );
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
this._superApply( arguments );
[338] Fix | Delete
}
[339] Fix | Delete
} );
[340] Fix | Delete
[341] Fix | Delete
$.fn.button = ( function( orig ) {
[342] Fix | Delete
return function() {
[343] Fix | Delete
if ( !this.length || ( this.length && this[ 0 ].tagName !== "INPUT" ) ||
[344] Fix | Delete
( this.length && this[ 0 ].tagName === "INPUT" && (
[345] Fix | Delete
this.attr( "type" ) !== "checkbox" && this.attr( "type" ) !== "radio"
[346] Fix | Delete
) ) ) {
[347] Fix | Delete
return orig.apply( this, arguments );
[348] Fix | Delete
}
[349] Fix | Delete
if ( !$.ui.checkboxradio ) {
[350] Fix | Delete
$.error( "Checkboxradio widget missing" );
[351] Fix | Delete
}
[352] Fix | Delete
if ( arguments.length === 0 ) {
[353] Fix | Delete
return this.checkboxradio( {
[354] Fix | Delete
"icon": false
[355] Fix | Delete
} );
[356] Fix | Delete
}
[357] Fix | Delete
return this.checkboxradio.apply( this, arguments );
[358] Fix | Delete
};
[359] Fix | Delete
} )( $.fn.button );
[360] Fix | Delete
[361] Fix | Delete
$.fn.buttonset = function() {
[362] Fix | Delete
if ( !$.ui.controlgroup ) {
[363] Fix | Delete
$.error( "Controlgroup widget missing" );
[364] Fix | Delete
}
[365] Fix | Delete
if ( arguments[ 0 ] === "option" && arguments[ 1 ] === "items" && arguments[ 2 ] ) {
[366] Fix | Delete
return this.controlgroup.apply( this,
[367] Fix | Delete
[ arguments[ 0 ], "items.button", arguments[ 2 ] ] );
[368] Fix | Delete
}
[369] Fix | Delete
if ( arguments[ 0 ] === "option" && arguments[ 1 ] === "items" ) {
[370] Fix | Delete
return this.controlgroup.apply( this, [ arguments[ 0 ], "items.button" ] );
[371] Fix | Delete
}
[372] Fix | Delete
if ( typeof arguments[ 0 ] === "object" && arguments[ 0 ].items ) {
[373] Fix | Delete
arguments[ 0 ].items = {
[374] Fix | Delete
button: arguments[ 0 ].items
[375] Fix | Delete
};
[376] Fix | Delete
}
[377] Fix | Delete
return this.controlgroup.apply( this, arguments );
[378] Fix | Delete
};
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
return $.ui.button;
[382] Fix | Delete
[383] Fix | Delete
} ) );
[384] Fix | Delete
[385] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function