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;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
this.animationStep = 0;
}
function isElementInViewport (el, h) {
var scrolled = window.pageYOffset,
viewed = scrolled + getViewportH(),
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;
Player.prototype.update = function() {
if (!this.isWalking()) {
this.handleInput();
}
this.elems.forEach(function (el, i) {
self.animate(el);
});
if (this.isWalking()) {
// Increase the animation step.
this.animationStep = ++this.animationStep % 60;
var scrollHandler = function () {
if (!self.scrolled) {
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 61);
}
};
if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
}
var resizeHandler = function () {
function delayed() {
self._scrollPage();
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
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;
}
};
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) {
window.scrollReveal = new scrollReveal();
});
this[finalAction] && this[finalAction]();
};
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);
};
});
/*
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;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
this.animationStep = 0;
}
function isElementInViewport (el, h) {
var scrolled = window.pageYOffset,
viewed = scrolled + getViewportH(),
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;
Player.prototype.update = function() {
if (!this.isWalking()) {
this.handleInput();
}
// Initialize all scrollreveals, triggering all
// reveals on visible elements.
this.elems.forEach(function (el, i) {
self.animate(el);
});
if (this.isWalking()) {
// Increase the animation step.
this.animationStep = ++this.animationStep % 60;
var scrollHandler = function () {
if (!self.scrolled) {
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 60);
}
};
if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
}
var resizeHandler = function () {
function delayed() {
self._scrollPage();
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
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;
}
};
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) {
window.scrollReveal = new scrollReveal();
});
this[finalAction] && this[finalAction]();
};
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
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;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
this.animationStep = 0;
}
function isElementInViewport (el, h) {
var scrolled = window.pageYOffset,
viewed = scrolled + getViewportH(),
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;
Player.prototype.update = function() {
if (!this.isWalking()) {
this.handleInput();
}
this.elems.forEach(function (el, i) {
self.animate(el);
});
if (this.isWalking()) {
// Increase the animation step.
this.animationStep = ++this.animationStep % 60;
var scrollHandler = function () {
if (!self.scrolled) {
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 61);
}
};
if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
}
var resizeHandler = function () {
function delayed() {
self._scrollPage();
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
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;
}
};
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) {
window.scrollReveal = new scrollReveal();
});
this[finalAction] && this[finalAction]();
};
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