// jscs:disable requirecamelcaseoruppercaseidentifiers
'use strict';
$(function() {
$.ajax({
url: 'https://api.github.com/repos/vsn4ik/bootstrap-submenu',
success: function(data) {
// xss check
if (typeof data.stargazers_count != 'number') {
return;
}
var $group = $('
');
$group.append('' + data.stargazers_count + ' ');
$('#gh-view-link').wrap($group);
}
});
/**
* document.documentelement: 'html', for mozilla firefox
* document.body: 'body', for other browsers
*/
var containers = [
document.body,
document.documentelement
];
var $scrollbtn = $('#scroll-top');
function updatescrollbtncls() {
var scrolltop = containers.reduce(function(result, element) {
return result + element.scrolltop;
}, 0);
$scrollbtn.toggleclass('hidden', scrolltop < 100);
}
$scrollbtn.on('click', function() {
window.onscroll = null;
$(this).addclass('hidden');
// 'html' for mozilla firefox, 'body' for other browsers
$(containers).animate({
scrolltop: 0
}, 800, $.proxy(function() {
window.onscroll = updatescrollbtncls;
}, this));
});
window.onscroll = updatescrollbtncls;
// dropdown fix
$('.dropdown > a[tabindex]').on('keydown', function(event) {
// 13: return
if (event.keycode == 13) {
$(this).dropdown('toggle');
}
});
// для отмены закрытия при клике на неактивный элемент либо padding
$('.dropdown-menu').on('click', function(event) {
if (this === event.target) {
event.stoppropagation();
}
});
$('[data-submenu]').submenupicker();
updatescrollbtncls();
hljs.inithighlighting();
});