@pi0/framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
1,578 lines (1,496 loc) • 885 kB
JavaScript
/**
* Framework7 2.0.0-beta.9
* Full featured mobile HTML framework for building iOS & Android apps
* http://framework7.io/
*
* Copyright 2014-2017 Vladimir Kharlampidi
*
* Released under the MIT License
*
* Released on: October 9, 2017
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Framework7 = factory());
}(this, (function () { 'use strict';
/**
* Template7 1.3.0
* Mobile-first HTML template engine
*
* http://www.idangero.us/template7/
*
* Copyright 2017, Vladimir Kharlampidi
* The iDangero.us
* http://www.idangero.us/
*
* Licensed under MIT
*
* Released on: September 13, 2017
*/
var t7ctx;
if (typeof window !== 'undefined') {
t7ctx = window;
} else if (typeof global !== 'undefined') {
t7ctx = global;
} else {
t7ctx = undefined;
}
var Template7Context = t7ctx;
var Template7Utils = {
quoteSingleRexExp: new RegExp('\'', 'g'),
quoteDoubleRexExp: new RegExp('"', 'g'),
isFunction: function isFunction(func) {
return typeof func === 'function';
},
escape: function escape(string) {
return (typeof Template7Context !== 'undefined' && Template7Context.escape) ?
Template7Context.escape(string) :
string
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
},
helperToSlices: function helperToSlices(string) {
var quoteDoubleRexExp = Template7Utils.quoteDoubleRexExp;
var quoteSingleRexExp = Template7Utils.quoteSingleRexExp;
var helperParts = string.replace(/[{}#}]/g, '').split(' ');
var slices = [];
var shiftIndex;
var i;
var j;
for (i = 0; i < helperParts.length; i += 1) {
var part = helperParts[i];
var blockQuoteRegExp = (void 0);
var openingQuote = (void 0);
if (i === 0) { slices.push(part); }
else if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) {
blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp;
openingQuote = part.indexOf('"') === 0 ? '"' : '\'';
// Plain String
if (part.match(blockQuoteRegExp).length === 2) {
// One word string
slices.push(part);
} else {
// Find closed Index
shiftIndex = 0;
for (j = i + 1; j < helperParts.length; j += 1) {
part += " " + (helperParts[j]);
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
slices.push(part);
break;
}
}
if (shiftIndex) { i = shiftIndex; }
}
} else if (part.indexOf('=') > 0) {
// Hash
var hashParts = part.split('=');
var hashName = hashParts[0];
var hashContent = hashParts[1];
if (!blockQuoteRegExp) {
blockQuoteRegExp = hashContent.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp;
openingQuote = hashContent.indexOf('"') === 0 ? '"' : '\'';
}
if (hashContent.match(blockQuoteRegExp).length !== 2) {
shiftIndex = 0;
for (j = i + 1; j < helperParts.length; j += 1) {
hashContent += " " + (helperParts[j]);
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
break;
}
}
if (shiftIndex) { i = shiftIndex; }
}
var hash = [hashName, hashContent.replace(blockQuoteRegExp, '')];
slices.push(hash);
} else {
// Plain variable
slices.push(part);
}
}
return slices;
},
stringToBlocks: function stringToBlocks(string) {
var blocks = [];
var i;
var j;
if (!string) { return []; }
var stringBlocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < stringBlocks.length; i += 1) {
var block = stringBlocks[i];
if (block === '') { continue; }
if (block.indexOf('{{') < 0) {
blocks.push({
type: 'plain',
content: block,
});
} else {
if (block.indexOf('{/') >= 0) {
continue;
}
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
// Simple variable
blocks.push({
type: 'variable',
contextName: block.replace(/[{}]/g, ''),
});
continue;
}
// Helpers
var helperSlices = Template7Utils.helperToSlices(block);
var helperName = helperSlices[0];
var isPartial = helperName === '>';
var helperContext = [];
var helperHash = {};
for (j = 1; j < helperSlices.length; j += 1) {
var slice = helperSlices[j];
if (Array.isArray(slice)) {
// Hash
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
} else {
helperContext.push(slice);
}
}
if (block.indexOf('{#') >= 0) {
// Condition/Helper
var helperContent = '';
var elseContent = '';
var toSkip = 0;
var shiftIndex = (void 0);
var foundClosed = false;
var foundElse = false;
var depth = 0;
for (j = i + 1; j < stringBlocks.length; j += 1) {
if (stringBlocks[j].indexOf('{{#') >= 0) {
depth += 1;
}
if (stringBlocks[j].indexOf('{{/') >= 0) {
depth -= 1;
}
if (stringBlocks[j].indexOf(("{{#" + helperName)) >= 0) {
helperContent += stringBlocks[j];
if (foundElse) { elseContent += stringBlocks[j]; }
toSkip += 1;
} else if (stringBlocks[j].indexOf(("{{/" + helperName)) >= 0) {
if (toSkip > 0) {
toSkip -= 1;
helperContent += stringBlocks[j];
if (foundElse) { elseContent += stringBlocks[j]; }
} else {
shiftIndex = j;
foundClosed = true;
break;
}
} else if (stringBlocks[j].indexOf('else') >= 0 && depth === 0) {
foundElse = true;
} else {
if (!foundElse) { helperContent += stringBlocks[j]; }
if (foundElse) { elseContent += stringBlocks[j]; }
}
}
if (foundClosed) {
if (shiftIndex) { i = shiftIndex; }
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
content: helperContent,
inverseContent: elseContent,
hash: helperHash,
});
}
} else if (block.indexOf(' ') > 0) {
if (isPartial) {
helperName = '_partial';
if (helperContext[0]) { helperContext[0] = "\"" + (helperContext[0].replace(/"|'/g, '')) + "\""; }
}
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
hash: helperHash,
});
}
}
}
return blocks;
},
parseJsVariable: function parseJsVariable(expression, replace, object) {
return expression.split(/([+ -*/^])/g).map(function (part) {
if (part.indexOf(replace) < 0) { return part; }
if (!object) { return JSON.stringify(''); }
var variable = object;
if (part.indexOf((replace + ".")) >= 0) {
part.split((replace + "."))[1].split('.').forEach(function (partName) {
if (variable[partName]) { variable = variable[partName]; }
else { variable = 'undefined'; }
});
}
return JSON.stringify(variable);
}).join('');
},
parseJsParents: function parseJsParents(expression, parents) {
return expression.split(/([+ -*^])/g).map(function (part) {
if (part.indexOf('../') < 0) { return part; }
if (!parents || parents.length === 0) { return JSON.stringify(''); }
var levelsUp = part.split('../').length - 1;
var parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1];
var variable = parentData;
var parentPart = part.replace(/..\//g, '');
parentPart.split('.').forEach(function (partName) {
if (variable[partName]) { variable = variable[partName]; }
else { variable = 'undefined'; }
});
return JSON.stringify(variable);
}).join('');
},
getCompileVar: function getCompileVar(name, ctx, data) {
if ( data === void 0 ) data = 'data_1';
var variable = ctx;
var parts;
var levelsUp = 0;
var newDepth;
if (name.indexOf('../') === 0) {
levelsUp = name.split('../').length - 1;
newDepth = variable.split('_')[1] - levelsUp;
variable = "ctx_" + (newDepth >= 1 ? newDepth : 1);
parts = name.split('../')[levelsUp].split('.');
} else if (name.indexOf('@global') === 0) {
variable = 'Template7.global';
parts = name.split('@global.')[1].split('.');
} else if (name.indexOf('@root') === 0) {
variable = 'root';
parts = name.split('@root.')[1].split('.');
} else {
parts = name.split('.');
}
for (var i = 0; i < parts.length; i += 1) {
var part = parts[i];
if (part.indexOf('@') === 0) {
var dataLevel = data.split('_')[1];
if (levelsUp > 0) {
dataLevel = newDepth;
}
if (i > 0) {
variable += "[(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")]";
} else {
variable = "(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")";
}
} else if (isFinite(part)) {
variable += "[" + part + "]";
} else if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) {
variable = part.replace('this', ctx);
} else {
variable += "." + part;
}
}
return variable;
},
getCompiledArguments: function getCompiledArguments(contextArray, ctx, data) {
var arr = [];
for (var i = 0; i < contextArray.length; i += 1) {
if (/^['"]/.test(contextArray[i])) { arr.push(contextArray[i]); }
else if (/^(true|false|\d+)$/.test(contextArray[i])) { arr.push(contextArray[i]); }
else {
arr.push(Template7Utils.getCompileVar(contextArray[i], ctx, data));
}
}
return arr.join(', ');
},
};
var Template7Helpers = {
_partial: function _partial(partialName, options) {
var p = Template7Class.partials[partialName];
if (!p || (p && !p.template)) { return ''; }
if (!p.compiled) {
p.compiled = new Template7Class(p.template).compile();
}
var ctx = this;
for (var hashName in options.hash) {
ctx[hashName] = options.hash[hashName];
}
return p.compiled(ctx, options.data, options.root);
},
escape: function escape(context) {
if (typeof context !== 'string') {
throw new Error('Template7: Passed context to "escape" helper should be a string');
}
return Template7Utils.escape(context);
},
if: function if$1(context, options) {
var ctx = context;
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); }
if (ctx) {
return options.fn(this, options.data);
}
return options.inverse(this, options.data);
},
unless: function unless(context, options) {
var ctx = context;
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); }
if (!ctx) {
return options.fn(this, options.data);
}
return options.inverse(this, options.data);
},
each: function each(context, options) {
var ctx = context;
var ret = '';
var i = 0;
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); }
if (Array.isArray(ctx)) {
if (options.hash.reverse) {
ctx = ctx.reverse();
}
for (i = 0; i < ctx.length; i += 1) {
ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i });
}
if (options.hash.reverse) {
ctx = ctx.reverse();
}
} else {
for (var key in ctx) {
i += 1;
ret += options.fn(ctx[key], { key: key });
}
}
if (i > 0) { return ret; }
return options.inverse(this);
},
with: function with$1(context, options) {
var ctx = context;
if (Template7Utils.isFunction(ctx)) { ctx = context.call(this); }
return options.fn(ctx);
},
join: function join(context, options) {
var ctx = context;
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); }
return ctx.join(options.hash.delimiter || options.hash.delimeter);
},
js: function js(expression, options) {
var data = options.data;
var func;
var execute = expression;
('index first last key').split(' ').forEach(function (prop) {
if (typeof data[prop] !== 'undefined') {
var re1 = new RegExp(("this.@" + prop), 'g');
var re2 = new RegExp(("@" + prop), 'g');
execute = execute
.replace(re1, JSON.stringify(data[prop]))
.replace(re2, JSON.stringify(data[prop]));
}
});
if (options.root && execute.indexOf('@root') >= 0) {
execute = Template7Utils.parseJsVariable(execute, '@root', options.root);
}
if (execute.indexOf('@global') >= 0) {
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global);
}
if (execute.indexOf('../') >= 0) {
execute = Template7Utils.parseJsParents(execute, options.parents);
}
if (execute.indexOf('return') >= 0) {
func = "(function(){" + execute + "})";
} else {
func = "(function(){return (" + execute + ")})";
}
return eval.call(this, func).call(this);
},
js_if: function js_if(expression, options) {
var data = options.data;
var func;
var execute = expression;
('index first last key').split(' ').forEach(function (prop) {
if (typeof data[prop] !== 'undefined') {
var re1 = new RegExp(("this.@" + prop), 'g');
var re2 = new RegExp(("@" + prop), 'g');
execute = execute
.replace(re1, JSON.stringify(data[prop]))
.replace(re2, JSON.stringify(data[prop]));
}
});
if (options.root && execute.indexOf('@root') >= 0) {
execute = Template7Utils.parseJsVariable(execute, '@root', options.root);
}
if (execute.indexOf('@global') >= 0) {
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Class.global);
}
if (execute.indexOf('../') >= 0) {
execute = Template7Utils.parseJsParents(execute, options.parents);
}
if (execute.indexOf('return') >= 0) {
func = "(function(){" + execute + "})";
} else {
func = "(function(){return (" + execute + ")})";
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
return options.inverse(this, options.data);
},
};
Template7Helpers.js_compare = Template7Helpers.js_if;
var Template7Options = {};
var Template7Partials = {};
var script = Template7Context.document.createElement('script');
Template7Context.document.head.appendChild(script);
var Template7Class = function Template7Class(template) {
var t = this;
t.template = template;
};
var staticAccessors = { options: {},partials: {},helpers: {} };
Template7Class.prototype.compile = function compile (template, depth) {
if ( template === void 0 ) template = this.template;
if ( depth === void 0 ) depth = 1;
var t = this;
if (t.compiled) { return t.compiled; }
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
var stringToBlocks = Template7Utils.stringToBlocks;
var getCompileVar = Template7Utils.getCompileVar;
var getCompiledArguments = Template7Utils.getCompiledArguments;
var blocks = stringToBlocks(template);
var ctx = "ctx_" + depth;
var data = "data_" + depth;
if (blocks.length === 0) {
return function empty() { return ''; };
}
function getCompileFn(block, newDepth) {
if (block.content) { return t.compile(block.content, newDepth); }
return function empty() { return ''; };
}
function getCompileInverse(block, newDepth) {
if (block.inverseContent) { return t.compile(block.inverseContent, newDepth); }
return function empty() { return ''; };
}
var resultString = '';
if (depth === 1) {
resultString += "(function (" + ctx + ", " + data + ", root) {\n";
} else {
resultString += "(function (" + ctx + ", " + data + ") {\n";
}
if (depth === 1) {
resultString += 'function isArray(arr){return Array.isArray(arr);}\n';
resultString += 'function isFunction(func){return (typeof func === \'function\');}\n';
resultString += 'function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n';
resultString += 'root = root || ctx_1 || {};\n';
}
resultString += 'var r = \'\';\n';
var i;
for (i = 0; i < blocks.length; i += 1) {
var block = blocks[i];
// Plain block
if (block.type === 'plain') {
resultString += "r +='" + ((block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')) + "';";
continue;
}
var variable = (void 0);
var compiledArguments = (void 0);
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx, data);
resultString += "r += c(" + variable + ", " + ctx + ");";
}
// Helpers block
if (block.type === 'helper') {
var parents = (void 0);
if (ctx !== 'ctx_1') {
var level = ctx.split('_')[1];
var parentsString = "ctx_" + (level - 1);
for (var j = level - 2; j >= 1; j -= 1) {
parentsString += ", ctx_" + j;
}
parents = "[" + parentsString + "]";
} else {
parents = "[" + ctx + "]";
}
if (block.helperName in Template7Helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx, data);
resultString += "r += (Template7.helpers." + (block.helperName) + ").call(" + ctx + ", " + (compiledArguments && ((compiledArguments + ", "))) + "{hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});";
} else if (block.contextName.length > 0) {
throw new Error(("Template7: Missing helper: \"" + (block.helperName) + "\""));
} else {
variable = getCompileVar(block.helperName, ctx, data);
resultString += "if (" + variable + ") {";
resultString += "if (isArray(" + variable + ")) {";
resultString += "r += (Template7.helpers.each).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});";
resultString += '}else {';
resultString += "r += (Template7.helpers.with).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});";
resultString += '}}';
}
}
}
resultString += '\nreturn r;})';
if (depth === 1) {
t.compiled = eval.call(Template7Context, resultString);
return t.compiled;
}
return resultString;
};
staticAccessors.options.get = function () {
return Template7Options;
};
staticAccessors.partials.get = function () {
return Template7Partials;
};
staticAccessors.helpers.get = function () {
return Template7Helpers;
};
Object.defineProperties( Template7Class, staticAccessors );
function Template7() {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var template = args[0];
var data = args[1];
if (args.length === 2) {
var instance = new Template7Class(template);
var rendered = instance.compile()(data);
instance = null;
return (rendered);
}
return new Template7Class(template);
}
Template7.registerHelper = function registerHelper(name, fn) {
Template7Class.helpers[name] = fn;
};
Template7.unregisterHelper = function unregisterHelper(name) {
Template7Class.helpers[name] = undefined;
delete Template7Class.helpers[name];
};
Template7.registerPartial = function registerPartial(name, template) {
Template7Class.partials[name] = { template: template };
};
Template7.unregisterPartial = function unregisterPartial(name) {
if (Template7Class.partials[name]) {
Template7Class.partials[name] = undefined;
delete Template7Class.partials[name];
}
};
Template7.compile = function compile(template, options) {
var instance = new Template7Class(template, options);
return instance.compile();
};
Template7.options = Template7Class.options;
Template7.helpers = Template7Class.helpers;
Template7.partials = Template7Class.partials;
/**
* Dom7 2.0.0
* Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API
* http://framework7.io/docs/dom.html
*
* Copyright 2017, Vladimir Kharlampidi
* The iDangero.us
* http://www.idangero.us/
*
* Licensed under MIT
*
* Released on: September 11, 2017
*/
var Dom7 = function Dom7(arr) {
var self = this;
// Create array-like object
for (var i = 0; i < arr.length; i += 1) {
self[i] = arr[i];
}
self.length = arr.length;
// Return collection with methods
return this;
};
function $$1$1(selector, context) {
var arr = [];
var i = 0;
if (selector && !context) {
if (selector instanceof Dom7) {
return selector;
}
}
if (selector) {
// String
if (typeof selector === 'string') {
var els;
var tempParent;
var 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 += 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);
}
$$1$1.fn = Dom7.prototype;
$$1$1.Class = Dom7;
$$1$1.use = function use() {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
args.forEach(function (methods) {
var isUtils = '__utils' in methods;
Object.keys(methods).forEach(function (methodName) {
if (methodName === '__utils') { return; }
if (isUtils) {
$$1$1[methodName] = methods[methodName];
} else {
$$1$1.fn[methodName] = methods[methodName];
}
});
});
};
function unique(arr) {
var uniqueArray = [];
for (var 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, function (match, group1) { return 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);
}
var Methods = {
// Classes and attributes
addClass: function addClass(className) {
var this$1 = this;
if (typeof className === 'undefined') {
return this;
}
var classes = className.split(' ');
for (var i = 0; i < classes.length; i += 1) {
for (var j = 0; j < this.length; j += 1) {
if (typeof this$1[j].classList !== 'undefined') { this$1[j].classList.add(classes[i]); }
}
}
return this;
},
removeClass: function removeClass(className) {
var this$1 = this;
var classes = className.split(' ');
for (var i = 0; i < classes.length; i += 1) {
for (var j = 0; j < this.length; j += 1) {
if (typeof this$1[j].classList !== 'undefined') { this$1[j].classList.remove(classes[i]); }
}
}
return this;
},
hasClass: function hasClass(className) {
if (!this[0]) { return false; }
return this[0].classList.contains(className);
},
toggleClass: function toggleClass(className) {
var this$1 = this;
var classes = className.split(' ');
for (var i = 0; i < classes.length; i += 1) {
for (var j = 0; j < this.length; j += 1) {
if (typeof this$1[j].classList !== 'undefined') { this$1[j].classList.toggle(classes[i]); }
}
}
return this;
},
attr: function attr(attrs, value) {
var arguments$1 = arguments;
var this$1 = this;
if (arguments.length === 1 && typeof attrs === 'string') {
// Get attr
if (this[0]) { return this[0].getAttribute(attrs); }
return undefined;
}
// Set attrs
for (var i = 0; i < this.length; i += 1) {
if (arguments$1.length === 2) {
// String
this$1[i].setAttribute(attrs, value);
} else {
// Object
for (var attrName in attrs) {
this$1[i][attrName] = attrs[attrName];
this$1[i].setAttribute(attrName, attrs[attrName]);
}
}
}
return this;
},
removeAttr: function removeAttr(attr) {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
this$1[i].removeAttribute(attr);
}
return this;
},
prop: function prop(props, value) {
var arguments$1 = arguments;
var this$1 = this;
if (arguments.length === 1 && typeof props === 'string') {
// Get prop
if (this[0]) { return this[0][props]; }
} else {
// Set props
for (var i = 0; i < this.length; i += 1) {
if (arguments$1.length === 2) {
// String
this$1[i][props] = value;
} else {
// Object
for (var propName in props) {
this$1[i][propName] = props[propName];
}
}
}
return this;
}
},
data: function data(key, value) {
var this$1 = this;
var el;
if (typeof value === 'undefined') {
el = this[0];
// Get value
if (el) {
if (el.dom7ElementDataStorage && (key in el.dom7ElementDataStorage)) {
return el.dom7ElementDataStorage[key];
}
var dataKey = el.getAttribute(("data-" + key));
if (dataKey) {
return dataKey;
}
return undefined;
}
return undefined;
}
// Set value
for (var i = 0; i < this.length; i += 1) {
el = this$1[i];
if (!el.dom7ElementDataStorage) { el.dom7ElementDataStorage = {}; }
el.dom7ElementDataStorage[key] = value;
}
return this;
},
removeData: function removeData(key) {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
var el = this$1[i];
if (el.dom7ElementDataStorage && el.dom7ElementDataStorage[key]) {
el.dom7ElementDataStorage[key] = null;
delete el.dom7ElementDataStorage[key];
}
}
},
dataset: function dataset() {
var el = this[0];
if (!el) { return undefined; }
var dataset = {};
if (el.dataset) {
for (var dataKey in el.dataset) {
dataset[dataKey] = el.dataset[dataKey];
}
} else {
for (var i = 0; i < el.attributes.length; i += 1) {
var attr = el.attributes[i];
if (attr.name.indexOf('data-') >= 0) {
dataset[toCamelCase(attr.name.split('data-')[1])] = attr.value;
}
}
}
for (var 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;
},
val: function val(value) {
var this$1 = this;
if (typeof value === 'undefined') {
if (this[0]) {
if (this[0].multiple && this[0].nodeName.toLowerCase() === 'select') {
var values = [];
for (var i = 0; i < this[0].selectedOptions.length; i += 1) {
values.push(this$1[0].selectedOptions[i].value);
}
return values;
}
return this[0].value;
}
return undefined;
}
for (var i$1 = 0; i$1 < this.length; i$1 += 1) {
this$1[i$1].value = value;
}
return this;
},
// Transforms
transform: function transform(transform$1) {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
var elStyle = this$1[i].style;
elStyle.webkitTransform = transform$1;
elStyle.transform = transform$1;
}
return this;
},
transition: function transition(duration) {
var this$1 = this;
if (typeof duration !== 'string') {
duration = duration + "ms";
}
for (var i = 0; i < this.length; i += 1) {
var elStyle = this$1[i].style;
elStyle.webkitTransitionDuration = duration;
elStyle.transitionDuration = duration;
}
return this;
},
// Events
on: function on() {
var this$1 = this;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var eventType = args[0];
var targetSelector;
var listener;
var capture = false;
if (typeof args[1] === 'function') {
targetSelector = false;
listener = args[1];
capture = args[2];
} else {
targetSelector = args[1];
listener = args[2];
capture = args[3];
}
function handleLiveEvent(e) {
var target = e.target;
if (!target) { return; }
var eventData = e.target.dom7EventData || [];
eventData.unshift(e);
if ($$1$1(target).is(targetSelector)) { listener.apply(target, eventData); }
else {
var parents = $$1$1(target).parents();
for (var k = 0; k < parents.length; k += 1) {
if ($$1$1(parents[k]).is(targetSelector)) { listener.apply(parents[k], eventData); }
}
}
}
function handleEvent(e) {
var eventData = e && e.target ? e.target.dom7EventData || [] : [];
eventData.unshift(e);
listener.apply(this, eventData);
}
var events = eventType.split(' ');
var j;
for (var i = 0; i < this.length; i += 1) {
var el = this$1[i];
if (!targetSelector) {
for (j = 0; j < events.length; j += 1) {
if (!el.dom7Listeners) { el.dom7Listeners = []; }
el.dom7Listeners.push({
type: eventType,
listener: listener,
proxyListener: handleEvent,
});
el.addEventListener(events[j], handleEvent, capture);
}
} else {
// Live events
for (j = 0; j < events.length; j += 1) {
if (!el.dom7LiveListeners) { el.dom7LiveListeners = []; }
el.dom7LiveListeners.push({
type: eventType,
listener: listener,
proxyListener: handleLiveEvent,
});
el.addEventListener(events[j], handleLiveEvent, capture);
}
}
}
return this;
},
off: function off() {
var this$1 = this;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var eventType = args[0];
var targetSelector;
var listener;
var capture = false;
if (typeof args[1] === 'function') {
targetSelector = false;
listener = args[1];
capture = args[2];
} else {
targetSelector = args[1];
listener = args[2];
capture = args[3];
}
var events = eventType.split(' ');
for (var i = 0; i < events.length; i += 1) {
for (var j = 0; j < this.length; j += 1) {
var el = this$1[j];
if (!targetSelector) {
if (el.dom7Listeners) {
for (var k = 0; k < el.dom7Listeners.length; k += 1) {
if (listener) {
if (el.dom7Listeners[k].listener === listener) {
el.removeEventListener(events[i], el.dom7Listeners[k].proxyListener, capture);
}
} else if (el.dom7Listeners[k].type === events[i]) {
el.removeEventListener(events[i], el.dom7Listeners[k].proxyListener, capture);
}
}
}
} else if (el.dom7LiveListeners) {
for (var k$1 = 0; k$1 < el.dom7LiveListeners.length; k$1 += 1) {
if (listener) {
if (el.dom7LiveListeners[k$1].listener === listener) {
el.removeEventListener(events[i], el.dom7LiveListeners[k$1].proxyListener, capture);
}
} else if (el.dom7LiveListeners[k$1].type === events[i]) {
el.removeEventListener(events[i], el.dom7LiveListeners[k$1].proxyListener, capture);
}
}
}
}
}
return this;
},
once: function once(eventName, targetSelector, listener, capture) {
var dom = this;
if (typeof targetSelector === 'function') {
listener = arguments[1];
capture = arguments[2];
targetSelector = false;
}
function proxy(e) {
var eventData = e.target.dom7EventData || [];
listener.apply(this, eventData);
dom.off(eventName, targetSelector, proxy, capture);
}
return dom.on(eventName, targetSelector, proxy, capture);
},
trigger: function trigger() {
var this$1 = this;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var events = args[0].split(' ');
var eventData = args[1];
for (var i = 0; i < events.length; i += 1) {
for (var j = 0; j < this.length; j += 1) {
var evt = (void 0);
try {
evt = new window.CustomEvent(events[i], { detail: eventData, bubbles: true, cancelable: true });
} catch (e) {
evt = document.createEvent('Event');
evt.initEvent(events[i], true, true);
evt.detail = eventData;
}
this$1[j].dom7EventData = args.filter(function (data, dataIndex) { return dataIndex > 0; });
this$1[j].dispatchEvent(evt);
this$1[j].dom7EventData = [];
delete this$1[j].dom7EventData;
}
}
return this;
},
transitionEnd: function transitionEnd(callback) {
var events = ['webkitTransitionEnd', 'transitionend'];
var dom = this;
var 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;
},
animationEnd: function animationEnd(callback) {
var events = ['webkitAnimationEnd', 'animationend'];
var dom = this;
var 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
width: function width() {
if (this[0] === window) {
return window.innerWidth;
}
if (this.length > 0) {
return parseFloat(this.css('width'));
}
return null;
},
outerWidth: function outerWidth(includeMargins) {
if (this.length > 0) {
if (includeMargins) {
var styles = this.styles();
return this[0].offsetWidth + parseFloat(styles.getPropertyValue('margin-right')) + parseFloat(styles.getPropertyValue('margin-left'));
}
return this[0].offsetWidth;
}
return null;
},
height: function height() {
if (this[0] === window) {
return window.innerHeight;
}
if (this.length > 0) {
return parseFloat(this.css('height'));
}
return null;
},
outerHeight: function outerHeight(includeMargins) {
if (this.length > 0) {
if (includeMargins) {
var styles = this.styles();
return this[0].offsetHeight + parseFloat(styles.getPropertyValue('margin-top')) + parseFloat(styles.getPropertyValue('margin-bottom'));
}
return this[0].offsetHeight;
}
return null;
},
offset: function offset() {
if (this.length > 0) {
var el = this[0];
var box = el.getBoundingClientRect();
var body = document.body;
var clientTop = el.clientTop || body.clientTop || 0;
var clientLeft = el.clientLeft || body.clientLeft || 0;
var scrollTop = el === window ? window.scrollY : el.scrollTop;
var scrollLeft = el === window ? window.scrollX : el.scrollLeft;
return {
top: (box.top + scrollTop) - clientTop,
left: (box.left + scrollLeft) - clientLeft,
};
}
return null;
},
hide: function hide() {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
this$1[i].style.display = 'none';
}
return this;
},
show: function show() {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
var el = this$1[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;
},
styles: function styles() {
if (this[0]) { return window.getComputedStyle(this[0], null); }
return {};
},
css: function css(props, value) {
var this$1 = this;
var 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) {
for (var prop in props) {
this$1[i].style[prop] = props[prop];
}
}
return this;
}
}
if (arguments.length === 2 && typeof props === 'string') {
for (i = 0; i < this.length; i += 1) {
this$1[i].style[props] = value;
}
return this;
}
return this;
},
// Dom manipulation
toArray: function toArray() {
var this$1 = this;
var arr = [];
for (var i = 0; i < this.length; i += 1) {
arr.push(this$1[i]);
}
return arr;
},
// Iterate over the collection passing elements to `callback`
each: function each(callback) {
var this$1 = this;
// Don't bother continuing without a callback
if (!callback) { return this; }
// Iterate over the current collection
for (var i = 0; i < this.length; i += 1) {
// If the callback returns false
if (callback.call(this$1[i], i, this$1[i]) === false) {
// End the loop early
return this$1;
}
}
// Return `this` to allow chained DOM operations
return this;
},
forEach: function forEach(callback) {
var this$1 = this;
// Don't bother continuing without a callback
if (!callback) { return this; }
// Iterate over the current collection
for (var i = 0; i < this.length; i += 1) {
// If the callback returns false
if (callback.call(this$1[i], this$1[i], i) === false) {
// End the loop early
return this$1;
}
}
// Return `this` to allow chained DOM operations
return this;
},
filter: function filter(callback) {
var matchedItems = [];
var dom = this;
for (var i = 0; i < dom.length; i += 1) {
if (callback.call(dom[i], i, dom[i])) { matchedItems.push(dom[i]); }
}
return new Dom7(matchedItems);
},
map: function map(callback) {
var modifiedItems = [];
var dom = this;
for (var i = 0; i < dom.length; i += 1) {
modifiedItems.push(callback.call(dom[i], i, dom[i]));
}
return new Dom7(modifiedItems);
},
html: function html(html$1) {
var this$1 = this;
if (typeof html$1 === 'undefined') {
return this[0] ? this[0].innerHTML : undefined;
}
for (var i = 0; i < this.length; i += 1) {
this$1[i].innerHTML = html$1;
}
return this;
},
text: function text(text$1) {
var this$1 = this;
if (typeof text$1 === 'undefined') {
if (this[0]) {
return this[0].textContent.trim();
}
return null;
}
for (var i = 0; i < this.length; i += 1) {
this$1[i].textContent = text$1;
}
return this;
},
is: function is(selector) {
var el = this[0];
var compareWith;
var 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 = $$1$1(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;
},
indexOf: function indexOf(el) {
var this$1 = this;
for (var i = 0; i < this.length; i += 1) {
if (this$1[i] === el) { return i; }
}
},
index: function index() {
var child = this[0];
var i;
if (child) {
i = 0;
while ((child = child.previousSibling) !== null) {
if (child.nodeType === 1) { i += 1; }
}
return i;
}
},
eq: function eq(index) {
if (typeof index === 'undefined') { return this; }
var length = this.length;
var 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]]);
},
append: function append() {
var this$1 = this;
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var newChild;
for (var k = 0; k < args.length; k += 1) {
newChild = args[k];
for (var i = 0; i < this.length; i += 1) {
if (typeof newChild === 'string') {
var tempDiv = document.createElement('div');
tempDiv.innerHTML = newChild;
while (tempDiv.firstChild) {
this$1[i].appendChild(tempDiv.firstChild);
}
} else if (newChild instanceof Dom7) {
for (var j = 0; j < newChild.length; j += 1) {
this$1[i].appendChild(newChild[j]);
}
} else {
this$1[i].appendChild(newChild);
}
}
}
return this;
},
appendTo: function appendTo(parent) {
$$1$1(parent).append(this);
return this;
},
prepend: function prepend(newChild) {
var this$1 = this;
var i;
var j;
for (i = 0; i < this.length; i += 1) {
if (typeof newChild === 'string') {
var tempDiv = document.createElement('div');
tempDiv.innerHTML = newChild;
for (j = tempDiv.childNodes.length - 1; j >= 0; j -= 1) {
this$1[i].insertBefore(tempDiv.childNodes[j], this$1[i].childNodes[0]);
}
} else if (newChild instanceof Dom7) {
for (j = 0; j < newChild.length; j += 1) {
this$1[i].insertBefore(newChild[j], this$1[i].childNodes[0]);
}
} else {
this$1[i].insertBefore(newChild, this$1[i].childNodes[0]);
}
}
return this;
},
prependTo: function prependTo(parent) {
$$1$1(parent).prepend(this);
return this;
},
insertBefore: function insertBefore(selector) {
var this$1 = this;
var before = $$1$1(selector);
for (var i = 0; i < this.length; i += 1) {
if (before.length === 1) {
before[0].parentNode.insertBefore(this$1[i], before[0]);
} else if (before.length > 1) {
for (var j = 0; j < before.length; j += 1) {
before[j].parentNode.insertBefore(this$1[i].cloneNode(true), before[j]);
}
}
}
},
insertAfter: function insertAfter(selector) {
var this$1 = this;
var after = $$1$1(selector);
for (var i = 0; i < this.length; i += 1) {
if (after.length === 1) {
after[0].parentNode.insertBefore(this$1[i], after[0].nextSibling);
} else if (after.length > 1) {
for (var j = 0; j < after.length; j += 1) {
after[j].parentNode.insertBefore(this$1[i].cloneNode(true), after[j].nextSibling);
}
}
}
},
next: function next(selector) {
if (this.length > 0) {
if (selector) {
if (this[0].nextElementSibling && $$1$1(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([]);
},
nextAll: function nextAll(selector) {
var nextEls = [];
var el = this[0];
if (!el) { return new Dom7([]); }
while (el.nextElementSibling) {
var next = el.nextElementSibling;
if (selector) {
if ($$1$1(next).is(selector)) { nextEls.push(next); }
} else { nextEls.push(next); }
el = next;
}
return new Dom7(nextEls);
},
prev: function prev(selector) {
if (this.length > 0) {
var el = this[0];
if (selector) {
if (el.previousElementSibling && $$1$1(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([]);
},
prevAll: function prevAll(selector) {
var prevEls = [];
var el = this[0];
if (!el) { return new Dom7([]); }
while (el.previousElementSibling) {
var prev = el.previousElementSibling;
if (selector) {
if ($$1$1(prev).is(selector)) { prevEls.push(prev); }
} else { prevEls.push(prev); }
el = prev;
}
return new Dom7(prevEls);
},
siblings: function siblings(selector) {
return this.nextAll(selector).add(this.prevAll(selector));
},
parent: function parent(selector) {
var this$1 = this;
var parents = [];
for (var i = 0; i < this.length; i += 1) {
if (this$1[i].parentNode !== null) {
if (selector) {
if ($$1$1(this$1[i].parentNode).is(selector)) { parents.push(this$1[i].parentNode); }
} else {
parents.push(this$1[i].parentNode);
}
}
}
return $$1$1(unique(parents));
},
parents: function parents(selector) {
var this$1 = this;
var parents = [];
for (var i = 0; i < this.length; i += 1) {
var parent = this$1[i].parentNode;
while (parent) {
if (selector) {
if ($$1$1(parent).is(selector)) { parents.push(parent); }
} else {
parents.push(parent);
}
parent = parent.parentNode;
}
}
return $$1$1(unique(parents));
},
closest: function closest(selector) {
var closest = this;
if (typeof selector === 'undefined') {
return new Dom7([]);
}
if (!closest.is(selector)) {
closest = closest.parents(selector).eq(0);
}
return closest;
},
find: function find(selector) {
var this$1 = this;
var foundElements = [];
for (var i = 0; i < this.length; i += 1) {
var found = this$1[i].querySelectorAll(selector);
for (var j = 0; j < found.length; j += 1) {
foundElements.push(found[j]);
}
}
return new Dom7(foundElements);
},
children: function children(selector) {
var this$1 = this;
var children = [];
for (var i = 0; i < this.length; i += 1)