PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/static/js/scripts.js

https://gitlab.com/gregtyka/hugo
JavaScript | 283 lines | 236 code | 39 blank | 8 comment | 72 complexity | 7dd25fc4f678cd85d1a9a1a3c8dda118 MD5 | raw file
  1. function initializeJS() {
  2. //tool tips
  3. jQuery('.tooltips').tooltip();
  4. //popovers
  5. jQuery('.popovers').popover();
  6. //sidebar dropdown menu
  7. jQuery('#sidebar .sub-menu > a').click(function () {
  8. // Close previous open submenu
  9. var last = jQuery('.sub.open', jQuery('#sidebar'));
  10. jQuery(last).slideUp(200);
  11. jQuery(last).removeClass("open");
  12. jQuery('.menu-arrow', jQuery(last).parent()).addClass('fa-angle-right');
  13. jQuery('.menu-arrow', jQuery(last).parent()).removeClass('fa-angle-down');
  14. // Toggle current submenu
  15. var sub = jQuery(this).next();
  16. if (sub.is(":visible")) {
  17. jQuery('.menu-arrow', this).addClass('fa-angle-right');
  18. jQuery('.menu-arrow', this).removeClass('fa-angle-down');
  19. sub.slideUp(200);
  20. jQuery(sub).removeClass("open")
  21. } else {
  22. jQuery('.menu-arrow', this).addClass('fa-angle-down');
  23. jQuery('.menu-arrow', this).removeClass('fa-angle-right');
  24. sub.slideDown(200);
  25. jQuery(sub).addClass("open")
  26. }
  27. // Center menu on screen
  28. var o = (jQuery(this).offset());
  29. diff = 200 - o.top;
  30. if(diff>0)
  31. jQuery("#sidebar").scrollTo("-="+Math.abs(diff),500);
  32. else
  33. jQuery("#sidebar").scrollTo("+="+Math.abs(diff),500);
  34. });
  35. // sidebar menu toggle
  36. jQuery(function() {
  37. function responsiveView() {
  38. var wSize = jQuery(window).width();
  39. if (wSize <= 768) {
  40. jQuery('#container').addClass('sidebar-close');
  41. jQuery('#sidebar > ul').hide();
  42. }
  43. if (wSize > 768) {
  44. jQuery('#container').removeClass('sidebar-close');
  45. jQuery('#sidebar > ul').show();
  46. }
  47. }
  48. jQuery(window).on('load', responsiveView);
  49. jQuery(window).on('resize', responsiveView);
  50. });
  51. jQuery('.toggle-nav').click(function () {
  52. if (jQuery('#sidebar > ul').is(":visible") === true) {
  53. jQuery('#main-content').css({
  54. 'margin-left': '0px'
  55. });
  56. jQuery('#sidebar').css({
  57. 'margin-left': '-180px'
  58. });
  59. jQuery('#sidebar > ul').hide();
  60. jQuery("#container").addClass("sidebar-closed");
  61. } else {
  62. jQuery('#main-content').css({
  63. 'margin-left': '180px'
  64. });
  65. jQuery('#sidebar > ul').show();
  66. jQuery('#sidebar').css({
  67. 'margin-left': '0'
  68. });
  69. jQuery("#container").removeClass("sidebar-closed");
  70. }
  71. });
  72. //bar chart
  73. if (jQuery(".custom-custom-bar-chart")) {
  74. jQuery(".bar").each(function () {
  75. var i = jQuery(this).find(".value").html();
  76. jQuery(this).find(".value").html("");
  77. jQuery(this).find(".value").animate({
  78. height: i
  79. }, 2000)
  80. })
  81. }
  82. }
  83. (function(){
  84. var caches = {};
  85. $.fn.showGithub = function(user, repo, type, count){
  86. $(this).each(function(){
  87. var $e = $(this);
  88. var user = $e.data('user') || user,
  89. repo = $e.data('repo') || repo,
  90. type = $e.data('type') || type || 'watch',
  91. count = $e.data('count') == 'true' || count || true;
  92. var $mainButton = $e.html('<span class="github-btn"><a class="btn btn-xs btn-default" href="#" target="_blank"><i class="icon-github"></i> <span class="gh-text"></span></a><a class="gh-count"href="#" target="_blank"></a></span>').find('.github-btn'),
  93. $button = $mainButton.find('.btn'),
  94. $text = $mainButton.find('.gh-text'),
  95. $counter = $mainButton.find('.gh-count');
  96. function addCommas(a) {
  97. return String(a).replace(/(\d)(?=(\d{3})+$)/g, '$1,');
  98. }
  99. function callback(a) {
  100. if (type == 'watch') {
  101. $counter.html(addCommas(a.watchers));
  102. } else {
  103. if (type == 'fork') {
  104. $counter.html(addCommas(a.forks));
  105. } else {
  106. if (type == 'follow') {
  107. $counter.html(addCommas(a.followers));
  108. }
  109. }
  110. }
  111. if (count) {
  112. $counter.css('display', 'inline-block');
  113. }
  114. }
  115. function jsonp(url) {
  116. var ctx = caches[url] || {};
  117. caches[url] = ctx;
  118. if(ctx.onload || ctx.data){
  119. if(ctx.data){
  120. callback(ctx.data);
  121. } else {
  122. setTimeout(jsonp, 500, url);
  123. }
  124. }else{
  125. ctx.onload = true;
  126. $.getJSON(url, function(a){
  127. ctx.onload = false;
  128. ctx.data = a;
  129. callback(a);
  130. });
  131. }
  132. }
  133. var urlBase = 'https://github.com/' + user + '/' + repo;
  134. $button.attr('href', urlBase + '/');
  135. if (type == 'watch') {
  136. $mainButton.addClass('github-watchers');
  137. $text.html('Star');
  138. $counter.attr('href', urlBase + '/stargazers');
  139. } else {
  140. if (type == 'fork') {
  141. $mainButton.addClass('github-forks');
  142. $text.html('Fork');
  143. $counter.attr('href', urlBase + '/network');
  144. } else {
  145. if (type == 'follow') {
  146. $mainButton.addClass('github-me');
  147. $text.html('Follow @' + user);
  148. $button.attr('href', 'https://github.com/' + user);
  149. $counter.attr('href', 'https://github.com/' + user + '/followers');
  150. }
  151. }
  152. }
  153. if (type == 'follow') {
  154. jsonp('https://api.github.com/users/' + user);
  155. } else {
  156. jsonp('https://api.github.com/repos/' + user + '/' + repo);
  157. }
  158. });
  159. };
  160. })();
  161. (function($){
  162. (function(){
  163. var caches = {};
  164. $.fn.showGithub = function(user, repo, type, count){
  165. $(this).each(function(){
  166. var $e = $(this);
  167. var user = $e.data('user') || user,
  168. repo = $e.data('repo') || repo,
  169. type = $e.data('type') || type || 'watch',
  170. count = $e.data('count') == 'true' || count || true;
  171. var $mainButton = $e.html('<span class="github-btn"><a class="btn btn-xs btn-default" href="#" target="_blank"><i class="icon-github"></i> <span class="gh-text"></span></a><a class="gh-count"href="#" target="_blank"></a></span>').find('.github-btn'),
  172. $button = $mainButton.find('.btn'),
  173. $text = $mainButton.find('.gh-text'),
  174. $counter = $mainButton.find('.gh-count');
  175. function addCommas(a) {
  176. return String(a).replace(/(\d)(?=(\d{3})+$)/g, '$1,');
  177. }
  178. function callback(a) {
  179. if (type == 'watch') {
  180. $counter.html(addCommas(a.watchers));
  181. } else {
  182. if (type == 'fork') {
  183. $counter.html(addCommas(a.forks));
  184. } else {
  185. if (type == 'follow') {
  186. $counter.html(addCommas(a.followers));
  187. }
  188. }
  189. }
  190. if (count) {
  191. $counter.css('display', 'inline-block');
  192. }
  193. }
  194. function jsonp(url) {
  195. var ctx = caches[url] || {};
  196. caches[url] = ctx;
  197. if(ctx.onload || ctx.data){
  198. if(ctx.data){
  199. callback(ctx.data);
  200. } else {
  201. setTimeout(jsonp, 500, url);
  202. }
  203. }else{
  204. ctx.onload = true;
  205. $.getJSON(url, function(a){
  206. ctx.onload = false;
  207. ctx.data = a;
  208. callback(a);
  209. });
  210. }
  211. }
  212. var urlBase = 'https://github.com/' + user + '/' + repo;
  213. $button.attr('href', urlBase + '/');
  214. if (type == 'watch') {
  215. $mainButton.addClass('github-watchers');
  216. $text.html('Star');
  217. $counter.attr('href', urlBase + '/stargazers');
  218. } else {
  219. if (type == 'fork') {
  220. $mainButton.addClass('github-forks');
  221. $text.html('Fork');
  222. $counter.attr('href', urlBase + '/network');
  223. } else {
  224. if (type == 'follow') {
  225. $mainButton.addClass('github-me');
  226. $text.html('@' + user);
  227. $button.attr('href', 'https://github.com/' + user);
  228. $counter.attr('href', 'https://github.com/' + user + '/followers');
  229. }
  230. }
  231. }
  232. if (type == 'follow') {
  233. jsonp('https://api.github.com/users/' + user);
  234. } else {
  235. jsonp('https://api.github.com/repos/' + user + '/' + repo);
  236. }
  237. });
  238. };
  239. })();
  240. })(jQuery);
  241. jQuery(document).ready(function(){
  242. initializeJS();
  243. $('[rel=show-github]').showGithub();
  244. });