diff --git a/ajax/libs/rimg/0.9.0/rimg.js b/ajax/libs/rimg/0.9.0/rimg.js new file mode 100644 index 000000000..69b4de786 --- /dev/null +++ b/ajax/libs/rimg/0.9.0/rimg.js @@ -0,0 +1,420 @@ +'use strict'; + +!function(){ + if(!console){ + console = { + log: function(){}, + error: function(){} + } + } + + var Rimg = function() { + var hidden = { + status : 'init', + observer : null, + breakpoints : [], + resizeWait: null, + resizeDimensions: '', + disableIntrospection: false + }; + + function parseBreakpoints(value){ + //custom: (once) -small 640w 1x, -retina-small 640w 2x, -medium 1280w 1x, -retina-medium 1280w 2x + //custom: (per image) data-src="image.jpg" + if(typeof value === 'string'){ + var breakpoints = value.split(','); + if(breakpoints.length === 0){ + //invalid + hidden.status = 'error'; + console.error('Rimg: your breakpoint-definition '+ value +' is invalid, check the documentation.'); + return null; + } + var definition = []; + var i = 0; + var il = breakpoints.length; + while(i 0){ + return definition; + }else{ + hidden.status = 'error'; + console.error('Rimg: your breakpoint-definition misses valid breakpoints, check the documentation.'); + return null; + } + }else{ + //invalid + hidden.status = 'error'; + console.error('Rimg: your breakpoint-definition is not a String, check the documentation.'); + return null; + } + } + + //discover initial settings + if(typeof window.RimgBreakpoint !== 'undefined'){ + //validate + var bpts = parseBreakpoints(RimgBreakpoint); + if(bpts !== null){ + hidden.breakpoints = bpts; + } + //clean reference + window.RimgBreakpoint = undefined; + }else{ + console.log('(remark) Rimg: no breakpoints defined, check the documentation.'); + return { + version: '0.4.1', + initialize: function(){} + } + } + + function event(type,evt,func,target){ + //add/remote event listeners + if(target === undefined){ + target = document; + } + if(evt === 'resize'){ + target = window; + } + if(type === 'add'){ + target.addEventListener(evt,func,false); + }else{ + target.removeEventListener(evt,func,false); + } + } + + function adjust(value){ + //change src property when appropriate + var ratio = window.devicePixelRatio || 1; + var data = value.getAttribute('data-src'); + if(data !== null){ + //only adjust images with data-src property + var file = data.substr(0,data.lastIndexOf('.')); + var extension = data.substr(data.lastIndexOf('.')); + var size = {x:value.width,y:value.height}; + //firefox presents width/height with 0, so check getComputedStyle if necessary: + if(value.width === 0){ + size.x = window.getComputedStyle(value,null).maxWidth; + size.x = size.x.replace('px',''); + size.x = Number(size.x); + } + if(value.height === 0){ + size.y = window.getComputedStyle(value,null).maxHeight; + size.y = size.y.replace('px',''); + size.y = Number(size.y); + } + var i = 0; + var il = hidden.breakpoints.length; + var breakpoint; + while(i 1){ + //find html node + var html; + if(target.childNodes[1].nodeName !== 'HTML'){ + //needed to skip HTML comments which are detected as nodes + var i = 0; + var il = target.childNodes.length; + while(i + html = target.childNodes[1]; + } + //find body node + if(html.childNodes[1].nodeName !== 'BODY'){ + var i = 0; + var il = html.childNodes.length; + while(i + inspect(html.childNodes[1]); + } + }else{ + console.error('Rimg.execute(): not a valid DOM representation, check your code.'); + } + }else{ + if(target !== undefined && target.nodeName !== undefined && target.nodeName.toLowerCase() === 'img'){ + //direct reference + inspect(target); + }else if(target[0] !== undefined && target[0].nodeName.toLowerCase() === 'img'){ + //child reference (after add) + inspect(target[0]); + }else{ + //no element found + } + } + }, + configure: function(value){ + var breakpoints = parseBreakpoints(value); + if(breakpoints !== null){ + hidden.breakpoints = breakpoints; + } + + if(hidden.status === 'ready' && !hidden.disableIntrospection){ + //if DOM loaded, execute right away + this.execute(document); + } + }, + resized: function(e){ + if(hidden.status !== 'ready'){ + //not available anymore + return; + } + + //cleanup + if(hidden.resizeWait !== null){ + clearInterval(hidden.resizeWait); + } + + if(hidden.time === undefined || new Date().getTime() - hidden.time > 1000){ + resize.bind(this)(); + }else{ + //wait 100ms to ensure performant and not a blocking script execution + hidden.resizeWait = setInterval(resize.bind(this),100); + } + }, + loaded: function(e){ + if(hidden.status !== 'progress'){ + //not available anymore + return; + } + + //cleanup listener + event('remove','DOMContentLoaded',this.loaded); + + //initial DOM checkup + if(!hidden.disableIntrospection){ + // DOM content loaded + if (hidden.observer === null) { + //check the whole page before any changes happen + this.execute(e.target); + }else{ + hidden.observer.observe(document.body, { + attributes: true, + childList: true, + characterData: true, + subtree: true, + attributeFilter: ['data-src'] + }); + //check full DOM + this.execute(document); + } + + //listen for browser resize + event('add','resize',this.resized.bind(this)); + } + hidden.status = 'ready'; + }, + disableIntrospection: function(){ + hidden.disableIntrospection = true; + + //remove mutation listeners + if(hidden.observer){ + hidden.observer.disconnect(); + }else{ + event('remove','DOMNodeInserted',nodeInserted); + } + }, + initialize: function(){ + if(hidden.status !== 'init'){ + if(hidden.status !== 'error'){ + console.error('Rimg.initialize(): Already initialized. No forced initialization supported, check your code.'); + } + return; + } + + //listen for DOM & change events + var base = this; + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; + if (MutationObserver === undefined) { + event('add','DOMAttrModified',function(e){ + //DOM attribute modified, not supported in webkit + //TODO Safari 5.0+ MutationObserver support, Chrome 18 + }); + //TODO issues with IE9 - http://help.dottoro.com/ljmcxjla.php + event('add','DOMNodeInserted',nodeInserted.bind(base)); + event('add','DOMSubtreeModified',function(e){ + //TODO nothing? + //console.debug('Rimg:','DOM subtree modified',e.target); + }); + }else{ + hidden.observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if(mutation.addedNodes.length > 0){ + base.execute(mutation.addedNodes); + }else if(mutation.attributeName === 'data-src'){ + base.execute(mutation.target); + } + }); + }); + } + hidden.status = 'progress'; + + // wait until DOM is loaded + event('add','DOMContentLoaded',this.loaded.bind(this)); + } + }; + }; + + // browser + window.Rimg = Object.create(Rimg()); + // start listening + window.Rimg.initialize(); +}(); diff --git a/ajax/libs/rimg/0.9.0/rimg.min.js b/ajax/libs/rimg/0.9.0/rimg.min.js new file mode 100644 index 000000000..68bd88adb --- /dev/null +++ b/ajax/libs/rimg/0.9.0/rimg.min.js @@ -0,0 +1,2 @@ +/*! http://github.com/joeyvandijk/rimg/ - 2013-11-14 */ +"use strict";!function(){console||(console={log:function(){},error:function(){}});var Rimg=function(){function parseBreakpoints(value){if("string"==typeof value){var breakpoints=value.split(",");if(0===breakpoints.length)return hidden.status="error",console.error("Rimg: your breakpoint-definition "+value+" is invalid, check the documentation."),null;for(var definition=[],i=0,il=breakpoints.length;il>i;){for(var bp=breakpoints[i],bpDefinition={src:[],width:-1,height:-1,pixelRatio:[],getSrc:function(value){var ratios=this.pixelRatio.length;if(0===ratios)return hidden.status="error",console.error("Rimg: missing a pixelRatio definition, check the documentation."),"";if(1===ratios)return this.src[0];if(2===ratios)return 1>=value?this.src[0]:this.src[1];for(var s=0,sl=this.pixelRatio.length;sl>s;){if(value===this.pixelRatio[s]||Math.round(value)===this.pixelRatio[s])return this.src[s];s++}return this.src[ratios-1]}},parts=bp.split(" "),p=0,pl=parts.length;pl>p;){var part=parts[p];""===part.replace(" ","")||(null!==part.match(/^[0-9]{0,4}w/gi)?bpDefinition.width=Number(part.substr(0,part.length-1)):null!==part.match(/^[0-9]{0,4}h/gi)?bpDefinition.height=Number(part.substr(0,part.length-1)):null!==part.match(/[0-9]{1}x/gi)?bpDefinition.pixelRatio.push(Number(part.substr(0,part.length-1))):bpDefinition.src.push(part)),p++}for(var d=0,dl=definition.length,found=!1;dl>d;){var def=definition[d];if(def.width===bpDefinition.width&&-1!==def.width||def.height===bpDefinition.height&&-1!==def.height){def.pixelRatio.push(bpDefinition.pixelRatio[0]),def.src.push(bpDefinition.src[0]),found=!0;break}d++}found||definition.push(bpDefinition),i++}return definition.length>0?definition:(hidden.status="error",console.error("Rimg: your breakpoint-definition misses valid breakpoints, check the documentation."),null)}return hidden.status="error",console.error("Rimg: your breakpoint-definition is not a String, check the documentation."),null}function event(type,evt,func,target){void 0===target&&(target=document),"resize"===evt&&(target=window),"add"===type?target.addEventListener(evt,func,!1):target.removeEventListener(evt,func,!1)}function adjust(value){var ratio=window.devicePixelRatio||1,data=value.getAttribute("data-src");if(null!==data){var file=data.substr(0,data.lastIndexOf(".")),extension=data.substr(data.lastIndexOf(".")),size={x:value.width,y:value.height};0===value.width&&(size.x=window.getComputedStyle(value,null).maxWidth,size.x=size.x.replace("px",""),size.x=Number(size.x)),0===value.height&&(size.y=window.getComputedStyle(value,null).maxHeight,size.y=size.y.replace("px",""),size.y=Number(size.y));for(var breakpoint,i=0,il=hidden.breakpoints.length;il>i;){var bp=hidden.breakpoints[i],wd=size.x;if(size.xi;){var item=value.children[i];inspect(item),i++}}function resize(){clearInterval(hidden.resizeWait);var nw=window.innerWidth+"x"+window.innerHeight;hidden.resizeDimensions!==nw&&(hidden.resizeDimensions=nw,this.execute(document)),hidden.time=(new Date).getTime()}function nodeInserted(e){this.execute(e.target)}var hidden={status:"init",observer:null,breakpoints:[],resizeWait:null,resizeDimensions:"",disableIntrospection:!1};if("undefined"==typeof window.RimgBreakpoint)return console.log("(remark) Rimg: no breakpoints defined, check the documentation."),{version:"0.4.1",initialize:function(){}};var bpts=parseBreakpoints(RimgBreakpoint);return null!==bpts&&(hidden.breakpoints=bpts),window.RimgBreakpoint=void 0,{version:"0.9.0",execute:function(target){if("error"===hidden.status)return console.error("Rimg.execute(): error-status so no actions can be executed, check your code."),void 0;if(void 0===target)return console.error("Rimg.execute(): undefined value, check your code to add a valid DOM element to this function."),void 0;if("#document"===target.nodeName)if(target.childNodes.length>1){var html;if("HTML"!==target.childNodes[1].nodeName)for(var i=0,il=target.childNodes.length;il>i;){if("HTML"===target.childNodes[i].nodeName){html=target.childNodes[i];break}i++}else html=target.childNodes[1];if("BODY"!==html.childNodes[1].nodeName)for(var i=0,il=html.childNodes.length;il>i;){if("BODY"===html.childNodes[i].nodeName){inspect(html.childNodes[i]);break}i++}else inspect(html.childNodes[1])}else console.error("Rimg.execute(): not a valid DOM representation, check your code.");else void 0!==target&&void 0!==target.nodeName&&"img"===target.nodeName.toLowerCase()?inspect(target):void 0!==target[0]&&"img"===target[0].nodeName.toLowerCase()&&inspect(target[0])},configure:function(value){var breakpoints=parseBreakpoints(value);null!==breakpoints&&(hidden.breakpoints=breakpoints),"ready"!==hidden.status||hidden.disableIntrospection||this.execute(document)},resized:function(){"ready"===hidden.status&&(null!==hidden.resizeWait&&clearInterval(hidden.resizeWait),void 0===hidden.time||(new Date).getTime()-hidden.time>1e3?resize.bind(this)():hidden.resizeWait=setInterval(resize.bind(this),100))},loaded:function(e){"progress"===hidden.status&&(event("remove","DOMContentLoaded",this.loaded),hidden.disableIntrospection||(null===hidden.observer?this.execute(e.target):(hidden.observer.observe(document.body,{attributes:!0,childList:!0,characterData:!0,subtree:!0,attributeFilter:["data-src"]}),this.execute(document)),event("add","resize",this.resized.bind(this))),hidden.status="ready")},disableIntrospection:function(){hidden.disableIntrospection=!0,hidden.observer?hidden.observer.disconnect():event("remove","DOMNodeInserted",nodeInserted)},initialize:function(){if("init"!==hidden.status)return"error"!==hidden.status&&console.error("Rimg.initialize(): Already initialized. No forced initialization supported, check your code."),void 0;var base=this,MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;void 0===MutationObserver?(event("add","DOMAttrModified",function(){}),event("add","DOMNodeInserted",nodeInserted.bind(base)),event("add","DOMSubtreeModified",function(){})):hidden.observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){mutation.addedNodes.length>0?base.execute(mutation.addedNodes):"data-src"===mutation.attributeName&&base.execute(mutation.target)})}),hidden.status="progress",event("add","DOMContentLoaded",this.loaded.bind(this))}}};window.Rimg=Object.create(Rimg()),window.Rimg.initialize()}(); \ No newline at end of file diff --git a/ajax/libs/rimg/package.json b/ajax/libs/rimg/package.json index 98e6ea063..76d3db002 100755 --- a/ajax/libs/rimg/package.json +++ b/ajax/libs/rimg/package.json @@ -1,7 +1,7 @@ { "name": "rimg", "filename": "rimg.min.js", - "version": "0.4.1", + "version": "0.9.0", "description": "A responsive image solution for browsers that support mediaqueries. Pure javascript and no server-side code..", "keywords": [ "responsive",