annotate js/jquery.slideshow.controls.js @ 0:1308906213ab

add files
author masa
date Tue, 05 Aug 2014 17:20:23 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1308906213ab add files
masa
parents:
diff changeset
1 /***********
1308906213ab add files
masa
parents:
diff changeset
2 *
1308906213ab add files
masa
parents:
diff changeset
3 * control addon:
1308906213ab add files
masa
parents:
diff changeset
4 *
1308906213ab add files
masa
parents:
diff changeset
5 * adds toggle, prev slide, next slide links/buttons and jump list
1308906213ab add files
masa
parents:
diff changeset
6 * - use key-c to toggle controls (in projection mode)
1308906213ab add files
masa
parents:
diff changeset
7 *
1308906213ab add files
masa
parents:
diff changeset
8 * layout structure:
1308906213ab add files
masa
parents:
diff changeset
9 *
1308906213ab add files
masa
parents:
diff changeset
10 * .layout
1308906213ab add files
masa
parents:
diff changeset
11 * > #controls (holding navigation controls)
1308906213ab add files
masa
parents:
diff changeset
12 * > #navLinks
1308906213ab add files
masa
parents:
diff changeset
13 * > #toggle
1308906213ab add files
masa
parents:
diff changeset
14 * > #navList
1308906213ab add files
masa
parents:
diff changeset
15 * > #jumplist
1308906213ab add files
masa
parents:
diff changeset
16 */
1308906213ab add files
masa
parents:
diff changeset
17
1308906213ab add files
masa
parents:
diff changeset
18
1308906213ab add files
masa
parents:
diff changeset
19 Slideshow.ctrlInit = function()
1308906213ab add files
masa
parents:
diff changeset
20 {
1308906213ab add files
masa
parents:
diff changeset
21 this.debug( 'calling ctrlInit()' );
1308906213ab add files
masa
parents:
diff changeset
22
1308906213ab add files
masa
parents:
diff changeset
23 var self = this; // NOTE: jquery binds this in .each,.click, etc to element
1308906213ab add files
masa
parents:
diff changeset
24
1308906213ab add files
masa
parents:
diff changeset
25 // todo: make layout into an id (not class?)
1308906213ab add files
masa
parents:
diff changeset
26 // do we need or allow more than one element?
1308906213ab add files
masa
parents:
diff changeset
27
1308906213ab add files
masa
parents:
diff changeset
28 // if no div.layout exists, create one
1308906213ab add files
masa
parents:
diff changeset
29 if( $( '.layout' ).length == 0 )
1308906213ab add files
masa
parents:
diff changeset
30 $( 'body' ).append( "<div class='layout'></div>");
1308906213ab add files
masa
parents:
diff changeset
31
1308906213ab add files
masa
parents:
diff changeset
32 $( '.layout' ).append( "<div id='controls'>" );
1308906213ab add files
masa
parents:
diff changeset
33
1308906213ab add files
masa
parents:
diff changeset
34 var $controls = $( '#controls' )
1308906213ab add files
masa
parents:
diff changeset
35
1308906213ab add files
masa
parents:
diff changeset
36 $controls.html( '<div id="navLinks">'
1308906213ab add files
masa
parents:
diff changeset
37 + '<a accesskey="t" id="toggle" href="#">&#216;<\/a>'
1308906213ab add files
masa
parents:
diff changeset
38 + '<a accesskey="z" id="prev" href="#">&laquo;<\/a>'
1308906213ab add files
masa
parents:
diff changeset
39 + '<a accesskey="x" id="next" href="#">&raquo;<\/a>'
1308906213ab add files
masa
parents:
diff changeset
40 + '<div id="navList"><select id="jumplist" /><\/div>'
1308906213ab add files
masa
parents:
diff changeset
41 + '<\/div>' );
1308906213ab add files
masa
parents:
diff changeset
42
1308906213ab add files
masa
parents:
diff changeset
43 $controls.hover( function() { self.ctrlShow(); }, function() { self.ctrlHide(); });
1308906213ab add files
masa
parents:
diff changeset
44 $('#toggle').click( function() { self.toggle(); } );
1308906213ab add files
masa
parents:
diff changeset
45 $('#prev').click( function() { self.go(-1); } );
1308906213ab add files
masa
parents:
diff changeset
46 $('#next').click( function() { self.go(1); } );
1308906213ab add files
masa
parents:
diff changeset
47
1308906213ab add files
masa
parents:
diff changeset
48 $('#jumplist').change( function() { self.goTo( parseInt( $( '#jumplist' ).val() )); } );
1308906213ab add files
masa
parents:
diff changeset
49
1308906213ab add files
masa
parents:
diff changeset
50 this.ctrlPopulateJumpList();
1308906213ab add files
masa
parents:
diff changeset
51 }
1308906213ab add files
masa
parents:
diff changeset
52
1308906213ab add files
masa
parents:
diff changeset
53
1308906213ab add files
masa
parents:
diff changeset
54 Slideshow.ctrlDebugOn = function()
1308906213ab add files
masa
parents:
diff changeset
55 {
1308906213ab add files
masa
parents:
diff changeset
56 this.debug( 'calling ctrlDebugOn()' );
1308906213ab add files
masa
parents:
diff changeset
57 $( '#controls' ).addClass( 'debug' );
1308906213ab add files
masa
parents:
diff changeset
58 }
1308906213ab add files
masa
parents:
diff changeset
59
1308906213ab add files
masa
parents:
diff changeset
60 Slideshow.ctrlDebugOff = function()
1308906213ab add files
masa
parents:
diff changeset
61 {
1308906213ab add files
masa
parents:
diff changeset
62 this.debug( 'calling ctrlDebugOff()' );
1308906213ab add files
masa
parents:
diff changeset
63 $( '#controls' ).removeClass( 'debug' );
1308906213ab add files
masa
parents:
diff changeset
64 }
1308906213ab add files
masa
parents:
diff changeset
65
1308906213ab add files
masa
parents:
diff changeset
66 Slideshow.ctrlKeys = function( event, key )
1308906213ab add files
masa
parents:
diff changeset
67 {
1308906213ab add files
masa
parents:
diff changeset
68 this.debug( 'calling ctrlKeys()' );
1308906213ab add files
masa
parents:
diff changeset
69
1308906213ab add files
masa
parents:
diff changeset
70 switch( key.which ) {
1308906213ab add files
masa
parents:
diff changeset
71 case 67: // c
1308906213ab add files
masa
parents:
diff changeset
72 this.ctrlToggle();
1308906213ab add files
masa
parents:
diff changeset
73 break;
1308906213ab add files
masa
parents:
diff changeset
74 }
1308906213ab add files
masa
parents:
diff changeset
75 }
1308906213ab add files
masa
parents:
diff changeset
76
1308906213ab add files
masa
parents:
diff changeset
77 Slideshow.ctrlChange = function()
1308906213ab add files
masa
parents:
diff changeset
78 {
1308906213ab add files
masa
parents:
diff changeset
79 this.debug( 'calling ctrlChange()' );
1308906213ab add files
masa
parents:
diff changeset
80 this.ctrlUpdateJumpList();
1308906213ab add files
masa
parents:
diff changeset
81 }
1308906213ab add files
masa
parents:
diff changeset
82
1308906213ab add files
masa
parents:
diff changeset
83 // -----------------------------------------------------
1308906213ab add files
masa
parents:
diff changeset
84
1308906213ab add files
masa
parents:
diff changeset
85 Slideshow.ctrlPopulateJumpList = function()
1308906213ab add files
masa
parents:
diff changeset
86 {
1308906213ab add files
masa
parents:
diff changeset
87 var self = this; // NOTE: jquery binds this in .each to element
1308906213ab add files
masa
parents:
diff changeset
88
1308906213ab add files
masa
parents:
diff changeset
89 var list = $('#jumplist').get(0);
1308906213ab add files
masa
parents:
diff changeset
90
1308906213ab add files
masa
parents:
diff changeset
91 this.$slides.each( function(i) {
1308906213ab add files
masa
parents:
diff changeset
92 var text = "-"; // untitled slide
1308906213ab add files
masa
parents:
diff changeset
93
1308906213ab add files
masa
parents:
diff changeset
94 // todo: use titleSelector if user set??
1308906213ab add files
masa
parents:
diff changeset
95 // $(this).find( self.settings.titleSelector ).text();
1308906213ab add files
masa
parents:
diff changeset
96
1308906213ab add files
masa
parents:
diff changeset
97 var $h1 = $( 'h1', this );
1308906213ab add files
masa
parents:
diff changeset
98 if( $h1.length > 0 )
1308906213ab add files
masa
parents:
diff changeset
99 {
1308906213ab add files
masa
parents:
diff changeset
100 text = $h1.first().text();
1308906213ab add files
masa
parents:
diff changeset
101 }
1308906213ab add files
masa
parents:
diff changeset
102 else // try h2
1308906213ab add files
masa
parents:
diff changeset
103 {
1308906213ab add files
masa
parents:
diff changeset
104 var $h2 = $( 'h2', this );
1308906213ab add files
masa
parents:
diff changeset
105 if( $h2.length > 0 )
1308906213ab add files
masa
parents:
diff changeset
106 {
1308906213ab add files
masa
parents:
diff changeset
107 text = $h2.first().text();
1308906213ab add files
masa
parents:
diff changeset
108 }
1308906213ab add files
masa
parents:
diff changeset
109 else // try h3
1308906213ab add files
masa
parents:
diff changeset
110 {
1308906213ab add files
masa
parents:
diff changeset
111 var $h3 = $( 'h3', this );
1308906213ab add files
masa
parents:
diff changeset
112 if( $h3.length > 0 )
1308906213ab add files
masa
parents:
diff changeset
113 {
1308906213ab add files
masa
parents:
diff changeset
114 text = $h3.first().text();
1308906213ab add files
masa
parents:
diff changeset
115 }
1308906213ab add files
masa
parents:
diff changeset
116 }
1308906213ab add files
masa
parents:
diff changeset
117 }
1308906213ab add files
masa
parents:
diff changeset
118
1308906213ab add files
masa
parents:
diff changeset
119 list.options[list.length] = new Option( (i+1)+' : '+ text, (i+1) );
1308906213ab add files
masa
parents:
diff changeset
120 });
1308906213ab add files
masa
parents:
diff changeset
121 }
1308906213ab add files
masa
parents:
diff changeset
122
1308906213ab add files
masa
parents:
diff changeset
123 Slideshow.ctrlUpdateJumpList = function()
1308906213ab add files
masa
parents:
diff changeset
124 {
1308906213ab add files
masa
parents:
diff changeset
125 $('#jumplist').get(0).selectedIndex = (this.snum-1);
1308906213ab add files
masa
parents:
diff changeset
126 }
1308906213ab add files
masa
parents:
diff changeset
127
1308906213ab add files
masa
parents:
diff changeset
128 Slideshow.ctrlShow = function()
1308906213ab add files
masa
parents:
diff changeset
129 {
1308906213ab add files
masa
parents:
diff changeset
130 $( '#navLinks' ).css( 'visibility', 'visible' );
1308906213ab add files
masa
parents:
diff changeset
131 }
1308906213ab add files
masa
parents:
diff changeset
132
1308906213ab add files
masa
parents:
diff changeset
133 Slideshow.ctrlHide = function()
1308906213ab add files
masa
parents:
diff changeset
134 {
1308906213ab add files
masa
parents:
diff changeset
135 $( '#navLinks' ).css( 'visibility', 'hidden' );
1308906213ab add files
masa
parents:
diff changeset
136 }
1308906213ab add files
masa
parents:
diff changeset
137
1308906213ab add files
masa
parents:
diff changeset
138 Slideshow.ctrlToggle = function()
1308906213ab add files
masa
parents:
diff changeset
139 {
1308906213ab add files
masa
parents:
diff changeset
140 // toggle control panel
1308906213ab add files
masa
parents:
diff changeset
141 var $navLinks = $( '#navLinks' );
1308906213ab add files
masa
parents:
diff changeset
142
1308906213ab add files
masa
parents:
diff changeset
143 if( $navLinks.css( 'visibility' ) != 'visible' )
1308906213ab add files
masa
parents:
diff changeset
144 $navLinks.css( 'visibility', 'visible' );
1308906213ab add files
masa
parents:
diff changeset
145 else
1308906213ab add files
masa
parents:
diff changeset
146 $navLinks.css( 'visibility', 'hidden' );
1308906213ab add files
masa
parents:
diff changeset
147 }
1308906213ab add files
masa
parents:
diff changeset
148
1308906213ab add files
masa
parents:
diff changeset
149
1308906213ab add files
masa
parents:
diff changeset
150 // ------------------------------------------------
1308906213ab add files
masa
parents:
diff changeset
151
1308906213ab add files
masa
parents:
diff changeset
152 Slideshow.ctrlAddEvents = function()
1308906213ab add files
masa
parents:
diff changeset
153 {
1308906213ab add files
masa
parents:
diff changeset
154 $( document ).on( 'slideshow.init', $.proxy( Slideshow.ctrlInit, this ));
1308906213ab add files
masa
parents:
diff changeset
155 $( document ).on( 'slideshow.debug.on', $.proxy( Slideshow.ctrlDebugOn, this ));
1308906213ab add files
masa
parents:
diff changeset
156 $( document ).on( 'slideshow.debug.off', $.proxy( Slideshow.ctrlDebugOff, this ));
1308906213ab add files
masa
parents:
diff changeset
157 $( document ).on( 'slideshow.keys', $.proxy( Slideshow.ctrlKeys, this ));
1308906213ab add files
masa
parents:
diff changeset
158 $( document ).on( 'slideshow.change', $.proxy( Slideshow.ctrlChange, this ));
1308906213ab add files
masa
parents:
diff changeset
159 }
1308906213ab add files
masa
parents:
diff changeset
160
1308906213ab add files
masa
parents:
diff changeset
161 Slideshow.ctrlAddStyles = function() {
1308906213ab add files
masa
parents:
diff changeset
162 this.debug( 'add builtin controls css via inline style elements' );
1308906213ab add files
masa
parents:
diff changeset
163
1308906213ab add files
masa
parents:
diff changeset
164 var styleProjection =
1308906213ab add files
masa
parents:
diff changeset
165 "<style media='screen,projection'> \n"+
1308906213ab add files
masa
parents:
diff changeset
166 " \n"+
1308906213ab add files
masa
parents:
diff changeset
167 " #controls.debug { background: #BBD; } \n"+
1308906213ab add files
masa
parents:
diff changeset
168 " \n"+
1308906213ab add files
masa
parents:
diff changeset
169 " #controls { position: fixed; \n"+
1308906213ab add files
masa
parents:
diff changeset
170 " left: 60%; bottom: 0; \n"+
1308906213ab add files
masa
parents:
diff changeset
171 " width: 40%; \n"+
1308906213ab add files
masa
parents:
diff changeset
172 " z-index: 100; \n"+
1308906213ab add files
masa
parents:
diff changeset
173 " text-align: right; \n"+
1308906213ab add files
masa
parents:
diff changeset
174 " font-weight: bold; \n"+
1308906213ab add files
masa
parents:
diff changeset
175 " font-size: 120%; \n"+
1308906213ab add files
masa
parents:
diff changeset
176 " } \n"+
1308906213ab add files
masa
parents:
diff changeset
177 " \n"+
1308906213ab add files
masa
parents:
diff changeset
178 " #controls :focus { outline: 1px dotted white;} \n"+
1308906213ab add files
masa
parents:
diff changeset
179 " \n"+
1308906213ab add files
masa
parents:
diff changeset
180 " #controls #navLinks { text-align: right; margin: 0; visibility: hidden; } \n"+
1308906213ab add files
masa
parents:
diff changeset
181
1308906213ab add files
masa
parents:
diff changeset
182 " \n"+
1308906213ab add files
masa
parents:
diff changeset
183 " #controls #navLinks a { padding: 0; margin: 0 0.5em; cursor: pointer; border: none; } \n"+
1308906213ab add files
masa
parents:
diff changeset
184 " \n"+
1308906213ab add files
masa
parents:
diff changeset
185 " #controls #navLinks :link, \n"+
1308906213ab add files
masa
parents:
diff changeset
186 " #controls #navLinks :visited {text-decoration: none; } \n"+
1308906213ab add files
masa
parents:
diff changeset
187 " \n"+
1308906213ab add files
masa
parents:
diff changeset
188 " #controls #navList #jumplist { background: white; color: black; } \n"+
1308906213ab add files
masa
parents:
diff changeset
189 "</style>";
1308906213ab add files
masa
parents:
diff changeset
190
1308906213ab add files
masa
parents:
diff changeset
191 var styleScreen =
1308906213ab add files
masa
parents:
diff changeset
192 "<style media='screen'> \n"+
1308906213ab add files
masa
parents:
diff changeset
193 "/********* \n"+
1308906213ab add files
masa
parents:
diff changeset
194 " * make toggle button visible and reposition to upper right corner \n"+
1308906213ab add files
masa
parents:
diff changeset
195 " * note: toogle button is nested inside #controls > #navLinks > #toogle \n"+
1308906213ab add files
masa
parents:
diff changeset
196 " */ \n"+
1308906213ab add files
masa
parents:
diff changeset
197 " \n"+
1308906213ab add files
masa
parents:
diff changeset
198 " #controls, \n"+
1308906213ab add files
masa
parents:
diff changeset
199 " #navLinks, \n"+
1308906213ab add files
masa
parents:
diff changeset
200 " #toggle { display: block; \n"+
1308906213ab add files
masa
parents:
diff changeset
201 " visibility: visible; \n"+
1308906213ab add files
masa
parents:
diff changeset
202 " margin: 0; padding: 0; \n"+
1308906213ab add files
masa
parents:
diff changeset
203 " } \n"+
1308906213ab add files
masa
parents:
diff changeset
204 " \n"+
1308906213ab add files
masa
parents:
diff changeset
205 " #toggle { position: fixed; \n"+
1308906213ab add files
masa
parents:
diff changeset
206 " top: 0; right: 0; \n"+
1308906213ab add files
masa
parents:
diff changeset
207 " padding: 0.5em; \n"+
1308906213ab add files
masa
parents:
diff changeset
208 " border-left: 1px solid; \n"+
1308906213ab add files
masa
parents:
diff changeset
209 " border-bottom: 1px solid; \n"+
1308906213ab add files
masa
parents:
diff changeset
210 " background: white; \n"+
1308906213ab add files
masa
parents:
diff changeset
211 " } \n"+
1308906213ab add files
masa
parents:
diff changeset
212 "</style>";
1308906213ab add files
masa
parents:
diff changeset
213
1308906213ab add files
masa
parents:
diff changeset
214 $( 'head' ).append( styleProjection );
1308906213ab add files
masa
parents:
diff changeset
215 $( 'head' ).append( styleScreen );
1308906213ab add files
masa
parents:
diff changeset
216 }
1308906213ab add files
masa
parents:
diff changeset
217
1308906213ab add files
masa
parents:
diff changeset
218 Slideshow.ctrlAddStyles();
1308906213ab add files
masa
parents:
diff changeset
219 Slideshow.ctrlAddEvents();