diff options
| author | jules <jules@okfoc.us> | 2013-12-13 16:06:43 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2013-12-13 16:06:43 -0500 |
| commit | e6a10925902812fe78732af31f289d7176b2c1a3 (patch) | |
| tree | 277e6cf2c782618e3a026c263b2b253bbafa4f73 /js/util.js | |
| parent | 346f3a9817b1e0812565396b9811a1ce5adc97b8 (diff) | |
general util.js
Diffstat (limited to 'js/util.js')
| -rw-r--r-- | js/util.js | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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 +}; |
