Commit 19fa9c0c by Arthur Schreiber

New test files for the javascript diff driver.

parent 324154a4
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
which happens to be a trending Javascript repo with an MIT license at
the time I was working on Javascript userdiff support in libgit2
I extracted just some of the code, so I suspect this is no longer valid var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction");
*/
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'],
sample = window['otherProperty'];
return (client < inner) ? inner : client; this.pixelX = 10;
} this.pixelY = 10;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop + 1;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
} }
function isElementInViewport (el, h) { Player.prototype.update = function() {
var scrolled = window.pageYOffset, if (!this.isWalking()) {
viewed = scrolled + getViewportH(), this.handleInput();
elTop = getOffset(el).top, }
elBottom = elTop + el.offsetHeight,
h = h || 0;
return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
}
scrollReveal.prototype = {
_init: function () {
var self = this;
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
this.scrolled = false;
this.elems.forEach(function (el, i) { if (this.isWalking()) {
self.animate(el); // Increase the animation step.
}); this.animationStep = ++this.animationStep % 60;
var scrollHandler = function () { if (this.x * 32 > this.pixelX) {
if (!self.scrolled) { this.pixelX++;
self.scrolled = true; } else if (this.x * 32 < this.pixelX) {
setTimeout(function () { this.pixelX--;
self._scrollPage(); }
}, 61);
}
};
var resizeHandler = function () { if (this.y * 32 > this.pixelY) {
function delayed() { this.pixelY++;
self._scrollPage(); } else if (this.y * 32 < this.pixelY) {
self.resizeTimeout = null; this.pixelY--;
} }
if (self.resizeTimeout) { } else {
clearTimeout(self.resizeTimeout); // Reset the animation step.
this.animationStep = 0;
}
};
Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
for (action in inputs) {
if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
} }
self.resizeTimeout = setTimeout(delayed, 200); }
}; }
window.addEventListener('scroll', scrollHandler, false);
window.addEventListener('resize', resizeHandler, false);
},
/*=============================================================================*/
_scrollPage: function () {
var self = this;
this.elems.forEach(function (el, i) {
if (isElementInViewport(el, self.options.viewportFactor)) {
self.animate(el);
}
});
this.scrolled = false;
this.tested = true;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { this[finalAction] && this[finalAction]();
window.scrollReveal = new scrollReveal(); };
});
Player.prototype.isWalking = function() {
return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
};
Player.prototype.moveDown = function() {
this.y += 1;
this.direction = Direction.DOWN;
};
Player.prototype.moveUp = function() {
this.y -= 1;
this.direction = Direction.UP;
};
Player.prototype.moveLeft = function() {
this.x -= 5;
this.direction = Direction.LEFT;
};
Player.prototype.moveRight = function() {
this.x += 1;
this.direction = Direction.RIGHT;
};
Player.prototype.draw = function(context) {
var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
}
})(window); context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
};
});
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
which happens to be a trending Javascript repo with an MIT license at
the time I was working on Javascript userdiff support in libgit2
I extracted just some of the code, so I suspect this is no longer valid var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction")
*/ , Image = require("./image");
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'];
return (client < inner) ? inner : client; this.pixelX = 0;
} this.pixelY = 0;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
} }
function isElementInViewport (el, h) { Player.prototype.update = function() {
var scrolled = window.pageYOffset, if (!this.isWalking()) {
viewed = scrolled + getViewportH(), this.handleInput();
elH = el.offsetHeight, }
elTop = getOffset(el).top,
elBottom = elTop + elH,
h = h || 0;
return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
}
scrollReveal.prototype = {
_init: function () {
var self = this;
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
this.scrolled = false;
// Initialize all scrollreveals, triggering all if (this.isWalking()) {
// reveals on visible elements. // Increase the animation step.
this.elems.forEach(function (el, i) { this.animationStep = ++this.animationStep % 60;
self.animate(el);
});
var scrollHandler = function () { if (this.x * 32 > this.pixelX) {
if (!self.scrolled) { this.pixelX++;
self.scrolled = true; } else if (this.x * 32 < this.pixelX) {
setTimeout(function () { this.pixelX--;
self._scrollPage(); }
}, 60);
}
};
var resizeHandler = function () { if (this.y * 32 > this.pixelY) {
function delayed() { this.pixelY++;
self._scrollPage(); } else if (this.y * 32 < this.pixelY) {
self.resizeTimeout = null; this.pixelY--;
} }
if (self.resizeTimeout) { } else {
clearTimeout(self.resizeTimeout); // Reset the animation step.
this.animationStep = 0;
}
};
Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
for (action in inputs) {
if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
} }
self.resizeTimeout = setTimeout(delayed, 200); }
}; }
window.addEventListener('scroll', scrollHandler, false);
window.addEventListener('resize', resizeHandler, false);
},
/*=============================================================================*/
_scrollPage: function () {
var self = this;
this.elems.forEach(function (el, i) {
if (isElementInViewport(el, self.options.viewportFactor)) {
self.animate(el);
}
});
this.scrolled = false;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { this[finalAction] && this[finalAction]();
window.scrollReveal = new scrollReveal(); };
});
Player.prototype.isWalking = function() {
return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
};
Player.prototype.moveDown = function() {
this.y += 1;
this.direction = Direction.DOWN;
};
Player.prototype.moveUp = function() {
this.y -= 1;
this.direction = Direction.UP;
};
Player.prototype.moveLeft = function() {
this.x -= 1;
this.direction = Direction.LEFT;
};
Player.prototype.moveRight = function() {
this.x += 1;
this.direction = Direction.RIGHT;
};
Player.prototype.draw = function(context) {
var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
}
})(window); context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
};
});
diff --git a/files/file.javascript b/files/file.javascript diff --git a/files/file.javascript b/files/file.javascript
index b9f1286..7cd3c5a 100644 index 0965b37..5391797 100644
--- a/files/file.javascript --- a/files/file.javascript
+++ b/files/file.javascript +++ b/files/file.javascript
@@ -16,3 +16,4 @@ function getViewportH () @@ -4,4 +4,3 @@
var client = docElem['clientHeight'], var Key = require("./key")
- inner = window['innerHeight']; - , Direction = require("./direction")
+ inner = window['innerHeight'], - , Image = require("./image");
+ sample = window['otherProperty']; + , Direction = require("./direction");
@@ -27,3 +28,3 @@ function getOffset (el) @@ -16,4 +15,4 @@ function Player(game)
if (!isNaN(el.offsetTop)) {
- offsetTop += el.offsetTop;
+ offsetTop += el.offsetTop + 1;
}
@@ -43,8 +44,7 @@ function isElementInViewport (el, h)
viewed = scrolled + getViewportH(),
- elH = el.offsetHeight,
elTop = getOffset(el).top,
- elBottom = elTop + elH,
+ elBottom = elTop + el.offsetHeight,
h = h || 0;
- return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - this.pixelX = 0;
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; - this.pixelY = 0;
} + this.pixelX = 10;
@@ -60,4 +60,2 @@ _init: function () + this.pixelY = 10;
- // Initialize all scrollreveals, triggering all @@ -82,3 +81,3 @@ function Player(game)
- // reveals on visible elements. Player.prototype.moveLeft = function() {
this.elems.forEach(function (el, i) { - this.x -= 1;
@@ -71,3 +69,3 @@ var scrollHandler = function () + this.x -= 5;
self._scrollPage(); this.direction = Direction.LEFT;
- }, 60); @@ -106,3 +105,3 @@ function Player(game)
+ }, 61);
} - context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
@@ -101,2 +99,3 @@ _scrollPage: function () + context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
this.scrolled = false; };
+ this.tested = true;
},
diff --git a/files/file.javascript b/files/file.javascript diff --git a/files/file.javascript b/files/file.javascript
index b9f1286..7cd3c5a 100644 index 0965b37..5391797 100644
--- a/files/file.javascript --- a/files/file.javascript
+++ b/files/file.javascript +++ b/files/file.javascript
@@ -16,3 +16,4 @@ @@ -4,4 +4,3 @@ define(function(require, exports, module) {
var client = docElem['clientHeight'], var Key = require("./key")
- inner = window['innerHeight']; - , Direction = require("./direction")
+ inner = window['innerHeight'], - , Image = require("./image");
+ sample = window['otherProperty']; + , Direction = require("./direction");
@@ -27,3 +28,3 @@ @@ -16,4 +15,4 @@ define(function(require, exports, module) {
if (!isNaN(el.offsetTop)) {
- offsetTop += el.offsetTop;
+ offsetTop += el.offsetTop + 1;
}
@@ -43,8 +44,7 @@
viewed = scrolled + getViewportH(),
- elH = el.offsetHeight,
elTop = getOffset(el).top,
- elBottom = elTop + elH,
+ elBottom = elTop + el.offsetHeight,
h = h || 0;
- return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; - this.pixelX = 0;
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; - this.pixelY = 0;
} + this.pixelX = 10;
@@ -60,4 +60,2 @@ + this.pixelY = 10;
- // Initialize all scrollreveals, triggering all @@ -82,3 +81,3 @@ define(function(require, exports, module) {
- // reveals on visible elements. Player.prototype.moveLeft = function() {
this.elems.forEach(function (el, i) { - this.x -= 1;
@@ -71,3 +69,3 @@ + this.x -= 5;
self._scrollPage(); this.direction = Direction.LEFT;
- }, 60); @@ -106,3 +105,3 @@ define(function(require, exports, module) {
+ }, 61);
} - context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
@@ -101,2 +99,3 @@ + context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
this.scrolled = false; };
+ this.tested = true;
},
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
which happens to be a trending Javascript repo with an MIT license at
the time I was working on Javascript userdiff support in libgit2
I extracted just some of the code, so I suspect this is no longer valid var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction");
*/
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'],
sample = window['otherProperty'];
return (client < inner) ? inner : client; this.pixelX = 10;
} this.pixelY = 10;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop + 1;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
} }
function isElementInViewport (el, h) { Player.prototype.update = function() {
var scrolled = window.pageYOffset, if (!this.isWalking()) {
viewed = scrolled + getViewportH(), this.handleInput();
elTop = getOffset(el).top, }
elBottom = elTop + el.offsetHeight,
h = h || 0;
return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
}
scrollReveal.prototype = {
_init: function () {
var self = this;
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
this.scrolled = false;
this.elems.forEach(function (el, i) { if (this.isWalking()) {
self.animate(el); // Increase the animation step.
}); this.animationStep = ++this.animationStep % 60;
var scrollHandler = function () { if (this.x * 32 > this.pixelX) {
if (!self.scrolled) { this.pixelX++;
self.scrolled = true; } else if (this.x * 32 < this.pixelX) {
setTimeout(function () { this.pixelX--;
self._scrollPage(); }
}, 61);
}
};
var resizeHandler = function () { if (this.y * 32 > this.pixelY) {
function delayed() { this.pixelY++;
self._scrollPage(); } else if (this.y * 32 < this.pixelY) {
self.resizeTimeout = null; this.pixelY--;
} }
if (self.resizeTimeout) { } else {
clearTimeout(self.resizeTimeout); // Reset the animation step.
this.animationStep = 0;
}
};
Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
for (action in inputs) {
if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
} }
self.resizeTimeout = setTimeout(delayed, 200); }
}; }
window.addEventListener('scroll', scrollHandler, false);
window.addEventListener('resize', resizeHandler, false);
},
/*=============================================================================*/
_scrollPage: function () {
var self = this;
this.elems.forEach(function (el, i) {
if (isElementInViewport(el, self.options.viewportFactor)) {
self.animate(el);
}
});
this.scrolled = false;
this.tested = true;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { this[finalAction] && this[finalAction]();
window.scrollReveal = new scrollReveal(); };
});
Player.prototype.isWalking = function() {
return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
};
Player.prototype.moveDown = function() {
this.y += 1;
this.direction = Direction.DOWN;
};
Player.prototype.moveUp = function() {
this.y -= 1;
this.direction = Direction.UP;
};
Player.prototype.moveLeft = function() {
this.x -= 5;
this.direction = Direction.LEFT;
};
Player.prototype.moveRight = function() {
this.x += 1;
this.direction = Direction.RIGHT;
};
Player.prototype.draw = function(context) {
var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
}
})(window); context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
};
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment