Browse Source

Merge pull request #521 from twbs/js-2

JS tweaks
pull/743/head
XhmikosR 10 years ago
parent
commit
004d2d45b5
  1. 42
      dist/js/ratchet.js
  2. 4
      docs/assets/js/docs.js
  3. 42
      docs/dist/js/ratchet.js
  4. 3
      js/popovers.js
  5. 24
      js/push.js
  6. 7
      js/segmented-controllers.js
  7. 4
      js/sliders.js
  8. 4
      js/toggles.js

42
dist/js/ratchet.js vendored

@ -103,8 +103,7 @@
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
} } catch (error) {
catch (error) {
popover = null; popover = null;
} }
@ -370,7 +369,11 @@
clearTimeout(options._timeout); clearTimeout(options._timeout);
} }
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url); if (xhr.status === 200) {
success(xhr, options);
} else {
failure(options.url);
}
} }
}; };
@ -490,7 +493,9 @@
} }
if (!transition) { if (!transition) {
complete && complete(); if (complete) {
complete();
}
} }
if (transition === 'fade') { if (transition === 'fade') {
@ -506,7 +511,9 @@
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
swap.classList.remove('fade'); swap.classList.remove('fade');
swap.classList.remove('in'); swap.classList.remove('in');
complete && complete(); if (complete) {
complete();
}
}; };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
@ -518,7 +525,9 @@
swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove('sliding', 'sliding-in');
swap.classList.remove(swapDirection); swap.classList.remove(swapDirection);
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
complete && complete(); if (complete) {
complete();
}
}; };
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
@ -623,7 +632,11 @@
window.addEventListener('touchstart', function () { isScrolling = false; }); window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }); window.addEventListener('touchmove', function () { isScrolling = true; });
window.addEventListener('touchend', touchend); window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('click', function (e) {
if (getTarget(e)) {
e.preventDefault();
}
});
window.addEventListener('popstate', popstate); window.addEventListener('popstate', popstate);
window.PUSH = PUSH; window.PUSH = PUSH;
@ -692,7 +705,12 @@
targetBody.classList.add(className); 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 // we're done moving
startedMoving = false; startedMoving = false;
setSlideNumber( setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0);
(+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
);
offsetX = slideNumber * sliderWidth; offsetX = slideNumber * sliderWidth;
@ -950,7 +966,9 @@
toggle.classList[slideOn ? 'add' : 'remove']('active'); toggle.classList[slideOn ? 'add' : 'remove']('active');
e = new CustomEvent('toggle', { e = new CustomEvent('toggle', {
detail: { isActive: slideOn }, detail: {
isActive: slideOn
},
bubbles: true, bubbles: true,
cancelable: true cancelable: true
}); });

4
docs/assets/js/docs.js

@ -185,6 +185,8 @@ $(function () {
$(window).on('load resize', initialize); $(window).on('load resize', initialize);
$(window).on('load', function () { $(window).on('load', function () {
window.FingerBlast && (new FingerBlast('.device-content')); if (window.FingerBlast) {
new FingerBlast('.device-content');
}
}); });
}); });

42
docs/dist/js/ratchet.js vendored

