Dashboard sipadu mbip
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

h2widget.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. hashEl, hashElInPage;
  21. try {
  22. hashEl = $( hash );
  23. } catch( e ) {
  24. hashEl = $();
  25. }
  26. try {
  27. hashElInPage = $( ".ui-page-active " + hash );
  28. } catch( e ) {
  29. hashElInPage = $();
  30. }
  31. if( typeof hash !== "undefined" &&
  32. hash.search( "/" ) === -1 &&
  33. hash !== "" &&
  34. hashEl.length > 0 &&
  35. !hashEl.hasClass( "ui-page" ) &&
  36. !hashEl.hasClass( "ui-popup" ) &&
  37. hashEl.data('role') !== "page" &&
  38. !hashElInPage.hasClass( "ui-panel" ) &&
  39. !hashElInPage.hasClass( "ui-popup" ) ) {
  40. //scroll to the id
  41. var pos = hashEl.offset().top;
  42. $.mobile.silentScroll( pos );
  43. $.mobile.navigate( hash, '', true );
  44. } else if( typeof f.toPage !== "object" &&
  45. hash !== "" &&
  46. $.mobile.path.parseUrl( href ).hash !== "" &&
  47. !hashEl.hasClass( "ui-page" ) && hashEl.attr('data-role') !== "page" &&
  48. !hashElInPage.hasClass( "ui-panel" ) &&
  49. !hashElInPage.hasClass( "ui-popup" ) ) {
  50. $( ele ).attr( "href", href );
  51. $.mobile.document.one( "pagechange", function() {
  52. if( typeof hash !== "undefined" &&
  53. hash.search( "/" ) === -1 &&
  54. hash !== "" &&
  55. hashEl.length > 0 &&
  56. hashElInPage.length > 0 &&
  57. !hashEl.hasClass( "ui-page" ) &&
  58. hashEl.data('role') !== "page" &&
  59. !hashElInPage.hasClass( "ui-panel" ) &&
  60. !hashElInPage.hasClass( "ui-popup" ) ) {
  61. hash = $.mobile.path.parseUrl( href ).hash;
  62. var pos = hashElInPage.offset().top;
  63. $.mobile.silentScroll( pos );
  64. }
  65. } );
  66. }
  67. });
  68. $( document ).on( "mobileinit", function(){
  69. hash = window.location.hash;
  70. $.mobile.document.one( "pageshow", function(){
  71. var hashEl, hashElInPage;
  72. try {
  73. hashEl = $( hash );
  74. } catch( e ) {
  75. hashEl = $();
  76. }
  77. try {
  78. hashElInPage = $( ".ui-page-active " + hash );
  79. } catch( e ) {
  80. hashElInPage = $();
  81. }
  82. if( hash !== "" &&
  83. hashEl.length > 0 &&
  84. hashElInPage.length > 0 &&
  85. hashEl.attr('data-role') !== "page" &&
  86. !hashEl.hasClass( "ui-page" ) &&
  87. !hashElInPage.hasClass( "ui-panel" ) &&
  88. !hashElInPage.hasClass( "ui-popup" ) &&
  89. !hashEl.is( "body" ) ){
  90. var pos = hashElInPage.offset().top;
  91. setTimeout( function(){
  92. $.mobile.silentScroll( pos );
  93. }, 100 );
  94. }
  95. });
  96. });
  97. //h2 widget
  98. $( document ).on( "mobileinit", function(){
  99. $.widget( "mobile.h2linker", {
  100. options:{
  101. initSelector: ":jqmData(quicklinks='true')"
  102. },
  103. _create:function(){
  104. var self = this,
  105. bodyid = "ui-page-top",
  106. panel = "<div data-role='panel' class='jqm-nav-panel jqm-quicklink-panel' data-position='right' data-display='overlay' data-theme='a'><ul data-role='listview' data-inset='false' data-theme='a' data-divider-theme='a' data-icon='false' class='jqm-list'><li data-role='list-divider'>Quick Links</li></ul></div>",
  107. first = true,
  108. h2dictionary = new Object();
  109. if(typeof $("body").attr("id") === "undefined"){
  110. $("body").attr("id",bodyid);
  111. } else {
  112. bodyid = $("body").attr("id");
  113. }
  114. this.element.find("div.jqm-content>h2").each(function(){
  115. var id, text = $(this).text();
  116. if(typeof $(this).attr("id") === "undefined"){
  117. id = text.replace(/[^\.a-z0-9:_-]+/gi,"");
  118. $(this).attr( "id", id );
  119. } else {
  120. id = $(this).attr("id");
  121. }
  122. h2dictionary[id] = text;
  123. if(!first){
  124. $(this).before( "<a href='#" + bodyid + "' class='jqm-deeplink ui-icon-carat-u ui-alt-icon'>Top</a>");
  125. } else {
  126. $(this).before("<a href='#' data-ajax='false' class='jqm-deeplink jqm-open-quicklink-panel ui-icon-carat-l ui-alt-icon'>Quick Links</a>");
  127. }
  128. first = false;
  129. });
  130. this._on(".jqm-open-quicklink-panel", {
  131. "click": function(){
  132. $(".ui-page-active .jqm-quicklink-panel").panel("open");
  133. return false;
  134. }
  135. });
  136. this._on( document, {
  137. "pagebeforechange": function(){
  138. this.element.find(".jqm-quicklink-panel").panel("close");
  139. this.element.find(".jqm-quicklink-panel .ui-btn-active").removeClass("ui-btn-active");
  140. }
  141. });
  142. if( $(h2dictionary).length > 0 ){
  143. this.element.prepend(panel)
  144. this.element.find(".jqm-quicklink-panel").panel().find("ul").listview();
  145. }
  146. $.each(h2dictionary,function(id,text){
  147. self.element.find(".jqm-quicklink-panel ul").append("<li><a href='#"+id+"'>"+text+"</a></li>");
  148. });
  149. self.element.find(".jqm-quicklink-panel ul").listview("refresh");
  150. }
  151. });
  152. });
  153. $( document ).bind( "pagecreate create", function( e ) {
  154. var initselector = $.mobile.h2linker.prototype.options.initSelector;
  155. if($(e.target).data("quicklinks")){
  156. $(e.target).h2linker();
  157. }
  158. });
  159. })( jQuery );