PageSourceSearch

https://activosdesalud.com/template_remark/global/vendor/breakpoints/breakpoints.js

js activosdesalud.com collected 2026-10-04 21:09:09 UTC 12,370 bytes, 476 lines download raw bytes

1/*! breakpoints.js - v0.4.2 - 2015-04-22
2 * https://github.com/amazingSurge/breakpoints.js
3 * Copyright (c) 2015 amazingSurge; Licensed GPL */
4(function(document, window, undefined) {
5    "use strict";
6
7    var Breakpoints = window.Breakpoints = function() {
8        Breakpoints.define.apply(Breakpoints, arguments);
9    };
10
11    function each(obj, fn) {
12        var continues;
13
14        for (var i in obj) {
15            continues = fn(i, obj[i]);
16            if (continues === false) {
17                break; //allow early exit
18            }
19        }
20    }
21
22    function isFunction(obj) {
23        return typeof obj == 'function' || false;
24    }
25
26    function extend(obj, source) {
27        for (var property in source) {
28            obj[property] = source[property];
29        }
30        return obj;
31    }
32
33    Breakpoints.defaults = {
34        // Extra small devices (phones)
35        xs: {
36            min: 0,
37            max: 767
38        },
39        // Small devices (tablets)
40        sm: {
41            min: 768,
42            max: 991
43        },
44        // Medium devices (desktops)
45        md: {
46            min: 992,
47            max: 1199
48        },
49        // Large devices (large desktops)
50        lg: {
51            min: 1200,
52            max: Infinity
53        }
54    };
55
56    var MediaBuilder = Breakpoints.mediaBuilder = {
57        min: function(min, unit) {
58            return '(min-width: ' + min + unit + ')';
59        },
60        max: function(max, unit) {
61            return '(max-width: ' + max + unit + ')';
62        },
63        between: function(min, max, unit) {
64            return '(min-width: ' + min + unit + ') and (max-width: ' + max + unit + ')';
65        },
66        get: function(min, max, unit) {
67            if (!unit) {
68                unit = 'px';
69            }
70            if (min === 0) {
71                return this.max(max, unit);
72            }
73            if (max === Infinity) {
74                return this.min(min, unit);
75            }
76            return this.between(min, max, unit);
77        }
78    };
79
80    var Callbacks = function() {
81        var list = [];
82
83        return {
84            length: 0,
85            add: function(fn, data, one) {
86                list.push({
87                    fn: fn,
88                    data: data || {},
89                    one: one || 0
90                });
91
92                this.length++;
93            },
94            remove: function(fn) {
95                for (var i = 0; i < list.length; i++) {
96                    if (list[i].fn === fn) {
97                        list.splice(i, 1);
98                        this.length--;
99                        i--;
100                    }
101                }
102            },
103            empty: function() {
104                list = [];
105                this.length = 0;
106            },
107            call: function(caller, i, fn) {
108                if (!i) {
109                    i = this.length - 1;
110                }
111                var callback = list[i];
112
113                if (isFunction(fn)) {
114                    fn.call(this, caller, callback, i);
115                } else {
116                    if (isFunction(callback.fn)) {
117                        callback.fn.call(caller || window, callback.data);
118                    }
119                }
120
121                if (callback.one) {
122                    delete list[i];
123                    this.length--;
124                }
125            },
126            fire: function(caller, fn) {
127                for (var i in list) {
128                    this.call(caller, i, fn);
129                }
130            }
131        };
132    };
133
134    var ChangeEvent = {
135        current: null,
136        callbacks: new Callbacks(),
137        trigger: function(size) {
138            var previous = this.current;
139            this.current = size;
140            this.callbacks.fire(size, function(caller, callback) {
141                if (isFunction(callback.fn)) {
142                    callback.fn.call({
143                        current: size,
144                        previous: previous
145                    }, callback.data);
146                }
147            });
148        },
149        one: function(data, fn) {
150            return this.on(data, fn, 1);
151        },
152        on: function(data, fn, /*INTERNAL*/ one) {
153            if (fn == null && isFunction(data)) {
154                fn = data;
155                data = undefined;
156            }
157            if (!isFunction(fn)) {
158                return this;
159            }
160            this.callbacks.add(fn, data, one);
161        },
162        off: function(fn) {
163            if (fn == null) {
164                this.callbacks.empty();
165            }
166        }
167    };
168
169    var MediaQuery = Breakpoints.mediaQuery = function(name, media) {
170        this.name = name;
171        this.media = media;
172
173        this.initialize.apply(this);
174    }
175
176    MediaQuery.prototype = {
177        constructor: MediaQuery,
178        initialize: function() {
179            this.callbacks = {
180                enter: new Callbacks(),
181                leave: new Callbacks()
182            };
183
184            this.mql = (window.matchMedia && window.matchMedia(this.media)) || {
185                matches: false,
186                media: this.media,
187                addListener: function() {},
188                removeListener: function() {}
189            };
190
191            var self = this;
192            this.mqlListener = function(mql) {
193                var type = (mql.matches && 'enter') || 'leave';
194
195                self.callbacks[type].fire(self);
196            };
197            this.mql.addListener(this.mqlListener);
198        },
199
200        on: function(types, data, fn, /*INTERNAL*/ one) {
201            var type;
202            if (typeof types === "object") {
203                for (type in types) {
204                    this.on(type, data, types[type], one);
205                }
206                return this;
207            }
208
209            if (fn == null && isFunction(data)) {
210                fn = data;
211                data = undefined;
212            }
213
214            if (!isFunction(fn)) {
215                return this;
216            }
217
218            if (types in this.callbacks) {
219                this.callbacks[types].add(fn, data, one);
220                if (this.isMatched() && types === 'enter') {
221                    this.callbacks[types].call(this);
222                }
223            }
224
225            return this;
226        },
227
228        one: function(types, data, fn) {
229            return this.on(types, data, fn, 1);
230        },
231
232        off: function(types, fn) {
233            var type;
234            if (typeof types === "object") {
235                for (type in types) {
236                    this.off(type, types[type]);
237                }
238                return this;
239            }
240
241            if (types == null) {
242                this.callbacks.enter.empty();
243                this.callbacks.leave.empty();
244            }
245            if (types in this.callbacks) {
246                if (fn) {
247                    this.callbacks[types].remove(fn);
248                } else {
249                    this.callbacks[types].empty();
250                }
251            }
252
253            return this;
254        },
255
256        isMatched: function() {
257            return this.mql.matches;
258        },
259
260        destory: function() {
261            this.off();
262        }
263    };
264    var Size = function(name, min, max, unit) {
265        this.name = name;
266        this.min = min ? min : 0;
267        this.max = max ? max : Infinity;
268
269        this.media = MediaBuilder.get(this.min, this.max, unit);
270
271        this.initialize.apply(this);
272
273        var self = this;
274        this.changeListener = function() {
275            if (self.isMatched()) {
276                ChangeEvent.trigger(self);
277            }
278        };
279        if (this.isMatched()) {
280            ChangeEvent.current = this;
281        }
282        this.mql.addListener(this.changeListener);
283    };
284
285    Size.prototype = MediaQuery.prototype;
286    Size.prototype.constructor = Size;
287
288    extend(Size.prototype, {
289        destory: function() {
290            this.off();
291            this.mql.removeListener(this.changeHander);
292        }
293    });
294
295    var UnionSize = function(names) {
296        this.name = names;
297        this.sizes = [];
298
299        var self = this;
300
301        var media = [];
302        each(names.split(' '), function(i, name) {
303            var size = Breakpoints.get(name);
304            if (size) {
305                self.sizes.push(size);
306                media.push(size.media);
307            }
308        });
309
310        this.media = media.join(',');
311
312        this.initialize.apply(this);
313    };
314
315    UnionSize.prototype = MediaQuery.prototype;
316    UnionSize.prototype.constructor = UnionSize;
317
318    var sizes = {};
319    var unionSizes = {};
320
321
322    Breakpoints = extend(Breakpoints, {
323        defined: false,
324        define: function(values, options) {
325            if (this.defined) {
326                this.destory();
327            }
328
329            if (!values) {
330                values = Breakpoints.defaults;
331            }
332
333            this.options = extend(options || {}, {
334                unit: 'px'
335            });
336
337            for (var size in values) {
338                this.set(size, values[size].min, values[size].max, this.options.unit);
339            }
340
341            this.defined = true;
342        },
343
344        destory: function() {
345            each(sizes, function(name, size) {
346                size.destory();
347            });
348            sizes = {};
349            ChangeEvent.current = null;
350        },
351
352        is: function(size) {
353            var breakpoint = this.get(size);
354            if (!breakpoint) {
355                return null;
356            }
357
358            return breakpoint.isMatched();
359        },
360
361        /* get all size name */
362        all: function() {
363            var names = [];
364            each(sizes, function(name) {
365                names.push(name);
366            });
367            return names;
368        },
369
370        set: function(name, min, max, unit) {
371            var size = this.get(name);
372            if (size) {
373                size.destory();
374            }
375
376            sizes[name] = new Size(name, min || null, max || null, unit || null)
377            return sizes[name];
378        },
379
380        get: function(size) {
381            if (sizes.hasOwnProperty(size)) {
382                return sizes[size];
383            }
384
385            return null;
386        },
387
388        getUnion: function(sizes) {
389            if (unionSizes.hasOwnProperty(sizes)) {
390                return unionSizes[sizes];
391            }
392
393            unionSizes[sizes] = new UnionSize(sizes)
394
395            return unionSizes[sizes];
396        },
397
398        getMin: function(size) {
399            var obj = this.get(size);
400            if (obj) {
401                return obj.min;
402            }
403            return null;
404        },
405
406        getMax: function(size) {
407            var obj = this.get(size);
408            if (obj) {
409                return obj.max;
410            }
411            return null;
412        },
413
414        current: function() {
415            return ChangeEvent.current;
416        },
417
418        getMedia: function(size) {
419            var obj = this.get(size);
420            if (obj) {
421                return obj.media;
422            }
423            return null;
424        },
425
426        on: function(sizes, types, data, fn, /*INTERNAL*/ one) {
427            if (sizes === 'change') {
428                fn = data;
429                data = types;
430                return ChangeEvent.on(data, fn, one);
431            }
432            if (sizes.indexOf(' ')) {
433                var union = this.getUnion(sizes);
434
435                if (union) {
436                    union.on(types, data, fn, one);
437                }
438            } else {
439                var size = this.get(sizes);
440
441                if (size) {
442                    size.on(types, data, fn, one);
443                }
444            }
445
446            return this;
447        },
448
449        one: function(sizes, types, data, fn) {
450            return this.on(sizes, types, data, fn, 1);
451        },
452
453        off: function(sizes, types, fn) {
454            if (sizes === 'change') {
455                return ChangeEvent.off(types);
456            }
457
458            if (sizes.indexOf(' ')) {
459                var union = this.getUnion(sizes);
460
461                if (union) {
462                    union.off(types, fn);
463                }
464            } else {
465                var size = this.get(sizes);
466
467                if (size) {
468                    size.off(types, fn);
469                }
470            }
471
472            return this;
473        }
474    });
475
476})(document, window);

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.