Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.button.js
1
/*
2
 * jQuery UI Button 1.8.11
1
/*!
2
 * jQuery UI Button 1.10.2
3
 * http://jqueryui.com
3 4
 *
4
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
6 7
 * http://jquery.org/license
7 8
 *
8
 * http://docs.jquery.com/UI/Button
9
 * http://api.jqueryui.com/button/
9 10
 *
10 11
 * Depends:
11 12
 *	jquery.ui.core.js
......
13 14
 */
14 15
(function( $, undefined ) {
15 16

  
16
var lastActive,
17
var lastActive, startXPos, startYPos, clickDragged,
17 18
	baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
18 19
	stateClasses = "ui-state-hover ui-state-active ",
19 20
	typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
20
	formResetHandler = function( event ) {
21
		$( ":ui-button", event.target.form ).each(function() {
22
			var inst = $( this ).data( "button" );
23
			setTimeout(function() {
24
				inst.refresh();
25
			}, 1 );
26
		});
21
	formResetHandler = function() {
22
		var buttons = $( this ).find( ":ui-button" );
23
		setTimeout(function() {
24
			buttons.button( "refresh" );
25
		}, 1 );
27 26
	},
28 27
	radioGroup = function( radio ) {
29 28
		var name = radio.name,
30 29
			form = radio.form,
31 30
			radios = $( [] );
32 31
		if ( name ) {
32
			name = name.replace( /'/g, "\\'" );
33 33
			if ( form ) {
34 34
				radios = $( form ).find( "[name='" + name + "']" );
35 35
			} else {
......
43 43
	};
44 44

  
45 45
$.widget( "ui.button", {
46
	version: "1.10.2",
47
	defaultElement: "<button>",
46 48
	options: {
47 49
		disabled: null,
48 50
		text: true,
......
54 56
	},
55 57
	_create: function() {
56 58
		this.element.closest( "form" )
57
			.unbind( "reset.button" )
58
			.bind( "reset.button", formResetHandler );
59
			.unbind( "reset" + this.eventNamespace )
60
			.bind( "reset" + this.eventNamespace, formResetHandler );
59 61

  
60 62
		if ( typeof this.options.disabled !== "boolean" ) {
61
			this.options.disabled = this.element.attr( "disabled" );
63
			this.options.disabled = !!this.element.prop( "disabled" );
64
		} else {
65
			this.element.prop( "disabled", this.options.disabled );
62 66
		}
63 67

  
64 68
		this._determineButtonType();
65 69
		this.hasTitle = !!this.buttonElement.attr( "title" );
66 70

  
67
		var self = this,
71
		var that = this,
68 72
			options = this.options,
69 73
			toggleButton = this.type === "checkbox" || this.type === "radio",
70
			hoverClass = "ui-state-hover" + ( !toggleButton ? " ui-state-active" : "" ),
74
			activeClass = !toggleButton ? "ui-state-active" : "",
71 75
			focusClass = "ui-state-focus";
72 76

  
73 77
		if ( options.label === null ) {
74
			options.label = this.buttonElement.html();
78
			options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
75 79
		}
76 80

  
77
		if ( this.element.is( ":disabled" ) ) {
78
			options.disabled = true;
79
		}
81
		this._hoverable( this.buttonElement );
80 82

  
81 83
		this.buttonElement
82 84
			.addClass( baseClasses )
83 85
			.attr( "role", "button" )
84
			.bind( "mouseenter.button", function() {
86
			.bind( "mouseenter" + this.eventNamespace, function() {
85 87
				if ( options.disabled ) {
86 88
					return;
87 89
				}
88
				$( this ).addClass( "ui-state-hover" );
89 90
				if ( this === lastActive ) {
90 91
					$( this ).addClass( "ui-state-active" );
91 92
				}
92 93
			})
93
			.bind( "mouseleave.button", function() {
94
			.bind( "mouseleave" + this.eventNamespace, function() {
94 95
				if ( options.disabled ) {
95 96
					return;
96 97
				}
97
				$( this ).removeClass( hoverClass );
98
				$( this ).removeClass( activeClass );
98 99
			})
99
			.bind( "focus.button", function() {
100
			.bind( "click" + this.eventNamespace, function( event ) {
101
				if ( options.disabled ) {
102
					event.preventDefault();
103
					event.stopImmediatePropagation();
104
				}
105
			});
106

  
107
		this.element
108
			.bind( "focus" + this.eventNamespace, function() {
100 109
				// no need to check disabled, focus won't be triggered anyway
101
				$( this ).addClass( focusClass );
110
				that.buttonElement.addClass( focusClass );
102 111
			})
103
			.bind( "blur.button", function() {
104
				$( this ).removeClass( focusClass );
112
			.bind( "blur" + this.eventNamespace, function() {
113
				that.buttonElement.removeClass( focusClass );
105 114
			});
106 115

  
107 116
		if ( toggleButton ) {
108
			this.element.bind( "change.button", function() {
109
				self.refresh();
117
			this.element.bind( "change" + this.eventNamespace, function() {
118
				if ( clickDragged ) {
119
					return;
120
				}
121
				that.refresh();
122
			});
123
			// if mouse moves between mousedown and mouseup (drag) set clickDragged flag
124
			// prevents issue where button state changes but checkbox/radio checked state
125
			// does not in Firefox (see ticket #6970)
126
			this.buttonElement
127
				.bind( "mousedown" + this.eventNamespace, function( event ) {
128
					if ( options.disabled ) {
129
						return;
130
					}
131
					clickDragged = false;
132
					startXPos = event.pageX;
133
					startYPos = event.pageY;
134
				})
135
				.bind( "mouseup" + this.eventNamespace, function( event ) {
136
					if ( options.disabled ) {
137
						return;
138
					}
139
					if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
140
						clickDragged = true;
141
					}
110 142
			});
111 143
		}
112 144

  
113 145
		if ( this.type === "checkbox" ) {
114
			this.buttonElement.bind( "click.button", function() {
115
				if ( options.disabled ) {
146
			this.buttonElement.bind( "click" + this.eventNamespace, function() {
147
				if ( options.disabled || clickDragged ) {
116 148
					return false;
117 149
				}
118
				$( this ).toggleClass( "ui-state-active" );
119
				self.buttonElement.attr( "aria-pressed", self.element[0].checked );
120 150
			});
121 151
		} else if ( this.type === "radio" ) {
122
			this.buttonElement.bind( "click.button", function() {
123
				if ( options.disabled ) {
152
			this.buttonElement.bind( "click" + this.eventNamespace, function() {
153
				if ( options.disabled || clickDragged ) {
124 154
					return false;
125 155
				}
126 156
				$( this ).addClass( "ui-state-active" );
127
				self.buttonElement.attr( "aria-pressed", true );
157
				that.buttonElement.attr( "aria-pressed", "true" );
128 158

  
129
				var radio = self.element[ 0 ];
159
				var radio = that.element[ 0 ];
130 160
				radioGroup( radio )
131 161
					.not( radio )
132 162
					.map(function() {
133 163
						return $( this ).button( "widget" )[ 0 ];
134 164
					})
135 165
					.removeClass( "ui-state-active" )
136
					.attr( "aria-pressed", false );
166
					.attr( "aria-pressed", "false" );
137 167
			});
138 168
		} else {
139 169
			this.buttonElement
140
				.bind( "mousedown.button", function() {
170
				.bind( "mousedown" + this.eventNamespace, function() {
141 171
					if ( options.disabled ) {
142 172
						return false;
143 173
					}
144 174
					$( this ).addClass( "ui-state-active" );
145 175
					lastActive = this;
146
					$( document ).one( "mouseup", function() {
176
					that.document.one( "mouseup", function() {
147 177
						lastActive = null;
148 178
					});
149 179
				})
150
				.bind( "mouseup.button", function() {
180
				.bind( "mouseup" + this.eventNamespace, function() {
151 181
					if ( options.disabled ) {
152 182
						return false;
153 183
					}
154 184
					$( this ).removeClass( "ui-state-active" );
155 185
				})
156
				.bind( "keydown.button", function(event) {
186
				.bind( "keydown" + this.eventNamespace, function(event) {
157 187
					if ( options.disabled ) {
158 188
						return false;
159 189
					}
160
					if ( event.keyCode == $.ui.keyCode.SPACE || event.keyCode == $.ui.keyCode.ENTER ) {
190
					if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
161 191
						$( this ).addClass( "ui-state-active" );
162 192
					}
163 193
				})
164
				.bind( "keyup.button", function() {
194
				// see #8559, we bind to blur here in case the button element loses
195
				// focus between keydown and keyup, it would be left in an "active" state
196
				.bind( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
165 197
					$( this ).removeClass( "ui-state-active" );
166 198
				});
167 199

  
......
179 211
		// $.Widget.prototype._setOptionDisabled so it's easy to proxy and can
180 212
		// be overridden by individual plugins
181 213
		this._setOption( "disabled", options.disabled );
214
		this._resetButton();
182 215
	},
183 216

  
184 217
	_determineButtonType: function() {
185
		
186
		if ( this.element.is(":checkbox") ) {
218
		var ancestor, labelSelector, checked;
219

  
220
		if ( this.element.is("[type=checkbox]") ) {
187 221
			this.type = "checkbox";
222
		} else if ( this.element.is("[type=radio]") ) {
223
			this.type = "radio";
224
		} else if ( this.element.is("input") ) {
225
			this.type = "input";
188 226
		} else {
189
			if ( this.element.is(":radio") ) {
190
				this.type = "radio";
191
			} else {
192
				if ( this.element.is("input") ) {
193
					this.type = "input";
194
				} else {
195
					this.type = "button";
196
				}
197
			}
227
			this.type = "button";
198 228
		}
199
		
229

  
200 230
		if ( this.type === "checkbox" || this.type === "radio" ) {
201 231
			// we don't search against the document in case the element
202 232
			// is disconnected from the DOM
203
			var ancestor = this.element.parents().filter(":last"),
204
				labelSelector = "label[for=" + this.element.attr("id") + "]";
233
			ancestor = this.element.parents().last();
234
			labelSelector = "label[for='" + this.element.attr("id") + "']";
205 235
			this.buttonElement = ancestor.find( labelSelector );
206 236
			if ( !this.buttonElement.length ) {
207 237
				ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
......
212 242
			}
213 243
			this.element.addClass( "ui-helper-hidden-accessible" );
214 244

  
215
			var checked = this.element.is( ":checked" );
245
			checked = this.element.is( ":checked" );
216 246
			if ( checked ) {
217 247
				this.buttonElement.addClass( "ui-state-active" );
218 248
			}
219
			this.buttonElement.attr( "aria-pressed", checked );
249
			this.buttonElement.prop( "aria-pressed", checked );
220 250
		} else {
221 251
			this.buttonElement = this.element;
222 252
		}
......
226 256
		return this.buttonElement;
227 257
	},
228 258

  
229
	destroy: function() {
259
	_destroy: function() {
230 260
		this.element
231 261
			.removeClass( "ui-helper-hidden-accessible" );
232 262
		this.buttonElement
......
238 268
		if ( !this.hasTitle ) {
239 269
			this.buttonElement.removeAttr( "title" );
240 270
		}
241

  
242
		$.Widget.prototype.destroy.call( this );
243 271
	},
244 272

  
245 273
	_setOption: function( key, value ) {
246
		$.Widget.prototype._setOption.apply( this, arguments );
274
		this._super( key, value );
247 275
		if ( key === "disabled" ) {
248 276
			if ( value ) {
249
				this.element.attr( "disabled", true );
277
				this.element.prop( "disabled", true );
250 278
			} else {
251
				this.element.removeAttr( "disabled" );
279
				this.element.prop( "disabled", false );
252 280
			}
281
			return;
253 282
		}
254 283
		this._resetButton();
255 284
	},
256 285

  
257 286
	refresh: function() {
258
		var isDisabled = this.element.is( ":disabled" );
287
		//See #8237 & #8828
288
		var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
289

  
259 290
		if ( isDisabled !== this.options.disabled ) {
260 291
			this._setOption( "disabled", isDisabled );
261 292
		}
......
264 295
				if ( $( this ).is( ":checked" ) ) {
265 296
					$( this ).button( "widget" )
266 297
						.addClass( "ui-state-active" )
267
						.attr( "aria-pressed", true );
298
						.attr( "aria-pressed", "true" );
268 299
				} else {
269 300
					$( this ).button( "widget" )
270 301
						.removeClass( "ui-state-active" )
271
						.attr( "aria-pressed", false );
302
						.attr( "aria-pressed", "false" );
272 303
				}
273 304
			});
274 305
		} else if ( this.type === "checkbox" ) {
275 306
			if ( this.element.is( ":checked" ) ) {
276 307
				this.buttonElement
277 308
					.addClass( "ui-state-active" )
278
					.attr( "aria-pressed", true );
309
					.attr( "aria-pressed", "true" );
279 310
			} else {
280 311
				this.buttonElement
281 312
					.removeClass( "ui-state-active" )
282
					.attr( "aria-pressed", false );
313
					.attr( "aria-pressed", "false" );
283 314
			}
284 315
		}
285 316
	},
......
292 323
			return;
293 324
		}
294 325
		var buttonElement = this.buttonElement.removeClass( typeClasses ),
295
			buttonText = $( "<span></span>" )
326
			buttonText = $( "<span></span>", this.document[0] )
296 327
				.addClass( "ui-button-text" )
297 328
				.html( this.options.label )
298 329
				.appendTo( buttonElement.empty() )
299 330
				.text(),
300 331
			icons = this.options.icons,
301 332
			multipleIcons = icons.primary && icons.secondary,
302
			buttonClasses = [];  
333
			buttonClasses = [];
303 334

  
304 335
		if ( icons.primary || icons.secondary ) {
305 336
			if ( this.options.text ) {
......
318 349
				buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
319 350

  
320 351
				if ( !this.hasTitle ) {
321
					buttonElement.attr( "title", buttonText );
352
					buttonElement.attr( "title", $.trim( buttonText ) );
322 353
				}
323 354
			}
324 355
		} else {
......
329 360
});
330 361

  
331 362
$.widget( "ui.buttonset", {
363
	version: "1.10.2",
332 364
	options: {
333
		items: ":button, :submit, :reset, :checkbox, :radio, a, :data(button)"
365
		items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
334 366
	},
335 367

  
336 368
	_create: function() {
337 369
		this.element.addClass( "ui-buttonset" );
338 370
	},
339
	
371

  
340 372
	_init: function() {
341 373
		this.refresh();
342 374
	},
......
346 378
			this.buttons.button( "option", key, value );
347 379
		}
348 380

  
349
		$.Widget.prototype._setOption.apply( this, arguments );
381
		this._super( key, value );
350 382
	},
351
	
383

  
352 384
	refresh: function() {
385
		var rtl = this.element.css( "direction" ) === "rtl";
386

  
353 387
		this.buttons = this.element.find( this.options.items )
354 388
			.filter( ":ui-button" )
355 389
				.button( "refresh" )
......
362 396
			})
363 397
				.removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
364 398
				.filter( ":first" )
365
					.addClass( "ui-corner-left" )
399
					.addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
366 400
				.end()
367 401
				.filter( ":last" )
368
					.addClass( "ui-corner-right" )
402
					.addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
369 403
				.end()
370 404
			.end();
371 405
	},
372 406

  
373
	destroy: function() {
407
	_destroy: function() {
374 408
		this.element.removeClass( "ui-buttonset" );
375 409
		this.buttons
376 410
			.map(function() {
......
379 413
				.removeClass( "ui-corner-left ui-corner-right" )
380 414
			.end()
381 415
			.button( "destroy" );
382

  
383
		$.Widget.prototype.destroy.call( this );
384 416
	}
385 417
});
386 418

  

Formats disponibles : Unified diff