-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogressive_enhancement.js
173 lines (103 loc) · 3.29 KB
/
progressive_enhancement.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
(function(){
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
byClass = Dom.getElementsByClassName;
window.STAPX = {};
STAPX.widgets = {};
STAPX.widgets.Slides = function( containerId, config ) {
//Private
var S = STAPX.widgets.Slides;
//Static
S.CLASS_SLIDE = "slide";
S.CLASS_HIDE = "hide";
S.CLASS_STEPS = "steps";
S.CLASS_STEP = "step";
S.CLASS_TRANSITIONED = "transitioned";
//Public
var public_methods = {
el : Dom.get( containerId ),
selectedSlide : null,
steps : null,
transitions : {
show : function( element ){
Dom.removeClass( element, S.CLASS_HIDE );
}
},
getSlides : function(){
return byClass( S.CLASS_SLIDE, "div", this.el );
},
getPreviousSlide : function(){
return Dom.getPreviousSibling( this.selectedSlide );
},
getNextSlide : function(){
return Dom.getNextSibling( this.selectedSlide );
},
advanceStep : function( slideId ){
var slide = Dom.get( slideId ),
steps = Dom.getElementsByClassName( S.CLASS_STEP, 'li', slide ),
step = null;
for( var i=0, l=steps.length; l > i; i++ ){
var tStep = steps[ i ];
if( !Dom.hasClass( tStep, S.CLASS_HIDE ) && !Dom.hasClass( tStep, S.CLASS_TRANSITIONED ) ){
Dom.addClass( tStep, S.CLASS_TRANSITIONED );
if( steps[ i+1 ] ){
step = steps[ i+1 ];
}
}
}
},
selectSlide : function( slideId ){
if( slideId ){
Dom.addClass( this.getSlides(), S.CLASS_HIDE );
Dom.removeClass( slideId, S.CLASS_HIDE );
this.selectedSlide = Dom.get( slideId );
return this.selectedSlide;
} else {
return false;
}
},
initSteps : function( slideId ){
var steps = Dom.getElementsByClassName(
S.CLASS_STEPS,
"ul",
Dom.get( slideId )
)[ 0 ].getElementsByTagName( "li" ),
getTransitions = function( element ){
var classes = element.className.split(" ")
transitions = [];
for( var i=0, l=classes.length; l > i; i++ ){
var classArray = classes[ i ].split( ":" );
if( classArray.length > 1 && classArray[0] === "transition" ){
transitions.push( classArray[ 1 ] );
}
}
if( transitions.length ){
Dom.addClass( element, S.CLASS_HIDE );
Dom.addClass( element, S.CLASS_STEP );
}
return transitions;
};
this.steps = [];
for( var i = 0, l = steps.length; l > i; i++ ){
this.steps.push({
element : steps[ i ],
transition : getTransitions( steps[ i ] )
})
}
return this.steps;
}
}
//Initialize
public_methods.selectSlide( public_methods.getSlides()[ 0 ] );
Event.on( public_methods.el, "click", function( event ){
if( event.shiftKey ){
this.selectSlide( this.getPreviousSlide() );
} else {
this.selectSlide( this.getNextSlide() );
}
}, null, public_methods )
return public_methods;
}
STAPX.app = {};
STAPX.app.slideshow = new STAPX.widgets.Slides( "mySlideshow" );
})();