');
dropdown.find('ul').append(item);
});
select.on('change', function () {
var val = select.val();
toggle.find('span').text(select.find('option:selected').text());
});
toggle.bind('click', function (e) {
e.preventDefault();
e.stopPropagation();
if (viewport == 'mobile' && !(isFirefox || isIE)) {
openSelect(select);
return false;
}
if ($(this).hasClass('active')) {
toogleDropdown(container, false);
$(this).removeClass('active');
} else {
$.each($('.' + container.attr('class')), function (index, val) {
if ($(this).find('.ht-select-button').hasClass('active')) {
toogleDropdown($(this), false);
}
});
toogleDropdown(container, true);
$(this).addClass('active');
}
return false;
});
}
/** Check if all of the entries in the given select are runtime accessible (currently only relevant for versions). */
function allEntriesAccessible(select) {
var allAccessible = true;
if (select.attr('name') === 'scroll-versions:version-name') {
$.each(select.find('option'), function () {
allAccessible &= ($(this).attr('data-version-accessible') === 'true');
});
}
return allAccessible;
}
/** Create the text for the drop-down entries (version entries may contain some extra info other than the property name). */
function createOptionText(option, showVersionAccessibility) {
var optionText = option.text();
if (showVersionAccessibility) {
var versionAccessible = option.attr('data-version-accessible');
if (versionAccessible) {
optionText += ' ';
}
}
return optionText;
}
function toogleDropdown(container, open) {
if (open) {
$('body').bind('click', function (e) {
e.preventDefault();
if ($(e.target).is(container.find('*')))return;
toogleDropdown(container, !open);
});
} else {
$('body').unbind('click');
}
var toggle = container.find('.ht-select-button');
var dropdown = container.find('.ht-dropdown');
if (open) {
toggle.addClass('active');
dropdown.addClass('open');
$.each(dropdown.find('li'), function (index, val) {
$(this).bind('mouseover', function () {
dropdown.find('li a').removeClass('hover');
$(this).find('a').addClass('hover');
});
$(this).find('a').bind('click', function (e) {
e.preventDefault();
var name = $(e.target).closest('a').attr('data-scroll-integration-name');
var value = $(e.target).closest('a').attr('data-scroll-integration-value');
var title = $(e.target).closest('a').attr('data-scroll-integration-title');
toggle.find('span').text(title);
var target = window.location.pathname + '?' + name + '=' + value;
var context = toggle.closest('form').find('input[name=context]').val();
if (context) {
target += '&context=' + context;
}
window.location.href = target;
});
});
} else {
toggle.removeClass('active');
dropdown.removeClass('open');
}
}
/*===================================
= Init Footer =
===================================*/
function initFooter() {
checkFooter();
$('#ht-jump-top').bind('click', function (e) {
e.preventDefault();
$('body,html').animate({
scrollTop: 0},
100);
});
}
function checkFooter() {
if ($('article.ht-content').outerHeight() < $(window).innerHeight()) {
$('#ht-jump-top').fadeOut();
} else {
$('#ht-jump-top').fadeIn();
}
}
/*=============================================
= Media Query Detection =
=============================================*/
function checkDevice() {
var i = parseInt($('#ht-mq-detect').css('width').replace('px', ''));
switch (i) {
case 1:
viewport = 'mobile';
break;
case 2:
viewport = 'tablet';
break;
case 3:
viewport = 'tablet';
break;
case 4:
viewport = 'desktop';
break;
case 5:
viewport = 'desktop';
break;
}
if (viewport != 'desktop')endDragbar();
else {
setDragbar(parseInt(getCookie('sidebar-width')));
$('html').removeClass('show-sidebar');
}
}
/*=====================================
= Window Resize =
=====================================*/
var rtime = new Date(1, 1, 2000, 12, 00, 00);
var timeout = false;
var delta = 200;
$(window).resize(function () {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
function resizeend() {
if (new Date() - rtime < delta) {
setTimeout(resizeend, delta);
} else {
timeout = false;
checkFooter();
checkDevice();
checkGrid();
}
}
function openSelect(selector) {
var element = $(selector)[0], worked = false;
if (document.createEvent) { // all browsers
var e = document.createEvent("MouseEvents");
e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
worked = element.dispatchEvent(e);
} else if (element.fireEvent) { // ie
worked = element.fireEvent("onmousedown");
}
if (!worked) { // unknown browser / error
}
}
/*=====================================
= Keyboard =
=====================================*/
var searchFieldActive;
var lastKey;
function initKeyboard() {
searchFieldActive = false;
$('body').bind('keyup', function (e) {
if (searchFieldActive && e.which != 27) {
return;
}
switch (e.which) {
case 219: // [
if (viewport !== 'desktop') {
toggleSidebar();
}
break;
case 191: // /
if (!sidebarExpanded) {
openSearch();
}
break;
case 71: // g
if (lastKey == 71) {
if (!sidebarExpanded) {
openSearch();
}
}
break;
case 27: // esc
closeSearch();
break;
}
lastKey = e.which;
});
}
/*=====================================
= Cookies =
=====================================*/
function setCookie(cname, cvalue) {
if (window.location.origin == 'file://') {
try {
localStorage.setItem(cname, cvalue);
} catch (e) {
console.log('Saving the state of the drag-bar is not supported because localStorage is not available');
}
} else {
var d = new Date();
d.setTime(d.getTime() + (24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
}
}
function getCookie(cname) {
if (window.location.origin == 'file://') {
try {
var value = localStorage.getItem(cname);
if (typeof value != 'undefined') {
return value;
}
} catch (e) {
console.log('Saving the state of the drag-bar is not supported because localStorage is not available');
}
} else {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
}
return "";
}
/*=====================================
= GRID =
=====================================*/
function checkGrid() {
if ($('#ht-wrap-container').width() > 1024) {
$('#ht-wrap-container').addClass('sp-grid-float');
$('#ht-wrap-container').removeClass('sp-grid-fluid');
} else {
$('#ht-wrap-container').addClass('sp-grid-fluid');
$('#ht-wrap-container').removeClass('sp-grid-float');
}
}
})($);