webhelp.min_v1.4.4.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*custom webhelp*/
  2. var windowheight = $( window ).height();
  3. var windowwidth = $( window ).width();
  4. $( document ).ready(function() {
  5. /*adjust dev branch notification*/
  6. if ($( '#dev-notification' ).length ) {
  7. $( '#dev-notification', '.dev-notification-text' ).width($( '.navbar-header' ).width());
  8. $( '.navbar-header' ).css("padding-top", $( '#dev-notification' ).height() + 10);
  9. }
  10. /*insert links to module functions*/
  11. if ($( 'a.current' ).length && $( 'dt .headerlink' ).length ) {
  12. if (window.location.href.indexOf('/ref/cli/') == -1) {
  13. var tgt = $( 'a.current' );
  14. tgt.after('<ul id="function-list"></ul>');
  15. $('dt .headerlink').each(function(idx, elem) {
  16. var i = [
  17. '<li><a class="function-nav-link" href="', elem.href, '">',
  18. last(elem.href.split('.')),
  19. '</a></li>']
  20. .join('');
  21. $( '#function-list' ).append(i);
  22. });
  23. }
  24. }
  25. /*scroll the right-hand navigation*/
  26. //var wheight = $( window ).height() - $( '#sidebar-static' ).height() - $( '#sidebar-static-bottom' ).height();
  27. var wheight = $( window ).height() - 160;
  28. $(function(){
  29. $( '#sidebar-nav' ).slimScroll({
  30. width: 'inherit',
  31. size: '14px',
  32. height: wheight
  33. }).promise().done(function() {
  34. if (window.location.hash) {
  35. var hash = window.location.hash.substring(1);
  36. var $link = $( '#sidebar-nav').find('a[href$="#' + hash + '"]').addClass("selected");
  37. if ($link.length) {
  38. var scrollTo_val = $link.offset().top - ($( '#sidebar-static' ).height() + 200) + 'px';
  39. $( '#sidebar-nav' ).slimScroll({ scrollTo : scrollTo_val });
  40. }
  41. else if ($( 'a.current' ).length) {
  42. var scrollTo_val = $( 'a.current' ).offset().top - ($( '#sidebar-static' ).height() + 200) + 'px';
  43. $( '#sidebar-nav' ).slimScroll({ scrollTo : scrollTo_val });
  44. }
  45. }
  46. else if ($( 'a.current' ).length) {
  47. var scrollTo_val = $( 'a.current' ).offset().top - ($( '#sidebar-static' ).height() + 200) + 'px';
  48. $( '#sidebar-nav' ).slimScroll({ scrollTo : scrollTo_val });
  49. }
  50. /*hidden by css - make visible after slimScroll plug-in loads*/
  51. $( '#sidebar-wrapper').css('visibility','visible');
  52. });
  53. });
  54. /*permalink display*/
  55. $( 'a.headerlink').html( '<span class="permalink"><i data-container="body" data-toggle="tooltip" data-placement="bottom" title="Link to this location" class="glyphicon glyphicon-link"></i></span>');
  56. $( 'h1,h2,h3,h4,h5,h6').mouseenter(function(){
  57. $(this).find( '.permalink' ).find( 'i' ).css({'color':'#000'});
  58. }).mouseleave(function(){
  59. $(this).find( '.permalink' ).find( 'i' ).css({'color':'#fff'});
  60. });
  61. /*smooth on-page scrolling for long topic*/
  62. $( '#sidebar-nav' ).on('click','a[href^="#"]',function (e) {
  63. e.preventDefault();
  64. $( '#sidebar-nav' ).find( 'a' ).removeClass('selected');
  65. $(this).addClass('selected');
  66. var target = this.hash;
  67. var $target = $(target);
  68. $('html, body').stop().animate({
  69. 'scrollTop': $target.offset().top + 200
  70. }, 900, 'swing', function () {
  71. window.location.hash = target;
  72. });
  73. });
  74. /*scroll to active topic*/
  75. $( '#sidebar-nav' ).on('click','a.function-nav-link',function (e) {
  76. e.preventDefault();
  77. $( 'a.function-nav-link' ).removeClass('selected');
  78. $(this).addClass('selected');
  79. var target = this.hash.substring(1);
  80. var $target = $('dt[id="' + target + '"]');
  81. $('html, body').stop().animate({
  82. 'scrollTop': $target.offset().top + 200
  83. }, 900, 'swing', function () {
  84. window.location.hash = target;
  85. });
  86. });
  87. /*search form*/
  88. $( '#search-form' ).find( 'input' ).keypress(function(e) {
  89. if(e.which == 13) {
  90. var cx = '004624818632696854117:yfmprrbw3pk&q=';
  91. 'find which search instance to use'
  92. if (DOCUMENTATION_OPTIONS.SEARCH_CX) {
  93. cx = DOCUMENTATION_OPTIONS.SEARCH_CX;
  94. }
  95. var searchterm = encodeURIComponent($(this).val());
  96. $(this).val("");
  97. window.location.href = 'https://www.google.com/cse?cx=' + cx + '&q=' + searchterm;
  98. }
  99. });
  100. /*menu collapse*/
  101. $( '#menu-toggle' ).click(function(e) {
  102. e.preventDefault();
  103. $( '#wrapper' ).toggleClass( 'toggled' );
  104. });
  105. /*version page selector*/
  106. $( 'div.releaselinks' ).on('click', 'a', function (e) {
  107. e.preventDefault();
  108. var clickedVer = $(this).attr("href");
  109. var $currentVer = $( 'div.versions' ).find( 'a.active' ).first();
  110. if (window.location.href.indexOf(clickedVer) == -1) {
  111. window.location.href = window.location.href.replace($currentVer.attr("href"), clickedVer);
  112. }
  113. else {
  114. if ($currentVer.text().indexOf("Master") == -1) {
  115. window.location.href = clickedVer + "topics/releases/" + $currentVer.text().trim() + ".html";
  116. }
  117. else window.location.href = clickedVer + "topics/releases/";
  118. }
  119. });
  120. /*lightbox around images*/
  121. $( 'img' ).not( '.nolightbox' ).each(function() {
  122. var source = $(this).attr( 'src' );
  123. var id = $(this).attr( 'id' );
  124. $(this).wrap('<a href="'+ source + '" data-lightbox="' + id + '"></a>' )
  125. });
  126. /*enable bootstrap tooltips*/
  127. $(function () {
  128. $('[data-toggle="tooltip"]').tooltip();
  129. });
  130. /*notification box*/
  131. var box;
  132. $("#notifications").on('click', function(e) {
  133. e.preventDefault();
  134. e.stopPropagation();
  135. $.get('//docs.saltstack.com/en/announcements.html?id=1', function (data) {
  136. box = bootbox.dialog({
  137. title: "Announcements",
  138. message: data
  139. });
  140. _gaq.push(['_trackEvent', 'docs', 'announcement-view']);
  141. });
  142. });
  143. $(document).on('click', '.bootbox', function (event) {
  144. box.modal('hide');
  145. });
  146. getMetaStatus();
  147. }); // $.document.ready
  148. //refresh on window resize
  149. var rtime = new Date(1, 1, 2000, 12,00,00);
  150. var timeout = false;
  151. var delta = 200;
  152. $(window).resize(function() {
  153. if (!$( '#menu-toggle' ).is(":visible")) {
  154. rtime = new Date();
  155. if (timeout === false) {
  156. timeout = true;
  157. setTimeout(resizeend, delta);
  158. }
  159. }
  160. });
  161. function resizeend() {
  162. if (new Date() - rtime < delta) {
  163. setTimeout(resizeend, delta);
  164. } else {
  165. timeout = false;
  166. if ($( window ).height() != windowheight && $(window).width() != windowwidth) {
  167. location.reload(false);
  168. }
  169. }
  170. }
  171. function last(list) {
  172. return list[list.length - 1];
  173. }
  174. var reviewTag = '<p><strong>Status:&nbsp;&nbsp;</strong><span class="label label-warning label-status" data-container="body" data-delay=\'{ "show": 100, "hide": 100 }\' data-toggle="tooltip" data-placement="right" title="This topic is being reviewed for technical accuracy">Technical Review</span></p>';
  175. var draftTag = '<p><strong>Status:&nbsp;&nbsp;</strong><span class="label label-important label-status" data-container="body" data-delay=\'{ "show": 100, "hide": 100 }\' data-toggle="tooltip" data-placement="right" title="This topic is a work in progress and might describe functionality that is not yet implemented. Use with caution.">Draft Content</span></p>';
  176. function getMetaStatus() {
  177. var metas = document.getElementsByTagName('meta');
  178. for (i=0; i<metas.length; i++) {
  179. if (metas[i].getAttribute("name") == "status") {
  180. var statusType = metas[i].getAttribute("content");
  181. (statusType == "review") ? tag = reviewTag : tag = draftTag;
  182. $( "h1" ).first().after(tag);
  183. }
  184. }
  185. }
  186. (function(document, history, location) {
  187. var HISTORY_SUPPORT = !!(history && history.pushState);
  188. var anchorScrolls = {
  189. ANCHOR_REGEX: /^#[^ ]+$/,
  190. OFFSET_HEIGHT_PX: 60,
  191. /**
  192. * Establish events, and fix initial scroll position if a hash is provided.
  193. */
  194. init: function() {
  195. this.scrollIfAnchor(location.hash);
  196. $('body').on('click', 'a', $.proxy(this, 'delegateAnchors'));
  197. },
  198. /**
  199. * Return the offset amount to deduct from the normal scroll position.
  200. * Modify as appropriate to allow for dynamic calculations
  201. */
  202. getFixedOffset: function() {
  203. return this.OFFSET_HEIGHT_PX;
  204. },
  205. /**
  206. * If the provided href is an anchor which resolves to an element on the
  207. * page, scroll to it.
  208. * @param {String} href
  209. * @return {Boolean} - Was the href an anchor.
  210. */
  211. scrollIfAnchor: function(href, pushToHistory) {
  212. var match, anchorOffset;
  213. if(!this.ANCHOR_REGEX.test(href)) {
  214. return false;
  215. }
  216. match = document.getElementById(href.slice(1));
  217. if(match) {
  218. anchorOffset = $(match).offset().top - this.getFixedOffset();
  219. $('html, body').animate({ scrollTop: anchorOffset});
  220. // Add the state to history as-per normal anchor links
  221. if(HISTORY_SUPPORT && pushToHistory) {
  222. history.pushState({}, document.title, location.pathname + href);
  223. }
  224. }
  225. return !!match;
  226. },
  227. /**
  228. * If the click event's target was an anchor, fix the scroll position.
  229. */
  230. delegateAnchors: function(e) {
  231. var elem = e.target;
  232. if(this.scrollIfAnchor(elem.getAttribute('href'), true)) {
  233. e.preventDefault();
  234. }
  235. }
  236. };
  237. $(document).ready($.proxy(anchorScrolls, 'init'));
  238. })(window.document, window.history, window.location);