-
Notifications
You must be signed in to change notification settings - Fork 12
/
devices.js
96 lines (86 loc) · 2.87 KB
/
devices.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
/*! CSSDevices v2.2.0 | MIT license | Maintained by Stuart Yamartino | https://cssdevices.com */
$(function(){
$('.cd-screen').each(function(){
if($(this).hasClass('cd-smart-loader')){
if(isSlideShow(this)){
$('> :gt(0)', this).hide();
}
$('> :first-child',this).each(function(){
handleLoadBinding(this);
});
}
else{
callSlideShow(this);
}
});
function isSlideShow(_self){
return $(_self).children().length > 1 && ! $(_self).hasClass('cd-no-slideshow');
}
function callSlideShow(_self){
if(isSlideShow(_self)){
var pauseSpeed = getOptionalData(_self, 'pause-speed', 5000);
var transitionSpeed = getOptionalData(_self, 'transition-speed', 1000);
$('> :gt(0)', _self).hide();
if ( ! $(_self).hasClass('cd-smart-loader') ) {
$('> :eq(0)', _self).css('display', 'block');
}
if( $(_self).hasClass('cd-transition-slider') ) {
setInterval(function(){$('> :first-child',_self).animate({ 'margin-left': '-100%' }, transitionSpeed).next().css({'display':'block','margin-left': '100%'}).animate({ 'margin-left': '0%' }, transitionSpeed).end().appendTo(_self);}, pauseSpeed);
}
else{
setInterval(function(){$('> :first-child',_self).fadeOut(transitionSpeed).next().fadeIn(transitionSpeed).end().appendTo(_self);}, pauseSpeed);
}
}
}
function handleLoadBinding(_self){
$(_self).on('load', handleLoad);
if (_self.complete) {
$(_self).off('load', handleLoad);
handleLoad.call(_self);
}
}
function handleLoad(){
var loadSpeed = getOptionalData($(this).parent('.cd-smart-loader')[0], 'fade-in-speed', 250);
$(this).fadeIn(loadSpeed);
callSlideShow($(this).parent()[0]);
}
function getOptionalData(saveThis, data, defaultValue){
if ($(saveThis).attr('data-' + data)) {
return $(saveThis).data(data);
}
return defaultValue;
}
$('.cd-device-loader').each(function(){
if( ! $(this).hasClass('cd-fill-parent')){
fadeDeviceIn(this);
}
});
//// Container Filler ////
var firstGo = true;
var scale;
fillContainer();
$(window).resize(function(){
fillContainer();
});
function fillContainer(){
$('.cd-fill-parent').each(function(){
if( firstGo ){
$(this).data('initial-width', $(this).width());
}
if( $(this).hasClass('cd-padded-device')){
var fontPercentage = ($(this).parent().width() - 40)/parseInt($(this).data('initial-width')) * 100;
}
else{
var fontPercentage = $(this).parent().width()/parseInt($(this).data('initial-width')) * 100;
}
$(this).css('font-size', fontPercentage + '%');
if( firstGo ){
fadeDeviceIn(this);
}
});
firstGo = false;
}
function fadeDeviceIn(_self){
$(_self).css('visibility', 'visible').hide().fadeIn(getOptionalData(_self, 'fade-in-speed', 250));
}
});