This repository was archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathapp.js
1283 lines (1276 loc) · 45.4 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Purpose: Provide client code */
'use strict'
import _ from 'lodash'
function initCordova (callback) {
if (window.cordova !== undefined) {
if (window.StatusBar !== undefined) {
callback()
} else {
document.addEventListener('deviceready', () => {
callback()
}, false)
}
} else {
callback()
}
}
let manageComponentData = {
created: function () {
this.$nextTick(function () {
this.$pageKey = this.getKey()
this.restoreData()
})
},
updated: function () {
this.rememberData()
},
methods: {
restoreData: function () {
if (this.$pageKey) {
if (window.localStorage[this.$pageKey]) {
let data = JSON.parse(window.localStorage[this.$pageKey])
for (let item in data) {
this.$data[item] = data[item]
}
}
}
},
rememberData: function () {
if (this.$pageKey) {
let data = {}
for (let item in this.$data) {
data[item] = this.$data[item]
}
window.localStorage[this.$pageKey] = JSON.stringify(data)
}
},
getKey: function () {
if (!this.$options._componentTag && this.$el && this.$el.f7PageData && this.$el.f7PageData.view && this.$el.f7PageData.url) {
let url = this.$el.f7PageData.url
if (url.substr(0, 1) === '/') url = url.substr(1)
if (url.substr(url.length - 1, 1) === '/') url = url.substr(0, url.length - 1)
let view = this.$el.f7PageData.view.selector
let key = 'data|' + view + '|' + url
return key
} else {
return null
}
}
}
}
let easierGlobalDataObject = {
computed: {
// Legacy support
$get () {
return this.$root.data
}
},
methods: {
$db (...args) {
return this.$root.$db(...args)
},
// Legacy support
$save (...args) {
this.$root.saveData(...args)
},
$remove (...args) {
this.$root.removeData(...args)
}
}
}
let easierLanguagePattern = {
methods: {
$lang (key, data = null) {
return this.$root.getLanguagePattern(key, data)
}
}
}
let easierFirebase = {
computed: {
// Authentication
$fireAuth () {
return window.firebase && window.firebase.auth ? window.firebase.auth : null
},
$user () {
return this.$root.user
},
// Realtime Database
$fireDB () {
return window.firebase && window.firebase.database ? (ref) => { return window.firebase.database().ref(ref) } : null
},
// Cloud Storage
$fireStore () {
return window.firebase && window.firebase.storage ? (ref) => { return window.firebase.storage().ref(ref) } : null
}
}
}
let mixins = {}
mixins.loadConfig = {
data: {
// Load App Framework version
frameworkVersion: process.env.FRAMEWORK_VERSION,
// Load project version
version: process.env.PROJECT_VERSION,
// Load application configuration
config: require(process.env.APP_ROOT_FROM_SCRIPTS + 'config.json')
},
// Update Framework7 modal title
created: function () {
this.$options.framework7.modalTitle = this.config.title
}
}
mixins.loadRoutes = {
data () {
return {
loginRoutes: [],
loginRequiringPages: {},
loginRequiringPagesOnStart: false
}
},
watch: {
f7Ready () {
// Check default routes for login requiring pages
this.$f7.views.forEach((view) => {
if (view.params.url && this.urlRequiresLogin(view.params.url)) {
// Remember URL (popup will be opened on init by login-screen.vue)
this.$set(this.loginRequiringPages, view.selector, view.params.url)
this.loginRequiringPagesOnStart = true
}
})
}
},
methods: {
urlRequiresLogin: function (url) {
let loginRequired = false
this.loginRoutes.map(route => {
let regexp = new RegExp('^' + route.replace(/\/:[a-zA-Z0-9-_]+\//g, '\/[a-zA-Z0-9-]+\/') + '$') // eslint-disable-line
url = url.match(/([0-9a-zA-Z-/]+)/)[1]
if (url.substr(0, 1) !== '/') url = '/' + url
if (url.substr(url.length - 1) !== '/') url = url + '/'
if (regexp.test(url)) loginRequired = true
})
return loginRequired
}
},
created: function () {
// Load routes file
let routes = require(process.env.APP_ROOT_FROM_SCRIPTS + 'routes.json')
for (let r = 0; r < routes.length; r++) {
// Page routes
try {
routes[r].component = require(process.env.APP_ROOT_FROM_SCRIPTS + 'pages/' + routes[r].component)
} catch (err) {
console.error('Failed to load page component "' + routes[r].component + '". Please update the routes.json file.')
}
// Login required?
if (routes[r].login === true) this.loginRoutes.push(routes[r].path)
// Tab routes
if (Array.isArray(routes[r].tabs)) {
for (let t = 0; t < routes[r].tabs.length; t++) {
try {
routes[r].tabs[t].component = require(process.env.APP_ROOT_FROM_SCRIPTS + 'pages/' + routes[r].tabs[t].component)
} catch (err) {
console.error('Failed to load page component "' + routes[r].tabs[t].component + '". Please update the routes.json file.')
}
// Login required?
if (routes[r].tabs[t].login === true) {
this.loginRoutes.push(routes[r].path + routes[r].tabs[t].path.substr(1))
}
// Alternate tab routes
if (Array.isArray(routes[r].tabs[t].routes)) {
for (let a = 0; a < routes[r].tabs[t].routes.length; a++) {
try {
routes[r].tabs[t].routes[a].component = require(process.env.APP_ROOT_FROM_SCRIPTS + 'pages/' + routes[r].tabs[t].routes[a].component)
} catch (err) {
console.error('Failed to load page component "' + routes[r].tabs[t].routes[a].component + '". Please update the routes.json file.')
}
// Login required?
if (routes[r].tabs[t].routes[a].login === true) {
this.loginRoutes.push(routes[r].path + routes[r].tabs[t].path.substr(1) + routes[r].tabs[t].routes[a].path.substr(1))
}
}
}
}
}
}
// Add login screen route
routes.push({
path: '/app-framework-login-screen/',
component: require('./login-screen.vue')
})
// Add routes to Framework7 initialization object
this.$options.framework7.routes = routes
// Add preroute function for login-requiring pages to Framework7
this.$options.framework7.preroute = (view, options) => {
// User not logged in, no back link, no dynamic content
if (this.user !== null || options.isBack === true || options.url === undefined) {
return true
} else {
// Login required for all pages or for this page
if (this.config.loginRequiredForAllPages || this.urlRequiresLogin(options.url)) {
// Remember URL
this.$set(this.loginRequiringPages, view.selector, options.url)
// Show login popup
this.$f7.popup('#app-framework-login-popup')
return false
} else {
return true
}
}
}
}
}
mixins.loadIconFonts = {
created: function () {
if (process.env.FONT_FRAMEWORK7 === 'true') require('framework7-icons/css/framework7-icons.css')
if (process.env.FONT_MATERIAL === 'true') require('../vendor/material-icons/material-icons.css')
if (process.env.FONT_ION === 'true') require('ionicons/dist/css/ionicons.css')
if (process.env.FONT_AWESOME === 'true') require('font-awesome/css/font-awesome.css')
}
}
mixins.manageFirebase = {
// Set initial values
data: {
user: null,
db: null,
store: null,
timestamp: null
},
// Init Firebase
created: function () {
// Use Firebase
if (process.env.USE_FIREBASE_APP === 'true') {
// Include scripts
let firebase = require('firebase/app')
if (process.env.USE_FIREBASE_AUTH === 'true') require('firebase/auth')
if (process.env.USE_FIREBASE_DATABASE === 'true') require('firebase/database')
if (process.env.USE_FIREBASE_STORAGE === 'true') require('firebase/storage')
// Initialize Firebase
window.firebase = firebase.initializeApp(this.config[process.env.FIREBASE_CONFIG])
// Use auth service
if (process.env.USE_FIREBASE_AUTH === 'true') {
// Get initial user data from local storage
this.user = window.localStorage.user ? JSON.parse(window.localStorage.user) : null
// Clean local storage if user is not logged in initially
if (!window.localStorage.user) this.cleanLocalStorageAfterLogut()
// Monitor user changes
firebase.auth().onAuthStateChanged(user => {
this.user = user ? {
uid: user.uid,
email: user.email,
name: user.displayName,
photo: user.photoURL
} : null
})
}
// Use database service
if (process.env.USE_FIREBASE_DATABASE === 'true') {
this.db = function (path) {
return firebase.database().ref(path)
}
this.timestamp = firebase.database.ServerValue.TIMESTAMP
}
// Use storage service
if (process.env.USE_FIREBASE_STORAGE === 'true') {
this.store = function (path) {
return firebase.storage().ref(path)
}
}
}
},
// Watch for changes
watch: {
user: function (newUser) {
// Update local storage
if (newUser === null) {
window.localStorage.removeItem('user')
this.cleanLocalStorageAfterLogut()
} else {
window.localStorage.user = JSON.stringify(newUser)
}
// Update window object
window.user = newUser
},
db: function (newDB) {
// Update window object
window.db = newDB
},
store: function (newStore) {
// Update window object
window.store = newStore
},
timestamp: function (newTimestamp) {
// Update window object
window.timestamp = newTimestamp
}
},
methods: {
cleanLocalStorageAfterLogut: function () {
for (let item in window.localStorage) {
// History
if (/^urls\|([0-9a-zA-Z._-]+)$/.test(item)) {
let urls = JSON.parse(window.localStorage[item])
let newUrls = []
let loginRequired = false
urls.map((url) => {
if (this.urlRequiresLogin(url)) {
loginRequired = true
} else if (!loginRequired) {
newUrls.push(url)
}
})
window.localStorage[item] = JSON.stringify(newUrls)
// Component data and scroll positions
} else if (/(scroll|data)\|[0-9a-zA-Z._-]+\|(.+)$/.test(item)) {
let url = item.match(/(scroll|data)\|[0-9a-zA-Z._-]+\|(.+)$/)[2]
if (this.urlRequiresLogin(url)) {
window.localStorage.removeItem(item)
}
}
}
}
}
}
mixins.sortObject = {
beforeCreate: function () {
window.sortObject = require('./sort-object')
}
}
mixins.resetCache = {
created: function () {
if (this.config.resetLocalStorageOnVersionChange === true &&
window.localStorage.projectVersion !== undefined &&
window.localStorage.projectVersion !== this.projectVersion) {
// Remember alert
let text = {
en: 'The application has been updated and the cache has been reset.',
de: 'Die Anwendung wurde aktualisiert und der Cache wurde zurückgesetzt.'
}
if (window.localStorage.language && text[window.localStorage.language]) {
window.localStorage.cacheResetAlert = text[window.localStorage.language]
} else if (text[window.localStorage.language]) {
window.localStorage.cacheResetAlert = text[window.localStorage.language]
} else {
window.localStorage.cacheResetAlert = text['en']
}
// Empty local storage
for (let item in window.localStorage) {
if (!/(firebase:(.+)|user|cacheResetAlert)/.test(item) && item !== 'user') {
window.localStorage.removeItem(item)
}
}
}
// Update framework version in local storage
window.localStorage.projectVersion = this.projectVersion
},
// Show Alert
watch: {
stateReady: function () {
if (window.localStorage.cacheResetAlert !== undefined) {
window.f7.alert(window.localStorage.cacheResetAlert, () => {
// Prevent to show alert twice
window.localStorage.removeItem('cacheResetAlert')
})
}
}
}
}
mixins.checkNPMupdates = {
watch: {
stateReady: function () {
if (process.env.NODE_ENV === 'development') {
let npm = require(process.env.PROJECT_ROOT_FROM_SCRIPTS + 'node_modules/.app-framework-cache/latest-npm-version.json')
if (npm !== undefined && npm.latest !== undefined) {
if (npm.latest === 'unknown') {
window.f7.alert('Failed to get latest NPM version. Please open an incident on GitHub.', 'App Framework')
} else if (/^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$/.test(npm.latest)) {
let currentVersion = this.frameworkVersion.split('.')
let npmVersion = npm.latest.split('.')
if (parseInt(currentVersion[0]) < parseInt(npmVersion[0]) ||
parseInt(currentVersion[1]) < parseInt(npmVersion[1]) ||
parseInt(currentVersion[2]) < parseInt(npmVersion[2])) {
window.f7.alert('Please update App Framework to the latest version <b>' + npm.latest + '</b>.<br /><br />You have installed version ' + this.frameworkVersion + '.<br /><br />The CLI commands are "CTRL + C" to stop the development server and "npm update" to update App Framework.', 'App Framework')
}
} else {
window.f7.alert('Failed to get parse NPM version. Please open an incident on GitHub.', 'App Framework')
}
}
}
}
}
}
mixins.initWorkarounds = {
data: {
materialCodepoints: null
},
beforeCreate: function () {
require('./workarounds.css')
// Actions not show/hide properly
window.Dom7(document).on('actions:open', (e) => {
e.target.__vue__.opened = true
})
window.Dom7(document).on('actions:close', (e) => {
e.target.__vue__.opened = false
})
// Login screen show/hide properly
window.Dom7(document).on('page:init', (e) => {
window.Dom7(e.target).find('.login-screen.modal-out').hide()
})
},
created: function () {
// Materical Icons not shown in older browsers / android versions
if (process.env.FONT_MATERIAL) {
this.materialCodepoints = require('./material-codepoints.json')
}
}
}
mixins.manageGlobalDataObject = {
// Set initial data
data: {
data: {}
},
// Methods to add or remove data
methods: {
$db (...args) {
// Check arguments
if (args.length < 1 || args.length > 2 || typeof args[0] !== 'string') {
throw new Error('$db() should have one or two arguments, the first one should be a string')
// Read data
} else if (args.length === 1) {
return _.get(this.data, args[0], undefined)
// Write/Remove data
} else {
// Clone current data
const data = _.cloneDeep(this.data)
// Update data
if (args[1] !== null) {
_.set(data, args[0], args[1])
// Remove data
} else {
_.unset(data, args[0])
}
// Save data to Vue object
this.$set(this, 'data', data)
// Save data to local storage
if (window.cordova) {
window.NativeStorage.setItem('data', data)
} else {
window.localStorage.data = JSON.stringify(this.data)
}
}
},
// Legacy support
saveData: function (path, value) {
this.$db(path, value)
},
removeData: function (path) {
this.$db(path, null)
}
},
// Restore local storage
created: function () {
if (window.cordova) {
const self = this
window.NativeStorage.getItem('data', function (data) {
self.data = data
}, function () {
self.data = {}
})
} else {
this.data = window.localStorage.data !== undefined ? JSON.parse(window.localStorage.data) : {}
}
}
}
mixins.appMode = {
data: {
appMode: null
},
created: function () {
if (window.cordova !== undefined) {
this.appMode = 'native'
} else if (window.Framework7.prototype.device.webView !== null || window.matchMedia('(display-mode: standalone)').matches) {
this.appMode = 'homescreen'
} else if (window.Framework7.prototype.device.ios !== false || window.Framework7.prototype.device.android !== false) {
this.appMode = 'mobile'
} else {
this.appMode = 'desktop'
}
}
}
mixins.manageApplicationFrame = {
beforeCreate: function () {
require('./application-frame.css')
},
created: function () {
this.updatePhoneFrame()
window.Dom7(window).on('resize', this.updatePhoneFrame)
},
methods: {
updatePhoneFrame: function () {
// Get attributes
let windowHeight = window.innerHeight
let windowWidth = window.innerWidth
let appMaxHeight = this.$root.config.limitApplicationHeight
let appMaxWidth = this.$root.config.limitApplicationWidth
let showPhoneFrame = this.$root.config.showPhoneFrameOnDesktop
let desktopMode = this.appMode === 'desktop'
// Calculate attributes
let phoneFrameMinHeight = appMaxHeight + 250
let phoneFrameMinWidth = appMaxWidth + 50
let mode = showPhoneFrame && desktopMode && windowHeight >= phoneFrameMinHeight && windowWidth >= phoneFrameMinWidth
? 'phoneFrame'
: desktopMode && windowHeight >= appMaxHeight && windowWidth >= appMaxWidth
? 'limitBoth'
: desktopMode && windowHeight >= appMaxHeight
? 'limitHeight'
: desktopMode && windowWidth >= appMaxWidth
? 'limitWidth'
: 'noFrame'
// Update classes
if (mode === 'phoneFrame') {
window.Dom7('body').css('background', this.$root.config.phoneFrameBodyBackgroundColor)
window.Dom7('body').addClass('phoneFrame')
window.Dom7('body').removeClass('limitHeight')
window.Dom7('body').removeClass('limitWidth')
} else if (mode === 'limitBoth') {
window.Dom7('body').css('background', this.$root.config.limitedSizeBodyBackgroundColor)
window.Dom7('body').removeClass('phoneFrame')
window.Dom7('body').addClass('limitHeight')
window.Dom7('body').addClass('limitWidth')
} else if (mode === 'limitHeight') {
window.Dom7('body').css('background', this.$root.config.limitedSizeBodyBackgroundColor)
window.Dom7('body').removeClass('phoneFrame')
window.Dom7('body').addClass('limitHeight')
window.Dom7('body').removeClass('limitWidth')
} else if (mode === 'limitWidth') {
window.Dom7('body').css('background', this.$root.config.limitedSizeBodyBackgroundColor)
window.Dom7('body').removeClass('phoneFrame')
window.Dom7('body').removeClass('limitHeight')
window.Dom7('body').addClass('limitWidth')
} else {
window.Dom7('body').removeClass('phoneFrame')
window.Dom7('body').removeClass('limitHeight')
window.Dom7('body').removeClass('limitWidth')
}
// Update size and position
if (mode === 'phoneFrame' || mode === 'limitBoth' || mode === 'limitHeight') {
window.Dom7('#frame').css('height', appMaxHeight + 'px')
window.Dom7('#frame').css('top', ((windowHeight - appMaxHeight) / 2) + 'px')
} else {
window.Dom7('#frame').css('height', windowHeight + 'px')
window.Dom7('#frame').css('top', '0')
}
if (mode === 'phoneFrame' || mode === 'limitBoth' || mode === 'limitWidth') {
window.Dom7('#frame').css('width', appMaxWidth + 'px')
window.Dom7('#frame').css('left', ((windowWidth - appMaxWidth) / 2) + 'px')
} else {
window.Dom7('#frame').css('width', windowWidth + 'px')
window.Dom7('#frame').css('left', '0')
}
}
}
}
mixins.addMissingStatusbar = {
mounted: function () {
if (window.Dom7('#app .statusbar-overlay').length < 1) {
window.Dom7('#app').prepend('<div class="statusbar-overlay"></div>')
}
}
}
mixins.tranformSubnavbarForMaterial = {
created: function () {
if (this.config.materialSubnavbarFix === true) {
window.Dom7(document).on('page:init', function (e) {
let subnavbar = window.Dom7(e.target).find('.subnavbar')
if (subnavbar.length > 0) {
window.Dom7(e.target).addClass('toolbar-fixed')
window.Dom7(e.target).removeClass('with-subnavbar')
subnavbar.prependTo(e.target).find('.page')
subnavbar.find('.buttons-row').addClass('toolbar-inner')
subnavbar.find('.buttons-row').removeClass('buttons-row')
subnavbar.addClass('toolbar')
subnavbar.addClass('tabbar')
subnavbar.removeClass('subnavbar')
}
})
}
}
}
mixins.manageLanguage = {
// Set default value
data: {
language: null
},
// Watch for change
watch: {
language: function (newLanguage, oldLanguage) {
// New language is valid
if (/^[a-z]{2}$/.test(newLanguage)) {
// Update local storage
window.localStorage.language = newLanguage
// Update Framework7 text patterns
let f7Text = {
en: {
modalButtonOk: 'OK',
modalButtonCancel: 'Cancel',
modalPreloaderTitle: 'Loading ... ',
modalUsernamePlaceholder: 'Username',
modalPasswordPlaceholder: 'Password',
smartSelectBackText: 'Back',
smartSelectPopupCloseText: 'Close',
smartSelectPickerCloseText: 'Done',
notificationCloseButtonText: 'Close'
},
de: {
modalButtonOk: 'OK',
modalButtonCancel: 'Abbrechen',
modalPreloaderTitle: 'Lädt ... ',
modalUsernamePlaceholder: 'Benutzername',
modalPasswordPlaceholder: 'Passwort',
smartSelectBackText: 'Zurück',
smartSelectPopupCloseText: 'Fertig',
smartSelectPickerCloseText: 'Fertig',
notificationCloseButtonText: 'OK'
}
}
let useText = f7Text[newLanguage] ? f7Text[newLanguage] : f7Text['en']
for (let item in useText) window.f7.params[item] = useText[item]
// New language is not valid
} else {
// Rollback to old or configuration value
this.language = oldLanguage !== null ? oldLanguage : this.config.language
}
}
},
// Restore local storage
created: function () {
this.language = window.localStorage.language ? window.localStorage.language : this.config.defaultLanguage
}
}
mixins.manageTheme = {
// Set initial value
data: function () {
return {
theme: null
}
},
// Watch for change
watch: {
theme: function (newTheme, oldTheme) {
// New theme is valid
if (/^(ios|material)$/.test(newTheme) && this.config.theme.split('-').indexOf(newTheme) >= 0) {
// New theme is different
if (newTheme !== oldTheme) {
// Update local storage
window.localStorage.theme = newTheme
// First theme change
if (oldTheme === null) {
// Update Framework7 initialization object
this.$options.framework7.material = newTheme === 'material'
// Load theme file in development mode
if (process.env.NODE_ENV === 'development') {
if (newTheme === 'ios') require('./ios')
else require('./material')
// Remove unneeded theme tags in production mode
} else {
window.Dom7('link').each((i, el) => {
let href = window.Dom7(el).attr('href').match(/^(ios|material)\.(.+)\.css$/)
if (href !== null && href[1] !== newTheme) {
window.Dom7(el).remove()
}
})
window.Dom7('script').each(function (i, el) {
let src = window.Dom7(el).attr('src').match(/^(ios|material)\.(.+)\.js$/)
if (src !== null && src[1] !== newTheme) {
window.Dom7(el).remove()
}
})
}
// Another theme change
} else {
// Reload the application
window.location.reload()
}
}
// New theme is not valid
} else {
// Rollback old value or configuration
this.theme = oldTheme !== null ? oldTheme : this.config.theme.split('-')[0]
}
}
},
// Restore local storage
created: function () {
this.theme = window.localStorage.theme ? window.localStorage.theme : this.config.theme.split('-')[0]
}
}
mixins.manageColor = {
// Set initial data
data: {
color: null,
colors: require('./theme-colors')
},
// Watch changes
watch: {
color: function (newColor, oldColor) {
// New color is valid
if (this.colors[this.theme][newColor] !== undefined) {
// Update local storage
window.localStorage.color = newColor
// Update DOM
window.Dom7('body')[0].className.split(' ').map(function (cName) {
if (/^theme-[a-z]+$/.test(cName)) window.Dom7('body').removeClass(cName)
})
window.Dom7('body').addClass('theme-' + newColor)
// New color is not valid
} else {
// Rollback old, config or default value
this.color = oldColor !== null ? oldColor : this.colors[this.theme][this.config.color] !== undefined ? this.config.color : this.colors.default[this.theme]
}
}
},
// Restore local storage
created: function () {
this.color = window.localStorage.color
}
}
mixins.manageLayout = {
// Set initial value
data: {
layout: null
},
// Watch changes
watch: {
layout: function (newLayout, oldLayout) {
if (newLayout === 'default' || newLayout === 'dark' || (newLayout === 'white' && this.theme === 'ios')) {
// Update local storage
window.localStorage.layout = newLayout
// Update DOM
window.Dom7('body')[0].className.split(' ').map(function (cName) {
if (/^layout-[a-z]+$/.test(cName)) window.Dom7('body').removeClass(cName)
})
if (newLayout !== 'default') window.Dom7('body').addClass('layout-' + newLayout)
} else {
// Rollback old or config value
this.layout = oldLayout !== null ? oldLayout : this.config.layout
}
}
},
// Restore local storage
created: function () {
this.layout = window.localStorage.layout
}
}
mixins.manageStatusbarVisibility = {
// Set variable
data: {
statusbarVisibility: null
},
// Deactivate automatic status bar handling
beforeCreate: function () {
this.$options.framework7.statusbarOverlay = false
},
// Handle change
watch: {
statusbarVisibility: function (newState, oldState) {
this.updateStatusBarVisibility(newState, oldState)
}
},
created: function () {
// Restore / set initial value
if (window.localStorage.statusbarVisibility !== undefined) {
this.statusbarVisibility = JSON.parse(window.localStorage.statusbarVisibility)
} else {
this.statusbarVisibility = this.config.statusbarVisibility
}
// Update on resize
window.Dom7(window).on('resize', () => {
this.updateStatusBarVisibility(this.statusbarVisibility, this.statusbarVisibility)
})
},
// Methods
methods: {
updateStatusBarVisibility: function (newState, oldState) {
if (newState === true || newState === false) {
// Update local storage
window.localStorage.statusbarVisibility = newState
// Update cordova
if (window.StatusBar) {
if (newState === true) {
window.StatusBar.show()
} else {
window.StatusBar.hide()
}
}
// Update DOM
if ((window.StatusBar !== undefined && newState === true && window.Framework7.prototype.device.statusBar === true) ||
(window.StatusBar === undefined && window.Framework7.prototype.device.statusBar === true && (window.Framework7.prototype.device.iphone === false || window.Dom7('html').width() < window.Dom7('html').height()))) {
window.Dom7('html').addClass('with-statusbar-overlay')
} else {
window.Dom7('html').removeClass('with-statusbar-overlay')
}
} else {
// Rollback old or config value
this.statusbarVisibility = oldState !== null ? oldState : this.config.statusbarVisibility
}
}
}
}
mixins.manageStatusbarTextColor = {
// Set variable
data: {
statusbarTextColor: null
},
// Handle change
watch: {
statusbarTextColor: function (newColor, oldColor) {
if (newColor === 'black' || newColor === 'white') {
// Update local storage
window.localStorage.statusbarTextColor = newColor
// Update cordova
if (window.StatusBar) {
if (newColor === 'white') {
window.StatusBar.styleBlackTranslucent()
} else {
window.StatusBar.styleDefault()
}
}
} else {
// Rollback old or config value
this.statusbarTextColor = oldColor !== null ? oldColor : this.config.statusbarTextColor
}
}
},
// Restore / set initial value
created: function () {
if (window.localStorage.statusbarTextColor !== undefined) {
this.statusbarTextColor = window.localStorage.statusbarTextColor
} else {
this.statusbarTextColor = this.config.statusbarTextColor
}
}
}
mixins.manageStatusbarBackgroundColor = {
// Set variable
data: {
statusbarBackgroundColor: null
},
// Handle change
watch: {
statusbarBackgroundColor: function (newColor, oldColor) {
// Add missing hash sign
if (/^[0-9a-f]{6}$/.test(newColor)) {
newColor = '#' + newColor
}
// New color is valid
if (/^#[0-9a-f]{6}$/.test(newColor)) {
// Update local storage
window.localStorage.statusbarBackgroundColor = newColor
// Update DOM
window.Dom7('.statusbar-overlay').css('background', newColor)
// Update Cordova
if (window.StatusBar) {
window.StatusBar.backgroundColorByHexString(newColor)
}
} else {
// Rollback old or config value
this.statusbarBackgroundColor = oldColor !== null ? oldColor : this.config.statusbarBackgroundColor
}
}
},
// Restore / set initial value
created: function () {
if (window.localStorage.statusbarBackgroundColor !== undefined) {
this.statusbarBackgroundColor = window.localStorage.statusbarBackgroundColor
} else {
this.statusbarBackgroundColor = this.config.statusbarBackgroundColor
}
}
}
mixins.preventOverscroll = {
created: function () {
// No native application (Overscroll disallowed by Cordova for native Apps)
if (!window.cordova) {
// Set overflow attribute to app container
window.Dom7('#app').css('-webkit-overflow-scrolling', 'touch')
// Definen start value
var startY = 0
// Remember touch start position
window.Dom7(document).on('touchstart', evt => {
startY = evt.touches ? evt.touches[0].screenY : evt.screenY
})
// Handle touch move
window.Dom7(document).on('touchmove', evt => {
// Get the element that was scrolled upon
var el = evt.target
// Check all parent elements for scrollability
while (el !== document.body) {
// Get some style properties
var style = window.getComputedStyle(el)
if (!style) {
// If we've encountered an element we can't compute the style for, get out
break
}
// Ignore range input element
if (el.nodeName === 'INPUT' && el.getAttribute('type') === 'range') {
return
}
// Ignore scrollable tabbar
if (window.Dom7(el).hasClass('tabbar-scrollable')) {
return
}
// Ignore horizontal timeline
if (window.Dom7(el).hasClass('horizontal-timeline')) {
return
}
// Determine scrolling property
var scrolling = style.getPropertyValue('-webkit-overflow-scrolling')
var overflowY = style.getPropertyValue('overflow-y')
var height = parseInt(style.getPropertyValue('height'), 10)
// Determine if the element should scroll
var isScrollable = scrolling === 'touch' && (overflowY === 'auto' || overflowY === 'scroll')
var canScroll = el.scrollHeight > el.offsetHeight
if (isScrollable && canScroll) {
// Get the current Y position of the touch
var curY = evt.touches ? evt.touches[0].screenY : evt.screenY
// Determine if the user is trying to scroll past the top or bottom
// In this case, the window will bounce, so we have to prevent scrolling completely
var isAtTop = (startY <= curY && el.scrollTop === 0)
var isAtBottom = (startY >= curY && el.scrollHeight - el.scrollTop === height)
// Stop a bounce bug when at the bottom or top of the scrollable element
if (isAtTop || isAtBottom) {
evt.preventDefault()
}
// No need to continue up the DOM, we've done our job
return
}
// Test the next parent
el = el.parentNode
}
// Stop the bouncing -- no parents are scrollable
evt.preventDefault()
})
}
}
}
mixins.manageState = {
data: {
stateReady: false
},
watch: {
f7Ready: function () {
const config = this.config
function restoreState (callback) {
restoreScrollOnPageLoad()
restoreTabOnPageLoad()
restoreFormInputOnPageLoad()
restoreViews(function () {
restoreOverlays(function () {
window.Dom7('#frame').show()
restoreFocus()
setTimeout(() => {
window.Dom7(window).trigger('resize')
}, 0)
callback()
})
})
}
function restoreViews (callback, viewId) {
viewId = viewId || 0
if (viewId < window.f7.views.length) {
restoreUrls(viewId, function () {
restoreViews(callback, viewId + 1)
})
} else {
callback()
}
}
function restoreUrls (viewId, callback, urls, urlId) {
urlId = urlId || 0
urls = urls || []
if (urlId === 0) {
try {
urls = JSON.parse(window.localStorage['urls|' + window.f7.views[viewId].selector])
urls = Array.isArray(urls) ? urls : []
} catch (err) {