Upgrade to jquery.mobile-1.0rc1
[busui.git] / js / jquery.mobile-1.0rc1.js
blob:a/js/jquery.mobile-1.0rc1.js -> blob:b/js/jquery.mobile-1.0rc1.js
/*! /*!
* jQuery Mobile v1.0b3 * jQuery Mobile v1.0rc1
* http://jquerymobile.com/ * http://jquerymobile.com/
* *
* Copyright 2010, jQuery Project * Copyright 2010, jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license * http://jquery.org/license
*/ */
/*! /*!
* jQuery UI Widget @VERSION * jQuery UI Widget @VERSION
* *
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license * http://jquery.org/license
* *
* http://docs.jquery.com/UI/Widget * http://docs.jquery.com/UI/Widget
*/ */
(function( $, undefined ) { (function( $, undefined ) {
   
// jQuery 1.4+ // jQuery 1.4+
if ( $.cleanData ) { if ( $.cleanData ) {
var _cleanData = $.cleanData; var _cleanData = $.cleanData;
$.cleanData = function( elems ) { $.cleanData = function( elems ) {
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
$( elem ).triggerHandler( "remove" ); $( elem ).triggerHandler( "remove" );
} }
_cleanData( elems ); _cleanData( elems );
}; };
} else { } else {
var _remove = $.fn.remove; var _remove = $.fn.remove;
$.fn.remove = function( selector, keepData ) { $.fn.remove = function( selector, keepData ) {
return this.each(function() { return this.each(function() {
if ( !keepData ) { if ( !keepData ) {
if ( !selector || $.filter( selector, [ this ] ).length ) { if ( !selector || $.filter( selector, [ this ] ).length ) {
$( "*", this ).add( [ this ] ).each(function() { $( "*", this ).add( [ this ] ).each(function() {
$( this ).triggerHandler( "remove" ); $( this ).triggerHandler( "remove" );
}); });
} }
} }
return _remove.call( $(this), selector, keepData ); return _remove.call( $(this), selector, keepData );
}); });
}; };
} }
   
$.widget = function( name, base, prototype ) { $.widget = function( name, base, prototype ) {
var namespace = name.split( "." )[ 0 ], var namespace = name.split( "." )[ 0 ],
fullName; fullName;
name = name.split( "." )[ 1 ]; name = name.split( "." )[ 1 ];
fullName = namespace + "-" + name; fullName = namespace + "-" + name;
   
if ( !prototype ) { if ( !prototype ) {
prototype = base; prototype = base;
base = $.Widget; base = $.Widget;
} }
   
// create selector for plugin // create selector for plugin
$.expr[ ":" ][ fullName ] = function( elem ) { $.expr[ ":" ][ fullName ] = function( elem ) {
return !!$.data( elem, name ); return !!$.data( elem, name );
}; };
   
$[ namespace ] = $[ namespace ] || {}; $[ namespace ] = $[ namespace ] || {};
$[ namespace ][ name ] = function( options, element ) { $[ namespace ][ name ] = function( options, element ) {
// allow instantiation without initializing for simple inheritance // allow instantiation without initializing for simple inheritance
if ( arguments.length ) { if ( arguments.length ) {
this._createWidget( options, element ); this._createWidget( options, element );
} }
}; };
   
var basePrototype = new base(); var basePrototype = new base();
// we need to make the options hash a property directly on the new instance // we need to make the options hash a property directly on the new instance
// otherwise we'll modify the options hash on the prototype that we're // otherwise we'll modify the options hash on the prototype that we're
// inheriting from // inheriting from
// $.each( basePrototype, function( key, val ) { // $.each( basePrototype, function( key, val ) {
// if ( $.isPlainObject(val) ) { // if ( $.isPlainObject(val) ) {
// basePrototype[ key ] = $.extend( {}, val ); // basePrototype[ key ] = $.extend( {}, val );
// } // }
// }); // });
basePrototype.options = $.extend( true, {}, basePrototype.options ); basePrototype.options = $.extend( true, {}, basePrototype.options );
$[ namespace ][ name ].prototype = $.extend( true, basePrototype, { $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
namespace: namespace, namespace: namespace,
widgetName: name, widgetName: name,
widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name, widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
widgetBaseClass: fullName widgetBaseClass: fullName
}, prototype ); }, prototype );
   
$.widget.bridge( name, $[ namespace ][ name ] ); $.widget.bridge( name, $[ namespace ][ name ] );
}; };
   
