function ff_getnatural_width(domelement){if(undefined!=domelement.naturalwidth){return domelement.naturalwidth;} var img=new image();img.src=domelement.src;return img.width;} function ff_getnatural_height(domelement){if(undefined!=domelement.naturalheight){return domelement.naturalheight;} var img=new image();img.src=domelement.src;return img.height;} (function(){var root=(typeof exports=='undefined'?window:exports);var config={check_mime_type:true};root.retina=retina;function retina(){} retina.configure=function(options){if(options==null)options={};for(var prop in options)config[prop]=options[prop];};retina.init=function(context){if(context==null)context=root;var existing_onload=context.onload||new function;context.onload=function(){var images=document.getelementsbytagname("img"),retinaimages=[],i,image;for(i=0;i1) return true;if(root.matchmedia&&root.matchmedia(mediaquery).matches) return true;return false;};root.retinaimagepath=retinaimagepath;function retinaimagepath(path,at_2x_path){this.path=path;if(typeof at_2x_path!=="undefined"&&at_2x_path!==null){this.at_2x_path=at_2x_path;this.perform_check=false;}else{this.at_2x_path=path.replace(/\.\w+$/,function(match){return"@2x"+match;});this.perform_check=true;}} retinaimagepath.confirmed_paths=[];retinaimagepath.prototype.is_external=function(){return!!(this.path.match(/^https?\:/i)&&!this.path.match('//'+document.domain))} retinaimagepath.prototype.check_2x_variant=function(callback){var http,that=this;if(this.is_external()){return callback(false);}else if(!this.perform_check&&typeof this.at_2x_path!=="undefined"&&this.at_2x_path!==null){return callback(true);}else if(this.at_2x_path in retinaimagepath.confirmed_paths){return callback(true);}else{http=new xmlhttprequest;http.open('head',this.at_2x_path);http.onreadystatechange=function(){if(http.readystate!=4){return callback(false);} if(http.status>=200&&http.status<=399){if(config.check_mime_type){var type=http.getresponseheader('content-type');if(type==null||!type.match(/^image/i)){return callback(false);}} retinaimagepath.confirmed_paths.push(that.at_2x_path);return callback(true);}else{return callback(false);}} http.send();}} function retinaimage(el){this.el=el;this.path=new retinaimagepath(this.el.getattribute('src'),this.el.getattribute('data-at2x'));var that=this;this.path.check_2x_variant(function(hasvariant){if(hasvariant)that.swap();});} root.retinaimage=retinaimage;retinaimage.prototype.swap=function(path){if(typeof path=='undefined')path=this.path.at_2x_path;var that=this;function load(){if(!that.el.complete){settimeout(load,5);}else{if(that.el.getattribute('data-disable-retina-attrs-resize')!='false'){var w=ff_getnatural_width(that.el);var h=ff_getnatural_height(that.el);that.el.setattribute('width',(1*w)?w:'');that.el.setattribute('height',(1*h)?h:'');} that.el.setattribute('src',path);}} load();};if(retina.isretina()){retina.init(root);}})();