PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/js/jquery.mobile.core.js

https://github.com/Wilto/jquery-mobile
JavaScript | 218 lines | 129 code | 46 blank | 43 comment | 16 complexity | f7f5dcb0df01b8d4657cd96e5352351b MD5 | raw file
  1. /*!
  2. * jQuery Mobile v@VERSION
  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. (function( $, window, undefined ) {
  10. // jQuery.mobile configurable options
  11. $.extend( $.mobile, {
  12. // Namespace used framework-wide for data-attrs. Default is no namespace
  13. ns: "",
  14. // Define the url parameter used for referencing widget-generated sub-pages.
  15. // Translates to to example.html&ui-page=subpageIdentifier
  16. // hash segment before &ui-page= is used to make Ajax request
  17. subPageUrlKey: "ui-page",
  18. // Class assigned to page currently in view, and during transitions
  19. activePageClass: "ui-page-active",
  20. // Class used for "active" button state, from CSS framework
  21. activeBtnClass: "ui-btn-active",
  22. // Automatically handle clicks and form submissions through Ajax, when same-domain
  23. ajaxEnabled: true,
  24. // Automatically load and show pages based on location.hash
  25. hashListeningEnabled: true,
  26. // Set default page transition - 'none' for no transitions
  27. defaultPageTransition: "slide",
  28. // Minimum scroll distance that will be remembered when returning to a page
  29. minScrollBack: 250,
  30. // Set default dialog transition - 'none' for no transitions
  31. defaultDialogTransition: "pop",
  32. // Show loading message during Ajax requests
  33. // if false, message will not appear, but loading classes will still be toggled on html el
  34. loadingMessage: "loading",
  35. // Error response message - appears when an Ajax page request fails
  36. pageLoadErrorMessage: "Error Loading Page",
  37. //automatically initialize the DOM when it's ready
  38. autoInitializePage: true,
  39. pushStateEnabled: true,
  40. // turn of binding to the native orientationchange due to android orientation behavior
  41. orientationChangeEnabled: true,
  42. // Support conditions that must be met in order to proceed
  43. // default enhanced qualifications are media query support OR IE 7+
  44. gradeA: function(){
  45. return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
  46. },
  47. // TODO might be useful upstream in jquery itself ?
  48. keyCode: {
  49. ALT: 18,
  50. BACKSPACE: 8,
  51. CAPS_LOCK: 20,
  52. COMMA: 188,
  53. COMMAND: 91,
  54. COMMAND_LEFT: 91, // COMMAND
  55. COMMAND_RIGHT: 93,
  56. CONTROL: 17,
  57. DELETE: 46,
  58. DOWN: 40,
  59. END: 35,
  60. ENTER: 13,
  61. ESCAPE: 27,
  62. HOME: 36,
  63. INSERT: 45,
  64. LEFT: 37,
  65. MENU: 93, // COMMAND_RIGHT
  66. NUMPAD_ADD: 107,
  67. NUMPAD_DECIMAL: 110,
  68. NUMPAD_DIVIDE: 111,
  69. NUMPAD_ENTER: 108,
  70. NUMPAD_MULTIPLY: 106,
  71. NUMPAD_SUBTRACT: 109,
  72. PAGE_DOWN: 34,
  73. PAGE_UP: 33,
  74. PERIOD: 190,
  75. RIGHT: 39,
  76. SHIFT: 16,
  77. SPACE: 32,
  78. TAB: 9,
  79. UP: 38,
  80. WINDOWS: 91 // COMMAND
  81. },
  82. // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
  83. silentScroll: function( ypos ) {
  84. if ( $.type( ypos ) !== "number" ) {
  85. ypos = $.mobile.defaultHomeScroll;
  86. }
  87. // prevent scrollstart and scrollstop events
  88. $.event.special.scrollstart.enabled = false;
  89. setTimeout(function() {
  90. window.scrollTo( 0, ypos );
  91. $( document ).trigger( "silentscroll", { x: 0, y: ypos });
  92. }, 20 );
  93. setTimeout(function() {
  94. $.event.special.scrollstart.enabled = true;
  95. }, 150 );
  96. },
  97. // Take a data attribute property, prepend the namespace
  98. // and then camel case the attribute string
  99. nsNormalize: function( prop ) {
  100. if ( !prop ) {
  101. return;
  102. }
  103. return $.camelCase( $.mobile.ns + prop );
  104. },
  105. getInheritedTheme: function( el, defaultTheme ) {
  106. // Find the closest parent with a theme class on it.
  107. var themedParent = el.closest( "[class*='ui-bar-'],[class*='ui-body-']" ),
  108. // If there's a themed parent, extract the theme letter
  109. // from the theme class .
  110. ltr = ( themedParent.length && /ui-(bar|body)-([a-z])\b/.exec( themedParent.attr( "class" ) )[ 2 ] || "" ) || "";
  111. // Return the theme letter we found, if none, return the
  112. // specified default.
  113. return ltr || defaultTheme || "a";
  114. }
  115. });
  116. // Mobile version of data and removeData and hasData methods
  117. // ensures all data is set and retrieved using jQuery Mobile's data namespace
  118. $.fn.jqmData = function( prop, value ) {
  119. var result;
  120. if ( typeof prop != "undefined" ) {
  121. result = this.data( prop ? $.mobile.nsNormalize( prop ) : prop, value );
  122. }
  123. return result;
  124. };
  125. $.jqmData = function( elem, prop, value ) {
  126. var result;
  127. if ( typeof prop != "undefined" ) {
  128. result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
  129. }
  130. return result;
  131. };
  132. $.fn.jqmRemoveData = function( prop ) {
  133. return this.removeData( $.mobile.nsNormalize( prop ) );
  134. };
  135. $.jqmRemoveData = function( elem, prop ) {
  136. return $.removeData( elem, $.mobile.nsNormalize( prop ) );
  137. };
  138. $.fn.removeWithDependents = function() {
  139. $.removeWithDependents( this );
  140. };
  141. $.removeWithDependents = function( elem ) {
  142. var $elem = $( elem );
  143. ( $elem.jqmData('dependents') || $() ).remove();
  144. $elem.remove();
  145. };
  146. $.fn.addDependents = function( newDependents ) {
  147. $.addDependents( $(this), newDependents );
  148. };
  149. $.addDependents = function( elem, newDependents ) {
  150. var dependents = $(elem).jqmData( 'dependents' ) || $();
  151. $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
  152. };
  153. // note that this helper doesn't attempt to handle the callback
  154. // or setting of an html elements text, its only purpose is
  155. // to return the html encoded version of the text in all cases. (thus the name)
  156. $.fn.getEncodedText = function() {
  157. return $( "<div/>" ).text( $(this).text() ).html();
  158. };
  159. // Monkey-patching Sizzle to filter the :jqmData selector
  160. var oldFind = $.find;
  161. $.find = function( selector, context, ret, extra ) {
  162. selector = selector.replace(/:jqmData\(([^)]*)\)/g, "[data-" + ( $.mobile.ns || "" ) + "$1]");
  163. return oldFind.call( this, selector, context, ret, extra );
  164. };
  165. $.extend( $.find, oldFind );
  166. $.find.matches = function( expr, set ) {
  167. return $.find( expr, null, null, set );
  168. };
  169. $.find.matchesSelector = function( node, expr ) {
  170. return $.find( expr, null, null, [ node ] ).length > 0;
  171. };
  172. })( jQuery, this );