diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a8cf56..9efccab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog -### 0.2.0 (November 24th, 2013) +### 0.3.1 (January 23rd, 2014) + +* Enabled polyfill to initialize after load when being fetched asynchronously + +### 0.3.0 (November 24th, 2013) * Initial Release diff --git a/bower.json b/bower.json index c41c329..13030a2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "object-fit", - "version": "0.3.0", + "version": "0.3.1", "main": "polyfill.object-fit.js", "ignore": [ "**/.*", diff --git a/dist/polyfill.object-fit.css b/dist/polyfill.object-fit.css index 676433f..f3060e3 100644 --- a/dist/polyfill.object-fit.css +++ b/dist/polyfill.object-fit.css @@ -4,7 +4,7 @@ * * @author: Anselm Hannemann * @author: Christian "Schepp" Schaefer - * @version: 0.3.0 + * @version: 0.3.1 * */ diff --git a/dist/polyfill.object-fit.js b/dist/polyfill.object-fit.js index a00ced3..b2c22a4 100644 --- a/dist/polyfill.object-fit.js +++ b/dist/polyfill.object-fit.js @@ -194,7 +194,7 @@ * * @author: Anselm Hannemann * @author: Christian "Schepp" Schaefer - * @version: 0.3.0 + * @version: 0.3.1 * */ @@ -543,15 +543,21 @@ if (objectFit._debug && window.console) { console.log('object-fit not natively supported'); } - if (window.addEventListener) { - window.addEventListener('load', function(){ - objectFit.init(args); - }, false); - } else { - window.attachEvent('onload', function(){ - objectFit.init(args); - }); - } + // If the library is loaded after document onload event + if(document.readyState === 'complete') { + objectFit.init(args); + } else { + // Otherwise attach event listeners + if (window.addEventListener) { + window.addEventListener('load', function(){ + objectFit.init(args); + }, false); + } else { + window.attachEvent('onload', function(){ + objectFit.init(args); + }); + } + } } else { if (objectFit._debug && window.console) { console.log('object-fit natively supported'); diff --git a/dist/polyfill.object-fit.min.js b/dist/polyfill.object-fit.min.js index 72317a5..22aed53 100644 --- a/dist/polyfill.object-fit.min.js +++ b/dist/polyfill.object-fit.min.js @@ -1 +1 @@ -"use strict";!function(){if("function"!=typeof window.getMatchedCSSRules){var ELEMENT_RE=/[\w-]+/g,ID_RE=/#[\w-]+/g,CLASS_RE=/\.[\w-]+/g,ATTR_RE=/\[[^\]]+\]/g,PSEUDO_CLASSES_RE=/\:(?!not)[\w-]+(\(.*\))?/g,PSEUDO_ELEMENTS_RE=/\:\:?(after|before|first-letter|first-line|selection)/g,toArray=function(list){var items=[];for(var i in list)items.push(list[i]);return items},getSheetRules=function(stylesheet){var sheet_media=stylesheet.media&&stylesheet.media.mediaText;return stylesheet.disabled?[]:sheet_media&&sheet_media.length&&!window.matchMedia(sheet_media).matches?[]:toArray(stylesheet.cssRules)},_find=function(string,re){string.match(re);return re?re.length:0},calculateScore=function(selector){for(var part,match,score=[0,0,0],parts=selector.split(" ");part=parts.shift(),"string"==typeof part;)match=_find(part,PSEUDO_ELEMENTS_RE),score[2]=match,match&&(part=part.replace(PSEUDO_ELEMENTS_RE,"")),match=_find(part,PSEUDO_CLASSES_RE),score[1]=match,match&&(part=part.replace(PSEUDO_CLASSES_RE,"")),match=_find(part,ATTR_RE),score[1]+=match,match&&(part=part.replace(ATTR_RE,"")),match=_find(part,ID_RE),score[0]=match,match&&(part=part.replace(ID_RE,"")),match=_find(part,CLASS_RE),score[1]+=match,match&&(part=part.replace(CLASS_RE,"")),score[2]+=_find(part,ELEMENT_RE);return parseInt(score.join(""),10)},getSpecificityScore=function(element,selector_text){for(var selector,score,selectors=selector_text.split(","),result=0;selector=selectors.shift();)(element.mozMatchesSelector&&element.mozMatchesSelector(selector)||element.msMatchesSelector&&element.msMatchesSelector(selector)||element.oMatchesSelector&&element.oMatchesSelector(selector)||element.webkitMatchesSelector&&element.webkitMatchesSelector(selector))&&(score=calculateScore(selector),result=score>result?score:result);return result},sortBySpecificity=function(element,rules){function compareSpecificity(a,b){return getSpecificityScore(element,b.selectorText)-getSpecificityScore(element,a.selectorText)}return rules.sort(compareSpecificity)};window.getMatchedCSSRules=function(element){var style_sheets,sheet,rules,rule,result=[];for(style_sheets=toArray(window.document.styleSheets);sheet=style_sheets.shift();)for(rules=getSheetRules(sheet);rule=rules.shift();)rule.styleSheet?rules=getSheetRules(rule.styleSheet).concat(rules):rule.media?rules=getSheetRules(rule).concat(rules):(element.mozMatchesSelector&&element.mozMatchesSelector(rule.selectorText)||element.msMatchesSelector&&element.msMatchesSelector(rule.selectorText)||element.oMatchesSelector&&element.oMatchesSelector(rule.selectorText)||element.webkitMatchesSelector&&element.webkitMatchesSelector(rule.selectorText))&&result.push(rule);return sortBySpecificity(element,result)}}}(),function(){for(var lastTime=0,vendors=["webkit","moz"],x=0;x"),iframe.contentWindow.document.body.appendChild(newelement),iframe.contentWindow.document.close();var defaultElement=iframe.contentWindow.document.querySelectorAll(element.nodeName.toLowerCase())[0],defaultComputedStyle=this.getComputedStyle(defaultElement,iframe.contentWindow);for(var property in defaultComputedStyle){var value=defaultComputedStyle.getPropertyValue?defaultComputedStyle.getPropertyValue(property):defaultComputedStyle[property];if(null!==value)switch(property){default:styles[property]=value;break;case"width":case"height":case"minWidth":case"minHeight":case"maxWidth":case"maxHeight":}}return document.body.removeChild(iframe),styles},objectFit.getMatchedStyle=function(element,property){var val=null,inlineval=null;element.style.getPropertyValue?inlineval=element.style.getPropertyValue(property):element.currentStyle&&(inlineval=element.currentStyle[property]);var rules=window.getMatchedCSSRules(element);if(rules.length)for(var i=rules.length;i-->0;){var r=rules[i],important=r.style.getPropertyPriority(property);if((null===val||important)&&(val=r.style.getPropertyValue(property),important))break}return val||null===inlineval||(val=inlineval),val},objectFit.orientation=function(replacedElement){if(replacedElement.parentNode&&"x-object-fit"===replacedElement.parentNode.nodeName.toLowerCase()){var width=replacedElement.naturalWidth||replacedElement.clientWidth,height=replacedElement.naturalHeight||replacedElement.clientHeight,parentWidth=replacedElement.parentNode.clientWidth,parentHeight=replacedElement.parentNode.clientHeight;!height||width/height>parentWidth/parentHeight?"wider"!==replacedElement.getAttribute("data-x-object-relation")&&(replacedElement.setAttribute("data-x-object-relation","wider"),replacedElement.className="x-object-fit-wider",this._debug&&window.console&&console.log("x-object-fit-wider")):"taller"!==replacedElement.getAttribute("data-x-object-relation")&&(replacedElement.setAttribute("data-x-object-relation","taller"),replacedElement.className="x-object-fit-taller",this._debug&&window.console&&console.log("x-object-fit-taller"))}},objectFit.process=function(args){if(args.selector&&args.replacedElements){switch(args.fittype=args.fittype||"none",args.fittype){default:return;case"none":case"fill":case"contain":case"cover":}var replacedElements=args.replacedElements;if(replacedElements.length)for(var i=0,replacedElementsLength=replacedElements.length;replacedElementsLength>i;i++)this.processElement(replacedElements[i],args)}},objectFit.processElement=function(replacedElement,args){var property,value,replacedElementStyles=objectFit.getComputedStyle(replacedElement),replacedElementDefaultStyles=objectFit.getDefaultComputedStyle(replacedElement),wrapperElement=document.createElement("x-object-fit");objectFit._debug&&window.console&&console.log("Applying to WRAPPER-------------------------------------------------------");for(property in replacedElementStyles)switch(property){default:value=objectFit.getMatchedStyle(replacedElement,property),null!==value&&""!==value&&(objectFit._debug&&window.console&&console.log(property+": "+value),wrapperElement.style[property]=value);break;case"length":case"parentRule":}objectFit._debug&&window.console&&console.log("Applying to REPLACED ELEMENT-------------------------------------------------------");for(property in replacedElementDefaultStyles)switch(property){default:value=replacedElementDefaultStyles[property],objectFit._debug&&window.console&&""!==value&&console.log(property+": "+value),replacedElement.style[property]=value;break;case"length":case"parentRule":}wrapperElement.setAttribute("class","x-object-fit-"+args.fittype),replacedElement.parentNode.insertBefore(wrapperElement,replacedElement),wrapperElement.appendChild(replacedElement),objectFit.orientation(replacedElement);var resizeTimer=null,resizeAction=function(){null!==resizeTimer&&window.cancelAnimationFrame(resizeTimer),resizeTimer=window.requestAnimationFrame(function(){objectFit.orientation(replacedElement)})};switch(args.fittype){default:break;case"contain":case"cover":window.addEventListener?(replacedElement.addEventListener("load",resizeAction,!1),window.addEventListener("resize",resizeAction,!1),window.addEventListener("orientationchange",resizeAction,!1)):(replacedElement.attachEvent("onload",resizeAction),window.attachEvent("onresize",resizeAction))}},objectFit.listen=function(args){var domInsertedAction=function(element){for(var i=0,argsLength=args.length;argsLength>i;i++)(element.mozMatchesSelector&&element.mozMatchesSelector(args[i].selector)||element.msMatchesSelector&&element.msMatchesSelector(args[i].selector)||element.oMatchesSelector&&element.oMatchesSelector(args[i].selector)||element.webkitMatchesSelector&&element.webkitMatchesSelector(args[i].selector))&&(args[i].replacedElements=[element],objectFit.process(args[i]),objectFit._debug&&window.console&&console.log("Matching node inserted: "+element.nodeName))},domInsertedObserverFunction=function(element){objectFit.observer.disconnect(),domInsertedAction(element),objectFit.observer.observe(document.documentElement,{childList:!0,subtree:!0})},domInsertedEventFunction=function(event){window.removeEventListener("DOMNodeInserted",domInsertedEventFunction,!1),domInsertedAction(event.target),window.addEventListener("DOMNodeInserted",domInsertedEventFunction,!1)},domRemovedAction=function(element){"x-object-fit"===element.nodeName.toLowerCase()&&(element.parentNode.removeChild(element),objectFit._debug&&window.console&&console.log("Matching node removed: "+element.nodeName))},domRemovedObserverFunction=function(element){objectFit.observer.disconnect(),domRemovedAction(element),objectFit.observer.observe(document.documentElement,{childList:!0,subtree:!0})},domRemovedEventFunction=function(event){window.removeEventListener("DOMNodeRemoved",domRemovedEventFunction,!1),domRemovedAction(event.target.parentNode),window.addEventListener("DOMNodeRemoved",domRemovedEventFunction,!1)};window.MutationObserver?(objectFit._debug&&window.console&&console.log("DOM MutationObserver"),this.observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.addedNodes&&mutation.addedNodes.length)for(var nodes=mutation.addedNodes,i=0,nodesLength=nodes.length;nodesLength>i;i++)domInsertedObserverFunction(nodes[i]);mutation.removedNodes&&mutation.removedNodes.length&&domRemovedObserverFunction(mutation.target)})}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0})):window.addEventListener&&(objectFit._debug&&window.console&&console.log("DOM Mutation Events"),window.addEventListener("DOMNodeInserted",domInsertedEventFunction,!1),window.addEventListener("DOMNodeRemoved",domRemovedEventFunction,!1))},objectFit.init=function(args){if(args){"Array"!=typeof args&&(args=[args]);for(var i=0,argsLength=args.length;argsLength>i;i++)args[i].replacedElements=document.querySelectorAll(args[i].selector),this.process(args[i]);this.listen(args)}},objectFit.polyfill=function(args){"objectFit"in document.documentElement.style==!1?(objectFit._debug&&window.console&&console.log("object-fit not natively supported"),window.addEventListener?window.addEventListener("load",function(){objectFit.init(args)},!1):window.attachEvent("onload",function(){objectFit.init(args)})):objectFit._debug&&window.console&&console.log("object-fit natively supported")},global.objectFit=objectFit}(window); \ No newline at end of file +"use strict";!function(){if("function"!=typeof window.getMatchedCSSRules){var ELEMENT_RE=/[\w-]+/g,ID_RE=/#[\w-]+/g,CLASS_RE=/\.[\w-]+/g,ATTR_RE=/\[[^\]]+\]/g,PSEUDO_CLASSES_RE=/\:(?!not)[\w-]+(\(.*\))?/g,PSEUDO_ELEMENTS_RE=/\:\:?(after|before|first-letter|first-line|selection)/g,toArray=function(list){var items=[];for(var i in list)items.push(list[i]);return items},getSheetRules=function(stylesheet){var sheet_media=stylesheet.media&&stylesheet.media.mediaText;return stylesheet.disabled?[]:sheet_media&&sheet_media.length&&!window.matchMedia(sheet_media).matches?[]:toArray(stylesheet.cssRules)},_find=function(string,re){string.match(re);return re?re.length:0},calculateScore=function(selector){for(var part,match,score=[0,0,0],parts=selector.split(" ");part=parts.shift(),"string"==typeof part;)match=_find(part,PSEUDO_ELEMENTS_RE),score[2]=match,match&&(part=part.replace(PSEUDO_ELEMENTS_RE,"")),match=_find(part,PSEUDO_CLASSES_RE),score[1]=match,match&&(part=part.replace(PSEUDO_CLASSES_RE,"")),match=_find(part,ATTR_RE),score[1]+=match,match&&(part=part.replace(ATTR_RE,"")),match=_find(part,ID_RE),score[0]=match,match&&(part=part.replace(ID_RE,"")),match=_find(part,CLASS_RE),score[1]+=match,match&&(part=part.replace(CLASS_RE,"")),score[2]+=_find(part,ELEMENT_RE);return parseInt(score.join(""),10)},getSpecificityScore=function(element,selector_text){for(var selector,score,selectors=selector_text.split(","),result=0;selector=selectors.shift();)(element.mozMatchesSelector&&element.mozMatchesSelector(selector)||element.msMatchesSelector&&element.msMatchesSelector(selector)||element.oMatchesSelector&&element.oMatchesSelector(selector)||element.webkitMatchesSelector&&element.webkitMatchesSelector(selector))&&(score=calculateScore(selector),result=score>result?score:result);return result},sortBySpecificity=function(element,rules){function compareSpecificity(a,b){return getSpecificityScore(element,b.selectorText)-getSpecificityScore(element,a.selectorText)}return rules.sort(compareSpecificity)};window.getMatchedCSSRules=function(element){var style_sheets,sheet,rules,rule,result=[];for(style_sheets=toArray(window.document.styleSheets);sheet=style_sheets.shift();)for(rules=getSheetRules(sheet);rule=rules.shift();)rule.styleSheet?rules=getSheetRules(rule.styleSheet).concat(rules):rule.media?rules=getSheetRules(rule).concat(rules):(element.mozMatchesSelector&&element.mozMatchesSelector(rule.selectorText)||element.msMatchesSelector&&element.msMatchesSelector(rule.selectorText)||element.oMatchesSelector&&element.oMatchesSelector(rule.selectorText)||element.webkitMatchesSelector&&element.webkitMatchesSelector(rule.selectorText))&&result.push(rule);return sortBySpecificity(element,result)}}}(),function(){for(var lastTime=0,vendors=["webkit","moz"],x=0;x"),iframe.contentWindow.document.body.appendChild(newelement),iframe.contentWindow.document.close();var defaultElement=iframe.contentWindow.document.querySelectorAll(element.nodeName.toLowerCase())[0],defaultComputedStyle=this.getComputedStyle(defaultElement,iframe.contentWindow);for(var property in defaultComputedStyle){var value=defaultComputedStyle.getPropertyValue?defaultComputedStyle.getPropertyValue(property):defaultComputedStyle[property];if(null!==value)switch(property){default:styles[property]=value;break;case"width":case"height":case"minWidth":case"minHeight":case"maxWidth":case"maxHeight":}}return document.body.removeChild(iframe),styles},objectFit.getMatchedStyle=function(element,property){var val=null,inlineval=null;element.style.getPropertyValue?inlineval=element.style.getPropertyValue(property):element.currentStyle&&(inlineval=element.currentStyle[property]);var rules=window.getMatchedCSSRules(element);if(rules.length)for(var i=rules.length;i-->0;){var r=rules[i],important=r.style.getPropertyPriority(property);if((null===val||important)&&(val=r.style.getPropertyValue(property),important))break}return val||null===inlineval||(val=inlineval),val},objectFit.orientation=function(replacedElement){if(replacedElement.parentNode&&"x-object-fit"===replacedElement.parentNode.nodeName.toLowerCase()){var width=replacedElement.naturalWidth||replacedElement.clientWidth,height=replacedElement.naturalHeight||replacedElement.clientHeight,parentWidth=replacedElement.parentNode.clientWidth,parentHeight=replacedElement.parentNode.clientHeight;!height||width/height>parentWidth/parentHeight?"wider"!==replacedElement.getAttribute("data-x-object-relation")&&(replacedElement.setAttribute("data-x-object-relation","wider"),replacedElement.className="x-object-fit-wider",this._debug&&window.console&&console.log("x-object-fit-wider")):"taller"!==replacedElement.getAttribute("data-x-object-relation")&&(replacedElement.setAttribute("data-x-object-relation","taller"),replacedElement.className="x-object-fit-taller",this._debug&&window.console&&console.log("x-object-fit-taller"))}},objectFit.process=function(args){if(args.selector&&args.replacedElements){switch(args.fittype=args.fittype||"none",args.fittype){default:return;case"none":case"fill":case"contain":case"cover":}var replacedElements=args.replacedElements;if(replacedElements.length)for(var i=0,replacedElementsLength=replacedElements.length;replacedElementsLength>i;i++)this.processElement(replacedElements[i],args)}},objectFit.processElement=function(replacedElement,args){var property,value,replacedElementStyles=objectFit.getComputedStyle(replacedElement),replacedElementDefaultStyles=objectFit.getDefaultComputedStyle(replacedElement),wrapperElement=document.createElement("x-object-fit");objectFit._debug&&window.console&&console.log("Applying to WRAPPER-------------------------------------------------------");for(property in replacedElementStyles)switch(property){default:value=objectFit.getMatchedStyle(replacedElement,property),null!==value&&""!==value&&(objectFit._debug&&window.console&&console.log(property+": "+value),wrapperElement.style[property]=value);break;case"length":case"parentRule":}objectFit._debug&&window.console&&console.log("Applying to REPLACED ELEMENT-------------------------------------------------------");for(property in replacedElementDefaultStyles)switch(property){default:value=replacedElementDefaultStyles[property],objectFit._debug&&window.console&&""!==value&&console.log(property+": "+value),replacedElement.style[property]=value;break;case"length":case"parentRule":}wrapperElement.setAttribute("class","x-object-fit-"+args.fittype),replacedElement.parentNode.insertBefore(wrapperElement,replacedElement),wrapperElement.appendChild(replacedElement),objectFit.orientation(replacedElement);var resizeTimer=null,resizeAction=function(){null!==resizeTimer&&window.cancelAnimationFrame(resizeTimer),resizeTimer=window.requestAnimationFrame(function(){objectFit.orientation(replacedElement)})};switch(args.fittype){default:break;case"contain":case"cover":window.addEventListener?(replacedElement.addEventListener("load",resizeAction,!1),window.addEventListener("resize",resizeAction,!1),window.addEventListener("orientationchange",resizeAction,!1)):(replacedElement.attachEvent("onload",resizeAction),window.attachEvent("onresize",resizeAction))}},objectFit.listen=function(args){var domInsertedAction=function(element){for(var i=0,argsLength=args.length;argsLength>i;i++)(element.mozMatchesSelector&&element.mozMatchesSelector(args[i].selector)||element.msMatchesSelector&&element.msMatchesSelector(args[i].selector)||element.oMatchesSelector&&element.oMatchesSelector(args[i].selector)||element.webkitMatchesSelector&&element.webkitMatchesSelector(args[i].selector))&&(args[i].replacedElements=[element],objectFit.process(args[i]),objectFit._debug&&window.console&&console.log("Matching node inserted: "+element.nodeName))},domInsertedObserverFunction=function(element){objectFit.observer.disconnect(),domInsertedAction(element),objectFit.observer.observe(document.documentElement,{childList:!0,subtree:!0})},domInsertedEventFunction=function(event){window.removeEventListener("DOMNodeInserted",domInsertedEventFunction,!1),domInsertedAction(event.target),window.addEventListener("DOMNodeInserted",domInsertedEventFunction,!1)},domRemovedAction=function(element){"x-object-fit"===element.nodeName.toLowerCase()&&(element.parentNode.removeChild(element),objectFit._debug&&window.console&&console.log("Matching node removed: "+element.nodeName))},domRemovedObserverFunction=function(element){objectFit.observer.disconnect(),domRemovedAction(element),objectFit.observer.observe(document.documentElement,{childList:!0,subtree:!0})},domRemovedEventFunction=function(event){window.removeEventListener("DOMNodeRemoved",domRemovedEventFunction,!1),domRemovedAction(event.target.parentNode),window.addEventListener("DOMNodeRemoved",domRemovedEventFunction,!1)};window.MutationObserver?(objectFit._debug&&window.console&&console.log("DOM MutationObserver"),this.observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.addedNodes&&mutation.addedNodes.length)for(var nodes=mutation.addedNodes,i=0,nodesLength=nodes.length;nodesLength>i;i++)domInsertedObserverFunction(nodes[i]);mutation.removedNodes&&mutation.removedNodes.length&&domRemovedObserverFunction(mutation.target)})}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0})):window.addEventListener&&(objectFit._debug&&window.console&&console.log("DOM Mutation Events"),window.addEventListener("DOMNodeInserted",domInsertedEventFunction,!1),window.addEventListener("DOMNodeRemoved",domRemovedEventFunction,!1))},objectFit.init=function(args){if(args){"Array"!=typeof args&&(args=[args]);for(var i=0,argsLength=args.length;argsLength>i;i++)args[i].replacedElements=document.querySelectorAll(args[i].selector),this.process(args[i]);this.listen(args)}},objectFit.polyfill=function(args){"objectFit"in document.documentElement.style==!1?(objectFit._debug&&window.console&&console.log("object-fit not natively supported"),"complete"===document.readyState?objectFit.init(args):window.addEventListener?window.addEventListener("load",function(){objectFit.init(args)},!1):window.attachEvent("onload",function(){objectFit.init(args)})):objectFit._debug&&window.console&&console.log("object-fit natively supported")},global.objectFit=objectFit}(window); \ No newline at end of file diff --git a/package.json b/package.json index 66219ad..4856382 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "object-fit", "title": "object-fit polyfill", "description": "Polyfill for the CSS object-fit property to fit images into containers", - "version": "0.3.0", + "version": "0.3.1", "homepage": "https://github.com/anselmh/object-fit", "repository": { "type": "git", diff --git a/src/polyfill.object-fit.core.js b/src/polyfill.object-fit.core.js index 1392dd0..3417f7f 100644 --- a/src/polyfill.object-fit.core.js +++ b/src/polyfill.object-fit.core.js @@ -353,15 +353,21 @@ if (objectFit._debug && window.console) { console.log('object-fit not natively supported'); } - if (window.addEventListener) { - window.addEventListener('load', function(){ - objectFit.init(args); - }, false); - } else { - window.attachEvent('onload', function(){ - objectFit.init(args); - }); - } + // If the library is loaded after document onload event + if(document.readyState === 'complete') { + objectFit.init(args); + } else { + // Otherwise attach event listeners + if (window.addEventListener) { + window.addEventListener('load', function(){ + objectFit.init(args); + }, false); + } else { + window.attachEvent('onload', function(){ + objectFit.init(args); + }); + } + } } else { if (objectFit._debug && window.console) { console.log('object-fit natively supported');