diff options
author | XhmikosR <xhmikosr@gmail.com> | 2015-01-30 12:31:35 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2015-01-30 12:31:35 +0300 |
commit | 004d2d45b52c54be0fa2c8f2db5c0569333d20db (patch) | |
tree | 9dd6acf8cb7e515104d2c390da191d9b7f1be922 | |
parent | e9bab3904b21c064fb27807cc429b475db4e2e59 (diff) | |
parent | 51b9b81509587a312ff36ddb94c5118ecf57aaf5 (diff) |
Merge pull request #521 from twbs/js-2
JS tweaks
-rw-r--r-- | dist/js/ratchet.js | 46 | ||||
-rw-r--r-- | docs/assets/js/docs.js | 4 | ||||
-rw-r--r-- | docs/assets/js/fingerblast.js | 2 | ||||
-rw-r--r-- | docs/dist/js/ratchet.js | 46 | ||||
-rw-r--r-- | js/popovers.js | 3 | ||||
-rw-r--r-- | js/push.js | 28 | ||||
-rw-r--r-- | js/segmented-controllers.js | 7 | ||||
-rw-r--r-- | js/sliders.js | 4 | ||||
-rw-r--r-- | js/toggles.js | 4 |
9 files changed, 100 insertions, 44 deletions
diff --git a/dist/js/ratchet.js b/dist/js/ratchet.js index 85e8cfd..d865c64 100644 --- a/dist/js/ratchet.js +++ b/dist/js/ratchet.js @@ -103,8 +103,7 @@ try { popover = document.querySelector(anchor.hash); - } - catch (error) { + } catch (error) { popover = null; } @@ -370,7 +369,11 @@ clearTimeout(options._timeout); } if (xhr.readyState === 4) { - xhr.status === 200 ? success(xhr, options) : failure(options.url); + if (xhr.status === 200) { + success(xhr, options); + } else { + failure(options.url); + } } }; @@ -397,7 +400,7 @@ } }; - function cacheCurrentContent() { + function cacheCurrentContent () { domCache[PUSH.id] = document.body.cloneNode(true); } @@ -472,7 +475,7 @@ document.body.insertBefore(swap, document.querySelector('.content')); } } else { - enter = /in$/.test(transition); + enter = /in$/.test(transition); if (transition === 'fade') { container.classList.add('in'); @@ -490,7 +493,9 @@ } if (!transition) { - complete && complete(); + if (complete) { + complete(); + } } if (transition === 'fade') { @@ -506,7 +511,9 @@ container.parentNode.removeChild(container); swap.classList.remove('fade'); swap.classList.remove('in'); - complete && complete(); + if (complete) { + complete(); + } }; container.addEventListener('webkitTransitionEnd', fadeContainerEnd); @@ -518,7 +525,9 @@ swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove(swapDirection); container.parentNode.removeChild(container); - complete && complete(); + if (complete) { + complete(); + } }; container.offsetWidth; // force reflow @@ -623,7 +632,11 @@ window.addEventListener('touchstart', function () { isScrolling = false; }); 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; @@ -692,7 +705,12 @@ 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(); + } + }); + }()); /* ======================================================================== @@ -820,9 +838,7 @@ // we're done moving startedMoving = false; - setSlideNumber( - (+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 - ); + setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0); offsetX = slideNumber * sliderWidth; @@ -950,7 +966,9 @@ toggle.classList[slideOn ? 'add' : 'remove']('active'); e = new CustomEvent('toggle', { - detail: { isActive: slideOn }, + detail: { + isActive: slideOn + }, bubbles: true, cancelable: true }); diff --git a/docs/assets/js/docs.js b/docs/assets/js/docs.js index 094d15a..753ffba 100644 --- a/docs/assets/js/docs.js +++ b/docs/assets/js/docs.js @@ -185,6 +185,8 @@ $(function () { $(window).on('load resize', initialize); $(window).on('load', function () { - window.FingerBlast && (new FingerBlast('.device-content')); + if (window.FingerBlast) { + new FingerBlast('.device-content'); + } }); }); diff --git a/docs/assets/js/fingerblast.js b/docs/assets/js/fingerblast.js index 68d6b43..5d5d646 100644 --- a/docs/assets/js/fingerblast.js +++ b/docs/assets/js/fingerblast.js @@ -9,7 +9,7 @@ 'use strict'; - function FingerBlast(element) { + function FingerBlast (element) { this.element = typeof element === 'string' ? document.querySelector(element) : element; if (this.element) { diff --git a/docs/dist/js/ratchet.js b/docs/dist/js/ratchet.js index 85e8cfd..d865c64 100644 --- a/docs/dist/js/ratchet.js +++ b/docs/dist/js/ratchet.js @@ -103,8 +103,7 @@ try { popover = document.querySelector(anchor.hash); - } - catch (error) { + } catch (error) { popover = null; } @@ -370,7 +369,11 @@ clearTimeout(options._timeout); } if (xhr.readyState === 4) { - xhr.status === 200 ? success(xhr, options) : failure(options.url); + if (xhr.status === 200) { + success(xhr, options); + } else { + failure(options.url); + } } }; @@ -397,7 +400,7 @@ } }; - function cacheCurrentContent() { + function cacheCurrentContent () { domCache[PUSH.id] = document.body.cloneNode(true); } @@ -472,7 +475,7 @@ document.body.insertBefore(swap, document.querySelector('.content')); } } else { - enter = /in$/.test(transition); + enter = /in$/.test(transition); if (transition === 'fade') { container.classList.add('in'); @@ -490,7 +493,9 @@ } if (!transition) { - complete && complete(); + if (complete) { + complete(); + } } if (transition === 'fade') { @@ -506,7 +511,9 @@ container.parentNode.removeChild(container); swap.classList.remove('fade'); swap.classList.remove('in'); - complete && complete(); + if (complete) { + complete(); + } }; container.addEventListener('webkitTransitionEnd', fadeContainerEnd); @@ -518,7 +525,9 @@ swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove(swapDirection); container.parentNode.removeChild(container); - complete && complete(); + if (complete) { + complete(); + } }; container.offsetWidth; // force reflow @@ -623,7 +632,11 @@ window.addEventListener('touchstart', function () { isScrolling = false; }); 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; @@ -692,7 +705,12 @@ 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(); + } + }); + }()); /* ======================================================================== @@ -820,9 +838,7 @@ // we're done moving startedMoving = false; - setSlideNumber( - (+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 - ); + setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0); offsetX = slideNumber * sliderWidth; @@ -950,7 +966,9 @@ toggle.classList[slideOn ? 'add' : 'remove']('active'); e = new CustomEvent('toggle', { - detail: { isActive: slideOn }, + detail: { + isActive: slideOn + }, bubbles: true, cancelable: true }); diff --git a/js/popovers.js b/js/popovers.js index f4f4bd9..d3e8f21 100644 --- a/js/popovers.js +++ b/js/popovers.js @@ -52,8 +52,7 @@ try { popover = document.querySelector(anchor.hash); - } - catch (error) { + } catch (error) { popover = null; } @@ -231,7 +231,11 @@ clearTimeout(options._timeout); } if (xhr.readyState === 4) { - xhr.status === 200 ? success(xhr, options) : failure(options.url); + if (xhr.status === 200) { + success(xhr, options); + } else { + failure(options.url); + } } }; @@ -258,7 +262,7 @@ } }; - function cacheCurrentContent() { + function cacheCurrentContent () { domCache[PUSH.id] = document.body.cloneNode(true); } @@ -333,7 +337,7 @@ document.body.insertBefore(swap, document.querySelector('.content')); } } else { - enter = /in$/.test(transition); + enter = /in$/.test(transition); if (transition === 'fade') { container.classList.add('in'); @@ -351,7 +355,9 @@ } if (!transition) { - complete && complete(); + if (complete) { + complete(); + } } if (transition === 'fade') { @@ -367,7 +373,9 @@ container.parentNode.removeChild(container); swap.classList.remove('fade'); swap.classList.remove('in'); - complete && complete(); + if (complete) { + complete(); + } }; container.addEventListener('webkitTransitionEnd', fadeContainerEnd); @@ -379,7 +387,9 @@ swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove(swapDirection); container.parentNode.removeChild(container); - complete && complete(); + if (complete) { + complete(); + } }; container.offsetWidth; // force reflow @@ -484,7 +494,11 @@ window.addEventListener('touchstart', function () { isScrolling = false; }); 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 3c0500d..ca3b5b4 100644 --- a/js/segmented-controllers.js +++ b/js/segmented-controllers.js @@ -61,5 +61,10 @@ 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(); + } + }); + }()); diff --git a/js/sliders.js b/js/sliders.js index ebb8ea5..a42b13b 100644 --- a/js/sliders.js +++ b/js/sliders.js @@ -123,9 +123,7 @@ // we're done moving startedMoving = false; - setSlideNumber( - (+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 - ); + setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0); offsetX = slideNumber * sliderWidth; diff --git a/js/toggles.js b/js/toggles.js index ec072e4..cbd3f72 100644 --- a/js/toggles.js +++ b/js/toggles.js @@ -104,7 +104,9 @@ toggle.classList[slideOn ? 'add' : 'remove']('active'); e = new CustomEvent('toggle', { - detail: { isActive: slideOn }, + detail: { + isActive: slideOn + }, bubbles: true, cancelable: true }); |