-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathindex.js
212 lines (189 loc) · 6.35 KB
/
index.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
import Template7 from 'template7';
import Swiper from 'swiper';
// A plugin for Framework7 to show a slideable welcome screen
var F7WelcomescreenPlugin = {
name: 'welcomescreen',
Welcomescreen: function (app, slidesParam, optionsParam) {
var slides = slidesParam;
var options = optionsParam;
// Private properties
var self = this,
defaultTemplate,
template,
container,
swiper,
swiperContainer,
defaults = {
closeButton: true, // enabled/disable close button
closeButtonText: 'Skip', // close button text
cssClass: '', // additional class on container
pagination: true, // swiper pagination,
navigation: false, // swiper navigation
loop: false, // swiper loop
open: true, // open welcome screen on init
parallax: false, // adds parallax capabilities
parallaxSpeed: 600, // parallax default speed
parallaxBackgroundImage: 'http://lorempixel.com/900/600/nightlife/2/', // parallax default background image
parallaxBackground: '-23%', // parallax default background effect
parallaxSlideElements: {
title: -100,
subtitle: -300,
text: -500,
},
};
function initSwiper() {
swiper = new Swiper('.welcomescreen-swiper', {
direction: 'horizontal',
loop: options.loop,
pagination: options.pagination
? { el: '.swiper-pagination' }
: undefined,
parallax: options.parallax,
speed: options.parallaxSpeed,
});
}
function setColors() {
if (options.bgcolor) {
container.css({
'background-color': options.bgcolor,
color: options.fontcolor,
});
}
}
function defineDefaultTemplate() {
defaultTemplate =
'<div class="welcomescreen-container {{#if options.cssClass}}{{options.cssClass}}{{/if}}">' +
'{{#if options.closeButton}}' +
'<div class="welcomescreen-closebtn close-welcomescreen">{{options.closeButtonText}}</div>' +
'{{/if}}' +
'<div class="welcomescreen-swiper">' +
'{{#if options.parallax}}<div class="parallax-bg" style="background-image:url({{options.parallaxBackgroundImage}})" data-swiper-parallax="{{options.parallaxBackground}}"></div>{{/if}}' +
'<div class="swiper-wrapper">' +
'{{#each slides}}' +
'<div class="swiper-slide" {{#if id}}id="{{id}}"{{/if}}>' +
'<div class="welcomescreen-title {{#unless title}}hide-title{{/unless}}" data-swiper-parallax="{{#if parallaxTitle}}{{parallaxTitle}}{{else}}{{@root.options.parallaxSlideElements.title}}{{/if}}">{{#if title}}{{title}}{{else}}title{{/if}}</div>' +
'{{#if content}}' +
'<div class="welcomescreen-content">{{content}}</div>' +
'{{else}}' +
'{{#if picture}}' +
'<div class="welcomescreen-picture" data-swiper-parallax="{{#if parallaxPicture}}{{parallaxPicture}}{{else}}{{@root.options.parallaxSlideElements.subtitle}}{{/if}}">{{picture}}</div>' +
'{{/if}}' +
'{{#if text}}' +
'<div class="welcomescreen-text" data-swiper-parallax="{{#if parallaxText}}{{parallaxText}}{{else}}{{@root.options.parallaxSlideElements.text}}{{/if}}">{{text}}</div>' +
'{{/if}}' +
'{{/if}}' +
'</div>' +
'{{/each}}' +
'</div>' +
'{{#if options.pagination}}' +
'<div class="welcomescreen-pagination swiper-pagination"></div>' +
'{{/if}}' +
'{{#if options.navigation}}' +
'<!-- If we need navigation buttons -->' +
'<div class="welcomescreen-navigation-prev swiper-button-prev"></div>' +
'<div class="welcomescreen-navigation-next swiper-button-next"></div>' +
'{{/if}}' +
'</div>' +
'</div>' +
'</div>';
}
function applyOptions() {
var def;
options = options || {};
for (def in defaults) {
if (typeof options[def] === 'undefined') {
options[def] = defaults[def];
}
}
}
function compileTemplate() {
const T7 = window.Template7 || Template7;
if (!options.template) {
template = T7.compile(defaultTemplate);
} else {
template = T7.compile(options.template);
}
}
self.open = function () {
container = window.Dom7(template({ options: options, slides: slides }));
swiperContainer = container.find('.welcomescreen-swiper');
setColors();
window.Dom7('body').append(container);
initSwiper();
container[0].f7Welcomescreen = self;
if (typeof options.onOpened === 'function') {
options.onOpened();
}
};
self.close = function () {
if (swiper) {
swiper.destroy(true);
}
if (container) {
container.remove();
}
container = swiperContainer = swiper = undefined;
if (typeof options.onClosed === 'function') {
options.onClosed();
}
};
self.next = function () {
if (swiper) {
swiper.slideNext();
}
};
self.previous = function () {
if (swiper) {
swiper.slidePrev();
}
};
self.slideTo = function (index) {
if (swiper) {
swiper.slideTo(index);
}
};
self.init = function (newSlides, newOptions) {
if (newSlides) slides = newSlides;
if (newOptions) options = newOptions;
defineDefaultTemplate();
compileTemplate();
applyOptions();
// Open on init
if (options.open) {
self.open();
}
};
self.init();
// Return instance
return self;
},
params: {
welcomescreen: {
options: {},
slides: [],
},
},
/* Event handlers */
on: {
init: function (foo) {
window.Dom7 = this.$;
window.swiper = this.swiper;
// Click handler to close welcomescreen
window.Dom7(document).on('click', '.close-welcomescreen', function (e) {
e.preventDefault();
var $wscreen = window.Dom7(this).parents('.welcomescreen-container');
if ($wscreen.length > 0 && $wscreen[0].f7Welcomescreen) {
$wscreen[0].f7Welcomescreen.close();
}
});
var app = this;
var params = app.params.welcomescreen;
app.welcomescreen = new F7WelcomescreenPlugin.Welcomescreen(
app,
params.slides,
params.options
);
},
},
};
export default F7WelcomescreenPlugin;