$.widget.bridge = function( name, object ) { $.widget.bridge = function( name, object ) {
$.fn[ name ] = function( options ) { $.fn[ name ] = function( options ) {
var isMethodCall = typeof options === "string", var isMethodCall = typeof options === "string",
args = Array.prototype.slice.call( arguments, 1 ), args = Array.prototype.slice.call( arguments, 1 ),
returnValue = this; returnValue = this;
   
// allow multiple hashes to be passed on init // allow multiple hashes to be passed on init
options = !isMethodCall && args.length ? options = !isMethodCall && args.length ?
$.extend.apply( null, [ true, options ].concat(args) ) : $.extend.apply( null, [ true, options ].concat(args) ) :
options; options;
   
// prevent calls to internal methods // prevent calls to internal methods
if ( isMethodCall && options.charAt( 0 ) === "_" ) { if ( isMethodCall && options.charAt( 0 ) === "_" ) {
return returnValue; return returnValue;
} }
   
if ( isMethodCall ) { if ( isMethodCall ) {
this.each(function() { this.each(function() {
var instance = $.data( this, name ); var instance = $.data( this, name );
if ( !instance ) { if ( !instance ) {
throw "cannot call methods on " + name + " prior to initialization; " + throw "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'"; "attempted to call method '" + options + "'";
} }
if ( !$.isFunction( instance[options] ) ) { if ( !$.isFunction( instance[options] ) ) {
throw "no such method '" + options + "' for " + name + " widget instance"; throw "no such method '" + options + "' for " + name + " widget instance";
} }
var methodValue = instance[ options ].apply( instance, args ); var methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) { if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue; returnValue = methodValue;
return false; return false;
} }
}); });
} else { } else {
this.each(function() { this.each(function() {
var instance = $.data( this, name ); var instance = $.data( this, name );
if ( instance ) { if ( instance ) {
instance.option( options || {} )._init(); instance.option( options || {} )._init();
} else { } else {
$.data( this, name, new object( options, this ) ); $.data( this, name, new object( options, this ) );
} }
}); });
} }
   
return returnValue; return returnValue;
}; };
}; };
   
$.Widget = function( options, element ) { $.Widget = function( options, element ) {
// allow instantiation without initializing for simple inheritance // allow instantiation without initializing for simple inheritance
if ( arguments.length ) { if ( arguments.length ) {
this._createWidget( options, element ); this._createWidget( options, element );
} }
}; };
   
