- var LivePhoto = require('./live-photo');
- var styles = require('./styles.scss');
- var supportsLivePhotos = true;
- var stylesInUse = 0;
- var useStyles = true;
- function initializeLivePhotos(elements, options) {
- if (!supportsLivePhotos) {
- return;
- }
- if (useStyles) {
- addStyles();
- }
- if (typeof elements === 'object' && elements.toString() === '[object Object]') {
- options = elements;
- elements = options.elements;
- delete options.elements;
- }
- elements || (elements = 'img[data-live-photo]');
- if (typeof elements === 'string') {
- elements = document.querySelectorAll(elements);
- }
- if (elements instanceof HTMLElement) {
- elements = [elements];
- }
- var livePhotos = [];
- Array.prototype.forEach.call(elements, function(el) {
- if (typeof el === 'string') {
- el = document.querySelector(el);
- }
- if (el) {
- var livePhoto = new LivePhoto(el, options);
- livePhotos.push(livePhoto);
- }
- });
- return livePhotos;
- }
- function addStyles() {
- styles.use();
- stylesInUse++;
- }
- function noStyles() {
- useStyles = false;
- }
- function cleanup() {
- while (stylesInUse > 0) {
- styles.unuse();
- stylesInUse--;
- }
- }
- function LivePhotos(elements, options) {
- return initializeLivePhotos(elements, options);
- }
- LivePhotos.initialize = initializeLivePhotos;
- LivePhotos.addStyles = addStyles;
- LivePhotos.noStyles = noStyles;
- LivePhotos.cleanup = cleanup;
- LivePhotos.LivePhoto = LivePhoto;
- module.exports = LivePhotos;