Changeset 12526 for branches/2.3/themes/default/js/ui/jquery.ui.button.js
- Timestamp:
- Oct 28, 2011, 3:32:48 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.3/themes/default/js/ui/jquery.ui.button.js
r9559 r12526 1 1 /* 2 * jQuery UI Button 1.8.1 02 * jQuery UI Button 1.8.16 3 3 * 4 4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) … … 14 14 (function( $, undefined ) { 15 15 16 var lastActive, 16 var lastActive, startXPos, startYPos, clickDragged, 17 17 baseClasses = "ui-button ui-widget ui-state-default ui-corner-all", 18 18 stateClasses = "ui-state-hover ui-state-active ", 19 19 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 }); 20 formResetHandler = function() { 21 var buttons = $( this ).find( ":ui-button" ); 22 setTimeout(function() { 23 buttons.button( "refresh" ); 24 }, 1 ); 27 25 }, 28 26 radioGroup = function( radio ) { … … 59 57 60 58 if ( typeof this.options.disabled !== "boolean" ) { 61 this.options.disabled = this.element. attr( "disabled" );59 this.options.disabled = this.element.propAttr( "disabled" ); 62 60 } 63 61 … … 97 95 $( this ).removeClass( hoverClass ); 98 96 }) 97 .bind( "click.button", function( event ) { 98 if ( options.disabled ) { 99 event.preventDefault(); 100 event.stopImmediatePropagation(); 101 } 102 }); 103 104 this.element 99 105 .bind( "focus.button", function() { 100 106 // no need to check disabled, focus won't be triggered anyway 101 $( this ).addClass( focusClass );107 self.buttonElement.addClass( focusClass ); 102 108 }) 103 109 .bind( "blur.button", function() { 104 $( this ).removeClass( focusClass );110 self.buttonElement.removeClass( focusClass ); 105 111 }); 106 112 107 113 if ( toggleButton ) { 108 114 this.element.bind( "change.button", function() { 115 if ( clickDragged ) { 116 return; 117 } 109 118 self.refresh(); 119 }); 120 // if mouse moves between mousedown and mouseup (drag) set clickDragged flag 121 // prevents issue where button state changes but checkbox/radio checked state 122 // does not in Firefox (see ticket #6970) 123 this.buttonElement 124 .bind( "mousedown.button", function( event ) { 125 if ( options.disabled ) { 126 return; 127 } 128 clickDragged = false; 129 startXPos = event.pageX; 130 startYPos = event.pageY; 131 }) 132 .bind( "mouseup.button", function( event ) { 133 if ( options.disabled ) { 134 return; 135 } 136 if ( startXPos !== event.pageX || startYPos !== event.pageY ) { 137 clickDragged = true; 138 } 110 139 }); 111 140 } … … 113 142 if ( this.type === "checkbox" ) { 114 143 this.buttonElement.bind( "click.button", function() { 115 if ( options.disabled ) {144 if ( options.disabled || clickDragged ) { 116 145 return false; 117 146 } … … 121 150 } else if ( this.type === "radio" ) { 122 151 this.buttonElement.bind( "click.button", function() { 123 if ( options.disabled ) {152 if ( options.disabled || clickDragged ) { 124 153 return false; 125 154 } 126 155 $( this ).addClass( "ui-state-active" ); 127 self.buttonElement.attr( "aria-pressed", true);156 self.buttonElement.attr( "aria-pressed", "true" ); 128 157 129 158 var radio = self.element[ 0 ]; … … 134 163 }) 135 164 .removeClass( "ui-state-active" ) 136 .attr( "aria-pressed", false);165 .attr( "aria-pressed", "false" ); 137 166 }); 138 167 } else { … … 180 209 // be overridden by individual plugins 181 210 this._setOption( "disabled", options.disabled ); 211 this._resetButton(); 182 212 }, 183 213 184 214 _determineButtonType: function() { 185 215 186 216 if ( this.element.is(":checkbox") ) { 187 217 this.type = "checkbox"; 218 } else if ( this.element.is(":radio") ) { 219 this.type = "radio"; 220 } else if ( this.element.is("input") ) { 221 this.type = "input"; 188 222 } 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 } 198 } 199 223 this.type = "button"; 224 } 225 200 226 if ( this.type === "checkbox" || this.type === "radio" ) { 201 227 // we don't search against the document in case the element 202 228 // is disconnected from the DOM 203 this.buttonElement = this.element.parents().last() 204 .find( "label[for=" + this.element.attr("id") + "]" ); 229 var ancestor = this.element.parents().filter(":last"), 230 labelSelector = "label[for='" + this.element.attr("id") + "']"; 231 this.buttonElement = ancestor.find( labelSelector ); 232 if ( !this.buttonElement.length ) { 233 ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings(); 234 this.buttonElement = ancestor.filter( labelSelector ); 235 if ( !this.buttonElement.length ) { 236 this.buttonElement = ancestor.find( labelSelector ); 237 } 238 } 205 239 this.element.addClass( "ui-helper-hidden-accessible" ); 206 240 … … 239 273 if ( key === "disabled" ) { 240 274 if ( value ) { 241 this.element. attr( "disabled", true );275 this.element.propAttr( "disabled", true ); 242 276 } else { 243 this.element.removeAttr( "disabled" ); 244 } 277 this.element.propAttr( "disabled", false ); 278 } 279 return; 245 280 } 246 281 this._resetButton(); … … 257 292 $( this ).button( "widget" ) 258 293 .addClass( "ui-state-active" ) 259 .attr( "aria-pressed", true);294 .attr( "aria-pressed", "true" ); 260 295 } else { 261 296 $( this ).button( "widget" ) 262 297 .removeClass( "ui-state-active" ) 263 .attr( "aria-pressed", false);298 .attr( "aria-pressed", "false" ); 264 299 } 265 300 }); … … 268 303 this.buttonElement 269 304 .addClass( "ui-state-active" ) 270 .attr( "aria-pressed", true);305 .attr( "aria-pressed", "true" ); 271 306 } else { 272 307 this.buttonElement 273 308 .removeClass( "ui-state-active" ) 274 .attr( "aria-pressed", false);309 .attr( "aria-pressed", "false" ); 275 310 } 276 311 } … … 295 330 296 331 if ( icons.primary || icons.secondary ) { 297 buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) ); 332 if ( this.options.text ) { 333 buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) ); 334 } 298 335 299 336 if ( icons.primary ) { … … 307 344 if ( !this.options.text ) { 308 345 buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" ); 309 buttonElement.removeClass( "ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary" );310 346 311 347 if ( !this.hasTitle ) { … … 342 378 343 379 refresh: function() { 380 var ltr = this.element.css( "direction" ) === "ltr"; 381 344 382 this.buttons = this.element.find( this.options.items ) 345 383 .filter( ":ui-button" ) … … 354 392 .removeClass( "ui-corner-all ui-corner-left ui-corner-right" ) 355 393 .filter( ":first" ) 356 .addClass( "ui-corner-left" )394 .addClass( ltr ? "ui-corner-left" : "ui-corner-right" ) 357 395 .end() 358 396 .filter( ":last" ) 359 .addClass( "ui-corner-right" )397 .addClass( ltr ? "ui-corner-right" : "ui-corner-left" ) 360 398 .end() 361 399 .end();
Note: See TracChangeset
for help on using the changeset viewer.