$.Widget.prototype = { $.Widget.prototype = {
widgetName: "widget", widgetName: "widget",
widgetEventPrefix: "", widgetEventPrefix: "",
options: { options: {
disabled: false disabled: false
}, },
_createWidget: function( options, element ) { _createWidget: function( options, element ) {
// $.widget.bridge stores the plugin instance, but we do it anyway // $.widget.bridge stores the plugin instance, but we do it anyway
// so that it's stored even before the _create function runs // so that it's stored even before the _create function runs
$.data( element, this.widgetName, this ); $.data( element, this.widgetName, this );
this.element = $( element ); this.element = $( element );
this.options = $.extend( true, {}, this.options = $.extend( true, {},
this.options, this.options,
this._getCreateOptions(), this._getCreateOptions(),
options ); options );
   
var self = this; var self = this;
this.element.bind( "remove." + this.widgetName, function() { this.element.bind( "remove." + this.widgetName, function() {
self.destroy(); self.destroy();
}); });
   
this._create(); this._create();
this._trigger( "create" ); this._trigger( "create" );
this._init(); this._init();
}, },
_getCreateOptions: function() { _getCreateOptions: function() {
var options = {}; var options = {};
if ( $.metadata ) { if ( $.metadata ) {
options = $.metadata.get( element )[ this.widgetName ]; options = $.metadata.get( element )[ this.widgetName ];
} }
return options; return options;
}, },
_create: function() {}, _create: function() {},
_init: function() {}, _init: function() {},
   
destroy: function() { destroy: function() {
this.element this.element
.unbind( "." + this.widgetName ) .unbind( "." + this.widgetName )
.removeData( this.widgetName ); .removeData( this.widgetName );
this.widget() this.widget()
.unbind( "." + this.widgetName ) .unbind( "." + this.widgetName )
.removeAttr( "aria-disabled" ) .removeAttr( "aria-disabled" )
.removeClass( .removeClass(
this.widgetBaseClass + "-disabled " + this.widgetBaseClass + "-disabled " +
"ui-state-disabled" ); "ui-state-disabled" );
}, },
   
widget: function() { widget: function() {
return this.element; return this.element;
}, },
   
option: function( key, value ) { option: function( key, value ) {
var options = key; var options = key;
   
if ( arguments.length === 0 ) { if ( arguments.length === 0 ) {
// don't return a reference to the internal hash // don't return a reference to the internal hash
return $.extend( {}, this.options ); return $.extend( {}, this.options );
} }
   
if (typeof key === "string" ) { if (typeof key === "string" ) {
if ( value === undefined ) { if ( value === undefined ) {
return this.options[ key ]; return this.options[ key ];
} }
options = {}; options = {};
options[ key ] = value; options[ key ] = value;
} }
   
this._setOptions( options ); this._setOptions( options );
   
return this; return this;
}, },
_setOptions: function( options ) { _setOptions: function( options ) {
var self = this; var self = this;
$.each( options, function( key, value ) { $.each( options, function( key, value ) {
self._setOption( key, value ); self._setOption( key, value );
}); });
   
return this; return this;
}, },
_setOption: function( key, value ) { _setOption: function( key, value ) {
this.options[ key ] = value; this.options[ key ] = value;
   
if ( key === "disabled" ) { if ( key === "disabled" ) {
this.widget() this.widget()
[ value ? "addClass" : "removeClass"]( [ value ? "addClass" : "removeClass"](
this.widgetBaseClass + "-disabled" + " " + this.widgetBaseClass + "-disabled" + " " +
"ui-state-disabled" ) "ui-state-disabled" )
.attr( "aria-disabled", value ); .attr( "aria-disabled", value );
} }
   
return this; return this;
}, },
   
enable: function() { enable: function() {
return this._setOption( "disabled", false ); return this._setOption( "disabled", false );
}, },
disable: function() { disable: function() {
return this._setOption( "disabled", true ); return this._setOption( "disabled", true );
}, },
   
_trigger: function( type, event, data ) { _trigger: function( type, event, data ) {
var callback = this.options[ type ]; var callback = this.options[ type ];
   
event = $.Event( event ); event = $.Event( event );
event.type = ( type === this.widgetEventPrefix ? event.type = ( type === this.widgetEventPrefix ?
type : type :
this.widgetEventPrefix + type ).toLowerCase(); this.widgetEventPrefix + type ).toLowerCase();
data = data || {}; data = data || {};
   
// copy original event properties over to the new event // copy original event properties over to the new event
// this would happen if we could call $.event.fix instead of $.Event // this would happen if we could call $.event.fix instead of $.Event
// but we don't have a way to force an event to be fixed multiple times // but we don't have a way to force an event to be fixed multiple times
if ( event.originalEvent ) { if ( event.originalEvent ) {
for ( var i = $.event.props.length, prop; i; ) { for ( var i = $.event.props.length, prop; i; ) {
prop = $.event.props[ --i ]; prop = $.event.props[ --i ];
event[ prop ] = event.originalEvent[ prop ]; event[ prop ] = event.originalEvent[ prop ];
} }
} }
   
this.element.trigger( event, data ); this.element.trigger( event, data );
   
return !( $.isFunction(callback) && return !( $.isFunction(callback) &&
callback.call( this.element[0], event, data ) === false || callback.call( this.element[0], event, data ) === false ||
event.isDefaultPrevented() ); event.isDefaultPrevented() );
} }
}; };
   
})( jQuery ); })( jQuery );
/* /*
* jQuery Mobile Framework : widget factory extentions for mobile * jQuery Mobile Framework : widget factory extentions for mobile
* Copyright (c) jQuery Project * Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license * http://jquery.org/license
*/ */
   
