Dashboard sipadu mbip
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

jqm-demos.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // Turn off Ajax for local file browsing
  2. if ( location.protocol.substr(0,4) === 'file' ||
  3. location.protocol.substr(0,11) === '*-extension' ||
  4. location.protocol.substr(0,6) === 'widget' ) {
  5. // Start with links with only the trailing slash and that aren't external links
  6. var fixLinks = function() {
  7. $( "a[href$='/'], a[href='.'], a[href='..']" ).not( "[rel='external']" ).each( function() {
  8. if( !$( this ).attr( "href" ).match("http") ){
  9. this.href = $( this ).attr( "href" ).replace( /\/$/, "" ) + "/index.html";
  10. }
  11. });
  12. };
  13. // Fix the links for the initial page
  14. $( fixLinks );
  15. // Fix the links for subsequent ajax page loads
  16. $( document ).on( "pagecreate", fixLinks );
  17. // Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
  18. $.ajax({
  19. url: '.',
  20. async: false,
  21. isLocal: true
  22. }).error(function() {
  23. // Ajax doesn't work so turn it off
  24. $( document ).on( "mobileinit", function() {
  25. $.mobile.ajaxEnabled = false;
  26. var message = $( '<div>' , {
  27. 'class': "jqm-content",
  28. style: "border:none; padding: 10px 15px; overflow: auto;",
  29. 'data-ajax-warning': true
  30. });
  31. message
  32. .append( "<h3>Note: Navigation may not work if viewed locally</h3>" )
  33. .append( "<p>The Ajax-based navigation used throughout the jQuery Mobile docs may need to be viewed on a web server to work in certain browsers. If you see an error message when you click a link, please try a different browser.</p>" );
  34. $( document ).on( "pagecreate", function( event ) {
  35. $( event.target ).append( message );
  36. });
  37. });
  38. });
  39. }
  40. $( document ).on( "pagecreate", ".jqm-demos", function( event ) {
  41. var search,
  42. page = $( this ),
  43. that = this,
  44. searchUrl = ( $( this ).hasClass( "jqm-home" ) ) ? "_search/" : "../_search/",
  45. searchContents = $( ".jqm-search ul.jqm-list" ).find( "li:not(.ui-collapsible)" ),
  46. version = $.mobile.version || "dev",
  47. words = version.split( "-" ),
  48. ver = words[0],
  49. str = words[1] || "",
  50. text = ver;
  51. // Insert jqm version in header
  52. if ( str.indexOf( "rc" ) == -1 ) {
  53. str = str.charAt( 0 ).toUpperCase() + str.slice( 1 );
  54. } else {
  55. str = str.toUpperCase().replace( ".", "" );
  56. }
  57. if ( $.mobile.version && str ) {
  58. text += " " + str;
  59. }
  60. $( ".jqm-version" ).html( text );
  61. // Global navmenu panel
  62. $( ".jqm-navmenu-panel ul" ).listview();
  63. $( document ).on( "panelopen", ".jqm-search-panel", function() {
  64. $( this ).find( "input" ).focus();
  65. })
  66. $( ".jqm-navmenu-link" ).on( "click", function() {
  67. page.find( ".jqm-navmenu-panel:not(.jqm-panel-page-nav)" ).panel( "open" );
  68. });
  69. // Turn off autocomplete / correct for demos search
  70. $( this ).find( ".jqm-search input" ).attr( "autocomplete", "off" ).attr( "autocorrect", "off" );
  71. // Global search
  72. $( ".jqm-search-link" ).on( "click", function() {
  73. page.find( ".jqm-search-panel" ).panel( "open" );
  74. });
  75. // Initalize search panel list and filter also remove collapsibles
  76. $( this ).find( ".jqm-search ul.jqm-list" ).html( searchContents ).listview({
  77. inset: false,
  78. theme: null,
  79. dividerTheme: null,
  80. icon: false,
  81. autodividers: true,
  82. autodividersSelector: function ( li ) {
  83. return "";
  84. },
  85. arrowKeyNav: true,
  86. enterToNav: true,
  87. highlight: true,
  88. submitTo: searchUrl
  89. }).filterable();
  90. // Initalize search page list and remove collapsibles
  91. $( this ).find( ".jqm-search-results-wrap ul.jqm-list" ).html( searchContents ).listview({
  92. inset: true,
  93. theme: null,
  94. dividerTheme: null,
  95. icon: false,
  96. arrowKeyNav: true,
  97. enterToNav: true,
  98. highlight: true
  99. }).filterable();
  100. // Fix links on homepage to point to sub directories
  101. if ( $( event.target ).hasClass( "jqm-home") ) {
  102. $( this ).find( "a" ).each( function() {
  103. $( this ).attr( "href", $( this ).attr( "href" ).replace( "../", "" ) );
  104. });
  105. }
  106. // Search results page get search query string and enter it into filter then trigger keyup to filter
  107. if ( $( event.target ).hasClass( "jqm-demos-search-results") ) {
  108. search = $.mobile.path.parseUrl( window.location.href ).search.split( "=" )[ 1 ];
  109. setTimeout(function() {
  110. e = $.Event( "keyup" );
  111. e.which = 65;
  112. $( that ).find( ".jqm-content .jqm-search-results-wrap input" ).val( search ).trigger(e).trigger( "change" );
  113. }, 0 );
  114. }
  115. });
  116. // Append keywords list to each list item
  117. $( document ).one( "pagecreate", ".jqm-demos", function( event ) {
  118. $( this ).find( ".jqm-search-results-list li, .jqm-search li" ).each(function() {
  119. var text = $( this ).attr( "data-filtertext" );
  120. $( this )
  121. .find( "a" )
  122. .append( "<span class='jqm-search-results-keywords ui-li-desc'>" + text + "</span>" );
  123. });
  124. });
  125. // Functions for highlighting text used for keywords highlight in search
  126. jQuery.fn.highlight = function( pat ) {
  127. function innerHighlight( node, pat ) {
  128. var skip = 0;
  129. if ( node.nodeType == 3 ) {
  130. var pos = node.data.toUpperCase().indexOf( pat );
  131. if ( pos >= 0 ) {
  132. var spannode = document.createElement( "span" );
  133. spannode.className = "jqm-search-results-highlight";
  134. var middlebit = node.splitText( pos );
  135. var endbit = middlebit.splitText( pat.length );
  136. var middleclone = middlebit.cloneNode( true );
  137. spannode.appendChild( middleclone );
  138. middlebit.parentNode.replaceChild( spannode, middlebit );
  139. skip = 1;
  140. }
  141. } else if ( node.nodeType == 1 && node.childNodes && !/(script|style)/i.test( node.tagName ) ) {
  142. for ( var i = 0; i < node.childNodes.length; ++i ) {
  143. i += innerHighlight( node.childNodes[i], pat );
  144. }
  145. }
  146. return skip;
  147. }
  148. return this.length && pat && pat.length ? this.each(function() {
  149. innerHighlight( this, pat.toUpperCase() );
  150. }) : this;
  151. };
  152. // Function to remove highlights in text
  153. jQuery.fn.removeHighlight = function() {
  154. return this.find( "span.jqm-search-results-highlight" ).each(function() {
  155. this.parentNode.firstChild.nodeName;
  156. with ( this.parentNode ) {
  157. replaceChild( this.firstChild, this );
  158. normalize();
  159. }
  160. }).end();
  161. };
  162. // Extension to listview to add keyboard navigation
  163. $( document ).on( "mobileinit", function() {
  164. (function( $, undefined ) {
  165. $.widget( "mobile.listview", $.mobile.listview, {
  166. options: {
  167. arrowKeyNav: false,
  168. enterToNav: false,
  169. highlight: false,
  170. submitTo: false
  171. },
  172. _create: function() {
  173. this._super();
  174. if ( this.options.arrowKeyNav ) {
  175. this._on( document, { "pageshow": "arrowKeyNav" });
  176. }
  177. if ( this.options.enterToNav ) {
  178. this._on( document, { "pageshow": "enterToNav" });
  179. }
  180. },
  181. submitTo: function() {
  182. var url,
  183. form = this.element.parent().find( "form" );
  184. form.attr( "method", "get" )
  185. .attr( "action", this.options.submitTo );
  186. url = this.options.submitTo + "?search=" + this.element.parent().find( "input" ).val();
  187. window.location = url;
  188. },
  189. enterToNav: function() {
  190. var form = this.element.parent().find( "form" );
  191. form.append( "<button type='submit' data-icon='carat-r' data-inline='true' class='ui-hidden-accessible' data-iconpos='notext'>Submit</button>" )
  192. .parent()
  193. .trigger( "create" );
  194. this.element.parent().find( "form" ).children( ".ui-btn" ).addClass( "ui-hidden-accessible" );
  195. this._on( form, {
  196. "submit": "submitHandler"
  197. });
  198. },
  199. enhanced: false,
  200. arrowKeyNav: function() {
  201. var input = this.element.prev("form").find( "input" );
  202. if ( !this.enhanced ) {
  203. this._on( input, {
  204. "keyup": "handleKeyUp"
  205. });
  206. this.enhanced = true;
  207. }
  208. },
  209. handleKeyUp: function( e ) {
  210. var search,
  211. input = this.element.prev("form").find( "input" );
  212. if ( e.which === $.ui.keyCode.DOWN ) {
  213. if ( this.element.find( "li.ui-btn-active" ).length === 0 ) {
  214. this.element.find( "li:first" ).toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  215. } else {
  216. this.element.find( "li.ui-btn-active a" ).toggleClass( "ui-btn-active");
  217. this.element.find( "li.ui-btn-active" ).toggleClass( "ui-btn-active" ).next().toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  218. }
  219. this.highlightDown();
  220. } else if ( e.which === $.ui.keyCode.UP ) {
  221. if ( this.element.find( "li.ui-btn-active" ).length !== 0 ) {
  222. this.element.find( "li.ui-btn-active a" ).toggleClass( "ui-btn-active");
  223. this.element.find( "li.ui-btn-active" ).toggleClass( "ui-btn-active" ).prev().toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  224. } else {
  225. this.element.find( "li:last" ).toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  226. }
  227. this.highlightUp();
  228. } else if ( typeof e.which !== "undefined" ) {
  229. this.element.find( "li.ui-btn-active" ).removeClass( "ui-btn-active" );
  230. if ( this.options.highlight ) {
  231. search = input.val();
  232. this.element.find( "li" ).each(function() {
  233. $( this ).removeHighlight();
  234. $( this ).highlight( search );
  235. });
  236. }
  237. }
  238. },
  239. submitHandler: function() {
  240. if ( this.element.find( "li.ui-btn-active" ).length !== 0 ) {
  241. var href = this.element.find( "li.ui-btn-active a" ).attr( "href" );
  242. $( ":mobile-pagecontainer" ).pagecontainer( "change", href );
  243. return false;
  244. }
  245. if ( this.options.submitTo ) {
  246. this.submitTo();
  247. }
  248. },
  249. highlightDown: function() {
  250. if ( this.element.find( "li.ui-btn-active" ).hasClass( "ui-screen-hidden" ) ) {
  251. this.element.find( "li.ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  252. this.element.find( "li.ui-btn-active" ).toggleClass( "ui-btn-active" ).next().toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  253. this.highlightDown();
  254. }
  255. return;
  256. },
  257. highlightUp: function() {
  258. if ( this.element.find( "li.ui-btn-active" ).hasClass( "ui-screen-hidden" ) ) {
  259. this.element.find( "li.ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  260. this.element.find( "li.ui-btn-active" ).toggleClass( "ui-btn-active" ).prev().toggleClass( "ui-btn-active" ).find("a").toggleClass( "ui-btn-active" );
  261. this.highlightUp();
  262. }
  263. return;
  264. }
  265. });
  266. })( jQuery );
  267. });