123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- /**
- * Modules in this bundle
- * @license
- *
- * modal-video:
- * license: appleple
- * author: appleple
- * homepage: http://developer.a-blogcms.jp
- * version: 2.4.1
- *
- * custom-event-polyfill:
- * license: MIT (http://opensource.org/licenses/MIT)
- * maintainers: krambuhl <[email protected]>
- * contributors: Frank Panetta, Mikhail Reenko <[email protected]>, Joscha Feth <[email protected]>
- * homepage: https://github.com/krambuhl/custom-event-polyfill#readme
- * version: 0.3.0
- *
- * es6-object-assign:
- * license: MIT (http://opensource.org/licenses/MIT)
- * author: Rubén Norte <[email protected]>
- * homepage: https://github.com/rubennorte/es6-object-assign
- * version: 1.1.0
- *
- * This header is generated by licensify (https://github.com/twada/licensify)
- */
- (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 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})({1:[function(require,module,exports){
- // Polyfill for creating CustomEvents on IE9/10/11
- // code pulled from:
- // https://github.com/d4tocchini/customevent-polyfill
- // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill
- try {
- var ce = new window.CustomEvent('test');
- ce.preventDefault();
- if (ce.defaultPrevented !== true) {
- // IE has problems with .preventDefault() on custom events
- // http://stackoverflow.com/questions/23349191
- throw new Error('Could not prevent default');
- }
- } catch(e) {
- var CustomEvent = function(event, params) {
- var evt, origPrevent;
- params = params || {
- bubbles: false,
- cancelable: false,
- detail: undefined
- };
- evt = document.createEvent("CustomEvent");
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
- origPrevent = evt.preventDefault;
- evt.preventDefault = function () {
- origPrevent.call(this);
- try {
- Object.defineProperty(this, 'defaultPrevented', {
- get: function () {
- return true;
- }
- });
- } catch(e) {
- this.defaultPrevented = true;
- }
- };
- return evt;
- };
- CustomEvent.prototype = window.Event.prototype;
- window.CustomEvent = CustomEvent; // expose definition to window
- }
- },{}],2:[function(require,module,exports){
- /**
- * Code refactored from Mozilla Developer Network:
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
- */
- 'use strict';
- function assign(target, firstSource) {
- if (target === undefined || target === null) {
- throw new TypeError('Cannot convert first argument to object');
- }
- var to = Object(target);
- for (var i = 1; i < arguments.length; i++) {
- var nextSource = arguments[i];
- if (nextSource === undefined || nextSource === null) {
- continue;
- }
- var keysArray = Object.keys(Object(nextSource));
- for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
- var nextKey = keysArray[nextIndex];
- var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
- if (desc !== undefined && desc.enumerable) {
- to[nextKey] = nextSource[nextKey];
- }
- }
- }
- return to;
- }
- function polyfill() {
- if (!Object.assign) {
- Object.defineProperty(Object, 'assign', {
- enumerable: false,
- configurable: true,
- writable: true,
- value: assign
- });
- }
- }
- module.exports = {
- assign: assign,
- polyfill: polyfill
- };
- },{}],3:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _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; }; }();
- require('custom-event-polyfill');
- var _util = require('../lib/util');
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var assign = require('es6-object-assign').assign;
- var defaults = {
- channel: 'youtube',
- facebook: {},
- youtube: {
- autoplay: 1,
- cc_load_policy: 1,
- color: null,
- controls: 1,
- disablekb: 0,
- enablejsapi: 0,
- end: null,
- fs: 1,
- h1: null,
- iv_load_policy: 1,
- list: null,
- listType: null,
- loop: 0,
- modestbranding: null,
- origin: null,
- playlist: null,
- playsinline: null,
- rel: 0,
- showinfo: 1,
- start: 0,
- wmode: 'transparent',
- theme: 'dark',
- nocookie: false
- },
- ratio: '16:9',
- vimeo: {
- api: false,
- autopause: true,
- autoplay: true,
- byline: true,
- callback: null,
- color: null,
- height: null,
- loop: false,
- maxheight: null,
- maxwidth: null,
- player_id: null,
- portrait: true,
- title: true,
- width: null,
- xhtml: false
- },
- allowFullScreen: true,
- animationSpeed: 300,
- classNames: {
- modalVideo: 'modal-video',
- modalVideoClose: 'modal-video-close',
- modalVideoBody: 'modal-video-body',
- modalVideoInner: 'modal-video-inner',
- modalVideoIframeWrap: 'modal-video-movie-wrap',
- modalVideoCloseBtn: 'modal-video-close-btn'
- },
- aria: {
- openMessage: 'You just openned the modal video',
- dismissBtnMessage: 'Close the modal by clicking here'
- }
- };
- var ModalVideo = function () {
- function ModalVideo(ele, option) {
- var _this = this;
- _classCallCheck(this, ModalVideo);
- var opt = assign({}, defaults, option);
- var selectors = typeof ele === 'string' ? document.querySelectorAll(ele) : ele;
- var body = document.querySelector('body');
- var classNames = opt.classNames;
- var speed = opt.animationSpeed;
- [].forEach.call(selectors, function (selector) {
- selector.addEventListener('click', function (event) {
- if (selector.tagName === 'A') {
- event.preventDefault();
- }
- var videoId = selector.dataset.videoId;
- var channel = selector.dataset.channel || opt.channel;
- var id = (0, _util.getUniqId)();
- var videoUrl = selector.dataset.videoUrl || _this.getVideoUrl(opt, channel, videoId);
- var html = _this.getHtml(opt, videoUrl, id);
- (0, _util.append)(body, html);
- var modal = document.getElementById(id);
- var btn = modal.querySelector('.js-modal-video-dismiss-btn');
- modal.focus();
- modal.addEventListener('click', function () {
- (0, _util.addClass)(modal, classNames.modalVideoClose);
- setTimeout(function () {
- (0, _util.remove)(modal);
- selector.focus();
- }, speed);
- });
- modal.addEventListener('keydown', function (e) {
- if (e.which === 9) {
- e.preventDefault();
- if (document.activeElement === modal) {
- btn.focus();
- } else {
- modal.setAttribute('aria-label', '');
- modal.focus();
- }
- }
- });
- btn.addEventListener('click', function () {
- (0, _util.triggerEvent)(modal, 'click');
- });
- });
- });
- }
- _createClass(ModalVideo, [{
- key: 'getPadding',
- value: function getPadding(ratio) {
- var arr = ratio.split(':');
- var width = Number(arr[0]);
- var height = Number(arr[1]);
- var padding = height * 100 / width;
- return padding + '%';
- }
- }, {
- key: 'getQueryString',
- value: function getQueryString(obj) {
- var url = '';
- Object.keys(obj).forEach(function (key) {
- url += key + '=' + obj[key] + '&';
- });
- return url.substr(0, url.length - 1);
- }
- }, {
- key: 'getVideoUrl',
- value: function getVideoUrl(opt, channel, videoId) {
- if (channel === 'youtube') {
- return this.getYoutubeUrl(opt.youtube, videoId);
- } else if (channel === 'vimeo') {
- return this.getVimeoUrl(opt.vimeo, videoId);
- } else if (channel === 'facebook') {
- return this.getFacebookUrl(opt.facebook, videoId);
- }
- return '';
- }
- }, {
- key: 'getVimeoUrl',
- value: function getVimeoUrl(vimeo, videoId) {
- var query = this.getQueryString(vimeo);
- return '//player.vimeo.com/video/' + videoId + '?' + query;
- }
- }, {
- key: 'getYoutubeUrl',
- value: function getYoutubeUrl(youtube, videoId) {
- var query = this.getQueryString(youtube);
- if (youtube.nocookie === true) {
- return '//www.youtube-nocookie.com/embed/' + videoId + '?' + query;
- }
- return '//www.youtube.com/embed/' + videoId + '?' + query;
- }
- }, {
- key: 'getFacebookUrl',
- value: function getFacebookUrl(facebook, videoId) {
- return '//www.facebook.com/v2.10/plugins/video.php?href=https://www.facebook.com/facebook/videos/' + videoId + '&' + this.getQueryString(facebook);
- }
- }, {
- key: 'getHtml',
- value: function getHtml(opt, videoUrl, id) {
- var padding = this.getPadding(opt.ratio);
- var classNames = opt.classNames;
- 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="' + videoUrl + '" frameborder=\'0\' allowfullscreen=' + opt.allowFullScreen + ' tabindex="-1"/>\n </div>\n </div>\n </div>\n </div>\n ';
- }
- }]);
- return ModalVideo;
- }();
- exports.default = ModalVideo;
- module.exports = exports['default'];
- },{"../lib/util":5,"custom-event-polyfill":1,"es6-object-assign":2}],4:[function(require,module,exports){
- 'use strict';
- module.exports = require('./core/');
- },{"./core/":3}],5:[function(require,module,exports){
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var append = exports.append = function append(element, string) {
- var div = document.createElement('div');
- div.innerHTML = string;
- while (div.children.length > 0) {
- element.appendChild(div.children[0]);
- }
- };
- var getUniqId = exports.getUniqId = function getUniqId() {
- return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
- };
- var remove = exports.remove = function remove(element) {
- if (element && element.parentNode) {
- element.parentNode.removeChild(element);
- }
- };
- var addClass = exports.addClass = function addClass(element, className) {
- if (element.classList) {
- element.classList.add(className);
- } else {
- element.className += ' ' + className;
- }
- };
- var triggerEvent = exports.triggerEvent = function triggerEvent(el, eventName, options) {
- var event = void 0;
- if (window.CustomEvent) {
- event = new CustomEvent(eventName, { cancelable: true });
- } else {
- event = document.createEvent('CustomEvent');
- event.initCustomEvent(eventName, false, false, options);
- }
- el.dispatchEvent(event);
- };
- },{}]},{},[4])(4)
- });
|