Skip to content

Commit

Permalink
Fix caching animatedGif by #3
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Apr 8, 2015
1 parent 1dc35fb commit e55ba62
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 34 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
v0.1.10 / Apr 8 2015
=========================
* [`unknown`][6] :bug: Hotfix [#3][6A]

[6A]: https://github.com/59naga/jaggy/issues/3
[6]: https://github.com/59naga/jaggy/commit/

v0.1.9 / Apr 7 2015
=========================
* [`a907a0a`][5] :lipstick: Add ng-annotate for uglifyjs
* [`d36c425`][5] :lipstick: Add ng-annotate for uglifyjs

[5]: https://github.com/59naga/jaggy/commits/master
[5]: https://github.com/59naga/jaggy/commit/d36c425846abff547f719c43dc2ecf67097079e8

v0.1.8 / Mar 30 2015
=========================
Expand Down
19 changes: 14 additions & 5 deletions lib/jaggy.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Jaggy= ->
Jaggy.createSVG.apply null,arguments if typeof window isnt 'undefined'
Jaggy.gulpPlugin.apply null,arguments if typeof window is 'undefined'
Jaggy.createSVG arguments... if window?
Jaggy.gulpPlugin arguments... if not window?

Jaggy.cli= ->
cli= new (require 'commander').Command
Expand Down Expand Up @@ -100,7 +100,7 @@ Jaggy.setCache= (url,element)->
catch error
localStorage.removeItem 'jaggy:'+url

console.error error
console.error 'jaggy:'+url,error

# Use for angular.js
Jaggy.angularModule= (window)->
Expand All @@ -121,7 +121,7 @@ Jaggy.angularModule= (window)->
options[key]= value
options.cache= !! jaggyConfig.useCache

#fix <img ng-src="url" jaggy>
# fix <img ng-src="url" jaggy>
url= attrs.src
url?= attrs.ngSrc

Expand All @@ -131,6 +131,15 @@ Jaggy.angularModule= (window)->
return element.replaceWith jaggyEmptyImage
element.replaceWith svg

# fix animatedGif caching
if svg.match and svg.match '<script>'
svgContainer= document.createElement 'div'
svgContainer.innerHTML= svg
script= svgContainer.querySelector('script')?.innerHTML
script= script.replace /&gt;/g,'>'
script= script.replace /&lt;/g,'<'
eval script

Jaggy.convertToSVG= (pixels,args...)->
callback= null
options= {}
Expand Down Expand Up @@ -158,7 +167,7 @@ Jaggy.enableAnimation= (svg)->

# fix disabled script
script= svg.querySelector 'script'
script.parentNode.replaceChild script.cloneNode(),script
script.parentNode.replaceChild script.cloneNode(),script if script
svg

# Use Buffer for node.js
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"main": "jaggy",
"bin": "jaggy",
"description": "is Converting to SVG by pixels",
"version": "0.1.9",
"version": "0.1.10",

"scripts": {
"build": "browserify lib/jaggy.coffee -r get-pixels -r gify-parse -t coffeeify | ng-annotate - --add > public/jaggy.browser.js",
"postbuild": "uglifyjs public/jaggy.browser.js --compres --mangle --source-map public/jaggy.browser.min.js.map --source-map-url jaggy.browser.min.js.map --output public/jaggy.browser.min.js",
"devbuild": "browserify lib/jaggy.coffee -r get-pixels -r gify-parse -t coffeeify | ng-annotate - --add > public/jaggy.browser.js",

"prestart": "onefile --json --output public/pkgs",
"start": "cd public && open http://localhost:8000 && python -m SimpleHTTPServer",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h2>via gulp.js (<code>$ npm test</code>)</h2>

<h2>via angular.js</h2>
<img src="tumblr_n39vfaV03s1rnbw6mo1_400.gif" jaggy alt="for Angular.js">
<img ng-src="uma.gif" jaggy alt="for Angular.js">
<img ng-src="yuno.png" jaggy alt="for Angular.js">
<img ng-src="comeon! emptyimage" jaggy alt="for Angular.js">

Expand Down
28 changes: 20 additions & 8 deletions public/jaggy.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ var Jaggy,
slice = [].slice;

Jaggy = function() {
if (typeof window !== 'undefined') {
Jaggy.createSVG.apply(null, arguments);
if (typeof window !== "undefined" && window !== null) {
Jaggy.createSVG.apply(Jaggy, arguments);
}
if (typeof window === 'undefined') {
return Jaggy.gulpPlugin.apply(null, arguments);
if (typeof window === "undefined" || window === null) {
return Jaggy.gulpPlugin.apply(Jaggy, arguments);
}
};

Expand Down Expand Up @@ -465,7 +465,7 @@ Jaggy.setCache = function(url, element) {
} catch (_error) {
error = _error;
localStorage.removeItem('jaggy:' + url);
return console.error(error);
return console.error('jaggy:' + url, error);
}
};

Expand Down Expand Up @@ -496,13 +496,22 @@ Jaggy.angularModule = function(window) {
url = attrs.ngSrc;
}
return Jaggy.createSVG(url, options, function(error, svg) {
var ref2, script, svgContainer;
if (error) {
if (!jaggyConfig.useEmptyImage) {
throw error;
}
return element.replaceWith(jaggyEmptyImage);
}
return element.replaceWith(svg);
element.replaceWith(svg);
if (svg.match && svg.match('<script>')) {
svgContainer = document.createElement('div');
svgContainer.innerHTML = svg;
script = (ref2 = svgContainer.querySelector('script')) != null ? ref2.innerHTML : void 0;
script = script.replace(/&gt;/g, '>');
script = script.replace(/&lt;/g, '<');
return eval(script);
}
});
};
}]);
Expand Down Expand Up @@ -548,7 +557,9 @@ Jaggy.enableAnimation = function(svg) {
throw new Error('Can enable appended element only');
}
script = svg.querySelector('script');
script.parentNode.replaceChild(script.cloneNode(), script);
if (script) {
script.parentNode.replaceChild(script.cloneNode(), script);
}
return svg;
};

Expand Down Expand Up @@ -28005,11 +28016,12 @@ module.exports={
"main": "jaggy",
"bin": "jaggy",
"description": "is Converting to SVG by pixels",
"version": "0.1.9",
"version": "0.1.10",

"scripts": {
"build": "browserify lib/jaggy.coffee -r get-pixels -r gify-parse -t coffeeify | ng-annotate - --add > public/jaggy.browser.js",
"postbuild": "uglifyjs public/jaggy.browser.js --compres --mangle --source-map public/jaggy.browser.min.js.map --source-map-url jaggy.browser.min.js.map --output public/jaggy.browser.min.js",
"devbuild": "browserify lib/jaggy.coffee -r get-pixels -r gify-parse -t coffeeify | ng-annotate - --add > public/jaggy.browser.js",

"prestart": "onefile --json --output public/pkgs",
"start": "cd public && open http://localhost:8000 && python -m SimpleHTTPServer",
Expand Down
30 changes: 13 additions & 17 deletions public/jaggy.browser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/jaggy.browser.min.js.map

Large diffs are not rendered by default.

Binary file added public/uma.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e55ba62

Please sign in to comment.