Browse Source

Fix JSHint warnings.

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

61
docs/assets/js/docs.js

@ -1,8 +1,10 @@
/* jshint jquery: true */
/* global FingerBlast: true */
$(function() {
var doc;
var device;
var platformToggle;
var windowWidth;
var windowHeight;
var pageHeight;
@ -10,13 +12,14 @@ $(function() {
var footerHeight;
var navComponentLinks;
var componentsList;
var componentLinks;
var contentSection;
var currentActive;
var topCache;
var win;
var bod;
var eventListeners;
var toolbarToggle;
var toggleTop;
var toggleHeight;
var initialize = function () {
@ -24,19 +27,19 @@ $(function() {
topCache = [];
win = $(window);
doc = $(document);
bod = $(document.body)
bod = $(document.body);
device = device || $('.js-device');
navComponentLinks = $('.js-jump-menu');
componentsList = $('.js-component-group');
componentLinks = $('.component-example a');
contentSection = $('.component');
topCache = contentSection.map(function () { return $(this).offset().top })
windowHeight = $(window).height() / 3
topCache = contentSection.map(function () { return $(this).offset().top; });
windowHeight = $(window).height() / 3;
windowWidth = $(window).width();
pageHeight = $(document).height();
contentPadding = parseInt($('.docs-content').css('padding-bottom'));
contentPadding = parseInt($('.docs-content').css('padding-bottom'), 10);
footerHeight = $('.docs-footer').outerHeight(false);
toolbarToggle = $('.js-docs-component-toolbar');
toolbarToggle = $('.js-docs-component-toolbar');
// Device placement
if (windowWidth >= 768) {
@ -50,7 +53,7 @@ $(function() {
calculateToggle();
if (!eventListeners) addEventListeners();
}
};
var addEventListeners = function () {
eventListeners = true;
@ -72,11 +75,11 @@ $(function() {
e.stopPropagation();
e.preventDefault();
componentsList.toggleClass('active');
})
});
doc.on('click', function () {
componentsList.removeClass('active');
})
});
// Platform switcher
$('.platform-switch').on('click', function () {
@ -101,58 +104,58 @@ $(function() {
win.on('scroll', calculateScroll);
win.on('scroll', calculateToggle);
}
};
var checkDesktopContent = function () {
windowWidth = $(window).width();
if (windowWidth <= 768) {
var content = $('.content')
var content = $('.content');
if (content.length > 1) {
$(content[0]).remove()
$(content[0]).remove();
}
}
}
};
var calculateScroll = function() {
// if small screen don't worry about this
if (windowWidth <= 768) return
if (windowWidth <= 768) return;
// Save scrollTop value
var contentSectionItem;
var currentTop = win.scrollTop();
if((device.initialTop - currentTop) <= device.dockingOffset) {
device[0].className = "device device-fixed";
device.css({top: device.dockingOffset})
device[0].className = 'device device-fixed';
device.css({top: device.dockingOffset});
} else {
device[0].className = "device"
device[0].setAttribute('style','')
device[0].className = 'device';
device[0].setAttribute('style','');
}
// Injection of components into device
for (var l = contentSection.length; l--;) {
if ((topCache[l] - currentTop) < windowHeight) {
if (currentActive == l) return;
if (currentActive === l) return;
currentActive = l;
bod.find('.component.active').removeClass('active');
contentSectionItem = $(contentSection[l])
contentSectionItem.addClass('active')
contentSectionItem = $(contentSection[l]);
contentSectionItem.addClass('active');
if(contentSectionItem.attr('id')) {
device.attr("id", contentSectionItem.attr('id') + "InDevice");
device.attr('id', contentSectionItem.attr('id') + 'InDevice');
} else {
device.attr("id", "")
device.attr('id', '');
}
if (!contentSectionItem.hasClass('informational')) {
updateContent(contentSectionItem.find('.highlight .html').text())
updateContent(contentSectionItem.find('.highlight .html').text());
}
break
break;
}
}
function updateContent(content) {
$('#iwindow').html(content);
}
}
};
// Toolbar toggle
var calculateToggle = function () {
@ -165,7 +168,7 @@ $(function() {
toolbarToggle.removeClass('visible');
componentsList.removeClass('active');
}
}
};
$(window).on('load resize', initialize);
$(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
/* global GLOBAL: true */
function FingerBlast(element) {
this.element = typeof element == 'string' ? document.querySelector(element) : element;
this.element = typeof element === 'string' ? document.querySelector(element) : element;
this.listen();
}
@ -23,13 +25,13 @@ FingerBlast.prototype = {
function contains (element, ancestor) {
var descendants, index, descendant;
if ("compareDocumentPosition" in ancestor) {
if ('compareDocumentPosition' in ancestor) {
return !!(ancestor.compareDocumentPosition(element) & 16);
} else if ("contains" in ancestor) {
return ancestor != element && ancestor.contains(element);
} else if ('contains' in ancestor) {
return ancestor !== element && ancestor.contains(element);
} else {
for (descendants = ancestor.getElementsByTagName("*"), index = 0; descendant = descendants[index++];) {
if (descendant == element) return true;
for (descendants = ancestor.getElementsByTagName('*'), index = 0; descendant = descendants[index++];) {
if (descendant === element) return true;
}
return false;
}
@ -37,12 +39,12 @@ FingerBlast.prototype = {
this.element.addEventListener('mouseover', function (e) {
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;
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;
// Convert "ontouch*" properties and attributes to listeners.
// Convert 'ontouch*' properties and attributes to listeners.
var onEventName = 'on' + eventName;
if (onEventName in this.target) {

8
js/popovers.js

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

79
js/push.js

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

17
js/sliders.js

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

2
js/toggles.js

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

Loading…
Cancel
Save