-
Notifications
You must be signed in to change notification settings - Fork 1
/
devicr.min.js
2 lines (2 loc) · 6.19 KB
/
devicr.min.js
1
2
/*! devicr 18-08-2014 */
function ArrayIntersect(){}function Backgroundr(a){this.source_selector=a}function Devicr(a){this.source_selector=a}function DevicrDevice(a,b){this.device=a,this.screen_device=b}function DevicrElement(a){this.devices=["retina","desktop","tablet","mobile"],this.element=a,this.element.removeAttribute("src"),this.getHigherDevices=function(a){var b=this.devices.indexOf(a),c=[];if(b>0)for(var d=0;b>d;d++)c[d]=this.devices[d];return c}}function DevicrSourceFinder(a){this.devicr_device=a}function DevicrSourceSelector(a,b){this.device=a,this.finder=b}function RibbonSourceSelector(a,b){this.device=a,this.finder=b}function ScreenDevice(){}function StreamrSourceSelector(a,b){this.device=a,this.finder=b}ArrayIntersect.intersect=function(a,b){for(var c=0,d=0,e=[];c<a.length&&d<b.length;)a[c]<b[d]?c++:a[c]>b[d]?d++:(e.push(a[c]),c++,d++);return e},Backgroundr.prototype.adapt=function(a){var b=this.source_selector.getBestSourceFor(a);a.replaceBackgroundSourceBy(b)},Devicr.prototype.adapt=function(a){var b=this.source_selector.getBestSourceFor(a);a.replaceSourceLoadedBy(b)},DevicrDevice.prototype.getDevice=function(){return this.device},DevicrDevice.prototype.isMobile=function(){return"mobile"===this.device},DevicrDevice.prototype.isTablet=function(){return"tablet"===this.device},DevicrDevice.prototype.isDesktop=function(){return"desktop"===this.device},DevicrDevice.prototype.isATabletWithBigScreen=function(){return this.isTablet()&&this.screen_device.getWidth()>750},DevicrDevice.prototype.isInLandscapeMode=function(){return this.screen_device.getHeight()<this.screen_device.getWidth()},DevicrDevice.prototype.isInPortraitMode=function(){return this.screen_device.getHeight()>=this.screen_device.getWidth()},DevicrDevice.prototype.hasRetinaPixelRatio=function(){return this.screen_device.getDevicePixelRatio()>1},DevicrElement.prototype.sourceLoaded=function(){return this.element.getAttribute("src")},DevicrElement.prototype.backgroundSourceLoaded=function(){return this.element.style.backgroundImage},DevicrElement.prototype.getSourceFor=function(a){return this.element.getAttribute(a)},DevicrElement.prototype.replaceSourceLoadedBy=function(a){this.element.setAttribute("src",a)},DevicrElement.prototype.replaceBackgroundSourceBy=function(a){this.element.setAttribute("style","background-image: url("+a+");")},DevicrElement.prototype.getAvailableDevices=function(){var a=this.devices,b=[],c=null;for(var d in a)c=this.getSourceFor(a[d]),null!==c&&""!==c&&b.push(a[d]);return b},DevicrElement.prototype.getHigherAvailableDevicesThan=function(a){var b=this.getHigherDevices(a);if(b.length>0){var c=this.getAvailableDevices();return ArrayIntersect.intersect(b,c)}return[]},DevicrSourceFinder.prototype.findHighestAvailableSource=function(a){var b=a.getAvailableDevices();return 0===b.length?null:a.getSourceFor(b.shift())},DevicrSourceFinder.prototype.findFirstHigherAvailableSource=function(a){var b=a.getHigherAvailableDevicesThan(this.devicr_device.getDevice());return 0===b.length?null:a.getSourceFor(b.pop())},DevicrSourceSelector.prototype.getBestSourceFor=function(a){this.device.getDevice();return this.device.isInLandscapeMode()?this.getBestLandscapeSourceFor(a):this.getBestPortraitSourceFor(a)},DevicrSourceSelector.prototype.getBestLandscapeSourceFor=function(a){return this.device.hasRetinaPixelRatio()?this.getBestLandscapeSourceWithRetinaDisplayFor(a):this.getBestLandscapeSourceWithoutRetinaDisplayFor(a)},DevicrSourceSelector.prototype.getBestPortraitSourceFor=function(a){var b=a.getSourceFor(this.device.getDevice());return null===b&&(b=this.finder.findFirstHigherAvailableSource(a)),null===b?this.finder.findHighestAvailableSource(a):b},DevicrSourceSelector.prototype.getBestLandscapeSourceWithRetinaDisplayFor=function(a){return this.finder.findHighestAvailableSource(a)},DevicrSourceSelector.prototype.getBestLandscapeSourceWithoutRetinaDisplayFor=function(a){var b=a.getSourceFor("desktop");return null===b?this.finder.findHighestAvailableSource(a):b},RibbonSourceSelector.prototype.getBestSourceFor=function(a){this.device.getDevice();return this.device.isInLandscapeMode()?this.getBestLandscapeSourceFor(a):this.getBestPortraitSourceFor(a)},RibbonSourceSelector.prototype.getBestLandscapeSourceFor=function(a){var b=null,c=this.device.getDevice();switch(c){case"mobile":b=a.getSourceFor("tablet");break;case"tablet":b=a.getSourceFor("retina");break;default:b=a.getSourceFor(this.device.getDevice())}return null===b&&(b=this.finder.findFirstHigherAvailableSource(a)),null===b?this.finder.findHighestAvailableSource(a):b},RibbonSourceSelector.prototype.getBestPortraitSourceFor=function(a){var b=a.getSourceFor(this.device.getDevice());return null===b&&(b=this.finder.findFirstHigherAvailableSource(a)),null===b?this.finder.findHighestAvailableSource(a):b},ScreenDevice.prototype.getHeight=function(){return window.innerHeight},ScreenDevice.prototype.getWidth=function(){return window.innerWidth},ScreenDevice.prototype.getDevicePixelRatio=function(){return window.devicePixelRatio},StreamrSourceSelector.prototype.getBestSourceFor=function(a){return"mobile"!=this.device.getDevice()&&this.device.isInLandscapeMode()?this.getBestLandscapeSourceFor(a):this.getBestPortraitSourceFor(a)},StreamrSourceSelector.prototype.getBestLandscapeSourceFor=function(a){return this.device.hasRetinaPixelRatio()?this.getBestLandscapeSourceWithRetinaDisplayFor(a):this.getBestLandscapeSourceWithoutRetinaDisplayFor(a)},StreamrSourceSelector.prototype.getBestPortraitSourceFor=function(a){if(this.device.isATabletWithBigScreen())return this.getBestPortraitSourceForBigTablets(a);var b=a.getSourceFor(this.device.getDevice());return null===b&&(b=this.finder.findFirstHigherAvailableSource(a)),null===b?this.finder.findHighestAvailableSource(a):b},StreamrSourceSelector.prototype.getBestLandscapeSourceWithRetinaDisplayFor=function(a){return this.finder.findHighestAvailableSource(a)},StreamrSourceSelector.prototype.getBestLandscapeSourceWithoutRetinaDisplayFor=function(a){var b=a.getSourceFor("desktop");return null===b?this.finder.findHighestAvailableSource(a):b},StreamrSourceSelector.prototype.getBestPortraitSourceForBigTablets=function(a){var b=null;return this.device.hasRetinaPixelRatio()||(b=this.finder.findFirstHigherAvailableSource(a)),null===b?this.finder.findHighestAvailableSource(a):b};