]>
Commit | Line | Data |
---|---|---|
5309fbda | 1 | /** |
5d51ea26 | 2 | * Framework7 4.4.7 |
5309fbda DC |
3 | * Full featured mobile HTML framework for building iOS & Android apps |
4 | * http://framework7.io/ | |
5 | * | |
6 | * Copyright 2014-2019 Vladimir Kharlampidi | |
7 | * | |
8 | * Released under the MIT License | |
9 | * | |
5d51ea26 | 10 | * Released on: July 19, 2019 |
5309fbda DC |
11 | */ |
12 | ||
13 | (function (global, factory) { | |
14 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
15 | typeof define === 'function' && define.amd ? define(factory) : | |
16 | (global = global || self, global.Framework7 = factory()); | |
17 | }(this, function () { 'use strict'; | |
18 | ||
19 | /** | |
5d51ea26 | 20 | * Template7 1.4.2 |
5309fbda DC |
21 | * Mobile-first HTML template engine |
22 | * | |
23 | * http://www.idangero.us/template7/ | |
24 | * | |
25 | * Copyright 2019, Vladimir Kharlampidi | |
26 | * The iDangero.us | |
27 | * http://www.idangero.us/ | |
28 | * | |
29 | * Licensed under MIT | |
30 | * | |
5d51ea26 | 31 | * Released on: June 14, 2019 |
5309fbda DC |
32 | */ |
33 | ||
34 | var t7ctx; | |
35 | if (typeof window !== 'undefined') { | |
36 | t7ctx = window; | |
37 | } else if (typeof global !== 'undefined') { | |
38 | t7ctx = global; | |
39 | } else { | |
40 | t7ctx = undefined; | |
41 | } | |
42 | ||
43 | var Template7Context = t7ctx; | |
44 | ||
45 | var Template7Utils = { | |
46 | quoteSingleRexExp: new RegExp('\'', 'g'), | |
47 | quoteDoubleRexExp: new RegExp('"', 'g'), | |
48 | isFunction: function isFunction(func) { | |
49 | return typeof func === 'function'; | |
50 | }, | |
51 | escape: function escape(string) { | |
52 | if ( string === void 0 ) string = ''; | |
53 | ||
54 | return string | |
55 | .replace(/&/g, '&') | |
56 | .replace(/</g, '<') | |
57 | .replace(/>/g, '>') | |
58 | .replace(/"/g, '"') | |
59 | .replace(/'/g, '''); | |
60 | }, | |
61 | helperToSlices: function helperToSlices(string) { | |
62 | var quoteDoubleRexExp = Template7Utils.quoteDoubleRexExp; | |
63 | var quoteSingleRexExp = Template7Utils.quoteSingleRexExp; | |
64 | var helperParts = string.replace(/[{}#}]/g, '').trim().split(' '); | |
65 | var slices = []; | |
66 | var shiftIndex; | |
67 | var i; | |
68 | var j; | |
69 | for (i = 0; i < helperParts.length; i += 1) { | |
70 | var part = helperParts[i]; | |
71 | var blockQuoteRegExp = (void 0); | |
72 | var openingQuote = (void 0); | |
73 | if (i === 0) { slices.push(part); } | |
74 | else if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) { | |
75 | blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | |
76 | openingQuote = part.indexOf('"') === 0 ? '"' : '\''; | |
77 | // Plain String | |
78 | if (part.match(blockQuoteRegExp).length === 2) { | |
79 | // One word string | |
80 | slices.push(part); | |
81 | } else { | |
82 | // Find closed Index | |
83 | shiftIndex = 0; | |
84 | for (j = i + 1; j < helperParts.length; j += 1) { | |
85 | part += " " + (helperParts[j]); | |
86 | if (helperParts[j].indexOf(openingQuote) >= 0) { | |
87 | shiftIndex = j; | |
88 | slices.push(part); | |
89 | break; | |
90 | } | |
91 | } | |
92 | if (shiftIndex) { i = shiftIndex; } | |
93 | } | |
94 | } else if (part.indexOf('=') > 0) { | |
95 | // Hash | |
96 | var hashParts = part.split('='); | |
97 | var hashName = hashParts[0]; | |
98 | var hashContent = hashParts[1]; | |
99 | if (!blockQuoteRegExp) { | |
100 | blockQuoteRegExp = hashContent.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | |
101 | openingQuote = hashContent.indexOf('"') === 0 ? '"' : '\''; | |
102 | } | |
103 | if (hashContent.match(blockQuoteRegExp).length !== 2) { | |
104 | shiftIndex = 0; | |
105 | for (j = i + 1; j < helperParts.length; j += 1) { | |
106 | hashContent += " " + (helperParts[j]); | |
107 | if (helperParts[j].indexOf(openingQuote) >= 0) { | |
108 | shiftIndex = j; | |
109 | break; | |
110 | } | |
111 | } | |
112 | if (shiftIndex) { i = shiftIndex; } | |
113 | } | |
114 | var hash = [hashName, hashContent.replace(blockQuoteRegExp, '')]; | |
115 | slices.push(hash); | |
116 | } else { | |
117 | // Plain variable | |
118 | slices.push(part); | |
119 | } | |
120 | } | |
121 | return slices; | |
122 | }, | |
123 | stringToBlocks: function stringToBlocks(string) { | |
124 | var blocks = []; | |
125 | var i; | |
126 | var j; | |
127 | if (!string) { return []; } | |
128 | var stringBlocks = string.split(/({{[^{^}]*}})/); | |
129 | for (i = 0; i < stringBlocks.length; i += 1) { | |
130 | var block = stringBlocks[i]; | |
131 | if (block === '') { continue; } | |
132 | if (block.indexOf('{{') < 0) { | |
133 | blocks.push({ | |
134 | type: 'plain', | |
135 | content: block, | |
136 | }); | |
137 | } else { | |
138 | if (block.indexOf('{/') >= 0) { | |
139 | continue; | |
140 | } | |
141 | block = block | |
142 | .replace(/{{([#/])*([ ])*/, '{{$1') | |
143 | .replace(/([ ])*}}/, '}}'); | |
144 | if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) { | |
145 | // Simple variable | |
146 | blocks.push({ | |
147 | type: 'variable', | |
148 | contextName: block.replace(/[{}]/g, ''), | |
149 | }); | |
150 | continue; | |
151 | } | |
152 | // Helpers | |
153 | var helperSlices = Template7Utils.helperToSlices(block); | |
154 | var helperName = helperSlices[0]; | |
155 | var isPartial = helperName === '>'; | |
156 | var helperContext = []; | |
157 | var helperHash = {}; | |
158 | for (j = 1; j < helperSlices.length; j += 1) { | |
159 | var slice = helperSlices[j]; | |
160 | if (Array.isArray(slice)) { | |
161 | // Hash | |
162 | helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1]; | |
163 | } else { | |
164 | helperContext.push(slice); | |
165 | } | |
166 | } | |
167 | ||
168 | if (block.indexOf('{#') >= 0) { | |
169 | // Condition/Helper | |
170 | var helperContent = ''; | |
171 | var elseContent = ''; | |
172 | var toSkip = 0; | |
173 | var shiftIndex = (void 0); | |
174 | var foundClosed = false; | |
175 | var foundElse = false; | |
176 | var depth = 0; | |
177 | for (j = i + 1; j < stringBlocks.length; j += 1) { | |
178 | if (stringBlocks[j].indexOf('{{#') >= 0) { | |
179 | depth += 1; | |
180 | } | |
181 | if (stringBlocks[j].indexOf('{{/') >= 0) { | |
182 | depth -= 1; | |
183 | } | |
184 | if (stringBlocks[j].indexOf(("{{#" + helperName)) >= 0) { | |
185 | helperContent += stringBlocks[j]; | |
186 | if (foundElse) { elseContent += stringBlocks[j]; } | |
187 | toSkip += 1; | |
188 | } else if (stringBlocks[j].indexOf(("{{/" + helperName)) >= 0) { | |
189 | if (toSkip > 0) { | |
190 | toSkip -= 1; | |
191 | helperContent += stringBlocks[j]; | |
192 | if (foundElse) { elseContent += stringBlocks[j]; } | |
193 | } else { | |
194 | shiftIndex = j; | |
195 | foundClosed = true; | |
196 | break; | |
197 | } | |
198 | } else if (stringBlocks[j].indexOf('else') >= 0 && depth === 0) { | |
199 | foundElse = true; | |
200 | } else { | |
201 | if (!foundElse) { helperContent += stringBlocks[j]; } | |
202 | if (foundElse) { elseContent += stringBlocks[j]; } | |
203 | } | |
204 | } | |
205 | if (foundClosed) { | |
206 | if (shiftIndex) { i = shiftIndex; } | |
207 | if (helperName === 'raw') { | |
208 | blocks.push({ | |
209 | type: 'plain', | |
210 | content: helperContent, | |
211 | }); | |
212 | } else { | |
213 | blocks.push({ | |
214 | type: 'helper', | |
215 | helperName: helperName, | |
216 | contextName: helperContext, | |
217 | content: helperContent, | |
218 | inverseContent: elseContent, | |
219 | hash: helperHash, | |
220 | }); | |
221 | } | |
222 | } | |
223 | } else if (block.indexOf(' ') > 0) { | |
224 | if (isPartial) { | |
225 | helperName = '_partial'; | |
226 | if (helperContext[0]) { | |
227 | if (helperContext[0].indexOf('[') === 0) { helperContext[0] = helperContext[0].replace(/[[\]]/g, ''); } | |
228 | else { helperContext[0] = "\"" + (helperContext[0].replace(/"|'/g, '')) + "\""; } | |
229 | } | |
230 | } | |
231 | blocks.push({ | |
232 | type: 'helper', | |
233 | helperName: helperName, | |
234 | contextName: helperContext, | |
235 | hash: helperHash, | |
236 | }); | |
237 | } | |
238 | } | |
239 | } | |
240 | return blocks; | |
241 | }, | |
242 | parseJsVariable: function parseJsVariable(expression, replace, object) { | |
243 | return expression.split(/([+ \-*/^()&=|<>!%:?])/g).reduce(function (arr, part) { | |
244 | if (!part) { | |
245 | return arr; | |
246 | } | |
247 | if (part.indexOf(replace) < 0) { | |
248 | arr.push(part); | |
249 | return arr; | |
250 | } | |
251 | if (!object) { | |
252 | arr.push(JSON.stringify('')); | |
253 | return arr; | |
254 | } | |
255 | ||
256 | var variable = object; | |
257 | if (part.indexOf((replace + ".")) >= 0) { | |
258 | part.split((replace + "."))[1].split('.').forEach(function (partName) { | |
259 | if (partName in variable) { variable = variable[partName]; } | |
260 | else { variable = undefined; } | |
261 | }); | |
262 | } | |
5d51ea26 DC |
263 | if ( |
264 | (typeof variable === 'string') | |
265 | || Array.isArray(variable) | |
266 | || (variable.constructor && variable.constructor === Object) | |
267 | ) { | |
5309fbda DC |
268 | variable = JSON.stringify(variable); |
269 | } | |
270 | if (variable === undefined) { variable = 'undefined'; } | |
271 | ||
272 | arr.push(variable); | |
273 | return arr; | |
274 | }, []).join(''); | |
5d51ea26 | 275 | |
5309fbda DC |
276 | }, |
277 | parseJsParents: function parseJsParents(expression, parents) { | |
278 | return expression.split(/([+ \-*^()&=|<>!%:?])/g).reduce(function (arr, part) { | |
279 | if (!part) { | |
280 | return arr; | |
281 | } | |
282 | ||
283 | if (part.indexOf('../') < 0) { | |
284 | arr.push(part); | |
285 | return arr; | |
286 | } | |
287 | ||
288 | if (!parents || parents.length === 0) { | |
289 | arr.push(JSON.stringify('')); | |
290 | return arr; | |
291 | } | |
292 | ||
293 | var levelsUp = part.split('../').length - 1; | |
294 | var parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1]; | |
295 | ||
296 | var variable = parentData; | |
297 | var parentPart = part.replace(/..\//g, ''); | |
298 | parentPart.split('.').forEach(function (partName) { | |
299 | if (typeof variable[partName] !== 'undefined') { variable = variable[partName]; } | |
300 | else { variable = 'undefined'; } | |
301 | }); | |
302 | if (variable === false || variable === true) { | |
303 | arr.push(JSON.stringify(variable)); | |
304 | return arr; | |
305 | } | |
306 | if (variable === null || variable === 'undefined') { | |
307 | arr.push(JSON.stringify('')); | |
308 | return arr; | |
309 | } | |
310 | arr.push(JSON.stringify(variable)); | |
311 | return arr; | |
312 | }, []).join(''); | |
313 | }, | |
314 | getCompileVar: function getCompileVar(name, ctx, data) { | |
315 | if ( data === void 0 ) data = 'data_1'; | |
316 | ||
317 | var variable = ctx; | |
318 | var parts; | |
319 | var levelsUp = 0; | |
320 | var newDepth; | |
321 | if (name.indexOf('../') === 0) { | |
322 | levelsUp = name.split('../').length - 1; | |
323 | newDepth = variable.split('_')[1] - levelsUp; | |
324 | variable = "ctx_" + (newDepth >= 1 ? newDepth : 1); | |
325 | parts = name.split('../')[levelsUp].split('.'); | |
326 | } else if (name.indexOf('@global') === 0) { | |
327 | variable = 'Template7.global'; | |
328 | parts = name.split('@global.')[1].split('.'); | |
329 | } else if (name.indexOf('@root') === 0) { | |
330 | variable = 'root'; | |
331 | parts = name.split('@root.')[1].split('.'); | |
332 | } else { | |
333 | parts = name.split('.'); | |
334 | } | |
335 | for (var i = 0; i < parts.length; i += 1) { | |
336 | var part = parts[i]; | |
337 | if (part.indexOf('@') === 0) { | |
338 | var dataLevel = data.split('_')[1]; | |
339 | if (levelsUp > 0) { | |
340 | dataLevel = newDepth; | |
341 | } | |
342 | if (i > 0) { | |
343 | variable += "[(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")]"; | |
344 | } else { | |
345 | variable = "(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")"; | |
346 | } | |
347 | } else if (Number.isFinite ? Number.isFinite(part) : Template7Context.isFinite(part)) { | |
348 | variable += "[" + part + "]"; | |
349 | } else if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) { | |
350 | variable = part.replace('this', ctx); | |
351 | } else { | |
352 | variable += "." + part; | |
353 | } | |
354 | } | |
355 | return variable; | |
356 | }, | |
357 | getCompiledArguments: function getCompiledArguments(contextArray, ctx, data) { | |
358 | var arr = []; | |
359 | for (var i = 0; i < contextArray.length; i += 1) { | |
360 | if (/^['"]/.test(contextArray[i])) { arr.push(contextArray[i]); } | |
361 | else if (/^(true|false|\d+)$/.test(contextArray[i])) { arr.push(contextArray[i]); } | |
362 | else { | |
363 | arr.push(Template7Utils.getCompileVar(contextArray[i], ctx, data)); | |
364 | } | |
365 | } | |
366 | ||
367 | return arr.join(', '); | |
368 | }, | |
369 | }; | |
370 | ||
371 | /* eslint no-eval: "off" */ | |
372 | ||
373 | var Template7Helpers = { | |
374 | _partial: function _partial(partialName, options) { | |
375 | var ctx = this; | |
376 | var p = Template7Class.partials[partialName]; | |
377 | if (!p || (p && !p.template)) { return ''; } | |
378 | if (!p.compiled) { | |
379 | p.compiled = new Template7Class(p.template).compile(); | |
380 | } | |
381 | Object.keys(options.hash).forEach(function (hashName) { | |
382 | ctx[hashName] = options.hash[hashName]; | |
383 | }); | |
384 | return p.compiled(ctx, options.data, options.root); | |
385 | }, | |
386 | escape: function escape(context) { | |
5d51ea26 | 387 | if (typeof context === 'undefined' || context === null) { return ''; } |
5309fbda DC |
388 | if (typeof context !== 'string') { |
389 | throw new Error('Template7: Passed context to "escape" helper should be a string'); | |
390 | } | |
391 | return Template7Utils.escape(context); | |
392 | }, | |
393 | if: function if$1(context, options) { | |
394 | var ctx = context; | |
395 | if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | |
396 | if (ctx) { | |
397 | return options.fn(this, options.data); | |
398 | } | |
399 | ||
400 | return options.inverse(this, options.data); | |
401 | }, | |
402 | unless: function unless(context, options) { | |
403 | var ctx = context; | |
404 | if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | |
405 | if (!ctx) { | |
406 | return options.fn(this, options.data); | |
407 | } | |
408 | ||
409 | return options.inverse(this, options.data); | |
410 | }, | |
411 | each: function each(context, options) { | |
412 | var ctx = context; | |
413 | var ret = ''; | |
414 | var i = 0; | |
415 | if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | |
416 | if (Array.isArray(ctx)) { | |
417 | if (options.hash.reverse) { | |
418 | ctx = ctx.reverse(); | |
419 | } | |
420 | for (i = 0; i < ctx.length; i += 1) { | |
421 | ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i }); | |
422 | } | |
423 | if (options.hash.reverse) { | |
424 | ctx = ctx.reverse(); | |
425 | } | |
426 | } else { | |
427 | // eslint-disable-next-line | |
428 | for (var key in ctx) { | |
429 | i += 1; | |
430 | ret += options.fn(ctx[key], { key: key }); | |
431 | } | |
432 | } | |
433 | if (i > 0) { return ret; } | |
434 | return options.inverse(this); | |
435 | }, | |
436 | with: function with$1(context, options) { | |
437 | var ctx = context; | |
438 | if (Template7Utils.isFunction(ctx)) { ctx = context.call(this); } | |
439 | return options.fn(ctx); | |
440 | }, | |
441 | join: function join(context, options) { | |
442 | var ctx = context; | |
443 | if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | |
444 | return ctx.join(options.hash.delimiter || options.hash.delimeter); | |
445 | }, | |
446 | js: function js(expression, options) { | |
447 | var data = options.data; | |
448 | var func; | |
449 | var execute = expression; | |
450 | ('index first last key').split(' ').forEach(function (prop) { | |
451 | if (typeof data[prop] !== 'undefined') { | |
452 | var re1 = new RegExp(("this.@" + prop), 'g'); | |
453 | var re2 = new RegExp(("@" + prop), 'g'); | |
454 | execute = execute | |
455 | .replace(re1, JSON.stringify(data[prop])) | |
456 | .replace(re2, JSON.stringify(data[prop])); | |
457 | } | |
458 | }); | |
459 | if (options.root && execute.indexOf('@root') >= 0) { | |
460 | execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | |
461 | } | |
462 | if (execute.indexOf('@global') >= 0) { | |
463 | execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | |
464 | } | |
465 | if (execute.indexOf('../') >= 0) { | |
466 | execute = Template7Utils.parseJsParents(execute, options.parents); | |
467 | } | |
468 | if (execute.indexOf('return') >= 0) { | |
469 | func = "(function(){" + execute + "})"; | |
470 | } else { | |
471 | func = "(function(){return (" + execute + ")})"; | |
472 | } | |
473 | return eval(func).call(this); | |
474 | }, | |
475 | js_if: function js_if(expression, options) { | |
476 | var data = options.data; | |
477 | var func; | |
478 | var execute = expression; | |
479 | ('index first last key').split(' ').forEach(function (prop) { | |
480 | if (typeof data[prop] !== 'undefined') { | |
481 | var re1 = new RegExp(("this.@" + prop), 'g'); | |
482 | var re2 = new RegExp(("@" + prop), 'g'); | |
483 | execute = execute | |
484 | .replace(re1, JSON.stringify(data[prop])) | |
485 | .replace(re2, JSON.stringify(data[prop])); | |
486 | } | |
487 | }); | |
488 | if (options.root && execute.indexOf('@root') >= 0) { | |
489 | execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | |
490 | } | |
491 | if (execute.indexOf('@global') >= 0) { | |
492 | execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | |
493 | } | |
494 | if (execute.indexOf('../') >= 0) { | |
495 | execute = Template7Utils.parseJsParents(execute, options.parents); | |
496 | } | |
497 | if (execute.indexOf('return') >= 0) { | |
498 | func = "(function(){" + execute + "})"; | |
499 | } else { | |
500 | func = "(function(){return (" + execute + ")})"; | |
501 | } | |
502 | var condition = eval(func).call(this); | |
503 | if (condition) { | |
504 | return options.fn(this, options.data); | |
505 | } | |
506 | ||
507 | return options.inverse(this, options.data); | |
508 | }, | |
509 | }; | |
510 | Template7Helpers.js_compare = Template7Helpers.js_if; | |
511 | ||
512 | var Template7Options = {}; | |
513 | var Template7Partials = {}; | |
514 | ||
515 | var Template7Class = function Template7Class(template) { | |
516 | var t = this; | |
517 | t.template = template; | |
518 | }; | |
519 | ||
520 | var staticAccessors = { options: { configurable: true },partials: { configurable: true },helpers: { configurable: true } }; | |
521 | Template7Class.prototype.compile = function compile (template, depth) { | |
522 | if ( template === void 0 ) template = this.template; | |
523 | if ( depth === void 0 ) depth = 1; | |
524 | ||
525 | var t = this; | |
526 | if (t.compiled) { return t.compiled; } | |
527 | ||
528 | if (typeof template !== 'string') { | |
529 | throw new Error('Template7: Template must be a string'); | |
530 | } | |
531 | var stringToBlocks = Template7Utils.stringToBlocks; | |
532 | var getCompileVar = Template7Utils.getCompileVar; | |
533 | var getCompiledArguments = Template7Utils.getCompiledArguments; | |
534 | ||
535 | var blocks = stringToBlocks(template); | |
536 | var ctx = "ctx_" + depth; | |
537 | var data = "data_" + depth; | |
538 | if (blocks.length === 0) { | |
539 | return function empty() { return ''; }; | |
540 | } | |
541 | ||
542 | function getCompileFn(block, newDepth) { | |
543 | if (block.content) { return t.compile(block.content, newDepth); } | |
544 | return function empty() { return ''; }; | |
545 | } | |
546 | function getCompileInverse(block, newDepth) { | |
547 | if (block.inverseContent) { return t.compile(block.inverseContent, newDepth); } | |
548 | return function empty() { return ''; }; | |
549 | } | |
550 | ||
551 | var resultString = ''; | |
552 | if (depth === 1) { | |
553 | resultString += "(function (" + ctx + ", " + data + ", root) {\n"; | |
554 | } else { | |
555 | resultString += "(function (" + ctx + ", " + data + ") {\n"; | |
556 | } | |
557 | if (depth === 1) { | |
558 | resultString += 'function isArray(arr){return Array.isArray(arr);}\n'; | |
559 | resultString += 'function isFunction(func){return (typeof func === \'function\');}\n'; | |
560 | resultString += 'function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n'; | |
561 | resultString += 'root = root || ctx_1 || {};\n'; | |
562 | } | |
563 | resultString += 'var r = \'\';\n'; | |
564 | var i; | |
565 | for (i = 0; i < blocks.length; i += 1) { | |
566 | var block = blocks[i]; | |
567 | // Plain block | |
568 | if (block.type === 'plain') { | |
569 | // eslint-disable-next-line | |
570 | resultString += "r +='" + ((block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')) + "';"; | |
571 | continue; | |
572 | } | |
573 | var variable = (void 0); | |
574 | var compiledArguments = (void 0); | |
575 | // Variable block | |
576 | if (block.type === 'variable') { | |
577 | variable = getCompileVar(block.contextName, ctx, data); | |
578 | resultString += "r += c(" + variable + ", " + ctx + ");"; | |
579 | } | |
580 | // Helpers block | |
581 | if (block.type === 'helper') { | |
582 | var parents = (void 0); | |
583 | if (ctx !== 'ctx_1') { | |
584 | var level = ctx.split('_')[1]; | |
585 | var parentsString = "ctx_" + (level - 1); | |
586 | for (var j = level - 2; j >= 1; j -= 1) { | |
587 | parentsString += ", ctx_" + j; | |
588 | } | |
589 | parents = "[" + parentsString + "]"; | |
590 | } else { | |
591 | parents = "[" + ctx + "]"; | |
592 | } | |
593 | var dynamicHelper = (void 0); | |
594 | if (block.helperName.indexOf('[') === 0) { | |
595 | block.helperName = getCompileVar(block.helperName.replace(/[[\]]/g, ''), ctx, data); | |
596 | dynamicHelper = true; | |
597 | } | |
598 | if (dynamicHelper || block.helperName in Template7Helpers) { | |
599 | compiledArguments = getCompiledArguments(block.contextName, ctx, data); | |
600 | resultString += "r += (Template7Helpers" + (dynamicHelper ? ("[" + (block.helperName) + "]") : ("." + (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 + "});"; | |
601 | } else if (block.contextName.length > 0) { | |
602 | throw new Error(("Template7: Missing helper: \"" + (block.helperName) + "\"")); | |
603 | } else { | |
604 | variable = getCompileVar(block.helperName, ctx, data); | |
605 | resultString += "if (" + variable + ") {"; | |
606 | resultString += "if (isArray(" + variable + ")) {"; | |
607 | resultString += "r += (Template7Helpers.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 + "});"; | |
608 | resultString += '}else {'; | |
609 | resultString += "r += (Template7Helpers.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 + "});"; | |
610 | resultString += '}}'; | |
611 | } | |
612 | } | |
613 | } | |
614 | resultString += '\nreturn r;})'; | |
615 | ||
616 | if (depth === 1) { | |
617 | // eslint-disable-next-line | |
618 | t.compiled = eval(resultString); | |
619 | return t.compiled; | |
620 | } | |
621 | return resultString; | |
622 | }; | |
623 | staticAccessors.options.get = function () { | |
624 | return Template7Options; | |
625 | }; | |
626 | staticAccessors.partials.get = function () { | |
627 | return Template7Partials; | |
628 | }; | |
629 | staticAccessors.helpers.get = function () { | |
630 | return Template7Helpers; | |
631 | }; | |
632 | ||
633 | Object.defineProperties( Template7Class, staticAccessors ); | |
634 | ||
635 | function Template7() { | |
636 | var args = [], len = arguments.length; | |
637 | while ( len-- ) args[ len ] = arguments[ len ]; | |
638 | ||
639 | var template = args[0]; | |
640 | var data = args[1]; | |
641 | if (args.length === 2) { | |
642 | var instance = new Template7Class(template); | |
643 | var rendered = instance.compile()(data); | |
644 | instance = null; | |
645 | return (rendered); | |
646 | } | |
647 | return new Template7Class(template); | |
648 | } | |
649 | Template7.registerHelper = function registerHelper(name, fn) { | |
650 | Template7Class.helpers[name] = fn; | |
651 | }; | |
652 | Template7.unregisterHelper = function unregisterHelper(name) { | |
653 | Template7Class.helpers[name] = undefined; | |
654 | delete Template7Class.helpers[name]; | |
655 | }; | |
656 | Template7.registerPartial = function registerPartial(name, template) { | |
657 | Template7Class.partials[name] = { template: template }; | |
658 | }; | |
659 | Template7.unregisterPartial = function unregisterPartial(name) { | |
660 | if (Template7Class.partials[name]) { | |
661 | Template7Class.partials[name] = undefined; | |
662 | delete Template7Class.partials[name]; | |
663 | } | |
664 | }; | |
665 | Template7.compile = function compile(template, options) { | |
666 | var instance = new Template7Class(template, options); | |
667 | return instance.compile(); | |
668 | }; | |
669 | ||
670 | Template7.options = Template7Class.options; | |
671 | Template7.helpers = Template7Class.helpers; | |
672 | Template7.partials = Template7Class.partials; | |
673 | ||
674 | /** | |
675 | * SSR Window 1.0.1 | |
676 | * Better handling for window object in SSR environment | |
677 | * https://github.com/nolimits4web/ssr-window | |
678 | * | |
679 | * Copyright 2018, Vladimir Kharlampidi | |
680 | * | |
681 | * Licensed under MIT | |
682 | * | |
683 | * Released on: July 18, 2018 | |
684 | */ | |
685 | var doc = (typeof document === 'undefined') ? { | |
686 | body: {}, | |
687 | addEventListener: function addEventListener() {}, | |
688 | removeEventListener: function removeEventListener() {}, | |
689 | activeElement: { | |
690 | blur: function blur() {}, | |
691 | nodeName: '', | |
692 | }, | |
693 | querySelector: function querySelector() { | |
694 | return null; | |
695 | }, | |
696 | querySelectorAll: function querySelectorAll() { | |
697 | return []; | |
698 | }, | |
699 | getElementById: function getElementById() { | |
700 | return null; | |
701 | }, | |
702 | createEvent: function createEvent() { | |
703 | return { | |
704 | initEvent: function initEvent() {}, | |
705 | }; | |
706 | }, | |
707 | createElement: function createElement() { | |
708 | return { | |
709 | children: [], | |
710 | childNodes: [], | |
711 | style: {}, | |
712 | setAttribute: function setAttribute() {}, | |
713 | getElementsByTagName: function getElementsByTagName() { | |
714 | return []; | |
715 | }, | |
716 | }; | |
717 | }, | |
718 | location: { hash: '' }, | |
719 | } : document; // eslint-disable-line | |
720 | ||
721 | var win = (typeof window === 'undefined') ? { | |
722 | document: doc, | |
723 | navigator: { | |
724 | userAgent: '', | |
725 | }, | |
726 | location: {}, | |
727 | history: {}, | |
728 | CustomEvent: function CustomEvent() { | |
729 | return this; | |
730 | }, | |
731 | addEventListener: function addEventListener() {}, | |
732 | removeEventListener: function removeEventListener() {}, | |
733 | getComputedStyle: function getComputedStyle() { | |
734 | return { | |
735 | getPropertyValue: function getPropertyValue() { | |
736 | return ''; | |
737 | }, | |
738 | }; | |
739 | }, | |
740 | Image: function Image() {}, | |
741 | Date: function Date() {}, | |
742 | screen: {}, | |
743 | setTimeout: function setTimeout() {}, | |
744 | clearTimeout: function clearTimeout() {}, | |
745 | } : window; // eslint-disable-line | |
746 | ||
747 | /** | |
748 | * Dom7 2.1.3 | |
749 | * Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API | |
750 | * http://framework7.io/docs/dom.html | |
751 | * | |
752 | * Copyright 2019, Vladimir Kharlampidi | |
753 | * The iDangero.us | |
754 | * http://www.idangero.us/ | |
755 | * | |
756 | * Licensed under MIT | |
757 | * | |
758 | * Released on: February 11, 2019 | |
759 | */ | |
760 | ||
761 | var Dom7 = function Dom7(arr) { | |
762 | var self = this; | |
763 | // Create array-like object | |
764 | for (var i = 0; i < arr.length; i += 1) { | |
765 | self[i] = arr[i]; | |
766 | } | |
767 | self.length = arr.length; | |
768 | // Return collection with methods | |
769 | return this; | |
770 | }; | |
771 | ||
772 | function $(selector, context) { | |
773 | var arr = []; | |
774 | var i = 0; | |
775 | if (selector && !context) { | |
776 | if (selector instanceof Dom7) { | |
777 | return selector; | |
778 | } | |
779 | } | |
780 | if (selector) { | |
781 | // String | |
782 | if (typeof selector === 'string') { | |
783 | var els; | |
784 | var tempParent; | |
785 | var html = selector.trim(); | |
786 | if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) { | |
787 | var toCreate = 'div'; | |
788 | if (html.indexOf('<li') === 0) { toCreate = 'ul'; } | |
789 | if (html.indexOf('<tr') === 0) { toCreate = 'tbody'; } | |
790 | if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) { toCreate = 'tr'; } | |
791 | if (html.indexOf('<tbody') === 0) { toCreate = 'table'; } | |
792 | if (html.indexOf('<option') === 0) { toCreate = 'select'; } | |
793 | tempParent = doc.createElement(toCreate); | |
794 | tempParent.innerHTML = html; | |
795 | for (i = 0; i < tempParent.childNodes.length; i += 1) { | |
796 | arr.push(tempParent.childNodes[i]); | |
797 | } | |
798 | } else { | |
799 | if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) { | |
800 | // Pure ID selector | |
801 | els = [doc.getElementById(selector.trim().split('#')[1])]; | |
802 | } else { | |
803 | // Other selectors | |
804 | els = (context || doc).querySelectorAll(selector.trim()); | |
805 | } | |
806 | for (i = 0; i < els.length; i += 1) { | |
807 | if (els[i]) { arr.push(els[i]); } | |
808 | } | |
809 | } | |
810 | } else if (selector.nodeType || selector === win || selector === doc) { | |
811 | // Node/element | |
812 | arr.push(selector); | |
813 | } else if (selector.length > 0 && selector[0].nodeType) { | |
814 | // Array of elements or instance of Dom | |
815 | for (i = 0; i < selector.length; i += 1) { | |
816 | arr.push(selector[i]); | |
817 | } | |
818 | } | |
819 | } | |
820 | return new Dom7(arr); | |
821 | } | |
822 | ||
823 | $.fn = Dom7.prototype; | |
824 | $.Class = Dom7; | |
825 | $.Dom7 = Dom7; | |
826 | ||
827 | function unique(arr) { | |
828 | var uniqueArray = []; | |
829 | for (var i = 0; i < arr.length; i += 1) { | |
830 | if (uniqueArray.indexOf(arr[i]) === -1) { uniqueArray.push(arr[i]); } | |
831 | } | |
832 | return uniqueArray; | |
833 | } | |
834 | function toCamelCase(string) { | |
835 | return string.toLowerCase().replace(/-(.)/g, function (match, group1) { return group1.toUpperCase(); }); | |
836 | } | |
837 | ||
838 | function requestAnimationFrame(callback) { | |
839 | if (win.requestAnimationFrame) { return win.requestAnimationFrame(callback); } | |
840 | else if (win.webkitRequestAnimationFrame) { return win.webkitRequestAnimationFrame(callback); } | |
841 | return win.setTimeout(callback, 1000 / 60); | |
842 | } | |
843 | function cancelAnimationFrame(id) { | |
844 | if (win.cancelAnimationFrame) { return win.cancelAnimationFrame(id); } | |
845 | else if (win.webkitCancelAnimationFrame) { return win.webkitCancelAnimationFrame(id); } | |
846 | return win.clearTimeout(id); | |
847 | } | |
848 | ||
849 | // Classes and attributes | |
850 | function addClass(className) { | |
851 | if (typeof className === 'undefined') { | |
852 | return this; | |
853 | } | |
854 | var classes = className.split(' '); | |
855 | for (var i = 0; i < classes.length; i += 1) { | |
856 | for (var j = 0; j < this.length; j += 1) { | |
857 | if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') { this[j].classList.add(classes[i]); } | |
858 | } | |
859 | } | |
860 | return this; | |
861 | } | |
862 | function removeClass(className) { | |
863 | var classes = className.split(' '); | |
864 | for (var i = 0; i < classes.length; i += 1) { | |
865 | for (var j = 0; j < this.length; j += 1) { | |
866 | if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') { this[j].classList.remove(classes[i]); } | |
867 | } | |
868 | } | |
869 | return this; | |
870 | } | |
871 | function hasClass(className) { | |
872 | if (!this[0]) { return false; } | |
873 | return this[0].classList.contains(className); | |
874 | } | |
875 | function toggleClass(className) { | |
876 | var classes = className.split(' '); | |
877 | for (var i = 0; i < classes.length; i += 1) { | |
878 | for (var j = 0; j < this.length; j += 1) { | |
879 | if (typeof this[j] !== 'undefined' && typeof this[j].classList !== 'undefined') { this[j].classList.toggle(classes[i]); } | |
880 | } | |
881 | } | |
882 | return this; | |
883 | } | |
884 | function attr(attrs, value) { | |
885 | var arguments$1 = arguments; | |
886 | ||
887 | if (arguments.length === 1 && typeof attrs === 'string') { | |
888 | // Get attr | |
889 | if (this[0]) { return this[0].getAttribute(attrs); } | |
890 | return undefined; | |
891 | } | |
892 | ||
893 | // Set attrs | |
894 | for (var i = 0; i < this.length; i += 1) { | |
895 | if (arguments$1.length === 2) { | |
896 | // String | |
897 | this[i].setAttribute(attrs, value); | |
898 | } else { | |
899 | // Object | |
900 | // eslint-disable-next-line | |
901 | for (var attrName in attrs) { | |
902 | this[i][attrName] = attrs[attrName]; | |
903 | this[i].setAttribute(attrName, attrs[attrName]); | |
904 | } | |
905 | } | |
906 | } | |
907 | return this; | |
908 | } | |
909 | // eslint-disable-next-line | |
910 | function removeAttr(attr) { | |
911 | for (var i = 0; i < this.length; i += 1) { | |
912 | this[i].removeAttribute(attr); | |
913 | } | |
914 | return this; | |
915 | } | |
916 | // eslint-disable-next-line | |
917 | function prop(props, value) { | |
918 | var arguments$1 = arguments; | |
919 | ||
920 | if (arguments.length === 1 && typeof props === 'string') { | |
921 | // Get prop | |
922 | if (this[0]) { return this[0][props]; } | |
923 | } else { | |
924 | // Set props | |
925 | for (var i = 0; i < this.length; i += 1) { | |
926 | if (arguments$1.length === 2) { | |
927 | // String | |
928 | this[i][props] = value; | |
929 | } else { | |
930 | // Object | |
931 | // eslint-disable-next-line | |
932 | for (var propName in props) { | |
933 | this[i][propName] = props[propName]; | |
934 | } | |
935 | } | |
936 | } | |
937 | return this; | |
938 | } | |
939 | } | |
940 | function data(key, value) { | |
941 | var el; | |
942 | if (typeof value === 'undefined') { | |
943 | el = this[0]; | |
944 | // Get value | |
945 | if (el) { | |
946 | if (el.dom7ElementDataStorage && (key in el.dom7ElementDataStorage)) { | |
947 | return el.dom7ElementDataStorage[key]; | |
948 | } | |
949 | ||
950 | var dataKey = el.getAttribute(("data-" + key)); | |
951 | if (dataKey) { | |
952 | return dataKey; | |
953 | } | |
954 | return undefined; | |
955 | } | |
956 | return undefined; | |
957 | } | |
958 | ||
959 | // Set value | |
960 | for (var i = 0; i < this.length; i += 1) { | |
961 | el = this[i]; | |
962 | if (!el.dom7ElementDataStorage) { el.dom7ElementDataStorage = {}; } | |
963 | el.dom7ElementDataStorage[key] = value; | |
964 | } | |
965 | return this; | |
966 | } | |
967 | function removeData(key) { | |
968 | for (var i = 0; i < this.length; i += 1) { | |
969 | var el = this[i]; | |
970 | if (el.dom7ElementDataStorage && el.dom7ElementDataStorage[key]) { | |
971 | el.dom7ElementDataStorage[key] = null; | |
972 | delete el.dom7ElementDataStorage[key]; | |
973 | } | |
974 | } | |
975 | } | |
976 | function dataset() { | |
977 | var el = this[0]; | |
978 | if (!el) { return undefined; } | |
979 | var dataset = {}; // eslint-disable-line | |
980 | if (el.dataset) { | |
981 | // eslint-disable-next-line | |
982 | for (var dataKey in el.dataset) { | |
983 | dataset[dataKey] = el.dataset[dataKey]; | |
984 | } | |
985 | } else { | |
986 | for (var i = 0; i < el.attributes.length; i += 1) { | |
987 | // eslint-disable-next-line | |
988 | var attr = el.attributes[i]; | |
989 | if (attr.name.indexOf('data-') >= 0) { | |
990 | dataset[toCamelCase(attr.name.split('data-')[1])] = attr.value; | |
991 | } | |
992 | } | |
993 | } | |
994 | // eslint-disable-next-line | |
995 | for (var key in dataset) { | |
996 | if (dataset[key] === 'false') { dataset[key] = false; } | |
997 | else if (dataset[key] === 'true') { dataset[key] = true; } | |
998 | else if (parseFloat(dataset[key]) === dataset[key] * 1) { dataset[key] *= 1; } | |
999 | } | |
1000 | return dataset; | |
1001 | } | |
1002 | function val(value) { | |
1003 | var dom = this; | |
1004 | if (typeof value === 'undefined') { | |
1005 | if (dom[0]) { | |
1006 | if (dom[0].multiple && dom[0].nodeName.toLowerCase() === 'select') { | |
1007 | var values = []; | |
1008 | for (var i = 0; i < dom[0].selectedOptions.length; i += 1) { | |
1009 | values.push(dom[0].selectedOptions[i].value); | |
1010 | } | |
1011 | return values; | |
1012 | } | |
1013 | return dom[0].value; | |
1014 | } | |
1015 | return undefined; | |
1016 | } | |
1017 | ||
1018 | for (var i$1 = 0; i$1 < dom.length; i$1 += 1) { | |
1019 | var el = dom[i$1]; | |
1020 | if (Array.isArray(value) && el.multiple && el.nodeName.toLowerCase() === 'select') { | |
1021 | for (var j = 0; j < el.options.length; j += 1) { | |
1022 | el.options[j].selected = value.indexOf(el.options[j].value) >= 0; | |
1023 | } | |
1024 | } else { | |
1025 | el.value = value; | |
1026 | } | |
1027 | } | |
1028 | return dom; | |
1029 | } | |
1030 | // Transforms | |
1031 | // eslint-disable-next-line | |
1032 | function transform(transform) { | |
1033 | for (var i = 0; i < this.length; i += 1) { | |
1034 | var elStyle = this[i].style; | |
1035 | elStyle.webkitTransform = transform; | |
1036 | elStyle.transform = transform; | |
1037 | } | |
1038 | return this; | |
1039 | } | |
1040 | function transition(duration) { | |
1041 | if (typeof duration !== 'string') { | |
1042 | duration = duration + "ms"; // eslint-disable-line | |
1043 | } | |
1044 | for (var i = 0; i < this.length; i += 1) { | |
1045 | var elStyle = this[i].style; | |
1046 | elStyle.webkitTransitionDuration = duration; | |
1047 | elStyle.transitionDuration = duration; | |
1048 | } | |
1049 | return this; | |
1050 | } | |
1051 | // Events | |
1052 | function on() { | |
1053 | var assign; | |
1054 | ||
1055 | var args = [], len = arguments.length; | |
1056 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1057 | var eventType = args[0]; | |
1058 | var targetSelector = args[1]; | |
1059 | var listener = args[2]; | |
1060 | var capture = args[3]; | |
1061 | if (typeof args[1] === 'function') { | |
1062 | (assign = args, eventType = assign[0], listener = assign[1], capture = assign[2]); | |
1063 | targetSelector = undefined; | |
1064 | } | |
1065 | if (!capture) { capture = false; } | |
1066 | ||
1067 | function handleLiveEvent(e) { | |
1068 | var target = e.target; | |
1069 | if (!target) { return; } | |
1070 | var eventData = e.target.dom7EventData || []; | |
1071 | if (eventData.indexOf(e) < 0) { | |
1072 | eventData.unshift(e); | |
1073 | } | |
1074 | if ($(target).is(targetSelector)) { listener.apply(target, eventData); } | |
1075 | else { | |
1076 | var parents = $(target).parents(); // eslint-disable-line | |
1077 | for (var k = 0; k < parents.length; k += 1) { | |
1078 | if ($(parents[k]).is(targetSelector)) { listener.apply(parents[k], eventData); } | |
1079 | } | |
1080 | } | |
1081 | } | |
1082 | function handleEvent(e) { | |
1083 | var eventData = e && e.target ? e.target.dom7EventData || [] : []; | |
1084 | if (eventData.indexOf(e) < 0) { | |
1085 | eventData.unshift(e); | |
1086 | } | |
1087 | listener.apply(this, eventData); | |
1088 | } | |
1089 | var events = eventType.split(' '); | |
1090 | var j; | |
1091 | for (var i = 0; i < this.length; i += 1) { | |
1092 | var el = this[i]; | |
1093 | if (!targetSelector) { | |
1094 | for (j = 0; j < events.length; j += 1) { | |
1095 | var event = events[j]; | |
1096 | if (!el.dom7Listeners) { el.dom7Listeners = {}; } | |
1097 | if (!el.dom7Listeners[event]) { el.dom7Listeners[event] = []; } | |
1098 | el.dom7Listeners[event].push({ | |
1099 | listener: listener, | |
1100 | proxyListener: handleEvent, | |
1101 | }); | |
1102 | el.addEventListener(event, handleEvent, capture); | |
1103 | } | |
1104 | } else { | |
1105 | // Live events | |
1106 | for (j = 0; j < events.length; j += 1) { | |
1107 | var event$1 = events[j]; | |
1108 | if (!el.dom7LiveListeners) { el.dom7LiveListeners = {}; } | |
1109 | if (!el.dom7LiveListeners[event$1]) { el.dom7LiveListeners[event$1] = []; } | |
1110 | el.dom7LiveListeners[event$1].push({ | |
1111 | listener: listener, | |
1112 | proxyListener: handleLiveEvent, | |
1113 | }); | |
1114 | el.addEventListener(event$1, handleLiveEvent, capture); | |
1115 | } | |
1116 | } | |
1117 | } | |
1118 | return this; | |
1119 | } | |
1120 | function off() { | |
1121 | var assign; | |
1122 | ||
1123 | var args = [], len = arguments.length; | |
1124 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1125 | var eventType = args[0]; | |
1126 | var targetSelector = args[1]; | |
1127 | var listener = args[2]; | |
1128 | var capture = args[3]; | |
1129 | if (typeof args[1] === 'function') { | |
1130 | (assign = args, eventType = assign[0], listener = assign[1], capture = assign[2]); | |
1131 | targetSelector = undefined; | |
1132 | } | |
1133 | if (!capture) { capture = false; } | |
1134 | ||
1135 | var events = eventType.split(' '); | |
1136 | for (var i = 0; i < events.length; i += 1) { | |
1137 | var event = events[i]; | |
1138 | for (var j = 0; j < this.length; j += 1) { | |
1139 | var el = this[j]; | |
1140 | var handlers = (void 0); | |
1141 | if (!targetSelector && el.dom7Listeners) { | |
1142 | handlers = el.dom7Listeners[event]; | |
1143 | } else if (targetSelector && el.dom7LiveListeners) { | |
1144 | handlers = el.dom7LiveListeners[event]; | |
1145 | } | |
1146 | if (handlers && handlers.length) { | |
1147 | for (var k = handlers.length - 1; k >= 0; k -= 1) { | |
1148 | var handler = handlers[k]; | |
1149 | if (listener && handler.listener === listener) { | |
1150 | el.removeEventListener(event, handler.proxyListener, capture); | |
1151 | handlers.splice(k, 1); | |
1152 | } else if (listener && handler.listener && handler.listener.dom7proxy && handler.listener.dom7proxy === listener) { | |
1153 | el.removeEventListener(event, handler.proxyListener, capture); | |
1154 | handlers.splice(k, 1); | |
1155 | } else if (!listener) { | |
1156 | el.removeEventListener(event, handler.proxyListener, capture); | |
1157 | handlers.splice(k, 1); | |
1158 | } | |
1159 | } | |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | return this; | |
1164 | } | |
1165 | function once() { | |
1166 | var assign; | |
1167 | ||
1168 | var args = [], len = arguments.length; | |
1169 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1170 | var dom = this; | |
1171 | var eventName = args[0]; | |
1172 | var targetSelector = args[1]; | |
1173 | var listener = args[2]; | |
1174 | var capture = args[3]; | |
1175 | if (typeof args[1] === 'function') { | |
1176 | (assign = args, eventName = assign[0], listener = assign[1], capture = assign[2]); | |
1177 | targetSelector = undefined; | |
1178 | } | |
1179 | function onceHandler() { | |
1180 | var eventArgs = [], len = arguments.length; | |
1181 | while ( len-- ) eventArgs[ len ] = arguments[ len ]; | |
1182 | ||
1183 | listener.apply(this, eventArgs); | |
1184 | dom.off(eventName, targetSelector, onceHandler, capture); | |
1185 | if (onceHandler.dom7proxy) { | |
1186 | delete onceHandler.dom7proxy; | |
1187 | } | |
1188 | } | |
1189 | onceHandler.dom7proxy = listener; | |
1190 | return dom.on(eventName, targetSelector, onceHandler, capture); | |
1191 | } | |
1192 | function trigger() { | |
1193 | var args = [], len = arguments.length; | |
1194 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1195 | ||
1196 | var events = args[0].split(' '); | |
1197 | var eventData = args[1]; | |
1198 | for (var i = 0; i < events.length; i += 1) { | |
1199 | var event = events[i]; | |
1200 | for (var j = 0; j < this.length; j += 1) { | |
1201 | var el = this[j]; | |
1202 | var evt = (void 0); | |
1203 | try { | |
1204 | evt = new win.CustomEvent(event, { | |
1205 | detail: eventData, | |
1206 | bubbles: true, | |
1207 | cancelable: true, | |
1208 | }); | |
1209 | } catch (e) { | |
1210 | evt = doc.createEvent('Event'); | |
1211 | evt.initEvent(event, true, true); | |
1212 | evt.detail = eventData; | |
1213 | } | |
1214 | // eslint-disable-next-line | |
1215 | el.dom7EventData = args.filter(function (data, dataIndex) { return dataIndex > 0; }); | |
1216 | el.dispatchEvent(evt); | |
1217 | el.dom7EventData = []; | |
1218 | delete el.dom7EventData; | |
1219 | } | |
1220 | } | |
1221 | return this; | |
1222 | } | |
1223 | function transitionEnd(callback) { | |
1224 | var events = ['webkitTransitionEnd', 'transitionend']; | |
1225 | var dom = this; | |
1226 | var i; | |
1227 | function fireCallBack(e) { | |
1228 | /* jshint validthis:true */ | |
1229 | if (e.target !== this) { return; } | |
1230 | callback.call(this, e); | |
1231 | for (i = 0; i < events.length; i += 1) { | |
1232 | dom.off(events[i], fireCallBack); | |
1233 | } | |
1234 | } | |
1235 | if (callback) { | |
1236 | for (i = 0; i < events.length; i += 1) { | |
1237 | dom.on(events[i], fireCallBack); | |
1238 | } | |
1239 | } | |
1240 | return this; | |
1241 | } | |
1242 | function animationEnd(callback) { | |
1243 | var events = ['webkitAnimationEnd', 'animationend']; | |
1244 | var dom = this; | |
1245 | var i; | |
1246 | function fireCallBack(e) { | |
1247 | if (e.target !== this) { return; } | |
1248 | callback.call(this, e); | |
1249 | for (i = 0; i < events.length; i += 1) { | |
1250 | dom.off(events[i], fireCallBack); | |
1251 | } | |
1252 | } | |
1253 | if (callback) { | |
1254 | for (i = 0; i < events.length; i += 1) { | |
1255 | dom.on(events[i], fireCallBack); | |
1256 | } | |
1257 | } | |
1258 | return this; | |
1259 | } | |
1260 | // Sizing/Styles | |
1261 | function width() { | |
1262 | if (this[0] === win) { | |
1263 | return win.innerWidth; | |
1264 | } | |
1265 | ||
1266 | if (this.length > 0) { | |
1267 | return parseFloat(this.css('width')); | |
1268 | } | |
1269 | ||
1270 | return null; | |
1271 | } | |
1272 | function outerWidth(includeMargins) { | |
1273 | if (this.length > 0) { | |
1274 | if (includeMargins) { | |
1275 | // eslint-disable-next-line | |
1276 | var styles = this.styles(); | |
1277 | return this[0].offsetWidth + parseFloat(styles.getPropertyValue('margin-right')) + parseFloat(styles.getPropertyValue('margin-left')); | |
1278 | } | |
1279 | return this[0].offsetWidth; | |
1280 | } | |
1281 | return null; | |
1282 | } | |
1283 | function height() { | |
1284 | if (this[0] === win) { | |
1285 | return win.innerHeight; | |
1286 | } | |
1287 | ||
1288 | if (this.length > 0) { | |
1289 | return parseFloat(this.css('height')); | |
1290 | } | |
1291 | ||
1292 | return null; | |
1293 | } | |
1294 | function outerHeight(includeMargins) { | |
1295 | if (this.length > 0) { | |
1296 | if (includeMargins) { | |
1297 | // eslint-disable-next-line | |
1298 | var styles = this.styles(); | |
1299 | return this[0].offsetHeight + parseFloat(styles.getPropertyValue('margin-top')) + parseFloat(styles.getPropertyValue('margin-bottom')); | |
1300 | } | |
1301 | return this[0].offsetHeight; | |
1302 | } | |
1303 | return null; | |
1304 | } | |
1305 | function offset() { | |
1306 | if (this.length > 0) { | |
1307 | var el = this[0]; | |
1308 | var box = el.getBoundingClientRect(); | |
1309 | var body = doc.body; | |
1310 | var clientTop = el.clientTop || body.clientTop || 0; | |
1311 | var clientLeft = el.clientLeft || body.clientLeft || 0; | |
1312 | var scrollTop = el === win ? win.scrollY : el.scrollTop; | |
1313 | var scrollLeft = el === win ? win.scrollX : el.scrollLeft; | |
1314 | return { | |
1315 | top: (box.top + scrollTop) - clientTop, | |
1316 | left: (box.left + scrollLeft) - clientLeft, | |
1317 | }; | |
1318 | } | |
1319 | ||
1320 | return null; | |
1321 | } | |
1322 | function hide() { | |
1323 | for (var i = 0; i < this.length; i += 1) { | |
1324 | this[i].style.display = 'none'; | |
1325 | } | |
1326 | return this; | |
1327 | } | |
1328 | function show() { | |
1329 | for (var i = 0; i < this.length; i += 1) { | |
1330 | var el = this[i]; | |
1331 | if (el.style.display === 'none') { | |
1332 | el.style.display = ''; | |
1333 | } | |
1334 | if (win.getComputedStyle(el, null).getPropertyValue('display') === 'none') { | |
1335 | // Still not visible | |
1336 | el.style.display = 'block'; | |
1337 | } | |
1338 | } | |
1339 | return this; | |
1340 | } | |
1341 | function styles() { | |
1342 | if (this[0]) { return win.getComputedStyle(this[0], null); } | |
1343 | return {}; | |
1344 | } | |
1345 | function css(props, value) { | |
1346 | var i; | |
1347 | if (arguments.length === 1) { | |
1348 | if (typeof props === 'string') { | |
1349 | if (this[0]) { return win.getComputedStyle(this[0], null).getPropertyValue(props); } | |
1350 | } else { | |
1351 | for (i = 0; i < this.length; i += 1) { | |
1352 | // eslint-disable-next-line | |
1353 | for (var prop in props) { | |
1354 | this[i].style[prop] = props[prop]; | |
1355 | } | |
1356 | } | |
1357 | return this; | |
1358 | } | |
1359 | } | |
1360 | if (arguments.length === 2 && typeof props === 'string') { | |
1361 | for (i = 0; i < this.length; i += 1) { | |
1362 | this[i].style[props] = value; | |
1363 | } | |
1364 | return this; | |
1365 | } | |
1366 | return this; | |
1367 | } | |
1368 | ||
1369 | // Dom manipulation | |
1370 | function toArray() { | |
1371 | var arr = []; | |
1372 | for (var i = 0; i < this.length; i += 1) { | |
1373 | arr.push(this[i]); | |
1374 | } | |
1375 | return arr; | |
1376 | } | |
1377 | // Iterate over the collection passing elements to `callback` | |
1378 | function each(callback) { | |
1379 | // Don't bother continuing without a callback | |
1380 | if (!callback) { return this; } | |
1381 | // Iterate over the current collection | |
1382 | for (var i = 0; i < this.length; i += 1) { | |
1383 | // If the callback returns false | |
1384 | if (callback.call(this[i], i, this[i]) === false) { | |
1385 | // End the loop early | |
1386 | return this; | |
1387 | } | |
1388 | } | |
1389 | // Return `this` to allow chained DOM operations | |
1390 | return this; | |
1391 | } | |
1392 | function forEach(callback) { | |
1393 | // Don't bother continuing without a callback | |
1394 | if (!callback) { return this; } | |
1395 | // Iterate over the current collection | |
1396 | for (var i = 0; i < this.length; i += 1) { | |
1397 | // If the callback returns false | |
1398 | if (callback.call(this[i], this[i], i) === false) { | |
1399 | // End the loop early | |
1400 | return this; | |
1401 | } | |
1402 | } | |
1403 | // Return `this` to allow chained DOM operations | |
1404 | return this; | |
1405 | } | |
1406 | function filter(callback) { | |
1407 | var matchedItems = []; | |
1408 | var dom = this; | |
1409 | for (var i = 0; i < dom.length; i += 1) { | |
1410 | if (callback.call(dom[i], i, dom[i])) { matchedItems.push(dom[i]); } | |
1411 | } | |
1412 | return new Dom7(matchedItems); | |
1413 | } | |
1414 | function map(callback) { | |
1415 | var modifiedItems = []; | |
1416 | var dom = this; | |
1417 | for (var i = 0; i < dom.length; i += 1) { | |
1418 | modifiedItems.push(callback.call(dom[i], i, dom[i])); | |
1419 | } | |
1420 | return new Dom7(modifiedItems); | |
1421 | } | |
1422 | // eslint-disable-next-line | |
1423 | function html(html) { | |
1424 | if (typeof html === 'undefined') { | |
1425 | return this[0] ? this[0].innerHTML : undefined; | |
1426 | } | |
1427 | ||
1428 | for (var i = 0; i < this.length; i += 1) { | |
1429 | this[i].innerHTML = html; | |
1430 | } | |
1431 | return this; | |
1432 | } | |
1433 | // eslint-disable-next-line | |
1434 | function text(text) { | |
1435 | if (typeof text === 'undefined') { | |
1436 | if (this[0]) { | |
1437 | return this[0].textContent.trim(); | |
1438 | } | |
1439 | return null; | |
1440 | } | |
1441 | ||
1442 | for (var i = 0; i < this.length; i += 1) { | |
1443 | this[i].textContent = text; | |
1444 | } | |
1445 | return this; | |
1446 | } | |
1447 | function is(selector) { | |
1448 | var el = this[0]; | |
1449 | var compareWith; | |
1450 | var i; | |
1451 | if (!el || typeof selector === 'undefined') { return false; } | |
1452 | if (typeof selector === 'string') { | |
1453 | if (el.matches) { return el.matches(selector); } | |
1454 | else if (el.webkitMatchesSelector) { return el.webkitMatchesSelector(selector); } | |
1455 | else if (el.msMatchesSelector) { return el.msMatchesSelector(selector); } | |
1456 | ||
1457 | compareWith = $(selector); | |
1458 | for (i = 0; i < compareWith.length; i += 1) { | |
1459 | if (compareWith[i] === el) { return true; } | |
1460 | } | |
1461 | return false; | |
1462 | } else if (selector === doc) { return el === doc; } | |
1463 | else if (selector === win) { return el === win; } | |
1464 | ||
1465 | if (selector.nodeType || selector instanceof Dom7) { | |
1466 | compareWith = selector.nodeType ? [selector] : selector; | |
1467 | for (i = 0; i < compareWith.length; i += 1) { | |
1468 | if (compareWith[i] === el) { return true; } | |
1469 | } | |
1470 | return false; | |
1471 | } | |
1472 | return false; | |
1473 | } | |
1474 | function indexOf(el) { | |
1475 | for (var i = 0; i < this.length; i += 1) { | |
1476 | if (this[i] === el) { return i; } | |
1477 | } | |
1478 | return -1; | |
1479 | } | |
1480 | function index() { | |
1481 | var child = this[0]; | |
1482 | var i; | |
1483 | if (child) { | |
1484 | i = 0; | |
1485 | // eslint-disable-next-line | |
1486 | while ((child = child.previousSibling) !== null) { | |
1487 | if (child.nodeType === 1) { i += 1; } | |
1488 | } | |
1489 | return i; | |
1490 | } | |
1491 | return undefined; | |
1492 | } | |
1493 | // eslint-disable-next-line | |
1494 | function eq(index) { | |
1495 | if (typeof index === 'undefined') { return this; } | |
1496 | var length = this.length; | |
1497 | var returnIndex; | |
1498 | if (index > length - 1) { | |
1499 | return new Dom7([]); | |
1500 | } | |
1501 | if (index < 0) { | |
1502 | returnIndex = length + index; | |
1503 | if (returnIndex < 0) { return new Dom7([]); } | |
1504 | return new Dom7([this[returnIndex]]); | |
1505 | } | |
1506 | return new Dom7([this[index]]); | |
1507 | } | |
1508 | function append() { | |
1509 | var args = [], len = arguments.length; | |
1510 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1511 | ||
1512 | var newChild; | |
1513 | ||
1514 | for (var k = 0; k < args.length; k += 1) { | |
1515 | newChild = args[k]; | |
1516 | for (var i = 0; i < this.length; i += 1) { | |
1517 | if (typeof newChild === 'string') { | |
1518 | var tempDiv = doc.createElement('div'); | |
1519 | tempDiv.innerHTML = newChild; | |
1520 | while (tempDiv.firstChild) { | |
1521 | this[i].appendChild(tempDiv.firstChild); | |
1522 | } | |
1523 | } else if (newChild instanceof Dom7) { | |
1524 | for (var j = 0; j < newChild.length; j += 1) { | |
1525 | this[i].appendChild(newChild[j]); | |
1526 | } | |
1527 | } else { | |
1528 | this[i].appendChild(newChild); | |
1529 | } | |
1530 | } | |
1531 | } | |
1532 | ||
1533 | return this; | |
1534 | } | |
1535 | // eslint-disable-next-line | |
1536 | function appendTo(parent) { | |
1537 | $(parent).append(this); | |
1538 | return this; | |
1539 | } | |
1540 | function prepend(newChild) { | |
1541 | var i; | |
1542 | var j; | |
1543 | for (i = 0; i < this.length; i += 1) { | |
1544 | if (typeof newChild === 'string') { | |
1545 | var tempDiv = doc.createElement('div'); | |
1546 | tempDiv.innerHTML = newChild; | |
1547 | for (j = tempDiv.childNodes.length - 1; j >= 0; j -= 1) { | |
1548 | this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]); | |
1549 | } | |
1550 | } else if (newChild instanceof Dom7) { | |
1551 | for (j = 0; j < newChild.length; j += 1) { | |
1552 | this[i].insertBefore(newChild[j], this[i].childNodes[0]); | |
1553 | } | |
1554 | } else { | |
1555 | this[i].insertBefore(newChild, this[i].childNodes[0]); | |
1556 | } | |
1557 | } | |
1558 | return this; | |
1559 | } | |
1560 | // eslint-disable-next-line | |
1561 | function prependTo(parent) { | |
1562 | $(parent).prepend(this); | |
1563 | return this; | |
1564 | } | |
1565 | function insertBefore(selector) { | |
1566 | var before = $(selector); | |
1567 | for (var i = 0; i < this.length; i += 1) { | |
1568 | if (before.length === 1) { | |
1569 | before[0].parentNode.insertBefore(this[i], before[0]); | |
1570 | } else if (before.length > 1) { | |
1571 | for (var j = 0; j < before.length; j += 1) { | |
1572 | before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]); | |
1573 | } | |
1574 | } | |
1575 | } | |
1576 | } | |
1577 | function insertAfter(selector) { | |
1578 | var after = $(selector); | |
1579 | for (var i = 0; i < this.length; i += 1) { | |
1580 | if (after.length === 1) { | |
1581 | after[0].parentNode.insertBefore(this[i], after[0].nextSibling); | |
1582 | } else if (after.length > 1) { | |
1583 | for (var j = 0; j < after.length; j += 1) { | |
1584 | after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling); | |
1585 | } | |
1586 | } | |
1587 | } | |
1588 | } | |
1589 | function next(selector) { | |
1590 | if (this.length > 0) { | |
1591 | if (selector) { | |
1592 | if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) { | |
1593 | return new Dom7([this[0].nextElementSibling]); | |
1594 | } | |
1595 | return new Dom7([]); | |
1596 | } | |
1597 | ||
1598 | if (this[0].nextElementSibling) { return new Dom7([this[0].nextElementSibling]); } | |
1599 | return new Dom7([]); | |
1600 | } | |
1601 | return new Dom7([]); | |
1602 | } | |
1603 | function nextAll(selector) { | |
1604 | var nextEls = []; | |
1605 | var el = this[0]; | |
1606 | if (!el) { return new Dom7([]); } | |
1607 | while (el.nextElementSibling) { | |
1608 | var next = el.nextElementSibling; // eslint-disable-line | |
1609 | if (selector) { | |
1610 | if ($(next).is(selector)) { nextEls.push(next); } | |
1611 | } else { nextEls.push(next); } | |
1612 | el = next; | |
1613 | } | |
1614 | return new Dom7(nextEls); | |
1615 | } | |
1616 | function prev(selector) { | |
1617 | if (this.length > 0) { | |
1618 | var el = this[0]; | |
1619 | if (selector) { | |
1620 | if (el.previousElementSibling && $(el.previousElementSibling).is(selector)) { | |
1621 | return new Dom7([el.previousElementSibling]); | |
1622 | } | |
1623 | return new Dom7([]); | |
1624 | } | |
1625 | ||
1626 | if (el.previousElementSibling) { return new Dom7([el.previousElementSibling]); } | |
1627 | return new Dom7([]); | |
1628 | } | |
1629 | return new Dom7([]); | |
1630 | } | |
1631 | function prevAll(selector) { | |
1632 | var prevEls = []; | |
1633 | var el = this[0]; | |
1634 | if (!el) { return new Dom7([]); } | |
1635 | while (el.previousElementSibling) { | |
1636 | var prev = el.previousElementSibling; // eslint-disable-line | |
1637 | if (selector) { | |
1638 | if ($(prev).is(selector)) { prevEls.push(prev); } | |
1639 | } else { prevEls.push(prev); } | |
1640 | el = prev; | |
1641 | } | |
1642 | return new Dom7(prevEls); | |
1643 | } | |
1644 | function siblings(selector) { | |
1645 | return this.nextAll(selector).add(this.prevAll(selector)); | |
1646 | } | |
1647 | function parent(selector) { | |
1648 | var parents = []; // eslint-disable-line | |
1649 | for (var i = 0; i < this.length; i += 1) { | |
1650 | if (this[i].parentNode !== null) { | |
1651 | if (selector) { | |
1652 | if ($(this[i].parentNode).is(selector)) { parents.push(this[i].parentNode); } | |
1653 | } else { | |
1654 | parents.push(this[i].parentNode); | |
1655 | } | |
1656 | } | |
1657 | } | |
1658 | return $(unique(parents)); | |
1659 | } | |
1660 | function parents(selector) { | |
1661 | var parents = []; // eslint-disable-line | |
1662 | for (var i = 0; i < this.length; i += 1) { | |
1663 | var parent = this[i].parentNode; // eslint-disable-line | |
1664 | while (parent) { | |
1665 | if (selector) { | |
1666 | if ($(parent).is(selector)) { parents.push(parent); } | |
1667 | } else { | |
1668 | parents.push(parent); | |
1669 | } | |
1670 | parent = parent.parentNode; | |
1671 | } | |
1672 | } | |
1673 | return $(unique(parents)); | |
1674 | } | |
1675 | function closest(selector) { | |
1676 | var closest = this; // eslint-disable-line | |
1677 | if (typeof selector === 'undefined') { | |
1678 | return new Dom7([]); | |
1679 | } | |
1680 | if (!closest.is(selector)) { | |
1681 | closest = closest.parents(selector).eq(0); | |
1682 | } | |
1683 | return closest; | |
1684 | } | |
1685 | function find(selector) { | |
1686 | var foundElements = []; | |
1687 | for (var i = 0; i < this.length; i += 1) { | |
1688 | var found = this[i].querySelectorAll(selector); | |
1689 | for (var j = 0; j < found.length; j += 1) { | |
1690 | foundElements.push(found[j]); | |
1691 | } | |
1692 | } | |
1693 | return new Dom7(foundElements); | |
1694 | } | |
1695 | function children(selector) { | |
1696 | var children = []; // eslint-disable-line | |
1697 | for (var i = 0; i < this.length; i += 1) { | |
1698 | var childNodes = this[i].childNodes; | |
1699 | ||
1700 | for (var j = 0; j < childNodes.length; j += 1) { | |
1701 | if (!selector) { | |
1702 | if (childNodes[j].nodeType === 1) { children.push(childNodes[j]); } | |
1703 | } else if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) { | |
1704 | children.push(childNodes[j]); | |
1705 | } | |
1706 | } | |
1707 | } | |
1708 | return new Dom7(unique(children)); | |
1709 | } | |
1710 | function remove() { | |
1711 | for (var i = 0; i < this.length; i += 1) { | |
1712 | if (this[i].parentNode) { this[i].parentNode.removeChild(this[i]); } | |
1713 | } | |
1714 | return this; | |
1715 | } | |
1716 | function detach() { | |
1717 | return this.remove(); | |
1718 | } | |
1719 | function add() { | |
1720 | var args = [], len = arguments.length; | |
1721 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1722 | ||
1723 | var dom = this; | |
1724 | var i; | |
1725 | var j; | |
1726 | for (i = 0; i < args.length; i += 1) { | |
1727 | var toAdd = $(args[i]); | |
1728 | for (j = 0; j < toAdd.length; j += 1) { | |
1729 | dom[dom.length] = toAdd[j]; | |
1730 | dom.length += 1; | |
1731 | } | |
1732 | } | |
1733 | return dom; | |
1734 | } | |
1735 | function empty() { | |
1736 | for (var i = 0; i < this.length; i += 1) { | |
1737 | var el = this[i]; | |
1738 | if (el.nodeType === 1) { | |
1739 | for (var j = 0; j < el.childNodes.length; j += 1) { | |
1740 | if (el.childNodes[j].parentNode) { | |
1741 | el.childNodes[j].parentNode.removeChild(el.childNodes[j]); | |
1742 | } | |
1743 | } | |
1744 | el.textContent = ''; | |
1745 | } | |
1746 | } | |
1747 | return this; | |
1748 | } | |
1749 | ||
1750 | var Methods = /*#__PURE__*/Object.freeze({ | |
1751 | addClass: addClass, | |
1752 | removeClass: removeClass, | |
1753 | hasClass: hasClass, | |
1754 | toggleClass: toggleClass, | |
1755 | attr: attr, | |
1756 | removeAttr: removeAttr, | |
1757 | prop: prop, | |
1758 | data: data, | |
1759 | removeData: removeData, | |
1760 | dataset: dataset, | |
1761 | val: val, | |
1762 | transform: transform, | |
1763 | transition: transition, | |
1764 | on: on, | |
1765 | off: off, | |
1766 | once: once, | |
1767 | trigger: trigger, | |
1768 | transitionEnd: transitionEnd, | |
1769 | animationEnd: animationEnd, | |
1770 | width: width, | |
1771 | outerWidth: outerWidth, | |
1772 | height: height, | |
1773 | outerHeight: outerHeight, | |
1774 | offset: offset, | |
1775 | hide: hide, | |
1776 | show: show, | |
1777 | styles: styles, | |
1778 | css: css, | |
1779 | toArray: toArray, | |
1780 | each: each, | |
1781 | forEach: forEach, | |
1782 | filter: filter, | |
1783 | map: map, | |
1784 | html: html, | |
1785 | text: text, | |
1786 | is: is, | |
1787 | indexOf: indexOf, | |
1788 | index: index, | |
1789 | eq: eq, | |
1790 | append: append, | |
1791 | appendTo: appendTo, | |
1792 | prepend: prepend, | |
1793 | prependTo: prependTo, | |
1794 | insertBefore: insertBefore, | |
1795 | insertAfter: insertAfter, | |
1796 | next: next, | |
1797 | nextAll: nextAll, | |
1798 | prev: prev, | |
1799 | prevAll: prevAll, | |
1800 | siblings: siblings, | |
1801 | parent: parent, | |
1802 | parents: parents, | |
1803 | closest: closest, | |
1804 | find: find, | |
1805 | children: children, | |
1806 | remove: remove, | |
1807 | detach: detach, | |
1808 | add: add, | |
1809 | empty: empty | |
1810 | }); | |
1811 | ||
1812 | function scrollTo() { | |
1813 | var assign; | |
1814 | ||
1815 | var args = [], len = arguments.length; | |
1816 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1817 | var left = args[0]; | |
1818 | var top = args[1]; | |
1819 | var duration = args[2]; | |
1820 | var easing = args[3]; | |
1821 | var callback = args[4]; | |
1822 | if (args.length === 4 && typeof easing === 'function') { | |
1823 | callback = easing; | |
1824 | (assign = args, left = assign[0], top = assign[1], duration = assign[2], callback = assign[3], easing = assign[4]); | |
1825 | } | |
1826 | if (typeof easing === 'undefined') { easing = 'swing'; } | |
1827 | ||
1828 | return this.each(function animate() { | |
1829 | var el = this; | |
1830 | var currentTop; | |
1831 | var currentLeft; | |
1832 | var maxTop; | |
1833 | var maxLeft; | |
1834 | var newTop; | |
1835 | var newLeft; | |
1836 | var scrollTop; // eslint-disable-line | |
1837 | var scrollLeft; // eslint-disable-line | |
1838 | var animateTop = top > 0 || top === 0; | |
1839 | var animateLeft = left > 0 || left === 0; | |
1840 | if (typeof easing === 'undefined') { | |
1841 | easing = 'swing'; | |
1842 | } | |
1843 | if (animateTop) { | |
1844 | currentTop = el.scrollTop; | |
1845 | if (!duration) { | |
1846 | el.scrollTop = top; | |
1847 | } | |
1848 | } | |
1849 | if (animateLeft) { | |
1850 | currentLeft = el.scrollLeft; | |
1851 | if (!duration) { | |
1852 | el.scrollLeft = left; | |
1853 | } | |
1854 | } | |
1855 | if (!duration) { return; } | |
1856 | if (animateTop) { | |
1857 | maxTop = el.scrollHeight - el.offsetHeight; | |
1858 | newTop = Math.max(Math.min(top, maxTop), 0); | |
1859 | } | |
1860 | if (animateLeft) { | |
1861 | maxLeft = el.scrollWidth - el.offsetWidth; | |
1862 | newLeft = Math.max(Math.min(left, maxLeft), 0); | |
1863 | } | |
1864 | var startTime = null; | |
1865 | if (animateTop && newTop === currentTop) { animateTop = false; } | |
1866 | if (animateLeft && newLeft === currentLeft) { animateLeft = false; } | |
1867 | function render(time) { | |
1868 | if ( time === void 0 ) time = new Date().getTime(); | |
1869 | ||
1870 | if (startTime === null) { | |
1871 | startTime = time; | |
1872 | } | |
1873 | var progress = Math.max(Math.min((time - startTime) / duration, 1), 0); | |
1874 | var easeProgress = easing === 'linear' ? progress : (0.5 - (Math.cos(progress * Math.PI) / 2)); | |
1875 | var done; | |
1876 | if (animateTop) { scrollTop = currentTop + (easeProgress * (newTop - currentTop)); } | |
1877 | if (animateLeft) { scrollLeft = currentLeft + (easeProgress * (newLeft - currentLeft)); } | |
1878 | if (animateTop && newTop > currentTop && scrollTop >= newTop) { | |
1879 | el.scrollTop = newTop; | |
1880 | done = true; | |
1881 | } | |
1882 | if (animateTop && newTop < currentTop && scrollTop <= newTop) { | |
1883 | el.scrollTop = newTop; | |
1884 | done = true; | |
1885 | } | |
1886 | if (animateLeft && newLeft > currentLeft && scrollLeft >= newLeft) { | |
1887 | el.scrollLeft = newLeft; | |
1888 | done = true; | |
1889 | } | |
1890 | if (animateLeft && newLeft < currentLeft && scrollLeft <= newLeft) { | |
1891 | el.scrollLeft = newLeft; | |
1892 | done = true; | |
1893 | } | |
1894 | ||
1895 | if (done) { | |
1896 | if (callback) { callback(); } | |
1897 | return; | |
1898 | } | |
1899 | if (animateTop) { el.scrollTop = scrollTop; } | |
1900 | if (animateLeft) { el.scrollLeft = scrollLeft; } | |
1901 | requestAnimationFrame(render); | |
1902 | } | |
1903 | requestAnimationFrame(render); | |
1904 | }); | |
1905 | } | |
1906 | // scrollTop(top, duration, easing, callback) { | |
1907 | function scrollTop() { | |
1908 | var assign; | |
1909 | ||
1910 | var args = [], len = arguments.length; | |
1911 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1912 | var top = args[0]; | |
1913 | var duration = args[1]; | |
1914 | var easing = args[2]; | |
1915 | var callback = args[3]; | |
1916 | if (args.length === 3 && typeof easing === 'function') { | |
1917 | (assign = args, top = assign[0], duration = assign[1], callback = assign[2], easing = assign[3]); | |
1918 | } | |
1919 | var dom = this; | |
1920 | if (typeof top === 'undefined') { | |
1921 | if (dom.length > 0) { return dom[0].scrollTop; } | |
1922 | return null; | |
1923 | } | |
1924 | return dom.scrollTo(undefined, top, duration, easing, callback); | |
1925 | } | |
1926 | function scrollLeft() { | |
1927 | var assign; | |
1928 | ||
1929 | var args = [], len = arguments.length; | |
1930 | while ( len-- ) args[ len ] = arguments[ len ]; | |
1931 | var left = args[0]; | |
1932 | var duration = args[1]; | |
1933 | var easing = args[2]; | |
1934 | var callback = args[3]; | |
1935 | if (args.length === 3 && typeof easing === 'function') { | |
1936 | (assign = args, left = assign[0], duration = assign[1], callback = assign[2], easing = assign[3]); | |
1937 | } | |
1938 | var dom = this; | |
1939 | if (typeof left === 'undefined') { | |
1940 | if (dom.length > 0) { return dom[0].scrollLeft; } | |
1941 | return null; | |
1942 | } | |
1943 | return dom.scrollTo(left, undefined, duration, easing, callback); | |
1944 | } | |
1945 | ||
1946 | var Scroll = /*#__PURE__*/Object.freeze({ | |
1947 | scrollTo: scrollTo, | |
1948 | scrollTop: scrollTop, | |
1949 | scrollLeft: scrollLeft | |
1950 | }); | |
1951 | ||
1952 | function animate(initialProps, initialParams) { | |
1953 | var els = this; | |
1954 | var a = { | |
1955 | props: Object.assign({}, initialProps), | |
1956 | params: Object.assign({ | |
1957 | duration: 300, | |
1958 | easing: 'swing', // or 'linear' | |
1959 | /* Callbacks | |
1960 | begin(elements) | |
1961 | complete(elements) | |
1962 | progress(elements, complete, remaining, start, tweenValue) | |
1963 | */ | |
1964 | }, initialParams), | |
1965 | ||
1966 | elements: els, | |
1967 | animating: false, | |
1968 | que: [], | |
1969 | ||
1970 | easingProgress: function easingProgress(easing, progress) { | |
1971 | if (easing === 'swing') { | |
1972 | return 0.5 - (Math.cos(progress * Math.PI) / 2); | |
1973 | } | |
1974 | if (typeof easing === 'function') { | |
1975 | return easing(progress); | |
1976 | } | |
1977 | return progress; | |
1978 | }, | |
1979 | stop: function stop() { | |
1980 | if (a.frameId) { | |
1981 | cancelAnimationFrame(a.frameId); | |
1982 | } | |
1983 | a.animating = false; | |
1984 | a.elements.each(function (index, el) { | |
1985 | var element = el; | |
1986 | delete element.dom7AnimateInstance; | |
1987 | }); | |
1988 | a.que = []; | |
1989 | }, | |
1990 | done: function done(complete) { | |
1991 | a.animating = false; | |
1992 | a.elements.each(function (index, el) { | |
1993 | var element = el; | |
1994 | delete element.dom7AnimateInstance; | |
1995 | }); | |
1996 | if (complete) { complete(els); } | |
1997 | if (a.que.length > 0) { | |
1998 | var que = a.que.shift(); | |
1999 | a.animate(que[0], que[1]); | |
2000 | } | |
2001 | }, | |
2002 | animate: function animate(props, params) { | |
2003 | if (a.animating) { | |
2004 | a.que.push([props, params]); | |
2005 | return a; | |
2006 | } | |
2007 | var elements = []; | |
2008 | ||
2009 | // Define & Cache Initials & Units | |
2010 | a.elements.each(function (index, el) { | |
2011 | var initialFullValue; | |
2012 | var initialValue; | |
2013 | var unit; | |
2014 | var finalValue; | |
2015 | var finalFullValue; | |
2016 | ||
2017 | if (!el.dom7AnimateInstance) { a.elements[index].dom7AnimateInstance = a; } | |
2018 | ||
2019 | elements[index] = { | |
2020 | container: el, | |
2021 | }; | |
2022 | Object.keys(props).forEach(function (prop) { | |
2023 | initialFullValue = win.getComputedStyle(el, null).getPropertyValue(prop).replace(',', '.'); | |
2024 | initialValue = parseFloat(initialFullValue); | |
2025 | unit = initialFullValue.replace(initialValue, ''); | |
2026 | finalValue = parseFloat(props[prop]); | |
2027 | finalFullValue = props[prop] + unit; | |
2028 | elements[index][prop] = { | |
2029 | initialFullValue: initialFullValue, | |
2030 | initialValue: initialValue, | |
2031 | unit: unit, | |
2032 | finalValue: finalValue, | |
2033 | finalFullValue: finalFullValue, | |
2034 | currentValue: initialValue, | |
2035 | }; | |
2036 | }); | |
2037 | }); | |
2038 | ||
2039 | var startTime = null; | |
2040 | var time; | |
2041 | var elementsDone = 0; | |
2042 | var propsDone = 0; | |
2043 | var done; | |
2044 | var began = false; | |
2045 | ||
2046 | a.animating = true; | |
2047 | ||
2048 | function render() { | |
2049 | time = new Date().getTime(); | |
2050 | var progress; | |
2051 | var easeProgress; | |
2052 | // let el; | |
2053 | if (!began) { | |
2054 | began = true; | |
2055 | if (params.begin) { params.begin(els); } | |
2056 | } | |
2057 | if (startTime === null) { | |
2058 | startTime = time; | |
2059 | } | |
2060 | if (params.progress) { | |
2061 | // eslint-disable-next-line | |
2062 | params.progress(els, Math.max(Math.min((time - startTime) / params.duration, 1), 0), ((startTime + params.duration) - time < 0 ? 0 : (startTime + params.duration) - time), startTime); | |
2063 | } | |
2064 | ||
2065 | elements.forEach(function (element) { | |
2066 | var el = element; | |
2067 | if (done || el.done) { return; } | |
2068 | Object.keys(props).forEach(function (prop) { | |
2069 | if (done || el.done) { return; } | |
2070 | progress = Math.max(Math.min((time - startTime) / params.duration, 1), 0); | |
2071 | easeProgress = a.easingProgress(params.easing, progress); | |
2072 | var ref = el[prop]; | |
2073 | var initialValue = ref.initialValue; | |
2074 | var finalValue = ref.finalValue; | |
2075 | var unit = ref.unit; | |
2076 | el[prop].currentValue = initialValue + (easeProgress * (finalValue - initialValue)); | |
2077 | var currentValue = el[prop].currentValue; | |
2078 | ||
2079 | if ( | |
2080 | (finalValue > initialValue && currentValue >= finalValue) || | |
2081 | (finalValue < initialValue && currentValue <= finalValue)) { | |
2082 | el.container.style[prop] = finalValue + unit; | |
2083 | propsDone += 1; | |
2084 | if (propsDone === Object.keys(props).length) { | |
2085 | el.done = true; | |
2086 | elementsDone += 1; | |
2087 | } | |
2088 | if (elementsDone === elements.length) { | |
2089 | done = true; | |
2090 | } | |
2091 | } | |
2092 | if (done) { | |
2093 | a.done(params.complete); | |
2094 | return; | |
2095 | } | |
2096 | el.container.style[prop] = currentValue + unit; | |
2097 | }); | |
2098 | }); | |
2099 | if (done) { return; } | |
2100 | // Then call | |
2101 | a.frameId = requestAnimationFrame(render); | |
2102 | } | |
2103 | a.frameId = requestAnimationFrame(render); | |
2104 | return a; | |
2105 | }, | |
2106 | }; | |
2107 | ||
2108 | if (a.elements.length === 0) { | |
2109 | return els; | |
2110 | } | |
2111 | ||
2112 | var animateInstance; | |
2113 | for (var i = 0; i < a.elements.length; i += 1) { | |
2114 | if (a.elements[i].dom7AnimateInstance) { | |
2115 | animateInstance = a.elements[i].dom7AnimateInstance; | |
2116 | } else { a.elements[i].dom7AnimateInstance = a; } | |
2117 | } | |
2118 | if (!animateInstance) { | |
2119 | animateInstance = a; | |
2120 | } | |
2121 | ||
2122 | if (initialProps === 'stop') { | |
2123 | animateInstance.stop(); | |
2124 | } else { | |
2125 | animateInstance.animate(a.props, a.params); | |
2126 | } | |
2127 | ||
2128 | return els; | |
2129 | } | |
2130 | ||
2131 | function stop() { | |
2132 | var els = this; | |
2133 | for (var i = 0; i < els.length; i += 1) { | |
2134 | if (els[i].dom7AnimateInstance) { | |
2135 | els[i].dom7AnimateInstance.stop(); | |
2136 | } | |
2137 | } | |
2138 | } | |
2139 | ||
2140 | var Animate = /*#__PURE__*/Object.freeze({ | |
2141 | animate: animate, | |
2142 | stop: stop | |
2143 | }); | |
2144 | ||
2145 | var noTrigger = ('resize scroll').split(' '); | |
2146 | function eventShortcut(name) { | |
2147 | var ref; | |
2148 | ||
2149 | var args = [], len = arguments.length - 1; | |
2150 | while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | |
2151 | if (typeof args[0] === 'undefined') { | |
2152 | for (var i = 0; i < this.length; i += 1) { | |
2153 | if (noTrigger.indexOf(name) < 0) { | |
2154 | if (name in this[i]) { this[i][name](); } | |
2155 | else { | |
2156 | $(this[i]).trigger(name); | |
2157 | } | |
2158 | } | |
2159 | } | |
2160 | return this; | |
2161 | } | |
2162 | return (ref = this).on.apply(ref, [ name ].concat( args )); | |
2163 | } | |
2164 | ||
2165 | function click() { | |
2166 | var args = [], len = arguments.length; | |
2167 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2168 | ||
2169 | return eventShortcut.bind(this).apply(void 0, [ 'click' ].concat( args )); | |
2170 | } | |
2171 | function blur() { | |
2172 | var args = [], len = arguments.length; | |
2173 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2174 | ||
2175 | return eventShortcut.bind(this).apply(void 0, [ 'blur' ].concat( args )); | |
2176 | } | |
2177 | function focus() { | |
2178 | var args = [], len = arguments.length; | |
2179 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2180 | ||
2181 | return eventShortcut.bind(this).apply(void 0, [ 'focus' ].concat( args )); | |
2182 | } | |
2183 | function focusin() { | |
2184 | var args = [], len = arguments.length; | |
2185 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2186 | ||
2187 | return eventShortcut.bind(this).apply(void 0, [ 'focusin' ].concat( args )); | |
2188 | } | |
2189 | function focusout() { | |
2190 | var args = [], len = arguments.length; | |
2191 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2192 | ||
2193 | return eventShortcut.bind(this).apply(void 0, [ 'focusout' ].concat( args )); | |
2194 | } | |
2195 | function keyup() { | |
2196 | var args = [], len = arguments.length; | |
2197 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2198 | ||
2199 | return eventShortcut.bind(this).apply(void 0, [ 'keyup' ].concat( args )); | |
2200 | } | |
2201 | function keydown() { | |
2202 | var args = [], len = arguments.length; | |
2203 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2204 | ||
2205 | return eventShortcut.bind(this).apply(void 0, [ 'keydown' ].concat( args )); | |
2206 | } | |
2207 | function keypress() { | |
2208 | var args = [], len = arguments.length; | |
2209 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2210 | ||
2211 | return eventShortcut.bind(this).apply(void 0, [ 'keypress' ].concat( args )); | |
2212 | } | |
2213 | function submit() { | |
2214 | var args = [], len = arguments.length; | |
2215 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2216 | ||
2217 | return eventShortcut.bind(this).apply(void 0, [ 'submit' ].concat( args )); | |
2218 | } | |
2219 | function change() { | |
2220 | var args = [], len = arguments.length; | |
2221 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2222 | ||
2223 | return eventShortcut.bind(this).apply(void 0, [ 'change' ].concat( args )); | |
2224 | } | |
2225 | function mousedown() { | |
2226 | var args = [], len = arguments.length; | |
2227 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2228 | ||
2229 | return eventShortcut.bind(this).apply(void 0, [ 'mousedown' ].concat( args )); | |
2230 | } | |
2231 | function mousemove() { | |
2232 | var args = [], len = arguments.length; | |
2233 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2234 | ||
2235 | return eventShortcut.bind(this).apply(void 0, [ 'mousemove' ].concat( args )); | |
2236 | } | |
2237 | function mouseup() { | |
2238 | var args = [], len = arguments.length; | |
2239 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2240 | ||
2241 | return eventShortcut.bind(this).apply(void 0, [ 'mouseup' ].concat( args )); | |
2242 | } | |
2243 | function mouseenter() { | |
2244 | var args = [], len = arguments.length; | |
2245 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2246 | ||
2247 | return eventShortcut.bind(this).apply(void 0, [ 'mouseenter' ].concat( args )); | |
2248 | } | |
2249 | function mouseleave() { | |
2250 | var args = [], len = arguments.length; | |
2251 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2252 | ||
2253 | return eventShortcut.bind(this).apply(void 0, [ 'mouseleave' ].concat( args )); | |
2254 | } | |
2255 | function mouseout() { | |
2256 | var args = [], len = arguments.length; | |
2257 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2258 | ||
2259 | return eventShortcut.bind(this).apply(void 0, [ 'mouseout' ].concat( args )); | |
2260 | } | |
2261 | function mouseover() { | |
2262 | var args = [], len = arguments.length; | |
2263 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2264 | ||
2265 | return eventShortcut.bind(this).apply(void 0, [ 'mouseover' ].concat( args )); | |
2266 | } | |
2267 | function touchstart() { | |
2268 | var args = [], len = arguments.length; | |
2269 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2270 | ||
2271 | return eventShortcut.bind(this).apply(void 0, [ 'touchstart' ].concat( args )); | |
2272 | } | |
2273 | function touchend() { | |
2274 | var args = [], len = arguments.length; | |
2275 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2276 | ||
2277 | return eventShortcut.bind(this).apply(void 0, [ 'touchend' ].concat( args )); | |
2278 | } | |
2279 | function touchmove() { | |
2280 | var args = [], len = arguments.length; | |
2281 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2282 | ||
2283 | return eventShortcut.bind(this).apply(void 0, [ 'touchmove' ].concat( args )); | |
2284 | } | |
2285 | function resize() { | |
2286 | var args = [], len = arguments.length; | |
2287 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2288 | ||
2289 | return eventShortcut.bind(this).apply(void 0, [ 'resize' ].concat( args )); | |
2290 | } | |
2291 | function scroll() { | |
2292 | var args = [], len = arguments.length; | |
2293 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2294 | ||
2295 | return eventShortcut.bind(this).apply(void 0, [ 'scroll' ].concat( args )); | |
2296 | } | |
2297 | ||
2298 | var eventShortcuts = /*#__PURE__*/Object.freeze({ | |
2299 | click: click, | |
2300 | blur: blur, | |
2301 | focus: focus, | |
2302 | focusin: focusin, | |
2303 | focusout: focusout, | |
2304 | keyup: keyup, | |
2305 | keydown: keydown, | |
2306 | keypress: keypress, | |
2307 | submit: submit, | |
2308 | change: change, | |
2309 | mousedown: mousedown, | |
2310 | mousemove: mousemove, | |
2311 | mouseup: mouseup, | |
2312 | mouseenter: mouseenter, | |
2313 | mouseleave: mouseleave, | |
2314 | mouseout: mouseout, | |
2315 | mouseover: mouseover, | |
2316 | touchstart: touchstart, | |
2317 | touchend: touchend, | |
2318 | touchmove: touchmove, | |
2319 | resize: resize, | |
2320 | scroll: scroll | |
2321 | }); | |
2322 | ||
2323 | [Methods, Scroll, Animate, eventShortcuts].forEach(function (group) { | |
2324 | Object.keys(group).forEach(function (methodName) { | |
2325 | $.fn[methodName] = group[methodName]; | |
2326 | }); | |
2327 | }); | |
2328 | ||
2329 | /** | |
2330 | * https://github.com/gre/bezier-easing | |
2331 | * BezierEasing - use bezier curve for transition easing function | |
2332 | * by Gaëtan Renaudeau 2014 - 2015 – MIT License | |
2333 | */ | |
2334 | ||
2335 | /* eslint-disable */ | |
2336 | ||
2337 | // These values are established by empiricism with tests (tradeoff: performance VS precision) | |
2338 | var NEWTON_ITERATIONS = 4; | |
2339 | var NEWTON_MIN_SLOPE = 0.001; | |
2340 | var SUBDIVISION_PRECISION = 0.0000001; | |
2341 | var SUBDIVISION_MAX_ITERATIONS = 10; | |
2342 | ||
2343 | var kSplineTableSize = 11; | |
2344 | var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); | |
2345 | ||
2346 | var float32ArraySupported = typeof Float32Array === 'function'; | |
2347 | ||
2348 | function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } | |
2349 | function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } | |
2350 | function C (aA1) { return 3.0 * aA1; } | |
2351 | ||
2352 | // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | |
2353 | function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; } | |
2354 | ||
2355 | // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | |
2356 | function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } | |
2357 | ||
2358 | function binarySubdivide (aX, aA, aB, mX1, mX2) { | |
2359 | var currentX, currentT, i = 0; | |
2360 | do { | |
2361 | currentT = aA + (aB - aA) / 2.0; | |
2362 | currentX = calcBezier(currentT, mX1, mX2) - aX; | |
2363 | if (currentX > 0.0) { | |
2364 | aB = currentT; | |
2365 | } else { | |
2366 | aA = currentT; | |
2367 | } | |
2368 | } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); | |
2369 | return currentT; | |
2370 | } | |
2371 | ||
2372 | function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) { | |
2373 | for (var i = 0; i < NEWTON_ITERATIONS; ++i) { | |
2374 | var currentSlope = getSlope(aGuessT, mX1, mX2); | |
2375 | if (currentSlope === 0.0) { | |
2376 | return aGuessT; | |
2377 | } | |
2378 | var currentX = calcBezier(aGuessT, mX1, mX2) - aX; | |
2379 | aGuessT -= currentX / currentSlope; | |
2380 | } | |
2381 | return aGuessT; | |
2382 | } | |
2383 | ||
2384 | function bezier (mX1, mY1, mX2, mY2) { | |
2385 | if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { | |
2386 | throw new Error('bezier x values must be in [0, 1] range'); | |
2387 | } | |
2388 | ||
2389 | // Precompute samples table | |
2390 | var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); | |
2391 | if (mX1 !== mY1 || mX2 !== mY2) { | |
2392 | for (var i = 0; i < kSplineTableSize; ++i) { | |
2393 | sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); | |
2394 | } | |
2395 | } | |
2396 | ||
2397 | function getTForX (aX) { | |
2398 | var intervalStart = 0.0; | |
2399 | var currentSample = 1; | |
2400 | var lastSample = kSplineTableSize - 1; | |
2401 | ||
2402 | for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { | |
2403 | intervalStart += kSampleStepSize; | |
2404 | } | |
2405 | --currentSample; | |
2406 | ||
2407 | // Interpolate to provide an initial guess for t | |
2408 | var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); | |
2409 | var guessForT = intervalStart + dist * kSampleStepSize; | |
2410 | ||
2411 | var initialSlope = getSlope(guessForT, mX1, mX2); | |
2412 | if (initialSlope >= NEWTON_MIN_SLOPE) { | |
2413 | return newtonRaphsonIterate(aX, guessForT, mX1, mX2); | |
2414 | } else if (initialSlope === 0.0) { | |
2415 | return guessForT; | |
2416 | } else { | |
2417 | return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); | |
2418 | } | |
2419 | } | |
2420 | ||
2421 | return function BezierEasing (x) { | |
2422 | if (mX1 === mY1 && mX2 === mY2) { | |
2423 | return x; // linear | |
2424 | } | |
2425 | // Because JavaScript number are imprecise, we should guarantee the extremes are right. | |
2426 | if (x === 0) { | |
2427 | return 0; | |
2428 | } | |
2429 | if (x === 1) { | |
2430 | return 1; | |
2431 | } | |
2432 | return calcBezier(getTForX(x), mY1, mY2); | |
2433 | }; | |
2434 | } | |
2435 | ||
2436 | /* eslint no-control-regex: "off" */ | |
2437 | ||
2438 | // Remove Diacritics | |
2439 | var defaultDiacriticsRemovalap = [ | |
2440 | { base: 'A', letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F' }, | |
2441 | { base: 'AA', letters: '\uA732' }, | |
2442 | { base: 'AE', letters: '\u00C6\u01FC\u01E2' }, | |
2443 | { base: 'AO', letters: '\uA734' }, | |
2444 | { base: 'AU', letters: '\uA736' }, | |
2445 | { base: 'AV', letters: '\uA738\uA73A' }, | |
2446 | { base: 'AY', letters: '\uA73C' }, | |
2447 | { base: 'B', letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181' }, | |
2448 | { base: 'C', letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E' }, | |
2449 | { base: 'D', letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779' }, | |
2450 | { base: 'DZ', letters: '\u01F1\u01C4' }, | |
2451 | { base: 'Dz', letters: '\u01F2\u01C5' }, | |
2452 | { base: 'E', letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E' }, | |
2453 | { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' }, | |
2454 | { base: 'G', letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E' }, | |
2455 | { base: 'H', letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D' }, | |
2456 | { base: 'I', letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197' }, | |
2457 | { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' }, | |
2458 | { base: 'K', letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2' }, | |
2459 | { base: 'L', letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780' }, | |
2460 | { base: 'LJ', letters: '\u01C7' }, | |
2461 | { base: 'Lj', letters: '\u01C8' }, | |
2462 | { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' }, | |
2463 | { base: 'N', letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4' }, | |
2464 | { base: 'NJ', letters: '\u01CA' }, | |
2465 | { base: 'Nj', letters: '\u01CB' }, | |
2466 | { base: 'O', letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C' }, | |
2467 | { base: 'OI', letters: '\u01A2' }, | |
2468 | { base: 'OO', letters: '\uA74E' }, | |
2469 | { base: 'OU', letters: '\u0222' }, | |
2470 | { base: 'OE', letters: '\u008C\u0152' }, | |
2471 | { base: 'oe', letters: '\u009C\u0153' }, | |
2472 | { base: 'P', letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754' }, | |
2473 | { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' }, | |
2474 | { base: 'R', letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782' }, | |
2475 | { base: 'S', letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784' }, | |
2476 | { base: 'T', letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786' }, | |
2477 | { base: 'TZ', letters: '\uA728' }, | |
2478 | { base: 'U', letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244' }, | |
2479 | { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' }, | |
2480 | { base: 'VY', letters: '\uA760' }, | |
2481 | { base: 'W', letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72' }, | |
2482 | { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' }, | |
2483 | { base: 'Y', letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE' }, | |
2484 | { base: 'Z', letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762' }, | |
2485 | { base: 'a', letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250' }, | |
2486 | { base: 'aa', letters: '\uA733' }, | |
2487 | { base: 'ae', letters: '\u00E6\u01FD\u01E3' }, | |
2488 | { base: 'ao', letters: '\uA735' }, | |
2489 | { base: 'au', letters: '\uA737' }, | |
2490 | { base: 'av', letters: '\uA739\uA73B' }, | |
2491 | { base: 'ay', letters: '\uA73D' }, | |
2492 | { base: 'b', letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253' }, | |
2493 | { base: 'c', letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184' }, | |
2494 | { base: 'd', letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A' }, | |
2495 | { base: 'dz', letters: '\u01F3\u01C6' }, | |
2496 | { base: 'e', letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD' }, | |
2497 | { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' }, | |
2498 | { base: 'g', letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F' }, | |
2499 | { base: 'h', letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265' }, | |
2500 | { base: 'hv', letters: '\u0195' }, | |
2501 | { base: 'i', letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131' }, | |
2502 | { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' }, | |
2503 | { base: 'k', letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3' }, | |
2504 | { base: 'l', letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747' }, | |
2505 | { base: 'lj', letters: '\u01C9' }, | |
2506 | { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' }, | |
2507 | { base: 'n', letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5' }, | |
2508 | { base: 'nj', letters: '\u01CC' }, | |
2509 | { base: 'o', letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275' }, | |
2510 | { base: 'oi', letters: '\u01A3' }, | |
2511 | { base: 'ou', letters: '\u0223' }, | |
2512 | { base: 'oo', letters: '\uA74F' }, | |
2513 | { base: 'p', letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755' }, | |
2514 | { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' }, | |
2515 | { base: 'r', letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783' }, | |
2516 | { base: 's', letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B' }, | |
2517 | { base: 't', letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787' }, | |
2518 | { base: 'tz', letters: '\uA729' }, | |
2519 | { base: 'u', letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289' }, | |
2520 | { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' }, | |
2521 | { base: 'vy', letters: '\uA761' }, | |
2522 | { base: 'w', letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73' }, | |
2523 | { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' }, | |
2524 | { base: 'y', letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF' }, | |
2525 | { base: 'z', letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763' } ]; | |
2526 | ||
2527 | var diacriticsMap = {}; | |
2528 | for (var i = 0; i < defaultDiacriticsRemovalap.length; i += 1) { | |
2529 | var letters = defaultDiacriticsRemovalap[i].letters; | |
2530 | for (var j = 0; j < letters.length; j += 1) { | |
2531 | diacriticsMap[letters[j]] = defaultDiacriticsRemovalap[i].base; | |
2532 | } | |
2533 | } | |
2534 | ||
2535 | var uniqueNumber = 1; | |
2536 | ||
2537 | var Utils = { | |
2538 | uniqueNumber: function uniqueNumber$1() { | |
2539 | uniqueNumber += 1; | |
2540 | return uniqueNumber; | |
2541 | }, | |
2542 | id: function id(mask, map) { | |
2543 | if ( mask === void 0 ) mask = 'xxxxxxxxxx'; | |
2544 | if ( map === void 0 ) map = '0123456789abcdef'; | |
2545 | ||
2546 | var length = map.length; | |
2547 | return mask.replace(/x/g, function () { return map[Math.floor((Math.random() * length))]; }); | |
2548 | }, | |
2549 | mdPreloaderContent: "\n <span class=\"preloader-inner\">\n <span class=\"preloader-inner-gap\"></span>\n <span class=\"preloader-inner-left\">\n <span class=\"preloader-inner-half-circle\"></span>\n </span>\n <span class=\"preloader-inner-right\">\n <span class=\"preloader-inner-half-circle\"></span>\n </span>\n </span>\n ".trim(), | |
5d51ea26 DC |
2550 | iosPreloaderContent: ("\n <span class=\"preloader-inner\">\n " + ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(function () { return '<span class="preloader-inner-line"></span>'; }).join('')) + "\n </span>\n ").trim(), |
2551 | auroraPreloaderContent: "\n <span class=\"preloader-inner\">\n <span class=\"preloader-inner-circle\"></span>\n </span>\n ", | |
5309fbda DC |
2552 | eventNameToColonCase: function eventNameToColonCase(eventName) { |
2553 | var hasColon; | |
2554 | return eventName.split('').map(function (char, index) { | |
2555 | if (char.match(/[A-Z]/) && index !== 0 && !hasColon) { | |
2556 | hasColon = true; | |
2557 | return (":" + (char.toLowerCase())); | |
2558 | } | |
2559 | return char.toLowerCase(); | |
2560 | }).join(''); | |
2561 | }, | |
2562 | deleteProps: function deleteProps(obj) { | |
2563 | var object = obj; | |
2564 | Object.keys(object).forEach(function (key) { | |
2565 | try { | |
2566 | object[key] = null; | |
2567 | } catch (e) { | |
2568 | // no setter for object | |
2569 | } | |
2570 | try { | |
2571 | delete object[key]; | |
2572 | } catch (e) { | |
2573 | // something got wrong | |
2574 | } | |
2575 | }); | |
2576 | }, | |
2577 | bezier: function bezier$1() { | |
2578 | var args = [], len = arguments.length; | |
2579 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2580 | ||
2581 | return bezier.apply(void 0, args); | |
2582 | }, | |
2583 | nextTick: function nextTick(callback, delay) { | |
2584 | if ( delay === void 0 ) delay = 0; | |
2585 | ||
2586 | return setTimeout(callback, delay); | |
2587 | }, | |
2588 | nextFrame: function nextFrame(callback) { | |
2589 | return Utils.requestAnimationFrame(function () { | |
2590 | Utils.requestAnimationFrame(callback); | |
2591 | }); | |
2592 | }, | |
2593 | now: function now() { | |
2594 | return Date.now(); | |
2595 | }, | |
2596 | requestAnimationFrame: function requestAnimationFrame(callback) { | |
2597 | return win.requestAnimationFrame(callback); | |
2598 | }, | |
2599 | cancelAnimationFrame: function cancelAnimationFrame(id) { | |
2600 | return win.cancelAnimationFrame(id); | |
2601 | }, | |
2602 | removeDiacritics: function removeDiacritics(str) { | |
2603 | return str.replace(/[^\u0000-\u007E]/g, function (a) { return diacriticsMap[a] || a; }); | |
2604 | }, | |
2605 | parseUrlQuery: function parseUrlQuery(url) { | |
2606 | var query = {}; | |
2607 | var urlToParse = url || win.location.href; | |
2608 | var i; | |
2609 | var params; | |
2610 | var param; | |
2611 | var length; | |
2612 | if (typeof urlToParse === 'string' && urlToParse.length) { | |
2613 | urlToParse = urlToParse.indexOf('?') > -1 ? urlToParse.replace(/\S*\?/, '') : ''; | |
2614 | params = urlToParse.split('&').filter(function (paramsPart) { return paramsPart !== ''; }); | |
2615 | length = params.length; | |
2616 | ||
2617 | for (i = 0; i < length; i += 1) { | |
2618 | param = params[i].replace(/#\S+/g, '').split('='); | |
2619 | query[decodeURIComponent(param[0])] = typeof param[1] === 'undefined' ? undefined : decodeURIComponent(param.slice(1).join('=')) || ''; | |
2620 | } | |
2621 | } | |
2622 | return query; | |
2623 | }, | |
2624 | getTranslate: function getTranslate(el, axis) { | |
2625 | if ( axis === void 0 ) axis = 'x'; | |
2626 | ||
2627 | var matrix; | |
2628 | var curTransform; | |
2629 | var transformMatrix; | |
2630 | ||
2631 | var curStyle = win.getComputedStyle(el, null); | |
2632 | ||
2633 | if (win.WebKitCSSMatrix) { | |
2634 | curTransform = curStyle.transform || curStyle.webkitTransform; | |
2635 | if (curTransform.split(',').length > 6) { | |
2636 | curTransform = curTransform.split(', ').map(function (a) { return a.replace(',', '.'); }).join(', '); | |
2637 | } | |
2638 | // Some old versions of Webkit choke when 'none' is passed; pass | |
2639 | // empty string instead in this case | |
2640 | transformMatrix = new win.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform); | |
2641 | } else { | |
2642 | transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); | |
2643 | matrix = transformMatrix.toString().split(','); | |
2644 | } | |
2645 | ||
2646 | if (axis === 'x') { | |
2647 | // Latest Chrome and webkits Fix | |
2648 | if (win.WebKitCSSMatrix) { curTransform = transformMatrix.m41; } | |
2649 | // Crazy IE10 Matrix | |
2650 | else if (matrix.length === 16) { curTransform = parseFloat(matrix[12]); } | |
2651 | // Normal Browsers | |
2652 | else { curTransform = parseFloat(matrix[4]); } | |
2653 | } | |
2654 | if (axis === 'y') { | |
2655 | // Latest Chrome and webkits Fix | |
2656 | if (win.WebKitCSSMatrix) { curTransform = transformMatrix.m42; } | |
2657 | // Crazy IE10 Matrix | |
2658 | else if (matrix.length === 16) { curTransform = parseFloat(matrix[13]); } | |
2659 | // Normal Browsers | |
2660 | else { curTransform = parseFloat(matrix[5]); } | |
2661 | } | |
2662 | return curTransform || 0; | |
2663 | }, | |
2664 | serializeObject: function serializeObject(obj, parents) { | |
2665 | if ( parents === void 0 ) parents = []; | |
2666 | ||
2667 | if (typeof obj === 'string') { return obj; } | |
2668 | var resultArray = []; | |
2669 | var separator = '&'; | |
2670 | var newParents; | |
2671 | function varName(name) { | |
2672 | if (parents.length > 0) { | |
2673 | var parentParts = ''; | |
2674 | for (var j = 0; j < parents.length; j += 1) { | |
2675 | if (j === 0) { parentParts += parents[j]; } | |
2676 | else { parentParts += "[" + (encodeURIComponent(parents[j])) + "]"; } | |
2677 | } | |
2678 | return (parentParts + "[" + (encodeURIComponent(name)) + "]"); | |
2679 | } | |
2680 | return encodeURIComponent(name); | |
2681 | } | |
2682 | function varValue(value) { | |
2683 | return encodeURIComponent(value); | |
2684 | } | |
2685 | Object.keys(obj).forEach(function (prop) { | |
2686 | var toPush; | |
2687 | if (Array.isArray(obj[prop])) { | |
2688 | toPush = []; | |
2689 | for (var i = 0; i < obj[prop].length; i += 1) { | |
2690 | if (!Array.isArray(obj[prop][i]) && typeof obj[prop][i] === 'object') { | |
2691 | newParents = parents.slice(); | |
2692 | newParents.push(prop); | |
2693 | newParents.push(String(i)); | |
2694 | toPush.push(Utils.serializeObject(obj[prop][i], newParents)); | |
2695 | } else { | |
2696 | toPush.push(((varName(prop)) + "[]=" + (varValue(obj[prop][i])))); | |
2697 | } | |
2698 | } | |
2699 | if (toPush.length > 0) { resultArray.push(toPush.join(separator)); } | |
2700 | } else if (obj[prop] === null || obj[prop] === '') { | |
2701 | resultArray.push(((varName(prop)) + "=")); | |
2702 | } else if (typeof obj[prop] === 'object') { | |
2703 | // Object, convert to named array | |
2704 | newParents = parents.slice(); | |
2705 | newParents.push(prop); | |
2706 | toPush = Utils.serializeObject(obj[prop], newParents); | |
2707 | if (toPush !== '') { resultArray.push(toPush); } | |
2708 | } else if (typeof obj[prop] !== 'undefined' && obj[prop] !== '') { | |
2709 | // Should be string or plain value | |
2710 | resultArray.push(((varName(prop)) + "=" + (varValue(obj[prop])))); | |
2711 | } else if (obj[prop] === '') { resultArray.push(varName(prop)); } | |
2712 | }); | |
2713 | return resultArray.join(separator); | |
2714 | }, | |
2715 | isObject: function isObject(o) { | |
2716 | return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object; | |
2717 | }, | |
2718 | merge: function merge() { | |
2719 | var args = [], len$1 = arguments.length; | |
2720 | while ( len$1-- ) args[ len$1 ] = arguments[ len$1 ]; | |
2721 | ||
2722 | var to = args[0]; | |
2723 | args.splice(0, 1); | |
2724 | var from = args; | |
2725 | ||
2726 | for (var i = 0; i < from.length; i += 1) { | |
2727 | var nextSource = args[i]; | |
2728 | if (nextSource !== undefined && nextSource !== null) { | |
2729 | var keysArray = Object.keys(Object(nextSource)); | |
2730 | for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) { | |
2731 | var nextKey = keysArray[nextIndex]; | |
2732 | var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); | |
2733 | if (desc !== undefined && desc.enumerable) { | |
2734 | to[nextKey] = nextSource[nextKey]; | |
2735 | } | |
2736 | } | |
2737 | } | |
2738 | } | |
2739 | return to; | |
2740 | }, | |
2741 | extend: function extend() { | |
2742 | var args = [], len$1 = arguments.length; | |
2743 | while ( len$1-- ) args[ len$1 ] = arguments[ len$1 ]; | |
2744 | ||
2745 | var deep = true; | |
2746 | var to; | |
2747 | var from; | |
2748 | if (typeof args[0] === 'boolean') { | |
2749 | deep = args[0]; | |
2750 | to = args[1]; | |
2751 | args.splice(0, 2); | |
2752 | from = args; | |
2753 | } else { | |
2754 | to = args[0]; | |
2755 | args.splice(0, 1); | |
2756 | from = args; | |
2757 | } | |
2758 | for (var i = 0; i < from.length; i += 1) { | |
2759 | var nextSource = args[i]; | |
2760 | if (nextSource !== undefined && nextSource !== null) { | |
2761 | var keysArray = Object.keys(Object(nextSource)); | |
2762 | for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) { | |
2763 | var nextKey = keysArray[nextIndex]; | |
2764 | var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); | |
2765 | if (desc !== undefined && desc.enumerable) { | |
2766 | if (!deep) { | |
2767 | to[nextKey] = nextSource[nextKey]; | |
2768 | } else if (Utils.isObject(to[nextKey]) && Utils.isObject(nextSource[nextKey])) { | |
2769 | Utils.extend(to[nextKey], nextSource[nextKey]); | |
2770 | } else if (!Utils.isObject(to[nextKey]) && Utils.isObject(nextSource[nextKey])) { | |
2771 | to[nextKey] = {}; | |
2772 | Utils.extend(to[nextKey], nextSource[nextKey]); | |
2773 | } else { | |
2774 | to[nextKey] = nextSource[nextKey]; | |
2775 | } | |
2776 | } | |
2777 | } | |
2778 | } | |
2779 | } | |
2780 | return to; | |
2781 | }, | |
2782 | colorHexToRgb: function colorHexToRgb(hex) { | |
2783 | var h = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) { return r + r + g + g + b + b; }); | |
2784 | var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(h); | |
2785 | return result | |
2786 | ? result.slice(1).map(function (n) { return parseInt(n, 16); }) | |
2787 | : null; | |
2788 | }, | |
2789 | colorRgbToHex: function colorRgbToHex(r, g, b) { | |
2790 | var result = [r, g, b].map(function (n) { | |
2791 | var hex = n.toString(16); | |
2792 | return hex.length === 1 ? ("0" + hex) : hex; | |
2793 | }).join(''); | |
2794 | return ("#" + result); | |
2795 | }, | |
2796 | colorRgbToHsl: function colorRgbToHsl(r, g, b) { | |
2797 | r /= 255; // eslint-disable-line | |
2798 | g /= 255; // eslint-disable-line | |
2799 | b /= 255; // eslint-disable-line | |
2800 | var max = Math.max(r, g, b); | |
2801 | var min = Math.min(r, g, b); | |
2802 | var d = max - min; | |
2803 | var h; | |
2804 | if (d === 0) { h = 0; } | |
2805 | else if (max === r) { h = ((g - b) / d) % 6; } | |
2806 | else if (max === g) { h = (b - r) / d + 2; } | |
2807 | else if (max === b) { h = (r - g) / d + 4; } | |
2808 | var l = (min + max) / 2; | |
2809 | var s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1)); | |
5d51ea26 | 2810 | if (h < 0) { h = 360 / 60 + h; } |
5309fbda DC |
2811 | return [h * 60, s, l]; |
2812 | }, | |
2813 | colorHslToRgb: function colorHslToRgb(h, s, l) { | |
2814 | var c = (1 - Math.abs(2 * l - 1)) * s; | |
2815 | var hp = h / 60; | |
2816 | var x = c * (1 - Math.abs((hp % 2) - 1)); | |
2817 | var rgb1; | |
2818 | if (Number.isNaN(h) || typeof h === 'undefined') { | |
2819 | rgb1 = [0, 0, 0]; | |
2820 | } else if (hp <= 1) { rgb1 = [c, x, 0]; } | |
2821 | else if (hp <= 2) { rgb1 = [x, c, 0]; } | |
2822 | else if (hp <= 3) { rgb1 = [0, c, x]; } | |
2823 | else if (hp <= 4) { rgb1 = [0, x, c]; } | |
2824 | else if (hp <= 5) { rgb1 = [x, 0, c]; } | |
2825 | else if (hp <= 6) { rgb1 = [c, 0, x]; } | |
2826 | var m = l - (c / 2); | |
2827 | return rgb1.map(function (n) { return Math.max(0, Math.min(255, Math.round(255 * (n + m)))); }); | |
2828 | }, | |
5d51ea26 DC |
2829 | colorHsbToHsl: function colorHsbToHsl(h, s, b) { |
2830 | var HSL = { | |
2831 | h: h, | |
2832 | s: 0, | |
2833 | l: 0, | |
2834 | }; | |
2835 | var HSB = { h: h, s: s, b: b }; | |
2836 | ||
2837 | HSL.l = (2 - HSB.s) * HSB.b / 2; | |
2838 | HSL.s = HSL.l && HSL.l < 1 ? HSB.s * HSB.b / (HSL.l < 0.5 ? HSL.l * 2 : 2 - HSL.l * 2) : HSL.s; | |
2839 | ||
2840 | return [HSL.h, HSL.s, HSL.l]; | |
2841 | }, | |
2842 | colorHslToHsb: function colorHslToHsb(h, s, l) { | |
2843 | var HSB = { | |
2844 | h: h, | |
2845 | s: 0, | |
2846 | b: 0, | |
2847 | }; | |
2848 | var HSL = { h: h, s: s, l: l }; | |
2849 | ||
2850 | var t = HSL.s * (HSL.l < 0.5 ? HSL.l : 1 - HSL.l); | |
2851 | HSB.b = HSL.l + t; | |
2852 | HSB.s = HSL.l > 0 ? 2 * t / HSB.b : HSB.s; | |
2853 | ||
2854 | return [HSB.h, HSB.s, HSB.b]; | |
2855 | }, | |
5309fbda DC |
2856 | colorThemeCSSProperties: function colorThemeCSSProperties() { |
2857 | var args = [], len = arguments.length; | |
2858 | while ( len-- ) args[ len ] = arguments[ len ]; | |
2859 | ||
2860 | var hex; | |
2861 | var rgb; | |
2862 | if (args.length === 1) { | |
2863 | hex = args[0]; | |
2864 | rgb = Utils.colorHexToRgb(hex); | |
2865 | } else if (args.length === 3) { | |
2866 | rgb = args; | |
2867 | hex = Utils.colorRgbToHex.apply(Utils, rgb); | |
2868 | } | |
2869 | if (!rgb) { return {}; } | |
2870 | var hsl = Utils.colorRgbToHsl.apply(Utils, rgb); | |
2871 | var hslShade = [hsl[0], hsl[1], Math.max(0, (hsl[2] - 0.08))]; | |
2872 | var hslTint = [hsl[0], hsl[1], Math.max(0, (hsl[2] + 0.08))]; | |
2873 | var shade = Utils.colorRgbToHex.apply(Utils, Utils.colorHslToRgb.apply(Utils, hslShade)); | |
2874 | var tint = Utils.colorRgbToHex.apply(Utils, Utils.colorHslToRgb.apply(Utils, hslTint)); | |
2875 | return { | |
2876 | '--f7-theme-color': hex, | |
2877 | '--f7-theme-color-rgb': rgb.join(', '), | |
2878 | '--f7-theme-color-shade': shade, | |
2879 | '--f7-theme-color-tint': tint, | |
2880 | }; | |
2881 | }, | |
2882 | }; | |
2883 | ||
5d51ea26 DC |
2884 | var Support = (function Support() { |
2885 | var testDiv = doc.createElement('div'); | |
2886 | ||
2887 | return { | |
2888 | touch: (function checkTouch() { | |
2889 | return !!((win.navigator.maxTouchPoints > 0) || ('ontouchstart' in win) || (win.DocumentTouch && doc instanceof win.DocumentTouch)); | |
2890 | }()), | |
2891 | ||
2892 | pointerEvents: !!(win.navigator.pointerEnabled || win.PointerEvent || ('maxTouchPoints' in win.navigator && win.navigator.maxTouchPoints > 0)), | |
2893 | prefixedPointerEvents: !!win.navigator.msPointerEnabled, | |
2894 | ||
2895 | transition: (function checkTransition() { | |
2896 | var style = testDiv.style; | |
2897 | return ('transition' in style || 'webkitTransition' in style || 'MozTransition' in style); | |
2898 | }()), | |
2899 | transforms3d: (win.Modernizr && win.Modernizr.csstransforms3d === true) || (function checkTransforms3d() { | |
2900 | var style = testDiv.style; | |
2901 | return ('webkitPerspective' in style || 'MozPerspective' in style || 'OPerspective' in style || 'MsPerspective' in style || 'perspective' in style); | |
2902 | }()), | |
2903 | ||
2904 | flexbox: (function checkFlexbox() { | |
2905 | var div = doc.createElement('div').style; | |
2906 | var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' '); | |
2907 | for (var i = 0; i < styles.length; i += 1) { | |
2908 | if (styles[i] in div) { return true; } | |
2909 | } | |
2910 | return false; | |
2911 | }()), | |
2912 | ||
2913 | observer: (function checkObserver() { | |
2914 | return ('MutationObserver' in win || 'WebkitMutationObserver' in win); | |
2915 | }()), | |
2916 | ||
2917 | passiveListener: (function checkPassiveListener() { | |
2918 | var supportsPassive = false; | |
2919 | try { | |
2920 | var opts = Object.defineProperty({}, 'passive', { | |
2921 | // eslint-disable-next-line | |
2922 | get: function get() { | |
2923 | supportsPassive = true; | |
2924 | }, | |
2925 | }); | |
2926 | win.addEventListener('testPassiveListener', null, opts); | |
2927 | } catch (e) { | |
2928 | // No support | |
2929 | } | |
2930 | return supportsPassive; | |
2931 | }()), | |
2932 | ||
2933 | gestures: (function checkGestures() { | |
2934 | return 'ongesturestart' in win; | |
2935 | }()), | |
2936 | ||
2937 | intersectionObserver: (function checkObserver() { | |
2938 | return ('IntersectionObserver' in win); | |
2939 | }()), | |
2940 | }; | |
2941 | }()); | |
2942 | ||
5309fbda DC |
2943 | var Device = (function Device() { |
2944 | var platform = win.navigator.platform; | |
2945 | var ua = win.navigator.userAgent; | |
2946 | ||
2947 | var device = { | |
2948 | ios: false, | |
2949 | android: false, | |
2950 | androidChrome: false, | |
2951 | desktop: false, | |
2952 | windowsPhone: false, | |
2953 | iphone: false, | |
2954 | iphoneX: false, | |
2955 | ipod: false, | |
2956 | ipad: false, | |
2957 | edge: false, | |
2958 | ie: false, | |
2959 | firefox: false, | |
2960 | macos: false, | |
2961 | windows: false, | |
2962 | cordova: !!(win.cordova || win.phonegap), | |
2963 | phonegap: !!(win.cordova || win.phonegap), | |
5d51ea26 | 2964 | electron: false, |
5309fbda DC |
2965 | }; |
2966 | ||
2967 | var screenWidth = win.screen.width; | |
2968 | var screenHeight = win.screen.height; | |
2969 | ||
2970 | var windowsPhone = ua.match(/(Windows Phone);?[\s\/]+([\d.]+)?/); // eslint-disable-line | |
2971 | var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line | |
2972 | var ipad = ua.match(/(iPad).*OS\s([\d_]+)/); | |
2973 | var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); | |
2974 | var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); | |
2975 | var iphoneX = iphone && ( | |
2976 | (screenWidth === 375 && screenHeight === 812) // X/XS | |
2977 | || (screenWidth === 414 && screenHeight === 896) // XR / XS Max | |
2978 | ); | |
2979 | var ie = ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0; | |
2980 | var edge = ua.indexOf('Edge/') >= 0; | |
2981 | var firefox = ua.indexOf('Gecko/') >= 0 && ua.indexOf('Firefox/') >= 0; | |
5309fbda | 2982 | var windows = platform === 'Win32'; |
5d51ea26 DC |
2983 | var electron = ua.toLowerCase().indexOf('electron') >= 0; |
2984 | var macos = platform === 'MacIntel'; | |
2985 | ||
2986 | // iPadOs 13 fix | |
2987 | if (!ipad | |
2988 | && macos | |
2989 | && Support.touch | |
2990 | && ( | |
2991 | (screenWidth === 1024 && screenHeight === 1366) // Pro 12.9 | |
2992 | || (screenWidth === 834 && screenHeight === 1194) // Pro 11 | |
2993 | || (screenWidth === 834 && screenHeight === 1112) // Pro 10.5 | |
2994 | || (screenWidth === 768 && screenHeight === 1024) // other | |
2995 | ) | |
2996 | ) { | |
2997 | ipad = ua.match(/(Version)\/([\d.]+)/); | |
2998 | macos = false; | |
2999 | } | |
5309fbda DC |
3000 | |
3001 | device.ie = ie; | |
3002 | device.edge = edge; | |
3003 | device.firefox = firefox; | |
3004 | ||
3005 | // Windows | |
3006 | if (windowsPhone) { | |
5d51ea26 | 3007 | device.os = 'windowsPhone'; |
5309fbda DC |
3008 | device.osVersion = windowsPhone[2]; |
3009 | device.windowsPhone = true; | |
3010 | } | |
3011 | // Android | |
3012 | if (android && !windows) { | |
3013 | device.os = 'android'; | |
3014 | device.osVersion = android[2]; | |
3015 | device.android = true; | |
3016 | device.androidChrome = ua.toLowerCase().indexOf('chrome') >= 0; | |
3017 | } | |
3018 | if (ipad || iphone || ipod) { | |
3019 | device.os = 'ios'; | |
3020 | device.ios = true; | |
3021 | } | |
3022 | // iOS | |
3023 | if (iphone && !ipod) { | |
3024 | device.osVersion = iphone[2].replace(/_/g, '.'); | |
3025 | device.iphone = true; | |
3026 | device.iphoneX = iphoneX; | |
3027 | } | |
3028 | if (ipad) { | |
3029 | device.osVersion = ipad[2].replace(/_/g, '.'); | |
3030 | device.ipad = true; | |
3031 | } | |
3032 | if (ipod) { | |
3033 | device.osVersion = ipod[3] ? ipod[3].replace(/_/g, '.') : null; | |
5d51ea26 | 3034 | device.ipod = true; |
5309fbda DC |
3035 | } |
3036 | // iOS 8+ changed UA | |
3037 | if (device.ios && device.osVersion && ua.indexOf('Version/') >= 0) { | |
3038 | if (device.osVersion.split('.')[0] === '10') { | |
3039 | device.osVersion = ua.toLowerCase().split('version/')[1].split(' ')[0]; | |
3040 | } | |
3041 | } | |
3042 | ||
3043 | // Webview | |
3044 | device.webView = !!((iphone || ipad || ipod) && (ua.match(/.*AppleWebKit(?!.*Safari)/i) || win.navigator.standalone)) | |
3045 | || (win.matchMedia && win.matchMedia('(display-mode: standalone)').matches); | |
3046 | device.webview = device.webView; | |
3047 | device.standalone = device.webView; | |
3048 | ||
3049 | // Desktop | |
5d51ea26 | 3050 | device.desktop = !(device.ios || device.android || device.windowsPhone) || electron; |
5309fbda | 3051 | if (device.desktop) { |
5d51ea26 | 3052 | device.electron = electron; |
5309fbda DC |
3053 | device.macos = macos; |
3054 | device.windows = windows; | |
3055 | } | |
3056 | ||
5309fbda DC |
3057 | // Meta statusbar |
3058 | var metaStatusbar = doc.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]'); | |
3059 | ||
3060 | // Check for status bar and fullscreen app mode | |
3061 | device.needsStatusbarOverlay = function needsStatusbarOverlay() { | |
5d51ea26 | 3062 | if (device.desktop) { return false; } |
5309fbda DC |
3063 | if (device.standalone && device.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') { |
3064 | return true; | |
3065 | } | |
3066 | if ((device.webView || (device.android && device.cordova)) && (win.innerWidth * win.innerHeight === win.screen.width * win.screen.height)) { | |
3067 | if (device.iphoneX && (win.orientation === 90 || win.orientation === -90)) { | |
3068 | return false; | |
3069 | } | |
3070 | return true; | |
3071 | } | |
3072 | return false; | |
3073 | }; | |
3074 | device.statusbar = device.needsStatusbarOverlay(); | |
3075 | ||
3076 | // Pixel Ratio | |
3077 | device.pixelRatio = win.devicePixelRatio || 1; | |
3078 | ||
5d51ea26 DC |
3079 | // Color Scheme |
3080 | var DARK = '(prefers-color-scheme: dark)'; | |
3081 | var LIGHT = '(prefers-color-scheme: light)'; | |
3082 | device.prefersColorScheme = function prefersColorTheme() { | |
3083 | var theme; | |
3084 | if (win.matchMedia && win.matchMedia(LIGHT).matches) { | |
3085 | theme = 'light'; | |
3086 | } | |
3087 | if (win.matchMedia && win.matchMedia(DARK).matches) { | |
3088 | theme = 'dark'; | |
3089 | } | |
3090 | return theme; | |
3091 | }; | |
3092 | ||
5309fbda DC |
3093 | // Export object |
3094 | return device; | |
3095 | }()); | |
3096 | ||
3097 | var EventsClass = function EventsClass(parents) { | |
3098 | if ( parents === void 0 ) parents = []; | |
3099 | ||
3100 | var self = this; | |
3101 | self.eventsParents = parents; | |
3102 | self.eventsListeners = {}; | |
3103 | }; | |
3104 | ||
3105 | EventsClass.prototype.on = function on (events, handler, priority) { | |
3106 | var self = this; | |
3107 | if (typeof handler !== 'function') { return self; } | |
3108 | var method = priority ? 'unshift' : 'push'; | |
3109 | events.split(' ').forEach(function (event) { | |
3110 | if (!self.eventsListeners[event]) { self.eventsListeners[event] = []; } | |
3111 | self.eventsListeners[event][method](handler); | |
3112 | }); | |
3113 | return self; | |
3114 | }; | |
3115 | ||
3116 | EventsClass.prototype.once = function once (events, handler, priority) { | |
3117 | var self = this; | |
3118 | if (typeof handler !== 'function') { return self; } | |
3119 | function onceHandler() { | |
3120 | var args = [], len = arguments.length; | |
3121 | while ( len-- ) args[ len ] = arguments[ len ]; | |
3122 | ||
3123 | handler.apply(self, args); | |
3124 | self.off(events, onceHandler); | |
3125 | if (onceHandler.f7proxy) { | |
3126 | delete onceHandler.f7proxy; | |
3127 | } | |
3128 | } | |
3129 | onceHandler.f7proxy = handler; | |
3130 | return self.on(events, onceHandler, priority); | |
3131 | }; | |
3132 | ||
3133 | EventsClass.prototype.off = function off (events, handler) { | |
3134 | var self = this; | |
3135 | if (!self.eventsListeners) { return self; } | |
3136 | events.split(' ').forEach(function (event) { | |
3137 | if (typeof handler === 'undefined') { | |
3138 | self.eventsListeners[event] = []; | |
3139 | } else if (self.eventsListeners[event]) { | |
3140 | self.eventsListeners[event].forEach(function (eventHandler, index) { | |
3141 | if (eventHandler === handler || (eventHandler.f7proxy && eventHandler.f7proxy === handler)) { | |
3142 | self.eventsListeners[event].splice(index, 1); | |
3143 | } | |
3144 | }); | |
3145 | } | |
3146 | }); | |
3147 | return self; | |
3148 | }; | |
3149 | ||
3150 | EventsClass.prototype.emit = function emit () { | |
3151 | var args = [], len = arguments.length; | |
3152 | while ( len-- ) args[ len ] = arguments[ len ]; | |
3153 | ||
3154 | var self = this; | |
3155 | if (!self.eventsListeners) { return self; } | |
3156 | var events; | |
3157 | var data; | |
3158 | var context; | |
3159 | var eventsParents; | |
3160 | if (typeof args[0] === 'string' || Array.isArray(args[0])) { | |
3161 | events = args[0]; | |
3162 | data = args.slice(1, args.length); | |
3163 | context = self; | |
3164 | eventsParents = self.eventsParents; | |
3165 | } else { | |
3166 | events = args[0].events; | |
3167 | data = args[0].data; | |
3168 | context = args[0].context || self; | |
3169 | eventsParents = args[0].local ? [] : args[0].parents || self.eventsParents; | |
3170 | } | |
3171 | var eventsArray = Array.isArray(events) ? events : events.split(' '); | |
3172 | var localEvents = eventsArray.map(function (eventName) { return eventName.replace('local::', ''); }); | |
3173 | var parentEvents = eventsArray.filter(function (eventName) { return eventName.indexOf('local::') < 0; }); | |
3174 | ||
3175 | localEvents.forEach(function (event) { | |
3176 | if (self.eventsListeners && self.eventsListeners[event]) { | |
3177 | var handlers = []; | |
3178 | self.eventsListeners[event].forEach(function (eventHandler) { | |
3179 | handlers.push(eventHandler); | |
3180 | }); | |
3181 | handlers.forEach(function (eventHandler) { | |
3182 | eventHandler.apply(context, data); | |
3183 | }); | |
3184 | } | |
3185 | }); | |
3186 | if (eventsParents && eventsParents.length > 0) { | |
3187 | eventsParents.forEach(function (eventsParent) { | |
3188 | eventsParent.emit.apply(eventsParent, [ parentEvents ].concat( data )); | |
3189 | }); | |
3190 | } | |
3191 | return self; | |
3192 | }; | |
3193 | ||
5d51ea26 | 3194 | var Framework7Class = /*@__PURE__*/(function (EventsClass) { |
5309fbda DC |
3195 | function Framework7Class(params, parents) { |
3196 | if ( params === void 0 ) params = {}; | |
3197 | if ( parents === void 0 ) parents = []; | |
3198 | ||
5d51ea26 | 3199 | EventsClass.call(this, parents); |
5309fbda DC |
3200 | var self = this; |
3201 | self.params = params; | |
3202 | ||
3203 | if (self.params && self.params.on) { | |
3204 | Object.keys(self.params.on).forEach(function (eventName) { | |
3205 | self.on(eventName, self.params.on[eventName]); | |
3206 | }); | |
3207 | } | |
3208 | } | |
3209 | ||
5d51ea26 DC |
3210 | if ( EventsClass ) Framework7Class.__proto__ = EventsClass; |
3211 | Framework7Class.prototype = Object.create( EventsClass && EventsClass.prototype ); | |
5309fbda DC |
3212 | Framework7Class.prototype.constructor = Framework7Class; |
3213 | ||
3214 | var staticAccessors = { components: { configurable: true } }; | |
3215 | ||
3216 | // eslint-disable-next-line | |
3217 | Framework7Class.prototype.useModuleParams = function useModuleParams (module, instanceParams) { | |
3218 | if (module.params) { | |
3219 | var originalParams = {}; | |
3220 | Object.keys(module.params).forEach(function (paramKey) { | |
3221 | if (typeof instanceParams[paramKey] === 'undefined') { return; } | |
3222 | originalParams[paramKey] = Utils.extend({}, instanceParams[paramKey]); | |
3223 | }); | |
3224 | Utils.extend(instanceParams, module.params); | |
3225 | Object.keys(originalParams).forEach(function (paramKey) { | |
3226 | Utils.extend(instanceParams[paramKey], originalParams[paramKey]); | |
3227 | }); | |
3228 | } | |
3229 | }; | |
3230 | ||
3231 | Framework7Class.prototype.useModulesParams = function useModulesParams (instanceParams) { | |
3232 | var instance = this; | |
3233 | if (!instance.modules) { return; } | |
3234 | Object.keys(instance.modules).forEach(function (moduleName) { | |
3235 | var module = instance.modules[moduleName]; | |
3236 | // Extend params | |
3237 | if (module.params) { | |
3238 | Utils.extend(instanceParams, module.params); | |
3239 | } | |
3240 | }); | |
3241 | }; | |
3242 | ||
3243 | Framework7Class.prototype.useModule = function useModule (moduleName, moduleParams) { | |
3244 | if ( moduleName === void 0 ) moduleName = ''; | |
3245 | if ( moduleParams === void 0 ) moduleParams = {}; | |
3246 | ||
3247 | var instance = this; | |
3248 | if (!instance.modules) { return; } | |
3249 | var module = typeof moduleName === 'string' ? instance.modules[moduleName] : moduleName; | |
3250 | if (!module) { return; } | |
3251 | ||
3252 | // Extend instance methods and props | |
3253 | if (module.instance) { | |
3254 | Object.keys(module.instance).forEach(function (modulePropName) { | |
3255 | var moduleProp = module.instance[modulePropName]; | |
3256 | if (typeof moduleProp === 'function') { | |
3257 | instance[modulePropName] = moduleProp.bind(instance); | |
3258 | } else { | |
3259 | instance[modulePropName] = moduleProp; | |
3260 | } | |
3261 | }); | |
3262 | } | |
3263 | // Add event listeners | |
3264 | if (module.on && instance.on) { | |
3265 | Object.keys(module.on).forEach(function (moduleEventName) { | |
3266 | instance.on(moduleEventName, module.on[moduleEventName]); | |
3267 | }); | |
3268 | } | |
3269 | // Add vnode hooks | |
3270 | if (module.vnode) { | |
3271 | if (!instance.vnodeHooks) { instance.vnodeHooks = {}; } | |
3272 | Object.keys(module.vnode).forEach(function (vnodeId) { | |
3273 | Object.keys(module.vnode[vnodeId]).forEach(function (hookName) { | |
3274 | var handler = module.vnode[vnodeId][hookName]; | |
3275 | if (!instance.vnodeHooks[hookName]) { instance.vnodeHooks[hookName] = {}; } | |
3276 | if (!instance.vnodeHooks[hookName][vnodeId]) { instance.vnodeHooks[hookName][vnodeId] = []; } | |
3277 | instance.vnodeHooks[hookName][vnodeId].push(handler.bind(instance)); | |
3278 | }); | |
3279 | }); | |
3280 | } | |
3281 | // Module create callback | |
3282 | if (module.create) { | |
3283 | module.create.bind(instance)(moduleParams); | |
3284 | } | |
3285 | }; | |
3286 | ||
3287 | Framework7Class.prototype.useModules = function useModules (modulesParams) { | |
3288 | if ( modulesParams === void 0 ) modulesParams = {}; | |
3289 | ||
3290 | var instance = this; | |
3291 | if (!instance.modules) { return; } | |
3292 | Object.keys(instance.modules).forEach(function (moduleName) { | |
3293 | var moduleParams = modulesParams[moduleName] || {}; | |
3294 | instance.useModule(moduleName, moduleParams); | |
3295 | }); | |
3296 | }; | |
3297 | ||
3298 | staticAccessors.components.set = function (components) { | |
3299 | var Class = this; | |
3300 | if (!Class.use) { return; } | |
3301 | Class.use(components); | |
3302 | }; | |
3303 | ||
3304 | Framework7Class.installModule = function installModule (module) { | |
3305 | var params = [], len = arguments.length - 1; | |
3306 | while ( len-- > 0 ) params[ len ] = arguments[ len + 1 ]; | |
3307 | ||
3308 | var Class = this; | |
3309 | if (!Class.prototype.modules) { Class.prototype.modules = {}; } | |
3310 | var name = module.name || (((Object.keys(Class.prototype.modules).length) + "_" + (Utils.now()))); | |
3311 | Class.prototype.modules[name] = module; | |
3312 | // Prototype | |
3313 | if (module.proto) { | |
3314 | Object.keys(module.proto).forEach(function (key) { | |
3315 | Class.prototype[key] = module.proto[key]; | |
3316 | }); | |
3317 | } | |
3318 | // Class | |
3319 | if (module.static) { | |
3320 | Object.keys(module.static).forEach(function (key) { | |
3321 | Class[key] = module.static[key]; | |
3322 | }); | |
3323 | } | |
3324 | // Callback | |
3325 | if (module.install) { | |
3326 | module.install.apply(Class, params); | |
3327 | } | |
3328 | return Class; | |
3329 | }; | |
3330 | ||
3331 | Framework7Class.use = function use (module) { | |
3332 | var params = [], len = arguments.length - 1; | |
3333 | while ( len-- > 0 ) params[ len ] = arguments[ len + 1 ]; | |
3334 | ||
3335 | var Class = this; | |
3336 | if (Array.isArray(module)) { | |
3337 | module.forEach(function (m) { return Class.installModule(m); }); | |
3338 | return Class; | |
3339 | } | |
3340 | return Class.installModule.apply(Class, [ module ].concat( params )); | |
3341 | }; | |
3342 | ||
3343 | Object.defineProperties( Framework7Class, staticAccessors ); | |
3344 | ||
3345 | return Framework7Class; | |
3346 | }(EventsClass)); | |
3347 | ||
3348 | function ConstructorMethods (parameters) { | |
3349 | if ( parameters === void 0 ) parameters = {}; | |
3350 | ||
3351 | var defaultSelector = parameters.defaultSelector; | |
3352 | var constructor = parameters.constructor; | |
3353 | var domProp = parameters.domProp; | |
3354 | var app = parameters.app; | |
3355 | var addMethods = parameters.addMethods; | |
3356 | var methods = { | |
3357 | create: function create() { | |
3358 | var args = [], len = arguments.length; | |
3359 | while ( len-- ) args[ len ] = arguments[ len ]; | |
3360 | ||
3361 | if (app) { return new (Function.prototype.bind.apply( constructor, [ null ].concat( [app], args) )); } | |
3362 | return new (Function.prototype.bind.apply( constructor, [ null ].concat( args) )); | |
3363 | }, | |
3364 | get: function get(el) { | |
3365 | if ( el === void 0 ) el = defaultSelector; | |
3366 | ||
3367 | if (el instanceof constructor) { return el; } | |
3368 | var $el = $(el); | |
3369 | if ($el.length === 0) { return undefined; } | |
3370 | return $el[0][domProp]; | |
3371 | }, | |
3372 | destroy: function destroy(el) { | |
3373 | var instance = methods.get(el); | |
3374 | if (instance && instance.destroy) { return instance.destroy(); } | |
3375 | return undefined; | |
3376 | }, | |
3377 | }; | |
3378 | if (addMethods && Array.isArray(addMethods)) { | |
3379 | addMethods.forEach(function (methodName) { | |
3380 | methods[methodName] = function (el) { | |
3381 | if ( el === void 0 ) el = defaultSelector; | |
3382 | var args = [], len = arguments.length - 1; | |
3383 | while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | |
3384 | ||
3385 | var instance = methods.get(el); | |
3386 | if (instance && instance[methodName]) { return instance[methodName].apply(instance, args); } | |
3387 | return undefined; | |
3388 | }; | |
3389 | }); | |
3390 | } | |
3391 | return methods; | |
3392 | } | |
3393 | ||
3394 | function ModalMethods (parameters) { | |
3395 | if ( parameters === void 0 ) parameters = {}; | |
3396 | ||
3397 | var defaultSelector = parameters.defaultSelector; | |
3398 | var constructor = parameters.constructor; | |
3399 | var app = parameters.app; | |
3400 | var methods = Utils.extend( | |
3401 | ConstructorMethods({ | |
3402 | defaultSelector: defaultSelector, | |
3403 | constructor: constructor, | |
3404 | app: app, | |
3405 | domProp: 'f7Modal', | |
3406 | }), | |
3407 | { | |
3408 | open: function open(el, animate) { | |
3409 | var $el = $(el); | |
3410 | var instance = $el[0].f7Modal; | |
3411 | if (!instance) { instance = new constructor(app, { el: $el }); } | |
3412 | return instance.open(animate); | |
3413 | }, | |
3414 | close: function close(el, animate) { | |
3415 | if ( el === void 0 ) el = defaultSelector; | |
3416 | ||
3417 | var $el = $(el); | |
3418 | if ($el.length === 0) { return undefined; } | |
3419 | var instance = $el[0].f7Modal; | |
3420 | if (!instance) { instance = new constructor(app, { el: $el }); } | |
3421 | return instance.close(animate); | |
3422 | }, | |
3423 | } | |
3424 | ); | |
3425 | return methods; | |
3426 | } | |
3427 | ||
3428 | var fetchedModules = []; | |
3429 | function loadModule(moduleToLoad) { | |
3430 | var Framework7 = this; | |
3431 | return new Promise(function (resolve, reject) { | |
3432 | var app = Framework7.instance; | |
3433 | var modulePath; | |
3434 | var moduleObj; | |
3435 | var moduleFunc; | |
3436 | if (!moduleToLoad) { | |
3437 | reject(new Error('Framework7: Lazy module must be specified')); | |
3438 | return; | |
3439 | } | |
3440 | ||
3441 | function install(module) { | |
3442 | Framework7.use(module); | |
3443 | ||
3444 | if (app) { | |
3445 | app.useModuleParams(module, app.params); | |
3446 | app.useModule(module); | |
3447 | } | |
3448 | } | |
3449 | ||
3450 | if (typeof moduleToLoad === 'string') { | |
3451 | var matchNamePattern = moduleToLoad.match(/([a-z0-9-]*)/i); | |
3452 | if (moduleToLoad.indexOf('.') < 0 && matchNamePattern && matchNamePattern[0].length === moduleToLoad.length) { | |
3453 | if (!app || (app && !app.params.lazyModulesPath)) { | |
3454 | reject(new Error('Framework7: "lazyModulesPath" app parameter must be specified to fetch module by name')); | |
3455 | return; | |
3456 | } | |
3457 | modulePath = (app.params.lazyModulesPath) + "/" + moduleToLoad + ".js"; | |
3458 | } else { | |
3459 | modulePath = moduleToLoad; | |
3460 | } | |
3461 | } else if (typeof moduleToLoad === 'function') { | |
3462 | moduleFunc = moduleToLoad; | |
3463 | } else { | |
3464 | // considering F7-Plugin object | |
3465 | moduleObj = moduleToLoad; | |
3466 | } | |
3467 | ||
3468 | if (moduleFunc) { | |
3469 | var module = moduleFunc(Framework7, false); | |
3470 | if (!module) { | |
3471 | reject(new Error('Framework7: Can\'t find Framework7 component in specified component function')); | |
3472 | return; | |
3473 | } | |
3474 | // Check if it was added | |
3475 | if (Framework7.prototype.modules && Framework7.prototype.modules[module.name]) { | |
3476 | resolve(); | |
3477 | return; | |
3478 | } | |
3479 | // Install It | |
3480 | install(module); | |
3481 | ||
3482 | resolve(); | |
3483 | } | |
3484 | if (moduleObj) { | |
3485 | var module$1 = moduleObj; | |
3486 | if (!module$1) { | |
3487 | reject(new Error('Framework7: Can\'t find Framework7 component in specified component')); | |
3488 | return; | |
3489 | } | |
3490 | // Check if it was added | |
3491 | if (Framework7.prototype.modules && Framework7.prototype.modules[module$1.name]) { | |
3492 | resolve(); | |
3493 | return; | |
3494 | } | |
3495 | // Install It | |
3496 | install(module$1); | |
3497 | ||
3498 | resolve(); | |
3499 | } | |
3500 | if (modulePath) { | |
3501 | if (fetchedModules.indexOf(modulePath) >= 0) { | |
3502 | resolve(); | |
3503 | return; | |
3504 | } | |
3505 | fetchedModules.push(modulePath); | |
3506 | var scriptLoad = new Promise(function (resolveScript, rejectScript) { | |
3507 | Framework7.request.get( | |
3508 | modulePath, | |
3509 | function (scriptContent) { | |
3510 | var id = Utils.id(); | |
3511 | var callbackLoadName = "f7_component_loader_callback_" + id; | |
3512 | ||
3513 | var scriptEl = document.createElement('script'); | |
3514 | scriptEl.innerHTML = "window." + callbackLoadName + " = function (Framework7, Framework7AutoInstallComponent) {return " + (scriptContent.trim()) + "}"; | |
3515 | $('head').append(scriptEl); | |
3516 | ||
3517 | var componentLoader = window[callbackLoadName]; | |
3518 | delete window[callbackLoadName]; | |
3519 | $(scriptEl).remove(); | |
3520 | ||
3521 | var module = componentLoader(Framework7, false); | |
3522 | ||
3523 | if (!module) { | |
3524 | rejectScript(new Error(("Framework7: Can't find Framework7 component in " + modulePath + " file"))); | |
3525 | return; | |
3526 | } | |
3527 | ||
3528 | // Check if it was added | |
3529 | if (Framework7.prototype.modules && Framework7.prototype.modules[module.name]) { | |
3530 | resolveScript(); | |
3531 | return; | |
3532 | } | |
3533 | ||
3534 | // Install It | |
3535 | install(module); | |
3536 | ||
3537 | resolveScript(); | |
3538 | }, | |
3539 | function (xhr, status) { | |
3540 | rejectScript(xhr, status); | |
3541 | } | |
3542 | ); | |
3543 | }); | |
3544 | var styleLoad = new Promise(function (resolveStyle) { | |
3545 | Framework7.request.get( | |
3546 | modulePath.replace('.js', app.rtl ? '.rtl.css' : '.css'), | |
3547 | function (styleContent) { | |
3548 | var styleEl = document.createElement('style'); | |
3549 | styleEl.innerHTML = styleContent; | |
3550 | $('head').append(styleEl); | |
3551 | ||
3552 | resolveStyle(); | |
3553 | }, | |
3554 | function () { | |
3555 | resolveStyle(); | |
3556 | } | |
3557 | ); | |
3558 | }); | |
3559 | ||
3560 | Promise.all([scriptLoad, styleLoad]).then(function () { | |
3561 | resolve(); | |
3562 | }).catch(function (err) { | |
3563 | reject(err); | |
3564 | }); | |
3565 | } | |
3566 | }); | |
3567 | } | |
3568 | ||
5d51ea26 | 3569 | var Framework7 = /*@__PURE__*/(function (Framework7Class) { |
5309fbda | 3570 | function Framework7(params) { |
5d51ea26 | 3571 | Framework7Class.call(this, params); |
5309fbda DC |
3572 | if (Framework7.instance) { |
3573 | throw new Error('Framework7 is already initialized and can\'t be initialized more than once'); | |
3574 | } | |
3575 | ||
3576 | var passedParams = Utils.extend({}, params); | |
3577 | ||
3578 | // App Instance | |
3579 | var app = this; | |
3580 | ||
3581 | Framework7.instance = app; | |
3582 | ||
3583 | // Default | |
3584 | var defaults = { | |
3585 | version: '1.0.0', | |
3586 | id: 'io.framework7.testapp', | |
3587 | root: 'body', | |
3588 | theme: 'auto', | |
3589 | language: win.navigator.language, | |
3590 | routes: [], | |
3591 | name: 'Framework7', | |
3592 | lazyModulesPath: null, | |
3593 | initOnDeviceReady: true, | |
3594 | init: true, | |
5d51ea26 | 3595 | autoDarkTheme: false, |
5309fbda DC |
3596 | }; |
3597 | ||
3598 | // Extend defaults with modules params | |
3599 | app.useModulesParams(defaults); | |
3600 | ||
3601 | // Extend defaults with passed params | |
3602 | app.params = Utils.extend(defaults, params); | |
3603 | ||
3604 | var $rootEl = $(app.params.root); | |
3605 | ||
3606 | Utils.extend(app, { | |
3607 | // App Id | |
3608 | id: app.params.id, | |
3609 | // App Name | |
3610 | name: app.params.name, | |
3611 | // App version | |
3612 | version: app.params.version, | |
3613 | // Routes | |
3614 | routes: app.params.routes, | |
3615 | // Lang | |
3616 | language: app.params.language, | |
3617 | // Root | |
3618 | root: $rootEl, | |
3619 | // RTL | |
3620 | rtl: $rootEl.css('direction') === 'rtl', | |
3621 | // Theme | |
3622 | theme: (function getTheme() { | |
3623 | if (app.params.theme === 'auto') { | |
5d51ea26 DC |
3624 | if (Device.ios) { return 'ios'; } |
3625 | if (Device.desktop && Device.electron) { return 'aurora'; } | |
3626 | return 'md'; | |
5309fbda DC |
3627 | } |
3628 | return app.params.theme; | |
3629 | }()), | |
3630 | // Initially passed parameters | |
3631 | passedParams: passedParams, | |
3632 | }); | |
3633 | ||
3634 | // Save Root | |
3635 | if (app.root && app.root[0]) { | |
3636 | app.root[0].f7 = app; | |
3637 | } | |
3638 | ||
3639 | // Install Modules | |
3640 | app.useModules(); | |
3641 | ||
3642 | // Init Data & Methods | |
3643 | app.initData(); | |
3644 | ||
5d51ea26 DC |
3645 | // Auto Dark Theme |
3646 | var DARK = '(prefers-color-scheme: dark)'; | |
3647 | var LIGHT = '(prefers-color-scheme: light)'; | |
3648 | app.mq = {}; | |
3649 | if (win.matchMedia) { | |
3650 | app.mq.dark = win.matchMedia(DARK); | |
3651 | app.mq.light = win.matchMedia(LIGHT); | |
3652 | } | |
3653 | app.colorSchemeListener = function colorSchemeListener(ref) { | |
3654 | var matches = ref.matches; | |
3655 | var media = ref.media; | |
3656 | ||
3657 | if (!matches) { | |
3658 | return; | |
3659 | } | |
3660 | var html = doc.querySelector('html'); | |
3661 | if (media === DARK) { | |
3662 | html.classList.add('theme-dark'); | |
3663 | } else if (media === LIGHT) { | |
3664 | html.classList.remove('theme-dark'); | |
3665 | } | |
3666 | }; | |
5309fbda DC |
3667 | // Init |
3668 | if (app.params.init) { | |
3669 | if (Device.cordova && app.params.initOnDeviceReady) { | |
3670 | $(doc).on('deviceready', function () { | |
3671 | app.init(); | |
3672 | }); | |
3673 | } else { | |
3674 | app.init(); | |
3675 | } | |
3676 | } | |
3677 | // Return app instance | |
3678 | return app; | |
3679 | } | |
3680 | ||
5d51ea26 DC |
3681 | if ( Framework7Class ) Framework7.__proto__ = Framework7Class; |
3682 | Framework7.prototype = Object.create( Framework7Class && Framework7Class.prototype ); | |
5309fbda DC |
3683 | Framework7.prototype.constructor = Framework7; |
3684 | ||
3685 | var prototypeAccessors = { $: { configurable: true },t7: { configurable: true } }; | |
3686 | var staticAccessors = { Dom7: { configurable: true },$: { configurable: true },Template7: { configurable: true },Class: { configurable: true },Events: { configurable: true } }; | |
3687 | ||
3688 | Framework7.prototype.initData = function initData () { | |
3689 | var app = this; | |
3690 | ||
3691 | // Data | |
3692 | app.data = {}; | |
3693 | if (app.params.data && typeof app.params.data === 'function') { | |
3694 | Utils.extend(app.data, app.params.data.bind(app)()); | |
3695 | } else if (app.params.data) { | |
3696 | Utils.extend(app.data, app.params.data); | |
3697 | } | |
3698 | // Methods | |
3699 | app.methods = {}; | |
3700 | if (app.params.methods) { | |
3701 | Object.keys(app.params.methods).forEach(function (methodName) { | |
3702 | if (typeof app.params.methods[methodName] === 'function') { | |
3703 | app.methods[methodName] = app.params.methods[methodName].bind(app); | |
3704 | } else { | |
3705 | app.methods[methodName] = app.params.methods[methodName]; | |
3706 | } | |
3707 | }); | |
3708 | } | |
3709 | }; | |
3710 | ||
5d51ea26 DC |
3711 | Framework7.prototype.enableAutoDarkTheme = function enableAutoDarkTheme () { |
3712 | if (!win.matchMedia) { return; } | |
3713 | var app = this; | |
3714 | var html = doc.querySelector('html'); | |
3715 | if (app.mq.dark && app.mq.light) { | |
3716 | app.mq.dark.addListener(app.colorSchemeListener); | |
3717 | app.mq.light.addListener(app.colorSchemeListener); | |
3718 | } | |
3719 | if (app.mq.dark && app.mq.dark.matches) { | |
3720 | html.classList.add('theme-dark'); | |
3721 | } else if (app.mq.light && app.mq.light.matches) { | |
3722 | html.classList.remove('theme-dark'); | |
3723 | } | |
3724 | }; | |
3725 | ||
3726 | Framework7.prototype.disableAutoDarkTheme = function disableAutoDarkTheme () { | |
3727 | if (!win.matchMedia) { return; } | |
3728 | var app = this; | |
3729 | if (app.mq.dark) { app.mq.dark.removeListener(app.colorSchemeListener); } | |
3730 | if (app.mq.light) { app.mq.light.removeListener(app.colorSchemeListener); } | |
3731 | }; | |
3732 | ||
5309fbda DC |
3733 | Framework7.prototype.init = function init () { |
3734 | var app = this; | |
3735 | if (app.initialized) { return app; } | |
3736 | ||
3737 | app.root.addClass('framework7-initializing'); | |
3738 | ||
3739 | // RTL attr | |
3740 | if (app.rtl) { | |
3741 | $('html').attr('dir', 'rtl'); | |
3742 | } | |
3743 | ||
5d51ea26 DC |
3744 | // Auto Dark Theme |
3745 | if (app.params.autoDarkTheme) { | |
3746 | app.enableAutoDarkTheme(); | |
3747 | } | |
3748 | ||
5309fbda DC |
3749 | // Root class |
3750 | app.root.addClass('framework7-root'); | |
3751 | ||
3752 | // Theme class | |
3753 | $('html').removeClass('ios md').addClass(app.theme); | |
3754 | ||
3755 | // Init class | |
3756 | Utils.nextFrame(function () { | |
3757 | app.root.removeClass('framework7-initializing'); | |
3758 | }); | |
3759 | // Emit, init other modules | |
3760 | app.initialized = true; | |
3761 | app.emit('init'); | |
3762 | ||
3763 | return app; | |
3764 | }; | |
3765 | ||
3766 | // eslint-disable-next-line | |
5d51ea26 | 3767 | Framework7.prototype.loadModule = function loadModule () { |
5309fbda DC |
3768 | var args = [], len = arguments.length; |
3769 | while ( len-- ) args[ len ] = arguments[ len ]; | |
3770 | ||
3771 | return Framework7.loadModule.apply(Framework7, args); | |
3772 | }; | |
3773 | ||
3774 | // eslint-disable-next-line | |
3775 | Framework7.prototype.loadModules = function loadModules () { | |
3776 | var args = [], len = arguments.length; | |
3777 | while ( len-- ) args[ len ] = arguments[ len ]; | |
3778 | ||
3779 | return Framework7.loadModules.apply(Framework7, args); | |
3780 | }; | |
3781 | ||
3782 | Framework7.prototype.getVnodeHooks = function getVnodeHooks (hook, id) { | |
3783 | var app = this; | |
3784 | if (!app.vnodeHooks || !app.vnodeHooks[hook]) { return []; } | |
3785 | return app.vnodeHooks[hook][id] || []; | |
3786 | }; | |
3787 | ||
3788 | // eslint-disable-next-line | |
3789 | prototypeAccessors.$.get = function () { | |
3790 | return $; | |
3791 | }; | |
3792 | // eslint-disable-next-line | |
3793 | prototypeAccessors.t7.get = function () { | |
3794 | return Template7; | |
3795 | }; | |
3796 | ||
3797 | staticAccessors.Dom7.get = function () { | |
3798 | return $; | |
3799 | }; | |
3800 | ||
3801 | staticAccessors.$.get = function () { | |
3802 | return $; | |
3803 | }; | |
3804 | ||
3805 | staticAccessors.Template7.get = function () { | |
3806 | return Template7; | |
3807 | }; | |
3808 | ||
3809 | staticAccessors.Class.get = function () { | |
5d51ea26 | 3810 | return Framework7Class; |
5309fbda DC |
3811 | }; |
3812 | ||
3813 | staticAccessors.Events.get = function () { | |
3814 | return EventsClass; | |
3815 | }; | |
3816 | ||
3817 | Object.defineProperties( Framework7.prototype, prototypeAccessors ); | |
3818 | Object.defineProperties( Framework7, staticAccessors ); | |
3819 | ||
3820 | return Framework7; | |
3821 | }(Framework7Class)); | |
3822 | ||
3823 | Framework7.ModalMethods = ModalMethods; | |
3824 | Framework7.ConstructorMethods = ConstructorMethods; | |
3825 | ||
3826 | Framework7.loadModule = loadModule; | |
3827 | Framework7.loadModules = function loadModules(modules) { | |
3828 | return Promise.all(modules.map(function (module) { return Framework7.loadModule(module); })); | |
3829 | }; | |
3830 | ||
3831 | var DeviceModule = { | |
3832 | name: 'device', | |
3833 | proto: { | |
3834 | device: Device, | |
3835 | }, | |
3836 | static: { | |
3837 | device: Device, | |
3838 | }, | |
3839 | on: { | |
3840 | init: function init() { | |
3841 | var classNames = []; | |
3842 | var html = doc.querySelector('html'); | |
3843 | var metaStatusbar = doc.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]'); | |
3844 | if (!html) { return; } | |
3845 | if (Device.standalone && Device.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') { | |
3846 | classNames.push('device-full-viewport'); | |
3847 | } | |
3848 | ||
3849 | // Pixel Ratio | |
3850 | classNames.push(("device-pixel-ratio-" + (Math.floor(Device.pixelRatio)))); | |
3851 | if (Device.pixelRatio >= 2) { | |
3852 | classNames.push('device-retina'); | |
3853 | } | |
3854 | // OS classes | |
3855 | if (Device.os) { | |
3856 | classNames.push( | |
3857 | ("device-" + (Device.os)), | |
3858 | ("device-" + (Device.os) + "-" + (Device.osVersion.split('.')[0])), | |
3859 | ("device-" + (Device.os) + "-" + (Device.osVersion.replace(/\./g, '-'))) | |
3860 | ); | |
3861 | if (Device.os === 'ios') { | |
3862 | var major = parseInt(Device.osVersion.split('.')[0], 10); | |
3863 | for (var i = major - 1; i >= 6; i -= 1) { | |
3864 | classNames.push(("device-ios-gt-" + i)); | |
3865 | } | |
3866 | if (Device.iphoneX) { | |
3867 | classNames.push('device-iphone-x'); | |
3868 | } | |
3869 | } | |
3870 | } else if (Device.desktop) { | |
3871 | classNames.push('device-desktop'); | |
3872 | if (Device.macos) { classNames.push('device-macos'); } | |
3873 | else if (Device.windows) { classNames.push('device-windows'); } | |
3874 | } | |
3875 | if (Device.cordova || Device.phonegap) { | |
3876 | classNames.push('device-cordova'); | |
3877 | } | |
3878 | ||
3879 | // Add html classes | |
3880 | classNames.forEach(function (className) { | |
3881 | html.classList.add(className); | |
3882 | }); | |
3883 | }, | |
3884 | }, | |
3885 | }; | |
3886 | ||
5309fbda DC |
3887 | var SupportModule = { |
3888 | name: 'support', | |
3889 | proto: { | |
3890 | support: Support, | |
3891 | }, | |
3892 | static: { | |
3893 | support: Support, | |
3894 | }, | |
3895 | on: { | |
3896 | init: function init() { | |
3897 | var html = doc.querySelector('html'); | |
3898 | if (!html) { return; } | |
3899 | var classNames = []; | |
3900 | // Add html classes | |
3901 | classNames.forEach(function (className) { | |
3902 | html.classList.add(className); | |
3903 | }); | |
3904 | }, | |
3905 | }, | |
3906 | }; | |
3907 | ||
3908 | var UtilsModule = { | |
3909 | name: 'utils', | |
3910 | proto: { | |
3911 | utils: Utils, | |
3912 | }, | |
3913 | static: { | |
3914 | utils: Utils, | |
3915 | }, | |
3916 | }; | |
3917 | ||
3918 | var ResizeModule = { | |
3919 | name: 'resize', | |
3920 | instance: { | |
3921 | getSize: function getSize() { | |
3922 | var app = this; | |
3923 | if (!app.root[0]) { return { width: 0, height: 0, left: 0, top: 0 }; } | |
3924 | var offset = app.root.offset(); | |
3925 | var ref = [app.root[0].offsetWidth, app.root[0].offsetHeight, offset.left, offset.top]; | |
3926 | var width = ref[0]; | |
3927 | var height = ref[1]; | |
3928 | var left = ref[2]; | |
3929 | var top = ref[3]; | |
3930 | app.width = width; | |
3931 | app.height = height; | |
3932 | app.left = left; | |
3933 | app.top = top; | |
3934 | return { width: width, height: height, left: left, top: top }; | |
3935 | }, | |
3936 | }, | |
3937 | on: { | |
3938 | init: function init() { | |
3939 | var app = this; | |
3940 | ||
3941 | // Get Size | |
3942 | app.getSize(); | |
3943 | ||
3944 | // Emit resize | |
3945 | win.addEventListener('resize', function () { | |
3946 | app.emit('resize'); | |
3947 | }, false); | |
3948 | ||
3949 | // Emit orientationchange | |
3950 | win.addEventListener('orientationchange', function () { | |
3951 | app.emit('orientationchange'); | |
3952 | }); | |
3953 | }, | |
3954 | orientationchange: function orientationchange() { | |
3955 | var app = this; | |
5309fbda DC |
3956 | // Fix iPad weird body scroll |
3957 | if (app.device.ipad) { | |
3958 | doc.body.scrollLeft = 0; | |
3959 | setTimeout(function () { | |
3960 | doc.body.scrollLeft = 0; | |
3961 | }, 0); | |
3962 | } | |
3963 | }, | |
3964 | resize: function resize() { | |
3965 | var app = this; | |
3966 | app.getSize(); | |
3967 | }, | |
3968 | }, | |
3969 | }; | |
3970 | ||
3971 | var globals = {}; | |
3972 | var jsonpRequests = 0; | |
3973 | ||
3974 | function Request(requestOptions) { | |
3975 | var globalsNoCallbacks = Utils.extend({}, globals); | |
3976 | ('beforeCreate beforeOpen beforeSend error complete success statusCode').split(' ').forEach(function (callbackName) { | |
3977 | delete globalsNoCallbacks[callbackName]; | |
3978 | }); | |
3979 | var defaults = Utils.extend({ | |
3980 | url: win.location.toString(), | |
3981 | method: 'GET', | |
3982 | data: false, | |
3983 | async: true, | |
3984 | cache: true, | |
3985 | user: '', | |
3986 | password: '', | |
3987 | headers: {}, | |
3988 | xhrFields: {}, | |
3989 | statusCode: {}, | |
3990 | processData: true, | |
3991 | dataType: 'text', | |
3992 | contentType: 'application/x-www-form-urlencoded', | |
3993 | timeout: 0, | |
3994 | }, globalsNoCallbacks); | |
3995 | ||
3996 | var options = Utils.extend({}, defaults, requestOptions); | |
3997 | var proceedRequest; | |
3998 | ||
3999 | // Function to run XHR callbacks and events | |
4000 | function fireCallback(callbackName) { | |
4001 | var data = [], len = arguments.length - 1; | |
4002 | while ( len-- > 0 ) data[ len ] = arguments[ len + 1 ]; | |
4003 | ||
4004 | /* | |
4005 | Callbacks: | |
4006 | beforeCreate (options), | |
4007 | beforeOpen (xhr, options), | |
4008 | beforeSend (xhr, options), | |
4009 | error (xhr, status), | |
4010 | complete (xhr, stautus), | |
4011 | success (response, status, xhr), | |
4012 | statusCode () | |
4013 | */ | |
4014 | var globalCallbackValue; | |
4015 | var optionCallbackValue; | |
4016 | if (globals[callbackName]) { | |
4017 | globalCallbackValue = globals[callbackName].apply(globals, data); | |
4018 | } | |
4019 | if (options[callbackName]) { | |
4020 | optionCallbackValue = options[callbackName].apply(options, data); | |
4021 | } | |
4022 | if (typeof globalCallbackValue !== 'boolean') { globalCallbackValue = true; } | |
4023 | if (typeof optionCallbackValue !== 'boolean') { optionCallbackValue = true; } | |
4024 | return (globalCallbackValue && optionCallbackValue); | |
4025 | } | |
4026 | ||
4027 | // Before create callback | |
4028 | proceedRequest = fireCallback('beforeCreate', options); | |
4029 | if (proceedRequest === false) { return undefined; } | |
4030 | ||
4031 | // For jQuery guys | |
4032 | if (options.type) { options.method = options.type; } | |
4033 | ||
4034 | // Parameters Prefix | |
4035 | var paramsPrefix = options.url.indexOf('?') >= 0 ? '&' : '?'; | |
4036 | ||
4037 | // UC method | |
4038 | var method = options.method.toUpperCase(); | |
4039 | ||
4040 | // Data to modify GET URL | |
4041 | if ((method === 'GET' || method === 'HEAD' || method === 'OPTIONS' || method === 'DELETE') && options.data) { | |
4042 | var stringData; | |
4043 | if (typeof options.data === 'string') { | |
4044 | // Should be key=value string | |
4045 | if (options.data.indexOf('?') >= 0) { stringData = options.data.split('?')[1]; } | |
4046 | else { stringData = options.data; } | |
4047 | } else { | |
4048 | // Should be key=value object | |
4049 | stringData = Utils.serializeObject(options.data); | |
4050 | } | |
4051 | if (stringData.length) { | |
4052 | options.url += paramsPrefix + stringData; | |
4053 | if (paramsPrefix === '?') { paramsPrefix = '&'; } | |
4054 | } | |
4055 | } | |
4056 | ||
4057 | // JSONP | |
4058 | if (options.dataType === 'json' && options.url.indexOf('callback=') >= 0) { | |
4059 | var callbackName = "f7jsonp_" + (Date.now() + ((jsonpRequests += 1))); | |
4060 | var abortTimeout; | |
4061 | var callbackSplit = options.url.split('callback='); | |
4062 | var requestUrl = (callbackSplit[0]) + "callback=" + callbackName; | |
4063 | if (callbackSplit[1].indexOf('&') >= 0) { | |
4064 | var addVars = callbackSplit[1].split('&').filter(function (el) { return el.indexOf('=') > 0; }).join('&'); | |
4065 | if (addVars.length > 0) { requestUrl += "&" + addVars; } | |
4066 | } | |
4067 | ||
4068 | // Create script | |
4069 | var script = doc.createElement('script'); | |
4070 | script.type = 'text/javascript'; | |
4071 | script.onerror = function onerror() { | |
4072 | clearTimeout(abortTimeout); | |
4073 | fireCallback('error', null, 'scripterror'); | |
4074 | fireCallback('complete', null, 'scripterror'); | |
4075 | }; | |
4076 | script.src = requestUrl; | |
4077 | ||
4078 | // Handler | |
4079 | win[callbackName] = function jsonpCallback(data) { | |
4080 | clearTimeout(abortTimeout); | |
4081 | fireCallback('success', data); | |
4082 | script.parentNode.removeChild(script); | |
4083 | script = null; | |
4084 | delete win[callbackName]; | |
4085 | }; | |
4086 | doc.querySelector('head').appendChild(script); | |
4087 | ||
4088 | if (options.timeout > 0) { | |
4089 | abortTimeout = setTimeout(function () { | |
4090 | script.parentNode.removeChild(script); | |
4091 | script = null; | |
4092 | fireCallback('error', null, 'timeout'); | |
4093 | }, options.timeout); | |
4094 | } | |
4095 | ||
4096 | return undefined; | |
4097 | } | |
4098 | ||
4099 | // Cache for GET/HEAD requests | |
4100 | if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS' || method === 'DELETE') { | |
4101 | if (options.cache === false) { | |
4102 | options.url += paramsPrefix + "_nocache" + (Date.now()); | |
4103 | } | |
4104 | } | |
4105 | ||
4106 | // Create XHR | |
4107 | var xhr = new XMLHttpRequest(); | |
4108 | ||
4109 | // Save Request URL | |
4110 | xhr.requestUrl = options.url; | |
4111 | xhr.requestParameters = options; | |
4112 | ||
4113 | // Before open callback | |
4114 | proceedRequest = fireCallback('beforeOpen', xhr, options); | |
4115 | if (proceedRequest === false) { return xhr; } | |
4116 | ||
4117 | // Open XHR | |
4118 | xhr.open(method, options.url, options.async, options.user, options.password); | |
4119 | ||
4120 | // Create POST Data | |
4121 | var postData = null; | |
4122 | ||
4123 | if ((method === 'POST' || method === 'PUT' || method === 'PATCH') && options.data) { | |
4124 | if (options.processData) { | |
4125 | var postDataInstances = [ArrayBuffer, Blob, Document, FormData]; | |
4126 | // Post Data | |
4127 | if (postDataInstances.indexOf(options.data.constructor) >= 0) { | |
4128 | postData = options.data; | |
4129 | } else { | |
4130 | // POST Headers | |
4131 | var boundary = "---------------------------" + (Date.now().toString(16)); | |
4132 | ||
4133 | if (options.contentType === 'multipart/form-data') { | |
4134 | xhr.setRequestHeader('Content-Type', ("multipart/form-data; boundary=" + boundary)); | |
4135 | } else { | |
4136 | xhr.setRequestHeader('Content-Type', options.contentType); | |
4137 | } | |
4138 | postData = ''; | |
4139 | var data$1 = Utils.serializeObject(options.data); | |
4140 | if (options.contentType === 'multipart/form-data') { | |
4141 | data$1 = data$1.split('&'); | |
4142 | var newData = []; | |
4143 | for (var i = 0; i < data$1.length; i += 1) { | |
4144 | newData.push(("Content-Disposition: form-data; name=\"" + (data$1[i].split('=')[0]) + "\"\r\n\r\n" + (data$1[i].split('=')[1]) + "\r\n")); | |
4145 | } | |
4146 | postData = "--" + boundary + "\r\n" + (newData.join(("--" + boundary + "\r\n"))) + "--" + boundary + "--\r\n"; | |
4147 | } else if (options.contentType === 'application/json') { | |
4148 | postData = JSON.stringify(options.data); | |
4149 | } else { | |
4150 | postData = data$1; | |
4151 | } | |
4152 | } | |
4153 | } else { | |
4154 | postData = options.data; | |
4155 | xhr.setRequestHeader('Content-Type', options.contentType); | |
4156 | } | |
4157 | } | |
5d51ea26 DC |
4158 | if (options.dataType === 'json' && (!options.headers || !options.headers.Accept)) { |
4159 | xhr.setRequestHeader('Accept', 'application/json'); | |
4160 | } | |
5309fbda DC |
4161 | |
4162 | // Additional headers | |
4163 | if (options.headers) { | |
4164 | Object.keys(options.headers).forEach(function (headerName) { | |
4165 | xhr.setRequestHeader(headerName, options.headers[headerName]); | |
4166 | }); | |
4167 | } | |
4168 | ||
4169 | // Check for crossDomain | |
4170 | if (typeof options.crossDomain === 'undefined') { | |
4171 | // eslint-disable-next-line | |
4172 | options.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(options.url) && RegExp.$2 !== win.location.host; | |
4173 | } | |
4174 | ||
4175 | if (!options.crossDomain) { | |
4176 | xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |
4177 | } | |
4178 | ||
4179 | if (options.xhrFields) { | |
4180 | Utils.extend(xhr, options.xhrFields); | |
4181 | } | |
4182 | ||
4183 | var xhrTimeout; | |
4184 | ||
4185 | // Handle XHR | |
4186 | xhr.onload = function onload() { | |
4187 | if (xhrTimeout) { clearTimeout(xhrTimeout); } | |
4188 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) { | |
4189 | var responseData; | |
4190 | if (options.dataType === 'json') { | |
4191 | var parseError; | |
4192 | try { | |
4193 | responseData = JSON.parse(xhr.responseText); | |
4194 | } catch (err) { | |
4195 | parseError = true; | |
4196 | } | |
4197 | if (!parseError) { | |
4198 | fireCallback('success', responseData, xhr.status, xhr); | |
4199 | } else { | |
4200 | fireCallback('error', xhr, 'parseerror'); | |
4201 | } | |
4202 | } else { | |
4203 | responseData = xhr.responseType === 'text' || xhr.responseType === '' ? xhr.responseText : xhr.response; | |
4204 | fireCallback('success', responseData, xhr.status, xhr); | |
4205 | } | |
4206 | } else { | |
4207 | fireCallback('error', xhr, xhr.status); | |
4208 | } | |
4209 | if (options.statusCode) { | |
4210 | if (globals.statusCode && globals.statusCode[xhr.status]) { globals.statusCode[xhr.status](xhr); } | |
4211 | if (options.statusCode[xhr.status]) { options.statusCode[xhr.status](xhr); } | |
4212 | } | |
4213 | fireCallback('complete', xhr, xhr.status); | |
4214 | }; | |
4215 | ||
4216 | xhr.onerror = function onerror() { | |
4217 | if (xhrTimeout) { clearTimeout(xhrTimeout); } | |
4218 | fireCallback('error', xhr, xhr.status); | |
4219 | fireCallback('complete', xhr, 'error'); | |
4220 | }; | |
4221 | ||
4222 | // Timeout | |
4223 | if (options.timeout > 0) { | |
4224 | xhr.onabort = function onabort() { | |
4225 | if (xhrTimeout) { clearTimeout(xhrTimeout); } | |
4226 | }; | |
4227 | xhrTimeout = setTimeout(function () { | |
4228 | xhr.abort(); | |
4229 | fireCallback('error', xhr, 'timeout'); | |
4230 | fireCallback('complete', xhr, 'timeout'); | |
4231 | }, options.timeout); | |
4232 | } | |
4233 | ||
4234 | // Ajax start callback | |
4235 | proceedRequest = fireCallback('beforeSend', xhr, options); | |
4236 | if (proceedRequest === false) { return xhr; } | |
4237 | ||
4238 | // Send XHR | |
4239 | xhr.send(postData); | |
4240 | ||
4241 | // Return XHR object | |
4242 | return xhr; | |
4243 | } | |
4244 | function RequestShortcut(method) { | |
4245 | var assign, assign$1; | |
4246 | ||
4247 | var args = [], len = arguments.length - 1; | |
4248 | while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | |
4249 | var ref = []; | |
4250 | var url = ref[0]; | |
4251 | var data = ref[1]; | |
4252 | var success = ref[2]; | |
4253 | var error = ref[3]; | |
4254 | var dataType = ref[4]; | |
4255 | if (typeof args[1] === 'function') { | |
4256 | (assign = args, url = assign[0], success = assign[1], error = assign[2], dataType = assign[3]); | |
4257 | } else { | |
4258 | (assign$1 = args, url = assign$1[0], data = assign$1[1], success = assign$1[2], error = assign$1[3], dataType = assign$1[4]); | |
4259 | } | |
4260 | [success, error].forEach(function (callback) { | |
4261 | if (typeof callback === 'string') { | |
4262 | dataType = callback; | |
4263 | if (callback === success) { success = undefined; } | |
4264 | else { error = undefined; } | |
4265 | } | |
4266 | }); | |
4267 | dataType = dataType || (method === 'json' || method === 'postJSON' ? 'json' : undefined); | |
4268 | var requestOptions = { | |
4269 | url: url, | |
4270 | method: method === 'post' || method === 'postJSON' ? 'POST' : 'GET', | |
4271 | data: data, | |
4272 | success: success, | |
4273 | error: error, | |
4274 | dataType: dataType, | |
4275 | }; | |
4276 | if (method === 'postJSON') { | |
4277 | Utils.extend(requestOptions, { | |
4278 | contentType: 'application/json', | |
4279 | processData: false, | |
4280 | crossDomain: true, | |
4281 | data: typeof data === 'string' ? data : JSON.stringify(data), | |
4282 | }); | |
4283 | } | |
4284 | return Request(requestOptions); | |
4285 | } | |
4286 | function RequestShortcutPromise(method) { | |
4287 | var args = [], len = arguments.length - 1; | |
4288 | while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | |
4289 | ||
4290 | var url = args[0]; | |
4291 | var data = args[1]; | |
4292 | var dataType = args[2]; | |
4293 | return new Promise(function (resolve, reject) { | |
4294 | RequestShortcut( | |
4295 | method, | |
4296 | url, | |
4297 | data, | |
4298 | function (response) { | |
4299 | resolve(response); | |
4300 | }, | |
4301 | function (xhr, status) { | |
4302 | reject(status); | |
4303 | }, | |
4304 | dataType | |
4305 | ); | |
4306 | }); | |
4307 | } | |
4308 | Object.assign(Request, { | |
4309 | get: function () { | |
4310 | var args = [], len = arguments.length; | |
4311 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4312 | ||
4313 | return RequestShortcut.apply(void 0, [ 'get' ].concat( args )); | |
4314 | }, | |
4315 | post: function () { | |
4316 | var args = [], len = arguments.length; | |
4317 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4318 | ||
4319 | return RequestShortcut.apply(void 0, [ 'post' ].concat( args )); | |
4320 | }, | |
4321 | json: function () { | |
4322 | var args = [], len = arguments.length; | |
4323 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4324 | ||
4325 | return RequestShortcut.apply(void 0, [ 'json' ].concat( args )); | |
4326 | }, | |
4327 | getJSON: function () { | |
4328 | var args = [], len = arguments.length; | |
4329 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4330 | ||
4331 | return RequestShortcut.apply(void 0, [ 'json' ].concat( args )); | |
4332 | }, | |
4333 | postJSON: function () { | |
4334 | var args = [], len = arguments.length; | |
4335 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4336 | ||
4337 | return RequestShortcut.apply(void 0, [ 'postJSON' ].concat( args )); | |
4338 | }, | |
4339 | }); | |
4340 | ||
4341 | Request.promise = function requestPromise(requestOptions) { | |
4342 | return new Promise(function (resolve, reject) { | |
4343 | Request(Object.assign(requestOptions, { | |
4344 | success: function success(data) { | |
4345 | resolve(data); | |
4346 | }, | |
4347 | error: function error(xhr, status) { | |
4348 | reject(status); | |
4349 | }, | |
4350 | })); | |
4351 | }); | |
4352 | }; | |
4353 | Object.assign(Request.promise, { | |
4354 | get: function () { | |
4355 | var args = [], len = arguments.length; | |
4356 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4357 | ||
4358 | return RequestShortcutPromise.apply(void 0, [ 'get' ].concat( args )); | |
4359 | }, | |
4360 | post: function () { | |
4361 | var args = [], len = arguments.length; | |
4362 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4363 | ||
4364 | return RequestShortcutPromise.apply(void 0, [ 'post' ].concat( args )); | |
4365 | }, | |
4366 | json: function () { | |
4367 | var args = [], len = arguments.length; | |
4368 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4369 | ||
4370 | return RequestShortcutPromise.apply(void 0, [ 'json' ].concat( args )); | |
4371 | }, | |
4372 | getJSON: function () { | |
4373 | var args = [], len = arguments.length; | |
4374 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4375 | ||
4376 | return RequestShortcutPromise.apply(void 0, [ 'json' ].concat( args )); | |
4377 | }, | |
4378 | postJSON: function () { | |
4379 | var args = [], len = arguments.length; | |
4380 | while ( len-- ) args[ len ] = arguments[ len ]; | |
4381 | ||
4382 | return RequestShortcutPromise.apply(void 0, [ 'postJSON' ].concat( args )); | |
4383 | }, | |
4384 | }); | |
4385 | ||
4386 | Request.setup = function setup(options) { | |
4387 | if (options.type && !options.method) { | |
4388 | Utils.extend(options, { method: options.type }); | |
4389 | } | |
4390 | Utils.extend(globals, options); | |
4391 | }; | |
4392 | ||
4393 | /* eslint no-param-reassign: "off" */ | |
4394 | ||
4395 | var RequestModule = { | |
4396 | name: 'request', | |
4397 | proto: { | |
4398 | request: Request, | |
4399 | }, | |
4400 | static: { | |
4401 | request: Request, | |
4402 | }, | |
4403 | }; | |
4404 | ||
4405 | function initTouch() { | |
4406 | var app = this; | |
4407 | var params = app.params.touch; | |
4408 | var useRipple = params[((app.theme) + "TouchRipple")]; | |
4409 | ||
4410 | if (Device.ios && Device.webView) { | |
4411 | // Strange hack required for iOS 8 webview to work on inputs | |
4412 | win.addEventListener('touchstart', function () {}); | |
4413 | } | |
4414 | ||
4415 | var touchStartX; | |
4416 | var touchStartY; | |
4417 | var touchStartTime; | |
4418 | var targetElement; | |
4419 | var trackClick; | |
4420 | var activeSelection; | |
4421 | var scrollParent; | |
4422 | var lastClickTime; | |
4423 | var isMoved; | |
4424 | var tapHoldFired; | |
4425 | var tapHoldTimeout; | |
4426 | var preventClick; | |
4427 | ||
4428 | var activableElement; | |
4429 | var activeTimeout; | |
4430 | ||
4431 | var needsFastClick; | |
4432 | var needsFastClickTimeOut; | |
4433 | ||
4434 | var rippleWave; | |
4435 | var rippleTarget; | |
4436 | var rippleTimeout; | |
4437 | ||
4438 | function findActivableElement(el) { | |
4439 | var target = $(el); | |
4440 | var parents = target.parents(params.activeStateElements); | |
4441 | var activable; | |
4442 | if (target.is(params.activeStateElements)) { | |
4443 | activable = target; | |
4444 | } | |
4445 | if (parents.length > 0) { | |
4446 | activable = activable ? activable.add(parents) : parents; | |
4447 | } | |
5d51ea26 DC |
4448 | if (activable && activable.length > 1) { |
4449 | var newActivable = []; | |
4450 | var preventPropagation; | |
4451 | for (var i = 0; i < activable.length; i += 1) { | |
4452 | if (!preventPropagation) { | |
4453 | newActivable.push(activable[i]); | |
4454 | if (activable.eq(i).hasClass('prevent-active-state-propagation') | |
4455 | || activable.eq(i).hasClass('no-active-state-propagation') | |
4456 | ) { | |
4457 | preventPropagation = true; | |
4458 | } | |
4459 | } | |
4460 | } | |
4461 | activable = $(newActivable); | |
4462 | } | |
5309fbda DC |
4463 | return activable || target; |
4464 | } | |
4465 | ||
4466 | function isInsideScrollableViewLight(el) { | |
4467 | var pageContent = el.parents('.page-content'); | |
4468 | return pageContent.length > 0; | |
4469 | } | |
4470 | function isInsideScrollableView(el) { | |
4471 | var pageContent = el.parents('.page-content'); | |
4472 | ||
4473 | if (pageContent.length === 0) { | |
4474 | return false; | |
4475 | } | |
4476 | ||
4477 | // This event handler covers the "tap to stop scrolling". | |
4478 | if (pageContent.prop('scrollHandlerSet') !== 'yes') { | |
4479 | pageContent.on('scroll', function () { | |
4480 | clearTimeout(activeTimeout); | |
4481 | clearTimeout(rippleTimeout); | |
4482 | }); | |
4483 | pageContent.prop('scrollHandlerSet', 'yes'); | |
4484 | } | |
4485 | ||
4486 | return true; | |
4487 | } | |
4488 | function addActive() { | |
4489 | if (!activableElement) { return; } | |
4490 | activableElement.addClass('active-state'); | |
4491 | } | |
4492 | function removeActive() { | |
4493 | if (!activableElement) { return; } | |
4494 | activableElement.removeClass('active-state'); | |
4495 | activableElement = null; | |
4496 | } | |
4497 | function isFormElement(el) { | |
4498 | var nodes = ('input select textarea label').split(' '); | |
4499 | if (el.nodeName && nodes.indexOf(el.nodeName.toLowerCase()) >= 0) { return true; } | |
4500 | return false; | |
4501 | } | |
4502 | function androidNeedsBlur(el) { | |
4503 | var noBlur = ('button input textarea select').split(' '); | |
4504 | if (doc.activeElement && el !== doc.activeElement && doc.activeElement !== doc.body) { | |
4505 | if (noBlur.indexOf(el.nodeName.toLowerCase()) >= 0) { | |
4506 | return false; | |
4507 | } | |
4508 | return true; | |
4509 | } | |
4510 | return false; | |
4511 | } | |
4512 | function targetNeedsFastClick(el) { | |
4513 | /* | |
4514 | if ( | |
4515 | Device.ios | |
4516 | && | |
4517 | ( | |
4518 | Device.osVersion.split('.')[0] > 9 | |
4519 | || | |
4520 | (Device.osVersion.split('.')[0] * 1 === 9 && Device.osVersion.split('.')[1] >= 1) | |
4521 | ) | |
4522 | ) { | |
4523 | return false; | |
4524 | } | |
4525 | */ | |
4526 | var $el = $(el); | |
4527 | if (el.nodeName.toLowerCase() === 'input' && (el.type === 'file' || el.type === 'range')) { return false; } | |
4528 | if (el.nodeName.toLowerCase() === 'select' && Device.android) { return false; } | |
4529 | if ($el.hasClass('no-fastclick') || $el.parents('.no-fastclick').length > 0) { return false; } | |
4530 | if (params.fastClicksExclude && $el.closest(params.fastClicksExclude).length > 0) { return false; } | |
4531 | ||
4532 | return true; | |
4533 | } | |
4534 | function targetNeedsFocus(el) { | |
4535 | if (doc.activeElement === el) { | |
4536 | return false; | |
4537 | } | |
4538 | var tag = el.nodeName.toLowerCase(); | |
4539 | var skipInputs = ('button checkbox file image radio submit').split(' '); | |
4540 | if (el.disabled || el.readOnly) { return false; } | |
4541 | if (tag === 'textarea') { return true; } | |
4542 | if (tag === 'select') { | |
4543 | if (Device.android) { return false; } | |
4544 | return true; | |
4545 | } | |
4546 | if (tag === 'input' && skipInputs.indexOf(el.type) < 0) { return true; } | |
4547 | return false; | |
4548 | } | |
4549 | function targetNeedsPrevent(el) { | |
4550 | var $el = $(el); | |
4551 | var prevent = true; | |
4552 | if ($el.is('label') || $el.parents('label').length > 0) { | |
4553 | if (Device.android) { | |
4554 | prevent = false; | |
4555 | } else if (Device.ios && $el.is('input')) { | |
4556 | prevent = true; | |
4557 | } else { prevent = false; } | |
4558 | } | |
4559 | return prevent; | |
4560 | } | |
4561 | ||
4562 | // Ripple handlers | |
4563 | function findRippleElement(el) { | |
4564 | var rippleElements = params.touchRippleElements; | |
4565 | var $el = $(el); | |
4566 | if ($el.is(rippleElements)) { | |
4567 | if ($el.hasClass('no-ripple')) { | |
4568 | return false; | |
4569 | } | |
4570 | return $el; | |
4571 | } | |
4572 | if ($el.parents(rippleElements).length > 0) { | |
4573 | var rippleParent = $el.parents(rippleElements).eq(0); | |
4574 | if (rippleParent.hasClass('no-ripple')) { | |
4575 | return false; | |
4576 | } | |
4577 | return rippleParent; | |
4578 | } | |
4579 | return false; | |
4580 | } | |
4581 | function createRipple($el, x, y) { | |
4582 | if (!$el) { return; } | |
4583 | rippleWave = app.touchRipple.create($el, x, y); | |
4584 | } | |
4585 | ||
4586 | function removeRipple() { | |
4587 | if (!rippleWave) { return; } | |
4588 | rippleWave.remove(); | |
4589 | rippleWave = undefined; | |
4590 | rippleTarget = undefined; | |
4591 | } | |
4592 | function rippleTouchStart(el) { | |
4593 | rippleTarget = findRippleElement(el); | |
4594 | if (!rippleTarget || rippleTarget.length === 0) { | |
4595 | rippleTarget = undefined; | |
4596 | return; | |
4597 | } | |
4598 | var inScrollable = params.fastClicks | |
4599 | ? isInsideScrollableView(rippleTarget) | |
4600 | : isInsideScrollableViewLight(rippleTarget); | |
4601 | ||
4602 | if (!inScrollable) { | |
5d51ea26 | 4603 | removeRipple(); |
5309fbda DC |
4604 | createRipple(rippleTarget, touchStartX, touchStartY); |
4605 | } else { | |
5d51ea26 | 4606 | clearTimeout(rippleTimeout); |
5309fbda | 4607 | rippleTimeout = setTimeout(function () { |
5d51ea26 | 4608 | removeRipple(); |
5309fbda DC |
4609 | createRipple(rippleTarget, touchStartX, touchStartY); |
4610 | }, 80); | |
4611 | } | |
4612 | } | |
4613 | function rippleTouchMove() { | |
4614 | clearTimeout(rippleTimeout); | |
4615 | removeRipple(); | |
4616 | } | |
4617 | function rippleTouchEnd() { | |
5d51ea26 | 4618 | if (!rippleWave && rippleTarget && !isMoved) { |
5309fbda DC |
4619 | clearTimeout(rippleTimeout); |
4620 | createRipple(rippleTarget, touchStartX, touchStartY); | |
4621 | setTimeout(removeRipple, 0); | |
4622 | } else { | |
4623 | removeRipple(); | |
4624 | } | |
4625 | } | |
4626 | ||
4627 | // Mouse Handlers | |
4628 | function handleMouseDown(e) { | |
4629 | findActivableElement(e.target).addClass('active-state'); | |
4630 | if ('which' in e && e.which === 3) { | |
4631 | setTimeout(function () { | |
4632 | $('.active-state').removeClass('active-state'); | |
4633 | }, 0); | |
4634 | } | |
4635 | if (useRipple) { | |
4636 | touchStartX = e.pageX; | |
4637 | touchStartY = e.pageY; | |
4638 | rippleTouchStart(e.target, e.pageX, e.pageY); | |
4639 | } | |
4640 | } | |
4641 | function handleMouseMove() { | |
4642 | $('.active-state').removeClass('active-state'); | |
4643 | if (useRipple) { | |
4644 | rippleTouchMove(); | |
4645 | } | |
4646 | } | |
4647 | function handleMouseUp() { | |
4648 | $('.active-state').removeClass('active-state'); | |
4649 | if (useRipple) { | |
4650 | rippleTouchEnd(); | |
4651 | } | |
4652 | } | |
4653 | ||
4654 | // Send Click | |
4655 | function sendClick(e) { | |
4656 | var touch = e.changedTouches[0]; | |
4657 | var evt = doc.createEvent('MouseEvents'); | |
4658 | var eventType = 'click'; | |
4659 | if (Device.android && targetElement.nodeName.toLowerCase() === 'select') { | |
4660 | eventType = 'mousedown'; | |
4661 | } | |
4662 | evt.initMouseEvent(eventType, true, true, win, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); | |
4663 | evt.forwardedTouchEvent = true; | |
4664 | ||
4665 | if (app.device.ios && win.navigator.standalone) { | |
4666 | // Fix the issue happens in iOS home screen apps where the wrong element is selected during a momentum scroll. | |
4667 | // Upon tapping, we give the scrolling time to stop, then we grab the element based where the user tapped. | |
4668 | setTimeout(function () { | |
4669 | targetElement = doc.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY); | |
5d51ea26 DC |
4670 | if (targetElement) { |
4671 | targetElement.dispatchEvent(evt); | |
4672 | } | |
5309fbda DC |
4673 | }, 10); |
4674 | } else { | |
4675 | targetElement.dispatchEvent(evt); | |
4676 | } | |
4677 | } | |
4678 | ||
4679 | // Touch Handlers | |
4680 | function handleTouchStart(e) { | |
4681 | var this$1 = this; | |
4682 | ||
4683 | isMoved = false; | |
4684 | tapHoldFired = false; | |
4685 | if (e.targetTouches.length > 1) { | |
4686 | if (activableElement) { removeActive(); } | |
4687 | return true; | |
4688 | } | |
4689 | if (e.touches.length > 1 && activableElement) { | |
4690 | removeActive(); | |
4691 | } | |
4692 | if (params.tapHold) { | |
4693 | if (tapHoldTimeout) { clearTimeout(tapHoldTimeout); } | |
4694 | tapHoldTimeout = setTimeout(function () { | |
4695 | if (e && e.touches && e.touches.length > 1) { return; } | |
4696 | tapHoldFired = true; | |
4697 | e.preventDefault(); | |
4698 | $(e.target).trigger('taphold'); | |
4699 | }, params.tapHoldDelay); | |
4700 | } | |
4701 | if (needsFastClickTimeOut) { clearTimeout(needsFastClickTimeOut); } | |
4702 | needsFastClick = targetNeedsFastClick(e.target); | |
4703 | ||
4704 | if (!needsFastClick) { | |
4705 | trackClick = false; | |
4706 | return true; | |
4707 | } | |
4708 | if (Device.ios || (Device.android && 'getSelection' in win)) { | |
4709 | var selection = win.getSelection(); | |
4710 | if ( | |
4711 | selection.rangeCount | |
4712 | && selection.focusNode !== doc.body | |
4713 | && (!selection.isCollapsed || doc.activeElement === selection.focusNode) | |
4714 | ) { | |
4715 | activeSelection = true; | |
4716 | return true; | |
4717 | } | |
4718 | ||
4719 | activeSelection = false; | |
4720 | } | |
4721 | if (Device.android) { | |
4722 | if (androidNeedsBlur(e.target)) { | |
4723 | doc.activeElement.blur(); | |
4724 | } | |
4725 | } | |
4726 | ||
4727 | trackClick = true; | |
4728 | targetElement = e.target; | |
4729 | touchStartTime = (new Date()).getTime(); | |
4730 | touchStartX = e.targetTouches[0].pageX; | |
4731 | touchStartY = e.targetTouches[0].pageY; | |
4732 | ||
4733 | // Detect scroll parent | |
4734 | if (Device.ios) { | |
4735 | scrollParent = undefined; | |
4736 | $(targetElement).parents().each(function () { | |
4737 | var parent = this$1; | |
4738 | if (parent.scrollHeight > parent.offsetHeight && !scrollParent) { | |
4739 | scrollParent = parent; | |
4740 | scrollParent.f7ScrollTop = scrollParent.scrollTop; | |
4741 | } | |
4742 | }); | |
4743 | } | |
4744 | if ((touchStartTime - lastClickTime) < params.fastClicksDelayBetweenClicks) { | |
4745 | e.preventDefault(); | |
4746 | } | |
4747 | ||
4748 | if (params.activeState) { | |
4749 | activableElement = findActivableElement(targetElement); | |
4750 | activeTimeout = setTimeout(addActive, 0); | |
4751 | } | |
4752 | if (useRipple) { | |
5d51ea26 | 4753 | rippleTouchStart(targetElement); |
5309fbda DC |
4754 | } |
4755 | return true; | |
4756 | } | |
4757 | function handleTouchMove(e) { | |
4758 | if (!trackClick) { return; } | |
4759 | var distance = params.fastClicksDistanceThreshold; | |
4760 | if (distance) { | |
4761 | var pageX = e.targetTouches[0].pageX; | |
4762 | var pageY = e.targetTouches[0].pageY; | |
4763 | if (Math.abs(pageX - touchStartX) > distance || Math.abs(pageY - touchStartY) > distance) { | |
4764 | isMoved = true; | |
4765 | } | |
4766 | } else { | |
4767 | isMoved = true; | |
4768 | } | |
4769 | if (isMoved) { | |
4770 | trackClick = false; | |
4771 | targetElement = null; | |
4772 | isMoved = true; | |
4773 | if (params.tapHold) { | |
4774 | clearTimeout(tapHoldTimeout); | |
4775 | } | |
4776 | if (params.activeState) { | |
4777 | clearTimeout(activeTimeout); | |
4778 | removeActive(); | |
4779 | } | |
4780 | if (useRipple) { | |
4781 | rippleTouchMove(); | |
4782 | } | |
4783 | } | |
4784 | } | |
4785 | function handleTouchEnd(e) { | |
4786 | clearTimeout(activeTimeout); | |
4787 | clearTimeout(tapHoldTimeout); | |
4788 | ||
4789 | var touchEndTime = (new Date()).getTime(); | |
4790 | ||
4791 | if (!trackClick) { | |
4792 | if (!activeSelection && needsFastClick) { | |
4793 | if (!(Device.android && !e.cancelable) && e.cancelable) { | |
4794 | e.preventDefault(); | |
4795 | } | |
4796 | } | |
4797 | if (params.activeState) { removeActive(); } | |
4798 | if (useRipple) { | |
4799 | rippleTouchEnd(); | |
4800 | } | |
4801 | return true; | |
4802 | } | |
4803 | ||
4804 | if (doc.activeElement === e.target) { | |
4805 | if (params.activeState) { removeActive(); } | |
4806 | if (useRipple) { | |
4807 | rippleTouchEnd(); | |
4808 | } | |
4809 | return true; | |
4810 | } | |
4811 | ||
4812 | if (!activeSelection) { | |
4813 | e.preventDefault(); | |
4814 | } | |
4815 | ||
4816 | if ((touchEndTime - lastClickTime) < params.fastClicksDelayBetweenClicks) { | |
4817 | setTimeout(removeActive, 0); | |
4818 | if (useRipple) { | |
4819 | rippleTouchEnd(); | |
4820 | } | |
4821 | return true; | |
4822 | } | |
4823 | ||
4824 | lastClickTime = touchEndTime; | |
4825 | ||
4826 | trackClick = false; | |
4827 | ||
4828 | if (Device.ios && scrollParent) { | |
4829 | if (scrollParent.scrollTop !== scrollParent.f7ScrollTop) { | |
4830 | return false; | |
4831 | } | |
4832 | } | |
4833 | ||
4834 | // Add active-state here because, in a very fast tap, the timeout didn't | |
4835 | // have the chance to execute. Removing active-state in a timeout gives | |
4836 | // the chance to the animation execute. | |
4837 | if (params.activeState) { | |
4838 | addActive(); | |
4839 | setTimeout(removeActive, 0); | |
4840 | } | |
4841 | // Remove Ripple | |
4842 | if (useRipple) { | |
4843 | rippleTouchEnd(); | |
4844 | } | |
4845 | ||
4846 | // Trigger focus when required | |
4847 | if (targetNeedsFocus(targetElement)) { | |
4848 | if (Device.ios && Device.webView) { | |
4849 | targetElement.focus(); | |
4850 | return false; | |
4851 | } | |
4852 | ||
4853 | targetElement.focus(); | |
4854 | } | |
4855 | ||
4856 | // Blur active elements | |
4857 | if (doc.activeElement && targetElement !== doc.activeElement && doc.activeElement !== doc.body && targetElement.nodeName.toLowerCase() !== 'label') { | |
4858 | doc.activeElement.blur(); | |
4859 | } | |
4860 | ||
4861 | // Send click | |
4862 | e.preventDefault(); | |
4863 | if (params.tapHoldPreventClicks && tapHoldFired) { | |
4864 | return false; | |
4865 | } | |
4866 | sendClick(e); | |
4867 | return false; | |
4868 | } | |
4869 | function handleTouchCancel() { | |
4870 | trackClick = false; | |
4871 | targetElement = null; | |
4872 | ||
4873 | // Remove Active State | |
4874 | clearTimeout(activeTimeout); | |
4875 | clearTimeout(tapHoldTimeout); | |
4876 | if (params.activeState) { | |
4877 | removeActive(); | |
4878 | } | |
4879 | ||
4880 | // Remove Ripple | |
4881 | if (useRipple) { | |
4882 | rippleTouchEnd(); | |
4883 | } | |
4884 | } | |
4885 | ||
4886 | function handleClick(e) { | |
4887 | var allowClick = false; | |
4888 | if (trackClick) { | |
4889 | targetElement = null; | |
4890 | trackClick = false; | |
4891 | return true; | |
4892 | } | |
4893 | if ((e.target.type === 'submit' && e.detail === 0) || e.target.type === 'file') { | |
4894 | return true; | |
4895 | } | |
4896 | if (!targetElement) { | |
4897 | if (!isFormElement(e.target)) { | |
4898 | allowClick = true; | |
4899 | } | |
4900 | } | |
4901 | if (!needsFastClick) { | |
4902 | allowClick = true; | |
4903 | } | |
4904 | if (doc.activeElement === targetElement) { | |
4905 | allowClick = true; | |
4906 | } | |
4907 | if (e.forwardedTouchEvent) { | |
4908 | allowClick = true; | |
4909 | } | |
4910 | if (!e.cancelable) { | |
4911 | allowClick = true; | |
4912 | } | |
4913 | if (params.tapHold && params.tapHoldPreventClicks && tapHoldFired) { | |
4914 | allowClick = false; | |
4915 | } | |
4916 | if (!allowClick) { | |
4917 | e.stopImmediatePropagation(); | |
4918 | e.stopPropagation(); | |
4919 | if (targetElement) { | |
4920 | if (targetNeedsPrevent(targetElement) || isMoved) { | |
4921 | e.preventDefault(); | |
4922 | } | |
4923 | } else { | |
4924 | e.preventDefault(); | |
4925 | } | |
4926 | targetElement = null; | |
4927 | } | |
4928 | needsFastClickTimeOut = setTimeout(function () { | |
4929 | needsFastClick = false; | |
4930 | }, (Device.ios || Device.androidChrome ? 100 : 400)); | |
4931 | ||
4932 | if (params.tapHold) { | |
4933 | tapHoldTimeout = setTimeout(function () { | |
4934 | tapHoldFired = false; | |
4935 | }, (Device.ios || Device.androidChrome ? 100 : 400)); | |
4936 | } | |
4937 | ||
4938 | return allowClick; | |
4939 | } | |
4940 | ||
4941 | function handleTouchStartLight(e) { | |
4942 | isMoved = false; | |
4943 | tapHoldFired = false; | |
4944 | preventClick = false; | |
4945 | if (e.targetTouches.length > 1) { | |
4946 | if (activableElement) { removeActive(); } | |
4947 | return true; | |
4948 | } | |
4949 | if (e.touches.length > 1 && activableElement) { | |
4950 | removeActive(); | |
4951 | } | |
4952 | if (params.tapHold) { | |
4953 | if (tapHoldTimeout) { clearTimeout(tapHoldTimeout); } | |
4954 | tapHoldTimeout = setTimeout(function () { | |
4955 | if (e && e.touches && e.touches.length > 1) { return; } | |
4956 | tapHoldFired = true; | |
4957 | e.preventDefault(); | |
4958 | preventClick = true; | |
4959 | $(e.target).trigger('taphold'); | |
4960 | }, params.tapHoldDelay); | |
4961 | } | |
4962 | targetElement = e.target; | |
4963 | touchStartX = e.targetTouches[0].pageX; | |
4964 | touchStartY = e.targetTouches[0].pageY; | |
4965 | ||
4966 | if (params.activeState) { | |
4967 | activableElement = findActivableElement(targetElement); | |
4968 | if (!isInsideScrollableViewLight(activableElement)) { | |
4969 | addActive(); | |
4970 | } else { | |
4971 | activeTimeout = setTimeout(addActive, 80); | |
4972 | } | |
4973 | } | |
4974 | if (useRipple) { | |
5d51ea26 | 4975 | rippleTouchStart(targetElement); |
5309fbda DC |
4976 | } |
4977 | return true; | |
4978 | } | |
4979 | function handleTouchMoveLight(e) { | |
5d51ea26 DC |
4980 | var touch; |
4981 | var distance; | |
4982 | if (e.type === 'touchmove') { | |
4983 | touch = e.targetTouches[0]; | |
4984 | distance = params.touchClicksDistanceThreshold; | |
4985 | // if (touch && touch.touchType === 'stylus') { | |
4986 | // distance = 5; | |
4987 | // } else { | |
4988 | // distance = 3; | |
4989 | // } | |
4990 | } | |
4991 | ||
4992 | if (distance && touch) { | |
4993 | var pageX = touch.pageX; | |
4994 | var pageY = touch.pageY; | |
5309fbda DC |
4995 | if (Math.abs(pageX - touchStartX) > distance || Math.abs(pageY - touchStartY) > distance) { |
4996 | isMoved = true; | |
4997 | } | |
4998 | } else { | |
4999 | isMoved = true; | |
5000 | } | |
5001 | if (isMoved) { | |
5002 | preventClick = true; | |
5003 | if (params.tapHold) { | |
5004 | clearTimeout(tapHoldTimeout); | |
5005 | } | |
5006 | if (params.activeState) { | |
5007 | clearTimeout(activeTimeout); | |
5008 | removeActive(); | |
5009 | } | |
5010 | if (useRipple) { | |
5011 | rippleTouchMove(); | |
5012 | } | |
5013 | } | |
5014 | } | |
5015 | function handleTouchEndLight(e) { | |
5016 | clearTimeout(activeTimeout); | |
5017 | clearTimeout(tapHoldTimeout); | |
5018 | if (doc.activeElement === e.target) { | |
5019 | if (params.activeState) { removeActive(); } | |
5020 | if (useRipple) { | |
5021 | rippleTouchEnd(); | |
5022 | } | |
5023 | return true; | |
5024 | } | |
5025 | if (params.activeState) { | |
5026 | addActive(); | |
5027 | setTimeout(removeActive, 0); | |
5028 | } | |
5029 | if (useRipple) { | |
5030 | rippleTouchEnd(); | |
5031 | } | |
5032 | if ((params.tapHoldPreventClicks && tapHoldFired) || preventClick) { | |
5033 | if (e.cancelable) { e.preventDefault(); } | |
5034 | preventClick = true; | |
5035 | return false; | |
5036 | } | |
5037 | return true; | |
5038 | } | |
5039 | function handleClickLight(e) { | |
5040 | var localPreventClick = preventClick; | |
5041 | if (targetElement && e.target !== targetElement) { | |
5042 | localPreventClick = true; | |
5043 | } | |
5044 | if (params.tapHold && params.tapHoldPreventClicks && tapHoldFired) { | |
5045 | localPreventClick = true; | |
5046 | } | |
5047 | if (localPreventClick) { | |
5048 | e.stopImmediatePropagation(); | |
5049 | e.stopPropagation(); | |
5050 | e.preventDefault(); | |
5051 | } | |
5052 | ||
5053 | if (params.tapHold) { | |
5054 | tapHoldTimeout = setTimeout( | |
5055 | function () { | |
5056 | tapHoldFired = false; | |
5057 | }, | |
5058 | (Device.ios || Device.androidChrome ? 100 : 400) | |
5059 | ); | |
5060 | } | |
5061 | preventClick = false; | |
5062 | targetElement = null; | |
5063 | ||
5064 | return !localPreventClick; | |
5065 | } | |
5066 | ||
5067 | function emitAppTouchEvent(name, e) { | |
5068 | app.emit({ | |
5069 | events: name, | |
5070 | data: [e], | |
5071 | }); | |
5072 | } | |
5073 | function appClick(e) { | |
5074 | emitAppTouchEvent('click', e); | |
5075 | } | |
5076 | function appTouchStartActive(e) { | |
5077 | emitAppTouchEvent('touchstart touchstart:active', e); | |
5078 | } | |
5079 | function appTouchMoveActive(e) { | |
5080 | emitAppTouchEvent('touchmove touchmove:active', e); | |
5081 | } | |
5082 | function appTouchEndActive(e) { | |
5083 | emitAppTouchEvent('touchend touchend:active', e); | |
5084 | } | |
5085 | function appTouchStartPassive(e) { | |
5086 | emitAppTouchEvent('touchstart:passive', e); | |
5087 | } | |
5088 | function appTouchMovePassive(e) { | |
5089 | emitAppTouchEvent('touchmove:passive', e); | |
5090 | } | |
5091 | function appTouchEndPassive(e) { | |
5092 | emitAppTouchEvent('touchend:passive', e); | |
5093 | } | |
5094 | ||
5095 | var passiveListener = Support.passiveListener ? { passive: true } : false; | |
5096 | var activeListener = Support.passiveListener ? { passive: false } : false; | |
5097 | ||
5098 | doc.addEventListener('click', appClick, true); | |
5099 | ||
5100 | if (Support.passiveListener) { | |
5101 | doc.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener); | |
5102 | doc.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener); | |
5103 | doc.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener); | |
5104 | ||
5105 | doc.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener); | |
5106 | doc.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener); | |
5107 | doc.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener); | |
5108 | } else { | |
5109 | doc.addEventListener(app.touchEvents.start, function (e) { | |
5110 | appTouchStartActive(e); | |
5111 | appTouchStartPassive(e); | |
5112 | }, false); | |
5113 | doc.addEventListener(app.touchEvents.move, function (e) { | |
5114 | appTouchMoveActive(e); | |
5115 | appTouchMovePassive(e); | |
5116 | }, false); | |
5117 | doc.addEventListener(app.touchEvents.end, function (e) { | |
5118 | appTouchEndActive(e); | |
5119 | appTouchEndPassive(e); | |
5120 | }, false); | |
5121 | } | |
5122 | ||
5123 | if (Support.touch) { | |
5124 | if (params.fastClicks) { | |
5125 | app.on('click', handleClick); | |
5126 | app.on('touchstart', handleTouchStart); | |
5127 | app.on('touchmove', handleTouchMove); | |
5128 | app.on('touchend', handleTouchEnd); | |
5129 | } else { | |
5130 | app.on('click', handleClickLight); | |
5131 | app.on('touchstart', handleTouchStartLight); | |
5132 | app.on('touchmove', handleTouchMoveLight); | |
5133 | app.on('touchend', handleTouchEndLight); | |
5134 | } | |
5135 | ||
5136 | doc.addEventListener('touchcancel', handleTouchCancel, { passive: true }); | |
5137 | } else if (params.activeState) { | |
5138 | app.on('touchstart', handleMouseDown); | |
5139 | app.on('touchmove', handleMouseMove); | |
5140 | app.on('touchend', handleMouseUp); | |
5141 | } | |
5142 | doc.addEventListener('contextmenu', function (e) { | |
5143 | if (params.disableContextMenu && (Device.ios || Device.android || Device.cordova)) { | |
5144 | e.preventDefault(); | |
5145 | } | |
5146 | if (useRipple) { | |
5147 | if (activableElement) { removeActive(); } | |
5148 | rippleTouchEnd(); | |
5149 | } | |
5150 | }); | |
5151 | } | |
5152 | ||
5153 | var TouchModule = { | |
5154 | name: 'touch', | |
5155 | params: { | |
5156 | touch: { | |
5157 | // Fast clicks | |
5158 | fastClicks: false, | |
5159 | fastClicksDistanceThreshold: 10, | |
5160 | fastClicksDelayBetweenClicks: 50, | |
5161 | fastClicksExclude: '', // CSS selector | |
5d51ea26 DC |
5162 | // Clicks |
5163 | touchClicksDistanceThreshold: 5, | |
5309fbda DC |
5164 | // ContextMenu |
5165 | disableContextMenu: false, | |
5166 | // Tap Hold | |
5167 | tapHold: false, | |
5168 | tapHoldDelay: 750, | |
5169 | tapHoldPreventClicks: true, | |
5170 | // Active State | |
5171 | activeState: true, | |
5d51ea26 | 5172 | activeStateElements: 'a, button, label, span, .actions-button, .stepper-button, .stepper-button-plus, .stepper-button-minus, .card-expandable, .menu-item, .link, .item-link', |
5309fbda DC |
5173 | mdTouchRipple: true, |
5174 | iosTouchRipple: false, | |
5d51ea26 | 5175 | auroraTouchRipple: false, |
5309fbda DC |
5176 | touchRippleElements: '.ripple, .link, .item-link, .list-button, .links-list a, .button, button, .input-clear-button, .dialog-button, .tab-link, .item-radio, .item-checkbox, .actions-button, .searchbar-disable-button, .fab a, .checkbox, .radio, .data-table .sortable-cell:not(.input-cell), .notification-close-button, .stepper-button, .stepper-button-minus, .stepper-button-plus, .menu-item-content', |
5177 | }, | |
5178 | }, | |
5179 | instance: { | |
5180 | touchEvents: { | |
5181 | start: Support.touch ? 'touchstart' : 'mousedown', | |
5182 | move: Support.touch ? 'touchmove' : 'mousemove', | |
5183 | end: Support.touch ? 'touchend' : 'mouseup', | |
5184 | }, | |
5185 | }, | |
5186 | on: { | |
5187 | init: initTouch, | |
5188 | }, | |
5189 | }; | |
5190 | ||
5191 | /** | |
5192 | * Expose `pathToRegexp`. | |
5193 | */ | |
5194 | var pathToRegexp_1 = pathToRegexp; | |
5195 | var parse_1 = parse; | |
5196 | var compile_1 = compile; | |
5197 | var tokensToFunction_1 = tokensToFunction; | |
5198 | var tokensToRegExp_1 = tokensToRegExp; | |
5199 | ||
5200 | /** | |
5201 | * Default configs. | |
5202 | */ | |
5203 | var DEFAULT_DELIMITER = '/'; | |
5204 | ||
5205 | /** | |
5206 | * The main path matching regexp utility. | |
5207 | * | |
5208 | * @type {RegExp} | |
5209 | */ | |
5210 | var PATH_REGEXP = new RegExp([ | |
5211 | // Match escaped characters that would otherwise appear in future matches. | |
5212 | // This allows the user to escape special characters that won't transform. | |
5213 | '(\\\\.)', | |
5214 | // Match Express-style parameters and un-named parameters with a prefix | |
5215 | // and optional suffixes. Matches appear as: | |
5216 | // | |
5217 | // ":test(\\d+)?" => ["test", "\d+", undefined, "?"] | |
5218 | // "(\\d+)" => [undefined, undefined, "\d+", undefined] | |
5219 | '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?' | |
5220 | ].join('|'), 'g'); | |
5221 | ||
5222 | /** | |
5223 | * Parse a string for the raw tokens. | |
5224 | * | |
5225 | * @param {string} str | |
5226 | * @param {Object=} options | |
5227 | * @return {!Array} | |
5228 | */ | |
5229 | function parse (str, options) { | |
5230 | var tokens = []; | |
5231 | var key = 0; | |
5232 | var index = 0; | |
5233 | var path = ''; | |
5234 | var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER; | |
5235 | var whitelist = (options && options.whitelist) || undefined; | |
5236 | var pathEscaped = false; | |
5237 | var res; | |
5238 | ||
5239 | while ((res = PATH_REGEXP.exec(str)) !== null) { | |
5240 | var m = res[0]; | |
5241 | var escaped = res[1]; | |
5242 | var offset = res.index; | |
5243 | path += str.slice(index, offset); | |
5244 | index = offset + m.length; | |
5245 | ||
5246 | // Ignore already escaped sequences. | |
5247 | if (escaped) { | |
5248 | path += escaped[1]; | |
5249 | pathEscaped = true; | |
5250 | continue | |
5251 | } | |
5252 | ||
5253 | var prev = ''; | |
5254 | var name = res[2]; | |
5255 | var capture = res[3]; | |
5256 | var group = res[4]; | |
5257 | var modifier = res[5]; | |
5258 | ||
5259 | if (!pathEscaped && path.length) { | |
5260 | var k = path.length - 1; | |
5261 | var c = path[k]; | |
5262 | var matches = whitelist ? whitelist.indexOf(c) > -1 : true; | |
5263 | ||
5264 | if (matches) { | |
5265 | prev = c; | |
5266 | path = path.slice(0, k); | |
5267 | } | |
5268 | } | |
5269 | ||
5270 | // Push the current path onto the tokens. | |
5271 | if (path) { | |
5272 | tokens.push(path); | |
5273 | path = ''; | |
5274 | pathEscaped = false; | |
5275 | } | |
5276 | ||
5277 | var repeat = modifier === '+' || modifier === '*'; | |
5278 | var optional = modifier === '?' || modifier === '*'; | |
5279 | var pattern = capture || group; | |
5280 | var delimiter = prev || defaultDelimiter; | |
5281 | ||
5282 | tokens.push({ | |
5283 | name: name || key++, | |
5284 | prefix: prev, | |
5285 | delimiter: delimiter, | |
5286 | optional: optional, | |
5287 | repeat: repeat, | |
5288 | pattern: pattern | |
5289 | ? escapeGroup(pattern) | |
5290 | : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']+?' | |
5291 | }); | |
5292 | } | |
5293 | ||
5294 | // Push any remaining characters. | |
5295 | if (path || index < str.length) { | |
5296 | tokens.push(path + str.substr(index)); | |
5297 | } | |
5298 | ||
5299 | return tokens | |
5300 | } | |
5301 | ||
5302 | /** | |
5303 | * Compile a string to a template function for the path. | |
5304 | * | |
5305 | * @param {string} str | |
5306 | * @param {Object=} options | |
5307 | * @return {!function(Object=, Object=)} | |
5308 | */ | |
5309 | function compile (str, options) { | |
5310 | return tokensToFunction(parse(str, options)) | |
5311 | } | |
5312 | ||
5313 | /** | |
5314 | * Expose a method for transforming tokens into the path function. | |
5315 | */ | |
5316 | function tokensToFunction (tokens) { | |
5317 | // Compile all the tokens into regexps. | |
5318 | var matches = new Array(tokens.length); | |
5319 | ||
5320 | // Compile all the patterns before compilation. | |
5321 | for (var i = 0; i < tokens.length; i++) { | |
5322 | if (typeof tokens[i] === 'object') { | |
5323 | matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$'); | |
5324 | } | |
5325 | } | |
5326 | ||
5327 | return function (data, options) { | |
5328 | var path = ''; | |
5329 | var encode = (options && options.encode) || encodeURIComponent; | |
5330 | ||
5331 | for (var i = 0; i < tokens.length; i++) { | |
5332 | var token = tokens[i]; | |
5333 | ||
5334 | if (typeof token === 'string') { | |
5335 | path += token; | |
5336 | continue | |
5337 | } | |
5338 | ||
5339 | var value = data ? data[token.name] : undefined; | |
5340 | var segment; | |
5341 | ||
5342 | if (Array.isArray(value)) { | |
5343 | if (!token.repeat) { | |
5344 | throw new TypeError('Expected "' + token.name + '" to not repeat, but got array') | |
5345 | } | |
5346 | ||
5347 | if (value.length === 0) { | |
5348 | if (token.optional) { continue } | |
5349 | ||
5350 | throw new TypeError('Expected "' + token.name + '" to not be empty') | |
5351 | } | |
5352 | ||
5353 | for (var j = 0; j < value.length; j++) { | |
5354 | segment = encode(value[j], token); | |
5355 | ||
5356 | if (!matches[i].test(segment)) { | |
5357 | throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"') | |
5358 | } | |
5359 | ||
5360 | path += (j === 0 ? token.prefix : token.delimiter) + segment; | |
5361 | } | |
5362 | ||
5363 | continue | |
5364 | } | |
5365 | ||
5366 | if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | |
5367 | segment = encode(String(value), token); | |
5368 | ||
5369 | if (!matches[i].test(segment)) { | |
5370 | throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"') | |
5371 | } | |
5372 | ||
5373 | path += token.prefix + segment; | |
5374 | continue | |
5375 | } | |
5376 | ||
5377 | if (token.optional) { continue } | |
5378 | ||
5379 | throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string')) | |
5380 | } | |
5381 | ||
5382 | return path | |
5383 | } | |
5384 | } | |
5385 | ||
5386 | /** | |
5387 | * Escape a regular expression string. | |
5388 | * | |
5389 | * @param {string} str | |
5390 | * @return {string} | |
5391 | */ | |
5392 | function escapeString (str) { | |
5393 | return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1') | |
5394 | } | |
5395 | ||
5396 | /** | |
5397 | * Escape the capturing group by escaping special characters and meaning. | |
5398 | * | |
5399 | * @param {string} group | |
5400 | * @return {string} | |
5401 | */ | |
5402 | function escapeGroup (group) { | |
5403 | return group.replace(/([=!:$/()])/g, '\\$1') | |
5404 | } | |
5405 | ||
5406 | /** | |
5407 | * Get the flags for a regexp from the options. | |
5408 | * | |
5409 | * @param {Object} options | |
5410 | * @return {string} | |
5411 | */ | |
5412 | function flags (options) { | |
5413 | return options && options.sensitive ? '' : 'i' | |
5414 | } | |
5415 | ||
5416 | /** | |
5417 | * Pull out keys from a regexp. | |
5418 | * | |
5419 | * @param {!RegExp} path | |
5420 | * @param {Array=} keys | |
5421 | * @return {!RegExp} | |
5422 | */ | |
5423 | function regexpToRegexp (path, keys) { | |
5424 | if (!keys) { return path } | |
5425 | ||
5426 | // Use a negative lookahead to match only capturing groups. | |
5427 | var groups = path.source.match(/\((?!\?)/g); | |
5428 | ||
5429 | if (groups) { | |
5430 | for (var i = 0; i < groups.length; i++) { | |
5431 | keys.push({ | |
5432 | name: i, | |
5433 | prefix: null, | |
5434 | delimiter: null, | |
5435 | optional: false, | |
5436 | repeat: false, | |
5437 | pattern: null | |
5438 | }); | |
5439 | } | |
5440 | } | |
5441 | ||
5442 | return path | |
5443 | } | |
5444 | ||
5445 | /** | |
5446 | * Transform an array into a regexp. | |
5447 | * | |
5448 | * @param {!Array} path | |
5449 | * @param {Array=} keys | |
5450 | * @param {Object=} options | |
5451 | * @return {!RegExp} | |
5452 | */ | |
5453 | function arrayToRegexp (path, keys, options) { | |
5454 | var parts = []; | |
5455 | ||
5456 | for (var i = 0; i < path.length; i++) { | |
5457 | parts.push(pathToRegexp(path[i], keys, options).source); | |
5458 | } | |
5459 | ||
5460 | return new RegExp('(?:' + parts.join('|') + ')', flags(options)) | |
5461 | } | |
5462 | ||
5463 | /** | |
5464 | * Create a path regexp from string input. | |
5465 | * | |
5466 | * @param {string} path | |
5467 | * @param {Array=} keys | |
5468 | * @param {Object=} options | |
5469 | * @return {!RegExp} | |
5470 | */ | |
5471 | function stringToRegexp (path, keys, options) { | |
5472 | return tokensToRegExp(parse(path, options), keys, options) | |
5473 | } | |
5474 | ||
5475 | /** | |
5476 | * Expose a function for taking tokens and returning a RegExp. | |
5477 | * | |
5478 | * @param {!Array} tokens | |
5479 | * @param {Array=} keys | |
5480 | * @param {Object=} options | |
5481 | * @return {!RegExp} | |
5482 | */ | |
5483 | function tokensToRegExp (tokens, keys, options) { | |
5484 | options = options || {}; | |
5485 | ||
5486 | var strict = options.strict; | |
5487 | var start = options.start !== false; | |
5488 | var end = options.end !== false; | |
5489 | var delimiter = options.delimiter || DEFAULT_DELIMITER; | |
5490 | var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|'); | |
5491 | var route = start ? '^' : ''; | |
5492 | ||
5493 | // Iterate over the tokens and create our regexp string. | |
5494 | for (var i = 0; i < tokens.length; i++) { | |
5495 | var token = tokens[i]; | |
5496 | ||
5497 | if (typeof token === 'string') { | |
5498 | route += escapeString(token); | |
5499 | } else { | |
5500 | var capture = token.repeat | |
5501 | ? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*' | |
5502 | : token.pattern; | |
5503 | ||
5504 | if (keys) { keys.push(token); } | |
5505 | ||
5506 | if (token.optional) { | |
5507 | if (!token.prefix) { | |
5508 | route += '(' + capture + ')?'; | |
5509 | } else { | |
5510 | route += '(?:' + escapeString(token.prefix) + '(' + capture + '))?'; | |
5511 | } | |
5512 | } else { | |
5513 | route += escapeString(token.prefix) + '(' + capture + ')'; | |
5514 | } | |
5515 | } | |
5516 | } | |
5517 | ||
5518 | if (end) { | |
5519 | if (!strict) { route += '(?:' + escapeString(delimiter) + ')?'; } | |
5520 | ||
5521 | route += endsWith === '$' ? '$' : '(?=' + endsWith + ')'; | |
5522 | } else { | |
5523 | var endToken = tokens[tokens.length - 1]; | |
5524 | var isEndDelimited = typeof endToken === 'string' | |
5525 | ? endToken[endToken.length - 1] === delimiter | |
5526 | : endToken === undefined; | |
5527 | ||
5528 | if (!strict) { route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?'; } | |
5529 | if (!isEndDelimited) { route += '(?=' + escapeString(delimiter) + '|' + endsWith + ')'; } | |
5530 | } | |
5531 | ||
5532 | return new RegExp(route, flags(options)) | |
5533 | } | |
5534 | ||
5535 | /** | |
5536 | * Normalize the given path string, returning a regular expression. | |
5537 | * | |
5538 | * An empty array can be passed in for the keys, which will hold the | |
5539 | * placeholder key descriptions. For example, using `/user/:id`, `keys` will | |
5540 | * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`. | |
5541 | * | |
5542 | * @param {(string|RegExp|Array)} path | |
5543 | * @param {Array=} keys | |
5544 | * @param {Object=} options | |
5545 | * @return {!RegExp} | |
5546 | */ | |
5547 | function pathToRegexp (path, keys, options) { | |
5548 | if (path instanceof RegExp) { | |
5549 | return regexpToRegexp(path, keys) | |
5550 | } | |
5551 | ||
5552 | if (Array.isArray(path)) { | |
5553 | return arrayToRegexp(/** @type {!Array} */ (path), keys, options) | |
5554 | } | |
5555 | ||
5556 | return stringToRegexp(/** @type {string} */ (path), keys, options) | |
5557 | } | |
5558 | pathToRegexp_1.parse = parse_1; | |
5559 | pathToRegexp_1.compile = compile_1; | |
5560 | pathToRegexp_1.tokensToFunction = tokensToFunction_1; | |
5561 | pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; | |
5562 | ||
5563 | var History = { | |
5564 | queue: [], | |
5565 | clearQueue: function clearQueue() { | |
5566 | if (History.queue.length === 0) { return; } | |
5567 | var currentQueue = History.queue.shift(); | |
5568 | currentQueue(); | |
5569 | }, | |
5570 | routerQueue: [], | |
5571 | clearRouterQueue: function clearRouterQueue() { | |
5572 | if (History.routerQueue.length === 0) { return; } | |
5573 | var currentQueue = History.routerQueue.pop(); | |
5574 | var router = currentQueue.router; | |
5575 | var stateUrl = currentQueue.stateUrl; | |
5576 | var action = currentQueue.action; | |
5577 | ||
5578 | var animate = router.params.animate; | |
5579 | if (router.params.pushStateAnimate === false) { animate = false; } | |
5580 | ||
5581 | if (action === 'back') { | |
5582 | router.back({ animate: animate, pushState: false }); | |
5583 | } | |
5584 | if (action === 'load') { | |
5585 | router.navigate(stateUrl, { animate: animate, pushState: false }); | |
5586 | } | |
5587 | }, | |
5588 | handle: function handle(e) { | |
5589 | if (History.blockPopstate) { return; } | |
5590 | var app = this; | |
5591 | // const mainView = app.views.main; | |
5592 | var state = e.state; | |
5593 | History.previousState = History.state; | |
5594 | History.state = state; | |
5595 | ||
5596 | History.allowChange = true; | |
5597 | History.clearQueue(); | |
5598 | ||
5599 | state = History.state; | |
5600 | if (!state) { state = {}; } | |
5601 | ||
5602 | app.views.forEach(function (view) { | |
5603 | var router = view.router; | |
5604 | var viewState = state[view.id]; | |
5605 | if (!viewState && view.params.pushState) { | |
5606 | viewState = { | |
5607 | url: view.router.history[0], | |
5608 | }; | |
5609 | } | |
5610 | if (!viewState) { return; } | |
5611 | var stateUrl = viewState.url || undefined; | |
5612 | ||
5613 | var animate = router.params.animate; | |
5614 | if (router.params.pushStateAnimate === false) { animate = false; } | |
5615 | ||
5616 | if (stateUrl !== router.url) { | |
5617 | if (router.history.indexOf(stateUrl) >= 0) { | |
5618 | // Go Back | |
5619 | if (router.allowPageChange) { | |
5620 | router.back({ animate: animate, pushState: false }); | |
5621 | } else { | |
5622 | History.routerQueue.push({ | |
5623 | action: 'back', | |
5624 | router: router, | |
5625 | }); | |
5626 | } | |
5627 | } else if (router.allowPageChange) { | |
5628 | // Load page | |
5629 | router.navigate(stateUrl, { animate: animate, pushState: false }); | |
5630 | } else { | |
5631 | History.routerQueue.unshift({ | |
5632 | action: 'load', | |
5633 | stateUrl: stateUrl, | |
5634 | router: router, | |
5635 | }); | |
5636 | } | |
5637 | } | |
5638 | }); | |
5639 | }, | |
5640 | initViewState: function initViewState(viewId, viewState) { | |
5641 | var obj; | |
5642 | ||
5643 | var newState = Utils.extend({}, (History.state || {}), ( obj = {}, obj[viewId] = viewState, obj )); | |
5644 | History.state = newState; | |
5645 | win.history.replaceState(newState, ''); | |
5646 | }, | |
5647 | push: function push(viewId, viewState, url) { | |
5648 | var obj; | |
5649 | ||
5650 | if (!History.allowChange) { | |
5651 | History.queue.push(function () { | |
5652 | History.push(viewId, viewState, url); | |
5653 | }); | |
5654 | return; | |
5655 | } | |
5656 | History.previousState = History.state; | |
5657 | var newState = Utils.extend({}, (History.previousState || {}), ( obj = {}, obj[viewId] = viewState, obj )); | |
5658 | History.state = newState; | |
5659 | win.history.pushState(newState, '', url); | |
5660 | }, | |
5661 | replace: function replace(viewId, viewState, url) { | |
5662 | var obj; | |
5663 | ||
5664 | if (!History.allowChange) { | |
5665 | History.queue.push(function () { | |
5666 | History.replace(viewId, viewState, url); | |
5667 | }); | |
5668 | return; | |
5669 | } | |
5670 | History.previousState = History.state; | |
5671 | var newState = Utils.extend({}, (History.previousState || {}), ( obj = {}, obj[viewId] = viewState, obj )); | |
5672 | History.state = newState; | |
5673 | win.history.replaceState(newState, '', url); | |
5674 | }, | |
5675 | go: function go(index) { | |
5676 | History.allowChange = false; | |
5677 | win.history.go(index); | |
5678 | }, | |
5679 | back: function back() { | |
5680 | History.allowChange = false; | |
5681 | win.history.back(); | |
5682 | }, | |
5683 | allowChange: true, | |
5684 | previousState: {}, | |
5685 | state: win.history.state, | |
5686 | blockPopstate: true, | |
5687 | init: function init(app) { | |
5688 | $(win).on('load', function () { | |
5689 | setTimeout(function () { | |
5690 | History.blockPopstate = false; | |
5691 | }, 0); | |
5692 | }); | |
5693 | ||
5694 | if (doc.readyState && doc.readyState === 'complete') { | |
5695 | History.blockPopstate = false; | |
5696 | } | |
5697 | ||
5698 | $(win).on('popstate', History.handle.bind(app)); | |
5699 | }, | |
5700 | }; | |
5701 | ||
5702 | function SwipeBack(r) { | |
5703 | var router = r; | |
5704 | var $el = router.$el; | |
5705 | var $navbarEl = router.$navbarEl; | |
5706 | var app = router.app; | |
5707 | var params = router.params; | |
5708 | var isTouched = false; | |
5709 | var isMoved = false; | |
5710 | var touchesStart = {}; | |
5711 | var isScrolling; | |
5d51ea26 DC |
5712 | var $currentPageEl = []; |
5713 | var $previousPageEl = []; | |
5309fbda DC |
5714 | var viewContainerWidth; |
5715 | var touchesDiff; | |
5716 | var allowViewTouchMove = true; | |
5717 | var touchStartTime; | |
5d51ea26 DC |
5718 | var $currentNavbarInnerEl = []; |
5719 | var $previousNavbarInnerEl = []; | |
5309fbda DC |
5720 | var dynamicNavbar; |
5721 | var separateNavbar; | |
5d51ea26 DC |
5722 | var $pageShadowEl; |
5723 | var $pageOpacityEl; | |
5309fbda DC |
5724 | |
5725 | var animatableNavEls; | |
5726 | ||
5727 | var paramsSwipeBackAnimateShadow = params[((app.theme) + "SwipeBackAnimateShadow")]; | |
5728 | var paramsSwipeBackAnimateOpacity = params[((app.theme) + "SwipeBackAnimateOpacity")]; | |
5729 | var paramsSwipeBackActiveArea = params[((app.theme) + "SwipeBackActiveArea")]; | |
5730 | var paramsSwipeBackThreshold = params[((app.theme) + "SwipeBackThreshold")]; | |
5731 | ||
5732 | var transformOrigin = app.rtl ? 'right center' : 'left center'; | |
5733 | ||
5734 | function animatableNavElements() { | |
5735 | var els = []; | |
5736 | var inverter = app.rtl ? -1 : 1; | |
5d51ea26 DC |
5737 | var currentNavIsLarge = $currentNavbarInnerEl.hasClass('navbar-inner-large'); |
5738 | var previousNavIsLarge = $previousNavbarInnerEl.hasClass('navbar-inner-large'); | |
5739 | var fromLarge = currentNavIsLarge && !$currentNavbarInnerEl.hasClass('navbar-inner-large-collapsed'); | |
5740 | var toLarge = previousNavIsLarge && !$previousNavbarInnerEl.hasClass('navbar-inner-large-collapsed'); | |
5741 | var $currentNavElements = $currentNavbarInnerEl.children('.left, .title, .right, .subnavbar, .fading, .title-large'); | |
5742 | var $previousNavElements = $previousNavbarInnerEl.children('.left, .title, .right, .subnavbar, .fading, .title-large'); | |
5309fbda DC |
5743 | var activeNavBackIconText; |
5744 | var previousNavBackIconText; | |
5745 | ||
5746 | if (params.iosAnimateNavbarBackIcon) { | |
5d51ea26 DC |
5747 | if ($currentNavbarInnerEl.hasClass('sliding')) { |
5748 | activeNavBackIconText = $currentNavbarInnerEl.children('.left').find('.back .icon + span').eq(0); | |
5309fbda | 5749 | } else { |
5d51ea26 | 5750 | activeNavBackIconText = $currentNavbarInnerEl.children('.left.sliding').find('.back .icon + span').eq(0); |
5309fbda | 5751 | } |
5d51ea26 DC |
5752 | if ($previousNavbarInnerEl.hasClass('sliding')) { |
5753 | previousNavBackIconText = $previousNavbarInnerEl.children('.left').find('.back .icon + span').eq(0); | |
5309fbda | 5754 | } else { |
5d51ea26 | 5755 | previousNavBackIconText = $previousNavbarInnerEl.children('.left.sliding').find('.back .icon + span').eq(0); |
5309fbda DC |
5756 | } |
5757 | if (activeNavBackIconText.length) { | |
5758 | $previousNavElements.each(function (index, el) { | |
5759 | if (!$(el).hasClass('title')) { return; } | |
5760 | el.f7NavbarLeftOffset += activeNavBackIconText.prev('.icon')[0].offsetWidth; | |
5761 | }); | |
5762 | } | |
5763 | } | |
5764 | $currentNavElements | |
5765 | .each(function (index, navEl) { | |
5766 | var $navEl = $(navEl); | |
5767 | var isSubnavbar = $navEl.hasClass('subnavbar'); | |
5768 | var isLeft = $navEl.hasClass('left'); | |
5769 | var isTitle = $navEl.hasClass('title'); | |
5770 | if (!fromLarge && $navEl.hasClass('.title-large')) { return; } | |
5771 | var el = { | |
5772 | el: navEl, | |
5773 | }; | |
5774 | if (fromLarge) { | |
5775 | if (isTitle) { return; } | |
5776 | if ($navEl.hasClass('title-large')) { | |
5777 | if (!separateNavbar) { return; } | |
5778 | if (toLarge) { | |
5779 | if (els.indexOf(el) < 0) { els.push(el); } | |
5780 | el.overflow = 'visible'; | |
5781 | el.transform = 'translateX(100%)'; | |
5782 | $navEl.find('.title-large-text, .title-large-inner').each(function (subIndex, subNavEl) { | |
5783 | els.push({ | |
5784 | el: subNavEl, | |
5785 | transform: function (progress) { return ("translateX(" + (-100 + progress * 100 * inverter) + "%)"); }, | |
5786 | }); | |
5787 | }); | |
5788 | } else { | |
5789 | if (els.indexOf(el) < 0) { els.push(el); } | |
5790 | el.overflow = 'hidden'; | |
5791 | el.transform = function (progress) { return ("translateY(calc(" + (-progress) + " * var(--f7-navbar-large-title-height)))"); }; | |
5792 | $navEl.find('.title-large-text, .title-large-inner').each(function (subIndex, subNavEl) { | |
5793 | els.push({ | |
5794 | el: subNavEl, | |
5795 | transform: function (progress) { return ("translateX(" + (progress * 100 * inverter) + "%) translateY(calc(" + progress + " * var(--f7-navbar-large-title-height)))"); }, | |
5796 | }); | |
5797 | }); | |
5798 | } | |
5799 | return; | |
5800 | } | |
5801 | } | |
5802 | if (toLarge) { | |
5803 | if (!fromLarge) { | |
5804 | if ($navEl.hasClass('title-large')) { | |
5805 | if (!separateNavbar) { return; } | |
5806 | if (els.indexOf(el) < 0) { els.push(el); } | |
5807 | el.opacity = 0; | |
5808 | } | |
5809 | } | |
5810 | if (isLeft && separateNavbar) { | |
5811 | if (els.indexOf(el) < 0) { els.push(el); } | |
5812 | el.opacity = function (progress) { return (1 - (Math.pow( progress, 0.33 ))); }; | |
5813 | $navEl.find('.back span').each(function (subIndex, subNavEl) { | |
5814 | els.push({ | |
5815 | el: subNavEl, | |
5816 | 'transform-origin': transformOrigin, | |
5817 | transform: function (progress) { return ("translateY(calc(var(--f7-navbar-height) * " + progress + ")) scale(" + (1 + (1 * progress)) + ")"); }, | |
5818 | }); | |
5819 | }); | |
5820 | return; | |
5821 | } | |
5822 | } | |
5823 | if ($navEl.hasClass('title-large')) { return; } | |
5d51ea26 | 5824 | var isSliding = $navEl.hasClass('sliding') || $currentNavbarInnerEl.hasClass('sliding'); |
5309fbda DC |
5825 | if (els.indexOf(el) < 0) { els.push(el); } |
5826 | if (!isSubnavbar || (isSubnavbar && !isSliding)) { | |
5827 | el.opacity = function (progress) { return (1 - (Math.pow( progress, 0.33 ))); }; | |
5828 | } | |
5829 | if (isSliding) { | |
5830 | var transformTarget = el; | |
5831 | if (isLeft && activeNavBackIconText.length && params.iosAnimateNavbarBackIcon) { | |
5832 | var textEl = { el: activeNavBackIconText[0] }; | |
5833 | transformTarget = textEl; | |
5834 | els.push(textEl); | |
5835 | } | |
5836 | transformTarget.transform = function (progress) { | |
5837 | var activeNavTranslate = progress * transformTarget.el.f7NavbarRightOffset; | |
5838 | if (Device.pixelRatio === 1) { activeNavTranslate = Math.round(activeNavTranslate); } | |
5839 | if (isSubnavbar && currentNavIsLarge && separateNavbar) { | |
5840 | return ("translate3d(" + activeNavTranslate + "px, calc(-1 * var(--f7-navbar-large-collapse-progress) * var(--f7-navbar-large-title-height)), 0)"); | |
5841 | } | |
5842 | return ("translate3d(" + activeNavTranslate + "px,0,0)"); | |
5843 | }; | |
5844 | } | |
5845 | }); | |
5846 | $previousNavElements | |
5847 | .each(function (index, navEl) { | |
5848 | var $navEl = $(navEl); | |
5849 | var isSubnavbar = $navEl.hasClass('subnavbar'); | |
5850 | var isLeft = $navEl.hasClass('left'); | |
5851 | var isTitle = $navEl.hasClass('title'); | |
5852 | var el = { | |
5853 | el: navEl, | |
5854 | }; | |
5855 | if (toLarge) { | |
5856 | if (isTitle) { return; } | |
5857 | if (els.indexOf(el) < 0) { els.push(el); } | |
5858 | ||
5859 | if ($navEl.hasClass('title-large')) { | |
5860 | if (!separateNavbar) { return; } | |
5861 | if (fromLarge) { | |
5862 | el.opacity = 1; | |
5863 | el.overflow = 'visible'; | |
5864 | el.transform = 'translateY(0)'; | |
5865 | $navEl.find('.title-large-text').each(function (subIndex, subNavEl) { | |
5866 | els.push({ | |
5867 | el: subNavEl, | |
5868 | 'transform-origin': transformOrigin, | |
5869 | opacity: function (progress) { return (Math.pow( progress, 3 )); }, | |
5870 | transform: function (progress) { return ("translateY(calc(" + (-1 + progress * 1) + " * var(--f7-navbar-large-title-height))) scale(" + (0.5 + progress * 0.5) + ")"); }, | |
5871 | }); | |
5872 | }); | |
5873 | } else { | |
5874 | el.transform = function (progress) { return ("translateY(calc(" + (progress - 1) + " * var(--f7-navbar-large-title-height)))"); }; | |
5875 | el.opacity = 1; | |
5876 | el.overflow = 'hidden'; | |
5877 | $navEl.find('.title-large-text').each(function (subIndex, subNavEl) { | |
5878 | els.push({ | |
5879 | el: subNavEl, | |
5880 | 'transform-origin': transformOrigin, | |
5881 | opacity: function (progress) { return (Math.pow( progress, 3 )); }, | |
5882 | transform: function (progress) { return ("scale(" + (0.5 + progress * 0.5) + ")"); }, | |
5883 | }); | |
5884 | }); | |
5885 | } | |
5886 | $navEl.find('.title-large-inner').each(function (subIndex, subNavEl) { | |
5887 | els.push({ | |
5888 | el: subNavEl, | |
5889 | 'transform-origin': transformOrigin, | |
5890 | opacity: function (progress) { return (Math.pow( progress, 3 )); }, | |
5891 | transform: function (progress) { return ("translateX(" + (-100 * (1 - progress) * inverter) + "%)"); }, | |
5892 | }); | |
5893 | }); | |
5894 | return; | |
5895 | } | |
5896 | } | |
5897 | if ($navEl.hasClass('title-large')) { return; } | |
5d51ea26 | 5898 | var isSliding = $navEl.hasClass('sliding') || $previousNavbarInnerEl.hasClass('sliding'); |
5309fbda DC |
5899 | if (els.indexOf(el) < 0) { els.push(el); } |
5900 | if (!isSubnavbar || (isSubnavbar && !isSliding)) { | |
5901 | el.opacity = function (progress) { return (Math.pow( progress, 3 )); }; | |
5902 | } | |
5903 | if (isSliding) { | |
5904 | var transformTarget = el; | |
5905 | if (isLeft && previousNavBackIconText.length && params.iosAnimateNavbarBackIcon) { | |
5d51ea26 | 5906 | var textEl = { el: previousNavBackIconText[0] }; |
5309fbda DC |
5907 | transformTarget = textEl; |
5908 | els.push(textEl); | |
5909 | } | |
5910 | transformTarget.transform = function (progress) { | |
5911 | var previousNavTranslate = transformTarget.el.f7NavbarLeftOffset * (1 - progress); | |
5912 | if (Device.pixelRatio === 1) { previousNavTranslate = Math.round(previousNavTranslate); } | |
5913 | if (isSubnavbar && previousNavIsLarge && separateNavbar) { | |
5914 | return ("translate3d(" + previousNavTranslate + "px, calc(-1 * var(--f7-navbar-large-collapse-progress) * var(--f7-navbar-large-title-height)), 0)"); | |
5915 | } | |
5916 | return ("translate3d(" + previousNavTranslate + "px,0,0)"); | |
5917 | }; | |
5918 | } | |
5919 | }); | |
5920 | return els; | |
5921 | } | |
5922 | ||
5923 | function setAnimatableNavElements(ref) { | |
5924 | if ( ref === void 0 ) ref = {}; | |
5925 | var progress = ref.progress; | |
5926 | var reset = ref.reset; | |
5927 | var transition = ref.transition; | |
5928 | ||
5929 | var styles = ['overflow', 'transform', 'transform-origin', 'opacity']; | |
5930 | for (var i = 0; i < animatableNavEls.length; i += 1) { | |
5931 | var el = animatableNavEls[i]; | |
5932 | if (el && el.el) { | |
5933 | if (transition === true) { el.el.classList.add('navbar-page-transitioning'); } | |
5934 | if (transition === false) { el.el.classList.remove('navbar-page-transitioning'); } | |
5935 | for (var j = 0; j < styles.length; j += 1) { | |
5936 | var styleProp = styles[j]; | |
5937 | if (el[styleProp]) { | |
5938 | if (reset) { | |
5939 | el.el.style[styleProp] = ''; | |
5940 | } else if (typeof el[styleProp] === 'function') { | |
5941 | el.el.style[styleProp] = el[styleProp](progress); | |
5942 | } else { | |
5943 | el.el.style[styleProp] = el[styleProp]; | |
5944 | } | |
5945 | } | |
5946 | } | |
5947 | } | |
5948 | } | |
5949 | } | |
5950 | ||
5951 | function handleTouchStart(e) { | |
5952 | var swipeBackEnabled = params[((app.theme) + "SwipeBack")]; | |
5953 | if (!allowViewTouchMove || !swipeBackEnabled || isTouched || (app.swipeout && app.swipeout.el) || !router.allowPageChange) { return; } | |
5954 | if ($(e.target).closest('.range-slider, .calendar-months').length > 0) { return; } | |
5955 | if ($(e.target).closest('.page-master, .page-master-detail').length > 0 && params.masterDetailBreakpoint > 0 && app.width >= params.masterDetailBreakpoint) { return; } | |
5956 | isMoved = false; | |
5957 | isTouched = true; | |
5958 | isScrolling = undefined; | |
5959 | touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX; | |
5960 | touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY; | |
5961 | touchStartTime = Utils.now(); | |
5962 | dynamicNavbar = router.dynamicNavbar; | |
5963 | separateNavbar = router.separateNavbar; | |
5964 | } | |
5965 | function handleTouchMove(e) { | |
5966 | if (!isTouched) { return; } | |
5967 | var pageX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; | |
5968 | var pageY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; | |
5969 | if (typeof isScrolling === 'undefined') { | |
5970 | isScrolling = !!(isScrolling || Math.abs(pageY - touchesStart.y) > Math.abs(pageX - touchesStart.x)) || (pageX < touchesStart.x && !app.rtl) || (pageX > touchesStart.x && app.rtl); | |
5971 | } | |
5972 | if (isScrolling || e.f7PreventSwipeBack || app.preventSwipeBack) { | |
5973 | isTouched = false; | |
5974 | return; | |
5975 | } | |
5976 | if (!isMoved) { | |
5977 | // Calc values during first move fired | |
5978 | var cancel = false; | |
5979 | var target = $(e.target); | |
5980 | ||
5981 | var swipeout = target.closest('.swipeout'); | |
5982 | if (swipeout.length > 0) { | |
5983 | if (!app.rtl && swipeout.find('.swipeout-actions-left').length > 0) { cancel = true; } | |
5984 | if (app.rtl && swipeout.find('.swipeout-actions-right').length > 0) { cancel = true; } | |
5985 | } | |
5986 | ||
5d51ea26 DC |
5987 | $currentPageEl = target.closest('.page'); |
5988 | if ($currentPageEl.hasClass('no-swipeback') || target.closest('.no-swipeback, .card-opened').length > 0) { cancel = true; } | |
5989 | $previousPageEl = $el.find('.page-previous:not(.stacked)'); | |
5990 | if ($previousPageEl.length > 1) { | |
5991 | $previousPageEl = $previousPageEl.eq($previousPageEl.length - 1); | |
5992 | } | |
5309fbda DC |
5993 | var notFromBorder = touchesStart.x - $el.offset().left > paramsSwipeBackActiveArea; |
5994 | viewContainerWidth = $el.width(); | |
5995 | if (app.rtl) { | |
5996 | notFromBorder = touchesStart.x < ($el.offset().left - $el[0].scrollLeft) + (viewContainerWidth - paramsSwipeBackActiveArea); | |
5997 | } else { | |
5998 | notFromBorder = touchesStart.x - $el.offset().left > paramsSwipeBackActiveArea; | |
5999 | } | |
6000 | if (notFromBorder) { cancel = true; } | |
5d51ea26 | 6001 | if ($previousPageEl.length === 0 || $currentPageEl.length === 0) { cancel = true; } |
5309fbda DC |
6002 | if (cancel) { |
6003 | isTouched = false; | |
6004 | return; | |
6005 | } | |
6006 | ||
6007 | if (paramsSwipeBackAnimateShadow) { | |
5d51ea26 DC |
6008 | $pageShadowEl = $currentPageEl.find('.page-shadow-effect'); |
6009 | if ($pageShadowEl.length === 0) { | |
6010 | $pageShadowEl = $('<div class="page-shadow-effect"></div>'); | |
6011 | $currentPageEl.append($pageShadowEl); | |
5309fbda DC |
6012 | } |
6013 | } | |
6014 | if (paramsSwipeBackAnimateOpacity) { | |
5d51ea26 DC |
6015 | $pageOpacityEl = $previousPageEl.find('.page-opacity-effect'); |
6016 | if ($pageOpacityEl.length === 0) { | |
6017 | $pageOpacityEl = $('<div class="page-opacity-effect"></div>'); | |
6018 | $previousPageEl.append($pageOpacityEl); | |
5309fbda DC |
6019 | } |
6020 | } | |
6021 | ||
6022 | if (dynamicNavbar) { | |
6023 | if (separateNavbar) { | |
5d51ea26 DC |
6024 | $currentNavbarInnerEl = $navbarEl.find('.navbar-current:not(.stacked)'); |
6025 | $previousNavbarInnerEl = $navbarEl.find('.navbar-previous:not(.stacked)'); | |
5309fbda | 6026 | } else { |
5d51ea26 DC |
6027 | $currentNavbarInnerEl = $currentPageEl.children('.navbar').children('.navbar-inner'); |
6028 | $previousNavbarInnerEl = $previousPageEl.children('.navbar').children('.navbar-inner'); | |
6029 | } | |
6030 | if ($previousNavbarInnerEl.length > 1) { | |
6031 | $previousNavbarInnerEl = $previousNavbarInnerEl.eq($previousNavbarInnerEl.length - 1); | |
5309fbda DC |
6032 | } |
6033 | ||
5d51ea26 | 6034 | animatableNavEls = animatableNavElements(); |
5309fbda DC |
6035 | } |
6036 | ||
6037 | // Close/Hide Any Picker | |
6038 | if ($('.sheet.modal-in').length > 0 && app.sheet) { | |
6039 | app.sheet.close($('.sheet.modal-in')); | |
6040 | } | |
6041 | } | |
6042 | e.f7PreventPanelSwipe = true; | |
6043 | isMoved = true; | |
6044 | app.preventSwipePanelBySwipeBack = true; | |
6045 | e.preventDefault(); | |
6046 | ||
6047 | // RTL inverter | |
6048 | var inverter = app.rtl ? -1 : 1; | |
6049 | ||
6050 | // Touches diff | |
6051 | touchesDiff = (pageX - touchesStart.x - paramsSwipeBackThreshold) * inverter; | |
6052 | if (touchesDiff < 0) { touchesDiff = 0; } | |
6053 | var percentage = Math.min(Math.max(touchesDiff / viewContainerWidth, 0), 1); | |
6054 | ||
6055 | // Swipe Back Callback | |
6056 | var callbackData = { | |
6057 | percentage: percentage, | |
6058 | progress: percentage, | |
5d51ea26 DC |
6059 | currentPageEl: $currentPageEl[0], |
6060 | previousPageEl: $previousPageEl[0], | |
6061 | currentNavbarEl: $currentNavbarInnerEl[0], | |
6062 | previousNavbarEl: $previousNavbarInnerEl[0], | |
5309fbda DC |
6063 | }; |
6064 | $el.trigger('swipeback:move', callbackData); | |
6065 | router.emit('swipebackMove', callbackData); | |
6066 | ||
6067 | // Transform pages | |
6068 | var currentPageTranslate = touchesDiff * inverter; | |
6069 | var previousPageTranslate = ((touchesDiff / 5) - (viewContainerWidth / 5)) * inverter; | |
6070 | if (!app.rtl) { | |
6071 | currentPageTranslate = Math.min(currentPageTranslate, viewContainerWidth); | |
6072 | previousPageTranslate = Math.min(previousPageTranslate, 0); | |
6073 | } else { | |
6074 | currentPageTranslate = Math.max(currentPageTranslate, -viewContainerWidth); | |
6075 | previousPageTranslate = Math.max(previousPageTranslate, 0); | |
6076 | } | |
6077 | if (Device.pixelRatio === 1) { | |
6078 | currentPageTranslate = Math.round(currentPageTranslate); | |
6079 | previousPageTranslate = Math.round(previousPageTranslate); | |
6080 | } | |
6081 | ||
6082 | router.swipeBackActive = true; | |
5d51ea26 | 6083 | $([$currentPageEl[0], $previousPageEl[0]]).addClass('page-swipeback-active'); |
5309fbda | 6084 | |
5d51ea26 DC |
6085 | $currentPageEl.transform(("translate3d(" + currentPageTranslate + "px,0,0)")); |
6086 | if (paramsSwipeBackAnimateShadow) { $pageShadowEl[0].style.opacity = 1 - (1 * percentage); } | |
5309fbda | 6087 | |
5d51ea26 DC |
6088 | if (app.theme === 'ios') { |
6089 | $previousPageEl.transform(("translate3d(" + previousPageTranslate + "px,0,0)")); | |
5309fbda | 6090 | } |
5d51ea26 | 6091 | if (paramsSwipeBackAnimateOpacity) { $pageShadowEl[0].style.opacity = 1 - (1 * percentage); } |
5309fbda DC |
6092 | |
6093 | // Dynamic Navbars Animation | |
6094 | if (!dynamicNavbar) { return; } | |
6095 | ||
6096 | setAnimatableNavElements({ progress: percentage }); | |
6097 | } | |
6098 | function handleTouchEnd() { | |
6099 | app.preventSwipePanelBySwipeBack = false; | |
6100 | if (!isTouched || !isMoved) { | |
6101 | isTouched = false; | |
6102 | isMoved = false; | |
6103 | return; | |
6104 | } | |
6105 | isTouched = false; | |
6106 | isMoved = false; | |
6107 | router.swipeBackActive = false; | |
5d51ea26 | 6108 | $([$currentPageEl[0], $previousPageEl[0]]).removeClass('page-swipeback-active'); |
5309fbda | 6109 | if (touchesDiff === 0) { |
5d51ea26 DC |
6110 | $([$currentPageEl[0], $previousPageEl[0]]).transform(''); |
6111 | if ($pageShadowEl && $pageShadowEl.length > 0) { $pageShadowEl.remove(); } | |
6112 | if ($pageOpacityEl && $pageOpacityEl.length > 0) { $pageOpacityEl.remove(); } | |
5309fbda DC |
6113 | if (dynamicNavbar) { |
6114 | setAnimatableNavElements({ reset: true }); | |
6115 | } | |
6116 | return; | |
6117 | } | |
6118 | var timeDiff = Utils.now() - touchStartTime; | |
6119 | var pageChanged = false; | |
6120 | // Swipe back to previous page | |
6121 | if ( | |
6122 | (timeDiff < 300 && touchesDiff > 10) | |
6123 | || (timeDiff >= 300 && touchesDiff > viewContainerWidth / 2) | |
6124 | ) { | |
5d51ea26 DC |
6125 | $currentPageEl.removeClass('page-current').addClass(("page-next" + (app.theme !== 'ios' ? ' page-next-on-right' : ''))); |
6126 | $previousPageEl.removeClass('page-previous').addClass('page-current').removeAttr('aria-hidden'); | |
6127 | if ($pageShadowEl) { $pageShadowEl[0].style.opacity = ''; } | |
6128 | if ($pageOpacityEl) { $pageOpacityEl[0].style.opacity = ''; } | |
5309fbda | 6129 | if (dynamicNavbar) { |
5d51ea26 DC |
6130 | $currentNavbarInnerEl.removeClass('navbar-current').addClass('navbar-next'); |
6131 | $previousNavbarInnerEl.removeClass('navbar-previous').addClass('navbar-current').removeAttr('aria-hidden'); | |
5309fbda DC |
6132 | } |
6133 | pageChanged = true; | |
6134 | } | |
6135 | // Reset custom styles | |
6136 | // Add transitioning class for transition-duration | |
5d51ea26 | 6137 | $([$currentPageEl[0], $previousPageEl[0]]).addClass('page-transitioning page-transitioning-swipeback').transform(''); |
5309fbda DC |
6138 | |
6139 | if (dynamicNavbar) { | |
6140 | setAnimatableNavElements({ progress: pageChanged ? 1 : 0, transition: true }); | |
6141 | } | |
6142 | allowViewTouchMove = false; | |
6143 | router.allowPageChange = false; | |
6144 | ||
6145 | // Swipe Back Callback | |
6146 | var callbackData = { | |
5d51ea26 DC |
6147 | currentPageEl: $currentPageEl[0], |
6148 | previousPageEl: $previousPageEl[0], | |
6149 | currentNavbarEl: $currentNavbarInnerEl[0], | |
6150 | previousNavbarEl: $previousNavbarInnerEl[0], | |
5309fbda DC |
6151 | }; |
6152 | ||
6153 | if (pageChanged) { | |
6154 | // Update Route | |
5d51ea26 DC |
6155 | router.currentRoute = $previousPageEl[0].f7Page.route; |
6156 | router.currentPage = $previousPageEl[0]; | |
5309fbda DC |
6157 | |
6158 | // Page before animation callback | |
5d51ea26 DC |
6159 | router.pageCallback('beforeOut', $currentPageEl, $currentNavbarInnerEl, 'current', 'next', { route: $currentPageEl[0].f7Page.route, swipeBack: true }); |
6160 | router.pageCallback('beforeIn', $previousPageEl, $previousNavbarInnerEl, 'previous', 'current', { route: $previousPageEl[0].f7Page.route, swipeBack: true }, $currentPageEl[0]); | |
5309fbda DC |
6161 | |
6162 | $el.trigger('swipeback:beforechange', callbackData); | |
6163 | router.emit('swipebackBeforeChange', callbackData); | |
6164 | } else { | |
6165 | $el.trigger('swipeback:beforereset', callbackData); | |
6166 | router.emit('swipebackBeforeReset', callbackData); | |
6167 | } | |
6168 | ||
5d51ea26 DC |
6169 | $currentPageEl.transitionEnd(function () { |
6170 | $([$currentPageEl[0], $previousPageEl[0]]).removeClass('page-transitioning page-transitioning-swipeback'); | |
5309fbda DC |
6171 | if (dynamicNavbar) { |
6172 | setAnimatableNavElements({ reset: true, transition: false }); | |
6173 | } | |
6174 | allowViewTouchMove = true; | |
6175 | router.allowPageChange = true; | |
6176 | if (pageChanged) { | |
6177 | // Update History | |
6178 | if (router.history.length === 1) { | |
6179 | router.history.unshift(router.url); | |
6180 | } | |
6181 | router.history.pop(); | |
6182 | router.saveHistory(); | |
6183 | ||
6184 | // Update push state | |
6185 | if (params.pushState) { | |
6186 | History.back(); | |
6187 | } | |
6188 | ||
6189 | // Page after animation callback | |
5d51ea26 DC |
6190 | router.pageCallback('afterOut', $currentPageEl, $currentNavbarInnerEl, 'current', 'next', { route: $currentPageEl[0].f7Page.route, swipeBack: true }); |
6191 | router.pageCallback('afterIn', $previousPageEl, $previousNavbarInnerEl, 'previous', 'current', { route: $previousPageEl[0].f7Page.route, swipeBack: true }); | |
5309fbda DC |
6192 | |
6193 | // Remove Old Page | |
5d51ea26 DC |
6194 | if (params.stackPages && router.initialPages.indexOf($currentPageEl[0]) >= 0) { |
6195 | $currentPageEl.addClass('stacked'); | |
5309fbda | 6196 | if (separateNavbar) { |
5d51ea26 | 6197 | $currentNavbarInnerEl.addClass('stacked'); |
5309fbda DC |
6198 | } |
6199 | } else { | |
5d51ea26 DC |
6200 | router.pageCallback('beforeRemove', $currentPageEl, $currentNavbarInnerEl, 'next', { swipeBack: true }); |
6201 | router.removePage($currentPageEl); | |
5309fbda | 6202 | if (separateNavbar) { |
5d51ea26 | 6203 | router.removeNavbar($currentNavbarInnerEl); |
5309fbda DC |
6204 | } |
6205 | } | |
6206 | ||
6207 | $el.trigger('swipeback:afterchange', callbackData); | |
6208 | router.emit('swipebackAfterChange', callbackData); | |
6209 | ||
6210 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
6211 | ||
6212 | if (params.preloadPreviousPage) { | |
6213 | router.back(router.history[router.history.length - 2], { preload: true }); | |
6214 | } | |
6215 | } else { | |
6216 | $el.trigger('swipeback:afterreset', callbackData); | |
6217 | router.emit('swipebackAfterReset', callbackData); | |
6218 | } | |
5d51ea26 DC |
6219 | if ($pageShadowEl && $pageShadowEl.length > 0) { $pageShadowEl.remove(); } |
6220 | if ($pageOpacityEl && $pageOpacityEl.length > 0) { $pageOpacityEl.remove(); } | |
5309fbda DC |
6221 | }); |
6222 | } | |
6223 | ||
6224 | function attachEvents() { | |
6225 | var passiveListener = (app.touchEvents.start === 'touchstart' && Support.passiveListener) ? { passive: true, capture: false } : false; | |
6226 | $el.on(app.touchEvents.start, handleTouchStart, passiveListener); | |
6227 | app.on('touchmove:active', handleTouchMove); | |
6228 | app.on('touchend:passive', handleTouchEnd); | |
6229 | } | |
6230 | function detachEvents() { | |
6231 | var passiveListener = (app.touchEvents.start === 'touchstart' && Support.passiveListener) ? { passive: true, capture: false } : false; | |
6232 | $el.off(app.touchEvents.start, handleTouchStart, passiveListener); | |
6233 | app.off('touchmove:active', handleTouchMove); | |
6234 | app.off('touchend:passive', handleTouchEnd); | |
6235 | } | |
6236 | ||
6237 | attachEvents(); | |
6238 | ||
6239 | router.on('routerDestroy', detachEvents); | |
6240 | } | |
6241 | ||
6242 | function redirect (direction, route, options) { | |
6243 | var router = this; | |
6244 | var redirect = route.route.redirect; | |
6245 | if (options.initial && router.params.pushState) { | |
6246 | options.replaceState = true; // eslint-disable-line | |
6247 | options.history = true; // eslint-disable-line | |
6248 | } | |
6249 | function redirectResolve(redirectUrl, redirectOptions) { | |
6250 | if ( redirectOptions === void 0 ) redirectOptions = {}; | |
6251 | ||
6252 | router.allowPageChange = true; | |
6253 | router[direction](redirectUrl, Utils.extend({}, options, redirectOptions)); | |
6254 | } | |
6255 | function redirectReject() { | |
6256 | router.allowPageChange = true; | |
6257 | } | |
6258 | if (typeof redirect === 'function') { | |
6259 | router.allowPageChange = false; | |
6260 | var redirectUrl = redirect.call(router, route, redirectResolve, redirectReject); | |
6261 | if (redirectUrl && typeof redirectUrl === 'string') { | |
6262 | router.allowPageChange = true; | |
6263 | return router[direction](redirectUrl, options); | |
6264 | } | |
6265 | return router; | |
6266 | } | |
6267 | return router[direction](redirect, options); | |
6268 | } | |
6269 | ||
6270 | function processQueue(router, routerQueue, routeQueue, to, from, resolve, reject) { | |
6271 | var queue = []; | |
6272 | ||
6273 | if (Array.isArray(routeQueue)) { | |
6274 | queue.push.apply(queue, routeQueue); | |
6275 | } else if (routeQueue && typeof routeQueue === 'function') { | |
6276 | queue.push(routeQueue); | |
6277 | } | |
6278 | if (routerQueue) { | |
6279 | if (Array.isArray(routerQueue)) { | |
6280 | queue.push.apply(queue, routerQueue); | |
6281 | } else { | |
6282 | queue.push(routerQueue); | |
6283 | } | |
6284 | } | |
6285 | ||
6286 | function next() { | |
6287 | if (queue.length === 0) { | |
6288 | resolve(); | |
6289 | return; | |
6290 | } | |
6291 | var queueItem = queue.shift(); | |
6292 | ||
6293 | queueItem.call( | |
6294 | router, | |
6295 | to, | |
6296 | from, | |
6297 | function () { | |
6298 | next(); | |
6299 | }, | |
6300 | function () { | |
6301 | reject(); | |
6302 | } | |
6303 | ); | |
6304 | } | |
6305 | next(); | |
6306 | } | |
6307 | ||
6308 | function processRouteQueue (to, from, resolve, reject) { | |
6309 | var router = this; | |
6310 | function enterNextRoute() { | |
6311 | if (to && to.route && (router.params.routesBeforeEnter || to.route.beforeEnter)) { | |
6312 | router.allowPageChange = false; | |
6313 | processQueue( | |
6314 | router, | |
6315 | router.params.routesBeforeEnter, | |
6316 | to.route.beforeEnter, | |
6317 | to, | |
6318 | from, | |
6319 | function () { | |
6320 | router.allowPageChange = true; | |
6321 | resolve(); | |
6322 | }, | |
6323 | function () { | |
6324 | reject(); | |
6325 | } | |
6326 | ); | |
6327 | } else { | |
6328 | resolve(); | |
6329 | } | |
6330 | } | |
6331 | function leaveCurrentRoute() { | |
6332 | if (from && from.route && (router.params.routesBeforeLeave || from.route.beforeLeave)) { | |
6333 | router.allowPageChange = false; | |
6334 | processQueue( | |
6335 | router, | |
6336 | router.params.routesBeforeLeave, | |
6337 | from.route.beforeLeave, | |
6338 | to, | |
6339 | from, | |
6340 | function () { | |
6341 | router.allowPageChange = true; | |
6342 | enterNextRoute(); | |
6343 | }, | |
6344 | function () { | |
6345 | reject(); | |
6346 | } | |
6347 | ); | |
6348 | } else { | |
6349 | enterNextRoute(); | |
6350 | } | |
6351 | } | |
6352 | leaveCurrentRoute(); | |
6353 | } | |
6354 | ||
6355 | function appRouterCheck (router, method) { | |
6356 | if (!router.view) { | |
6357 | throw new Error(("Framework7: it is not allowed to use router methods on global app router. Use router methods only on related View, e.g. app.views.main.router." + method + "(...)")); | |
6358 | } | |
6359 | } | |
6360 | ||
6361 | function refreshPage() { | |
6362 | var router = this; | |
6363 | appRouterCheck(router, 'refreshPage'); | |
6364 | return router.navigate(router.currentRoute.url, { | |
6365 | ignoreCache: true, | |
6366 | reloadCurrent: true, | |
6367 | }); | |
6368 | } | |
6369 | ||
6370 | function forward(el, forwardOptions) { | |
6371 | if ( forwardOptions === void 0 ) forwardOptions = {}; | |
6372 | ||
6373 | var router = this; | |
6374 | var $el = $(el); | |
6375 | var app = router.app; | |
6376 | var view = router.view; | |
6377 | var options = Utils.extend(false, { | |
6378 | animate: router.params.animate, | |
6379 | pushState: true, | |
6380 | replaceState: false, | |
6381 | history: true, | |
6382 | reloadCurrent: router.params.reloadPages, | |
6383 | reloadPrevious: false, | |
6384 | reloadAll: false, | |
6385 | clearPreviousHistory: false, | |
6386 | reloadDetail: router.params.reloadDetail, | |
6387 | on: {}, | |
6388 | }, forwardOptions); | |
6389 | ||
6390 | var masterDetailEnabled = router.params.masterDetailBreakpoint > 0; | |
6391 | var isMaster = masterDetailEnabled && options.route && options.route.route && options.route.route.master === true; | |
6392 | var masterPageEl; | |
6393 | var otherDetailPageEl; | |
6394 | ||
6395 | var currentRouteIsModal = router.currentRoute.modal; | |
6396 | var modalType; | |
6397 | if (!currentRouteIsModal) { | |
6398 | ('popup popover sheet loginScreen actions customModal panel').split(' ').forEach(function (modalLoadProp) { | |
6399 | if (router.currentRoute && router.currentRoute.route && router.currentRoute.route[modalLoadProp]) { | |
6400 | currentRouteIsModal = true; | |
6401 | modalType = modalLoadProp; | |
6402 | } | |
6403 | }); | |
6404 | } | |
6405 | ||
6406 | if (currentRouteIsModal) { | |
6407 | var modalToClose = router.currentRoute.modal | |
6408 | || router.currentRoute.route.modalInstance | |
6409 | || app[modalType].get(); | |
6410 | var previousUrl = router.history[router.history.length - 2]; | |
6411 | var previousRoute = router.findMatchingRoute(previousUrl); | |
6412 | if (!previousRoute && previousUrl) { | |
6413 | previousRoute = { | |
6414 | url: previousUrl, | |
6415 | path: previousUrl.split('?')[0], | |
6416 | query: Utils.parseUrlQuery(previousUrl), | |
6417 | route: { | |
6418 | path: previousUrl.split('?')[0], | |
6419 | url: previousUrl, | |
6420 | }, | |
6421 | }; | |
6422 | } | |
6423 | ||
6424 | router.modalRemove(modalToClose); | |
6425 | } | |
6426 | ||
6427 | var dynamicNavbar = router.dynamicNavbar; | |
6428 | var separateNavbar = router.separateNavbar; | |
6429 | ||
6430 | var $viewEl = router.$el; | |
6431 | var $newPage = $el; | |
6432 | var reload = options.reloadPrevious || options.reloadCurrent || options.reloadAll; | |
6433 | var $oldPage; | |
6434 | ||
6435 | var $navbarEl; | |
6436 | var $newNavbarInner; | |
6437 | var $oldNavbarInner; | |
6438 | ||
6439 | router.allowPageChange = false; | |
6440 | if ($newPage.length === 0) { | |
6441 | router.allowPageChange = true; | |
6442 | return router; | |
6443 | } | |
6444 | ||
6445 | if ($newPage.length) { | |
6446 | // Remove theme elements | |
6447 | router.removeThemeElements($newPage); | |
6448 | } | |
6449 | ||
6450 | if (dynamicNavbar) { | |
6451 | $newNavbarInner = $newPage.children('.navbar').children('.navbar-inner'); | |
6452 | if (separateNavbar) { | |
6453 | $navbarEl = router.$navbarEl; | |
6454 | if ($newNavbarInner.length > 0) { | |
6455 | $newPage.children('.navbar').remove(); | |
6456 | } | |
6457 | if ($newNavbarInner.length === 0 && $newPage[0] && $newPage[0].f7Page) { | |
6458 | // Try from pageData | |
6459 | $newNavbarInner = $newPage[0].f7Page.$navbarEl; | |
6460 | } | |
6461 | } | |
6462 | } | |
6463 | ||
6464 | // Save Keep Alive Cache | |
6465 | if (options.route && options.route.route && options.route.route.keepAlive && !options.route.route.keepAliveData) { | |
6466 | options.route.route.keepAliveData = { | |
6467 | pageEl: $el[0], | |
6468 | }; | |
6469 | } | |
6470 | ||
6471 | // Pages In View | |
6472 | var $pagesInView = $viewEl | |
6473 | .children('.page:not(.stacked)') | |
6474 | .filter(function (index, pageInView) { return pageInView !== $newPage[0]; }); | |
6475 | ||
6476 | // Navbars In View | |
6477 | var $navbarsInView; | |
6478 | if (separateNavbar) { | |
6479 | $navbarsInView = $navbarEl | |
6480 | .children('.navbar-inner:not(.stacked)') | |
6481 | .filter(function (index, navbarInView) { return navbarInView !== $newNavbarInner[0]; }); | |
6482 | } | |
6483 | ||
6484 | // Exit when reload previous and only 1 page in view so nothing ro reload | |
6485 | if (options.reloadPrevious && $pagesInView.length < 2) { | |
6486 | router.allowPageChange = true; | |
6487 | return router; | |
6488 | } | |
6489 | ||
6490 | // Find Detail' master page | |
6491 | var isDetail; | |
6492 | var reloadDetail; | |
6493 | if (masterDetailEnabled && !options.reloadAll) { | |
6494 | for (var i = 0; i < $pagesInView.length; i += 1) { | |
6495 | if (!masterPageEl | |
6496 | && $pagesInView[i].classList.contains('page-master') | |
6497 | ) { | |
6498 | masterPageEl = $pagesInView[i]; | |
6499 | continue; // eslint-disable-line | |
6500 | } | |
6501 | } | |
6502 | isDetail = !isMaster && masterPageEl; | |
6503 | ||
6504 | if (isDetail) { | |
6505 | // Find Other Detail | |
6506 | if (masterPageEl) { | |
6507 | for (var i$1 = 0; i$1 < $pagesInView.length; i$1 += 1) { | |
6508 | if ($pagesInView[i$1].classList.contains('page-master-detail') | |
6509 | ) { | |
6510 | otherDetailPageEl = $pagesInView[i$1]; | |
6511 | continue; // eslint-disable-line | |
6512 | } | |
6513 | } | |
6514 | } | |
6515 | } | |
6516 | reloadDetail = isDetail && options.reloadDetail && app.width >= router.params.masterDetailBreakpoint && masterPageEl; | |
6517 | } | |
6518 | ||
6519 | // New Page | |
6520 | var newPagePosition = 'next'; | |
6521 | if (options.reloadCurrent || options.reloadAll || reloadDetail) { | |
6522 | newPagePosition = 'current'; | |
6523 | } else if (options.reloadPrevious) { | |
6524 | newPagePosition = 'previous'; | |
6525 | } | |
6526 | $newPage | |
5d51ea26 | 6527 | .removeClass('page-previous page-current page-next') |
5309fbda DC |
6528 | .addClass(("page-" + newPagePosition + (isMaster ? ' page-master' : '') + (isDetail ? ' page-master-detail' : ''))) |
6529 | .removeClass('stacked') | |
6530 | .trigger('page:unstack') | |
6531 | .trigger('page:position', { position: newPagePosition }); | |
5d51ea26 DC |
6532 | router.emit('pageUnstack', $newPage[0]); |
6533 | router.emit('pagePosition', $newPage[0], newPagePosition); | |
6534 | ||
5309fbda DC |
6535 | if (isMaster || isDetail) { |
6536 | $newPage.trigger('page:role', { role: isMaster ? 'master' : 'detail' }); | |
6537 | } | |
6538 | ||
6539 | ||
6540 | if (dynamicNavbar && $newNavbarInner.length) { | |
6541 | $newNavbarInner | |
5d51ea26 | 6542 | .removeClass('navbar-previous navbar-current navbar-next') |
5309fbda DC |
6543 | .addClass(("navbar-" + newPagePosition + (isMaster ? ' navbar-master' : '') + (isDetail ? ' navbar-master-detail' : ''))) |
6544 | .removeClass('stacked'); | |
6545 | } | |
6546 | ||
6547 | // Find Old Page | |
6548 | if (options.reloadCurrent || reloadDetail) { | |
6549 | $oldPage = $pagesInView.eq($pagesInView.length - 1); | |
6550 | if (separateNavbar) { | |
6551 | // $oldNavbarInner = $navbarsInView.eq($pagesInView.length - 1); | |
6552 | $oldNavbarInner = $(app.navbar.getElByPage($oldPage)); | |
6553 | } | |
6554 | } else if (options.reloadPrevious) { | |
6555 | $oldPage = $pagesInView.eq($pagesInView.length - 2); | |
6556 | if (separateNavbar) { | |
6557 | // $oldNavbarInner = $navbarsInView.eq($pagesInView.length - 2); | |
6558 | $oldNavbarInner = $(app.navbar.getElByPage($oldPage)); | |
6559 | } | |
6560 | } else if (options.reloadAll) { | |
6561 | $oldPage = $pagesInView.filter(function (index, pageEl) { return pageEl !== $newPage[0]; }); | |
6562 | if (separateNavbar) { | |
6563 | $oldNavbarInner = $navbarsInView.filter(function (index, navbarEl) { return navbarEl !== $newNavbarInner[0]; }); | |
6564 | } | |
6565 | } else { | |
6566 | if ($pagesInView.length > 1) { | |
6567 | var i$2 = 0; | |
6568 | for (i$2 = 0; i$2 < $pagesInView.length - 1; i$2 += 1) { | |
6569 | if (masterPageEl | |
6570 | && $pagesInView[i$2] === masterPageEl | |
6571 | ) { | |
6572 | $pagesInView.eq(i$2).addClass('page-master-stacked'); | |
6573 | $pagesInView.eq(i$2).trigger('page:masterstack'); | |
5d51ea26 | 6574 | router.emit('pageMasterStack', $pagesInView[i$2]); |
5309fbda DC |
6575 | if (separateNavbar) { |
6576 | $(app.navbar.getElByPage(masterPageEl)).addClass('navbar-master-stacked'); | |
6577 | } | |
6578 | continue; // eslint-disable-line | |
6579 | } | |
6580 | var oldNavbarInnerEl = app.navbar.getElByPage($pagesInView.eq(i$2)); | |
6581 | if (router.params.stackPages) { | |
6582 | $pagesInView.eq(i$2).addClass('stacked'); | |
6583 | $pagesInView.eq(i$2).trigger('page:stack'); | |
5d51ea26 | 6584 | router.emit('pageStack', $pagesInView[i$2]); |
5309fbda DC |
6585 | if (separateNavbar) { |
6586 | $(oldNavbarInnerEl).addClass('stacked'); | |
6587 | } | |
6588 | } else { | |
6589 | // Page remove event | |
6590 | router.pageCallback('beforeRemove', $pagesInView[i$2], $navbarsInView && $navbarsInView[i$2], 'previous', undefined, options); | |
6591 | router.removePage($pagesInView[i$2]); | |
6592 | if (separateNavbar && oldNavbarInnerEl) { | |
6593 | router.removeNavbar(oldNavbarInnerEl); | |
6594 | } | |
6595 | } | |
6596 | } | |
6597 | } | |
6598 | $oldPage = $viewEl | |
6599 | .children('.page:not(.stacked)') | |
6600 | .filter(function (index, page) { return page !== $newPage[0]; }); | |
6601 | if (separateNavbar) { | |
6602 | $oldNavbarInner = $navbarEl | |
6603 | .children('.navbar-inner:not(.stacked)') | |
6604 | .filter(function (index, navbarInner) { return navbarInner !== $newNavbarInner[0]; }); | |
6605 | } | |
6606 | } | |
6607 | ||
6608 | if (dynamicNavbar && !separateNavbar) { | |
6609 | $oldNavbarInner = $oldPage.children('.navbar').children('.navbar-inner'); | |
6610 | } | |
6611 | if (isDetail && !options.reloadAll) { | |
6612 | if ($oldPage.length > 1 || reloadDetail) { | |
6613 | $oldPage = $oldPage.filter(function (pageIndex, pageEl) { return !pageEl.classList.contains('page-master'); }); | |
6614 | } | |
6615 | if ($oldNavbarInner && ($oldNavbarInner.length > 1 || reloadDetail)) { | |
6616 | $oldNavbarInner = $oldNavbarInner.filter(function (navbarIndex, navbarEl) { return !navbarEl.classList.contains('navbar-master'); }); | |
6617 | } | |
6618 | } | |
6619 | ||
6620 | // Push State | |
6621 | if (router.params.pushState && (options.pushState || options.replaceState) && !options.reloadPrevious) { | |
6622 | var pushStateRoot = router.params.pushStateRoot || ''; | |
6623 | History[options.reloadCurrent || (reloadDetail && otherDetailPageEl) || options.reloadAll || options.replaceState ? 'replace' : 'push']( | |
6624 | view.id, | |
6625 | { | |
6626 | url: options.route.url, | |
6627 | }, | |
6628 | pushStateRoot + router.params.pushStateSeparator + options.route.url | |
6629 | ); | |
6630 | } | |
6631 | ||
6632 | if (!options.reloadPrevious) { | |
6633 | // Current Page & Navbar | |
6634 | router.currentPageEl = $newPage[0]; | |
6635 | if (dynamicNavbar && $newNavbarInner.length) { | |
6636 | router.currentNavbarEl = $newNavbarInner[0]; | |
6637 | } else { | |
6638 | delete router.currentNavbarEl; | |
6639 | } | |
6640 | ||
6641 | // Current Route | |
6642 | router.currentRoute = options.route; | |
6643 | } | |
6644 | ||
6645 | // Update router history | |
6646 | var url = options.route.url; | |
6647 | ||
6648 | if (options.history) { | |
6649 | if (((options.reloadCurrent || (reloadDetail && otherDetailPageEl)) && router.history.length) > 0 || options.replaceState) { | |
6650 | router.history[router.history.length - (options.reloadPrevious ? 2 : 1)] = url; | |
6651 | } else if (options.reloadPrevious) { | |
6652 | router.history[router.history.length - 2] = url; | |
6653 | } else if (options.reloadAll) { | |
6654 | router.history = [url]; | |
6655 | } else { | |
6656 | router.history.push(url); | |
6657 | } | |
6658 | } | |
6659 | router.saveHistory(); | |
6660 | ||
6661 | // Insert new page and navbar | |
6662 | var newPageInDom = $newPage.parents(doc).length > 0; | |
6663 | var f7Component = $newPage[0].f7Component; | |
6664 | if (options.reloadPrevious) { | |
6665 | if (f7Component && !newPageInDom) { | |
6666 | f7Component.$mount(function (componentEl) { | |
6667 | $(componentEl).insertBefore($oldPage); | |
6668 | }); | |
6669 | } else { | |
6670 | $newPage.insertBefore($oldPage); | |
6671 | } | |
6672 | if (separateNavbar && $newNavbarInner.length) { | |
6673 | if ($newNavbarInner.children('.title-large').length) { | |
6674 | $newNavbarInner.addClass('navbar-inner-large'); | |
6675 | } | |
6676 | if ($oldNavbarInner.length) { | |
6677 | $newNavbarInner.insertBefore($oldNavbarInner); | |
6678 | } else { | |
6679 | if (!router.$navbarEl.parents(doc).length) { | |
6680 | router.$el.prepend(router.$navbarEl); | |
6681 | } | |
6682 | $navbarEl.append($newNavbarInner); | |
6683 | } | |
6684 | } | |
6685 | } else { | |
6686 | if ($oldPage.next('.page')[0] !== $newPage[0]) { | |
6687 | if (f7Component && !newPageInDom) { | |
6688 | f7Component.$mount(function (componentEl) { | |
6689 | $viewEl.append(componentEl); | |
6690 | }); | |
6691 | } else { | |
6692 | $viewEl.append($newPage[0]); | |
6693 | } | |
6694 | } | |
6695 | if (separateNavbar && $newNavbarInner.length) { | |
6696 | if ($newNavbarInner.children('.title-large').length) { | |
6697 | $newNavbarInner.addClass('navbar-inner-large'); | |
6698 | } | |
6699 | if (!router.$navbarEl.parents(doc).length) { | |
6700 | router.$el.prepend(router.$navbarEl); | |
6701 | } | |
6702 | $navbarEl.append($newNavbarInner[0]); | |
6703 | } | |
6704 | } | |
6705 | if (!newPageInDom) { | |
6706 | router.pageCallback('mounted', $newPage, $newNavbarInner, newPagePosition, reload ? newPagePosition : 'current', options, $oldPage); | |
6707 | } else if (options.route && options.route.route && options.route.route.keepAlive && !$newPage[0].f7PageMounted) { | |
6708 | $newPage[0].f7PageMounted = true; | |
6709 | router.pageCallback('mounted', $newPage, $newNavbarInner, newPagePosition, reload ? newPagePosition : 'current', options, $oldPage); | |
6710 | } | |
6711 | ||
6712 | // Remove old page | |
6713 | if ((options.reloadCurrent || reloadDetail) && $oldPage.length > 0) { | |
6714 | if (router.params.stackPages && router.initialPages.indexOf($oldPage[0]) >= 0) { | |
6715 | $oldPage.addClass('stacked'); | |
6716 | $oldPage.trigger('page:stack'); | |
5d51ea26 | 6717 | router.emit('pageStack', $oldPage[0]); |
5309fbda DC |
6718 | if (separateNavbar) { |
6719 | $oldNavbarInner.addClass('stacked'); | |
6720 | } | |
6721 | } else { | |
6722 | // Page remove event | |
5d51ea26 DC |
6723 | router.pageCallback('beforeOut', $oldPage, $oldNavbarInner, 'current', undefined, options); |
6724 | router.pageCallback('afterOut', $oldPage, $oldNavbarInner, 'current', undefined, options); | |
6725 | router.pageCallback('beforeRemove', $oldPage, $oldNavbarInner, 'current', undefined, options); | |
5309fbda DC |
6726 | router.removePage($oldPage); |
6727 | if (separateNavbar && $oldNavbarInner && $oldNavbarInner.length) { | |
6728 | router.removeNavbar($oldNavbarInner); | |
6729 | } | |
6730 | } | |
6731 | } else if (options.reloadAll) { | |
6732 | $oldPage.each(function (index, pageEl) { | |
6733 | var $oldPageEl = $(pageEl); | |
6734 | var $oldNavbarInnerEl = $(app.navbar.getElByPage($oldPageEl)); | |
6735 | if (router.params.stackPages && router.initialPages.indexOf($oldPageEl[0]) >= 0) { | |
6736 | $oldPageEl.addClass('stacked'); | |
6737 | $oldPageEl.trigger('page:stack'); | |
5d51ea26 | 6738 | router.emit('pageStack', $oldPageEl[0]); |
5309fbda DC |
6739 | if (separateNavbar) { |
6740 | $oldNavbarInnerEl.addClass('stacked'); | |
6741 | } | |
6742 | } else { | |
6743 | // Page remove event | |
5d51ea26 DC |
6744 | if ($oldPageEl.hasClass('page-current')) { |
6745 | router.pageCallback('beforeOut', $oldPage, $oldNavbarInner, 'current', undefined, options); | |
6746 | router.pageCallback('afterOut', $oldPage, $oldNavbarInner, 'current', undefined, options); | |
6747 | } | |
5309fbda DC |
6748 | router.pageCallback('beforeRemove', $oldPageEl, $oldNavbarInner && $oldNavbarInner.eq(index), 'previous', undefined, options); |
6749 | router.removePage($oldPageEl); | |
6750 | if (separateNavbar && $oldNavbarInnerEl.length) { | |
6751 | router.removeNavbar($oldNavbarInnerEl); | |
6752 | } | |
6753 | } | |
6754 | }); | |
6755 | } else if (options.reloadPrevious) { | |
6756 | if (router.params.stackPages && router.initialPages.indexOf($oldPage[0]) >= 0) { | |
6757 | $oldPage.addClass('stacked'); | |
6758 | $oldPage.trigger('page:stack'); | |
5d51ea26 | 6759 | router.emit('pageStack', $oldPage[0]); |
5309fbda DC |
6760 | if (separateNavbar) { |
6761 | $oldNavbarInner.addClass('stacked'); | |
6762 | } | |
6763 | } else { | |
6764 | // Page remove event | |
6765 | router.pageCallback('beforeRemove', $oldPage, $oldNavbarInner, 'previous', undefined, options); | |
6766 | router.removePage($oldPage); | |
6767 | if (separateNavbar && $oldNavbarInner && $oldNavbarInner.length) { | |
6768 | router.removeNavbar($oldNavbarInner); | |
6769 | } | |
6770 | } | |
6771 | } | |
6772 | ||
6773 | // Load Tab | |
6774 | if (options.route.route.tab) { | |
6775 | router.tabLoad(options.route.route.tab, Utils.extend({}, options, { | |
6776 | history: false, | |
6777 | pushState: false, | |
6778 | })); | |
6779 | } | |
6780 | ||
6781 | // Page init and before init events | |
6782 | router.pageCallback('init', $newPage, $newNavbarInner, newPagePosition, reload ? newPagePosition : 'current', options, $oldPage); | |
6783 | ||
6784 | if (options.reloadCurrent || options.reloadAll || reloadDetail) { | |
6785 | router.allowPageChange = true; | |
6786 | router.pageCallback('beforeIn', $newPage, $newNavbarInner, newPagePosition, 'current', options); | |
5d51ea26 DC |
6787 | $newPage.removeAttr('aria-hidden'); |
6788 | if (dynamicNavbar && $newNavbarInner) { | |
6789 | $newNavbarInner.removeAttr('aria-hidden'); | |
6790 | } | |
5309fbda DC |
6791 | router.pageCallback('afterIn', $newPage, $newNavbarInner, newPagePosition, 'current', options); |
6792 | if (options.reloadCurrent && options.clearPreviousHistory) { router.clearPreviousHistory(); } | |
6793 | if (reloadDetail) { | |
6794 | masterPageEl.classList.add('page-previous'); | |
6795 | masterPageEl.classList.remove('page-current'); | |
6796 | $(masterPageEl).trigger('page:position', { position: 'previous' }); | |
5d51ea26 DC |
6797 | router.emit('pagePosition', masterPageEl, 'previous'); |
6798 | ||
5309fbda DC |
6799 | if (masterPageEl.f7Page && masterPageEl.f7Page.navbarEl) { |
6800 | masterPageEl.f7Page.navbarEl.classList.add('navbar-previous'); | |
6801 | masterPageEl.f7Page.navbarEl.classList.remove('navbar-current'); | |
6802 | } | |
6803 | } | |
6804 | return router; | |
6805 | } | |
6806 | if (options.reloadPrevious) { | |
6807 | router.allowPageChange = true; | |
6808 | return router; | |
6809 | } | |
6810 | ||
6811 | // Before animation event | |
5309fbda | 6812 | router.pageCallback('beforeOut', $oldPage, $oldNavbarInner, 'current', 'previous', options); |
5d51ea26 | 6813 | router.pageCallback('beforeIn', $newPage, $newNavbarInner, 'next', 'current', options); |
5309fbda DC |
6814 | |
6815 | // Animation | |
6816 | function afterAnimation() { | |
6817 | var pageClasses = 'page-previous page-current page-next'; | |
6818 | var navbarClasses = 'navbar-previous navbar-current navbar-next'; | |
6819 | $newPage.removeClass(pageClasses).addClass('page-current').removeAttr('aria-hidden').trigger('page:position', { position: 'current' }); | |
5d51ea26 | 6820 | router.emit('pagePosition', $newPage[0], 'current'); |
5309fbda | 6821 | $oldPage.removeClass(pageClasses).addClass('page-previous').trigger('page:position', { position: 'previous' }); |
5d51ea26 DC |
6822 | router.emit('pagePosition', $oldPage[0], 'previous'); |
6823 | ||
5309fbda DC |
6824 | if (!$oldPage.hasClass('page-master')) { |
6825 | $oldPage.attr('aria-hidden', 'true'); | |
6826 | } | |
6827 | if (dynamicNavbar) { | |
6828 | $newNavbarInner.removeClass(navbarClasses).addClass('navbar-current').removeAttr('aria-hidden'); | |
6829 | $oldNavbarInner.removeClass(navbarClasses).addClass('navbar-previous'); | |
6830 | if (!$oldNavbarInner.hasClass('navbar-master')) { | |
6831 | $oldNavbarInner.attr('aria-hidden', 'true'); | |
6832 | } | |
6833 | } | |
6834 | // After animation event | |
6835 | router.allowPageChange = true; | |
5309fbda | 6836 | router.pageCallback('afterOut', $oldPage, $oldNavbarInner, 'current', 'previous', options); |
5d51ea26 | 6837 | router.pageCallback('afterIn', $newPage, $newNavbarInner, 'next', 'current', options); |
5309fbda | 6838 | |
5d51ea26 | 6839 | var keepOldPage = (router.params.preloadPreviousPage || router.params[((app.theme) + "SwipeBack")]) && !isMaster; |
5309fbda | 6840 | if (!keepOldPage) { |
5d51ea26 | 6841 | if ($newPage.hasClass('smart-select-page') || $newPage.hasClass('photo-browser-page') || $newPage.hasClass('autocomplete-page') || $newPage.hasClass('color-picker-page')) { |
5309fbda DC |
6842 | keepOldPage = true; |
6843 | } | |
6844 | } | |
6845 | if (!keepOldPage) { | |
6846 | if (router.params.stackPages) { | |
6847 | $oldPage.addClass('stacked'); | |
6848 | $oldPage.trigger('page:stack'); | |
5d51ea26 | 6849 | router.emit('pageStack', $oldPage[0]); |
5309fbda DC |
6850 | if (separateNavbar) { |
6851 | $oldNavbarInner.addClass('stacked'); | |
6852 | } | |
6853 | } else if (!($newPage.attr('data-name') && $newPage.attr('data-name') === 'smart-select-page')) { | |
6854 | // Remove event | |
6855 | router.pageCallback('beforeRemove', $oldPage, $oldNavbarInner, 'previous', undefined, options); | |
6856 | router.removePage($oldPage); | |
6857 | if (separateNavbar && $oldNavbarInner.length) { | |
6858 | router.removeNavbar($oldNavbarInner); | |
6859 | } | |
6860 | } | |
6861 | } | |
6862 | if (options.clearPreviousHistory) { router.clearPreviousHistory(); } | |
6863 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
6864 | ||
6865 | if (router.params.pushState) { | |
6866 | History.clearRouterQueue(); | |
6867 | } | |
6868 | } | |
6869 | function setPositionClasses() { | |
6870 | var pageClasses = 'page-previous page-current page-next'; | |
6871 | var navbarClasses = 'navbar-previous navbar-current navbar-next'; | |
6872 | $oldPage.removeClass(pageClasses).addClass('page-current').removeAttr('aria-hidden').trigger('page:position', { position: 'current' }); | |
5d51ea26 | 6873 | router.emit('pagePosition', $oldPage[0], 'current'); |
5309fbda | 6874 | $newPage.removeClass(pageClasses).addClass('page-next').removeAttr('aria-hidden').trigger('page:position', { position: 'next' }); |
5d51ea26 | 6875 | router.emit('pagePosition', $newPage[0], 'next'); |
5309fbda DC |
6876 | if (dynamicNavbar) { |
6877 | $oldNavbarInner.removeClass(navbarClasses).addClass('navbar-current').removeAttr('aria-hidden'); | |
6878 | $newNavbarInner.removeClass(navbarClasses).addClass('navbar-next').removeAttr('aria-hidden'); | |
6879 | } | |
6880 | } | |
6881 | if (options.animate && !(isMaster && app.width >= router.params.masterDetailBreakpoint)) { | |
5d51ea26 | 6882 | var delay = router.params[((router.app.theme) + "PageLoadDelay")]; |
5309fbda DC |
6883 | if (delay) { |
6884 | setTimeout(function () { | |
6885 | setPositionClasses(); | |
6886 | router.animate($oldPage, $newPage, $oldNavbarInner, $newNavbarInner, 'forward', function () { | |
6887 | afterAnimation(); | |
6888 | }); | |
6889 | }, delay); | |
6890 | } else { | |
6891 | setPositionClasses(); | |
6892 | router.animate($oldPage, $newPage, $oldNavbarInner, $newNavbarInner, 'forward', function () { | |
6893 | afterAnimation(); | |
6894 | }); | |
6895 | } | |
6896 | } else { | |
6897 | afterAnimation(); | |
6898 | } | |
6899 | return router; | |
6900 | } | |
6901 | function load(loadParams, loadOptions, ignorePageChange) { | |
6902 | if ( loadParams === void 0 ) loadParams = {}; | |
6903 | if ( loadOptions === void 0 ) loadOptions = {}; | |
6904 | ||
6905 | var router = this; | |
6906 | if (!router.allowPageChange && !ignorePageChange) { return router; } | |
6907 | var params = loadParams; | |
6908 | var options = loadOptions; | |
6909 | var url = params.url; | |
6910 | var content = params.content; | |
6911 | var el = params.el; | |
6912 | var pageName = params.pageName; | |
6913 | var template = params.template; | |
6914 | var templateUrl = params.templateUrl; | |
6915 | var component = params.component; | |
6916 | var componentUrl = params.componentUrl; | |
6917 | ||
6918 | if (!options.reloadCurrent | |
6919 | && options.route | |
6920 | && options.route.route | |
6921 | && options.route.route.parentPath | |
6922 | && router.currentRoute.route | |
6923 | && router.currentRoute.route.parentPath === options.route.route.parentPath) { | |
6924 | // Do something nested | |
6925 | if (options.route.url === router.url) { | |
6926 | router.allowPageChange = true; | |
6927 | return false; | |
6928 | } | |
6929 | // Check for same params | |
6930 | var sameParams = Object.keys(options.route.params).length === Object.keys(router.currentRoute.params).length; | |
6931 | if (sameParams) { | |
6932 | // Check for equal params name | |
6933 | Object.keys(options.route.params).forEach(function (paramName) { | |
6934 | if ( | |
6935 | !(paramName in router.currentRoute.params) | |
6936 | || (router.currentRoute.params[paramName] !== options.route.params[paramName]) | |
6937 | ) { | |
6938 | sameParams = false; | |
6939 | } | |
6940 | }); | |
6941 | } | |
6942 | if (sameParams) { | |
6943 | if (options.route.route.tab) { | |
6944 | return router.tabLoad(options.route.route.tab, options); | |
6945 | } | |
6946 | return false; | |
6947 | } | |
6948 | if (!sameParams | |
6949 | && options.route.route.tab | |
6950 | && router.currentRoute.route.tab | |
6951 | && router.currentRoute.parentPath === options.route.parentPath | |
6952 | ) { | |
6953 | return router.tabLoad(options.route.route.tab, options); | |
6954 | } | |
6955 | } | |
6956 | ||
6957 | if ( | |
6958 | options.route | |
6959 | && options.route.url | |
6960 | && router.url === options.route.url | |
6961 | && !(options.reloadCurrent || options.reloadPrevious) | |
6962 | && !router.params.allowDuplicateUrls | |
6963 | ) { | |
6964 | router.allowPageChange = true; | |
6965 | return false; | |
6966 | } | |
6967 | ||
6968 | if (!options.route && url) { | |
6969 | options.route = router.parseRouteUrl(url); | |
6970 | Utils.extend(options.route, { route: { url: url, path: url } }); | |
6971 | } | |
6972 | ||
6973 | // Component Callbacks | |
6974 | function resolve(pageEl, newOptions) { | |
6975 | return router.forward(pageEl, Utils.extend(options, newOptions)); | |
6976 | } | |
6977 | function reject() { | |
6978 | router.allowPageChange = true; | |
6979 | return router; | |
6980 | } | |
6981 | ||
6982 | if (url || templateUrl || componentUrl) { | |
6983 | router.allowPageChange = false; | |
6984 | } | |
6985 | ||
6986 | // Proceed | |
6987 | if (content) { | |
6988 | router.forward(router.getPageEl(content), options); | |
6989 | } else if (template || templateUrl) { | |
6990 | // Parse template and send page element | |
6991 | try { | |
6992 | router.pageTemplateLoader(template, templateUrl, options, resolve, reject); | |
6993 | } catch (err) { | |
6994 | router.allowPageChange = true; | |
6995 | throw err; | |
6996 | } | |
6997 | } else if (el) { | |
6998 | // Load page from specified HTMLElement or by page name in pages container | |
6999 | router.forward(router.getPageEl(el), options); | |
7000 | } else if (pageName) { | |
7001 | // Load page by page name in pages container | |
7002 | router.forward(router.$el.children((".page[data-name=\"" + pageName + "\"]")).eq(0), options); | |
7003 | } else if (component || componentUrl) { | |
7004 | // Load from component (F7/Vue/React/...) | |
7005 | try { | |
7006 | router.pageComponentLoader(router.el, component, componentUrl, options, resolve, reject); | |
7007 | } catch (err) { | |
7008 | router.allowPageChange = true; | |
7009 | throw err; | |
7010 | } | |
7011 | } else if (url) { | |
7012 | // Load using XHR | |
7013 | if (router.xhr) { | |
7014 | router.xhr.abort(); | |
7015 | router.xhr = false; | |
7016 | } | |
7017 | router.xhrRequest(url, options) | |
7018 | .then(function (pageContent) { | |
7019 | router.forward(router.getPageEl(pageContent), options); | |
7020 | }) | |
7021 | .catch(function () { | |
7022 | router.allowPageChange = true; | |
7023 | }); | |
7024 | } | |
7025 | return router; | |
7026 | } | |
7027 | function navigate(navigateParams, navigateOptions) { | |
7028 | if ( navigateOptions === void 0 ) navigateOptions = {}; | |
7029 | ||
7030 | var router = this; | |
7031 | if (router.swipeBackActive) { return router; } | |
7032 | var url; | |
7033 | var createRoute; | |
7034 | var name; | |
7035 | var query; | |
7036 | var params; | |
7037 | var route; | |
7038 | if (typeof navigateParams === 'string') { | |
7039 | url = navigateParams; | |
7040 | } else { | |
7041 | url = navigateParams.url; | |
7042 | createRoute = navigateParams.route; | |
7043 | name = navigateParams.name; | |
7044 | query = navigateParams.query; | |
7045 | params = navigateParams.params; | |
7046 | } | |
7047 | if (name) { | |
7048 | // find route by name | |
7049 | route = router.findRouteByKey('name', name); | |
7050 | if (!route) { | |
7051 | throw new Error(("Framework7: route with name \"" + name + "\" not found")); | |
7052 | } | |
7053 | url = router.constructRouteUrl(route, { params: params, query: query }); | |
7054 | if (url) { | |
7055 | return router.navigate(url, navigateOptions); | |
7056 | } | |
7057 | throw new Error(("Framework7: can't construct URL for route with name \"" + name + "\"")); | |
7058 | } | |
7059 | var app = router.app; | |
7060 | appRouterCheck(router, 'navigate'); | |
7061 | if (url === '#' || url === '') { | |
7062 | return router; | |
7063 | } | |
7064 | ||
7065 | var navigateUrl = url.replace('./', ''); | |
7066 | if (navigateUrl[0] !== '/' && navigateUrl.indexOf('#') !== 0) { | |
7067 | var currentPath = router.currentRoute.parentPath || router.currentRoute.path; | |
7068 | navigateUrl = ((currentPath ? (currentPath + "/") : '/') + navigateUrl) | |
7069 | .replace('///', '/') | |
7070 | .replace('//', '/'); | |
7071 | } | |
7072 | if (createRoute) { | |
7073 | route = Utils.extend(router.parseRouteUrl(navigateUrl), { | |
7074 | route: Utils.extend({}, createRoute), | |
7075 | }); | |
7076 | } else { | |
7077 | route = router.findMatchingRoute(navigateUrl); | |
7078 | } | |
7079 | ||
7080 | if (!route) { | |
7081 | return router; | |
7082 | } | |
7083 | ||
7084 | if (route.route.redirect) { | |
7085 | return redirect.call(router, 'navigate', route, navigateOptions); | |
7086 | } | |
7087 | ||
7088 | ||
7089 | var options = {}; | |
7090 | if (route.route.options) { | |
7091 | Utils.extend(options, route.route.options, navigateOptions); | |
7092 | } else { | |
7093 | Utils.extend(options, navigateOptions); | |
7094 | } | |
7095 | options.route = route; | |
7096 | ||
7097 | if (options && options.context) { | |
7098 | route.context = options.context; | |
7099 | options.route.context = options.context; | |
7100 | } | |
7101 | ||
7102 | function resolve() { | |
7103 | var routerLoaded = false; | |
7104 | ('popup popover sheet loginScreen actions customModal panel').split(' ').forEach(function (modalLoadProp) { | |
7105 | if (route.route[modalLoadProp] && !routerLoaded) { | |
7106 | routerLoaded = true; | |
7107 | router.modalLoad(modalLoadProp, route, options); | |
7108 | } | |
7109 | }); | |
7110 | if (route.route.keepAlive && route.route.keepAliveData) { | |
7111 | router.load({ el: route.route.keepAliveData.pageEl }, options, false); | |
7112 | routerLoaded = true; | |
7113 | } | |
7114 | ('url content component pageName el componentUrl template templateUrl').split(' ').forEach(function (pageLoadProp) { | |
7115 | var obj; | |
7116 | ||
7117 | if (route.route[pageLoadProp] && !routerLoaded) { | |
7118 | routerLoaded = true; | |
7119 | router.load(( obj = {}, obj[pageLoadProp] = route.route[pageLoadProp], obj ), options, false); | |
7120 | } | |
7121 | }); | |
7122 | if (routerLoaded) { return; } | |
7123 | // Async | |
7124 | function asyncResolve(resolveParams, resolveOptions) { | |
7125 | router.allowPageChange = false; | |
7126 | var resolvedAsModal = false; | |
7127 | if (resolveOptions && resolveOptions.context) { | |
7128 | if (!route.context) { route.context = resolveOptions.context; } | |
7129 | else { route.context = Utils.extend({}, route.context, resolveOptions.context); } | |
7130 | options.route.context = route.context; | |
7131 | } | |
7132 | ('popup popover sheet loginScreen actions customModal panel').split(' ').forEach(function (modalLoadProp) { | |
7133 | if (resolveParams[modalLoadProp]) { | |
7134 | resolvedAsModal = true; | |
7135 | var modalRoute = Utils.extend({}, route, { route: resolveParams }); | |
7136 | router.allowPageChange = true; | |
7137 | router.modalLoad(modalLoadProp, modalRoute, Utils.extend(options, resolveOptions)); | |
7138 | } | |
7139 | }); | |
7140 | if (resolvedAsModal) { return; } | |
7141 | router.load(resolveParams, Utils.extend(options, resolveOptions), true); | |
7142 | } | |
7143 | function asyncReject() { | |
7144 | router.allowPageChange = true; | |
7145 | } | |
7146 | if (route.route.async) { | |
7147 | router.allowPageChange = false; | |
7148 | ||
7149 | route.route.async.call(router, options.route, router.currentRoute, asyncResolve, asyncReject); | |
7150 | } | |
7151 | } | |
7152 | function reject() { | |
7153 | router.allowPageChange = true; | |
7154 | } | |
7155 | ||
7156 | if (router.params.masterDetailBreakpoint > 0 && route.route.masterRoute) { | |
7157 | // load detail route | |
7158 | var preloadMaster = true; | |
5d51ea26 | 7159 | var masterLoaded = false; |
5309fbda | 7160 | if (router.currentRoute && router.currentRoute.route) { |
5d51ea26 DC |
7161 | if ( |
7162 | router.currentRoute.route.master | |
7163 | && ( | |
7164 | router.currentRoute.route === route.route.masterRoute | |
7165 | || router.currentRoute.route.path === route.route.masterRoute.path | |
7166 | ) | |
7167 | ) { | |
5309fbda DC |
7168 | preloadMaster = false; |
7169 | } | |
5d51ea26 DC |
7170 | if ( |
7171 | router.currentRoute.route.masterRoute | |
7172 | && (router.currentRoute.route.masterRoute === route.route.masterRoute | |
7173 | || router.currentRoute.route.masterRoute.path === route.route.masterRoute.path | |
7174 | ) | |
7175 | ) { | |
5309fbda | 7176 | preloadMaster = false; |
5d51ea26 | 7177 | masterLoaded = true; |
5309fbda DC |
7178 | } |
7179 | } | |
5d51ea26 | 7180 | if (preloadMaster || (masterLoaded && navigateOptions.reloadAll)) { |
5309fbda DC |
7181 | router.navigate(route.route.masterRoute.path, { |
7182 | animate: false, | |
7183 | reloadAll: navigateOptions.reloadAll, | |
7184 | reloadCurrent: navigateOptions.reloadCurrent, | |
7185 | reloadPrevious: navigateOptions.reloadPrevious, | |
5d51ea26 DC |
7186 | pushState: !navigateOptions.initial, |
7187 | history: !navigateOptions.initial, | |
5309fbda DC |
7188 | once: { |
7189 | pageAfterIn: function pageAfterIn() { | |
7190 | router.navigate(navigateParams, Utils.extend({}, navigateOptions, { | |
7191 | animate: false, | |
7192 | reloadAll: false, | |
7193 | reloadCurrent: false, | |
7194 | reloadPrevious: false, | |
5d51ea26 DC |
7195 | history: !navigateOptions.initial, |
7196 | pushState: !navigateOptions.initial, | |
5309fbda DC |
7197 | })); |
7198 | }, | |
7199 | }, | |
7200 | }); | |
7201 | return router; | |
7202 | } | |
7203 | } | |
7204 | ||
7205 | processRouteQueue.call( | |
7206 | router, | |
7207 | route, | |
7208 | router.currentRoute, | |
7209 | function () { | |
7210 | if (route.route.modules) { | |
7211 | app | |
7212 | .loadModules(Array.isArray(route.route.modules) ? route.route.modules : [route.route.modules]) | |
7213 | .then(function () { | |
7214 | resolve(); | |
7215 | }) | |
7216 | .catch(function () { | |
7217 | reject(); | |
7218 | }); | |
7219 | } else { | |
7220 | resolve(); | |
7221 | } | |
7222 | }, | |
7223 | function () { | |
7224 | reject(); | |
7225 | } | |
7226 | ); | |
7227 | ||
7228 | // Return Router | |
7229 | return router; | |
7230 | } | |
7231 | ||
7232 | function tabLoad(tabRoute, loadOptions) { | |
7233 | if ( loadOptions === void 0 ) loadOptions = {}; | |
7234 | ||
7235 | var router = this; | |
7236 | var options = Utils.extend({ | |
7237 | animate: router.params.animate, | |
7238 | pushState: true, | |
7239 | history: true, | |
7240 | parentPageEl: null, | |
7241 | preload: false, | |
7242 | on: {}, | |
7243 | }, loadOptions); | |
7244 | ||
7245 | var currentRoute; | |
7246 | var previousRoute; | |
7247 | if (options.route) { | |
7248 | // Set Route | |
7249 | if (!options.preload && options.route !== router.currentRoute) { | |
7250 | previousRoute = router.previousRoute; | |
7251 | router.currentRoute = options.route; | |
7252 | } | |
7253 | if (options.preload) { | |
7254 | currentRoute = options.route; | |
7255 | previousRoute = router.currentRoute; | |
7256 | } else { | |
7257 | currentRoute = router.currentRoute; | |
7258 | if (!previousRoute) { previousRoute = router.previousRoute; } | |
7259 | } | |
7260 | ||
7261 | // Update Browser History | |
7262 | if (router.params.pushState && options.pushState && !options.reloadPrevious) { | |
7263 | History.replace( | |
7264 | router.view.id, | |
7265 | { | |
7266 | url: options.route.url, | |
7267 | }, | |
7268 | (router.params.pushStateRoot || '') + router.params.pushStateSeparator + options.route.url | |
7269 | ); | |
7270 | } | |
7271 | ||
7272 | // Update Router History | |
7273 | if (options.history) { | |
7274 | router.history[Math.max(router.history.length - 1, 0)] = options.route.url; | |
7275 | router.saveHistory(); | |
7276 | } | |
7277 | } | |
7278 | ||
7279 | // Show Tab | |
7280 | var $parentPageEl = $(options.parentPageEl || router.currentPageEl); | |
7281 | var tabEl; | |
7282 | if ($parentPageEl.length && $parentPageEl.find(("#" + (tabRoute.id))).length) { | |
7283 | tabEl = $parentPageEl.find(("#" + (tabRoute.id))).eq(0); | |
7284 | } else if (router.view.selector) { | |
7285 | tabEl = (router.view.selector) + " #" + (tabRoute.id); | |
7286 | } else { | |
7287 | tabEl = "#" + (tabRoute.id); | |
7288 | } | |
7289 | var tabShowResult = router.app.tab.show({ | |
7290 | tabEl: tabEl, | |
7291 | animate: options.animate, | |
7292 | tabRoute: options.route, | |
7293 | }); | |
7294 | ||
7295 | var $newTabEl = tabShowResult.$newTabEl; | |
7296 | var $oldTabEl = tabShowResult.$oldTabEl; | |
7297 | var animated = tabShowResult.animated; | |
7298 | var onTabsChanged = tabShowResult.onTabsChanged; | |
7299 | ||
7300 | if ($newTabEl && $newTabEl.parents('.page').length > 0 && options.route) { | |
7301 | var tabParentPageData = $newTabEl.parents('.page')[0].f7Page; | |
7302 | if (tabParentPageData && options.route) { | |
7303 | tabParentPageData.route = options.route; | |
7304 | } | |
7305 | } | |
7306 | ||
7307 | // Tab Content Loaded | |
7308 | function onTabLoaded(contentEl) { | |
7309 | // Remove theme elements | |
7310 | router.removeThemeElements($newTabEl); | |
7311 | ||
7312 | var tabEventTarget = $newTabEl; | |
7313 | if (typeof contentEl !== 'string') { tabEventTarget = $(contentEl); } | |
7314 | ||
7315 | tabEventTarget.trigger('tab:init tab:mounted', tabRoute); | |
7316 | router.emit('tabInit tabMounted', $newTabEl[0], tabRoute); | |
7317 | ||
7318 | if ($oldTabEl && $oldTabEl.length) { | |
7319 | if (animated) { | |
7320 | onTabsChanged(function () { | |
7321 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
7322 | if (router.params.unloadTabContent) { | |
7323 | router.tabRemove($oldTabEl, $newTabEl, tabRoute); | |
7324 | } | |
7325 | }); | |
7326 | } else { | |
7327 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
7328 | if (router.params.unloadTabContent) { | |
7329 | router.tabRemove($oldTabEl, $newTabEl, tabRoute); | |
7330 | } | |
7331 | } | |
7332 | } | |
7333 | } | |
7334 | ||
7335 | if ($newTabEl[0].f7RouterTabLoaded) { | |
7336 | if (!$oldTabEl || !$oldTabEl.length) { return router; } | |
7337 | if (animated) { | |
7338 | onTabsChanged(function () { | |
7339 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
7340 | }); | |
7341 | } else { | |
7342 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
7343 | } | |
7344 | return router; | |
7345 | } | |
7346 | ||
7347 | // Load Tab Content | |
7348 | function loadTab(loadTabParams, loadTabOptions) { | |
7349 | // Load Tab Props | |
7350 | var url = loadTabParams.url; | |
7351 | var content = loadTabParams.content; | |
7352 | var el = loadTabParams.el; | |
7353 | var template = loadTabParams.template; | |
7354 | var templateUrl = loadTabParams.templateUrl; | |
7355 | var component = loadTabParams.component; | |
7356 | var componentUrl = loadTabParams.componentUrl; | |
7357 | // Component/Template Callbacks | |
7358 | function resolve(contentEl) { | |
7359 | router.allowPageChange = true; | |
7360 | if (!contentEl) { return; } | |
7361 | if (typeof contentEl === 'string') { | |
7362 | $newTabEl.html(contentEl); | |
7363 | } else { | |
7364 | $newTabEl.html(''); | |
7365 | if (contentEl.f7Component) { | |
7366 | contentEl.f7Component.$mount(function (componentEl) { | |
7367 | $newTabEl.append(componentEl); | |
7368 | }); | |
7369 | } else { | |
7370 | $newTabEl.append(contentEl); | |
7371 | } | |
7372 | } | |
7373 | $newTabEl[0].f7RouterTabLoaded = true; | |
7374 | onTabLoaded(contentEl); | |
7375 | } | |
7376 | function reject() { | |
7377 | router.allowPageChange = true; | |
7378 | return router; | |
7379 | } | |
7380 | ||
7381 | if (content) { | |
7382 | resolve(content); | |
7383 | } else if (template || templateUrl) { | |
7384 | try { | |
7385 | router.tabTemplateLoader(template, templateUrl, loadTabOptions, resolve, reject); | |
7386 | } catch (err) { | |
7387 | router.allowPageChange = true; | |
7388 | throw err; | |
7389 | } | |
7390 | } else if (el) { | |
7391 | resolve(el); | |
7392 | } else if (component || componentUrl) { | |
7393 | // Load from component (F7/Vue/React/...) | |
7394 | try { | |
7395 | router.tabComponentLoader($newTabEl[0], component, componentUrl, loadTabOptions, resolve, reject); | |
7396 | } catch (err) { | |
7397 | router.allowPageChange = true; | |
7398 | throw err; | |
7399 | } | |
7400 | } else if (url) { | |
7401 | // Load using XHR | |
7402 | if (router.xhr) { | |
7403 | router.xhr.abort(); | |
7404 | router.xhr = false; | |
7405 | } | |
7406 | router.xhrRequest(url, loadTabOptions) | |
7407 | .then(function (tabContent) { | |
7408 | resolve(tabContent); | |
7409 | }) | |
7410 | .catch(function () { | |
7411 | router.allowPageChange = true; | |
7412 | }); | |
7413 | } | |
7414 | } | |
7415 | ||
7416 | var hasContentLoadProp; | |
7417 | ('url content component el componentUrl template templateUrl').split(' ').forEach(function (tabLoadProp) { | |
7418 | var obj; | |
7419 | ||
7420 | if (tabRoute[tabLoadProp]) { | |
7421 | hasContentLoadProp = true; | |
7422 | loadTab(( obj = {}, obj[tabLoadProp] = tabRoute[tabLoadProp], obj ), options); | |
7423 | } | |
7424 | }); | |
7425 | ||
7426 | // Async | |
7427 | function asyncResolve(resolveParams, resolveOptions) { | |
7428 | loadTab(resolveParams, Utils.extend(options, resolveOptions)); | |
7429 | } | |
7430 | function asyncReject() { | |
7431 | router.allowPageChange = true; | |
7432 | } | |
7433 | if (tabRoute.async) { | |
7434 | tabRoute.async.call(router, currentRoute, previousRoute, asyncResolve, asyncReject); | |
7435 | } else if (!hasContentLoadProp) { | |
7436 | router.allowPageChange = true; | |
7437 | } | |
7438 | ||
7439 | return router; | |
7440 | } | |
7441 | function tabRemove($oldTabEl, $newTabEl, tabRoute) { | |
7442 | var router = this; | |
7443 | ||
7444 | var hasTabComponentChild; | |
7445 | if ($oldTabEl[0]) { | |
7446 | $oldTabEl[0].f7RouterTabLoaded = false; | |
7447 | delete $oldTabEl[0].f7RouterTabLoaded; | |
7448 | } | |
7449 | $oldTabEl.children().each(function (index, tabChild) { | |
7450 | if (tabChild.f7Component) { | |
7451 | hasTabComponentChild = true; | |
7452 | $(tabChild).trigger('tab:beforeremove', tabRoute); | |
7453 | tabChild.f7Component.$destroy(); | |
7454 | } | |
7455 | }); | |
7456 | if (!hasTabComponentChild) { | |
7457 | $oldTabEl.trigger('tab:beforeremove', tabRoute); | |
7458 | } | |
7459 | router.emit('tabBeforeRemove', $oldTabEl[0], $newTabEl[0], tabRoute); | |
7460 | router.removeTabContent($oldTabEl[0], tabRoute); | |
7461 | } | |
7462 | ||
7463 | function modalLoad(modalType, route, loadOptions) { | |
7464 | if ( loadOptions === void 0 ) loadOptions = {}; | |
7465 | ||
7466 | var router = this; | |
7467 | var app = router.app; | |
7468 | var isPanel = modalType === 'panel'; | |
7469 | var modalOrPanel = isPanel ? 'panel' : 'modal'; | |
7470 | ||
7471 | var options = Utils.extend({ | |
7472 | animate: router.params.animate, | |
7473 | pushState: true, | |
7474 | history: true, | |
7475 | on: {}, | |
7476 | }, loadOptions); | |
7477 | ||
7478 | var modalParams = Utils.extend({}, route.route[modalType]); | |
7479 | var modalRoute = route.route; | |
7480 | ||
7481 | function onModalLoaded() { | |
7482 | // Create Modal | |
7483 | var modal = app[modalType].create(modalParams); | |
7484 | modalRoute.modalInstance = modal; | |
7485 | ||
7486 | var hasEl = modal.el; | |
7487 | ||
7488 | function closeOnSwipeBack() { | |
7489 | modal.close(); | |
7490 | } | |
7491 | modal.on((modalOrPanel + "Open"), function () { | |
7492 | if (!hasEl) { | |
7493 | // Remove theme elements | |
7494 | router.removeThemeElements(modal.el); | |
7495 | ||
7496 | // Emit events | |
7497 | modal.$el.trigger(((modalType.toLowerCase()) + ":init " + (modalType.toLowerCase()) + ":mounted"), route, modal); | |
7498 | router.emit(((!isPanel ? 'modalInit' : '') + " " + modalType + "Init " + modalType + "Mounted"), modal.el, route, modal); | |
7499 | } | |
7500 | router.once('swipeBackMove', closeOnSwipeBack); | |
7501 | }); | |
7502 | modal.on((modalOrPanel + "Close"), function () { | |
7503 | router.off('swipeBackMove', closeOnSwipeBack); | |
7504 | if (!modal.closeByRouter) { | |
7505 | router.back(); | |
7506 | } | |
7507 | }); | |
7508 | ||
7509 | modal.on((modalOrPanel + "Closed"), function () { | |
7510 | modal.$el.trigger(((modalType.toLowerCase()) + ":beforeremove"), route, modal); | |
7511 | modal.emit(("" + (!isPanel ? 'modalBeforeRemove ' : '') + modalType + "BeforeRemove"), modal.el, route, modal); | |
7512 | var modalComponent = modal.el.f7Component; | |
7513 | if (modalComponent) { | |
7514 | modalComponent.$destroy(); | |
7515 | } | |
7516 | Utils.nextTick(function () { | |
7517 | if (modalComponent || modalParams.component) { | |
7518 | router.removeModal(modal.el); | |
7519 | } | |
7520 | modal.destroy(); | |
7521 | delete modal.route; | |
7522 | delete modalRoute.modalInstance; | |
7523 | }); | |
7524 | }); | |
7525 | ||
7526 | if (options.route) { | |
7527 | // Update Browser History | |
7528 | if (router.params.pushState && options.pushState) { | |
7529 | History.push( | |
7530 | router.view.id, | |
7531 | { | |
7532 | url: options.route.url, | |
7533 | modal: modalType, | |
7534 | }, | |
7535 | (router.params.pushStateRoot || '') + router.params.pushStateSeparator + options.route.url | |
7536 | ); | |
7537 | } | |
7538 | ||
7539 | // Set Route | |
7540 | if (options.route !== router.currentRoute) { | |
7541 | modal.route = Utils.extend(options.route, { modal: modal }); | |
7542 | router.currentRoute = modal.route; | |
7543 | } | |
7544 | ||
7545 | // Update Router History | |
7546 | if (options.history) { | |
7547 | router.history.push(options.route.url); | |
7548 | router.saveHistory(); | |
7549 | } | |
7550 | } | |
7551 | ||
7552 | if (hasEl) { | |
7553 | // Remove theme elements | |
7554 | router.removeThemeElements(modal.el); | |
7555 | ||
7556 | // Emit events | |
7557 | modal.$el.trigger(((modalType.toLowerCase()) + ":init " + (modalType.toLowerCase()) + ":mounted"), route, modal); | |
7558 | router.emit((modalOrPanel + "Init " + modalType + "Init " + modalType + "Mounted"), modal.el, route, modal); | |
7559 | } | |
7560 | ||
7561 | // Open | |
7562 | modal.open(); | |
7563 | } | |
7564 | ||
7565 | // Load Modal Content | |
7566 | function loadModal(loadModalParams, loadModalOptions) { | |
7567 | // Load Modal Props | |
7568 | var url = loadModalParams.url; | |
7569 | var content = loadModalParams.content; | |
7570 | var template = loadModalParams.template; | |
7571 | var templateUrl = loadModalParams.templateUrl; | |
7572 | var component = loadModalParams.component; | |
7573 | var componentUrl = loadModalParams.componentUrl; | |
7574 | ||
7575 | // Component/Template Callbacks | |
7576 | function resolve(contentEl) { | |
7577 | if (contentEl) { | |
7578 | if (typeof contentEl === 'string') { | |
7579 | modalParams.content = contentEl; | |
7580 | } else if (contentEl.f7Component) { | |
7581 | contentEl.f7Component.$mount(function (componentEl) { | |
7582 | modalParams.el = componentEl; | |
7583 | app.root.append(componentEl); | |
7584 | }); | |
7585 | } else { | |
7586 | modalParams.el = contentEl; | |
7587 | } | |
7588 | onModalLoaded(); | |
7589 | } | |
7590 | } | |
7591 | function reject() { | |
7592 | router.allowPageChange = true; | |
7593 | return router; | |
7594 | } | |
7595 | ||
7596 | if (content) { | |
7597 | resolve(content); | |
7598 | } else if (template || templateUrl) { | |
7599 | try { | |
7600 | router.modalTemplateLoader(template, templateUrl, loadModalOptions, resolve, reject); | |
7601 | } catch (err) { | |
7602 | router.allowPageChange = true; | |
7603 | throw err; | |
7604 | } | |
7605 | } else if (component || componentUrl) { | |
7606 | // Load from component (F7/Vue/React/...) | |
7607 | try { | |
7608 | router.modalComponentLoader(app.root[0], component, componentUrl, loadModalOptions, resolve, reject); | |
7609 | } catch (err) { | |
7610 | router.allowPageChange = true; | |
7611 | throw err; | |
7612 | } | |
7613 | } else if (url) { | |
7614 | // Load using XHR | |
7615 | if (router.xhr) { | |
7616 | router.xhr.abort(); | |
7617 | router.xhr = false; | |
7618 | } | |
7619 | router.xhrRequest(url, loadModalOptions) | |
7620 | .then(function (modalContent) { | |
7621 | modalParams.content = modalContent; | |
7622 | onModalLoaded(); | |
7623 | }) | |
7624 | .catch(function () { | |
7625 | router.allowPageChange = true; | |
7626 | }); | |
7627 | } else { | |
7628 | onModalLoaded(); | |
7629 | } | |
7630 | } | |
7631 | ||
7632 | var foundLoadProp; | |
7633 | ('url content component el componentUrl template templateUrl').split(' ').forEach(function (modalLoadProp) { | |
7634 | var obj; | |
7635 | ||
7636 | if (modalParams[modalLoadProp] && !foundLoadProp) { | |
7637 | foundLoadProp = true; | |
7638 | loadModal(( obj = {}, obj[modalLoadProp] = modalParams[modalLoadProp], obj ), options); | |
7639 | } | |
7640 | }); | |
7641 | if (!foundLoadProp && modalType === 'actions') { | |
7642 | onModalLoaded(); | |
7643 | } | |
7644 | ||
7645 | // Async | |
7646 | function asyncResolve(resolveParams, resolveOptions) { | |
7647 | loadModal(resolveParams, Utils.extend(options, resolveOptions)); | |
7648 | } | |
7649 | function asyncReject() { | |
7650 | router.allowPageChange = true; | |
7651 | } | |
7652 | if (modalParams.async) { | |
7653 | modalParams.async.call(router, options.route, router.currentRoute, asyncResolve, asyncReject); | |
7654 | } | |
7655 | return router; | |
7656 | } | |
7657 | function modalRemove(modal) { | |
7658 | Utils.extend(modal, { closeByRouter: true }); | |
7659 | modal.close(); | |
7660 | } | |
7661 | ||
7662 | function backward(el, backwardOptions) { | |
7663 | var router = this; | |
7664 | var $el = $(el); | |
7665 | var app = router.app; | |
7666 | var view = router.view; | |
7667 | ||
7668 | var options = Utils.extend({ | |
7669 | animate: router.params.animate, | |
7670 | pushState: true, | |
5d51ea26 | 7671 | replaceState: false, |
5309fbda DC |
7672 | }, backwardOptions); |
7673 | ||
7674 | var masterDetailEnabled = router.params.masterDetailBreakpoint > 0; | |
7675 | var isMaster = masterDetailEnabled && options.route && options.route.route && options.route.route.master === true; | |
7676 | var masterPageEl; | |
7677 | ||
7678 | var dynamicNavbar = router.dynamicNavbar; | |
7679 | var separateNavbar = router.separateNavbar; | |
7680 | ||
7681 | var $newPage = $el; | |
7682 | var $oldPage = router.$el.children('.page-current'); | |
7683 | var currentIsMaster = masterDetailEnabled && $oldPage.hasClass('page-master'); | |
7684 | ||
7685 | if ($newPage.length) { | |
7686 | // Remove theme elements | |
7687 | router.removeThemeElements($newPage); | |
7688 | } | |
7689 | ||
7690 | var $navbarEl; | |
7691 | var $newNavbarInner; | |
7692 | var $oldNavbarInner; | |
7693 | ||
7694 | if (dynamicNavbar) { | |
7695 | $newNavbarInner = $newPage.children('.navbar').children('.navbar-inner'); | |
7696 | if (separateNavbar) { | |
7697 | $navbarEl = router.$navbarEl; | |
7698 | if ($newNavbarInner.length > 0) { | |
7699 | $newPage.children('.navbar').remove(); | |
7700 | } | |
7701 | if ($newNavbarInner.length === 0 && $newPage[0] && $newPage[0].f7Page) { | |
7702 | // Try from pageData | |
7703 | $newNavbarInner = $newPage[0].f7Page.$navbarEl; | |
7704 | } | |
7705 | $oldNavbarInner = $navbarEl.find('.navbar-current'); | |
7706 | } else { | |
7707 | $oldNavbarInner = $oldPage.children('.navbar').children('.navbar-inner'); | |
7708 | } | |
7709 | } | |
7710 | ||
7711 | router.allowPageChange = false; | |
7712 | if ($newPage.length === 0 || $oldPage.length === 0) { | |
7713 | router.allowPageChange = true; | |
7714 | return router; | |
7715 | } | |
7716 | ||
7717 | // Remove theme elements | |
7718 | router.removeThemeElements($newPage); | |
7719 | ||
7720 | // Save Keep Alive Cache | |
7721 | if (options.route && options.route.route && options.route.route.keepAlive && !options.route.route.keepAliveData) { | |
7722 | options.route.route.keepAliveData = { | |
7723 | pageEl: $el[0], | |
7724 | }; | |
7725 | } | |
7726 | ||
7727 | // Pages In View | |
7728 | var isDetail; | |
7729 | if (masterDetailEnabled) { | |
7730 | var $pagesInView = router.$el | |
7731 | .children('.page:not(.stacked)') | |
7732 | .filter(function (index, pageInView) { return pageInView !== $newPage[0]; }); | |
7733 | ||
7734 | // Find Detail' master page | |
7735 | for (var i = 0; i < $pagesInView.length; i += 1) { | |
7736 | if (!masterPageEl | |
7737 | && $pagesInView[i].classList.contains('page-master') | |
7738 | ) { | |
7739 | masterPageEl = $pagesInView[i]; | |
7740 | continue; // eslint-disable-line | |
7741 | } | |
7742 | } | |
7743 | ||
7744 | isDetail = !isMaster | |
7745 | && masterPageEl | |
7746 | && (router.history.indexOf(options.route.url) > router.history.indexOf(masterPageEl.f7Page.route.url)); | |
5d51ea26 DC |
7747 | |
7748 | if (!isDetail && !isMaster && masterPageEl && masterPageEl.f7Page && options.route.route.masterRoute) { | |
7749 | isDetail = options.route.route.masterRoute.path === masterPageEl.f7Page.route.route.path; | |
7750 | } | |
5309fbda DC |
7751 | } |
7752 | ||
7753 | ||
7754 | // New Page | |
7755 | $newPage | |
7756 | .addClass(("page-previous" + (isMaster ? ' page-master' : '') + (isDetail ? ' page-master-detail' : ''))) | |
7757 | .removeClass('stacked') | |
7758 | .removeAttr('aria-hidden') | |
7759 | .trigger('page:unstack') | |
7760 | .trigger('page:position', { position: 'previous' }); | |
5d51ea26 DC |
7761 | router.emit('pageUnstack', $newPage[0]); |
7762 | router.emit('pagePosition', $newPage[0], 'previous'); | |
5309fbda DC |
7763 | if (isMaster || isDetail) { |
7764 | $newPage.trigger('page:role', { role: isMaster ? 'master' : 'detail' }); | |
7765 | } | |
7766 | ||
7767 | if (dynamicNavbar && $newNavbarInner.length > 0) { | |
7768 | $newNavbarInner | |
7769 | .addClass(("navbar-previous" + (isMaster ? ' navbar-master' : '') + (isDetail ? ' navbar-master-detail' : ''))) | |
7770 | .removeClass('stacked') | |
7771 | .removeAttr('aria-hidden'); | |
7772 | } | |
7773 | ||
7774 | // Remove previous page in case of "forced" | |
7775 | var backIndex; | |
7776 | if (options.force) { | |
7777 | if ($oldPage.prev('.page-previous:not(.stacked)').length > 0 || $oldPage.prev('.page-previous').length === 0) { | |
7778 | if (router.history.indexOf(options.route.url) >= 0) { | |
7779 | backIndex = router.history.length - router.history.indexOf(options.route.url) - 1; | |
7780 | router.history = router.history.slice(0, router.history.indexOf(options.route.url) + 2); | |
7781 | view.history = router.history; | |
7782 | } else if (router.history[[router.history.length - 2]]) { | |
7783 | router.history[router.history.length - 2] = options.route.url; | |
7784 | } else { | |
7785 | router.history.unshift(router.url); | |
7786 | } | |
7787 | ||
7788 | if (backIndex && router.params.stackPages) { | |
7789 | $oldPage.prevAll('.page-previous').each(function (index, pageToRemove) { | |
7790 | var $pageToRemove = $(pageToRemove); | |
7791 | var $navbarToRemove; | |
7792 | if (separateNavbar) { | |
7793 | // $navbarToRemove = $oldNavbarInner.prevAll('.navbar-previous').eq(index); | |
7794 | $navbarToRemove = $(app.navbar.getElByPage($pageToRemove)); | |
7795 | } | |
7796 | if ($pageToRemove[0] !== $newPage[0] && $pageToRemove.index() > $newPage.index()) { | |
7797 | if (router.initialPages.indexOf($pageToRemove[0]) >= 0) { | |
7798 | $pageToRemove.addClass('stacked'); | |
7799 | $pageToRemove.trigger('page:stack'); | |
5d51ea26 | 7800 | router.emit('pageStack', $pageToRemove[0]); |
5309fbda DC |
7801 | if (separateNavbar) { |
7802 | $navbarToRemove.addClass('stacked'); | |
7803 | } | |
7804 | } else { | |
7805 | router.pageCallback('beforeRemove', $pageToRemove, $navbarToRemove, 'previous', undefined, options); | |
7806 | router.removePage($pageToRemove); | |
7807 | if (separateNavbar && $navbarToRemove.length > 0) { | |
7808 | router.removeNavbar($navbarToRemove); | |
7809 | } | |
7810 | } | |
7811 | } | |
7812 | }); | |
7813 | } else { | |
7814 | var $pageToRemove = $oldPage.prev('.page-previous:not(.stacked)'); | |
7815 | var $navbarToRemove; | |
7816 | if (separateNavbar) { | |
7817 | // $navbarToRemove = $oldNavbarInner.prev('.navbar-inner:not(.stacked)'); | |
7818 | $navbarToRemove = $(app.navbar.getElByPage($pageToRemove)); | |
7819 | } | |
7820 | if (router.params.stackPages && router.initialPages.indexOf($pageToRemove[0]) >= 0) { | |
7821 | $pageToRemove.addClass('stacked'); | |
7822 | $pageToRemove.trigger('page:stack'); | |
5d51ea26 | 7823 | router.emit('pageStack', $pageToRemove[0]); |
5309fbda DC |
7824 | $navbarToRemove.addClass('stacked'); |
7825 | } else if ($pageToRemove.length > 0) { | |
7826 | router.pageCallback('beforeRemove', $pageToRemove, $navbarToRemove, 'previous', undefined, options); | |
7827 | router.removePage($pageToRemove); | |
7828 | if (separateNavbar && $navbarToRemove.length) { | |
7829 | router.removeNavbar($navbarToRemove); | |
7830 | } | |
7831 | } | |
7832 | } | |
7833 | } | |
7834 | } | |
7835 | ||
7836 | // Insert new page | |
7837 | var newPageInDom = $newPage.parents(doc).length > 0; | |
7838 | var f7Component = $newPage[0].f7Component; | |
7839 | ||
7840 | function insertPage() { | |
7841 | if ($newPage.next($oldPage).length === 0) { | |
7842 | if (!newPageInDom && f7Component) { | |
7843 | f7Component.$mount(function (componentEl) { | |
7844 | $(componentEl).insertBefore($oldPage); | |
7845 | }); | |
7846 | } else { | |
7847 | $newPage.insertBefore($oldPage); | |
7848 | } | |
7849 | } | |
7850 | if (separateNavbar && $newNavbarInner.length) { | |
7851 | if ($newNavbarInner.children('.title-large').length) { | |
7852 | $newNavbarInner.addClass('navbar-inner-large'); | |
7853 | } | |
7854 | $newNavbarInner.insertBefore($oldNavbarInner); | |
7855 | if ($oldNavbarInner.length > 0) { | |
7856 | $newNavbarInner.insertBefore($oldNavbarInner); | |
7857 | } else { | |
7858 | if (!router.$navbarEl.parents(doc).length) { | |
7859 | router.$el.prepend(router.$navbarEl); | |
7860 | } | |
7861 | $navbarEl.append($newNavbarInner); | |
7862 | } | |
7863 | } | |
7864 | if (!newPageInDom) { | |
7865 | router.pageCallback('mounted', $newPage, $newNavbarInner, 'previous', 'current', options, $oldPage); | |
7866 | } else if (options.route && options.route.route && options.route.route.keepAlive && !$newPage[0].f7PageMounted) { | |
7867 | $newPage[0].f7PageMounted = true; | |
7868 | router.pageCallback('mounted', $newPage, $newNavbarInner, 'previous', 'current', options, $oldPage); | |
7869 | } | |
7870 | } | |
7871 | ||
7872 | if (options.preload) { | |
7873 | // Insert Page | |
7874 | insertPage(); | |
7875 | // Tab route | |
7876 | if (options.route.route.tab) { | |
7877 | router.tabLoad(options.route.route.tab, Utils.extend({}, options, { | |
7878 | history: false, | |
7879 | pushState: false, | |
7880 | preload: true, | |
7881 | })); | |
7882 | } | |
7883 | if (isMaster) { | |
7884 | $newPage | |
7885 | .removeClass('page-master-stacked') | |
7886 | .trigger('page:masterunstack'); | |
5d51ea26 | 7887 | router.emit('pageMasterUnstack', $newPage[0]); |
5309fbda DC |
7888 | if (separateNavbar) { |
7889 | $(app.navbar.getElByPage($newPage)).removeClass('navbar-master-stacked'); | |
7890 | } | |
7891 | } | |
7892 | // Page init and before init events | |
7893 | router.pageCallback('init', $newPage, $newNavbarInner, 'previous', 'current', options, $oldPage); | |
7894 | var $previousPages = $newPage.prevAll('.page-previous:not(.stacked):not(.page-master)'); | |
7895 | if ($previousPages.length > 0) { | |
7896 | $previousPages.each(function (index, pageToRemove) { | |
7897 | var $pageToRemove = $(pageToRemove); | |
7898 | var $navbarToRemove; | |
7899 | if (separateNavbar) { | |
7900 | // $navbarToRemove = $newNavbarInner.prevAll('.navbar-previous:not(.stacked)').eq(index); | |
7901 | $navbarToRemove = $(app.navbar.getElByPage($pageToRemove)); | |
7902 | } | |
7903 | if (router.params.stackPages && router.initialPages.indexOf(pageToRemove) >= 0) { | |
7904 | $pageToRemove.addClass('stacked'); | |
7905 | $pageToRemove.trigger('page:stack'); | |
5d51ea26 | 7906 | router.emit('pageStack', $pageToRemove[0]); |
5309fbda DC |
7907 | if (separateNavbar) { |
7908 | $navbarToRemove.addClass('stacked'); | |
7909 | } | |
7910 | } else { | |
7911 | router.pageCallback('beforeRemove', $pageToRemove, $navbarToRemove, 'previous', undefined); | |
7912 | router.removePage($pageToRemove); | |
7913 | if (separateNavbar && $navbarToRemove.length) { | |
7914 | router.removeNavbar($navbarToRemove); | |
7915 | } | |
7916 | } | |
7917 | }); | |
7918 | } | |
7919 | router.allowPageChange = true; | |
7920 | return router; | |
7921 | } | |
7922 | ||
7923 | // History State | |
7924 | if (!(Device.ie || Device.edge || (Device.firefox && !Device.ios))) { | |
7925 | if (router.params.pushState && options.pushState) { | |
5d51ea26 DC |
7926 | if (options.replaceState) { |
7927 | var pushStateRoot = router.params.pushStateRoot || ''; | |
7928 | History.replace( | |
7929 | view.id, | |
7930 | { | |
7931 | url: options.route.url, | |
7932 | }, | |
7933 | pushStateRoot + router.params.pushStateSeparator + options.route.url | |
7934 | ); | |
7935 | } else if (backIndex) { | |
7936 | History.go(-backIndex); | |
7937 | } else { | |
7938 | History.back(); | |
7939 | } | |
5309fbda DC |
7940 | } |
7941 | } | |
7942 | ||
7943 | // Update History | |
5d51ea26 DC |
7944 | if (options.replaceState) { |
7945 | router.history[router.history.length - 1] = options.route.url; | |
7946 | } else { | |
7947 | if (router.history.length === 1) { | |
7948 | router.history.unshift(router.url); | |
7949 | } | |
7950 | router.history.pop(); | |
5309fbda | 7951 | } |
5309fbda DC |
7952 | router.saveHistory(); |
7953 | ||
7954 | // Current Page & Navbar | |
7955 | router.currentPageEl = $newPage[0]; | |
7956 | if (dynamicNavbar && $newNavbarInner.length) { | |
7957 | router.currentNavbarEl = $newNavbarInner[0]; | |
7958 | } else { | |
7959 | delete router.currentNavbarEl; | |
7960 | } | |
7961 | ||
7962 | // Current Route | |
7963 | router.currentRoute = options.route; | |
7964 | ||
7965 | // History State | |
7966 | if (Device.ie || Device.edge || (Device.firefox && !Device.ios)) { | |
7967 | if (router.params.pushState && options.pushState) { | |
5d51ea26 DC |
7968 | if (options.replaceState) { |
7969 | var pushStateRoot$1 = router.params.pushStateRoot || ''; | |
7970 | History.replace( | |
7971 | view.id, | |
7972 | { | |
7973 | url: options.route.url, | |
7974 | }, | |
7975 | pushStateRoot$1 + router.params.pushStateSeparator + options.route.url | |
7976 | ); | |
7977 | } else if (backIndex) { | |
7978 | History.go(-backIndex); | |
7979 | } else { | |
7980 | History.back(); | |
7981 | } | |
5309fbda DC |
7982 | } |
7983 | } | |
7984 | ||
7985 | // Insert Page | |
7986 | insertPage(); | |
7987 | ||
7988 | // Load Tab | |
7989 | if (options.route.route.tab) { | |
7990 | router.tabLoad(options.route.route.tab, Utils.extend({}, options, { | |
7991 | history: false, | |
7992 | pushState: false, | |
7993 | })); | |
7994 | } | |
7995 | ||
7996 | // Page init and before init events | |
7997 | router.pageCallback('init', $newPage, $newNavbarInner, 'previous', 'current', options, $oldPage); | |
7998 | ||
7999 | // Before animation callback | |
5309fbda | 8000 | router.pageCallback('beforeOut', $oldPage, $oldNavbarInner, 'current', 'next', options); |
5d51ea26 | 8001 | router.pageCallback('beforeIn', $newPage, $newNavbarInner, 'previous', 'current', options); |
5309fbda DC |
8002 | |
8003 | // Animation | |
8004 | function afterAnimation() { | |
8005 | // Set classes | |
8006 | var pageClasses = 'page-previous page-current page-next'; | |
8007 | var navbarClasses = 'navbar-previous navbar-current navbar-next'; | |
8008 | $newPage.removeClass(pageClasses).addClass('page-current').removeAttr('aria-hidden').trigger('page:position', { position: 'current' }); | |
5d51ea26 | 8009 | router.emit('pagePosition', $newPage[0], 'current'); |
5309fbda | 8010 | $oldPage.removeClass(pageClasses).addClass('page-next').attr('aria-hidden', 'true').trigger('page:position', { position: 'next' }); |
5d51ea26 | 8011 | router.emit('pagePosition', $oldPage[0], 'next'); |
5309fbda DC |
8012 | if (dynamicNavbar) { |
8013 | $newNavbarInner.removeClass(navbarClasses).addClass('navbar-current').removeAttr('aria-hidden'); | |
8014 | $oldNavbarInner.removeClass(navbarClasses).addClass('navbar-next').attr('aria-hidden', 'true'); | |
8015 | } | |
8016 | ||
8017 | // After animation event | |
5309fbda | 8018 | router.pageCallback('afterOut', $oldPage, $oldNavbarInner, 'current', 'next', options); |
5d51ea26 | 8019 | router.pageCallback('afterIn', $newPage, $newNavbarInner, 'previous', 'current', options); |
5309fbda DC |
8020 | |
8021 | // Remove Old Page | |
8022 | if (router.params.stackPages && router.initialPages.indexOf($oldPage[0]) >= 0) { | |
8023 | $oldPage.addClass('stacked'); | |
8024 | $oldPage.trigger('page:stack'); | |
5d51ea26 | 8025 | router.emit('pageStack', $oldPage[0]); |
5309fbda DC |
8026 | if (separateNavbar) { |
8027 | $oldNavbarInner.addClass('stacked'); | |
8028 | } | |
8029 | } else { | |
8030 | router.pageCallback('beforeRemove', $oldPage, $oldNavbarInner, 'next', undefined, options); | |
8031 | router.removePage($oldPage); | |
8032 | if (separateNavbar && $oldNavbarInner.length) { | |
8033 | router.removeNavbar($oldNavbarInner); | |
8034 | } | |
8035 | } | |
8036 | ||
8037 | router.allowPageChange = true; | |
8038 | router.emit('routeChanged', router.currentRoute, router.previousRoute, router); | |
8039 | ||
8040 | // Preload previous page | |
5d51ea26 | 8041 | var preloadPreviousPage = router.params.preloadPreviousPage || router.params[((app.theme) + "SwipeBack")]; |
5309fbda DC |
8042 | if (preloadPreviousPage && router.history[router.history.length - 2] && !isMaster) { |
8043 | router.back(router.history[router.history.length - 2], { preload: true }); | |
8044 | } | |
8045 | if (router.params.pushState) { | |
8046 | History.clearRouterQueue(); | |
8047 | } | |
8048 | } | |
8049 | ||
8050 | function setPositionClasses() { | |
8051 | var pageClasses = 'page-previous page-current page-next'; | |
8052 | var navbarClasses = 'navbar-previous navbar-current navbar-next'; | |
8053 | $oldPage.removeClass(pageClasses).addClass('page-current').trigger('page:position', { position: 'current' }); | |
5d51ea26 | 8054 | router.emit('pagePosition', $oldPage[0], 'current'); |
5309fbda | 8055 | $newPage.removeClass(pageClasses).addClass('page-previous').removeAttr('aria-hidden').trigger('page:position', { position: 'previous' }); |
5d51ea26 | 8056 | router.emit('pagePosition', $newPage[0], 'previous'); |
5309fbda DC |
8057 | if (dynamicNavbar) { |
8058 | $oldNavbarInner.removeClass(navbarClasses).addClass('navbar-current'); | |
8059 | $newNavbarInner.removeClass(navbarClasses).addClass('navbar-previous').removeAttr('aria-hidden'); | |
8060 | } | |
8061 | } | |
8062 | ||
8063 | if (options.animate && !(currentIsMaster && app.width >= router.params.masterDetailBreakpoint)) { | |
8064 | setPositionClasses(); | |
8065 | router.animate($oldPage, $newPage, $oldNavbarInner, $newNavbarInner, 'backward', function () { | |
8066 | afterAnimation(); | |
8067 | }); | |
8068 | } else { | |
8069 | afterAnimation(); | |
8070 | } | |
8071 | ||
8072 | return router; | |
8073 | } | |
8074 | function loadBack(backParams, backOptions, ignorePageChange) { | |
8075 | var router = this; | |
8076 | ||
8077 | if (!router.allowPageChange && !ignorePageChange) { return router; } | |
8078 | var params = backParams; | |
8079 | var options = backOptions; | |
8080 | var url = params.url; | |
8081 | var content = params.content; | |
8082 | var el = params.el; | |
8083 | var pageName = params.pageName; | |
8084 | var template = params.template; | |
8085 | var templateUrl = params.templateUrl; | |
8086 | var component = params.component; | |
8087 | var componentUrl = params.componentUrl; | |
8088 | ||
8089 | if ( | |
8090 | options.route.url | |
8091 | && router.url === options.route.url | |
8092 | && !(options.reloadCurrent || options.reloadPrevious) | |
8093 | && !router.params.allowDuplicateUrls | |
8094 | ) { | |
8095 | return false; | |
8096 | } | |
8097 | ||
8098 | if (!options.route && url) { | |
8099 | options.route = router.parseRouteUrl(url); | |
8100 | } | |
8101 | ||
8102 | // Component Callbacks | |
8103 | function resolve(pageEl, newOptions) { | |
8104 | return router.backward(pageEl, Utils.extend(options, newOptions)); | |
8105 | } | |
8106 | function reject() { | |
8107 | router.allowPageChange = true; | |
8108 | return router; | |
8109 | } | |
8110 | ||
8111 | if (url || templateUrl || componentUrl) { | |
8112 | router.allowPageChange = false; | |
8113 | } | |
8114 | ||
8115 | // Proceed | |
8116 | if (content) { | |
8117 | router.backward(router.getPageEl(content), options); | |
8118 | } else if (template || templateUrl) { | |
8119 | // Parse template and send page element | |
8120 | try { | |
8121 | router.pageTemplateLoader(template, templateUrl, options, resolve, reject); | |
8122 | } catch (err) { | |
8123 | router.allowPageChange = true; | |
8124 | throw err; | |
8125 | } | |
8126 | } else if (el) { | |
8127 | // Load page from specified HTMLElement or by page name in pages container | |
8128 | router.backward(router.getPageEl(el), options); | |
8129 | } else if (pageName) { | |
8130 | // Load page by page name in pages container | |
8131 | router.backward(router.$el.children((".page[data-name=\"" + pageName + "\"]")).eq(0), options); | |
8132 | } else if (component || componentUrl) { | |
8133 | // Load from component (F7/Vue/React/...) | |
8134 | try { | |
8135 | router.pageComponentLoader(router.el, component, componentUrl, options, resolve, reject); | |
8136 | } catch (err) { | |
8137 | router.allowPageChange = true; | |
8138 | throw err; | |
8139 | } | |
8140 | } else if (url) { | |
8141 | // Load using XHR | |
8142 | if (router.xhr) { | |
8143 | router.xhr.abort(); | |
8144 | router.xhr = false; | |
8145 | } | |
8146 | router.xhrRequest(url, options) | |
8147 | .then(function (pageContent) { | |
8148 | router.backward(router.getPageEl(pageContent), options); | |
8149 | }) | |
8150 | .catch(function () { | |
8151 | router.allowPageChange = true; | |
8152 | }); | |
8153 | } | |
8154 | return router; | |
8155 | } | |
8156 | function back() { | |
8157 | var args = [], len = arguments.length; | |
8158 | while ( len-- ) args[ len ] = arguments[ len ]; | |
8159 | ||
8160 | var router = this; | |
8161 | if (router.swipeBackActive) { return router; } | |
8162 | var navigateUrl; | |
8163 | var navigateOptions; | |
8164 | var route; | |
8165 | if (typeof args[0] === 'object') { | |
8166 | navigateOptions = args[0] || {}; | |
8167 | } else { | |
8168 | navigateUrl = args[0]; | |
8169 | navigateOptions = args[1] || {}; | |
8170 | } | |
8171 | ||
8172 | var name = navigateOptions.name; | |
8173 | var params = navigateOptions.params; | |
8174 | var query = navigateOptions.query; | |
8175 | if (name) { | |
8176 | // find route by name | |
8177 | route = router.findRouteByKey('name', name); | |
8178 | if (!route) { | |
8179 | throw new Error(("Framework7: route with name \"" + name + "\" not found")); | |
8180 | } | |
8181 | navigateUrl = router.constructRouteUrl(route, { params: params, query: query }); | |
8182 | if (navigateUrl) { | |
8183 | return router.back(navigateUrl, Utils.extend({}, navigateOptions, { | |
8184 | name: null, | |
8185 | params: null, | |
8186 | query: null, | |
8187 | })); | |
8188 | } | |
8189 | throw new Error(("Framework7: can't construct URL for route with name \"" + name + "\"")); | |
8190 | } | |
8191 | ||
8192 | var app = router.app; | |
8193 | appRouterCheck(router, 'back'); | |
8194 | ||
8195 | var currentRouteIsModal = router.currentRoute.modal; | |
8196 | var modalType; | |
8197 | if (!currentRouteIsModal) { | |
8198 | ('popup popover sheet loginScreen actions customModal panel').split(' ').forEach(function (modalLoadProp) { | |
8199 | if (router.currentRoute.route[modalLoadProp]) { | |
8200 | currentRouteIsModal = true; | |
8201 | modalType = modalLoadProp; | |
8202 | } | |
8203 | }); | |
8204 | } | |
8205 | if (currentRouteIsModal) { | |
8206 | var modalToClose = router.currentRoute.modal | |
8207 | || router.currentRoute.route.modalInstance | |
8208 | || app[modalType].get(); | |
8209 | var previousUrl = router.history[router.history.length - 2]; | |
8210 | var previousRoute; | |
8211 | // check if previous route is modal too | |
8212 | if (modalToClose && modalToClose.$el) { | |
8213 | var prevOpenedModals = modalToClose.$el.prevAll('.modal-in'); | |
8214 | if (prevOpenedModals.length && prevOpenedModals[0].f7Modal) { | |
8215 | previousRoute = prevOpenedModals[0].f7Modal.route; | |
8216 | } | |
8217 | } | |
8218 | if (!previousRoute) { | |
8219 | previousRoute = router.findMatchingRoute(previousUrl); | |
8220 | } | |
8221 | ||
8222 | if (!previousRoute && previousUrl) { | |
8223 | previousRoute = { | |
8224 | url: previousUrl, | |
8225 | path: previousUrl.split('?')[0], | |
8226 | query: Utils.parseUrlQuery(previousUrl), | |
8227 | route: { | |
8228 | path: previousUrl.split('?')[0], | |
8229 | url: previousUrl, | |
8230 | }, | |
8231 | }; | |
8232 | } | |
8233 | if (!navigateUrl || navigateUrl.replace(/[# ]/g, '').trim().length === 0) { | |
8234 | if (!previousRoute || !modalToClose) { | |
8235 | return router; | |
8236 | } | |
8237 | } | |
8238 | var forceOtherUrl = navigateOptions.force && previousRoute && navigateUrl; | |
8239 | if (previousRoute && modalToClose) { | |
8240 | if (router.params.pushState && navigateOptions.pushState !== false) { | |
8241 | History.back(); | |
8242 | } | |
8243 | router.currentRoute = previousRoute; | |
8244 | router.history.pop(); | |
8245 | router.saveHistory(); | |
8246 | router.modalRemove(modalToClose); | |
8247 | if (forceOtherUrl) { | |
8248 | router.navigate(navigateUrl, { reloadCurrent: true }); | |
8249 | } | |
8250 | } else if (modalToClose) { | |
8251 | router.modalRemove(modalToClose); | |
8252 | if (navigateUrl) { | |
8253 | router.navigate(navigateUrl, { reloadCurrent: true }); | |
8254 | } | |
8255 | } | |
8256 | return router; | |
8257 | } | |
8258 | var $previousPage = router.$el.children('.page-current').prevAll('.page-previous:not(.page-master)').eq(0); | |
8259 | ||
8260 | var skipMaster; | |
8261 | if (router.params.masterDetailBreakpoint > 0) { | |
8262 | var $previousMaster = router.$el.children('.page-current').prevAll('.page-master').eq(0); | |
8263 | if ($previousMaster.length) { | |
8264 | var expectedPreviousPageUrl = router.history[router.history.length - 2]; | |
8265 | var expectedPreviousPageRoute = router.findMatchingRoute(expectedPreviousPageUrl); | |
8266 | if (expectedPreviousPageRoute && expectedPreviousPageRoute.route === $previousMaster[0].f7Page.route.route) { | |
8267 | $previousPage = $previousMaster; | |
8268 | if (!navigateOptions.preload) { | |
8269 | skipMaster = app.width >= router.params.masterDetailBreakpoint; | |
8270 | } | |
8271 | } | |
8272 | } | |
8273 | } | |
8274 | if (!navigateOptions.force && $previousPage.length && !skipMaster) { | |
8275 | if (router.params.pushState | |
8276 | && $previousPage[0].f7Page | |
8277 | && router.history[router.history.length - 2] !== $previousPage[0].f7Page.route.url | |
8278 | ) { | |
8279 | router.back( | |
8280 | router.history[router.history.length - 2], | |
8281 | Utils.extend(navigateOptions, { force: true }) | |
8282 | ); | |
8283 | return router; | |
8284 | } | |
8285 | var previousPageRoute = $previousPage[0].f7Page.route; | |
8286 | ||
8287 | processRouteQueue.call( | |
8288 | router, | |
8289 | previousPageRoute, | |
8290 | router.currentRoute, | |
8291 | function () { | |
8292 | router.loadBack({ el: $previousPage }, Utils.extend(navigateOptions, { | |
8293 | route: previousPageRoute, | |
8294 | })); | |
8295 | }, | |
8296 | function () {} | |
8297 | ); | |
8298 | ||
8299 | return router; | |
8300 | } | |
8301 | ||
8302 | // Navigate URL | |
8303 | if (navigateUrl === '#') { | |
8304 | navigateUrl = undefined; | |
8305 | } | |
8306 | if (navigateUrl && navigateUrl[0] !== '/' && navigateUrl.indexOf('#') !== 0) { | |
8307 | navigateUrl = ((router.path || '/') + navigateUrl).replace('//', '/'); | |
8308 | } | |
8309 | if (!navigateUrl && router.history.length > 1) { | |
8310 | navigateUrl = router.history[router.history.length - 2]; | |
8311 | } | |
8312 | if (skipMaster && !navigateOptions.force && router.history[router.history.length - 3]) { | |
8313 | return router.back(router.history[router.history.length - 3], Utils.extend({}, navigateOptions || {}, { | |
8314 | force: true, | |
8315 | animate: false, | |
8316 | })); | |
8317 | } | |
8318 | if (skipMaster && !navigateOptions.force) { | |
8319 | return router; | |
8320 | } | |
8321 | ||
8322 | // Find route to load | |
8323 | route = router.findMatchingRoute(navigateUrl); | |
8324 | if (!route) { | |
8325 | if (navigateUrl) { | |
8326 | route = { | |
8327 | url: navigateUrl, | |
8328 | path: navigateUrl.split('?')[0], | |
8329 | query: Utils.parseUrlQuery(navigateUrl), | |
8330 | route: { | |
8331 | path: navigateUrl.split('?')[0], | |
8332 | url: navigateUrl, | |
8333 | }, | |
8334 | }; | |
8335 | } | |
8336 | } | |
8337 | if (!route) { | |
8338 | return router; | |
8339 | } | |
8340 | ||
8341 | if (route.route.redirect) { | |
8342 | return redirect.call(router, 'back', route, navigateOptions); | |
8343 | } | |
8344 | ||
8345 | var options = {}; | |
8346 | if (route.route.options) { | |
8347 | Utils.extend(options, route.route.options, navigateOptions); | |
8348 | } else { | |
8349 | Utils.extend(options, navigateOptions); | |
8350 | } | |
8351 | options.route = route; | |
8352 | ||
8353 | if (options && options.context) { | |
8354 | route.context = options.context; | |
8355 | options.route.context = options.context; | |
8356 | } | |
8357 | ||
8358 | var backForceLoaded; | |
8359 | if (options.force && router.params.stackPages) { | |
8360 | router.$el.children('.page-previous.stacked').each(function (index, pageEl) { | |
8361 | if (pageEl.f7Page && pageEl.f7Page.route && pageEl.f7Page.route.url === route.url) { | |
8362 | backForceLoaded = true; | |
8363 | router.loadBack({ el: pageEl }, options); | |
8364 | } | |
8365 | }); | |
8366 | if (backForceLoaded) { | |
8367 | return router; | |
8368 | } | |
8369 | } | |
8370 | function resolve() { | |
8371 | var routerLoaded = false; | |
8372 | if (route.route.keepAlive && route.route.keepAliveData) { | |
8373 | router.loadBack({ el: route.route.keepAliveData.pageEl }, options); | |
8374 | routerLoaded = true; | |
8375 | } | |
8376 | ('url content component pageName el componentUrl template templateUrl').split(' ').forEach(function (pageLoadProp) { | |
8377 | var obj; | |
8378 | ||
8379 | if (route.route[pageLoadProp] && !routerLoaded) { | |
8380 | routerLoaded = true; | |
8381 | router.loadBack(( obj = {}, obj[pageLoadProp] = route.route[pageLoadProp], obj ), options); | |
8382 | } | |
8383 | }); | |
8384 | if (routerLoaded) { return; } | |
8385 | // Async | |
8386 | function asyncResolve(resolveParams, resolveOptions) { | |
8387 | router.allowPageChange = false; | |
8388 | if (resolveOptions && resolveOptions.context) { | |
8389 | if (!route.context) { route.context = resolveOptions.context; } | |
8390 | else { route.context = Utils.extend({}, route.context, resolveOptions.context); } | |
8391 | options.route.context = route.context; | |
8392 | } | |
8393 | router.loadBack(resolveParams, Utils.extend(options, resolveOptions), true); | |
8394 | } | |
8395 | function asyncReject() { | |
8396 | router.allowPageChange = true; | |
8397 | } | |
8398 | if (route.route.async) { | |
8399 | router.allowPageChange = false; | |
8400 | ||
8401 | route.route.async.call(router, route, router.currentRoute, asyncResolve, asyncReject); | |
8402 | } | |
8403 | } | |
8404 | function reject() { | |
8405 | router.allowPageChange = true; | |
8406 | } | |
8407 | ||
8408 | if (options.preload) { | |
8409 | resolve(); | |
8410 | } else { | |
8411 | processRouteQueue.call( | |
8412 | router, | |
8413 | route, | |
8414 | router.currentRoute, | |
8415 | function () { | |
8416 | if (route.route.modules) { | |
8417 | app | |
8418 | .loadModules(Array.isArray(route.route.modules) ? route.route.modules : [route.route.modules]) | |
8419 | .then(function () { | |
8420 | resolve(); | |
8421 | }) | |
8422 | .catch(function () { | |
8423 | reject(); | |
8424 | }); | |
8425 | } else { | |
8426 | resolve(); | |
8427 | } | |
8428 | }, | |
8429 | function () { | |
8430 | reject(); | |
8431 | } | |
8432 | ); | |
8433 | } | |
8434 | ||
8435 | // Return Router | |
8436 | return router; | |
8437 | } | |
8438 | ||
8439 | function clearPreviousPages() { | |
8440 | var router = this; | |
8441 | appRouterCheck(router, 'clearPreviousPages'); | |
8442 | var app = router.app; | |
8443 | var separateNavbar = router.separateNavbar; | |
8444 | ||
8445 | var $pagesToRemove = router.$el | |
8446 | .children('.page') | |
8447 | .filter(function (index, pageInView) { | |
8448 | if (router.currentRoute && (router.currentRoute.modal || router.currentRoute.panel)) { return true; } | |
8449 | return pageInView !== router.currentPageEl; | |
8450 | }); | |
8451 | ||
8452 | $pagesToRemove.each(function (index, pageEl) { | |
8453 | var $oldPageEl = $(pageEl); | |
8454 | var $oldNavbarInnerEl = $(app.navbar.getElByPage($oldPageEl)); | |
8455 | if (router.params.stackPages && router.initialPages.indexOf($oldPageEl[0]) >= 0) { | |
8456 | $oldPageEl.addClass('stacked'); | |
8457 | if (separateNavbar) { | |
8458 | $oldNavbarInnerEl.addClass('stacked'); | |
8459 | } | |
8460 | } else { | |
8461 | // Page remove event | |
8462 | router.pageCallback('beforeRemove', $oldPageEl, $oldNavbarInnerEl, 'previous', undefined, {}); | |
8463 | router.removePage($oldPageEl); | |
8464 | if (separateNavbar && $oldNavbarInnerEl.length) { | |
8465 | router.removeNavbar($oldNavbarInnerEl); | |
8466 | } | |
8467 | } | |
8468 | }); | |
8469 | } | |
8470 | ||
8471 | function clearPreviousHistory() { | |
8472 | var router = this; | |
8473 | appRouterCheck(router, 'clearPreviousHistory'); | |
8474 | var url = router.history[router.history.length - 1]; | |
8475 | ||
8476 | router.clearPreviousPages(); | |
8477 | ||
8478 | router.history = [url]; | |
8479 | router.view.history = [url]; | |
8480 | router.saveHistory(); | |
8481 | } | |
8482 | ||
5d51ea26 | 8483 | var Router = /*@__PURE__*/(function (Framework7Class) { |
5309fbda | 8484 | function Router(app, view) { |
5d51ea26 | 8485 | Framework7Class.call(this, {}, [typeof view === 'undefined' ? app : view]); |
5309fbda DC |
8486 | var router = this; |
8487 | ||
8488 | // Is App Router | |
8489 | router.isAppRouter = typeof view === 'undefined'; | |
8490 | ||
8491 | if (router.isAppRouter) { | |
8492 | // App Router | |
8493 | Utils.extend(false, router, { | |
8494 | app: app, | |
8495 | params: app.params.view, | |
8496 | routes: app.routes || [], | |
8497 | cache: app.cache, | |
8498 | }); | |
8499 | } else { | |
8500 | // View Router | |
8501 | Utils.extend(false, router, { | |
8502 | app: app, | |
8503 | view: view, | |
8504 | viewId: view.id, | |
8505 | params: view.params, | |
8506 | routes: view.routes, | |
8507 | $el: view.$el, | |
8508 | el: view.el, | |
8509 | $navbarEl: view.$navbarEl, | |
8510 | navbarEl: view.navbarEl, | |
8511 | history: view.history, | |
8512 | scrollHistory: view.scrollHistory, | |
8513 | cache: app.cache, | |
8514 | dynamicNavbar: app.theme === 'ios' && view.params.iosDynamicNavbar, | |
8515 | separateNavbar: app.theme === 'ios' && view.params.iosDynamicNavbar && view.params.iosSeparateDynamicNavbar, | |
8516 | initialPages: [], | |
8517 | initialNavbars: [], | |
8518 | }); | |
8519 | } | |
8520 | ||
8521 | // Install Modules | |
8522 | router.useModules(); | |
8523 | ||
8524 | // Temporary Dom | |
8525 | router.tempDom = doc.createElement('div'); | |
8526 | ||
8527 | // AllowPageChage | |
8528 | router.allowPageChange = true; | |
8529 | ||
8530 | // Current Route | |
8531 | var currentRoute = {}; | |
8532 | var previousRoute = {}; | |
8533 | Object.defineProperty(router, 'currentRoute', { | |
8534 | enumerable: true, | |
8535 | configurable: true, | |
8536 | set: function set(newRoute) { | |
8537 | if ( newRoute === void 0 ) newRoute = {}; | |
8538 | ||
8539 | previousRoute = Utils.extend({}, currentRoute); | |
8540 | currentRoute = newRoute; | |
8541 | if (!currentRoute) { return; } | |
8542 | router.url = currentRoute.url; | |
8543 | router.emit('routeChange', newRoute, previousRoute, router); | |
8544 | }, | |
8545 | get: function get() { | |
8546 | return currentRoute; | |
8547 | }, | |
8548 | }); | |
8549 | Object.defineProperty(router, 'previousRoute', { | |
8550 | enumerable: true, | |
8551 | configurable: true, | |
8552 | get: function get() { | |
8553 | return previousRoute; | |
8554 | }, | |
8555 | set: function set(newRoute) { | |
8556 | previousRoute = newRoute; | |
8557 | }, | |
8558 | }); | |
8559 | ||
8560 | return router; | |
8561 | } | |
8562 | ||
5d51ea26 DC |
8563 | if ( Framework7Class ) Router.__proto__ = Framework7Class; |
8564 | Router.prototype = Object.create( Framework7Class && Framework7Class.prototype ); | |
5309fbda DC |
8565 | Router.prototype.constructor = Router; |
8566 | ||
8567 | Router.prototype.animatableNavElements = function animatableNavElements (newNavbarInner, oldNavbarInner, toLarge, fromLarge, direction) { | |
8568 | var router = this; | |
8569 | var dynamicNavbar = router.dynamicNavbar; | |
8570 | var separateNavbar = router.separateNavbar; | |
8571 | var animateIcon = router.params.iosAnimateNavbarBackIcon; | |
8572 | ||
8573 | var newNavEls; | |
8574 | var oldNavEls; | |
8575 | function animatableNavEl($el, navbarInner) { | |
8576 | var isSliding = $el.hasClass('sliding') || navbarInner.hasClass('sliding'); | |
8577 | var isSubnavbar = $el.hasClass('subnavbar'); | |
8578 | var needsOpacityTransition = isSliding ? !isSubnavbar : true; | |
8579 | var $iconEl = $el.find('.back .icon'); | |
8580 | var isIconLabel; | |
8581 | if (isSliding && animateIcon && $el.hasClass('left') && $iconEl.length > 0 && $iconEl.next('span').length) { | |
8582 | $el = $iconEl.next('span'); // eslint-disable-line | |
8583 | isIconLabel = true; | |
8584 | } | |
8585 | return { | |
8586 | $el: $el, | |
8587 | isIconLabel: isIconLabel, | |
8588 | leftOffset: $el[0].f7NavbarLeftOffset, | |
8589 | rightOffset: $el[0].f7NavbarRightOffset, | |
8590 | isSliding: isSliding, | |
8591 | isSubnavbar: isSubnavbar, | |
8592 | needsOpacityTransition: needsOpacityTransition, | |
8593 | }; | |
8594 | } | |
8595 | if (dynamicNavbar) { | |
8596 | newNavEls = []; | |
8597 | oldNavEls = []; | |
8598 | newNavbarInner.children('.left, .right, .title, .subnavbar').each(function (index, navEl) { | |
8599 | var $navEl = $(navEl); | |
8600 | if ($navEl.hasClass('left') && fromLarge && direction === 'forward' && separateNavbar) { return; } | |
8601 | if ($navEl.hasClass('title') && toLarge) { return; } | |
8602 | newNavEls.push(animatableNavEl($navEl, newNavbarInner)); | |
8603 | }); | |
8604 | if (!(oldNavbarInner.hasClass('navbar-master') && router.params.masterDetailBreakpoint > 0 && router.app.width >= router.params.masterDetailBreakpoint)) { | |
8605 | oldNavbarInner.children('.left, .right, .title, .subnavbar').each(function (index, navEl) { | |
8606 | var $navEl = $(navEl); | |
8607 | if ($navEl.hasClass('left') && toLarge && !fromLarge && direction === 'forward' && separateNavbar) { return; } | |
8608 | if ($navEl.hasClass('left') && toLarge && direction === 'backward' && separateNavbar) { return; } | |
8609 | if ($navEl.hasClass('title') && fromLarge) { | |
8610 | return; | |
8611 | } | |
8612 | oldNavEls.push(animatableNavEl($navEl, oldNavbarInner)); | |
8613 | }); | |
8614 | } | |
8615 | [oldNavEls, newNavEls].forEach(function (navEls) { | |
8616 | navEls.forEach(function (navEl) { | |
8617 | var n = navEl; | |
8618 | var isSliding = navEl.isSliding; | |
8619 | var $el = navEl.$el; | |
8620 | var otherEls = navEls === oldNavEls ? newNavEls : oldNavEls; | |
8621 | if (!(isSliding && $el.hasClass('title') && otherEls)) { return; } | |
8622 | otherEls.forEach(function (otherNavEl) { | |
8623 | if (otherNavEl.isIconLabel) { | |
8624 | var iconTextEl = otherNavEl.$el[0]; | |
8625 | n.leftOffset += iconTextEl ? (iconTextEl.offsetLeft || 0) : 0; | |
8626 | } | |
8627 | }); | |
8628 | }); | |
8629 | }); | |
8630 | } | |
8631 | ||
8632 | return { newNavEls: newNavEls, oldNavEls: oldNavEls }; | |
8633 | }; | |
8634 | ||
8635 | Router.prototype.animate = function animate (oldPage, newPage, oldNavbarInner, newNavbarInner, direction, callback) { | |
8636 | var router = this; | |
8637 | if (router.params.animateCustom) { | |
8638 | router.params.animateCustom.apply(router, [oldPage, newPage, oldNavbarInner, newNavbarInner, direction, callback]); | |
8639 | return; | |
8640 | } | |
8641 | var dynamicNavbar = router.dynamicNavbar; | |
8642 | var ios = router.app.theme === 'ios'; | |
8643 | // Router Animation class | |
8644 | var routerTransitionClass = "router-transition-" + direction + " router-transition"; | |
8645 | ||
8646 | var newNavEls; | |
8647 | var oldNavEls; | |
8648 | ||
8649 | var fromLarge; | |
8650 | var toLarge; | |
8651 | ||
8652 | var oldIsLarge; | |
8653 | var newIsLarge; | |
8654 | ||
8655 | if (ios && dynamicNavbar) { | |
8656 | oldIsLarge = oldNavbarInner && oldNavbarInner.hasClass('navbar-inner-large'); | |
8657 | newIsLarge = newNavbarInner && newNavbarInner.hasClass('navbar-inner-large'); | |
8658 | fromLarge = oldIsLarge && !oldNavbarInner.hasClass('navbar-inner-large-collapsed'); | |
8659 | toLarge = newIsLarge && !newNavbarInner.hasClass('navbar-inner-large-collapsed'); | |
8660 | var navEls = router.animatableNavElements(newNavbarInner, oldNavbarInner, toLarge, fromLarge, direction); | |
8661 | newNavEls = navEls.newNavEls; | |
8662 | oldNavEls = navEls.oldNavEls; | |
8663 | } | |
8664 | ||
8665 | function animateNavbars(progress) { | |
8666 | if (!(ios && dynamicNavbar)) { return; } | |
8667 | if (progress === 1) { | |
8668 | if (toLarge) { | |
8669 | newNavbarInner.addClass('router-navbar-transition-to-large'); | |
8670 | oldNavbarInner.addClass('router-navbar-transition-to-large'); | |
8671 | } | |
8672 | if (fromLarge) { | |
8673 | newNavbarInner.addClass('router-navbar-transition-from-large'); | |
8674 | oldNavbarInner.addClass('router-navbar-transition-from-large'); | |
8675 | } | |
8676 | } | |
8677 | newNavEls.forEach(function (navEl) { | |
8678 | var $el = navEl.$el; | |
8679 | var offset = direction === 'forward' ? navEl.rightOffset : navEl.leftOffset; | |
8680 | if (navEl.isSliding) { | |
8681 | if (navEl.isSubnavbar && newIsLarge) { | |
8682 | $el[0].style.setProperty('transform', ("translate3d(" + (offset * (1 - progress)) + "px, calc(-1 * var(--f7-navbar-large-collapse-progress) * var(--f7-navbar-large-title-height)), 0)"), 'important'); | |
8683 | } else { | |
8684 | $el.transform(("translate3d(" + (offset * (1 - progress)) + "px,0,0)")); | |
8685 | } | |
8686 | } | |
8687 | }); | |
8688 | oldNavEls.forEach(function (navEl) { | |
8689 | var $el = navEl.$el; | |
8690 | var offset = direction === 'forward' ? navEl.leftOffset : navEl.rightOffset; | |
8691 | if (navEl.isSliding) { | |
8692 | if (navEl.isSubnavbar && oldIsLarge) { | |
8693 | $el.transform(("translate3d(" + (offset * (progress)) + "px, calc(-1 * var(--f7-navbar-large-collapse-progress) * var(--f7-navbar-large-title-height)), 0)")); | |
8694 | } else { | |
8695 | $el.transform(("translate3d(" + (offset * (progress)) + "px,0,0)")); | |
8696 | } | |
8697 | } | |
8698 | }); | |
8699 | } | |
8700 | ||
8701 | // AnimationEnd Callback | |
8702 | function onDone() { | |
8703 | if (router.dynamicNavbar) { | |
8704 | if (newNavbarInner) { | |
8705 | newNavbarInner.removeClass('router-navbar-transition-to-large router-navbar-transition-from-large'); | |
8706 | newNavbarInner.addClass('navbar-no-title-large-transition'); | |
8707 | Utils.nextFrame(function () { | |
8708 | newNavbarInner.removeClass('navbar-no-title-large-transition'); | |
8709 | }); | |
8710 | } | |
8711 | if (oldNavbarInner) { | |
8712 | oldNavbarInner.removeClass('router-navbar-transition-to-large router-navbar-transition-from-large'); | |
8713 | } | |
8714 | if (newNavbarInner.hasClass('sliding')) { | |
8715 | newNavbarInner.find('.title, .left, .right, .left .icon, .subnavbar').transform(''); | |
8716 | } else { | |
8717 | newNavbarInner.find('.sliding').transform(''); | |
8718 | } | |
8719 | if (oldNavbarInner.hasClass('sliding')) { | |
8720 | oldNavbarInner.find('.title, .left, .right, .left .icon, .subnavbar').transform(''); | |
8721 | } else { | |
8722 | oldNavbarInner.find('.sliding').transform(''); | |
8723 | } | |
8724 | } | |
8725 | router.$el.removeClass(routerTransitionClass); | |
8726 | if (callback) { callback(); } | |
8727 | } | |
8728 | ||
8729 | (direction === 'forward' ? newPage : oldPage).animationEnd(function () { | |
8730 | onDone(); | |
8731 | }); | |
8732 | ||
8733 | // Animate | |
8734 | if (dynamicNavbar) { | |
8735 | // Prepare Navbars | |
8736 | animateNavbars(0); | |
8737 | Utils.nextFrame(function () { | |
8738 | // Add class, start animation | |
8739 | animateNavbars(1); | |
8740 | router.$el.addClass(routerTransitionClass); | |
8741 | }); | |
8742 | } else { | |
8743 | // Add class, start animation | |
8744 | router.$el.addClass(routerTransitionClass); | |
8745 | } | |
8746 | }; | |
8747 | ||
8748 | Router.prototype.removeModal = function removeModal (modalEl) { | |
8749 | var router = this; | |
8750 | router.removeEl(modalEl); | |
8751 | }; | |
8752 | // eslint-disable-next-line | |
8753 | Router.prototype.removeTabContent = function removeTabContent (tabEl) { | |
8754 | var $tabEl = $(tabEl); | |
8755 | $tabEl.html(''); | |
8756 | }; | |
8757 | ||
8758 | Router.prototype.removeNavbar = function removeNavbar (el) { | |
8759 | var router = this; | |
8760 | router.removeEl(el); | |
8761 | }; | |
8762 | ||
8763 | Router.prototype.removePage = function removePage (el) { | |
8764 | var $el = $(el); | |
8765 | var f7Page = $el && $el[0] && $el[0].f7Page; | |
8766 | var router = this; | |
8767 | if (f7Page && f7Page.route && f7Page.route.route && f7Page.route.route.keepAlive) { | |
8768 | $el.remove(); | |
8769 | return; | |
8770 | } | |
8771 | router.removeEl(el); | |
8772 | }; | |
8773 | ||
8774 | Router.prototype.removeEl = function removeEl (el) { | |
8775 | if (!el) { return; } | |
8776 | var router = this; | |
8777 | var $el = $(el); | |
8778 | if ($el.length === 0) { return; } | |
8779 | $el.find('.tab').each(function (tabIndex, tabEl) { | |
8780 | $(tabEl).children().each(function (index, tabChild) { | |
8781 | if (tabChild.f7Component) { | |
8782 | $(tabChild).trigger('tab:beforeremove'); | |
8783 | tabChild.f7Component.$destroy(); | |
8784 | } | |
8785 | }); | |
8786 | }); | |
8787 | if ($el[0].f7Component && $el[0].f7Component.$destroy) { | |
8788 | $el[0].f7Component.$destroy(); | |
8789 | } | |
8790 | if (!router.params.removeElements) { | |
8791 | return; | |
8792 | } | |
8793 | if (router.params.removeElementsWithTimeout) { | |
8794 | setTimeout(function () { | |
8795 | $el.remove(); | |
8796 | }, router.params.removeElementsTimeout); | |
8797 | } else { | |
8798 | $el.remove(); | |
8799 | } | |
8800 | }; | |
8801 | ||
8802 | Router.prototype.getPageEl = function getPageEl (content) { | |
8803 | var router = this; | |
8804 | if (typeof content === 'string') { | |
8805 | router.tempDom.innerHTML = content; | |
8806 | } else { | |
8807 | if ($(content).hasClass('page')) { | |
8808 | return content; | |
8809 | } | |
8810 | router.tempDom.innerHTML = ''; | |
8811 | $(router.tempDom).append(content); | |
8812 | } | |
8813 | ||
8814 | return router.findElement('.page', router.tempDom); | |
8815 | }; | |
8816 | ||
8817 | Router.prototype.findElement = function findElement (stringSelector, container, notStacked) { | |
8818 | var router = this; | |
8819 | var view = router.view; | |
8820 | var app = router.app; | |
8821 | ||
8822 | // Modals Selector | |
8823 | var modalsSelector = '.popup, .dialog, .popover, .actions-modal, .sheet-modal, .login-screen, .page'; | |
8824 | ||
8825 | var $container = $(container); | |
8826 | var selector = stringSelector; | |
8827 | if (notStacked) { selector += ':not(.stacked)'; } | |
8828 | ||
8829 | var found = $container | |
8830 | .find(selector) | |
8831 | .filter(function (index, el) { return $(el).parents(modalsSelector).length === 0; }); | |
8832 | ||
8833 | if (found.length > 1) { | |
8834 | if (typeof view.selector === 'string') { | |
8835 | // Search in related view | |
8836 | found = $container.find(((view.selector) + " " + selector)); | |
8837 | } | |
8838 | if (found.length > 1) { | |
8839 | // Search in main view | |
8840 | found = $container.find(("." + (app.params.viewMainClass) + " " + selector)); | |
8841 | } | |
8842 | } | |
8843 | if (found.length === 1) { return found; } | |
8844 | ||
8845 | // Try to find not stacked | |
8846 | if (!notStacked) { found = router.findElement(selector, $container, true); } | |
8847 | if (found && found.length === 1) { return found; } | |
8848 | if (found && found.length > 1) { return $(found[0]); } | |
8849 | return undefined; | |
8850 | }; | |
8851 | ||
8852 | Router.prototype.flattenRoutes = function flattenRoutes (routes) { | |
8853 | if ( routes === void 0 ) routes = this.routes; | |
8854 | ||
8855 | var router = this; | |
8856 | var flattenedRoutes = []; | |
8857 | routes.forEach(function (route) { | |
8858 | var hasTabRoutes = false; | |
8859 | if ('tabs' in route && route.tabs) { | |
8860 | var mergedPathsRoutes = route.tabs.map(function (tabRoute) { | |
8861 | var tRoute = Utils.extend({}, route, { | |
8862 | path: (((route.path) + "/" + (tabRoute.path))).replace('///', '/').replace('//', '/'), | |
8863 | parentPath: route.path, | |
8864 | tab: tabRoute, | |
8865 | }); | |
8866 | delete tRoute.tabs; | |
8867 | delete tRoute.routes; | |
8868 | return tRoute; | |
8869 | }); | |
8870 | hasTabRoutes = true; | |
8871 | flattenedRoutes = flattenedRoutes.concat(router.flattenRoutes(mergedPathsRoutes)); | |
8872 | } | |
8873 | if ('detailRoutes' in route) { | |
8874 | var mergedPathsRoutes$1 = route.detailRoutes.map(function (detailRoute) { | |
8875 | var dRoute = Utils.extend({}, detailRoute); | |
8876 | dRoute.masterRoute = route; | |
8877 | dRoute.masterRoutePath = route.path; | |
8878 | return dRoute; | |
8879 | }); | |
8880 | flattenedRoutes = flattenedRoutes.concat(route, router.flattenRoutes(mergedPathsRoutes$1)); | |
8881 | } | |
8882 | if ('routes' in route) { | |
8883 | var mergedPathsRoutes$2 = route.routes.map(function (childRoute) { | |
8884 | var cRoute = Utils.extend({}, childRoute); | |
8885 | cRoute.path = (((route.path) + "/" + (cRoute.path))).replace('///', '/').replace('//', '/'); | |
8886 | return cRoute; | |
8887 | }); | |
8888 | if (hasTabRoutes) { | |
8889 | flattenedRoutes = flattenedRoutes.concat(router.flattenRoutes(mergedPathsRoutes$2)); | |
8890 | } else { | |
8891 | flattenedRoutes = flattenedRoutes.concat(route, router.flattenRoutes(mergedPathsRoutes$2)); | |
8892 | } | |
8893 | } | |
8894 | if (!('routes' in route) && !('tabs' in route && route.tabs) && !('detailRoutes' in route)) { | |
8895 | flattenedRoutes.push(route); | |
8896 | } | |
8897 | }); | |
8898 | return flattenedRoutes; | |
8899 | }; | |
8900 | ||
8901 | // eslint-disable-next-line | |
8902 | Router.prototype.parseRouteUrl = function parseRouteUrl (url) { | |
8903 | if (!url) { return {}; } | |
8904 | var query = Utils.parseUrlQuery(url); | |
8905 | var hash = url.split('#')[1]; | |
8906 | var params = {}; | |
8907 | var path = url.split('#')[0].split('?')[0]; | |
8908 | return { | |
8909 | query: query, | |
8910 | hash: hash, | |
8911 | params: params, | |
8912 | url: url, | |
8913 | path: path, | |
8914 | }; | |
8915 | }; | |
8916 | ||
8917 | // eslint-disable-next-line | |
8918 | Router.prototype.constructRouteUrl = function constructRouteUrl (route, ref) { | |
8919 | if ( ref === void 0 ) ref = {}; | |
8920 | var params = ref.params; | |
8921 | var query = ref.query; | |
8922 | ||
8923 | var path = route.path; | |
8924 | var toUrl = pathToRegexp_1.compile(path); | |
8925 | var url; | |
8926 | try { | |
8927 | url = toUrl(params || {}); | |
8928 | } catch (error) { | |
8929 | throw new Error(("Framework7: error constructing route URL from passed params:\nRoute: " + path + "\n" + (error.toString()))); | |
8930 | } | |
8931 | ||
8932 | if (query) { | |
8933 | if (typeof query === 'string') { url += "?" + query; } | |
8934 | else { url += "?" + (Utils.serializeObject(query)); } | |
8935 | } | |
8936 | ||
8937 | return url; | |
8938 | }; | |
8939 | ||
8940 | Router.prototype.findTabRoute = function findTabRoute (tabEl) { | |
8941 | var router = this; | |
8942 | var $tabEl = $(tabEl); | |
8943 | var parentPath = router.currentRoute.route.parentPath; | |
8944 | var tabId = $tabEl.attr('id'); | |
8945 | var flattenedRoutes = router.flattenRoutes(router.routes); | |
8946 | var foundTabRoute; | |
8947 | flattenedRoutes.forEach(function (route) { | |
8948 | if ( | |
8949 | route.parentPath === parentPath | |
8950 | && route.tab | |
8951 | && route.tab.id === tabId | |
8952 | ) { | |
8953 | foundTabRoute = route; | |
8954 | } | |
8955 | }); | |
8956 | return foundTabRoute; | |
8957 | }; | |
8958 | ||
8959 | Router.prototype.findRouteByKey = function findRouteByKey (key, value) { | |
8960 | var router = this; | |
8961 | var routes = router.routes; | |
8962 | var flattenedRoutes = router.flattenRoutes(routes); | |
8963 | var matchingRoute; | |
8964 | ||
8965 | flattenedRoutes.forEach(function (route) { | |
8966 | if (matchingRoute) { return; } | |
8967 | if (route[key] === value) { | |
8968 | matchingRoute = route; | |
8969 | } | |
8970 | }); | |
8971 | return matchingRoute; | |
8972 | }; | |
8973 | ||
8974 | Router.prototype.findMatchingRoute = function findMatchingRoute (url) { | |
8975 | if (!url) { return undefined; } | |
8976 | var router = this; | |
8977 | var routes = router.routes; | |
8978 | var flattenedRoutes = router.flattenRoutes(routes); | |
8979 | var ref = router.parseRouteUrl(url); | |
8980 | var path = ref.path; | |
8981 | var query = ref.query; | |
8982 | var hash = ref.hash; | |
8983 | var params = ref.params; | |
8984 | var matchingRoute; | |
8985 | flattenedRoutes.forEach(function (route) { | |
8986 | if (matchingRoute) { return; } | |
8987 | var keys = []; | |
8988 | ||
8989 | var pathsToMatch = [route.path]; | |
8990 | if (route.alias) { | |
8991 | if (typeof route.alias === 'string') { pathsToMatch.push(route.alias); } | |
8992 | else if (Array.isArray(route.alias)) { | |
8993 | route.alias.forEach(function (aliasPath) { | |
8994 | pathsToMatch.push(aliasPath); | |
8995 | }); | |
8996 | } | |
8997 | } | |
8998 | ||
8999 | var matched; | |
9000 | pathsToMatch.forEach(function (pathToMatch) { | |
9001 | if (matched) { return; } | |
9002 | matched = pathToRegexp_1(pathToMatch, keys).exec(path); | |
9003 | }); | |
9004 | ||
9005 | if (matched) { | |
9006 | keys.forEach(function (keyObj, index) { | |
9007 | if (typeof keyObj.name === 'number') { return; } | |
9008 | var paramValue = matched[index + 1]; | |
5d51ea26 DC |
9009 | if (typeof paramValue === 'undefined' || paramValue === null) { |
9010 | params[keyObj.name] = paramValue; | |
9011 | } else { | |
9012 | params[keyObj.name] = decodeURIComponent(paramValue); | |
9013 | } | |
5309fbda DC |
9014 | }); |
9015 | ||
9016 | var parentPath; | |
9017 | if (route.parentPath) { | |
9018 | parentPath = path.split('/').slice(0, route.parentPath.split('/').length - 1).join('/'); | |
9019 | } | |
9020 | ||
9021 | matchingRoute = { | |
9022 | query: query, | |
9023 | hash: hash, | |
9024 | params: params, | |
9025 | url: url, | |
9026 | path: path, | |
9027 | parentPath: parentPath, | |
9028 | route: route, | |
9029 | name: route.name, | |
9030 | }; | |
9031 | } | |
9032 | }); | |
9033 | return matchingRoute; | |
9034 | }; | |
9035 | ||
9036 | // eslint-disable-next-line | |
9037 | Router.prototype.replaceRequestUrlParams = function replaceRequestUrlParams (url, options) { | |
9038 | if ( url === void 0 ) url = ''; | |
9039 | if ( options === void 0 ) options = {}; | |
9040 | ||
9041 | var compiledUrl = url; | |
9042 | if (typeof compiledUrl === 'string' | |
9043 | && compiledUrl.indexOf('{{') >= 0 | |
9044 | && options | |
9045 | && options.route | |
9046 | && options.route.params | |
9047 | && Object.keys(options.route.params).length | |
9048 | ) { | |
9049 | Object.keys(options.route.params).forEach(function (paramName) { | |
9050 | var regExp = new RegExp(("{{" + paramName + "}}"), 'g'); | |
9051 | compiledUrl = compiledUrl.replace(regExp, options.route.params[paramName] || ''); | |
9052 | }); | |
9053 | } | |
9054 | return compiledUrl; | |
9055 | }; | |
9056 | ||
9057 | Router.prototype.removeFromXhrCache = function removeFromXhrCache (url) { | |
9058 | var router = this; | |
9059 | var xhrCache = router.cache.xhr; | |
9060 | var index = false; | |
9061 | for (var i = 0; i < xhrCache.length; i += 1) { | |
9062 | if (xhrCache[i].url === url) { index = i; } | |
9063 | } | |
9064 | if (index !== false) { xhrCache.splice(index, 1); } | |
9065 | }; | |
9066 | ||
9067 | Router.prototype.xhrRequest = function xhrRequest (requestUrl, options) { | |
9068 | var router = this; | |
9069 | var params = router.params; | |
9070 | var ignoreCache = options.ignoreCache; | |
9071 | var url = requestUrl; | |
9072 | ||
9073 | var hasQuery = url.indexOf('?') >= 0; | |
9074 | if (params.passRouteQueryToRequest | |
9075 | && options | |
9076 | && options.route | |
9077 | && options.route.query | |
9078 | && Object.keys(options.route.query).length | |
9079 | ) { | |
9080 | url += "" + (hasQuery ? '&' : '?') + (Utils.serializeObject(options.route.query)); | |
9081 | hasQuery = true; | |
9082 | } | |
9083 | ||
9084 | if (params.passRouteParamsToRequest | |
9085 | && options | |
9086 | && options.route | |
9087 | && options.route.params | |
9088 | && Object.keys(options.route.params).length | |
9089 | ) { | |
9090 | url += "" + (hasQuery ? '&' : '?') + (Utils.serializeObject(options.route.params)); | |
9091 | hasQuery = true; | |
9092 | } | |
9093 | ||
9094 | if (url.indexOf('{{') >= 0) { | |
9095 | url = router.replaceRequestUrlParams(url, options); | |
9096 | } | |
9097 | // should we ignore get params or not | |
9098 | if (params.xhrCacheIgnoreGetParameters && url.indexOf('?') >= 0) { | |
9099 | url = url.split('?')[0]; | |
9100 | } | |
9101 | return new Promise(function (resolve, reject) { | |
9102 | if (params.xhrCache && !ignoreCache && url.indexOf('nocache') < 0 && params.xhrCacheIgnore.indexOf(url) < 0) { | |
9103 | for (var i = 0; i < router.cache.xhr.length; i += 1) { | |
9104 | var cachedUrl = router.cache.xhr[i]; | |
9105 | if (cachedUrl.url === url) { | |
9106 | // Check expiration | |
9107 | if (Utils.now() - cachedUrl.time < params.xhrCacheDuration) { | |
9108 | // Load from cache | |
9109 | resolve(cachedUrl.content); | |
9110 | return; | |
9111 | } | |
9112 | } | |
9113 | } | |
9114 | } | |
9115 | router.xhr = router.app.request({ | |
9116 | url: url, | |
9117 | method: 'GET', | |
9118 | beforeSend: function beforeSend(xhr) { | |
9119 | router.emit('routerAjaxStart', xhr, options); | |
9120 | }, | |
9121 | complete: function complete(xhr, status) { | |
9122 | router.emit('routerAjaxComplete', xhr); | |
9123 | if ((status !== 'error' && status !== 'timeout' && (xhr.status >= 200 && xhr.status < 300)) || xhr.status === 0) { | |
9124 | if (params.xhrCache && xhr.responseText !== '') { | |
9125 | router.removeFromXhrCache(url); | |
9126 | router.cache.xhr.push({ | |
9127 | url: url, | |
9128 | time: Utils.now(), | |
9129 | content: xhr.responseText, | |
9130 | }); | |
9131 | } | |
9132 | router.emit('routerAjaxSuccess', xhr, options); | |
9133 | resolve(xhr.responseText); | |
9134 | } else { | |
9135 | router.emit('routerAjaxError', xhr, options); | |
9136 | reject(xhr); | |
9137 | } | |
9138 | }, | |
9139 | error: function error(xhr) { | |
9140 | router.emit('routerAjaxError', xhr, options); | |
9141 | reject(xhr); | |
9142 | }, | |
9143 | }); | |
9144 | }); | |
9145 | }; | |
9146 | ||
9147 | // Remove theme elements | |
9148 | Router.prototype.removeThemeElements = function removeThemeElements (el) { | |
9149 | var router = this; | |
9150 | var theme = router.app.theme; | |
5d51ea26 DC |
9151 | var toRemove; |
9152 | if (theme === 'ios') { | |
9153 | toRemove = '.md-only, .aurora-only, .if-md, .if-aurora, .if-not-ios, .not-ios'; | |
9154 | } else if (theme === 'md') { | |
9155 | toRemove = '.ios-only, .aurora-only, .if-ios, .if-aurora, .if-not-md, .not-md'; | |
9156 | } else if (theme === 'aurora') { | |
9157 | toRemove = '.ios-only, .md-only, .if-ios, .if-md, .if-not-aurora, .not-aurora'; | |
9158 | } | |
9159 | $(el).find(toRemove).remove(); | |
5309fbda DC |
9160 | }; |
9161 | ||
9162 | Router.prototype.getPageData = function getPageData (pageEl, navbarEl, from, to, route, pageFromEl) { | |
9163 | if ( route === void 0 ) route = {}; | |
9164 | ||
9165 | var router = this; | |
9166 | var $pageEl = $(pageEl).eq(0); | |
9167 | var $navbarEl = $(navbarEl).eq(0); | |
9168 | var currentPage = $pageEl[0].f7Page || {}; | |
9169 | var direction; | |
9170 | var pageFrom; | |
9171 | if ((from === 'next' && to === 'current') || (from === 'current' && to === 'previous')) { direction = 'forward'; } | |
9172 | if ((from === 'current' && to === 'next') || (from === 'previous' && to === 'current')) { direction = 'backward'; } | |
9173 | if (currentPage && !currentPage.fromPage) { | |
9174 | var $pageFromEl = $(pageFromEl); | |
9175 | if ($pageFromEl.length) { | |
9176 | pageFrom = $pageFromEl[0].f7Page; | |
9177 | } | |
9178 | } | |
9179 | pageFrom = currentPage.pageFrom || pageFrom; | |
9180 | if (pageFrom && pageFrom.pageFrom) { | |
9181 | pageFrom.pageFrom = null; | |
9182 | } | |
9183 | var page = { | |
9184 | app: router.app, | |
9185 | view: router.view, | |
9186 | router: router, | |
9187 | $el: $pageEl, | |
9188 | el: $pageEl[0], | |
9189 | $pageEl: $pageEl, | |
9190 | pageEl: $pageEl[0], | |
9191 | $navbarEl: $navbarEl, | |
9192 | navbarEl: $navbarEl[0], | |
9193 | name: $pageEl.attr('data-name'), | |
9194 | position: from, | |
9195 | from: from, | |
9196 | to: to, | |
9197 | direction: direction, | |
9198 | route: currentPage.route ? currentPage.route : route, | |
9199 | pageFrom: pageFrom, | |
9200 | }; | |
9201 | ||
9202 | $pageEl[0].f7Page = page; | |
9203 | return page; | |
9204 | }; | |
9205 | ||
9206 | // Callbacks | |
9207 | Router.prototype.pageCallback = function pageCallback (callback, pageEl, navbarEl, from, to, options, pageFromEl) { | |
9208 | if ( options === void 0 ) options = {}; | |
9209 | ||
9210 | if (!pageEl) { return; } | |
9211 | var router = this; | |
9212 | var $pageEl = $(pageEl); | |
9213 | if (!$pageEl.length) { return; } | |
9214 | var $navbarEl = $(navbarEl); | |
9215 | var route = options.route; | |
9216 | var restoreScrollTopOnBack = router.params.restoreScrollTopOnBack | |
9217 | && !( | |
9218 | router.params.masterDetailBreakpoint > 0 | |
9219 | && $pageEl.hasClass('page-master') | |
9220 | && router.app.width >= router.params.masterDetailBreakpoint | |
9221 | ); | |
9222 | var keepAlive = $pageEl[0].f7Page && $pageEl[0].f7Page.route && $pageEl[0].f7Page.route.route && $pageEl[0].f7Page.route.route.keepAlive; | |
9223 | ||
9224 | if (callback === 'beforeRemove' && keepAlive) { | |
9225 | callback = 'beforeUnmount'; // eslint-disable-line | |
9226 | } | |
9227 | ||
9228 | var camelName = "page" + (callback[0].toUpperCase() + callback.slice(1, callback.length)); | |
9229 | var colonName = "page:" + (callback.toLowerCase()); | |
9230 | ||
9231 | var page = {}; | |
9232 | if (callback === 'beforeRemove' && $pageEl[0].f7Page) { | |
9233 | page = Utils.extend($pageEl[0].f7Page, { from: from, to: to, position: from }); | |
9234 | } else { | |
9235 | page = router.getPageData($pageEl[0], $navbarEl[0], from, to, route, pageFromEl); | |
9236 | } | |
9237 | page.swipeBack = !!options.swipeBack; | |
9238 | ||
9239 | var ref = options.route ? options.route.route : {}; | |
9240 | var on = ref.on; if ( on === void 0 ) on = {}; | |
9241 | var once = ref.once; if ( once === void 0 ) once = {}; | |
9242 | if (options.on) { | |
9243 | Utils.extend(on, options.on); | |
9244 | } | |
9245 | if (options.once) { | |
9246 | Utils.extend(once, options.once); | |
9247 | } | |
9248 | ||
9249 | function attachEvents() { | |
9250 | if ($pageEl[0].f7RouteEventsAttached) { return; } | |
9251 | $pageEl[0].f7RouteEventsAttached = true; | |
9252 | if (on && Object.keys(on).length > 0) { | |
9253 | $pageEl[0].f7RouteEventsOn = on; | |
9254 | Object.keys(on).forEach(function (eventName) { | |
9255 | on[eventName] = on[eventName].bind(router); | |
9256 | $pageEl.on(Utils.eventNameToColonCase(eventName), on[eventName]); | |
9257 | }); | |
9258 | } | |
9259 | if (once && Object.keys(once).length > 0) { | |
9260 | $pageEl[0].f7RouteEventsOnce = once; | |
9261 | Object.keys(once).forEach(function (eventName) { | |
9262 | once[eventName] = once[eventName].bind(router); | |
9263 | $pageEl.once(Utils.eventNameToColonCase(eventName), once[eventName]); | |
9264 | }); | |
9265 | } | |
9266 | } | |
9267 | ||
9268 | function detachEvents() { | |
9269 | if (!$pageEl[0].f7RouteEventsAttached) { return; } | |
9270 | if ($pageEl[0].f7RouteEventsOn) { | |
9271 | Object.keys($pageEl[0].f7RouteEventsOn).forEach(function (eventName) { | |
9272 | $pageEl.off(Utils.eventNameToColonCase(eventName), $pageEl[0].f7RouteEventsOn[eventName]); | |
9273 | }); | |
9274 | } | |
9275 | if ($pageEl[0].f7RouteEventsOnce) { | |
9276 | Object.keys($pageEl[0].f7RouteEventsOnce).forEach(function (eventName) { | |
9277 | $pageEl.off(Utils.eventNameToColonCase(eventName), $pageEl[0].f7RouteEventsOnce[eventName]); | |
9278 | }); | |
9279 | } | |
9280 | $pageEl[0].f7RouteEventsAttached = null; | |
9281 | $pageEl[0].f7RouteEventsOn = null; | |
9282 | $pageEl[0].f7RouteEventsOnce = null; | |
9283 | delete $pageEl[0].f7RouteEventsAttached; | |
9284 | delete $pageEl[0].f7RouteEventsOn; | |
9285 | delete $pageEl[0].f7RouteEventsOnce; | |
9286 | } | |
9287 | ||
9288 | if (callback === 'mounted') { | |
9289 | attachEvents(); | |
9290 | } | |
9291 | if (callback === 'init') { | |
9292 | if (restoreScrollTopOnBack && (from === 'previous' || !from) && to === 'current' && router.scrollHistory[page.route.url] && !$pageEl.hasClass('no-restore-scroll')) { | |
9293 | var $pageContent = $pageEl.find('.page-content'); | |
9294 | if ($pageContent.length > 0) { | |
9295 | // eslint-disable-next-line | |
9296 | $pageContent = $pageContent.filter(function (pageContentIndex, pageContentEl) { | |
9297 | return ( | |
9298 | $(pageContentEl).parents('.tab:not(.tab-active)').length === 0 | |
9299 | && !$(pageContentEl).is('.tab:not(.tab-active)') | |
9300 | ); | |
9301 | }); | |
9302 | } | |
9303 | $pageContent.scrollTop(router.scrollHistory[page.route.url]); | |
9304 | } | |
9305 | attachEvents(); | |
9306 | if ($pageEl[0].f7PageInitialized) { | |
9307 | $pageEl.trigger('page:reinit', page); | |
9308 | router.emit('pageReinit', page); | |
9309 | return; | |
9310 | } | |
9311 | $pageEl[0].f7PageInitialized = true; | |
9312 | } | |
9313 | if (restoreScrollTopOnBack && callback === 'beforeOut' && from === 'current' && to === 'previous') { | |
9314 | // Save scroll position | |
9315 | var $pageContent$1 = $pageEl.find('.page-content'); | |
9316 | if ($pageContent$1.length > 0) { | |
9317 | // eslint-disable-next-line | |
9318 | $pageContent$1 = $pageContent$1.filter(function (pageContentIndex, pageContentEl) { | |
9319 | return ( | |
9320 | $(pageContentEl).parents('.tab:not(.tab-active)').length === 0 | |
9321 | && !$(pageContentEl).is('.tab:not(.tab-active)') | |
9322 | ); | |
9323 | }); | |
9324 | } | |
9325 | router.scrollHistory[page.route.url] = $pageContent$1.scrollTop(); | |
9326 | } | |
9327 | if (restoreScrollTopOnBack && callback === 'beforeOut' && from === 'current' && to === 'next') { | |
9328 | // Delete scroll position | |
9329 | delete router.scrollHistory[page.route.url]; | |
9330 | } | |
9331 | ||
9332 | $pageEl.trigger(colonName, page); | |
9333 | router.emit(camelName, page); | |
9334 | ||
9335 | if (callback === 'beforeRemove' || callback === 'beforeUnmount') { | |
9336 | detachEvents(); | |
9337 | if (!keepAlive) { | |
9338 | if ($pageEl[0].f7Page && $pageEl[0].f7Page.navbarEl) { | |
9339 | delete $pageEl[0].f7Page.navbarEl.f7Page; | |
9340 | } | |
9341 | $pageEl[0].f7Page = null; | |
9342 | } | |
9343 | } | |
9344 | }; | |
9345 | ||
9346 | Router.prototype.saveHistory = function saveHistory () { | |
9347 | var router = this; | |
9348 | router.view.history = router.history; | |
9349 | if (router.params.pushState) { | |
9350 | win.localStorage[("f7router-" + (router.view.id) + "-history")] = JSON.stringify(router.history); | |
9351 | } | |
9352 | }; | |
9353 | ||
9354 | Router.prototype.restoreHistory = function restoreHistory () { | |
9355 | var router = this; | |
9356 | if (router.params.pushState && win.localStorage[("f7router-" + (router.view.id) + "-history")]) { | |
9357 | router.history = JSON.parse(win.localStorage[("f7router-" + (router.view.id) + "-history")]); | |
9358 | router.view.history = router.history; | |
9359 | } | |
9360 | }; | |
9361 | ||
9362 | Router.prototype.clearHistory = function clearHistory () { | |
9363 | var router = this; | |
9364 | router.history = []; | |
9365 | if (router.view) { router.view.history = []; } | |
9366 | router.saveHistory(); | |
9367 | }; | |
9368 | ||
9369 | Router.prototype.updateCurrentUrl = function updateCurrentUrl (newUrl) { | |
9370 | var router = this; | |
9371 | appRouterCheck(router, 'updateCurrentUrl'); | |
9372 | // Update history | |
9373 | if (router.history.length) { | |
9374 | router.history[router.history.length - 1] = newUrl; | |
9375 | } else { | |
9376 | router.history.push(newUrl); | |
9377 | } | |
9378 | ||
9379 | // Update current route params | |
9380 | var ref = router.parseRouteUrl(newUrl); | |
9381 | var query = ref.query; | |
9382 | var hash = ref.hash; | |
9383 | var params = ref.params; | |
9384 | var url = ref.url; | |
9385 | var path = ref.path; | |
9386 | if (router.currentRoute) { | |
9387 | Utils.extend(router.currentRoute, { | |
9388 | query: query, | |
9389 | hash: hash, | |
9390 | params: params, | |
9391 | url: url, | |
9392 | path: path, | |
9393 | }); | |
9394 | } | |
9395 | ||
9396 | if (router.params.pushState) { | |
9397 | var pushStateRoot = router.params.pushStateRoot || ''; | |
9398 | History.replace( | |
9399 | router.view.id, | |
9400 | { | |
9401 | url: newUrl, | |
9402 | }, | |
9403 | pushStateRoot + router.params.pushStateSeparator + newUrl | |
9404 | ); | |
9405 | } | |
9406 | ||
9407 | // Save History | |
9408 | router.saveHistory(); | |
9409 | ||
9410 | router.emit('routeUrlUpdate', router.currentRoute, router); | |
9411 | }; | |
9412 | ||
9413 | Router.prototype.init = function init () { | |
9414 | var router = this; | |
9415 | var app = router.app; | |
9416 | var view = router.view; | |
9417 | ||
9418 | // Init Swipeback | |
9419 | { | |
9420 | if ( | |
9421 | (view && router.params.iosSwipeBack && app.theme === 'ios') | |
9422 | || (view && router.params.mdSwipeBack && app.theme === 'md') | |
5d51ea26 | 9423 | || (view && router.params.auroraSwipeBack && app.theme === 'aurora') |
5309fbda DC |
9424 | ) { |
9425 | SwipeBack(router); | |
9426 | } | |
9427 | } | |
9428 | ||
9429 | // Dynamic not separated navbbar | |
9430 | if (router.dynamicNavbar && !router.separateNavbar) { | |
9431 | router.$el.addClass('router-dynamic-navbar-inside'); | |
9432 | } | |
9433 | ||
9434 | var initUrl = router.params.url; | |
9435 | var documentUrl = doc.location.href.split(doc.location.origin)[1]; | |
9436 | var historyRestored; | |
9437 | var ref = router.params; | |
9438 | var pushState = ref.pushState; | |
9439 | var pushStateOnLoad = ref.pushStateOnLoad; | |
9440 | var pushStateSeparator = ref.pushStateSeparator; | |
9441 | var pushStateAnimateOnLoad = ref.pushStateAnimateOnLoad; | |
9442 | var ref$1 = router.params; | |
9443 | var pushStateRoot = ref$1.pushStateRoot; | |
9444 | if (win.cordova && pushState && !pushStateSeparator && !pushStateRoot && doc.location.pathname.indexOf('index.html')) { | |
9445 | // eslint-disable-next-line | |
9446 | console.warn('Framework7: wrong or not complete pushState configuration, trying to guess pushStateRoot'); | |
9447 | pushStateRoot = doc.location.pathname.split('index.html')[0]; | |
9448 | } | |
5309fbda DC |
9449 | if (!pushState || !pushStateOnLoad) { |
9450 | if (!initUrl) { | |
9451 | initUrl = documentUrl; | |
9452 | } | |
9453 | if (doc.location.search && initUrl.indexOf('?') < 0) { | |
9454 | initUrl += doc.location.search; | |
9455 | } | |
9456 | if (doc.location.hash && initUrl.indexOf('#') < 0) { | |
9457 | initUrl += doc.location.hash; | |
9458 | } | |
9459 | } else { | |
9460 | if (pushStateRoot && documentUrl.indexOf(pushStateRoot) >= 0) { | |
9461 | documentUrl = documentUrl.split(pushStateRoot)[1]; | |
9462 | if (documentUrl === '') { documentUrl = '/'; } | |
9463 | } | |
9464 | if (pushStateSeparator.length > 0 && documentUrl.indexOf(pushStateSeparator) >= 0) { | |
9465 | initUrl = documentUrl.split(pushStateSeparator)[1]; | |
9466 | } else { | |
9467 | initUrl = documentUrl; | |
9468 | } | |
9469 | router.restoreHistory(); | |
9470 | if (router.history.indexOf(initUrl) >= 0) { | |
9471 | router.history = router.history.slice(0, router.history.indexOf(initUrl) + 1); | |
9472 | } else if (router.params.url === initUrl) { | |
9473 | router.history = [initUrl]; | |
9474 | } else if (History.state && History.state[view.id] && History.state[view.id].url === router.history[router.history.length - 1]) { | |
9475 | initUrl = router.history[router.history.length - 1]; | |
9476 | } else { | |
9477 | router.history = [documentUrl.split(pushStateSeparator)[0] || '/', initUrl]; | |
9478 | } | |
9479 | if (router.history.length > 1) { | |
9480 | historyRestored = true; | |
9481 | } else { | |
9482 | router.history = []; | |
9483 | } | |
9484 | router.saveHistory(); | |
9485 | } | |
9486 | var currentRoute; | |
9487 | if (router.history.length > 1) { | |
9488 | // Will load page | |
9489 | currentRoute = router.findMatchingRoute(router.history[0]); | |
9490 | if (!currentRoute) { | |
9491 | currentRoute = Utils.extend(router.parseRouteUrl(router.history[0]), { | |
9492 | route: { | |
9493 | url: router.history[0], | |
9494 | path: router.history[0].split('?')[0], | |
9495 | }, | |
9496 | }); | |
9497 | } | |
9498 | } else { | |
9499 | // Don't load page | |
9500 | currentRoute = router.findMatchingRoute(initUrl); | |
9501 | if (!currentRoute) { | |
9502 | currentRoute = Utils.extend(router.parseRouteUrl(initUrl), { | |
9503 | route: { | |
9504 | url: initUrl, | |
9505 | path: initUrl.split('?')[0], | |
9506 | }, | |
9507 | }); | |
9508 | } | |
9509 | } | |
9510 | ||
9511 | if (router.params.stackPages) { | |
9512 | router.$el.children('.page').each(function (index, pageEl) { | |
9513 | var $pageEl = $(pageEl); | |
9514 | router.initialPages.push($pageEl[0]); | |
9515 | if (router.separateNavbar && $pageEl.children('.navbar').length > 0) { | |
9516 | router.initialNavbars.push($pageEl.children('.navbar').find('.navbar-inner')[0]); | |
9517 | } | |
9518 | }); | |
9519 | } | |
9520 | ||
9521 | if (router.$el.children('.page:not(.stacked)').length === 0 && initUrl) { | |
9522 | // No pages presented in DOM, reload new page | |
9523 | router.navigate(initUrl, { | |
9524 | initial: true, | |
9525 | reloadCurrent: true, | |
9526 | pushState: false, | |
9527 | }); | |
9528 | } else { | |
9529 | // Init current DOM page | |
9530 | var hasTabRoute; | |
9531 | router.currentRoute = currentRoute; | |
9532 | router.$el.children('.page:not(.stacked)').each(function (index, pageEl) { | |
9533 | var $pageEl = $(pageEl); | |
9534 | var $navbarInnerEl; | |
9535 | $pageEl.addClass('page-current'); | |
9536 | if (router.separateNavbar) { | |
9537 | $navbarInnerEl = $pageEl.children('.navbar').children('.navbar-inner'); | |
9538 | if ($navbarInnerEl.length > 0) { | |
9539 | if (!router.$navbarEl.parents(doc).length) { | |
9540 | router.$el.prepend(router.$navbarEl); | |
9541 | } | |
9542 | $navbarInnerEl.addClass('navbar-current'); | |
9543 | router.$navbarEl.append($navbarInnerEl); | |
9544 | if ($navbarInnerEl.children('.title-large').length) { | |
9545 | $navbarInnerEl.addClass('navbar-inner-large'); | |
9546 | } | |
9547 | $pageEl.children('.navbar').remove(); | |
9548 | } else { | |
9549 | router.$navbarEl.addClass('navbar-hidden'); | |
9550 | if ($navbarInnerEl.children('.title-large').length) { | |
9551 | router.$navbarEl.addClass('navbar-hidden navbar-large-hidden'); | |
9552 | } | |
9553 | } | |
9554 | } | |
9555 | if (router.currentRoute && router.currentRoute.route && router.currentRoute.route.master && router.params.masterDetailBreakpoint > 0) { | |
9556 | $pageEl.addClass('page-master'); | |
9557 | $pageEl.trigger('page:role', { role: 'master' }); | |
9558 | if ($navbarInnerEl && $navbarInnerEl.length) { | |
9559 | $navbarInnerEl.addClass('navbar-master'); | |
9560 | } | |
9561 | } | |
9562 | var initOptions = { | |
9563 | route: router.currentRoute, | |
9564 | }; | |
9565 | if (router.currentRoute && router.currentRoute.route && router.currentRoute.route.options) { | |
9566 | Utils.extend(initOptions, router.currentRoute.route.options); | |
9567 | } | |
9568 | router.currentPageEl = $pageEl[0]; | |
9569 | if (router.separateNavbar && $navbarInnerEl.length) { | |
9570 | router.currentNavbarEl = $navbarInnerEl[0]; | |
9571 | } | |
9572 | router.removeThemeElements($pageEl); | |
9573 | if (router.separateNavbar && $navbarInnerEl.length) { | |
9574 | router.removeThemeElements($navbarInnerEl); | |
9575 | } | |
9576 | if (initOptions.route.route.tab) { | |
9577 | hasTabRoute = true; | |
9578 | router.tabLoad(initOptions.route.route.tab, Utils.extend({}, initOptions)); | |
9579 | } | |
9580 | router.pageCallback('init', $pageEl, $navbarInnerEl, 'current', undefined, initOptions); | |
9581 | }); | |
9582 | if (historyRestored) { | |
9583 | router.navigate(initUrl, { | |
9584 | initial: true, | |
9585 | pushState: false, | |
9586 | history: false, | |
9587 | animate: pushStateAnimateOnLoad, | |
9588 | once: { | |
9589 | pageAfterIn: function pageAfterIn() { | |
5d51ea26 DC |
9590 | var preloadPreviousPage = router.params.preloadPreviousPage || router.params[((app.theme) + "SwipeBack")]; |
9591 | if (preloadPreviousPage && router.history.length > 2) { | |
5309fbda DC |
9592 | router.back({ preload: true }); |
9593 | } | |
9594 | }, | |
9595 | }, | |
9596 | }); | |
9597 | } | |
9598 | if (!historyRestored && !hasTabRoute) { | |
9599 | router.history.push(initUrl); | |
9600 | router.saveHistory(); | |
9601 | } | |
9602 | } | |
9603 | if (initUrl && pushState && pushStateOnLoad && (!History.state || !History.state[view.id])) { | |
9604 | History.initViewState(view.id, { | |
9605 | url: initUrl, | |
9606 | }); | |
9607 | } | |
9608 | router.emit('local::init routerInit', router); | |
9609 | }; | |
9610 | ||
9611 | Router.prototype.destroy = function destroy () { | |
9612 | var router = this; | |
9613 | ||
9614 | router.emit('local::destroy routerDestroy', router); | |
9615 | ||
9616 | // Delete props & methods | |
9617 | Object.keys(router).forEach(function (routerProp) { | |
9618 | router[routerProp] = null; | |
9619 | delete router[routerProp]; | |
9620 | }); | |
9621 | ||
9622 | router = null; | |
9623 | }; | |
9624 | ||
9625 | return Router; | |
9626 | }(Framework7Class)); | |
9627 | ||
9628 | // Load | |
9629 | Router.prototype.forward = forward; | |
9630 | Router.prototype.load = load; | |
9631 | Router.prototype.navigate = navigate; | |
9632 | Router.prototype.refreshPage = refreshPage; | |
9633 | // Tab | |
9634 | Router.prototype.tabLoad = tabLoad; | |
9635 | Router.prototype.tabRemove = tabRemove; | |
9636 | // Modal | |
9637 | Router.prototype.modalLoad = modalLoad; | |
9638 | Router.prototype.modalRemove = modalRemove; | |
9639 | // Back | |
9640 | Router.prototype.backward = backward; | |
9641 | Router.prototype.loadBack = loadBack; | |
9642 | Router.prototype.back = back; | |
9643 | // Clear previoius pages from the DOM | |
9644 | Router.prototype.clearPreviousPages = clearPreviousPages; | |
9645 | // Clear history | |
9646 | Router.prototype.clearPreviousHistory = clearPreviousHistory; | |
9647 | ||
5d51ea26 | 9648 | var RouterModule = { |
5309fbda DC |
9649 | name: 'router', |
9650 | static: { | |
9651 | Router: Router, | |
9652 | }, | |
9653 | instance: { | |
9654 | cache: { | |
9655 | xhr: [], | |
9656 | templates: [], | |
9657 | components: [], | |
9658 | }, | |
9659 | }, | |
9660 | create: function create() { | |
9661 | var instance = this; | |
9662 | if (instance.app) { | |
9663 | // View Router | |
9664 | if (instance.params.router) { | |
9665 | instance.router = new Router(instance.app, instance); | |
9666 | } | |
9667 | } else { | |
9668 | // App Router | |
9669 | instance.router = new Router(instance); | |
9670 | } | |
9671 | }, | |
9672 | }; | |
9673 | ||
5d51ea26 | 9674 | var View = /*@__PURE__*/(function (Framework7Class) { |
5309fbda DC |
9675 | function View(appInstance, el, viewParams) { |
9676 | if ( viewParams === void 0 ) viewParams = {}; | |
9677 | ||
5d51ea26 | 9678 | Framework7Class.call(this, viewParams, [appInstance]); |
5309fbda DC |
9679 | |
9680 | var app = appInstance; | |
9681 | var $el = $(el); | |
9682 | var view = this; | |
9683 | ||
9684 | var defaults = { | |
9685 | routes: [], | |
9686 | routesAdd: [], | |
9687 | }; | |
9688 | ||
9689 | // Default View params | |
9690 | view.params = Utils.extend(defaults, app.params.view, viewParams); | |
9691 | ||
9692 | // Routes | |
9693 | if (view.params.routes.length > 0) { | |
9694 | view.routes = view.params.routes; | |
9695 | } else { | |
9696 | view.routes = [].concat(app.routes, view.params.routesAdd); | |
9697 | } | |
9698 | ||
9699 | // Selector | |
9700 | var selector; | |
9701 | if (typeof el === 'string') { selector = el; } | |
9702 | else { | |
9703 | // Supposed to be HTMLElement or Dom7 | |
9704 | selector = ($el.attr('id') ? ("#" + ($el.attr('id'))) : '') + ($el.attr('class') ? ("." + ($el.attr('class').replace(/ /g, '.').replace('.active', ''))) : ''); | |
9705 | } | |
9706 | ||
9707 | // DynamicNavbar | |
9708 | var $navbarEl; | |
9709 | if (app.theme === 'ios' && view.params.iosDynamicNavbar && view.params.iosSeparateDynamicNavbar) { | |
9710 | $navbarEl = $el.children('.navbar').eq(0); | |
9711 | if ($navbarEl.length === 0) { | |
9712 | $navbarEl = $('<div class="navbar"></div>'); | |
9713 | } | |
9714 | } | |
9715 | ||
9716 | // View Props | |
9717 | Utils.extend(false, view, { | |
9718 | app: app, | |
9719 | $el: $el, | |
9720 | el: $el[0], | |
9721 | name: view.params.name, | |
9722 | main: view.params.main || $el.hasClass('view-main'), | |
9723 | $navbarEl: $navbarEl, | |
9724 | navbarEl: $navbarEl ? $navbarEl[0] : undefined, | |
9725 | selector: selector, | |
9726 | history: [], | |
9727 | scrollHistory: {}, | |
9728 | }); | |
9729 | ||
9730 | // Save in DOM | |
9731 | $el[0].f7View = view; | |
9732 | ||
9733 | // Install Modules | |
9734 | view.useModules(); | |
9735 | ||
9736 | // Add to app | |
9737 | app.views.push(view); | |
9738 | if (view.main) { | |
9739 | app.views.main = view; | |
9740 | } | |
9741 | if (view.name) { | |
9742 | app.views[view.name] = view; | |
9743 | } | |
9744 | ||
9745 | // Index | |
9746 | view.index = app.views.indexOf(view); | |
9747 | ||
9748 | // View ID | |
9749 | var viewId; | |
9750 | if (view.name) { | |
9751 | viewId = "view_" + (view.name); | |
9752 | } else if (view.main) { | |
9753 | viewId = 'view_main'; | |
9754 | } else { | |
9755 | viewId = "view_" + (view.index); | |
9756 | } | |
9757 | view.id = viewId; | |
9758 | ||
9759 | // Init View | |
9760 | if (app.initialized) { | |
9761 | view.init(); | |
9762 | } else { | |
9763 | app.on('init', function () { | |
9764 | view.init(); | |
9765 | }); | |
9766 | } | |
9767 | ||
9768 | return view; | |
9769 | } | |
9770 | ||
5d51ea26 DC |
9771 | if ( Framework7Class ) View.__proto__ = Framework7Class; |
9772 | View.prototype = Object.create( Framework7Class && Framework7Class.prototype ); | |
5309fbda DC |
9773 | View.prototype.constructor = View; |
9774 | ||
9775 | View.prototype.destroy = function destroy () { | |
9776 | var view = this; | |
9777 | var app = view.app; | |
9778 | ||
9779 | view.$el.trigger('view:beforedestroy', view); | |
9780 | view.emit('local::beforeDestroy viewBeforeDestroy', view); | |
9781 | ||
9782 | app.off('resize', view.checkmasterDetailBreakpoint); | |
9783 | ||
9784 | if (view.main) { | |
9785 | app.views.main = null; | |
9786 | delete app.views.main; | |
9787 | } else if (view.name) { | |
9788 | app.views[view.name] = null; | |
9789 | delete app.views[view.name]; | |
9790 | } | |
9791 | view.$el[0].f7View = null; | |
9792 | delete view.$el[0].f7View; | |
9793 | ||
9794 | app.views.splice(app.views.indexOf(view), 1); | |
9795 | ||
9796 | // Destroy Router | |
9797 | if (view.params.router && view.router) { | |
9798 | view.router.destroy(); | |
9799 | } | |
9800 | ||
9801 | view.emit('local::destroy viewDestroy', view); | |
9802 | ||
9803 | // Delete props & methods | |
9804 | Object.keys(view).forEach(function (viewProp) { | |
9805 | view[viewProp] = null; | |
9806 | delete view[viewProp]; | |
9807 | }); | |
9808 | ||
9809 | view = null; | |
9810 | }; | |
9811 | ||
9812 | View.prototype.checkmasterDetailBreakpoint = function checkmasterDetailBreakpoint () { | |
9813 | var view = this; | |
9814 | var app = view.app; | |
9815 | var wasMasterDetail = view.$el.hasClass('view-master-detail'); | |
9816 | if (app.width >= view.params.masterDetailBreakpoint) { | |
9817 | view.$el.addClass('view-master-detail'); | |
9818 | if (!wasMasterDetail) { | |
9819 | view.emit('local::masterDetailBreakpoint viewMasterDetailBreakpoint'); | |
9820 | view.$el.trigger('view:masterDetailBreakpoint', view); | |
9821 | } | |
9822 | } else { | |
9823 | view.$el.removeClass('view-master-detail'); | |
9824 | if (wasMasterDetail) { | |
9825 | view.emit('local::masterDetailBreakpoint viewMasterDetailBreakpoint'); | |
9826 | view.$el.trigger('view:masterDetailBreakpoint', view); | |
9827 | } | |
9828 | } | |
9829 | }; | |
9830 | ||
9831 | View.prototype.initMasterDetail = function initMasterDetail () { | |
9832 | var view = this; | |
9833 | var app = view.app; | |
9834 | view.checkmasterDetailBreakpoint = view.checkmasterDetailBreakpoint.bind(view); | |
9835 | view.checkmasterDetailBreakpoint(); | |
9836 | app.on('resize', view.checkmasterDetailBreakpoint); | |
9837 | }; | |
9838 | ||
9839 | View.prototype.init = function init () { | |
9840 | var view = this; | |
9841 | if (view.params.router) { | |
9842 | if (view.params.masterDetailBreakpoint > 0) { | |
9843 | view.initMasterDetail(); | |
9844 | } | |
9845 | view.router.init(); | |
9846 | view.$el.trigger('view:init', view); | |
9847 | view.emit('local::init viewInit', view); | |
9848 | } | |
9849 | }; | |
9850 | ||
9851 | return View; | |
9852 | }(Framework7Class)); | |
9853 | ||
9854 | // Use Router | |
5d51ea26 | 9855 | View.use(RouterModule); |
5309fbda DC |
9856 | |
9857 | function initClicks(app) { | |
9858 | function handleClicks(e) { | |
9859 | var $clickedEl = $(e.target); | |
9860 | var $clickedLinkEl = $clickedEl.closest('a'); | |
9861 | var isLink = $clickedLinkEl.length > 0; | |
9862 | var url = isLink && $clickedLinkEl.attr('href'); | |
5d51ea26 | 9863 | // const isTabLink = isLink && $clickedLinkEl.hasClass('tab-link') && ($clickedLinkEl.attr('data-tab') || (url && url.indexOf('#') === 0)); |
5309fbda DC |
9864 | |
9865 | // Check if link is external | |
9866 | if (isLink) { | |
9867 | // eslint-disable-next-line | |
9868 | if ($clickedLinkEl.is(app.params.clicks.externalLinks) || (url && url.indexOf('javascript:') >= 0)) { | |
9869 | var target = $clickedLinkEl.attr('target'); | |
9870 | if ( | |
9871 | url | |
9872 | && win.cordova | |
9873 | && win.cordova.InAppBrowser | |
9874 | && (target === '_system' || target === '_blank') | |
9875 | ) { | |
9876 | e.preventDefault(); | |
9877 | win.cordova.InAppBrowser.open(url, target); | |
9878 | } | |
9879 | return; | |
9880 | } | |
9881 | } | |
9882 | ||
9883 | // Modules Clicks | |
9884 | Object.keys(app.modules).forEach(function (moduleName) { | |
9885 | var moduleClicks = app.modules[moduleName].clicks; | |
9886 | if (!moduleClicks) { return; } | |
5d51ea26 | 9887 | if (e.preventF7Router) { return; } |
5309fbda DC |
9888 | Object.keys(moduleClicks).forEach(function (clickSelector) { |
9889 | var matchingClickedElement = $clickedEl.closest(clickSelector).eq(0); | |
9890 | if (matchingClickedElement.length > 0) { | |
9891 | moduleClicks[clickSelector].call(app, matchingClickedElement, matchingClickedElement.dataset(), e); | |
9892 | } | |
9893 | }); | |
9894 | }); | |
9895 | ||
5309fbda DC |
9896 | // Load Page |
9897 | var clickedLinkData = {}; | |
9898 | if (isLink) { | |
9899 | e.preventDefault(); | |
9900 | clickedLinkData = $clickedLinkEl.dataset(); | |
9901 | } | |
9902 | ||
9903 | // Prevent Router | |
5d51ea26 | 9904 | if (e.preventF7Router) { return; } |
5309fbda DC |
9905 | if ($clickedLinkEl.hasClass('prevent-router') || $clickedLinkEl.hasClass('router-prevent')) { return; } |
9906 | ||
5d51ea26 | 9907 | var validUrl = url && url.length > 0 && url[0] !== '#'; |
5309fbda DC |
9908 | if (validUrl || $clickedLinkEl.hasClass('back')) { |
9909 | var view; | |
9910 | if (clickedLinkData.view) { | |
9911 | view = $(clickedLinkData.view)[0].f7View; | |
9912 | } else { | |
9913 | view = $clickedEl.parents('.view')[0] && $clickedEl.parents('.view')[0].f7View; | |
9914 | if (!$clickedLinkEl.hasClass('back') && view && view.params.linksView) { | |
9915 | if (typeof view.params.linksView === 'string') { view = $(view.params.linksView)[0].f7View; } | |
9916 | else if (view.params.linksView instanceof View) { view = view.params.linksView; } | |
9917 | } | |
9918 | } | |
9919 | if (!view) { | |
9920 | if (app.views.main) { view = app.views.main; } | |
9921 | } | |
9922 | if (!view || !view.router) { return; } | |
9923 | if (clickedLinkData.context && typeof clickedLinkData.context === 'string') { | |
9924 | try { | |
9925 | clickedLinkData.context = JSON.parse(clickedLinkData.context); | |
9926 | } catch (err) { | |
9927 | // something wrong there | |
9928 | } | |
9929 | } | |
9930 | if ($clickedLinkEl[0].f7RouteProps) { | |
9931 | clickedLinkData.props = $clickedLinkEl[0].f7RouteProps; | |
9932 | } | |
9933 | if ($clickedLinkEl.hasClass('back')) { view.router.back(url, clickedLinkData); } | |
9934 | else { view.router.navigate(url, clickedLinkData); } | |
9935 | } | |
9936 | } | |
9937 | ||
9938 | app.on('click', handleClicks); | |
9939 | ||
9940 | // TODO: check if need this in iOS | |
9941 | // Prevent scrolling on overlays | |
9942 | // function preventScrolling(e) { | |
9943 | // e.preventDefault(); | |
9944 | // } | |
9945 | // if (Support.touch && !Device.android) { | |
9946 | // const activeListener = Support.passiveListener ? { passive: false, capture: false } : false; | |
9947 | // $(document).on((app.params.touch.fastClicks ? 'touchstart' : 'touchmove'), '.panel-backdrop, .dialog-backdrop, .preloader-backdrop, .popup-backdrop, .searchbar-backdrop', preventScrolling, activeListener); | |
9948 | // } | |
9949 | } | |
9950 | var ClicksModule = { | |
9951 | name: 'clicks', | |
9952 | params: { | |
9953 | clicks: { | |
9954 | // External Links | |
9955 | externalLinks: '.external', | |
9956 | }, | |
9957 | }, | |
9958 | on: { | |
9959 | init: function init() { | |
9960 | var app = this; | |
9961 | initClicks(app); | |
9962 | }, | |
9963 | }, | |
9964 | }; | |
9965 | ||
9966 | var RouterTemplateLoaderModule = { | |
9967 | name: 'routerTemplateLoader', | |
9968 | proto: { | |
9969 | templateLoader: function templateLoader(template, templateUrl, options, resolve, reject) { | |
9970 | var router = this; | |
9971 | function compile(t) { | |
9972 | var compiledHtml; | |
9973 | var context; | |
9974 | try { | |
9975 | context = options.context || {}; | |
9976 | if (typeof context === 'function') { context = context.call(router); } | |
9977 | else if (typeof context === 'string') { | |
9978 | try { | |
9979 | context = JSON.parse(context); | |
9980 | } catch (err) { | |
9981 | reject(); | |
9982 | throw (err); | |
9983 | } | |
9984 | } | |
9985 | if (typeof t === 'function') { | |
9986 | compiledHtml = t(context); | |
9987 | } else { | |
9988 | compiledHtml = Template7.compile(t)(Utils.extend({}, context || {}, { | |
9989 | $app: router.app, | |
9990 | $root: Utils.extend({}, router.app.data, router.app.methods), | |
9991 | $route: options.route, | |
9992 | $f7route: options.route, | |
9993 | $router: router, | |
9994 | $f7router: router, | |
9995 | $theme: { | |
9996 | ios: router.app.theme === 'ios', | |
9997 | md: router.app.theme === 'md', | |
5d51ea26 | 9998 | aurora: router.app.theme === 'aurora', |
5309fbda DC |
9999 | }, |
10000 | })); | |
10001 | } | |
10002 | } catch (err) { | |
10003 | reject(); | |
10004 | throw (err); | |
10005 | } | |
10006 | resolve(compiledHtml, { context: context }); | |
10007 | } | |
10008 | if (templateUrl) { | |
10009 | // Load via XHR | |
10010 | if (router.xhr) { | |
10011 | router.xhr.abort(); | |
10012 | router.xhr = false; | |
10013 | } | |
10014 | router | |
10015 | .xhrRequest(templateUrl, options) | |
10016 | .then(function (templateContent) { | |
10017 | compile(templateContent); | |
10018 | }) | |
10019 | .catch(function () { | |
10020 | reject(); | |
10021 | }); | |
10022 | } else { | |
10023 | compile(template); | |
10024 | } | |
10025 | }, | |
10026 | ||
10027 | modalTemplateLoader: function modalTemplateLoader(template, templateUrl, options, resolve, reject) { | |
10028 | var router = this; | |
10029 | return router.templateLoader(template, templateUrl, options, function (html) { | |
10030 | resolve(html); | |
10031 | }, reject); | |
10032 | }, | |
10033 | ||
10034 | tabTemplateLoader: function tabTemplateLoader(template, templateUrl, options, resolve, reject) { | |
10035 | var router = this; | |
10036 | return router.templateLoader(template, templateUrl, options, function (html) { | |
10037 | resolve(html); | |
10038 | }, reject); | |
10039 | }, | |
10040 | ||
10041 | pageTemplateLoader: function pageTemplateLoader(template, templateUrl, options, resolve, reject) { | |
10042 | var router = this; | |
10043 | return router.templateLoader(template, templateUrl, options, function (html, newOptions) { | |
10044 | if ( newOptions === void 0 ) newOptions = {}; | |
10045 | ||
10046 | resolve(router.getPageEl(html), newOptions); | |
10047 | }, reject); | |
10048 | }, | |
10049 | }, | |
10050 | }; | |
10051 | ||
10052 | var RouterComponentLoaderModule = { | |
10053 | name: 'routerComponentLoader', | |
10054 | proto: { | |
10055 | componentLoader: function componentLoader(component, componentUrl, options, resolve, reject) { | |
10056 | if ( options === void 0 ) options = {}; | |
10057 | ||
10058 | var router = this; | |
10059 | var app = router.app; | |
10060 | var url = typeof component === 'string' ? component : componentUrl; | |
10061 | var compiledUrl = router.replaceRequestUrlParams(url, options); | |
10062 | function compile(componentOptions) { | |
10063 | var context = options.context || {}; | |
10064 | if (typeof context === 'function') { context = context.call(router); } | |
10065 | else if (typeof context === 'string') { | |
10066 | try { | |
10067 | context = JSON.parse(context); | |
10068 | } catch (err) { | |
10069 | reject(); | |
10070 | throw (err); | |
10071 | } | |
10072 | } | |
10073 | var extendContext = Utils.merge( | |
10074 | {}, | |
10075 | context, | |
10076 | { | |
10077 | $route: options.route, | |
10078 | $f7route: options.route, | |
10079 | $router: router, | |
10080 | $f7router: router, | |
10081 | $theme: { | |
10082 | ios: app.theme === 'ios', | |
10083 | md: app.theme === 'md', | |
5d51ea26 | 10084 | aurora: app.theme === 'aurora', |
5309fbda DC |
10085 | }, |
10086 | } | |
10087 | ); | |
10088 | var createdComponent = app.component.create(componentOptions, extendContext); | |
10089 | resolve(createdComponent.el); | |
10090 | } | |
10091 | var cachedComponent; | |
10092 | if (compiledUrl) { | |
10093 | router.cache.components.forEach(function (cached) { | |
10094 | if (cached.url === compiledUrl) { cachedComponent = cached.component; } | |
10095 | }); | |
10096 | } | |
10097 | if (compiledUrl && cachedComponent) { | |
10098 | compile(cachedComponent); | |
10099 | } else if (compiledUrl && !cachedComponent) { | |
10100 | // Load via XHR | |
10101 | if (router.xhr) { | |
10102 | router.xhr.abort(); | |
10103 | router.xhr = false; | |
10104 | } | |
10105 | router | |
10106 | .xhrRequest(url, options) | |
10107 | .then(function (loadedComponent) { | |
10108 | var parsedComponent = app.component.parse(loadedComponent); | |
10109 | router.cache.components.push({ | |
10110 | url: compiledUrl, | |
10111 | component: parsedComponent, | |
10112 | }); | |
10113 | compile(parsedComponent); | |
10114 | }) | |
10115 | .catch(function (err) { | |
10116 | reject(); | |
10117 | throw (err); | |
10118 | }); | |
10119 | } else { | |
10120 | compile(component); | |
10121 | } | |
10122 | }, | |
10123 | ||
10124 | modalComponentLoader: function modalComponentLoader(rootEl, component, componentUrl, options, resolve, reject) { | |
10125 | var router = this; | |
10126 | router.componentLoader(component, componentUrl, options, function (el) { | |
10127 | resolve(el); | |
10128 | }, reject); | |
10129 | }, | |
10130 | ||
10131 | tabComponentLoader: function tabComponentLoader(tabEl, component, componentUrl, options, resolve, reject) { | |
10132 | var router = this; | |
10133 | router.componentLoader(component, componentUrl, options, function (el) { | |
10134 | resolve(el); | |
10135 | }, reject); | |
10136 | }, | |
10137 | ||
10138 | pageComponentLoader: function pageComponentLoader(routerEl, component, componentUrl, options, resolve, reject) { | |
10139 | var router = this; | |
10140 | router.componentLoader(component, componentUrl, options, function (el, newOptions) { | |
10141 | if ( newOptions === void 0 ) newOptions = {}; | |
10142 | ||
10143 | resolve(el, newOptions); | |
10144 | }, reject); | |
10145 | }, | |
10146 | }, | |
10147 | }; | |
10148 | ||
10149 | var HistoryModule = { | |
10150 | name: 'history', | |
10151 | static: { | |
10152 | history: History, | |
10153 | }, | |
10154 | on: { | |
10155 | init: function init() { | |
10156 | History.init(this); | |
10157 | }, | |
10158 | }, | |
10159 | }; | |
10160 | ||
10161 | var keyPrefix = 'f7storage-'; | |
10162 | var Storage = { | |
10163 | get: function get(key) { | |
10164 | return new Promise(function (resolve, reject) { | |
10165 | try { | |
10166 | var value = JSON.parse(win.localStorage.getItem(("" + keyPrefix + key))); | |
10167 | resolve(value); | |
10168 | } catch (e) { | |
10169 | reject(e); | |
10170 | } | |
10171 | }); | |
10172 | }, | |
10173 | set: function set(key, value) { | |
10174 | return new Promise(function (resolve, reject) { | |
10175 | try { | |
10176 | win.localStorage.setItem(("" + keyPrefix + key), JSON.stringify(value)); | |
10177 | resolve(); | |
10178 | } catch (e) { | |
10179 | reject(e); | |
10180 | } | |
10181 | }); | |
10182 | }, | |
10183 | remove: function remove(key) { | |
10184 | return new Promise(function (resolve, reject) { | |
10185 | try { | |
10186 | win.localStorage.removeItem(("" + keyPrefix + key)); | |
10187 | resolve(); | |
10188 | } catch (e) { | |
10189 | reject(e); | |
10190 | } | |
10191 | }); | |
10192 | }, | |
10193 | clear: function clear() { | |
10194 | ||
10195 | }, | |
10196 | length: function length() { | |
10197 | ||
10198 | }, | |
10199 | keys: function keys() { | |
10200 | return new Promise(function (resolve, reject) { | |
10201 | try { | |
10202 | var keys = Object.keys(win.localStorage) | |
10203 | .filter(function (keyName) { return keyName.indexOf(keyPrefix) === 0; }) | |
10204 | .map(function (keyName) { return keyName.replace(keyPrefix, ''); }); | |
10205 | resolve(keys); | |
10206 | } catch (e) { | |
10207 | reject(e); | |
10208 | } | |
10209 | }); | |
10210 | }, | |
10211 | forEach: function forEach(callback) { | |
10212 | return new Promise(function (resolve, reject) { | |
10213 | try { | |
10214 | Object.keys(win.localStorage) | |
10215 | .filter(function (keyName) { return keyName.indexOf(keyPrefix) === 0; }) | |
10216 | .forEach(function (keyName, index) { | |
10217 | var key = keyName.replace(keyPrefix, ''); | |
10218 | Storage.get(key).then(function (value) { | |
10219 | callback(key, value, index); | |
10220 | }); | |
10221 | }); | |
10222 | resolve(); | |
10223 | } catch (e) { | |
10224 | reject(e); | |
10225 | } | |
10226 | }); | |
10227 | }, | |
10228 | }; | |
10229 | ||
10230 | var StorageModule = { | |
10231 | name: 'storage', | |
10232 | static: { | |
10233 | Storage: Storage, | |
10234 | storage: Storage, | |
10235 | }, | |
10236 | }; | |
10237 | ||
10238 | function vnode(sel, data, children, text, elm) { | |
10239 | var key = data === undefined ? undefined : data.key; | |
10240 | return { sel: sel, data: data, children: children, | |
10241 | text: text, elm: elm, key: key }; | |
10242 | } | |
10243 | ||
10244 | var array = Array.isArray; | |
10245 | function primitive(s) { | |
10246 | return typeof s === 'string' || typeof s === 'number'; | |
10247 | } | |
10248 | ||
10249 | function addNS(data, children, sel) { | |
10250 | data.ns = 'http://www.w3.org/2000/svg'; | |
10251 | if (sel !== 'foreignObject' && children !== undefined) { | |
10252 | for (var i = 0; i < children.length; ++i) { | |
10253 | var childData = children[i].data; | |
10254 | if (childData !== undefined) { | |
10255 | addNS(childData, children[i].children, children[i].sel); | |
10256 | } | |
10257 | } | |
10258 | } | |
10259 | } | |
10260 | function h(sel, b, c) { | |
10261 | var data = {}, children, text, i; | |
10262 | if (c !== undefined) { | |
10263 | data = b; | |
10264 | if (array(c)) { | |
10265 | children = c; | |
10266 | } | |
10267 | else if (primitive(c)) { | |
10268 | text = c; | |
10269 | } | |
10270 | else if (c && c.sel) { | |
10271 | children = [c]; | |
10272 | } | |
10273 | } | |
10274 | else if (b !== undefined) { | |
10275 | if (array(b)) { | |
10276 | children = b; | |
10277 | } | |
10278 | else if (primitive(b)) { | |
10279 | text = b; | |
10280 | } | |
10281 | else if (b && b.sel) { | |
10282 | children = [b]; | |
10283 | } | |
10284 | else { | |
10285 | data = b; | |
10286 | } | |
10287 | } | |
10288 | if (array(children)) { | |
10289 | for (i = 0; i < children.length; ++i) { | |
10290 | if (primitive(children[i])) | |
10291 | { children[i] = vnode(undefined, undefined, undefined, children[i], undefined); } | |
10292 | } | |
10293 | } | |
10294 | if (sel[0] === 's' && sel[1] === 'v' && sel[2] === 'g' && | |
10295 | (sel.length === 3 || sel[3] === '.' || sel[3] === '#')) { | |
10296 | addNS(data, children, sel); | |
10297 | } | |
10298 | return vnode(sel, data, children, text, undefined); | |
10299 | } | |
10300 | ||
10301 | /* eslint no-use-before-define: "off" */ | |
10302 | ||
10303 | var selfClosing = 'area base br col command embed hr img input keygen link menuitem meta param source track wbr'.split(' '); | |
5d51ea26 DC |
10304 | var propsAttrs = 'hidden checked disabled readonly selected autocomplete autofocus autoplay required multiple value indeterminate'.split(' '); |
10305 | var booleanProps = 'hidden checked disabled readonly selected autocomplete autofocus autoplay required multiple readOnly indeterminate'.split(' '); | |
5309fbda DC |
10306 | var tempDom = doc.createElement('div'); |
10307 | ||
10308 | function getHooks(data, app, initial, isRoot) { | |
10309 | var hooks = {}; | |
10310 | if (!data || !data.attrs || !data.attrs.class) { return hooks; } | |
10311 | var classNames = data.attrs.class; | |
10312 | var insert = []; | |
10313 | var destroy = []; | |
10314 | var update = []; | |
10315 | var postpatch = []; | |
10316 | classNames.split(' ').forEach(function (className) { | |
10317 | if (!initial) { | |
10318 | insert.push.apply(insert, app.getVnodeHooks('insert', className)); | |
10319 | } | |
10320 | destroy.push.apply(destroy, app.getVnodeHooks('destroy', className)); | |
10321 | update.push.apply(update, app.getVnodeHooks('update', className)); | |
10322 | postpatch.push.apply(postpatch, app.getVnodeHooks('postpatch', className)); | |
10323 | }); | |
10324 | ||
10325 | if (isRoot && !initial) { | |
10326 | postpatch.push(function (oldVnode, vnode) { | |
10327 | var vn = vnode || oldVnode; | |
10328 | if (!vn) { return; } | |
10329 | if (vn.data && vn.data.context && vn.data.context.$options.updated) { | |
10330 | vn.data.context.$options.updated(); | |
10331 | } | |
10332 | }); | |
10333 | } | |
10334 | if (insert.length === 0 && destroy.length === 0 && update.length === 0 && postpatch.length === 0) { | |
10335 | return hooks; | |
10336 | } | |
10337 | if (insert.length) { | |
10338 | hooks.insert = function (vnode) { | |
10339 | insert.forEach(function (f) { return f(vnode); }); | |
10340 | }; | |
10341 | } | |
10342 | if (destroy.length) { | |
10343 | hooks.destroy = function (vnode) { | |
10344 | destroy.forEach(function (f) { return f(vnode); }); | |
10345 | }; | |
10346 | } | |
10347 | if (update.length) { | |
10348 | hooks.update = function (oldVnode, vnode) { | |
10349 | update.forEach(function (f) { return f(oldVnode, vnode); }); | |
10350 | }; | |
10351 | } | |
10352 | if (postpatch.length) { | |
10353 | hooks.postpatch = function (oldVnode, vnode) { | |
10354 | postpatch.forEach(function (f) { return f(oldVnode, vnode); }); | |
10355 | }; | |
10356 | } | |
10357 | ||
10358 | return hooks; | |
10359 | } | |
10360 | function getEventHandler(handlerString, context, ref) { | |
10361 | if ( ref === void 0 ) ref = {}; | |
10362 | var stop = ref.stop; | |
10363 | var prevent = ref.prevent; | |
10364 | var once = ref.once; | |
10365 | ||
10366 | var fired = false; | |
5309fbda DC |
10367 | var methodName; |
10368 | var method; | |
10369 | var customArgs = []; | |
10370 | var needMethodBind = true; | |
10371 | ||
10372 | if (handlerString.indexOf('(') < 0) { | |
10373 | methodName = handlerString; | |
10374 | } else { | |
10375 | methodName = handlerString.split('(')[0]; | |
10376 | } | |
10377 | if (methodName.indexOf('.') >= 0) { | |
10378 | methodName.split('.').forEach(function (path, pathIndex) { | |
10379 | if (pathIndex === 0 && path === 'this') { return; } | |
10380 | if (pathIndex === 0 && path === 'window') { | |
10381 | // eslint-disable-next-line | |
10382 | method = win; | |
10383 | needMethodBind = false; | |
10384 | return; | |
10385 | } | |
10386 | if (!method) { method = context; } | |
10387 | if (method[path]) { method = method[path]; } | |
10388 | else { | |
10389 | throw new Error(("Framework7: Component doesn't have method \"" + (methodName.split('.').slice(0, pathIndex + 1).join('.')) + "\"")); | |
10390 | } | |
10391 | }); | |
10392 | } else { | |
10393 | if (!context[methodName]) { | |
10394 | throw new Error(("Framework7: Component doesn't have method \"" + methodName + "\"")); | |
10395 | } | |
10396 | method = context[methodName]; | |
10397 | } | |
10398 | if (needMethodBind) { | |
10399 | method = method.bind(context); | |
10400 | } | |
10401 | ||
10402 | function handler() { | |
10403 | var args = [], len = arguments.length; | |
10404 | while ( len-- ) args[ len ] = arguments[ len ]; | |
10405 | ||
10406 | var e = args[0]; | |
10407 | if (once && fired) { return; } | |
10408 | if (stop) { e.stopPropagation(); } | |
10409 | if (prevent) { e.preventDefault(); } | |
10410 | fired = true; | |
10411 | ||
10412 | if (handlerString.indexOf('(') < 0) { | |
10413 | customArgs = args; | |
10414 | } else { | |
5d51ea26 DC |
10415 | var handlerArguments = handlerString |
10416 | .split('(')[1] | |
10417 | .split(')')[0] | |
10418 | .replace(/'[^']*'|"[^"]*"/g, function (a) { return a.replace(/,/g, '<_comma_>'); }) | |
10419 | .split(',') | |
10420 | .map(function (a) { return a.replace(/<_comma_>/g, ','); }); | |
10421 | handlerArguments.forEach(function (argument) { | |
5309fbda DC |
10422 | var arg = argument.trim(); |
10423 | // eslint-disable-next-line | |
10424 | if (!isNaN(arg)) { arg = parseFloat(arg); } | |
10425 | else if (arg === 'true') { arg = true; } | |
10426 | else if (arg === 'false') { arg = false; } | |
10427 | else if (arg === 'null') { arg = null; } | |
10428 | else if (arg === 'undefined') { arg = undefined; } | |
10429 | else if (arg[0] === '"') { arg = arg.replace(/"/g, ''); } | |
10430 | else if (arg[0] === '\'') { arg = arg.replace(/'/g, ''); } | |
10431 | else if (arg.indexOf('.') > 0) { | |
10432 | var deepArg; | |
10433 | arg.split('.').forEach(function (path) { | |
10434 | if (!deepArg) { deepArg = context; } | |
10435 | deepArg = deepArg[path]; | |
10436 | }); | |
10437 | arg = deepArg; | |
10438 | } else { | |
10439 | arg = context[arg]; | |
10440 | } | |
10441 | customArgs.push(arg); | |
10442 | }); | |
10443 | } | |
10444 | ||
10445 | method.apply(void 0, customArgs); | |
10446 | } | |
10447 | ||
10448 | return handler; | |
10449 | } | |
10450 | ||
10451 | function getData(el, context, app, initial, isRoot) { | |
10452 | var data = { | |
10453 | context: context, | |
10454 | }; | |
10455 | var attributes = el.attributes; | |
10456 | Array.prototype.forEach.call(attributes, function (attr) { | |
10457 | var attrName = attr.name; | |
10458 | var attrValue = attr.value; | |
10459 | if (propsAttrs.indexOf(attrName) >= 0) { | |
10460 | // Props | |
10461 | if (!data.props) { data.props = {}; } | |
10462 | if (attrName === 'readonly') { | |
10463 | attrName = 'readOnly'; | |
10464 | } | |
10465 | if (booleanProps.indexOf(attrName) >= 0) { | |
10466 | // eslint-disable-next-line | |
10467 | data.props[attrName] = attrValue === false ? false : true; | |
10468 | } else { | |
10469 | data.props[attrName] = attrValue; | |
10470 | } | |
10471 | } else if (attrName === 'key') { | |
10472 | // Key | |
10473 | data.key = attrValue; | |
10474 | } else if (attrName.indexOf('@') === 0) { | |
10475 | // Events | |
10476 | if (!data.on) { data.on = {}; } | |
10477 | var eventName = attrName.substr(1); | |
10478 | var stop = false; | |
10479 | var prevent = false; | |
10480 | var once = false; | |
10481 | if (eventName.indexOf('.') >= 0) { | |
10482 | eventName.split('.').forEach(function (eventNamePart, eventNameIndex) { | |
10483 | if (eventNameIndex === 0) { eventName = eventNamePart; } | |
10484 | else { | |
10485 | if (eventNamePart === 'stop') { stop = true; } | |
10486 | if (eventNamePart === 'prevent') { prevent = true; } | |
10487 | if (eventNamePart === 'once') { once = true; } | |
10488 | } | |
10489 | }); | |
10490 | } | |
10491 | data.on[eventName] = getEventHandler(attrValue, context, { stop: stop, prevent: prevent, once: once }); | |
10492 | } else if (attrName === 'style') { | |
10493 | // Style | |
10494 | if (attrValue.indexOf('{') >= 0 && attrValue.indexOf('}') >= 0) { | |
10495 | try { | |
10496 | data.style = JSON.parse(attrValue); | |
10497 | } catch (e) { | |
10498 | if (!data.attrs) { data.attrs = {}; } | |
10499 | data.attrs.style = attrValue; | |
10500 | } | |
10501 | } else { | |
10502 | if (!data.attrs) { data.attrs = {}; } | |
10503 | data.attrs.style = attrValue; | |
10504 | } | |
10505 | } else { | |
10506 | // Rest of attribures | |
10507 | if (!data.attrs) { data.attrs = {}; } | |
10508 | data.attrs[attrName] = attrValue; | |
10509 | ||
10510 | // ID -> Key | |
10511 | if (attrName === 'id' && !data.key && !isRoot) { | |
10512 | data.key = attrValue; | |
10513 | } | |
10514 | } | |
10515 | }); | |
10516 | var hooks = getHooks(data, app, initial, isRoot); | |
10517 | hooks.prepatch = function (oldVnode, vnode) { | |
10518 | if (!oldVnode || !vnode) { return; } | |
10519 | if (oldVnode && oldVnode.data && oldVnode.data.props) { | |
10520 | Object.keys(oldVnode.data.props).forEach(function (key) { | |
10521 | if (booleanProps.indexOf(key) < 0) { return; } | |
10522 | if (!vnode.data) { vnode.data = {}; } | |
10523 | if (!vnode.data.props) { vnode.data.props = {}; } | |
10524 | if (oldVnode.data.props[key] === true && !(key in vnode.data.props)) { | |
10525 | vnode.data.props[key] = false; | |
10526 | } | |
10527 | }); | |
10528 | } | |
10529 | }; | |
10530 | if (hooks) { | |
10531 | data.hook = hooks; | |
10532 | } | |
10533 | return data; | |
10534 | } | |
10535 | ||
10536 | function getChildren(el, context, app, initial) { | |
10537 | var children = []; | |
10538 | var nodes = el.childNodes; | |
10539 | for (var i = 0; i < nodes.length; i += 1) { | |
10540 | var childNode = nodes[i]; | |
10541 | var child = elementToVNode(childNode, context, app, initial); | |
10542 | if (child) { | |
10543 | children.push(child); | |
10544 | } | |
10545 | } | |
10546 | return children; | |
10547 | } | |
10548 | ||
10549 | function elementToVNode(el, context, app, initial, isRoot) { | |
10550 | if (el.nodeType === 1) { | |
5d51ea26 DC |
10551 | // element (statement adds inline SVG compatibility) |
10552 | var tagName = (el instanceof win.SVGElement) ? el.nodeName : el.nodeName.toLowerCase(); | |
5309fbda DC |
10553 | return h( |
10554 | tagName, | |
10555 | getData(el, context, app, initial, isRoot), | |
10556 | selfClosing.indexOf(tagName) >= 0 ? [] : getChildren(el, context, app, initial) | |
10557 | ); | |
10558 | } | |
10559 | if (el.nodeType === 3) { | |
10560 | // text | |
10561 | return el.textContent; | |
10562 | } | |
10563 | return null; | |
10564 | } | |
10565 | ||
10566 | function vdom (html, context, app, initial) { | |
10567 | if ( html === void 0 ) html = ''; | |
10568 | ||
10569 | // Save to temp dom | |
10570 | tempDom.innerHTML = html.trim(); | |
10571 | ||
10572 | // Parse DOM | |
10573 | var rootEl; | |
10574 | for (var i = 0; i < tempDom.childNodes.length; i += 1) { | |
10575 | if (!rootEl && tempDom.childNodes[i].nodeType === 1) { | |
10576 | rootEl = tempDom.childNodes[i]; | |
10577 | } | |
10578 | } | |
10579 | var result = elementToVNode(rootEl, context, app, initial, true); | |
10580 | ||
10581 | // Clean | |
10582 | tempDom.innerHTML = ''; | |
10583 | ||
10584 | return result; | |
10585 | } | |
10586 | ||
10587 | function createElement(tagName) { | |
10588 | return document.createElement(tagName); | |
10589 | } | |
10590 | function createElementNS(namespaceURI, qualifiedName) { | |
10591 | return document.createElementNS(namespaceURI, qualifiedName); | |
10592 | } | |
10593 | function createTextNode(text) { | |
10594 | return document.createTextNode(text); | |
10595 | } | |
10596 | function createComment(text) { | |
10597 | return document.createComment(text); | |
10598 | } | |
10599 | function insertBefore$1(parentNode, newNode, referenceNode) { | |
10600 | parentNode.insertBefore(newNode, referenceNode); | |
10601 | } | |
10602 | function removeChild(node, child) { | |
10603 | if (!node) { return; } | |
10604 | node.removeChild(child); | |
10605 | } | |
10606 | function appendChild(node, child) { | |
10607 | node.appendChild(child); | |
10608 | } | |
10609 | function parentNode(node) { | |
10610 | return node.parentNode; | |
10611 | } | |
10612 | function nextSibling(node) { | |
10613 | return node.nextSibling; | |
10614 | } | |
10615 | function tagName(elm) { | |
10616 | return elm.tagName; | |
10617 | } | |
10618 | function setTextContent(node, text) { | |
10619 | node.textContent = text; | |
10620 | } | |
10621 | function getTextContent(node) { | |
10622 | return node.textContent; | |
10623 | } | |
10624 | function isElement(node) { | |
10625 | return node.nodeType === 1; | |
10626 | } | |
10627 | function isText(node) { | |
10628 | return node.nodeType === 3; | |
10629 | } | |
10630 | function isComment(node) { | |
10631 | return node.nodeType === 8; | |
10632 | } | |
10633 | var htmlDomApi = { | |
10634 | createElement: createElement, | |
10635 | createElementNS: createElementNS, | |
10636 | createTextNode: createTextNode, | |
10637 | createComment: createComment, | |
10638 | insertBefore: insertBefore$1, | |
10639 | removeChild: removeChild, | |
10640 | appendChild: appendChild, | |
10641 | parentNode: parentNode, | |
10642 | nextSibling: nextSibling, | |
10643 | tagName: tagName, | |
10644 | setTextContent: setTextContent, | |
10645 | getTextContent: getTextContent, | |
10646 | isElement: isElement, | |
10647 | isText: isText, | |
10648 | isComment: isComment, | |
10649 | }; | |
10650 | ||
10651 | function isUndef(s) { return s === undefined; } | |
10652 | function isDef(s) { return s !== undefined; } | |
10653 | var emptyNode = vnode('', {}, [], undefined, undefined); | |
10654 | function sameVnode(vnode1, vnode2) { | |
10655 | return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel; | |
10656 | } | |
5d51ea26 DC |
10657 | function isVnode(vnode) { |
10658 | return vnode.sel !== undefined; | |
5309fbda DC |
10659 | } |
10660 | function createKeyToOldIdx(children, beginIdx, endIdx) { | |
10661 | var i, map = {}, key, ch; | |
10662 | for (i = beginIdx; i <= endIdx; ++i) { | |
10663 | ch = children[i]; | |
10664 | if (ch != null) { | |
10665 | key = ch.key; | |
10666 | if (key !== undefined) | |
10667 | { map[key] = i; } | |
10668 | } | |
10669 | } | |
10670 | return map; | |
10671 | } | |
10672 | var hooks = ['create', 'update', 'remove', 'destroy', 'pre', 'post']; | |
5d51ea26 | 10673 | function init(modules, domApi) { |
5309fbda DC |
10674 | var i, j, cbs = {}; |
10675 | var api = domApi !== undefined ? domApi : htmlDomApi; | |
10676 | for (i = 0; i < hooks.length; ++i) { | |
10677 | cbs[hooks[i]] = []; | |
10678 | for (j = 0; j < modules.length; ++j) { | |
10679 | var hook = modules[j][hooks[i]]; | |
10680 | if (hook !== undefined) { | |
10681 | cbs[hooks[i]].push(hook); | |
10682 | } | |
10683 | } | |
10684 | } | |
10685 | function emptyNodeAt(elm) { | |
10686 | var id = elm.id ? '#' + elm.id : ''; | |
10687 | var c = elm.className ? '.' + elm.className.split(' ').join('.') : ''; | |
10688 | return vnode(api.tagName(elm).toLowerCase() + id + c, {}, [], undefined, elm); | |
10689 | } | |
10690 | function createRmCb(childElm, listeners) { | |
10691 | return function rmCb() { | |
10692 | if (--listeners === 0) { | |
10693 | var parent_1 = api.parentNode(childElm); | |
10694 | api.removeChild(parent_1, childElm); | |
10695 | } | |
10696 | }; | |
10697 | } | |
5d51ea26 DC |
10698 | function createElm(vnode, insertedVnodeQueue) { |
10699 | var i, data = vnode.data; | |
5309fbda DC |
10700 | if (data !== undefined) { |
10701 | if (isDef(i = data.hook) && isDef(i = i.init)) { | |
5d51ea26 DC |
10702 | i(vnode); |
10703 | data = vnode.data; | |
5309fbda DC |
10704 | } |
10705 | } | |
5d51ea26 | 10706 | var children = vnode.children, sel = vnode.sel; |
5309fbda | 10707 | if (sel === '!') { |
5d51ea26 DC |
10708 | if (isUndef(vnode.text)) { |
10709 | vnode.text = ''; | |
5309fbda | 10710 | } |
5d51ea26 | 10711 | vnode.elm = api.createComment(vnode.text); |
5309fbda DC |
10712 | } |
10713 | else if (sel !== undefined) { | |
10714 | // Parse selector | |
10715 | var hashIdx = sel.indexOf('#'); | |
10716 | var dotIdx = sel.indexOf('.', hashIdx); | |
10717 | var hash = hashIdx > 0 ? hashIdx : sel.length; | |
10718 | var dot = dotIdx > 0 ? dotIdx : sel.length; | |
10719 | var tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel; | |
5d51ea26 | 10720 | var elm = vnode.elm = isDef(data) && isDef(i = data.ns) ? api.createElementNS(i, tag) |
5309fbda DC |
10721 | : api.createElement(tag); |
10722 | if (hash < dot) | |
10723 | { elm.setAttribute('id', sel.slice(hash + 1, dot)); } | |
10724 | if (dotIdx > 0) | |
10725 | { elm.setAttribute('class', sel.slice(dot + 1).replace(/\./g, ' ')); } | |
10726 | for (i = 0; i < cbs.create.length; ++i) | |
5d51ea26 | 10727 | { cbs.create[i](emptyNode, vnode); } |
5309fbda DC |
10728 | if (array(children)) { |
10729 | for (i = 0; i < children.length; ++i) { | |
10730 | var ch = children[i]; | |
10731 | if (ch != null) { | |
10732 | api.appendChild(elm, createElm(ch, insertedVnodeQueue)); | |
10733 | } | |
10734 | } | |
10735 | } | |
5d51ea26 DC |
10736 | else if (primitive(vnode.text)) { |
10737 | api.appendChild(elm, api.createTextNode(vnode.text)); | |
5309fbda | 10738 | } |
5d51ea26 | 10739 | i = vnode.data.hook; // Reuse variable |
5309fbda DC |
10740 | if (isDef(i)) { |
10741 | if (i.create) | |
5d51ea26 | 10742 | { i.create(emptyNode, vnode); } |
5309fbda | 10743 | if (i.insert) |
5d51ea26 | 10744 | { insertedVnodeQueue.push(vnode); } |
5309fbda DC |
10745 | } |
10746 | } | |
10747 | else { | |
5d51ea26 | 10748 | vnode.elm = api.createTextNode(vnode.text); |
5309fbda | 10749 | } |
5d51ea26 | 10750 | return vnode.elm; |
5309fbda DC |
10751 | } |
10752 | function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) { | |
10753 | for (; startIdx <= endIdx; ++startIdx) { | |
10754 | var ch = vnodes[startIdx]; | |
10755 | if (ch != null) { | |
10756 | api.insertBefore(parentElm, createElm(ch, insertedVnodeQueue), before); | |
10757 | } | |
10758 | } | |
10759 | } | |
5d51ea26 DC |
10760 | function invokeDestroyHook(vnode) { |
10761 | var i, j, data = vnode.data; | |
5309fbda DC |
10762 | if (data !== undefined) { |
10763 | if (isDef(i = data.hook) && isDef(i = i.destroy)) | |
5d51ea26 | 10764 | { i(vnode); } |
5309fbda | 10765 | for (i = 0; i < cbs.destroy.length; ++i) |
5d51ea26 DC |
10766 | { cbs.destroy[i](vnode); } |
10767 | if (vnode.children !== undefined) { | |
10768 | for (j = 0; j < vnode.children.length; ++j) { | |
10769 | i = vnode.children[j]; | |
5309fbda DC |
10770 | if (i != null && typeof i !== "string") { |
10771 | invokeDestroyHook(i); | |
10772 | } | |
10773 | } | |
10774 | } | |
10775 | } | |
10776 | } | |
10777 | function removeVnodes(parentElm, vnodes, startIdx, endIdx) { | |
10778 | for (; startIdx <= endIdx; ++startIdx) { | |
10779 | var i_1 = void 0, listeners = void 0, rm = void 0, ch = vnodes[startIdx]; | |
10780 | if (ch != null) { | |
10781 | if (isDef(ch.sel)) { | |
10782 | invokeDestroyHook(ch); | |
10783 | listeners = cbs.remove.length + 1; | |
10784 | rm = createRmCb(ch.elm, listeners); | |
10785 | for (i_1 = 0; i_1 < cbs.remove.length; ++i_1) | |
10786 | { cbs.remove[i_1](ch, rm); } | |
10787 | if (isDef(i_1 = ch.data) && isDef(i_1 = i_1.hook) && isDef(i_1 = i_1.remove)) { | |
10788 | i_1(ch, rm); | |
10789 | } | |
10790 | else { | |
10791 | rm(); | |
10792 | } | |
10793 | } | |
10794 | else { | |
10795 | api.removeChild(parentElm, ch.elm); | |
10796 | } | |
10797 | } | |
10798 | } | |
10799 | } | |
10800 | function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) { | |
10801 | var oldStartIdx = 0, newStartIdx = 0; | |
10802 | var oldEndIdx = oldCh.length - 1; | |
10803 | var oldStartVnode = oldCh[0]; | |
10804 | var oldEndVnode = oldCh[oldEndIdx]; | |
10805 | var newEndIdx = newCh.length - 1; | |
10806 | var newStartVnode = newCh[0]; | |
10807 | var newEndVnode = newCh[newEndIdx]; | |
10808 | var oldKeyToIdx; | |
10809 | var idxInOld; | |
10810 | var elmToMove; | |
10811 | var before; | |
10812 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) { | |
10813 | if (oldStartVnode == null) { | |
10814 | oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left | |
10815 | } | |
10816 | else if (oldEndVnode == null) { | |
10817 | oldEndVnode = oldCh[--oldEndIdx]; | |
10818 | } | |
10819 | else if (newStartVnode == null) { | |
10820 | newStartVnode = newCh[++newStartIdx]; | |
10821 | } | |
10822 | else if (newEndVnode == null) { | |
10823 | newEndVnode = newCh[--newEndIdx]; | |
10824 | } | |
10825 | else if (sameVnode(oldStartVnode, newStartVnode)) { | |
10826 | patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue); | |
10827 | oldStartVnode = oldCh[++oldStartIdx]; | |
10828 | newStartVnode = newCh[++newStartIdx]; | |
10829 | } | |
10830 | else if (sameVnode(oldEndVnode, newEndVnode)) { | |
10831 | patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue); | |
10832 | oldEndVnode = oldCh[--oldEndIdx]; | |
10833 | newEndVnode = newCh[--newEndIdx]; | |
10834 | } | |
10835 | else if (sameVnode(oldStartVnode, newEndVnode)) { | |
10836 | patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue); | |
10837 | api.insertBefore(parentElm, oldStartVnode.elm, api.nextSibling(oldEndVnode.elm)); | |
10838 | oldStartVnode = oldCh[++oldStartIdx]; | |
10839 | newEndVnode = newCh[--newEndIdx]; | |
10840 | } | |
10841 | else if (sameVnode(oldEndVnode, newStartVnode)) { | |
10842 | patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue); | |
10843 | api.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm); | |
10844 | oldEndVnode = oldCh[--oldEndIdx]; | |
10845 | newStartVnode = newCh[++newStartIdx]; | |
10846 | } | |
10847 | else { | |
10848 | if (oldKeyToIdx === undefined) { | |
10849 | oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); | |
10850 | } | |
10851 | idxInOld = oldKeyToIdx[newStartVnode.key]; | |
10852 | if (isUndef(idxInOld)) { | |
10853 | api.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm); | |
10854 | newStartVnode = newCh[++newStartIdx]; | |
10855 | } | |
10856 | else { | |
10857 | elmToMove = oldCh[idxInOld]; | |
10858 | if (elmToMove.sel !== newStartVnode.sel) { | |
10859 | api.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm); | |
10860 | } | |
10861 | else { | |
10862 | patchVnode(elmToMove, newStartVnode, insertedVnodeQueue); | |
10863 | oldCh[idxInOld] = undefined; | |
10864 | api.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm); | |
10865 | } | |
10866 | newStartVnode = newCh[++newStartIdx]; | |
10867 | } | |
10868 | } | |
10869 | } | |
10870 | if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) { | |
10871 | if (oldStartIdx > oldEndIdx) { | |
10872 | before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm; | |
10873 | addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue); | |
10874 | } | |
10875 | else { | |
10876 | removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); | |
10877 | } | |
10878 | } | |
10879 | } | |
5d51ea26 | 10880 | function patchVnode(oldVnode, vnode, insertedVnodeQueue) { |
5309fbda | 10881 | var i, hook; |
5d51ea26 DC |
10882 | if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) { |
10883 | i(oldVnode, vnode); | |
5309fbda | 10884 | } |
5d51ea26 | 10885 | var elm = vnode.elm = oldVnode.elm; |
5309fbda | 10886 | var oldCh = oldVnode.children; |
5d51ea26 DC |
10887 | var ch = vnode.children; |
10888 | if (oldVnode === vnode) | |
5309fbda | 10889 | { return; } |
5d51ea26 | 10890 | if (vnode.data !== undefined) { |
5309fbda | 10891 | for (i = 0; i < cbs.update.length; ++i) |
5d51ea26 DC |
10892 | { cbs.update[i](oldVnode, vnode); } |
10893 | i = vnode.data.hook; | |
5309fbda | 10894 | if (isDef(i) && isDef(i = i.update)) |
5d51ea26 | 10895 | { i(oldVnode, vnode); } |
5309fbda | 10896 | } |
5d51ea26 | 10897 | if (isUndef(vnode.text)) { |
5309fbda DC |
10898 | if (isDef(oldCh) && isDef(ch)) { |
10899 | if (oldCh !== ch) | |
10900 | { updateChildren(elm, oldCh, ch, insertedVnodeQueue); } | |
10901 | } | |
10902 | else if (isDef(ch)) { | |
10903 | if (isDef(oldVnode.text)) | |
10904 | { api.setTextContent(elm, ''); } | |
10905 | addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue); | |
10906 | } | |
10907 | else if (isDef(oldCh)) { | |
10908 | removeVnodes(elm, oldCh, 0, oldCh.length - 1); | |
10909 | } | |
10910 | else if (isDef(oldVnode.text)) { | |
10911 | api.setTextContent(elm, ''); | |
10912 | } | |
10913 | } | |
5d51ea26 DC |
10914 | else if (oldVnode.text !== vnode.text) { |
10915 | api.setTextContent(elm, vnode.text); | |
5309fbda DC |
10916 | } |
10917 | if (isDef(hook) && isDef(i = hook.postpatch)) { | |
5d51ea26 | 10918 | i(oldVnode, vnode); |
5309fbda DC |
10919 | } |
10920 | } | |
5d51ea26 | 10921 | return function patch(oldVnode, vnode) { |
5309fbda DC |
10922 | var i, elm, parent; |
10923 | var insertedVnodeQueue = []; | |
10924 | for (i = 0; i < cbs.pre.length; ++i) | |
10925 | { cbs.pre[i](); } | |
10926 | if (!isVnode(oldVnode)) { | |
10927 | oldVnode = emptyNodeAt(oldVnode); | |
10928 | } | |
5d51ea26 DC |
10929 | if (sameVnode(oldVnode, vnode)) { |
10930 | patchVnode(oldVnode, vnode, insertedVnodeQueue); | |
5309fbda DC |
10931 | } |
10932 | else { | |
10933 | elm = oldVnode.elm; | |
10934 | parent = api.parentNode(elm); | |
5d51ea26 | 10935 | createElm(vnode, insertedVnodeQueue); |
5309fbda | 10936 | if (parent !== null) { |
5d51ea26 | 10937 | api.insertBefore(parent, vnode.elm, api.nextSibling(elm)); |
5309fbda DC |
10938 | removeVnodes(parent, [oldVnode], 0, 0); |
10939 | } | |
10940 | } | |
10941 | for (i = 0; i < insertedVnodeQueue.length; ++i) { | |
10942 | insertedVnodeQueue[i].data.hook.insert(insertedVnodeQueue[i]); | |
10943 | } | |
10944 | for (i = 0; i < cbs.post.length; ++i) | |
10945 | { cbs.post[i](); } | |
5d51ea26 | 10946 | return vnode; |
5309fbda DC |
10947 | }; |
10948 | } | |
10949 | ||
10950 | var xlinkNS = 'http://www.w3.org/1999/xlink'; | |
10951 | var xmlNS = 'http://www.w3.org/XML/1998/namespace'; | |
10952 | var colonChar = 58; | |
10953 | var xChar = 120; | |
10954 | function updateAttrs(oldVnode, vnode) { | |
10955 | var key, elm = vnode.elm, oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs; | |
10956 | if (!oldAttrs && !attrs) | |
10957 | { return; } | |
10958 | if (oldAttrs === attrs) | |
10959 | { return; } | |
10960 | oldAttrs = oldAttrs || {}; | |
10961 | attrs = attrs || {}; | |
10962 | // update modified attributes, add new attributes | |
10963 | for (key in attrs) { | |
10964 | var cur = attrs[key]; | |
10965 | var old = oldAttrs[key]; | |
10966 | if (old !== cur) { | |
10967 | if (cur === true) { | |
10968 | elm.setAttribute(key, ""); | |
10969 | } | |
10970 | else if (cur === false) { | |
10971 | elm.removeAttribute(key); | |
10972 | } | |
10973 | else { | |
10974 | if (key.charCodeAt(0) !== xChar) { | |
10975 | elm.setAttribute(key, cur); | |
10976 | } | |
10977 | else if (key.charCodeAt(3) === colonChar) { | |
10978 | // Assume xml namespace | |
10979 | elm.setAttributeNS(xmlNS, key, cur); | |
10980 | } | |
10981 | else if (key.charCodeAt(5) === colonChar) { | |
10982 | // Assume xlink namespace | |
10983 | elm.setAttributeNS(xlinkNS, key, cur); | |
10984 | } | |
10985 | else { | |
10986 | elm.setAttribute(key, cur); | |
10987 | } | |
10988 | } | |
10989 | } | |
10990 | } | |
10991 | // remove removed attributes | |
10992 | // use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value) | |
10993 | // the other option is to remove all attributes with value == undefined | |
10994 | for (key in oldAttrs) { | |
10995 | if (!(key in attrs)) { | |
10996 | elm.removeAttribute(key); | |
10997 | } | |
10998 | } | |
10999 | } | |
11000 | var attributesModule = { create: updateAttrs, update: updateAttrs }; | |
11001 | ||
11002 | function updateProps(oldVnode, vnode) { | |
11003 | var key, cur, old, elm = vnode.elm, oldProps = oldVnode.data.props, props = vnode.data.props; | |
11004 | if (!oldProps && !props) | |
11005 | { return; } | |
11006 | if (oldProps === props) | |
11007 | { return; } | |
11008 | oldProps = oldProps || {}; | |
11009 | props = props || {}; | |
11010 | for (key in oldProps) { | |
11011 | if (!props[key]) { | |
11012 | delete elm[key]; | |
11013 | } | |
11014 | } | |
11015 | for (key in props) { | |
11016 | cur = props[key]; | |
11017 | old = oldProps[key]; | |
11018 | if (old !== cur && (key !== 'value' || elm[key] !== cur)) { | |
11019 | elm[key] = cur; | |
11020 | } | |
11021 | } | |
11022 | } | |
11023 | var propsModule = { create: updateProps, update: updateProps }; | |
11024 | ||
11025 | var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout; | |
11026 | var nextFrame = function (fn) { raf(function () { raf(fn); }); }; | |
11027 | function setNextFrame(obj, prop, val) { | |
11028 | nextFrame(function () { obj[prop] = val; }); | |
11029 | } | |
11030 | function updateStyle(oldVnode, vnode) { | |
11031 | var cur, name, elm = vnode.elm, oldStyle = oldVnode.data.style, style = vnode.data.style; | |
11032 | if (!oldStyle && !style) | |
11033 | { return; } | |
11034 | if (oldStyle === style) | |
11035 | { return; } | |
11036 | oldStyle = oldStyle || {}; | |
11037 | style = style || {}; | |
11038 | var oldHasDel = 'delayed' in oldStyle; | |
11039 | for (name in oldStyle) { | |
11040 | if (!style[name]) { | |
11041 | if (name[0] === '-' && name[1] === '-') { | |
11042 | elm.style.removeProperty(name); | |
11043 | } | |
11044 | else { | |
11045 | elm.style[name] = ''; | |
11046 | } | |
11047 | } | |
11048 | } | |
11049 | for (name in style) { | |
11050 | cur = style[name]; | |
11051 | if (name === 'delayed' && style.delayed) { | |
11052 | for (var name2 in style.delayed) { | |
11053 | cur = style.delayed[name2]; | |
11054 | if (!oldHasDel || cur !== oldStyle.delayed[name2]) { | |
11055 | setNextFrame(elm.style, name2, cur); | |
11056 | } | |
11057 | } | |
11058 | } | |
11059 | else if (name !== 'remove' && cur !== oldStyle[name]) { | |
11060 | if (name[0] === '-' && name[1] === '-') { | |
11061 | elm.style.setProperty(name, cur); | |
11062 | } | |
11063 | else { | |
11064 | elm.style[name] = cur; | |
11065 | } | |
11066 | } | |
11067 | } | |
11068 | } | |
11069 | function applyDestroyStyle(vnode) { | |
11070 | var style, name, elm = vnode.elm, s = vnode.data.style; | |
11071 | if (!s || !(style = s.destroy)) | |
11072 | { return; } | |
11073 | for (name in style) { | |
11074 | elm.style[name] = style[name]; | |
11075 | } | |
11076 | } | |
11077 | function applyRemoveStyle(vnode, rm) { | |
11078 | var s = vnode.data.style; | |
11079 | if (!s || !s.remove) { | |
11080 | rm(); | |
11081 | return; | |
11082 | } | |
11083 | var name, elm = vnode.elm, i = 0, compStyle, style = s.remove, amount = 0, applied = []; | |
11084 | for (name in style) { | |
11085 | applied.push(name); | |
11086 | elm.style[name] = style[name]; | |
11087 | } | |
11088 | compStyle = getComputedStyle(elm); | |
11089 | var props = compStyle['transition-property'].split(', '); | |
11090 | for (; i < props.length; ++i) { | |
11091 | if (applied.indexOf(props[i]) !== -1) | |
11092 | { amount++; } | |
11093 | } | |
11094 | elm.addEventListener('transitionend', function (ev) { | |
11095 | if (ev.target === elm) | |
11096 | { --amount; } | |
11097 | if (amount === 0) | |
11098 | { rm(); } | |
11099 | }); | |
11100 | } | |
11101 | var styleModule = { | |
11102 | create: updateStyle, | |
11103 | update: updateStyle, | |
11104 | destroy: applyDestroyStyle, | |
11105 | remove: applyRemoveStyle | |
11106 | }; | |
11107 | ||
11108 | function invokeHandler(handler, event, args) { | |
11109 | if (typeof handler === 'function') { | |
11110 | // call function handler | |
11111 | handler.apply(void 0, [ event ].concat( args )); | |
11112 | } | |
11113 | } | |
11114 | function handleEvent(event, args, vnode) { | |
11115 | var name = event.type; | |
11116 | var on = vnode.data.on; | |
11117 | // call event handler(s) if exists | |
11118 | if (on && on[name]) { | |
5d51ea26 | 11119 | invokeHandler(on[name], event, args); |
5309fbda DC |
11120 | } |
11121 | } | |
11122 | function createListener() { | |
11123 | return function handler(event) { | |
11124 | var args = [], len = arguments.length - 1; | |
11125 | while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | |
11126 | ||
11127 | handleEvent(event, args, handler.vnode); | |
11128 | }; | |
11129 | } | |
11130 | function updateEvents(oldVnode, vnode) { | |
11131 | var oldOn = oldVnode.data.on; | |
11132 | var oldListener = oldVnode.listener; | |
11133 | var oldElm = oldVnode.elm; | |
11134 | var on = vnode && vnode.data.on; | |
11135 | var elm = (vnode && vnode.elm); | |
11136 | // optimization for reused immutable handlers | |
11137 | if (oldOn === on) { | |
11138 | return; | |
11139 | } | |
11140 | // remove existing listeners which no longer used | |
11141 | if (oldOn && oldListener) { | |
11142 | // if element changed or deleted we remove all existing listeners unconditionally | |
11143 | if (!on) { | |
11144 | Object.keys(oldOn).forEach(function (name) { | |
11145 | $(oldElm).off(name, oldListener); | |
11146 | }); | |
11147 | } else { | |
11148 | Object.keys(oldOn).forEach(function (name) { | |
11149 | if (!on[name]) { | |
11150 | $(oldElm).off(name, oldListener); | |
11151 | } | |
11152 | }); | |
11153 | } | |
11154 | } | |
11155 | // add new listeners which has not already attached | |
11156 | if (on) { | |
11157 | // reuse existing listener or create new | |
11158 | var listener = oldVnode.listener || createListener(); | |
11159 | vnode.listener = listener; | |
11160 | // update vnode for listener | |
11161 | listener.vnode = vnode; | |
11162 | // if element changed or added we add all needed listeners unconditionally | |
11163 | if (!oldOn) { | |
11164 | Object.keys(on).forEach(function (name) { | |
11165 | $(elm).on(name, listener); | |
11166 | }); | |
11167 | } else { | |
11168 | Object.keys(on).forEach(function (name) { | |
11169 | if (!oldOn[name]) { | |
11170 | $(elm).on(name, listener); | |
11171 | } | |
11172 | }); | |
11173 | } | |
11174 | } | |
11175 | } | |
11176 | ||
11177 | var eventListenersModule = { | |
11178 | create: updateEvents, | |
11179 | update: updateEvents, | |
11180 | destroy: updateEvents, | |
11181 | }; | |
11182 | ||
11183 | /* eslint import/no-named-as-default: off */ | |
11184 | ||
5d51ea26 | 11185 | var patch = init([ |
5309fbda DC |
11186 | attributesModule, |
11187 | propsModule, | |
11188 | styleModule, | |
11189 | eventListenersModule ]); | |
11190 | ||
11191 | var Framework7Component = function Framework7Component(app, options, extendContext) { | |
11192 | if ( extendContext === void 0 ) extendContext = {}; | |
11193 | ||
11194 | var id = Utils.id(); | |
11195 | var self = Utils.merge( | |
11196 | this, | |
11197 | extendContext, | |
11198 | { | |
11199 | $: $, | |
11200 | $$: $, | |
11201 | $dom7: $, | |
11202 | $app: app, | |
11203 | $f7: app, | |
11204 | $options: Utils.extend({ id: id }, options), | |
5d51ea26 | 11205 | $id: options.id || id, |
5309fbda DC |
11206 | } |
11207 | ); | |
11208 | var $options = self.$options; | |
11209 | ||
11210 | // Root data and methods | |
11211 | Object.defineProperty(self, '$root', { | |
11212 | enumerable: true, | |
11213 | configurable: true, | |
11214 | get: function get() { | |
11215 | var root = Utils.merge({}, app.data, app.methods); | |
11216 | if (win && win.Proxy) { | |
11217 | root = new win.Proxy(root, { | |
11218 | set: function set(target, name, val) { | |
11219 | app.data[name] = val; | |
11220 | }, | |
11221 | deleteProperty: function deleteProperty(target, name) { | |
11222 | delete app.data[name]; | |
11223 | delete app.methods[name]; | |
11224 | }, | |
11225 | has: function has(target, name) { | |
11226 | return (name in app.data || name in app.methods); | |
11227 | }, | |
11228 | }); | |
11229 | } | |
11230 | return root; | |
11231 | }, | |
11232 | set: function set() {}, | |
11233 | }); | |
11234 | ||
11235 | // Apply context | |
11236 | ('beforeCreate created beforeMount mounted beforeDestroy destroyed updated').split(' ').forEach(function (cycleKey) { | |
11237 | if ($options[cycleKey]) { $options[cycleKey] = $options[cycleKey].bind(self); } | |
11238 | }); | |
11239 | ||
11240 | if ($options.data) { | |
11241 | $options.data = $options.data.bind(self); | |
11242 | // Data | |
11243 | Utils.extend(self, $options.data()); | |
11244 | } | |
11245 | if ($options.render) { $options.render = $options.render.bind(self); } | |
11246 | if ($options.methods) { | |
11247 | Object.keys($options.methods).forEach(function (methodName) { | |
11248 | self[methodName] = $options.methods[methodName].bind(self); | |
11249 | }); | |
11250 | } | |
11251 | ||
11252 | // Bind Events | |
11253 | if ($options.on) { | |
11254 | Object.keys($options.on).forEach(function (eventName) { | |
11255 | $options.on[eventName] = $options.on[eventName].bind(self); | |
11256 | }); | |
11257 | } | |
11258 | if ($options.once) { | |
11259 | Object.keys($options.once).forEach(function (eventName) { | |
11260 | $options.once[eventName] = $options.once[eventName].bind(self); | |
11261 | }); | |
11262 | } | |
11263 | ||
11264 | // Before create hook | |
11265 | if ($options.beforeCreate) { $options.beforeCreate(); } | |
11266 | ||
11267 | // Render | |
11268 | var html = self.$render(); | |
11269 | ||
11270 | // Make Dom | |
11271 | if (html && typeof html === 'string') { | |
11272 | html = html.trim(); | |
11273 | self.$vnode = vdom(html, self, app, true); | |
11274 | self.el = doc.createElement('div'); | |
11275 | patch(self.el, self.$vnode); | |
11276 | } else if (html) { | |
11277 | self.el = html; | |
11278 | } | |
11279 | self.$el = $(self.el); | |
11280 | ||
11281 | // Set styles scope ID | |
11282 | if ($options.style) { | |
11283 | self.$styleEl = doc.createElement('style'); | |
11284 | self.$styleEl.innerHTML = $options.style; | |
11285 | if ($options.styleScoped) { | |
11286 | self.el.setAttribute(("data-f7-" + ($options.id)), ''); | |
11287 | } | |
11288 | } | |
11289 | ||
11290 | self.$attachEvents(); | |
11291 | ||
11292 | // Created callback | |
11293 | if ($options.created) { $options.created(); } | |
11294 | ||
11295 | // Store component instance | |
11296 | self.el.f7Component = self; | |
11297 | ||
11298 | return self; | |
11299 | }; | |
11300 | ||
11301 | Framework7Component.prototype.$attachEvents = function $attachEvents () { | |
11302 | var self = this; | |
11303 | var $options = self.$options; | |
11304 | var $el = self.$el; | |
11305 | if ($options.on) { | |
11306 | Object.keys($options.on).forEach(function (eventName) { | |
11307 | $el.on(Utils.eventNameToColonCase(eventName), $options.on[eventName]); | |
11308 | }); | |
11309 | } | |
11310 | if ($options.once) { | |
11311 | Object.keys($options.once).forEach(function (eventName) { | |
11312 | $el.once(Utils.eventNameToColonCase(eventName), $options.once[eventName]); | |
11313 | }); | |
11314 | } | |
11315 | }; | |
11316 | ||
11317 | Framework7Component.prototype.$detachEvents = function $detachEvents () { | |
11318 | var self = this; | |
11319 | var $options = self.$options; | |
11320 | var $el = self.$el; | |
11321 | if ($options.on) { | |
11322 | Object.keys($options.on).forEach(function (eventName) { | |
11323 | $el.off(Utils.eventNameToColonCase(eventName), $options.on[eventName]); | |
11324 | }); | |
11325 | } | |
11326 | if ($options.once) { | |
11327 | Object.keys($options.once).forEach(function (eventName) { | |
11328 | $el.off(Utils.eventNameToColonCase(eventName), $options.once[eventName]); | |
11329 | }); | |
11330 | } | |
11331 | }; | |
11332 | ||
11333 | Framework7Component.prototype.$render = function $render () { | |
11334 | var self = this; | |
11335 | var $options = self.$options; | |
11336 | var html = ''; | |
11337 | if ($options.render) { | |
11338 | html = $options.render(); | |
11339 | } else if ($options.template) { | |
11340 | if (typeof $options.template === 'string') { | |
11341 | try { | |
11342 | html = Template7.compile($options.template)(self); | |
11343 | } catch (err) { | |
11344 | throw err; | |
11345 | } | |
11346 | } else { | |
11347 | // Supposed to be function | |
11348 | html = $options.template(self); | |
11349 | } | |
11350 | } | |
11351 | return html; | |
11352 | }; | |
11353 | ||
11354 | Framework7Component.prototype.$forceUpdate = function $forceUpdate () { | |
11355 | var self = this; | |
11356 | var html = self.$render(); | |
11357 | ||
11358 | // Make Dom | |
11359 | if (html && typeof html === 'string') { | |
11360 | html = html.trim(); | |
11361 | var newVNode = vdom(html, self, self.$app); | |
11362 | self.$vnode = patch(self.$vnode, newVNode); | |
11363 | } | |
11364 | }; | |
11365 | ||
11366 | Framework7Component.prototype.$setState = function $setState (mergeState) { | |
11367 | var self = this; | |
11368 | Utils.merge(self, mergeState); | |
11369 | self.$forceUpdate(); | |
11370 | }; | |
11371 | ||
11372 | Framework7Component.prototype.$mount = function $mount (mountMethod) { | |
11373 | var self = this; | |
11374 | if (self.$options.beforeMount) { self.$options.beforeMount(); } | |
11375 | if (self.$styleEl) { $('head').append(self.$styleEl); } | |
11376 | if (mountMethod) { mountMethod(self.el); } | |
11377 | if (self.$options.mounted) { self.$options.mounted(); } | |
11378 | }; | |
11379 | ||
11380 | Framework7Component.prototype.$destroy = function $destroy () { | |
11381 | var self = this; | |
11382 | if (self.$options.beforeDestroy) { self.$options.beforeDestroy(); } | |
11383 | if (self.$styleEl) { $(self.$styleEl).remove(); } | |
11384 | self.$detachEvents(); | |
11385 | if (self.$options.destroyed) { self.$options.destroyed(); } | |
11386 | // Delete component instance | |
11387 | if (self.el && self.el.f7Component) { | |
11388 | self.el.f7Component = null; | |
11389 | delete self.el.f7Component; | |
11390 | } | |
11391 | // Patch with empty node | |
11392 | if (self.$vnode) { | |
11393 | self.$vnode = patch(self.$vnode, { sel: self.$vnode.sel, data: {} }); | |
11394 | } | |
11395 | Utils.deleteProps(self); | |
11396 | }; | |
11397 | ||
11398 | function parseComponent(componentString) { | |
11399 | var id = Utils.id(); | |
11400 | var callbackCreateName = "f7_component_create_callback_" + id; | |
11401 | var callbackRenderName = "f7_component_render_callback_" + id; | |
11402 | ||
11403 | // Template | |
11404 | var template; | |
11405 | var hasTemplate = componentString.match(/<template([ ]?)([a-z0-9-]*)>/); | |
11406 | var templateType = hasTemplate[2] || 't7'; | |
11407 | if (hasTemplate) { | |
11408 | template = componentString | |
11409 | .split(/<template[ ]?[a-z0-9-]*>/) | |
11410 | .filter(function (item, index) { return index > 0; }) | |
11411 | .join('<template>') | |
11412 | .split('</template>') | |
11413 | .filter(function (item, index, arr) { return index < arr.length - 1; }) | |
11414 | .join('</template>') | |
11415 | .replace(/{{#raw}}([ \n]*)<template/g, '{{#raw}}<template') | |
11416 | .replace(/\/template>([ \n]*){{\/raw}}/g, '/template>{{/raw}}') | |
11417 | .replace(/([ \n])<template/g, '$1{{#raw}}<template') | |
11418 | .replace(/\/template>([ \n])/g, '/template>{{/raw}}$1'); | |
11419 | } | |
11420 | ||
11421 | // Parse Styles | |
11422 | var style = null; | |
11423 | var styleScoped = false; | |
11424 | ||
11425 | if (componentString.indexOf('<style>') >= 0) { | |
11426 | style = componentString.split('<style>')[1].split('</style>')[0]; | |
11427 | } else if (componentString.indexOf('<style scoped>') >= 0) { | |
11428 | styleScoped = true; | |
11429 | style = componentString.split('<style scoped>')[1].split('</style>')[0]; | |
11430 | style = style.split('\n').map(function (line) { | |
11431 | var trimmedLine = line.trim(); | |
11432 | if (trimmedLine.indexOf('@') === 0) { return line; } | |
11433 | if (line.indexOf('{') >= 0) { | |
11434 | if (line.indexOf('{{this}}') >= 0) { | |
11435 | return line.replace('{{this}}', ("[data-f7-" + id + "]")); | |
11436 | } | |
11437 | return ("[data-f7-" + id + "] " + (line.trim())); | |
11438 | } | |
11439 | return line; | |
11440 | }).join('\n'); | |
11441 | } | |
11442 | ||
11443 | // Parse Script | |
11444 | var scriptContent; | |
11445 | var scriptEl; | |
11446 | if (componentString.indexOf('<script>') >= 0) { | |
11447 | var scripts = componentString.split('<script>'); | |
11448 | scriptContent = scripts[scripts.length - 1].split('</script>')[0].trim(); | |
11449 | } else { | |
11450 | scriptContent = 'return {}'; | |
11451 | } | |
11452 | if (!scriptContent || !scriptContent.trim()) { scriptContent = 'return {}'; } | |
11453 | ||
11454 | scriptContent = "window." + callbackCreateName + " = function () {" + scriptContent + "}"; | |
11455 | ||
11456 | // Insert Script El | |
11457 | scriptEl = doc.createElement('script'); | |
11458 | scriptEl.innerHTML = scriptContent; | |
11459 | $('head').append(scriptEl); | |
11460 | ||
11461 | var component = win[callbackCreateName](); | |
11462 | ||
11463 | // Remove Script El | |
11464 | $(scriptEl).remove(); | |
11465 | win[callbackCreateName] = null; | |
11466 | delete win[callbackCreateName]; | |
11467 | ||
11468 | // Assign Template | |
11469 | if (!component.template && !component.render) { | |
11470 | component.template = template; | |
11471 | component.templateType = templateType; | |
11472 | } | |
11473 | if (component.template) { | |
11474 | if (component.templateType === 't7') { | |
11475 | component.template = Template7.compile(component.template); | |
11476 | } | |
11477 | if (component.templateType === 'es') { | |
11478 | var renderContent = "window." + callbackRenderName + " = function () {\n return function render() {\n return `" + (component.template) + "`;\n }\n }"; | |
11479 | scriptEl = doc.createElement('script'); | |
11480 | scriptEl.innerHTML = renderContent; | |
11481 | $('head').append(scriptEl); | |
11482 | ||
11483 | component.render = win[callbackRenderName](); | |
11484 | ||
11485 | // Remove Script El | |
11486 | $(scriptEl).remove(); | |
11487 | win[callbackRenderName] = null; | |
11488 | delete win[callbackRenderName]; | |
11489 | } | |
11490 | } | |
11491 | ||
11492 | // Assign Style | |
11493 | if (style) { | |
11494 | component.style = style; | |
11495 | component.styleScoped = styleScoped; | |
11496 | } | |
11497 | ||
11498 | // Component ID | |
11499 | component.id = id; | |
11500 | return component; | |
11501 | } | |
11502 | ||
11503 | var ComponentModule = { | |
11504 | name: 'component', | |
11505 | create: function create() { | |
11506 | var app = this; | |
11507 | app.component = { | |
11508 | parse: function parse(componentString) { | |
11509 | return parseComponent(componentString); | |
11510 | }, | |
11511 | create: function create(options, extendContext) { | |
11512 | return new Framework7Component(app, options, extendContext); | |
11513 | }, | |
11514 | }; | |
11515 | }, | |
11516 | }; | |
11517 | ||
11518 | var SW = { | |
11519 | registrations: [], | |
11520 | register: function register(path, scope) { | |
11521 | var app = this; | |
11522 | if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) { | |
11523 | return new Promise(function (resolve, reject) { | |
11524 | reject(new Error('Service worker is not supported')); | |
11525 | }); | |
11526 | } | |
11527 | return new Promise(function (resolve, reject) { | |
11528 | app.serviceWorker.container.register(path, (scope ? { scope: scope } : {})) | |
11529 | .then(function (reg) { | |
11530 | SW.registrations.push(reg); | |
11531 | app.emit('serviceWorkerRegisterSuccess', reg); | |
11532 | resolve(reg); | |
11533 | }).catch(function (error) { | |
11534 | app.emit('serviceWorkerRegisterError', error); | |
11535 | reject(error); | |
11536 | }); | |
11537 | }); | |
11538 | }, | |
11539 | unregister: function unregister(registration) { | |
11540 | var app = this; | |
11541 | if (!('serviceWorker' in window.navigator) || !app.serviceWorker.container) { | |
11542 | return new Promise(function (resolve, reject) { | |
11543 | reject(new Error('Service worker is not supported')); | |
11544 | }); | |
11545 | } | |
11546 | var registrations; | |
11547 | if (!registration) { registrations = SW.registrations; } | |
11548 | else if (Array.isArray(registration)) { registrations = registration; } | |
11549 | else { registrations = [registration]; } | |
11550 | return Promise.all(registrations.map(function (reg) { return new Promise(function (resolve, reject) { | |
11551 | reg.unregister() | |
11552 | .then(function () { | |
11553 | if (SW.registrations.indexOf(reg) >= 0) { | |
11554 | SW.registrations.splice(SW.registrations.indexOf(reg), 1); | |
11555 | } | |
11556 | app.emit('serviceWorkerUnregisterSuccess', reg); | |
11557 | resolve(); | |
11558 | }) | |
11559 | .catch(function (error) { | |
11560 | app.emit('serviceWorkerUnregisterError', reg, error); | |
11561 | reject(error); | |
11562 | }); | |
11563 | }); })); | |
11564 | }, | |
11565 | }; | |
11566 | ||
11567 | var ServiceWorkerModule = { | |
11568 | name: 'sw', | |
11569 | params: { | |
11570 | serviceWorker: { | |
11571 | path: undefined, | |
11572 | scope: undefined, | |
11573 | }, | |
11574 | }, | |
11575 | create: function create() { | |
11576 | var app = this; | |
11577 | Utils.extend(app, { | |
11578 | serviceWorker: { | |
11579 | container: ('serviceWorker' in window.navigator) ? window.navigator.serviceWorker : undefined, | |
11580 | registrations: SW.registrations, | |
11581 | register: SW.register.bind(app), | |
11582 | unregister: SW.unregister.bind(app), | |
11583 | }, | |
11584 | }); | |
11585 | }, | |
11586 | on: { | |
11587 | init: function init() { | |
11588 | if (!('serviceWorker' in window.navigator)) { return; } | |
11589 | var app = this; | |
11590 | if (!app.serviceWorker.container) { return; } | |
11591 | var paths = app.params.serviceWorker.path; | |
11592 | var scope = app.params.serviceWorker.scope; | |
11593 | if (!paths || (Array.isArray(paths) && !paths.length)) { return; } | |
11594 | var toRegister = Array.isArray(paths) ? paths : [paths]; | |
11595 | toRegister.forEach(function (path) { | |
11596 | app.serviceWorker.register(path, scope); | |
11597 | }); | |
11598 | }, | |
11599 | }, | |
11600 | }; | |
11601 | ||
11602 | var Statusbar = { | |
11603 | hide: function hide() { | |
11604 | $('html').removeClass('with-statusbar'); | |
11605 | if (Device.cordova && win.StatusBar) { | |
11606 | win.StatusBar.hide(); | |
11607 | } | |
11608 | }, | |
11609 | show: function show() { | |
11610 | if (Device.cordova && win.StatusBar) { | |
11611 | win.StatusBar.show(); | |
11612 | Utils.nextTick(function () { | |
11613 | if (Device.needsStatusbarOverlay()) { | |
11614 | $('html').addClass('with-statusbar'); | |
11615 | } | |
11616 | }); | |
11617 | return; | |
11618 | } | |
11619 | $('html').addClass('with-statusbar'); | |
11620 | }, | |
11621 | onClick: function onClick() { | |
11622 | var app = this; | |
11623 | var pageContent; | |
11624 | if ($('.popup.modal-in').length > 0) { | |
11625 | // Check for opened popup | |
11626 | pageContent = $('.popup.modal-in').find('.page:not(.page-previous):not(.page-next):not(.cached)').find('.page-content'); | |
11627 | } else if ($('.panel.panel-active').length > 0) { | |
11628 | // Check for opened panel | |
11629 | pageContent = $('.panel.panel-active').find('.page:not(.page-previous):not(.page-next):not(.cached)').find('.page-content'); | |
11630 | } else if ($('.views > .view.tab-active').length > 0) { | |
11631 | // View in tab bar app layout | |
11632 | pageContent = $('.views > .view.tab-active').find('.page:not(.page-previous):not(.page-next):not(.cached)').find('.page-content'); | |
11633 | } else if ($('.views').length > 0) { | |
11634 | pageContent = $('.views').find('.page:not(.page-previous):not(.page-next):not(.cached)').find('.page-content'); | |
11635 | } else { | |
11636 | pageContent = app.root.children('.view').find('.page:not(.page-previous):not(.page-next):not(.cached)').find('.page-content'); | |
11637 | } | |
11638 | ||
11639 | if (pageContent && pageContent.length > 0) { | |
11640 | // Check for tab | |
11641 | if (pageContent.hasClass('tab')) { | |
11642 | pageContent = pageContent.parent('.tabs').children('.page-content.tab-active'); | |
11643 | } | |
11644 | if (pageContent.length > 0) { pageContent.scrollTop(0, 300); } | |
11645 | } | |
11646 | }, | |
11647 | setTextColor: function setTextColor(color) { | |
11648 | if (Device.cordova && win.StatusBar) { | |
11649 | if (color === 'white') { | |
11650 | win.StatusBar.styleLightContent(); | |
11651 | } else { | |
11652 | win.StatusBar.styleDefault(); | |
11653 | } | |
11654 | } | |
11655 | }, | |
11656 | setIosTextColor: function setIosTextColor(color) { | |
11657 | if (!Device.ios) { return; } | |
11658 | Statusbar.setTextColor(color); | |
11659 | }, | |
11660 | setBackgroundColor: function setBackgroundColor(color) { | |
11661 | $('.statusbar').css('background-color', color); | |
11662 | if (Device.cordova && win.StatusBar) { | |
11663 | win.StatusBar.backgroundColorByHexString(color); | |
11664 | } | |
11665 | }, | |
11666 | isVisible: function isVisible() { | |
11667 | if (Device.cordova && win.StatusBar) { | |
11668 | return win.StatusBar.isVisible; | |
11669 | } | |
11670 | return false; | |
11671 | }, | |
11672 | overlaysWebView: function overlaysWebView(overlays) { | |
11673 | if ( overlays === void 0 ) overlays = true; | |
11674 | ||
11675 | if (Device.cordova && win.StatusBar) { | |
11676 | win.StatusBar.overlaysWebView(overlays); | |
11677 | if (overlays) { | |
11678 | $('html').addClass('with-statusbar'); | |
11679 | } else { | |
11680 | $('html').removeClass('with-statusbar'); | |
11681 | } | |
11682 | } | |
11683 | }, | |
11684 | checkOverlay: function checkOverlay() { | |
11685 | if (Device.needsStatusbarOverlay()) { | |
11686 | $('html').addClass('with-statusbar'); | |
11687 | } else { | |
11688 | $('html').removeClass('with-statusbar'); | |
11689 | } | |
11690 | }, | |
11691 | init: function init() { | |
11692 | var app = this; | |
11693 | var params = app.params.statusbar; | |
11694 | if (!params.enabled) { return; } | |
11695 | ||
11696 | if (params.overlay === 'auto') { | |
11697 | if (Device.needsStatusbarOverlay()) { | |
11698 | $('html').addClass('with-statusbar'); | |
11699 | } else { | |
11700 | $('html').removeClass('with-statusbar'); | |
11701 | } | |
11702 | ||
11703 | if (Device.ios && (Device.cordova || Device.webView)) { | |
11704 | if (win.orientation === 0) { | |
11705 | app.once('resize', function () { | |
11706 | Statusbar.checkOverlay(); | |
11707 | }); | |
11708 | } | |
11709 | ||
11710 | $(doc).on('resume', function () { | |
11711 | Statusbar.checkOverlay(); | |
11712 | }, false); | |
11713 | ||
11714 | app.on(Device.ios ? 'orientationchange' : 'orientationchange resize', function () { | |
11715 | Statusbar.checkOverlay(); | |
11716 | }); | |
11717 | } | |
11718 | } else if (params.overlay === true) { | |
11719 | $('html').addClass('with-statusbar'); | |
11720 | } else if (params.overlay === false) { | |
11721 | $('html').removeClass('with-statusbar'); | |
11722 | } | |
11723 | ||
11724 | if (Device.cordova && win.StatusBar) { | |
11725 | if (params.scrollTopOnClick) { | |
11726 | $(win).on('statusTap', Statusbar.onClick.bind(app)); | |
11727 | } | |
11728 | if (Device.ios) { | |
11729 | if (params.iosOverlaysWebView) { | |
11730 | win.StatusBar.overlaysWebView(true); | |
11731 | } else { | |
11732 | win.StatusBar.overlaysWebView(false); | |
11733 | } | |
11734 | if (params.iosTextColor === 'white') { | |
11735 | win.StatusBar.styleLightContent(); | |
11736 | } else { | |
11737 | win.StatusBar.styleDefault(); | |
11738 | } | |
11739 | } | |
11740 | if (Device.android) { | |
11741 | if (params.androidOverlaysWebView) { | |
11742 | win.StatusBar.overlaysWebView(true); | |
11743 | } else { | |
11744 | win.StatusBar.overlaysWebView(false); | |
11745 | } | |
11746 | if (params.androidTextColor === 'white') { | |
11747 | win.StatusBar.styleLightContent(); | |
11748 | } else { | |
11749 | win.StatusBar.styleDefault(); | |
11750 | } | |
11751 | } | |
11752 | } | |
11753 | if (params.iosBackgroundColor && Device.ios) { | |
11754 | Statusbar.setBackgroundColor(params.iosBackgroundColor); | |
11755 | } | |
11756 | if ((params.materialBackgroundColor || params.androidBackgroundColor) && Device.android) { | |
11757 | Statusbar.setBackgroundColor(params.materialBackgroundColor || params.androidBackgroundColor); | |
11758 | } | |
11759 | }, | |
11760 | }; | |
11761 | ||
11762 | var Statusbar$1 = { | |
11763 | name: 'statusbar', | |
11764 | params: { | |
11765 | statusbar: { | |
11766 | enabled: true, | |
11767 | overlay: 'auto', | |
11768 | scrollTopOnClick: true, | |
11769 | ||
11770 | iosOverlaysWebView: true, | |
11771 | iosTextColor: 'black', | |
11772 | iosBackgroundColor: null, | |
11773 | ||
11774 | androidOverlaysWebView: false, | |
11775 | androidTextColor: 'black', | |
11776 | androidBackgroundColor: null, | |
11777 | }, | |
11778 | }, | |
11779 | create: function create() { | |
11780 | var app = this; | |
11781 | Utils.extend(app, { | |
11782 | statusbar: { | |
11783 | checkOverlay: Statusbar.checkOverlay, | |
11784 | hide: Statusbar.hide, | |
11785 | show: Statusbar.show, | |
11786 | overlaysWebView: Statusbar.overlaysWebView, | |
11787 | setTextColor: Statusbar.setTextColor, | |
11788 | setBackgroundColor: Statusbar.setBackgroundColor, | |
11789 | isVisible: Statusbar.isVisible, | |
11790 | init: Statusbar.init.bind(app), | |
11791 | }, | |
11792 | }); | |
11793 | }, | |
11794 | on: { | |
11795 | init: function init() { | |
11796 | var app = this; | |
11797 | Statusbar.init.call(app); | |
11798 | }, | |
11799 | }, | |
11800 | clicks: { | |
11801 | '.statusbar': function onStatusbarClick() { | |
11802 | var app = this; | |
11803 | if (!app.params.statusbar.enabled) { return; } | |
11804 | if (!app.params.statusbar.scrollTopOnClick) { return; } | |
11805 | Statusbar.onClick.call(app); | |
11806 | }, | |
11807 | }, | |
11808 | }; | |
11809 | ||
11810 | function getCurrentView(app) { | |
5d51ea26 DC |
11811 | var $popoverView = $('.popover.modal-in .view'); |
11812 | var $popupView = $('.popup.modal-in .view'); | |
11813 | var $panelView = $('.panel.panel-active .view'); | |
11814 | var $viewsEl = $('.views'); | |
11815 | if ($viewsEl.length === 0) { $viewsEl = app.root; } | |
5309fbda | 11816 | // Find active view as tab |
5d51ea26 | 11817 | var $viewEl = $viewsEl.children('.view'); |
5309fbda | 11818 | // Propably in tabs or split view |
5d51ea26 DC |
11819 | if ($viewEl.length > 1) { |
11820 | if ($viewEl.hasClass('tab')) { | |
5309fbda | 11821 | // Tabs |
5d51ea26 | 11822 | $viewEl = $viewsEl.children('.view.tab-active'); |
5309fbda DC |
11823 | } |
11824 | } | |
5d51ea26 DC |
11825 | if ($popoverView.length > 0 && $popoverView[0].f7View) { return $popoverView[0].f7View; } |
11826 | if ($popupView.length > 0 && $popupView[0].f7View) { return $popupView[0].f7View; } | |
11827 | if ($panelView.length > 0 && $panelView[0].f7View) { return $panelView[0].f7View; } | |
11828 | if ($viewEl.length > 0) { | |
11829 | if ($viewEl.length === 1 && $viewEl[0].f7View) { return $viewEl[0].f7View; } | |
11830 | if ($viewEl.length > 1) { | |
5309fbda DC |
11831 | return app.views.main; |
11832 | } | |
11833 | } | |
11834 | return undefined; | |
11835 | } | |
11836 | ||
11837 | var View$1 = { | |
11838 | name: 'view', | |
11839 | params: { | |
11840 | view: { | |
11841 | name: undefined, | |
11842 | main: false, | |
11843 | router: true, | |
11844 | linksView: null, | |
11845 | stackPages: false, | |
11846 | xhrCache: true, | |
11847 | xhrCacheIgnore: [], | |
11848 | xhrCacheIgnoreGetParameters: false, | |
11849 | xhrCacheDuration: 1000 * 60 * 10, // Ten minutes | |
11850 | preloadPreviousPage: true, | |
11851 | allowDuplicateUrls: false, | |
11852 | reloadPages: false, | |
11853 | reloadDetail: false, | |
11854 | masterDetailBreakpoint: 0, | |
11855 | removeElements: true, | |
11856 | removeElementsWithTimeout: false, | |
11857 | removeElementsTimeout: 0, | |
11858 | restoreScrollTopOnBack: true, | |
11859 | unloadTabContent: true, | |
11860 | passRouteQueryToRequest: true, | |
11861 | passRouteParamsToRequest: false, | |
11862 | // Swipe Back | |
11863 | iosSwipeBack: true, | |
11864 | iosSwipeBackAnimateShadow: true, | |
11865 | iosSwipeBackAnimateOpacity: true, | |
11866 | iosSwipeBackActiveArea: 30, | |
11867 | iosSwipeBackThreshold: 0, | |
11868 | mdSwipeBack: false, | |
11869 | mdSwipeBackAnimateShadow: true, | |
11870 | mdSwipeBackAnimateOpacity: false, | |
11871 | mdSwipeBackActiveArea: 30, | |
11872 | mdSwipeBackThreshold: 0, | |
5d51ea26 DC |
11873 | auroraSwipeBack: false, |
11874 | auroraSwipeBackAnimateShadow: false, | |
11875 | auroraSwipeBackAnimateOpacity: true, | |
11876 | auroraSwipeBackActiveArea: 30, | |
11877 | auroraSwipeBackThreshold: 0, | |
5309fbda DC |
11878 | // Push State |
11879 | pushState: false, | |
11880 | pushStateRoot: undefined, | |
11881 | pushStateAnimate: true, | |
11882 | pushStateAnimateOnLoad: false, | |
11883 | pushStateSeparator: '#!', | |
11884 | pushStateOnLoad: true, | |
11885 | // Animate Pages | |
11886 | animate: true, | |
11887 | // iOS Dynamic Navbar | |
11888 | iosDynamicNavbar: true, | |
11889 | iosSeparateDynamicNavbar: true, | |
11890 | // Animate iOS Navbar Back Icon | |
11891 | iosAnimateNavbarBackIcon: true, | |
11892 | // Delays | |
11893 | iosPageLoadDelay: 0, | |
11894 | mdPageLoadDelay: 0, | |
5d51ea26 | 11895 | auroraPageLoadDelay: 0, |
5309fbda DC |
11896 | // Routes hooks |
11897 | routesBeforeEnter: null, | |
11898 | routesBeforeLeave: null, | |
11899 | }, | |
11900 | }, | |
11901 | static: { | |
11902 | View: View, | |
11903 | }, | |
11904 | create: function create() { | |
11905 | var app = this; | |
11906 | Utils.extend(app, { | |
11907 | views: Utils.extend([], { | |
11908 | create: function create(el, params) { | |
11909 | return new View(app, el, params); | |
11910 | }, | |
11911 | get: function get(viewEl) { | |
11912 | var $viewEl = $(viewEl); | |
11913 | if ($viewEl.length && $viewEl[0].f7View) { return $viewEl[0].f7View; } | |
11914 | return undefined; | |
11915 | }, | |
11916 | }), | |
11917 | }); | |
11918 | Object.defineProperty(app.views, 'current', { | |
11919 | enumerable: true, | |
11920 | configurable: true, | |
11921 | get: function get() { | |
11922 | return getCurrentView(app); | |
11923 | }, | |
11924 | }); | |
11925 | // Alias | |
11926 | app.view = app.views; | |
11927 | }, | |
11928 | on: { | |
11929 | init: function init() { | |
11930 | var app = this; | |
11931 | $('.view-init').each(function (index, viewEl) { | |
11932 | if (viewEl.f7View) { return; } | |
11933 | var viewParams = $(viewEl).dataset(); | |
11934 | app.views.create(viewEl, viewParams); | |
11935 | }); | |
11936 | }, | |
11937 | modalOpen: function modalOpen(modal) { | |
11938 | var app = this; | |
11939 | modal.$el.find('.view-init').each(function (index, viewEl) { | |
11940 | if (viewEl.f7View) { return; } | |
11941 | var viewParams = $(viewEl).dataset(); | |
11942 | app.views.create(viewEl, viewParams); | |
11943 | }); | |
11944 | }, | |
11945 | modalBeforeDestroy: function modalBeforeDestroy(modal) { | |
11946 | if (!modal || !modal.$el) { return; } | |
11947 | modal.$el.find('.view-init').each(function (index, viewEl) { | |
11948 | var view = viewEl.f7View; | |
11949 | if (!view) { return; } | |
11950 | view.destroy(); | |
11951 | }); | |
11952 | }, | |
11953 | }, | |
11954 | }; | |
11955 | ||
11956 | var Navbar = { | |
11957 | size: function size(el) { | |
11958 | var app = this; | |
5d51ea26 DC |
11959 | if (app.theme !== 'ios' && !app.params.navbar[((app.theme) + "CenterTitle")]) { |
11960 | return; | |
11961 | } | |
5309fbda DC |
11962 | var $el = $(el); |
11963 | if ($el.hasClass('navbar')) { | |
11964 | $el = $el.children('.navbar-inner').each(function (index, navbarEl) { | |
11965 | app.navbar.size(navbarEl); | |
11966 | }); | |
11967 | return; | |
11968 | } | |
11969 | ||
11970 | if ( | |
11971 | $el.hasClass('stacked') | |
11972 | || $el.parents('.stacked').length > 0 | |
11973 | || $el.parents('.tab:not(.tab-active)').length > 0 | |
11974 | || $el.parents('.popup:not(.modal-in)').length > 0 | |
11975 | ) { | |
11976 | return; | |
11977 | } | |
11978 | ||
5d51ea26 | 11979 | if (app.theme !== 'ios' && app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
11980 | $el.addClass('navbar-inner-centered-title'); |
11981 | } | |
11982 | if (app.theme === 'ios' && !app.params.navbar.iosCenterTitle) { | |
11983 | $el.addClass('navbar-inner-left-title'); | |
11984 | } | |
11985 | ||
11986 | var $viewEl = $el.parents('.view').eq(0); | |
11987 | var left = app.rtl ? $el.children('.right') : $el.children('.left'); | |
11988 | var right = app.rtl ? $el.children('.left') : $el.children('.right'); | |
11989 | var title = $el.children('.title'); | |
11990 | var subnavbar = $el.children('.subnavbar'); | |
11991 | var noLeft = left.length === 0; | |
11992 | var noRight = right.length === 0; | |
11993 | var leftWidth = noLeft ? 0 : left.outerWidth(true); | |
11994 | var rightWidth = noRight ? 0 : right.outerWidth(true); | |
11995 | var titleWidth = title.outerWidth(true); | |
11996 | var navbarStyles = $el.styles(); | |
11997 | var navbarWidth = $el[0].offsetWidth; | |
11998 | var navbarInnerWidth = navbarWidth - parseInt(navbarStyles.paddingLeft, 10) - parseInt(navbarStyles.paddingRight, 10); | |
11999 | var isPrevious = $el.hasClass('navbar-previous'); | |
12000 | var sliding = $el.hasClass('sliding'); | |
12001 | ||
12002 | var router; | |
12003 | var dynamicNavbar; | |
12004 | var separateNavbar; | |
12005 | var separateNavbarRightOffset = 0; | |
12006 | var separateNavbarLeftOffset = 0; | |
12007 | ||
12008 | if ($viewEl.length > 0 && $viewEl[0].f7View) { | |
12009 | router = $viewEl[0].f7View.router; | |
12010 | dynamicNavbar = router && router.dynamicNavbar; | |
12011 | separateNavbar = router && router.separateNavbar; | |
12012 | if (!separateNavbar) { | |
12013 | separateNavbarRightOffset = navbarWidth; | |
12014 | separateNavbarLeftOffset = navbarWidth / 5; | |
12015 | } | |
12016 | } | |
12017 | ||
12018 | var currLeft; | |
12019 | var diff; | |
12020 | if (noRight) { | |
12021 | currLeft = navbarInnerWidth - titleWidth; | |
12022 | } | |
12023 | if (noLeft) { | |
12024 | currLeft = 0; | |
12025 | } | |
12026 | if (!noLeft && !noRight) { | |
12027 | currLeft = ((navbarInnerWidth - rightWidth - titleWidth) + leftWidth) / 2; | |
12028 | } | |
12029 | var requiredLeft = (navbarInnerWidth - titleWidth) / 2; | |
12030 | if (navbarInnerWidth - leftWidth - rightWidth > titleWidth) { | |
12031 | if (requiredLeft < leftWidth) { | |
12032 | requiredLeft = leftWidth; | |
12033 | } | |
12034 | if (requiredLeft + titleWidth > navbarInnerWidth - rightWidth) { | |
12035 | requiredLeft = navbarInnerWidth - rightWidth - titleWidth; | |
12036 | } | |
12037 | diff = requiredLeft - currLeft; | |
12038 | } else { | |
12039 | diff = 0; | |
12040 | } | |
12041 | ||
12042 | // RTL inverter | |
12043 | var inverter = app.rtl ? -1 : 1; | |
12044 | ||
12045 | if (dynamicNavbar && app.theme === 'ios') { | |
12046 | if (title.hasClass('sliding') || (title.length > 0 && sliding)) { | |
12047 | var titleLeftOffset = (-(currLeft + diff) * inverter) + separateNavbarLeftOffset; | |
12048 | var titleRightOffset = ((navbarInnerWidth - currLeft - diff - titleWidth) * inverter) - separateNavbarRightOffset; | |
12049 | ||
12050 | if (isPrevious) { | |
12051 | if (router && router.params.iosAnimateNavbarBackIcon) { | |
12052 | var activeNavbarBackLink = $el.parent().find('.navbar-current').children('.left.sliding').find('.back .icon ~ span'); | |
12053 | if (activeNavbarBackLink.length > 0) { | |
12054 | titleLeftOffset += activeNavbarBackLink[0].offsetLeft; | |
12055 | } | |
12056 | } | |
12057 | } | |
12058 | title[0].f7NavbarLeftOffset = titleLeftOffset; | |
12059 | title[0].f7NavbarRightOffset = titleRightOffset; | |
12060 | } | |
12061 | if (!noLeft && (left.hasClass('sliding') || sliding)) { | |
12062 | if (app.rtl) { | |
12063 | left[0].f7NavbarLeftOffset = (-(navbarInnerWidth - left[0].offsetWidth) / 2) * inverter; | |
12064 | left[0].f7NavbarRightOffset = leftWidth * inverter; | |
12065 | } else { | |
12066 | left[0].f7NavbarLeftOffset = -leftWidth + separateNavbarLeftOffset; | |
12067 | left[0].f7NavbarRightOffset = ((navbarInnerWidth - left[0].offsetWidth) / 2) - separateNavbarRightOffset; | |
12068 | if (router && router.params.iosAnimateNavbarBackIcon && left.find('.back .icon').length > 0) { | |
12069 | if (left.find('.back .icon ~ span').length) { | |
12070 | var leftOffset = left[0].f7NavbarLeftOffset; | |
12071 | var rightOffset = left[0].f7NavbarRightOffset; | |
12072 | left[0].f7NavbarLeftOffset = 0; | |
12073 | left[0].f7NavbarRightOffset = 0; | |
12074 | left.find('.back .icon ~ span')[0].f7NavbarLeftOffset = leftOffset; | |
12075 | left.find('.back .icon ~ span')[0].f7NavbarRightOffset = rightOffset - left.find('.back .icon')[0].offsetWidth; | |
12076 | } | |
12077 | } | |
12078 | } | |
12079 | } | |
12080 | if (!noRight && (right.hasClass('sliding') || sliding)) { | |
12081 | if (app.rtl) { | |
12082 | right[0].f7NavbarLeftOffset = -rightWidth * inverter; | |
12083 | right[0].f7NavbarRightOffset = ((navbarInnerWidth - right[0].offsetWidth) / 2) * inverter; | |
12084 | } else { | |
12085 | right[0].f7NavbarLeftOffset = (-(navbarInnerWidth - right[0].offsetWidth) / 2) + separateNavbarLeftOffset; | |
12086 | right[0].f7NavbarRightOffset = rightWidth - separateNavbarRightOffset; | |
12087 | } | |
12088 | } | |
12089 | if (subnavbar.length && (subnavbar.hasClass('sliding') || sliding)) { | |
12090 | subnavbar[0].f7NavbarLeftOffset = app.rtl ? subnavbar[0].offsetWidth : (-subnavbar[0].offsetWidth + separateNavbarLeftOffset); | |
12091 | subnavbar[0].f7NavbarRightOffset = (-subnavbar[0].f7NavbarLeftOffset - separateNavbarRightOffset) + separateNavbarLeftOffset; | |
12092 | } | |
12093 | } | |
12094 | ||
12095 | // Center title | |
5d51ea26 | 12096 | if (app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12097 | var titleLeft = diff; |
12098 | if (app.rtl && noLeft && noRight && title.length > 0) { titleLeft = -titleLeft; } | |
12099 | title.css({ left: (titleLeft + "px") }); | |
12100 | } | |
12101 | }, | |
12102 | hide: function hide(el, animate) { | |
12103 | if ( animate === void 0 ) animate = true; | |
12104 | ||
12105 | var app = this; | |
12106 | var $el = $(el); | |
12107 | if ($el.hasClass('navbar-inner')) { $el = $el.parents('.navbar'); } | |
12108 | if (!$el.length) { return; } | |
12109 | if ($el.hasClass('navbar-hidden')) { return; } | |
12110 | var className = "navbar-hidden" + (animate ? ' navbar-transitioning' : ''); | |
5d51ea26 DC |
12111 | var currentIsLarge = app.theme === 'ios' |
12112 | ? $el.find('.navbar-current .title-large').length | |
12113 | : $el.find('.title-large').length; | |
5309fbda DC |
12114 | if (currentIsLarge) { |
12115 | className += ' navbar-large-hidden'; | |
12116 | } | |
12117 | $el.transitionEnd(function () { | |
12118 | $el.removeClass('navbar-transitioning'); | |
12119 | }); | |
12120 | $el.addClass(className); | |
5d51ea26 DC |
12121 | $el.trigger('navbar:hide'); |
12122 | app.emit('navbarHide', $el[0]); | |
5309fbda DC |
12123 | }, |
12124 | show: function show(el, animate) { | |
12125 | if ( el === void 0 ) el = '.navbar-hidden'; | |
12126 | if ( animate === void 0 ) animate = true; | |
12127 | ||
5d51ea26 | 12128 | var app = this; |
5309fbda DC |
12129 | var $el = $(el); |
12130 | if ($el.hasClass('navbar-inner')) { $el = $el.parents('.navbar'); } | |
12131 | if (!$el.length) { return; } | |
12132 | if (!$el.hasClass('navbar-hidden')) { return; } | |
12133 | if (animate) { | |
12134 | $el.addClass('navbar-transitioning'); | |
12135 | $el.transitionEnd(function () { | |
12136 | $el.removeClass('navbar-transitioning'); | |
12137 | }); | |
12138 | } | |
12139 | $el.removeClass('navbar-hidden navbar-large-hidden'); | |
5d51ea26 DC |
12140 | $el.trigger('navbar:show'); |
12141 | app.emit('navbarShow', $el[0]); | |
5309fbda DC |
12142 | }, |
12143 | getElByPage: function getElByPage(page) { | |
12144 | var $pageEl; | |
12145 | var $navbarInnerEl; | |
12146 | var pageData; | |
12147 | if (page.$navbarEl || page.$el) { | |
12148 | pageData = page; | |
12149 | $pageEl = page.$el; | |
12150 | } else { | |
12151 | $pageEl = $(page); | |
12152 | if ($pageEl.length > 0) { pageData = $pageEl[0].f7Page; } | |
12153 | } | |
12154 | if (pageData && pageData.$navbarEl && pageData.$navbarEl.length > 0) { | |
12155 | $navbarInnerEl = pageData.$navbarEl; | |
12156 | } else if ($pageEl) { | |
12157 | $navbarInnerEl = $pageEl.children('.navbar').children('.navbar-inner'); | |
12158 | } | |
12159 | if (!$navbarInnerEl || ($navbarInnerEl && $navbarInnerEl.length === 0)) { return undefined; } | |
12160 | return $navbarInnerEl[0]; | |
12161 | }, | |
12162 | getPageByEl: function getPageByEl(navbarInnerEl) { | |
12163 | var $navbarInnerEl = $(navbarInnerEl); | |
12164 | if ($navbarInnerEl.hasClass('navbar')) { | |
12165 | $navbarInnerEl = $navbarInnerEl.find('.navbar-inner'); | |
12166 | if ($navbarInnerEl.length > 1) { return undefined; } | |
12167 | } | |
12168 | if ($navbarInnerEl.parents('.page').length) { | |
12169 | return $navbarInnerEl.parents('.page')[0]; | |
12170 | } | |
12171 | var pageEl; | |
12172 | $navbarInnerEl.parents('.view').find('.page').each(function (index, el) { | |
12173 | if (el && el.f7Page && el.f7Page.navbarEl && $navbarInnerEl[0] === el.f7Page.navbarEl) { | |
12174 | pageEl = el; | |
12175 | } | |
12176 | }); | |
12177 | return pageEl; | |
12178 | }, | |
12179 | ||
12180 | collapseLargeTitle: function collapseLargeTitle(navbarInnerEl) { | |
12181 | var app = this; | |
12182 | var $navbarInnerEl = $(navbarInnerEl); | |
12183 | if ($navbarInnerEl.hasClass('navbar')) { | |
12184 | $navbarInnerEl = $navbarInnerEl.find('.navbar-inner-large'); | |
12185 | if ($navbarInnerEl.length > 1) { | |
12186 | $navbarInnerEl = $(navbarInnerEl).find('.navbar-inner-large.navbar-current'); | |
12187 | } | |
12188 | if ($navbarInnerEl.length > 1 || !$navbarInnerEl.length) { | |
12189 | return; | |
12190 | } | |
12191 | } | |
12192 | var $pageEl = $(app.navbar.getPageByEl($navbarInnerEl)); | |
12193 | $navbarInnerEl.addClass('navbar-inner-large-collapsed'); | |
12194 | $pageEl.eq(0).addClass('page-with-navbar-large-collapsed').trigger('page:navbarlargecollapsed'); | |
5d51ea26 DC |
12195 | app.emit('pageNavbarLargeCollapsed', $pageEl[0]); |
12196 | var $navbarEl = $navbarInnerEl.parents('.navbar'); | |
12197 | if (app.theme === 'md' || app.theme === 'aurora') { | |
12198 | $navbarEl.addClass('navbar-large-collapsed'); | |
5309fbda | 12199 | } |
5d51ea26 DC |
12200 | $navbarEl.trigger('navbar:collapse'); |
12201 | app.emit('navbarCollapse', $navbarEl[0]); | |
5309fbda DC |
12202 | }, |
12203 | expandLargeTitle: function expandLargeTitle(navbarInnerEl) { | |
12204 | var app = this; | |
12205 | var $navbarInnerEl = $(navbarInnerEl); | |
12206 | if ($navbarInnerEl.hasClass('navbar')) { | |
12207 | $navbarInnerEl = $navbarInnerEl.find('.navbar-inner-large'); | |
12208 | if ($navbarInnerEl.length > 1) { | |
12209 | $navbarInnerEl = $(navbarInnerEl).find('.navbar-inner-large.navbar-current'); | |
12210 | } | |
12211 | if ($navbarInnerEl.length > 1 || !$navbarInnerEl.length) { | |
12212 | return; | |
12213 | } | |
12214 | } | |
12215 | var $pageEl = $(app.navbar.getPageByEl($navbarInnerEl)); | |
12216 | $navbarInnerEl.removeClass('navbar-inner-large-collapsed'); | |
12217 | $pageEl.eq(0).removeClass('page-with-navbar-large-collapsed').trigger('page:navbarlargeexpanded'); | |
5d51ea26 DC |
12218 | app.emit('pageNavbarLargeExpanded', $pageEl[0]); |
12219 | var $navbarEl = $navbarInnerEl.parents('.navbar'); | |
12220 | if (app.theme === 'md' || app.theme === 'aurora') { | |
12221 | $navbarEl.removeClass('navbar-large-collapsed'); | |
5309fbda | 12222 | } |
5d51ea26 DC |
12223 | $navbarEl.trigger('navbar:expand'); |
12224 | app.emit('navbarExpand', $navbarEl[0]); | |
5309fbda DC |
12225 | }, |
12226 | toggleLargeTitle: function toggleLargeTitle(navbarInnerEl) { | |
12227 | var app = this; | |
12228 | var $navbarInnerEl = $(navbarInnerEl); | |
12229 | if ($navbarInnerEl.hasClass('navbar')) { | |
12230 | $navbarInnerEl = $navbarInnerEl.find('.navbar-inner-large'); | |
12231 | if ($navbarInnerEl.length > 1) { | |
12232 | $navbarInnerEl = $(navbarInnerEl).find('.navbar-inner-large.navbar-current'); | |
12233 | } | |
12234 | if ($navbarInnerEl.length > 1 || !$navbarInnerEl.length) { | |
12235 | return; | |
12236 | } | |
12237 | } | |
12238 | if ($navbarInnerEl.hasClass('navbar-inner-large-collapsed')) { | |
12239 | app.navbar.expandLargeTitle($navbarInnerEl); | |
12240 | } else { | |
12241 | app.navbar.collapseLargeTitle($navbarInnerEl); | |
12242 | } | |
12243 | }, | |
12244 | initNavbarOnScroll: function initNavbarOnScroll(pageEl, navbarInnerEl, needHide, needCollapse) { | |
12245 | var app = this; | |
12246 | var $pageEl = $(pageEl); | |
12247 | var $navbarInnerEl = $(navbarInnerEl); | |
5d51ea26 | 12248 | var $navbarEl = app.theme === 'md' || app.theme === 'aurora' |
5309fbda DC |
12249 | ? $navbarInnerEl.parents('.navbar') |
12250 | : $(navbarInnerEl || app.navbar.getElByPage(pageEl)).closest('.navbar'); | |
12251 | var isLarge = $navbarInnerEl.find('.title-large').length || $navbarInnerEl.hasClass('.navbar-inner-large'); | |
12252 | var navbarHideHeight = 44; | |
12253 | var snapPageScrollToLargeTitle = app.params.navbar.snapPageScrollToLargeTitle; | |
12254 | ||
12255 | var previousScrollTop; | |
12256 | var currentScrollTop; | |
12257 | ||
12258 | var scrollHeight; | |
12259 | var offsetHeight; | |
12260 | var reachEnd; | |
12261 | var action; | |
12262 | var navbarHidden; | |
12263 | ||
12264 | var navbarCollapsed; | |
12265 | var navbarTitleLargeHeight; | |
12266 | if (needCollapse || (needHide && isLarge)) { | |
12267 | navbarTitleLargeHeight = $navbarInnerEl.css('--f7-navbar-large-title-height'); | |
12268 | if (navbarTitleLargeHeight && navbarTitleLargeHeight.indexOf('px') >= 0) { | |
12269 | navbarTitleLargeHeight = parseInt(navbarTitleLargeHeight, 10); | |
12270 | if (Number.isNaN(navbarTitleLargeHeight)) { | |
5d51ea26 DC |
12271 | if (app.theme === 'ios') { navbarTitleLargeHeight = 52; } |
12272 | else if (app.theme === 'md') { navbarTitleLargeHeight = 48; } | |
12273 | else if (app.theme === 'aurora') { navbarTitleLargeHeight = 38; } | |
5309fbda | 12274 | } |
5d51ea26 DC |
12275 | } else { // eslint-disable-next-line |
12276 | if (app.theme === 'ios') { navbarTitleLargeHeight = 52; } | |
12277 | else if (app.theme === 'md') { navbarTitleLargeHeight = 48; } | |
12278 | else if (app.theme === 'aurora') { navbarTitleLargeHeight = 38; } | |
5309fbda DC |
12279 | } |
12280 | } | |
12281 | if (needHide && isLarge) { | |
12282 | navbarHideHeight += navbarTitleLargeHeight; | |
12283 | } | |
12284 | ||
12285 | var scrollChanged; | |
12286 | var scrollContent; | |
12287 | var scrollTimeoutId; | |
12288 | var touchEndTimeoutId; | |
12289 | var touchSnapTimeout = 70; | |
12290 | var desktopSnapTimeout = 300; | |
12291 | ||
12292 | function snapLargeNavbar() { | |
12293 | var inSearchbarExpanded = $navbarInnerEl.hasClass('with-searchbar-expandable-enabled'); | |
12294 | if (inSearchbarExpanded) { return; } | |
12295 | if (!scrollContent || currentScrollTop < 0) { return; } | |
12296 | if (currentScrollTop >= navbarTitleLargeHeight / 2 && currentScrollTop < navbarTitleLargeHeight) { | |
12297 | $(scrollContent).scrollTop(navbarTitleLargeHeight, 100); | |
12298 | } else if (currentScrollTop < navbarTitleLargeHeight) { | |
12299 | $(scrollContent).scrollTop(0, 200); | |
12300 | } | |
12301 | } | |
12302 | ||
12303 | function handleLargeNavbarCollapse() { | |
12304 | var collapseProgress = Math.min(Math.max((currentScrollTop / navbarTitleLargeHeight), 0), 1); | |
12305 | var inSearchbarExpanded = $navbarInnerEl.hasClass('with-searchbar-expandable-enabled'); | |
12306 | if (inSearchbarExpanded) { return; } | |
12307 | navbarCollapsed = $navbarInnerEl.hasClass('navbar-inner-large-collapsed'); | |
12308 | if (collapseProgress === 0 && navbarCollapsed) { | |
12309 | app.navbar.expandLargeTitle($navbarInnerEl[0]); | |
12310 | $navbarInnerEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
12311 | $pageEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
12312 | $navbarInnerEl[0].style.overflow = ''; | |
5d51ea26 | 12313 | if (app.theme === 'md' || app.theme === 'aurora') { |
5309fbda DC |
12314 | $navbarEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); |
12315 | } | |
12316 | } else if (collapseProgress === 1 && !navbarCollapsed) { | |
12317 | app.navbar.collapseLargeTitle($navbarInnerEl[0]); | |
12318 | $navbarInnerEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
12319 | $navbarInnerEl[0].style.overflow = ''; | |
12320 | $pageEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
5d51ea26 | 12321 | if (app.theme === 'md' || app.theme === 'aurora') { |
5309fbda DC |
12322 | $navbarEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); |
12323 | } | |
12324 | } else if ((collapseProgress === 1 && navbarCollapsed) || (collapseProgress === 0 && !navbarCollapsed)) { | |
12325 | $navbarInnerEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
12326 | $navbarInnerEl[0].style.overflow = ''; | |
12327 | $pageEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); | |
5d51ea26 | 12328 | if (app.theme === 'md' || app.theme === 'aurora') { |
5309fbda DC |
12329 | $navbarEl[0].style.removeProperty('--f7-navbar-large-collapse-progress'); |
12330 | } | |
12331 | } else { | |
12332 | $navbarInnerEl[0].style.setProperty('--f7-navbar-large-collapse-progress', collapseProgress); | |
12333 | $navbarInnerEl[0].style.overflow = 'visible'; | |
12334 | $pageEl[0].style.setProperty('--f7-navbar-large-collapse-progress', collapseProgress); | |
5d51ea26 | 12335 | if (app.theme === 'md' || app.theme === 'aurora') { |
5309fbda DC |
12336 | $navbarEl[0].style.setProperty('--f7-navbar-large-collapse-progress', collapseProgress); |
12337 | } | |
12338 | } | |
12339 | ||
12340 | if (snapPageScrollToLargeTitle) { | |
12341 | if (!Support.touch) { | |
12342 | clearTimeout(scrollTimeoutId); | |
12343 | scrollTimeoutId = setTimeout(function () { | |
12344 | snapLargeNavbar(); | |
12345 | }, desktopSnapTimeout); | |
12346 | } else if (touchEndTimeoutId) { | |
12347 | clearTimeout(touchEndTimeoutId); | |
12348 | touchEndTimeoutId = null; | |
12349 | touchEndTimeoutId = setTimeout(function () { | |
12350 | snapLargeNavbar(); | |
12351 | clearTimeout(touchEndTimeoutId); | |
12352 | touchEndTimeoutId = null; | |
12353 | }, touchSnapTimeout); | |
12354 | } | |
12355 | } | |
12356 | } | |
12357 | ||
12358 | function handleTitleHideShow() { | |
12359 | scrollHeight = scrollContent.scrollHeight; | |
12360 | offsetHeight = scrollContent.offsetHeight; | |
12361 | reachEnd = currentScrollTop + offsetHeight >= scrollHeight; | |
12362 | navbarHidden = $navbarEl.hasClass('navbar-hidden'); | |
12363 | ||
12364 | if (reachEnd) { | |
12365 | if (app.params.navbar.showOnPageScrollEnd) { | |
12366 | action = 'show'; | |
12367 | } | |
12368 | } else if (previousScrollTop > currentScrollTop) { | |
12369 | if (app.params.navbar.showOnPageScrollTop || currentScrollTop <= navbarHideHeight) { | |
12370 | action = 'show'; | |
12371 | } else { | |
12372 | action = 'hide'; | |
12373 | } | |
12374 | } else if (currentScrollTop > navbarHideHeight) { | |
12375 | action = 'hide'; | |
12376 | } else { | |
12377 | action = 'show'; | |
12378 | } | |
12379 | ||
12380 | if (action === 'show' && navbarHidden) { | |
12381 | app.navbar.show($navbarEl); | |
12382 | navbarHidden = false; | |
12383 | } else if (action === 'hide' && !navbarHidden) { | |
12384 | app.navbar.hide($navbarEl); | |
12385 | navbarHidden = true; | |
12386 | } | |
12387 | previousScrollTop = currentScrollTop; | |
12388 | } | |
12389 | ||
12390 | function handleScroll() { | |
12391 | scrollContent = this; | |
12392 | currentScrollTop = scrollContent.scrollTop; | |
12393 | scrollChanged = currentScrollTop; | |
12394 | ||
12395 | if (needCollapse) { | |
12396 | handleLargeNavbarCollapse(); | |
12397 | } | |
12398 | if ($pageEl.hasClass('page-previous')) { return; } | |
12399 | if (needHide) { | |
12400 | handleTitleHideShow(); | |
12401 | } | |
12402 | } | |
12403 | function handeTouchStart() { | |
12404 | scrollChanged = false; | |
12405 | } | |
12406 | function handleTouchEnd() { | |
12407 | clearTimeout(touchEndTimeoutId); | |
12408 | touchEndTimeoutId = null; | |
12409 | touchEndTimeoutId = setTimeout(function () { | |
12410 | if (scrollChanged !== false) { | |
12411 | snapLargeNavbar(); | |
12412 | clearTimeout(touchEndTimeoutId); | |
12413 | touchEndTimeoutId = null; | |
12414 | } | |
12415 | }, touchSnapTimeout); | |
12416 | } | |
12417 | $pageEl.on('scroll', '.page-content', handleScroll, true); | |
12418 | if (Support.touch && needCollapse && snapPageScrollToLargeTitle) { | |
12419 | app.on('touchstart:passive', handeTouchStart); | |
12420 | app.on('touchend:passive', handleTouchEnd); | |
12421 | } | |
12422 | if (needCollapse) { | |
12423 | $pageEl.find('.page-content').each(function (pageContentIndex, pageContentEl) { | |
12424 | if (pageContentEl.scrollTop > 0) { handleScroll.call(pageContentEl); } | |
12425 | }); | |
12426 | } | |
12427 | $pageEl[0].f7DetachNavbarScrollHandlers = function f7DetachNavbarScrollHandlers() { | |
12428 | delete $pageEl[0].f7DetachNavbarScrollHandlers; | |
12429 | $pageEl.off('scroll', '.page-content', handleScroll, true); | |
12430 | if (Support.touch && needCollapse && snapPageScrollToLargeTitle) { | |
12431 | app.off('touchstart:passive', handeTouchStart); | |
12432 | app.off('touchend:passive', handleTouchEnd); | |
12433 | } | |
12434 | }; | |
12435 | }, | |
12436 | }; | |
12437 | var Navbar$1 = { | |
12438 | name: 'navbar', | |
12439 | create: function create() { | |
12440 | var app = this; | |
12441 | Utils.extend(app, { | |
12442 | navbar: { | |
12443 | size: Navbar.size.bind(app), | |
12444 | hide: Navbar.hide.bind(app), | |
12445 | show: Navbar.show.bind(app), | |
12446 | getElByPage: Navbar.getElByPage.bind(app), | |
12447 | getPageByEl: Navbar.getPageByEl.bind(app), | |
12448 | collapseLargeTitle: Navbar.collapseLargeTitle.bind(app), | |
12449 | expandLargeTitle: Navbar.expandLargeTitle.bind(app), | |
12450 | toggleLargeTitle: Navbar.toggleLargeTitle.bind(app), | |
12451 | initNavbarOnScroll: Navbar.initNavbarOnScroll.bind(app), | |
12452 | }, | |
12453 | }); | |
12454 | }, | |
12455 | params: { | |
12456 | navbar: { | |
12457 | scrollTopOnTitleClick: true, | |
12458 | iosCenterTitle: true, | |
12459 | mdCenterTitle: false, | |
5d51ea26 | 12460 | auroraCenterTitle: true, |
5309fbda DC |
12461 | hideOnPageScroll: false, |
12462 | showOnPageScrollEnd: true, | |
12463 | showOnPageScrollTop: true, | |
12464 | collapseLargeTitleOnScroll: true, | |
12465 | snapPageScrollToLargeTitle: true, | |
12466 | }, | |
12467 | }, | |
12468 | on: { | |
5d51ea26 | 12469 | 'panelBreakpoint panelResize resize viewMasterDetailBreakpoint': function onResize() { |
5309fbda DC |
12470 | var app = this; |
12471 | $('.navbar').each(function (index, navbarEl) { | |
12472 | app.navbar.size(navbarEl); | |
12473 | }); | |
12474 | }, | |
12475 | pageBeforeRemove: function pageBeforeRemove(page) { | |
12476 | if (page.$el[0].f7DetachNavbarScrollHandlers) { | |
12477 | page.$el[0].f7DetachNavbarScrollHandlers(); | |
12478 | } | |
12479 | }, | |
12480 | pageBeforeIn: function pageBeforeIn(page) { | |
12481 | var app = this; | |
12482 | if (app.theme !== 'ios') { return; } | |
12483 | var $navbarEl; | |
12484 | var view = page.$el.parents('.view')[0].f7View; | |
12485 | var navbarInnerEl = app.navbar.getElByPage(page); | |
12486 | if (!navbarInnerEl) { | |
12487 | $navbarEl = page.$el.parents('.view').children('.navbar'); | |
12488 | } else { | |
12489 | $navbarEl = $(navbarInnerEl).parents('.navbar'); | |
12490 | } | |
12491 | if (page.$el.hasClass('no-navbar') || (view.router.dynamicNavbar && !navbarInnerEl)) { | |
12492 | var animate = !!(page.pageFrom && page.router.history.length > 0); | |
12493 | app.navbar.hide($navbarEl, animate); | |
12494 | } else { | |
12495 | app.navbar.show($navbarEl); | |
12496 | } | |
12497 | }, | |
12498 | pageReinit: function pageReinit(page) { | |
12499 | var app = this; | |
12500 | var $navbarInnerEl = $(app.navbar.getElByPage(page)); | |
12501 | if (!$navbarInnerEl || $navbarInnerEl.length === 0) { return; } | |
12502 | app.navbar.size($navbarInnerEl); | |
12503 | }, | |
12504 | pageInit: function pageInit(page) { | |
12505 | var app = this; | |
12506 | var $navbarInnerEl = $(app.navbar.getElByPage(page)); | |
12507 | if (!$navbarInnerEl || $navbarInnerEl.length === 0) { return; } | |
12508 | ||
12509 | // Size | |
12510 | app.navbar.size($navbarInnerEl); | |
12511 | ||
12512 | // Need Collapse On Scroll | |
12513 | var needCollapseOnScrollHandler; | |
12514 | if ($navbarInnerEl.children('.title-large').length > 0) { | |
12515 | $navbarInnerEl.addClass('navbar-inner-large'); | |
12516 | } | |
12517 | if ($navbarInnerEl.hasClass('navbar-inner-large')) { | |
12518 | if (app.params.navbar.collapseLargeTitleOnScroll) { needCollapseOnScrollHandler = true; } | |
5d51ea26 | 12519 | if (app.theme === 'md' || app.theme === 'aurora') { |
5309fbda DC |
12520 | $navbarInnerEl.parents('.navbar').addClass('navbar-large'); |
12521 | } | |
12522 | page.$el.addClass('page-with-navbar-large'); | |
12523 | } | |
12524 | ||
12525 | // Need Hide On Scroll | |
12526 | var needHideOnScrollHandler; | |
12527 | if ( | |
12528 | app.params.navbar.hideOnPageScroll | |
12529 | || page.$el.find('.hide-navbar-on-scroll').length | |
12530 | || page.$el.hasClass('hide-navbar-on-scroll') | |
12531 | || page.$el.find('.hide-bars-on-scroll').length | |
12532 | || page.$el.hasClass('hide-bars-on-scroll') | |
12533 | ) { | |
12534 | if ( | |
12535 | page.$el.find('.keep-navbar-on-scroll').length | |
12536 | || page.$el.hasClass('keep-navbar-on-scroll') | |
12537 | || page.$el.find('.keep-bars-on-scroll').length | |
12538 | || page.$el.hasClass('keep-bars-on-scroll') | |
12539 | ) { | |
12540 | needHideOnScrollHandler = false; | |
12541 | } else { | |
12542 | needHideOnScrollHandler = true; | |
12543 | } | |
12544 | } | |
12545 | ||
12546 | if (needCollapseOnScrollHandler || needHideOnScrollHandler) { | |
12547 | app.navbar.initNavbarOnScroll(page.el, $navbarInnerEl[0], needHideOnScrollHandler, needCollapseOnScrollHandler); | |
12548 | } | |
12549 | }, | |
12550 | modalOpen: function modalOpen(modal) { | |
12551 | var app = this; | |
5d51ea26 | 12552 | if (!app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12553 | return; |
12554 | } | |
12555 | modal.$el.find('.navbar:not(.navbar-previous):not(.stacked)').each(function (index, navbarEl) { | |
12556 | app.navbar.size(navbarEl); | |
12557 | }); | |
12558 | }, | |
12559 | panelOpen: function panelOpen(panel) { | |
12560 | var app = this; | |
5d51ea26 | 12561 | if (!app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12562 | return; |
12563 | } | |
12564 | panel.$el.find('.navbar:not(.navbar-previous):not(.stacked)').each(function (index, navbarEl) { | |
12565 | app.navbar.size(navbarEl); | |
12566 | }); | |
12567 | }, | |
12568 | panelSwipeOpen: function panelSwipeOpen(panel) { | |
12569 | var app = this; | |
5d51ea26 | 12570 | if (!app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12571 | return; |
12572 | } | |
12573 | panel.$el.find('.navbar:not(.navbar-previous):not(.stacked)').each(function (index, navbarEl) { | |
12574 | app.navbar.size(navbarEl); | |
12575 | }); | |
12576 | }, | |
12577 | tabShow: function tabShow(tabEl) { | |
12578 | var app = this; | |
5d51ea26 | 12579 | if (!app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12580 | return; |
12581 | } | |
12582 | $(tabEl).find('.navbar:not(.navbar-previous):not(.stacked)').each(function (index, navbarEl) { | |
12583 | app.navbar.size(navbarEl); | |
12584 | }); | |
12585 | }, | |
12586 | }, | |
12587 | clicks: { | |
12588 | '.navbar .title': function onTitleClick($clickedEl) { | |
12589 | var app = this; | |
12590 | if (!app.params.navbar.scrollTopOnTitleClick) { return; } | |
12591 | if ($clickedEl.closest('a').length > 0) { | |
12592 | return; | |
12593 | } | |
12594 | var pageContent; | |
12595 | // Find active page | |
12596 | var navbar = $clickedEl.parents('.navbar'); | |
12597 | ||
12598 | // Static Layout | |
12599 | pageContent = navbar.parents('.page-content'); | |
12600 | ||
12601 | if (pageContent.length === 0) { | |
12602 | // Fixed Layout | |
12603 | if (navbar.parents('.page').length > 0) { | |
12604 | pageContent = navbar.parents('.page').find('.page-content'); | |
12605 | } | |
12606 | // Through Layout | |
12607 | if (pageContent.length === 0) { | |
12608 | if (navbar.nextAll('.page-current:not(.stacked)').length > 0) { | |
12609 | pageContent = navbar.nextAll('.page-current:not(.stacked)').find('.page-content'); | |
12610 | } | |
12611 | } | |
12612 | } | |
12613 | if (pageContent && pageContent.length > 0) { | |
12614 | // Check for tab | |
12615 | if (pageContent.hasClass('tab')) { | |
12616 | pageContent = pageContent.parent('.tabs').children('.page-content.tab-active'); | |
12617 | } | |
12618 | if (pageContent.length > 0) { pageContent.scrollTop(0, 300); } | |
12619 | } | |
12620 | }, | |
12621 | }, | |
12622 | vnode: { | |
12623 | 'navbar-inner': { | |
12624 | postpatch: function postpatch(vnode) { | |
12625 | var app = this; | |
5d51ea26 | 12626 | if (!app.params.navbar[((app.theme) + "CenterTitle")]) { |
5309fbda DC |
12627 | return; |
12628 | } | |
12629 | app.navbar.size(vnode.elm); | |
12630 | }, | |
12631 | }, | |
12632 | }, | |
12633 | }; | |
12634 | ||
12635 | var Toolbar = { | |
12636 | setHighlight: function setHighlight(tabbarEl) { | |
12637 | var app = this; | |
12638 | if (app.theme !== 'md') { return; } | |
12639 | ||
12640 | var $tabbarEl = $(tabbarEl); | |
12641 | ||
12642 | if ($tabbarEl.length === 0 || !($tabbarEl.hasClass('tabbar') || $tabbarEl.hasClass('tabbar-labels'))) { return; } | |
12643 | ||
12644 | var $highlightEl = $tabbarEl.find('.tab-link-highlight'); | |
12645 | var tabLinksCount = $tabbarEl.find('.tab-link').length; | |
12646 | if (tabLinksCount === 0) { | |
12647 | $highlightEl.remove(); | |
12648 | return; | |
12649 | } | |
12650 | ||
12651 | if ($highlightEl.length === 0) { | |
12652 | $tabbarEl.children('.toolbar-inner').append('<span class="tab-link-highlight"></span>'); | |
12653 | $highlightEl = $tabbarEl.find('.tab-link-highlight'); | |
12654 | } else if ($highlightEl.next().length) { | |
12655 | $tabbarEl.children('.toolbar-inner').append($highlightEl); | |
12656 | } | |
12657 | ||
12658 | var $activeLink = $tabbarEl.find('.tab-link-active'); | |
12659 | var highlightWidth; | |
12660 | var highlightTranslate; | |
12661 | ||
12662 | if ($tabbarEl.hasClass('tabbar-scrollable') && $activeLink && $activeLink[0]) { | |
12663 | highlightWidth = ($activeLink[0].offsetWidth) + "px"; | |
12664 | highlightTranslate = ($activeLink[0].offsetLeft) + "px"; | |
12665 | } else { | |
12666 | var activeIndex = $activeLink.index(); | |
12667 | highlightWidth = (100 / tabLinksCount) + "%"; | |
12668 | highlightTranslate = ((app.rtl ? -activeIndex : activeIndex) * 100) + "%"; | |
12669 | } | |
12670 | ||
12671 | Utils.nextFrame(function () { | |
12672 | $highlightEl | |
12673 | .css('width', highlightWidth) | |
12674 | .transform(("translate3d(" + highlightTranslate + ",0,0)")); | |
12675 | }); | |
12676 | }, | |
12677 | init: function init(tabbarEl) { | |
12678 | var app = this; | |
12679 | app.toolbar.setHighlight(tabbarEl); | |
12680 | }, | |
12681 | hide: function hide(el, animate) { | |
12682 | if ( animate === void 0 ) animate = true; | |
12683 | ||
12684 | var $el = $(el); | |
12685 | if ($el.hasClass('toolbar-hidden')) { return; } | |
12686 | var className = "toolbar-hidden" + (animate ? ' toolbar-transitioning' : ''); | |
12687 | $el.transitionEnd(function () { | |
12688 | $el.removeClass('toolbar-transitioning'); | |
12689 | }); | |
12690 | $el.addClass(className); | |
12691 | }, | |
12692 | show: function show(el, animate) { | |
12693 | if ( animate === void 0 ) animate = true; | |
12694 | ||
12695 | var $el = $(el); | |
12696 | if (!$el.hasClass('toolbar-hidden')) { return; } | |
12697 | if (animate) { | |
12698 | $el.addClass('toolbar-transitioning'); | |
12699 | $el.transitionEnd(function () { | |
12700 | $el.removeClass('toolbar-transitioning'); | |
12701 | }); | |
12702 | } | |
12703 | $el.removeClass('toolbar-hidden'); | |
12704 | }, | |
12705 | initHideToolbarOnScroll: function initHideToolbarOnScroll(pageEl) { | |
12706 | var app = this; | |
12707 | var $pageEl = $(pageEl); | |
12708 | var $toolbarEl = $pageEl.parents('.view').children('.toolbar'); | |
12709 | if ($toolbarEl.length === 0) { | |
12710 | $toolbarEl = $pageEl.find('.toolbar'); | |
12711 | } | |
12712 | if ($toolbarEl.length === 0) { | |
12713 | $toolbarEl = $pageEl.parents('.views').children('.tabbar, .tabbar-labels'); | |
12714 | } | |
12715 | if ($toolbarEl.length === 0) { | |
12716 | return; | |
12717 | } | |
12718 | ||
12719 | var previousScrollTop; | |
12720 | var currentScrollTop; | |
12721 | ||
12722 | var scrollHeight; | |
12723 | var offsetHeight; | |
12724 | var reachEnd; | |
12725 | var action; | |
12726 | var toolbarHidden; | |
12727 | function handleScroll() { | |
12728 | var scrollContent = this; | |
12729 | if ($pageEl.hasClass('page-previous')) { return; } | |
12730 | currentScrollTop = scrollContent.scrollTop; | |
12731 | scrollHeight = scrollContent.scrollHeight; | |
12732 | offsetHeight = scrollContent.offsetHeight; | |
12733 | reachEnd = currentScrollTop + offsetHeight >= scrollHeight; | |
12734 | toolbarHidden = $toolbarEl.hasClass('toolbar-hidden'); | |
12735 | ||
12736 | if (reachEnd) { | |
12737 | if (app.params.toolbar.showOnPageScrollEnd) { | |
12738 | action = 'show'; | |
12739 | } | |
12740 | } else if (previousScrollTop > currentScrollTop) { | |
12741 | if (app.params.toolbar.showOnPageScrollTop || currentScrollTop <= 44) { | |
12742 | action = 'show'; | |
12743 | } else { | |
12744 | action = 'hide'; | |
12745 | } | |
12746 | } else if (currentScrollTop > 44) { | |
12747 | action = 'hide'; | |
12748 | } else { | |
12749 | action = 'show'; | |
12750 | } | |
12751 | ||
12752 | if (action === 'show' && toolbarHidden) { | |
12753 | app.toolbar.show($toolbarEl); | |
12754 | toolbarHidden = false; | |
12755 | } else if (action === 'hide' && !toolbarHidden) { | |
12756 | app.toolbar.hide($toolbarEl); | |
12757 | toolbarHidden = true; | |
12758 | } | |
12759 | ||
12760 | previousScrollTop = currentScrollTop; | |
12761 | } | |
12762 | $pageEl.on('scroll', '.page-content', handleScroll, true); | |
12763 | $pageEl[0].f7ScrollToolbarHandler = handleScroll; | |
12764 | }, | |
12765 | }; | |
12766 | var Toolbar$1 = { | |
12767 | name: 'toolbar', | |
12768 | create: function create() { | |
12769 | var app = this; | |
12770 | Utils.extend(app, { | |
12771 | toolbar: { | |
12772 | hide: Toolbar.hide.bind(app), | |
12773 | show: Toolbar.show.bind(app), | |
12774 | setHighlight: Toolbar.setHighlight.bind(app), | |
12775 | initHideToolbarOnScroll: Toolbar.initHideToolbarOnScroll.bind(app), | |
12776 | init: Toolbar.init.bind(app), | |
12777 | }, | |
12778 | }); | |
12779 | }, | |
12780 | params: { | |
12781 | toolbar: { | |
12782 | hideOnPageScroll: false, | |
12783 | showOnPageScrollEnd: true, | |
12784 | showOnPageScrollTop: true, | |
12785 | }, | |
12786 | }, | |
12787 | on: { | |
12788 | pageBeforeRemove: function pageBeforeRemove(page) { | |
12789 | if (page.$el[0].f7ScrollToolbarHandler) { | |
12790 | page.$el.off('scroll', '.page-content', page.$el[0].f7ScrollToolbarHandler, true); | |
12791 | } | |
12792 | }, | |
12793 | pageBeforeIn: function pageBeforeIn(page) { | |
12794 | var app = this; | |
12795 | var $toolbarEl = page.$el.parents('.view').children('.toolbar'); | |
12796 | if ($toolbarEl.length === 0) { | |
12797 | $toolbarEl = page.$el.parents('.views').children('.tabbar, .tabbar-labels'); | |
12798 | } | |
12799 | if ($toolbarEl.length === 0) { | |
12800 | $toolbarEl = page.$el.find('.toolbar'); | |
12801 | } | |
12802 | if ($toolbarEl.length === 0) { | |
12803 | return; | |
12804 | } | |
12805 | if (page.$el.hasClass('no-toolbar')) { | |
12806 | app.toolbar.hide($toolbarEl); | |
12807 | } else { | |
12808 | app.toolbar.show($toolbarEl); | |
12809 | } | |
12810 | }, | |
12811 | pageInit: function pageInit(page) { | |
12812 | var app = this; | |
12813 | page.$el.find('.tabbar, .tabbar-labels').each(function (index, tabbarEl) { | |
12814 | app.toolbar.init(tabbarEl); | |
12815 | }); | |
12816 | if ( | |
12817 | app.params.toolbar.hideOnPageScroll | |
12818 | || page.$el.find('.hide-toolbar-on-scroll').length | |
12819 | || page.$el.hasClass('hide-toolbar-on-scroll') | |
12820 | || page.$el.find('.hide-bars-on-scroll').length | |
12821 | || page.$el.hasClass('hide-bars-on-scroll') | |
12822 | ) { | |
12823 | if ( | |
12824 | page.$el.find('.keep-toolbar-on-scroll').length | |
12825 | || page.$el.hasClass('keep-toolbar-on-scroll') | |
12826 | || page.$el.find('.keep-bars-on-scroll').length | |
12827 | || page.$el.hasClass('keep-bars-on-scroll') | |
12828 | ) { | |
12829 | return; | |
12830 | } | |
12831 | app.toolbar.initHideToolbarOnScroll(page.el); | |
12832 | } | |
12833 | }, | |
12834 | init: function init() { | |
12835 | var app = this; | |
12836 | app.root.find('.tabbar, .tabbar-labels').each(function (index, tabbarEl) { | |
12837 | app.toolbar.init(tabbarEl); | |
12838 | }); | |
12839 | }, | |
12840 | }, | |
12841 | }; | |
12842 | ||
12843 | var Subnavbar = { | |
12844 | name: 'subnavbar', | |
12845 | on: { | |
12846 | pageInit: function pageInit(page) { | |
12847 | if (page.$navbarEl && page.$navbarEl.length && page.$navbarEl.find('.subnavbar').length) { | |
12848 | page.$el.addClass('page-with-subnavbar'); | |
12849 | } | |
12850 | if (page.$el.find('.subnavbar').length) { | |
12851 | page.$el.addClass('page-with-subnavbar'); | |
12852 | } | |
12853 | }, | |
12854 | }, | |
12855 | }; | |
12856 | ||
12857 | var TouchRipple = function TouchRipple($el, x, y) { | |
12858 | var ripple = this; | |
12859 | if (!$el) { return undefined; } | |
12860 | var box = $el[0].getBoundingClientRect(); | |
12861 | var center = { | |
12862 | x: x - box.left, | |
12863 | y: y - box.top, | |
12864 | }; | |
12865 | var width = box.width; | |
12866 | var height = box.height; | |
12867 | var diameter = Math.max((Math.pow( ((Math.pow( height, 2 )) + (Math.pow( width, 2 ))), 0.5 )), 48); | |
12868 | ||
12869 | ripple.$rippleWaveEl = $(("<div class=\"ripple-wave\" style=\"width: " + diameter + "px; height: " + diameter + "px; margin-top:-" + (diameter / 2) + "px; margin-left:-" + (diameter / 2) + "px; left:" + (center.x) + "px; top:" + (center.y) + "px;\"></div>")); | |
12870 | ||
12871 | $el.prepend(ripple.$rippleWaveEl); | |
12872 | ||
5309fbda DC |
12873 | ripple.rippleTransform = "translate3d(" + (-center.x + (width / 2)) + "px, " + (-center.y + (height / 2)) + "px, 0) scale(1)"; |
12874 | ||
12875 | Utils.nextFrame(function () { | |
12876 | if (!ripple || !ripple.$rippleWaveEl) { return; } | |
12877 | ripple.$rippleWaveEl.transform(ripple.rippleTransform); | |
12878 | }); | |
12879 | ||
12880 | return ripple; | |
12881 | }; | |
12882 | ||
5d51ea26 | 12883 | TouchRipple.prototype.destroy = function destroy () { |
5309fbda DC |
12884 | var ripple = this; |
12885 | if (ripple.$rippleWaveEl) { | |
12886 | ripple.$rippleWaveEl.remove(); | |
12887 | } | |
12888 | Object.keys(ripple).forEach(function (key) { | |
12889 | ripple[key] = null; | |
12890 | delete ripple[key]; | |
12891 | }); | |
12892 | ripple = null; | |
12893 | }; | |
12894 | ||
12895 | TouchRipple.prototype.remove = function remove () { | |
12896 | var ripple = this; | |
12897 | if (ripple.removing) { return; } | |
12898 | var $rippleWaveEl = this.$rippleWaveEl; | |
12899 | var rippleTransform = this.rippleTransform; | |
12900 | var removeTimeout = Utils.nextTick(function () { | |
5d51ea26 | 12901 | ripple.destroy(); |
5309fbda DC |
12902 | }, 400); |
12903 | ripple.removing = true; | |
12904 | $rippleWaveEl | |
12905 | .addClass('ripple-wave-fill') | |
12906 | .transform(rippleTransform.replace('scale(1)', 'scale(1.01)')) | |
12907 | .transitionEnd(function () { | |
12908 | clearTimeout(removeTimeout); | |
12909 | Utils.nextFrame(function () { | |
12910 | $rippleWaveEl | |
12911 | .addClass('ripple-wave-out') | |
12912 | .transform(rippleTransform.replace('scale(1)', 'scale(1.01)')); | |
12913 | ||
12914 | removeTimeout = Utils.nextTick(function () { | |
5d51ea26 | 12915 | ripple.destroy(); |
5309fbda DC |
12916 | }, 700); |
12917 | ||
12918 | $rippleWaveEl.transitionEnd(function () { | |
12919 | clearTimeout(removeTimeout); | |
5d51ea26 | 12920 | ripple.destroy(); |
5309fbda DC |
12921 | }); |
12922 | }); | |
12923 | }); | |
12924 | }; | |
12925 | ||
12926 | var TouchRipple$1 = { | |
12927 | name: 'touch-ripple', | |
12928 | static: { | |
12929 | TouchRipple: TouchRipple, | |
12930 | }, | |
12931 | create: function create() { | |
12932 | var app = this; | |
12933 | app.touchRipple = { | |
12934 | create: function create() { | |
12935 | var args = [], len = arguments.length; | |
12936 | while ( len-- ) args[ len ] = arguments[ len ]; | |
12937 | ||
12938 | return new (Function.prototype.bind.apply( TouchRipple, [ null ].concat( args) )); | |
12939 | }, | |
12940 | }; | |
12941 | }, | |
12942 | }; | |
12943 | ||
12944 | var openedModals = []; | |
12945 | var dialogsQueue = []; | |
12946 | function clearDialogsQueue() { | |
12947 | if (dialogsQueue.length === 0) { return; } | |
12948 | var dialog = dialogsQueue.shift(); | |
12949 | dialog.open(); | |
12950 | } | |
5d51ea26 | 12951 | var Modal = /*@__PURE__*/(function (Framework7Class) { |
5309fbda | 12952 | function Modal(app, params) { |
5d51ea26 | 12953 | Framework7Class.call(this, params, [app]); |
5309fbda DC |
12954 | |
12955 | var modal = this; | |
12956 | ||
12957 | var defaults = {}; | |
12958 | ||
12959 | // Extend defaults with modules params | |
12960 | modal.useModulesParams(defaults); | |
12961 | ||
12962 | modal.params = Utils.extend(defaults, params); | |
12963 | modal.opened = false; | |
12964 | ||
12965 | // Install Modules | |
12966 | modal.useModules(); | |
12967 | ||
12968 | return this; | |
12969 | } | |
12970 | ||
5d51ea26 DC |
12971 | if ( Framework7Class ) Modal.__proto__ = Framework7Class; |
12972 | Modal.prototype = Object.create( Framework7Class && Framework7Class.prototype ); | |
5309fbda DC |
12973 | Modal.prototype.constructor = Modal; |
12974 | ||
12975 | Modal.prototype.onOpen = function onOpen () { | |
12976 | var modal = this; | |
12977 | modal.opened = true; | |
12978 | openedModals.push(modal); | |
12979 | $('html').addClass(("with-modal-" + (modal.type.toLowerCase()))); | |
12980 | modal.$el.trigger(("modal:open " + (modal.type.toLowerCase()) + ":open"), modal); | |
12981 | modal.emit(("local::open modalOpen " + (modal.type) + "Open"), modal); | |
12982 | }; | |
12983 | ||
12984 | Modal.prototype.onOpened = function onOpened () { | |
12985 | var modal = this; | |
12986 | modal.$el.trigger(("modal:opened " + (modal.type.toLowerCase()) + ":opened"), modal); | |
12987 | modal.emit(("local::opened modalOpened " + (modal.type) + "Opened"), modal); | |
12988 | }; | |
12989 | ||
12990 | Modal.prototype.onClose = function onClose () { | |
12991 | var modal = this; | |
12992 | modal.opened = false; | |
12993 | if (!modal.type || !modal.$el) { return; } | |
12994 | openedModals.splice(openedModals.indexOf(modal), 1); | |
12995 | $('html').removeClass(("with-modal-" + (modal.type.toLowerCase()))); | |
12996 | modal.$el.trigger(("modal:close " + (modal.type.toLowerCase()) + ":close"), modal); | |
12997 | modal.emit(("local::close modalClose " + (modal.type) + "Close"), modal); | |
12998 | }; | |
12999 | ||
13000 | Modal.prototype.onClosed = function onClosed () { | |
13001 | var modal = this; | |
13002 | if (!modal.type || !modal.$el) { return; } | |
13003 | modal.$el.removeClass('modal-out'); | |
13004 | modal.$el.hide(); | |
13005 | modal.$el.trigger(("modal:closed " + (modal.type.toLowerCase()) + ":closed"), modal); | |
13006 | modal.emit(("local::closed modalClosed " + (modal.type) + "Closed"), modal); | |
13007 | }; | |
13008 | ||
13009 | Modal.prototype.open = function open (animateModal) { | |
13010 | var modal = this; | |
13011 | var app = modal.app; | |
13012 | var $el = modal.$el; | |
13013 | var $backdropEl = modal.$backdropEl; | |
13014 | var type = modal.type; | |
13015 | var animate = true; | |
13016 | if (typeof animateModal !== 'undefined') { animate = animateModal; } | |
13017 | else if (typeof modal.params.animate !== 'undefined') { | |
13018 | animate = modal.params.animate; | |
13019 | } | |
13020 | ||
13021 | if (!$el || $el.hasClass('modal-in')) { | |
13022 | return modal; | |
13023 | } | |
13024 | ||
13025 | if (type === 'dialog' && app.params.modal.queueDialogs) { | |
13026 | var pushToQueue; | |
13027 | if ($('.dialog.modal-in').length > 0) { | |
13028 | pushToQueue = true; | |
13029 | } else if (openedModals.length > 0) { | |
13030 | openedModals.forEach(function (openedModal) { | |
13031 | if (openedModal.type === 'dialog') { pushToQueue = true; } | |
13032 | }); | |
13033 | } | |
13034 | if (pushToQueue) { | |
13035 | dialogsQueue.push(modal); | |
13036 | return modal; | |
13037 | } | |
13038 | } | |
13039 | ||
13040 | var $modalParentEl = $el.parent(); | |
13041 | var wasInDom = $el.parents(doc).length > 0; | |
13042 | if (app.params.modal.moveToRoot && !$modalParentEl.is(app.root)) { | |
13043 | app.root.append($el); | |
13044 | modal.once((type + "Closed"), function () { | |
13045 | if (wasInDom) { | |
13046 | $modalParentEl.append($el); | |
13047 | } else { | |
13048 | $el.remove(); | |
13049 | } | |
13050 | }); | |
13051 | } | |
13052 | // Show Modal | |
13053 | $el.show(); | |
13054 | ||
13055 | /* eslint no-underscore-dangle: ["error", { "allow": ["_clientLeft"] }] */ | |
13056 | modal._clientLeft = $el[0].clientLeft; | |
13057 | ||
13058 | // Modal | |
13059 | function transitionEnd() { | |
13060 | if ($el.hasClass('modal-out')) { | |
13061 | modal.onClosed(); | |
13062 | } else if ($el.hasClass('modal-in')) { | |
13063 | modal.onOpened(); | |
13064 | } | |
13065 | } | |
13066 | if (animate) { | |
13067 | if ($backdropEl) { | |
13068 | $backdropEl.removeClass('not-animated'); | |
13069 | $backdropEl.addClass('backdrop-in'); | |
13070 | } | |
13071 | $el | |
13072 | .animationEnd(function () { | |
13073 | transitionEnd(); | |
13074 | }); | |
13075 | $el | |
13076 | .transitionEnd(function () { | |
13077 | transitionEnd(); | |
13078 | }); | |
13079 | $el | |
13080 | .removeClass('modal-out not-animated') | |
13081 | .addClass('modal-in'); | |
13082 | modal.onOpen(); | |
13083 | } else { | |
13084 | if ($backdropEl) { | |
13085 | $backdropEl.addClass('backdrop-in not-animated'); | |
13086 | } | |
13087 | $el.removeClass('modal-out').addClass('modal-in not-animated'); | |
13088 | modal.onOpen(); | |
13089 | modal.onOpened(); | |
13090 | } | |
13091 | ||
13092 | return modal; | |
13093 | }; | |
13094 | ||
13095 | Modal.prototype.close = function close (animateModal) { | |
13096 | var modal = this; | |
13097 | var $el = modal.$el; | |
13098 | var $backdropEl = modal.$backdropEl; | |
13099 | ||
13100 | var animate = true; | |
13101 | if (typeof animateModal !== 'undefined') { animate = animateModal; } | |
13102 | else if (typeof modal.params.animate !== 'undefined') { | |
13103 | animate = modal.params.animate; | |
13104 | } | |
13105 | ||
13106 | if (!$el || !$el.hasClass('modal-in')) { | |
13107 | return modal; | |
13108 | } | |
13109 | ||
13110 | // backdrop | |
13111 | if ($backdropEl) { | |
13112 | var needToHideBackdrop = true; | |
13113 | if (modal.type === 'popup') { | |
13114 | modal.$el.prevAll('.popup.modal-in').each(function (index, popupEl) { | |
13115 | var popupInstance = popupEl.f7Modal; | |
13116 | if (!popupInstance) { return; } | |
13117 | if ( | |
13118 | popupInstance.params.closeByBackdropClick | |
13119 | && popupInstance.params.backdrop | |
13120 | && popupInstance.backdropEl === modal.backdropEl | |
13121 | ) { | |
13122 | needToHideBackdrop = false; | |
13123 | } | |
13124 | }); | |
13125 | } | |
13126 | if (needToHideBackdrop) { | |
13127 | $backdropEl[animate ? 'removeClass' : 'addClass']('not-animated'); | |
13128 | $backdropEl.removeClass('backdrop-in'); | |
13129 | } | |
13130 | } | |
13131 | ||
13132 | // Modal | |
13133 | $el[animate ? 'removeClass' : 'addClass']('not-animated'); | |
13134 | function transitionEnd() { | |
13135 | if ($el.hasClass('modal-out')) { | |
13136 | modal.onClosed(); | |
13137 | } else if ($el.hasClass('modal-in')) { | |
13138 | modal.onOpened(); | |
13139 | } | |
13140 | } | |
13141 | if (animate) { | |
13142 | $el | |
13143 | .animationEnd(function () { | |
13144 | transitionEnd(); | |
13145 | }); | |
13146 | $el | |
13147 | .transitionEnd(function () { | |
13148 | transitionEnd(); | |
13149 | }); | |
13150 | $el | |
13151 | .removeClass('modal-in') | |
13152 | .addClass('modal-out'); | |
13153 | // Emit close | |
13154 | modal.onClose(); | |
13155 | } else { | |
13156 | $el | |
13157 | .addClass('not-animated') | |
13158 | .removeClass('modal-in') | |
13159 | .addClass('modal-out'); | |
13160 | // Emit close | |
13161 | modal.onClose(); | |
13162 | modal.onClosed(); | |
13163 | } | |
13164 | ||
13165 | if (modal.type === 'dialog') { | |
13166 | clearDialogsQueue(); | |
13167 | } | |
13168 | ||
13169 | return modal; | |
13170 | }; | |
13171 | ||
13172 | Modal.prototype.destroy = function destroy () { | |
13173 | var modal = this; | |
13174 | if (modal.destroyed) { return; } | |
13175 | modal.emit(("local::beforeDestroy modalBeforeDestroy " + (modal.type) + "BeforeDestroy"), modal); | |
13176 | if (modal.$el) { | |
13177 | modal.$el.trigger(("modal:beforedestroy " + (modal.type.toLowerCase()) + ":beforedestroy"), modal); | |
13178 | if (modal.$el.length && modal.$el[0].f7Modal) { | |
13179 | delete modal.$el[0].f7Modal; | |
13180 | } | |
13181 | } | |
13182 | Utils.deleteProps(modal); | |
13183 | modal.destroyed = true; | |
13184 | }; | |
13185 | ||
13186 | return Modal; | |
13187 | }(Framework7Class)); | |
13188 | ||
5d51ea26 | 13189 | var CustomModal = /*@__PURE__*/(function (Modal) { |
5309fbda DC |
13190 | function CustomModal(app, params) { |
13191 | var extendedParams = Utils.extend({ | |
13192 | backdrop: true, | |
13193 | closeByBackdropClick: true, | |
13194 | on: {}, | |
13195 | }, params); | |
13196 | ||
13197 | // Extends with open/close Modal methods; | |
5d51ea26 | 13198 | Modal.call(this, app, extendedParams); |
5309fbda DC |
13199 | |
13200 | var customModal = this; | |
13201 | ||
13202 | customModal.params = extendedParams; | |
13203 | ||
13204 | // Find Element | |
13205 | var $el; | |
13206 | if (!customModal.params.el) { | |
13207 | $el = $(customModal.params.content); | |
13208 | } else { | |
13209 | $el = $(customModal.params.el); | |
13210 | } | |
13211 | ||
13212 | if ($el && $el.length > 0 && $el[0].f7Modal) { | |
13213 | return $el[0].f7Modal; | |
13214 | } | |
13215 | ||
13216 | if ($el.length === 0) { | |
13217 | return customModal.destroy(); | |
13218 | } | |
13219 | var $backdropEl; | |
13220 | if (customModal.params.backdrop) { | |
13221 | $backdropEl = app.root.children('.custom-modal-backdrop'); | |
13222 | if ($backdropEl.length === 0) { | |
13223 | $backdropEl = $('<div class="custom-modal-backdrop"></div>'); | |
13224 | app.root.append($backdropEl); | |
13225 | } | |
13226 | } | |
13227 | ||
13228 | function handleClick(e) { | |
13229 | if (!customModal || customModal.destroyed) { return; } | |
13230 | if ($backdropEl && e.target === $backdropEl[0]) { | |
13231 | customModal.close(); | |
13232 | } | |
13233 | } | |
13234 | ||
13235 | customModal.on('customModalOpened', function () { | |
13236 | if (customModal.params.closeByBackdropClick && customModal.params.backdrop) { | |
13237 | app.on('click', handleClick); | |
13238 | } | |
13239 | }); | |
13240 | customModal.on('customModalClose', function () { | |
13241 | if (customModal.params.closeByBackdropClick && customModal.params.backdrop) { | |
13242 | app.off('click', handleClick); | |
13243 | } | |
13244 | }); | |
13245 | ||
13246 | Utils.extend(customModal, { | |
13247 | app: app, | |
13248 | $el: $el, | |
13249 | el: $el[0], | |
13250 | $backdropEl: $backdropEl, | |
13251 | backdropEl: $backdropEl && $backdropEl[0], | |
13252 | type: 'customModal', | |
13253 | }); | |
13254 | ||
13255 | $el[0].f7Modal = customModal; | |
13256 | ||
13257 | return customModal; | |
13258 | } | |
13259 | ||
5d51ea26 DC |
13260 | if ( Modal ) CustomModal.__proto__ = Modal; |
13261 | CustomModal.prototype = Object.create( Modal && Modal.prototype ); | |
5309fbda DC |
13262 | CustomModal.prototype.constructor = CustomModal; |
13263 | ||
13264 | return CustomModal; | |
13265 | }(Modal)); | |
13266 | ||
13267 | var Modal$1 = { | |
13268 | name: 'modal', | |
13269 | static: { | |
13270 | Modal: Modal, | |
13271 | CustomModal: CustomModal, | |
13272 | }, | |
13273 | create: function create() { | |
13274 | var app = this; | |
13275 | app.customModal = { | |
13276 | create: function create(params) { | |
13277 | return new CustomModal(app, params); | |
13278 | }, | |
13279 | }; | |
13280 | }, | |
13281 | params: { | |
13282 | modal: { | |
13283 | moveToRoot: true, | |
13284 | queueDialogs: true, | |
13285 | }, | |
13286 | }, | |
13287 | }; | |
13288 | ||
13289 | { | |
13290 | if (typeof window !== 'undefined') { | |
13291 | // Template7 | |
13292 | if (!window.Template7) { window.Template7 = Template7; } | |
13293 | ||
13294 | // Dom7 | |
13295 | if (!window.Dom7) { window.Dom7 = $; } | |
13296 | } | |
13297 | } | |
13298 | ||
13299 | // Install Core Modules & Components | |
13300 | Router.use([ | |
13301 | RouterTemplateLoaderModule, | |
13302 | RouterComponentLoaderModule ]); | |
13303 | ||
13304 | Framework7.use([ | |
13305 | DeviceModule, | |
13306 | SupportModule, | |
13307 | UtilsModule, | |
13308 | ResizeModule, | |
13309 | RequestModule, | |
13310 | TouchModule, | |
13311 | ClicksModule, | |
5d51ea26 | 13312 | RouterModule, |
5309fbda DC |
13313 | HistoryModule, |
13314 | StorageModule, | |
13315 | ComponentModule, | |
13316 | ServiceWorkerModule, | |
13317 | Statusbar$1, | |
13318 | View$1, | |
13319 | Navbar$1, | |
13320 | Toolbar$1, | |
13321 | Subnavbar, | |
13322 | TouchRipple$1, | |
13323 | Modal$1 ]); | |
13324 | ||
13325 | return Framework7; | |
13326 | ||
13327 | })); |