@mobiscroll/react-lite
Version:
React UI library for progressive web and hybrid apps
1,858 lines (1,570 loc) • 314 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('react-dom'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['react', 'react-dom', 'prop-types'], factory) :
(global = global || self, global.mobiscroll = factory(global.React, global.ReactDOM, global.PropTypes));
}(this, (function (React, ReactDOM, PropTypes) { 'use strict';
React = React && React.hasOwnProperty('default') ? React['default'] : React;
ReactDOM = ReactDOM && ReactDOM.hasOwnProperty('default') ? ReactDOM['default'] : ReactDOM;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
var mobiscroll = mobiscroll || {},
util = {};
var os,
vers,
majorVersion,
minorVersion,
version = [],
isBrowser = typeof window !== 'undefined',
isDark = isBrowser && window.matchMedia && window.matchMedia('(prefers-color-scheme:dark)').matches,
userAgent = isBrowser ? navigator.userAgent : '',
platform = isBrowser ? navigator.platform : '',
maxTouchPoints = isBrowser ? navigator.maxTouchPoints : 0,
isSafari = /Safari/.test(userAgent),
device = userAgent.match(/Android|iPhone|iPad|iPod|Windows Phone|Windows|MSIE/i),
raf = isBrowser && window.requestAnimationFrame || function (func) {
return setTimeout(func, 20);
};
if (/Android/i.test(device)) {
os = 'android';
vers = userAgent.match(/Android\s+([\d.]+)/i);
if (vers) {
version = vers[0].replace('Android ', '').split('.');
}
} else if (/iPhone|iPad|iPod/i.test(device) || /iPhone|iPad|iPod/i.test(platform) || platform === 'MacIntel' && maxTouchPoints > 1) {
// On iPad with iOS 13 desktop site request is automatically enabled in Safari,
// so 'iPad' is no longer present in the user agent string.
// In this case we check `navigator.platform` and `navigator.maxTouchPoints`.
// maxTouchPoints is needed to exclude desktop Mac OS X.
os = 'ios';
vers = userAgent.match(/OS\s+([\d_]+)/i);
if (vers) {
version = vers[0].replace(/_/g, '.').replace('OS ', '').split('.');
}
} else if (/Windows Phone/i.test(device)) {
os = 'wp';
} else if (/Windows|MSIE/i.test(device)) {
os = 'windows';
}
majorVersion = version[0];
minorVersion = version[1];
function testProps(props) {
var i;
for (i in props) {
if (mod[props[i]] !== undefined) {
return true;
}
}
return false;
}
function testPrefix() {
var prefixes = ['Webkit', 'Moz', 'O', 'ms'],
p;
for (p in prefixes) {
if (testProps([prefixes[p] + 'Transform'])) {
return '-' + prefixes[p].toLowerCase() + '-';
}
}
return '';
}
function testTouch(e, elm) {
if (e.type == 'touchstart') {
elm.__mbscTouched = 1;
} else if (elm.__mbscTouched) {
delete elm.__mbscTouched;
return false;
}
return true;
}
function listen(el, event, handler, opt) {
if (el) {
el.addEventListener(event, handler, opt);
}
}
function unlisten(el, event, handler, opt) {
if (el) {
el.removeEventListener(event, handler, opt);
}
}
function matches(element, selector) {
if (!selector || !element || element.nodeType !== 1) {
return false;
}
var matchesSelector = element.matches || element.matchesSelector || element.webkitMatchesSelector || element.mozMatchesSelector || element.msMatchesSelector;
return matchesSelector.call(element, selector);
}
function closest(el, target, selector) {
while (target) {
if (matches(target, selector)) {
return target;
}
target = target !== el ? target.parentNode : null;
}
return null;
}
function trigger(elm, name, data) {
var evt;
try {
evt = new CustomEvent(name, {
detail: data,
bubbles: true,
cancelable: true
});
} catch (e) {
evt = document.createEvent('Event');
evt.initEvent(name, true, true);
evt.detail = data;
}
elm.dispatchEvent(evt);
}
var animEnd,
canvas,
mod,
cssPrefix,
hasGhostClick,
hasTransition,
isWebView,
isWkWebView,
jsPrefix,
win;
if (isBrowser) {
win = window;
canvas = document.createElement('canvas');
mod = document.createElement('modernizr').style;
cssPrefix = testPrefix();
jsPrefix = cssPrefix.replace(/^-/, '').replace(/-$/, '').replace('moz', 'Moz');
animEnd = mod.animation !== undefined ? 'animationend' : 'webkitAnimationEnd';
hasTransition = mod.transition !== undefined; // UIWebView on iOS still has the ghost click,
// WkWebView does not have a ghost click, but it's hard to tell if it's UIWebView or WkWebView
// In addition in iOS 12.2 if we enable tap handling, it brakes the form inputs
// (keyboard appears, but the cursor is not in the input).
isWebView = os === 'ios' && !isSafari;
isWkWebView = isWebView && win.webkit && win.webkit.messageHandlers;
hasGhostClick = mod.touchAction === undefined || isWebView && !isWkWebView;
}
var cssNumber = {
'column-count': 1,
'columns': 1,
'font-weight': 1,
'line-height': 1,
'opacity': 1,
'z-index': 1,
'zoom': 1
},
propMap = {
'readonly': 'readOnly'
},
emptyArray = [],
_slice = Array.prototype.slice;
function isFunction(value) {
return typeof value === "function";
}
function isObject(obj) {
return typeof obj === "object";
}
function likeArray(obj) {
return typeof obj.length == 'number';
}
function camelize(str) {
return str.replace(/-+(.)?/g, function (match, chr) {
return chr ? chr.toUpperCase() : '';
});
}
function extend(target, source, deep) {
for (var key in source) {
if (deep && ($.isPlainObject(source[key]) || $.isArray(source[key]))) {
if ($.isPlainObject(source[key]) && !$.isPlainObject(target[key]) || $.isArray(source[key]) && !$.isArray(target[key])) {
target[key] = {};
}
extend(target[key], source[key], deep);
} else if (source[key] !== undefined) {
target[key] = source[key];
}
}
}
function dasherize(str) {
return str.replace(/::/g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/_/g, '-').toLowerCase();
}
function maybeAddPx(name, value) {
return typeof value == "number" && !cssNumber[dasherize(name)] ? value + "px" : value;
}
var Dom = function () {
var Dom = function Dom(arr) {
var _this = this,
i = 0; // Create array-like object
for (i = 0; i < arr.length; i++) {
_this[i] = arr[i];
}
_this.length = arr.length; // Return collection with methods
return $(this);
};
var $ = function $(selector, context) {
var arr = [],
i = 0;
if (selector && !context) {
if (selector instanceof Dom) {
return selector;
}
}
if (isFunction(selector)) {
return $(document).ready(selector);
}
if (selector) {
// String
if (typeof selector === 'string') {
var els, tempParent, html;
selector = html = selector.trim();
if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
var 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++) {
arr.push(tempParent.childNodes[i]);
}
} else {
if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
// Pure ID selector
els = [document.getElementById(selector.split('#')[1])];
} else {
if (context instanceof Dom) {
context = context[0];
} // Other selectors
els = (context || document).querySelectorAll(selector);
}
for (i = 0; i < els.length; i++) {
if (els[i]) {
arr.push(els[i]);
}
}
}
} // Node/element
else if (selector.nodeType || selector === window || selector === document) {
arr.push(selector);
} //Array of elements or instance of Dom
else if (selector.length > 0 && selector[0].nodeType) {
for (i = 0; i < selector.length; i++) {
arr.push(selector[i]);
}
} else if ($.isArray(selector)) {
arr = selector;
}
}
return new Dom(arr);
};
Dom.prototype = {
ready: function ready(callback) {
if (document.attachEvent ? document.readyState == 'complete' : document.readyState != 'loading') {
callback($);
} else {
document.addEventListener('DOMContentLoaded', function () {
callback($);
}, false);
}
return this;
},
concat: emptyArray.concat,
empty: function empty() {
return this.each(function () {
this.innerHTML = '';
});
},
map: function map(fn) {
return $($.map(this, function (el, i) {
return fn.call(el, i, el);
}));
},
slice: function slice() {
return $(_slice.apply(this, arguments));
},
// Classes and attriutes
// NOTE: element.classList attribure is not supported on android 2.3!!!
addClass: function addClass(className) {
if (typeof className === 'undefined') {
return this;
}
var classes = className.split(' ');
for (var i = 0; i < classes.length; i++) {
for (var j = 0; j < this.length; j++) {
if (typeof this[j].classList !== 'undefined' && classes[i] !== '') {
this[j].classList.add(classes[i]);
}
}
}
return this;
},
removeClass: function removeClass(className) {
if (typeof className === 'undefined') {
return this;
}
var classes = className.split(' ');
for (var i = 0; i < classes.length; i++) {
for (var j = 0; j < this.length; j++) {
if (typeof this[j].classList !== 'undefined' && classes[i] !== '') {
this[j].classList.remove(classes[i]);
}
}
}
return this;
},
hasClass: function hasClass(className) {
return this[0] ? this[0].classList.contains(className) : false;
},
toggleClass: function toggleClass(className) {
var classes = className.split(' ');
for (var i = 0; i < classes.length; i++) {
for (var j = 0; j < this.length; j++) {
if (typeof this[j].classList !== 'undefined') {
this[j].classList.toggle(classes[i]);
}
}
}
return this;
},
closest: function closest(selector, context) {
var node = this[0],
collection = false;
if (isObject(selector)) {
collection = $(selector);
}
while (node && !(collection ? collection.indexOf(node) >= 0 : matches(node, selector))) {
node = node !== context && node.nodeType !== node.DOCUMENT_NODE && node.parentNode;
}
return $(node);
},
attr: function attr(attrs, value) {
var attr;
if (arguments.length === 1 && typeof attrs === 'string') {
// Get attr
if (this.length) {
attr = this[0].getAttribute(attrs);
return attr || attr === '' ? attr : undefined;
}
} else {
// Set attrs
for (var i = 0; i < this.length; i++) {
if (arguments.length === 2) {
// String
this[i].setAttribute(attrs, value);
} else {
// Object
for (var attrName in attrs) {
this[i][attrName] = attrs[attrName];
this[i].setAttribute(attrName, attrs[attrName]);
}
}
}
return this;
}
},
removeAttr: function removeAttr(attr) {
for (var i = 0; i < this.length; i++) {
this[i].removeAttribute(attr);
}
return this;
},
prop: function prop(props, value) {
props = propMap[props] || props;
if (arguments.length === 1 && typeof props === 'string') {
// Get prop
return this[0] ? this[0][props] : undefined;
} else {
// Set props
for (var i = 0; i < this.length; i++) {
this[i][props] = value;
}
return this;
}
},
val: function val(value) {
if (typeof value === 'undefined') {
if (this.length && this[0].multiple) {
return $.map(this.find('option:checked'), function (v) {
return v.value;
});
}
return this[0] ? this[0].value : undefined;
}
if (this.length && this[0].multiple) {
$.each(this[0].options, function () {
this.selected = value.indexOf(this.value) != -1;
});
} else {
for (var i = 0; i < this.length; i++) {
this[i].value = value;
}
}
return this;
},
//Events
on: function on(eventName, targetSelector, listener, capture) {
var boundListener,
elm,
event,
events = eventName.split(' '),
i,
j;
function handleLiveEvent(e) {
var target = e.target;
while (target) {
if ($(target).is(targetSelector)) {
listener.call(target, e);
}
target = target !== this ? target.parentNode : null;
}
}
function handleNamespaces(el, name, listener, capture) {
var namespace = name.split('.');
if (!el.DomNameSpaces) {
el.DomNameSpaces = [];
}
el.DomNameSpaces.push({
namespace: namespace[1],
event: namespace[0],
listener: listener,
capture: capture
});
el.addEventListener(namespace[0], listener, capture);
}
for (i = 0; i < this.length; i++) {
elm = this[i];
if (isFunction(targetSelector) || targetSelector === false) {
// Usual events
if (isFunction(targetSelector)) {
capture = listener || false;
listener = targetSelector;
}
for (j = 0; j < events.length; j++) {
event = events[j]; // check for namespaces
if (event.indexOf('.') != -1) {
handleNamespaces(elm, event, listener, capture);
} else {
elm.addEventListener(event, listener, capture);
}
}
} else {
// Live events
boundListener = handleLiveEvent.bind(elm);
for (j = 0; j < events.length; j++) {
event = events[j];
if (!elm.DomLiveListeners) {
elm.DomLiveListeners = [];
}
elm.DomLiveListeners.push({
listener: listener,
liveListener: boundListener
});
if (event.indexOf('.') != -1) {
handleNamespaces(elm, event, boundListener, capture);
} else {
elm.addEventListener(event, boundListener, capture);
}
}
}
}
return this;
},
off: function off(eventName, targetSelector, listener, capture) {
var elm,
event,
events,
i,
j,
k,
liveListeners,
that = this;
function removeEvents(event) {
var el,
i,
j,
item,
nameSpaces,
parts = event.split('.'),
name = parts[0],
ns = parts[1];
for (i = 0; i < that.length; ++i) {
el = that[i];
nameSpaces = el.DomNameSpaces;
if (nameSpaces) {
for (j = 0; j < nameSpaces.length; ++j) {
item = nameSpaces[j];
if (item.namespace == ns && (item.event == name || !name)) {
el.removeEventListener(item.event, item.listener, item.capture);
item.removed = true;
}
} // remove the events from the DomNameSpaces array
for (j = nameSpaces.length - 1; j >= 0; --j) {
if (nameSpaces[j].removed) {
nameSpaces.splice(j, 1);
}
}
}
}
}
events = eventName.split(' ');
for (i = 0; i < events.length; i++) {
event = events[i];
for (j = 0; j < this.length; j++) {
elm = this[j];
liveListeners = elm.DomLiveListeners;
if (isFunction(targetSelector) || targetSelector === false) {
// Usual events
if (isFunction(targetSelector)) {
capture = listener || false;
listener = targetSelector;
}
if (event.indexOf('.') === 0) {
// remove namespace events
removeEvents(event.substr(1));
} else {
elm.removeEventListener(event, listener, capture);
}
} else {
// Live event
if (liveListeners) {
for (k = 0; k < liveListeners.length; k++) {
if (liveListeners[k].listener === listener) {
elm.removeEventListener(event, liveListeners[k].liveListener, capture);
}
}
}
if (elm.DomNameSpaces && elm.DomNameSpaces.length && event) {
removeEvents(event);
}
}
}
}
return this;
},
trigger: function trigger$1(eventName, eventData) {
var events = eventName.split(' ');
for (var i = 0; i < events.length; i++) {
for (var j = 0; j < this.length; j++) {
trigger(this[j], events[i], eventData);
}
}
return this;
},
// Sizing/Styles
width: function width(dim) {
if (dim !== undefined) {
return this.css('width', dim);
}
if (this[0] === window) {
return window.innerWidth;
} else if (this[0] === document) {
return document.documentElement.scrollWidth;
} else {
return this.length > 0 ? parseFloat(this.css('width')) : null;
}
},
height: function height(dim) {
if (dim !== undefined) {
return this.css('height', dim);
}
if (this[0] === window) {
return window.innerHeight;
} else if (this[0] === document) {
var body = document.body,
html = document.documentElement;
return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
} else {
return this.length > 0 ? parseFloat(this.css('height')) : null;
}
},
innerWidth: function innerWidth() {
var elm = this;
if (this.length > 0) {
if (this[0].innerWidth) {
return this[0].innerWidth;
} else {
var size = this[0].offsetWidth,
sides = ['left', 'right'];
sides.forEach(function (side) {
size -= parseInt(elm.css(camelize('border-' + side + '-width')) || 0, 10);
});
return size;
}
}
},
innerHeight: function innerHeight() {
var elm = this;
if (this.length > 0) {
if (this[0].innerHeight) {
return this[0].innerHeight;
} else {
var size = this[0].offsetHeight,
sides = ['top', 'bottom'];
sides.forEach(function (side) {
size -= parseInt(elm.css(camelize('border-' + side + '-width')) || 0, 10);
});
return size;
}
}
},
offset: function offset() {
if (this.length > 0) {
var el = this[0],
box = el.getBoundingClientRect(),
doc = document.documentElement;
return {
top: box.top + window.pageYOffset - doc.clientTop,
left: box.left + window.pageXOffset - doc.clientLeft
};
}
},
hide: function hide() {
for (var i = 0; i < this.length; i++) {
this[i].style.display = 'none';
}
return this;
},
show: function show() {
for (var i = 0; i < this.length; i++) {
if (this[i].style.display == "none") {
this[i].style.display = '';
}
if (getComputedStyle(this[i], '').getPropertyValue("display") == "none") {
this[i].style.display = 'block';
}
}
return this;
},
clone: function clone() {
return this.map(function () {
return this.cloneNode(true);
});
},
styles: function styles() {
return this[0] ? window.getComputedStyle(this[0], null) : undefined;
},
css: function css(property, value) {
var i,
key,
element = this[0],
css = '';
if (arguments.length < 2) {
if (!element) {
return;
}
if (typeof property === 'string') {
return element.style[property] || getComputedStyle(element, '').getPropertyValue(property);
}
}
if (typeof property === 'string') {
if (!value && value !== 0) {
this.each(function () {
this.style.removeProperty(dasherize(property));
});
} else {
css = dasherize(property) + ":" + maybeAddPx(property, value);
}
} else {
for (key in property) {
if (!property[key] && property[key] !== 0) {
for (i = 0; i < this.length; i++) {
this[i].style.removeProperty(dasherize(key));
}
} else {
css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';';
}
}
}
return this.each(function () {
this.style.cssText += ';' + css;
});
},
each: function each(callback) {
for (var i = 0; i < this.length; i++) {
if (callback.apply(this[i], [i, this[i]]) === false) {
break;
}
}
return this;
},
filter: function filter(callback) {
var matchedItems = [];
for (var i = 0; i < this.length; i++) {
if (isFunction(callback)) {
if (callback.call(this[i], i, this[i])) {
matchedItems.push(this[i]);
}
} else if (matches(this[i], callback)) {
matchedItems.push(this[i]);
}
}
return new Dom(matchedItems);
},
html: function html(_html) {
if (typeof _html === 'undefined') {
return this[0] ? this[0].innerHTML : undefined;
} else {
this.empty();
for (var i = 0; i < this.length; i++) {
this[i].innerHTML = _html;
}
return this;
}
},
text: function text(_text) {
if (typeof _text === 'undefined') {
return this[0] ? this[0].textContent.trim() : null;
} else {
for (var i = 0; i < this.length; i++) {
this[i].textContent = _text;
}
return this;
}
},
is: function is(selector) {
return this.length > 0 && matches(this[0], selector);
},
not: function not(selector) {
var nodes = [];
if (isFunction(selector) && selector.call !== undefined) {
this.each(function (idx) {
if (!selector.call(this, idx)) {
nodes.push(this);
}
});
} else {
var excludes = typeof selector == 'string' ? this.filter(selector) : likeArray(selector) && isFunction(selector.item) ? _slice.call(selector) : $(selector);
if (isObject(excludes)) {
excludes = $.map(excludes, function (el) {
return el;
});
}
this.each(function (i, el) {
if (excludes.indexOf(el) < 0) {
nodes.push(el);
}
});
}
return $(nodes);
},
indexOf: function indexOf(el) {
for (var i = 0; i < this.length; i++) {
if (this[i] === el) {
return i;
}
}
},
index: function index(element) {
return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]);
},
get: function get(idx) {
return idx === undefined ? _slice.call(this) : this[idx >= 0 ? idx : idx + this.length];
},
eq: function eq(index) {
if (typeof index === 'undefined') {
return this;
}
var length = this.length,
returnIndex;
if (index > length - 1) {
return new Dom([]);
}
if (index < 0) {
returnIndex = length + index;
return returnIndex < 0 ? new Dom([]) : new Dom([this[returnIndex]]);
}
return new Dom([this[index]]);
},
append: function append(newChild) {
var i, j;
for (i = 0; i < this.length; i++) {
if (typeof newChild === 'string') {
var tempDiv = document.createElement('div');
tempDiv.innerHTML = newChild;
while (tempDiv.firstChild) {
this[i].appendChild(tempDiv.firstChild);
}
} else if (newChild instanceof Dom) {
for (j = 0; j < newChild.length; j++) {
this[i].appendChild(newChild[j]);
}
} else {
this[i].appendChild(newChild);
}
}
return this;
},
appendTo: function appendTo(parent) {
$(parent).append(this);
return this;
},
prepend: function prepend(newChild) {
var i, j;
for (i = 0; i < this.length; i++) {
if (typeof newChild === 'string') {
var tempDiv = document.createElement('div');
tempDiv.innerHTML = newChild;
for (j = tempDiv.childNodes.length - 1; j >= 0; j--) {
this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
} // this[i].insertAdjacentHTML('afterbegin', newChild);
} else if (newChild instanceof Dom) {
for (j = 0; j < newChild.length; j++) {
this[i].insertBefore(newChild[j], this[i].childNodes[0]);
}
} else {
this[i].insertBefore(newChild, this[i].childNodes[0]);
}
}
return this;
},
prependTo: function prependTo(parent) {
$(parent).prepend(this);
return this;
},
insertBefore: function insertBefore(selector) {
var before = $(selector);
for (var i = 0; i < this.length; i++) {
if (before.length === 1) {
before[0].parentNode.insertBefore(this[i], before[0]);
} else if (before.length > 1) {
for (var j = 0; j < before.length; j++) {
before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
}
}
}
return this;
},
insertAfter: function insertAfter(selector) {
var after = $(selector);
for (var i = 0; i < this.length; i++) {
if (after.length === 1) {
after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
} else if (after.length > 1) {
for (var j = 0; j < after.length; j++) {
after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
}
}
}
return this;
},
next: function next(selector) {
if (this.length > 0) {
if (selector) {
if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) {
return new Dom([this[0].nextElementSibling]);
} else {
return new Dom([]);
}
} else {
if (this[0].nextElementSibling) {
return new Dom([this[0].nextElementSibling]);
} else {
return new Dom([]);
}
}
} else {
return new Dom([]);
}
},
nextAll: function nextAll(selector) {
var nextEls = [],
el = this[0];
if (!el) {
return new Dom([]);
}
while (el.nextElementSibling) {
var next = el.nextElementSibling;
if (selector) {
if ($(next).is(selector)) {
nextEls.push(next);
}
} else {
nextEls.push(next);
}
el = next;
}
return new Dom(nextEls);
},
prev: function prev(selector) {
if (this.length > 0) {
if (selector) {
if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) {
return new Dom([this[0].previousElementSibling]);
} else {
return new Dom([]);
}
} else {
if (this[0].previousElementSibling) {
return new Dom([this[0].previousElementSibling]);
} else {
return new Dom([]);
}
}
} else {
return new Dom([]);
}
},
prevAll: function prevAll(selector) {
var prevEls = [];
var el = this[0];
if (!el) {
return new Dom([]);
}
while (el.previousElementSibling) {
var prev = el.previousElementSibling;
if (selector) {
if ($(prev).is(selector)) {
prevEls.push(prev);
}
} else {
prevEls.push(prev);
}
el = prev;
}
return new Dom(prevEls);
},
parent: function parent(selector) {
var parents = [];
for (var i = 0; i < this.length; i++) {
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));
},
parents: function parents(selector) {
var parents = [];
for (var i = 0; i < this.length; i++) {
var parent = this[i].parentNode;
while (parent) {
if (selector) {
if ($(parent).is(selector)) {
parents.push(parent);
}
} else {
parents.push(parent);
}
parent = parent.parentNode;
}
}
return $($.unique(parents));
},
find: function find(selector) {
var foundElements = [];
for (var i = 0; i < this.length; i++) {
var found = this[i].querySelectorAll(selector);
for (var j = 0; j < found.length; j++) {
foundElements.push(found[j]);
}
}
return new Dom(foundElements);
},
children: function children(selector) {
var children = [];
for (var i = 0; i < this.length; i++) {
var childNodes = this[i].childNodes;
for (var j = 0; j < childNodes.length; j++) {
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 Dom($.unique(children));
},
remove: function remove() {
for (var i = 0; i < this.length; i++) {
if (this[i].parentNode) {
this[i].parentNode.removeChild(this[i]);
}
}
return this;
},
add: function add() {
var dom = this;
var i, j;
for (i = 0; i < arguments.length; i++) {
var toAdd = $(arguments[i]);
for (j = 0; j < toAdd.length; j++) {
dom[dom.length] = toAdd[j];
dom.length++;
}
}
return dom;
},
before: function before(elm) {
$(elm).insertBefore(this);
return this;
},
after: function after(elm) {
$(elm).insertAfter(this);
return this;
},
scrollTop: function scrollTop(value) {
if (!this.length) {
return;
}
var hasScrollTop = 'scrollTop' in this[0];
if (value === undefined) {
return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset;
}
return this.each(hasScrollTop ? function () {
this.scrollTop = value;
} : function () {
this.scrollTo(this.scrollX, value);
});
},
scrollLeft: function scrollLeft(value) {
if (!this.length) {
return;
}
var hasScrollLeft = 'scrollLeft' in this[0];
if (value === undefined) {
return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset;
}
return this.each(hasScrollLeft ? function () {
this.scrollLeft = value;
} : function () {
this.scrollTo(value, this.scrollY);
});
},
contents: function contents() {
return this.map(function (i, v) {
return _slice.call(v.childNodes);
});
},
nextUntil: function nextUntil(selector) {
var n = this,
array = [];
while (n.length && !n.filter(selector).length) {
array.push(n[0]);
n = n.next();
}
return $(array);
},
prevUntil: function prevUntil(selector) {
var n = this,
array = [];
while (n.length && !$(n).filter(selector).length) {
array.push(n[0]);
n = n.prev();
}
return $(array);
},
detach: function detach() {
return this.remove();
}
}; // Link to prototype
$.fn = Dom.prototype;
return $;
}(); // Export to local scope
var $ = Dom; // Export to mobiscroll
mobiscroll.$ = Dom; // DOM Library Utilites
$.inArray = function (elem, array, i) {
return emptyArray.indexOf.call(array, elem, i);
};
$.extend = function (target) {
var deep,
args = _slice.call(arguments, 1);
if (typeof target == 'boolean') {
deep = target;
target = args.shift();
}
target = target || {};
args.forEach(function (arg) {
extend(target, arg, deep);
});
return target;
};
$.isFunction = isFunction;
$.isArray = function (arr) {
return Object.prototype.toString.apply(arr) === '[object Array]';
};
$.isPlainObject = function (obj) {
return isObject(obj) && obj !== null && obj !== obj.window && Object.getPrototypeOf(obj) == Object.prototype;
};
$.each = function (obj, callback) {
var i, prop;
if (!isObject(obj) || !callback) {
return;
}
if ($.isArray(obj) || obj instanceof Dom) {
// Array
for (i = 0; i < obj.length; i++) {
if (callback.call(obj[i], i, obj[i]) === false) {
break;
}
}
} else {
// Object
for (prop in obj) {
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(prop) && prop !== 'length') {
if (callback.call(obj[prop], prop, obj[prop]) === false) {
break;
}
}
}
}
return this;
};
$.unique = function (arr) {
var unique = [];
for (var i = 0; i < arr.length; i++) {
if (unique.indexOf(arr[i]) === -1) {
unique.push(arr[i]);
}
}
return unique;
};
$.map = function (elements, callback) {
var value,
values = [],
i,
key;
if (likeArray(elements)) {
for (i = 0; i < elements.length; i++) {
value = callback(elements[i], i);
if (value !== null) {
values.push(value);
}
}
} else {
for (key in elements) {
value = callback(elements[key], key);
if (value !== null) {
values.push(value);
}
}
}
return values.length > 0 ? $.fn.concat.apply([], values) : values;
};
function noop() {}
function isString(s) {
return typeof s === 'string';
}
function constrain(val, min, max) {
return Math.max(min, Math.min(val, max));
}
function vibrate(time) {
if ('vibrate' in navigator) {
navigator.vibrate(time || 50);
}
}
function getPercent(v, min, max) {
return (v - min) * 100 / (max - min);
}
function getBoolAttr(attr, def, $elm) {
var v = $elm.attr(attr);
return v === undefined || v === '' ? def : v === 'true';
}
var tapped = 0;
var allowQuick;
function preventClick() {
// Prevent ghost click
tapped++;
setTimeout(function () {
tapped--;
}, 500);
}
function triggerClick(ev, control) {
// Prevent duplicate triggers on the same element
// e.g. a form checkbox inside a listview item
if (control.mbscClick) {
return;
}
var touch = (ev.originalEvent || ev).changedTouches[0],
evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
evt.isMbscTap = true; // Prevent ionic to bust our click
// This works for Ionic 1 - 3, not sure about 4
evt.isIonicTap = true; // This will allow a click fired together with this click
// We need this, because clicking on a label will trigger a click
// on the associated input as well, which should not be busted
allowQuick = true;
control.mbscChange = true;
control.mbscClick = true;
control.dispatchEvent(evt);
allowQuick = false; // Prevent ghost click
preventClick();
setTimeout(function () {
delete control.mbscClick;
});
}
function getCoord(e, c, page) {
var ev = e.originalEvent || e,
prop = (page ? 'page' : 'client') + c; // Multi touch support
if (ev.targetTouches && ev.targetTouches[0]) {
return ev.targetTouches[0][prop];
}
if (ev.changedTouches && ev.changedTouches[0]) {
return ev.changedTouches[0][prop];
}
return e[prop];
}
function getControlType($elm) {
var attrs = ['switch', 'range', 'rating', 'segmented', 'stepper'];
var elm = $elm[0];
var role = $elm.attr('data-role');
var type = $elm.attr('type') || elm.nodeName.toLowerCase();
if (/(switch|range|rating|segmented|stepper|select)/.test(role)) {
type = role;
} else {
for (var i = 0; i < attrs.length; i++) {
if ($elm.is('[mbsc-' + attrs[i] + ']')) {
type = attrs[i];
}
}
}
return type;
}
function activateControl(control, type, ev) {
control.focus();
if (/(button|submit|checkbox|switch|radio)/.test(type)) {
ev.preventDefault();
}
if (!/select/.test(type)) {
triggerClick(ev, control);
}
}
function tap(that, el, handler, prevent, tolerance, time) {
var startX,
startY,
target,
moved,
startTime,
$ = mobiscroll.$,
$elm = $(el);
tolerance = tolerance || 9;
function onStart(ev) {
if (!target) {
// Can't always call preventDefault here, it kills page scroll
// if (prevent) {
// ev.preventDefault();
// }
target = this;
startX = getCoord(ev, 'X');
startY = getCoord(ev, 'Y');
moved = false;
startTime = new Date();
}
}
function onMove(ev) {
// If movement is more than 20px, don't fire the click event handler
if (target && !moved && (Math.abs(getCoord(ev, 'X') - startX) > tolerance || Math.abs(getCoord(ev, 'Y') - startY) > tolerance)) {
moved = true;
}
}
function onEnd(ev) {
if (target) {
if (time && new Date() - startTime < 100 || !moved) {
// ev.preventDefault();
// handler.call(target, ev, that);
triggerClick(ev, ev.target);
} else {
preventClick();
}
target = false;
}
}
function onClick(ev) {
if (prevent) {
ev.preventDefault();
} // If handler was not called on touchend, call it on click;
handler.call(this, ev, that);
}
function onCancel() {
target = false;
}
$elm.each(function (i, elm) {
if (that.settings.tap) {
listen(elm, 'touchstart', onStart, {
passive: true
});
listen(elm, 'touchcancel', onCancel);
listen(elm, 'touchmove', onMove, {
passive: true
});
listen(elm, 'touchend', onEnd);
}
listen(elm, 'click', onClick);
elm.__mbscOff = function () {
unlisten(elm, 'touchstart', onStart, {
passive: true
});
unlisten(elm, 'touchcancel', onCancel);
unlisten(elm, 'touchmove', onMove, {
passive: true
});
unlisten(elm, 'touchend', onEnd);
unlisten(elm, 'click', onClick);
delete elm.__mbscOff;
};
});
}
function tapOff($elm) {
if ($elm && $elm[0] && $elm[0].__mbscOff) {
$elm[0].__mbscOff();
}
} // Prevent standard behaviour on body click
function bustClick(ev) {
// Textarea needs the mousedown event
if (tapped && !allowQuick && !ev.isMbscTap && !(ev.target.nodeName == 'TEXTAREA' && ev.type == 'mousedown')) {
ev.stopPropagation();
ev.preventDefault();
return false;
}
}
if (isBrowser) {
['mouseover', 'mousedown', 'mouseup', 'click'].forEach(function (ev) {
document.addEventListener(ev, bustClick, true);
});
if (os == 'android' && majorVersion < 5) {
document.addEventListener('change', function (ev) {
if (tapped && ev.target.type == 'checkbox' && !ev.target.mbscChange) {
ev.stopPropagation();
ev.preventDefault();
}
delete ev.target.mbscChange;
}, true);
}
}
/*!
* Mobiscroll v4.10.9
* http://mobiscroll.com
*
*
* Copyright 2010-2018, Acid Media
*
*/
function getWidth(el) {
return el[0].innerWidth || el.innerWidth();
}
function getThemeName(s) {
var themeName = s.theme,
themeVariant = s.themeVariant;
if (themeName == 'auto' || !themeName) {
themeName = ms.autoTheme;
}
if (themeName == 'default') {
themeName = 'mobiscroll';
}
if ((themeVariant === 'dark' || isDark && themeVariant === 'auto') && ms.themes.form[themeName + '-dark']) {
themeName = themeName + '-dark';
} else if (themeVariant === 'light' && /.+-dark$/.test(themeName)) {
themeName = themeName.replace(/-dark$/, '');
}
return themeName;
}
function autoInit(selector, Component, hasRefresh) {
if (isBrowser) {
$$1(function () {
$$1(selector).each(function () {
new Component(this, {});
});
$$1(document).on('mbsc-enhance', function (ev, settings) {
if ($$1(ev.target).is(selector)) {
new Component(ev.target, settings || {});
} else {
$$1(selector, ev.target).each(function () {
new Component(this, settings || {});
});
}
});
if (hasRefresh) {
$$1(document).on('mbsc-refresh', function (ev) {
var inst;
if ($$1(ev.target).is(selector)) {
inst = instances[ev.target.id];
if (inst) {
inst.refresh();
}
} else {
$$1(selector, ev.target).each(function () {
inst = instances[this.id];
if (inst) {
inst.refresh();
}
});
}
});
}
});
}
}
var ms,
$$1 = mobiscroll.$,
id = +new Date(),
instances = {},
classes = {},
empty = {},
breakpoints = {
xsmall: 0,
small: 576,
medium: 768,
large: 992,
xlarge: 1200
},
extend$1 = $$1.extend;
extend$1(util, {
getCoord: getCoord,
preventClick: preventClick,
vibrate: vibrate
});
ms = extend$1(mobiscroll, {
$: $$1,
version: '4.10.9',
autoTheme: 'mobiscroll',
themes: {
form: {},
page: {},
frame: {},
scroller: {},
listview: {},
navigation: {},
progress: {},
card: {}
},
platform: {
name: os,
majorVersion: majorVersion,
minorVersion: minorVersion
},
i18n: {},
instances: instances,
classes: classes,
util: util,
settings: {},
setDefaults: function setDefaults(o) {
extend$1(this.settings, o);
},
customTheme: function customTheme(name, baseTheme) {
var i,
themes = mobiscroll.themes,
comps = ['frame', 'scroller', 'listview', 'navigation', 'form', 'page', 'progress', 'card'];
for (i = 0; i < comps.length; i++) {
themes[comps[i]][name] = extend$1({}, themes[comps[i]][baseTheme], {
baseTheme: baseTheme
});
}
}
});
var Base = function Base(el, settings) {
var ctx,
lang,
preset,
resp,
s,
theme,
themeName,
trigger,
defaults,
that = this;
that.settings = {};
that.element = el;
that._init = noop;
that._destroy = noop;
that._processSettings = noop;
that._checkResp = function (width) {
if (that && that._responsive) {
var newResp = getResponsiveSettings(width);
if (resp !== newResp) {
resp = newResp;
that.init({});
return true;
}
}
};
that._getRespCont = function () {
return $$1(s.context == 'body' ? window : s.context);
};
that.init = function (newSettings, newValue) {
var key, value; // In case of settings update save the old value
if (newSettings && that.getVal) {
value = that.getVal();
} // Reset settings object
for (key in that.settings) {
delete that.settings[key];
}
s = that.settings; // Update original user settings
extend$1(settings, newSettings); // Load user defaults
if (that._hasDef) {
defaults = ms.settings;
} // Create settings object
extend$1(s, that._defaults, defaults, settings);
ctx = that._getRespCont();
if (that._responsive) {
if (!resp) {
resp = getResponsiveSettings();
}
extend$1(s, resp);
} // Get theme defaults
if (that._hasThem