diff --git a/Gruntfile.js b/Gruntfile.js index 650be31..8f9677d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,7 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ +/* jshint node: true */ module.exports = function(grunt) { 'use strict'; @@ -148,6 +149,21 @@ module.exports = function(grunt) { docs: {} }, + jshint: { + options: { + jshintrc: 'js/.jshintrc' + }, + grunt: { + src: 'Gruntfile.js' + }, + src: { + src: 'js/*.js' + }, + docs: { + src: ['docs/assets/js/docs.js', 'docs/assets/js/fingerblast.js'] + } + }, + validation: { options: { charset: 'utf-8', @@ -186,9 +202,9 @@ module.exports = function(grunt) { grunt.registerTask('dist-js', ['concat', 'uglify']); grunt.registerTask('dist', ['dist-css', 'dist-js', 'copy']); grunt.registerTask('validate-html', ['jekyll', 'validation']); - grunt.registerTask('default', ['dist']); grunt.registerTask('build', ['dist']); - grunt.registerTask('test', ['dist', 'validate-html']); + grunt.registerTask('default', ['dist']); + grunt.registerTask('test', ['dist', 'jshint', 'validate-html']); // Version numbering task. // grunt change-version-number --oldver=A.B.C --newver=X.Y.Z diff --git a/dist/js/ratchet.js b/dist/js/ratchet.js index 4372a7b..d8176fd 100644 --- a/dist/js/ratchet.js +++ b/dist/js/ratchet.js @@ -13,27 +13,37 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var findModals = function (target) { var i, modals = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = modals.length; i--;) { if (modals[i] === target) return target; } + for (i = modals.length; i--;) { + if (modals[i] === target) { + return target; + } + } } }; var getModal = function (event) { var modalToggle = findModals(event.target); - if (modalToggle && modalToggle.hash) return document.querySelector(modalToggle.hash); + if (modalToggle && modalToggle.hash) { + return document.querySelector(modalToggle.hash); + } }; window.addEventListener('touchend', function (event) { var modal = getModal(event); if (modal) { - if (modal && modal.classList.contains('modal')) modal.classList.toggle('active'); + if (modal && modal.classList.contains('modal')) { + modal.classList.toggle('active'); + } event.preventDefault(); // prevents rewriting url (apps can still use hash values in url) } }); -}(); +}()); /* ---------------------------------- * POPOVER v2.0.0 @@ -41,23 +51,28 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var popover; var findPopovers = function (target) { var i, popovers = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = popovers.length; i--;) { if (popovers[i] === target) return target; } + for (i = popovers.length; i--;) { + if (popovers[i] === target) { + return target; + } + } } }; var onPopoverHidden = function () { popover.style.display = 'none'; popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); - } + }; - var backdrop = function () { + var backdrop = (function () { var element = document.createElement('div'); element.classList.add('backdrop'); @@ -69,31 +84,39 @@ }); return element; - }(); + }()); 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; + if (popover == null) { + return; + } - if (!popover || !popover.classList.contains('popover')) return; + if (!popover || !popover.classList.contains('popover')) { + return; + } return popover; - } + }; var showHidePopover = function (e) { var popover = getPopover(e); - if (!popover) return; + if (!popover) { + return; + } popover.style.display = 'block'; popover.offsetHeight; @@ -105,7 +128,7 @@ window.addEventListener('touchend', showHidePopover); window.addEventListener('click', showHidePopover); -}(); +}()); /* ---------------------------------- * PUSH v2.0.0 @@ -114,7 +137,10 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +/* global _gaq: true */ + +!(function () { + 'use strict'; var noop = function () {}; @@ -141,7 +167,9 @@ var cacheReplace = function (data, updates) { PUSH.id = data.id; - if (updates) data = getCached(data.id); + if (updates) { + data = getCached(data.id); + } cacheMapping[data.id] = JSON.stringify(data); window.history.replaceState(data.id, data.title, data.url); domCache[data.id] = document.body.cloneNode(true); @@ -155,8 +183,12 @@ cacheBackStack.push(id); - while (cacheForwardStack.length) delete cacheMapping[cacheForwardStack.shift()]; - while (cacheBackStack.length > maxCacheLength) delete cacheMapping[cacheBackStack.shift()]; + while (cacheForwardStack.length) { + delete cacheMapping[cacheForwardStack.shift()]; + } + while (cacheBackStack.length > maxCacheLength) { + delete cacheMapping[cacheBackStack.shift()]; + } window.history.pushState(null, '', cacheMapping[PUSH.id].url); @@ -165,13 +197,15 @@ }; 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; var popStack = forward ? cacheForwardStack : cacheBackStack; - if (PUSH.id) pushStack.push(PUSH.id); + if (PUSH.id) { + pushStack.push(PUSH.id); + } popStack.pop(); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); @@ -185,18 +219,16 @@ var getTarget = function (e) { var target = findTarget(e.target); - if ( - ! target - || e.which > 1 - || e.metaKey - || e.ctrlKey - || isScrolling - || location.protocol !== target.protocol - || 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' - ) return; + if (!target || + e.which > 1 || + e.metaKey || + e.ctrlKey || + isScrolling || + location.protocol !== target.protocol || + 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') { return; } return target; }; @@ -208,7 +240,9 @@ var touchend = function (e) { var target = getTarget(e); - if (!target) return; + if (!target) { + return; + } e.preventDefault(); @@ -231,7 +265,9 @@ var transitionFromObj; var id = e.state; - if (!id || !cacheMapping[id]) return; + if (!id || !cacheMapping[id]) { + return; + } direction = PUSH.id < id ? 'forward' : 'back'; @@ -240,18 +276,22 @@ activeObj = getCached(id); activeDom = domCache[id]; - if (activeObj.title) document.title = activeObj.title; + 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({ @@ -267,9 +307,14 @@ if (transitionFromObj.transition) { activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); for (key in bars) { - barElement = document.querySelector(bars[key]) - if (activeObj[key]) swapContent(activeObj[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (activeObj[key]) { + swapContent(activeObj[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } @@ -290,18 +335,19 @@ 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; for (key in bars) { - options[key] = options[key] || document.querySelector(bars[key]); + if (bars.hasOwnProperty(key)) { + options[key] = options[key] || document.querySelector(bars[key]); + } } if (xhr && xhr.readyState < 4) { xhr.onreadystatechange = noop; - xhr.abort() + xhr.abort(); } xhr = new XMLHttpRequest(); @@ -309,13 +355,17 @@ xhr.setRequestHeader('X-PUSH', 'true'); xhr.onreadystatechange = function () { - if (options._timeout) clearTimeout(options._timeout); - if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); + if (options._timeout) { + clearTimeout(options._timeout); + } + 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, @@ -329,7 +379,9 @@ xhr.send(); - if (xhr.readyState && !options.ignorePush) cachePush(); + if (xhr.readyState && !options.ignorePush) { + cachePush(); + } }; @@ -341,21 +393,30 @@ var barElement; var data = parseXHR(xhr, options); - if (!data.contents) return locationReplace(options.url); + if (!data.contents) { + return locationReplace(options.url); + } - if (data.title) document.title = data.title; + if (data.title) { + document.title = data.title; + } if (options.transition) { for (key in bars) { - barElement = document.querySelector(bars[key]) - if (data[key]) swapContent(data[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (data[key]) { + swapContent(data[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } 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, @@ -364,12 +425,16 @@ triggerStateChange(); }); - if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics - if (!options.hash) return; + 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); }; @@ -382,13 +447,17 @@ var swapDirection; if (!transition) { - if (container) container.innerHTML = swap.innerHTML; - else if (swap.classList.contains('content')) document.body.appendChild(swap); - else document.body.insertBefore(swap, document.querySelector('.content')); + if (container) { + container.innerHTML = swap.innerHTML; + } else if (swap.classList.contains('content')) { + document.body.appendChild(swap); + } else { + document.body.insertBefore(swap, document.querySelector('.content')); + } } else { enter = /in$/.test(transition); - if (transition == 'fade') { + if (transition === 'fade') { container.classList.add('in'); container.classList.add('fade'); swap.classList.add('fade'); @@ -403,42 +472,44 @@ container.parentNode.insertBefore(swap, container); } - if (!transition) complete && complete(); + 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); } }; @@ -455,7 +526,11 @@ var findTarget = function (target) { var i, toggles = document.querySelectorAll('a'); 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; + } + } } }; @@ -464,19 +539,21 @@ 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]; + for (i in obj) { + if (obj.hasOwnProperty(i)) { + result[i] = obj[i]; + } + } Object.keys(bars).forEach(function (key) { var el = dom.querySelector(bars[key]); - if (el) el.parentNode.removeChild(el); + if (el) { + el.parentNode.removeChild(el); + } result[key] = el; }); @@ -493,13 +570,15 @@ data.url = options.url; - if (!responseText) return data; + if (!responseText) { + return data; + } if (/]*>([\s\S.]*)<\/head>/i)[0] - body.innerHTML = responseText.match(/
]*>([\s\S.]*)<\/body>/i)[0] + head.innerHTML = responseText.match(/]*>([\s\S.]*)<\/head>/i)[0]; + body.innerHTML = responseText.match(/]*>([\s\S.]*)<\/body>/i)[0]; } else { head = body = document.createElement('div'); head.innerHTML = responseText; @@ -508,8 +587,11 @@ data.title = head.querySelector('title'); data.title = data.title && data.title.innerText.trim(); - if (options.transition) data = extendWithDom(data, '.content', body); - else data.contents = body; + if (options.transition) { + data = extendWithDom(data, '.content', body); + } else { + data.contents = body; + } return data; }; @@ -519,13 +601,13 @@ // ========================== 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('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('popstate', popstate); window.PUSH = PUSH; -}(); +}()); /* ---------------------------------- * Segmented controls v2.0.0 @@ -533,15 +615,21 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var getTarget = function (target) { var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item'); for (; target && target !== document; target = target.parentNode) { - for (i = segmentedControls.length; i--;) { if (segmentedControls[i] === target) return target; } + for (i = segmentedControls.length; i--;) { + if (segmentedControls[i] === target) { + return target; + } + } } }; - window.addEventListener("touchend", function (e) { + window.addEventListener('touchend', function (e) { var activeTab; var activeBodies; var targetBody; @@ -549,19 +637,27 @@ var className = 'active'; var classSelector = '.' + className; - if (!targetTab) return; + if (!targetTab) { + return; + } activeTab = targetTab.parentNode.querySelector(classSelector); - if (activeTab) activeTab.classList.remove(className); + if (activeTab) { + activeTab.classList.remove(className); + } targetTab.classList.add(className); - if (!targetTab.hash) return; + if (!targetTab.hash) { + return; + } targetBody = document.querySelector(targetTab.hash); - if (!targetBody) return; + if (!targetBody) { + return; + } activeBodies = targetBody.parentNode.querySelectorAll(classSelector); @@ -572,8 +668,8 @@ targetBody.classList.add(className); }); - window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); }); -}(); + window.addEventListener('click', function (e) { if (getTarget(e.target)) {e.preventDefault();} }); +}()); /* ---------------------------------- * SLIDER v2.0.0 * Licensed under The MIT License @@ -581,7 +677,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var pageX; var pageY; @@ -600,13 +697,18 @@ var getSlider = function (target) { var i, sliders = document.querySelectorAll('.slider > .slide-group'); 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 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) { @@ -615,12 +717,14 @@ slideNumber += offset; slideNumber = Math.min(slideNumber, 0); slideNumber = Math.max(-(slider.children.length - 1), slideNumber); - } + }; var onTouchStart = function (e) { slider = getSlider(e.target); - if (!slider) return; + if (!slider) { + return; + } var firstItem = slider.querySelector('.slide'); @@ -629,7 +733,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; @@ -641,34 +745,40 @@ }; var onTouchMove = function (e) { - if (e.touches.length > 1 || !slider) return; // Exit if a pinch || no slider + if (e.touches.length > 1 || !slider) { + return; // Exit if a pinch || no slider + } deltaX = e.touches[0].pageX - pageX; deltaY = e.touches[0].pageY - pageY; 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); } - if (isScrolling) return; + if (isScrolling) { + return; + } offsetX = (deltaX / resistance) + getScroll(); 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)'; }; var onTouchEnd = function (e) { - if (!slider || isScrolling) return; + 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; @@ -689,7 +799,7 @@ window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchend', onTouchEnd); -}(); +}()); /* ---------------------------------- * TOGGLE v2.0.0 @@ -697,7 +807,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var start = {}; var touchMove = false; @@ -707,16 +818,22 @@ var findToggle = function (target) { var i, toggles = document.querySelectorAll('.toggle'); 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) { e = e.originalEvent || e; toggle = findToggle(e.target); - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -730,9 +847,13 @@ window.addEventListener('touchmove', function (e) { e = e.originalEvent || e; - if (e.touches.length > 1) return; // Exit if a pinch + if (e.touches.length > 1) { + return; // Exit if a pinch + } - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var current = e.touches[0]; @@ -743,12 +864,18 @@ touchMove = true; distanceX = current.pageX - start.pageX; - if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) return; + if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) { + return; + } e.preventDefault(); - if (distanceX < 0) return handle.style.webkitTransform = 'translate3d(0,0,0)'; - if (distanceX > offset) return handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + if (distanceX < 0) { + return (handle.style.webkitTransform = 'translate3d(0,0,0)'); + } + if (distanceX > offset) { + return (handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'); + } handle.style.webkitTransform = 'translate3d(' + distanceX + 'px,0,0)'; @@ -756,7 +883,9 @@ }); window.addEventListener('touchend', function (e) { - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -764,8 +893,11 @@ var offset = (toggleWidth - handleWidth); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); - if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; - else handle.style.webkitTransform = 'translate3d(0,0,0)'; + if (slideOn) { + handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + } else { + handle.style.webkitTransform = 'translate3d(0,0,0)'; + } toggle.classList[slideOn ? 'add' : 'remove']('active'); @@ -781,4 +913,4 @@ toggle = false; }); -}(); +}()); diff --git a/dist/js/ratchet.min.js b/dist/js/ratchet.min.js index 6c3332d..b8bc8f3 100644 --- a/dist/js/ratchet.min.js +++ b/dist/js/ratchet.min.js @@ -7,4 +7,4 @@ * v2.0.0 designed by @connors. * ===================================================== */ -!function(){var a=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},b=function(b){var c=a(b.target);return c&&c.hash?document.querySelector(c.hash):void 0};window.addEventListener("touchend",function(a){var c=b(a);c&&(c&&c.classList.contains("modal")&&c.classList.toggle("active"),a.preventDefault())})}(),!function(){var a,b=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},c=function(){a.style.display="none",a.removeEventListener("webkitTransitionEnd",c)},d=function(){var b=document.createElement("div");return b.classList.add("backdrop"),b.addEventListener("touchend",function(){a.addEventListener("webkitTransitionEnd",c),a.classList.remove("visible"),a.parentNode.removeChild(d)}),b}(),e=function(c){var d=b(c.target);if(d&&d.hash&&!(d.hash.indexOf("/")>0)){try{a=document.querySelector(d.hash)}catch(e){a=null}if(null!=a&&a&&a.classList.contains("popover"))return a}},f=function(a){var b=e(a);b&&(b.style.display="block",b.offsetHeight,b.classList.add("visible"),b.parentNode.appendChild(d))};window.addEventListener("touchend",f),window.addEventListener("click",f)}(),!function(){var a,b=function(){},c=20,d=sessionStorage,e={},f={"slide-in":"slide-out","slide-out":"slide-in",fade:"fade"},g={bartab:".bar-tab",barnav:".bar-nav",barfooter:".bar-footer",barheadersecondary:".bar-header-secondary"},h=function(a,b){o.id=a.id,b&&(a=k(a.id)),d[a.id]=JSON.stringify(a),window.history.replaceState(a.id,a.title,a.url),e[a.id]=document.body.cloneNode(!0)},i=function(){var a=o.id,b=JSON.parse(d.cacheForwardStack||"[]"),e=JSON.parse(d.cacheBackStack||"[]");for(e.push(a);b.length;)delete d[b.shift()];for(;e.length>c;)delete d[e.shift()];window.history.pushState(null,"",d[o.id].url),d.cacheForwardStack=JSON.stringify(b),d.cacheBackStack=JSON.stringify(e)},j=function(a,b){var c="forward"==b,e=JSON.parse(d.cacheForwardStack||"[]"),f=JSON.parse(d.cacheBackStack||"[]"),g=c?f:e,h=c?e:f;o.id&&g.push(o.id),h.pop(),d.cacheForwardStack=JSON.stringify(e),d.cacheBackStack=JSON.stringify(f)},k=function(a){return JSON.parse(d[a]||null)||{}},l=function(b){var c=t(b.target);if(!(!c||b.which>1||b.metaKey||b.ctrlKey||a||location.protocol!==c.protocol||location.host!==c.host||!c.hash&&/#/.test(c.href)||c.hash&&c.href.replace(c.hash,"")===location.href.replace(location.hash,"")||"push"==c.getAttribute("data-ignore")))return c},m=function(a){var b=l(a);b&&(a.preventDefault(),o({url:b.href,hash:b.hash,timeout:b.getAttribute("data-timeout"),transition:b.getAttribute("data-transition")}))},n=function(a){var b,c,h,i,l,m,n,p,q=a.state;if(q&&d[q]){if(l=o.id]*>([\s\S.]*)<\/head>/i)[0],d.innerHTML=f.match(/]*>([\s\S.]*)<\/body>/i)[0]):(c=d=document.createElement("div"),c.innerHTML=f),e.title=c.querySelector("title"),e.title=e.title&&e.title.innerText.trim(),b.transition?e=v(e,".content",d):e.contents=d,e):e};window.addEventListener("touchstart",function(){a=!1}),window.addEventListener("touchmove",function(){a=!0}),window.addEventListener("touchend",m),window.addEventListener("click",function(a){l(a)&&a.preventDefault()}),window.addEventListener("popstate",n),window.PUSH=o}(),!function(){var a=function(a){for(var b,c=document.querySelectorAll(".segmented-control .control-item");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchend",function(b){var c,d,e,f=a(b.target),g="active",h="."+g;if(f&&(c=f.parentNode.querySelector(h),c&&c.classList.remove(g),f.classList.add(g),f.hash&&(e=document.querySelector(f.hash)))){d=e.parentNode.querySelectorAll(h);for(var i=0;i.slide-group");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},o=function(){var a=c.style.webkitTransform.match(/translate3d\(([^,]*)/);return parseInt(a?a[1]:0)},p=function(a){var b=a?0>d?"ceil":"floor":"round";k=Math[b](o()/(m/c.children.length)),k+=a,k=Math.min(k,0),k=Math.max(-(c.children.length-1),k)},q=function(f){if(c=n(f.target)){var k=c.querySelector(".slide");m=k.offsetWidth*c.children.length,l=void 0,j=c.offsetWidth,i=1,g=-(c.children.length-1),h=+new Date,a=f.touches[0].pageX,b=f.touches[0].pageY,d=0,e=0,p(0),c.style["-webkit-transition-duration"]=0}},r=function(h){h.touches.length>1||!c||(d=h.touches[0].pageX-a,e=h.touches[0].pageY-b,a=h.touches[0].pageX,b=h.touches[0].pageY,"undefined"==typeof l&&(l=Math.abs(e)>Math.abs(d)),l||(f=d/i+o(),h.preventDefault(),i=0==k&&d>0?a/j+1.25:k==g&&0>d?Math.abs(a)/j+1.25:1,c.style.webkitTransform="translate3d("+f+"px,0,0)"))},s=function(a){c&&!l&&(p(+new Date-h<1e3&&Math.abs(d)>15?0>d?-1:1:0),f=k*j,c.style["-webkit-transition-duration"]=".2s",c.style.webkitTransform="translate3d("+f+"px,0,0)",a=new CustomEvent("slide",{detail:{slideNumber:Math.abs(k)},bubbles:!0,cancelable:!0}),c.parentNode.dispatchEvent(a))};window.addEventListener("touchstart",q),window.addEventListener("touchmove",r),window.addEventListener("touchend",s)}(),!function(){var a={},b=!1,c=!1,d=!1,e=function(a){for(var b,c=document.querySelectorAll(".toggle");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchstart",function(c){if(c=c.originalEvent||c,d=e(c.target)){var f=d.querySelector(".toggle-handle"),g=d.clientWidth,h=f.clientWidth,i=d.classList.contains("active")?g-h:0;a={pageX:c.touches[0].pageX-i,pageY:c.touches[0].pageY},b=!1}}),window.addEventListener("touchmove",function(e){if(e=e.originalEvent||e,!(e.touches.length>1)&&d){var f=d.querySelector(".toggle-handle"),g=e.touches[0],h=d.clientWidth,i=f.clientWidth,j=h-i;if(b=!0,c=g.pageX-a.pageX,!(Math.abs(c) c)return f.style.webkitTransform="translate3d(0,0,0)";if(c>j)return f.style.webkitTransform="translate3d("+j+"px,0,0)";f.style.webkitTransform="translate3d("+c+"px,0,0)",d.classList[c>h/2-i/2?"add":"remove"]("active")}}}),window.addEventListener("touchend",function(a){if(d){var e=d.querySelector(".toggle-handle"),f=d.clientWidth,g=e.clientWidth,h=f-g,i=!b&&!d.classList.contains("active")||b&&c>f/2-g/2;e.style.webkitTransform=i?"translate3d("+h+"px,0,0)":"translate3d(0,0,0)",d.classList[i?"add":"remove"]("active"),a=new CustomEvent("toggle",{detail:{isActive:i},bubbles:!0,cancelable:!0}),d.dispatchEvent(a),b=!1,d=!1}})}(); \ No newline at end of file +!function(){"use strict";var a=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},b=function(b){var c=a(b.target);return c&&c.hash?document.querySelector(c.hash):void 0};window.addEventListener("touchend",function(a){var c=b(a);c&&(c&&c.classList.contains("modal")&&c.classList.toggle("active"),a.preventDefault())})}(),!function(){"use strict";var a,b=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},c=function(){a.style.display="none",a.removeEventListener("webkitTransitionEnd",c)},d=function(){var b=document.createElement("div");return b.classList.add("backdrop"),b.addEventListener("touchend",function(){a.addEventListener("webkitTransitionEnd",c),a.classList.remove("visible"),a.parentNode.removeChild(d)}),b}(),e=function(c){var d=b(c.target);if(d&&d.hash&&!(d.hash.indexOf("/")>0)){try{a=document.querySelector(d.hash)}catch(e){a=null}if(null!=a&&a&&a.classList.contains("popover"))return a}},f=function(a){var b=e(a);b&&(b.style.display="block",b.offsetHeight,b.classList.add("visible"),b.parentNode.appendChild(d))};window.addEventListener("touchend",f),window.addEventListener("click",f)}(),!function(){"use strict";var a,b=function(){},c=20,d=sessionStorage,e={},f={"slide-in":"slide-out","slide-out":"slide-in",fade:"fade"},g={bartab:".bar-tab",barnav:".bar-nav",barfooter:".bar-footer",barheadersecondary:".bar-header-secondary"},h=function(a,b){o.id=a.id,b&&(a=k(a.id)),d[a.id]=JSON.stringify(a),window.history.replaceState(a.id,a.title,a.url),e[a.id]=document.body.cloneNode(!0)},i=function(){var a=o.id,b=JSON.parse(d.cacheForwardStack||"[]"),e=JSON.parse(d.cacheBackStack||"[]");for(e.push(a);b.length;)delete d[b.shift()];for(;e.length>c;)delete d[e.shift()];window.history.pushState(null,"",d[o.id].url),d.cacheForwardStack=JSON.stringify(b),d.cacheBackStack=JSON.stringify(e)},j=function(a,b){var c="forward"===b,e=JSON.parse(d.cacheForwardStack||"[]"),f=JSON.parse(d.cacheBackStack||"[]"),g=c?f:e,h=c?e:f;o.id&&g.push(o.id),h.pop(),d.cacheForwardStack=JSON.stringify(e),d.cacheBackStack=JSON.stringify(f)},k=function(a){return JSON.parse(d[a]||null)||{}},l=function(b){var c=t(b.target);if(!(!c||b.which>1||b.metaKey||b.ctrlKey||a||location.protocol!==c.protocol||location.host!==c.host||!c.hash&&/#/.test(c.href)||c.hash&&c.href.replace(c.hash,"")===location.href.replace(location.hash,"")||"push"===c.getAttribute("data-ignore")))return c},m=function(a){var b=l(a);b&&(a.preventDefault(),o({url:b.href,hash:b.hash,timeout:b.getAttribute("data-timeout"),transition:b.getAttribute("data-transition")}))},n=function(a){var b,c,h,i,l,m,n,p,q=a.state;if(q&&d[q]){if(l=o.id ]*>([\s\S.]*)<\/head>/i)[0],d.innerHTML=f.match(/]*>([\s\S.]*)<\/body>/i)[0]):(c=d=document.createElement("div"),c.innerHTML=f),e.title=c.querySelector("title"),e.title=e.title&&e.title.innerText.trim(),b.transition?e=v(e,".content",d):e.contents=d,e):e};window.addEventListener("touchstart",function(){a=!1}),window.addEventListener("touchmove",function(){a=!0}),window.addEventListener("touchend",m),window.addEventListener("click",function(a){l(a)&&a.preventDefault()}),window.addEventListener("popstate",n),window.PUSH=o}(),!function(){"use strict";var a=function(a){for(var b,c=document.querySelectorAll(".segmented-control .control-item");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchend",function(b){var c,d,e,f=a(b.target),g="active",h="."+g;if(f&&(c=f.parentNode.querySelector(h),c&&c.classList.remove(g),f.classList.add(g),f.hash&&(e=document.querySelector(f.hash)))){d=e.parentNode.querySelectorAll(h);for(var i=0;i.slide-group");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},o=function(){var a=c.style.webkitTransform.match(/translate3d\(([^,]*)/),b=a?a[1]:0;return parseInt(b,10)},p=function(a){var b=a?0>d?"ceil":"floor":"round";k=Math[b](o()/(m/c.children.length)),k+=a,k=Math.min(k,0),k=Math.max(-(c.children.length-1),k)},q=function(f){if(c=n(f.target)){var k=c.querySelector(".slide");m=k.offsetWidth*c.children.length,l=void 0,j=c.offsetWidth,i=1,g=-(c.children.length-1),h=+new Date,a=f.touches[0].pageX,b=f.touches[0].pageY,d=0,e=0,p(0),c.style["-webkit-transition-duration"]=0}},r=function(h){h.touches.length>1||!c||(d=h.touches[0].pageX-a,e=h.touches[0].pageY-b,a=h.touches[0].pageX,b=h.touches[0].pageY,"undefined"==typeof l&&(l=Math.abs(e)>Math.abs(d)),l||(f=d/i+o(),h.preventDefault(),i=0===k&&d>0?a/j+1.25:k===g&&0>d?Math.abs(a)/j+1.25:1,c.style.webkitTransform="translate3d("+f+"px,0,0)"))},s=function(a){c&&!l&&(p(+new Date-h<1e3&&Math.abs(d)>15?0>d?-1:1:0),f=k*j,c.style["-webkit-transition-duration"]=".2s",c.style.webkitTransform="translate3d("+f+"px,0,0)",a=new CustomEvent("slide",{detail:{slideNumber:Math.abs(k)},bubbles:!0,cancelable:!0}),c.parentNode.dispatchEvent(a))};window.addEventListener("touchstart",q),window.addEventListener("touchmove",r),window.addEventListener("touchend",s)}(),!function(){"use strict";var a={},b=!1,c=!1,d=!1,e=function(a){for(var b,c=document.querySelectorAll(".toggle");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchstart",function(c){if(c=c.originalEvent||c,d=e(c.target)){var f=d.querySelector(".toggle-handle"),g=d.clientWidth,h=f.clientWidth,i=d.classList.contains("active")?g-h:0;a={pageX:c.touches[0].pageX-i,pageY:c.touches[0].pageY},b=!1}}),window.addEventListener("touchmove",function(e){if(e=e.originalEvent||e,!(e.touches.length>1)&&d){var f=d.querySelector(".toggle-handle"),g=e.touches[0],h=d.clientWidth,i=f.clientWidth,j=h-i;if(b=!0,c=g.pageX-a.pageX,!(Math.abs(c) c)return f.style.webkitTransform="translate3d(0,0,0)";if(c>j)return f.style.webkitTransform="translate3d("+j+"px,0,0)";f.style.webkitTransform="translate3d("+c+"px,0,0)",d.classList[c>h/2-i/2?"add":"remove"]("active")}}}),window.addEventListener("touchend",function(a){if(d){var e=d.querySelector(".toggle-handle"),f=d.clientWidth,g=e.clientWidth,h=f-g,i=!b&&!d.classList.contains("active")||b&&c>f/2-g/2;e.style.webkitTransform=i?"translate3d("+h+"px,0,0)":"translate3d(0,0,0)",d.classList[i?"add":"remove"]("active"),a=new CustomEvent("toggle",{detail:{isActive:i},bubbles:!0,cancelable:!0}),d.dispatchEvent(a),b=!1,d=!1}})}(); \ No newline at end of file diff --git a/docs/assets/js/docs.js b/docs/assets/js/docs.js index 677dc75..902385c 100644 --- a/docs/assets/js/docs.js +++ b/docs/assets/js/docs.js @@ -1,8 +1,11 @@ +/* jshint jquery: true */ +/* global FingerBlast: true */ + $(function() { + 'use strict'; var doc; var device; - var platformToggle; var windowWidth; var windowHeight; var pageHeight; @@ -10,13 +13,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 +28,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) { @@ -49,8 +53,10 @@ $(function() { calculateScroll(); calculateToggle(); - if (!eventListeners) addEventListeners(); - } + if (!eventListeners) { + addEventListeners(); + } + }; var addEventListeners = function () { eventListeners = true; @@ -72,11 +78,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 +107,63 @@ $(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',''); + } + + function updateContent(content) { + $('#iwindow').html(content); } // 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') - if(contentSectionItem.attr('id')) { - device.attr("id", contentSectionItem.attr('id') + "InDevice"); + contentSectionItem = $(contentSection[l]); + contentSectionItem.addClass('active'); + if (contentSectionItem.attr('id')) { + 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 +176,7 @@ $(function() { toolbarToggle.removeClass('visible'); componentsList.removeClass('active'); } - } + }; $(window).on('load resize', initialize); $(window).on('load', function () { new FingerBlast('.device-content'); }); diff --git a/docs/assets/js/docs.min.js b/docs/assets/js/docs.min.js index 78e0aa1..fd256e0 100644 --- a/docs/assets/js/docs.min.js +++ b/docs/assets/js/docs.min.js @@ -7,4 +7,4 @@ * v2.0.0 designed by @connors. * ===================================================== */ -function FingerBlast(a){this.element="string"==typeof a?document.querySelector(a):a,this.listen()}$(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o=function(){k=0,l=[],win=$(window),a=$(document),bod=$(document.body),b=b||$(".js-device"),h=$(".js-jump-menu"),i=$(".js-component-group"),componentLinks=$(".component-example a"),j=$(".component"),l=j.map(function(){return $(this).offset().top}),d=$(window).height()/3,c=$(window).width(),e=$(document).height(),f=parseInt($(".docs-content").css("padding-bottom")),g=$(".docs-footer").outerHeight(!1),n=$(".js-docs-component-toolbar"),c>=768&&(b.initialLeft=b.offset().left,b.initialTop=b.initialTop||b.offset().top,b.dockingOffset=($(window).height()-b.height())/2),q(),r(),s(),m||p()},p=function(){m=!0,b.on("click",function(a){a.preventDefault()}),$(".js-docs-nav-trigger").on("click",function(){var a=$(".docs-nav-group"),b=$(".js-docs-nav-trigger");b.toggleClass("active"),a.toggleClass("active")}),h.click(function(a){a.stopPropagation(),a.preventDefault(),i.toggleClass("active")}),a.on("click",function(){i.removeClass("active")}),$(".platform-switch").on("click",function(){var a=$(".docs-components"),b=$(this).attr("data-platform");a.hasClass("platform-ios")?(a.removeClass("platform-ios"),a.addClass(b)):a.hasClass("platform-android")?(a.removeClass("platform-android"),a.addClass(b)):a.addClass(b),$(this).siblings(".active").removeClass("active"),$(this).addClass("active")}),win.on("scroll",r),win.on("scroll",s)},q=function(){if(c=$(window).width(),768>=c){var a=$(".content");a.length>1&&$(a[0]).remove()}},r=function(){function a(a){$("#iwindow").html(a)}if(!(768>=c)){var e,f=win.scrollTop();b.initialTop-f<=b.dockingOffset?(b[0].className="device device-fixed",b.css({top:b.dockingOffset})):(b[0].className="device",b[0].setAttribute("style",""));for(var g=j.length;g--;)if(l[g]-f =b?n.addClass("visible"):b>=a&&(n.removeClass("visible"),i.removeClass("active"))};$(window).on("load resize",o),$(window).on("load",function(){new FingerBlast(".device-content")})}),FingerBlast.prototype={x:0/0,y:0/0,startDistance:0/0,startAngle:0/0,mouseIsDown:!1,listen:function(){function a(a,b){var c,d,e;if("compareDocumentPosition"in b)return!!(16&b.compareDocumentPosition(a));if("contains"in b)return b!=a&&b.contains(a);for(c=b.getElementsByTagName("*"),d=0;e=c[d++];)if(e==a)return!0;return!1}var b=this.activate.bind(this),c=this.deactivate.bind(this);this.element.addEventListener("mouseover",function(c){var d=c.relatedTarget;d==this||a(d,this)||b()}),this.element.addEventListener("mouseout",function(b){var d=b.relatedTarget;d==this||a(d,this)||c(b)})},activate:function(){this.active||(this.element.addEventListener("mousedown",this.touchStart=this.touchStart.bind(this),!0),this.element.addEventListener("mousemove",this.touchMove=this.touchMove.bind(this),!0),this.element.addEventListener("mouseup",this.touchEnd=this.touchEnd.bind(this),!0),this.element.addEventListener("click",this.click=this.click.bind(this),!0),this.active=!0)},deactivate:function(a){this.active=!1,this.mouseIsDown&&this.touchEnd(a),this.element.removeEventListener("mousedown",this.touchStart,!0),this.element.removeEventListener("mousemove",this.touchMove,!0),this.element.removeEventListener("mouseup",this.touchEnd,!0),this.element.removeEventListener("click",this.click,!0)},click:function(a){a.synthetic||(a.preventDefault(),a.stopPropagation())},touchStart:function(a){a.synthetic||/input|textarea/.test(a.target.tagName.toLowerCase())||(this.mouseIsDown=!0,a.preventDefault(),a.stopPropagation(),this.fireTouchEvents("touchstart",a))},touchMove:function(a){a.synthetic||(a.preventDefault(),a.stopPropagation(),this.move(a.clientX,a.clientY),this.mouseIsDown&&this.fireTouchEvents("touchmove",a))},touchEnd:function(a){a.synthetic||(this.mouseIsDown=!1,a.preventDefault(),a.stopPropagation(),this.fireTouchEvents("touchend",a),this.target&&(this.target.dispatchEvent(this.createMouseEvent("mouseover",a)),this.target.dispatchEvent(this.createMouseEvent("mousemove",a)),this.target.dispatchEvent(this.createMouseEvent("mousedown",a))))},fireTouchEvents:function(a,b){var c=[],d=[];if(this.target){var e="on"+a;if(e in this.target&&(console.warn("Converting `"+e+"` property to event listener.",this.target),this.target.addEventListener(a,this.target[e],!1),delete this.target[e]),this.target.hasAttribute(e)){console.warn("Converting `"+e+"` attribute to event listener.",this.target);var f=new GLOBAL.Function("event",this.target.getAttribute(e));this.target.addEventListener(a,f,!1),this.target.removeAttribute(e)}var g=this.createMouseEvent(a,b);if(c.push(g),c.length>1){var h=c[0].pageX-c[1].pageX,i=c[0].pageY-c[1].pageY,j=Math.sqrt(Math.pow(h,2)+Math.pow(i,2)),k=Math.atan2(h,i)*(180/Math.PI),l="gesturechange";"touchstart"===a&&(l="gesturestart",this.startDistance=j,this.startAngle=k),"touchend"===a&&(l="gestureend"),c.forEach(function(a){var b=this.createMouseEvent.call(a._finger,l,a);d.push(b)}.bind(this)),c.concat(d).forEach(function(a){a.scale=j/this.startDistance,a.rotation=this.startAngle-k})}c.forEach(function(a){a.touches=c.filter(function(a){return~a.type.indexOf("touch")&&"touchend"!==a.type}),a.changedTouches=c.filter(function(b){return~b.type.indexOf("touch")&&b._finger.target===a._finger.target}),a.targetTouches=a.changedTouches.filter(function(a){return~a.type.indexOf("touch")&&"touchend"!==a.type})}),c.concat(d).forEach(function(a,b){a.identifier=b,a._finger.target.dispatchEvent(a)})}},createMouseEvent:function(a,b){var c=document.createEvent("MouseEvent");return c.initMouseEvent(a,!0,!0,b.view,b.detail,this.x||b.screenX,this.y||b.screenY,this.x||b.clientX,this.y||b.clientY,b.ctrlKey,b.shiftKey,b.altKey,b.metaKey,b.button,this.target||b.relatedTarget),c.synthetic=!0,c._finger=this,c},move:function(a,b){isNaN(a)||isNaN(b)?this.target=null:(this.x=a,this.y=b,this.mouseIsDown||(this.target=document.elementFromPoint(a,b)))}}; \ No newline at end of file +function FingerBlast(a){"use strict";this.element="string"==typeof a?document.querySelector(a):a,this.listen()}$(function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=function(){l=0,m=[],n=$(window),a=$(document),o=$(document.body),b=b||$(".js-device"),h=$(".js-jump-menu"),i=$(".js-component-group"),j=$(".component-example a"),k=$(".component"),m=k.map(function(){return $(this).offset().top}),d=$(window).height()/3,c=$(window).width(),e=$(document).height(),f=parseInt($(".docs-content").css("padding-bottom"),10),g=$(".docs-footer").outerHeight(!1),q=$(".js-docs-component-toolbar"),c>=768&&(b.initialLeft=b.offset().left,b.initialTop=b.initialTop||b.offset().top,b.dockingOffset=($(window).height()-b.height())/2),t(),u(),v(),p||s()},s=function(){p=!0,b.on("click",function(a){a.preventDefault()}),$(".js-docs-nav-trigger").on("click",function(){var a=$(".docs-nav-group"),b=$(".js-docs-nav-trigger");b.toggleClass("active"),a.toggleClass("active")}),h.click(function(a){a.stopPropagation(),a.preventDefault(),i.toggleClass("active")}),a.on("click",function(){i.removeClass("active")}),$(".platform-switch").on("click",function(){var a=$(".docs-components"),b=$(this).attr("data-platform");a.hasClass("platform-ios")?(a.removeClass("platform-ios"),a.addClass(b)):a.hasClass("platform-android")?(a.removeClass("platform-android"),a.addClass(b)):a.addClass(b),$(this).siblings(".active").removeClass("active"),$(this).addClass("active")}),n.on("scroll",u),n.on("scroll",v)},t=function(){if(c=$(window).width(),768>=c){var a=$(".content");a.length>1&&$(a[0]).remove()}},u=function(){function a(a){$("#iwindow").html(a)}if(!(768>=c)){var e,f=n.scrollTop();b.initialTop-f<=b.dockingOffset?(b[0].className="device device-fixed",b.css({top:b.dockingOffset})):(b[0].className="device",b[0].setAttribute("style",""));for(var g=k.length;g--;)if(m[g]-f =b?q.addClass("visible"):b>=a&&(q.removeClass("visible"),i.removeClass("active"))};$(window).on("load resize",r),$(window).on("load",function(){new FingerBlast(".device-content")})}),FingerBlast.prototype={x:0/0,y:0/0,startDistance:0/0,startAngle:0/0,mouseIsDown:!1,listen:function(){"use strict";function a(a,b){var c,d,e;if("compareDocumentPosition"in b)return!!(16&b.compareDocumentPosition(a));if("contains"in b)return b!==a&&b.contains(a);for(c=b.getElementsByTagName("*"),d=0;e=c[d++];)if(e===a)return!0;return!1}var b=this.activate.bind(this),c=this.deactivate.bind(this);this.element.addEventListener("mouseover",function(c){var d=c.relatedTarget;d===this||a(d,this)||b()}),this.element.addEventListener("mouseout",function(b){var d=b.relatedTarget;d===this||a(d,this)||c(b)})},activate:function(){"use strict";this.active||(this.element.addEventListener("mousedown",this.touchStart=this.touchStart.bind(this),!0),this.element.addEventListener("mousemove",this.touchMove=this.touchMove.bind(this),!0),this.element.addEventListener("mouseup",this.touchEnd=this.touchEnd.bind(this),!0),this.element.addEventListener("click",this.click=this.click.bind(this),!0),this.active=!0)},deactivate:function(a){"use strict";this.active=!1,this.mouseIsDown&&this.touchEnd(a),this.element.removeEventListener("mousedown",this.touchStart,!0),this.element.removeEventListener("mousemove",this.touchMove,!0),this.element.removeEventListener("mouseup",this.touchEnd,!0),this.element.removeEventListener("click",this.click,!0)},click:function(a){"use strict";a.synthetic||(a.preventDefault(),a.stopPropagation())},touchStart:function(a){"use strict";a.synthetic||/input|textarea/.test(a.target.tagName.toLowerCase())||(this.mouseIsDown=!0,a.preventDefault(),a.stopPropagation(),this.fireTouchEvents("touchstart",a))},touchMove:function(a){"use strict";a.synthetic||(a.preventDefault(),a.stopPropagation(),this.move(a.clientX,a.clientY),this.mouseIsDown&&this.fireTouchEvents("touchmove",a))},touchEnd:function(a){"use strict";a.synthetic||(this.mouseIsDown=!1,a.preventDefault(),a.stopPropagation(),this.fireTouchEvents("touchend",a),this.target&&(this.target.dispatchEvent(this.createMouseEvent("mouseover",a)),this.target.dispatchEvent(this.createMouseEvent("mousemove",a)),this.target.dispatchEvent(this.createMouseEvent("mousedown",a))))},fireTouchEvents:function(a,b){"use strict";var c=[],d=[];if(this.target){var e="on"+a;if(e in this.target&&(console.warn("Converting `"+e+"` property to event listener.",this.target),this.target.addEventListener(a,this.target[e],!1),delete this.target[e]),this.target.hasAttribute(e)){console.warn("Converting `"+e+"` attribute to event listener.",this.target);var f=new GLOBAL.Function("event",this.target.getAttribute(e));this.target.addEventListener(a,f,!1),this.target.removeAttribute(e)}var g=this.createMouseEvent(a,b);if(c.push(g),c.length>1){var h=c[0].pageX-c[1].pageX,i=c[0].pageY-c[1].pageY,j=Math.sqrt(Math.pow(h,2)+Math.pow(i,2)),k=Math.atan2(h,i)*(180/Math.PI),l="gesturechange";"touchstart"===a&&(l="gesturestart",this.startDistance=j,this.startAngle=k),"touchend"===a&&(l="gestureend"),c.forEach(function(a){var b=this.createMouseEvent.call(a._finger,l,a);d.push(b)}.bind(this)),c.concat(d).forEach(function(a){a.scale=j/this.startDistance,a.rotation=this.startAngle-k})}c.forEach(function(a){a.touches=c.filter(function(a){return~a.type.indexOf("touch")&&"touchend"!==a.type}),a.changedTouches=c.filter(function(b){return~b.type.indexOf("touch")&&b._finger.target===a._finger.target}),a.targetTouches=a.changedTouches.filter(function(a){return~a.type.indexOf("touch")&&"touchend"!==a.type})}),c.concat(d).forEach(function(a,b){a.identifier=b,a._finger.target.dispatchEvent(a)})}},createMouseEvent:function(a,b){"use strict";var c=document.createEvent("MouseEvent");return c.initMouseEvent(a,!0,!0,b.view,b.detail,this.x||b.screenX,this.y||b.screenY,this.x||b.clientX,this.y||b.clientY,b.ctrlKey,b.shiftKey,b.altKey,b.metaKey,b.button,this.target||b.relatedTarget),c.synthetic=!0,c._finger=this,c},move:function(a,b){"use strict";isNaN(a)||isNaN(b)?this.target=null:(this.x=a,this.y=b,this.mouseIsDown||(this.target=document.elementFromPoint(a,b)))}}; \ No newline at end of file diff --git a/docs/assets/js/fingerblast.js b/docs/assets/js/fingerblast.js index 58543c2..eb882bb 100644 --- a/docs/assets/js/fingerblast.js +++ b/docs/assets/js/fingerblast.js @@ -1,9 +1,14 @@ // FINGERBLAST.js // -------------- -// Adapted from phantom limb by brian cartensen +// Adapted from phantom limb by Brian Cartensen + +/* jshint bitwise: false */ +/* global GLOBAL: true */ function FingerBlast(element) { - this.element = typeof element == 'string' ? document.querySelector(element) : element; + 'use strict'; + + this.element = typeof element === 'string' ? document.querySelector(element) : element; this.listen(); } @@ -17,19 +22,22 @@ FingerBlast.prototype = { mouseIsDown: false, listen: function () { + 'use strict'; var activate = this.activate.bind(this); var deactivate = this.deactivate.bind(this); 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,17 +45,25 @@ 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); + } }); }, activate: function () { - if (this.active) return; + 'use strict'; + + if (this.active) { + return; + } this.element.addEventListener('mousedown', (this.touchStart = this.touchStart.bind(this)), true); this.element.addEventListener('mousemove', (this.touchMove = this.touchMove.bind(this)), true); this.element.addEventListener('mouseup', (this.touchEnd = this.touchEnd.bind(this)), true); @@ -56,8 +72,12 @@ FingerBlast.prototype = { }, deactivate: function (e) { + 'use strict'; + this.active = false; - if (this.mouseIsDown) this.touchEnd(e); + if (this.mouseIsDown) { + this.touchEnd(e); + } this.element.removeEventListener('mousedown', this.touchStart, true); this.element.removeEventListener('mousemove', this.touchMove, true); this.element.removeEventListener('mouseup', this.touchEnd, true); @@ -65,13 +85,21 @@ FingerBlast.prototype = { }, click: function (e) { - if (e.synthetic) return; + 'use strict'; + + if (e.synthetic) { + return; + } e.preventDefault(); e.stopPropagation(); }, touchStart: function (e) { - if (e.synthetic || /input|textarea/.test(e.target.tagName.toLowerCase())) return; + 'use strict'; + + if (e.synthetic || /input|textarea/.test(e.target.tagName.toLowerCase())) { + return; + } this.mouseIsDown = true; @@ -82,18 +110,28 @@ FingerBlast.prototype = { }, touchMove: function (e) { - if (e.synthetic) return; + 'use strict'; + + if (e.synthetic) { + return; + } e.preventDefault(); e.stopPropagation(); this.move(e.clientX, e.clientY); - if (this.mouseIsDown) this.fireTouchEvents('touchmove', e); + if (this.mouseIsDown) { + this.fireTouchEvents('touchmove', e); + } }, touchEnd: function (e) { - if (e.synthetic) return; + 'use strict'; + + if (e.synthetic) { + return; + } this.mouseIsDown = false; @@ -102,7 +140,9 @@ FingerBlast.prototype = { this.fireTouchEvents('touchend', e); - if (!this.target) return; + if (!this.target) { + return; + } // Mobile Safari moves all the mouse events to fire after the touchend event. this.target.dispatchEvent(this.createMouseEvent('mouseover', e)); @@ -111,12 +151,16 @@ FingerBlast.prototype = { }, fireTouchEvents: function (eventName, originalEvent) { + 'use strict'; + var events = []; var gestures = []; - 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; if (onEventName in this.target) { @@ -153,7 +197,9 @@ FingerBlast.prototype = { this.startAngle = angle; } - if (eventName === 'touchend') gestureName = 'gestureend'; + if (eventName === 'touchend') { + gestureName = 'gestureend'; + } events.forEach(function(event) { var gesture = this.createMouseEvent.call(event._finger, gestureName, event); @@ -189,6 +235,8 @@ FingerBlast.prototype = { }, createMouseEvent: function (eventName, originalEvent) { + 'use strict'; + var e = document.createEvent('MouseEvent'); e.initMouseEvent(eventName, true, true, @@ -207,6 +255,8 @@ FingerBlast.prototype = { }, move: function (x, y) { + 'use strict'; + if (isNaN(x) || isNaN(y)) { this.target = null; } else { diff --git a/docs/dist/js/ratchet.js b/docs/dist/js/ratchet.js index 4372a7b..d8176fd 100644 --- a/docs/dist/js/ratchet.js +++ b/docs/dist/js/ratchet.js @@ -13,27 +13,37 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var findModals = function (target) { var i, modals = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = modals.length; i--;) { if (modals[i] === target) return target; } + for (i = modals.length; i--;) { + if (modals[i] === target) { + return target; + } + } } }; var getModal = function (event) { var modalToggle = findModals(event.target); - if (modalToggle && modalToggle.hash) return document.querySelector(modalToggle.hash); + if (modalToggle && modalToggle.hash) { + return document.querySelector(modalToggle.hash); + } }; window.addEventListener('touchend', function (event) { var modal = getModal(event); if (modal) { - if (modal && modal.classList.contains('modal')) modal.classList.toggle('active'); + if (modal && modal.classList.contains('modal')) { + modal.classList.toggle('active'); + } event.preventDefault(); // prevents rewriting url (apps can still use hash values in url) } }); -}(); +}()); /* ---------------------------------- * POPOVER v2.0.0 @@ -41,23 +51,28 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var popover; var findPopovers = function (target) { var i, popovers = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = popovers.length; i--;) { if (popovers[i] === target) return target; } + for (i = popovers.length; i--;) { + if (popovers[i] === target) { + return target; + } + } } }; var onPopoverHidden = function () { popover.style.display = 'none'; popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); - } + }; - var backdrop = function () { + var backdrop = (function () { var element = document.createElement('div'); element.classList.add('backdrop'); @@ -69,31 +84,39 @@ }); return element; - }(); + }()); 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; + if (popover == null) { + return; + } - if (!popover || !popover.classList.contains('popover')) return; + if (!popover || !popover.classList.contains('popover')) { + return; + } return popover; - } + }; var showHidePopover = function (e) { var popover = getPopover(e); - if (!popover) return; + if (!popover) { + return; + } popover.style.display = 'block'; popover.offsetHeight; @@ -105,7 +128,7 @@ window.addEventListener('touchend', showHidePopover); window.addEventListener('click', showHidePopover); -}(); +}()); /* ---------------------------------- * PUSH v2.0.0 @@ -114,7 +137,10 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +/* global _gaq: true */ + +!(function () { + 'use strict'; var noop = function () {}; @@ -141,7 +167,9 @@ var cacheReplace = function (data, updates) { PUSH.id = data.id; - if (updates) data = getCached(data.id); + if (updates) { + data = getCached(data.id); + } cacheMapping[data.id] = JSON.stringify(data); window.history.replaceState(data.id, data.title, data.url); domCache[data.id] = document.body.cloneNode(true); @@ -155,8 +183,12 @@ cacheBackStack.push(id); - while (cacheForwardStack.length) delete cacheMapping[cacheForwardStack.shift()]; - while (cacheBackStack.length > maxCacheLength) delete cacheMapping[cacheBackStack.shift()]; + while (cacheForwardStack.length) { + delete cacheMapping[cacheForwardStack.shift()]; + } + while (cacheBackStack.length > maxCacheLength) { + delete cacheMapping[cacheBackStack.shift()]; + } window.history.pushState(null, '', cacheMapping[PUSH.id].url); @@ -165,13 +197,15 @@ }; 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; var popStack = forward ? cacheForwardStack : cacheBackStack; - if (PUSH.id) pushStack.push(PUSH.id); + if (PUSH.id) { + pushStack.push(PUSH.id); + } popStack.pop(); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); @@ -185,18 +219,16 @@ var getTarget = function (e) { var target = findTarget(e.target); - if ( - ! target - || e.which > 1 - || e.metaKey - || e.ctrlKey - || isScrolling - || location.protocol !== target.protocol - || 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' - ) return; + if (!target || + e.which > 1 || + e.metaKey || + e.ctrlKey || + isScrolling || + location.protocol !== target.protocol || + 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') { return; } return target; }; @@ -208,7 +240,9 @@ var touchend = function (e) { var target = getTarget(e); - if (!target) return; + if (!target) { + return; + } e.preventDefault(); @@ -231,7 +265,9 @@ var transitionFromObj; var id = e.state; - if (!id || !cacheMapping[id]) return; + if (!id || !cacheMapping[id]) { + return; + } direction = PUSH.id < id ? 'forward' : 'back'; @@ -240,18 +276,22 @@ activeObj = getCached(id); activeDom = domCache[id]; - if (activeObj.title) document.title = activeObj.title; + 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({ @@ -267,9 +307,14 @@ if (transitionFromObj.transition) { activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); for (key in bars) { - barElement = document.querySelector(bars[key]) - if (activeObj[key]) swapContent(activeObj[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (activeObj[key]) { + swapContent(activeObj[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } @@ -290,18 +335,19 @@ 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; for (key in bars) { - options[key] = options[key] || document.querySelector(bars[key]); + if (bars.hasOwnProperty(key)) { + options[key] = options[key] || document.querySelector(bars[key]); + } } if (xhr && xhr.readyState < 4) { xhr.onreadystatechange = noop; - xhr.abort() + xhr.abort(); } xhr = new XMLHttpRequest(); @@ -309,13 +355,17 @@ xhr.setRequestHeader('X-PUSH', 'true'); xhr.onreadystatechange = function () { - if (options._timeout) clearTimeout(options._timeout); - if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); + if (options._timeout) { + clearTimeout(options._timeout); + } + 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, @@ -329,7 +379,9 @@ xhr.send(); - if (xhr.readyState && !options.ignorePush) cachePush(); + if (xhr.readyState && !options.ignorePush) { + cachePush(); + } }; @@ -341,21 +393,30 @@ var barElement; var data = parseXHR(xhr, options); - if (!data.contents) return locationReplace(options.url); + if (!data.contents) { + return locationReplace(options.url); + } - if (data.title) document.title = data.title; + if (data.title) { + document.title = data.title; + } if (options.transition) { for (key in bars) { - barElement = document.querySelector(bars[key]) - if (data[key]) swapContent(data[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (data[key]) { + swapContent(data[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } 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, @@ -364,12 +425,16 @@ triggerStateChange(); }); - if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics - if (!options.hash) return; + 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); }; @@ -382,13 +447,17 @@ var swapDirection; if (!transition) { - if (container) container.innerHTML = swap.innerHTML; - else if (swap.classList.contains('content')) document.body.appendChild(swap); - else document.body.insertBefore(swap, document.querySelector('.content')); + if (container) { + container.innerHTML = swap.innerHTML; + } else if (swap.classList.contains('content')) { + document.body.appendChild(swap); + } else { + document.body.insertBefore(swap, document.querySelector('.content')); + } } else { enter = /in$/.test(transition); - if (transition == 'fade') { + if (transition === 'fade') { container.classList.add('in'); container.classList.add('fade'); swap.classList.add('fade'); @@ -403,42 +472,44 @@ container.parentNode.insertBefore(swap, container); } - if (!transition) complete && complete(); + 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); } }; @@ -455,7 +526,11 @@ var findTarget = function (target) { var i, toggles = document.querySelectorAll('a'); 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; + } + } } }; @@ -464,19 +539,21 @@ 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]; + for (i in obj) { + if (obj.hasOwnProperty(i)) { + result[i] = obj[i]; + } + } Object.keys(bars).forEach(function (key) { var el = dom.querySelector(bars[key]); - if (el) el.parentNode.removeChild(el); + if (el) { + el.parentNode.removeChild(el); + } result[key] = el; }); @@ -493,13 +570,15 @@ data.url = options.url; - if (!responseText) return data; + if (!responseText) { + return data; + } if (/]*>([\s\S.]*)<\/head>/i)[0] - body.innerHTML = responseText.match(/]*>([\s\S.]*)<\/body>/i)[0] + head.innerHTML = responseText.match(/]*>([\s\S.]*)<\/head>/i)[0]; + body.innerHTML = responseText.match(/]*>([\s\S.]*)<\/body>/i)[0]; } else { head = body = document.createElement('div'); head.innerHTML = responseText; @@ -508,8 +587,11 @@ data.title = head.querySelector('title'); data.title = data.title && data.title.innerText.trim(); - if (options.transition) data = extendWithDom(data, '.content', body); - else data.contents = body; + if (options.transition) { + data = extendWithDom(data, '.content', body); + } else { + data.contents = body; + } return data; }; @@ -519,13 +601,13 @@ // ========================== 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('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('popstate', popstate); window.PUSH = PUSH; -}(); +}()); /* ---------------------------------- * Segmented controls v2.0.0 @@ -533,15 +615,21 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var getTarget = function (target) { var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item'); for (; target && target !== document; target = target.parentNode) { - for (i = segmentedControls.length; i--;) { if (segmentedControls[i] === target) return target; } + for (i = segmentedControls.length; i--;) { + if (segmentedControls[i] === target) { + return target; + } + } } }; - window.addEventListener("touchend", function (e) { + window.addEventListener('touchend', function (e) { var activeTab; var activeBodies; var targetBody; @@ -549,19 +637,27 @@ var className = 'active'; var classSelector = '.' + className; - if (!targetTab) return; + if (!targetTab) { + return; + } activeTab = targetTab.parentNode.querySelector(classSelector); - if (activeTab) activeTab.classList.remove(className); + if (activeTab) { + activeTab.classList.remove(className); + } targetTab.classList.add(className); - if (!targetTab.hash) return; + if (!targetTab.hash) { + return; + } targetBody = document.querySelector(targetTab.hash); - if (!targetBody) return; + if (!targetBody) { + return; + } activeBodies = targetBody.parentNode.querySelectorAll(classSelector); @@ -572,8 +668,8 @@ targetBody.classList.add(className); }); - window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); }); -}(); + window.addEventListener('click', function (e) { if (getTarget(e.target)) {e.preventDefault();} }); +}()); /* ---------------------------------- * SLIDER v2.0.0 * Licensed under The MIT License @@ -581,7 +677,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var pageX; var pageY; @@ -600,13 +697,18 @@ var getSlider = function (target) { var i, sliders = document.querySelectorAll('.slider > .slide-group'); 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 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) { @@ -615,12 +717,14 @@ slideNumber += offset; slideNumber = Math.min(slideNumber, 0); slideNumber = Math.max(-(slider.children.length - 1), slideNumber); - } + }; var onTouchStart = function (e) { slider = getSlider(e.target); - if (!slider) return; + if (!slider) { + return; + } var firstItem = slider.querySelector('.slide'); @@ -629,7 +733,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; @@ -641,34 +745,40 @@ }; var onTouchMove = function (e) { - if (e.touches.length > 1 || !slider) return; // Exit if a pinch || no slider + if (e.touches.length > 1 || !slider) { + return; // Exit if a pinch || no slider + } deltaX = e.touches[0].pageX - pageX; deltaY = e.touches[0].pageY - pageY; 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); } - if (isScrolling) return; + if (isScrolling) { + return; + } offsetX = (deltaX / resistance) + getScroll(); 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)'; }; var onTouchEnd = function (e) { - if (!slider || isScrolling) return; + 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; @@ -689,7 +799,7 @@ window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchend', onTouchEnd); -}(); +}()); /* ---------------------------------- * TOGGLE v2.0.0 @@ -697,7 +807,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var start = {}; var touchMove = false; @@ -707,16 +818,22 @@ var findToggle = function (target) { var i, toggles = document.querySelectorAll('.toggle'); 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) { e = e.originalEvent || e; toggle = findToggle(e.target); - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -730,9 +847,13 @@ window.addEventListener('touchmove', function (e) { e = e.originalEvent || e; - if (e.touches.length > 1) return; // Exit if a pinch + if (e.touches.length > 1) { + return; // Exit if a pinch + } - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var current = e.touches[0]; @@ -743,12 +864,18 @@ touchMove = true; distanceX = current.pageX - start.pageX; - if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) return; + if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) { + return; + } e.preventDefault(); - if (distanceX < 0) return handle.style.webkitTransform = 'translate3d(0,0,0)'; - if (distanceX > offset) return handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + if (distanceX < 0) { + return (handle.style.webkitTransform = 'translate3d(0,0,0)'); + } + if (distanceX > offset) { + return (handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'); + } handle.style.webkitTransform = 'translate3d(' + distanceX + 'px,0,0)'; @@ -756,7 +883,9 @@ }); window.addEventListener('touchend', function (e) { - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -764,8 +893,11 @@ var offset = (toggleWidth - handleWidth); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); - if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; - else handle.style.webkitTransform = 'translate3d(0,0,0)'; + if (slideOn) { + handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + } else { + handle.style.webkitTransform = 'translate3d(0,0,0)'; + } toggle.classList[slideOn ? 'add' : 'remove']('active'); @@ -781,4 +913,4 @@ toggle = false; }); -}(); +}()); diff --git a/docs/dist/js/ratchet.min.js b/docs/dist/js/ratchet.min.js index 6c3332d..b8bc8f3 100644 --- a/docs/dist/js/ratchet.min.js +++ b/docs/dist/js/ratchet.min.js @@ -7,4 +7,4 @@ * v2.0.0 designed by @connors. * ===================================================== */ -!function(){var a=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},b=function(b){var c=a(b.target);return c&&c.hash?document.querySelector(c.hash):void 0};window.addEventListener("touchend",function(a){var c=b(a);c&&(c&&c.classList.contains("modal")&&c.classList.toggle("active"),a.preventDefault())})}(),!function(){var a,b=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},c=function(){a.style.display="none",a.removeEventListener("webkitTransitionEnd",c)},d=function(){var b=document.createElement("div");return b.classList.add("backdrop"),b.addEventListener("touchend",function(){a.addEventListener("webkitTransitionEnd",c),a.classList.remove("visible"),a.parentNode.removeChild(d)}),b}(),e=function(c){var d=b(c.target);if(d&&d.hash&&!(d.hash.indexOf("/")>0)){try{a=document.querySelector(d.hash)}catch(e){a=null}if(null!=a&&a&&a.classList.contains("popover"))return a}},f=function(a){var b=e(a);b&&(b.style.display="block",b.offsetHeight,b.classList.add("visible"),b.parentNode.appendChild(d))};window.addEventListener("touchend",f),window.addEventListener("click",f)}(),!function(){var a,b=function(){},c=20,d=sessionStorage,e={},f={"slide-in":"slide-out","slide-out":"slide-in",fade:"fade"},g={bartab:".bar-tab",barnav:".bar-nav",barfooter:".bar-footer",barheadersecondary:".bar-header-secondary"},h=function(a,b){o.id=a.id,b&&(a=k(a.id)),d[a.id]=JSON.stringify(a),window.history.replaceState(a.id,a.title,a.url),e[a.id]=document.body.cloneNode(!0)},i=function(){var a=o.id,b=JSON.parse(d.cacheForwardStack||"[]"),e=JSON.parse(d.cacheBackStack||"[]");for(e.push(a);b.length;)delete d[b.shift()];for(;e.length>c;)delete d[e.shift()];window.history.pushState(null,"",d[o.id].url),d.cacheForwardStack=JSON.stringify(b),d.cacheBackStack=JSON.stringify(e)},j=function(a,b){var c="forward"==b,e=JSON.parse(d.cacheForwardStack||"[]"),f=JSON.parse(d.cacheBackStack||"[]"),g=c?f:e,h=c?e:f;o.id&&g.push(o.id),h.pop(),d.cacheForwardStack=JSON.stringify(e),d.cacheBackStack=JSON.stringify(f)},k=function(a){return JSON.parse(d[a]||null)||{}},l=function(b){var c=t(b.target);if(!(!c||b.which>1||b.metaKey||b.ctrlKey||a||location.protocol!==c.protocol||location.host!==c.host||!c.hash&&/#/.test(c.href)||c.hash&&c.href.replace(c.hash,"")===location.href.replace(location.hash,"")||"push"==c.getAttribute("data-ignore")))return c},m=function(a){var b=l(a);b&&(a.preventDefault(),o({url:b.href,hash:b.hash,timeout:b.getAttribute("data-timeout"),transition:b.getAttribute("data-transition")}))},n=function(a){var b,c,h,i,l,m,n,p,q=a.state;if(q&&d[q]){if(l=o.id ]*>([\s\S.]*)<\/head>/i)[0],d.innerHTML=f.match(/]*>([\s\S.]*)<\/body>/i)[0]):(c=d=document.createElement("div"),c.innerHTML=f),e.title=c.querySelector("title"),e.title=e.title&&e.title.innerText.trim(),b.transition?e=v(e,".content",d):e.contents=d,e):e};window.addEventListener("touchstart",function(){a=!1}),window.addEventListener("touchmove",function(){a=!0}),window.addEventListener("touchend",m),window.addEventListener("click",function(a){l(a)&&a.preventDefault()}),window.addEventListener("popstate",n),window.PUSH=o}(),!function(){var a=function(a){for(var b,c=document.querySelectorAll(".segmented-control .control-item");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchend",function(b){var c,d,e,f=a(b.target),g="active",h="."+g;if(f&&(c=f.parentNode.querySelector(h),c&&c.classList.remove(g),f.classList.add(g),f.hash&&(e=document.querySelector(f.hash)))){d=e.parentNode.querySelectorAll(h);for(var i=0;i.slide-group");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},o=function(){var a=c.style.webkitTransform.match(/translate3d\(([^,]*)/);return parseInt(a?a[1]:0)},p=function(a){var b=a?0>d?"ceil":"floor":"round";k=Math[b](o()/(m/c.children.length)),k+=a,k=Math.min(k,0),k=Math.max(-(c.children.length-1),k)},q=function(f){if(c=n(f.target)){var k=c.querySelector(".slide");m=k.offsetWidth*c.children.length,l=void 0,j=c.offsetWidth,i=1,g=-(c.children.length-1),h=+new Date,a=f.touches[0].pageX,b=f.touches[0].pageY,d=0,e=0,p(0),c.style["-webkit-transition-duration"]=0}},r=function(h){h.touches.length>1||!c||(d=h.touches[0].pageX-a,e=h.touches[0].pageY-b,a=h.touches[0].pageX,b=h.touches[0].pageY,"undefined"==typeof l&&(l=Math.abs(e)>Math.abs(d)),l||(f=d/i+o(),h.preventDefault(),i=0==k&&d>0?a/j+1.25:k==g&&0>d?Math.abs(a)/j+1.25:1,c.style.webkitTransform="translate3d("+f+"px,0,0)"))},s=function(a){c&&!l&&(p(+new Date-h<1e3&&Math.abs(d)>15?0>d?-1:1:0),f=k*j,c.style["-webkit-transition-duration"]=".2s",c.style.webkitTransform="translate3d("+f+"px,0,0)",a=new CustomEvent("slide",{detail:{slideNumber:Math.abs(k)},bubbles:!0,cancelable:!0}),c.parentNode.dispatchEvent(a))};window.addEventListener("touchstart",q),window.addEventListener("touchmove",r),window.addEventListener("touchend",s)}(),!function(){var a={},b=!1,c=!1,d=!1,e=function(a){for(var b,c=document.querySelectorAll(".toggle");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchstart",function(c){if(c=c.originalEvent||c,d=e(c.target)){var f=d.querySelector(".toggle-handle"),g=d.clientWidth,h=f.clientWidth,i=d.classList.contains("active")?g-h:0;a={pageX:c.touches[0].pageX-i,pageY:c.touches[0].pageY},b=!1}}),window.addEventListener("touchmove",function(e){if(e=e.originalEvent||e,!(e.touches.length>1)&&d){var f=d.querySelector(".toggle-handle"),g=e.touches[0],h=d.clientWidth,i=f.clientWidth,j=h-i;if(b=!0,c=g.pageX-a.pageX,!(Math.abs(c) c)return f.style.webkitTransform="translate3d(0,0,0)";if(c>j)return f.style.webkitTransform="translate3d("+j+"px,0,0)";f.style.webkitTransform="translate3d("+c+"px,0,0)",d.classList[c>h/2-i/2?"add":"remove"]("active")}}}),window.addEventListener("touchend",function(a){if(d){var e=d.querySelector(".toggle-handle"),f=d.clientWidth,g=e.clientWidth,h=f-g,i=!b&&!d.classList.contains("active")||b&&c>f/2-g/2;e.style.webkitTransform=i?"translate3d("+h+"px,0,0)":"translate3d(0,0,0)",d.classList[i?"add":"remove"]("active"),a=new CustomEvent("toggle",{detail:{isActive:i},bubbles:!0,cancelable:!0}),d.dispatchEvent(a),b=!1,d=!1}})}(); \ No newline at end of file +!function(){"use strict";var a=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},b=function(b){var c=a(b.target);return c&&c.hash?document.querySelector(c.hash):void 0};window.addEventListener("touchend",function(a){var c=b(a);c&&(c&&c.classList.contains("modal")&&c.classList.toggle("active"),a.preventDefault())})}(),!function(){"use strict";var a,b=function(a){for(var b,c=document.querySelectorAll("a");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},c=function(){a.style.display="none",a.removeEventListener("webkitTransitionEnd",c)},d=function(){var b=document.createElement("div");return b.classList.add("backdrop"),b.addEventListener("touchend",function(){a.addEventListener("webkitTransitionEnd",c),a.classList.remove("visible"),a.parentNode.removeChild(d)}),b}(),e=function(c){var d=b(c.target);if(d&&d.hash&&!(d.hash.indexOf("/")>0)){try{a=document.querySelector(d.hash)}catch(e){a=null}if(null!=a&&a&&a.classList.contains("popover"))return a}},f=function(a){var b=e(a);b&&(b.style.display="block",b.offsetHeight,b.classList.add("visible"),b.parentNode.appendChild(d))};window.addEventListener("touchend",f),window.addEventListener("click",f)}(),!function(){"use strict";var a,b=function(){},c=20,d=sessionStorage,e={},f={"slide-in":"slide-out","slide-out":"slide-in",fade:"fade"},g={bartab:".bar-tab",barnav:".bar-nav",barfooter:".bar-footer",barheadersecondary:".bar-header-secondary"},h=function(a,b){o.id=a.id,b&&(a=k(a.id)),d[a.id]=JSON.stringify(a),window.history.replaceState(a.id,a.title,a.url),e[a.id]=document.body.cloneNode(!0)},i=function(){var a=o.id,b=JSON.parse(d.cacheForwardStack||"[]"),e=JSON.parse(d.cacheBackStack||"[]");for(e.push(a);b.length;)delete d[b.shift()];for(;e.length>c;)delete d[e.shift()];window.history.pushState(null,"",d[o.id].url),d.cacheForwardStack=JSON.stringify(b),d.cacheBackStack=JSON.stringify(e)},j=function(a,b){var c="forward"===b,e=JSON.parse(d.cacheForwardStack||"[]"),f=JSON.parse(d.cacheBackStack||"[]"),g=c?f:e,h=c?e:f;o.id&&g.push(o.id),h.pop(),d.cacheForwardStack=JSON.stringify(e),d.cacheBackStack=JSON.stringify(f)},k=function(a){return JSON.parse(d[a]||null)||{}},l=function(b){var c=t(b.target);if(!(!c||b.which>1||b.metaKey||b.ctrlKey||a||location.protocol!==c.protocol||location.host!==c.host||!c.hash&&/#/.test(c.href)||c.hash&&c.href.replace(c.hash,"")===location.href.replace(location.hash,"")||"push"===c.getAttribute("data-ignore")))return c},m=function(a){var b=l(a);b&&(a.preventDefault(),o({url:b.href,hash:b.hash,timeout:b.getAttribute("data-timeout"),transition:b.getAttribute("data-transition")}))},n=function(a){var b,c,h,i,l,m,n,p,q=a.state;if(q&&d[q]){if(l=o.id ]*>([\s\S.]*)<\/head>/i)[0],d.innerHTML=f.match(/]*>([\s\S.]*)<\/body>/i)[0]):(c=d=document.createElement("div"),c.innerHTML=f),e.title=c.querySelector("title"),e.title=e.title&&e.title.innerText.trim(),b.transition?e=v(e,".content",d):e.contents=d,e):e};window.addEventListener("touchstart",function(){a=!1}),window.addEventListener("touchmove",function(){a=!0}),window.addEventListener("touchend",m),window.addEventListener("click",function(a){l(a)&&a.preventDefault()}),window.addEventListener("popstate",n),window.PUSH=o}(),!function(){"use strict";var a=function(a){for(var b,c=document.querySelectorAll(".segmented-control .control-item");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchend",function(b){var c,d,e,f=a(b.target),g="active",h="."+g;if(f&&(c=f.parentNode.querySelector(h),c&&c.classList.remove(g),f.classList.add(g),f.hash&&(e=document.querySelector(f.hash)))){d=e.parentNode.querySelectorAll(h);for(var i=0;i.slide-group");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a},o=function(){var a=c.style.webkitTransform.match(/translate3d\(([^,]*)/),b=a?a[1]:0;return parseInt(b,10)},p=function(a){var b=a?0>d?"ceil":"floor":"round";k=Math[b](o()/(m/c.children.length)),k+=a,k=Math.min(k,0),k=Math.max(-(c.children.length-1),k)},q=function(f){if(c=n(f.target)){var k=c.querySelector(".slide");m=k.offsetWidth*c.children.length,l=void 0,j=c.offsetWidth,i=1,g=-(c.children.length-1),h=+new Date,a=f.touches[0].pageX,b=f.touches[0].pageY,d=0,e=0,p(0),c.style["-webkit-transition-duration"]=0}},r=function(h){h.touches.length>1||!c||(d=h.touches[0].pageX-a,e=h.touches[0].pageY-b,a=h.touches[0].pageX,b=h.touches[0].pageY,"undefined"==typeof l&&(l=Math.abs(e)>Math.abs(d)),l||(f=d/i+o(),h.preventDefault(),i=0===k&&d>0?a/j+1.25:k===g&&0>d?Math.abs(a)/j+1.25:1,c.style.webkitTransform="translate3d("+f+"px,0,0)"))},s=function(a){c&&!l&&(p(+new Date-h<1e3&&Math.abs(d)>15?0>d?-1:1:0),f=k*j,c.style["-webkit-transition-duration"]=".2s",c.style.webkitTransform="translate3d("+f+"px,0,0)",a=new CustomEvent("slide",{detail:{slideNumber:Math.abs(k)},bubbles:!0,cancelable:!0}),c.parentNode.dispatchEvent(a))};window.addEventListener("touchstart",q),window.addEventListener("touchmove",r),window.addEventListener("touchend",s)}(),!function(){"use strict";var a={},b=!1,c=!1,d=!1,e=function(a){for(var b,c=document.querySelectorAll(".toggle");a&&a!==document;a=a.parentNode)for(b=c.length;b--;)if(c[b]===a)return a};window.addEventListener("touchstart",function(c){if(c=c.originalEvent||c,d=e(c.target)){var f=d.querySelector(".toggle-handle"),g=d.clientWidth,h=f.clientWidth,i=d.classList.contains("active")?g-h:0;a={pageX:c.touches[0].pageX-i,pageY:c.touches[0].pageY},b=!1}}),window.addEventListener("touchmove",function(e){if(e=e.originalEvent||e,!(e.touches.length>1)&&d){var f=d.querySelector(".toggle-handle"),g=e.touches[0],h=d.clientWidth,i=f.clientWidth,j=h-i;if(b=!0,c=g.pageX-a.pageX,!(Math.abs(c) c)return f.style.webkitTransform="translate3d(0,0,0)";if(c>j)return f.style.webkitTransform="translate3d("+j+"px,0,0)";f.style.webkitTransform="translate3d("+c+"px,0,0)",d.classList[c>h/2-i/2?"add":"remove"]("active")}}}),window.addEventListener("touchend",function(a){if(d){var e=d.querySelector(".toggle-handle"),f=d.clientWidth,g=e.clientWidth,h=f-g,i=!b&&!d.classList.contains("active")||b&&c>f/2-g/2;e.style.webkitTransform=i?"translate3d("+h+"px,0,0)":"translate3d(0,0,0)",d.classList[i?"add":"remove"]("active"),a=new CustomEvent("toggle",{detail:{isActive:i},bubbles:!0,cancelable:!0}),d.dispatchEvent(a),b=!1,d=!1}})}(); \ No newline at end of file diff --git a/js/.jshintrc b/js/.jshintrc new file mode 100644 index 0000000..b81ecc1 --- /dev/null +++ b/js/.jshintrc @@ -0,0 +1,22 @@ +{ + "bitwise" : true, + "browser" : true, + "camelcase" : true, + "curly" : true, + "devel" : true, + "eqeqeq" : true, + "eqnull" : true, + "expr" : true, + "forin" : true, + "freeze" : true, + "immed" : true, + "indent" : 2, + "latedef" : true, + "newcap" : true, + "nonbsp" : true, + "quotmark" : "single", + "strict" : true, + "trailing" : true, + "undef" : true, + "unused" : true +} diff --git a/js/modals.js b/js/modals.js index f4fbb68..0fc3bf6 100644 --- a/js/modals.js +++ b/js/modals.js @@ -4,24 +4,34 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var findModals = function (target) { var i, modals = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = modals.length; i--;) { if (modals[i] === target) return target; } + for (i = modals.length; i--;) { + if (modals[i] === target) { + return target; + } + } } }; var getModal = function (event) { var modalToggle = findModals(event.target); - if (modalToggle && modalToggle.hash) return document.querySelector(modalToggle.hash); + if (modalToggle && modalToggle.hash) { + return document.querySelector(modalToggle.hash); + } }; window.addEventListener('touchend', function (event) { var modal = getModal(event); if (modal) { - if (modal && modal.classList.contains('modal')) modal.classList.toggle('active'); + if (modal && modal.classList.contains('modal')) { + modal.classList.toggle('active'); + } event.preventDefault(); // prevents rewriting url (apps can still use hash values in url) } }); -}(); +}()); diff --git a/js/popovers.js b/js/popovers.js index ff9b306..5551b41 100644 --- a/js/popovers.js +++ b/js/popovers.js @@ -4,23 +4,28 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var popover; var findPopovers = function (target) { var i, popovers = document.querySelectorAll('a'); for (; target && target !== document; target = target.parentNode) { - for (i = popovers.length; i--;) { if (popovers[i] === target) return target; } + for (i = popovers.length; i--;) { + if (popovers[i] === target) { + return target; + } + } } }; var onPopoverHidden = function () { popover.style.display = 'none'; popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); - } + }; - var backdrop = function () { + var backdrop = (function () { var element = document.createElement('div'); element.classList.add('backdrop'); @@ -32,31 +37,39 @@ }); return element; - }(); + }()); 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; + if (popover == null) { + return; + } - if (!popover || !popover.classList.contains('popover')) return; + if (!popover || !popover.classList.contains('popover')) { + return; + } return popover; - } + }; var showHidePopover = function (e) { var popover = getPopover(e); - if (!popover) return; + if (!popover) { + return; + } popover.style.display = 'block'; popover.offsetHeight; @@ -68,4 +81,4 @@ window.addEventListener('touchend', showHidePopover); window.addEventListener('click', showHidePopover); -}(); +}()); diff --git a/js/push.js b/js/push.js index 3df4793..da45507 100644 --- a/js/push.js +++ b/js/push.js @@ -5,7 +5,10 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +/* global _gaq: true */ + +!(function () { + 'use strict'; var noop = function () {}; @@ -32,7 +35,9 @@ var cacheReplace = function (data, updates) { PUSH.id = data.id; - if (updates) data = getCached(data.id); + if (updates) { + data = getCached(data.id); + } cacheMapping[data.id] = JSON.stringify(data); window.history.replaceState(data.id, data.title, data.url); domCache[data.id] = document.body.cloneNode(true); @@ -46,8 +51,12 @@ cacheBackStack.push(id); - while (cacheForwardStack.length) delete cacheMapping[cacheForwardStack.shift()]; - while (cacheBackStack.length > maxCacheLength) delete cacheMapping[cacheBackStack.shift()]; + while (cacheForwardStack.length) { + delete cacheMapping[cacheForwardStack.shift()]; + } + while (cacheBackStack.length > maxCacheLength) { + delete cacheMapping[cacheBackStack.shift()]; + } window.history.pushState(null, '', cacheMapping[PUSH.id].url); @@ -56,13 +65,15 @@ }; 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; var popStack = forward ? cacheForwardStack : cacheBackStack; - if (PUSH.id) pushStack.push(PUSH.id); + if (PUSH.id) { + pushStack.push(PUSH.id); + } popStack.pop(); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); @@ -76,18 +87,16 @@ var getTarget = function (e) { var target = findTarget(e.target); - if ( - ! target - || e.which > 1 - || e.metaKey - || e.ctrlKey - || isScrolling - || location.protocol !== target.protocol - || 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' - ) return; + if (!target || + e.which > 1 || + e.metaKey || + e.ctrlKey || + isScrolling || + location.protocol !== target.protocol || + 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') { return; } return target; }; @@ -99,7 +108,9 @@ var touchend = function (e) { var target = getTarget(e); - if (!target) return; + if (!target) { + return; + } e.preventDefault(); @@ -122,7 +133,9 @@ var transitionFromObj; var id = e.state; - if (!id || !cacheMapping[id]) return; + if (!id || !cacheMapping[id]) { + return; + } direction = PUSH.id < id ? 'forward' : 'back'; @@ -131,18 +144,22 @@ activeObj = getCached(id); activeDom = domCache[id]; - if (activeObj.title) document.title = activeObj.title; + 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,9 +175,14 @@ if (transitionFromObj.transition) { activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); for (key in bars) { - barElement = document.querySelector(bars[key]) - if (activeObj[key]) swapContent(activeObj[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (activeObj[key]) { + swapContent(activeObj[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } @@ -181,18 +203,19 @@ 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; for (key in bars) { - options[key] = options[key] || document.querySelector(bars[key]); + if (bars.hasOwnProperty(key)) { + options[key] = options[key] || document.querySelector(bars[key]); + } } if (xhr && xhr.readyState < 4) { xhr.onreadystatechange = noop; - xhr.abort() + xhr.abort(); } xhr = new XMLHttpRequest(); @@ -200,13 +223,17 @@ xhr.setRequestHeader('X-PUSH', 'true'); xhr.onreadystatechange = function () { - if (options._timeout) clearTimeout(options._timeout); - if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); + if (options._timeout) { + clearTimeout(options._timeout); + } + 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, @@ -220,7 +247,9 @@ xhr.send(); - if (xhr.readyState && !options.ignorePush) cachePush(); + if (xhr.readyState && !options.ignorePush) { + cachePush(); + } }; @@ -232,21 +261,30 @@ var barElement; var data = parseXHR(xhr, options); - if (!data.contents) return locationReplace(options.url); + if (!data.contents) { + return locationReplace(options.url); + } - if (data.title) document.title = data.title; + if (data.title) { + document.title = data.title; + } if (options.transition) { for (key in bars) { - barElement = document.querySelector(bars[key]) - if (data[key]) swapContent(data[key], barElement); - else if (barElement) barElement.parentNode.removeChild(barElement); + if (bars.hasOwnProperty(key)) { + barElement = document.querySelector(bars[key]); + if (data[key]) { + swapContent(data[key], barElement); + } else if (barElement) { + barElement.parentNode.removeChild(barElement); + } + } } } 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 +293,16 @@ triggerStateChange(); }); - if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics - if (!options.hash) return; + 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); }; @@ -273,13 +315,17 @@ var swapDirection; if (!transition) { - if (container) container.innerHTML = swap.innerHTML; - else if (swap.classList.contains('content')) document.body.appendChild(swap); - else document.body.insertBefore(swap, document.querySelector('.content')); + if (container) { + container.innerHTML = swap.innerHTML; + } else if (swap.classList.contains('content')) { + document.body.appendChild(swap); + } else { + document.body.insertBefore(swap, document.querySelector('.content')); + } } else { enter = /in$/.test(transition); - if (transition == 'fade') { + if (transition === 'fade') { container.classList.add('in'); container.classList.add('fade'); swap.classList.add('fade'); @@ -294,42 +340,44 @@ container.parentNode.insertBefore(swap, container); } - if (!transition) complete && complete(); + 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); } }; @@ -346,7 +394,11 @@ var findTarget = function (target) { var i, toggles = document.querySelectorAll('a'); 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; + } + } } }; @@ -355,19 +407,21 @@ 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]; + for (i in obj) { + if (obj.hasOwnProperty(i)) { + result[i] = obj[i]; + } + } Object.keys(bars).forEach(function (key) { var el = dom.querySelector(bars[key]); - if (el) el.parentNode.removeChild(el); + if (el) { + el.parentNode.removeChild(el); + } result[key] = el; }); @@ -384,13 +438,15 @@ data.url = options.url; - if (!responseText) return data; + if (!responseText) { + return data; + } if (/]*>([\s\S.]*)<\/head>/i)[0] - body.innerHTML = responseText.match(/]*>([\s\S.]*)<\/body>/i)[0] + head.innerHTML = responseText.match(/]*>([\s\S.]*)<\/head>/i)[0]; + body.innerHTML = responseText.match(/]*>([\s\S.]*)<\/body>/i)[0]; } else { head = body = document.createElement('div'); head.innerHTML = responseText; @@ -399,8 +455,11 @@ data.title = head.querySelector('title'); data.title = data.title && data.title.innerText.trim(); - if (options.transition) data = extendWithDom(data, '.content', body); - else data.contents = body; + if (options.transition) { + data = extendWithDom(data, '.content', body); + } else { + data.contents = body; + } return data; }; @@ -410,10 +469,10 @@ // ========================== 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('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('popstate', popstate); window.PUSH = PUSH; -}(); +}()); diff --git a/js/segmented-controllers.js b/js/segmented-controllers.js index 359b5d6..006c13d 100644 --- a/js/segmented-controllers.js +++ b/js/segmented-controllers.js @@ -4,15 +4,21 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; + var getTarget = function (target) { var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item'); for (; target && target !== document; target = target.parentNode) { - for (i = segmentedControls.length; i--;) { if (segmentedControls[i] === target) return target; } + for (i = segmentedControls.length; i--;) { + if (segmentedControls[i] === target) { + return target; + } + } } }; - window.addEventListener("touchend", function (e) { + window.addEventListener('touchend', function (e) { var activeTab; var activeBodies; var targetBody; @@ -20,19 +26,27 @@ var className = 'active'; var classSelector = '.' + className; - if (!targetTab) return; + if (!targetTab) { + return; + } activeTab = targetTab.parentNode.querySelector(classSelector); - if (activeTab) activeTab.classList.remove(className); + if (activeTab) { + activeTab.classList.remove(className); + } targetTab.classList.add(className); - if (!targetTab.hash) return; + if (!targetTab.hash) { + return; + } targetBody = document.querySelector(targetTab.hash); - if (!targetBody) return; + if (!targetBody) { + return; + } activeBodies = targetBody.parentNode.querySelectorAll(classSelector); @@ -43,5 +57,5 @@ targetBody.classList.add(className); }); - window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); }); -}(); \ No newline at end of file + window.addEventListener('click', function (e) { if (getTarget(e.target)) {e.preventDefault();} }); +}()); \ No newline at end of file diff --git a/js/sliders.js b/js/sliders.js index 76708ad..43dc248 100644 --- a/js/sliders.js +++ b/js/sliders.js @@ -5,7 +5,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var pageX; var pageY; @@ -24,13 +25,18 @@ var getSlider = function (target) { var i, sliders = document.querySelectorAll('.slider > .slide-group'); 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 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,12 +45,14 @@ slideNumber += offset; slideNumber = Math.min(slideNumber, 0); slideNumber = Math.max(-(slider.children.length - 1), slideNumber); - } + }; var onTouchStart = function (e) { slider = getSlider(e.target); - if (!slider) return; + if (!slider) { + return; + } var firstItem = slider.querySelector('.slide'); @@ -53,7 +61,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; @@ -65,34 +73,40 @@ }; var onTouchMove = function (e) { - if (e.touches.length > 1 || !slider) return; // Exit if a pinch || no slider + if (e.touches.length > 1 || !slider) { + return; // Exit if a pinch || no slider + } deltaX = e.touches[0].pageX - pageX; deltaY = e.touches[0].pageY - pageY; 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); } - if (isScrolling) return; + if (isScrolling) { + return; + } offsetX = (deltaX / resistance) + getScroll(); 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)'; }; var onTouchEnd = function (e) { - if (!slider || isScrolling) return; + 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; @@ -113,4 +127,4 @@ window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchend', onTouchEnd); -}(); +}()); diff --git a/js/toggles.js b/js/toggles.js index 496d9a6..e8e9f7c 100644 --- a/js/toggles.js +++ b/js/toggles.js @@ -4,7 +4,8 @@ * http://opensource.org/licenses/MIT * ---------------------------------- */ -!function () { +!(function () { + 'use strict'; var start = {}; var touchMove = false; @@ -14,16 +15,22 @@ var findToggle = function (target) { var i, toggles = document.querySelectorAll('.toggle'); 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) { e = e.originalEvent || e; toggle = findToggle(e.target); - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -37,9 +44,13 @@ window.addEventListener('touchmove', function (e) { e = e.originalEvent || e; - if (e.touches.length > 1) return; // Exit if a pinch + if (e.touches.length > 1) { + return; // Exit if a pinch + } - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var current = e.touches[0]; @@ -50,12 +61,18 @@ touchMove = true; distanceX = current.pageX - start.pageX; - if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) return; + if (Math.abs(distanceX) < Math.abs(current.pageY - start.pageY)) { + return; + } e.preventDefault(); - if (distanceX < 0) return handle.style.webkitTransform = 'translate3d(0,0,0)'; - if (distanceX > offset) return handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + if (distanceX < 0) { + return (handle.style.webkitTransform = 'translate3d(0,0,0)'); + } + if (distanceX > offset) { + return (handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'); + } handle.style.webkitTransform = 'translate3d(' + distanceX + 'px,0,0)'; @@ -63,7 +80,9 @@ }); window.addEventListener('touchend', function (e) { - if (!toggle) return; + if (!toggle) { + return; + } var handle = toggle.querySelector('.toggle-handle'); var toggleWidth = toggle.clientWidth; @@ -71,8 +90,11 @@ var offset = (toggleWidth - handleWidth); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); - if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; - else handle.style.webkitTransform = 'translate3d(0,0,0)'; + if (slideOn) { + handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; + } else { + handle.style.webkitTransform = 'translate3d(0,0,0)'; + } toggle.classList[slideOn ? 'add' : 'remove']('active'); @@ -88,4 +110,4 @@ toggle = false; }); -}(); +}());