PageSourceSearch

https://www.meishinken.co.jp/blog/wp-content/themes/passing-experience/js/modal-video.js

js meishinken.co.jp collected 2026-10-05 01:20:38 UTC 12,341 bytes, 366 lines download raw bytes

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.2
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(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ModalVideo = f()}})(function(){var define,module,exports;return (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
122Object.defineProperty(exports, "__esModule", {
123  value: true
124});
125
126var _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; }; }();
127
128require('custom-event-polyfill');
129
130var _util = require('../lib/util');
131
132function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
133
134var assign = require('es6-object-assign').assign;
135
136var defaults = {
137  channel: 'youtube',
138  facebook: {},
139  youtube: {
140    autoplay: 1,
141    cc_load_policy: 1,
142    color: null,
143    controls: 1,
144    disablekb: 0,
145    enablejsapi: 0,
146    end: null,
147    fs: 1,
148    h1: null,
149    iv_load_policy: 1,
150    list: null,
151    listType: null,
152    loop: 0,
153    modestbranding: null,
154    origin: null,
155    playlist: null,
156    playsinline: null,
157    rel: 0,
158    showinfo: 1,
159    start: 0,
160    wmode: 'transparent',
161    theme: 'dark',
162    nocookie: false
163  },
164  ratio: '16:9',
165  vimeo: {
166    api: false,
167    autopause: true,
168    autoplay: true,
169    byline: true,
170    callback: null,
171    color: null,
172    height: null,
173    loop: false,
174    maxheight: null,
175    maxwidth: null,
176    player_id: null,
177    portrait: true,
178    title: true,
179    width: null,
180    xhtml: false
181  },
182  allowFullScreen: true,
183  allowAutoplay: true,
184  animationSpeed: 300,
185  classNames: {
186    modalVideo: 'modal-video',
187    modalVideoClose: 'modal-video-close',
188    modalVideoBody: 'modal-video-body',
189    modalVideoInner: 'modal-video-inner',
190    modalVideoIframeWrap: 'modal-video-movie-wrap',
191    modalVideoCloseBtn: 'modal-video-close-btn'
192  },
193  aria: {
194    openMessage: 'You just openned the modal video',
195    dismissBtnMessage: 'Close the modal by clicking here'
196  }
197};
198
199var ModalVideo = function () {
200  function ModalVideo(ele, option) {
201    var _this = this;
202
203    _classCallCheck(this, ModalVideo);
204
205    var opt = assign({}, defaults, option);
206    var selectors = typeof ele === 'string' ? document.querySelectorAll(ele) : ele;
207    var body = document.querySelector('body');
208    var classNames = opt.classNames;
209    var speed = opt.animationSpeed;
210    [].forEach.call(selectors, function (selector) {
211      selector.addEventListener('click', function (event) {
212        if (selector.tagName === 'A') {
213          event.preventDefault();
214        }
215        var videoId = selector.dataset.videoId;
216        var channel = selector.dataset.channel || opt.channel;
217        var id = (0, _util.getUniqId)();
218        var videoUrl = selector.dataset.videoUrl || _this.getVideoUrl(opt, channel, videoId);
219        var html = _this.getHtml(opt, videoUrl, id);
220        (0, _util.append)(body, html);
221        var modal = document.getElementById(id);
222        var btn = modal.querySelector('.js-modal-video-dismiss-btn');
223        modal.focus();
224        modal.addEventListener('click', function () {
225          (0, _util.addClass)(modal, classNames.modalVideoClose);
226          setTimeout(function () {
227            (0, _util.remove)(modal);
228            selector.focus();
229          }, speed);
230        });
231        modal.addEventListener('keydown', function (e) {
232          if (e.which === 9) {
233            e.preventDefault();
234            if (document.activeElement === modal) {
235              btn.focus();
236            } else {
237              modal.setAttribute('aria-label', '');
238              modal.focus();
239            }
240          }
241        });
242        btn.addEventListener('click', function () {
243          (0, _util.triggerEvent)(modal, 'click');
244        });
245      });
246    });
247  }
248
249  _createClass(ModalVideo, [{
250    key: 'getPadding',
251    value: function getPadding(ratio) {
252      var arr = ratio.split(':');
253      var width = Number(arr[0]);
254      var height = Number(arr[1]);
255      var padding = height * 100 / width;
256      return padding + '%';
257    }
258  }, {
259    key: 'getQueryString',
260    value: function getQueryString(obj) {
261      var url = '';
262      Object.keys(obj).forEach(function (key) {
263        url += key + '=' + obj[key] + '&';
264      });
265      return url.substr(0, url.length - 1);
266    }
267  }, {
268    key: 'getVideoUrl',
269    value: function getVideoUrl(opt, channel, videoId) {
270      if (channel === 'youtube') {
271        return this.getYoutubeUrl(opt.youtube, videoId);
272      } else if (channel === 'vimeo') {
273        return this.getVimeoUrl(opt.vimeo, videoId);
274      } else if (channel === 'facebook') {
275        return this.getFacebookUrl(opt.facebook, videoId);
276      }
277      return '';
278    }
279  }, {
280    key: 'getVimeoUrl',
281    value: function getVimeoUrl(vimeo, videoId) {
282      var query = this.getQueryString(vimeo);
283      return '//player.vimeo.com/video/' + videoId + '?' + query;
284    }
285  }, {
286    key: 'getYoutubeUrl',
287    value: function getYoutubeUrl(youtube, videoId) {
288      var query = this.getQueryString(youtube);
289      if (youtube.nocookie === true) {
290        return '//www.youtube-nocookie.com/embed/' + videoId + '?' + query;
291      }
292
293      return '//www.youtube.com/embed/' + videoId + '?' + query;
294    }
295  }, {
296    key: 'getFacebookUrl',
297    value: function getFacebookUrl(facebook, videoId) {
298      return '//www.facebook.com/v2.10/plugins/video.php?href=https://www.facebook.com/facebook/videos/' + videoId + '&' + this.getQueryString(facebook);
299    }
300  }, {
301    key: 'getHtml',
302    value: function getHtml(opt, videoUrl, id) {
303      var padding = this.getPadding(opt.ratio);
304      var classNames = opt.classNames;
305      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 + '">\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="https:' + videoUrl + '" frameborder=\'0\' allowfullscreen=' + opt.allowFullScreen + ' tabindex="-1" ' + (opt.allowAutoplay ? 'allow="autoplay"' : '') + '/>\n            </div>\n          </div>\n        </div>\n      </div>\n    ';
306    }
307  }]);
308
309  return ModalVideo;
310}();
311
312exports.default = ModalVideo;
313module.exports = exports['default'];
314
315},{"../lib/util":5,"custom-event-polyfill":1,"es6-object-assign":2}],4:[function(require,module,exports){
316'use strict';
317
318module.exports = require('./core/');
319
320},{"./core/":3}],5:[function(require,module,exports){
321'use strict';
322
323Object.defineProperty(exports, "__esModule", {
324  value: true
325});
326var append = exports.append = function append(element, string) {
327  var div = document.createElement('div');
328  div.innerHTML = string;
329  while (div.children.length > 0) {
330    element.appendChild(div.children[0]);
331  }
332};
333
334var getUniqId = exports.getUniqId = function getUniqId() {
335  return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
336};
337
338var remove = exports.remove = function remove(element) {
339  if (element && element.parentNode) {
340    element.parentNode.removeChild(element);
341  }
342};
343
344var addClass = exports.addClass = function addClass(element, className) {
345  if (element.classList) {
346    element.classList.add(className);
347  } else {
348    element.className += ' ' + className;
349  }
350};
351
352var triggerEvent = exports.triggerEvent = function triggerEvent(el, eventName, options) {
353  var event = void 0;
354  if (window.CustomEvent) {
355    event = new CustomEvent(eventName, { cancelable: true });
356  } else {
357    event = document.createEvent('CustomEvent');
358    event.initCustomEvent(eventName, false, false, options);
359  }
360  el.dispatchEvent(event);
361};
362
363},{}]},{},[4])(4)
364});
365
366

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.