Browse Source

Fix JSHint warnings.

pull/379/head
XhmikosR 11 years ago
parent
commit
53180e031f
  1. 59
      docs/assets/js/docs.js
  2. 22
      docs/assets/js/fingerblast.js
  3. 6
      js/popovers.js
  4. 75
      js/push.js
  5. 2
      js/segmented-controllers.js
  6. 17
      js/sliders.js
  7. 2
      js/toggles.js

59
docs/assets/js/docs.js

@ -1,8 +1,10 @@
/* jshint jquery: true */
/* global FingerBlast: true */
$(function() { $(function() {
var doc; var doc;
var device; var device;
var platformToggle;
var windowWidth; var windowWidth;
var windowHeight; var windowHeight;
var pageHeight; var pageHeight;
@ -10,13 +12,14 @@ $(function() {
var footerHeight; var footerHeight;
var navComponentLinks; var navComponentLinks;
var componentsList; var componentsList;
var componentLinks;
var contentSection; var contentSection;
var currentActive; var currentActive;
var topCache; var topCache;
var win;
var bod;
var eventListeners; var eventListeners;
var toolbarToggle; var toolbarToggle;
var toggleTop;
var toggleHeight;
var initialize = function () { var initialize = function () {
@ -24,17 +27,17 @@ $(function() {
topCache = []; topCache = [];
win = $(window); win = $(window);
doc = $(document); doc = $(document);
bod = $(document.body) bod = $(document.body);
device = device || $('.js-device'); device = device || $('.js-device');
navComponentLinks = $('.js-jump-menu'); navComponentLinks = $('.js-jump-menu');
componentsList = $('.js-component-group'); componentsList = $('.js-component-group');
componentLinks = $('.component-example a'); componentLinks = $('.component-example a');
contentSection = $('.component'); contentSection = $('.component');
topCache = contentSection.map(function () { return $(this).offset().top }) topCache = contentSection.map(function () { return $(this).offset().top; });
windowHeight = $(window).height() / 3 windowHeight = $(window).height() / 3;
windowWidth = $(window).width(); windowWidth = $(window).width();
pageHeight = $(document).height(); pageHeight = $(document).height();
contentPadding = parseInt($('.docs-content').css('padding-bottom')); contentPadding = parseInt($('.docs-content').css('padding-bottom'), 10);
footerHeight = $('.docs-footer').outerHeight(false); footerHeight = $('.docs-footer').outerHeight(false);
toolbarToggle = $('.js-docs-component-toolbar'); toolbarToggle = $('.js-docs-component-toolbar');
@ -50,7 +53,7 @@ $(function() {
calculateToggle(); calculateToggle();
if (!eventListeners) addEventListeners(); if (!eventListeners) addEventListeners();
} };
var addEventListeners = function () { var addEventListeners = function () {
eventListeners = true; eventListeners = true;
@ -72,11 +75,11 @@ $(function() {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
componentsList.toggleClass('active'); componentsList.toggleClass('active');
}) });
doc.on('click', function () { doc.on('click', function () {
componentsList.removeClass('active'); componentsList.removeClass('active');
}) });
// Platform switcher // Platform switcher
$('.platform-switch').on('click', function () { $('.platform-switch').on('click', function () {
@ -101,58 +104,58 @@ $(function() {
win.on('scroll', calculateScroll); win.on('scroll', calculateScroll);
win.on('scroll', calculateToggle); win.on('scroll', calculateToggle);
} };
var checkDesktopContent = function () { var checkDesktopContent = function () {
windowWidth = $(window).width(); windowWidth = $(window).width();
if (windowWidth <= 768) { if (windowWidth <= 768) {
var content = $('.content') var content = $('.content');
if (content.length > 1) { if (content.length > 1) {
$(content[0]).remove() $(content[0]).remove();
}
} }
} }
};
var calculateScroll = function() { var calculateScroll = function() {
// if small screen don't worry about this // if small screen don't worry about this
if (windowWidth <= 768) return if (windowWidth <= 768) return;
// Save scrollTop value // Save scrollTop value
var contentSectionItem; var contentSectionItem;
var currentTop = win.scrollTop(); var currentTop = win.scrollTop();
if((device.initialTop - currentTop) <= device.dockingOffset) { if((device.initialTop - currentTop) <= device.dockingOffset) {
device[0].className = "device device-fixed"; device[0].className = 'device device-fixed';
device.css({top: device.dockingOffset}) device.css({top: device.dockingOffset});
} else { } else {
device[0].className = "device" device[0].className = 'device';
device[0].setAttribute('style','') device[0].setAttribute('style','');
} }
// Injection of components into device // Injection of components into device
for (var l = contentSection.length; l--;) { for (var l = contentSection.length; l--;) {
if ((topCache[l] - currentTop) < windowHeight) { if ((topCache[l] - currentTop) < windowHeight) {
if (currentActive == l) return; if (currentActive === l) return;
currentActive = l; currentActive = l;
bod.find('.component.active').removeClass('active'); bod.find('.component.active').removeClass('active');
contentSectionItem = $(contentSection[l]) contentSectionItem = $(contentSection[l]);
contentSectionItem.addClass('active') contentSectionItem.addClass('active');
if(contentSectionItem.attr('id')) { if(contentSectionItem.attr('id')) {
device.attr("id", contentSectionItem.attr('id') + "InDevice"); device.attr('id', contentSectionItem.attr('id') + 'InDevice');
} else { } else {
device.attr("id", "") device.attr('id', '');
} }
if (!contentSectionItem.hasClass('informational')) { if (!contentSectionItem.hasClass('informational')) {
updateContent(contentSectionItem.find('.highlight .html').text()) updateContent(contentSectionItem.find('.highlight .html').text());
} }
break break;
} }
} }
function updateContent(content) { function updateContent(content) {
$('#iwindow').html(content); $('#iwindow').html(content);
} }
} };
// Toolbar toggle // Toolbar toggle
var calculateToggle = function () { var calculateToggle = function () {
@ -165,7 +168,7 @@ $(function() {
toolbarToggle.removeClass('visible'); toolbarToggle.removeClass('visible');
componentsList.removeClass('active'); componentsList.removeClass('active');
} }
} };
$(window).on('load resize', initialize); $(window).on('load resize', initialize);
$(window).on('load', function () { new FingerBlast('.device-content'); }); $(window).on('load', function () { new FingerBlast('.device-content'); });

22
docs/assets/js/fingerblast.js

@ -2,8 +2,10 @@
// -------------- // --------------
// Adapted from phantom limb by brian cartensen // Adapted from phantom limb by brian cartensen
/* global GLOBAL: true */
function FingerBlast(element) { function FingerBlast(element) {
this.element = typeof element == 'string' ? document.querySelector(element) : element; this.element = typeof element === 'string' ? document.querySelector(element) : element;
this.listen(); this.listen();
} }
@ -23,13 +25,13 @@ FingerBlast.prototype = {
function contains (element, ancestor) { function contains (element, ancestor) {
var descendants, index, descendant; var descendants, index, descendant;
if ("compareDocumentPosition" in ancestor) { if ('compareDocumentPosition' in ancestor) {
return !!(ancestor.compareDocumentPosition(element) & 16); return !!(ancestor.compareDocumentPosition(element) & 16);
} else if ("contains" in ancestor) { } else if ('contains' in ancestor) {
return ancestor != element && ancestor.contains(element); return ancestor !== element && ancestor.contains(element);
} else { } else {
for (descendants = ancestor.getElementsByTagName("*"), index = 0; descendant = descendants[index++];) { for (descendants = ancestor.getElementsByTagName('*'), index = 0; descendant = descendants[index++];) {
if (descendant == element) return true; if (descendant === element) return true;
} }
return false; return false;
} }
@ -37,12 +39,12 @@ FingerBlast.prototype = {
this.element.addEventListener('mouseover', function (e) { this.element.addEventListener('mouseover', function (e) {
var target = e.relatedTarget; var target = e.relatedTarget;
if (target != this && !contains(target, this)) activate(); if (target !== this && !contains(target, this)) activate();
}); });
this.element.addEventListener("mouseout", function (e) { this.element.addEventListener('mouseout', function (e) {
var target = e.relatedTarget; var target = e.relatedTarget;
if (target != this && !contains(target, this)) deactivate(e); if (target !== this && !contains(target, this)) deactivate(e);
}); });
}, },
@ -116,7 +118,7 @@ FingerBlast.prototype = {
if (!this.target) return; if (!this.target) return;
// Convert "ontouch*" properties and attributes to listeners. // Convert 'ontouch*' properties and attributes to listeners.
var onEventName = 'on' + eventName; var onEventName = 'on' + eventName;
if (onEventName in this.target) { if (onEventName in this.target) {

6
js/popovers.js

@ -18,7 +18,7 @@
var onPopoverHidden = function () { var onPopoverHidden = function () {
popover.style.display = 'none'; popover.style.display = 'none';
popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
} };
var backdrop = function () { var backdrop = function () {
var element = document.createElement('div'); var element = document.createElement('div');
@ -37,7 +37,7 @@
var getPopover = function (e) { var getPopover = function (e) {
var anchor = findPopovers(e.target); var anchor = findPopovers(e.target);
if (!anchor || !anchor.hash || (anchor.hash.indexOf("/") > 0)) return; if (!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) return;
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
@ -51,7 +51,7 @@
if (!popover || !popover.classList.contains('popover')) return; if (!popover || !popover.classList.contains('popover')) return;
return popover; return popover;
} };
var showHidePopover = function (e) { var showHidePopover = function (e) {
var popover = getPopover(e); var popover = getPopover(e);

75
js/push.js

@ -5,6 +5,8 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
/* global _gaq: true */
!function () { !function () {
var noop = function () {}; var noop = function () {};
@ -56,7 +58,7 @@
}; };
var cachePop = function (id, direction) { var cachePop = function (id, direction) {
var forward = direction == 'forward'; var forward = direction === 'forward';
var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'); var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]');
var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]');
var pushStack = forward ? cacheBackStack : cacheForwardStack; var pushStack = forward ? cacheBackStack : cacheForwardStack;
@ -86,7 +88,7 @@
|| location.host !== target.host || location.host !== target.host
|| !target.hash && /#/.test(target.href) || !target.hash && /#/.test(target.href)
|| target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '') || target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '')
|| target.getAttribute('data-ignore') == 'push' || target.getAttribute('data-ignore') === 'push'
) return; ) return;
return target; return target;
@ -133,16 +135,16 @@
if (activeObj.title) document.title = activeObj.title; if (activeObj.title) document.title = activeObj.title;
if (direction == 'back') { if (direction === 'back') {
transitionFrom = JSON.parse(direction == 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack); transitionFrom = JSON.parse(direction === 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack);
transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]); transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]);
} else { } else {
transitionFromObj = activeObj; transitionFromObj = activeObj;
} }
if (direction == 'back' && !transitionFromObj.id) return PUSH.id = id; if (direction === 'back' && !transitionFromObj.id) return PUSH.id = id;
transition = direction == 'back' ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition; transition = direction === 'back' ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition;
if (!activeDom) { if (!activeDom) {
return PUSH({ return PUSH({
@ -158,7 +160,7 @@
if (transitionFromObj.transition) { if (transitionFromObj.transition) {
activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true));
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) barElement = document.querySelector(bars[key]);
if (activeObj[key]) swapContent(activeObj[key], barElement); if (activeObj[key]) swapContent(activeObj[key], barElement);
else if (barElement) barElement.parentNode.removeChild(barElement); else if (barElement) barElement.parentNode.removeChild(barElement);
} }
@ -181,7 +183,6 @@
var PUSH = function (options) { var PUSH = function (options) {
var key; var key;
var data = {};
var xhr = PUSH.xhr; var xhr = PUSH.xhr;
options.container = options.container || options.transition ? document.querySelector('.content') : document.body; options.container = options.container || options.transition ? document.querySelector('.content') : document.body;
@ -192,7 +193,7 @@
if (xhr && xhr.readyState < 4) { if (xhr && xhr.readyState < 4) {
xhr.onreadystatechange = noop; xhr.onreadystatechange = noop;
xhr.abort() xhr.abort();
} }
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
@ -201,12 +202,12 @@
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
if (options._timeout) clearTimeout(options._timeout); if (options._timeout) clearTimeout(options._timeout);
if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); if (xhr.readyState === 4) xhr.status === 200 ? success(xhr, options) : failure(options.url);
}; };
if (!PUSH.id) { if (!PUSH.id) {
cacheReplace({ cacheReplace({
id : +new Date, id : +new Date(),
url : window.location.href, url : window.location.href,
title : document.title, title : document.title,
timeout : options.timeout, timeout : options.timeout,
@ -238,7 +239,7 @@
if (options.transition) { if (options.transition) {
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) barElement = document.querySelector(bars[key]);
if (data[key]) swapContent(data[key], barElement); if (data[key]) swapContent(data[key], barElement);
else if (barElement) barElement.parentNode.removeChild(barElement); else if (barElement) barElement.parentNode.removeChild(barElement);
} }
@ -246,7 +247,7 @@
swapContent(data.contents, options.container, options.transition, function () { swapContent(data.contents, options.container, options.transition, function () {
cacheReplace({ cacheReplace({
id : options.id || +new Date, id : options.id || +new Date(),
url : data.url, url : data.url,
title : data.title, title : data.title,
timeout : options.timeout, timeout : options.timeout,
@ -255,12 +256,12 @@
triggerStateChange(); triggerStateChange();
}); });
if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']); // google analytics
if (!options.hash) return; if (!options.hash) return;
}; };
var failure = function (url) { var failure = function (url) {
throw new Error('Could not get: ' + url) throw new Error('Could not get: ' + url);
}; };
@ -279,7 +280,7 @@
} else { } else {
enter = /in$/.test(transition); enter = /in$/.test(transition);
if (transition == 'fade') { if (transition === 'fade') {
container.classList.add('in'); container.classList.add('in');
container.classList.add('fade'); container.classList.add('fade');
swap.classList.add('fade'); swap.classList.add('fade');
@ -296,40 +297,40 @@
if (!transition) complete && complete(); if (!transition) complete && complete();
if (transition == 'fade') { if (transition === 'fade') {
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
container.classList.remove('in'); container.classList.remove('in');
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); var fadeContainerEnd = function () {
function fadeContainerEnd() {
container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); container.removeEventListener('webkitTransitionEnd', fadeContainerEnd);
swap.classList.add('in'); swap.classList.add('in');
swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); swap.addEventListener('webkitTransitionEnd', fadeSwapEnd);
} };
function fadeSwapEnd () { var fadeSwapEnd = function () {
swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd);
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
swap.classList.remove('fade'); swap.classList.remove('fade');
swap.classList.remove('in'); swap.classList.remove('in');
complete && complete(); complete && complete();
} };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
} }
if (/slide/.test(transition)) { if (/slide/.test(transition)) {
container.offsetWidth; // force reflow var slideEnd = function () {
swapDirection = enter ? 'right' : 'left'
containerDirection = enter ? 'left' : 'right'
container.classList.add(containerDirection);
swap.classList.remove(swapDirection);
swap.addEventListener('webkitTransitionEnd', slideEnd);
function slideEnd() {
swap.removeEventListener('webkitTransitionEnd', slideEnd); swap.removeEventListener('webkitTransitionEnd', slideEnd);
swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove('sliding', 'sliding-in');
swap.classList.remove(swapDirection); swap.classList.remove(swapDirection);
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
complete && complete(); complete && complete();
} };
container.offsetWidth; // force reflow
swapDirection = enter ? 'right' : 'left';
containerDirection = enter ? 'left' : 'right';
container.classList.add(containerDirection);
swap.classList.remove(swapDirection);
swap.addEventListener('webkitTransitionEnd', slideEnd);
} }
}; };
@ -355,10 +356,6 @@
window.location.replace(url); window.location.replace(url);
}; };
var parseURL = function (url) {
var a = document.createElement('a'); a.href = url; return a;
};
var extendWithDom = function (obj, fragment, dom) { var extendWithDom = function (obj, fragment, dom) {
var i; var i;
var result = {}; var result = {};
@ -389,8 +386,8 @@
if (/<html/i.test(responseText)) { if (/<html/i.test(responseText)) {
head = document.createElement('div'); head = document.createElement('div');
body = document.createElement('div'); body = document.createElement('div');
head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0] head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0];
body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0] body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0];
} else { } else {
head = body = document.createElement('div'); head = body = document.createElement('div');
head.innerHTML = responseText; head.innerHTML = responseText;
@ -410,7 +407,7 @@
// ========================== // ==========================
window.addEventListener('touchstart', function () { isScrolling = false; }); window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }) window.addEventListener('touchmove', function () { isScrolling = true; });
window.addEventListener('touchend', touchend); window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); }); window.addEventListener('click', function (e) { if (getTarget(e)) e.preventDefault(); });
window.addEventListener('popstate', popstate); window.addEventListener('popstate', popstate);

2
js/segmented-controllers.js

@ -12,7 +12,7 @@
} }
}; };
window.addEventListener("touchend", function (e) { window.addEventListener('touchend', function (e) {
var activeTab; var activeTab;
var activeBodies; var activeBodies;
var targetBody; var targetBody;

17
js/sliders.js

@ -26,11 +26,12 @@
for (; target && target !== document; target = target.parentNode) { for (; target && target !== document; target = target.parentNode) {
for (i = sliders.length; i--;) { if (sliders[i] === target) return target; } for (i = sliders.length; i--;) { if (sliders[i] === target) return target; }
} }
} };
var getScroll = function () { var getScroll = function () {
var translate3d = slider.style.webkitTransform.match(/translate3d\(([^,]*)/); var translate3d = slider.style.webkitTransform.match(/translate3d\(([^,]*)/);
return parseInt(translate3d ? translate3d[1] : 0) var ret = translate3d ? translate3d[1] : 0;
return parseInt(ret, 10);
}; };
var setSlideNumber = function (offset) { var setSlideNumber = function (offset) {
@ -39,7 +40,7 @@
slideNumber += offset; slideNumber += offset;
slideNumber = Math.min(slideNumber, 0); slideNumber = Math.min(slideNumber, 0);
slideNumber = Math.max(-(slider.children.length - 1), slideNumber); slideNumber = Math.max(-(slider.children.length - 1), slideNumber);
} };
var onTouchStart = function (e) { var onTouchStart = function (e) {
slider = getSlider(e.target); slider = getSlider(e.target);
@ -53,7 +54,7 @@
sliderWidth = slider.offsetWidth; sliderWidth = slider.offsetWidth;
resistance = 1; resistance = 1;
lastSlide = -(slider.children.length - 1); lastSlide = -(slider.children.length - 1);
startTime = +new Date; startTime = +new Date();
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
deltaX = 0; deltaX = 0;
@ -72,7 +73,7 @@
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
if (typeof isScrolling == 'undefined') { if (typeof isScrolling === 'undefined') {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX); isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
} }
@ -82,8 +83,8 @@
e.preventDefault(); e.preventDefault();
resistance = slideNumber == 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 : resistance = slideNumber === 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 :
slideNumber == lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1; slideNumber === lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1;
slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)'; slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)';
}; };
@ -92,7 +93,7 @@
if (!slider || isScrolling) return; if (!slider || isScrolling) return;
setSlideNumber( setSlideNumber(
(+new Date) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 (+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
); );
offsetX = slideNumber * sliderWidth; offsetX = slideNumber * sliderWidth;

2
js/toggles.js

@ -16,7 +16,7 @@
for (; target && target !== document; target = target.parentNode) { for (; target && target !== document; target = target.parentNode) {
for (i = toggles.length; i--;) { if (toggles[i] === target) return target; } for (i = toggles.length; i--;) { if (toggles[i] === target) return target; }
} }
} };
window.addEventListener('touchstart', function (e) { window.addEventListener('touchstart', function (e) {
e = e.originalEvent || e; e = e.originalEvent || e;

Loading…
Cancel
Save