@ -103,8 +103,7 @@
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
} } catch (error) {
catch (error) {
popover = null; popover = null;
} }
@ -370,7 +369,11 @@
clearTimeout(options._timeout); clearTimeout(options._timeout);
} }
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url); if (xhr.status === 200) {
success(xhr, options);
} else {
failure(options.url);
}
} }
}; };
@ -490,7 +493,9 @@
} }
if (!transition) { if (!transition) {
complete && complete(); if (complete) {
complete();
}
} }
if (transition === 'fade') { if (transition === 'fade') {
@ -506,7 +511,9 @@
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
swap.classList.remove('fade'); swap.classList.remove('fade');
swap.classList.remove('in'); swap.classList.remove('in');
complete && complete(); if (complete) {
complete();
}
}; };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
@ -518,7 +525,9 @@
swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove('sliding', 'sliding-in');
swap.classList.remove(swapDirection); swap.classList.remove(swapDirection);
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
complete && complete(); if (complete) {
complete();
}
}; };
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
@ -623,7 +632,11 @@
window.addEventListener('touchstart', function () { isScrolling = false; }); window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }); window.addEventListener('touchmove', function () { isScrolling = true; });
window.addEventListener('touchend', touchend); window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('click', function (e) {
if (getTarget(e)) {
e.preventDefault();
}
});
window.addEventListener('popstate', popstate); window.addEventListener('popstate', popstate);
window.PUSH = PUSH; window.PUSH = PUSH;
@ -692,7 +705,12 @@
targetBody.classList.add(className); 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 // we're done moving
startedMoving = false; startedMoving = false;
setSlideNumber( setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0);
(+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
);
offsetX = slideNumber * sliderWidth; offsetX = slideNumber * sliderWidth;
@ -950,7 +966,9 @@
toggle.classList[slideOn ? 'add' : 'remove']('active'); toggle.classList[slideOn ? 'add' : 'remove']('active');
e = new CustomEvent('toggle', { e = new CustomEvent('toggle', {
detail: { isActive: slideOn }, detail: {
isActive: slideOn
},
bubbles: true, bubbles: true,
cancelable: true cancelable: true
}); });

3
js/popovers.js

@ -52,8 +52,7 @@
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
} } catch (error) {
catch (error) {
popover = null; popover = null;
} }

24
js/push.js

@ -231,7 +231,11 @@
clearTimeout(options._timeout); clearTimeout(options._timeout);
} }
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url); if (xhr.status === 200) {
success(xhr, options);
} else {
failure(options.url);
}
} }
}; };
@ -351,7 +355,9 @@
} }
if (!transition) { if (!transition) {
complete && complete(); if (complete) {
complete();
}
} }
if (transition === 'fade') { if (transition === 'fade') {
@ -367,7 +373,9 @@
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
swap.classList.remove('fade'); swap.classList.remove('fade');
swap.classList.remove('in'); swap.classList.remove('in');
complete && complete(); if (complete) {
complete();
}
}; };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
@ -379,7 +387,9 @@
swap.classList.remove('sliding', 'sliding-in'); swap.classList.remove('sliding', 'sliding-in');
swap.classList.remove(swapDirection); swap.classList.remove(swapDirection);
container.parentNode.removeChild(container); container.parentNode.removeChild(container);
complete && complete(); if (complete) {
complete();
}
}; };
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
@ -484,7 +494,11 @@
window.addEventListener('touchstart', function () { isScrolling = false; }); window.addEventListener('touchstart', function () { isScrolling = false; });
window.addEventListener('touchmove', function () { isScrolling = true; }); window.addEventListener('touchmove', function () { isScrolling = true; });
window.addEventListener('touchend', touchend); window.addEventListener('touchend', touchend);
window.addEventListener('click', function (e) { if (getTarget(e)) {e.preventDefault();} }); window.addEventListener('click', function (e) {
if (getTarget(e)) {
e.preventDefault();
}
});
window.addEventListener('popstate', popstate); window.addEventListener('popstate', popstate);
window.PUSH = PUSH; window.PUSH = PUSH;

7
js/segmented-controllers.js

@ -61,5 +61,10 @@
targetBody.classList.add(className); 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();
}
});
}()); }());

4
js/sliders.js

@ -123,9 +123,7 @@
// we're done moving // we're done moving
startedMoving = false; startedMoving = false;
setSlideNumber( setSlideNumber((+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0);
(+new Date()) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
);
offsetX = slideNumber * sliderWidth; offsetX = slideNumber * sliderWidth;

4
js/toggles.js

@ -104,7 +104,9 @@
toggle.classList[slideOn ? 'add' : 'remove']('active'); toggle.classList[slideOn ? 'add' : 'remove']('active');
e = new CustomEvent('toggle', { e = new CustomEvent('toggle', {
detail: { isActive: slideOn }, detail: {
isActive: slideOn
},
bubbles: true, bubbles: true,
cancelable: true cancelable: true
}); });

Loading…
Cancel
Save