1/*! 2 * Retina.js v1.3.0 3 * 4 * Copyright 2014 Imulus, LLC 5 * Released under the MIT license 6 * 7 * Retina.js is an open source script that makes it easy to serve 8 * high-resolution images to devices with retina displays. 9 */ 10 11(function() { 12 var root = (typeof exports === 'undefined' ? window : exports); 13 var config = { 14 // An option to choose a suffix for 2x images 15 retinaImageSuffix : '@2x', 16 17 // Ensure Content-Type is an image before trying to load @2x image 18 // https://github.com/imulus/retinajs/pull/45) 19 check_mime_type: true, 20 21 // Resize high-resolution images to original image's pixel dimensions 22 // https://github.com/imulus/retinajs/issues/8 23 force_original_dimensions: true 24 }; 25 26 function Retina() {} 27 28 root.Retina = Retina; 29 30 Retina.configure = function(options) { 31 if (options === null) { options = {}; } 32 for (var prop in options) { if (options.hasOwnProperty(prop)) { config[prop] = options[prop]; } } 33 }; 34 35 Retina.init = function(context) { 36 if (context === null) { context = root; } 37 var existing_onload = context.onload || function(){}; 38 context.onload = function() { 39 var images = document.getElementsByTagName('img'), retinaImages = [], i, image; 40 for (i = 0; i < images.length; i += 1) { 41 image = images[i]; 42 if (!!!image.getAttributeNode('data-no-retina')) { retinaImages.push(new RetinaImage(image)); } 43 } 44 existing_onload(); 45 }; 46 }; 47 48 Retina.isRetina = function(){ 49 var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; 50 if (root.devicePixelRatio > 1) { return true; } 51 if (root.matchMedia && root.matchMedia(mediaQuery).matches) { return true; } 52 return false; 53 }; 54 55 var regexMatch = /\.\w+$/; 56 function suffixReplace (match) { return config.retinaImageSuffix + match; } 57 function RetinaImagePath(path, at_2x_path) { 58 this.path = path || ''; 59 if (typeof at_2x_path !== 'undefined' && at_2x_path !== null) { 60 this.at_2x_path = at_2x_path; 61 this.perform_check = false; 62 } else { 63 if (undefined !== document.createElement) { 64 var locationObject = document.createElement('a'); 65 locationObject.href = this.path; 66 locationObject.pathname = locationObject.pathname.replace(regexMatch, suffixReplace); 67 this.at_2x_path = locationObject.href; 68 } else { 69 var parts = this.path.split('?'); 70 parts[0] = parts[0].replace(regexMatch, suffixReplace); 71 this.at_2x_path = parts.join('?'); 72 } 73 this.perform_check = true; 74 } 75 } 76 77 root.RetinaImagePath = RetinaImagePath; 78 RetinaImagePath.confirmed_paths = []; 79 RetinaImagePath.prototype.is_external = function() { 80 return !!(this.path.match(/^https?\:/i) && !this.path.match('//' + document.domain) ); 81 }; 82 83 RetinaImagePath.prototype.check_2x_variant = function(callback) { 84 var http, that = this; 85 if (this.is_external()) { 86 return callback(false); 87 } else if (!this.perform_check && typeof this.at_2x_path !== 'undefined' && this.at_2x_path !== null) { 88 return callback(true); 89 } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) { 90 return callback(true); 91 } else { 92 http = new XMLHttpRequest(); 93 http.open('HEAD', this.at_2x_path); 94 http.onreadystatechange = function() { 95 if (http.readyState !== 4) { return callback(false); } 96 if (http.status >= 200 && http.status <= 399) { 97 if (config.check_mime_type) { var type = http.getResponseHeader('Content-Type'); if (type === null || !type.match(/^image/i)) { return callback(false); } } 98 RetinaImagePath.confirmed_paths.push(that.at_2x_path); return callback(true); 99 } else { return callback(false); } 100 }; 101 http.send(); 102 } 103 }; 104 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(); } }); } 105 root.RetinaImage = RetinaImage; 106 RetinaImage.prototype.swap = function(path) { 107 if (typeof path === 'undefined') { path = this.path.at_2x_path; } 108 var that = this; 109 function load() { 110 if (! that.el.complete) { setTimeout(load, 5); } else { 111 if (config.force_original_dimensions) { that.el.setAttribute('width', that.el.offsetWidth); that.el.setAttribute('height', that.el.offsetHeight); } 112 that.el.setAttribute('src', path); 113 } 114 } 115 load(); 116 }; 117 if (Retina.isRetina()) { Retina.init(root); } 118})();
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.