PageSourceSearch

https://thesmalls.ca/wp-content/themes/bravo/js/retina-update.js?ver=4.0

js thesmalls.ca collected 2026-10-02 14:13:45 UTC 3,640 bytes, 140 lines download raw bytes

1(function() {
2  var root = (typeof exports == 'undefined' ? window : exports);
3
4  var config = {
5    // Ensure Content-Type is an image before trying to load @2x image
6    // https://github.com/imulus/retinajs/pull/45)
7    check_mime_type: true,
8
9    // Resize high-resolution images to original image's pixel dimensions
10    // https://github.com/imulus/retinajs/issues/8
11    force_original_dimensions: true
12 };
13
14  root.Retina = Retina;
15
16  function Retina() {}
17
18  Retina.configure = function(options) {
19    if (options == null) options = {};
20    for (var prop in options) config[prop] = options[prop];
21  };
22
23  Retina.init = function(context) {
24    if (context == null) context = root;
25
26    var existing_onload = context.onload || new Function;
27
28    context.onload = function() {
29      var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
30      for (i = 0; i < images.length; i++) {
31        image = images[i];
32        retinaImages.push(new RetinaImage(image));
33      }
34      existing_onload();
35    }
36  };
37
38  Retina.isRetina = function(){
39    var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
40                      (min--moz-device-pixel-ratio: 1.5),\
41                      (-o-min-device-pixel-ratio: 3/2),\
42                      (min-resolution: 1.5dppx)";
43
44    if (root.devicePixelRatio > 1)
45      return true;
46
47    if (root.matchMedia && root.matchMedia(mediaQuery).matches)
48      return true;
49
50    return false;
51  };
52
53
54  root.RetinaImagePath = RetinaImagePath;
55
56  function RetinaImagePath(path) {
57    if(path){
58      this.path = path;
59      this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
60    }
61  }
62
63  RetinaImagePath.confirmed_paths = [];
64
65  RetinaImagePath.prototype.is_external = function() {
66    return !!(this.path.match(/^https?\:/i) && !this.path.match('//' + document.domain) )
67  }
68
69  RetinaImagePath.prototype.check_2x_variant = function(callback) {
70    var http, that = this;
71    if (this.is_external()) {
72      return callback(false);
73    } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
74      return callback(true);
75    } else {
76      http = new XMLHttpRequest;
77      http.open('HEAD', this.at_2x_path);
78      http.onreadystatechange = function() {
79        if (http.readyState != 4) {
80          return callback(false);
81        }
82
83        if (http.status >= 200 && http.status <= 399) {
84          if (config.check_mime_type) {
85            var type = http.getResponseHeader('Content-Type');
86            if (type == null || !type.match(/^image/i)) {
87              return callback(false);
88            }
89          }
90
91          RetinaImagePath.confirmed_paths.push(that.at_2x_path);
92          return callback(true);
93        } else {
94          return callback(false);
95        }
96      }
97      http.send();
98    }
99  }
100
101
102
103  function RetinaImage(el) {
104    this.el = el;
105    this.path = new RetinaImagePath(this.el.getAttribute('src'));
106    var that = this;
107    this.path.check_2x_variant(function(hasVariant) {
108      if (hasVariant) that.swap();
109    });
110  }
111
112  root.RetinaImage = RetinaImage;
113
114  RetinaImage.prototype.swap = function(path) {
115    if (typeof path == 'undefined') path = this.path.at_2x_path;
116
117    var that = this;
118    function load() {
119      if (! that.el.complete) {
120        setTimeout(load, 5);
121      } else {
122        if (config.force_original_dimensions) {
123          that.el.setAttribute('width', that.el.offsetWidth);
124          that.el.setAttribute('height', that.el.offsetHeight);
125        }
126
127        that.el.setAttribute('src', path);
128      }
129    }
130    load();
131  }
132
133
134
135
136  if (Retina.isRetina()) {
137    Retina.init(root);
138  }
139
140})();

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.