Browse Source

Run `grunt`.

pull/379/head
XhmikosR 11 years ago
parent
commit
c094faff4c
  1. 392
      dist/js/ratchet.js
  2. 2
      dist/js/ratchet.min.js
  3. 2
      docs/assets/js/docs.min.js
  4. 392
      docs/dist/js/ratchet.js
  5. 2
      docs/dist/js/ratchet.min.js

392
dist/js/ratchet.js vendored

@ -13,27 +13,37 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var findModals = function (target) { var findModals = function (target) {
var i, modals = document.querySelectorAll('a'); var i, modals = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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 getModal = function (event) {
var modalToggle = findModals(event.target); 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) { window.addEventListener('touchend', function (event) {
var modal = getModal(event); var modal = getModal(event);
if (modal) { 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) event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
} }
}); });
}(); }());
/* ---------------------------------- /* ----------------------------------
* POPOVER v2.0.0 * POPOVER v2.0.0
@ -41,23 +51,28 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var popover; var popover;
var findPopovers = function (target) { var findPopovers = function (target) {
var i, popovers = document.querySelectorAll('a'); var i, popovers = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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 () { var onPopoverHidden = function () {
popover.style.display = 'none'; popover.style.display = 'none';
popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
} };
var backdrop = function () { var backdrop = (function () {
var element = document.createElement('div'); var element = document.createElement('div');
element.classList.add('backdrop'); element.classList.add('backdrop');
@ -69,12 +84,14 @@
}); });
return element; return element;
}(); }());
var getPopover = function (e) { var getPopover = function (e) {
var anchor = findPopovers(e.target); var anchor = findPopovers(e.target);
if (!anchor || !anchor.hash || (anchor.hash.indexOf("/") > 0)) return; if (!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) {
return;
}
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
@ -83,17 +100,23 @@
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; return popover;
} };
var showHidePopover = function (e) { var showHidePopover = function (e) {
var popover = getPopover(e); var popover = getPopover(e);
if (!popover) return; if (!popover) {
return;
}
popover.style.display = 'block'; popover.style.display = 'block';
popover.offsetHeight; popover.offsetHeight;
@ -105,7 +128,7 @@
window.addEventListener('touchend', showHidePopover); window.addEventListener('touchend', showHidePopover);
window.addEventListener('click', showHidePopover); window.addEventListener('click', showHidePopover);
}(); }());
/* ---------------------------------- /* ----------------------------------
* PUSH v2.0.0 * PUSH v2.0.0
@ -114,7 +137,10 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { /* global _gaq: true */
!(function () {
'use strict';
var noop = function () {}; var noop = function () {};
@ -141,7 +167,9 @@
var cacheReplace = function (data, updates) { var cacheReplace = function (data, updates) {
PUSH.id = data.id; PUSH.id = data.id;
if (updates) data = getCached(data.id); if (updates) {
data = getCached(data.id);
}
cacheMapping[data.id] = JSON.stringify(data); cacheMapping[data.id] = JSON.stringify(data);
window.history.replaceState(data.id, data.title, data.url); window.history.replaceState(data.id, data.title, data.url);
domCache[data.id] = document.body.cloneNode(true); domCache[data.id] = document.body.cloneNode(true);
@ -155,8 +183,12 @@
cacheBackStack.push(id); cacheBackStack.push(id);
while (cacheForwardStack.length) delete cacheMapping[cacheForwardStack.shift()]; while (cacheForwardStack.length) {
while (cacheBackStack.length > maxCacheLength) delete cacheMapping[cacheBackStack.shift()]; delete cacheMapping[cacheForwardStack.shift()];
}
while (cacheBackStack.length > maxCacheLength) {
delete cacheMapping[cacheBackStack.shift()];
}
window.history.pushState(null, '', cacheMapping[PUSH.id].url); window.history.pushState(null, '', cacheMapping[PUSH.id].url);
@ -165,13 +197,15 @@
}; };
var cachePop = function (id, direction) { var cachePop = function (id, direction) {
var forward = direction == 'forward'; var forward = direction === 'forward';
var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'); var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]');
var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]');
var pushStack = forward ? cacheBackStack : cacheForwardStack; var pushStack = forward ? cacheBackStack : cacheForwardStack;
var popStack = forward ? cacheForwardStack : cacheBackStack; var popStack = forward ? cacheForwardStack : cacheBackStack;
if (PUSH.id) pushStack.push(PUSH.id); if (PUSH.id) {
pushStack.push(PUSH.id);
}
popStack.pop(); popStack.pop();
cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack);
@ -185,18 +219,16 @@
var getTarget = function (e) { var getTarget = function (e) {
var target = findTarget(e.target); var target = findTarget(e.target);
if ( if (!target ||
! target e.which > 1 ||
|| e.which > 1 e.metaKey ||
|| e.metaKey e.ctrlKey ||
|| e.ctrlKey isScrolling ||
|| isScrolling location.protocol !== target.protocol ||
|| location.protocol !== target.protocol location.host !== target.host ||
|| location.host !== target.host !target.hash && /#/.test(target.href) ||
|| !target.hash && /#/.test(target.href) target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '') ||
|| target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '') target.getAttribute('data-ignore') === 'push') { return; }
|| target.getAttribute('data-ignore') == 'push'
) return;
return target; return target;
}; };
@ -208,7 +240,9 @@
var touchend = function (e) { var touchend = function (e) {
var target = getTarget(e); var target = getTarget(e);
if (!target) return; if (!target) {
return;
}
e.preventDefault(); e.preventDefault();
@ -231,7 +265,9 @@
var transitionFromObj; var transitionFromObj;
var id = e.state; var id = e.state;
if (!id || !cacheMapping[id]) return; if (!id || !cacheMapping[id]) {
return;
}
direction = PUSH.id < id ? 'forward' : 'back'; direction = PUSH.id < id ? 'forward' : 'back';
@ -240,18 +276,22 @@
activeObj = getCached(id); activeObj = getCached(id);
activeDom = domCache[id]; activeDom = domCache[id];
if (activeObj.title) document.title = activeObj.title; if (activeObj.title) {
document.title = activeObj.title;
}
if (direction == 'back') { if (direction === 'back') {
transitionFrom = JSON.parse(direction == 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack); transitionFrom = JSON.parse(direction === 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack);
transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]); transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]);
} else { } else {
transitionFromObj = activeObj; 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) { if (!activeDom) {
return PUSH({ return PUSH({
@ -267,9 +307,14 @@
if (transitionFromObj.transition) { if (transitionFromObj.transition) {
activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true));
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) if (bars.hasOwnProperty(key)) {
if (activeObj[key]) swapContent(activeObj[key], barElement); barElement = document.querySelector(bars[key]);
else if (barElement) barElement.parentNode.removeChild(barElement); if (activeObj[key]) {
swapContent(activeObj[key], barElement);
} else if (barElement) {
barElement.parentNode.removeChild(barElement);
}
}
} }
} }
@ -290,18 +335,19 @@
var PUSH = function (options) { var PUSH = function (options) {
var key; var key;
var data = {};
var xhr = PUSH.xhr; var xhr = PUSH.xhr;
options.container = options.container || options.transition ? document.querySelector('.content') : document.body; options.container = options.container || options.transition ? document.querySelector('.content') : document.body;
for (key in bars) { for (key in bars) {
if (bars.hasOwnProperty(key)) {
options[key] = options[key] || document.querySelector(bars[key]); options[key] = options[key] || document.querySelector(bars[key]);
} }
}
if (xhr && xhr.readyState < 4) { if (xhr && xhr.readyState < 4) {
xhr.onreadystatechange = noop; xhr.onreadystatechange = noop;
xhr.abort() xhr.abort();
} }
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
@ -309,13 +355,17 @@
xhr.setRequestHeader('X-PUSH', 'true'); xhr.setRequestHeader('X-PUSH', 'true');
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
if (options._timeout) clearTimeout(options._timeout); if (options._timeout) {
if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); clearTimeout(options._timeout);
}
if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url);
}
}; };
if (!PUSH.id) { if (!PUSH.id) {
cacheReplace({ cacheReplace({
id : +new Date, id : +new Date(),
url : window.location.href, url : window.location.href,
title : document.title, title : document.title,
timeout : options.timeout, timeout : options.timeout,
@ -329,7 +379,9 @@
xhr.send(); xhr.send();
if (xhr.readyState && !options.ignorePush) cachePush(); if (xhr.readyState && !options.ignorePush) {
cachePush();
}
}; };
@ -341,21 +393,30 @@
var barElement; var barElement;
var data = parseXHR(xhr, options); 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) { if (options.transition) {
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) if (bars.hasOwnProperty(key)) {
if (data[key]) swapContent(data[key], barElement); barElement = document.querySelector(bars[key]);
else if (barElement) barElement.parentNode.removeChild(barElement); if (data[key]) {
swapContent(data[key], barElement);
} else if (barElement) {
barElement.parentNode.removeChild(barElement);
}
}
} }
} }
swapContent(data.contents, options.container, options.transition, function () { swapContent(data.contents, options.container, options.transition, function () {
cacheReplace({ cacheReplace({
id : options.id || +new Date, id : options.id || +new Date(),
url : data.url, url : data.url,
title : data.title, title : data.title,
timeout : options.timeout, timeout : options.timeout,
@ -364,12 +425,16 @@
triggerStateChange(); triggerStateChange();
}); });
if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics if (!options.ignorePush && window._gaq) {
if (!options.hash) return; _gaq.push(['_trackPageview']); // google analytics
}
if (!options.hash) {
return;
}
}; };
var failure = function (url) { var failure = function (url) {
throw new Error('Could not get: ' + url) throw new Error('Could not get: ' + url);
}; };
@ -382,13 +447,17 @@
var swapDirection; var swapDirection;
if (!transition) { if (!transition) {
if (container) container.innerHTML = swap.innerHTML; if (container) {
else if (swap.classList.contains('content')) document.body.appendChild(swap); container.innerHTML = swap.innerHTML;
else document.body.insertBefore(swap, document.querySelector('.content')); } else if (swap.classList.contains('content')) {
document.body.appendChild(swap);
} else {
document.body.insertBefore(swap, document.querySelector('.content'));
}
} else { } else {
enter = /in$/.test(transition); enter = /in$/.test(transition);
if (transition == 'fade') { if (transition === 'fade') {
container.classList.add('in'); container.classList.add('in');
container.classList.add('fade'); container.classList.add('fade');
swap.classList.add('fade'); swap.classList.add('fade');
@ -403,42 +472,44 @@
container.parentNode.insertBefore(swap, container); container.parentNode.insertBefore(swap, container);
} }
if (!transition) complete && complete(); if (!transition) {
complete && complete();
}
if (transition == 'fade') { if (transition === 'fade') {
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
container.classList.remove('in'); container.classList.remove('in');
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); var fadeContainerEnd = function () {
function fadeContainerEnd() {
container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); container.removeEventListener('webkitTransitionEnd', fadeContainerEnd);
swap.classList.add('in'); swap.classList.add('in');
swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); swap.addEventListener('webkitTransitionEnd', fadeSwapEnd);
} };
function fadeSwapEnd () { var fadeSwapEnd = function () {
swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd);
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(); complete && complete();
} };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
} }
if (/slide/.test(transition)) { if (/slide/.test(transition)) {
container.offsetWidth; // force reflow var slideEnd = function () {
swapDirection = enter ? 'right' : 'left'
containerDirection = enter ? 'left' : 'right'
container.classList.add(containerDirection);
swap.classList.remove(swapDirection);
swap.addEventListener('webkitTransitionEnd', slideEnd);
function slideEnd() {
swap.removeEventListener('webkitTransitionEnd', slideEnd); swap.removeEventListener('webkitTransitionEnd', slideEnd);
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(); 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 findTarget = function (target) {
var i, toggles = document.querySelectorAll('a'); var i, toggles = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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); 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 extendWithDom = function (obj, fragment, dom) {
var i; 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) { Object.keys(bars).forEach(function (key) {
var el = dom.querySelector(bars[key]); var el = dom.querySelector(bars[key]);
if (el) el.parentNode.removeChild(el); if (el) {
el.parentNode.removeChild(el);
}
result[key] = el; result[key] = el;
}); });
@ -493,13 +570,15 @@
data.url = options.url; data.url = options.url;
if (!responseText) return data; if (!responseText) {
return data;
}
if (/<html/i.test(responseText)) { if (/<html/i.test(responseText)) {
head = document.createElement('div'); head = document.createElement('div');
body = document.createElement('div'); body = document.createElement('div');
head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0] head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0];
body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0] body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0];
} else { } else {
head = body = document.createElement('div'); head = body = document.createElement('div');
head.innerHTML = responseText; head.innerHTML = responseText;
@ -508,8 +587,11 @@
data.title = head.querySelector('title'); data.title = head.querySelector('title');
data.title = data.title && data.title.innerText.trim(); data.title = data.title && data.title.innerText.trim();
if (options.transition) data = extendWithDom(data, '.content', body); if (options.transition) {
else data.contents = body; data = extendWithDom(data, '.content', body);
} else {
data.contents = body;
}
return data; return data;
}; };
@ -519,13 +601,13 @@
// ========================== // ==========================
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;
}(); }());
/* ---------------------------------- /* ----------------------------------
* Segmented controls v2.0.0 * Segmented controls v2.0.0
@ -533,15 +615,21 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var getTarget = function (target) { var getTarget = function (target) {
var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item'); var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item');
for (; target && target !== document; target = target.parentNode) { 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 activeTab;
var activeBodies; var activeBodies;
var targetBody; var targetBody;
@ -549,19 +637,27 @@
var className = 'active'; var className = 'active';
var classSelector = '.' + className; var classSelector = '.' + className;
if (!targetTab) return; if (!targetTab) {
return;
}
activeTab = targetTab.parentNode.querySelector(classSelector); activeTab = targetTab.parentNode.querySelector(classSelector);
if (activeTab) activeTab.classList.remove(className); if (activeTab) {
activeTab.classList.remove(className);
}
targetTab.classList.add(className); targetTab.classList.add(className);
if (!targetTab.hash) return; if (!targetTab.hash) {
return;
}
targetBody = document.querySelector(targetTab.hash); targetBody = document.querySelector(targetTab.hash);
if (!targetBody) return; if (!targetBody) {
return;
}
activeBodies = targetBody.parentNode.querySelectorAll(classSelector); activeBodies = targetBody.parentNode.querySelectorAll(classSelector);
@ -572,8 +668,8 @@
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();} });
}(); }());
/* ---------------------------------- /* ----------------------------------
* SLIDER v2.0.0 * SLIDER v2.0.0
* Licensed under The MIT License * Licensed under The MIT License
@ -581,7 +677,8 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var pageX; var pageX;
var pageY; var pageY;
@ -600,13 +697,18 @@
var getSlider = function (target) { var getSlider = function (target) {
var i, sliders = document.querySelectorAll('.slider > .slide-group'); var i, sliders = document.querySelectorAll('.slider > .slide-group');
for (; target && target !== document; target = target.parentNode) { 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 getScroll = function () {
var translate3d = slider.style.webkitTransform.match(/translate3d\(([^,]*)/); 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) { var setSlideNumber = function (offset) {
@ -615,12 +717,14 @@
slideNumber += offset; slideNumber += offset;
slideNumber = Math.min(slideNumber, 0); slideNumber = Math.min(slideNumber, 0);
slideNumber = Math.max(-(slider.children.length - 1), slideNumber); slideNumber = Math.max(-(slider.children.length - 1), slideNumber);
} };
var onTouchStart = function (e) { var onTouchStart = function (e) {
slider = getSlider(e.target); slider = getSlider(e.target);
if (!slider) return; if (!slider) {
return;
}
var firstItem = slider.querySelector('.slide'); var firstItem = slider.querySelector('.slide');
@ -629,7 +733,7 @@
sliderWidth = slider.offsetWidth; sliderWidth = slider.offsetWidth;
resistance = 1; resistance = 1;
lastSlide = -(slider.children.length - 1); lastSlide = -(slider.children.length - 1);
startTime = +new Date; startTime = +new Date();
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
deltaX = 0; deltaX = 0;
@ -641,34 +745,40 @@
}; };
var onTouchMove = function (e) { 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; deltaX = e.touches[0].pageX - pageX;
deltaY = e.touches[0].pageY - pageY; deltaY = e.touches[0].pageY - pageY;
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
if (typeof isScrolling == 'undefined') { if (typeof isScrolling === 'undefined') {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX); isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
} }
if (isScrolling) return; if (isScrolling) {
return;
}
offsetX = (deltaX / resistance) + getScroll(); offsetX = (deltaX / resistance) + getScroll();
e.preventDefault(); e.preventDefault();
resistance = slideNumber == 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 : resistance = slideNumber === 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 :
slideNumber == lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1; slideNumber === lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1;
slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)'; slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)';
}; };
var onTouchEnd = function (e) { var onTouchEnd = function (e) {
if (!slider || isScrolling) return; if (!slider || isScrolling) {
return;
}
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;
@ -689,7 +799,7 @@
window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchmove', onTouchMove);
window.addEventListener('touchend', onTouchEnd); window.addEventListener('touchend', onTouchEnd);
}(); }());
/* ---------------------------------- /* ----------------------------------
* TOGGLE v2.0.0 * TOGGLE v2.0.0
@ -697,7 +807,8 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var start = {}; var start = {};
var touchMove = false; var touchMove = false;
@ -707,16 +818,22 @@
var findToggle = function (target) { var findToggle = function (target) {
var i, toggles = document.querySelectorAll('.toggle'); var i, toggles = document.querySelectorAll('.toggle');
for (; target && target !== document; target = target.parentNode) { 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) { window.addEventListener('touchstart', function (e) {
e = e.originalEvent || e; e = e.originalEvent || e;
toggle = findToggle(e.target); toggle = findToggle(e.target);
if (!toggle) return; if (!toggle) {
return;
}
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.clientWidth; var toggleWidth = toggle.clientWidth;
@ -730,9 +847,13 @@
window.addEventListener('touchmove', function (e) { window.addEventListener('touchmove', function (e) {
e = e.originalEvent || 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 handle = toggle.querySelector('.toggle-handle');
var current = e.touches[0]; var current = e.touches[0];
@ -743,12 +864,18 @@
touchMove = true; touchMove = true;
distanceX = current.pageX - start.pageX; 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(); e.preventDefault();
if (distanceX < 0) return handle.style.webkitTransform = 'translate3d(0,0,0)'; if (distanceX < 0) {
if (distanceX > offset) return handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,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)'; handle.style.webkitTransform = 'translate3d(' + distanceX + 'px,0,0)';
@ -756,7 +883,9 @@
}); });
window.addEventListener('touchend', function (e) { window.addEventListener('touchend', function (e) {
if (!toggle) return; if (!toggle) {
return;
}
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.clientWidth; var toggleWidth = toggle.clientWidth;
@ -764,8 +893,11 @@
var offset = (toggleWidth - handleWidth); var offset = (toggleWidth - handleWidth);
var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2)));
if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; if (slideOn) {
else handle.style.webkitTransform = 'translate3d(0,0,0)'; handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)';
} else {
handle.style.webkitTransform = 'translate3d(0,0,0)';
}
toggle.classList[slideOn ? 'add' : 'remove']('active'); toggle.classList[slideOn ? 'add' : 'remove']('active');
@ -781,4 +913,4 @@
toggle = false; toggle = false;
}); });
}(); }());

2
dist/js/ratchet.min.js vendored

File diff suppressed because one or more lines are too long

2
docs/assets/js/docs.min.js vendored

File diff suppressed because one or more lines are too long

392
docs/dist/js/ratchet.js vendored

@ -13,27 +13,37 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var findModals = function (target) { var findModals = function (target) {
var i, modals = document.querySelectorAll('a'); var i, modals = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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 getModal = function (event) {
var modalToggle = findModals(event.target); 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) { window.addEventListener('touchend', function (event) {
var modal = getModal(event); var modal = getModal(event);
if (modal) { 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) event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
} }
}); });
}(); }());
/* ---------------------------------- /* ----------------------------------
* POPOVER v2.0.0 * POPOVER v2.0.0
@ -41,23 +51,28 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var popover; var popover;
var findPopovers = function (target) { var findPopovers = function (target) {
var i, popovers = document.querySelectorAll('a'); var i, popovers = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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 () { var onPopoverHidden = function () {
popover.style.display = 'none'; popover.style.display = 'none';
popover.removeEventListener('webkitTransitionEnd', onPopoverHidden); popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
} };
var backdrop = function () { var backdrop = (function () {
var element = document.createElement('div'); var element = document.createElement('div');
element.classList.add('backdrop'); element.classList.add('backdrop');
@ -69,12 +84,14 @@
}); });
return element; return element;
}(); }());
var getPopover = function (e) { var getPopover = function (e) {
var anchor = findPopovers(e.target); var anchor = findPopovers(e.target);
if (!anchor || !anchor.hash || (anchor.hash.indexOf("/") > 0)) return; if (!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) {
return;
}
try { try {
popover = document.querySelector(anchor.hash); popover = document.querySelector(anchor.hash);
@ -83,17 +100,23 @@
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; return popover;
} };
var showHidePopover = function (e) { var showHidePopover = function (e) {
var popover = getPopover(e); var popover = getPopover(e);
if (!popover) return; if (!popover) {
return;
}
popover.style.display = 'block'; popover.style.display = 'block';
popover.offsetHeight; popover.offsetHeight;
@ -105,7 +128,7 @@
window.addEventListener('touchend', showHidePopover); window.addEventListener('touchend', showHidePopover);
window.addEventListener('click', showHidePopover); window.addEventListener('click', showHidePopover);
}(); }());
/* ---------------------------------- /* ----------------------------------
* PUSH v2.0.0 * PUSH v2.0.0
@ -114,7 +137,10 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { /* global _gaq: true */
!(function () {
'use strict';
var noop = function () {}; var noop = function () {};
@ -141,7 +167,9 @@
var cacheReplace = function (data, updates) { var cacheReplace = function (data, updates) {
PUSH.id = data.id; PUSH.id = data.id;
if (updates) data = getCached(data.id); if (updates) {
data = getCached(data.id);
}
cacheMapping[data.id] = JSON.stringify(data); cacheMapping[data.id] = JSON.stringify(data);
window.history.replaceState(data.id, data.title, data.url); window.history.replaceState(data.id, data.title, data.url);
domCache[data.id] = document.body.cloneNode(true); domCache[data.id] = document.body.cloneNode(true);
@ -155,8 +183,12 @@
cacheBackStack.push(id); cacheBackStack.push(id);
while (cacheForwardStack.length) delete cacheMapping[cacheForwardStack.shift()]; while (cacheForwardStack.length) {
while (cacheBackStack.length > maxCacheLength) delete cacheMapping[cacheBackStack.shift()]; delete cacheMapping[cacheForwardStack.shift()];
}
while (cacheBackStack.length > maxCacheLength) {
delete cacheMapping[cacheBackStack.shift()];
}
window.history.pushState(null, '', cacheMapping[PUSH.id].url); window.history.pushState(null, '', cacheMapping[PUSH.id].url);
@ -165,13 +197,15 @@
}; };
var cachePop = function (id, direction) { var cachePop = function (id, direction) {
var forward = direction == 'forward'; var forward = direction === 'forward';
var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]'); var cacheForwardStack = JSON.parse(cacheMapping.cacheForwardStack || '[]');
var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]'); var cacheBackStack = JSON.parse(cacheMapping.cacheBackStack || '[]');
var pushStack = forward ? cacheBackStack : cacheForwardStack; var pushStack = forward ? cacheBackStack : cacheForwardStack;
var popStack = forward ? cacheForwardStack : cacheBackStack; var popStack = forward ? cacheForwardStack : cacheBackStack;
if (PUSH.id) pushStack.push(PUSH.id); if (PUSH.id) {
pushStack.push(PUSH.id);
}
popStack.pop(); popStack.pop();
cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack);
@ -185,18 +219,16 @@
var getTarget = function (e) { var getTarget = function (e) {
var target = findTarget(e.target); var target = findTarget(e.target);
if ( if (!target ||
! target e.which > 1 ||
|| e.which > 1 e.metaKey ||
|| e.metaKey e.ctrlKey ||
|| e.ctrlKey isScrolling ||
|| isScrolling location.protocol !== target.protocol ||
|| location.protocol !== target.protocol location.host !== target.host ||
|| location.host !== target.host !target.hash && /#/.test(target.href) ||
|| !target.hash && /#/.test(target.href) target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '') ||
|| target.hash && target.href.replace(target.hash, '') === location.href.replace(location.hash, '') target.getAttribute('data-ignore') === 'push') { return; }
|| target.getAttribute('data-ignore') == 'push'
) return;
return target; return target;
}; };
@ -208,7 +240,9 @@
var touchend = function (e) { var touchend = function (e) {
var target = getTarget(e); var target = getTarget(e);
if (!target) return; if (!target) {
return;
}
e.preventDefault(); e.preventDefault();
@ -231,7 +265,9 @@
var transitionFromObj; var transitionFromObj;
var id = e.state; var id = e.state;
if (!id || !cacheMapping[id]) return; if (!id || !cacheMapping[id]) {
return;
}
direction = PUSH.id < id ? 'forward' : 'back'; direction = PUSH.id < id ? 'forward' : 'back';
@ -240,18 +276,22 @@
activeObj = getCached(id); activeObj = getCached(id);
activeDom = domCache[id]; activeDom = domCache[id];
if (activeObj.title) document.title = activeObj.title; if (activeObj.title) {
document.title = activeObj.title;
}
if (direction == 'back') { if (direction === 'back') {
transitionFrom = JSON.parse(direction == 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack); transitionFrom = JSON.parse(direction === 'back' ? cacheMapping.cacheForwardStack : cacheMapping.cacheBackStack);
transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]); transitionFromObj = getCached(transitionFrom[transitionFrom.length - 1]);
} else { } else {
transitionFromObj = activeObj; 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) { if (!activeDom) {
return PUSH({ return PUSH({
@ -267,9 +307,14 @@
if (transitionFromObj.transition) { if (transitionFromObj.transition) {
activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true)); activeObj = extendWithDom(activeObj, '.content', activeDom.cloneNode(true));
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) if (bars.hasOwnProperty(key)) {
if (activeObj[key]) swapContent(activeObj[key], barElement); barElement = document.querySelector(bars[key]);
else if (barElement) barElement.parentNode.removeChild(barElement); if (activeObj[key]) {
swapContent(activeObj[key], barElement);
} else if (barElement) {
barElement.parentNode.removeChild(barElement);
}
}
} }
} }
@ -290,18 +335,19 @@
var PUSH = function (options) { var PUSH = function (options) {
var key; var key;
var data = {};
var xhr = PUSH.xhr; var xhr = PUSH.xhr;
options.container = options.container || options.transition ? document.querySelector('.content') : document.body; options.container = options.container || options.transition ? document.querySelector('.content') : document.body;
for (key in bars) { for (key in bars) {
if (bars.hasOwnProperty(key)) {
options[key] = options[key] || document.querySelector(bars[key]); options[key] = options[key] || document.querySelector(bars[key]);
} }
}
if (xhr && xhr.readyState < 4) { if (xhr && xhr.readyState < 4) {
xhr.onreadystatechange = noop; xhr.onreadystatechange = noop;
xhr.abort() xhr.abort();
} }
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
@ -309,13 +355,17 @@
xhr.setRequestHeader('X-PUSH', 'true'); xhr.setRequestHeader('X-PUSH', 'true');
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
if (options._timeout) clearTimeout(options._timeout); if (options._timeout) {
if (xhr.readyState == 4) xhr.status == 200 ? success(xhr, options) : failure(options.url); clearTimeout(options._timeout);
}
if (xhr.readyState === 4) {
xhr.status === 200 ? success(xhr, options) : failure(options.url);
}
}; };
if (!PUSH.id) { if (!PUSH.id) {
cacheReplace({ cacheReplace({
id : +new Date, id : +new Date(),
url : window.location.href, url : window.location.href,
title : document.title, title : document.title,
timeout : options.timeout, timeout : options.timeout,
@ -329,7 +379,9 @@
xhr.send(); xhr.send();
if (xhr.readyState && !options.ignorePush) cachePush(); if (xhr.readyState && !options.ignorePush) {
cachePush();
}
}; };
@ -341,21 +393,30 @@
var barElement; var barElement;
var data = parseXHR(xhr, options); 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) { if (options.transition) {
for (key in bars) { for (key in bars) {
barElement = document.querySelector(bars[key]) if (bars.hasOwnProperty(key)) {
if (data[key]) swapContent(data[key], barElement); barElement = document.querySelector(bars[key]);
else if (barElement) barElement.parentNode.removeChild(barElement); if (data[key]) {
swapContent(data[key], barElement);
} else if (barElement) {
barElement.parentNode.removeChild(barElement);
}
}
} }
} }
swapContent(data.contents, options.container, options.transition, function () { swapContent(data.contents, options.container, options.transition, function () {
cacheReplace({ cacheReplace({
id : options.id || +new Date, id : options.id || +new Date(),
url : data.url, url : data.url,
title : data.title, title : data.title,
timeout : options.timeout, timeout : options.timeout,
@ -364,12 +425,16 @@
triggerStateChange(); triggerStateChange();
}); });
if (!options.ignorePush && window._gaq) _gaq.push(['_trackPageview']) // google analytics if (!options.ignorePush && window._gaq) {
if (!options.hash) return; _gaq.push(['_trackPageview']); // google analytics
}
if (!options.hash) {
return;
}
}; };
var failure = function (url) { var failure = function (url) {
throw new Error('Could not get: ' + url) throw new Error('Could not get: ' + url);
}; };
@ -382,13 +447,17 @@
var swapDirection; var swapDirection;
if (!transition) { if (!transition) {
if (container) container.innerHTML = swap.innerHTML; if (container) {
else if (swap.classList.contains('content')) document.body.appendChild(swap); container.innerHTML = swap.innerHTML;
else document.body.insertBefore(swap, document.querySelector('.content')); } else if (swap.classList.contains('content')) {
document.body.appendChild(swap);
} else {
document.body.insertBefore(swap, document.querySelector('.content'));
}
} else { } else {
enter = /in$/.test(transition); enter = /in$/.test(transition);
if (transition == 'fade') { if (transition === 'fade') {
container.classList.add('in'); container.classList.add('in');
container.classList.add('fade'); container.classList.add('fade');
swap.classList.add('fade'); swap.classList.add('fade');
@ -403,42 +472,44 @@
container.parentNode.insertBefore(swap, container); container.parentNode.insertBefore(swap, container);
} }
if (!transition) complete && complete(); if (!transition) {
complete && complete();
}
if (transition == 'fade') { if (transition === 'fade') {
container.offsetWidth; // force reflow container.offsetWidth; // force reflow
container.classList.remove('in'); container.classList.remove('in');
container.addEventListener('webkitTransitionEnd', fadeContainerEnd); var fadeContainerEnd = function () {
function fadeContainerEnd() {
container.removeEventListener('webkitTransitionEnd', fadeContainerEnd); container.removeEventListener('webkitTransitionEnd', fadeContainerEnd);
swap.classList.add('in'); swap.classList.add('in');
swap.addEventListener('webkitTransitionEnd', fadeSwapEnd); swap.addEventListener('webkitTransitionEnd', fadeSwapEnd);
} };
function fadeSwapEnd () { var fadeSwapEnd = function () {
swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd); swap.removeEventListener('webkitTransitionEnd', fadeSwapEnd);
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(); complete && complete();
} };
container.addEventListener('webkitTransitionEnd', fadeContainerEnd);
} }
if (/slide/.test(transition)) { if (/slide/.test(transition)) {
container.offsetWidth; // force reflow var slideEnd = function () {
swapDirection = enter ? 'right' : 'left'
containerDirection = enter ? 'left' : 'right'
container.classList.add(containerDirection);
swap.classList.remove(swapDirection);
swap.addEventListener('webkitTransitionEnd', slideEnd);
function slideEnd() {
swap.removeEventListener('webkitTransitionEnd', slideEnd); swap.removeEventListener('webkitTransitionEnd', slideEnd);
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(); 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 findTarget = function (target) {
var i, toggles = document.querySelectorAll('a'); var i, toggles = document.querySelectorAll('a');
for (; target && target !== document; target = target.parentNode) { 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); 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 extendWithDom = function (obj, fragment, dom) {
var i; 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) { Object.keys(bars).forEach(function (key) {
var el = dom.querySelector(bars[key]); var el = dom.querySelector(bars[key]);
if (el) el.parentNode.removeChild(el); if (el) {
el.parentNode.removeChild(el);
}
result[key] = el; result[key] = el;
}); });
@ -493,13 +570,15 @@
data.url = options.url; data.url = options.url;
if (!responseText) return data; if (!responseText) {
return data;
}
if (/<html/i.test(responseText)) { if (/<html/i.test(responseText)) {
head = document.createElement('div'); head = document.createElement('div');
body = document.createElement('div'); body = document.createElement('div');
head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0] head.innerHTML = responseText.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0];
body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0] body.innerHTML = responseText.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0];
} else { } else {
head = body = document.createElement('div'); head = body = document.createElement('div');
head.innerHTML = responseText; head.innerHTML = responseText;
@ -508,8 +587,11 @@
data.title = head.querySelector('title'); data.title = head.querySelector('title');
data.title = data.title && data.title.innerText.trim(); data.title = data.title && data.title.innerText.trim();
if (options.transition) data = extendWithDom(data, '.content', body); if (options.transition) {
else data.contents = body; data = extendWithDom(data, '.content', body);
} else {
data.contents = body;
}
return data; return data;
}; };
@ -519,13 +601,13 @@
// ========================== // ==========================
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;
}(); }());
/* ---------------------------------- /* ----------------------------------
* Segmented controls v2.0.0 * Segmented controls v2.0.0
@ -533,15 +615,21 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var getTarget = function (target) { var getTarget = function (target) {
var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item'); var i, segmentedControls = document.querySelectorAll('.segmented-control .control-item');
for (; target && target !== document; target = target.parentNode) { 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 activeTab;
var activeBodies; var activeBodies;
var targetBody; var targetBody;
@ -549,19 +637,27 @@
var className = 'active'; var className = 'active';
var classSelector = '.' + className; var classSelector = '.' + className;
if (!targetTab) return; if (!targetTab) {
return;
}
activeTab = targetTab.parentNode.querySelector(classSelector); activeTab = targetTab.parentNode.querySelector(classSelector);
if (activeTab) activeTab.classList.remove(className); if (activeTab) {
activeTab.classList.remove(className);
}
targetTab.classList.add(className); targetTab.classList.add(className);
if (!targetTab.hash) return; if (!targetTab.hash) {
return;
}
targetBody = document.querySelector(targetTab.hash); targetBody = document.querySelector(targetTab.hash);
if (!targetBody) return; if (!targetBody) {
return;
}
activeBodies = targetBody.parentNode.querySelectorAll(classSelector); activeBodies = targetBody.parentNode.querySelectorAll(classSelector);
@ -572,8 +668,8 @@
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();} });
}(); }());
/* ---------------------------------- /* ----------------------------------
* SLIDER v2.0.0 * SLIDER v2.0.0
* Licensed under The MIT License * Licensed under The MIT License
@ -581,7 +677,8 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var pageX; var pageX;
var pageY; var pageY;
@ -600,13 +697,18 @@
var getSlider = function (target) { var getSlider = function (target) {
var i, sliders = document.querySelectorAll('.slider > .slide-group'); var i, sliders = document.querySelectorAll('.slider > .slide-group');
for (; target && target !== document; target = target.parentNode) { 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 getScroll = function () {
var translate3d = slider.style.webkitTransform.match(/translate3d\(([^,]*)/); 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) { var setSlideNumber = function (offset) {
@ -615,12 +717,14 @@
slideNumber += offset; slideNumber += offset;
slideNumber = Math.min(slideNumber, 0); slideNumber = Math.min(slideNumber, 0);
slideNumber = Math.max(-(slider.children.length - 1), slideNumber); slideNumber = Math.max(-(slider.children.length - 1), slideNumber);
} };
var onTouchStart = function (e) { var onTouchStart = function (e) {
slider = getSlider(e.target); slider = getSlider(e.target);
if (!slider) return; if (!slider) {
return;
}
var firstItem = slider.querySelector('.slide'); var firstItem = slider.querySelector('.slide');
@ -629,7 +733,7 @@
sliderWidth = slider.offsetWidth; sliderWidth = slider.offsetWidth;
resistance = 1; resistance = 1;
lastSlide = -(slider.children.length - 1); lastSlide = -(slider.children.length - 1);
startTime = +new Date; startTime = +new Date();
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
deltaX = 0; deltaX = 0;
@ -641,34 +745,40 @@
}; };
var onTouchMove = function (e) { 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; deltaX = e.touches[0].pageX - pageX;
deltaY = e.touches[0].pageY - pageY; deltaY = e.touches[0].pageY - pageY;
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
if (typeof isScrolling == 'undefined') { if (typeof isScrolling === 'undefined') {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX); isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
} }
if (isScrolling) return; if (isScrolling) {
return;
}
offsetX = (deltaX / resistance) + getScroll(); offsetX = (deltaX / resistance) + getScroll();
e.preventDefault(); e.preventDefault();
resistance = slideNumber == 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 : resistance = slideNumber === 0 && deltaX > 0 ? (pageX / sliderWidth) + 1.25 :
slideNumber == lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1; slideNumber === lastSlide && deltaX < 0 ? (Math.abs(pageX) / sliderWidth) + 1.25 : 1;
slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)'; slider.style.webkitTransform = 'translate3d(' + offsetX + 'px,0,0)';
}; };
var onTouchEnd = function (e) { var onTouchEnd = function (e) {
if (!slider || isScrolling) return; if (!slider || isScrolling) {
return;
}
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;
@ -689,7 +799,7 @@
window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchmove', onTouchMove);
window.addEventListener('touchend', onTouchEnd); window.addEventListener('touchend', onTouchEnd);
}(); }());
/* ---------------------------------- /* ----------------------------------
* TOGGLE v2.0.0 * TOGGLE v2.0.0
@ -697,7 +807,8 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
* ---------------------------------- */ * ---------------------------------- */
!function () { !(function () {
'use strict';
var start = {}; var start = {};
var touchMove = false; var touchMove = false;
@ -707,16 +818,22 @@
var findToggle = function (target) { var findToggle = function (target) {
var i, toggles = document.querySelectorAll('.toggle'); var i, toggles = document.querySelectorAll('.toggle');
for (; target && target !== document; target = target.parentNode) { 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) { window.addEventListener('touchstart', function (e) {
e = e.originalEvent || e; e = e.originalEvent || e;
toggle = findToggle(e.target); toggle = findToggle(e.target);
if (!toggle) return; if (!toggle) {
return;
}
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.clientWidth; var toggleWidth = toggle.clientWidth;
@ -730,9 +847,13 @@
window.addEventListener('touchmove', function (e) { window.addEventListener('touchmove', function (e) {
e = e.originalEvent || 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 handle = toggle.querySelector('.toggle-handle');
var current = e.touches[0]; var current = e.touches[0];
@ -743,12 +864,18 @@
touchMove = true; touchMove = true;
distanceX = current.pageX - start.pageX; 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(); e.preventDefault();
if (distanceX < 0) return handle.style.webkitTransform = 'translate3d(0,0,0)'; if (distanceX < 0) {
if (distanceX > offset) return handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,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)'; handle.style.webkitTransform = 'translate3d(' + distanceX + 'px,0,0)';
@ -756,7 +883,9 @@
}); });
window.addEventListener('touchend', function (e) { window.addEventListener('touchend', function (e) {
if (!toggle) return; if (!toggle) {
return;
}
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.clientWidth; var toggleWidth = toggle.clientWidth;
@ -764,8 +893,11 @@
var offset = (toggleWidth - handleWidth); var offset = (toggleWidth - handleWidth);
var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2)));
if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; if (slideOn) {
else handle.style.webkitTransform = 'translate3d(0,0,0)'; handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)';
} else {
handle.style.webkitTransform = 'translate3d(0,0,0)';
}
toggle.classList[slideOn ? 'add' : 'remove']('active'); toggle.classList[slideOn ? 'add' : 'remove']('active');
@ -781,4 +913,4 @@
toggle = false; toggle = false;
}); });
}(); }());

2
docs/dist/js/ratchet.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save