PageSourceSearch

https://20minutebody.com/wp-content/themes/twentyminute/js/lity-1.5.0/dist/lity.js

js 20minutebody.com collected 2026-10-07 22:02:51 UTC 12,432 bytes, 437 lines download raw bytes

vendor: 4,443 bytes, lines 1-154
1/*! Lity - v1.5.0 - 2015-09-22
2* http://sorgalla.com/lity/
3* Copyright (c) 2015 Jan Sorgalla; Licensed MIT */
4(function(window, factory) {
5    if (typeof define === 'function' && define.amd) {
6        define(['jquery'], function($) {
7            return factory(window, $);
8        });
9    } else if (typeof module === 'object' && typeof module.exports === 'object') {
10        module.exports = factory(window, require('jquery'));
11    } else {
12        window.lity = factory(window, window.jQuery || window.Zepto);
13    }
14}(window, function(window, $) {
15    'use strict';
16
17    var document = window.document;
18
19    var _win = $(window);
20    var _html = $('html');
21    var _instanceCount = 0;
22
23    var _imageRegexp = /\.(png|jpe?g|gif|svg|webp|bmp|ico|tiff?)(\?\S*)?$/i;
24    var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})(.*)?/i;
25    var _vimeoRegex =  /(vimeo(pro)?.com)\/(?:[^\d]+)?(\d+)\??(.*)?$/;
26    var _googlemapsRegex = /((maps|www)\.)?google\.([^\/\?]+)\/?((maps\/?)?\?)(.*)/i;
27
28    var _defaultHandlers = {
29        image: imageHandler,
30        inline: inlineHandler,
31        iframe: iframeHandler
32    };
33
34    var _defaultOptions = {
35        esc: true,
36        handler: null,
37        template: '<div class="lity" tabindex="-1"><div class="lity-wrap" data-lity-close><div class="lity-loader">Loading...</div><div class="lity-container"><div class="lity-content"></div><button class="lity-close" type="button" title="Close (Esc)" data-lity-close>×</button></div></div></div>'
38    };
39
40    function globalToggle() {
41        _html[_instanceCount > 0 ? 'addClass' : 'removeClass']('lity-active');
42    }
43
44    var transitionEndEvent = (function() {
45        var el = document.createElement('div');
46
47        var transEndEventNames = {
48            WebkitTransition: 'webkitTransitionEnd',
49            MozTransition: 'transitionend',
50            OTransition: 'oTransitionEnd otransitionend',
51            transition: 'transitionend'
52        };
53
54        for (var name in transEndEventNames) {
55            if (el.style[name] !== undefined) {
56                return transEndEventNames[name];
57            }
58        }
59
60        return false;
61    })();
62
63    function transitionEnd(element) {
64        var deferred = $.Deferred();
65
66        if (!transitionEndEvent) {
67            deferred.resolve();
68        } else {
69            element.one(transitionEndEvent, deferred.resolve);
70            setTimeout(deferred.resolve, 500);
71        }
72
73        return deferred.promise();
74    }
75
76    function settings(currSettings, key, value) {
77        if (arguments.length === 1) {
78            return $.extend({}, currSettings);
79        }
80
81        if (typeof key === 'string') {
82            if (typeof value === 'undefined') {
83                return typeof currSettings[key] === 'undefined' ?
84                    null :
85                    currSettings[key];
86            }
87            currSettings[key] = value;
88        } else {
89            $.extend(currSettings, key);
90        }
91
92        return this;
93    }
94
95    function protocol() {
96        return 'file:' === window.location.protocol ? 'http:' : '';
97    }
98
99    function parseQueryParams(params){
100        var pairs = decodeURI(params).split('&');
101        var obj = {}, p;
102
103        for (var i = 0, n = pairs.length; i < n; i++) {
104            if (!pairs[i]) {
105                continue;
106            }
107
108            p = pairs[i].split('=');
109            obj[p[0]] = p[1];
110        }
111
112        return obj;
113    }
114
115    function appendQueryParams(url, params) {
116        return url + (url.indexOf('?') > -1 ? '&' : '?') + $.param(params);
117    }
118
119    function error(msg) {
120        return $('<span class="lity-error"/>').append(msg);
121    }
122
123    function imageHandler(target) {
124        if (!_imageRegexp.test(target)) {
125            return false;
126        }
127
128        var img = $('<img src="' + target + '">');
129        var deferred = $.Deferred();
130        var failed = function() {
131            deferred.reject(error('Failed loading image'));
132        };
133
134        img
135            .on('load', function() {
136                if (this.naturalWidth === 0) {
137                    return failed();
138                }
139
140                deferred.resolve(img);
141            })
142            .on('error', failed)
143        ;
144
145        return deferred.promise();
146    }
147
148    function inlineHandler(target) {
149        var el;
150
151        try {
152            el = $(target);
153        } catch (e) {
154            return false;
155        }
156
157        if (!el.length) {
158            return false;
159        }
160
161        var placeholder = $('<span style="display:none !important" class="lity-inline-placeholder"/>');
162
163        return el
164            .after(placeholder)
165            .on('lity:ready', function(e, instance) {
166                instance.one('lity:remove', function() {
167                    placeholder
168                        .before(el.addClass('lity-hide'))
169                        .remove()
170                    ;
171                });
172            })
173        ;
174    }
175
176    function iframeHandler(target) {
177        var matches, url = target;
178
179        matches = _youtubeRegex.exec(target);
180
181        if (matches) {
182            url = appendQueryParams(
183                protocol() + '//www.youtube' + (matches[2] || '') + '.com/embed/' + matches[4],
184                $.extend(
185                    {
186                        autoplay: 1
187                    },
188                    parseQueryParams(matches[5] || '')
189                )
190            );
191        }
192
193        matches = _vimeoRegex.exec(target);
194
195        if (matches) {
196            url = appendQueryParams(
197                protocol() + '//player.vimeo.com/video/' + matches[3],
198                $.extend(
199                    {
200                        autoplay: 1
201                    },
202                    parseQueryParams(matches[4] || '')
203                )
204            );
205        }
206
207        matches = _googlemapsRegex.exec(target);
208
209        if (matches) {
210            url = appendQueryParams(
211                protocol() + '//www.google.' + matches[3] + '/maps?' + matches[6],
212                {
213                    output: matches[6].indexOf('layer=c') > 0 ? 'svembed' : 'embed'
214                }
215            );
216        }
217
218        return '<div class="lity-iframe-container"><iframe frameborder="0" allowfullscreen src="' + url + '"></iframe></div>';
219    }
220
221    function lity(options) {
222        var _options = {},
223            _handlers = {},
224            _instance,
225            _content,
226            _ready = $.Deferred().resolve();
227
228        function keyup(e) {
229            if (e.keyCode === 27) {
230                close();
231            }
232        }
233
234        function resize() {
235            var height = document.documentElement.clientHeight ? document.documentElement.clientHeight : Math.round(_win.height());
236
237            _content
238                .css('max-height', Math.floor(height) + 'px')
239                .trigger('lity:resize', [_instance, popup])
240            ;
241        }
242
243        function ready(content) {
244            if (!_instance) {
245                return;
246            }
247
248            _content = $(content);
249
250            _win.on('resize', resize);
251            resize();
252
253            _instance
254                .find('.lity-loader')
255                .each(function() {
256                    var el = $(this);
257                    transitionEnd(el).always(function() {
258                        el.remove();
259                    });
260                })
261            ;
262
263            _instance
264                .removeClass('lity-loading')
265                .find('.lity-content')
266                .empty()
267                .append(_content)
268            ;
269
270            _content
271                .removeClass('lity-hide')
272                .trigger('lity:ready', [_instance, popup])
273            ;
274
275            _ready.resolve();
276        }
277
278        function init(handler, content, options) {
279            _instanceCount++;
280            globalToggle();
281
282            _instance = $(options.template)
283                .addClass('lity-loading')
284                .appendTo('body');
285
286            if (!!options.esc) {
287                _win.one('keyup', keyup);
288            }
289
290            setTimeout(function() {
291                _instance
292                    .addClass('lity-opened lity-' + handler)
293                    .on('click', '[data-lity-close]', function(e) {
294                        if ($(e.target).is('[data-lity-close]')) {
295                            close();
296                        }
297                    })
298                    .trigger('lity:open', [_instance, popup])
299                ;
300
301                $.when(content).always(ready);
302            }, 0);
303        }
304
305        function open(target, options) {
306            var handler, content, handlers = $.extend({}, _defaultHandlers, _handlers);
307
308            if (options.handler && handlers[options.handler]) {
309                content = handlers[options.handler](target, instance, popup);
310                handler = options.handler;
311            } else {
312                var lateHandlers = {};
313
314                // Run inline and iframe handlers after all other handlers
315                $.each(['inline', 'iframe'], function(i, name) {
316                    if (handlers[name]) {
317                        lateHandlers[name] = handlers[name];
318                    }
319
320                    delete handlers[name];
321                });
322
323                var call = function(name, callback) {
324                    // Handler might be "removed" by setting callback to null
325                    if (!callback) {
326                        return true;
327                    }
328
329                    content = callback(target, popup);
330
331                    if (!!content) {
332                        handler = name;
333                        return false;
334                    }
335                };
336
337                $.each(handlers, call);
338
339                if (!handler) {
340                    $.each(lateHandlers, call);
341                }
342            }
343
344            if (content) {
345                _ready = $.Deferred();
346                $.when(close()).done($.proxy(init, null, handler, content, options));
347            }
348
349            return !!content;
350        }
351
352        function close() {
353            if (!_instance) {
354                return;
355            }
356
357            var deferred = $.Deferred();
358
359            _ready.done(function() {
360                _instanceCount--;
361                globalToggle();
362
363                _win
364                    .off('resize', resize)
365                    .off('keyup', keyup)
366                ;
367
368                _content.trigger('lity:close', [_instance, popup]);
369
370                _instance
371                    .removeClass('lity-opened')
372                    .addClass('lity-closed')
373                ;
374
375                var instance = _instance, content = _content;
376                _instance = null;
377                _content = null;
378
379                transitionEnd(content.add(instance)).always(function() {
380                    content.trigger('lity:remove', [instance, popup]);
381                    instance.remove();
382                    deferred.resolve();
383                });
384            });
385
386            return deferred.promise();
387        }
388
389        function popup(event) {
390            // If not an event, act as alias of popup.open
391            if (!event.preventDefault) {
392                return popup.open(event);
393            }
394
395            var el = $(this);
396            var target = el.data('lity-target') || el.attr('href') || el.attr('src');
397
398            if (!target) {
399                return;
400            }
401
402            var options = $.extend(
403                {},
404                _defaultOptions,
405                _options,
406                el.data('lity-options') || el.data('lity')
407            );
408
409            if (open(target, options)) {
410                event.preventDefault();
411            }
412        }
413
414        popup.handlers = $.proxy(settings, popup, _handlers);
415        popup.options = $.proxy(settings, popup, _options);
416
417        popup.open = function(target) {
418            open(target, $.extend({}, _defaultOptions, _options));
419            return popup;
420        };
421
422        popup.close = function() {
423            close();
424            return popup;
425        };
426
427        return popup.options(options);
428    }
429
430    lity.version = '1.5.0';
431    lity.handlers = $.proxy(settings, lity, _defaultHandlers);
432    lity.options = $.proxy(settings, lity, _defaultOptions);
433
434    $(document).on('click', '[data-lity]', lity());
435
436    return lity;
437}));

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.