summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorjules <jules@okfoc.us>2013-12-13 16:06:43 -0500
committerjules <jules@okfoc.us>2013-12-13 16:06:43 -0500
commite6a10925902812fe78732af31f289d7176b2c1a3 (patch)
tree277e6cf2c782618e3a026c263b2b253bbafa4f73 /js
parent346f3a9817b1e0812565396b9811a1ce5adc97b8 (diff)
general util.js
Diffstat (limited to 'js')
-rw-r--r--js/util.js38
-rw-r--r--js/vendor/gif-encode/client.js2
2 files changed, 39 insertions, 1 deletions
diff --git a/js/util.js b/js/util.js
index 9dc306c..fc27166 100644
--- a/js/util.js
+++ b/js/util.js
@@ -1,3 +1,41 @@
$.fn.int = function(){ return parseInt($(this).val(),10) }
$.fn.float = function(){ return parseFloat($(this).val()) }
function clamp(n,a,b){ return n<a?a:n<b?n:b }
+
+function loadImage(imageURL, callback) {
+ document.getElementById("save").style.display = "none"
+ document.getElementById("encode").style.display = "none"
+ status("loading")
+ var imageURL = proxify( imageURL );
+
+ window.gif = window.img = null
+
+ if (imageURL.substr(-3) === "gif") {
+ window.gif = GIF(imageURL);
+ // gif.on("error", tryToLoadNextImage);
+ // gif.on("rendered", trackLoadTime);
+ gif.on("rendered", callback);
+ return gif.render();
+ } else {
+ window.img = new Image();
+ // img.addEventListener("error", tryToLoadNextImage);
+ img.addEventListener("load", callback);
+ img.crossOrigin = "anonymous";
+ return img.src = imageURL;
+ }
+}
+
+function giveImage() {
+ if (imageURL.substr(-3) === "gif") {
+ return gif.frames[gif.currentFrame()].ctx.canvas;
+ } else {
+ return img;
+ }
+}
+
+function proxify (url) {
+ if (url.indexOf("http") == 0)
+ return "/cgi-bin/proxy?" + url // .replace(/^https?:\/\//, "");
+ else
+ return url
+};
diff --git a/js/vendor/gif-encode/client.js b/js/vendor/gif-encode/client.js
index a6c09ec..128c93d 100644
--- a/js/vendor/gif-encode/client.js
+++ b/js/vendor/gif-encode/client.js
@@ -99,7 +99,7 @@ function GifEncoder(){
var ww = [];
base.init = function(){
for (var i = 0; i < WORKERS; i++) {
- var worker = new Worker('gif-encode/worker.js');
+ var worker = new Worker('js/vendor/gif-encode/worker.js');
worker.onmessage = base.receiveWork;
ww.push(worker);
}