Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Build 0.4.13 - New method to update dimensions after changing padding

  • Loading branch information...
commit 879a9e5914ef784f5bd9e3384f44fdf512a42d4a 1 parent d9f8976
@draeton authored
View
6 README.md
@@ -1,19 +1,19 @@
## Stitches
[Stitches](http://draeton.github.com/stitches/) is an HTML5 sprite sheet generator.
-The current version is `0.4.12`. Documentation is available
+The current version is `0.4.13`. Documentation is available
[here](http://draeton.github.com/stitches/stitches/docs/stitches.html).
## Implementation
Stitches requires a stylesheet, a script, and an HTML element to get the job done:
- <link rel="stylesheet" href="css/stitches-0.4.12-min.css">
+ <link rel="stylesheet" href="css/stitches-0.4.13-min.css">
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/modernizr-2.0.6.min.js"></script>
- <script src="js/stitches-0.4.12-min.js"></script>
+ <script src="js/stitches-0.4.13-min.js"></script>
Once that's in place, the sprite sheet generator is created by the `init` method:
View
4 build.properties
@@ -1,4 +1,4 @@
-#Wed, 25 Jan 2012 11:43:05 -0500
+#Wed, 25 Jan 2012 11:49:40 -0500
build.major=0
build.minor=4
-build.number=12
+build.number=13
View
0  build/css/stitches-0.4.12-min.css → build/css/stitches-0.4.13-min.css
File renamed without changes
View
0  build/css/stitches-0.4.12.css → build/css/stitches-0.4.13.css
File renamed without changes
View
2  build/js/stitches-0.4.12-min.js → build/js/stitches-0.4.13-min.js
@@ -1 +1 @@
-(function(window,$,Modernizr){window.Stitches=(function(){var defaults={jsdir:"js",prefix:"sprite",padding:10,dataURI:false};return{_topics:{},init:function($elem,config){Stitches.settings=$.extend({},defaults,config);Stitches.iconQueue=[];Stitches.Page.$elem=$elem;Stitches.sub("page.error",Stitches.Page.errorHandler);Stitches.sub("page.init.done",Stitches.Page.fetchTemplates);Stitches.sub("page.templates.done",Stitches.Page.render);Stitches.sub("page.render.done",Stitches.checkAPIs);Stitches.sub("page.apis.done",Stitches.Page.bindDragAndDrop);Stitches.sub("page.apis.done",Stitches.Page.bindButtons);Stitches.sub("page.apis.done",Stitches.Page.bindCabinet);Stitches.sub("page.apis.done",Stitches.Page.bindOptions);Stitches.sub("page.apis.done",Stitches.Page.subscribe);Stitches.sub("page.drop.done",Stitches.File.queueFiles);Stitches.sub("file.queue.done",Stitches.File.queueIcons);Stitches.sub("file.icon.done",Stitches.Page.addIcon);Stitches.sub("file.remove.done",Stitches.Page.removeIcon);Stitches.sub("file.unqueue",Stitches.File.unqueueIcon);Stitches.sub("file.unqueue.all",Stitches.File.unqueueAllIcons);Stitches.sub("sprite.generate",Stitches.generateStitches);Stitches.pub("page.init.done");},sub:function(topic,fn){var callbacks=Stitches._topics[topic]||$.Callbacks("stopOnFalse");if(fn){callbacks.add(fn);}Stitches._topics[topic]=callbacks;},unsub:function(topic,fn){var callbacks=Stitches._topics[topic];if(callbacks){callbacks.remove(fn);}},pub:function(topic){var callbacks=Stitches._topics[topic],args=Array.prototype.slice.call(arguments,1);if(callbacks){callbacks.fire.apply(callbacks,args);}},checkAPIs:function(){Modernizr.load([{test:typeof FileReader!=="undefined"&&Modernizr.draganddrop,nope:Stitches.settings.jsdir+"/dropfile/dropfile.js"},{test:Modernizr.canvas,nope:Stitches.settings.jsdir+"/flashcanvas/flashcanvas.js",complete:function(){if(typeof FileReader!=="undefined"&&Modernizr.draganddrop&&Modernizr.canvas){Stitches.pub("page.apis.done");}else{Stitches.pub("page.error",new Error("Required APIs are not present."));}}}]);},generateStitches:function(looseIcons){var placedIcons=Stitches.positionImages(looseIcons);var sprite=Stitches.makeStitches(placedIcons);var stylesheet=Stitches.makeStylesheet(placedIcons,sprite);Stitches.pub("sprite.generate.done",sprite,stylesheet);},positionImages:function(looseIcons){var placedIcons=[];$(looseIcons).each(function(idx,icon){icon.x=icon.y=0;icon.isPlaced=false;});looseIcons=looseIcons.sort(function(a,b){if(b.area===a.area){return b.name>a.name?1:-1;}else{return b.area-a.area;}});Stitches.canvas=Stitches.Icons.idealCanvas(looseIcons);Stitches.Icons.placeIcons(looseIcons,placedIcons,Stitches.canvas);Stitches.Icons.cropCanvas(placedIcons,Stitches.canvas);Stitches.pub("sprite.position.done",placedIcons);return placedIcons;},makeStitches:function(placedIcons){var context,data;try{context=Stitches.canvas.getContext("2d");$(placedIcons).each(function(idx,icon){context.drawImage(icon.image,icon.x,icon.y);});data=Stitches.canvas.toDataURL();}catch(e){Stitches.pub("page.error",e);}Stitches.pub("sprite.image.done",data);return data;},makeStylesheet:function(placedIcons,sprite){placedIcons=placedIcons.sort(function(a,b){return a.name<b.name?-1:1;});var prefix=Stitches.settings.prefix;var backgroundImage;if(Stitches.settings.dataURI){backgroundImage=sprite;}else{backgroundImage="download.png";}var css=["."+prefix+" {"," background: url("+backgroundImage+") no-repeat;","}\n"];$(placedIcons).each(function(idx,icon){css=css.concat(["."+prefix+"-"+icon.name+" {"," width: "+icon.image.width+"px;"," height: "+icon.image.height+"px;"," background-position: -"+icon.x+"px -"+icon.y+"px;","}\n"]);});var data="data:,"+encodeURIComponent(css.join("\n"));Stitches.pub("sprite.stylesheet.done",data);return data;}};})();})(window,jQuery,Modernizr);(function(window,Stitches,$){var document=window.document;Stitches.Icons=(function(){return{idealCanvas:function(icons){var maxW=0;var maxH=0;var area=0;$(icons).each(function(idx,icon){maxW=icon.width>maxW?icon.width:maxW;maxH=icon.height>maxH?icon.height:maxH;area+=icon.area;});var ideal=Math.ceil(Math.sqrt(area));var idealW=maxW>ideal?maxW:ideal;var idealH=maxH>ideal?maxH:ideal;var canvas=document.createElement("canvas");canvas.width=idealW;canvas.height=idealH;return canvas;},placeIcons:function(loose,placed,canvas){var i=0;while(loose.length&&i<10){$(loose).each(function(idx,icon){if(!icon.isPlaced){icon.isPlaced=Stitches.Icons.placeIcon(icon,placed,canvas);}});i++;}for(i=0;i<loose.length;i++){if(loose[i].isPlaced){loose.splice(i);}}return true;},placeIcon:function(icon,placed,canvas){var i=0;while(i<2){for(var y=0;y<=canvas.height-icon.height;y++){for(var x=0;x<=canvas.width-icon.width;x++){icon.x=x;icon.y=y;var overlap=Stitches.Icons.isOverlapped(icon,placed);if(!overlap){return true;}x=overlap.x+overlap.width;}y=overlap.y+overlap.height;}canvas.width+=icon.width;canvas.height+=icon.height;i++;}return false;},isOverlapped:function(icon,placed){var x1,x2,y1,y2;var intersect=[];var overlap=null;$(placed).each(function(idx,p){x1=(p.x<icon.x+icon.width);x2=(p.x+p.width>icon.x);y1=(p.y<icon.y+icon.height);y2=(p.y+p.height>icon.y);if(x1&&x2&&y1&&y2){intersect.push(p);}});if(intersect.length){overlap=intersect.pop();}else{placed.push(icon);}return overlap;},cropCanvas:function(placed,canvas){var w=0,h=0;$(placed).each(function(idx,icon){w=w>icon.x+icon.width?w:icon.x+icon.width;h=h>icon.y+icon.height?h:icon.y+icon.height;});canvas.width=w;canvas.height=h;}};})();})(window,Stitches,jQuery);(function(window,Stitches){var guid=0;var nameCache={};Stitches.Icon=function(name,src,cb){var self=this;this.guid=guid++;this.name=Stitches.Icon.getName(name);this.image=new Image();this.image.onload=function(){self.x=0;self.y=0;self.width=self.image.width+Stitches.settings.padding;self.height=self.image.height+Stitches.settings.padding;self.area=self.width*self.height;if(cb){cb(self);}};this.image.src=src;};Stitches.Icon.getName=function(name){var i=1,fix;name=name.replace(/[\s.]+/gi,"-").replace(/[^a-z0-9\-]/gi,"_");if(nameCache[name]){do{fix=name+"-"+i++;}while(nameCache[fix]);name=fix;}nameCache[name]=true;return name;};Stitches.Icon.clearNameCache=function(name){if(name){delete nameCache[name];}else{nameCache={};}};})(window,Stitches);(function(){var cache={};Stitches.tmpl=function tmpl(str,data){var fn=!/\W/.test(str)?cache[str]=cache[str]||tmpl(document.getElementById(str).innerHTML):new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+str.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return data?fn(data):fn;};})();(function(window,Stitches,$){Stitches.Page=(function(){var rendered=false;return{fetchTemplates:function(){return $.get(Stitches.settings.jsdir+"/stitches.html",function(html){$("body").append(html);Stitches.Page.templates={stitches:Stitches.tmpl("stitches_tmpl"),icon:Stitches.tmpl("stitches_icon_tmpl")};Stitches.pub("page.templates.done");});},render:function(){var $div=$(Stitches.Page.templates.stitches({}));$div.appendTo(Stitches.Page.$elem);Stitches.Page.$stitches=$(".stitches",Stitches.Page.$elem);Stitches.Page.$drawer=$(".drawer",Stitches.Page.$elem);Stitches.Page.$dropbox=$(".dropbox",Stitches.Page.$elem);Stitches.Page.$droplabel=$(".droplabel",Stitches.Page.$elem);Stitches.Page.$filelist=$(".filelist",Stitches.Page.$elem);Stitches.Page.$buttons=$(".buttons",Stitches.Page.$elem);Stitches.Page.buttons={$generate:$("a.generate",Stitches.Page.$buttons),$clear:$("a.clear",Stitches.Page.$buttons),$sprite:$("a.dlsprite",Stitches.Page.$buttons),$stylesheet:$("a.dlstylesheet",Stitches.Page.$buttons)};Stitches.Page.$options=$(".options",Stitches.Page.$elem);Stitches.Page.inputs={$prefix:$("input[name=prefix]",Stitches.Page.$options),$padding:$("input[name=padding]",Stitches.Page.$options),$dataURI:$("input[name=dataURI]",Stitches.Page.$options)};Stitches.Page.inputs.$prefix.val(Stitches.settings.prefix);Stitches.Page.inputs.$padding.val(Stitches.settings.padding);Stitches.Page.inputs.$dataURI.filter("[value="+Stitches.settings.dataURI+"]").attr("checked",true);rendered=true;Stitches.pub("page.render.done");},errorHandler:function(e){if(rendered){Stitches.Page.$droplabel.html("&times; "+e.message).addClass("error");}throw e;},subscribe:function(){var buttons=Stitches.Page.buttons;var $droplabel=Stitches.Page.$droplabel;Stitches.sub("file.icon.done",function(icon){if(Stitches.iconQueue.length===1){$droplabel.fadeOut("fast");buttons.$generate.removeClass("disabled");buttons.$clear.removeClass("disabled");}buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});Stitches.sub("file.remove.done",function(icon){if(Stitches.iconQueue.length<1){$droplabel.fadeIn("fast");buttons.$generate.addClass("disabled");buttons.$clear.addClass("disabled");}buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});Stitches.sub("sprite.generate.done",function(sprite,stylesheet){buttons.$sprite.attr("href",sprite).removeClass("disabled");buttons.$stylesheet.attr("href",stylesheet).removeClass("disabled");});},_noop:function(e){e.preventDefault();e.stopPropagation();},bindDragAndDrop:function(){var dropbox=Stitches.Page.$dropbox.get(0);dropbox.addEventListener("dragenter",Stitches.Page._dragStart,false);dropbox.addEventListener("dragleave",Stitches.Page._dragStop,false);dropbox.addEventListener("dragexit",Stitches.Page._dragStop,false);dropbox.addEventListener("dragover",Stitches.Page._noop,false);dropbox.addEventListener("drop",Stitches.Page._drop,false);},_dragStart:function(e){Stitches.Page.$dropbox.addClass("dropping");},_dragStop:function(e){if($(e.target).parents(".dropbox").length===0){Stitches.Page.$dropbox.removeClass("dropping");}},_drop:function(e){e.stopPropagation();e.preventDefault();Stitches.Page.$dropbox.removeClass("dropping");var evt=e||window.event;var files=(evt.files||evt.dataTransfer.files);if(files.length>0){Stitches.pub("page.drop.done",files);}},bindButtons:function(){var $elem=Stitches.Page.$elem;$elem.delegate("a.disabled","click",Stitches.Page._noop);$elem.delegate("a.generate","click",Stitches.Page._generate);$elem.delegate("a.remove","click",Stitches.Page._removeFile);$elem.delegate("a.clear","click",Stitches.Page._removeAllFiles);},bindCabinet:function(){var $elem=Stitches.Page.$elem;var $stitches=Stitches.Page.$stitches;var $options=Stitches.Page.$options;var $drawer=Stitches.Page.$drawer;var $cabinet=$("form.cabinet",$drawer);var $input=$("input.files",$drawer);$stitches.hover(function(){$drawer.stop().animate({left:"-5px"},250);},function(){$drawer.stop().animate({left:"-125px"},250);});$input.bind("change",function(){if(this.files.length){Stitches.pub("page.drop.done",this.files);}$cabinet.trigger("reset");});$drawer.delegate("a.open-options","click",function(){$options.fadeIn();});},bindOptions:function(){var $options=Stitches.Page.$options;var buttons=Stitches.Page.buttons;$options.delegate("a.close-options","click",function(){$options.fadeOut();});$options.delegate("input","change",function(){buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});$options.delegate("input[name=prefix]","change",function(){Stitches.settings.prefix=Stitches.Page.inputs.$prefix.val();});$options.delegate("input[name=padding]","change",function(){var padding=Stitches.Page.inputs.$padding.val();Stitches.settings.padding=+padding;});$options.delegate("input[name=dataURI]","change",function(){var dataURI=Stitches.Page.inputs.$dataURI.filter(":checked").val();Stitches.settings.dataURI=dataURI==="true"?true:false;});},_generate:function(e){Stitches.pub("sprite.generate",[].concat(Stitches.iconQueue));},_removeFile:function(e){var icon=$(this).parent("li").data("icon");Stitches.pub("file.unqueue",icon);},_removeAllFiles:function(e){Stitches.pub("file.unqueue.all");},addIcon:function(icon){$(Stitches.Page.templates.icon(icon)).data("icon",icon).appendTo(Stitches.Page.$filelist).fadeIn("fast");},removeIcon:function(icon){Stitches.Page.$filelist.find("li").filter(function(){return $(this).data("icon")===icon;}).fadeOut("fast").remove();}};})();})(window,Stitches,jQuery);(function(window,Stitches,$){Stitches.File=(function(){var readQueue=[];return{queueFiles:function(files){$.each(files,function(i,file){if(/jpeg|png|gif/.test(file.type)){readQueue.push(file);Stitches.pub("file.queue.done",file);}});},queueIcons:function(){var file,reader;file=readQueue.shift();if(file){try{reader=new FileReader();reader.onloadend=function(e){var icon=new Stitches.Icon(file.name,e.target.result);Stitches.iconQueue.push(icon);Stitches.pub("file.icon.done",icon);};reader.readAsDataURL(file);}catch(e){Stitches.pub("page.error",e);}}},unqueueIcon:function(icon){Stitches.iconQueue=$.grep(Stitches.iconQueue,function(item){return item!==icon;});Stitches.Icon.clearNameCache(icon.name);Stitches.pub("file.remove.done",icon);},unqueueAllIcons:function(){$.each(Stitches.iconQueue,function(i,icon){Stitches.File.unqueueIcon(icon);});Stitches.Icon.clearNameCache();}};})();})(window,Stitches,jQuery);
+(function(window,$,Modernizr){window.Stitches=(function(){var defaults={jsdir:"js",prefix:"sprite",padding:10,dataURI:false};return{_topics:{},init:function($elem,config){Stitches.settings=$.extend({},defaults,config);Stitches.iconQueue=[];Stitches.Page.$elem=$elem;Stitches.sub("page.error",Stitches.Page.errorHandler);Stitches.sub("page.init.done",Stitches.Page.fetchTemplates);Stitches.sub("page.templates.done",Stitches.Page.render);Stitches.sub("page.render.done",Stitches.checkAPIs);Stitches.sub("page.apis.done",Stitches.Page.bindDragAndDrop);Stitches.sub("page.apis.done",Stitches.Page.bindButtons);Stitches.sub("page.apis.done",Stitches.Page.bindCabinet);Stitches.sub("page.apis.done",Stitches.Page.bindOptions);Stitches.sub("page.apis.done",Stitches.Page.subscribe);Stitches.sub("page.drop.done",Stitches.File.queueFiles);Stitches.sub("file.queue.done",Stitches.File.queueIcons);Stitches.sub("file.icon.done",Stitches.Page.addIcon);Stitches.sub("file.remove.done",Stitches.Page.removeIcon);Stitches.sub("file.unqueue",Stitches.File.unqueueIcon);Stitches.sub("file.unqueue.all",Stitches.File.unqueueAllIcons);Stitches.sub("sprite.generate",Stitches.generateStitches);Stitches.pub("page.init.done");},sub:function(topic,fn){var callbacks=Stitches._topics[topic]||$.Callbacks("stopOnFalse");if(fn){callbacks.add(fn);}Stitches._topics[topic]=callbacks;},unsub:function(topic,fn){var callbacks=Stitches._topics[topic];if(callbacks){callbacks.remove(fn);}},pub:function(topic){var callbacks=Stitches._topics[topic],args=Array.prototype.slice.call(arguments,1);if(callbacks){callbacks.fire.apply(callbacks,args);}},checkAPIs:function(){Modernizr.load([{test:typeof FileReader!=="undefined"&&Modernizr.draganddrop,nope:Stitches.settings.jsdir+"/dropfile/dropfile.js"},{test:Modernizr.canvas,nope:Stitches.settings.jsdir+"/flashcanvas/flashcanvas.js",complete:function(){if(typeof FileReader!=="undefined"&&Modernizr.draganddrop&&Modernizr.canvas){Stitches.pub("page.apis.done");}else{Stitches.pub("page.error",new Error("Required APIs are not present."));}}}]);},generateStitches:function(looseIcons){var placedIcons=Stitches.positionImages(looseIcons);var sprite=Stitches.makeStitches(placedIcons);var stylesheet=Stitches.makeStylesheet(placedIcons,sprite);Stitches.pub("sprite.generate.done",sprite,stylesheet);},positionImages:function(looseIcons){var placedIcons=[];$(looseIcons).each(function(idx,icon){icon.x=icon.y=0;icon.isPlaced=false;});looseIcons=looseIcons.sort(function(a,b){if(b.area===a.area){return b.name>a.name?1:-1;}else{return b.area-a.area;}});Stitches.canvas=Stitches.Icons.idealCanvas(looseIcons);Stitches.Icons.placeIcons(looseIcons,placedIcons,Stitches.canvas);Stitches.Icons.cropCanvas(placedIcons,Stitches.canvas);Stitches.pub("sprite.position.done",placedIcons);return placedIcons;},makeStitches:function(placedIcons){var context,data;try{context=Stitches.canvas.getContext("2d");$(placedIcons).each(function(idx,icon){context.drawImage(icon.image,icon.x,icon.y);});data=Stitches.canvas.toDataURL();}catch(e){Stitches.pub("page.error",e);}Stitches.pub("sprite.image.done",data);return data;},makeStylesheet:function(placedIcons,sprite){placedIcons=placedIcons.sort(function(a,b){return a.name<b.name?-1:1;});var prefix=Stitches.settings.prefix;var backgroundImage;if(Stitches.settings.dataURI){backgroundImage=sprite;}else{backgroundImage="download.png";}var css=["."+prefix+" {"," background: url("+backgroundImage+") no-repeat;","}\n"];$(placedIcons).each(function(idx,icon){css=css.concat(["."+prefix+"-"+icon.name+" {"," width: "+icon.image.width+"px;"," height: "+icon.image.height+"px;"," background-position: -"+icon.x+"px -"+icon.y+"px;","}\n"]);});var data="data:,"+encodeURIComponent(css.join("\n"));Stitches.pub("sprite.stylesheet.done",data);return data;}};})();})(window,jQuery,Modernizr);(function(window,Stitches,$){var document=window.document;Stitches.Icons=(function(){return{idealCanvas:function(icons){var maxW=0;var maxH=0;var area=0;$(icons).each(function(idx,icon){maxW=icon.width>maxW?icon.width:maxW;maxH=icon.height>maxH?icon.height:maxH;area+=icon.area;});var ideal=Math.ceil(Math.sqrt(area));var idealW=maxW>ideal?maxW:ideal;var idealH=maxH>ideal?maxH:ideal;var canvas=document.createElement("canvas");canvas.width=idealW;canvas.height=idealH;return canvas;},placeIcons:function(loose,placed,canvas){var i=0;while(loose.length&&i<10){$(loose).each(function(idx,icon){if(!icon.isPlaced){icon.isPlaced=Stitches.Icons.placeIcon(icon,placed,canvas);}});i++;}for(i=0;i<loose.length;i++){if(loose[i].isPlaced){loose.splice(i);}}return true;},placeIcon:function(icon,placed,canvas){var i=0;while(i<2){for(var y=0;y<=canvas.height-icon.height;y++){for(var x=0;x<=canvas.width-icon.width;x++){icon.x=x;icon.y=y;var overlap=Stitches.Icons.isOverlapped(icon,placed);if(!overlap){return true;}x=overlap.x+overlap.width;}y=overlap.y+overlap.height;}canvas.width+=icon.width;canvas.height+=icon.height;i++;}return false;},isOverlapped:function(icon,placed){var x1,x2,y1,y2;var intersect=[];var overlap=null;$(placed).each(function(idx,p){x1=(p.x<icon.x+icon.width);x2=(p.x+p.width>icon.x);y1=(p.y<icon.y+icon.height);y2=(p.y+p.height>icon.y);if(x1&&x2&&y1&&y2){intersect.push(p);}});if(intersect.length){overlap=intersect.pop();}else{placed.push(icon);}return overlap;},cropCanvas:function(placed,canvas){var w=0,h=0;$(placed).each(function(idx,icon){w=w>icon.x+icon.width?w:icon.x+icon.width;h=h>icon.y+icon.height?h:icon.y+icon.height;});canvas.width=w;canvas.height=h;}};})();})(window,Stitches,jQuery);(function(window,Stitches){var guid=0;var nameCache={};Stitches.Icon=function(name,src,cb){var self=this;this.guid=guid++;this.name=Stitches.Icon.getName(name);this.image=new Image();this.image.onload=function(){self.x=0;self.y=0;self.width=self.image.width+Stitches.settings.padding;self.height=self.image.height+Stitches.settings.padding;self.area=self.width*self.height;if(cb){cb(self);}};this.image.src=src;};Stitches.Icon.getName=function(name){var i=1,fix;name=name.replace(/[\s.]+/gi,"-").replace(/[^a-z0-9\-]/gi,"_");if(nameCache[name]){do{fix=name+"-"+i++;}while(nameCache[fix]);name=fix;}nameCache[name]=true;return name;};Stitches.Icon.clearNameCache=function(name){if(name){delete nameCache[name];}else{nameCache={};}};})(window,Stitches);(function(){var cache={};Stitches.tmpl=function tmpl(str,data){var fn=!/\W/.test(str)?cache[str]=cache[str]||tmpl(document.getElementById(str).innerHTML):new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+str.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return data?fn(data):fn;};})();(function(window,Stitches,$){Stitches.Page=(function(){var rendered=false;return{fetchTemplates:function(){return $.get(Stitches.settings.jsdir+"/stitches.html",function(html){$("body").append(html);Stitches.Page.templates={stitches:Stitches.tmpl("stitches_tmpl"),icon:Stitches.tmpl("stitches_icon_tmpl")};Stitches.pub("page.templates.done");});},render:function(){var $div=$(Stitches.Page.templates.stitches({}));$div.appendTo(Stitches.Page.$elem);Stitches.Page.$stitches=$(".stitches",Stitches.Page.$elem);Stitches.Page.$drawer=$(".drawer",Stitches.Page.$elem);Stitches.Page.$dropbox=$(".dropbox",Stitches.Page.$elem);Stitches.Page.$droplabel=$(".droplabel",Stitches.Page.$elem);Stitches.Page.$filelist=$(".filelist",Stitches.Page.$elem);Stitches.Page.$buttons=$(".buttons",Stitches.Page.$elem);Stitches.Page.buttons={$generate:$("a.generate",Stitches.Page.$buttons),$clear:$("a.clear",Stitches.Page.$buttons),$sprite:$("a.dlsprite",Stitches.Page.$buttons),$stylesheet:$("a.dlstylesheet",Stitches.Page.$buttons)};Stitches.Page.$options=$(".options",Stitches.Page.$elem);Stitches.Page.inputs={$prefix:$("input[name=prefix]",Stitches.Page.$options),$padding:$("input[name=padding]",Stitches.Page.$options),$dataURI:$("input[name=dataURI]",Stitches.Page.$options)};Stitches.Page.inputs.$prefix.val(Stitches.settings.prefix);Stitches.Page.inputs.$padding.val(Stitches.settings.padding);Stitches.Page.inputs.$dataURI.filter("[value="+Stitches.settings.dataURI+"]").attr("checked",true);rendered=true;Stitches.pub("page.render.done");},errorHandler:function(e){if(rendered){Stitches.Page.$droplabel.html("&times; "+e.message).addClass("error");}throw e;},subscribe:function(){var buttons=Stitches.Page.buttons;var $droplabel=Stitches.Page.$droplabel;Stitches.sub("file.icon.done",function(icon){if(Stitches.iconQueue.length===1){$droplabel.fadeOut("fast");buttons.$generate.removeClass("disabled");buttons.$clear.removeClass("disabled");}buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});Stitches.sub("file.remove.done",function(icon){if(Stitches.iconQueue.length<1){$droplabel.fadeIn("fast");buttons.$generate.addClass("disabled");buttons.$clear.addClass("disabled");}buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});Stitches.sub("sprite.generate.done",function(sprite,stylesheet){buttons.$sprite.attr("href",sprite).removeClass("disabled");buttons.$stylesheet.attr("href",stylesheet).removeClass("disabled");});},_noop:function(e){e.preventDefault();e.stopPropagation();},bindDragAndDrop:function(){var dropbox=Stitches.Page.$dropbox.get(0);dropbox.addEventListener("dragenter",Stitches.Page._dragStart,false);dropbox.addEventListener("dragleave",Stitches.Page._dragStop,false);dropbox.addEventListener("dragexit",Stitches.Page._dragStop,false);dropbox.addEventListener("dragover",Stitches.Page._noop,false);dropbox.addEventListener("drop",Stitches.Page._drop,false);},_dragStart:function(e){Stitches.Page.$dropbox.addClass("dropping");},_dragStop:function(e){if($(e.target).parents(".dropbox").length===0){Stitches.Page.$dropbox.removeClass("dropping");}},_drop:function(e){e.stopPropagation();e.preventDefault();Stitches.Page.$dropbox.removeClass("dropping");var evt=e||window.event;var files=(evt.files||evt.dataTransfer.files);if(files.length>0){Stitches.pub("page.drop.done",files);}},bindButtons:function(){var $elem=Stitches.Page.$elem;$elem.delegate("a.disabled","click",Stitches.Page._noop);$elem.delegate("a.generate","click",Stitches.Page._generate);$elem.delegate("a.remove","click",Stitches.Page._removeFile);$elem.delegate("a.clear","click",Stitches.Page._removeAllFiles);},bindCabinet:function(){var $elem=Stitches.Page.$elem;var $stitches=Stitches.Page.$stitches;var $options=Stitches.Page.$options;var $drawer=Stitches.Page.$drawer;var $cabinet=$("form.cabinet",$drawer);var $input=$("input.files",$drawer);$stitches.hover(function(){$drawer.stop().animate({left:"-5px"},250);},function(){$drawer.stop().animate({left:"-125px"},250);});$input.bind("change",function(){if(this.files.length){Stitches.pub("page.drop.done",this.files);}$cabinet.trigger("reset");});$drawer.delegate("a.open-options","click",function(){$options.fadeIn();});},bindOptions:function(){var $options=Stitches.Page.$options;var buttons=Stitches.Page.buttons;$options.delegate("a.close-options","click",function(){$options.fadeOut();});$options.delegate("input","change",function(){buttons.$sprite.addClass("disabled");buttons.$stylesheet.addClass("disabled");});$options.delegate("input[name=prefix]","change",function(){Stitches.settings.prefix=Stitches.Page.inputs.$prefix.val();});$options.delegate("input[name=padding]","change",function(){var padding=Stitches.Page.inputs.$padding.val();Stitches.settings.padding=+padding;Stitches.Page.updateIconDimensions();});$options.delegate("input[name=dataURI]","change",function(){var dataURI=Stitches.Page.inputs.$dataURI.filter(":checked").val();Stitches.settings.dataURI=dataURI==="true"?true:false;});},_generate:function(e){Stitches.pub("sprite.generate",[].concat(Stitches.iconQueue));},_removeFile:function(e){var icon=$(this).parent("li").data("icon");Stitches.pub("file.unqueue",icon);},_removeAllFiles:function(e){Stitches.pub("file.unqueue.all");},addIcon:function(icon){$(Stitches.Page.templates.icon(icon)).data("icon",icon).appendTo(Stitches.Page.$filelist).fadeIn("fast");},removeIcon:function(icon){Stitches.Page.$filelist.find("li").filter(function(){return $(this).data("icon")===icon;}).fadeOut("fast").remove();},updateIconDimensions:function(){var padding=Stitches.setting.padding;$.each(Stitches.iconQueue,function(i,icon){icon.width=icon.image.width+padding;icon.height=icon.image.height+padding;});}};})();})(window,Stitches,jQuery);(function(window,Stitches,$){Stitches.File=(function(){var readQueue=[];return{queueFiles:function(files){$.each(files,function(i,file){if(/jpeg|png|gif/.test(file.type)){readQueue.push(file);Stitches.pub("file.queue.done",file);}});},queueIcons:function(){var file,reader;file=readQueue.shift();if(file){try{reader=new FileReader();reader.onloadend=function(e){var icon=new Stitches.Icon(file.name,e.target.result);Stitches.iconQueue.push(icon);Stitches.pub("file.icon.done",icon);};reader.readAsDataURL(file);}catch(e){Stitches.pub("page.error",e);}}},unqueueIcon:function(icon){Stitches.iconQueue=$.grep(Stitches.iconQueue,function(item){return item!==icon;});Stitches.Icon.clearNameCache(icon.name);Stitches.pub("file.remove.done",icon);},unqueueAllIcons:function(){$.each(Stitches.iconQueue,function(i,icon){Stitches.File.unqueueIcon(icon);});Stitches.Icon.clearNameCache();}};})();})(window,Stitches,jQuery);
View
13 build/js/stitches-0.4.12.js → build/js/stitches-0.4.13.js
@@ -774,6 +774,7 @@
$options.delegate("input[name=padding]", "change", function () {
var padding = Stitches.Page.inputs.$padding.val();
Stitches.settings.padding = +padding;
+ Stitches.Page.updateIconDimensions();
});
$options.delegate("input[name=dataURI]", "change", function () {
@@ -819,6 +820,18 @@
})
.fadeOut("fast")
.remove();
+ },
+
+ // ### updateIconDimensions
+ //
+ // Update icon dimensions after changing padding setting
+ updateIconDimensions: function () {
+ var padding = Stitches.setting.padding;
+
+ $.each(Stitches.iconQueue, function (i, icon) {
+ icon.width = icon.image.width + padding;
+ icon.height = icon.image.height + padding;
+ });
}
};
})();
View
BIN  dist/stitches-0.4.13.zip
Binary file not shown
View
13 docs/page.html
@@ -224,6 +224,7 @@
<span class="kd">var</span> <span class="nx">$options</span> <span class="o">=</span> <span class="nx">Stitches</span><span class="p">.</span><span class="nx">Page</span><span class="p">.</span><span class="nx">$options</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">buttons</span> <span class="o">=</span> <span class="nx">Stitches</span><span class="p">.</span><span class="nx">Page</span><span class="p">.</span><span class="nx">buttons</span><span class="p">;</span>
+ <span class="nx">$options</span><span class="p">.</span><span class="nx">delegate</span><span class="p">(</span><span class="s2">&quot;a.close-options&quot;</span><span class="p">,</span> <span class="s2">&quot;click&quot;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">$options</span><span class="p">.</span><span class="nx">fadeOut</span><span class="p">();</span>
<span class="p">});</span>
@@ -269,6 +270,18 @@
<p>Add an icon to the file list
@param {Icon} icon</p> </td> <td class="code"> <div class="highlight"><pre>
+ <span class="nx">addIcon</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">icon</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">$</span><span class="p">(</span><span class="nx">Stitches</span><span class="p">.</span><span class="nx">Page</span><span class="p">.</span><span class="nx">templates</span><span class="p">.</span><span class="nx">icon</span><span class="p">(</span><span class="nx">icon</span><span class="p">))</span>
+ <span class="p">.</span><span class="nx">data</span><span class="p">(</span><span class="s2">&quot;icon&quot;</span><span class="p">,</span> <span class="nx">icon</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">appendTo</span><span class="p">(</span><span class="nx">Stitches</span><span class="p">.</span><span class="nx">Page</span><span class="p">.</span><span class="nx">$filelist</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">fadeIn</span><span class="p">(</span><span class="s2">&quot;fast&quot;</span><span class="p">);</span>
+ <span class="p">},</span>
+
+
+</pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <h3>removeIcon</h3>
+
+<p>Remove an icon from the file list
+ @param {Icon} icon</p> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">removeIcon</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">icon</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">Stitches</span><span class="p">.</span><span class="nx">Page</span><span class="p">.</span><span class="nx">$filelist</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">&quot;li&quot;</span><span class="p">)</span>
<span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
View
13 src/page.js
@@ -225,6 +225,7 @@
$options.delegate("input[name=padding]", "change", function () {
var padding = Stitches.Page.inputs.$padding.val();
Stitches.settings.padding = +padding;
+ Stitches.Page.updateIconDimensions();
});
$options.delegate("input[name=dataURI]", "change", function () {
@@ -270,6 +271,18 @@
})
.fadeOut("fast")
.remove();
+ },
+
+ // ### updateIconDimensions
+ //
+ // Update icon dimensions after changing padding setting
+ updateIconDimensions: function () {
+ var padding = Stitches.setting.padding;
+
+ $.each(Stitches.iconQueue, function (i, icon) {
+ icon.width = icon.image.width + padding;
+ icon.height = icon.image.height + padding;
+ });
}
};
})();
Please sign in to comment.
Something went wrong with that request. Please try again.