PageSourceSearch

https://earthpet-house.jp/wp-content/themes/original/js/jquery-modal-video.js

js earthpet-house.jp collected 2026-10-02 15:15:33 UTC 14,855 bytes, 440 lines download raw bytes

vendor: 14,855 bytes, lines 1-440
1/**
2 * Modules in this bundle
3 * @license
4 *
5 * modal-video:
6 *   license: appleple
7 *   author: appleple
8 *   homepage: http://developer.a-blogcms.jp
9 *   version: 2.4.6
10 *
11 * custom-event-polyfill:
12 *   license: MIT (http://opensource.org/licenses/MIT)
13 *   contributors: Frank Panetta, Mikhail Reenko <[email protected]>, Joscha Feth <[email protected]>
14 *   homepage: https://github.com/krambuhl/custom-event-polyfill#readme
15 *   version: 0.3.0
16 *
17 * es6-object-assign:
18 *   license: MIT (http://opensource.org/licenses/MIT)
19 *   author: Rubén Norte <[email protected]>
20 *   homepage: https://github.com/rubennorte/es6-object-assign
21 *   version: 1.1.0
22 *
23 * This header is generated by licensify (https://github.com/twada/licensify)
24 */
25(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
26// Polyfill for creating CustomEvents on IE9/10/11
27
28// code pulled from:
29// https://github.com/d4tocchini/customevent-polyfill
30// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill
31
32try {
33    var ce = new window.CustomEvent('test');
34    ce.preventDefault();
35    if (ce.defaultPrevented !== true) {
36        // IE has problems with .preventDefault() on custom events
37        // http://stackoverflow.com/questions/23349191
38        throw new Error('Could not prevent default');
39    }
40} catch(e) {
41  var CustomEvent = function(event, params) {
42    var evt, origPrevent;
43    params = params || {
44      bubbles: false,
45      cancelable: false,
46      detail: undefined
47    };
48
49    evt = document.createEvent("CustomEvent");
50    evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
51    origPrevent = evt.preventDefault;
52    evt.preventDefault = function () {
53      origPrevent.call(this);
54      try {
55        Object.defineProperty(this, 'defaultPrevented', {
56          get: function () {
57            return true;
58          }
59        });
60      } catch(e) {
61        this.defaultPrevented = true;
62      }
63    };
64    return evt;
65  };
66
67  CustomEvent.prototype = window.Event.prototype;
68  window.CustomEvent = CustomEvent; // expose definition to window
69}
70
71},{}],2:[function(require,module,exports){
72/**
73 * Code refactored from Mozilla Developer Network:
74 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
75 */
76
77'use strict';
78
79function assign(target, firstSource) {
80  if (target === undefined || target === null) {
81    throw new TypeError('Cannot convert first argument to object');
82  }
83
84  var to = Object(target);
85  for (var i = 1; i < arguments.length; i++) {
86    var nextSource = arguments[i];
87    if (nextSource === undefined || nextSource === null) {
88      continue;
89    }
90
91    var keysArray = Object.keys(Object(nextSource));
92    for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
93      var nextKey = keysArray[nextIndex];
94      var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
95      if (desc !== undefined && desc.enumerable) {
96        to[nextKey] = nextSource[nextKey];
97      }
98    }
99  }
100  return to;
101}
102
103function polyfill() {
104  if (!Object.assign) {
105    Object.defineProperty(Object, 'assign', {
106      enumerable: false,
107      configurable: true,
108      writable: true,
109      value: assign
110    });
111  }
112}
113
114module.exports = {
115  assign: assign,
116  polyfill: polyfill
117};
118
119},{}],3:[function(require,module,exports){
120'use strict';
121
122var ModalVideo = require('../index');
123
124var applyJQuery = function applyJQuery(jQuery) {
125  jQuery.fn.modalVideo = function (settings) {
126    if (typeof settings === 'strings') {} else {
127      new ModalVideo(this, settings);
128    }
129    return this;
130  };
131};
132
133if (typeof define === 'function' && define.amd) {
134  define(['jquery'], applyJQuery);
135} else {
136  var jq = window.jQuery ? window.jQuery : window.$;
137  if (typeof jq !== 'undefined') {
138    applyJQuery(jq);
139  }
140}
141
142module.exports = applyJQuery;
143
144},{"../index":5}],4:[function(require,module,exports){
145'use strict';
146
147Object.defineProperty(exports, "__esModule", {
148  value: true
149});
150
151var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
152
153require('custom-event-polyfill');
154
155var _util = require('../lib/util');
156
157function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
158
159var assign = require('es6-object-assign').assign;
160
161var defaults = {
162  channel: 'youtube',
163  facebook: {},
164  youtube: {
165    autoplay: 1,
166    cc_load_policy: 1,
167    color: null,
168    controls: 1,
169    disablekb: 0,
170    enablejsapi: 0,
171    end: null,
172    fs: 1,
173    h1: null,
174    iv_load_policy: 1,
175    loop: 0,
176    modestbranding: null,
177    mute: 0,
178    origin: null,
179    playsinline: null,
180    rel: 0,
181    showinfo: 1,
182    start: 0,
183    wmode: 'transparent',
184    theme: 'dark',
185    nocookie: false
186  },
187  ratio: '16:9',
188  vimeo: {
189    api: false,
190    autopause: true,
191    autoplay: true,
192    byline: true,
193    callback: null,
194    color: null,
195    controls: true,
196    height: null,
197    loop: false,
198    maxheight: null,
199    maxwidth: null,
200    muted: false,
201    player_id: null,
202    portrait: true,
203    title: true,
204    width: null,
205    xhtml: false
206  },
207  allowFullScreen: true,
208  allowAutoplay: true,
209  animationSpeed: 300,
210  classNames: {
211    modalVideo: 'modal-video',
212    modalVideoClose: 'modal-video-close',
213    modalVideoBody: 'modal-video-body',
214    modalVideoInner: 'modal-video-inner',
215    modalVideoIframeWrap: 'modal-video-movie-wrap',
216    modalVideoCloseBtn: 'modal-video-close-btn'
217  },
218  aria: {
219    openMessage: 'You just openned the modal video',
220    dismissBtnMessage: 'Close the modal by clicking here'
221  }
222};
223
224var ModalVideo = function () {
225  function ModalVideo(ele, option) {
226    var _this = this;
227
228    _classCallCheck(this, ModalVideo);
229
230    var opt = assign({}, defaults, option);
231    var selectors = typeof ele === 'string' ? document.querySelectorAll(ele) : ele;
232    var body = document.querySelector('body');
233    var classNames = opt.classNames;
234    var speed = opt.animationSpeed;
235    [].forEach.call(selectors, function (selector) {
236      selector.addEventListener('click', function (event) {
237        if (selector.tagName === 'A') {
238          event.preventDefault();
239        }
240        var videoId = selector.dataset.videoId;
241        var channel = selector.dataset.channel || opt.channel;
242        var id = (0, _util.getUniqId)();
243        var videoUrl = selector.dataset.videoUrl || _this.getVideoUrl(opt, channel, videoId);
244        var html = _this.getHtml(opt, videoUrl, id);
245        (0, _util.append)(body, html);
246        var modal = document.getElementById(id);
247        var btn = modal.querySelector('.js-modal-video-dismiss-btn');
248        var timeout = void 0; // used for resize
249        var resizeModalVideoWhenHeightGreaterThanWindowHeight = function resizeModalVideoWhenHeightGreaterThanWindowHeight() {
250          clearTimeout(timeout);
251          // Resize modal-video-iframe-wrap when window size changed when the height of the video is greater than the height of the window.
252          timeout = setTimeout(function () {
253            var width = _this.getWidthFulfillAspectRatio(opt.ratio, window.innerHeight, window.innerWidth);
254
255            var modalVideoInner = document.getElementById('modal-video-inner-' + id);
256            if (modalVideoInner.style.maxWidth !== width) {
257              modalVideoInner.style.maxWidth = width;
258            }
259          }, 10);
260        };
261        modal.focus();
262        modal.addEventListener('click', function () {
263          (0, _util.addClass)(modal, classNames.modalVideoClose);
264          window.removeEventListener('resize', resizeModalVideoWhenHeightGreaterThanWindowHeight);
265          setTimeout(function () {
266            (0, _util.remove)(modal);
267            selector.focus();
268          }, speed);
269        });
270        modal.addEventListener('keydown', function (e) {
271          if (e.which === 9) {
272            e.preventDefault();
273            if (document.activeElement === modal) {
274              btn.focus();
275            } else {
276              modal.setAttribute('aria-label', '');
277              modal.focus();
278            }
279          }
280        });
281        window.addEventListener('resize', resizeModalVideoWhenHeightGreaterThanWindowHeight);
282        btn.addEventListener('click', function () {
283          (0, _util.triggerEvent)(modal, 'click');
284        });
285      });
286    });
287  }
288
289  _createClass(ModalVideo, [{
290    key: 'getPadding',
291    value: function getPadding(ratio) {
292      var arr = ratio.split(':');
293      var width = Number(arr[0]);
294      var height = Number(arr[1]);
295      var padding = height * 100 / width;
296      return padding + '%';
297    }
298
299    /**
300     * Calculate the width of the video fulfill aspect ratio.
301     * When the height of the video is greater than the height of the window,
302     * this function return the width that fulfill the aspect ratio for the height of the window.
303     * In other cases, this function return '100%'(the height relative to the width is determined by css).
304     *
305     * @param string ratio
306     * @param number maxHeight
307     * @param number maxWidth
308     * @returns string
309     */
310
311  }, {
312    key: 'getWidthFulfillAspectRatio',
313    value: function getWidthFulfillAspectRatio(ratio, maxHeight, maxWidth) {
314      var arr = ratio.split(':');
315      var width = Number(arr[0]);
316      var height = Number(arr[1]);
317
318      // Height that fulfill the aspect ratio for maxWidth.
319      var videoHeight = maxWidth * (height / width);
320
321      if (maxHeight < videoHeight) {
322        // when the height of the video is greater than the height of the window.
323        // calculate the width that fulfill the aspect ratio for the height of the window.
324
325        // ex: 16:9 aspect ratio
326        // 16:9 = width : height
327        // → width = 16 / 9 * height
328        return Math.floor(width / height * maxHeight) + 'px';
329      }
330
331      return '100%';
332    }
333  }, {
334    key: 'getQueryString',
335    value: function getQueryString(obj) {
336      var url = '';
337      Object.keys(obj).forEach(function (key) {
338        url += key + '=' + obj[key] + '&';
339      });
340      return url.substr(0, url.length - 1);
341    }
342  }, {
343    key: 'getVideoUrl',
344    value: function getVideoUrl(opt, channel, videoId) {
345      if (channel === 'youtube') {
346        return this.getYoutubeUrl(opt.youtube, videoId);
347      } else if (channel === 'vimeo') {
348        return this.getVimeoUrl(opt.vimeo, videoId);
349      } else if (channel === 'facebook') {
350        return this.getFacebookUrl(opt.facebook, videoId);
351      } else if (channel === 'custom') {
352        return opt.url;
353      }
354      return '';
355    }
356  }, {
357    key: 'getVimeoUrl',
358    value: function getVimeoUrl(vimeo, videoId) {
359      var query = this.getQueryString(vimeo);
360      return '//player.vimeo.com/video/' + videoId + '?' + query;
361    }
362  }, {
363    key: 'getYoutubeUrl',
364    value: function getYoutubeUrl(youtube, videoId) {
365      var query = this.getQueryString(youtube);
366      if (youtube.nocookie === true) {
367        return '//www.youtube-nocookie.com/embed/' + videoId + '?' + query;
368      }
369
370      return '//www.youtube.com/embed/' + videoId + '?' + query;
371    }
372  }, {
373    key: 'getFacebookUrl',
374    value: function getFacebookUrl(facebook, videoId) {
375      return '//www.facebook.com/v2.10/plugins/video.php?href=https://www.facebook.com/facebook/videos/' + videoId + '&' + this.getQueryString(facebook);
376    }
377  }, {
378    key: 'getHtml',
379    value: function getHtml(opt, videoUrl, id) {
380      var padding = this.getPadding(opt.ratio);
381      var classNames = opt.classNames;
382      return '\n      <div class="' + classNames.modalVideo + '" tabindex="-1" role="dialog" aria-label="' + opt.aria.openMessage + '" id="' + id + '">\n        <div class="' + classNames.modalVideoBody + '">\n          <div class="' + classNames.modalVideoInner + '" id="modal-video-inner-' + id + '">\n            <div class="' + classNames.modalVideoIframeWrap + '" style="padding-bottom:' + padding + '">\n              <button class="' + classNames.modalVideoCloseBtn + ' js-modal-video-dismiss-btn" aria-label="' + opt.aria.dismissBtnMessage + '"></button>\n              <iframe width=\'460\' height=\'230\' src="' + videoUrl + '" frameborder=\'0\' allowfullscreen=' + opt.allowFullScreen + ' tabindex="-1" allow="' + (opt.allowAutoplay ? 'autoplay;' : '') + ' accelerometer; encrypted-media; gyroscope; picture-in-picture" />\n            </div>\n          </div>\n        </div>\n      </div>\n    ';
383    }
384  }]);
385
386  return ModalVideo;
387}();
388
389exports.default = ModalVideo;
390module.exports = exports['default'];
391
392},{"../lib/util":6,"custom-event-polyfill":1,"es6-object-assign":2}],5:[function(require,module,exports){
393'use strict';
394
395module.exports = require('./core/');
396
397},{"./core/":4}],6:[function(require,module,exports){
398'use strict';
399
400Object.defineProperty(exports, "__esModule", {
401  value: true
402});
403var append = exports.append = function append(element, string) {
404  var div = document.createElement('div');
405  div.innerHTML = string;
406  while (div.children.length > 0) {
407    element.appendChild(div.children[0]);
408  }
409};
410
411var getUniqId = exports.getUniqId = function getUniqId() {
412  return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
413};
414
415var remove = exports.remove = function remove(element) {
416  if (element && element.parentNode) {
417    element.parentNode.removeChild(element);
418  }
419};
420
421var addClass = exports.addClass = function addClass(element, className) {
422  if (element.classList) {
423    element.classList.add(className);
424  } else {
425    element.className += ' ' + className;
426  }
427};
428
429var triggerEvent = exports.triggerEvent = function triggerEvent(el, eventName, options) {
430  var event = void 0;
431  if (window.CustomEvent) {
432    event = new CustomEvent(eventName, { cancelable: true });
433  } else {
434    event = document.createEvent('CustomEvent');
435    event.initCustomEvent(eventName, false, false, options);
436  }
437  el.dispatchEvent(event);
438};
439
440},{}]},{},[3]);

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.