Merge pull request #2054 from stkevintan/patch-2
[JS code style]Fix some irregular coding & Uniform indentpull/1469/merge
commit
6f27d40f13
|
@ -1,9 +1,9 @@
|
||||||
$( document ).ready(function() {
|
$( document ).ready(function() {
|
||||||
var oldURLs=["/README.md","/README.html",".html",".md","/v1.1/","/v1.0/"];
|
var oldURLs = ["/README.md","/README.html",".html",".md","/v1.1/","/v1.0/"];
|
||||||
var fwdDirs=["examples/","cluster/","docs/devel","docs/design"];
|
var fwdDirs = ["examples/","cluster/","docs/devel","docs/design"];
|
||||||
var doRedirect = false;
|
var doRedirect = false;
|
||||||
var notHere = false;
|
var notHere = false;
|
||||||
var forwardingURL=window.location.href;
|
var forwardingURL = window.location.href;
|
||||||
|
|
||||||
var redirects = [{
|
var redirects = [{
|
||||||
"from": "resource-quota",
|
"from": "resource-quota",
|
||||||
|
@ -26,14 +26,14 @@ $( document ).ready(function() {
|
||||||
"to": "http://kubernetes.io/docs/whatisk8s/"
|
"to": "http://kubernetes.io/docs/whatisk8s/"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
for (i=0;i<redirects.length;i++) {
|
for (var i = 0; i < redirects.length; i++) {
|
||||||
if (forwardingURL.indexOf(redirects[i].from) > -1){
|
if (forwardingURL.indexOf(redirects[i].from) > -1){
|
||||||
notHere = true;
|
notHere = true;
|
||||||
window.location.replace(redirects[i].to);
|
window.location.replace(redirects[i].to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0;i<fwdDirs.length;i++) {
|
for (var i = 0; i < fwdDirs.length; i++) {
|
||||||
if (forwardingURL.indexOf(fwdDirs[i]) > -1){
|
if (forwardingURL.indexOf(fwdDirs[i]) > -1){
|
||||||
var urlPieces = forwardingURL.split(fwdDirs[i]);
|
var urlPieces = forwardingURL.split(fwdDirs[i]);
|
||||||
var newURL = "https://github.com/kubernetes/kubernetes/tree/{{page.githubbranch}}/" + fwdDirs[i] + urlPieces[1];
|
var newURL = "https://github.com/kubernetes/kubernetes/tree/{{page.githubbranch}}/" + fwdDirs[i] + urlPieces[1];
|
||||||
|
@ -42,11 +42,11 @@ $( document ).ready(function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!notHere) {
|
if (!notHere) {
|
||||||
for (i=0;i<oldURLs.length;i++) {
|
for (var i = 0; i < oldURLs.length; i++) {
|
||||||
if (forwardingURL.indexOf(oldURLs[i]) > -1 &&
|
if (forwardingURL.indexOf(oldURLs[i]) > -1 &&
|
||||||
forwardingURL.indexOf("404.html") < 0){
|
forwardingURL.indexOf("404.html") < 0){
|
||||||
doRedirect=true;
|
doRedirect = true;
|
||||||
forwardingURL=forwardingURL.replace(oldURLs[i],"/");
|
forwardingURL = forwardingURL.replace(oldURLs[i],"/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (doRedirect){
|
if (doRedirect){
|
||||||
|
|
788
js/script.js
788
js/script.js
|
@ -1,523 +1,523 @@
|
||||||
//modal close button
|
//modal close button
|
||||||
(function(){
|
(function(){
|
||||||
//π.modalCloseButton = function(closingFunction){
|
//π.modalCloseButton = function(closingFunction){
|
||||||
// return π.button('pi-modal-close-button', null, null, closingFunction);
|
// return π.button('pi-modal-close-button', null, null, closingFunction);
|
||||||
//};
|
//};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
var body;
|
var body;
|
||||||
|
|
||||||
//helper functions
|
//helper functions
|
||||||
function copyCode(elem){
|
function copyCode(elem){
|
||||||
if (document.getElementById(elem)) {
|
if (document.getElementById(elem)) {
|
||||||
// create hidden text element, if it doesn't already exist
|
// create hidden text element, if it doesn't already exist
|
||||||
var targetId = "_hiddenCopyText_";
|
var targetId = "_hiddenCopyText_";
|
||||||
// must use a temporary form element for the selection and copy
|
// must use a temporary form element for the selection and copy
|
||||||
target = document.getElementById(targetId);
|
target = document.getElementById(targetId);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
var target = document.createElement("textarea");
|
var target = document.createElement("textarea");
|
||||||
target.style.position = "absolute";
|
target.style.position = "absolute";
|
||||||
target.style.left = "-9999px";
|
target.style.left = "-9999px";
|
||||||
target.style.top = "0";
|
target.style.top = "0";
|
||||||
target.id = targetId;
|
target.id = targetId;
|
||||||
document.body.appendChild(target);
|
document.body.appendChild(target);
|
||||||
}
|
}
|
||||||
target.value = document.getElementById(elem).innerText;
|
target.value = document.getElementById(elem).innerText;
|
||||||
// select the content
|
// select the content
|
||||||
target.setSelectionRange(0, target.value.length);
|
target.setSelectionRange(0, target.value.length);
|
||||||
|
|
||||||
// copy the selection
|
|
||||||
var succeed;
|
|
||||||
try {
|
|
||||||
succeed = document.execCommand("copy");
|
|
||||||
} catch(e) {
|
|
||||||
sweetAlert("Oh, no...","Sorry, your browser doesn't support document.execCommand('copy'), so we can't copy this code to your clipboard.");
|
|
||||||
succeed = false;
|
|
||||||
}
|
|
||||||
if (succeed) sweetAlert("Copied to clipboard:",target.value);
|
|
||||||
return succeed;
|
|
||||||
} else {
|
|
||||||
sweetAlert("Oops!",elem + " not found when trying to copy code");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function booleanAttributeValue(element, attribute, defaultValue){
|
|
||||||
// returns true if an attribute is present with no value
|
|
||||||
// e.g. booleanAttributeValue(element, 'data-modal', false);
|
|
||||||
if (element.hasAttribute(attribute)) {
|
|
||||||
var value = element.getAttribute(attribute);
|
|
||||||
if (value === '' || value === 'true') {
|
|
||||||
return true;
|
|
||||||
} else if (value === 'false') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultValue;
|
// copy the selection
|
||||||
|
var succeed;
|
||||||
|
try {
|
||||||
|
succeed = document.execCommand("copy");
|
||||||
|
} catch(e) {
|
||||||
|
sweetAlert("Oh, no...","Sorry, your browser doesn't support document.execCommand('copy'), so we can't copy this code to your clipboard.");
|
||||||
|
succeed = false;
|
||||||
|
}
|
||||||
|
if (succeed) sweetAlert("Copied to clipboard:",target.value);
|
||||||
|
return succeed;
|
||||||
|
} else {
|
||||||
|
sweetAlert("Oops!",elem + " not found when trying to copy code");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function booleanAttributeValue(element, attribute, defaultValue){
|
||||||
|
// returns true if an attribute is present with no value
|
||||||
|
// e.g. booleanAttributeValue(element, 'data-modal', false);
|
||||||
|
if (element.hasAttribute(attribute)) {
|
||||||
|
var value = element.getAttribute(attribute);
|
||||||
|
if (value === '' || value === 'true') {
|
||||||
|
return true;
|
||||||
|
} else if (value === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function classOnCondition(element, className, condition) {
|
function classOnCondition(element, className, condition) {
|
||||||
if (condition)
|
if (condition)
|
||||||
$(element).addClass(className);
|
$(element).addClass(className);
|
||||||
else
|
else
|
||||||
$(element).removeClass(className);
|
$(element).removeClass(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
function highestZ() {
|
function highestZ() {
|
||||||
var Z = 1000;
|
var Z = 1000;
|
||||||
|
|
||||||
$("*").each(function(){
|
$("*").each(function(){
|
||||||
var thisZ = $(this).css('z-index');
|
var thisZ = $(this).css('z-index');
|
||||||
|
|
||||||
if (thisZ != "auto" && thisZ > Z) Z = ++thisZ;
|
if (thisZ != "auto" && thisZ > Z) Z = ++thisZ;
|
||||||
});
|
});
|
||||||
|
|
||||||
return Z;
|
return Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
function newDOMElement(tag, className, id){
|
function newDOMElement(tag, className, id){
|
||||||
var el = document.createElement(tag);
|
var el = document.createElement(tag);
|
||||||
|
|
||||||
if (className) el.className = className;
|
if (className) el.className = className;
|
||||||
if (id) el.id = id;
|
if (id) el.id = id;
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
function px(n){
|
function px(n){
|
||||||
return n + 'px';
|
return n + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
var kub = (function () {
|
var kub = (function () {
|
||||||
var HEADER_HEIGHT;
|
var HEADER_HEIGHT;
|
||||||
var html, header, mainNav, quickstartButton, hero, encyclopedia, footer, headlineWrapper;
|
var html, header, mainNav, quickstartButton, hero, encyclopedia, footer, headlineWrapper;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
html = $('html');
|
html = $('html');
|
||||||
body = $('body');
|
body = $('body');
|
||||||
header = $('header');
|
header = $('header');
|
||||||
mainNav = $('#mainNav');
|
mainNav = $('#mainNav');
|
||||||
quickstartButton = $('#quickstartButton');
|
quickstartButton = $('#quickstartButton');
|
||||||
hero = $('#hero');
|
hero = $('#hero');
|
||||||
encyclopedia = $('#encyclopedia');
|
encyclopedia = $('#encyclopedia');
|
||||||
footer = $('footer');
|
footer = $('footer');
|
||||||
headlineWrapper = $('#headlineWrapper');
|
headlineWrapper = $('#headlineWrapper');
|
||||||
HEADER_HEIGHT = header.outerHeight();
|
HEADER_HEIGHT = header.outerHeight();
|
||||||
|
|
||||||
resetTheView();
|
resetTheView();
|
||||||
|
|
||||||
window.addEventListener('resize', resetTheView);
|
window.addEventListener('resize', resetTheView);
|
||||||
window.addEventListener('scroll', resetTheView);
|
window.addEventListener('scroll', resetTheView);
|
||||||
window.addEventListener('keydown', handleKeystrokes);
|
window.addEventListener('keydown', handleKeystrokes);
|
||||||
|
|
||||||
document.onunload = function(){
|
document.onunload = function(){
|
||||||
window.removeEventListener('resize', resetTheView);
|
window.removeEventListener('resize', resetTheView);
|
||||||
window.removeEventListener('scroll', resetTheView);
|
window.removeEventListener('scroll', resetTheView);
|
||||||
window.removeEventListener('keydown', handleKeystrokes);
|
window.removeEventListener('keydown', handleKeystrokes);
|
||||||
};
|
};
|
||||||
|
|
||||||
setInterval(setFooterType, 10);
|
setInterval(setFooterType, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setFooterType() {
|
function setFooterType() {
|
||||||
var windowHeight = window.innerHeight;
|
var windowHeight = window.innerHeight;
|
||||||
var bodyHeight;
|
var bodyHeight;
|
||||||
|
|
||||||
switch (html[0].id) {
|
switch (html[0].id) {
|
||||||
case 'docs': {
|
case 'docs': {
|
||||||
bodyHeight = hero.outerHeight() + encyclopedia.outerHeight();
|
bodyHeight = hero.outerHeight() + encyclopedia.outerHeight();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'home':
|
case 'home':
|
||||||
// case 'caseStudies':
|
// case 'caseStudies':
|
||||||
bodyHeight = windowHeight;
|
bodyHeight = windowHeight;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'caseStudies':
|
case 'caseStudies':
|
||||||
case 'partners':
|
case 'partners':
|
||||||
bodyHeight = windowHeight * 2;
|
bodyHeight = windowHeight * 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
bodyHeight = hero.outerHeight() + $('#mainContent').outerHeight();
|
bodyHeight = hero.outerHeight() + $('#mainContent').outerHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var footerHeight = footer.outerHeight();
|
var footerHeight = footer.outerHeight();
|
||||||
classOnCondition(body, 'fixed', windowHeight - footerHeight > bodyHeight);
|
classOnCondition(body, 'fixed', windowHeight - footerHeight > bodyHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTheView() {
|
function resetTheView() {
|
||||||
if (html.hasClass('open-nav')) {
|
if (html.hasClass('open-nav')) {
|
||||||
toggleMenu();
|
toggleMenu();
|
||||||
} else {
|
} else {
|
||||||
HEADER_HEIGHT = header.outerHeight();
|
HEADER_HEIGHT = header.outerHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html.hasClass('open-toc')) {
|
if (html.hasClass('open-toc')) {
|
||||||
toggleToc();
|
toggleToc();
|
||||||
}
|
}
|
||||||
|
|
||||||
classOnCondition(html, 'flip-nav', window.pageYOffset > 0);
|
classOnCondition(html, 'flip-nav', window.pageYOffset > 0);
|
||||||
|
|
||||||
if (html[0].id == 'home') {
|
if (html[0].id == 'home') {
|
||||||
setHomeHeaderStyles();
|
setHomeHeaderStyles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHomeHeaderStyles() {
|
function setHomeHeaderStyles() {
|
||||||
var Y = window.pageYOffset;
|
var Y = window.pageYOffset;
|
||||||
var quickstartBottom = quickstartButton[0].getBoundingClientRect().bottom;
|
var quickstartBottom = quickstartButton[0].getBoundingClientRect().bottom;
|
||||||
|
|
||||||
classOnCondition(html[0], 'y-enough', Y > quickstartBottom);
|
classOnCondition(html[0], 'y-enough', Y > quickstartBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleMenu() {
|
function toggleMenu() {
|
||||||
if (window.innerWidth < 800) {
|
if (window.innerWidth < 800) {
|
||||||
pushmenu.show('primary');
|
pushmenu.show('primary');
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
var newHeight = HEADER_HEIGHT;
|
var newHeight = HEADER_HEIGHT;
|
||||||
|
|
||||||
if (!html.hasClass('open-nav')) {
|
if (!html.hasClass('open-nav')) {
|
||||||
newHeight = mainNav.outerHeight();
|
newHeight = mainNav.outerHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
header.css({height: px(newHeight)});
|
header.css({height: px(newHeight)});
|
||||||
html.toggleClass('open-nav');
|
html.toggleClass('open-nav');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeystrokes(e) {
|
function handleKeystrokes(e) {
|
||||||
switch (e.which) {
|
switch (e.which) {
|
||||||
case 27: {
|
case 27: {
|
||||||
if (html.hasClass('open-nav')) {
|
if (html.hasClass('open-nav')) {
|
||||||
toggleMenu();
|
toggleMenu();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVideo() {
|
function showVideo() {
|
||||||
$('body').css({overflow: 'hidden'});
|
$('body').css({overflow: 'hidden'});
|
||||||
|
|
||||||
var videoPlayer = $("#videoPlayer");
|
var videoPlayer = $("#videoPlayer");
|
||||||
var videoIframe = videoPlayer.find("iframe")[0];
|
var videoIframe = videoPlayer.find("iframe")[0];
|
||||||
videoIframe.src = videoIframe.getAttribute("data-url");
|
videoIframe.src = videoIframe.getAttribute("data-url");
|
||||||
videoPlayer.css({zIndex: highestZ()});
|
videoPlayer.css({zIndex: highestZ()});
|
||||||
videoPlayer.fadeIn(300);
|
videoPlayer.fadeIn(300);
|
||||||
videoPlayer.click(function(){
|
videoPlayer.click(function(){
|
||||||
$('body').css({overflow: 'auto'});
|
$('body').css({overflow: 'auto'});
|
||||||
|
|
||||||
videoPlayer.fadeOut(300, function(){
|
videoPlayer.fadeOut(300, function(){
|
||||||
videoIframe.src = '';
|
videoIframe.src = '';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function tocWasClicked(e) {
|
function tocWasClicked(e) {
|
||||||
var target = $(e.target);
|
var target = $(e.target);
|
||||||
var docsToc = $("#docsToc");
|
var docsToc = $("#docsToc");
|
||||||
return (target[0] === docsToc[0] || target.parents("#docsToc").length > 0);
|
return (target[0] === docsToc[0] || target.parents("#docsToc").length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function listenForTocClick(e) {
|
function listenForTocClick(e) {
|
||||||
if (!tocWasClicked(e)) toggleToc();
|
if (!tocWasClicked(e)) toggleToc();
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleToc() {
|
function toggleToc() {
|
||||||
html.toggleClass('open-toc');
|
html.toggleClass('open-toc');
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (html.hasClass('open-toc')) {
|
if (html.hasClass('open-toc')) {
|
||||||
window.addEventListener('click', listenForTocClick);
|
window.addEventListener('click', listenForTocClick);
|
||||||
} else {
|
} else {
|
||||||
window.removeEventListener('click', listenForTocClick);
|
window.removeEventListener('click', listenForTocClick);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toggleToc: toggleToc,
|
toggleToc: toggleToc,
|
||||||
toggleMenu: toggleMenu,
|
toggleMenu: toggleMenu,
|
||||||
showVideo: showVideo
|
showVideo: showVideo
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
// accordion
|
// accordion
|
||||||
(function(){
|
(function(){
|
||||||
var yah = true;
|
var yah = true;
|
||||||
var moving = false;
|
var moving = false;
|
||||||
var CSS_BROWSER_HACK_DELAY = 25;
|
var CSS_BROWSER_HACK_DELAY = 25;
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
// Safari chokes on the animation here, so...
|
// Safari chokes on the animation here, so...
|
||||||
if (navigator.userAgent.indexOf('Chrome') == -1 && navigator.userAgent.indexOf('Safari') != -1){
|
if (navigator.userAgent.indexOf('Chrome') == -1 && navigator.userAgent.indexOf('Safari') != -1){
|
||||||
var hackStyle = newDOMElement('style');
|
var hackStyle = newDOMElement('style');
|
||||||
hackStyle.innerHTML = '.pi-accordion .wrapper{transition: none}';
|
hackStyle.innerHTML = '.pi-accordion .wrapper{transition: none}';
|
||||||
body.append(hackStyle);
|
body.append(hackStyle);
|
||||||
}
|
}
|
||||||
// Gross.
|
// Gross.
|
||||||
|
|
||||||
$('.pi-accordion').each(function () {
|
$('.pi-accordion').each(function () {
|
||||||
var accordion = this;
|
var accordion = this;
|
||||||
var content = this.innerHTML;
|
var content = this.innerHTML;
|
||||||
var container = newDOMElement('div', 'container');
|
var container = newDOMElement('div', 'container');
|
||||||
container.innerHTML = content;
|
container.innerHTML = content;
|
||||||
$(accordion).empty();
|
$(accordion).empty();
|
||||||
accordion.appendChild(container);
|
accordion.appendChild(container);
|
||||||
CollapseBox($(container));
|
CollapseBox($(container));
|
||||||
});
|
});
|
||||||
|
|
||||||
setYAH();
|
setYAH();
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
yah = false;
|
yah = false;
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
function CollapseBox(container){
|
function CollapseBox(container){
|
||||||
container.children('.item').each(function(){
|
container.children('.item').each(function(){
|
||||||
// build the TOC DOM
|
// build the TOC DOM
|
||||||
// the animated open/close is enabled by having each item's content exist in the flow, at its natural height,
|
// the animated open/close is enabled by having each item's content exist in the flow, at its natural height,
|
||||||
// enclosed in a wrapper with height = 0 when closed, and height = contentHeight when open.
|
// enclosed in a wrapper with height = 0 when closed, and height = contentHeight when open.
|
||||||
var item = this;
|
var item = this;
|
||||||
|
|
||||||
// only add content wrappers to containers, not to links
|
// only add content wrappers to containers, not to links
|
||||||
var isContainer = item.tagName === 'DIV';
|
var isContainer = item.tagName === 'DIV';
|
||||||
|
|
||||||
var titleText = item.getAttribute('data-title');
|
var titleText = item.getAttribute('data-title');
|
||||||
var title = newDOMElement('div', 'title');
|
var title = newDOMElement('div', 'title');
|
||||||
title.innerHTML = titleText;
|
title.innerHTML = titleText;
|
||||||
|
|
||||||
var wrapper, content;
|
var wrapper, content;
|
||||||
|
|
||||||
if (isContainer) {
|
if (isContainer) {
|
||||||
wrapper = newDOMElement('div', 'wrapper');
|
wrapper = newDOMElement('div', 'wrapper');
|
||||||
content = newDOMElement('div', 'content');
|
content = newDOMElement('div', 'content');
|
||||||
content.innerHTML = item.innerHTML;
|
content.innerHTML = item.innerHTML;
|
||||||
wrapper.appendChild(content);
|
wrapper.appendChild(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
item.innerHTML = '';
|
item.innerHTML = '';
|
||||||
item.appendChild(title);
|
item.appendChild(title);
|
||||||
|
|
||||||
if (wrapper) {
|
if (wrapper) {
|
||||||
item.appendChild(wrapper);
|
item.appendChild(wrapper);
|
||||||
$(wrapper).css({height: 0});
|
$(wrapper).css({height: 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(title).click(function(){
|
$(title).click(function(){
|
||||||
if (!yah) {
|
if (!yah) {
|
||||||
if (moving) return;
|
if (moving) return;
|
||||||
moving = true;
|
moving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container[0].getAttribute('data-single')) {
|
if (container[0].getAttribute('data-single')) {
|
||||||
var openSiblings = item.siblings().filter(function(sib){return sib.hasClass('on');});
|
var openSiblings = item.siblings().filter(function(sib){return sib.hasClass('on');});
|
||||||
openSiblings.forEach(function(sibling){
|
openSiblings.forEach(function(sibling){
|
||||||
toggleItem(sibling);
|
toggleItem(sibling);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
if (!isContainer) {
|
if (!isContainer) {
|
||||||
moving = false;
|
moving = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toggleItem(item);
|
toggleItem(item);
|
||||||
}, CSS_BROWSER_HACK_DELAY);
|
}, CSS_BROWSER_HACK_DELAY);
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggleItem(thisItem){
|
function toggleItem(thisItem){
|
||||||
var thisWrapper = $(thisItem).find('.wrapper').eq(0);
|
var thisWrapper = $(thisItem).find('.wrapper').eq(0);
|
||||||
|
|
||||||
if (!thisWrapper) return;
|
if (!thisWrapper) return;
|
||||||
|
|
||||||
var contentHeight = thisWrapper.find('.content').eq(0).innerHeight() + 'px';
|
var contentHeight = thisWrapper.find('.content').eq(0).innerHeight() + 'px';
|
||||||
|
|
||||||
if ($(thisItem).hasClass('on')) {
|
if ($(thisItem).hasClass('on')) {
|
||||||
thisWrapper.css({height: contentHeight});
|
thisWrapper.css({height: contentHeight});
|
||||||
$(thisItem).removeClass('on');
|
$(thisItem).removeClass('on');
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
thisWrapper.css({height: 0});
|
thisWrapper.css({height: 0});
|
||||||
moving = false;
|
moving = false;
|
||||||
}, CSS_BROWSER_HACK_DELAY);
|
}, CSS_BROWSER_HACK_DELAY);
|
||||||
} else {
|
} else {
|
||||||
$(item).addClass('on');
|
$(item).addClass('on');
|
||||||
thisWrapper.css({height: contentHeight});
|
thisWrapper.css({height: contentHeight});
|
||||||
|
|
||||||
var duration = parseFloat(getComputedStyle(thisWrapper[0]).transitionDuration) * 1000;
|
var duration = parseFloat(getComputedStyle(thisWrapper[0]).transitionDuration) * 1000;
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
thisWrapper.css({height: ''});
|
thisWrapper.css({height: ''});
|
||||||
moving = false;
|
moving = false;
|
||||||
}, duration);
|
}, duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
var innerContainers = $(content).children('.container');
|
var innerContainers = $(content).children('.container');
|
||||||
if (innerContainers.length > 0) {
|
if (innerContainers.length > 0) {
|
||||||
innerContainers.each(function(){
|
innerContainers.each(function(){
|
||||||
CollapseBox($(this));
|
CollapseBox($(this));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setYAH() {
|
function setYAH() {
|
||||||
var pathname = location.href.split('#')[0]; // on page load, make sure the page is YAH even if there's a hash
|
var pathname = location.href.split('#')[0]; // on page load, make sure the page is YAH even if there's a hash
|
||||||
var currentLinks = [];
|
var currentLinks = [];
|
||||||
|
|
||||||
$('.pi-accordion a').each(function () {
|
$('.pi-accordion a').each(function () {
|
||||||
if (pathname === this.href) currentLinks.push(this);
|
if (pathname === this.href) currentLinks.push(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
currentLinks.forEach(function (yahLink) {
|
currentLinks.forEach(function (yahLink) {
|
||||||
$(yahLink).parents('.item').each(function(){
|
$(yahLink).parents('.item').each(function(){
|
||||||
$(this).addClass('on');
|
$(this).addClass('on');
|
||||||
$(this).find('.wrapper').eq(0).css({height: 'auto'});
|
$(this).find('.wrapper').eq(0).css({height: 'auto'});
|
||||||
$(this).find('.content').eq(0).css({opacity: 1});
|
$(this).find('.content').eq(0).css({opacity: 1});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(yahLink).addClass('yah');
|
$(yahLink).addClass('yah');
|
||||||
yahLink.onclick = function(e){e.preventDefault();};
|
yahLink.onclick = function(e){e.preventDefault();};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
var pushmenu = (function(){
|
var pushmenu = (function(){
|
||||||
var allPushMenus = {};
|
var allPushMenus = {};
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-auto-burger]').each(function(){
|
$('[data-auto-burger]').each(function(){
|
||||||
var container = this;
|
var container = this;
|
||||||
var id = container.getAttribute('data-auto-burger');
|
var id = container.getAttribute('data-auto-burger');
|
||||||
|
|
||||||
var autoBurger = document.getElementById(id) || newDOMElement('div', 'pi-pushmenu', id);
|
var autoBurger = document.getElementById(id) || newDOMElement('div', 'pi-pushmenu', id);
|
||||||
var ul = autoBurger.querySelector('ul') || newDOMElement('ul');
|
var ul = autoBurger.querySelector('ul') || newDOMElement('ul');
|
||||||
|
|
||||||
$(container).find('a[href], button').each(function () {
|
$(container).find('a[href], button').each(function () {
|
||||||
if (!booleanAttributeValue(this, 'data-auto-burger-exclude', false)) {
|
if (!booleanAttributeValue(this, 'data-auto-burger-exclude', false)) {
|
||||||
var clone = this.cloneNode(true);
|
var clone = this.cloneNode(true);
|
||||||
clone.id = '';
|
clone.id = '';
|
||||||
|
|
||||||
if (clone.tagName == "BUTTON") {
|
if (clone.tagName == "BUTTON") {
|
||||||
var aTag = newDOMElement('a');
|
var aTag = newDOMElement('a');
|
||||||
aTag.href = '';
|
aTag.href = '';
|
||||||
aTag.innerHTML = clone.innerHTML;
|
aTag.innerHTML = clone.innerHTML;
|
||||||
aTag.onclick = clone.onclick;
|
aTag.onclick = clone.onclick;
|
||||||
clone = aTag;
|
clone = aTag;
|
||||||
}
|
}
|
||||||
var li = newDOMElement('li');
|
var li = newDOMElement('li');
|
||||||
li.appendChild(clone);
|
li.appendChild(clone);
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
autoBurger.appendChild(ul);
|
autoBurger.appendChild(ul);
|
||||||
body.append(autoBurger);
|
body.append(autoBurger);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".pi-pushmenu").each(function(){
|
$(".pi-pushmenu").each(function(){
|
||||||
allPushMenus[this.id] = PushMenu(this);
|
allPushMenus[this.id] = PushMenu(this);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function show(objId) {
|
function show(objId) {
|
||||||
allPushMenus[objId].expose();
|
allPushMenus[objId].expose();
|
||||||
}
|
}
|
||||||
|
|
||||||
function PushMenu(el) {
|
function PushMenu(el) {
|
||||||
var html = document.querySelector('html');
|
var html = document.querySelector('html');
|
||||||
|
|
||||||
var overlay = newDOMElement('div', 'overlay');
|
var overlay = newDOMElement('div', 'overlay');
|
||||||
var content = newDOMElement('div', 'content');
|
var content = newDOMElement('div', 'content');
|
||||||
content.appendChild(el.querySelector('*'));
|
content.appendChild(el.querySelector('*'));
|
||||||
|
|
||||||
var side = el.getAttribute("data-side") || "right";
|
var side = el.getAttribute("data-side") || "right";
|
||||||
|
|
||||||
var sled = newDOMElement('div', 'sled');
|
var sled = newDOMElement('div', 'sled');
|
||||||
$(sled).css(side, 0);
|
$(sled).css(side, 0);
|
||||||
|
|
||||||
sled.appendChild(content);
|
sled.appendChild(content);
|
||||||
|
|
||||||
var closeButton = newDOMElement('button', 'push-menu-close-button');
|
var closeButton = newDOMElement('button', 'push-menu-close-button');
|
||||||
closeButton.onclick = closeMe;
|
closeButton.onclick = closeMe;
|
||||||
|
|
||||||
sled.appendChild(closeButton);
|
sled.appendChild(closeButton);
|
||||||
|
|
||||||
overlay.appendChild(sled);
|
overlay.appendChild(sled);
|
||||||
el.innerHTML = '';
|
el.innerHTML = '';
|
||||||
el.appendChild(overlay);
|
el.appendChild(overlay);
|
||||||
|
|
||||||
sled.onclick = function(e){
|
sled.onclick = function(e){
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
|
||||||
overlay.onclick = closeMe;
|
overlay.onclick = closeMe;
|
||||||
|
|
||||||
window.addEventListener('resize', closeMe);
|
window.addEventListener('resize', closeMe);
|
||||||
|
|
||||||
function closeMe(e) {
|
function closeMe(e) {
|
||||||
if (e.target == sled) return;
|
if (e.target == sled) return;
|
||||||
|
|
||||||
$(el).removeClass('on');
|
$(el).removeClass('on');
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$(el).css({display: 'none'});
|
$(el).css({display: 'none'});
|
||||||
|
|
||||||
$(body).removeClass('overlay-on');
|
$(body).removeClass('overlay-on');
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
function exposeMe(){
|
function exposeMe(){
|
||||||
$(body).addClass('overlay-on'); // in the default config, kills body scrolling
|
$(body).addClass('overlay-on'); // in the default config, kills body scrolling
|
||||||
|
|
||||||
$(el).css({
|
$(el).css({
|
||||||
display: 'block',
|
display: 'block',
|
||||||
zIndex: highestZ()
|
zIndex: highestZ()
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$(el).addClass('on');
|
$(el).addClass('on');
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
expose: exposeMe
|
expose: exposeMe
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
show: show
|
show: show
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// Make global nav be active based on pathname
|
// Make global nav be active based on pathname
|
||||||
if ((location.pathname.split("/")[1]) !== ""){
|
if ((location.pathname.split("/")[1]) !== ""){
|
||||||
$('.global-nav li a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
|
$('.global-nav li a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If vendor strip doesn't exist add className
|
// If vendor strip doesn't exist add className
|
||||||
if ( !$('#vendorStrip').length > 0 ) {
|
if ( !$('#vendorStrip').length > 0 ) {
|
||||||
$('#hero').addClass('bot-bar');
|
$('#hero').addClass('bot-bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If is not homepage add class to hero section
|
// If is not homepage add class to hero section
|
||||||
if (!$('#home').length > 0 ) {
|
if (!$('#home').length > 0 ) {
|
||||||
$('#hero').addClass('no-sub');
|
$('#hero').addClass('no-sub');
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue