| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452 |
- /**
- * Dom7 2.1.5
- * Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API
- * http://framework7.io/docs/dom.html
- *
- * Copyright 2020, Vladimir Kharlampidi
- * The iDangero.us
- * http://www.idangero.us/
- *
- * Licensed under MIT
- *
- * Released on: May 15, 2020
- */
- import { document, window } from 'ssr-window';
- class Dom7 {
- constructor(arr) {
- const self = this;
- // Create array-like object
- for (let i = 0; i < arr.length; i += 1) {
- self[i] = arr[i];
- }
- self.length = arr.length;
- // Return collection with methods
- return this;
- }
- }
- function $(selector, context) {
- const arr = [];
- let i = 0;
- if (selector && !context) {
- if (selector instanceof Dom7) {
- return selector;
- }
- }
- if (selector) {
- // String
- if (typeof selector === 'string') {
- let els;
- let tempParent;
- const html = selector.trim();
- if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
- let toCreate = 'div';
- if (html.indexOf('<li') === 0) toCreate = 'ul';
- if (html.indexOf('<tr') === 0) toCreate = 'tbody';
- if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
- if (html.indexOf('<tbody') === 0) toCreate = 'table';
- if (html.indexOf('<option') === 0) toCreate = 'select';
- tempParent = document.createElement(toCreate);
- tempParent.innerHTML = html;
- for (i = 0; i < tempParent.childNodes.length; i += 1) {
- arr.push(tempParent.childNodes[i]);
- }
- } else {
- if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
- // Pure ID selector
- els = [document.getElementById(selector.trim().split('#')[1])];
- } else {
- // Other selectors
- els = (context || document).querySelectorAll(selector.trim());
- }
- for (i = 0; i < els.length; i += 1) {
- if (els[i]) arr.push(els[i]);
- }
- }
- } else if (selector.nodeType || selector === window || selector === document) {
- // Node/element
- arr.push(selector);
- } else if (selector.length > 0 && selector[0].nodeType) {
- // Array of elements or instance of Dom
- for (i = 0; i < selector.length; i += 1) {
- arr.push(selector[i]);
- }
- }
- }
- return new Dom7(arr);
- }
- $.fn = Dom7.prototype;
- $.Class = Dom7;
- $.Dom7 = Dom7;
- function unique(arr) {
- const uniqueArray = [];
- for (let i = 0; i < arr.length; i += 1) {
- if (uniqueArray.indexOf(arr[i]) === -1) uniqueArray.push(arr[i]);
- }
- return uniqueArray;
- }
- function toCamelCase(string) {
- return string.toLowerCase().replace(/-(.)/g, (match, group1) => group1.toUpperCase());
- }
- function requestAnimationFrame(callback) {
- if (window.requestAnimationFrame) return window.requestAnimationFrame(callback);
- else if (window.webkitRequestAnimationFrame) return window.webkitRequestAnimationFrame(callback);
- return window.setTimeout(callback, 1000 / 60);
- }
- function cancelAnimationFrame(id) {
- if (window.cancelAnimationFrame) return window.cancelAnimationFrame(id);
- else if (window.webkitCancelAnimationFrame) return window.webkitCancelAnimationFrame(id);
- return window.clearTimeout(id);
- }
- // Classes and attributes
- function addClass(className) {
- if (typeof className === 'undefined') {
- return this;
- }
- const classes = className.split(' ');
- for (let i = 0; i < classes.length; i += 1) {
- for (let j = 0; j < this.length; j += 1) {
- if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') this[j].classList.add(classes[i]);
- }
- }
- return this;
- }
- function removeClass(className) {
- const classes = className.split(' ');
- for (let i = 0; i < classes.length; i += 1) {
- for (let j = 0; j < this.length; j += 1) {
- if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') this[j].classList.remove(classes[i]);
- }
- }
- return this;
- }
- function hasClass(className) {
- if (!this[0]) return false;
- return this[0].classList.contains(className);
- }
- function toggleClass(className) {
- const classes = className.split(' ');
- for (let i = 0; i < classes.length; i += 1) {
- for (let j = 0; j < this.length; j += 1) {
- if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') this[j].classList.toggle(classes[i]);
- }
- }
- return this;
- }
- function attr(attrs, value) {
- if (arguments.length === 1 && typeof attrs === 'string') {
- // Get attr
- if (this[0]) return this[0].getAttribute(attrs);
- return undefined;
- }
- // Set attrs
- for (let i = 0; i < this.length; i += 1) {
- if (arguments.length === 2) {
- // String
- this[i].setAttribute(attrs, value);
- } else {
- // Object
- // eslint-disable-next-line
- for (const attrName in attrs) {
- this[i][attrName] = attrs[attrName];
- this[i].setAttribute(attrName, attrs[attrName]);
- }
- }
- }
- return this;
- }
- // eslint-disable-next-line
- function removeAttr(attr) {
- for (let i = 0; i < this.length; i += 1) {
- this[i].removeAttribute(attr);
- }
- return this;
- }
- // eslint-disable-next-line
- function prop(props, value) {
- if (arguments.length === 1 && typeof props === 'string') {
- // Get prop
- if (this[0]) return this[0][props];
- } else {
- // Set props
- for (let i = 0; i < this.length; i += 1) {
- if (arguments.length === 2) {
- // String
- this[i][props] = value;
- } else {
- // Object
- // eslint-disable-next-line
- for (const propName in props) {
- this[i][propName] = props[propName];
- }
- }
- }
- return this;
- }
- }
- function data(key, value) {
- let el;
- if (typeof value === 'undefined') {
- el = this[0];
- // Get value
- if (el) {
- if (el.dom7ElementDataStorage && (key in el.dom7ElementDataStorage)) {
- return el.dom7ElementDataStorage[key];
- }
- const dataKey = el.getAttribute(`data-${key}`);
- if (dataKey) {
- return dataKey;
- }
- return undefined;
- }
- return undefined;
- }
- // Set value
- for (let i = 0; i < this.length; i += 1) {
- el = this[i];
- if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {};
- el.dom7ElementDataStorage[key] = value;
- }
- return this;
- }
- function removeData(key) {
- for (let i = 0; i < this.length; i += 1) {
- const el = this[i];
- if (el.dom7ElementDataStorage && el.dom7ElementDataStorage[key]) {
- el.dom7ElementDataStorage[key] = null;
- delete el.dom7ElementDataStorage[key];
- }
- }
- }
- function dataset() {
- const el = this[0];
- if (!el) return undefined;
- const dataset = {}; // eslint-disable-line
- if (el.dataset) {
- // eslint-disable-next-line
- for (const dataKey in el.dataset) {
- dataset[dataKey] = el.dataset[dataKey];
- }
- } else {
- for (let i = 0; i < el.attributes.length; i += 1) {
- // eslint-disable-next-line
- const attr = el.attributes[i];
- if (attr.name.indexOf('data-') >= 0) {
- dataset[toCamelCase(attr.name.split('data-')[1])] = attr.value;
- }
- }
- }
- // eslint-disable-next-line
- for (const key in dataset) {
- if (dataset[key] === 'false') dataset[key] = false;
- else if (dataset[key] === 'true') dataset[key] = true;
- else if (parseFloat(dataset[key]) === dataset[key] * 1) dataset[key] *= 1;
- }
- return dataset;
- }
- function val(value) {
- const dom = this;
- if (typeof value === 'undefined') {
- if (dom[0]) {
- if (dom[0].multiple && dom[0].nodeName.toLowerCase() === 'select') {
- const values = [];
- for (let i = 0; i < dom[0].selectedOptions.length; i += 1) {
- values.push(dom[0].selectedOptions[i].value);
- }
- return values;
- }
- return dom[0].value;
- }
- return undefined;
- }
- for (let i = 0; i < dom.length; i += 1) {
- const el = dom[i];
- if (Array.isArray(value) && el.multiple && el.nodeName.toLowerCase() === 'select') {
- for (let j = 0; j < el.options.length; j += 1) {
- el.options[j].selected = value.indexOf(el.options[j].value) >= 0;
- }
- } else {
- el.value = value;
- }
- }
- return dom;
- }
- // Transforms
- // eslint-disable-next-line
- function transform(transform) {
- for (let i = 0; i < this.length; i += 1) {
- const elStyle = this[i].style;
- elStyle.webkitTransform = transform;
- elStyle.transform = transform;
- }
- return this;
- }
- function transition(duration) {
- if (typeof duration !== 'string') {
- duration = `${duration}ms`; // eslint-disable-line
- }
- for (let i = 0; i < this.length; i += 1) {
- const elStyle = this[i].style;
- elStyle.webkitTransitionDuration = duration;
- elStyle.transitionDuration = duration;
- }
- return this;
- }
- // Events
- function on(...args) {
- let [eventType, targetSelector, listener, capture] = args;
- if (typeof args[1] === 'function') {
- [eventType, listener, capture] = args;
- targetSelector = undefined;
- }
- if (!capture) capture = false;
- function handleLiveEvent(e) {
- const target = e.target;
- if (!target) return;
- const eventData = e.target.dom7EventData || [];
- if (eventData.indexOf(e) < 0) {
- eventData.unshift(e);
- }
- if ($(target).is(targetSelector)) listener.apply(target, eventData);
- else {
- const parents = $(target).parents(); // eslint-disable-line
- for (let k = 0; k < parents.length; k += 1) {
- if ($(parents[k]).is(targetSelector)) listener.apply(parents[k], eventData);
- }
- }
- }
- function handleEvent(e) {
- const eventData = e && e.target ? e.target.dom7EventData || [] : [];
- if (eventData.indexOf(e) < 0) {
- eventData.unshift(e);
- }
- listener.apply(this, eventData);
- }
- const events = eventType.split(' ');
- let j;
- for (let i = 0; i < this.length; i += 1) {
- const el = this[i];
- if (!targetSelector) {
- for (j = 0; j < events.length; j += 1) {
- const event = events[j];
- if (!el.dom7Listeners) el.dom7Listeners = {};
- if (!el.dom7Listeners[event]) el.dom7Listeners[event] = [];
- el.dom7Listeners[event].push({
- listener,
- proxyListener: handleEvent,
- });
- el.addEventListener(event, handleEvent, capture);
- }
- } else {
- // Live events
- for (j = 0; j < events.length; j += 1) {
- const event = events[j];
- if (!el.dom7LiveListeners) el.dom7LiveListeners = {};
- if (!el.dom7LiveListeners[event]) el.dom7LiveListeners[event] = [];
- el.dom7LiveListeners[event].push({
- listener,
- proxyListener: handleLiveEvent,
- });
- el.addEventListener(event, handleLiveEvent, capture);
- }
- }
- }
- return this;
- }
- function off(...args) {
- let [eventType, targetSelector, listener, capture] = args;
- if (typeof args[1] === 'function') {
- [eventType, listener, capture] = args;
- targetSelector = undefined;
- }
- if (!capture) capture = false;
- const events = eventType.split(' ');
- for (let i = 0; i < events.length; i += 1) {
- const event = events[i];
- for (let j = 0; j < this.length; j += 1) {
- const el = this[j];
- let handlers;
- if (!targetSelector && el.dom7Listeners) {
- handlers = el.dom7Listeners[event];
- } else if (targetSelector && el.dom7LiveListeners) {
- handlers = el.dom7LiveListeners[event];
- }
- if (handlers && handlers.length) {
- for (let k = handlers.length - 1; k >= 0; k -= 1) {
- const handler = handlers[k];
- if (listener && handler.listener === listener) {
- el.removeEventListener(event, handler.proxyListener, capture);
- handlers.splice(k, 1);
- } else if (listener && handler.listener && handler.listener.dom7proxy && handler.listener.dom7proxy === listener) {
- el.removeEventListener(event, handler.proxyListener, capture);
- handlers.splice(k, 1);
- } else if (!listener) {
- el.removeEventListener(event, handler.proxyListener, capture);
- handlers.splice(k, 1);
- }
- }
- }
- }
- }
- return this;
- }
- function once(...args) {
- const dom = this;
- let [eventName, targetSelector, listener, capture] = args;
- if (typeof args[1] === 'function') {
- [eventName, listener, capture] = args;
- targetSelector = undefined;
- }
- function onceHandler(...eventArgs) {
- listener.apply(this, eventArgs);
- dom.off(eventName, targetSelector, onceHandler, capture);
- if (onceHandler.dom7proxy) {
- delete onceHandler.dom7proxy;
- }
- }
- onceHandler.dom7proxy = listener;
- return dom.on(eventName, targetSelector, onceHandler, capture);
- }
- function trigger(...args) {
- const events = args[0].split(' ');
- const eventData = args[1];
- for (let i = 0; i < events.length; i += 1) {
- const event = events[i];
- for (let j = 0; j < this.length; j += 1) {
- const el = this[j];
- let evt;
- try {
- evt = new window.CustomEvent(event, {
- detail: eventData,
- bubbles: true,
- cancelable: true,
- });
- } catch (e) {
- evt = document.createEvent('Event');
- evt.initEvent(event, true, true);
- evt.detail = eventData;
- }
- // eslint-disable-next-line
- el.dom7EventData = args.filter((data, dataIndex) => dataIndex > 0);
- el.dispatchEvent(evt);
- el.dom7EventData = [];
- delete el.dom7EventData;
- }
- }
- return this;
- }
- function transitionEnd(callback) {
- const events = ['webkitTransitionEnd', 'transitionend'];
- const dom = this;
- let i;
- function fireCallBack(e) {
- /* jshint validthis:true */
- if (e.target !== this) return;
- callback.call(this, e);
- for (i = 0; i < events.length; i += 1) {
- dom.off(events[i], fireCallBack);
- }
- }
- if (callback) {
- for (i = 0; i < events.length; i += 1) {
- dom.on(events[i], fireCallBack);
- }
- }
- return this;
- }
- function animationEnd(callback) {
- const events = ['webkitAnimationEnd', 'animationend'];
- const dom = this;
- let i;
- function fireCallBack(e) {
- if (e.target !== this) return;
- callback.call(this, e);
- for (i = 0; i < events.length; i += 1) {
- dom.off(events[i], fireCallBack);
- }
- }
- if (callback) {
- for (i = 0; i < events.length; i += 1) {
- dom.on(events[i], fireCallBack);
- }
- }
- return this;
- }
- // Sizing/Styles
- function width() {
- if (this[0] === window) {
- return window.innerWidth;
- }
- if (this.length > 0) {
- return parseFloat(this.css('width'));
- }
- return null;
- }
- function outerWidth(includeMargins) {
- if (this.length > 0) {
- if (includeMargins) {
- // eslint-disable-next-line
- const styles = this.styles();
- return this[0].offsetWidth + parseFloat(styles.getPropertyValue('margin-right')) + parseFloat(styles.getPropertyValue('margin-left'));
- }
- return this[0].offsetWidth;
- }
- return null;
- }
- function height() {
- if (this[0] === window) {
- return window.innerHeight;
- }
- if (this.length > 0) {
- return parseFloat(this.css('height'));
- }
- return null;
- }
- function outerHeight(includeMargins) {
- if (this.length > 0) {
- if (includeMargins) {
- // eslint-disable-next-line
- const styles = this.styles();
- return this[0].offsetHeight + parseFloat(styles.getPropertyValue('margin-top')) + parseFloat(styles.getPropertyValue('margin-bottom'));
- }
- return this[0].offsetHeight;
- }
- return null;
- }
- function offset() {
- if (this.length > 0) {
- const el = this[0];
- const box = el.getBoundingClientRect();
- const body = document.body;
- const clientTop = el.clientTop || body.clientTop || 0;
- const clientLeft = el.clientLeft || body.clientLeft || 0;
- const scrollTop = el === window ? window.scrollY : el.scrollTop;
- const scrollLeft = el === window ? window.scrollX : el.scrollLeft;
- return {
- top: (box.top + scrollTop) - clientTop,
- left: (box.left + scrollLeft) - clientLeft,
- };
- }
- return null;
- }
- function hide() {
- for (let i = 0; i < this.length; i += 1) {
- this[i].style.display = 'none';
- }
- return this;
- }
- function show() {
- for (let i = 0; i < this.length; i += 1) {
- const el = this[i];
- if (el.style.display === 'none') {
- el.style.display = '';
- }
- if (window.getComputedStyle(el, null).getPropertyValue('display') === 'none') {
- // Still not visible
- el.style.display = 'block';
- }
- }
- return this;
- }
- function styles() {
- if (this[0]) return window.getComputedStyle(this[0], null);
- return {};
- }
- function css(props, value) {
- let i;
- if (arguments.length === 1) {
- if (typeof props === 'string') {
- if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
- } else {
- for (i = 0; i < this.length; i += 1) {
- // eslint-disable-next-line
- for (let prop in props) {
- this[i].style[prop] = props[prop];
- }
- }
- return this;
- }
- }
- if (arguments.length === 2 && typeof props === 'string') {
- for (i = 0; i < this.length; i += 1) {
- this[i].style[props] = value;
- }
- return this;
- }
- return this;
- }
- // Dom manipulation
- function toArray() {
- const arr = [];
- for (let i = 0; i < this.length; i += 1) {
- arr.push(this[i]);
- }
- return arr;
- }
- // Iterate over the collection passing elements to `callback`
- function each(callback) {
- // Don't bother continuing without a callback
- if (!callback) return this;
- // Iterate over the current collection
- for (let i = 0; i < this.length; i += 1) {
- // If the callback returns false
- if (callback.call(this[i], i, this[i]) === false) {
- // End the loop early
- return this;
- }
- }
- // Return `this` to allow chained DOM operations
- return this;
- }
- function forEach(callback) {
- // Don't bother continuing without a callback
- if (!callback) return this;
- // Iterate over the current collection
- for (let i = 0; i < this.length; i += 1) {
- // If the callback returns false
- if (callback.call(this[i], this[i], i) === false) {
- // End the loop early
- return this;
- }
- }
- // Return `this` to allow chained DOM operations
- return this;
- }
- function filter(callback) {
- const matchedItems = [];
- const dom = this;
- for (let i = 0; i < dom.length; i += 1) {
- if (callback.call(dom[i], i, dom[i])) matchedItems.push(dom[i]);
- }
- return new Dom7(matchedItems);
- }
- function map(callback) {
- const modifiedItems = [];
- const dom = this;
- for (let i = 0; i < dom.length; i += 1) {
- modifiedItems.push(callback.call(dom[i], i, dom[i]));
- }
- return new Dom7(modifiedItems);
- }
- // eslint-disable-next-line
- function html(html) {
- if (typeof html === 'undefined') {
- return this[0] ? this[0].innerHTML : undefined;
- }
- for (let i = 0; i < this.length; i += 1) {
- this[i].innerHTML = html;
- }
- return this;
- }
- // eslint-disable-next-line
- function text(text) {
- if (typeof text === 'undefined') {
- if (this[0]) {
- return this[0].textContent.trim();
- }
- return null;
- }
- for (let i = 0; i < this.length; i += 1) {
- this[i].textContent = text;
- }
- return this;
- }
- function is(selector) {
- const el = this[0];
- let compareWith;
- let i;
- if (!el || typeof selector === 'undefined') return false;
- if (typeof selector === 'string') {
- if (el.matches) return el.matches(selector);
- else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
- else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
- compareWith = $(selector);
- for (i = 0; i < compareWith.length; i += 1) {
- if (compareWith[i] === el) return true;
- }
- return false;
- } else if (selector === document) return el === document;
- else if (selector === window) return el === window;
- if (selector.nodeType || selector instanceof Dom7) {
- compareWith = selector.nodeType ? [selector] : selector;
- for (i = 0; i < compareWith.length; i += 1) {
- if (compareWith[i] === el) return true;
- }
- return false;
- }
- return false;
- }
- function indexOf(el) {
- for (let i = 0; i < this.length; i += 1) {
- if (this[i] === el) return i;
- }
- return -1;
- }
- function index() {
- let child = this[0];
- let i;
- if (child) {
- i = 0;
- // eslint-disable-next-line
- while ((child = child.previousSibling) !== null) {
- if (child.nodeType === 1) i += 1;
- }
- return i;
- }
- return undefined;
- }
- // eslint-disable-next-line
- function eq(index) {
- if (typeof index === 'undefined') return this;
- const length = this.length;
- let returnIndex;
- if (index > length - 1) {
- return new Dom7([]);
- }
- if (index < 0) {
- returnIndex = length + index;
- if (returnIndex < 0) return new Dom7([]);
- return new Dom7([this[returnIndex]]);
- }
- return new Dom7([this[index]]);
- }
- function append(...args) {
- let newChild;
- for (let k = 0; k < args.length; k += 1) {
- newChild = args[k];
- for (let i = 0; i < this.length; i += 1) {
- if (typeof newChild === 'string') {
- const tempDiv = document.createElement('div');
- tempDiv.innerHTML = newChild;
- while (tempDiv.firstChild) {
- this[i].appendChild(tempDiv.firstChild);
- }
- } else if (newChild instanceof Dom7) {
- for (let j = 0; j < newChild.length; j += 1) {
- this[i].appendChild(newChild[j]);
- }
- } else {
- this[i].appendChild(newChild);
- }
- }
- }
- return this;
- }
- // eslint-disable-next-line
- function appendTo(parent) {
- $(parent).append(this);
- return this;
- }
- function prepend(newChild) {
- let i;
- let j;
- for (i = 0; i < this.length; i += 1) {
- if (typeof newChild === 'string') {
- const tempDiv = document.createElement('div');
- tempDiv.innerHTML = newChild;
- for (j = tempDiv.childNodes.length - 1; j >= 0; j -= 1) {
- this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
- }
- } else if (newChild instanceof Dom7) {
- for (j = 0; j < newChild.length; j += 1) {
- this[i].insertBefore(newChild[j], this[i].childNodes[0]);
- }
- } else {
- this[i].insertBefore(newChild, this[i].childNodes[0]);
- }
- }
- return this;
- }
- // eslint-disable-next-line
- function prependTo(parent) {
- $(parent).prepend(this);
- return this;
- }
- function insertBefore(selector) {
- const before = $(selector);
- for (let i = 0; i < this.length; i += 1) {
- if (before.length === 1) {
- before[0].parentNode.insertBefore(this[i], before[0]);
- } else if (before.length > 1) {
- for (let j = 0; j < before.length; j += 1) {
- before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
- }
- }
- }
- }
- function insertAfter(selector) {
- const after = $(selector);
- for (let i = 0; i < this.length; i += 1) {
- if (after.length === 1) {
- after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
- } else if (after.length > 1) {
- for (let j = 0; j < after.length; j += 1) {
- after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
- }
- }
- }
- }
- function next(selector) {
- if (this.length > 0) {
- if (selector) {
- if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) {
- return new Dom7([this[0].nextElementSibling]);
- }
- return new Dom7([]);
- }
- if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]);
- return new Dom7([]);
- }
- return new Dom7([]);
- }
- function nextAll(selector) {
- const nextEls = [];
- let el = this[0];
- if (!el) return new Dom7([]);
- while (el.nextElementSibling) {
- const next = el.nextElementSibling; // eslint-disable-line
- if (selector) {
- if ($(next).is(selector)) nextEls.push(next);
- } else nextEls.push(next);
- el = next;
- }
- return new Dom7(nextEls);
- }
- function prev(selector) {
- if (this.length > 0) {
- const el = this[0];
- if (selector) {
- if (el.previousElementSibling && $(el.previousElementSibling).is(selector)) {
- return new Dom7([el.previousElementSibling]);
- }
- return new Dom7([]);
- }
- if (el.previousElementSibling) return new Dom7([el.previousElementSibling]);
- return new Dom7([]);
- }
- return new Dom7([]);
- }
- function prevAll(selector) {
- const prevEls = [];
- let el = this[0];
- if (!el) return new Dom7([]);
- while (el.previousElementSibling) {
- const prev = el.previousElementSibling; // eslint-disable-line
- if (selector) {
- if ($(prev).is(selector)) prevEls.push(prev);
- } else prevEls.push(prev);
- el = prev;
- }
- return new Dom7(prevEls);
- }
- function siblings(selector) {
- return this.nextAll(selector).add(this.prevAll(selector));
- }
- function parent(selector) {
- const parents = []; // eslint-disable-line
- for (let i = 0; i < this.length; i += 1) {
- if (this[i].parentNode !== null) {
- if (selector) {
- if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
- } else {
- parents.push(this[i].parentNode);
- }
- }
- }
- return $(unique(parents));
- }
- function parents(selector) {
- const parents = []; // eslint-disable-line
- for (let i = 0; i < this.length; i += 1) {
- let parent = this[i].parentNode; // eslint-disable-line
- while (parent) {
- if (selector) {
- if ($(parent).is(selector)) parents.push(parent);
- } else {
- parents.push(parent);
- }
- parent = parent.parentNode;
- }
- }
- return $(unique(parents));
- }
- function closest(selector) {
- let closest = this; // eslint-disable-line
- if (typeof selector === 'undefined') {
- return new Dom7([]);
- }
- if (!closest.is(selector)) {
- closest = closest.parents(selector).eq(0);
- }
- return closest;
- }
- function find(selector) {
- const foundElements = [];
- for (let i = 0; i < this.length; i += 1) {
- const found = this[i].querySelectorAll(selector);
- for (let j = 0; j < found.length; j += 1) {
- foundElements.push(found[j]);
- }
- }
- return new Dom7(foundElements);
- }
- function children(selector) {
- const children = []; // eslint-disable-line
- for (let i = 0; i < this.length; i += 1) {
- const childNodes = this[i].childNodes;
- for (let j = 0; j < childNodes.length; j += 1) {
- if (!selector) {
- if (childNodes[j].nodeType === 1) children.push(childNodes[j]);
- } else if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) {
- children.push(childNodes[j]);
- }
- }
- }
- return new Dom7(unique(children));
- }
- function remove() {
- for (let i = 0; i < this.length; i += 1) {
- if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
- }
- return this;
- }
- function detach() {
- return this.remove();
- }
- function add(...args) {
- const dom = this;
- let i;
- let j;
- for (i = 0; i < args.length; i += 1) {
- const toAdd = $(args[i]);
- for (j = 0; j < toAdd.length; j += 1) {
- dom[dom.length] = toAdd[j];
- dom.length += 1;
- }
- }
- return dom;
- }
- function empty() {
- for (let i = 0; i < this.length; i += 1) {
- const el = this[i];
- if (el.nodeType === 1) {
- for (let j = 0; j < el.childNodes.length; j += 1) {
- if (el.childNodes[j].parentNode) {
- el.childNodes[j].parentNode.removeChild(el.childNodes[j]);
- }
- }
- el.textContent = '';
- }
- }
- return this;
- }
- var Methods = /*#__PURE__*/Object.freeze({
- addClass: addClass,
- removeClass: removeClass,
- hasClass: hasClass,
- toggleClass: toggleClass,
- attr: attr,
- removeAttr: removeAttr,
- prop: prop,
- data: data,
- removeData: removeData,
- dataset: dataset,
- val: val,
- transform: transform,
- transition: transition,
- on: on,
- off: off,
- once: once,
- trigger: trigger,
- transitionEnd: transitionEnd,
- animationEnd: animationEnd,
- width: width,
- outerWidth: outerWidth,
- height: height,
- outerHeight: outerHeight,
- offset: offset,
- hide: hide,
- show: show,
- styles: styles,
- css: css,
- toArray: toArray,
- each: each,
- forEach: forEach,
- filter: filter,
- map: map,
- html: html,
- text: text,
- is: is,
- indexOf: indexOf,
- index: index,
- eq: eq,
- append: append,
- appendTo: appendTo,
- prepend: prepend,
- prependTo: prependTo,
- insertBefore: insertBefore,
- insertAfter: insertAfter,
- next: next,
- nextAll: nextAll,
- prev: prev,
- prevAll: prevAll,
- siblings: siblings,
- parent: parent,
- parents: parents,
- closest: closest,
- find: find,
- children: children,
- remove: remove,
- detach: detach,
- add: add,
- empty: empty
- });
- function scrollTo(...args) {
- let [left, top, duration, easing, callback] = args;
- if (args.length === 4 && typeof easing === 'function') {
- callback = easing;
- [left, top, duration, callback, easing] = args;
- }
- if (typeof easing === 'undefined') easing = 'swing';
- return this.each(function animate() {
- const el = this;
- let currentTop;
- let currentLeft;
- let maxTop;
- let maxLeft;
- let newTop;
- let newLeft;
- let scrollTop; // eslint-disable-line
- let scrollLeft; // eslint-disable-line
- let animateTop = top > 0 || top === 0;
- let animateLeft = left > 0 || left === 0;
- if (typeof easing === 'undefined') {
- easing = 'swing';
- }
- if (animateTop) {
- currentTop = el.scrollTop;
- if (!duration) {
- el.scrollTop = top;
- }
- }
- if (animateLeft) {
- currentLeft = el.scrollLeft;
- if (!duration) {
- el.scrollLeft = left;
- }
- }
- if (!duration) return;
- if (animateTop) {
- maxTop = el.scrollHeight - el.offsetHeight;
- newTop = Math.max(Math.min(top, maxTop), 0);
- }
- if (animateLeft) {
- maxLeft = el.scrollWidth - el.offsetWidth;
- newLeft = Math.max(Math.min(left, maxLeft), 0);
- }
- let startTime = null;
- if (animateTop && newTop === currentTop) animateTop = false;
- if (animateLeft && newLeft === currentLeft) animateLeft = false;
- function render(time = new Date().getTime()) {
- if (startTime === null) {
- startTime = time;
- }
- const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
- const easeProgress = easing === 'linear' ? progress : (0.5 - (Math.cos(progress * Math.PI) / 2));
- let done;
- if (animateTop) scrollTop = currentTop + (easeProgress * (newTop - currentTop));
- if (animateLeft) scrollLeft = currentLeft + (easeProgress * (newLeft - currentLeft));
- if (animateTop && newTop > currentTop && scrollTop >= newTop) {
- el.scrollTop = newTop;
- done = true;
- }
- if (animateTop && newTop < currentTop && scrollTop <= newTop) {
- el.scrollTop = newTop;
- done = true;
- }
- if (animateLeft && newLeft > currentLeft && scrollLeft >= newLeft) {
- el.scrollLeft = newLeft;
- done = true;
- }
- if (animateLeft && newLeft < currentLeft && scrollLeft <= newLeft) {
- el.scrollLeft = newLeft;
- done = true;
- }
- if (done) {
- if (callback) callback();
- return;
- }
- if (animateTop) el.scrollTop = scrollTop;
- if (animateLeft) el.scrollLeft = scrollLeft;
- requestAnimationFrame(render);
- }
- requestAnimationFrame(render);
- });
- }
- // scrollTop(top, duration, easing, callback) {
- function scrollTop(...args) {
- let [top, duration, easing, callback] = args;
- if (args.length === 3 && typeof easing === 'function') {
- [top, duration, callback, easing] = args;
- }
- const dom = this;
- if (typeof top === 'undefined') {
- if (dom.length > 0) return dom[0].scrollTop;
- return null;
- }
- return dom.scrollTo(undefined, top, duration, easing, callback);
- }
- function scrollLeft(...args) {
- let [left, duration, easing, callback] = args;
- if (args.length === 3 && typeof easing === 'function') {
- [left, duration, callback, easing] = args;
- }
- const dom = this;
- if (typeof left === 'undefined') {
- if (dom.length > 0) return dom[0].scrollLeft;
- return null;
- }
- return dom.scrollTo(left, undefined, duration, easing, callback);
- }
- var Scroll = /*#__PURE__*/Object.freeze({
- scrollTo: scrollTo,
- scrollTop: scrollTop,
- scrollLeft: scrollLeft
- });
- function animate(initialProps, initialParams) {
- const els = this;
- const a = {
- props: Object.assign({}, initialProps),
- params: Object.assign({
- duration: 300,
- easing: 'swing', // or 'linear'
- /* Callbacks
- begin(elements)
- complete(elements)
- progress(elements, complete, remaining, start, tweenValue)
- */
- }, initialParams),
- elements: els,
- animating: false,
- que: [],
- easingProgress(easing, progress) {
- if (easing === 'swing') {
- return 0.5 - (Math.cos(progress * Math.PI) / 2);
- }
- if (typeof easing === 'function') {
- return easing(progress);
- }
- return progress;
- },
- stop() {
- if (a.frameId) {
- cancelAnimationFrame(a.frameId);
- }
- a.animating = false;
- a.elements.each((index, el) => {
- const element = el;
- delete element.dom7AnimateInstance;
- });
- a.que = [];
- },
- done(complete) {
- a.animating = false;
- a.elements.each((index, el) => {
- const element = el;
- delete element.dom7AnimateInstance;
- });
- if (complete) complete(els);
- if (a.que.length > 0) {
- const que = a.que.shift();
- a.animate(que[0], que[1]);
- }
- },
- animate(props, params) {
- if (a.animating) {
- a.que.push([props, params]);
- return a;
- }
- const elements = [];
- // Define & Cache Initials & Units
- a.elements.each((index, el) => {
- let initialFullValue;
- let initialValue;
- let unit;
- let finalValue;
- let finalFullValue;
- if (!el.dom7AnimateInstance) a.elements[index].dom7AnimateInstance = a;
- elements[index] = {
- container: el,
- };
- Object.keys(props).forEach((prop) => {
- initialFullValue = window.getComputedStyle(el, null).getPropertyValue(prop).replace(',', '.');
- initialValue = parseFloat(initialFullValue);
- unit = initialFullValue.replace(initialValue, '');
- finalValue = parseFloat(props[prop]);
- finalFullValue = props[prop] + unit;
- elements[index][prop] = {
- initialFullValue,
- initialValue,
- unit,
- finalValue,
- finalFullValue,
- currentValue: initialValue,
- };
- });
- });
- let startTime = null;
- let time;
- let elementsDone = 0;
- let propsDone = 0;
- let done;
- let began = false;
- a.animating = true;
- function render() {
- time = new Date().getTime();
- let progress;
- let easeProgress;
- // let el;
- if (!began) {
- began = true;
- if (params.begin) params.begin(els);
- }
- if (startTime === null) {
- startTime = time;
- }
- if (params.progress) {
- // eslint-disable-next-line
- params.progress(els, Math.max(Math.min((time - startTime) / params.duration, 1), 0), ((startTime + params.duration) - time < 0 ? 0 : (startTime + params.duration) - time), startTime);
- }
- elements.forEach((element) => {
- const el = element;
- if (done || el.done) return;
- Object.keys(props).forEach((prop) => {
- if (done || el.done) return;
- progress = Math.max(Math.min((time - startTime) / params.duration, 1), 0);
- easeProgress = a.easingProgress(params.easing, progress);
- const { initialValue, finalValue, unit } = el[prop];
- el[prop].currentValue = initialValue + (easeProgress * (finalValue - initialValue));
- const currentValue = el[prop].currentValue;
- if (
- (finalValue > initialValue && currentValue >= finalValue) ||
- (finalValue < initialValue && currentValue <= finalValue)) {
- el.container.style[prop] = finalValue + unit;
- propsDone += 1;
- if (propsDone === Object.keys(props).length) {
- el.done = true;
- elementsDone += 1;
- }
- if (elementsDone === elements.length) {
- done = true;
- }
- }
- if (done) {
- a.done(params.complete);
- return;
- }
- el.container.style[prop] = currentValue + unit;
- });
- });
- if (done) return;
- // Then call
- a.frameId = requestAnimationFrame(render);
- }
- a.frameId = requestAnimationFrame(render);
- return a;
- },
- };
- if (a.elements.length === 0) {
- return els;
- }
- let animateInstance;
- for (let i = 0; i < a.elements.length; i += 1) {
- if (a.elements[i].dom7AnimateInstance) {
- animateInstance = a.elements[i].dom7AnimateInstance;
- } else a.elements[i].dom7AnimateInstance = a;
- }
- if (!animateInstance) {
- animateInstance = a;
- }
- if (initialProps === 'stop') {
- animateInstance.stop();
- } else {
- animateInstance.animate(a.props, a.params);
- }
- return els;
- }
- function stop() {
- const els = this;
- for (let i = 0; i < els.length; i += 1) {
- if (els[i].dom7AnimateInstance) {
- els[i].dom7AnimateInstance.stop();
- }
- }
- }
- var Animate = /*#__PURE__*/Object.freeze({
- animate: animate,
- stop: stop
- });
- const noTrigger = ('resize scroll').split(' ');
- function eventShortcut(name, ...args) {
- if (typeof args[0] === 'undefined') {
- for (let i = 0; i < this.length; i += 1) {
- if (noTrigger.indexOf(name) < 0) {
- if (name in this[i]) this[i][name]();
- else {
- $(this[i]).trigger(name);
- }
- }
- }
- return this;
- }
- return this.on(name, ...args);
- }
- function click(...args) {
- return eventShortcut.bind(this)('click', ...args);
- }
- function blur(...args) {
- return eventShortcut.bind(this)('blur', ...args);
- }
- function focus(...args) {
- return eventShortcut.bind(this)('focus', ...args);
- }
- function focusin(...args) {
- return eventShortcut.bind(this)('focusin', ...args);
- }
- function focusout(...args) {
- return eventShortcut.bind(this)('focusout', ...args);
- }
- function keyup(...args) {
- return eventShortcut.bind(this)('keyup', ...args);
- }
- function keydown(...args) {
- return eventShortcut.bind(this)('keydown', ...args);
- }
- function keypress(...args) {
- return eventShortcut.bind(this)('keypress', ...args);
- }
- function submit(...args) {
- return eventShortcut.bind(this)('submit', ...args);
- }
- function change(...args) {
- return eventShortcut.bind(this)('change', ...args);
- }
- function mousedown(...args) {
- return eventShortcut.bind(this)('mousedown', ...args);
- }
- function mousemove(...args) {
- return eventShortcut.bind(this)('mousemove', ...args);
- }
- function mouseup(...args) {
- return eventShortcut.bind(this)('mouseup', ...args);
- }
- function mouseenter(...args) {
- return eventShortcut.bind(this)('mouseenter', ...args);
- }
- function mouseleave(...args) {
- return eventShortcut.bind(this)('mouseleave', ...args);
- }
- function mouseout(...args) {
- return eventShortcut.bind(this)('mouseout', ...args);
- }
- function mouseover(...args) {
- return eventShortcut.bind(this)('mouseover', ...args);
- }
- function touchstart(...args) {
- return eventShortcut.bind(this)('touchstart', ...args);
- }
- function touchend(...args) {
- return eventShortcut.bind(this)('touchend', ...args);
- }
- function touchmove(...args) {
- return eventShortcut.bind(this)('touchmove', ...args);
- }
- function resize(...args) {
- return eventShortcut.bind(this)('resize', ...args);
- }
- function scroll(...args) {
- return eventShortcut.bind(this)('scroll', ...args);
- }
- var eventShortcuts = /*#__PURE__*/Object.freeze({
- click: click,
- blur: blur,
- focus: focus,
- focusin: focusin,
- focusout: focusout,
- keyup: keyup,
- keydown: keydown,
- keypress: keypress,
- submit: submit,
- change: change,
- mousedown: mousedown,
- mousemove: mousemove,
- mouseup: mouseup,
- mouseenter: mouseenter,
- mouseleave: mouseleave,
- mouseout: mouseout,
- mouseover: mouseover,
- touchstart: touchstart,
- touchend: touchend,
- touchmove: touchmove,
- resize: resize,
- scroll: scroll
- });
- [Methods, Scroll, Animate, eventShortcuts].forEach((group) => {
- Object.keys(group).forEach((methodName) => {
- $.fn[methodName] = group[methodName];
- });
- });
- export default $;
|