1
|
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2
|
(function(addon) {
|
3
|
|
4
|
var component;
|
5
|
|
6
|
if (window.UIkit2) {
|
7
|
component = addon(UIkit2);
|
8
|
}
|
9
|
|
10
|
if (typeof define == 'function' && define.amd) {
|
11
|
define('uikit-slideshow-fx', ['uikit'], function() {
|
12
|
return component || addon(UIkit2);
|
13
|
});
|
14
|
}
|
15
|
|
16
|
})(function(UI) {
|
17
|
|
18
|
"use strict";
|
19
|
|
20
|
var Animations = UI.slideshow.animations;
|
21
|
|
22
|
UI.$.extend(UI.slideshow.animations, {
|
23
|
slice: function(current, next, dir, fromfx) {
|
24
|
|
25
|
if (!current.data('cover')) {
|
26
|
return Animations.fade.apply(this, arguments);
|
27
|
}
|
28
|
|
29
|
var d = UI.$.Deferred();
|
30
|
|
31
|
var sliceWidth = Math.ceil(this.element.width() / this.options.slices),
|
32
|
bgimage = next.data('cover').css('background-image'),
|
33
|
ghost = UI.$('<li class="uk-slideshow-ghost"></li>').css({
|
34
|
top : 0,
|
35
|
left : 0,
|
36
|
width : this.container.width(),
|
37
|
height : this.container.height(),
|
38
|
opacity: 1,
|
39
|
zIndex : 15
|
40
|
}),
|
41
|
ghostWidth = ghost.width(),
|
42
|
ghostHeight = ghost.height(),
|
43
|
pos = fromfx == 'slice-up' ? ghostHeight:'0',
|
44
|
bar;
|
45
|
|
46
|
for (var i = 0; i < this.options.slices; i++) {
|
47
|
|
48
|
if (fromfx == 'slice-up-down') {
|
49
|
pos = ((i % 2) + 2) % 2==0 ? '0':ghostHeight;
|
50
|
}
|
51
|
|
52
|
var width = (i == this.options.slices-1) ? sliceWidth : sliceWidth,
|
53
|
clipto = ('rect(0px, '+(width*(i+1))+'px, '+ghostHeight+'px, '+(sliceWidth*i)+'px)'),
|
54
|
clipfrom;
|
55
|
|
56
|
//slice-down - default
|
57
|
clipfrom = ('rect(0px, '+(width*(i+1))+'px, 0px, '+(sliceWidth*i)+'px)');
|
58
|
|
59
|
if (fromfx == 'slice-up' || (fromfx == 'slice-up-down' && ((i % 2) + 2) % 2==0 )) {
|
60
|
clipfrom = ('rect('+ghostHeight+'px, '+(width*(i+1))+'px, '+ghostHeight+'px, '+(sliceWidth*i)+'px)');
|
61
|
}
|
62
|
|
63
|
bar = UI.$('<div class="uk-cover-background"></div>').css({
|
64
|
'position' : 'absolute',
|
65
|
'top' : 0,
|
66
|
'left' : 0,
|
67
|
'width' : ghostWidth,
|
68
|
'height' : ghostHeight,
|
69
|
'background-image' : bgimage,
|
70
|
'clip' : clipfrom,
|
71
|
'opacity' : 0,
|
72
|
'transition' : 'all '+this.options.duration+'ms ease-in-out '+(i*60)+'ms',
|
73
|
'-webkit-transition' : 'all '+this.options.duration+'ms ease-in-out '+(i*60)+'ms'
|
74
|
|
75
|
}).data('clip', clipto);
|
76
|
|
77
|
ghost.append(bar);
|
78
|
}
|
79
|
|
80
|
this.container.append(ghost);
|
81
|
|
82
|
ghost.children().last().on(UI.support.transition.end, function() {
|
83
|
|
84
|
setTimeout(function() {
|
85
|
ghost.remove();
|
86
|
d.resolve();
|
87
|
}, 0);
|
88
|
});
|
89
|
|
90
|
ghost.width();
|
91
|
|
92
|
ghost.children().each(function() {
|
93
|
bar = UI.$(this);
|
94
|
bar.css({ clip: bar.data('clip'), opacity: 1 });
|
95
|
});
|
96
|
|
97
|
return d.promise();
|
98
|
},
|
99
|
|
100
|
'slice-up': function(current, next, dir) {
|
101
|
return Animations.slice.apply(this, [current, next, dir, 'slice-up']);
|
102
|
},
|
103
|
|
104
|
'slice-down': function(current, next, dir) {
|
105
|
return Animations.slice.apply(this, [current, next, dir, 'slice-down']);
|
106
|
},
|
107
|
|
108
|
'slice-up-down': function(current, next, dir) {
|
109
|
return Animations.slice.apply(this, [current, next, dir, 'slice-up-down']);
|
110
|
},
|
111
|
|
112
|
fold: function(current, next, dir) {
|
113
|
|
114
|
if (!next.data('cover')) {
|
115
|
return Animations.fade.apply(this, arguments);
|
116
|
}
|
117
|
|
118
|
var d = UI.$.Deferred();
|
119
|
|
120
|
var sliceWidth = Math.ceil(this.element.width() / this.options.slices),
|
121
|
bgimage = next.data('cover').css('background-image'),
|
122
|
ghost = UI.$('<li class="uk-slideshow-ghost"></li>').css({
|
123
|
width : next.width(),
|
124
|
height : next.height(),
|
125
|
opacity: 1,
|
126
|
zIndex : 15
|
127
|
}),
|
128
|
ghostWidth = next.width(),
|
129
|
ghostHeight = next.height(),
|
130
|
bar;
|
131
|
|
132
|
for (var i = 0; i < this.options.slices; i++) {
|
133
|
|
134
|
bar = UI.$('<div class="uk-cover-background"></div>').css({
|
135
|
'position' : 'absolute',
|
136
|
'top' : 0,
|
137
|
'left' : 0,
|
138
|
'width' : ghostWidth,
|
139
|
'height' : ghostHeight,
|
140
|
'background-image' : bgimage,
|
141
|
'transform-origin' : (sliceWidth*i)+'px 0 0',
|
142
|
'clip' : ('rect(0px, '+(sliceWidth*(i+1))+'px, '+ghostHeight+'px, '+(sliceWidth*i)+'px)'),
|
143
|
'opacity' : 0,
|
144
|
'transform' : 'scaleX(0.000001)',
|
145
|
'transition' : 'all '+this.options.duration+'ms ease-in-out '+(100+i*60)+'ms',
|
146
|
'-webkit-transition' : 'all '+this.options.duration+'ms ease-in-out '+(100+i*60)+'ms'
|
147
|
});
|
148
|
|
149
|
ghost.prepend(bar);
|
150
|
}
|
151
|
|
152
|
this.container.append(ghost);
|
153
|
|
154
|
ghost.width();
|
155
|
|
156
|
ghost.children().first().on(UI.support.transition.end, function() {
|
157
|
setTimeout(function() {
|
158
|
ghost.remove();
|
159
|
d.resolve();
|
160
|
}, 0);
|
161
|
}).end().css({
|
162
|
transform: 'scaleX(1)',
|
163
|
opacity: 1
|
164
|
});
|
165
|
|
166
|
return d.promise();
|
167
|
},
|
168
|
|
169
|
puzzle: function(current, next, dir) {
|
170
|
|
171
|
if (!next.data('cover')) {
|
172
|
return Animations.fade.apply(this, arguments);
|
173
|
}
|
174
|
|
175
|
var d = UI.$.Deferred(), $this = this;
|
176
|
|
177
|
var boxCols = Math.round(this.options.slices/2),
|
178
|
boxWidth = Math.round(next.width()/boxCols),
|
179
|
boxRows = Math.round(next.height()/boxWidth),
|
180
|
boxHeight = Math.round(next.height()/boxRows)+1,
|
181
|
bgimage = next.data('cover').css('background-image'),
|
182
|
ghost = UI.$('<li class="uk-slideshow-ghost"></li>').css({
|
183
|
width : this.container.width(),
|
184
|
height : this.container.height(),
|
185
|
opacity : 1,
|
186
|
zIndex : 15
|
187
|
}),
|
188
|
ghostWidth = this.container.width(),
|
189
|
ghostHeight = this.container.height(),
|
190
|
box, rect, width;
|
191
|
|
192
|
for (var rows = 0; rows < boxRows; rows++) {
|
193
|
|
194
|
for (var cols = 0; cols < boxCols; cols++) {
|
195
|
|
196
|
width = (cols == boxCols-1) ? (boxWidth + 2) : boxWidth;
|
197
|
|
198
|
rect = [
|
199
|
(boxHeight * rows) +'px', // top
|
200
|
(width * (cols+1)) +'px', // right
|
201
|
(boxHeight * (rows + 1)) +'px', // bottom
|
202
|
(boxWidth * cols) +'px' // left
|
203
|
];
|
204
|
|
205
|
box = UI.$('<div class="uk-cover-background"></div>').css({
|
206
|
'position' : 'absolute',
|
207
|
'top' : 0,
|
208
|
'left' : 0,
|
209
|
'opacity' : 0,
|
210
|
'width' : ghostWidth,
|
211
|
'height' : ghostHeight,
|
212
|
'background-image' : bgimage,
|
213
|
'clip' : ('rect('+rect.join(',')+')'),
|
214
|
'-webkit-transform' : 'translateZ(0)', // fixes webkit opacity flickering bug
|
215
|
'transform' : 'translateZ(0)' // fixes moz opacity flickering bug
|
216
|
});
|
217
|
|
218
|
ghost.append(box);
|
219
|
}
|
220
|
}
|
221
|
|
222
|
this.container.append(ghost);
|
223
|
|
224
|
var boxes = shuffle(ghost.children());
|
225
|
|
226
|
boxes.each(function(i) {
|
227
|
UI.$(this).css({
|
228
|
'transition': 'all '+$this.options.duration+'ms ease-in-out '+(50+i*25)+'ms',
|
229
|
'-webkit-transition': 'all '+$this.options.duration+'ms ease-in-out '+(50+i*25)+'ms'
|
230
|
});
|
231
|
}).last().on(UI.support.transition.end, function() {
|
232
|
|
233
|
setTimeout(function() {
|
234
|
ghost.remove();
|
235
|
d.resolve();
|
236
|
}, 0);
|
237
|
});
|
238
|
|
239
|
ghost.width();
|
240
|
|
241
|
boxes.css({opacity: 1});
|
242
|
|
243
|
return d.promise();
|
244
|
},
|
245
|
|
246
|
boxes: function(current, next, dir, fromfx) {
|
247
|
|
248
|
if (!next.data('cover')) {
|
249
|
return Animations.fade.apply(this, arguments);
|
250
|
}
|
251
|
|
252
|
var d = UI.$.Deferred();
|
253
|
|
254
|
var boxCols = Math.round(this.options.slices/2),
|
255
|
boxWidth = Math.round(next.width()/boxCols),
|
256
|
boxRows = Math.round(next.height()/boxWidth),
|
257
|
boxHeight = Math.round(next.height()/boxRows)+1,
|
258
|
bgimage = next.data('cover').css('background-image'),
|
259
|
ghost = UI.$('<li class="uk-slideshow-ghost"></li>').css({
|
260
|
width : next.width(),
|
261
|
height : next.height(),
|
262
|
opacity : 1,
|
263
|
zIndex : 15
|
264
|
}),
|
265
|
ghostWidth = next.width(),
|
266
|
ghostHeight = next.height(),
|
267
|
box, rect, width, cols;
|
268
|
|
269
|
for (var rows = 0; rows < boxRows; rows++) {
|
270
|
|
271
|
for (cols = 0; cols < boxCols; cols++) {
|
272
|
|
273
|
width = (cols == boxCols-1) ? (boxWidth + 2) : boxWidth;
|
274
|
|
275
|
rect = [
|
276
|
(boxHeight * rows) +'px', // top
|
277
|
(width * (cols+1)) +'px', // right
|
278
|
(boxHeight * (rows + 1)) +'px', // bottom
|
279
|
(boxWidth * cols) +'px' // left
|
280
|
];
|
281
|
|
282
|
box = UI.$('<div class="uk-cover-background"></div>').css({
|
283
|
'position' : 'absolute',
|
284
|
'top' : 0,
|
285
|
'left' : 0,
|
286
|
'opacity' : 1,
|
287
|
'width' : ghostWidth,
|
288
|
'height' : ghostHeight,
|
289
|
'background-image' : bgimage,
|
290
|
'transform-origin' : rect[3]+' '+rect[0]+' 0',
|
291
|
'clip' : ('rect('+rect.join(',')+')'),
|
292
|
'-webkit-transform' : 'scale(0.0000000000000001)',
|
293
|
'transform' : 'scale(0.0000000000000001)'
|
294
|
});
|
295
|
|
296
|
ghost.append(box);
|
297
|
}
|
298
|
}
|
299
|
|
300
|
this.container.append(ghost);
|
301
|
|
302
|
var rowIndex = 0, colIndex = 0, timeBuff = 0, box2Darr = [[]], boxes = ghost.children(), prevCol;
|
303
|
|
304
|
if (fromfx == 'boxes-reverse') {
|
305
|
boxes = [].reverse.apply(boxes);
|
306
|
}
|
307
|
|
308
|
boxes.each(function() {
|
309
|
|
310
|
box2Darr[rowIndex][colIndex] = UI.$(this);
|
311
|
colIndex++;
|
312
|
|
313
|
if(colIndex == boxCols) {
|
314
|
rowIndex++;
|
315
|
colIndex = 0;
|
316
|
box2Darr[rowIndex] = [];
|
317
|
}
|
318
|
});
|
319
|
|
320
|
for (cols = 0, prevCol = 0; cols < (boxCols * boxRows); cols++) {
|
321
|
|
322
|
prevCol = cols;
|
323
|
|
324
|
for (var row = 0; row < boxRows; row++) {
|
325
|
|
326
|
if (prevCol >= 0 && prevCol < boxCols) {
|
327
|
|
328
|
box2Darr[row][prevCol].css({
|
329
|
'transition': 'all '+this.options.duration+'ms linear '+(50+timeBuff)+'ms',
|
330
|
'-webkit-transition': 'all '+this.options.duration+'ms linear '+(50+timeBuff)+'ms'
|
331
|
});
|
332
|
}
|
333
|
prevCol--;
|
334
|
}
|
335
|
timeBuff += 100;
|
336
|
}
|
337
|
|
338
|
boxes.last().on(UI.support.transition.end, function() {
|
339
|
|
340
|
setTimeout(function() {
|
341
|
ghost.remove();
|
342
|
d.resolve();
|
343
|
}, 0);
|
344
|
});
|
345
|
|
346
|
ghost.width();
|
347
|
|
348
|
boxes.css({
|
349
|
'-webkit-transform': 'scale(1)',
|
350
|
'transform': 'scale(1)'
|
351
|
});
|
352
|
|
353
|
return d.promise();
|
354
|
},
|
355
|
|
356
|
'boxes-reverse': function(current, next, dir) {
|
357
|
return Animations.boxes.apply(this, [current, next, dir, 'boxes-reverse']);
|
358
|
},
|
359
|
|
360
|
'random-fx': function(){
|
361
|
|
362
|
var animations = ['slice-up', 'fold', 'puzzle', 'slice-down', 'boxes', 'slice-up-down', 'boxes-reverse'];
|
363
|
|
364
|
this.fxIndex = (this.fxIndex === undefined ? -1 : this.fxIndex) + 1;
|
365
|
|
366
|
if (!animations[this.fxIndex]) this.fxIndex = 0;
|
367
|
|
368
|
return Animations[animations[this.fxIndex]].apply(this, arguments);
|
369
|
}
|
370
|
});
|
371
|
|
372
|
|
373
|
// helper functions
|
374
|
|
375
|
// Shuffle an array
|
376
|
var shuffle = function(arr) {
|
377
|
for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x) {}
|
378
|
return arr;
|
379
|
};
|
380
|
|
381
|
return UI.slideshow.animations;
|
382
|
});
|