PageSourceSearch

https://www.jhrl.com/sites/all/themes/custom/vrweb_foundation/js/v…/foundation.interchange.js?tlse4v

js jhrl.com collected 2026-10-06 13:18:43 UTC 6,929 bytes, 280 lines download raw bytes

1/*jslint unparam: true, browser: true, indent: 2 */
2
3;(function ($, window, document, undefined) {
4  'use strict';
5
6  Foundation.libs.interchange = {
7    name : 'interchange',
8
9    version : '4.2.4',
10
11    cache : {},
12
13    images_loaded : false,
14
15    settings : {
16      load_attr : 'interchange',
17
18      named_queries : {
19        'default' : 'only screen and (min-width: 1px)',
20        small : 'only screen and (min-width: 768px)',
21        medium : 'only screen and (min-width: 1280px)',
22        large : 'only screen and (min-width: 1440px)',
23        landscape : 'only screen and (orientation: landscape)',
24        portrait : 'only screen and (orientation: portrait)',
25        retina : 'only screen and (-webkit-min-device-pixel-ratio: 2),' + 
26          'only screen and (min--moz-device-pixel-ratio: 2),' + 
27          'only screen and (-o-min-device-pixel-ratio: 2/1),' + 
28          'only screen and (min-device-pixel-ratio: 2),' + 
29          'only screen and (min-resolution: 192dpi),' + 
30          'only screen and (min-resolution: 2dppx)'
31      },
32
33      directives : {
34        replace: function (el, path) {
35          if (/IMG/.test(el[0].nodeName)) {
36            var orig_path = el[0].src;
37
38            if (new RegExp(path, 'i').test(orig_path)) return;
39
40            el[0].src = path;
41
42            return el.trigger('replace', [el[0].src, orig_path]);
43          }
44        }
45      }
46    },
47
48    init : function (scope, method, options) {
49      Foundation.inherit(this, 'throttle');
50
51      if (typeof method === 'object') {
52        $.extend(true, this.settings, method);
53      }
54
55      this.events();
56      this.images();
57
58      if (typeof method !== 'string') {
59        return this.settings.init;
60      } else {
61        return this[method].call(this, options);
62      }
63    },
64
65    events : function () {
66      var self = this;
67
68      $(window).on('resize.fndtn.interchange', self.throttle(function () {
69        self.resize.call(self);
70      }, 50));
71    },
72
73    resize : function () {
74      var cache = this.cache;
75
76      if(!this.images_loaded) {
77        setTimeout($.proxy(this.resize, this), 50);
78        return;
79      }
80
81      for (var uuid in cache) {
82        if (cache.hasOwnProperty(uuid)) {
83          var passed = this.results(uuid, cache[uuid]);
84
85          if (passed) {
86            this.settings.directives[passed
87              .scenario[1]](passed.el, passed.scenario[0]);
88          }
89        }
90      }
91
92    },
93
94    results : function (uuid, scenarios) {
95      var count = scenarios.length;
96
97      if (count > 0) {
98        var el = $('[data-uuid="' + uuid + '"]');
99
100        for (var i = count - 1; i >= 0; i--) {
101          var mq, rule = scenarios[i][2];
102          if (this.settings.named_queries.hasOwnProperty(rule)) {
103            mq = matchMedia(this.settings.named_queries[rule]);
104          } else {
105            mq = matchMedia(rule);
106          }
107          if (mq.matches) {
108            return {el: el, scenario: scenarios[i]};
109          }
110        }
111      }
112
113      return false;
114    },
115
116    images : function (force_update) {
117      if (typeof this.cached_images === 'undefined' || force_update) {
118        return this.update_images();
119      }
120
121      return this.cached_images;
122    },
123
124    update_images : function () {
125      var images = document.getElementsByTagName('img'),
126          count = images.length,
127          loaded_count = 0,
128          data_attr = 'data-' + this.settings.load_attr;
129
130      this.cached_images = [];
131      this.images_loaded = false;
132
133      for (var i = count - 1; i >= 0; i--) {
134        this.loaded($(images[i]), function (image) {
135          loaded_count++;
136          if (image) {
137            var str = image.getAttribute(data_attr) || '';
138
139            if (str.length > 0) {
140              this.cached_images.push(image);
141            }
142          }
143
144          if(loaded_count === count) {
145            this.images_loaded = true;
146            this.enhance();
147          }
148        }.bind(this));
149      }
150
151      return 'deferred';
152    },
153
154    // based on jquery.imageready.js
155    // @weblinc, @jsantell, (c) 2012
156
157    loaded : function (image, callback) {
158      function loaded () {
159        callback(image[0]);
160      }
161
162      function bindLoad () {
163        this.one('load', loaded);
164
165        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
166          var src = this.attr( 'src' ),
167              param = src.match( /\?/ ) ? '&' : '?';
168
169          param += 'random=' + (new Date()).getTime();
170          this.attr('src', src + param);
171        }
172      }
173
174      if (!image.attr('src')) {
175        loaded();
176        return;
177      }
178
179      if (image[0].complete || image[0].readyState === 4) {
180        loaded();
181      } else {
182        bindLoad.call(image);
183      }
184    },
185
186    enhance : function () {
187      var count = this.images().length;
188
189      for (var i = count - 1; i >= 0; i--) {
190        this._object($(this.images()[i]));
191      }
192
193      return $(window).trigger('resize');
194    },
195
196    parse_params : function (path, directive, mq) {
197      return [this.trim(path), this.convert_directive(directive), this.trim(mq)];
198    },
199
200    convert_directive : function (directive) {
201      var trimmed = this.trim(directive);
202
203      if (trimmed.length > 0) {
204        return trimmed;
205      }
206
207      return 'replace';
208    },
209
210    _object : function(el) {
211      var raw_arr = this.parse_data_attr(el),
212          scenarios = [], count = raw_arr.length;
213
214      if (count > 0) {
215        for (var i = count - 1; i >= 0; i--) {
216          var split = raw_arr[i].split(/\((.*?)(\))$/);
217
218          if (split.length > 1) {
219            var cached_split = split[0].split(','),
220                params = this.parse_params(cached_split[0],
221                  cached_split[1], split[1]);
222
223            scenarios.push(params);
224          }
225        }
226      }
227
228      return this.store(el, scenarios);
229    },
230
231    uuid : function (separator) {
232      var delim = separator || "-";
233
234      function S4() {
235        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
236      }
237
238      return (S4() + S4() + delim + S4() + delim + S4()
239        + delim + S4() + delim + S4() + S4() + S4());
240    },
241
242    store : function (el, scenarios) {
243      var uuid = this.uuid(),
244          current_uuid = el.data('uuid');
245
246      if (current_uuid) return this.cache[current_uuid];
247
248      el.attr('data-uuid', uuid);
249
250      return this.cache[uuid] = scenarios;
251    },
252
253    trim : function(str) {
254      if (typeof str === 'string') {
255        return $.trim(str);
256      }
257
258      return str;
259    },
260
261    parse_data_attr : function (el) {
262      var raw = el.data(this.settings.load_attr).split(/\[(.*?)\]/),
263          count = raw.length, output = [];
264
265      for (var i = count - 1; i >= 0; i--) {
266        if (raw[i].replace(/[\W\d]+/, '').length > 4) {
267          output.push(raw[i]);
268        }
269      }
270
271      return output;
272    },
273
274    reflow : function () {
275      this.images(true);
276    }
277
278  };
279
280}(Foundation.zj, this, this.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.