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