PageRenderTime 62ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 2ms

/marketing/jquery.mobile.js

http://github.com/zurb/foundation
JavaScript | 5626 lines | 3540 code | 814 blank | 1272 comment | 638 complexity | 3246e0778806f3bf302e3ffd18c7dba1 MD5 | raw file
  1. /*!
  2. * jQuery Mobile v1.0b1
  3. * http://jquerymobile.com/
  4. *
  5. * Copyright 2010, jQuery Project
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://jquery.org/license
  8. */
  9. /*!
  10. * jQuery UI Widget @VERSION
  11. *
  12. * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
  13. * Dual licensed under the MIT or GPL Version 2 licenses.
  14. * http://jquery.org/license
  15. *
  16. * http://docs.jquery.com/UI/Widget
  17. */
  18. (function( $, undefined ) {
  19. // jQuery 1.4+
  20. if ( $.cleanData ) {
  21. var _cleanData = $.cleanData;
  22. $.cleanData = function( elems ) {
  23. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  24. $( elem ).triggerHandler( "remove" );
  25. }
  26. _cleanData( elems );
  27. };
  28. } else {
  29. var _remove = $.fn.remove;
  30. $.fn.remove = function( selector, keepData ) {
  31. return this.each(function() {
  32. if ( !keepData ) {
  33. if ( !selector || $.filter( selector, [ this ] ).length ) {
  34. $( "*", this ).add( [ this ] ).each(function() {
  35. $( this ).triggerHandler( "remove" );
  36. });
  37. }
  38. }
  39. return _remove.call( $(this), selector, keepData );
  40. });
  41. };
  42. }
  43. $.widget = function( name, base, prototype ) {
  44. var namespace = name.split( "." )[ 0 ],
  45. fullName;
  46. name = name.split( "." )[ 1 ];
  47. fullName = namespace + "-" + name;
  48. if ( !prototype ) {
  49. prototype = base;
  50. base = $.Widget;
  51. }
  52. // create selector for plugin
  53. $.expr[ ":" ][ fullName ] = function( elem ) {
  54. return !!$.data( elem, name );
  55. };
  56. $[ namespace ] = $[ namespace ] || {};
  57. $[ namespace ][ name ] = function( options, element ) {
  58. // allow instantiation without initializing for simple inheritance
  59. if ( arguments.length ) {
  60. this._createWidget( options, element );
  61. }
  62. };
  63. var basePrototype = new base();
  64. // we need to make the options hash a property directly on the new instance
  65. // otherwise we'll modify the options hash on the prototype that we're
  66. // inheriting from
  67. // $.each( basePrototype, function( key, val ) {
  68. // if ( $.isPlainObject(val) ) {
  69. // basePrototype[ key ] = $.extend( {}, val );
  70. // }
  71. // });
  72. basePrototype.options = $.extend( true, {}, basePrototype.options );
  73. $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
  74. namespace: namespace,
  75. widgetName: name,
  76. widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
  77. widgetBaseClass: fullName
  78. }, prototype );
  79. $.widget.bridge( name, $[ namespace ][ name ] );
  80. };
  81. $.widget.bridge = function( name, object ) {
  82. $.fn[ name ] = function( options ) {
  83. var isMethodCall = typeof options === "string",
  84. args = Array.prototype.slice.call( arguments, 1 ),
  85. returnValue = this;
  86. // allow multiple hashes to be passed on init
  87. options = !isMethodCall && args.length ?
  88. $.extend.apply( null, [ true, options ].concat(args) ) :
  89. options;
  90. // prevent calls to internal methods
  91. if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  92. return returnValue;
  93. }
  94. if ( isMethodCall ) {
  95. this.each(function() {
  96. var instance = $.data( this, name );
  97. if ( !instance ) {
  98. throw "cannot call methods on " + name + " prior to initialization; " +
  99. "attempted to call method '" + options + "'";
  100. }
  101. if ( !$.isFunction( instance[options] ) ) {
  102. throw "no such method '" + options + "' for " + name + " widget instance";
  103. }
  104. var methodValue = instance[ options ].apply( instance, args );
  105. if ( methodValue !== instance && methodValue !== undefined ) {
  106. returnValue = methodValue;
  107. return false;
  108. }
  109. });
  110. } else {
  111. this.each(function() {
  112. var instance = $.data( this, name );
  113. if ( instance ) {
  114. instance.option( options || {} )._init();
  115. } else {
  116. $.data( this, name, new object( options, this ) );
  117. }
  118. });
  119. }
  120. return returnValue;
  121. };
  122. };
  123. $.Widget = function( options, element ) {
  124. // allow instantiation without initializing for simple inheritance
  125. if ( arguments.length ) {
  126. this._createWidget( options, element );
  127. }
  128. };
  129. $.Widget.prototype = {
  130. widgetName: "widget",
  131. widgetEventPrefix: "",
  132. options: {
  133. disabled: false
  134. },
  135. _createWidget: function( options, element ) {
  136. // $.widget.bridge stores the plugin instance, but we do it anyway
  137. // so that it's stored even before the _create function runs
  138. $.data( element, this.widgetName, this );
  139. this.element = $( element );
  140. this.options = $.extend( true, {},
  141. this.options,
  142. this._getCreateOptions(),
  143. options );
  144. var self = this;
  145. this.element.bind( "remove." + this.widgetName, function() {
  146. self.destroy();
  147. });
  148. this._create();
  149. this._trigger( "create" );
  150. this._init();
  151. },
  152. _getCreateOptions: function() {
  153. var options = {};
  154. if ( $.metadata ) {
  155. options = $.metadata.get( element )[ this.widgetName ];
  156. }
  157. return options;
  158. },
  159. _create: function() {},
  160. _init: function() {},
  161. destroy: function() {
  162. this.element
  163. .unbind( "." + this.widgetName )
  164. .removeData( this.widgetName );
  165. this.widget()
  166. .unbind( "." + this.widgetName )
  167. .removeAttr( "aria-disabled" )
  168. .removeClass(
  169. this.widgetBaseClass + "-disabled " +
  170. "ui-state-disabled" );
  171. },
  172. widget: function() {
  173. return this.element;
  174. },
  175. option: function( key, value ) {
  176. var options = key;
  177. if ( arguments.length === 0 ) {
  178. // don't return a reference to the internal hash
  179. return $.extend( {}, this.options );
  180. }
  181. if (typeof key === "string" ) {
  182. if ( value === undefined ) {
  183. return this.options[ key ];
  184. }
  185. options = {};
  186. options[ key ] = value;
  187. }
  188. this._setOptions( options );
  189. return this;
  190. },
  191. _setOptions: function( options ) {
  192. var self = this;
  193. $.each( options, function( key, value ) {
  194. self._setOption( key, value );
  195. });
  196. return this;
  197. },
  198. _setOption: function( key, value ) {
  199. this.options[ key ] = value;
  200. if ( key === "disabled" ) {
  201. this.widget()
  202. [ value ? "addClass" : "removeClass"](
  203. this.widgetBaseClass + "-disabled" + " " +
  204. "ui-state-disabled" )
  205. .attr( "aria-disabled", value );
  206. }
  207. return this;
  208. },
  209. enable: function() {
  210. return this._setOption( "disabled", false );
  211. },
  212. disable: function() {
  213. return this._setOption( "disabled", true );
  214. },
  215. _trigger: function( type, event, data ) {
  216. var callback = this.options[ type ];
  217. event = $.Event( event );
  218. event.type = ( type === this.widgetEventPrefix ?
  219. type :
  220. this.widgetEventPrefix + type ).toLowerCase();
  221. data = data || {};
  222. // copy original event properties over to the new event
  223. // this would happen if we could call $.event.fix instead of $.Event
  224. // but we don't have a way to force an event to be fixed multiple times
  225. if ( event.originalEvent ) {
  226. for ( var i = $.event.props.length, prop; i; ) {
  227. prop = $.event.props[ --i ];
  228. event[ prop ] = event.originalEvent[ prop ];
  229. }
  230. }
  231. this.element.trigger( event, data );
  232. return !( $.isFunction(callback) &&
  233. callback.call( this.element[0], event, data ) === false ||
  234. event.isDefaultPrevented() );
  235. }
  236. };
  237. })( jQuery );
  238. /*
  239. * jQuery Mobile Framework : widget factory extentions for mobile
  240. * Copyright (c) jQuery Project
  241. * Dual licensed under the MIT or GPL Version 2 licenses.
  242. * http://jquery.org/license
  243. */
  244. (function($, undefined ) {
  245. $.widget( "mobile.widget", {
  246. _getCreateOptions: function() {
  247. var elem = this.element,
  248. options = {};
  249. $.each( this.options, function( option ) {
  250. var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
  251. return "-" + c.toLowerCase();
  252. } ) );
  253. if ( value !== undefined ) {
  254. options[ option ] = value;
  255. }
  256. });
  257. return options;
  258. }
  259. });
  260. })( jQuery );
  261. /*
  262. * jQuery Mobile Framework : resolution and CSS media query related helpers and behavior
  263. * Copyright (c) jQuery Project
  264. * Dual licensed under the MIT or GPL Version 2 licenses.
  265. * http://jquery.org/license
  266. */
  267. (function($, undefined ) {
  268. var $window = $(window),
  269. $html = $( "html" ),
  270. //media-query-like width breakpoints, which are translated to classes on the html element
  271. resolutionBreakpoints = [320,480,768,1024];
  272. /* $.mobile.media method: pass a CSS media type or query and get a bool return
  273. note: this feature relies on actual media query support for media queries, though types will work most anywhere
  274. examples:
  275. $.mobile.media('screen') //>> tests for screen media type
  276. $.mobile.media('screen and (min-width: 480px)') //>> tests for screen media type with window width > 480px
  277. $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') //>> tests for webkit 2x pixel ratio (iPhone 4)
  278. */
  279. $.mobile.media = (function() {
  280. // TODO: use window.matchMedia once at least one UA implements it
  281. var cache = {},
  282. testDiv = $( "<div id='jquery-mediatest'>" ),
  283. fakeBody = $( "<body>" ).append( testDiv );
  284. return function( query ) {
  285. if ( !( query in cache ) ) {
  286. var styleBlock = document.createElement('style'),
  287. cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
  288. //must set type for IE!
  289. styleBlock.type = "text/css";
  290. if (styleBlock.styleSheet){
  291. styleBlock.styleSheet.cssText = cssrule;
  292. }
  293. else {
  294. styleBlock.appendChild(document.createTextNode(cssrule));
  295. }
  296. $html.prepend( fakeBody ).prepend( styleBlock );
  297. cache[ query ] = testDiv.css( "position" ) === "absolute";
  298. fakeBody.add( styleBlock ).remove();
  299. }
  300. return cache[ query ];
  301. };
  302. })();
  303. /*
  304. private function for adding/removing breakpoint classes to HTML element for faux media-query support
  305. It does not require media query support, instead using JS to detect screen width > cross-browser support
  306. This function is called on orientationchange, resize, and mobileinit, and is bound via the 'htmlclass' event namespace
  307. */
  308. function detectResolutionBreakpoints(){
  309. var currWidth = $window.width(),
  310. minPrefix = "min-width-",
  311. maxPrefix = "max-width-",
  312. minBreakpoints = [],
  313. maxBreakpoints = [],
  314. unit = "px",
  315. breakpointClasses;
  316. $html.removeClass( minPrefix + resolutionBreakpoints.join(unit + " " + minPrefix) + unit + " " +
  317. maxPrefix + resolutionBreakpoints.join( unit + " " + maxPrefix) + unit );
  318. $.each(resolutionBreakpoints,function( i, breakPoint ){
  319. if( currWidth >= breakPoint ){
  320. minBreakpoints.push( minPrefix + breakPoint + unit );
  321. }
  322. if( currWidth <= breakPoint ){
  323. maxBreakpoints.push( maxPrefix + breakPoint + unit );
  324. }
  325. });
  326. if( minBreakpoints.length ){ breakpointClasses = minBreakpoints.join(" "); }
  327. if( maxBreakpoints.length ){ breakpointClasses += " " + maxBreakpoints.join(" "); }
  328. $html.addClass( breakpointClasses );
  329. };
  330. /* $.mobile.addResolutionBreakpoints method:
  331. pass either a number or an array of numbers and they'll be added to the min/max breakpoint classes
  332. Examples:
  333. $.mobile.addResolutionBreakpoints( 500 );
  334. $.mobile.addResolutionBreakpoints( [500, 1200] );
  335. */
  336. $.mobile.addResolutionBreakpoints = function( newbps ){
  337. if( $.type( newbps ) === "array" ){
  338. resolutionBreakpoints = resolutionBreakpoints.concat( newbps );
  339. }
  340. else {
  341. resolutionBreakpoints.push( newbps );
  342. }
  343. resolutionBreakpoints.sort(function(a,b){ return a-b; });
  344. detectResolutionBreakpoints();
  345. };
  346. /* on mobileinit, add classes to HTML element
  347. and set handlers to update those on orientationchange and resize*/
  348. $(document).bind("mobileinit.htmlclass", function(){
  349. /* bind to orientationchange and resize
  350. to add classes to HTML element for min/max breakpoints and orientation */
  351. var ev = $.support.orientation;
  352. $window.bind("orientationchange.htmlclass throttledResize.htmlclass", function(event){
  353. //add orientation class to HTML element on flip/resize.
  354. if(event.orientation){
  355. $html.removeClass( "portrait landscape" ).addClass( event.orientation );
  356. }
  357. //add classes to HTML element for min/max breakpoints
  358. detectResolutionBreakpoints();
  359. });
  360. });
  361. /* Manually trigger an orientationchange event when the dom ready event fires.
  362. This will ensure that any viewport meta tag that may have been injected
  363. has taken effect already, allowing us to properly calculate the width of the
  364. document.
  365. */
  366. $(function(){
  367. //trigger event manually
  368. $window.trigger( "orientationchange.htmlclass" );
  369. });
  370. })(jQuery);/*
  371. * jQuery Mobile Framework : support tests
  372. * Copyright (c) jQuery Project
  373. * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
  374. * Note: Code is in draft form and is subject to change
  375. */
  376. ( function( $, undefined ) {
  377. var fakeBody = $( "<body>" ).prependTo( "html" ),
  378. fbCSS = fakeBody[ 0 ].style,
  379. vendors = [ "webkit", "moz", "o" ],
  380. webos = "palmGetResource" in window, //only used to rule out scrollTop
  381. bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
  382. // thx Modernizr
  383. function propExists( prop ){
  384. var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
  385. props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
  386. for( var v in props ){
  387. if( fbCSS[ v ] !== undefined ){
  388. return true;
  389. }
  390. }
  391. }
  392. // test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
  393. function baseTagTest(){
  394. var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
  395. base = $( "head base" ),
  396. fauxEle = null,
  397. href = "";
  398. if ( !base.length ) {
  399. base = fauxEle = $( "<base>", { "href": fauxBase} ).appendTo( "head" );
  400. }
  401. else {
  402. href = base.attr( "href" );
  403. }
  404. var link = $( "<a href='testurl'></a>" ).prependTo( fakeBody ),
  405. rebase = link[ 0 ].href;
  406. base[ 0 ].href = href ? href : location.pathname;
  407. if ( fauxEle ) {
  408. fauxEle.remove();
  409. }
  410. return rebase.indexOf( fauxBase ) === 0;
  411. }
  412. // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
  413. // allows for inclusion of IE 6+, including Windows Mobile 7
  414. $.mobile.browser = {};
  415. $.mobile.browser.ie = ( function() {
  416. var v = 3,
  417. div = document.createElement( "div" ),
  418. a = div.all || [];
  419. while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] );
  420. return v > 4 ? v : !v;
  421. }() );
  422. $.extend( $.support, {
  423. orientation: "orientation" in window,
  424. touch: "ontouchend" in document,
  425. cssTransitions: "WebKitTransitionEvent" in window,
  426. pushState: !!history.pushState,
  427. mediaquery: $.mobile.media( "only all" ),
  428. cssPseudoElement: !!propExists( "content" ),
  429. boxShadow: !!propExists( "boxShadow" ) && !bb,
  430. scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos,
  431. dynamicBaseTag: baseTagTest(),
  432. eventCapture: ( "addEventListener" in document ) // This is a weak test. We may want to beef this up later.
  433. } );
  434. fakeBody.remove();
  435. // for ruling out shadows via css
  436. if( !$.support.boxShadow ){ $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" ); }
  437. } )( jQuery );/*
  438. * jQuery Mobile Framework : "mouse" plugin
  439. * Copyright (c) jQuery Project
  440. * Dual licensed under the MIT or GPL Version 2 licenses.
  441. * http://jquery.org/license
  442. */
  443. // This plugin is an experiment for abstracting away the touch and mouse
  444. // events so that developers don't have to worry about which method of input
  445. // the device their document is loaded on supports.
  446. //
  447. // The idea here is to allow the developer to register listeners for the
  448. // basic mouse events, such as mousedown, mousemove, mouseup, and click,
  449. // and the plugin will take care of registering the correct listeners
  450. // behind the scenes to invoke the listener at the fastest possible time
  451. // for that device, while still retaining the order of event firing in
  452. // the traditional mouse environment, should multiple handlers be registered
  453. // on the same element for different events.
  454. //
  455. // The current version exposes the following virtual events to jQuery bind methods:
  456. // "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"
  457. (function($, window, document, undefined) {
  458. var dataPropertyName = "virtualMouseBindings",
  459. touchTargetPropertyName = "virtualTouchID",
  460. virtualEventNames = "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),
  461. touchEventProps = "clientX clientY pageX pageY screenX screenY".split(" "),
  462. activeDocHandlers = {},
  463. resetTimerID = 0,
  464. startX = 0,
  465. startY = 0,
  466. didScroll = false,
  467. clickBlockList = [],
  468. blockMouseTriggers = false,
  469. blockTouchTriggers = false,
  470. eventCaptureSupported = $.support.eventCapture,
  471. $document = $(document),
  472. nextTouchID = 1,
  473. lastTouchID = 0;
  474. $.vmouse = {
  475. moveDistanceThreshold: 10,
  476. clickDistanceThreshold: 10,
  477. resetTimerDuration: 1500
  478. };
  479. function getNativeEvent(event)
  480. {
  481. while (event && typeof event.originalEvent !== "undefined") {
  482. event = event.originalEvent;
  483. }
  484. return event;
  485. }
  486. function createVirtualEvent(event, eventType)
  487. {
  488. var t = event.type;
  489. event = $.Event(event);
  490. event.type = eventType;
  491. var oe = event.originalEvent;
  492. var props = $.event.props;
  493. // copy original event properties over to the new event
  494. // this would happen if we could call $.event.fix instead of $.Event
  495. // but we don't have a way to force an event to be fixed multiple times
  496. if (oe) {
  497. for ( var i = props.length, prop; i; ) {
  498. prop = props[ --i ];
  499. event[prop] = oe[prop];
  500. }
  501. }
  502. if (t.search(/^touch/) !== -1){
  503. var ne = getNativeEvent(oe),
  504. t = ne.touches,
  505. ct = ne.changedTouches,
  506. touch = (t && t.length) ? t[0] : ((ct && ct.length) ? ct[0] : undefined);
  507. if (touch){
  508. for (var i = 0, len = touchEventProps.length; i < len; i++){
  509. var prop = touchEventProps[i];
  510. event[prop] = touch[prop];
  511. }
  512. }
  513. }
  514. return event;
  515. }
  516. function getVirtualBindingFlags(element)
  517. {
  518. var flags = {};
  519. while (element){
  520. var b = $.data(element, dataPropertyName);
  521. for (var k in b) {
  522. if (b[k]){
  523. flags[k] = flags.hasVirtualBinding = true;
  524. }
  525. }
  526. element = element.parentNode;
  527. }
  528. return flags;
  529. }
  530. function getClosestElementWithVirtualBinding(element, eventType)
  531. {
  532. while (element){
  533. var b = $.data(element, dataPropertyName);
  534. if (b && (!eventType || b[eventType])) {
  535. return element;
  536. }
  537. element = element.parentNode;
  538. }
  539. return null;
  540. }
  541. function enableTouchBindings()
  542. {
  543. blockTouchTriggers = false;
  544. }
  545. function disableTouchBindings()
  546. {
  547. blockTouchTriggers = true;
  548. }
  549. function enableMouseBindings()
  550. {
  551. lastTouchID = 0;
  552. clickBlockList.length = 0;
  553. blockMouseTriggers = false;
  554. // When mouse bindings are enabled, our
  555. // touch bindings are disabled.
  556. disableTouchBindings();
  557. }
  558. function disableMouseBindings()
  559. {
  560. // When mouse bindings are disabled, our
  561. // touch bindings are enabled.
  562. enableTouchBindings();
  563. }
  564. function startResetTimer()
  565. {
  566. clearResetTimer();
  567. resetTimerID = setTimeout(function(){
  568. resetTimerID = 0;
  569. enableMouseBindings();
  570. }, $.vmouse.resetTimerDuration);
  571. }
  572. function clearResetTimer()
  573. {
  574. if (resetTimerID){
  575. clearTimeout(resetTimerID);
  576. resetTimerID = 0;
  577. }
  578. }
  579. function triggerVirtualEvent(eventType, event, flags)
  580. {
  581. var defaultPrevented = false;
  582. if ((flags && flags[eventType]) || (!flags && getClosestElementWithVirtualBinding(event.target, eventType))) {
  583. var ve = createVirtualEvent(event, eventType);
  584. $(event.target).trigger(ve);
  585. defaultPrevented = ve.isDefaultPrevented();
  586. }
  587. return defaultPrevented;
  588. }
  589. function mouseEventCallback(event)
  590. {
  591. var touchID = $.data(event.target, touchTargetPropertyName);
  592. if (!blockMouseTriggers && (!lastTouchID || lastTouchID !== touchID)){
  593. triggerVirtualEvent("v" + event.type, event);
  594. }
  595. }
  596. function handleTouchStart(event)
  597. {
  598. var touches = getNativeEvent(event).touches;
  599. if (touches && touches.length === 1){
  600. var target = event.target,
  601. flags = getVirtualBindingFlags(target);
  602. if (flags.hasVirtualBinding){
  603. lastTouchID = nextTouchID++;
  604. $.data(target, touchTargetPropertyName, lastTouchID);
  605. clearResetTimer();
  606. disableMouseBindings();
  607. didScroll = false;
  608. var t = getNativeEvent(event).touches[0];
  609. startX = t.pageX;
  610. startY = t.pageY;
  611. triggerVirtualEvent("vmouseover", event, flags);
  612. triggerVirtualEvent("vmousedown", event, flags);
  613. }
  614. }
  615. }
  616. function handleScroll(event)
  617. {
  618. if (blockTouchTriggers){
  619. return;
  620. }
  621. if (!didScroll){
  622. triggerVirtualEvent("vmousecancel", event, getVirtualBindingFlags(event.target));
  623. }
  624. didScroll = true;
  625. startResetTimer();
  626. }
  627. function handleTouchMove(event)
  628. {
  629. if (blockTouchTriggers){
  630. return;
  631. }
  632. var t = getNativeEvent(event).touches[0];
  633. var didCancel = didScroll,
  634. moveThreshold = $.vmouse.moveDistanceThreshold;
  635. didScroll = didScroll
  636. || (Math.abs(t.pageX - startX) > moveThreshold || Math.abs(t.pageY - startY) > moveThreshold);
  637. var flags = getVirtualBindingFlags(event.target);
  638. if (didScroll && !didCancel){
  639. triggerVirtualEvent("vmousecancel", event, flags);
  640. }
  641. triggerVirtualEvent("vmousemove", event, flags);
  642. startResetTimer();
  643. }
  644. function handleTouchEnd(event)
  645. {
  646. if (blockTouchTriggers){
  647. return;
  648. }
  649. disableTouchBindings();
  650. var flags = getVirtualBindingFlags(event.target);
  651. triggerVirtualEvent("vmouseup", event, flags);
  652. if (!didScroll){
  653. if (triggerVirtualEvent("vclick", event, flags)){
  654. // The target of the mouse events that follow the touchend
  655. // event don't necessarily match the target used during the
  656. // touch. This means we need to rely on coordinates for blocking
  657. // any click that is generated.
  658. var t = getNativeEvent(event).changedTouches[0];
  659. clickBlockList.push({ touchID: lastTouchID, x: t.clientX, y: t.clientY });
  660. // Prevent any mouse events that follow from triggering
  661. // virtual event notifications.
  662. blockMouseTriggers = true;
  663. }
  664. }
  665. triggerVirtualEvent("vmouseout", event, flags);
  666. didScroll = false;
  667. startResetTimer();
  668. }
  669. function hasVirtualBindings(ele)
  670. {
  671. var bindings = $.data(ele, dataPropertyName), k;
  672. if (bindings){
  673. for (k in bindings){
  674. if (bindings[k]){
  675. return true;
  676. }
  677. }
  678. }
  679. return false;
  680. }
  681. function dummyMouseHandler(){}
  682. function getSpecialEventObject(eventType)
  683. {
  684. var realType = eventType.substr(1);
  685. return {
  686. setup: function(data, namespace) {
  687. // If this is the first virtual mouse binding for this element,
  688. // add a bindings object to its data.
  689. if (!hasVirtualBindings(this)){
  690. $.data(this, dataPropertyName, {});
  691. }
  692. // If setup is called, we know it is the first binding for this
  693. // eventType, so initialize the count for the eventType to zero.
  694. var bindings = $.data(this, dataPropertyName);
  695. bindings[eventType] = true;
  696. // If this is the first virtual mouse event for this type,
  697. // register a global handler on the document.
  698. activeDocHandlers[eventType] = (activeDocHandlers[eventType] || 0) + 1;
  699. if (activeDocHandlers[eventType] === 1){
  700. $document.bind(realType, mouseEventCallback);
  701. }
  702. // Some browsers, like Opera Mini, won't dispatch mouse/click events
  703. // for elements unless they actually have handlers registered on them.
  704. // To get around this, we register dummy handlers on the elements.
  705. $(this).bind(realType, dummyMouseHandler);
  706. // For now, if event capture is not supported, we rely on mouse handlers.
  707. if (eventCaptureSupported){
  708. // If this is the first virtual mouse binding for the document,
  709. // register our touchstart handler on the document.
  710. activeDocHandlers["touchstart"] = (activeDocHandlers["touchstart"] || 0) + 1;
  711. if (activeDocHandlers["touchstart"] === 1) {
  712. $document.bind("touchstart", handleTouchStart)
  713. .bind("touchend", handleTouchEnd)
  714. // On touch platforms, touching the screen and then dragging your finger
  715. // causes the window content to scroll after some distance threshold is
  716. // exceeded. On these platforms, a scroll prevents a click event from being
  717. // dispatched, and on some platforms, even the touchend is suppressed. To
  718. // mimic the suppression of the click event, we need to watch for a scroll
  719. // event. Unfortunately, some platforms like iOS don't dispatch scroll
  720. // events until *AFTER* the user lifts their finger (touchend). This means
  721. // we need to watch both scroll and touchmove events to figure out whether
  722. // or not a scroll happenens before the touchend event is fired.
  723. .bind("touchmove", handleTouchMove)
  724. .bind("scroll", handleScroll);
  725. }
  726. }
  727. },
  728. teardown: function(data, namespace) {
  729. // If this is the last virtual binding for this eventType,
  730. // remove its global handler from the document.
  731. --activeDocHandlers[eventType];
  732. if (!activeDocHandlers[eventType]){
  733. $document.unbind(realType, mouseEventCallback);
  734. }
  735. if (eventCaptureSupported){
  736. // If this is the last virtual mouse binding in existence,
  737. // remove our document touchstart listener.
  738. --activeDocHandlers["touchstart"];
  739. if (!activeDocHandlers["touchstart"]) {
  740. $document.unbind("touchstart", handleTouchStart)
  741. .unbind("touchmove", handleTouchMove)
  742. .unbind("touchend", handleTouchEnd)
  743. .unbind("scroll", handleScroll);
  744. }
  745. }
  746. var $this = $(this),
  747. bindings = $.data(this, dataPropertyName);
  748. // teardown may be called when an element was
  749. // removed from the DOM. If this is the case,
  750. // jQuery core may have already stripped the element
  751. // of any data bindings so we need to check it before
  752. // using it.
  753. if (bindings){
  754. bindings[eventType] = false;
  755. }
  756. // Unregister the dummy event handler.
  757. $this.unbind(realType, dummyMouseHandler);
  758. // If this is the last virtual mouse binding on the
  759. // element, remove the binding data from the element.
  760. if (!hasVirtualBindings(this)){
  761. $this.removeData(dataPropertyName);
  762. }
  763. }
  764. };
  765. }
  766. // Expose our custom events to the jQuery bind/unbind mechanism.
  767. for (var i = 0; i < virtualEventNames.length; i++){
  768. $.event.special[virtualEventNames[i]] = getSpecialEventObject(virtualEventNames[i]);
  769. }
  770. // Add a capture click handler to block clicks.
  771. // Note that we require event capture support for this so if the device
  772. // doesn't support it, we punt for now and rely solely on mouse events.
  773. if (eventCaptureSupported){
  774. document.addEventListener("click", function(e){
  775. var cnt = clickBlockList.length;
  776. var target = e.target;
  777. if (cnt) {
  778. var x = e.clientX,
  779. y = e.clientY,
  780. threshold = $.vmouse.clickDistanceThreshold;
  781. // The idea here is to run through the clickBlockList to see if
  782. // the current click event is in the proximity of one of our
  783. // vclick events that had preventDefault() called on it. If we find
  784. // one, then we block the click.
  785. //
  786. // Why do we have to rely on proximity?
  787. //
  788. // Because the target of the touch event that triggered the vclick
  789. // can be different from the target of the click event synthesized
  790. // by the browser. The target of a mouse/click event that is syntehsized
  791. // from a touch event seems to be implementation specific. For example,
  792. // some browsers will fire mouse/click events for a link that is near
  793. // a touch event, even though the target of the touchstart/touchend event
  794. // says the user touched outside the link. Also, it seems that with most
  795. // browsers, the target of the mouse/click event is not calculated until the
  796. // time it is dispatched, so if you replace an element that you touched
  797. // with another element, the target of the mouse/click will be the new
  798. // element underneath that point.
  799. //
  800. // Aside from proximity, we also check to see if the target and any
  801. // of its ancestors were the ones that blocked a click. This is necessary
  802. // because of the strange mouse/click target calculation done in the
  803. // Android 2.1 browser, where if you click on an element, and there is a
  804. // mouse/click handler on one of its ancestors, the target will be the
  805. // innermost child of the touched element, even if that child is no where
  806. // near the point of touch.
  807. var ele = target;
  808. while (ele) {
  809. for (var i = 0; i < cnt; i++) {
  810. var o = clickBlockList[i],
  811. touchID = 0;
  812. if ((ele === target && Math.abs(o.x - x) < threshold && Math.abs(o.y - y) < threshold) || $.data(ele, touchTargetPropertyName) === o.touchID){
  813. // XXX: We may want to consider removing matches from the block list
  814. // instead of waiting for the reset timer to fire.
  815. e.preventDefault();
  816. e.stopPropagation();
  817. return;
  818. }
  819. }
  820. ele = ele.parentNode;
  821. }
  822. }
  823. }, true);
  824. }
  825. })(jQuery, window, document);
  826. /*
  827. * jQuery Mobile Framework : events
  828. * Copyright (c) jQuery Project
  829. * Dual licensed under the MIT or GPL Version 2 licenses.
  830. * http://jquery.org/license
  831. */
  832. (function($, undefined ) {
  833. // add new event shortcuts
  834. $.each( "touchstart touchmove touchend orientationchange throttledresize tap taphold swipe swipeleft swiperight scrollstart scrollstop".split( " " ), function( i, name ) {
  835. $.fn[ name ] = function( fn ) {
  836. return fn ? this.bind( name, fn ) : this.trigger( name );
  837. };
  838. $.attrFn[ name ] = true;
  839. });
  840. var supportTouch = $.support.touch,
  841. scrollEvent = "touchmove scroll",
  842. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  843. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  844. touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
  845. function triggerCustomEvent(obj, eventType, event)
  846. {
  847. var originalType = event.type;
  848. event.type = eventType;
  849. $.event.handle.call( obj, event );
  850. event.type = originalType;
  851. }
  852. // also handles scrollstop
  853. $.event.special.scrollstart = {
  854. enabled: true,
  855. setup: function() {
  856. var thisObject = this,
  857. $this = $( thisObject ),
  858. scrolling,
  859. timer;
  860. function trigger( event, state ) {
  861. scrolling = state;
  862. triggerCustomEvent( thisObject, scrolling ? "scrollstart" : "scrollstop", event );
  863. }
  864. // iPhone triggers scroll after a small delay; use touchmove instead
  865. $this.bind( scrollEvent, function( event ) {
  866. if ( !$.event.special.scrollstart.enabled ) {
  867. return;
  868. }
  869. if ( !scrolling ) {
  870. trigger( event, true );
  871. }
  872. clearTimeout( timer );
  873. timer = setTimeout(function() {
  874. trigger( event, false );
  875. }, 50 );
  876. });
  877. }
  878. };
  879. // also handles taphold
  880. $.event.special.tap = {
  881. setup: function() {
  882. var thisObject = this,
  883. $this = $( thisObject );
  884. $this
  885. .bind("vmousedown", function( event ) {
  886. if ( event.which && event.which !== 1 ) {
  887. return false;
  888. }
  889. var touching = true,
  890. origTarget = event.target,
  891. origEvent = event.originalEvent,
  892. timer;
  893. function clearTapHandlers() {
  894. touching = false;
  895. clearTimeout(timer);
  896. $this.unbind("vclick", clickHandler).unbind("vmousecancel", clearTapHandlers);
  897. }
  898. function clickHandler(event) {
  899. clearTapHandlers();
  900. /* ONLY trigger a 'tap' event if the start target is
  901. * the same as the stop target.
  902. */
  903. if ( origTarget == event.target ) {
  904. triggerCustomEvent( thisObject, "tap", event );
  905. }
  906. }
  907. $this.bind("vmousecancel", clearTapHandlers).bind("vclick", clickHandler);
  908. timer = setTimeout(function() {
  909. if ( touching ) {
  910. triggerCustomEvent( thisObject, "taphold", event );
  911. }
  912. }, 750 );
  913. });
  914. }
  915. };
  916. // also handles swipeleft, swiperight
  917. $.event.special.swipe = {
  918. setup: function() {
  919. var thisObject = this,
  920. $this = $( thisObject );
  921. $this
  922. .bind( touchStartEvent, function( event ) {
  923. var data = event.originalEvent.touches ?
  924. event.originalEvent.touches[ 0 ] :
  925. event,
  926. start = {
  927. time: (new Date).getTime(),
  928. coords: [ data.pageX, data.pageY ],
  929. origin: $( event.target )
  930. },
  931. stop;
  932. function moveHandler( event ) {
  933. if ( !start ) {
  934. return;
  935. }
  936. var data = event.originalEvent.touches ?
  937. event.originalEvent.touches[ 0 ] :
  938. event;
  939. stop = {
  940. time: (new Date).getTime(),
  941. coords: [ data.pageX, data.pageY ]
  942. };
  943. // prevent scrolling
  944. if ( Math.abs( start.coords[0] - stop.coords[0] ) > 10 ) {
  945. event.preventDefault();
  946. }
  947. }
  948. $this
  949. .bind( touchMoveEvent, moveHandler )
  950. .one( touchStopEvent, function( event ) {
  951. $this.unbind( touchMoveEvent, moveHandler );
  952. if ( start && stop ) {
  953. if ( stop.time - start.time < 1000 &&
  954. Math.abs( start.coords[0] - stop.coords[0]) > 30 &&
  955. Math.abs( start.coords[1] - stop.coords[1]) < 75 ) {
  956. start.origin
  957. .trigger( "swipe" )
  958. .trigger( start.coords[0] > stop.coords[0] ? "swipeleft" : "swiperight" );
  959. }
  960. }
  961. start = stop = undefined;
  962. });
  963. });
  964. }
  965. };
  966. (function($){
  967. // "Cowboy" Ben Alman
  968. var win = $(window),
  969. special_event,
  970. get_orientation,
  971. last_orientation;
  972. $.event.special.orientationchange = special_event = {
  973. setup: function(){
  974. // If the event is supported natively, return false so that jQuery
  975. // will bind to the event using DOM methods.
  976. if ( $.support.orientation ) { return false; }
  977. // Get the current orientation to avoid initial double-triggering.
  978. last_orientation = get_orientation();
  979. // Because the orientationchange event doesn't exist, simulate the
  980. // event by testing window dimensions on resize.
  981. win.bind( "throttledresize", handler );
  982. },
  983. teardown: function(){
  984. // If the event is not supported natively, return false so that
  985. // jQuery will unbind the event using DOM methods.
  986. if ( $.support.orientation ) { return false; }
  987. // Because the orientationchange event doesn't exist, unbind the
  988. // resize event handler.
  989. win.unbind( "throttledresize", handler );
  990. },
  991. add: function( handleObj ) {
  992. // Save a reference to the bound event handler.
  993. var old_handler = handleObj.handler;
  994. handleObj.handler = function( event ) {
  995. // Modify event object, adding the .orientation property.
  996. event.orientation = get_orientation();
  997. // Call the originally-bound event handler and return its result.
  998. return old_handler.apply( this, arguments );
  999. };
  1000. }
  1001. };
  1002. // If the event is not supported natively, this handler will be bound to
  1003. // the window resize event to simulate the orientationchange event.
  1004. function handler() {
  1005. // Get the current orientation.
  1006. var orientation = get_orientation();
  1007. if ( orientation !== last_orientation ) {
  1008. // The orientation has changed, so trigger the orientationchange event.
  1009. last_orientation = orientation;
  1010. win.trigger( "orientationchange" );
  1011. }
  1012. };
  1013. // Get the current page orientation. This method is exposed publicly, should it
  1014. // be needed, as jQuery.event.special.orientationchange.orientation()
  1015. $.event.special.orientationchange.orientation = get_orientation = function() {
  1016. var elem = document.documentElement;
  1017. return elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" : "landscape";
  1018. };
  1019. })(jQuery);
  1020. // throttled resize event
  1021. (function(){
  1022. $.event.special.throttledresize = {
  1023. setup: function() {
  1024. $( this ).bind( "resize", handler );
  1025. },
  1026. teardown: function(){
  1027. $( this ).unbind( "resize", handler );
  1028. }
  1029. };
  1030. var throttle = 250,
  1031. handler = function(){
  1032. curr = ( new Date() ).getTime();
  1033. diff = curr - lastCall;
  1034. if( diff >= throttle ){
  1035. lastCall = curr;
  1036. $( this ).trigger( "throttledresize" );
  1037. }
  1038. else{
  1039. if( heldCall ){
  1040. clearTimeout( heldCall );
  1041. }
  1042. //promise a held call will still execute
  1043. heldCall = setTimeout( handler, throttle - diff );
  1044. }
  1045. },
  1046. lastCall = 0,
  1047. heldCall,
  1048. curr,
  1049. diff;
  1050. })();
  1051. $.each({
  1052. scrollstop: "scrollstart",
  1053. taphold: "tap",
  1054. swipeleft: "swipe",
  1055. swiperight: "swipe"
  1056. }, function( event, sourceEvent ) {
  1057. $.event.special[ event ] = {
  1058. setup: function() {
  1059. $( this ).bind( sourceEvent, $.noop );
  1060. }
  1061. };
  1062. });
  1063. })( jQuery );
  1064. /*!
  1065. * jQuery hashchange event - v1.3 - 7/21/2010
  1066. * http://benalman.com/projects/jquery-hashchange-plugin/
  1067. *
  1068. * Copyright (c) 2010 "Cowboy" Ben Alman
  1069. * Dual licensed under the MIT and GPL licenses.
  1070. * http://benalman.com/about/license/
  1071. */
  1072. // Script: jQuery hashchange event
  1073. //
  1074. // *Version: 1.3, Last updated: 7/21/2010*
  1075. //
  1076. // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
  1077. // GitHub - http://github.com/cowboy/jquery-hashchange/
  1078. // Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js
  1079. // (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped)
  1080. //
  1081. // About: License
  1082. //
  1083. // Copyright (c) 2010 "Cowboy" Ben Alman,
  1084. // Dual licensed under the MIT and GPL licenses.
  1085. // http://benalman.com/about/license/
  1086. //
  1087. // About: Examples
  1088. //
  1089. // These working examples, complete with fully commented code, illustrate a few
  1090. // ways in which this plugin can be used.
  1091. //
  1092. // hashchange event - http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/
  1093. // document.domain - http://benalman.com/code/projects/jquery-hashchange/examples/document_domain/
  1094. //
  1095. // About: Support and Testing
  1096. //
  1097. // Information about what version or versions of jQuery this plugin has been
  1098. // tested with, what browsers it has been tested in, and where the unit tests
  1099. // reside (so you can test it yourself).
  1100. //
  1101. // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2
  1102. // Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Chrome 5-6, Safari 3.2-5,
  1103. // Opera 9.6-10.60, iPhone 3.1, Android 1.6-2.2, BlackBerry 4.6-5.
  1104. // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
  1105. //
  1106. // About: Known issues
  1107. //
  1108. // While this jQuery hashchange event implementation is quite stable and
  1109. // robust, there are a few unfortunate browser bugs surrounding expected
  1110. // hashchange event-based behaviors, independent of any JavaScript
  1111. // window.onhashchange abstraction. See the following examples for more
  1112. // information:
  1113. //
  1114. // Chrome: Back Button - http://benalman.com/code/projects/jquery-hashchange/examples/bug-chrome-back-button/
  1115. // Firefox: Remote XMLHttpRequest - http://benalman.com/code/projects/jquery-hashchange/examples/bug-firefox-remote-xhr/
  1116. // WebKit: Back Button in an Iframe - http://benalman.com/code/projects/jquery-hashchange/examples/bug-webkit-hash-iframe/
  1117. // Safari: Back Button from a different domain - http://benalman.com/code/projects/jquery-hashchange/examples/bug-safari-back-from-diff-domain/
  1118. //
  1119. // Also note that should a browser natively support the window.onhashchange
  1120. // event, but not report that it does, the fallback polling loop will be used.
  1121. //
  1122. // About: Release History
  1123. //
  1124. // 1.3 - (7/21/2010) Reorganized IE6/7 Iframe code to make it more
  1125. // "removable" for mobile-only development. Added IE6/7 document.title
  1126. // support. Attempted to make Iframe as hidden as possible by using
  1127. // techniques from http://www.paciellogroup.com/blog/?p=604. Added
  1128. // support for the "shortcut" format $(window).hashchange( fn ) and
  1129. // $(window).hashchange() like jQuery provides for built-in events.
  1130. // Renamed jQuery.hashchangeDelay to <jQuery.fn.hashchange.delay> and
  1131. // lowered its default value to 50. Added <jQuery.fn.hashchange.domain>
  1132. // and <jQuery.fn.hashchange.src> properties plus document-domain.html
  1133. // file to address access denied issues when setting document.domain in
  1134. // IE6/7.
  1135. // 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin
  1136. // from a page on another domain would cause an error in Safari 4. Also,
  1137. // IE6/7 Iframe is now inserted after the body (this actually works),
  1138. // which prevents the page from scrolling when the event is first bound.
  1139. // Event can also now be bound before DOM ready, but it won't be usable
  1140. // before then in IE6/7.
  1141. // 1.1 - (1/21/2010) Incorporated document.documentMode test to fix IE8 bug
  1142. // where browser version is incorrectly reported as 8.0, despite
  1143. // inclusion of the X-UA-Compatible IE=EmulateIE7 meta tag.
  1144. // 1.0 - (1/9/2010) Initial Release. Broke out the jQuery BBQ event.special
  1145. // window.onhashchange functionality into a separate plugin for users
  1146. // who want just the basic event & back button support, without all the
  1147. // extra awesomeness that BBQ provides. This plugin will be included as
  1148. // part of jQuery BBQ, but also be available separately.
  1149. (function($,window,undefined){
  1150. '$:nomunge'; // Used by YUI compressor.
  1151. // Reused string.
  1152. var str_hashchange = 'hashchange',
  1153. // Method / object references.
  1154. doc = document,
  1155. fake_onhashchange,
  1156. special = $.event.special,
  1157. // Does the browser support window.onhashchange? Note that IE8 running in
  1158. // IE7 compatibility mode reports true for 'onhashchange' in window, even
  1159. // though the event isn't supported, so also test document.documentMode.
  1160. doc_mode = doc.documentMode,
  1161. supports_onhashchange = 'on' + str_hashchange in window && ( doc_mode === undefined || doc_mode > 7 );
  1162. // Get location.hash (or what you'd expect location.hash to be) sans any
  1163. // leading #. Thanks for making this necessary, Firefox!
  1164. function get_fragment( url ) {
  1165. url = url || location.href;
  1166. return '#' + url.replace( /^[^#]*#?(.*)$/, '$1' );
  1167. };
  1168. // Method: jQuery.fn.hashchange
  1169. //
  1170. // Bind a handler to the window.onhashchange event or trigger all bound
  1171. // window.onhashchange event handlers. This behavior is consistent with
  1172. // jQuery's built-in event handlers.
  1173. //
  1174. // Usage:
  1175. //
  1176. // > jQuery(window).hashchange( [ handler ] );
  1177. //
  1178. // Arguments:
  1179. //
  1180. // handler - (Function) Optional handler to be bound to the hashchange
  1181. // event. This is a "shortcut" for the more verbose form:
  1182. // jQuery(window).bind( 'hashchange', handler ). If handler is omitted,
  1183. // all bound window.onhashchange event handlers will be triggered. This
  1184. // is a shortcut for the more verbose
  1185. // jQuery(window).trigger( 'hashchange' ). These forms are described in
  1186. // the <hashchange event> section.
  1187. //
  1188. // Returns:
  1189. //
  1190. // (jQuery) The initial jQuery collection of elements.
  1191. // Allow the "shortcut" format $(elem).hashchange( fn ) for binding and
  1192. // $(elem).hashchange() for triggering, like jQuery does for built-in events.
  1193. $.fn[ str_hashchange ] = function( fn ) {
  1194. return fn ? this.bind( str_hashchange, fn ) : this.trigger( str_hashchange );
  1195. };
  1196. // Property: jQuery.fn.hashchange.delay
  1197. //
  1198. // The numeric interval (in milliseconds) at which the <hashchange event>
  1199. // polling loop executes. Defaults to 50.
  1200. // Property: jQuery.fn.hashchange.domain
  1201. //
  1202. // If you're setting document.domain in your JavaScript, and you want hash
  1203. // history to work in IE6/7, not only must this property be set, but you must
  1204. // also set document.domain BEFORE jQuery is loaded into the page. This
  1205. // property is only applicable if you are supporting IE6/7 (or IE8 operating
  1206. // in "IE7 compatibility" mode).
  1207. //
  1208. // In addition, the <jQuery.fn.hashchange.src> property must be set to the
  1209. // path of the included "document-domain.html" file, which can be renamed or
  1210. // modified if necessary (note that the document.domain specified must be the
  1211. // same in both your main JavaScript as well as in this file).
  1212. //
  1213. // Usage:
  1214. //
  1215. // jQuery.fn.hashchange.domain = document.domain;
  1216. // Property: jQuery.fn.hashchange.src
  1217. //
  1218. // If, for some reason, you need to specify an Iframe src file (for example,
  1219. // when setting document.domain as in <jQuery.fn.hashchange.domain>), you can
  1220. // do so using this property. Note that when using this property, history
  1221. // won't be recorded in IE6/7 until the Iframe src file loads. This property
  1222. // is only applicable if you are supporting IE6/7 (or IE8 operating in "IE7
  1223. // compatibility" mode).
  1224. //
  1225. // Usage:
  1226. //
  1227. // jQuery.fn.hashchange.src = 'path/to/file.html';
  1228. $.fn[ str_hashchange ].delay = 50;
  1229. /*
  1230. $.fn[ str_hashchange ].domain = null;
  1231. $.fn[ str_hashchange ].src = null;
  1232. */
  1233. // Event: hashchange event
  1234. //
  1235. // Fired when location.hash changes. In browsers that support it, the native
  1236. // HTML5 window.onhashchange event is used, otherwise a polling loop is
  1237. // initialized, running every <jQuery.fn.hashchange.delay> milliseconds to
  1238. // see if the hash has changed. In IE6/7 (and IE8 operating in "IE7
  1239. // compatibility" mode), a hidden Iframe is created to allow the back button
  1240. // and hash-based history to work.
  1241. //
  1242. // Usage as described in <jQuery.fn.hashchange>:
  1243. //
  1244. // > // Bind an event handler.
  1245. // > jQuery(window).hashchange( function(e) {
  1246. // > var hash = location.hash;
  1247. // > ...
  1248. // > });
  1249. // >
  1250. // > // Manually trigger the event handler.
  1251. // > jQuery(window).hashchange();
  1252. //
  1253. // A more verbose usage that allows for event namespacing:
  1254. //
  1255. // > // Bind an event handler.
  1256. // > jQuery(window).bind( 'hashchange', function(e) {
  1257. // > var hash = location.hash;
  1258. // > ...
  1259. // > });
  1260. // >
  1261. // > // Manually trigger the event handler.
  1262. // > jQuery(window).trigger( 'hashchange' );
  1263. //
  1264. // Additional Notes:
  1265. //
  1266. // * The polling loop and Iframe are not created until at least one handler
  1267. // is actually bound to the 'hashchange' event.
  1268. // * If you need the bound handler(s) to execute immediately, in cases where
  1269. // a location.hash exists on page load, via bookmark or page refresh for
  1270. // example, use jQuery(window).hashchange() or the more verbose
  1271. // jQuery(window).trigger( 'hashchange' ).
  1272. // * The event can be bound before DOM ready, but since it won't be usable
  1273. // before then in IE6/7 (due to the necessary Iframe), recommended usage is
  1274. // to bind it inside a DOM ready handler.
  1275. // Override existing $.event.special.hashchange methods (allowing this plugin
  1276. // to be defined after jQuery BBQ in BBQ's source code).
  1277. special[ str_hashchange ] = $.extend( special[ str_hashchange ], {
  1278. // Called only when the first 'hashchange' event is bound to window.
  1279. setup: function() {
  1280. // If window.onhashchange is supported natively, there's nothing to do..
  1281. if ( supports_onhashchange ) { return false; }
  1282. // Otherwise, we need to create our own. And we don't want to call this
  1283. // until the user binds to the event, just in case they never do, since it
  1284. // will create a polling loop and possibly even a hidden Iframe.
  1285. $( fake_onhashchange.start );
  1286. },
  1287. // Called only when the last 'hashchange' event is unbound from window.
  1288. teardown: function() {
  1289. // If window.onhashchange is supported natively, there's nothing to do..
  1290. if ( supports_onhashchange ) { return false; }
  1291. // Otherwise, we need to stop ours (if possible).
  1292. $( fake_onhashchange.stop );
  1293. }
  1294. });
  1295. // fake_onhashchange does all the work of triggering the window.onhashchange
  1296. // event for browsers that don't natively support it, including creating a
  1297. // polling loop to watch for hash changes and in IE 6/7 creating a hidden
  1298. // Iframe to enable back and forward.
  1299. fake_onhashchange = (function(){
  1300. var self = {},
  1301. timeout_id,
  1302. // Remember the initial hash so it doesn't get triggered immediately.
  1303. last_hash = get_fragment(),
  1304. fn_retval = function(val){ return val; },
  1305. history_set = fn_retval,
  1306. history_get = fn_retval;
  1307. // Start the polling loop.
  1308. self.start = function() {
  1309. timeout_id || poll();
  1310. };
  1311. // Stop the polling loop.
  1312. self.stop = function() {
  1313. timeout_id && clearTimeout( timeout_id );
  1314. timeout_id = undefined;
  1315. };
  1316. // This polling loop checks every $.fn.hashchange.delay milliseconds to see
  1317. // if location.hash has changed, and triggers the 'hashchange' event on
  1318. // window when necessary.
  1319. function poll() {
  1320. var hash = get_fragment(),
  1321. history_hash = history_get( last_hash );
  1322. if ( hash !== last_hash ) {
  1323. history_set( last_hash = hash, history_hash );
  1324. $(window).trigger( str_hashchange );
  1325. } else if ( history_hash !== last_hash ) {
  1326. location.href = location.href.replace( /#.*/, '' ) + history_hash;
  1327. }
  1328. timeout_id = setTimeout( poll, $.fn[ str_hashchange ].delay );
  1329. };
  1330. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  1331. // vvvvvvvvvvvvvvvvvvv REMOVE IF NOT SUPPORTING IE6/7/8 vvvvvvvvvvvvvvvvvvv
  1332. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  1333. $.browser.msie && !supports_onhashchange && (function(){
  1334. // Not only do IE6/7 need the "magical" Iframe treatment, but so does IE8
  1335. // when running in "IE7 compatibility" mode.
  1336. var iframe,
  1337. iframe_src;
  1338. // When the event is bound and polling starts in IE 6/7, create a hidden
  1339. // Iframe for history handling.
  1340. self.start = function(){
  1341. if ( !iframe ) {
  1342. iframe_src = $.fn[ str_hashchange ].src;
  1343. iframe_src = iframe_src && iframe_src + get_fragment();
  1344. // Create hidden Iframe. Attempt to make Iframe as hidden as possible
  1345. // by using techniques from http://www.paciellogroup.com/blog/?p=604.
  1346. iframe = $('<iframe tabindex="-1" title="empty"/>').hide()
  1347. // When Iframe has completely loaded, initialize the history and
  1348. // start polling.
  1349. .one( 'load', function(){
  1350. iframe_src || history_set( get_fragment() );
  1351. poll();
  1352. })
  1353. // Load Iframe src if specified, otherwise nothing.
  1354. .attr( 'src', iframe_src || 'javascript:0' )
  1355. // Append Iframe after the end of the body to prevent unnecessary
  1356. // initial page scrolling (yes, this works).
  1357. .insertAfter( 'body' )[0].contentWindow;
  1358. // Whenever `document.title` changes, update the Iframe's title to
  1359. // prettify the back/next history menu entries. Since IE sometimes
  1360. // errors with "Unspecified error" the very first time this is set
  1361. // (yes, very useful) wrap this with a try/catch block.
  1362. doc.onpropertychange = function(){
  1363. try {
  1364. if ( event.propertyName === 'title' ) {
  1365. iframe.document.title = doc.title;
  1366. }
  1367. } catch(e) {}
  1368. };
  1369. }
  1370. };
  1371. // Override the "stop" method since an IE6/7 Iframe was created. Even
  1372. // if there are no longer any bound event handlers, the polling loop
  1373. // is still necessary for back/next to work at all!
  1374. self.stop = fn_retval;
  1375. // Get history by looking at the hidden Iframe's location.hash.
  1376. history_get = function() {
  1377. return get_fragment( iframe.location.href );
  1378. };
  1379. // Set a new history item by opening and then closing the Iframe
  1380. // document, *then* setting its location.hash. If document.domain has
  1381. // been set, update that as well.
  1382. history_set = function( hash, history_hash ) {
  1383. var iframe_doc = iframe.document,
  1384. domain = $.fn[ str_hashchange ].domain;
  1385. if ( hash !== history_hash ) {
  1386. // Update Iframe with any initial `document.title` that might be set.
  1387. iframe_doc.title = doc.title;
  1388. // Opening the Iframe's document after it has been closed is what
  1389. // actually adds a history entry.
  1390. iframe_doc.open();
  1391. // Set document.domain for the Iframe document as well, if necessary.
  1392. domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
  1393. iframe_doc.close();
  1394. // Update the Iframe's hash, for great justice.
  1395. iframe.location.hash = hash;
  1396. }
  1397. };
  1398. })();
  1399. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1400. // ^^^^^^^^^^^^^^^^^^^ REMOVE IF NOT SUPPORTING IE6/7/8 ^^^^^^^^^^^^^^^^^^^
  1401. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1402. return self;
  1403. })();
  1404. })(jQuery,this);
  1405. /*
  1406. * jQuery Mobile Framework : "page" plugin
  1407. * Copyright (c) jQuery Project
  1408. * Dual licensed under the MIT or GPL Version 2 licenses.
  1409. * http://jquery.org/license
  1410. */
  1411. (function($, undefined ) {
  1412. $.widget( "mobile.page", $.mobile.widget, {
  1413. options: {
  1414. backBtnText: "Back",
  1415. addBackBtn: false,
  1416. backBtnTheme: null,
  1417. degradeInputs: {
  1418. color: false,
  1419. date: false,
  1420. datetime: false,
  1421. "datetime-local": false,
  1422. email: false,
  1423. month: false,
  1424. number: false,
  1425. range: "number",
  1426. search: true,
  1427. tel: false,
  1428. time: false,
  1429. url: false,
  1430. week: false
  1431. },
  1432. keepNative: null
  1433. },
  1434. _create: function() {
  1435. var $elem = this.element,
  1436. o = this.options;
  1437. this.keepNative = ":jqmData(role='none'), :jqmData(role='nojs')" + (o.keepNative ? ", " + o.keepNative : "");
  1438. if ( this._trigger( "beforeCreate" ) === false ) {
  1439. return;
  1440. }
  1441. //some of the form elements currently rely on the presence of ui-page and ui-content
  1442. // classes so we'll handle page and content roles outside of the main role processing
  1443. // loop below.
  1444. $elem.find( ":jqmData(role='page'), :jqmData(role='content')" ).andSelf().each(function() {
  1445. $(this).addClass( "ui-" + $(this).jqmData( "role" ) );
  1446. });
  1447. $elem.find( ":jqmData(role='nojs')" ).addClass( "ui-nojs" );
  1448. // pre-find data els
  1449. var $dataEls = $elem.find( ":jqmData(role)" ).andSelf().each(function() {
  1450. var $this = $( this ),
  1451. role = $this.jqmData( "role" ),
  1452. theme = $this.jqmData( "theme" );
  1453. //apply theming and markup modifications to page,header,content,footer
  1454. if ( role === "header" || role === "footer" ) {
  1455. $this.addClass( "ui-bar-" + (theme || $this.parent( ":jqmData(role='page')" ).jqmData( "theme" ) || "a") );
  1456. // add ARIA role
  1457. $this.attr( "role", role === "header" ? "banner" : "contentinfo" );
  1458. //right,left buttons
  1459. var $headeranchors = $this.children( "a" ),
  1460. leftbtn = $headeranchors.hasClass( "ui-btn-left" ),
  1461. rightbtn = $headeranchors.hasClass( "ui-btn-right" );
  1462. if ( !leftbtn ) {
  1463. leftbtn = $headeranchors.eq( 0 ).not( ".ui-btn-right" ).addClass( "ui-btn-left" ).length;
  1464. }
  1465. if ( !rightbtn ) {
  1466. rightbtn = $headeranchors.eq( 1 ).addClass( "ui-btn-right" ).length;
  1467. }
  1468. // auto-add back btn on pages beyond first view
  1469. if ( o.addBackBtn && role === "header" &&
  1470. $( ".ui-page" ).length > 1 &&
  1471. $elem.jqmData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
  1472. !leftbtn && $this.jqmData( "backbtn" ) !== false ) {
  1473. var backBtn = $( "<a href='#' class='ui-btn-left' data-"+ $.mobile.ns +"rel='back' data-"+ $.mobile.ns +"icon='arrow-l'>"+ o.backBtnText +"</a>" ).prependTo( $this );
  1474. //if theme is provided, override default inheritance
  1475. if( o.backBtnTheme ){
  1476. backBtn.attr( "data-"+ $.mobile.ns +"theme", o.backBtnTheme );
  1477. }
  1478. }
  1479. //page title
  1480. $this.children( "h1, h2, h3, h4, h5, h6" )
  1481. .addClass( "ui-title" )
  1482. //regardless of h element number in src, it becomes h1 for the enhanced page
  1483. .attr({ "tabindex": "0", "role": "heading", "aria-level": "1" });
  1484. } else if ( role === "content" ) {
  1485. if ( theme ) {
  1486. $this.addClass( "ui-body-" + theme );
  1487. }
  1488. // add ARIA role
  1489. $this.attr( "role", "main" );
  1490. } else if ( role === "page" ) {
  1491. $this.addClass( "ui-body-" + (theme || "c") );
  1492. }
  1493. switch(role) {
  1494. case "header":
  1495. case "footer":
  1496. case "page":
  1497. case "content":
  1498. $this.addClass( "ui-" + role );
  1499. break;
  1500. case "collapsible":
  1501. case "fieldcontain":
  1502. case "navbar":
  1503. case "listview":
  1504. case "dialog":
  1505. $this[ role ]();
  1506. break;
  1507. }
  1508. });
  1509. //enhance form controls
  1510. this._enhanceControls();
  1511. //links in bars, or those with data-role become buttons
  1512. $elem.find( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a" )
  1513. .not( ".ui-btn" )
  1514. .not(this.keepNative)
  1515. .buttonMarkup();
  1516. $elem
  1517. .find(":jqmData(role='controlgroup')")
  1518. .controlgroup();
  1519. //links within content areas
  1520. $elem.find( "a:not(.ui-btn):not(.ui-link-inherit)" )
  1521. .not(this.keepNative)
  1522. .addClass( "ui-link" );
  1523. //fix toolbars
  1524. $elem.fixHeaderFooter();
  1525. },
  1526. _typeAttributeRegex: /\s+type=["']?\w+['"]?/,
  1527. _enhanceControls: function() {
  1528. var o = this.options, self = this;
  1529. // degrade inputs to avoid poorly implemented native functionality
  1530. this.element.find( "input" ).not(this.keepNative).each(function() {
  1531. var type = this.getAttribute( "type" ),
  1532. optType = o.degradeInputs[ type ] || "text";
  1533. if ( o.degradeInputs[ type ] ) {
  1534. $( this ).replaceWith(
  1535. $( "<div>" ).html( $(this).clone() ).html()
  1536. .replace( self._typeAttributeRegex, " type=\""+ optType +"\" data-" + $.mobile.ns + "type=\""+type+"\" " ) );
  1537. }
  1538. });
  1539. // We re-find form elements since the degredation code above
  1540. // may have injected new elements. We cache the non-native control
  1541. // query to reduce the number of times we search through the entire page.
  1542. var allControls = this.element.find("input, textarea, select, button"),
  1543. nonNativeControls = allControls.not(this.keepNative);
  1544. // XXX: Temporary workaround for issue 785. Turn off autocorrect and
  1545. // autocomplete since the popup they use can't be dismissed by
  1546. // the user. Note that we test for the presence of the feature
  1547. // by looking for the autocorrect property on the input element.
  1548. var textInputs = allControls.filter( "input[type=text]" );
  1549. if (textInputs.length && typeof textInputs[0].autocorrect !== "undefined") {
  1550. textInputs.each(function(){
  1551. // Set the attribute instead of the property just in case there
  1552. // is code that attempts to make modifications via HTML.
  1553. this.setAttribute("autocorrect", "off");
  1554. this.setAttribute("autocomplete", "off");
  1555. });
  1556. }
  1557. // enchance form controls
  1558. nonNativeControls
  1559. .filter( "[type='radio'], [type='checkbox']" )
  1560. .checkboxradio();
  1561. nonNativeControls
  1562. .filter( "button, [type='button'], [type='submit'], [type='reset'], [type='image']" )
  1563. .button();
  1564. nonNativeControls
  1565. .filter( "input, textarea" )
  1566. .not( "[type='radio'], [type='checkbox'], [type='button'], [type='submit'], [type='reset'], [type='image'], [type='hidden']" )
  1567. .textinput();
  1568. nonNativeControls
  1569. .filter( "input, select" )
  1570. .filter( ":jqmData(role='slider'), :jqmData(type='range')" )
  1571. .slider();
  1572. nonNativeControls
  1573. .filter( "select:not(:jqmData(role='slider'))" )
  1574. .selectmenu();
  1575. }
  1576. });
  1577. })( jQuery );
  1578. /*!
  1579. * jQuery Mobile v@VERSION
  1580. * http://jquerymobile.com/
  1581. *
  1582. * Copyright 2010, jQuery Project
  1583. * Dual licensed under the MIT or GPL Version 2 licenses.
  1584. * http://jquery.org/license
  1585. */
  1586. (function( $, window, undefined ) {
  1587. //jQuery.mobile configurable options
  1588. $.extend( $.mobile, {
  1589. //namespace used framework-wide for data-attrs. Default is no namespace
  1590. ns: "",
  1591. //define the url parameter used for referencing widget-generated sub-pages.
  1592. //Translates to to example.html&ui-page=subpageIdentifier
  1593. //hash segment before &ui-page= is used to make Ajax request
  1594. subPageUrlKey: "ui-page",
  1595. //anchor links with a data-rel, or pages with a data-role, that match these selectors will be untrackable in history
  1596. //(no change in URL, not bookmarkable)
  1597. nonHistorySelectors: "dialog",
  1598. //class assigned to page currently in view, and during transitions
  1599. activePageClass: "ui-page-active",
  1600. //class used for "active" button state, from CSS framework
  1601. activeBtnClass: "ui-btn-active",
  1602. //automatically handle clicks and form submissions through Ajax, when same-domain
  1603. ajaxEnabled: true,
  1604. //When enabled, clicks and taps that result in Ajax page changes will happen slightly sooner on touch devices.
  1605. //Also, it will prevent the address bar from appearing on platforms like iOS during page transitions.
  1606. //This option has no effect on non-touch devices, but enabling it may interfere with jQuery plugins that bind to click events
  1607. useFastClick: true,
  1608. //automatically load and show pages based on location.hash
  1609. hashListeningEnabled: true,
  1610. //set default page transition - 'none' for no transitions
  1611. defaultPageTransition: "slide",
  1612. //minimum scroll distance that will be remembered when returning to a page
  1613. minScrollBack: screen.height / 2,
  1614. //set default dialog transition - 'none' for no transitions
  1615. defaultDialogTransition: "pop",
  1616. //show loading message during Ajax requests
  1617. //if false, message will not appear, but loading classes will still be toggled on html el
  1618. loadingMessage: "loading",
  1619. //error response message - appears when an Ajax page request fails
  1620. pageLoadErrorMessage: "Error Loading Page",
  1621. //support conditions that must be met in order to proceed
  1622. //default enhanced qualifications are media query support OR IE 7+
  1623. gradeA: function(){
  1624. return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
  1625. },
  1626. //TODO might be useful upstream in jquery itself ?
  1627. keyCode: {
  1628. ALT: 18,
  1629. BACKSPACE: 8,
  1630. CAPS_LOCK: 20,
  1631. COMMA: 188,
  1632. COMMAND: 91,
  1633. COMMAND_LEFT: 91, // COMMAND
  1634. COMMAND_RIGHT: 93,
  1635. CONTROL: 17,
  1636. DELETE: 46,
  1637. DOWN: 40,
  1638. END: 35,
  1639. ENTER: 13,
  1640. ESCAPE: 27,
  1641. HOME: 36,
  1642. INSERT: 45,
  1643. LEFT: 37,
  1644. MENU: 93, // COMMAND_RIGHT
  1645. NUMPAD_ADD: 107,
  1646. NUMPAD_DECIMAL: 110,
  1647. NUMPAD_DIVIDE: 111,
  1648. NUMPAD_ENTER: 108,
  1649. NUMPAD_MULTIPLY: 106,
  1650. NUMPAD_SUBTRACT: 109,
  1651. PAGE_DOWN: 34,
  1652. PAGE_UP: 33,
  1653. PERIOD: 190,
  1654. RIGHT: 39,
  1655. SHIFT: 16,
  1656. SPACE: 32,
  1657. TAB: 9,
  1658. UP: 38,
  1659. WINDOWS: 91 // COMMAND
  1660. },
  1661. //scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
  1662. silentScroll: function( ypos ) {
  1663. if( $.type( ypos ) !== "number" ){
  1664. ypos = $.mobile.defaultHomeScroll;
  1665. }
  1666. // prevent scrollstart and scrollstop events
  1667. $.event.special.scrollstart.enabled = false;
  1668. setTimeout(function() {
  1669. window.scrollTo( 0, ypos );
  1670. $(document).trigger( "silentscroll", { x: 0, y: ypos });
  1671. },20);
  1672. setTimeout(function() {
  1673. $.event.special.scrollstart.enabled = true;
  1674. }, 150 );
  1675. },
  1676. // compile the namespace normalization regex once
  1677. normalizeRegex: /-([a-z])/g,
  1678. // take a data attribute property, prepend the namespace
  1679. // and then camel case the attribute string
  1680. nsNormalize: function(prop){
  1681. if(!prop) return;
  1682. return $.camelCase( $.mobile.ns + prop );
  1683. }
  1684. });
  1685. //mobile version of data and removeData and hasData methods
  1686. //ensures all data is set and retrieved using jQuery Mobile's data namespace
  1687. $.fn.jqmData = function( prop, value ){
  1688. return this.data( prop ? $.mobile.nsNormalize(prop) : prop, value );
  1689. };
  1690. $.jqmData = function( elem, prop, value ){
  1691. return $.data( elem, $.mobile.nsNormalize(prop), value );
  1692. };
  1693. $.fn.jqmRemoveData = function( prop ){
  1694. return this.removeData( $.mobile.nsNormalize(prop) );
  1695. };
  1696. $.jqmRemoveData = function( elem, prop ){
  1697. return $.removeData( elem, $.mobile.nsNormalize(prop) );
  1698. };
  1699. $.jqmHasData = function( elem, prop ){
  1700. return $.hasData( elem, $.mobile.nsNormalize(prop) );
  1701. };
  1702. // Monkey-patching Sizzle to filter the :jqmData selector
  1703. var oldFind = $.find;
  1704. $.find = function( selector, context, ret, extra ) {
  1705. selector = selector.replace(/:jqmData\(([^)]*)\)/g, "[data-" + ($.mobile.ns || "") + "$1]");
  1706. return oldFind.call( this, selector, context, ret, extra );
  1707. };
  1708. $.extend( $.find, oldFind );
  1709. $.find.matches = function( expr, set ) {
  1710. return $.find( expr, null, null, set );
  1711. };
  1712. $.find.matchesSelector = function( node, expr ) {
  1713. return $.find( expr, null, null, [node] ).length > 0;
  1714. };
  1715. })( jQuery, this );
  1716. /*
  1717. * jQuery Mobile Framework : core utilities for auto ajax navigation, base tag mgmt,
  1718. * Copyright (c) jQuery Project
  1719. * Dual licensed under the MIT or GPL Version 2 licenses.
  1720. * http://jquery.org/license
  1721. */
  1722. ( function( $, undefined ) {
  1723. //define vars for interal use
  1724. var $window = $( window ),
  1725. $html = $( 'html' ),
  1726. $head = $( 'head' ),
  1727. //url path helpers for use in relative url management
  1728. path = {
  1729. // This scary looking regular expression parses an absolute URL or its relative
  1730. // variants (protocol, site, document, query, and hash), into the various
  1731. // components (protocol, host, path, query, fragment, etc that make up the
  1732. // URL as well as some other commonly used sub-parts. When used with RegExp.exec()
  1733. // or String.match, it parses the URL into a results array that looks like this:
  1734. //
  1735. // [0]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
  1736. // [1]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
  1737. // [2]: http://jblas:password@mycompany.com:8080/mail/inbox
  1738. // [3]: http://jblas:password@mycompany.com:8080
  1739. // [4]: http:
  1740. // [5]: jblas:password@mycompany.com:8080
  1741. // [6]: jblas:password
  1742. // [7]: jblas
  1743. // [8]: password
  1744. // [9]: mycompany.com:8080
  1745. // [10]: mycompany.com
  1746. // [11]: 8080
  1747. // [12]: /mail/inbox
  1748. // [13]: /mail/
  1749. // [14]: inbox
  1750. // [15]: ?msg=1234&type=unread
  1751. // [16]: #msg-content
  1752. //
  1753. urlParseRE: /^(((([^:\/#\?]+:)?(?:\/\/((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?]+)(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
  1754. //Parse a URL into a structure that allows easy access to
  1755. //all of the URL components by name.
  1756. parseUrl: function( url ) {
  1757. // If we're passed an object, we'll assume that it is
  1758. // a parsed url object and just return it back to the caller.
  1759. if ( typeof url === "object" ) {
  1760. return url;
  1761. }
  1762. var u = url || "",
  1763. matches = path.urlParseRE.exec( url ),
  1764. results;
  1765. if ( matches ) {
  1766. // Create an object that allows the caller to access the sub-matches
  1767. // by name. Note that IE returns an empty string instead of undefined,
  1768. // like all other browsers do, so we normalize everything so its consistent
  1769. // no matter what browser we're running on.
  1770. results = {
  1771. href: matches[0] || "",
  1772. hrefNoHash: matches[1] || "",
  1773. hrefNoSearch: matches[2] || "",
  1774. domain: matches[3] || "",
  1775. protocol: matches[4] || "",
  1776. authority: matches[5] || "",
  1777. username: matches[7] || "",
  1778. password: matches[8] || "",
  1779. host: matches[9] || "",
  1780. hostname: matches[10] || "",
  1781. port: matches[11] || "",
  1782. pathname: matches[12] || "",
  1783. directory: matches[13] || "",
  1784. filename: matches[14] || "",
  1785. search: matches[15] || "",
  1786. hash: matches[16] || ""
  1787. };
  1788. }
  1789. return results || {};
  1790. },
  1791. //Turn relPath into an asbolute path. absPath is
  1792. //an optional absolute path which describes what
  1793. //relPath is relative to.
  1794. makePathAbsolute: function( relPath, absPath ) {
  1795. if ( relPath && relPath.charAt( 0 ) === "/" ) {
  1796. return relPath;
  1797. }
  1798. relPath = relPath || "";
  1799. absPath = absPath ? absPath.replace( /^\/|\/?[^\/]*$/g, "" ) : "";
  1800. var absStack = absPath ? absPath.split( "/" ) : [],
  1801. relStack = relPath.split( "/" );
  1802. for ( var i = 0; i < relStack.length; i++ ) {
  1803. var d = relStack[ i ];
  1804. switch ( d ) {
  1805. case ".":
  1806. break;
  1807. case "..":
  1808. if ( absStack.length ) {
  1809. absStack.pop();
  1810. }
  1811. break;
  1812. default:
  1813. absStack.push( d );
  1814. break;
  1815. }
  1816. }
  1817. return "/" + absStack.join( "/" );
  1818. },
  1819. //Returns true if both urls have the same domain.
  1820. isSameDomain: function( absUrl1, absUrl2 ) {
  1821. return path.parseUrl( absUrl1 ).domain === path.parseUrl( absUrl2 ).domain;
  1822. },
  1823. //Returns true for any relative variant.
  1824. isRelativeUrl: function( url ) {
  1825. // All relative Url variants have one thing in common, no protocol.
  1826. return path.parseUrl( url ).protocol === "";
  1827. },
  1828. //Returns true for an absolute url.
  1829. isAbsoluteUrl: function( url ) {
  1830. return path.parseUrl( url ).protocol !== "";
  1831. },
  1832. //Turn the specified realtive URL into an absolute one. This function
  1833. //can handle all relative variants (protocol, site, document, query, fragment).
  1834. makeUrlAbsolute: function( relUrl, absUrl ) {
  1835. if ( !path.isRelativeUrl( relUrl ) ) {
  1836. return relUrl;
  1837. }
  1838. var relObj = path.parseUrl( relUrl ),
  1839. absObj = path.parseUrl( absUrl ),
  1840. protocol = relObj.protocol || absObj.protocol,
  1841. authority = relObj.authority || absObj.authority,
  1842. hasPath = relObj.pathname !== "",
  1843. pathname = path.makePathAbsolute( relObj.pathname || absObj.filename, absObj.pathname ),
  1844. search = relObj.search || ( !hasPath && absObj.search ) || "",
  1845. hash = relObj.hash;
  1846. return protocol + "//" + authority + pathname + search + hash;
  1847. },
  1848. //Add search (aka query) params to the specified url.
  1849. addSearchParams: function( url, params ) {
  1850. var u = path.parseUrl( url ),
  1851. p = ( typeof params === "object" ) ? $.param( params ) : params,
  1852. s = u.search || "?";
  1853. return u.hrefNoSearch + s + ( s.charAt( s.length - 1 ) !== "?" ? "&" : "" ) + p + ( u.hash || "" );
  1854. },
  1855. convertUrlToDataUrl: function( absUrl ) {
  1856. var u = path.parseUrl( absUrl );
  1857. if ( path.isEmbeddedPage( u ) ) {
  1858. return u.hash.replace( /^#/, "" );
  1859. } else if ( path.isSameDomain( u, documentBase ) ) {
  1860. return u.hrefNoHash.replace( documentBase.domain, "" );
  1861. }
  1862. return absUrl;
  1863. },
  1864. //get path from current hash, or from a file path
  1865. get: function( newPath ) {
  1866. if( newPath === undefined ) {
  1867. newPath = location.hash;
  1868. }
  1869. return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' );
  1870. },
  1871. //return the substring of a filepath before the sub-page key, for making a server request
  1872. getFilePath: function( path ) {
  1873. var splitkey = '&' + $.mobile.subPageUrlKey;
  1874. return path && path.split( splitkey )[0].split( dialogHashKey )[0];
  1875. },
  1876. //set location hash to path
  1877. set: function( path ) {
  1878. location.hash = path;
  1879. },
  1880. //test if a given url (string) is a path
  1881. //NOTE might be exceptionally naive
  1882. isPath: function( url ) {
  1883. return ( /\// ).test( url );
  1884. },
  1885. //return a url path with the window's location protocol/hostname/pathname removed
  1886. clean: function( url ) {
  1887. return url.replace( documentBase.domain, "" );
  1888. },
  1889. //just return the url without an initial #
  1890. stripHash: function( url ) {
  1891. return url.replace( /^#/, "" );
  1892. },
  1893. //remove the preceding hash, any query params, and dialog notations
  1894. cleanHash: function( hash ) {
  1895. return path.stripHash( hash.replace( /\?.*$/, "" ).replace( dialogHashKey, "" ) );
  1896. },
  1897. //check whether a url is referencing the same domain, or an external domain or different protocol
  1898. //could be mailto, etc
  1899. isExternal: function( url ) {
  1900. var u = path.parseUrl( url );
  1901. return u.protocol && u.domain !== documentUrl.domain ? true : false;
  1902. },
  1903. hasProtocol: function( url ) {
  1904. return ( /^(:?\w+:)/ ).test( url );
  1905. },
  1906. isEmbeddedPage: function( url ) {
  1907. var u = path.parseUrl( url );
  1908. //if the path is absolute, then we need to compare the url against
  1909. //both the documentUrl and the documentBase. The main reason for this
  1910. //is that links embedded within external documents will refer to the
  1911. //application document, whereas links embedded within the application
  1912. //document will be resolved against the document base.
  1913. if ( u.protocol !== "" ) {
  1914. return ( u.hash && ( u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ) ) );
  1915. }
  1916. return (/^#/).test( u.href );
  1917. }
  1918. },
  1919. //will be defined when a link is clicked and given an active class
  1920. $activeClickedLink = null,
  1921. //urlHistory is purely here to make guesses at whether the back or forward button was clicked
  1922. //and provide an appropriate transition
  1923. urlHistory = {
  1924. //array of pages that are visited during a single page load. each has a url and optional transition
  1925. stack: [],
  1926. //maintain an index number for the active page in the stack
  1927. activeIndex: 0,
  1928. //get active
  1929. getActive: function() {
  1930. return urlHistory.stack[ urlHistory.activeIndex ];
  1931. },
  1932. getPrev: function() {
  1933. return urlHistory.stack[ urlHistory.activeIndex - 1 ];
  1934. },
  1935. getNext: function() {
  1936. return urlHistory.stack[ urlHistory.activeIndex + 1 ];
  1937. },
  1938. // addNew is used whenever a new page is added
  1939. addNew: function( url, transition, title, storedTo ) {
  1940. //if there's forward history, wipe it
  1941. if( urlHistory.getNext() ) {
  1942. urlHistory.clearForward();
  1943. }
  1944. urlHistory.stack.push( {url : url, transition: transition, title: title, page: storedTo } );
  1945. urlHistory.activeIndex = urlHistory.stack.length - 1;
  1946. },
  1947. //wipe urls ahead of active index
  1948. clearForward: function() {
  1949. urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
  1950. },
  1951. directHashChange: function( opts ) {
  1952. var back , forward, newActiveIndex;
  1953. // check if url isp in history and if it's ahead or behind current page
  1954. $.each( urlHistory.stack, function( i, historyEntry ) {
  1955. //if the url is in the stack, it's a forward or a back
  1956. if( opts.currentUrl === historyEntry.url ) {
  1957. //define back and forward by whether url is older or newer than current page
  1958. back = i < urlHistory.activeIndex;
  1959. forward = !back;
  1960. newActiveIndex = i;
  1961. }
  1962. });
  1963. // save new page index, null check to prevent falsey 0 result
  1964. this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
  1965. if( back ) {
  1966. opts.isBack();
  1967. } else if( forward ) {
  1968. opts.isForward();
  1969. }
  1970. },
  1971. //disable hashchange event listener internally to ignore one change
  1972. //toggled internally when location.hash is updated to match the url of a successful page load
  1973. ignoreNextHashChange: false
  1974. },
  1975. //define first selector to receive focus when a page is shown
  1976. focusable = "[tabindex],a,button:visible,select:visible,input",
  1977. //queue to hold simultanious page transitions
  1978. pageTransitionQueue = [],
  1979. //indicates whether or not page is in process of transitioning
  1980. isPageTransitioning = false,
  1981. //nonsense hash change key for dialogs, so they create a history entry
  1982. dialogHashKey = "&ui-state=dialog",
  1983. //existing base tag?
  1984. $base = $head.children( "base" ),
  1985. //tuck away the original document URL minus any fragment.
  1986. documentUrl = path.parseUrl( location.href ),
  1987. //if the document has an embedded base tag, documentBase is set to its
  1988. //initial value. If a base tag does not exist, then we default to the documentUrl.
  1989. documentBase = $base.length ? path.parseUrl( path.makeUrlAbsolute( $base.attr( "href" ), documentUrl.href ) ) : documentUrl,
  1990. //cache the comparison once.
  1991. documentBaseDiffers = ( documentUrl.hrefNoHash !== documentBase.hrefNoHash );
  1992. //base element management, defined depending on dynamic base tag support
  1993. var base = $.support.dynamicBaseTag ? {
  1994. //define base element, for use in routing asset urls that are referenced in Ajax-requested markup
  1995. element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
  1996. //set the generated BASE element's href attribute to a new page's base path
  1997. set: function( href ) {
  1998. base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
  1999. },
  2000. //set the generated BASE element's href attribute to a new page's base path
  2001. reset: function() {
  2002. base.element.attr( "href", documentBase.hrefNoHash );
  2003. }
  2004. } : undefined;
  2005. /*
  2006. internal utility functions
  2007. --------------------------------------*/
  2008. //direct focus to the page title, or otherwise first focusable element
  2009. function reFocus( page ) {
  2010. var lastClicked = page.jqmData( "lastClicked" );
  2011. if( lastClicked && lastClicked.length ) {
  2012. lastClicked.focus();
  2013. }
  2014. else {
  2015. var pageTitle = page.find( ".ui-title:eq(0)" );
  2016. if( pageTitle.length ) {
  2017. pageTitle.focus();
  2018. }
  2019. else{
  2020. page.find( focusable ).eq( 0 ).focus();
  2021. }
  2022. }
  2023. }
  2024. //remove active classes after page transition or error
  2025. function removeActiveLinkClass( forceRemoval ) {
  2026. if( !!$activeClickedLink && ( !$activeClickedLink.closest( '.ui-page-active' ).length || forceRemoval ) ) {
  2027. $activeClickedLink.removeClass( $.mobile.activeBtnClass );
  2028. }
  2029. $activeClickedLink = null;
  2030. }
  2031. function releasePageTransitionLock() {
  2032. isPageTransitioning = false;
  2033. if( pageTransitionQueue.length > 0 ) {
  2034. $.mobile.changePage.apply( null, pageTransitionQueue.pop() );
  2035. }
  2036. }
  2037. //function for transitioning between two existing pages
  2038. function transitionPages( toPage, fromPage, transition, reverse ) {
  2039. //get current scroll distance
  2040. var currScroll = $.support.scrollTop ? $window.scrollTop() : true,
  2041. toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll,
  2042. screenHeight = getScreenHeight();
  2043. //if scrolled down, scroll to top
  2044. if( currScroll ){
  2045. window.scrollTo( 0, $.mobile.defaultHomeScroll );
  2046. }
  2047. //if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
  2048. if( toScroll < $.mobile.minScrollBack ){
  2049. toScroll = 0;
  2050. }
  2051. if( fromPage ) {
  2052. //set as data for returning to that spot
  2053. fromPage
  2054. .height( screenHeight + currScroll )
  2055. .jqmData( "lastScroll", currScroll )
  2056. .jqmData( "lastClicked", $activeClickedLink );
  2057. //trigger before show/hide events
  2058. fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
  2059. }
  2060. toPage
  2061. .height( screenHeight + toScroll )
  2062. .data( "page" )._trigger( "beforeshow", null, { prevPage: fromPage || $( "" ) } );
  2063. //clear page loader
  2064. $.mobile.hidePageLoadingMsg();
  2065. //find the transition handler for the specified transition. If there
  2066. //isn't one in our transitionHandlers dictionary, use the default one.
  2067. //call the handler immediately to kick-off the transition.
  2068. var th = $.mobile.transitionHandlers[transition || "none"] || $.mobile.defaultTransitionHandler,
  2069. promise = th( transition, reverse, toPage, fromPage );
  2070. promise.done(function() {
  2071. //reset toPage height bac
  2072. toPage.height( "" );
  2073. //jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
  2074. if( toScroll ){
  2075. $.mobile.silentScroll( toScroll );
  2076. $( document ).one( "silentscroll", function() { reFocus( toPage ); } );
  2077. }
  2078. else{
  2079. reFocus( toPage );
  2080. }
  2081. //trigger show/hide events
  2082. if( fromPage ) {
  2083. fromPage.height("").data( "page" )._trigger( "hide", null, { nextPage: toPage } );
  2084. }
  2085. //trigger pageshow, define prevPage as either fromPage or empty jQuery obj
  2086. toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );
  2087. });
  2088. return promise;
  2089. }
  2090. //simply set the active page's minimum height to screen height, depending on orientation
  2091. function getScreenHeight(){
  2092. var orientation = jQuery.event.special.orientationchange.orientation(),
  2093. port = orientation === "portrait",
  2094. winMin = port ? 480 : 320,
  2095. screenHeight = port ? screen.availHeight : screen.availWidth,
  2096. winHeight = Math.max( winMin, $( window ).height() ),
  2097. pageMin = Math.min( screenHeight, winHeight );
  2098. return pageMin;
  2099. }
  2100. //simply set the active page's minimum height to screen height, depending on orientation
  2101. function resetActivePageHeight(){
  2102. $( "." + $.mobile.activePageClass ).css( "min-height", getScreenHeight() );
  2103. }
  2104. //shared page enhancements
  2105. function enhancePage( $page, role ) {
  2106. // If a role was specified, make sure the data-role attribute
  2107. // on the page element is in sync.
  2108. if( role ) {
  2109. $page.attr( "data-" + $.mobile.ns + "role", role );
  2110. }
  2111. //run page plugin
  2112. $page.page();
  2113. }
  2114. /* exposed $.mobile methods */
  2115. //animation complete callback
  2116. $.fn.animationComplete = function( callback ) {
  2117. if( $.support.cssTransitions ) {
  2118. return $( this ).one( 'webkitAnimationEnd', callback );
  2119. }
  2120. else{
  2121. // defer execution for consistency between webkit/non webkit
  2122. setTimeout( callback, 0 );
  2123. return $( this );
  2124. }
  2125. };
  2126. //update location.hash, with or without triggering hashchange event
  2127. //TODO - deprecate this one at 1.0
  2128. $.mobile.updateHash = path.set;
  2129. //expose path object on $.mobile
  2130. $.mobile.path = path;
  2131. //expose base object on $.mobile
  2132. $.mobile.base = base;
  2133. //url stack, useful when plugins need to be aware of previous pages viewed
  2134. //TODO: deprecate this one at 1.0
  2135. $.mobile.urlstack = urlHistory.stack;
  2136. //history stack
  2137. $.mobile.urlHistory = urlHistory;
  2138. //default non-animation transition handler
  2139. $.mobile.noneTransitionHandler = function( name, reverse, $toPage, $fromPage ) {
  2140. if ( $fromPage ) {
  2141. $fromPage.removeClass( $.mobile.activePageClass );
  2142. }
  2143. $toPage.addClass( $.mobile.activePageClass );
  2144. return $.Deferred().resolve( name, reverse, $toPage, $fromPage ).promise();
  2145. };
  2146. //default handler for unknown transitions
  2147. $.mobile.defaultTransitionHandler = $.mobile.noneTransitionHandler;
  2148. //transition handler dictionary for 3rd party transitions
  2149. $.mobile.transitionHandlers = {
  2150. none: $.mobile.defaultTransitionHandler
  2151. };
  2152. //enable cross-domain page support
  2153. $.mobile.allowCrossDomainPages = false;
  2154. //return the original document url
  2155. $.mobile.getDocumentUrl = function(asParsedObject) {
  2156. return asParsedObject ? $.extend( {}, documentUrl ) : documentUrl.href;
  2157. };
  2158. //return the original document base url
  2159. $.mobile.getDocumentBase = function(asParsedObject) {
  2160. return asParsedObject ? $.extend( {}, documentBase ) : documentBase.href;
  2161. };
  2162. // Load a page into the DOM.
  2163. $.mobile.loadPage = function( url, options ) {
  2164. // This function uses deferred notifications to let callers
  2165. // know when the page is done loading, or if an error has occurred.
  2166. var deferred = $.Deferred(),
  2167. // The default loadPage options with overrides specified by
  2168. // the caller.
  2169. settings = $.extend( {}, $.mobile.loadPage.defaults, options ),
  2170. // The DOM element for the page after it has been loaded.
  2171. page = null,
  2172. // If the reloadPage option is true, and the page is already
  2173. // in the DOM, dupCachedPage will be set to the page element
  2174. // so that it can be removed after the new version of the
  2175. // page is loaded off the network.
  2176. dupCachedPage = null,
  2177. // The absolute version of the URL passed into the function. This
  2178. // version of the URL may contain dialog/subpage params in it.
  2179. absUrl = path.makeUrlAbsolute( url, documentBase.hrefNoHash );
  2180. // If the caller provided data, and we're using "get" request,
  2181. // append the data to the URL.
  2182. if ( settings.data && settings.type === "get" ) {
  2183. absUrl = path.addSearchParams( absUrl, settings.data );
  2184. settings.data = undefined;
  2185. }
  2186. // The absolute version of the URL minus any dialog/subpage params.
  2187. // In otherwords the real URL of the page to be loaded.
  2188. var fileUrl = path.getFilePath( absUrl ),
  2189. // The version of the Url actually stored in the data-url attribute of
  2190. // the page. For embedded pages, it is just the id of the page. For pages
  2191. // within the same domain as the document base, it is the site relative
  2192. // path. For cross-domain pages (Phone Gap only) the entire absolute Url
  2193. // used to load the page.
  2194. dataUrl = path.convertUrlToDataUrl( absUrl );
  2195. // Make sure we have a pageContainer to work with.
  2196. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  2197. // Check to see if the page already exists in the DOM.
  2198. page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  2199. // Reset base to the default document base.
  2200. if ( base ) {
  2201. base.reset();
  2202. }
  2203. // If the page we are interested in is already in the DOM,
  2204. // and the caller did not indicate that we should force a
  2205. // reload of the file, we are done. Otherwise, track the
  2206. // existing page as a duplicated.
  2207. if ( page.length ) {
  2208. if ( !settings.reloadPage ) {
  2209. enhancePage( page, settings.role );
  2210. deferred.resolve( absUrl, options, page );
  2211. return deferred.promise();
  2212. }
  2213. dupCachedPage = page;
  2214. }
  2215. if ( settings.showLoadMsg ) {
  2216. $.mobile.showPageLoadingMsg();
  2217. }
  2218. // Load the new page.
  2219. $.ajax({
  2220. url: fileUrl,
  2221. type: settings.type,
  2222. data: settings.data,
  2223. dataType: "html",
  2224. success: function( html ) {
  2225. //pre-parse html to check for a data-url,
  2226. //use it as the new fileUrl, base path, etc
  2227. var all = $( "<div></div>" ),
  2228. //page title regexp
  2229. newPageTitle = html.match( /<title[^>]*>([^<]*)/ ) && RegExp.$1,
  2230. // TODO handle dialogs again
  2231. pageElemRegex = new RegExp( ".*(<[^>]+\\bdata-" + $.mobile.ns + "role=[\"']?page[\"']?[^>]*>).*" ),
  2232. dataUrlRegex = new RegExp( "\\bdata-" + $.mobile.ns + "url=[\"']?([^\"'>]*)[\"']?" );
  2233. // data-url must be provided for the base tag so resource requests can be directed to the
  2234. // correct url. loading into a temprorary element makes these requests immediately
  2235. if( pageElemRegex.test( html )
  2236. && RegExp.$1
  2237. && dataUrlRegex.test( RegExp.$1 )
  2238. && RegExp.$1 ) {
  2239. url = fileUrl = path.getFilePath( RegExp.$1 );
  2240. }
  2241. if ( base ) {
  2242. base.set( fileUrl );
  2243. }
  2244. //workaround to allow scripts to execute when included in page divs
  2245. all.get( 0 ).innerHTML = html;
  2246. page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first();
  2247. if ( newPageTitle && !page.jqmData( "title" ) ) {
  2248. page.jqmData( "title", newPageTitle );
  2249. }
  2250. //rewrite src and href attrs to use a base url
  2251. if( !$.support.dynamicBaseTag ) {
  2252. var newPath = path.get( fileUrl );
  2253. page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
  2254. var thisAttr = $( this ).is( '[href]' ) ? 'href' :
  2255. $(this).is('[src]') ? 'src' : 'action',
  2256. thisUrl = $( this ).attr( thisAttr );
  2257. // XXX_jblas: We need to fix this so that it removes the document
  2258. // base URL, and then prepends with the new page URL.
  2259. //if full path exists and is same, chop it - helps IE out
  2260. thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
  2261. if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
  2262. $( this ).attr( thisAttr, newPath + thisUrl );
  2263. }
  2264. });
  2265. }
  2266. //append to page and enhance
  2267. page
  2268. .attr( "data-" + $.mobile.ns + "url", path.convertUrlToDataUrl( fileUrl ) )
  2269. .appendTo( settings.pageContainer );
  2270. enhancePage( page, settings.role );
  2271. // Enhancing the page may result in new dialogs/sub pages being inserted
  2272. // into the DOM. If the original absUrl refers to a sub-page, that is the
  2273. // real page we are interested in.
  2274. if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) {
  2275. page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  2276. }
  2277. // Remove loading message.
  2278. if ( settings.showLoadMsg ) {
  2279. $.mobile.hidePageLoadingMsg();
  2280. }
  2281. deferred.resolve( absUrl, options, page, dupCachedPage );
  2282. },
  2283. error: function() {
  2284. //set base back to current path
  2285. if( base ) {
  2286. base.set( path.get() );
  2287. }
  2288. // Remove loading message.
  2289. if ( settings.showLoadMsg ) {
  2290. $.mobile.hidePageLoadingMsg();
  2291. //show error message
  2292. $( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" )
  2293. .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 })
  2294. .appendTo( settings.pageContainer )
  2295. .delay( 800 )
  2296. .fadeOut( 400, function() {
  2297. $( this ).remove();
  2298. });
  2299. }
  2300. deferred.reject( absUrl, options );
  2301. }
  2302. });
  2303. return deferred.promise();
  2304. };
  2305. $.mobile.loadPage.defaults = {
  2306. type: "get",
  2307. data: undefined,
  2308. reloadPage: false,
  2309. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  2310. showLoadMsg: true,
  2311. pageContainer: undefined
  2312. };
  2313. // Show a specific page in the page container.
  2314. $.mobile.changePage = function( toPage, options ) {
  2315. // XXX: REMOVE_BEFORE_SHIPPING_1.0
  2316. // This is temporary code that makes changePage() compatible with previous alpha versions.
  2317. if ( typeof options !== "object" ) {
  2318. var opts = null;
  2319. // Map old-style call signature for form submit to the new options object format.
  2320. if ( typeof toPage === "object" && toPage.url && toPage.type ) {
  2321. opts = {
  2322. type: toPage.type,
  2323. data: toPage.data,
  2324. forcePageLoad: true
  2325. };
  2326. toPage = toPage.url;
  2327. }
  2328. // The arguments passed into the function need to be re-mapped
  2329. // to the new options object format.
  2330. var len = arguments.length;
  2331. if ( len > 1 ) {
  2332. var argNames = [ "transition", "reverse", "changeHash", "fromHashChange" ], i;
  2333. for ( i = 1; i < len; i++ ) {
  2334. var a = arguments[ i ];
  2335. if ( typeof a !== "undefined" ) {
  2336. opts = opts || {};
  2337. opts[ argNames[ i - 1 ] ] = a;
  2338. }
  2339. }
  2340. }
  2341. // If an options object was created, then we know changePage() was called
  2342. // with an old signature.
  2343. if ( opts ) {
  2344. return $.mobile.changePage( toPage, opts );
  2345. }
  2346. }
  2347. // XXX: REMOVE_BEFORE_SHIPPING_1.0
  2348. // If we are in the midst of a transition, queue the current request.
  2349. // We'll call changePage() once we're done with the current transition to
  2350. // service the request.
  2351. if( isPageTransitioning ) {
  2352. pageTransitionQueue.unshift( arguments );
  2353. return;
  2354. }
  2355. // Set the isPageTransitioning flag to prevent any requests from
  2356. // entering this method while we are in the midst of loading a page
  2357. // or transitioning.
  2358. isPageTransitioning = true;
  2359. var settings = $.extend( {}, $.mobile.changePage.defaults, options );
  2360. // Make sure we have a pageContainer to work with.
  2361. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  2362. // If the caller passed us a url, call loadPage()
  2363. // to make sure it is loaded into the DOM. We'll listen
  2364. // to the promise object it returns so we know when
  2365. // it is done loading or if an error ocurred.
  2366. if ( typeof toPage == "string" ) {
  2367. $.mobile.loadPage( toPage, settings )
  2368. .done(function( url, options, newPage, dupCachedPage ) {
  2369. isPageTransitioning = false;
  2370. options.duplicateCachedPage = dupCachedPage;
  2371. $.mobile.changePage( newPage, options );
  2372. })
  2373. .fail(function( url, options ) {
  2374. // XXX_jblas: Fire off changepagefailed notificaiton.
  2375. isPageTransitioning = false;
  2376. //clear out the active button state
  2377. removeActiveLinkClass( true );
  2378. //release transition lock so navigation is free again
  2379. releasePageTransitionLock();
  2380. settings.pageContainer.trigger("changepagefailed");
  2381. });
  2382. return;
  2383. }
  2384. // The caller passed us a real page DOM element. Update our
  2385. // internal state and then trigger a transition to the page.
  2386. var mpc = settings.pageContainer,
  2387. fromPage = $.mobile.activePage,
  2388. url = toPage.jqmData( "url" ),
  2389. fileUrl = path.getFilePath( url ),
  2390. active = urlHistory.getActive(),
  2391. activeIsInitialPage = urlHistory.activeIndex === 0,
  2392. historyDir = 0,
  2393. pageTitle = document.title,
  2394. isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
  2395. // Let listeners know we're about to change the current page.
  2396. mpc.trigger( "beforechangepage" );
  2397. // If we are trying to transition to the same page that we are currently on ignore the request.
  2398. // an illegal same page request is defined by the current page being the same as the url, as long as there's history
  2399. // and toPage is not an array or object (those are allowed to be "same")
  2400. //
  2401. // XXX_jblas: We need to remove this at some point when we allow for transitions
  2402. // to the same page.
  2403. if( fromPage && fromPage[0] === toPage[0] ) {
  2404. isPageTransitioning = false;
  2405. mpc.trigger( "changepage" );
  2406. return;
  2407. }
  2408. // We need to make sure the page we are given has already been enhanced.
  2409. enhancePage( toPage, settings.role );
  2410. // If the changePage request was sent from a hashChange event, check to see if the
  2411. // page is already within the urlHistory stack. If so, we'll assume the user hit
  2412. // the forward/back button and will try to match the transition accordingly.
  2413. if( settings.fromHashChange ) {
  2414. urlHistory.directHashChange({
  2415. currentUrl: url,
  2416. isBack: function() { historyDir = -1; },
  2417. isForward: function() { historyDir = 1; }
  2418. });
  2419. }
  2420. // Kill the keyboard.
  2421. // XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,
  2422. // we should be tracking focus with a live() handler so we already have
  2423. // the element in hand at this point.
  2424. $( document.activeElement || "" ).add( "input:focus, textarea:focus, select:focus" ).blur();
  2425. // If we're displaying the page as a dialog, we don't want the url
  2426. // for the dialog content to be used in the hash. Instead, we want
  2427. // to append the dialogHashKey to the url of the current page.
  2428. if ( isDialog && active ) {
  2429. url = active.url + dialogHashKey;
  2430. }
  2431. // Set the location hash.
  2432. if( settings.changeHash !== false && url ) {
  2433. //disable hash listening temporarily
  2434. urlHistory.ignoreNextHashChange = true;
  2435. //update hash and history
  2436. path.set( url );
  2437. }
  2438. //if title element wasn't found, try the page div data attr too
  2439. var newPageTitle = toPage.jqmData( "title" ) || toPage.children(":jqmData(role='header')").find(".ui-title" ).text();
  2440. if( !!newPageTitle && pageTitle == document.title ) {
  2441. pageTitle = newPageTitle;
  2442. }
  2443. //add page to history stack if it's not back or forward
  2444. if( !historyDir ) {
  2445. urlHistory.addNew( url, settings.transition, pageTitle, toPage );
  2446. }
  2447. //set page title
  2448. document.title = urlHistory.getActive().title;
  2449. //set "toPage" as activePage
  2450. $.mobile.activePage = toPage;
  2451. // Make sure we have a transition defined.
  2452. settings.transition = settings.transition
  2453. || ( ( historyDir && !activeIsInitialPage ) ? active.transition : undefined )
  2454. || ( settings.role === "dialog" ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
  2455. // If we're navigating back in the URL history, set reverse accordingly.
  2456. settings.reverse = settings.reverse || historyDir < 0;
  2457. transitionPages( toPage, fromPage, settings.transition, settings.reverse )
  2458. .done(function() {
  2459. removeActiveLinkClass();
  2460. //if there's a duplicateCachedPage, remove it from the DOM now that it's hidden
  2461. if ( settings.duplicateCachedPage ) {
  2462. settings.duplicateCachedPage.remove();
  2463. }
  2464. //remove initial build class (only present on first pageshow)
  2465. $html.removeClass( "ui-mobile-rendering" );
  2466. releasePageTransitionLock();
  2467. // Let listeners know we're all done changing the current page.
  2468. mpc.trigger( "changepage" );
  2469. });
  2470. };
  2471. $.mobile.changePage.defaults = {
  2472. transition: undefined,
  2473. reverse: false,
  2474. changeHash: true,
  2475. fromHashChange: false,
  2476. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  2477. duplicateCachedPage: undefined,
  2478. pageContainer: undefined
  2479. };
  2480. /* Event Bindings - hashchange, submit, and click */
  2481. //bind to form submit events, handle with Ajax
  2482. $( "form" ).live('submit', function( event ) {
  2483. var $this = $( this );
  2484. if( !$.mobile.ajaxEnabled ||
  2485. $this.is( ":jqmData(ajax='false')" ) ) {
  2486. return;
  2487. }
  2488. var type = $this.attr( "method" ),
  2489. url = path.makeUrlAbsolute( $this.attr( "action" ), getClosestBaseUrl($this) ),
  2490. target = $this.attr( "target" );
  2491. //external submits use regular HTTP
  2492. if( path.isExternal( url ) || target ) {
  2493. return;
  2494. }
  2495. $.mobile.changePage(
  2496. url,
  2497. {
  2498. type: type.length && type.toLowerCase() || "get",
  2499. data: $this.serialize(),
  2500. transition: $this.jqmData( "transition" ),
  2501. direction: $this.jqmData( "direction" ),
  2502. reloadPage: true
  2503. }
  2504. );
  2505. event.preventDefault();
  2506. });
  2507. function findClosestLink( ele )
  2508. {
  2509. while ( ele ) {
  2510. if ( ele.nodeName.toLowerCase() == "a" ) {
  2511. break;
  2512. }
  2513. ele = ele.parentNode;
  2514. }
  2515. return ele;
  2516. }
  2517. // The base URL for any given element depends on the page it resides in.
  2518. function getClosestBaseUrl( ele )
  2519. {
  2520. // Find the closest page and extract out its url.
  2521. var url = $( ele ).closest( ".ui-page" ).jqmData( "url" ),
  2522. base = documentBase.hrefNoHash;
  2523. if ( !url || !path.isPath( url ) ) {
  2524. url = base;
  2525. }
  2526. return path.makeUrlAbsolute( url, base);
  2527. }
  2528. //add active state on vclick
  2529. $( document ).bind( "vclick", function( event ) {
  2530. var link = findClosestLink( event.target );
  2531. if ( link ) {
  2532. if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) {
  2533. $( link ).closest( ".ui-btn" ).not( ".ui-disabled" ).addClass( $.mobile.activeBtnClass );
  2534. $( "." + $.mobile.activePageClass + " .ui-btn" ).not( link ).blur();
  2535. }
  2536. }
  2537. });
  2538. // click routing - direct to HTTP or Ajax, accordingly
  2539. // TODO: most of the time, vclick will be all we need for fastClick bulletproofing.
  2540. // However, it seems that in Android 2.1, a click event
  2541. // will occasionally arrive independently of the bound vclick
  2542. // binding to click as well seems to help in this edge case
  2543. // we'll dig into this further in the next release cycle
  2544. $( document ).bind( $.mobile.useFastClick ? "vclick click" : "click", function( event ) {
  2545. var link = findClosestLink( event.target );
  2546. if ( !link ) {
  2547. return;
  2548. }
  2549. var $link = $( link ),
  2550. //remove active link class if external (then it won't be there if you come back)
  2551. httpCleanup = function(){
  2552. window.setTimeout( function() { removeActiveLinkClass( true ); }, 200 );
  2553. };
  2554. //if there's a data-rel=back attr, go back in history
  2555. if( $link.is( ":jqmData(rel='back')" ) ) {
  2556. window.history.back();
  2557. return false;
  2558. }
  2559. //if ajax is disabled, exit early
  2560. if( !$.mobile.ajaxEnabled ){
  2561. httpCleanup();
  2562. //use default click handling
  2563. return;
  2564. }
  2565. var baseUrl = getClosestBaseUrl( $link ),
  2566. //get href, if defined, otherwise default to empty hash
  2567. href = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl );
  2568. // XXX_jblas: Ideally links to application pages should be specified as
  2569. // an url to the application document with a hash that is either
  2570. // the site relative path or id to the page. But some of the
  2571. // internal code that dynamically generates sub-pages for nested
  2572. // lists and select dialogs, just write a hash in the link they
  2573. // create. This means the actual URL path is based on whatever
  2574. // the current value of the base tag is at the time this code
  2575. // is called. For now we are just assuming that any url with a
  2576. // hash in it is an application page reference.
  2577. if ( href.search( "#" ) != -1 ) {
  2578. href = href.replace( /[^#]*#/, "" );
  2579. if ( !href ) {
  2580. //link was an empty hash meant purely
  2581. //for interaction, so we ignore it.
  2582. event.preventDefault();
  2583. return;
  2584. } else if ( path.isPath( href ) ) {
  2585. //we have apath so make it the href we want to load.
  2586. href = path.makeUrlAbsolute( href, baseUrl );
  2587. } else {
  2588. //we have a simple id so use the documentUrl as its base.
  2589. href = path.makeUrlAbsolute( "#" + href, documentUrl.hrefNoHash );
  2590. }
  2591. }
  2592. // Should we handle this link, or let the browser deal with it?
  2593. var useDefaultUrlHandling = $link.is( "[rel='external']" ) || $link.is( ":jqmData(ajax='false')" ) || $link.is( "[target]" ),
  2594. // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
  2595. // requests if the document doing the request was loaded via the file:// protocol.
  2596. // This is usually to allow the application to "phone home" and fetch app specific
  2597. // data. We normally let the browser handle external/cross-domain urls, but if the
  2598. // allowCrossDomainPages option is true, we will allow cross-domain http/https
  2599. // requests to go through our page loading logic.
  2600. isCrossDomainPageLoad = ( $.mobile.allowCrossDomainPages && documentUrl.protocol === "file:" && href.search( /^https?:/ ) != -1 ),
  2601. //check for protocol or rel and its not an embedded page
  2602. //TODO overlap in logic from isExternal, rel=external check should be
  2603. // moved into more comprehensive isExternalLink
  2604. isExternal = useDefaultUrlHandling || ( path.isExternal( href ) && !isCrossDomainPageLoad );
  2605. $activeClickedLink = $link.closest( ".ui-btn" );
  2606. if( isExternal ) {
  2607. httpCleanup();
  2608. //use default click handling
  2609. return;
  2610. }
  2611. //use ajax
  2612. var transition = $link.jqmData( "transition" ),
  2613. direction = $link.jqmData( "direction" ),
  2614. reverse = ( direction && direction === "reverse" ) ||
  2615. // deprecated - remove by 1.0
  2616. $link.jqmData( "back" ),
  2617. //this may need to be more specific as we use data-rel more
  2618. role = $link.attr( "data-" + $.mobile.ns + "rel" ) || undefined;
  2619. $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } );
  2620. event.preventDefault();
  2621. });
  2622. //hashchange event handler
  2623. $window.bind( "hashchange", function( e, triggered ) {
  2624. //find first page via hash
  2625. var to = path.stripHash( location.hash ),
  2626. //transition is false if it's the first page, undefined otherwise (and may be overridden by default)
  2627. transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined;
  2628. //if listening is disabled (either globally or temporarily), or it's a dialog hash
  2629. if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
  2630. urlHistory.ignoreNextHashChange = false;
  2631. return;
  2632. }
  2633. // special case for dialogs
  2634. if( urlHistory.stack.length > 1 &&
  2635. to.indexOf( dialogHashKey ) > -1 ) {
  2636. // If current active page is not a dialog skip the dialog and continue
  2637. // in the same direction
  2638. if(!$.mobile.activePage.is( ".ui-dialog" )) {
  2639. //determine if we're heading forward or backward and continue accordingly past
  2640. //the current dialog
  2641. urlHistory.directHashChange({
  2642. currentUrl: to,
  2643. isBack: function() { window.history.back(); },
  2644. isForward: function() { window.history.forward(); }
  2645. });
  2646. // prevent changepage
  2647. return;
  2648. } else {
  2649. var setTo = function() { to = $.mobile.urlHistory.getActive().page; };
  2650. // if the current active page is a dialog and we're navigating
  2651. // to a dialog use the dialog objected saved in the stack
  2652. urlHistory.directHashChange({ currentUrl: to, isBack: setTo, isForward: setTo });
  2653. }
  2654. }
  2655. //if to is defined, load it
  2656. if ( to ) {
  2657. to = ( typeof to === "string" && !path.isPath( to ) ) ? ( '#' + to ) : to;
  2658. $.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true } );
  2659. }
  2660. //there's no hash, go to the first page in the dom
  2661. else {
  2662. $.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true } );
  2663. }
  2664. });
  2665. //set page min-heights to be device specific
  2666. $( document ).bind( "pageshow", resetActivePageHeight );
  2667. $( window ).bind( "throttledresize", resetActivePageHeight );
  2668. })( jQuery );
  2669. /*!
  2670. * jQuery Mobile v@VERSION
  2671. * http://jquerymobile.com/
  2672. *
  2673. * Copyright 2010, jQuery Project
  2674. * Dual licensed under the MIT or GPL Version 2 licenses.
  2675. * http://jquery.org/license
  2676. */
  2677. ( function( $, window, undefined ) {
  2678. function css3TransitionHandler( name, reverse, $to, $from )
  2679. {
  2680. var deferred = new $.Deferred(),
  2681. reverseClass = reverse ? " reverse" : "",
  2682. viewportClass = "ui-mobile-viewport-transitioning viewport-" + name,
  2683. doneFunc = function() {
  2684. $to.add( $from ).removeClass( "out in reverse " + name );
  2685. if ( $from ) {
  2686. $from.removeClass( $.mobile.activePageClass );
  2687. }
  2688. $to.parent().removeClass( viewportClass );
  2689. deferred.resolve( name, reverse, $to, $from );
  2690. };
  2691. $to.animationComplete( doneFunc );
  2692. $to.parent().addClass( viewportClass );
  2693. if ( $from ) {
  2694. $from.addClass( name + " out" + reverseClass );
  2695. }
  2696. $to.addClass( $.mobile.activePageClass + " " + name + " in" + reverseClass );
  2697. return deferred.promise();
  2698. }
  2699. // Make our transition handler public.
  2700. $.mobile.css3TransitionHandler = css3TransitionHandler;
  2701. // If the default transition handler is the 'none' handler, replace it with our handler.
  2702. if ( $.mobile.defaultTransitionHandler === $.mobile.noneTransitionHandler ) {
  2703. $.mobile.defaultTransitionHandler = css3TransitionHandler;
  2704. }
  2705. })( jQuery, this );
  2706. /*
  2707. * jQuery Mobile Framework : "fixHeaderFooter" plugin - on-demand positioning for headers,footers
  2708. * Copyright (c) jQuery Project
  2709. * Dual licensed under the MIT or GPL Version 2 licenses.
  2710. * http://jquery.org/license
  2711. */
  2712. (function($, undefined ) {
  2713. $.fn.fixHeaderFooter = function(options){
  2714. if( !$.support.scrollTop ){ return this; }
  2715. return this.each(function(){
  2716. var $this = $(this);
  2717. if( $this.jqmData('fullscreen') ){ $this.addClass('ui-page-fullscreen'); }
  2718. $this.find( ".ui-header:jqmData(position='fixed')" ).addClass('ui-header-fixed ui-fixed-inline fade'); //should be slidedown
  2719. $this.find( ".ui-footer:jqmData(position='fixed')" ).addClass('ui-footer-fixed ui-fixed-inline fade'); //should be slideup
  2720. });
  2721. };
  2722. //single controller for all showing,hiding,toggling
  2723. $.fixedToolbars = (function(){
  2724. if( !$.support.scrollTop ){ return; }
  2725. var currentstate = 'inline',
  2726. autoHideMode = false,
  2727. showDelay = 100,
  2728. delayTimer,
  2729. ignoreTargets = 'a,input,textarea,select,button,label,.ui-header-fixed,.ui-footer-fixed',
  2730. toolbarSelector = '.ui-header-fixed:first, .ui-footer-fixed:not(.ui-footer-duplicate):last',
  2731. stickyFooter, //for storing quick references to duplicate footers
  2732. supportTouch = $.support.touch,
  2733. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  2734. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  2735. stateBefore = null,
  2736. scrollTriggered = false,
  2737. touchToggleEnabled = true;
  2738. function showEventCallback(event)
  2739. {
  2740. // An event that affects the dimensions of the visual viewport has
  2741. // been triggered. If the header and/or footer for the current page are in overlay
  2742. // mode, we want to hide them, and then fire off a timer to show them at a later
  2743. // point. Events like a resize can be triggered continuously during a scroll, on
  2744. // some platforms, so the timer is used to delay the actual positioning until the
  2745. // flood of events have subsided.
  2746. //
  2747. // If we are in autoHideMode, we don't do anything because we know the scroll
  2748. // callbacks for the plugin will fire off a show when the scrolling has stopped.
  2749. if (!autoHideMode && currentstate == 'overlay') {
  2750. if (!delayTimer)
  2751. $.fixedToolbars.hide(true);
  2752. $.fixedToolbars.startShowTimer();
  2753. }
  2754. }
  2755. $(function() {
  2756. $(document)
  2757. .bind( "vmousedown",function(event){
  2758. if( touchToggleEnabled ) {
  2759. stateBefore = currentstate;
  2760. }
  2761. })
  2762. .bind( "vclick",function(event){
  2763. if( touchToggleEnabled ) {
  2764. if( $(event.target).closest(ignoreTargets).length ){ return; }
  2765. if( !scrollTriggered ){
  2766. $.fixedToolbars.toggle(stateBefore);
  2767. stateBefore = null;
  2768. }
  2769. }
  2770. })
  2771. .bind('silentscroll', showEventCallback);
  2772. /*
  2773. The below checks first for a $(document).scrollTop() value, and if zero, binds scroll events to $(window) instead. If the scrollTop value is actually zero, both will return zero anyway.
  2774. Works with $(document), not $(window) : Opera Mobile (WinMO phone; kinda broken anyway)
  2775. Works with $(window), not $(document) : IE 7/8
  2776. Works with either $(window) or $(document) : Chrome, FF 3.6/4, Android 1.6/2.1, iOS
  2777. Needs work either way : BB5, Opera Mobile (iOS)
  2778. */
  2779. (( $(document).scrollTop() == 0 ) ? $(window) : $(document))
  2780. .bind('scrollstart',function(event){
  2781. scrollTriggered = true;
  2782. if(stateBefore == null){ stateBefore = currentstate; }
  2783. // We only enter autoHideMode if the headers/footers are in
  2784. // an overlay state or the show timer was started. If the
  2785. // show timer is set, clear it so the headers/footers don't
  2786. // show up until after we're done scrolling.
  2787. var isOverlayState = stateBefore == 'overlay';
  2788. autoHideMode = isOverlayState || !!delayTimer;
  2789. if (autoHideMode){
  2790. $.fixedToolbars.clearShowTimer();
  2791. if (isOverlayState) {
  2792. $.fixedToolbars.hide(true);
  2793. }
  2794. }
  2795. })
  2796. .bind('scrollstop',function(event){
  2797. if( $(event.target).closest(ignoreTargets).length ){ return; }
  2798. scrollTriggered = false;
  2799. if (autoHideMode) {
  2800. autoHideMode = false;
  2801. $.fixedToolbars.startShowTimer();
  2802. }
  2803. stateBefore = null;
  2804. });
  2805. $(window).bind('resize', showEventCallback);
  2806. });
  2807. //before page is shown, check for duplicate footer
  2808. $('.ui-page').live('pagebeforeshow', function(event, ui){
  2809. var page = $(event.target),
  2810. footer = page.find( ":jqmData(role='footer')" ),
  2811. id = footer.data('id'),
  2812. prevPage = ui.prevPage,
  2813. prevFooter = prevPage && prevPage.find( ":jqmData(role='footer')" ),
  2814. prevFooterMatches = prevFooter.length && prevFooter.jqmData( "id" ) === id;
  2815. if( id && prevFooterMatches ){
  2816. stickyFooter = footer;
  2817. setTop( stickyFooter.removeClass( "fade in out" ).appendTo( $.mobile.pageContainer ) );
  2818. }
  2819. });
  2820. //after page is shown, append footer to new page
  2821. $('.ui-page').live('pageshow', function(event, ui){
  2822. var $this = $(this);
  2823. if( stickyFooter && stickyFooter.length ){
  2824. setTimeout(function(){
  2825. setTop( stickyFooter.appendTo( $this ).addClass("fade") );
  2826. stickyFooter = null;
  2827. }, 500);
  2828. }
  2829. $.fixedToolbars.show(true, this);
  2830. });
  2831. //When a collapsiable is hidden or shown we need to trigger the fixed toolbar to reposition itself (#1635)
  2832. $( ".ui-collapsible-contain" ).live( "collapse expand", showEventCallback );
  2833. // element.getBoundingClientRect() is broken in iOS 3.2.1 on the iPad. The
  2834. // coordinates inside of the rect it returns don't have the page scroll position
  2835. // factored out of it like the other platforms do. To get around this,
  2836. // we'll just calculate the top offset the old fashioned way until core has
  2837. // a chance to figure out how to handle this situation.
  2838. //
  2839. // TODO: We'll need to get rid of getOffsetTop() once a fix gets folded into core.
  2840. function getOffsetTop(ele)
  2841. {
  2842. var top = 0;
  2843. if (ele)
  2844. {
  2845. var op = ele.offsetParent, body = document.body;
  2846. top = ele.offsetTop;
  2847. while (ele && ele != body)
  2848. {
  2849. top += ele.scrollTop || 0;
  2850. if (ele == op)
  2851. {
  2852. top += op.offsetTop;
  2853. op = ele.offsetParent;
  2854. }
  2855. ele = ele.parentNode;
  2856. }
  2857. }
  2858. return top;
  2859. }
  2860. function setTop(el){
  2861. var fromTop = $(window).scrollTop(),
  2862. thisTop = getOffsetTop(el[0]), // el.offset().top returns the wrong value on iPad iOS 3.2.1, call our workaround instead.
  2863. thisCSStop = el.css('top') == 'auto' ? 0 : parseFloat(el.css('top')),
  2864. screenHeight = window.innerHeight,
  2865. thisHeight = el.outerHeight(),
  2866. useRelative = el.parents('.ui-page:not(.ui-page-fullscreen)').length,
  2867. relval;
  2868. if( el.is('.ui-header-fixed') ){
  2869. relval = fromTop - thisTop + thisCSStop;
  2870. if( relval < thisTop){ relval = 0; }
  2871. return el.css('top', ( useRelative ) ? relval : fromTop);
  2872. }
  2873. else{
  2874. //relval = -1 * (thisTop - (fromTop + screenHeight) + thisCSStop + thisHeight);
  2875. //if( relval > thisTop ){ relval = 0; }
  2876. relval = fromTop + screenHeight - thisHeight - (thisTop - thisCSStop);
  2877. return el.css('top', ( useRelative ) ? relval : fromTop + screenHeight - thisHeight );
  2878. }
  2879. }
  2880. //exposed methods
  2881. return {
  2882. show: function(immediately, page){
  2883. $.fixedToolbars.clearShowTimer();
  2884. currentstate = 'overlay';
  2885. var $ap = page ? $(page) : ($.mobile.activePage ? $.mobile.activePage : $(".ui-page-active"));
  2886. return $ap.children( toolbarSelector ).each(function(){
  2887. var el = $(this),
  2888. fromTop = $(window).scrollTop(),
  2889. thisTop = getOffsetTop(el[0]), // el.offset().top returns the wrong value on iPad iOS 3.2.1, call our workaround instead.
  2890. screenHeight = window.innerHeight,
  2891. thisHeight = el.outerHeight(),
  2892. alreadyVisible = (el.is('.ui-header-fixed') && fromTop <= thisTop + thisHeight) || (el.is('.ui-footer-fixed') && thisTop <= fromTop + screenHeight);
  2893. //add state class
  2894. el.addClass('ui-fixed-overlay').removeClass('ui-fixed-inline');
  2895. if( !alreadyVisible && !immediately ){
  2896. el.animationComplete(function(){
  2897. el.removeClass('in');
  2898. }).addClass('in');
  2899. }
  2900. setTop(el);
  2901. });
  2902. },
  2903. hide: function(immediately){
  2904. currentstate = 'inline';
  2905. var $ap = $.mobile.activePage ? $.mobile.activePage : $(".ui-page-active");
  2906. return $ap.children( toolbarSelector ).each(function(){
  2907. var el = $(this);
  2908. var thisCSStop = el.css('top'); thisCSStop = thisCSStop == 'auto' ? 0 : parseFloat(thisCSStop);
  2909. //add state class
  2910. el.addClass('ui-fixed-inline').removeClass('ui-fixed-overlay');
  2911. if (thisCSStop < 0 || (el.is('.ui-header-fixed') && thisCSStop != 0))
  2912. {
  2913. if(immediately){
  2914. el.css('top',0);
  2915. }
  2916. else{
  2917. if( el.css('top') !== 'auto' && parseFloat(el.css('top')) !== 0 ){
  2918. var classes = 'out reverse';
  2919. el.animationComplete(function(){
  2920. el.removeClass(classes);
  2921. el.css('top',0);
  2922. }).addClass(classes);
  2923. }
  2924. }
  2925. }
  2926. });
  2927. },
  2928. startShowTimer: function(){
  2929. $.fixedToolbars.clearShowTimer();
  2930. var args = $.makeArray(arguments);
  2931. delayTimer = setTimeout(function(){
  2932. delayTimer = undefined;
  2933. $.fixedToolbars.show.apply(null, args);
  2934. }, showDelay);
  2935. },
  2936. clearShowTimer: function() {
  2937. if (delayTimer) {
  2938. clearTimeout(delayTimer);
  2939. }
  2940. delayTimer = undefined;
  2941. },
  2942. toggle: function(from){
  2943. if(from){ currentstate = from; }
  2944. return (currentstate == 'overlay') ? $.fixedToolbars.hide() : $.fixedToolbars.show();
  2945. },
  2946. setTouchToggleEnabled: function(enabled) {
  2947. touchToggleEnabled = enabled;
  2948. }
  2949. };
  2950. })();
  2951. })(jQuery);
  2952. /*
  2953. * jQuery Mobile Framework : "checkboxradio" plugin
  2954. * Copyright (c) jQuery Project
  2955. * Dual licensed under the MIT or GPL Version 2 licenses.
  2956. * http://jquery.org/license
  2957. */
  2958. (function($, undefined ) {
  2959. $.widget( "mobile.checkboxradio", $.mobile.widget, {
  2960. options: {
  2961. theme: null
  2962. },
  2963. _create: function(){
  2964. var self = this,
  2965. input = this.element,
  2966. //NOTE: Windows Phone could not find the label through a selector
  2967. //filter works though.
  2968. label = input.closest("form,fieldset,:jqmData(role='page')").find("label").filter('[for="' + input[0].id + '"]'),
  2969. inputtype = input.attr( "type" ),
  2970. checkedicon = "ui-icon-" + inputtype + "-on",
  2971. uncheckedicon = "ui-icon-" + inputtype + "-off";
  2972. if ( inputtype != "checkbox" && inputtype != "radio" ) { return; }
  2973. //expose for other methods
  2974. $.extend( this,{
  2975. label : label,
  2976. inputtype : inputtype,
  2977. checkedicon : checkedicon,
  2978. uncheckedicon : uncheckedicon
  2979. });
  2980. // If there's no selected theme...
  2981. if( !this.options.theme ) {
  2982. this.options.theme = this.element.jqmData( "theme" );
  2983. }
  2984. label
  2985. .buttonMarkup({
  2986. theme: this.options.theme,
  2987. icon: this.element.parents( ":jqmData(type='horizontal')" ).length ? undefined : uncheckedicon,
  2988. shadow: false
  2989. });
  2990. // wrap the input + label in a div
  2991. input
  2992. .add( label )
  2993. .wrapAll( "<div class='ui-" + inputtype +"'></div>" );
  2994. label.bind({
  2995. vmouseover: function() {
  2996. if( $(this).parent().is('.ui-disabled') ){ return false; }
  2997. },
  2998. vclick: function( event ){
  2999. if ( input.is( ":disabled" ) ){
  3000. event.preventDefault();
  3001. return;
  3002. }
  3003. self._cacheVals();
  3004. input.prop( "checked", inputtype === "radio" && true || !(input.prop("checked")) );
  3005. // input set for common radio buttons will contain all the radio
  3006. // buttons, but will not for checkboxes. clearing the checked status
  3007. // of other radios ensures the active button state is applied properly
  3008. self._getInputSet().not(input).prop('checked', false);
  3009. self._updateAll();
  3010. return false;
  3011. }
  3012. });
  3013. input
  3014. .bind({
  3015. vmousedown: function(){
  3016. this._cacheVals();
  3017. },
  3018. vclick: function(){
  3019. // adds checked attribute to checked input when keyboard is used
  3020. if ($(this).is(":checked")) {
  3021. $(this).prop( "checked", true);
  3022. self._getInputSet().not($(this)).prop('checked', false);
  3023. } else {
  3024. $(this).prop("checked", false);
  3025. }
  3026. self._updateAll();
  3027. },
  3028. focus: function() {
  3029. label.addClass( "ui-focus" );
  3030. },
  3031. blur: function() {
  3032. label.removeClass( "ui-focus" );
  3033. }
  3034. });
  3035. this.refresh();
  3036. },
  3037. _cacheVals: function(){
  3038. this._getInputSet().each(function(){
  3039. $(this).jqmData("cacheVal", $(this).is(":checked") );
  3040. });
  3041. },
  3042. //returns either a set of radios with the same name attribute, or a single checkbox
  3043. _getInputSet: function(){
  3044. return this.element.closest( "form,fieldset,:jqmData(role='page')" )
  3045. .find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.inputtype +"']" );
  3046. },
  3047. _updateAll: function(){
  3048. var self = this;
  3049. this._getInputSet().each(function(){
  3050. if( $(this).is(":checked") || self.inputtype === "checkbox" ){
  3051. $(this).trigger("change");
  3052. }
  3053. })
  3054. .checkboxradio( "refresh" );
  3055. },
  3056. refresh: function( ){
  3057. var input = this.element,
  3058. label = this.label,
  3059. icon = label.find( ".ui-icon" );
  3060. // input[0].checked expando doesn't always report the proper value
  3061. // for checked='checked'
  3062. if ( $(input[0]).prop('checked') ) {
  3063. label.addClass( $.mobile.activeBtnClass );
  3064. icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
  3065. } else {
  3066. label.removeClass( $.mobile.activeBtnClass );
  3067. icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
  3068. }
  3069. if( input.is( ":disabled" ) ){
  3070. this.disable();
  3071. }
  3072. else {
  3073. this.enable();
  3074. }
  3075. },
  3076. disable: function(){
  3077. this.element.prop("disabled",true).parent().addClass("ui-disabled");
  3078. },
  3079. enable: function(){
  3080. this.element.prop("disabled",false).parent().removeClass("ui-disabled");
  3081. }
  3082. });
  3083. })( jQuery );
  3084. /*
  3085. * jQuery Mobile Framework : "textinput" plugin for text inputs, textareas
  3086. * Copyright (c) jQuery Project
  3087. * Dual licensed under the MIT or GPL Version 2 licenses.
  3088. * http://jquery.org/license
  3089. */
  3090. (function($, undefined ) {
  3091. $.widget( "mobile.textinput", $.mobile.widget, {
  3092. options: {
  3093. theme: null
  3094. },
  3095. _create: function(){
  3096. var input = this.element,
  3097. o = this.options,
  3098. theme = o.theme,
  3099. themeclass;
  3100. if ( !theme ) {
  3101. var themedParent = this.element.closest("[class*='ui-bar-'],[class*='ui-body-']"),
  3102. themeLetter = themedParent.length && /ui-(bar|body)-([a-z])/.exec( themedParent.attr("class") ),
  3103. theme = themeLetter && themeLetter[2] || "c";
  3104. }
  3105. themeclass = " ui-body-" + theme;
  3106. $('label[for="'+input.attr('id')+'"]').addClass('ui-input-text');
  3107. input.addClass('ui-input-text ui-body-'+ o.theme);
  3108. var focusedEl = input;
  3109. //"search" input widget
  3110. if( input.is( "[type='search'],:jqmData(type='search')" ) ){
  3111. focusedEl = input.wrap('<div class="ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield'+ themeclass +'"></div>').parent();
  3112. var clearbtn = $('<a href="#" class="ui-input-clear" title="clear text">clear text</a>')
  3113. .tap(function( e ){
  3114. input.val('').focus();
  3115. input.trigger('change');
  3116. clearbtn.addClass('ui-input-clear-hidden');
  3117. e.preventDefault();
  3118. })
  3119. .appendTo(focusedEl)
  3120. .buttonMarkup({icon: 'delete', iconpos: 'notext', corners:true, shadow:true});
  3121. function toggleClear(){
  3122. if(input.val() == ''){
  3123. clearbtn.addClass('ui-input-clear-hidden');
  3124. }
  3125. else{
  3126. clearbtn.removeClass('ui-input-clear-hidden');
  3127. }
  3128. }
  3129. toggleClear();
  3130. input.keyup(toggleClear);
  3131. input.focus(toggleClear);
  3132. }
  3133. else{
  3134. input.addClass('ui-corner-all ui-shadow-inset' + themeclass);
  3135. }
  3136. input
  3137. .focus(function(){
  3138. focusedEl.addClass('ui-focus');
  3139. })
  3140. .blur(function(){
  3141. focusedEl.removeClass('ui-focus');
  3142. });
  3143. //autogrow
  3144. if ( input.is('textarea') ) {
  3145. var extraLineHeight = 15,
  3146. keyupTimeoutBuffer = 100,
  3147. keyup = function() {
  3148. var scrollHeight = input[0].scrollHeight,
  3149. clientHeight = input[0].clientHeight;
  3150. if ( clientHeight < scrollHeight ) {
  3151. input.css({ height: (scrollHeight + extraLineHeight) });
  3152. }
  3153. },
  3154. keyupTimeout;
  3155. input.keyup(function() {
  3156. clearTimeout( keyupTimeout );
  3157. keyupTimeout = setTimeout( keyup, keyupTimeoutBuffer );
  3158. });
  3159. }
  3160. },
  3161. disable: function(){
  3162. ( this.element.attr("disabled",true).is( "[type='search'],:jqmData(type='search')" ) ? this.element.parent() : this.element ).addClass("ui-disabled");
  3163. },
  3164. enable: function(){
  3165. ( this.element.attr("disabled", false).is( "[type='search'],:jqmData(type='search')" ) ? this.element.parent() : this.element ).removeClass("ui-disabled");
  3166. }
  3167. });
  3168. })( jQuery );
  3169. /*
  3170. * jQuery Mobile Framework : "selectmenu" plugin
  3171. * Copyright (c) jQuery Project
  3172. * Dual licensed under the MIT or GPL Version 2 licenses.
  3173. * http://jquery.org/license
  3174. */
  3175. (function($, undefined ) {
  3176. $.widget( "mobile.selectmenu", $.mobile.widget, {
  3177. options: {
  3178. theme: null,
  3179. disabled: false,
  3180. icon: 'arrow-d',
  3181. iconpos: 'right',
  3182. inline: null,
  3183. corners: true,
  3184. shadow: true,
  3185. iconshadow: true,
  3186. menuPageTheme: 'b',
  3187. overlayTheme: 'a',
  3188. hidePlaceholderMenuItems: true,
  3189. closeText: 'Close',
  3190. nativeMenu: true
  3191. },
  3192. _create: function(){
  3193. var self = this,
  3194. o = this.options,
  3195. select = this.element
  3196. .wrap( "<div class='ui-select'>" ),
  3197. selectID = select.attr( "id" ),
  3198. label = $( 'label[for="'+ selectID +'"]' ).addClass( "ui-select" ),
  3199. //IE throws an exception at options.item() function when
  3200. //there is no selected item
  3201. //select first in this case
  3202. selectedIndex = select[0].selectedIndex == -1 ? 0 : select[0].selectedIndex,
  3203. button = ( self.options.nativeMenu ? $( "<div/>" ) : $( "<a>", {
  3204. "href": "#",
  3205. "role": "button",
  3206. "id": buttonId,
  3207. "aria-haspopup": "true",
  3208. "aria-owns": menuId
  3209. }) )
  3210. .text( $( select[0].options.item( selectedIndex ) ).text() )
  3211. .insertBefore( select )
  3212. .buttonMarkup({
  3213. theme: o.theme,
  3214. icon: o.icon,
  3215. iconpos: o.iconpos,
  3216. inline: o.inline,
  3217. corners: o.corners,
  3218. shadow: o.shadow,
  3219. iconshadow: o.iconshadow
  3220. }),
  3221. //multi select or not
  3222. isMultiple = self.isMultiple = select[0].multiple;
  3223. //Opera does not properly support opacity on select elements
  3224. //In Mini, it hides the element, but not its text
  3225. //On the desktop,it seems to do the opposite
  3226. //for these reasons, using the nativeMenu option results in a full native select in Opera
  3227. if( o.nativeMenu && window.opera && window.opera.version ){
  3228. select.addClass( "ui-select-nativeonly" );
  3229. }
  3230. //vars for non-native menus
  3231. if( !o.nativeMenu ){
  3232. var options = select.find("option"),
  3233. buttonId = selectID + "-button",
  3234. menuId = selectID + "-menu",
  3235. thisPage = select.closest( ".ui-page" ),
  3236. //button theme
  3237. theme = /ui-btn-up-([a-z])/.exec( button.attr("class") )[1],
  3238. menuPage = $( "<div data-" + $.mobile.ns + "role='dialog' data-" +$.mobile.ns + "theme='"+ o.menuPageTheme +"'>" +
  3239. "<div data-" + $.mobile.ns + "role='header'>" +
  3240. "<div class='ui-title'>" + label.text() + "</div>"+
  3241. "</div>"+
  3242. "<div data-" + $.mobile.ns + "role='content'></div>"+
  3243. "</div>" )
  3244. .appendTo( $.mobile.pageContainer )
  3245. .page(),
  3246. menuPageContent = menuPage.find( ".ui-content" ),
  3247. menuPageClose = menuPage.find( ".ui-header a" ),
  3248. screen = $( "<div>", {"class": "ui-selectmenu-screen ui-screen-hidden"})
  3249. .appendTo( thisPage ),
  3250. listbox = $( "<div>", { "class": "ui-selectmenu ui-selectmenu-hidden ui-overlay-shadow ui-corner-all pop ui-body-" + o.overlayTheme } )
  3251. .insertAfter(screen),
  3252. list = $( "<ul>", {
  3253. "class": "ui-selectmenu-list",
  3254. "id": menuId,
  3255. "role": "listbox",
  3256. "aria-labelledby": buttonId
  3257. })
  3258. .attr( "data-" + $.mobile.ns + "theme", theme )
  3259. .appendTo( listbox ),
  3260. header = $( "<div>", {
  3261. "class": "ui-header ui-bar-" + theme
  3262. })
  3263. .prependTo( listbox ),
  3264. headerTitle = $( "<h1>", {
  3265. "class": "ui-title"
  3266. })
  3267. .appendTo( header ),
  3268. headerClose = $( "<a>", {
  3269. "text": o.closeText,
  3270. "href": "#",
  3271. "class": "ui-btn-left"
  3272. })
  3273. .attr( "data-" + $.mobile.ns + "iconpos", "notext" )
  3274. .attr( "data-" + $.mobile.ns + "icon", "delete" )
  3275. .appendTo( header )
  3276. .buttonMarkup(),
  3277. menuType;
  3278. } //end non native vars
  3279. // add counter for multi selects
  3280. if( isMultiple ){
  3281. self.buttonCount = $('<span>')
  3282. .addClass( 'ui-li-count ui-btn-up-c ui-btn-corner-all' )
  3283. .hide()
  3284. .appendTo( button );
  3285. }
  3286. //disable if specified
  3287. if( o.disabled ){ this.disable(); }
  3288. //events on native select
  3289. select
  3290. .change(function(){
  3291. self.refresh();
  3292. });
  3293. //expose to other methods
  3294. $.extend(self, {
  3295. select: select,
  3296. optionElems: options,
  3297. selectID: selectID,
  3298. label: label,
  3299. buttonId:buttonId,
  3300. menuId:menuId,
  3301. thisPage:thisPage,
  3302. button:button,
  3303. menuPage:menuPage,
  3304. menuPageContent:menuPageContent,
  3305. screen:screen,
  3306. listbox:listbox,
  3307. list:list,
  3308. menuType:menuType,
  3309. header:header,
  3310. headerClose:headerClose,
  3311. headerTitle:headerTitle,
  3312. placeholder: ''
  3313. });
  3314. //support for using the native select menu with a custom button
  3315. if( o.nativeMenu ){
  3316. select
  3317. .appendTo(button)
  3318. .bind( "vmousedown", function( e ){
  3319. //add active class to button
  3320. button.addClass( $.mobile.activeBtnClass );
  3321. })
  3322. .bind( "focus vmouseover", function(){
  3323. button.trigger( "vmouseover" );
  3324. })
  3325. .bind( "vmousemove", function(){
  3326. //remove active class on scroll/touchmove
  3327. button.removeClass( $.mobile.activeBtnClass );
  3328. })
  3329. .bind( "change blur vmouseout", function(){
  3330. button
  3331. .trigger( "vmouseout" )
  3332. .removeClass( $.mobile.activeBtnClass );
  3333. });
  3334. } else {
  3335. //create list from select, update state
  3336. self.refresh();
  3337. select
  3338. .attr( "tabindex", "-1" )
  3339. .focus(function(){
  3340. $(this).blur();
  3341. button.focus();
  3342. });
  3343. //button events
  3344. button
  3345. .bind( "vclick keydown" , function( event ){
  3346. if( event.type == "vclick" ||
  3347. event.keyCode && ( event.keyCode === $.mobile.keyCode.ENTER || event.keyCode === $.mobile.keyCode.SPACE ) ){
  3348. self.open();
  3349. event.preventDefault();
  3350. }
  3351. });
  3352. //events for list items
  3353. list
  3354. .attr( "role", "listbox" )
  3355. .delegate( ".ui-li>a", "focusin", function() {
  3356. $( this ).attr( "tabindex", "0" );
  3357. })
  3358. .delegate( ".ui-li>a", "focusout", function() {
  3359. $( this ).attr( "tabindex", "-1" );
  3360. })
  3361. .delegate("li:not(.ui-disabled, .ui-li-divider)", "vclick", function(event){
  3362. // index of option tag to be selected
  3363. var oldIndex = select[0].selectedIndex,
  3364. newIndex = list.find( "li:not(.ui-li-divider)" ).index( this ),
  3365. option = self.optionElems.eq( newIndex )[0];
  3366. // toggle selected status on the tag for multi selects
  3367. option.selected = isMultiple ? !option.selected : true;
  3368. // toggle checkbox class for multiple selects
  3369. if( isMultiple ){
  3370. $(this)
  3371. .find('.ui-icon')
  3372. .toggleClass('ui-icon-checkbox-on', option.selected)
  3373. .toggleClass('ui-icon-checkbox-off', !option.selected);
  3374. }
  3375. // trigger change if value changed
  3376. if( isMultiple || oldIndex !== newIndex ){
  3377. select.trigger( "change" );
  3378. }
  3379. //hide custom select for single selects only
  3380. if( !isMultiple ){
  3381. self.close();
  3382. }
  3383. event.preventDefault();
  3384. })
  3385. //keyboard events for menu items
  3386. .keydown(function( e ) {
  3387. var target = $( e.target ),
  3388. li = target.closest( "li" );
  3389. // switch logic based on which key was pressed
  3390. switch ( e.keyCode ) {
  3391. // up or left arrow keys
  3392. case 38:
  3393. var prev = li.prev();
  3394. // if there's a previous option, focus it
  3395. if ( prev.length ) {
  3396. target
  3397. .blur()
  3398. .attr( "tabindex", "-1" );
  3399. prev.find( "a" ).first().focus();
  3400. }
  3401. return false;
  3402. break;
  3403. // down or right arrow keys
  3404. case 40:
  3405. var next = li.next();
  3406. // if there's a next option, focus it
  3407. if ( next.length ) {
  3408. target
  3409. .blur()
  3410. .attr( "tabindex", "-1" );
  3411. next.find( "a" ).first().focus();
  3412. }
  3413. return false;
  3414. break;
  3415. // if enter or space is pressed, trigger click
  3416. case 13:
  3417. case 32:
  3418. target.trigger( "vclick" );
  3419. return false;
  3420. break;
  3421. }
  3422. });
  3423. //events on "screen" overlay
  3424. screen.bind("vclick", function( event ){
  3425. self.close();
  3426. });
  3427. //close button on small overlays
  3428. self.headerClose.click(function(){
  3429. if( self.menuType == "overlay" ){
  3430. self.close();
  3431. return false;
  3432. }
  3433. })
  3434. }
  3435. },
  3436. _buildList: function(){
  3437. var self = this,
  3438. o = this.options,
  3439. placeholder = this.placeholder,
  3440. optgroups = [],
  3441. lis = [],
  3442. dataIcon = self.isMultiple ? "checkbox-off" : "false";
  3443. self.list.empty().filter('.ui-listview').listview('destroy');
  3444. //populate menu with options from select element
  3445. self.select.find( "option" ).each(function( i ){
  3446. var $this = $(this),
  3447. $parent = $this.parent(),
  3448. text = $this.text(),
  3449. anchor = "<a href='#'>"+ text +"</a>",
  3450. classes = [],
  3451. extraAttrs = [];
  3452. // are we inside an optgroup?
  3453. if( $parent.is("optgroup") ){
  3454. var optLabel = $parent.attr("label");
  3455. // has this optgroup already been built yet?
  3456. if( $.inArray(optLabel, optgroups) === -1 ){
  3457. lis.push( "<li data-" + $.mobile.ns + "role='list-divider'>"+ optLabel +"</li>" );
  3458. optgroups.push( optLabel );
  3459. }
  3460. }
  3461. //find placeholder text
  3462. if( !this.getAttribute('value') || text.length == 0 || $this.jqmData('placeholder') ){
  3463. if( o.hidePlaceholderMenuItems ){
  3464. classes.push( "ui-selectmenu-placeholder" );
  3465. }
  3466. placeholder = self.placeholder = text;
  3467. }
  3468. // support disabled option tags
  3469. if( this.disabled ){
  3470. classes.push( "ui-disabled" );
  3471. extraAttrs.push( "aria-disabled='true'" );
  3472. }
  3473. lis.push( "<li data-" + $.mobile.ns + "icon='"+ dataIcon +"' class='"+ classes.join(" ") + "' " + extraAttrs.join(" ") +">"+ anchor +"</li>" )
  3474. });
  3475. self.list.html( lis.join(" ") );
  3476. self.list.find( "li" )
  3477. .attr({ "role": "option", "tabindex": "-1" })
  3478. .first().attr( "tabindex", "0" );
  3479. // hide header close link for single selects
  3480. if( !this.isMultiple ){
  3481. this.headerClose.hide();
  3482. }
  3483. // hide header if it's not a multiselect and there's no placeholder
  3484. if( !this.isMultiple && !placeholder.length ){
  3485. this.header.hide();
  3486. } else {
  3487. this.headerTitle.text( this.placeholder );
  3488. }
  3489. //now populated, create listview
  3490. self.list.listview();
  3491. },
  3492. refresh: function( forceRebuild ){
  3493. var self = this,
  3494. select = this.element,
  3495. isMultiple = this.isMultiple,
  3496. options = this.optionElems = select.find("option"),
  3497. selected = options.filter(":selected"),
  3498. // return an array of all selected index's
  3499. indicies = selected.map(function(){
  3500. return options.index( this );
  3501. }).get();
  3502. if( !self.options.nativeMenu && ( forceRebuild || select[0].options.length != self.list.find('li').length )){
  3503. self._buildList();
  3504. }
  3505. self.button
  3506. .find( ".ui-btn-text" )
  3507. .text(function(){
  3508. if( !isMultiple ){
  3509. return selected.text();
  3510. }
  3511. return selected.length ?
  3512. selected.map(function(){ return $(this).text(); }).get().join(', ') :
  3513. self.placeholder;
  3514. });
  3515. // multiple count inside button
  3516. if( isMultiple ){
  3517. self.buttonCount[ selected.length > 1 ? 'show' : 'hide' ]().text( selected.length );
  3518. }
  3519. if( !self.options.nativeMenu ){
  3520. self.list
  3521. .find( 'li:not(.ui-li-divider)' )
  3522. .removeClass( $.mobile.activeBtnClass )
  3523. .attr( 'aria-selected', false )
  3524. .each(function( i ){
  3525. if( $.inArray(i, indicies) > -1 ){
  3526. var item = $(this).addClass( $.mobile.activeBtnClass );
  3527. // aria selected attr
  3528. item.find( 'a' ).attr( 'aria-selected', true );
  3529. // multiple selects: add the "on" checkbox state to the icon
  3530. if( isMultiple ){
  3531. item.find('.ui-icon').removeClass('ui-icon-checkbox-off').addClass('ui-icon-checkbox-on');
  3532. }
  3533. }
  3534. });
  3535. }
  3536. },
  3537. open: function(){
  3538. if( this.options.disabled || this.options.nativeMenu ){ return; }
  3539. var self = this,
  3540. menuHeight = self.list.parent().outerHeight(),
  3541. menuWidth = self.list.parent().outerWidth(),
  3542. scrollTop = $(window).scrollTop(),
  3543. btnOffset = self.button.offset().top,
  3544. screenHeight = window.innerHeight,
  3545. screenWidth = window.innerWidth;
  3546. //add active class to button
  3547. self.button.addClass( $.mobile.activeBtnClass );
  3548. //remove after delay
  3549. setTimeout(function(){
  3550. self.button.removeClass( $.mobile.activeBtnClass );
  3551. }, 300);
  3552. function focusMenuItem(){
  3553. self.list.find( ".ui-btn-active" ).focus();
  3554. }
  3555. if( menuHeight > screenHeight - 80 || !$.support.scrollTop ){
  3556. //for webos (set lastscroll using button offset)
  3557. if( scrollTop == 0 && btnOffset > screenHeight ){
  3558. self.thisPage.one('pagehide',function(){
  3559. $(this).jqmData('lastScroll', btnOffset);
  3560. });
  3561. }
  3562. self.menuPage.one('pageshow', function() {
  3563. // silentScroll() is called whenever a page is shown to restore
  3564. // any previous scroll position the page may have had. We need to
  3565. // wait for the "silentscroll" event before setting focus to avoid
  3566. // the browser's "feature" which offsets rendering to make sure
  3567. // whatever has focus is in view.
  3568. $(window).one("silentscroll", function(){ focusMenuItem(); });
  3569. });
  3570. self.menuType = "page";
  3571. self.menuPageContent.append( self.list );
  3572. $.mobile.changePage( self.menuPage, { transition: 'pop' } );
  3573. }
  3574. else {
  3575. self.menuType = "overlay";
  3576. self.screen
  3577. .height( $(document).height() )
  3578. .removeClass('ui-screen-hidden');
  3579. //try and center the overlay over the button
  3580. var roomtop = btnOffset - scrollTop,
  3581. roombot = scrollTop + screenHeight - btnOffset,
  3582. halfheight = menuHeight / 2,
  3583. maxwidth = parseFloat(self.list.parent().css('max-width')),
  3584. newtop, newleft;
  3585. if( roomtop > menuHeight / 2 && roombot > menuHeight / 2 ){
  3586. newtop = btnOffset + ( self.button.outerHeight() / 2 ) - halfheight;
  3587. }
  3588. else{
  3589. //30px tolerance off the edges
  3590. newtop = roomtop > roombot ? scrollTop + screenHeight - menuHeight - 30 : scrollTop + 30;
  3591. }
  3592. // if the menuwidth is smaller than the screen center is
  3593. if (menuWidth < maxwidth) {
  3594. newleft = (screenWidth - menuWidth) / 2;
  3595. } else { //otherwise insure a >= 30px offset from the left
  3596. newleft = self.button.offset().left + self.button.outerWidth() / 2 - menuWidth / 2;
  3597. // 30px tolerance off the edges
  3598. if (newleft < 30) {
  3599. newleft = 30;
  3600. } else if ((newleft + menuWidth) > screenWidth) {
  3601. newleft = screenWidth - menuWidth - 30;
  3602. }
  3603. }
  3604. self.listbox
  3605. .append( self.list )
  3606. .removeClass( "ui-selectmenu-hidden" )
  3607. .css({
  3608. top: newtop,
  3609. left: newleft
  3610. })
  3611. .addClass("in");
  3612. focusMenuItem();
  3613. }
  3614. // wait before the dialog can be closed
  3615. setTimeout(function(){
  3616. self.isOpen = true;
  3617. }, 400);
  3618. },
  3619. close: function(){
  3620. if( this.options.disabled || !this.isOpen || this.options.nativeMenu ){ return; }
  3621. var self = this;
  3622. function focusButton(){
  3623. setTimeout(function(){
  3624. self.button.focus();
  3625. }, 40);
  3626. self.listbox.removeAttr('style').append( self.list );
  3627. }
  3628. if(self.menuType == "page"){
  3629. // button refocus ensures proper height calculation
  3630. // by removing the inline style and ensuring page inclusion
  3631. self.menuPage.one("pagehide", focusButton);
  3632. // doesn't solve the possible issue with calling change page
  3633. // where the objects don't define data urls which prevents dialog key
  3634. // stripping - changePage has incoming refactor
  3635. window.history.back();
  3636. }
  3637. else{
  3638. self.screen.addClass( "ui-screen-hidden" );
  3639. self.listbox.addClass( "ui-selectmenu-hidden" ).removeAttr( "style" ).removeClass("in");
  3640. focusButton();
  3641. }
  3642. // allow the dialog to be closed again
  3643. this.isOpen = false;
  3644. },
  3645. disable: function(){
  3646. this.element.attr("disabled",true);
  3647. this.button.addClass('ui-disabled').attr("aria-disabled", true);
  3648. return this._setOption( "disabled", true );
  3649. },
  3650. enable: function(){
  3651. this.element.attr("disabled",false);
  3652. this.button.removeClass('ui-disabled').attr("aria-disabled", false);
  3653. return this._setOption( "disabled", false );
  3654. }
  3655. });
  3656. })( jQuery );
  3657. /*
  3658. * jQuery Mobile Framework : plugin for making button-like links
  3659. * Copyright (c) jQuery Project
  3660. * Dual licensed under the MIT or GPL Version 2 licenses.
  3661. * http://jquery.org/license
  3662. */
  3663. ( function( $, undefined ) {
  3664. $.fn.buttonMarkup = function( options ) {
  3665. return this.each( function() {
  3666. var el = $( this ),
  3667. o = $.extend( {}, $.fn.buttonMarkup.defaults, el.jqmData(), options ),
  3668. // Classes Defined
  3669. buttonClass,
  3670. innerClass = "ui-btn-inner",
  3671. iconClass;
  3672. if ( attachEvents ) {
  3673. attachEvents();
  3674. }
  3675. // if not, try to find closest theme container
  3676. if ( !o.theme ) {
  3677. var themedParent = el.closest( "[class*='ui-bar-'],[class*='ui-body-']" );
  3678. o.theme = themedParent.length ?
  3679. /ui-(bar|body)-([a-z])/.exec( themedParent.attr( "class" ) )[2] :
  3680. "c";
  3681. }
  3682. buttonClass = "ui-btn ui-btn-up-" + o.theme;
  3683. if ( o.inline ) {
  3684. buttonClass += " ui-btn-inline";
  3685. }
  3686. if ( o.icon ) {
  3687. o.icon = "ui-icon-" + o.icon;
  3688. o.iconpos = o.iconpos || "left";
  3689. iconClass = "ui-icon " + o.icon;
  3690. if ( o.shadow ) {
  3691. iconClass += " ui-icon-shadow";
  3692. }
  3693. }
  3694. if ( o.iconpos ) {
  3695. buttonClass += " ui-btn-icon-" + o.iconpos;
  3696. if ( o.iconpos == "notext" && !el.attr( "title" ) ) {
  3697. el.attr( "title", el.text() );
  3698. }
  3699. }
  3700. if ( o.corners ) {
  3701. buttonClass += " ui-btn-corner-all";
  3702. innerClass += " ui-btn-corner-all";
  3703. }
  3704. if ( o.shadow ) {
  3705. buttonClass += " ui-shadow";
  3706. }
  3707. el
  3708. .attr( "data-" + $.mobile.ns + "theme", o.theme )
  3709. .addClass( buttonClass );
  3710. var wrap = ( "<D class='" + innerClass + "'><D class='ui-btn-text'></D>" +
  3711. ( o.icon ? "<span class='" + iconClass + "'></span>" : "" ) +
  3712. "</D>" ).replace( /D/g, o.wrapperEls );
  3713. el.wrapInner( wrap );
  3714. });
  3715. };
  3716. $.fn.buttonMarkup.defaults = {
  3717. corners: true,
  3718. shadow: true,
  3719. iconshadow: true,
  3720. wrapperEls: "span"
  3721. };
  3722. function closestEnabledButton( element )
  3723. {
  3724. while ( element ) {
  3725. var $ele = $( element );
  3726. if ( $ele.hasClass( "ui-btn" ) && !$ele.hasClass( "ui-disabled" ) ) {
  3727. break;
  3728. }
  3729. element = element.parentNode;
  3730. }
  3731. return element;
  3732. }
  3733. var attachEvents = function() {
  3734. $( document ).bind( {
  3735. "vmousedown": function( event ) {
  3736. var btn = closestEnabledButton( event.target );
  3737. if ( btn ) {
  3738. var $btn = $( btn ),
  3739. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  3740. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  3741. }
  3742. },
  3743. "vmousecancel vmouseup": function( event ) {
  3744. var btn = closestEnabledButton( event.target );
  3745. if ( btn ) {
  3746. var $btn = $( btn ),
  3747. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  3748. $btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  3749. }
  3750. },
  3751. "vmouseover focus": function( event ) {
  3752. var btn = closestEnabledButton( event.target );
  3753. if ( btn ) {
  3754. var $btn = $( btn ),
  3755. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  3756. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  3757. }
  3758. },
  3759. "vmouseout blur": function( event ) {
  3760. var btn = closestEnabledButton( event.target );
  3761. if ( btn ) {
  3762. var $btn = $( btn ),
  3763. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  3764. $btn.removeClass( "ui-btn-hover-" + theme ).addClass( "ui-btn-up-" + theme );
  3765. }
  3766. }
  3767. });
  3768. attachEvents = null;
  3769. };
  3770. })( jQuery );
  3771. /*
  3772. * jQuery Mobile Framework : "button" plugin - links that proxy to native input/buttons
  3773. * Copyright (c) jQuery Project
  3774. * Dual licensed under the MIT or GPL Version 2 licenses.
  3775. * http://jquery.org/license
  3776. */
  3777. (function($, undefined ) {
  3778. $.widget( "mobile.button", $.mobile.widget, {
  3779. options: {
  3780. theme: null,
  3781. icon: null,
  3782. iconpos: null,
  3783. inline: null,
  3784. corners: true,
  3785. shadow: true,
  3786. iconshadow: true
  3787. },
  3788. _create: function(){
  3789. var $el = this.element,
  3790. o = this.options;
  3791. //add ARIA role
  3792. this.button = $( "<div></div>" )
  3793. .text( $el.text() || $el.val() )
  3794. .buttonMarkup({
  3795. theme: o.theme,
  3796. icon: o.icon,
  3797. iconpos: o.iconpos,
  3798. inline: o.inline,
  3799. corners: o.corners,
  3800. shadow: o.shadow,
  3801. iconshadow: o.iconshadow
  3802. })
  3803. .insertBefore( $el )
  3804. .append( $el.addClass('ui-btn-hidden') );
  3805. //add hidden input during submit
  3806. var type = $el.attr('type');
  3807. if( type !== 'button' && type !== 'reset' ){
  3808. $el.bind("vclick", function(){
  3809. var $buttonPlaceholder = $("<input>",
  3810. {type: "hidden", name: $el.attr("name"), value: $el.attr("value")})
  3811. .insertBefore($el);
  3812. //bind to doc to remove after submit handling
  3813. $(document).submit(function(){
  3814. $buttonPlaceholder.remove();
  3815. });
  3816. });
  3817. }
  3818. this.refresh();
  3819. },
  3820. enable: function(){
  3821. this.element.attr("disabled", false);
  3822. this.button.removeClass("ui-disabled").attr("aria-disabled", false);
  3823. return this._setOption("disabled", false);
  3824. },
  3825. disable: function(){
  3826. this.element.attr("disabled", true);
  3827. this.button.addClass("ui-disabled").attr("aria-disabled", true);
  3828. return this._setOption("disabled", true);
  3829. },
  3830. refresh: function(){
  3831. if( this.element.attr('disabled') ){
  3832. this.disable();
  3833. }
  3834. else{
  3835. this.enable();
  3836. }
  3837. }
  3838. });
  3839. })( jQuery );/*
  3840. * jQuery Mobile Framework : "slider" plugin
  3841. * Copyright (c) jQuery Project
  3842. * Dual licensed under the MIT or GPL Version 2 licenses.
  3843. * http://jquery.org/license
  3844. */
  3845. (function($, undefined ) {
  3846. $.widget( "mobile.slider", $.mobile.widget, {
  3847. options: {
  3848. theme: null,
  3849. trackTheme: null,
  3850. disabled: false
  3851. },
  3852. _create: function(){
  3853. var self = this,
  3854. control = this.element,
  3855. parentTheme = control.parents('[class*=ui-bar-],[class*=ui-body-]').eq(0),
  3856. parentTheme = parentTheme.length ? parentTheme.attr('class').match(/ui-(bar|body)-([a-z])/)[2] : 'c',
  3857. theme = this.options.theme ? this.options.theme : parentTheme,
  3858. trackTheme = this.options.trackTheme ? this.options.trackTheme : parentTheme,
  3859. cType = control[0].nodeName.toLowerCase(),
  3860. selectClass = (cType == 'select') ? 'ui-slider-switch' : '',
  3861. controlID = control.attr('id'),
  3862. labelID = controlID + '-label',
  3863. label = $('[for="'+ controlID +'"]').attr('id',labelID),
  3864. val = function(){
  3865. return (cType == 'input') ? parseFloat(control.val()) : control[0].selectedIndex;
  3866. },
  3867. min = (cType == 'input') ? parseFloat(control.attr('min')) : 0,
  3868. max = (cType == 'input') ? parseFloat(control.attr('max')) : control.find('option').length-1,
  3869. step = window.parseFloat(control.attr('step') || 1),
  3870. slider = $('<div class="ui-slider '+ selectClass +' ui-btn-down-'+ trackTheme+' ui-btn-corner-all" role="application"></div>'),
  3871. handle = $('<a href="#" class="ui-slider-handle"></a>')
  3872. .appendTo(slider)
  3873. .buttonMarkup({corners: true, theme: theme, shadow: true})
  3874. .attr({
  3875. 'role': 'slider',
  3876. 'aria-valuemin': min,
  3877. 'aria-valuemax': max,
  3878. 'aria-valuenow': val(),
  3879. 'aria-valuetext': val(),
  3880. 'title': val(),
  3881. 'aria-labelledby': labelID
  3882. });
  3883. $.extend(this, {
  3884. slider: slider,
  3885. handle: handle,
  3886. dragging: false,
  3887. beforeStart: null
  3888. });
  3889. if(cType == 'select'){
  3890. slider.wrapInner('<div class="ui-slider-inneroffset"></div>');
  3891. var options = control.find('option');
  3892. control.find('option').each(function(i){
  3893. var side = (i==0) ?'b':'a',
  3894. corners = (i==0) ? 'right' :'left',
  3895. theme = (i==0) ? ' ui-btn-down-' + trackTheme :' ui-btn-active';
  3896. $('<div class="ui-slider-labelbg ui-slider-labelbg-'+ side + theme +' ui-btn-corner-'+ corners+'"></div>').prependTo(slider);
  3897. $('<span class="ui-slider-label ui-slider-label-'+ side + theme +' ui-btn-corner-'+ corners+'" role="img">'+$(this).text()+'</span>').prependTo(handle);
  3898. });
  3899. }
  3900. label.addClass('ui-slider');
  3901. // monitor the input for updated values
  3902. control
  3903. .addClass((cType == 'input') ? 'ui-slider-input' : 'ui-slider-switch')
  3904. .change(function(){
  3905. self.refresh( val(), true );
  3906. })
  3907. .keyup(function(){ // necessary?
  3908. self.refresh( val(), true, true );
  3909. })
  3910. .blur(function(){
  3911. self.refresh( val(), true );
  3912. });
  3913. // prevent screen drag when slider activated
  3914. $(document).bind( "vmousemove", function(event){
  3915. if ( self.dragging ) {
  3916. self.refresh( event );
  3917. return false;
  3918. }
  3919. });
  3920. slider
  3921. .bind( "vmousedown", function(event){
  3922. self.dragging = true;
  3923. if ( cType === "select" ) {
  3924. self.beforeStart = control[0].selectedIndex;
  3925. }
  3926. self.refresh( event );
  3927. return false;
  3928. });
  3929. slider
  3930. .add(document)
  3931. .bind( "vmouseup", function(){
  3932. if ( self.dragging ) {
  3933. self.dragging = false;
  3934. if ( cType === "select" ) {
  3935. if ( self.beforeStart === control[0].selectedIndex ) {
  3936. //tap occurred, but value didn't change. flip it!
  3937. self.refresh( self.beforeStart === 0 ? 1 : 0 );
  3938. }
  3939. var curval = val();
  3940. var snapped = Math.round( curval / (max - min) * 100 );
  3941. handle
  3942. .addClass("ui-slider-handle-snapping")
  3943. .css("left", snapped + "%")
  3944. .animationComplete(function(){
  3945. handle.removeClass("ui-slider-handle-snapping");
  3946. });
  3947. }
  3948. return false;
  3949. }
  3950. });
  3951. slider.insertAfter(control);
  3952. // NOTE force focus on handle
  3953. this.handle
  3954. .bind( "vmousedown", function(){
  3955. $(this).focus();
  3956. })
  3957. .bind( "vclick", false );
  3958. this.handle
  3959. .bind( "keydown", function( event ) {
  3960. var index = val();
  3961. if ( self.options.disabled ) {
  3962. return;
  3963. }
  3964. // In all cases prevent the default and mark the handle as active
  3965. switch ( event.keyCode ) {
  3966. case $.mobile.keyCode.HOME:
  3967. case $.mobile.keyCode.END:
  3968. case $.mobile.keyCode.PAGE_UP:
  3969. case $.mobile.keyCode.PAGE_DOWN:
  3970. case $.mobile.keyCode.UP:
  3971. case $.mobile.keyCode.RIGHT:
  3972. case $.mobile.keyCode.DOWN:
  3973. case $.mobile.keyCode.LEFT:
  3974. event.preventDefault();
  3975. if ( !self._keySliding ) {
  3976. self._keySliding = true;
  3977. $( this ).addClass( "ui-state-active" );
  3978. }
  3979. break;
  3980. }
  3981. // move the slider according to the keypress
  3982. switch ( event.keyCode ) {
  3983. case $.mobile.keyCode.HOME:
  3984. self.refresh(min);
  3985. break;
  3986. case $.mobile.keyCode.END:
  3987. self.refresh(max);
  3988. break;
  3989. case $.mobile.keyCode.PAGE_UP:
  3990. case $.mobile.keyCode.UP:
  3991. case $.mobile.keyCode.RIGHT:
  3992. self.refresh(index + step);
  3993. break;
  3994. case $.mobile.keyCode.PAGE_DOWN:
  3995. case $.mobile.keyCode.DOWN:
  3996. case $.mobile.keyCode.LEFT:
  3997. self.refresh(index - step);
  3998. break;
  3999. }
  4000. }) // remove active mark
  4001. .keyup(function( event ) {
  4002. if ( self._keySliding ) {
  4003. self._keySliding = false;
  4004. $( this ).removeClass( "ui-state-active" );
  4005. }
  4006. });
  4007. this.refresh();
  4008. },
  4009. refresh: function(val, isfromControl, preventInputUpdate){
  4010. if ( this.options.disabled ) { return; }
  4011. var control = this.element, percent,
  4012. cType = control[0].nodeName.toLowerCase(),
  4013. min = (cType === "input") ? parseFloat(control.attr("min")) : 0,
  4014. max = (cType === "input") ? parseFloat(control.attr("max")) : control.find("option").length - 1;
  4015. if ( typeof val === "object" ) {
  4016. var data = val,
  4017. // a slight tolerance helped get to the ends of the slider
  4018. tol = 8;
  4019. if ( !this.dragging
  4020. || data.pageX < this.slider.offset().left - tol
  4021. || data.pageX > this.slider.offset().left + this.slider.width() + tol ) {
  4022. return;
  4023. }
  4024. percent = Math.round( ((data.pageX - this.slider.offset().left) / this.slider.width() ) * 100 );
  4025. } else {
  4026. if ( val == null ) {
  4027. val = (cType === "input") ? parseFloat(control.val()) : control[0].selectedIndex;
  4028. }
  4029. percent = (parseFloat(val) - min) / (max - min) * 100;
  4030. }
  4031. if ( isNaN(percent) ) { return; }
  4032. if ( percent < 0 ) { percent = 0; }
  4033. if ( percent > 100 ) { percent = 100; }
  4034. var newval = Math.round( (percent / 100) * (max - min) ) + min;
  4035. if ( newval < min ) { newval = min; }
  4036. if ( newval > max ) { newval = max; }
  4037. //flip the stack of the bg colors
  4038. if ( percent > 60 && cType === "select" ) {
  4039. }
  4040. this.handle.css("left", percent + "%");
  4041. this.handle.attr({
  4042. "aria-valuenow": (cType === "input") ? newval : control.find("option").eq(newval).attr("value"),
  4043. "aria-valuetext": (cType === "input") ? newval : control.find("option").eq(newval).text(),
  4044. title: newval
  4045. });
  4046. // add/remove classes for flip toggle switch
  4047. if ( cType === "select" ) {
  4048. if ( newval === 0 ) {
  4049. this.slider.addClass("ui-slider-switch-a")
  4050. .removeClass("ui-slider-switch-b");
  4051. } else {
  4052. this.slider.addClass("ui-slider-switch-b")
  4053. .removeClass("ui-slider-switch-a");
  4054. }
  4055. }
  4056. if(!preventInputUpdate){
  4057. // update control's value
  4058. if ( cType === "input" ) {
  4059. control.val(newval);
  4060. } else {
  4061. control[ 0 ].selectedIndex = newval;
  4062. }
  4063. if (!isfromControl) { control.trigger("change"); }
  4064. }
  4065. },
  4066. enable: function(){
  4067. this.element.attr("disabled", false);
  4068. this.slider.removeClass("ui-disabled").attr("aria-disabled", false);
  4069. return this._setOption("disabled", false);
  4070. },
  4071. disable: function(){
  4072. this.element.attr("disabled", true);
  4073. this.slider.addClass("ui-disabled").attr("aria-disabled", true);
  4074. return this._setOption("disabled", true);
  4075. }
  4076. });
  4077. })( jQuery );
  4078. /*
  4079. * jQuery Mobile Framework : "collapsible" plugin
  4080. * Copyright (c) jQuery Project
  4081. * Dual licensed under the MIT or GPL Version 2 licenses.
  4082. * http://jquery.org/license
  4083. */
  4084. ( function( $, undefined ) {
  4085. $.widget( "mobile.collapsible", $.mobile.widget, {
  4086. options: {
  4087. expandCueText: " click to expand contents",
  4088. collapseCueText: " click to collapse contents",
  4089. collapsed: false,
  4090. heading: ">:header,>legend",
  4091. theme: null,
  4092. iconTheme: "d"
  4093. },
  4094. _create: function() {
  4095. var $el = this.element,
  4096. o = this.options,
  4097. collapsibleContain = $el.addClass( "ui-collapsible-contain" ),
  4098. collapsibleHeading = $el.find( o.heading ).eq( 0 ),
  4099. collapsibleContent = collapsibleContain.wrapInner( '<div class="ui-collapsible-content"></div>' ).find( ".ui-collapsible-content" ),
  4100. collapsibleParent = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" );
  4101. //replace collapsibleHeading if it's a legend
  4102. if ( collapsibleHeading.is( "legend" ) ) {
  4103. collapsibleHeading = $( '<div role="heading">'+ collapsibleHeading.html() +"</div>" ).insertBefore( collapsibleHeading );
  4104. collapsibleHeading.next().remove();
  4105. }
  4106. collapsibleHeading
  4107. //drop heading in before content
  4108. .insertBefore( collapsibleContent )
  4109. //modify markup & attributes
  4110. .addClass( "ui-collapsible-heading" )
  4111. .append( '<span class="ui-collapsible-heading-status"></span>' )
  4112. .wrapInner( '<a href="#" class="ui-collapsible-heading-toggle"></a>' )
  4113. .find( "a:eq(0)" )
  4114. .buttonMarkup( {
  4115. shadow: !collapsibleParent.length,
  4116. corners: false,
  4117. iconPos: "left",
  4118. icon: "plus",
  4119. theme: o.theme
  4120. } )
  4121. .find( ".ui-icon" )
  4122. .removeAttr( "class" )
  4123. .buttonMarkup( {
  4124. shadow: true,
  4125. corners: true,
  4126. iconPos: "notext",
  4127. icon: "plus",
  4128. theme: o.iconTheme
  4129. } );
  4130. if ( ! collapsibleParent.length ) {
  4131. collapsibleHeading
  4132. .find( "a:eq(0)" )
  4133. .addClass( "ui-corner-all" )
  4134. .find( ".ui-btn-inner" )
  4135. .addClass( "ui-corner-all" );
  4136. }
  4137. else {
  4138. if ( collapsibleContain.jqmData( "collapsible-last" ) ) {
  4139. collapsibleHeading
  4140. .find( "a:eq(0), .ui-btn-inner" )
  4141. .addClass( "ui-corner-bottom" );
  4142. }
  4143. }
  4144. //events
  4145. collapsibleContain
  4146. .bind( "collapse", function( event ) {
  4147. if ( ! event.isDefaultPrevented() && $( event.target ).closest( ".ui-collapsible-contain" ).is( collapsibleContain ) ) {
  4148. event.preventDefault();
  4149. collapsibleHeading
  4150. .addClass( "ui-collapsible-heading-collapsed" )
  4151. .find( ".ui-collapsible-heading-status" )
  4152. .text( o.expandCueText )
  4153. .end()
  4154. .find( ".ui-icon" )
  4155. .removeClass( "ui-icon-minus" )
  4156. .addClass( "ui-icon-plus" );
  4157. collapsibleContent.addClass( "ui-collapsible-content-collapsed" ).attr( "aria-hidden", true );
  4158. if ( collapsibleContain.jqmData( "collapsible-last" ) ) {
  4159. collapsibleHeading
  4160. .find( "a:eq(0), .ui-btn-inner" )
  4161. .addClass( "ui-corner-bottom" );
  4162. }
  4163. }
  4164. } )
  4165. .bind( "expand", function( event ) {
  4166. if ( ! event.isDefaultPrevented() ) {
  4167. event.preventDefault();
  4168. collapsibleHeading
  4169. .removeClass( "ui-collapsible-heading-collapsed" )
  4170. .find( ".ui-collapsible-heading-status" ).text( o.collapseCueText );
  4171. collapsibleHeading.find( ".ui-icon" ).removeClass( "ui-icon-plus" ).addClass( "ui-icon-minus" );
  4172. collapsibleContent.removeClass( "ui-collapsible-content-collapsed" ).attr( "aria-hidden", false );
  4173. if ( collapsibleContain.jqmData( "collapsible-last" ) ) {
  4174. collapsibleHeading
  4175. .find( "a:eq(0), .ui-btn-inner" )
  4176. .removeClass( "ui-corner-bottom" );
  4177. }
  4178. }
  4179. } )
  4180. .trigger( o.collapsed ? "collapse" : "expand" );
  4181. //close others in a set
  4182. if ( collapsibleParent.length && !collapsibleParent.jqmData( "collapsiblebound" ) ) {
  4183. collapsibleParent
  4184. .jqmData( "collapsiblebound", true )
  4185. .bind( "expand", function( event ){
  4186. $( event.target )
  4187. .closest( ".ui-collapsible-contain" )
  4188. .siblings( ".ui-collapsible-contain" )
  4189. .trigger( "collapse" );
  4190. } );
  4191. var set = collapsibleParent.find( ":jqmData(role='collapsible'):first" );
  4192. set.first()
  4193. .find( "a:eq(0)" )
  4194. .addClass( "ui-corner-top" )
  4195. .find( ".ui-btn-inner" )
  4196. .addClass( "ui-corner-top" );
  4197. set.last().jqmData( "collapsible-last", true );
  4198. }
  4199. collapsibleHeading
  4200. .bind( "vclick", function( e ) {
  4201. if ( collapsibleHeading.is( ".ui-collapsible-heading-collapsed" ) ) {
  4202. collapsibleContain.trigger( "expand" );
  4203. }
  4204. else {
  4205. collapsibleContain.trigger( "collapse" );
  4206. }
  4207. e.preventDefault();
  4208. } );
  4209. }
  4210. } );
  4211. } )( jQuery );
  4212. /*
  4213. * jQuery Mobile Framework: "controlgroup" plugin - corner-rounding for groups of buttons, checks, radios, etc
  4214. * Copyright (c) jQuery Project
  4215. * Dual licensed under the MIT or GPL Version 2 licenses.
  4216. * http://jquery.org/license
  4217. */
  4218. (function($, undefined ) {
  4219. $.fn.controlgroup = function(options){
  4220. return this.each(function(){
  4221. var o = $.extend({
  4222. direction: $( this ).jqmData( "type" ) || "vertical",
  4223. shadow: false
  4224. },options);
  4225. var groupheading = $(this).find('>legend'),
  4226. flCorners = o.direction == 'horizontal' ? ['ui-corner-left', 'ui-corner-right'] : ['ui-corner-top', 'ui-corner-bottom'],
  4227. type = $(this).find('input:eq(0)').attr('type');
  4228. //replace legend with more stylable replacement div
  4229. if( groupheading.length ){
  4230. $(this).wrapInner('<div class="ui-controlgroup-controls"></div>');
  4231. $('<div role="heading" class="ui-controlgroup-label">'+ groupheading.html() +'</div>').insertBefore( $(this).children(0) );
  4232. groupheading.remove();
  4233. }
  4234. $(this).addClass('ui-corner-all ui-controlgroup ui-controlgroup-'+o.direction);
  4235. function flipClasses(els){
  4236. els
  4237. .removeClass('ui-btn-corner-all ui-shadow')
  4238. .eq(0).addClass(flCorners[0])
  4239. .end()
  4240. .filter(':last').addClass(flCorners[1]).addClass('ui-controlgroup-last');
  4241. }
  4242. flipClasses($(this).find('.ui-btn'));
  4243. flipClasses($(this).find('.ui-btn-inner'));
  4244. if(o.shadow){
  4245. $(this).addClass('ui-shadow');
  4246. }
  4247. });
  4248. };
  4249. })(jQuery);/*
  4250. * jQuery Mobile Framework : "fieldcontain" plugin - simple class additions to make form row separators
  4251. * Copyright (c) jQuery Project
  4252. * Dual licensed under the MIT or GPL Version 2 licenses.
  4253. * http://jquery.org/license
  4254. */
  4255. (function($, undefined ) {
  4256. $.fn.fieldcontain = function(options){
  4257. return this.addClass('ui-field-contain ui-body ui-br');
  4258. };
  4259. })(jQuery);/*
  4260. * jQuery Mobile Framework : "listview" plugin
  4261. * Copyright (c) jQuery Project
  4262. * Dual licensed under the MIT or GPL Version 2 licenses.
  4263. * http://jquery.org/license
  4264. */
  4265. (function($, undefined ) {
  4266. //Keeps track of the number of lists per page UID
  4267. //This allows support for multiple nested list in the same page
  4268. //https://github.com/jquery/jquery-mobile/issues/1617
  4269. var listCountPerPage = {};
  4270. $.widget( "mobile.listview", $.mobile.widget, {
  4271. options: {
  4272. theme: "c",
  4273. countTheme: "c",
  4274. headerTheme: "b",
  4275. dividerTheme: "b",
  4276. splitIcon: "arrow-r",
  4277. splitTheme: "b",
  4278. inset: false
  4279. },
  4280. _create: function() {
  4281. var t = this;
  4282. // create listview markup
  4283. t.element.addClass(function( i, orig ) {
  4284. return orig + " ui-listview " + ( t.options.inset ? " ui-listview-inset ui-corner-all ui-shadow " : "" );
  4285. });
  4286. t.refresh();
  4287. },
  4288. _itemApply: function( $list, item ) {
  4289. // TODO class has to be defined in markup
  4290. item.find( ".ui-li-count" )
  4291. .addClass( "ui-btn-up-" + ($list.jqmData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" ).end()
  4292. .find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" ).end()
  4293. .find( "p, dl" ).addClass( "ui-li-desc" ).end()
  4294. .find( ">img:eq(0), .ui-link-inherit>img:eq(0)" ).addClass( "ui-li-thumb" ).each(function() {
  4295. item.addClass( $(this).is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
  4296. }).end()
  4297. .find( ".ui-li-aside" ).each(function() {
  4298. var $this = $(this);
  4299. $this.prependTo( $this.parent() ); //shift aside to front for css float
  4300. });
  4301. },
  4302. _removeCorners: function( li ) {
  4303. li
  4304. .add( li.find(".ui-btn-inner, .ui-li-link-alt, .ui-li-thumb") )
  4305. .removeClass( "ui-corner-top ui-corner-bottom ui-corner-br ui-corner-bl ui-corner-tr ui-corner-tl" );
  4306. },
  4307. refresh: function( create ) {
  4308. this._createSubPages();
  4309. var o = this.options,
  4310. $list = this.element,
  4311. self = this,
  4312. dividertheme = $list.jqmData( "dividertheme" ) || o.dividerTheme,
  4313. listsplittheme = $list.jqmData( "splittheme" ),
  4314. listspliticon = $list.jqmData( "spliticon" ),
  4315. li = $list.children( "li" ),
  4316. counter = $.support.cssPseudoElement || !$.nodeName( $list[0], "ol" ) ? 0 : 1;
  4317. if ( counter ) {
  4318. $list.find( ".ui-li-dec" ).remove();
  4319. }
  4320. for (var pos = 0, numli = li.length; pos < numli; pos++) {
  4321. var item = li.eq(pos),
  4322. itemClass = "ui-li";
  4323. // If we're creating the element, we update it regardless
  4324. if ( create || !item.hasClass( "ui-li" ) ) {
  4325. var itemTheme = item.jqmData("theme") || o.theme,
  4326. a = item.children( "a" );
  4327. if ( a.length ) {
  4328. var icon = item.jqmData("icon");
  4329. item
  4330. .buttonMarkup({
  4331. wrapperEls: "div",
  4332. shadow: false,
  4333. corners: false,
  4334. iconpos: "right",
  4335. icon: a.length > 1 || icon === false ? false : icon || "arrow-r",
  4336. theme: itemTheme
  4337. });
  4338. a.first().addClass( "ui-link-inherit" );
  4339. if ( a.length > 1 ) {
  4340. itemClass += " ui-li-has-alt";
  4341. var last = a.last(),
  4342. splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
  4343. last
  4344. .appendTo(item)
  4345. .attr( "title", last.text() )
  4346. .addClass( "ui-li-link-alt" )
  4347. .empty()
  4348. .buttonMarkup({
  4349. shadow: false,
  4350. corners: false,
  4351. theme: itemTheme,
  4352. icon: false,
  4353. iconpos: false
  4354. })
  4355. .find( ".ui-btn-inner" )
  4356. .append( $( "<span />" ).buttonMarkup({
  4357. shadow: true,
  4358. corners: true,
  4359. theme: splittheme,
  4360. iconpos: "notext",
  4361. icon: listspliticon || last.jqmData( "icon" ) || o.splitIcon
  4362. } ) );
  4363. }
  4364. } else if ( item.jqmData( "role" ) === "list-divider" ) {
  4365. itemClass += " ui-li-divider ui-btn ui-bar-" + dividertheme;
  4366. item.attr( "role", "heading" );
  4367. //reset counter when a divider heading is encountered
  4368. if ( counter ) {
  4369. counter = 1;
  4370. }
  4371. } else {
  4372. itemClass += " ui-li-static ui-body-" + itemTheme;
  4373. }
  4374. }
  4375. if( o.inset ){
  4376. if ( pos === 0 ) {
  4377. itemClass += " ui-corner-top";
  4378. item
  4379. .add( item.find( ".ui-btn-inner" ) )
  4380. .find( ".ui-li-link-alt" )
  4381. .addClass( "ui-corner-tr" )
  4382. .end()
  4383. .find( ".ui-li-thumb" )
  4384. .addClass( "ui-corner-tl" );
  4385. if(item.next().next().length){
  4386. self._removeCorners( item.next() );
  4387. }
  4388. }
  4389. if ( pos === li.length - 1 ) {
  4390. itemClass += " ui-corner-bottom";
  4391. item
  4392. .add( item.find( ".ui-btn-inner" ) )
  4393. .find( ".ui-li-link-alt" )
  4394. .addClass( "ui-corner-br" )
  4395. .end()
  4396. .find( ".ui-li-thumb" )
  4397. .addClass( "ui-corner-bl" );
  4398. if(item.prev().prev().length){
  4399. self._removeCorners( item.prev() );
  4400. }
  4401. }
  4402. }
  4403. if ( counter && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
  4404. var countParent = item.is(".ui-li-static:first") ? item : item.find( ".ui-link-inherit" );
  4405. countParent
  4406. .addClass( "ui-li-jsnumbering" )
  4407. .prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
  4408. }
  4409. item.add( item.children( ".ui-btn-inner" ) ).addClass( itemClass );
  4410. if ( !create ) {
  4411. self._itemApply( $list, item );
  4412. }
  4413. }
  4414. },
  4415. //create a string for ID/subpage url creation
  4416. _idStringEscape: function( str ){
  4417. return str.replace(/[^a-zA-Z0-9]/g, '-');
  4418. },
  4419. _createSubPages: function() {
  4420. var parentList = this.element,
  4421. parentPage = parentList.closest( ".ui-page" ),
  4422. parentUrl = parentPage.jqmData( "url" ),
  4423. parentId = parentUrl || parentPage[ 0 ][ $.expando ],
  4424. parentListId = parentList.attr( "id" ),
  4425. o = this.options,
  4426. dns = "data-" + $.mobile.ns,
  4427. self = this,
  4428. persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" );
  4429. if ( typeof( listCountPerPage[ parentId ] ) === 'undefined' ) {
  4430. listCountPerPage[ parentId ] = -1;
  4431. }
  4432. parentListId = parentListId || ++listCountPerPage[ parentId ];
  4433. $( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) {
  4434. var list = $( this ),
  4435. listId = list.attr( "id" ) || parentListId + "-" + i,
  4436. parent = list.parent(),
  4437. nodeEls = $( list.prevAll().toArray().reverse() ),
  4438. nodeEls = nodeEls.length ? nodeEls : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
  4439. title = nodeEls.first().text(),//url limits to first 30 chars of text
  4440. id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId;
  4441. theme = list.jqmData( "theme" ) || o.theme,
  4442. countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme,
  4443. newPage = list.detach()
  4444. .wrap( "<div " + dns + "role='page' " + dns + "url='" + id + "' " + dns + "theme='" + theme + "' " + dns + "count-theme='" + countTheme + "'><div " + dns + "role='content'></div></div>" )
  4445. .parent()
  4446. .before( "<div " + dns + "role='header' " + dns + "theme='" + o.headerTheme + "'><div class='ui-title'>" + title + "</div></div>" )
  4447. .after( persistentFooterID ? $( "<div " + dns + "role='footer' " + dns + "id='"+ persistentFooterID +"'>") : "" )
  4448. .parent()
  4449. .appendTo( $.mobile.pageContainer );
  4450. newPage.page();
  4451. var anchor = parent.find('a:first');
  4452. if ( !anchor.length ) {
  4453. anchor = $("<a />").html( nodeEls || title ).prependTo( parent.empty() );
  4454. }
  4455. anchor.attr('href','#' + id);
  4456. }).listview();
  4457. }
  4458. });
  4459. })( jQuery );
  4460. /*
  4461. * jQuery Mobile Framework : "listview" filter extension
  4462. * Copyright (c) jQuery Project
  4463. * Dual licensed under the MIT or GPL Version 2 licenses.
  4464. * http://jquery.org/license
  4465. */
  4466. (function($, undefined ) {
  4467. $.mobile.listview.prototype.options.filter = false;
  4468. $.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
  4469. $.mobile.listview.prototype.options.filterTheme = "c";
  4470. $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
  4471. var list = $( this ),
  4472. listview = list.data( "listview" );
  4473. if ( !listview.options.filter ) {
  4474. return;
  4475. }
  4476. var wrapper = $( "<form>", { "class": "ui-listview-filter ui-bar-" + listview.options.filterTheme, "role": "search" } ),
  4477. search = $( "<input>", {
  4478. placeholder: listview.options.filterPlaceholder
  4479. })
  4480. .attr( "data-" + $.mobile.ns + "type", "search" )
  4481. .jqmData( 'lastval', "" )
  4482. .bind( "keyup change", function() {
  4483. var val = this.value.toLowerCase(),
  4484. listItems=null,
  4485. lastval = $( this ).jqmData('lastval')+"";
  4486. //change val as lastval for next execution
  4487. $(this).jqmData( 'lastval' , val );
  4488. change = val.replace( new RegExp( "^" + lastval ) , "" );
  4489. if( val.length < lastval.length || change.length != ( val.length - lastval.length ) ){
  4490. //removed chars or pasted something totaly different, check all items
  4491. listItems = list.children();
  4492. } else {
  4493. //only chars added, not removed, only use visible subset
  4494. listItems = list.children( ':not(.ui-screen-hidden)' );
  4495. }
  4496. if ( val ) {
  4497. // This handles hiding regular rows without the text we search for
  4498. // and any list dividers without regular rows shown under it
  4499. var item,
  4500. childItems = false,
  4501. itemtext="";
  4502. for ( var i = listItems.length - 1; i >= 0; i-- ) {
  4503. item = $( listItems[i] );
  4504. itemtext = item.jqmData( 'filtertext' ) || item.text();
  4505. if ( item.is( "li:jqmData(role=list-divider)" ) ) {
  4506. item.toggleClass( 'ui-filter-hidequeue' , !childItems );
  4507. // New bucket!
  4508. childItems = false;
  4509. } else if ( itemtext.toLowerCase().indexOf( val ) === -1) {
  4510. //mark to be hidden
  4511. item.toggleClass( 'ui-filter-hidequeue' , true );
  4512. } else {
  4513. // There's a shown item in the bucket
  4514. childItems = true;
  4515. }
  4516. }
  4517. // show items, not marked to be hidden
  4518. listItems
  4519. .filter( ':not(.ui-filter-hidequeue)' )
  4520. .toggleClass('ui-screen-hidden',false);
  4521. // hide items, marked to be hidden
  4522. listItems
  4523. .filter( '.ui-filter-hidequeue' )
  4524. .toggleClass('ui-screen-hidden',true)
  4525. .toggleClass( 'ui-filter-hidequeue' , false );
  4526. }else{
  4527. //filtervalue is empty => show all
  4528. listItems.toggleClass('ui-screen-hidden',false);
  4529. }
  4530. })
  4531. .appendTo( wrapper )
  4532. .textinput();
  4533. if ($( this ).jqmData( "inset" ) ) {
  4534. wrapper.addClass( "ui-listview-filter-inset" );
  4535. }
  4536. wrapper.insertBefore( list );
  4537. });
  4538. })( jQuery );/*
  4539. * jQuery Mobile Framework : "dialog" plugin.
  4540. * Copyright (c) jQuery Project
  4541. * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
  4542. * Note: Code is in draft form and is subject to change
  4543. */
  4544. ( function( $, undefined ) {
  4545. $.widget( "mobile.dialog", $.mobile.widget, {
  4546. options: {
  4547. closeBtnText: "Close"
  4548. },
  4549. _create: function() {
  4550. var $el = this.element;
  4551. /* class the markup for dialog styling */
  4552. $el
  4553. //add ARIA role
  4554. .attr( "role", "dialog" )
  4555. .addClass( "ui-page ui-dialog ui-body-a" )
  4556. .find( ":jqmData(role=header)" )
  4557. .addClass( "ui-corner-top ui-overlay-shadow" )
  4558. .prepend( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "rel='back' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText +"</a>" )
  4559. .end()
  4560. .find( '.ui-content:not([class*="ui-body-"])' )
  4561. .addClass( 'ui-body-c' )
  4562. .end()
  4563. .find( ".ui-content,:jqmData(role='footer')" )
  4564. .last()
  4565. .addClass( "ui-corner-bottom ui-overlay-shadow" );
  4566. /* bind events
  4567. - clicks and submits should use the closing transition that the dialog opened with
  4568. unless a data-transition is specified on the link/form
  4569. - if the click was on the close button, or the link has a data-rel="back" it'll go back in history naturally
  4570. */
  4571. $el
  4572. .bind( "vclick submit", function( e ) {
  4573. var $target = $( e.target ).closest( e.type === "vclick" ? "a" : "form" );
  4574. if( $target.length && ! $target.jqmData( "transition" ) ) {
  4575. var active = $.mobile.urlHistory.getActive() || {};
  4576. $target
  4577. .attr( "data-" + $.mobile.ns + "transition", ( active.transition || $.mobile.defaultDialogTransition ) )
  4578. .attr( "data-" + $.mobile.ns + "direction", "reverse" );
  4579. }
  4580. })
  4581. .bind( "pagehide", function() {
  4582. $( this ).find( "." + $.mobile.activeBtnClass ).removeClass( $.mobile.activeBtnClass );
  4583. });
  4584. },
  4585. //close method goes back in history
  4586. close: function() {
  4587. window.history.back();
  4588. }
  4589. });
  4590. })( jQuery );
  4591. /*
  4592. * jQuery Mobile Framework : "navbar" plugin
  4593. * Copyright (c) jQuery Project
  4594. * Dual licensed under the MIT or GPL Version 2 licenses.
  4595. * http://jquery.org/license
  4596. */
  4597. (function($, undefined ) {
  4598. $.widget( "mobile.navbar", $.mobile.widget, {
  4599. options: {
  4600. iconpos: 'top',
  4601. grid: null
  4602. },
  4603. _create: function(){
  4604. var $navbar = this.element,
  4605. $navbtns = $navbar.find("a"),
  4606. iconpos = $navbtns.filter( ":jqmData(icon)").length ? this.options.iconpos : undefined;
  4607. $navbar
  4608. .addClass('ui-navbar')
  4609. .attr("role","navigation")
  4610. .find("ul")
  4611. .grid({grid: this.options.grid });
  4612. if( !iconpos ){
  4613. $navbar.addClass("ui-navbar-noicons");
  4614. }
  4615. $navbtns
  4616. .buttonMarkup({
  4617. corners: false,
  4618. shadow: false,
  4619. iconpos: iconpos
  4620. });
  4621. $navbar.delegate("a", "vclick",function(event){
  4622. $navbtns.not( ".ui-state-persist" ).removeClass( $.mobile.activeBtnClass );
  4623. $( this ).addClass( $.mobile.activeBtnClass );
  4624. });
  4625. }
  4626. });
  4627. })( jQuery );
  4628. /*
  4629. * jQuery Mobile Framework : plugin for creating CSS grids
  4630. * Copyright (c) jQuery Project
  4631. * Dual licensed under the MIT or GPL Version 2 licenses.
  4632. * http://jquery.org/license
  4633. */
  4634. (function($, undefined ) {
  4635. $.fn.grid = function(options){
  4636. return this.each(function(){
  4637. var o = $.extend({
  4638. grid: null
  4639. },options);
  4640. var $kids = $(this).children(),
  4641. gridCols = {solo:1, a:2, b:3, c:4, d:5},
  4642. grid = o.grid,
  4643. iterator;
  4644. if( !grid ){
  4645. if( $kids.length <= 5 ){
  4646. for(var letter in gridCols){
  4647. if(gridCols[letter] == $kids.length){ grid = letter; }
  4648. }
  4649. }
  4650. else{
  4651. grid = 'a';
  4652. }
  4653. }
  4654. iterator = gridCols[grid];
  4655. $(this).addClass('ui-grid-' + grid);
  4656. $kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a');
  4657. if(iterator > 1){
  4658. $kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b');
  4659. }
  4660. if(iterator > 2){
  4661. $kids.filter(':nth-child(3n+3)').addClass('ui-block-c');
  4662. }
  4663. if(iterator > 3){
  4664. $kids.filter(':nth-child(4n+4)').addClass('ui-block-d');
  4665. }
  4666. if(iterator > 4){
  4667. $kids.filter(':nth-child(5n+5)').addClass('ui-block-e');
  4668. }
  4669. });
  4670. };
  4671. })(jQuery);/*!
  4672. * jQuery Mobile v@VERSION
  4673. * http://jquerymobile.com/
  4674. *
  4675. * Copyright 2010, jQuery Project
  4676. * Dual licensed under the MIT or GPL Version 2 licenses.
  4677. * http://jquery.org/license
  4678. */
  4679. (function( $, window, undefined ) {
  4680. var $html = $( "html" ),
  4681. $head = $( "head" ),
  4682. $window = $( window );
  4683. //trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
  4684. $( window.document ).trigger( "mobileinit" );
  4685. //support conditions
  4686. //if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
  4687. //otherwise, proceed with the enhancements
  4688. if ( !$.mobile.gradeA() ) {
  4689. return;
  4690. }
  4691. // override ajaxEnabled on platforms that have known conflicts with hash history updates
  4692. // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
  4693. if( window.blackberry && !window.WebKitPoint || window.operamini && Object.prototype.toString.call( window.operamini ) === "[object OperaMini]" ){
  4694. $.mobile.ajaxEnabled = false;
  4695. }
  4696. //add mobile, initial load "rendering" classes to docEl
  4697. $html.addClass( "ui-mobile ui-mobile-rendering" );
  4698. //loading div which appears during Ajax requests
  4699. //will not appear if $.mobile.loadingMessage is false
  4700. var $loader = $.mobile.loadingMessage ? $( "<div class='ui-loader ui-body-a ui-corner-all'>" + "<span class='ui-icon ui-icon-loading spin'></span>" + "<h1>" + $.mobile.loadingMessage + "</h1>" + "</div>" ) : undefined;
  4701. $.extend($.mobile, {
  4702. // turn on/off page loading message.
  4703. showPageLoadingMsg: function() {
  4704. if( $.mobile.loadingMessage ){
  4705. var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
  4706. $loader
  4707. .appendTo( $.mobile.pageContainer )
  4708. //position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
  4709. .css( {
  4710. top: $.support.scrollTop && $(window).scrollTop() + $(window).height() / 2 ||
  4711. activeBtn.length && activeBtn.offset().top || 100
  4712. } );
  4713. }
  4714. $html.addClass( "ui-loading" );
  4715. },
  4716. hidePageLoadingMsg: function() {
  4717. $html.removeClass( "ui-loading" );
  4718. },
  4719. // XXX: deprecate for 1.0
  4720. pageLoading: function ( done ) {
  4721. if ( done ) {
  4722. $.mobile.hidePageLoadingMsg();
  4723. } else {
  4724. $.mobile.showPageLoadingMsg();
  4725. }
  4726. },
  4727. // find and enhance the pages in the dom and transition to the first page.
  4728. initializePage: function(){
  4729. //find present pages
  4730. var $pages = $( ":jqmData(role='page')" );
  4731. //add dialogs, set data-url attrs
  4732. $pages.add( ":jqmData(role='dialog')" ).each(function(){
  4733. var $this = $(this);
  4734. // unless the data url is already set set it to the id
  4735. if( !$this.jqmData('url') ){
  4736. $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) );
  4737. }
  4738. });
  4739. //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
  4740. $.mobile.firstPage = $pages.first();
  4741. //define page container
  4742. $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
  4743. //cue page loading message
  4744. $.mobile.showPageLoadingMsg();
  4745. // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
  4746. if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){
  4747. $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
  4748. }
  4749. // otherwise, trigger a hashchange to load a deeplink
  4750. else {
  4751. $window.trigger( "hashchange", [ true ] );
  4752. }
  4753. }
  4754. });
  4755. //check which scrollTop value should be used by scrolling to 1 immediately at domready
  4756. //then check what the scroll top is. Android will report 0... others 1
  4757. //note that this initial scroll won't hide the address bar. It's just for the check.
  4758. $(function(){
  4759. window.scrollTo( 0, 1 );
  4760. //if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
  4761. //it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
  4762. //so if it's 1, use 0 from now on
  4763. $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;
  4764. //dom-ready inits
  4765. $( $.mobile.initializePage );
  4766. //window load event
  4767. //hide iOS browser chrome on load
  4768. $window.load( $.mobile.silentScroll );
  4769. });
  4770. })( jQuery, this );