From c0d00ce2ca44a1ca55e4487992072e5fb88893f5 Mon Sep 17 00:00:00 2001 From: Simon Waldherr Date: Mon, 8 Apr 2013 17:16:53 +0200 Subject: [PATCH] more valid (jshint) code --- dist/ratchet.js | 390 +++++++++++++++++++------------- lib/js/modals.js | 17 +- lib/js/popovers.js | 32 ++- lib/js/push.js | 210 +++++++++-------- lib/js/segmented-controllers.js | 39 ++-- lib/js/sliders.js | 28 +-- lib/js/toggles.js | 59 +++-- 7 files changed, 452 insertions(+), 323 deletions(-) diff --git a/dist/ratchet.js b/dist/ratchet.js index 084a559..fb92559 100644 --- a/dist/ratchet.js +++ b/dist/ratchet.js @@ -13,37 +13,51 @@ * ---------------------------------- */ !function () { + "use strict"; var findModals = function (target) { var i; var 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) modal.classList.toggle('active'); + if (modal) { + modal.classList.toggle('active'); + } }); -}();/* ---------------------------------- +}(); +/* ---------------------------------- * POPOVER v1.0.0 * Licensed under The MIT License * http://opensource.org/licenses/MIT * ---------------------------------- */ !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; + } + } } }; @@ -51,7 +65,7 @@ document.body.removeChild(backdrop); popover.style.display = 'none'; popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); - } + }; var backdrop = function () { var element = document.createElement('div'); @@ -69,28 +83,38 @@ var getPopover = function (e) { var anchor = findPopovers(e.target); - if (!anchor || !anchor.hash) return; + if (!anchor || !anchor.hash) { + return; + } popover = document.querySelector(anchor.hash); - if (!popover || !popover.classList.contains('popover')) return; + if (!popover || !popover.classList.contains('popover')) { + return; + } return popover; - } + }; window.addEventListener('touchend', function (e) { var popover = getPopover(e); - if (!popover) return; + if (!popover) { + return; + } popover.style.display = 'block'; - popover.offsetHeight; + //popover.offsetHeight; popover.classList.add('visible'); popover.parentNode.appendChild(backdrop); }); - window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); }); + window.addEventListener('click', function (e) { + if (getPopover(e)) { + e.preventDefault(); + } + }); }(); /* ---------------------------------- @@ -101,47 +125,51 @@ * ---------------------------------- */ !function () { - + "use strict"; var noop = function () {}; - // Pushstate cacheing // ================== - var isScrolling; - var maxCacheLength = 20; - var cacheMapping = sessionStorage; - var domCache = {}; - var transitionMap = { + var isScrolling, + maxCacheLength = 20, + cacheMapping = sessionStorage, + domCache = {}, + transitionMap = { 'slide-in' : 'slide-out', 'slide-out' : 'slide-in', 'fade' : 'fade' - }; - var bars = { + }, + bars = { bartab : '.bar-tab', bartitle : '.bar-title', barfooter : '.bar-footer', barheadersecondary : '.bar-header-secondary' - } + }; 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); }; var cachePush = function () { - var id = PUSH.id; - - var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'); - var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); + var id = PUSH.id, + cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'), + cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); 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); @@ -150,13 +178,15 @@ }; var cachePop = function (id, direction) { - 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); + var forward = direction === 'forward', + cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'), + cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'), + pushStack = forward ? cacheBackStack : cacheForwardStack, + popStack = forward ? cacheForwardStack : cacheBackStack; + + if (PUSH.id) { + pushStack.push(PUSH.id); + } popStack.pop(); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); @@ -170,18 +200,9 @@ 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; }; @@ -193,7 +214,9 @@ var touchend = function (e) { var target = getTarget(e); - if (!target) return; + if (!target) { + return; + } e.preventDefault(); @@ -206,37 +229,43 @@ }; var popstate = function (e) { - var key; - var barElement; - var activeObj; - var activeDom; - var direction; - var transition; - var transitionFrom; - var transitionFromObj; - var id = e.state; - - if (!id || !cacheMapping[id]) return; + var key, + barElement, + activeObj, + activeDom, + direction, + transition, + transitionFrom, + transitionFromObj, + id = e.state; + + if (!id || !cacheMapping[id]) { + return; + } - direction = PUSH.id < id ? 'forward' : 'back'; + direction = (PUSH.id < id) ? 'forward' : 'back'; cachePop(id, direction); 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 id; + } - transition = direction == 'back' ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition; + transition = (direction === 'back') ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition; if (!activeDom) { return PUSH({ @@ -252,9 +281,13 @@ 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); + barElement = document.querySelector(bars[key]); + if (activeObj[key]) { + swapContent(activeObj[key], barElement); + } + else if (barElement) { + barElement.parentNode.removeChild(barElement); + } } } @@ -274,9 +307,9 @@ // ======================= var PUSH = function (options) { - var key; - var data = {}; - var xhr = PUSH.xhr; + var key, + data = {}, + xhr = PUSH.xhr; options.container = options.container || options.transition ? document.querySelector('.content') : document.body; @@ -295,7 +328,9 @@ xhr.onreadystatechange = function () { if (options._timeout) clearTimeout(options._timeout); - if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); + if (xhr.readyState === 4) { + (xhr.status === 200) ? success(xhr, options) : failure(options.url); + } }; if (!PUSH.id) { @@ -362,9 +397,29 @@ // ============ var swapContent = function (swap, container, transition, complete) { - var enter; - var containerDirection; - var swapDirection; + "use strict"; + function fadeContainerEnd() { + container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); + swap.classList.add('in'); + swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); + } + function fadeSwapEnd () { + swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); + container.parentNode.removeChild(container); + swap.classList.remove('fade'); + swap.classList.remove('in'); + complete && complete(); + } + function slideEnd() { + swap.removeEventListener('webkitTransitionEnd', slideEnd); + swap.classList.remove('slide'); + swap.classList.remove(swapDirection); + container.parentNode.removeChild(container); + complete && complete(); + } + var enter, + containerDirection, + swapDirection; if (!transition) { if (container) container.innerHTML = swap.innerHTML; @@ -373,7 +428,7 @@ } else { enter = /in$/.test(transition); - if (transition == 'fade') { + if (transition === 'fade') { container.classList.add('in'); container.classList.add('fade'); swap.classList.add('fade'); @@ -388,25 +443,14 @@ 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() { - container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); - swap.classList.add('in'); - swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); - } - function fadeSwapEnd () { - swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); - container.parentNode.removeChild(container); - swap.classList.remove('fade'); - swap.classList.remove('in'); - complete && complete(); - } } if (/slide/.test(transition)) { @@ -416,14 +460,6 @@ container.classList.add(containerDirection); swap.classList.remove(swapDirection); swap.addEventListener('webkitTransitionEnd', slideEnd); - - function slideEnd() { - swap.removeEventListener('webkitTransitionEnd', slideEnd); - swap.classList.remove('slide'); - swap.classList.remove(swapDirection); - container.parentNode.removeChild(container); - complete && complete(); - } } }; @@ -457,7 +493,9 @@ var i; var result = {}; - for (i in obj) result[i] = obj[i]; + for (i = 0; i < obj.length; i += 1) { + result[i] = obj[i]; + } Object.keys(bars).forEach(function (key) { var el = dom.querySelector(bars[key]); @@ -471,14 +509,16 @@ }; var parseXHR = function (xhr, options) { - var head; - var body; - var data = {}; - var responseText = xhr.responseText; + var head, + body, + data = {}, + responseText = xhr.responseText; data.url = options.url; - if (!responseText) return data; + if (!responseText) { + return data; + } if (/ 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)'; @@ -739,14 +802,17 @@ window.addEventListener('touchend', function (e) { if (!toggle) return; - var handle = toggle.querySelector('.toggle-handle'); - var toggleWidth = toggle.offsetWidth; - var handleWidth = handle.offsetWidth; - var offset = toggleWidth - handleWidth; - var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); + var handle = toggle.querySelector('.toggle-handle'), + toggleWidth = toggle.offsetWidth, + handleWidth = handle.offsetWidth, + offset = toggleWidth - handleWidth, + 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'); diff --git a/lib/js/modals.js b/lib/js/modals.js index 4448107..01bf48a 100644 --- a/lib/js/modals.js +++ b/lib/js/modals.js @@ -5,21 +5,30 @@ * ---------------------------------- */ !function () { + "use strict"; var findModals = function (target) { var i; var 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) modal.classList.toggle('active'); + if (modal) { + modal.classList.toggle('active'); + } }); -}(); \ No newline at end of file +}(); diff --git a/lib/js/popovers.js b/lib/js/popovers.js index 6cdf1c6..05e5ef5 100644 --- a/lib/js/popovers.js +++ b/lib/js/popovers.js @@ -5,13 +5,17 @@ * ---------------------------------- */ !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; + } + } } }; @@ -19,7 +23,7 @@ document.body.removeChild(backdrop); popover.style.display = 'none'; popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); - } + }; var backdrop = function () { var element = document.createElement('div'); @@ -37,27 +41,37 @@ var getPopover = function (e) { var anchor = findPopovers(e.target); - if (!anchor || !anchor.hash) return; + if (!anchor || !anchor.hash) { + return; + } popover = document.querySelector(anchor.hash); - if (!popover || !popover.classList.contains('popover')) return; + if (!popover || !popover.classList.contains('popover')) { + return; + } return popover; - } + }; window.addEventListener('touchend', function (e) { var popover = getPopover(e); - if (!popover) return; + if (!popover) { + return; + } popover.style.display = 'block'; - popover.offsetHeight; + //popover.offsetHeight; popover.classList.add('visible'); popover.parentNode.appendChild(backdrop); }); - window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); }); + window.addEventListener('click', function (e) { + if (getPopover(e)) { + e.preventDefault(); + } + }); }(); diff --git a/lib/js/push.js b/lib/js/push.js index e0e772d..3ae258e 100644 --- a/lib/js/push.js +++ b/lib/js/push.js @@ -6,24 +6,22 @@ * ---------------------------------- */ !function () { - + "use strict"; var noop = function () {}; - // Pushstate cacheing // ================== - var isScrolling; - var maxCacheLength = 20; - var cacheMapping = sessionStorage; - var domCache = {}; - var transitionMap = { + var isScrolling, + maxCacheLength = 20, + cacheMapping = sessionStorage, + domCache = {}, + transitionMap = { 'slide-in' : 'slide-out', 'slide-out' : 'slide-in', 'fade' : 'fade' - }; - - var bars = { + }, + bars = { bartab : '.bar-tab', bartitle : '.bar-title', barfooter : '.bar-footer', @@ -32,22 +30,27 @@ 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); }; var cachePush = function () { - var id = PUSH.id; - - var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'); - var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); + var id = PUSH.id, + cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'), + cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); 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 +59,15 @@ }; var cachePop = function (id, direction) { - 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); + var forward = direction === 'forward', + cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'), + cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'), + pushStack = forward ? cacheBackStack : cacheForwardStack, + popStack = forward ? cacheForwardStack : cacheBackStack; + + if (PUSH.id) { + pushStack.push(PUSH.id); + } popStack.pop(); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); @@ -76,18 +81,9 @@ 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 +95,9 @@ var touchend = function (e) { var target = getTarget(e); - if (!target) return; + if (!target) { + return; + } e.preventDefault(); @@ -112,37 +110,43 @@ }; var popstate = function (e) { - var key; - var barElement; - var activeObj; - var activeDom; - var direction; - var transition; - var transitionFrom; - var transitionFromObj; - var id = e.state; - - if (!id || !cacheMapping[id]) return; + var key, + barElement, + activeObj, + activeDom, + direction, + transition, + transitionFrom, + transitionFromObj, + id = e.state; + + if (!id || !cacheMapping[id]) { + return; + } - direction = PUSH.id < id ? 'forward' : 'back'; + direction = (PUSH.id < id) ? 'forward' : 'back'; cachePop(id, direction); 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 id; + } - transition = direction == 'back' ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition; + transition = (direction === 'back') ? transitionMap[transitionFromObj.transition] : transitionFromObj.transition; if (!activeDom) { return PUSH({ @@ -158,9 +162,13 @@ 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); + barElement = document.querySelector(bars[key]); + if (activeObj[key]) { + swapContent(activeObj[key], barElement); + } + else if (barElement) { + barElement.parentNode.removeChild(barElement); + } } } @@ -180,9 +188,9 @@ // ======================= var PUSH = function (options) { - var key; - var data = {}; - var xhr = PUSH.xhr; + var key, + data = {}, + xhr = PUSH.xhr; options.container = options.container || options.transition ? document.querySelector('.content') : document.body; @@ -201,7 +209,9 @@ xhr.onreadystatechange = function () { if (options._timeout) clearTimeout(options._timeout); - if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); + if (xhr.readyState === 4) { + (xhr.status === 200) ? success(xhr, options) : failure(options.url); + } }; if (!PUSH.id) { @@ -268,9 +278,29 @@ // ============ var swapContent = function (swap, container, transition, complete) { - var enter; - var containerDirection; - var swapDirection; + "use strict"; + function fadeContainerEnd() { + container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); + swap.classList.add('in'); + swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); + } + function fadeSwapEnd () { + swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); + container.parentNode.removeChild(container); + swap.classList.remove('fade'); + swap.classList.remove('in'); + complete && complete(); + } + function slideEnd() { + swap.removeEventListener('webkitTransitionEnd', slideEnd); + swap.classList.remove('slide'); + swap.classList.remove(swapDirection); + container.parentNode.removeChild(container); + complete && complete(); + } + var enter, + containerDirection, + swapDirection; if (!transition) { if (container) container.innerHTML = swap.innerHTML; @@ -279,7 +309,7 @@ } else { enter = /in$/.test(transition); - if (transition == 'fade') { + if (transition === 'fade') { container.classList.add('in'); container.classList.add('fade'); swap.classList.add('fade'); @@ -294,25 +324,14 @@ 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() { - container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); - swap.classList.add('in'); - swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); - } - function fadeSwapEnd () { - swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); - container.parentNode.removeChild(container); - swap.classList.remove('fade'); - swap.classList.remove('in'); - complete && complete(); - } } if (/slide/.test(transition)) { @@ -322,14 +341,6 @@ container.classList.add(containerDirection); swap.classList.remove(swapDirection); swap.addEventListener('webkitTransitionEnd', slideEnd); - - function slideEnd() { - swap.removeEventListener('webkitTransitionEnd', slideEnd); - swap.classList.remove('slide'); - swap.classList.remove(swapDirection); - container.parentNode.removeChild(container); - complete && complete(); - } } }; @@ -363,7 +374,9 @@ var i; var result = {}; - for (i in obj) result[i] = obj[i]; + for (i = 0; i < obj.length; i += 1) { + result[i] = obj[i]; + } Object.keys(bars).forEach(function (key) { var el = dom.querySelector(bars[key]); @@ -377,14 +390,16 @@ }; var parseXHR = function (xhr, options) { - var head; - var body; - var data = {}; - var responseText = xhr.responseText; + var head, + body, + data = {}, + responseText = xhr.responseText; data.url = options.url; - if (!responseText) return data; + if (!responseText) { + return data; + } if (/ 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)'; @@ -68,14 +76,17 @@ window.addEventListener('touchend', function (e) { if (!toggle) return; - var handle = toggle.querySelector('.toggle-handle'); - var toggleWidth = toggle.offsetWidth; - var handleWidth = handle.offsetWidth; - var offset = toggleWidth - handleWidth; - var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); + var handle = toggle.querySelector('.toggle-handle'), + toggleWidth = toggle.offsetWidth, + handleWidth = handle.offsetWidth, + offset = toggleWidth - handleWidth, + 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');