1/* 2 * [y] hybris Platform 3 * 4 * Copyright (c) 2000-2016 SAP SE or an SAP affiliate company. 5 * All rights reserved. 6 * 7 * This software is the confidential and proprietary information of SAP 8 * ("Confidential Information"). You shall not disclose such Confidential 9 * Information and shall use it only in accordance with the terms of the 10 * license agreement you entered into with SAP. 11 */ 12;(function (window, document) { 13 'use strict'; 14 15 var nextTick, addEvent; 16 nextTick = window.requestAnimationFrame || 17 window.mozRequestAnimationFrame || 18 window.webkitRequestAnimationFrame || 19 function (callback) { 20 window.setTimeout(callback, 1000 / 60); 21 }; 22 23 addEvent = (function(){ 24 if (document.addEventListener){ 25 return function addStandardEventListener(el, eventName, fn){ 26 return el.addEventListener(eventName, fn, false); 27 }; 28 } 29 else { 30 return function addIEEventListener(el, eventName, fn){ 31 return el.attachEvent('on'+eventName, fn); 32 }; 33 } 34 })(); 35 36 function Imager (elements, opts) { 37 var self = this,doc = document; 38 opts = opts || {}; 39 40 this.elements = elements || '.js-responsive-image'; 41 this.className = opts.className || 'js-responsive-image-replaced'; 42 this.onResize = opts.hasOwnProperty('onResize') ? opts.onResize : true; 43 this.onImagesReplaced = opts.onImagesReplaced || function () {}; 44 45 this.eles = $(elements); 46 nextTick(function(){self.init();}); 47 } 48 49 Imager.prototype.init = function(){ 50 this.checkImagesNeedReplacing(this.eles); 51 if(this.onResize){this.registerResizeEvent();} 52 }; 53 54 Imager.prototype.checkImagesNeedReplacing = function (images) { 55 var self = this; 56 57 if (!this.isResizing) { 58 this.isResizing = true; 59 60 images.each(function(){self.replaceImagesBasedOnScreenDimensions(this);}); 61 62 this.isResizing = false; 63 this.onImagesReplaced(images); 64 } 65 }; 66 67 Imager.prototype.replaceImagesBasedOnScreenDimensions = function (image) { 68 var src,availableWidths = [],srcARRAY,cwidth; 69 70 if( $(image).attr("data-media")!=undefined){ 71 var eMedia = $(image).attr("data-media") 72 $(image).removeAttr("data-media") 73 eMedia = $.parseJSON(eMedia) 74 $.each(eMedia, function(key, value) { 75 availableWidths.push(parseInt(key)); 76 }); 77 $(image).data("width",availableWidths); 78 $(image).data("media",eMedia); 79 } 80 81 srcARRAY = $(image).data("media"); 82 cwidth = Imager.getClosestValue($(image).parent().width(), $.extend([],$(image).data("width"))); 83 84 if(image.src == srcARRAY[cwidth]){return;} 85 image.src = srcARRAY[cwidth]; 86 }; 87 88 Imager.getClosestValue = function getClosestValue(baseValue, candidates){ 89 if(baseValue >= candidates[0]){ 90 candidates.shift() 91 if(candidates.length>1){ 92 getClosestValue(baseValue,candidates) 93 } 94 } 95 return candidates[0]; 96 } 97 98 Imager.prototype.registerResizeEvent = function(){ 99 var self = this; 100 addEvent(window, 'resize', function(){ 101 self.checkImagesNeedReplacing(self.eles); 102 }); 103 }; 104 105 if (typeof module === 'object' && typeof module.exports === 'object') { 106 module.exports = exports = Imager; 107 } else if (typeof define === 'function' && define.amd) { 108 define(function () { return Imager; }); 109 } else if (typeof window === 'object') { 110 window.Imager = Imager; 111 } 112 113}(window, document));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.