1/*! 2 * jQuery UI Widget @VERSION 3 * 4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) 5 * Dual licensed under the MIT or GPL Version 2 licenses. 6 * http://jquery.org/license 7 * 8 * http://docs.jquery.com/UI/Widget 9 */ 10(function( $, undefined ) { 11 12var slice = Array.prototype.slice; 13 14var _cleanData = $.cleanData; 15$.cleanData = function( elems ) { 16 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { 17 $( elem ).triggerHandler( "remove" ); 18 } 19 _cleanData( elems ); 20}; 21 22$.widget = function( name, base, prototype ) { 23 var namespace = name.split( "." )[ 0 ], 24 fullName; 25 name = name.split( "." )[ 1 ]; 26 fullName = namespace + "-" + name; 27 28 if ( !prototype ) { 29 prototype = base; 30 base = $.Widget; 31 } 32 33 // create selector for plugin 34 $.expr[ ":" ][ fullName ] = function( elem ) { 35 return !!$.data( elem, name ); 36 }; 37 38 $[ namespace ] = $[ namespace ] || {}; 39 // create the constructor using $.extend() so we can carry over any 40 // static properties stored on the existing constructor (if there is one) 41 $[ namespace ][ name ] = $.extend( function( options, element ) { 42 // allow instantiation without "new" keyword 43 if ( !this._createWidget ) {
44 return new $[ namespace ][ name ]( options, element ); 45 } 46 47 // allow instantiation without initializing for simple inheritance 48 // must use "new" keyword (the code above always passes args) 49 if ( arguments.length ) { 50 this._createWidget( options, element ); 51 } 52 }, $[ namespace ][ name ], { version: prototype.version } ); 53 54 var basePrototype = new base(); 55 // we need to make the options hash a property directly on the new instance 56 // otherwise we'll modify the options hash on the prototype that we're 57 // inheriting from 58 basePrototype.options = $.widget.extend( {}, basePrototype.options ); 59 $.each( prototype, function( prop, value ) { 60 if ( $.isFunction( value ) ) { 61 prototype[ prop ] = (function() { 62 var _super = function( method ) { 63 return base.prototype[ method ].apply( this, slice.call( arguments, 1 ) ); 64 }; 65 var _superApply = function( method, args ) { 66 return base.prototype[ method ].apply( this, args ); 67 }; 68 return function() { 69 var __super = this._super, 70 __superApply = this._superApply, 71 returnValue; 72 73 this._super = _super; 74 this._superApply = _superApply; 75 76 returnValue = value.apply( this, arguments ); 77 78 this._super = __super; 79 this._superApply = __superApply; 80 81 return returnValue; 82 }; 83 }()); 84 } 85 }); 86 $[ namespace ][ name ].prototype = $.widget.extend( basePrototype, { 87 namespace: namespace, 88 widgetName: name, 89 widgetEventPrefix: name, 90 widgetBaseClass: fullName 91 }, prototype ); 92 93 $.widget.bridge( name, $[ namespace ][ name ] ); 94}; 95 96$.widget.extend = function( target ) { 97 var input = slice.call( arguments, 1 ), 98 inputIndex = 0, 99 inputLength = input.length, 100 key, 101 value; 102 for ( ; inputIndex < inputLength; inputIndex++ ) { 103 for ( key in input[ inputIndex ] ) { 104 value = input[ inputIndex ][ key ]; 105 if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { 106 target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value; 107 } 108 } 109 } 110 return target; 111}; 112 113$.widget.bridge = function( name, object ) { 114 $.fn[ name ] = function( options ) { 115 var isMethodCall = typeof options === "string", 116 args = slice.call( arguments, 1 ), 117 returnValue = this; 118 119 // allow multiple hashes to be passed on init 120 options = !isMethodCall && args.length ? 121 $.widget.extend.apply( null, [ options ].concat(args) ) : 122 options; 123 124 if ( isMethodCall ) { 125 this.each(function() { 126 var instance = $.data( this, name ); 127 if ( !instance ) { 128 return $.error( "cannot call methods on " + name + " prior to initialization; " + 129 "attempted to call method '" + options + "'" ); 130 } 131 if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) { 132 return $.error( "no such method '" + options + "' for " + name + " widget instance" ); 133 } 134 var methodValue = instance[ options ].apply( instance, args ); 135 if ( methodValue !== instance && methodValue !== undefined ) { 136 returnValue = methodValue && methodValue.jquery ? 137 returnValue.pushStack( methodValue.get() ) : 138 methodValue; 139 return false; 140 } 141 }); 142 } else { 143 this.each(function() { 144 var instance = $.data( this, name ); 145 if ( instance ) { 146 instance.option( options || {} )._init(); 147 } else { 148 object( options, this ); 149 } 150 }); 151 } 152 153 return returnValue; 154 }; 155}; 156 157$.Widget = function( options, element ) { 158 // allow instantiation without "new" keyword 159 if ( !this._createWidget ) {
160 return new $[ namespace ][ name ]( options, element ); 161 } 162 163 // allow instantiation without initializing for simple inheritance 164 // must use "new" keyword (the code above always passes args) 165 if ( arguments.length ) { 166 this._createWidget( options, element ); 167 } 168}; 169 170$.Widget.prototype = { 171 widgetName: "widget", 172 widgetEventPrefix: "", 173 defaultElement: "<div>", 174 options: { 175 disabled: false, 176 177 // callbacks 178 create: null 179 }, 180 _createWidget: function( options, element ) { 181 element = $( element || this.defaultElement || this )[ 0 ]; 182 this.element = $( element ); 183 this.options = $.widget.extend( {}, 184 this.options, 185 this._getCreateOptions(), 186 options ); 187 188 this.bindings = $(); 189 this.hoverable = $(); 190 this.focusable = $(); 191 192 if ( element !== this ) { 193 $.data( element, this.widgetName, this ); 194 this._bind({ remove: "destroy" }); 195 } 196 197 this._create(); 198 this._trigger( "create" ); 199 this._init(); 200 }, 201 _getCreateOptions: $.noop, 202 _create: $.noop, 203 _init: $.noop, 204 205 destroy: function() { 206 this._destroy(); 207 // we can probably remove the unbind calls in 2.0 208 // all event bindings should go through this._bind() 209 this.element 210 .unbind( "." + this.widgetName ) 211 .removeData( this.widgetName ); 212 this.widget() 213 .unbind( "." + this.widgetName ) 214 .removeAttr( "aria-disabled" ) 215 .removeClass( 216 this.widgetBaseClass + "-disabled " + 217 "ui-state-disabled" ); 218 219 // clean up events and states 220 this.bindings.unbind( "." + this.widgetName ); 221 this.hoverable.removeClass( "ui-state-hover" ); 222 this.focusable.removeClass( "ui-state-focus" ); 223 }, 224 _destroy: $.noop, 225 226 widget: function() { 227 return this.element; 228 }, 229 230 option: function( key, value ) { 231 var options = key, 232 parts, 233 curOption, 234 i; 235 236 if ( arguments.length === 0 ) { 237 // don't return a reference to the internal hash 238 return $.widget.extend( {}, this.options ); 239 } 240 241 if ( typeof key === "string" ) { 242 // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } } 243 options = {}; 244 parts = key.split( "." ); 245 key = parts.shift(); 246 if ( parts.length ) { 247 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] ); 248 for ( i = 0; i < parts.length - 1; i++ ) { 249 curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {}; 250 curOption = curOption[ parts[ i ] ]; 251 } 252 key = parts.pop(); 253 if ( value === undefined ) { 254 return curOption[ key ] === undefined ? null : curOption[ key ]; 255 } 256 curOption[ key ] = value; 257 } else { 258 if ( value === undefined ) { 259 return this.options[ key ] === undefined ? null : this.options[ key ]; 260 } 261 options[ key ] = value; 262 } 263 } 264 265 this._setOptions( options ); 266 267 return this; 268 }, 269 _setOptions: function( options ) { 270 var self = this; 271 $.each( options, function( key, value ) { 272 self._setOption( key, value ); 273 }); 274 275 return this; 276 }, 277 _setOption: function( key, value ) { 278 this.options[ key ] = value; 279 280 if ( key === "disabled" ) { 281 this.widget() 282 .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value ) 283 .attr( "aria-disabled", value ); 284 this.hoverable.removeClass( "ui-state-hover" ); 285 this.focusable.removeClass( "ui-state-focus" ); 286 } 287 288 return this; 289 }, 290 291 enable: function() { 292 return this._setOption( "disabled", false ); 293 }, 294 disable: function() { 295 return this._setOption( "disabled", true ); 296 }, 297 298 _bind: function( element, handlers ) { 299 // no element argument, shuffle and use this.element 300 if ( !handlers ) { 301 handlers = element; 302 element = this.element; 303 } else { 304 // accept selectors, DOM elements 305 element = $( element ); 306 this.bindings = this.bindings.add( element ); 307 } 308 var instance = this; 309 $.each( handlers, function( event, handler ) { 310 element.bind( event + "." + instance.widgetName, function() { 311 // allow widgets to customize the disabled handling 312 // - disabled as an array instead of boolean 313 // - disabled class as method for disabling individual parts 314 if ( instance.options.disabled === true || 315 $( this ).hasClass( "ui-state-disabled" ) ) { 316 return; 317 } 318 return ( typeof handler === "string" ? instance[ handler ] : handler ) 319 .apply( instance, arguments ); 320 }); 321 }); 322 }, 323 324 _hoverable: function( element ) { 325 this.hoverable = this.hoverable.add( element ); 326 this._bind( element, { 327 mouseenter: function( event ) { 328 $( event.currentTarget ).addClass( "ui-state-hover" ); 329 }, 330 mouseleave: function( event ) { 331 $( event.currentTarget ).removeClass( "ui-state-hover" ); 332 } 333 }); 334 }, 335 336 _focusable: function( element ) { 337 this.focusable = this.focusable.add( element ); 338 this._bind( element, { 339 focusin: function( event ) { 340 $( event.currentTarget ).addClass( "ui-state-focus" ); 341 }, 342 focusout: function( event ) { 343 $( event.currentTarget ).removeClass( "ui-state-focus" ); 344 } 345 }); 346 }, 347 348 _trigger: function( type, event, data ) { 349 var callback = this.options[ type ], 350 args; 351 352 event = $.Event( event ); 353 event.type = ( type === this.widgetEventPrefix ? 354 type : 355 this.widgetEventPrefix + type ).toLowerCase(); 356 data = data || {}; 357 358 // copy original event properties over to the new event 359 // this would happen if we could call $.event.fix instead of $.Event 360 // but we don't have a way to force an event to be fixed multiple times 361 if ( event.originalEvent ) { 362 for ( var i = $.event.props.length, prop; i; ) { 363 prop = $.event.props[ --i ]; 364 event[ prop ] = event.originalEvent[ prop ]; 365 } 366 } 367 368 this.element.trigger( event, data ); 369 370 args = $.isArray( data ) ? 371 [ event ].concat( data ) : 372 [ event, data ]; 373 374 return !( $.isFunction( callback ) && 375 callback.apply( this.element[0], args ) === false || 376 event.isDefaultPrevented() ); 377 } 378}; 379 380$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { 381 $.Widget.prototype[ "_" + method ] = function( element, options, callback ) { 382 if ( typeof options === "string" ) { 383 options = { effect: options }; 384 } 385 var hasOptions, 386 effectName = !options ? 387 method : 388 options === true || typeof options === "number" ? 389 defaultEffect : 390 options.effect || defaultEffect; 391 options = options || {}; 392 if ( typeof options === "number" ) { 393 options = { duration: options }; 394 } 395 hasOptions = !$.isEmptyObject( options ); 396 options.complete = callback; 397 if ( options.delay ) { 398 element.delay( options.delay ); 399 } 400 if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) { 401 element[ method ]( options ); 402 } else if ( effectName !== method && element[ effectName ] ) {
403 element[ effectName ]( options.duration, options.easing, callback ); 404 } else { 405 element.queue(function( next ) { 406 $( this )[ method ](); 407 if ( callback ) { 408 callback.call( element[ 0 ] ); 409 } 410 next(); 411 }); 412 } 413 }; 414}); 415 416// DEPRECATED 417if ( $.uiBackCompat !== false ) { 418 $.Widget.prototype._getCreateOptions = function() { 419 return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ]; 420 }; 421} 422 423})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.