|
1 | 1 | (function( $, undefined ) { |
| 2 | + //special click handling to make widget work remove after nav changes in 1.4 |
| 3 | + var href, |
| 4 | + ele = ""; |
| 5 | + $( document ).on( "click", "a", function( e ) { |
| 6 | + href = $( this ).attr( "href" ); |
| 7 | + var hash = $.mobile.path.parseUrl( href ); |
| 8 | + if( typeof href !== "undefined" && hash !== "" && href !== href.replace( hash,"" ) && hash.search( "/" ) === -1 ){ |
| 9 | + //remove the hash from the link to allow normal loading of the page. |
| 10 | + var newHref = href.replace( hash,"" ); |
| 11 | + $( this ).attr( "href", newHref ); |
| 12 | + } |
| 13 | + ele = $( this ); |
| 14 | + }); |
| 15 | + $( document ).on( "pagebeforechange", function( e, f ){ |
| 16 | + f.originalHref = href; |
| 17 | + }); |
| 18 | + $( document ).on("pagebeforechange", function( e,f ){ |
| 19 | + var hash = $.mobile.path.parseUrl(f.toPage).hash; |
| 20 | + if( typeof hash !== "undefined" && hash.search( "/" ) === -1 && hash !== "" && $( hash ).length > 0 && !$( ".ui-page-active " + hash ).hasClass( "ui-page" ) && !$( ".ui-page-active " + hash ).hasClass( "ui-panel" ) && !$( ".ui-page-active " + hash ).hasClass( "ui-popup" )){ |
| 21 | + //scroll to the id |
| 22 | + var pos = $( hash ).offset().top; |
| 23 | + $.mobile.silentScroll( pos ); |
| 24 | + return false; |
| 25 | + } else if( $.mobile.path.parseUrl( f.originalHref ).hash !== "" ){ |
| 26 | + $( ele ).attr( href, f.originalHref ); |
| 27 | + $.mobile.document.one( "pagechange", function(){ |
| 28 | + hash = $.mobile.path.parseUrl(f.originalHref).hash; |
| 29 | + var pos = $( ".ui-page-active " + hash) .offset().top; |
| 30 | + $.mobile.silentScroll( pos ); |
| 31 | + } ); |
| 32 | + } |
| 33 | + }); |
| 34 | + $( document ).on( "mobileinit", function(){ |
| 35 | + hash = window.location.hash; |
| 36 | + $.mobile.document.one( "pageshow", function(){ |
| 37 | + if( hash !== "" && !$( ".ui-page-active " + hash ).hasClass( "ui-page" ) && !$( ".ui-page-active " + hash ).hasClass( "ui-panel" ) && !$( ".ui-page-active " + hash ).hasClass( "ui-popup" ) && !$( hash ).is( "body" ) ){ |
| 38 | + var pos = $( ".ui-page-active " + hash ).offset().top; |
| 39 | + setTimeout( function(){ |
| 40 | + $.mobile.silentScroll( pos ); |
| 41 | + }, 100 ); |
| 42 | + } |
| 43 | + }); |
| 44 | + }); |
| 45 | + //h2 widget |
| 46 | + $( document ).on( "mobileinit", function(){ |
| 47 | + $.widget( "mobile.h2linker", $.mobile.widget, { |
| 48 | + options:{ |
| 49 | + initSelector: ":jqmData(quicklinks='true')" |
| 50 | + }, |
2 | 51 |
|
3 | | - $.widget( "mobile.h2linker", $.mobile.widget, { |
4 | | - options:{ |
5 | | - initSelector: ":jqmData(quicklinks='true')" |
6 | | - }, |
7 | | - |
8 | | - _create:function(){ |
9 | | - var self = this, |
10 | | - bodyid = "ui-page-top", |
11 | | - panel = "<div data-role='panel' class='jqm-nav-panel jqm-quicklink-panel' data-position='right' data-display='overlay' data-theme='c'><ul data-role='listview' data-inset='false' data-theme='d' data-divider-theme='d' class='jqm-list'><li class='jqm-list-header'>Jump to section</li></ul></div>", |
12 | | - first = true, |
13 | | - h2dictionary = new Object(); |
14 | | - if(typeof $("body").attr("id") === "undefined"){ |
15 | | - $("body").attr("id",bodyid); |
16 | | - } else { |
17 | | - bodyid = $("body").attr("id"); |
18 | | - } |
19 | | - this.element.find("h2").each(function(){ |
20 | | - var id, text = $(this).text(); |
21 | | - |
22 | | - if(typeof $(this).attr("id") === "undefined"){ |
23 | | - id = text.replace(/[^\.a-z0-9:_-]+/i,""); |
24 | | - $(this).attr( "id", id ); |
| 52 | + _create:function(){ |
| 53 | + var self = this, |
| 54 | + bodyid = "ui-page-top", |
| 55 | + panel = "<div data-role='panel' class='jqm-nav-panel jqm-quicklink-panel' data-position='right' data-display='overlay' data-theme='c'><ul data-role='listview' data-inset='false' data-theme='d' data-divider-theme='d' class='jqm-list'><li class='jqm-list-header'>Jump to section</li></ul></div>", |
| 56 | + first = true, |
| 57 | + h2dictionary = new Object(); |
| 58 | + if(typeof $("body").attr("id") === "undefined"){ |
| 59 | + $("body").attr("id",bodyid); |
25 | 60 | } else { |
26 | | - id = $(this).attr("id"); |
| 61 | + bodyid = $("body").attr("id"); |
27 | 62 | } |
| 63 | + this.element.find("h2").each(function(){ |
| 64 | + var id, text = $(this).text(); |
| 65 | + |
| 66 | + if(typeof $(this).attr("id") === "undefined"){ |
| 67 | + id = text.replace(/[^\.a-z0-9:_-]+/i,""); |
| 68 | + $(this).attr( "id", id ); |
| 69 | + } else { |
| 70 | + id = $(this).attr("id"); |
| 71 | + } |
28 | 72 |
|
29 | | - h2dictionary[id] = text; |
30 | | - if(!first){ |
31 | | - $(this).before("<a href='#"+bodyid+"' class='jqm-sections-link ui-link jqm-top-link'>Return to top<span class='ui-icon ui-icon-arrow-u'> </span></a>"); |
32 | | - } else { |
33 | | - $(this).before("<a href='#'' data-ajax='false' class='jqm-sections-link ui-link jqm-top-link jqm-open-quicklink-panel'>Jump to section<span class='ui-icon ui-icon-bars'> </span></a>"); |
| 73 | + h2dictionary[id] = text; |
| 74 | + if(!first){ |
| 75 | + $(this).before("<a href='#"+bodyid+"' class='jqm-sections-link ui-link jqm-top-link'>Return to top<span class='ui-icon ui-icon-arrow-u'> </span></a>"); |
| 76 | + } else { |
| 77 | + $(this).before("<a href='#'' data-ajax='false' class='jqm-sections-link ui-link jqm-top-link jqm-open-quicklink-panel'>Jump to section<span class='ui-icon ui-icon-bars'> </span></a>"); |
| 78 | + } |
| 79 | + first = false; |
| 80 | + }); |
| 81 | + this._on(".jqm-open-quicklink-panel", { |
| 82 | + "click": function(){ |
| 83 | + $(".ui-page-active .jqm-quicklink-panel").panel("open"); |
| 84 | + return false; |
| 85 | + } |
| 86 | + }); |
| 87 | + this._on(".jqm-quicklink-panel", { |
| 88 | + "vclick": function(){ |
| 89 | + this.element.find(".jqm-quicklink-panel").panel("close"); |
| 90 | + } |
| 91 | + }); |
| 92 | + if( $(h2dictionary).length > 0 ){ |
| 93 | + this.element.prepend(panel) |
| 94 | + this.element.find(".jqm-quicklink-panel").panel().find("ul").listview(); |
34 | 95 | } |
35 | | - first = false; |
36 | | - }); |
37 | | - this._on(".jqm-open-quicklink-panel", { |
38 | | - "click": function(){ |
39 | | - $(".ui-page-active .jqm-quicklink-panel").panel("open"); |
40 | | - return false; |
41 | | - } |
42 | | - }); |
| 96 | + $.each(h2dictionary,function(id,text){ |
| 97 | + self.element.find(".jqm-quicklink-panel ul").append("<li><a href='#"+id+"'>"+text+"</a></li>"); |
| 98 | + }); |
| 99 | + self.element.find(".jqm-quicklink-panel ul").listview("refresh"); |
43 | 100 |
|
44 | | - if( $(h2dictionary).length > 0 ){ |
45 | | - this.element.prepend(panel) |
46 | | - this.element.find(".jqm-quicklink-panel").panel().find("ul").listview(); |
47 | | - } |
48 | | - $.each(h2dictionary,function(id,text){ |
49 | | - self.element.find(".jqm-quicklink-panel ul").append("<li><a href='#"+id+"'>"+text+"</a></li>"); |
50 | | - }); |
51 | | - self.element.find(".jqm-quicklink-panel ul").listview("refresh"); |
52 | 101 |
|
53 | | - } |
| 102 | + } |
| 103 | + }); |
54 | 104 | }); |
55 | | - $.mobile.document.bind( "pagecreate create", function( e ) { |
| 105 | + $( document ).bind( "pagecreate create", function( e ) { |
56 | 106 | var initselector = $.mobile.h2linker.prototype.options.initSelector; |
57 | 107 | if($(e.target).data("quicklinks")){ |
58 | 108 | $(e.target).h2linker(); |
|
0 commit comments