(function( $, undefined ) { (function( $, undefined ) {
   
$.widget( "mobile.widget", { $.widget( "mobile.widget", {
  // decorate the parent _createWidget to trigger `widgetinit` for users
  // who wish to do post post `widgetcreate` alterations/additions
  //
  // TODO create a pull request for jquery ui to trigger this event
  // in the original _createWidget
  _createWidget: function() {
  $.Widget.prototype._createWidget.apply( this, arguments );
  this._trigger( 'init' );
  },
   
_getCreateOptions: function() { _getCreateOptions: function() {
   
var elem = this.element, var elem = this.element,
options = {}; options = {};
   
$.each( this.options, function( option ) { $.each( this.options, function( option ) {
   
var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) { var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
return "-" + c.toLowerCase(); return "-" + c.toLowerCase();
}) })
); );
   
if ( value !== undefined ) { if ( value !== undefined ) {
options[ option ] = value; options[ option ] = value;
} }
}); });
   
return options; return options;
} }
}); });
   
})( jQuery ); })( jQuery );
/* /*
* jQuery Mobile Framework : resolution and CSS media query related helpers and behavior * jQuery Mobile Framework : a workaround for window.matchMedia
* Copyright (c) jQuery Project * Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license * http://jquery.org/license
*/ */
(function( $, undefined ) { (function( $, undefined ) {
   
var $window = $( window ), var $window = $( window ),
$html = $( "html" ); $html = $( "html" );
   
/* $.mobile.media method: pass a CSS media type or query and get a bool return /* $.mobile.media method: pass a CSS media type or query and get a bool return
note: this feature relies on actual media query support for media queries, though types will work most anywhere note: this feature relies on actual media query support for media queries, though types will work most anywhere
examples: examples:
$.mobile.media('screen') //>> tests for screen media type $.mobile.media('screen') //>> tests for screen media type
$.mobile.media('screen and (min-width: 480px)') //>> tests for screen media type with window width > 480px $.mobile.media('screen and (min-width: 480px)') //>> tests for screen media type with window width > 480px
$.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') //>> tests for webkit 2x pixel ratio (iPhone 4) $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') //>> tests for webkit 2x pixel ratio (iPhone 4)
*/ */
$.mobile.media = (function() { $.mobile.media = (function() {
// TODO: use window.matchMedia once at least one UA implements it // TODO: use window.matchMedia once at least one UA implements it
var cache = {}, var cache = {},
testDiv = $( "<div id='jquery-mediatest'>" ), testDiv = $( "<div id='jquery-mediatest'>" ),
fakeBody = $( "<body>" ).append( testDiv ); fakeBody = $( "<body>" ).append( testDiv );
   
return function( query ) { return function( query ) {
if ( !( query in cache ) ) { if ( !( query in cache ) ) {
var styleBlock = document.createElement( "style" ), var styleBlock = document.createElement( "style" ),
cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }"; cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
   
//must set type for IE! //must set type for IE!
styleBlock.type = "text/css"; styleBlock.type = "text/css";
   
if ( styleBlock.styleSheet ){ if ( styleBlock.styleSheet ){
styleBlock.styleSheet.cssText = cssrule; styleBlock.styleSheet.cssText = cssrule;
} else { } else {
styleBlock.appendChild( document.createTextNode(cssrule) ); styleBlock.appendChild( document.createTextNode(cssrule) );
} }
   
$html.prepend( fakeBody ).prepend( styleBlock ); $html.prepend( fakeBody ).prepend( styleBlock );
cache[ query ] = testDiv.css( "position" ) === "absolute"; cache[ query ] = testDiv.css( "position" ) === "absolute";
fakeBody.add( styleBlock ).remove(); fakeBody.add( styleBlock ).remove();
} }
return cache[ query ]; return cache[ query ];
}; };
})(); })();
   
})(jQuery);/* })(jQuery);/*
* jQuery Mobile Framework : support tests * jQuery Mobile Framework : support tests
* Copyright (c) jQuery Project * Copyright (c) jQuery Project
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
*/ */
   
(function( $, undefined ) { (function( $, undefined ) {
   
var fakeBody = $( "<body>" ).prependTo( "html" ), var fakeBody = $( "<body>" ).prependTo( "html" ),
fbCSS = fakeBody[ 0 ].style, fbCSS = fakeBody[ 0 ].style,
vendors = [ "Webkit", "Moz", "O" ], vendors = [ "Webkit", "Moz", "O" ],
webos = "palmGetResource" in window, //only used to rule out scrollTop webos = "palmGetResource" in window, //only used to rule out scrollTop
bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
   
// thx Modernizr // thx Modernizr
function propExists( prop ) { function propExists( prop ) {
var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ), var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " ); props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
   
for ( var v in props ){ for ( var v in props ){
if ( fbCSS[ props[ v ] ] !== undefined ) { if ( fbCSS[ props[ v ] ] !== undefined ) {
return true; return true;
} }
} }
} }
   
// Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting ) // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
function baseTagTest() { function baseTagTest() {
var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/", var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
base = $( "head base" ), base = $( "head base" ),
fauxEle = null, fauxEle = null,
href = "", href = "",
link, rebase; link, rebase;
   
if ( !base.length ) { if ( !base.len