photoswipe-simplify
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -0,4 +1,6 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/*! | ||
* photoswipe-simplify v0.0.1: PhotoSwipe.js simplify by the VanillaJS. | ||
* (c) 2018 Mineo Okuda | ||
* photoswipe-simplify v0.0.2: PhotoSwipe.js simplify by the VanillaJS. | ||
* (c) 2019 Mineo Okuda | ||
* MIT License | ||
@@ -18,238 +20,498 @@ * git+ssh://git@github.com:min30327/photoswipe-simplify.git | ||
(function(root, factory) { | ||
'use strict'; | ||
(function (global, factory) { | ||
(typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : factory(); | ||
})(this, function () { | ||
'use strict'; | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} | ||
else if (typeof exports === 'object') { | ||
// COMMONJS | ||
module.exports = factory(); | ||
} | ||
else { | ||
// BROWSER | ||
root.photoswipeSimplify = factory(); | ||
} | ||
}(this, (function() { | ||
/** | ||
* @this {Promise} | ||
*/ | ||
'use strict'; | ||
function finallyConstructor(callback) { | ||
var constructor = this.constructor; | ||
return this.then(function (value) { | ||
return constructor.resolve(callback()).then(function () { | ||
return value; | ||
}); | ||
}, function (reason) { | ||
return constructor.resolve(callback()).then(function () { | ||
return constructor.reject(reason); | ||
}); | ||
}); | ||
} | ||
var defaults = { | ||
target : "[data-pswp]" | ||
}; | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
// other code modifying setTimeout (like sinon.useFakeTimers()) | ||
var setTimeoutFunc = setTimeout; | ||
var extend = function () { | ||
function noop() {} | ||
// Variables | ||
var extended = {}; | ||
var deep = false; | ||
var i = 0; | ||
var length = arguments.length; | ||
// Polyfill for Function.prototype.bind | ||
function bind(fn, thisArg) { | ||
return function () { | ||
fn.apply(thisArg, arguments); | ||
}; | ||
} | ||
// Merge the object into the extended object | ||
var merge = function (obj) { | ||
for (var prop in obj) { | ||
if (obj.hasOwnProperty(prop)) { | ||
extended[prop] = obj[prop]; | ||
} | ||
} | ||
}; | ||
/** | ||
* @constructor | ||
* @param {Function} fn | ||
*/ | ||
function Promise(fn) { | ||
if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new'); | ||
if (typeof fn !== 'function') throw new TypeError('not a function'); | ||
/** @type {!number} */ | ||
this._state = 0; | ||
/** @type {!boolean} */ | ||
this._handled = false; | ||
/** @type {Promise|undefined} */ | ||
this._value = undefined; | ||
/** @type {!Array<!Function>} */ | ||
this._deferreds = []; | ||
// Loop through each object and conduct a merge | ||
for ( i = 0; i < length; i++ ) { | ||
var obj = arguments[i]; | ||
merge(obj); | ||
} | ||
doResolve(fn, this); | ||
} | ||
return extended; | ||
function handle(self, deferred) { | ||
while (self._state === 3) { | ||
self = self._value; | ||
} | ||
if (self._state === 0) { | ||
self._deferreds.push(deferred); | ||
return; | ||
} | ||
self._handled = true; | ||
Promise._immediateFn(function () { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
if (cb === null) { | ||
(self._state === 1 ? resolve : reject)(deferred.promise, self._value); | ||
return; | ||
} | ||
var ret; | ||
try { | ||
ret = cb(self._value); | ||
} catch (e) { | ||
reject(deferred.promise, e); | ||
return; | ||
} | ||
resolve(deferred.promise, ret); | ||
}); | ||
} | ||
}; | ||
var photoswipeSimplify = function(){}; | ||
function resolve(self, newValue) { | ||
try { | ||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure | ||
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.'); | ||
if (newValue && ((typeof newValue === 'undefined' ? 'undefined' : _typeof(newValue)) === 'object' || typeof newValue === 'function')) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
self._state = 3; | ||
self._value = newValue; | ||
finale(self); | ||
return; | ||
} else if (typeof then === 'function') { | ||
doResolve(bind(then, newValue), self); | ||
return; | ||
} | ||
} | ||
self._state = 1; | ||
self._value = newValue; | ||
finale(self); | ||
} catch (e) { | ||
reject(self, e); | ||
} | ||
} | ||
photoswipeSimplify.prototype = { | ||
function reject(self, newValue) { | ||
self._state = 2; | ||
self._value = newValue; | ||
finale(self); | ||
} | ||
initialized: false, | ||
pswpElement: "", | ||
galleries : [], | ||
thumbnails : [], | ||
tmps : [], | ||
items : [], | ||
options : {}, | ||
ImagesLoaded : false, | ||
function finale(self) { | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function () { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
} | ||
}); | ||
} | ||
init : function(options){ | ||
var self = this; | ||
self.options = extend(defaults, options || {}); | ||
if(!self.initialized){ | ||
self.append_template(); | ||
self.initialized = true; | ||
} | ||
self.initPhotoSwipe(self.options.target); | ||
}, | ||
for (var i = 0, len = self._deferreds.length; i < len; i++) { | ||
handle(self, self._deferreds[i]); | ||
} | ||
self._deferreds = null; | ||
} | ||
append_template: function (){ | ||
var body = document.getElementsByTagName('body')[0]; | ||
var elem = document.createElement('div'); | ||
elem.innerHTML = '<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div> </div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>'; | ||
body.appendChild(elem); | ||
}, | ||
/** | ||
* @constructor | ||
*/ | ||
function Handler(onFulfilled, onRejected, promise) { | ||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; | ||
this.onRejected = typeof onRejected === 'function' ? onRejected : null; | ||
this.promise = promise; | ||
} | ||
initPhotoSwipe : function(selector) { | ||
var self = this; | ||
self.pswpElement = document.querySelectorAll('.pswp')[0]; | ||
self.galleries = document.querySelectorAll( selector ); | ||
/** | ||
* Take a potentially misbehaving resolver function and make sure | ||
* onFulfilled and onRejected are only called once. | ||
* | ||
* Makes no guarantees about asynchrony. | ||
*/ | ||
function doResolve(fn, self) { | ||
var done = false; | ||
try { | ||
fn(function (value) { | ||
if (done) return; | ||
done = true; | ||
resolve(self, value); | ||
}, function (reason) { | ||
if (done) return; | ||
done = true; | ||
reject(self, reason); | ||
}); | ||
} catch (ex) { | ||
if (done) return; | ||
done = true; | ||
reject(self, ex); | ||
} | ||
} | ||
if(self.galleries.length > 0){ | ||
for(var i = 0; i < self.galleries.length; i++) { | ||
Promise.prototype['catch'] = function (onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
self.items[i] = []; | ||
self.thumbnails[i] = []; | ||
self.tmps[i] = self.galleries[i].getElementsByTagName('a'); | ||
Promise.prototype.then = function (onFulfilled, onRejected) { | ||
// @ts-ignore | ||
var prom = new this.constructor(noop); | ||
self.tmps[i] = Array.prototype.slice.call(self.tmps[i]); | ||
handle(this, new Handler(onFulfilled, onRejected, prom)); | ||
return prom; | ||
}; | ||
if(self.tmps[i].length > 0){ | ||
for(var l = 0; l < self.tmps[i].length; l++) { | ||
Promise.prototype['finally'] = finallyConstructor; | ||
var src = self.tmps[i][l].getAttribute('href'); | ||
if (/(.gif|.jpe?g|.png|.bmp)/.test(src.toLowerCase())) { | ||
self.thumbnails[i].push(self.tmps[i][l]); | ||
} | ||
} | ||
} | ||
var promise = new Promise(function (resolve) { | ||
self.parseItems(resolve,i); | ||
}); | ||
promise.then((function(){ | ||
self.galleryLoaded(); | ||
})); | ||
if(self.thumbnails[i].length > 0){ | ||
for(var n = 0; n < self.thumbnails[i].length; n++) { | ||
self.thumbnails[i][n].setAttribute('data-pswp-index',i); | ||
self.thumbnails[i][n].classList.add('pswp--item'); | ||
Promise.all = function (arr) { | ||
return new Promise(function (resolve, reject) { | ||
if (!arr || typeof arr.length === 'undefined') throw new TypeError('Promise.all accepts an array'); | ||
var args = Array.prototype.slice.call(arr); | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
self.attachEvent(self.thumbnails[i][n],i,n); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
galleryLoaded : function(){ | ||
var self = this; | ||
if(self.galleries.length > 0){ | ||
for(var i = 0; i < self.galleries.length; i++) { | ||
self.galleries[i].classList.add('pswp--loaded'); | ||
} | ||
} | ||
}, | ||
function res(i, val) { | ||
try { | ||
if (val && ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call(val, function (val) { | ||
res(i, val); | ||
}, reject); | ||
return; | ||
} | ||
} | ||
args[i] = val; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
} | ||
attachEvent : function(el,galleryIndex,index){ | ||
var self = this; | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
}; | ||
el.addEventListener('click',(function(e){ | ||
e.preventDefault(); | ||
document.body.classList.add('pswp--launched'); | ||
var active = document.querySelector('.pswp--active'); | ||
if(active){ | ||
active.classList.remove('pswp--active'); | ||
} | ||
self.galleries[galleryIndex].classList.add('pswp--active'); | ||
self.galleries[galleryIndex].setAttribute('data-pswp-index',index); | ||
if(self.galleries[galleryIndex].classList.contains('pswp--loaded')){ | ||
if(index >= 0) { | ||
self.open(galleryIndex,index); | ||
} | ||
} | ||
return false; | ||
})); | ||
}, | ||
Promise.resolve = function (value) { | ||
if (value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value.constructor === Promise) { | ||
return value; | ||
} | ||
getImageSizes : function(src,galleryIndex,i,title,author){ | ||
var self = this; | ||
new Promise(function (resolve, reject) { | ||
var img = new Image(); | ||
img.src = src; | ||
img.onload = function(){ | ||
self.items[galleryIndex][i] ={ | ||
src: src, | ||
w : img.naturalWidth, | ||
h : img.naturalHeight, | ||
title : title, | ||
author : author | ||
}; | ||
resolve(); | ||
}; | ||
}); | ||
}, | ||
return new Promise(function (resolve) { | ||
resolve(value); | ||
}); | ||
}; | ||
open : function(galleryIndex,index) { | ||
Promise.reject = function (value) { | ||
return new Promise(function (resolve, reject) { | ||
reject(value); | ||
}); | ||
}; | ||
var self = this; | ||
var pwsp; | ||
var gallery = self.galleries[galleryIndex]; | ||
Promise.race = function (values) { | ||
return new Promise(function (resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
values[i].then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
self.options.galleryUID = galleryIndex; | ||
self.options.index = index; | ||
self.options.getThumbBoundsFn = function(index) { | ||
var gallery = document.querySelector('.pswp--active'); | ||
if(gallery){ | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = typeof setImmediate === 'function' && function (fn) { | ||
setImmediate(fn); | ||
} || function (fn) { | ||
setTimeoutFunc(fn, 0); | ||
}; | ||
var thumbnail = gallery.querySelectorAll('.pswp--item')[index].getElementsByTagName('img')[0], | ||
pageYScroll = window.pageYOffset || document.documentElement.scrollTop, | ||
rect = thumbnail.getBoundingClientRect(); | ||
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}; | ||
} | ||
}; | ||
self.options.addCaptionHTMLFn = function(item, captionEl, isFake) { | ||
if(!item.title) { | ||
captionEl.children[0].innerText = ''; | ||
return false; | ||
} | ||
captionEl.children[0].innerHTML = item.title; | ||
if(item.author){ | ||
captionEl.children[0].innerHTML += '<br><small>' + item.author + '</small>'; | ||
} | ||
return true; | ||
}; | ||
document.body.classList.remove('pswp--launched'); | ||
pwsp = new PhotoSwipe( self.pswpElement, PhotoSwipeUI_Default, self.items[galleryIndex], self.options); | ||
pwsp.init(); | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
} | ||
}; | ||
}, | ||
parseItems : function(resolve,galleryIndex) { | ||
var self = this; | ||
var promises = []; | ||
if(self.thumbnails[galleryIndex].length > 0){ | ||
/** @suppress {undefinedVars} */ | ||
var globalNS = function () { | ||
// the only reliable means to get the global object is | ||
// `Function('return this')()` | ||
// However, this causes CSP violations in Chrome apps. | ||
if (typeof self !== 'undefined') { | ||
return self; | ||
} | ||
if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
if (typeof global !== 'undefined') { | ||
return global; | ||
} | ||
throw new Error('unable to locate global object'); | ||
}(); | ||
for(var i = 0;i < self.thumbnails[galleryIndex].length; i++) { | ||
if (!('Promise' in globalNS)) { | ||
globalNS['Promise'] = Promise; | ||
} else if (!globalNS.Promise.prototype['finally']) { | ||
globalNS.Promise.prototype['finally'] = finallyConstructor; | ||
} | ||
}); | ||
var src = self.thumbnails[galleryIndex][i].getAttribute('href'); | ||
var title = self.thumbnails[galleryIndex][i].getAttribute('data-caption'); | ||
var author = self.thumbnails[galleryIndex][i].getAttribute('data-author'); | ||
promises.push(self.getImageSizes(src,galleryIndex,i,title,author)); | ||
Promise.all(promises).then((function () { | ||
resolve(); | ||
})); | ||
} | ||
} | ||
} | ||
}; | ||
var pswpSimplify = new photoswipeSimplify(); | ||
(function (root, factory) { | ||
'use strict'; | ||
return pswpSimplify; | ||
})) | ||
); | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') { | ||
// COMMONJS | ||
module.exports = factory(); | ||
} else { | ||
// BROWSER | ||
root.photoswipeSimplify = factory(); | ||
} | ||
})(this, function () { | ||
'use strict'; | ||
var defaults = { | ||
target: "[data-pswp]" | ||
}; | ||
var extend = function extend() { | ||
// Variables | ||
var extended = {}; | ||
var deep = false; | ||
var i = 0; | ||
var length = arguments.length; | ||
// Merge the object into the extended object | ||
var merge = function merge(obj) { | ||
for (var prop in obj) { | ||
if (obj.hasOwnProperty(prop)) { | ||
extended[prop] = obj[prop]; | ||
} | ||
} | ||
}; | ||
// Loop through each object and conduct a merge | ||
for (i = 0; i < length; i++) { | ||
var obj = arguments[i]; | ||
merge(obj); | ||
} | ||
return extended; | ||
}; | ||
var photoswipeSimplify = function photoswipeSimplify() {}; | ||
photoswipeSimplify.prototype = { | ||
initialized: false, | ||
pswpElement: "", | ||
galleries: [], | ||
thumbnails: [], | ||
tmps: [], | ||
items: [], | ||
options: {}, | ||
ImagesLoaded: false, | ||
init: function init(options) { | ||
var self = this; | ||
self.options = extend(defaults, options || {}); | ||
if (!self.initialized) { | ||
self.append_template(); | ||
self.initialized = true; | ||
} | ||
self.initPhotoSwipe(self.options.target); | ||
}, | ||
append_template: function append_template() { | ||
var body = document.getElementsByTagName('body')[0]; | ||
var elem = document.createElement('div'); | ||
elem.innerHTML = '<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div> </div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>'; | ||
body.appendChild(elem); | ||
}, | ||
initPhotoSwipe: function initPhotoSwipe(selector) { | ||
var self = this; | ||
self.pswpElement = document.querySelectorAll('.pswp')[0]; | ||
self.galleries = document.querySelectorAll(selector); | ||
if (self.galleries.length > 0) { | ||
for (var i = 0; i < self.galleries.length; i++) { | ||
self.items[i] = []; | ||
self.thumbnails[i] = []; | ||
self.tmps[i] = self.galleries[i].getElementsByTagName('a'); | ||
self.tmps[i] = Array.prototype.slice.call(self.tmps[i]); | ||
if (self.tmps[i].length > 0) { | ||
for (var l = 0; l < self.tmps[i].length; l++) { | ||
var src = self.tmps[i][l].getAttribute('href'); | ||
if (/(.gif|.jpe?g|.png|.bmp)/.test(src.toLowerCase())) { | ||
self.thumbnails[i].push(self.tmps[i][l]); | ||
} | ||
} | ||
} | ||
var promise = new Promise(function (resolve) { | ||
self.parseItems(resolve, i); | ||
}); | ||
promise.then(function () { | ||
self.galleryLoaded(); | ||
}); | ||
if (self.thumbnails[i].length > 0) { | ||
for (var n = 0; n < self.thumbnails[i].length; n++) { | ||
self.thumbnails[i][n].setAttribute('data-pswp-index', i); | ||
self.thumbnails[i][n].classList.add('pswp--item'); | ||
self.attachEvent(self.thumbnails[i][n], i, n); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
galleryLoaded: function galleryLoaded() { | ||
var self = this; | ||
if (self.galleries.length > 0) { | ||
for (var i = 0; i < self.galleries.length; i++) { | ||
self.galleries[i].classList.add('pswp--loaded'); | ||
} | ||
} | ||
}, | ||
attachEvent: function attachEvent(el, galleryIndex, index) { | ||
var self = this; | ||
el.addEventListener('click', function (e) { | ||
e.preventDefault(); | ||
document.body.classList.add('pswp--launched'); | ||
var active = document.querySelector('.pswp--active'); | ||
if (active) { | ||
active.classList.remove('pswp--active'); | ||
} | ||
self.galleries[galleryIndex].classList.add('pswp--active'); | ||
self.galleries[galleryIndex].setAttribute('data-pswp-index', index); | ||
if (self.galleries[galleryIndex].classList.contains('pswp--loaded')) { | ||
if (index >= 0) { | ||
self.open(galleryIndex, index); | ||
} | ||
} | ||
return false; | ||
}); | ||
}, | ||
getImageSizes: function getImageSizes(src, galleryIndex, i, title, author) { | ||
var self = this; | ||
new Promise(function (resolve, reject) { | ||
var img = new Image(); | ||
img.src = src; | ||
img.onload = function () { | ||
self.items[galleryIndex][i] = { | ||
src: src, | ||
w: img.naturalWidth, | ||
h: img.naturalHeight, | ||
title: title, | ||
author: author | ||
}; | ||
resolve(); | ||
}; | ||
}); | ||
}, | ||
open: function open(galleryIndex, index) { | ||
var self = this; | ||
var pwsp; | ||
var gallery = self.galleries[galleryIndex]; | ||
self.options.galleryUID = galleryIndex; | ||
self.options.index = index; | ||
self.options.getThumbBoundsFn = function (index) { | ||
var gallery = document.querySelector('.pswp--active'); | ||
if (gallery) { | ||
var thumbnail = gallery.querySelectorAll('.pswp--item')[index].getElementsByTagName('img')[0], | ||
pageYScroll = window.pageYOffset || document.documentElement.scrollTop, | ||
rect = thumbnail.getBoundingClientRect(); | ||
return { x: rect.left, y: rect.top + pageYScroll, w: rect.width }; | ||
} | ||
}; | ||
self.options.addCaptionHTMLFn = function (item, captionEl, isFake) { | ||
if (!item.title) { | ||
captionEl.children[0].innerText = ''; | ||
return false; | ||
} | ||
captionEl.children[0].innerHTML = item.title; | ||
if (item.author) { | ||
captionEl.children[0].innerHTML += '<br><small>' + item.author + '</small>'; | ||
} | ||
return true; | ||
}; | ||
document.body.classList.remove('pswp--launched'); | ||
pwsp = new PhotoSwipe(self.pswpElement, PhotoSwipeUI_Default, self.items[galleryIndex], self.options); | ||
pwsp.init(); | ||
}, | ||
parseItems: function parseItems(resolve, galleryIndex) { | ||
var self = this; | ||
var promises = []; | ||
if (self.thumbnails[galleryIndex].length > 0) { | ||
for (var i = 0; i < self.thumbnails[galleryIndex].length; i++) { | ||
var src = self.thumbnails[galleryIndex][i].getAttribute('href'); | ||
var title = self.thumbnails[galleryIndex][i].getAttribute('data-caption'); | ||
var author = self.thumbnails[galleryIndex][i].getAttribute('data-author'); | ||
promises.push(self.getImageSizes(src, galleryIndex, i, title, author)); | ||
Promise.all(promises).then(function () { | ||
resolve(); | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
var pswpSimplify = new photoswipeSimplify(); | ||
return pswpSimplify; | ||
}); |
@@ -1,2 +0,2 @@ | ||
/*! photoswipe-simplify v0.0.1 | (c) 2018 Mineo Okuda | MIT License | git+ssh://git@github.com:min30327/photoswipe-simplify.git */ | ||
!(function(t,e){"use strict";"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.photoswipeSimplify=e()})(this,(function(){"use strict";var t={target:"[data-pswp]"},e=function(){var t={},e=0,i=arguments.length;for(e=0;e<i;e++){var s=arguments[e];!(function(e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(s)}return t},i=function(){};return i.prototype={initialized:!1,pswpElement:"",galleries:[],thumbnails:[],tmps:[],items:[],options:{},ImagesLoaded:!1,init:function(i){var s=this;s.options=e(t,i||{}),s.initialized||(s.append_template(),s.initialized=!0),s.initPhotoSwipe(s.options.target)},append_template:function(){var t=document.getElementsByTagName("body")[0],e=document.createElement("div");e.innerHTML='<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div> </div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>',t.appendChild(e)},initPhotoSwipe:function(t){var e=this;if(e.pswpElement=document.querySelectorAll(".pswp")[0],e.galleries=document.querySelectorAll(t),e.galleries.length>0)for(var i=0;i<e.galleries.length;i++){if(e.items[i]=[],e.thumbnails[i]=[],e.tmps[i]=e.galleries[i].getElementsByTagName("a"),e.tmps[i]=Array.prototype.slice.call(e.tmps[i]),e.tmps[i].length>0)for(var s=0;s<e.tmps[i].length;s++){var n=e.tmps[i][s].getAttribute("href");/(.gif|.jpe?g|.png|.bmp)/.test(n.toLowerCase())&&e.thumbnails[i].push(e.tmps[i][s])}var a=new Promise(function(t){e.parseItems(t,i)});if(a.then((function(){e.galleryLoaded()})),e.thumbnails[i].length>0)for(var o=0;o<e.thumbnails[i].length;o++)e.thumbnails[i][o].setAttribute("data-pswp-index",i),e.thumbnails[i][o].classList.add("pswp--item"),e.attachEvent(e.thumbnails[i][o],i,o)}},galleryLoaded:function(){var t=this;if(t.galleries.length>0)for(var e=0;e<t.galleries.length;e++)t.galleries[e].classList.add("pswp--loaded")},attachEvent:function(t,e,i){var s=this;t.addEventListener("click",(function(t){t.preventDefault(),document.body.classList.add("pswp--launched");var n=document.querySelector(".pswp--active");return n&&n.classList.remove("pswp--active"),s.galleries[e].classList.add("pswp--active"),s.galleries[e].setAttribute("data-pswp-index",i),s.galleries[e].classList.contains("pswp--loaded")&&i>=0&&s.open(e,i),!1}))},getImageSizes:function(t,e,i,s,n){var a=this;new Promise(function(o,l){var p=new Image;p.src=t,p.onload=function(){a.items[e][i]={src:t,w:p.naturalWidth,h:p.naturalHeight,title:s,author:n},o()}})},open:function(t,e){var i,s=this;s.galleries[t];s.options.galleryUID=t,s.options.index=e,s.options.getThumbBoundsFn=function(t){var e=document.querySelector(".pswp--active");if(e){var i=e.querySelectorAll(".pswp--item")[t].getElementsByTagName("img")[0],s=window.pageYOffset||document.documentElement.scrollTop,n=i.getBoundingClientRect();return{x:n.left,y:n.top+s,w:n.width}}},s.options.addCaptionHTMLFn=function(t,e,i){return t.title?(e.children[0].innerHTML=t.title,t.author&&(e.children[0].innerHTML+="<br><small>"+t.author+"</small>"),!0):(e.children[0].innerText="",!1)},document.body.classList.remove("pswp--launched"),i=new PhotoSwipe(s.pswpElement,PhotoSwipeUI_Default,s.items[t],s.options),i.init()},parseItems:function(t,e){var i=this,s=[];if(i.thumbnails[e].length>0)for(var n=0;n<i.thumbnails[e].length;n++){var a=i.thumbnails[e][n].getAttribute("href"),o=i.thumbnails[e][n].getAttribute("data-caption"),l=i.thumbnails[e][n].getAttribute("data-author");s.push(i.getImageSizes(a,e,n,o,l)),Promise.all(s).then((function(){t()}))}}},new i})); | ||
/*! photoswipe-simplify v0.0.2 | (c) 2019 Mineo Okuda | MIT License | git+ssh://git@github.com:min30327/photoswipe-simplify.git */ | ||
var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!(function(t,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()})(0,(function(){"use strict";function t(t){var e=this.constructor;return this.then((function(n){return e.resolve(t()).then((function(){return n}))}),(function(n){return e.resolve(t()).then((function(){return e.reject(n)}))}))}function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function i(t){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],u(t,this)}function o(t,e){for(;3===t._state;)t=t._value;if(0===t._state)return void t._deferreds.push(e);t._handled=!0,i._immediateFn((function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?r:s)(e.promise,t._value);var i;try{i=n(t._value)}catch(t){return void s(e.promise,t)}r(e.promise,i)}))}function r(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"===(void 0===e?"undefined":_typeof(e))||"function"==typeof e)){var o=e.then;if(e instanceof i)return t._state=3,t._value=e,void a(t);if("function"==typeof o)return void u(n(o,e),t)}t._state=1,t._value=e,a(t)}catch(e){s(t,e)}}function s(t,e){t._state=2,t._value=e,a(t)}function a(t){2===t._state&&0===t._deferreds.length&&i._immediateFn((function(){t._handled||i._unhandledRejectionFn(t._value)}));for(var e=0,n=t._deferreds.length;e<n;e++)o(t,t._deferreds[e]);t._deferreds=null}function l(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function u(t,e){var n=!1;try{t((function(t){n||(n=!0,r(e,t))}),(function(t){n||(n=!0,s(e,t))}))}catch(t){if(n)return;n=!0,s(e,t)}}var p=setTimeout;i.prototype.catch=function(t){return this.then(null,t)},i.prototype.then=function(t,n){var i=new this.constructor(e);return o(this,new l(t,n,i)),i},i.prototype.finally=t,i.all=function(t){return new i(function(e,n){function i(t,s){try{if(s&&("object"===(void 0===s?"undefined":_typeof(s))||"function"==typeof s)){var a=s.then;if("function"==typeof a)return void a.call(s,(function(e){i(t,e)}),n)}o[t]=s,0==--r&&e(o)}catch(t){n(t)}}if(!t||void 0===t.length)throw new TypeError("Promise.all accepts an array");var o=Array.prototype.slice.call(t);if(0===o.length)return e([]);for(var r=o.length,s=0;s<o.length;s++)i(s,o[s])})},i.resolve=function(t){return t&&"object"===(void 0===t?"undefined":_typeof(t))&&t.constructor===i?t:new i(function(e){e(t)})},i.reject=function(t){return new i(function(e,n){n(t)})},i.race=function(t){return new i(function(e,n){for(var i=0,o=t.length;i<o;i++)t[i].then(e,n)})},i._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){p(t,0)},i._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var c=(function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")})();"Promise"in c?c.Promise.prototype.finally||(c.Promise.prototype.finally=t):c.Promise=i})),(function(t,e){"use strict";"function"==typeof define&&define.amd?define([],e):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=e():t.photoswipeSimplify=e()})(this,(function(){"use strict";var t={target:"[data-pswp]"},e=function(){var t={},e=0,n=arguments.length;for(e=0;e<n;e++){var i=arguments[e];!(function(e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(i)}return t},n=function(){};return n.prototype={initialized:!1,pswpElement:"",galleries:[],thumbnails:[],tmps:[],items:[],options:{},ImagesLoaded:!1,init:function(n){var i=this;i.options=e(t,n||{}),i.initialized||(i.append_template(),i.initialized=!0),i.initPhotoSwipe(i.options.target)},append_template:function(){var t=document.getElementsByTagName("body")[0],e=document.createElement("div");e.innerHTML='<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--share" title="Share"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"><div class="pswp__share-tooltip"></div> </div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>',t.appendChild(e)},initPhotoSwipe:function(t){var e=this;if(e.pswpElement=document.querySelectorAll(".pswp")[0],e.galleries=document.querySelectorAll(t),e.galleries.length>0)for(var n=0;n<e.galleries.length;n++){if(e.items[n]=[],e.thumbnails[n]=[],e.tmps[n]=e.galleries[n].getElementsByTagName("a"),e.tmps[n]=Array.prototype.slice.call(e.tmps[n]),e.tmps[n].length>0)for(var i=0;i<e.tmps[n].length;i++){var o=e.tmps[n][i].getAttribute("href");/(.gif|.jpe?g|.png|.bmp)/.test(o.toLowerCase())&&e.thumbnails[n].push(e.tmps[n][i])}var r=new Promise(function(t){e.parseItems(t,n)});if(r.then((function(){e.galleryLoaded()})),e.thumbnails[n].length>0)for(var s=0;s<e.thumbnails[n].length;s++)e.thumbnails[n][s].setAttribute("data-pswp-index",n),e.thumbnails[n][s].classList.add("pswp--item"),e.attachEvent(e.thumbnails[n][s],n,s)}},galleryLoaded:function(){var t=this;if(t.galleries.length>0)for(var e=0;e<t.galleries.length;e++)t.galleries[e].classList.add("pswp--loaded")},attachEvent:function(t,e,n){var i=this;t.addEventListener("click",(function(t){t.preventDefault(),document.body.classList.add("pswp--launched");var o=document.querySelector(".pswp--active");return o&&o.classList.remove("pswp--active"),i.galleries[e].classList.add("pswp--active"),i.galleries[e].setAttribute("data-pswp-index",n),i.galleries[e].classList.contains("pswp--loaded")&&n>=0&&i.open(e,n),!1}))},getImageSizes:function(t,e,n,i,o){var r=this;new Promise(function(s,a){var l=new Image;l.src=t,l.onload=function(){r.items[e][n]={src:t,w:l.naturalWidth,h:l.naturalHeight,title:i,author:o},s()}})},open:function(t,e){var n,i=this;i.galleries[t];i.options.galleryUID=t,i.options.index=e,i.options.getThumbBoundsFn=function(t){var e=document.querySelector(".pswp--active");if(e){var n=e.querySelectorAll(".pswp--item")[t].getElementsByTagName("img")[0],i=window.pageYOffset||document.documentElement.scrollTop,o=n.getBoundingClientRect();return{x:o.left,y:o.top+i,w:o.width}}},i.options.addCaptionHTMLFn=function(t,e,n){return t.title?(e.children[0].innerHTML=t.title,t.author&&(e.children[0].innerHTML+="<br><small>"+t.author+"</small>"),!0):(e.children[0].innerText="",!1)},document.body.classList.remove("pswp--launched"),n=new PhotoSwipe(i.pswpElement,PhotoSwipeUI_Default,i.items[t],i.options),n.init()},parseItems:function(t,e){var n=this,i=[];if(n.thumbnails[e].length>0)for(var o=0;o<n.thumbnails[e].length;o++){var r=n.thumbnails[e][o].getAttribute("href"),s=n.thumbnails[e][o].getAttribute("data-caption"),a=n.thumbnails[e][o].getAttribute("data-author");i.push(n.getImageSizes(r,e,o,s,a)),Promise.all(i).then((function(){t()}))}}},new n})); |
@@ -7,3 +7,3 @@ /** | ||
scripts: true, // Turn on/off script tasks | ||
polyfills: true, // Turn on/off polyfill tasks | ||
polyfills: false, // Turn on/off polyfill tasks | ||
styles: false, // Turn on/off style tasks | ||
@@ -45,2 +45,3 @@ svgs: false, // Turn on/off SVG tasks | ||
var optimizejs = settings.scripts ? require('gulp-optimize-js') : null; | ||
var babel = require('gulp-babel'); | ||
@@ -99,2 +100,17 @@ | ||
.pipe(optimizejs) | ||
.pipe(function(){ | ||
return babel({ | ||
presets: [ | ||
[ | ||
'env', { | ||
'plugins': ['@babel/transform-runtime'], | ||
'targets': { | ||
'browsers': ['ie >= 11'] | ||
}, | ||
'modules' : false | ||
} | ||
] | ||
] | ||
}) | ||
}) | ||
.pipe(gulp.dest, paths.scripts.output) | ||
@@ -101,0 +117,0 @@ .pipe(rename, { suffix: '.min' + fileVersion }) |
{ | ||
"_args": [ | ||
[ | ||
"photoswipe-simplify@0.0.2", | ||
"photoswipe-simplify@0.0.3", | ||
"/Users/mineo/workspace/DEMO/photoswipe-simplify/" | ||
] | ||
], | ||
"_from": "photoswipe-simplify@0.0.2", | ||
"_id": "photoswipe-simplify@0.0.2", | ||
"_from": "photoswipe-simplify@0.0.3", | ||
"_id": "photoswipe-simplify@0.0.3", | ||
"_inBundle": false, | ||
@@ -16,8 +16,8 @@ "_location": "/photoswipe-simplify", | ||
"registry": true, | ||
"raw": "photoswipe-simplify@0.0.2", | ||
"raw": "photoswipe-simplify@0.0.3", | ||
"name": "photoswipe-simplify", | ||
"escapedName": "photoswipe-simplify", | ||
"rawSpec": "0.0.2", | ||
"rawSpec": "0.0.3", | ||
"saveSpec": null, | ||
"fetchSpec": "0.0.2" | ||
"fetchSpec": "0.0.3" | ||
}, | ||
@@ -27,3 +27,3 @@ "_requiredBy": [ | ||
], | ||
"_spec": "0.0.2", | ||
"_spec": "0.0.3", | ||
"_where": "/Users/mineo/workspace/DEMO/photoswipe-simplify/", | ||
@@ -36,4 +36,8 @@ "author": { | ||
"devDependencies": { | ||
"@babel/plugin-transform-runtime": "^7.2.0", | ||
"babel-core": "^6.26.3", | ||
"babel-preset-env": "^1.7.0", | ||
"del": "^2.2.2", | ||
"gulp": "^3.9.1", | ||
"gulp-babel": "^7.0.1", | ||
"gulp-concat": "^2.6.1", | ||
@@ -56,3 +60,4 @@ "gulp-file-include": "^0.14.0", | ||
"lazypipe": "^1.0.1", | ||
"node-fs": "^0.1.7" | ||
"node-fs": "^0.1.7", | ||
"promise-polyfill": "8.1.0" | ||
}, | ||
@@ -66,6 +71,8 @@ "license": "MIT", | ||
}, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"dependencies": { | ||
"@babel/polyfill": "^7.2.5", | ||
"@babel/runtime": "^7.3.1", | ||
"photoswipe": "^4.1.2" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/** | ||
@@ -11,2 +12,290 @@ * Written by Mineo Okuda on 25/10/18. | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
/** | ||
* @this {Promise} | ||
*/ | ||
function finallyConstructor(callback) { | ||
var constructor = this.constructor; | ||
return this.then( | ||
function(value) { | ||
return constructor.resolve(callback()).then(function() { | ||
return value; | ||
}); | ||
}, | ||
function(reason) { | ||
return constructor.resolve(callback()).then(function() { | ||
return constructor.reject(reason); | ||
}); | ||
} | ||
); | ||
} | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
// other code modifying setTimeout (like sinon.useFakeTimers()) | ||
var setTimeoutFunc = setTimeout; | ||
function noop() {} | ||
// Polyfill for Function.prototype.bind | ||
function bind(fn, thisArg) { | ||
return function() { | ||
fn.apply(thisArg, arguments); | ||
}; | ||
} | ||
/** | ||
* @constructor | ||
* @param {Function} fn | ||
*/ | ||
function Promise(fn) { | ||
if (!(this instanceof Promise)) | ||
throw new TypeError('Promises must be constructed via new'); | ||
if (typeof fn !== 'function') throw new TypeError('not a function'); | ||
/** @type {!number} */ | ||
this._state = 0; | ||
/** @type {!boolean} */ | ||
this._handled = false; | ||
/** @type {Promise|undefined} */ | ||
this._value = undefined; | ||
/** @type {!Array<!Function>} */ | ||
this._deferreds = []; | ||
doResolve(fn, this); | ||
} | ||
function handle(self, deferred) { | ||
while (self._state === 3) { | ||
self = self._value; | ||
} | ||
if (self._state === 0) { | ||
self._deferreds.push(deferred); | ||
return; | ||
} | ||
self._handled = true; | ||
Promise._immediateFn(function() { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
if (cb === null) { | ||
(self._state === 1 ? resolve : reject)(deferred.promise, self._value); | ||
return; | ||
} | ||
var ret; | ||
try { | ||
ret = cb(self._value); | ||
} catch (e) { | ||
reject(deferred.promise, e); | ||
return; | ||
} | ||
resolve(deferred.promise, ret); | ||
}); | ||
} | ||
function resolve(self, newValue) { | ||
try { | ||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure | ||
if (newValue === self) | ||
throw new TypeError('A promise cannot be resolved with itself.'); | ||
if ( | ||
newValue && | ||
(typeof newValue === 'object' || typeof newValue === 'function') | ||
) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
self._state = 3; | ||
self._value = newValue; | ||
finale(self); | ||
return; | ||
} else if (typeof then === 'function') { | ||
doResolve(bind(then, newValue), self); | ||
return; | ||
} | ||
} | ||
self._state = 1; | ||
self._value = newValue; | ||
finale(self); | ||
} catch (e) { | ||
reject(self, e); | ||
} | ||
} | ||
function reject(self, newValue) { | ||
self._state = 2; | ||
self._value = newValue; | ||
finale(self); | ||
} | ||
function finale(self) { | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function() { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
} | ||
}); | ||
} | ||
for (var i = 0, len = self._deferreds.length; i < len; i++) { | ||
handle(self, self._deferreds[i]); | ||
} | ||
self._deferreds = null; | ||
} | ||
/** | ||
* @constructor | ||
*/ | ||
function Handler(onFulfilled, onRejected, promise) { | ||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; | ||
this.onRejected = typeof onRejected === 'function' ? onRejected : null; | ||
this.promise = promise; | ||
} | ||
/** | ||
* Take a potentially misbehaving resolver function and make sure | ||
* onFulfilled and onRejected are only called once. | ||
* | ||
* Makes no guarantees about asynchrony. | ||
*/ | ||
function doResolve(fn, self) { | ||
var done = false; | ||
try { | ||
fn( | ||
function(value) { | ||
if (done) return; | ||
done = true; | ||
resolve(self, value); | ||
}, | ||
function(reason) { | ||
if (done) return; | ||
done = true; | ||
reject(self, reason); | ||
} | ||
); | ||
} catch (ex) { | ||
if (done) return; | ||
done = true; | ||
reject(self, ex); | ||
} | ||
} | ||
Promise.prototype['catch'] = function(onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
Promise.prototype.then = function(onFulfilled, onRejected) { | ||
// @ts-ignore | ||
var prom = new this.constructor(noop); | ||
handle(this, new Handler(onFulfilled, onRejected, prom)); | ||
return prom; | ||
}; | ||
Promise.prototype['finally'] = finallyConstructor; | ||
Promise.all = function(arr) { | ||
return new Promise(function(resolve, reject) { | ||
if (!arr || typeof arr.length === 'undefined') | ||
throw new TypeError('Promise.all accepts an array'); | ||
var args = Array.prototype.slice.call(arr); | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
function res(i, val) { | ||
try { | ||
if (val && (typeof val === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call( | ||
val, | ||
function(val) { | ||
res(i, val); | ||
}, | ||
reject | ||
); | ||
return; | ||
} | ||
} | ||
args[i] = val; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
}; | ||
Promise.resolve = function(value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise) { | ||
return value; | ||
} | ||
return new Promise(function(resolve) { | ||
resolve(value); | ||
}); | ||
}; | ||
Promise.reject = function(value) { | ||
return new Promise(function(resolve, reject) { | ||
reject(value); | ||
}); | ||
}; | ||
Promise.race = function(values) { | ||
return new Promise(function(resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
values[i].then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = | ||
(typeof setImmediate === 'function' && | ||
function(fn) { | ||
setImmediate(fn); | ||
}) || | ||
function(fn) { | ||
setTimeoutFunc(fn, 0); | ||
}; | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
} | ||
}; | ||
/** @suppress {undefinedVars} */ | ||
var globalNS = (function() { | ||
// the only reliable means to get the global object is | ||
// `Function('return this')()` | ||
// However, this causes CSP violations in Chrome apps. | ||
if (typeof self !== 'undefined') { | ||
return self; | ||
} | ||
if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
if (typeof global !== 'undefined') { | ||
return global; | ||
} | ||
throw new Error('unable to locate global object'); | ||
})(); | ||
if (!('Promise' in globalNS)) { | ||
globalNS['Promise'] = Promise; | ||
} else if (!globalNS.Promise.prototype['finally']) { | ||
globalNS.Promise.prototype['finally'] = finallyConstructor; | ||
} | ||
}))); | ||
(function(root, factory) { | ||
@@ -13,0 +302,0 @@ 'use strict'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4234770
1322
3
25
25
+ Added@babel/polyfill@^7.2.5
+ Added@babel/runtime@^7.3.1
+ Added@babel/polyfill@7.12.1(transitive)
+ Added@babel/runtime@7.26.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.13.110.14.1(transitive)