PageRenderTime 66ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/marketing/jquery.mobile.js

http://github.com/zurb/foundation
JavaScript | 5626 lines | 3540 code | 814 blank | 1272 comment | 638 complexity | 3246e0778806f3bf302e3ffd18c7dba1 MD5 | raw file

Large files files are truncated, but you can click here to view the full 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.titl

Large files files are truncated, but you can click here to view the full file