Commit 19fa9c0c by Arthur Schreiber

New test files for the javascript diff driver.

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