Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Copyright 2011 Joe Hewitt
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
Expand Down
52 changes: 26 additions & 26 deletions scrollability.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports.flashIndicators = function() {
// var scrollables = document.querySelectorAll('.scrollable.vertical');
// for (var i = 0; i < scrollables.length; ++i) {
// exports.scrollTo(scrollables[i], 0, 0, 20, true);
// }
// }
}

function onLoad() {
Expand Down Expand Up @@ -119,7 +119,7 @@ function onTouchStart(event) {
document.addEventListener(isTouch ? 'touchend' : 'mouseup', onTouchEnd, false);

// if (D) event.preventDefault();

function onTouchMove(event) {
event.preventDefault();
touchMoved = true;
Expand Down Expand Up @@ -162,15 +162,15 @@ function onTouchStart(event) {
function onTouchEnd(event) {
// Simulate a click event when releasing the finger
if (touched) {
var evt = document.createEvent('MouseEvents');
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1);
touched[0].dispatchEvent(evt);
touched[0].dispatchEvent(evt);
releaseTouched(touched);
}

document.removeEventListener(isTouch ? 'touchmove' : 'mousemove', onTouchMove, false);
document.removeEventListener(isTouch ? 'touchend' : 'mouseup', onTouchEnd, false);

touchAnimators.forEach(function(animator) {
animator.takeoff();
});
Expand Down Expand Up @@ -228,7 +228,7 @@ function wrapAnimator(animator, startX, startY, startTime) {
if (scrollbar) {
addTracker(scrollbar, trackScrollbar);
if (!scrollbar.parentNode) {
node.parentNode.appendChild(scrollbar);
node.parentNode.appendChild(scrollbar);
}
}

Expand All @@ -242,13 +242,13 @@ function wrapAnimator(animator, startX, startY, startTime) {

update(position);
}

animator.reposition = update;
animator.track = track;
animator.takeoff = takeoff;
animator.terminate = terminate;
return animator;

function addTracker(node, callback) {
tracked.push({node: node, callback: callback, keyframes: []});
}
Expand All @@ -274,7 +274,7 @@ function wrapAnimator(animator, startX, startY, startTime) {

velocity = touch - lastTouch;
lastTouch = touch;

if (Math.abs(velocity) >= kStoppedThreshold) {
if (stopped) {
--stopped;
Expand Down Expand Up @@ -360,7 +360,7 @@ function wrapAnimator(animator, startX, startY, startTime) {

if (node.cleanup) {
node.cleanup();
}
}

globalStyleSheet.insertRule(timeline.css, 0);

Expand All @@ -387,7 +387,7 @@ function wrapAnimator(animator, startX, startY, startTime) {
}

node.addEventListener("webkitAnimationEnd", node.normalEnd, false);

play(node, timeline.name, timeline.time);

tracked.forEach(function(item) {
Expand Down Expand Up @@ -485,7 +485,7 @@ function wrapAnimator(animator, startX, startY, startTime) {
position += velocity;
}

saveKeyframe(!continues);
saveKeyframe(!continues);
time += kAnimationStep;
}

Expand Down Expand Up @@ -554,19 +554,19 @@ function wrapAnimator(animator, startX, startY, startTime) {
fadeIn(scrollbar);
} else {
scrollbar.style.opacity = '0';
scrollbar.style.webkitTransition = 'opacity 0.33s linear';
scrollbar.style.webkitTransition = 'opacity 0.33s linear';
}
}

node.removeEventListener("webkitAnimationEnd", node.normalEnd, false);
node.removeEventListener("webkitAnimationEnd", node.normalEnd, false);

delete node.earlyEnd;
delete node.normalEnd;

if (!animator.mute) {
dispatch("scrollability-end", node);
}

}

function terminate() {
Expand All @@ -578,7 +578,7 @@ function wrapAnimator(animator, startX, startY, startTime) {

function getTouchAnimators(node, touchX, touchY, startTime) {
var animators = [];

// Get universally scrollable elements
var candidates = document.querySelectorAll('.scrollable.universal');
for (var j = 0; j < candidates.length; ++j) {
Expand Down Expand Up @@ -609,7 +609,7 @@ function findAnimators(element, animators, touchX, touchY, startTime) {
if (!exists) {
animator = wrapAnimator(animator, touchX, touchY, startTime);
if (animator) {
animators.push(animator);
animators.push(animator);
}
}
}
Expand All @@ -622,7 +622,7 @@ function createAnimatorForElement(element, touchX, touchY, startTime) {
var classes = element.className.split(' ');
if (classes.indexOf("scrollable") == -1)
return;

for (var i = 0; i < classes.length; ++i) {
var name = classes[i];
if (directions[name]) {
Expand All @@ -648,7 +648,7 @@ function generateCSSKeyframes(animator, keyframes, name, time, offset) {

lines.push('}');

return lines.join('\n');
return lines.join('\n');
}

function setTouched(target) {
Expand Down Expand Up @@ -702,9 +702,9 @@ function createXDirection(node) {
viewport: parent.offsetWidth,
bounce: parent.offsetWidth * kBounceLimit,
constrained: true,

filter: function(x, y) {
return x;
return x;
},

disable: function (x, y, startX, startY) {
Expand Down Expand Up @@ -743,23 +743,23 @@ function createYDirection(node) {
viewport: parent.offsetHeight,
bounce: parent.offsetHeight * kBounceLimit,
constrained: true,

filter: function(x, y) {
return y;
},

disable: function(x, y, startX, startY) {
var dx = Math.abs(x - startX);
var dy = Math.abs(y - startY);
if (dx > dy && dx > kLockThreshold) {
return true;
}
},

update: function(position) {
return 'translate3d(0, ' + Math.round(position) + 'px, 0)';
}
};
};
}

function play(node, name, time) {
Expand Down
30 changes: 15 additions & 15 deletions static/examples/pages.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<title>Scrollability</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<style type="text/css">
<!doctype html>

<html lang="en">
<head>
<title>Scrollability</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<style type="text/css">

html, body {
padding: 0;
margin: 0;
background: #000;
}

.scrollable {
display: inline-block;
max-width: 1000px;
Expand All @@ -40,8 +40,8 @@
background-size: cover;
}

</style>
</style>

<script type="text/javascript" src="/scrollability.min.js"></script>

<script language="javascript">
Expand Down Expand Up @@ -88,6 +88,6 @@
//window.onclick = function() { location.reload(true) }

</script>
</head>
</head>
<body><div class="scrollable horizontal paginated universal"><div class="gallery clipper"></div></div></body>
</html>
8 changes: 4 additions & 4 deletions static/examples/tableview.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title>Scrollability</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<style type="text/css">

html {
Expand All @@ -26,7 +26,7 @@
/* overflow: scroll;
-webkit-overflow-scrolling: touch;*/
}

.item {
position: relative;
top: -1px;
Expand Down Expand Up @@ -161,7 +161,7 @@
}, false);

</script>

</head>
<body>
<div class="bar top" onclick="location.reload(true)">Scrollability Demo</div>
Expand Down
2 changes: 1 addition & 1 deletion static/scrollbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
right: 2px;
width: 7px;
height: 1px;
z-index: 2147483647;
z-index: 2147483647;
opacity: 0;
-webkit-transform: translate3d(0,0,0);
-webkit-box-sizing: border-box;
Expand Down