annotate presen/s6/js/jquery.slideshow.counter.js @ 30:3050872e76df

merge
author ikkun
date Tue, 16 May 2017 01:19:23 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
ikkun
parents:
diff changeset
1 /***********
ikkun
parents:
diff changeset
2 *
ikkun
parents:
diff changeset
3 * counter addon:
ikkun
parents:
diff changeset
4 *
ikkun
parents:
diff changeset
5 * adds slide counter (e.g. 1/7)
ikkun
parents:
diff changeset
6 * - use key-n to toggle slide counter (in projection mode)
ikkun
parents:
diff changeset
7 *
ikkun
parents:
diff changeset
8 * layout structure:
ikkun
parents:
diff changeset
9 *
ikkun
parents:
diff changeset
10 * .layout
ikkun
parents:
diff changeset
11 * > #counter (e.g. 1/7)
ikkun
parents:
diff changeset
12 */
ikkun
parents:
diff changeset
13
ikkun
parents:
diff changeset
14
ikkun
parents:
diff changeset
15 Slideshow.counterInit = function()
ikkun
parents:
diff changeset
16 {
ikkun
parents:
diff changeset
17 this.debug( 'calling counterInit()' );
ikkun
parents:
diff changeset
18
ikkun
parents:
diff changeset
19 // if no div.layout exists, create one
ikkun
parents:
diff changeset
20 if( $( '.layout' ).length == 0 )
ikkun
parents:
diff changeset
21 $( 'body' ).append( "<div class='layout'></div>");
ikkun
parents:
diff changeset
22
ikkun
parents:
diff changeset
23 $( '.layout' ).append( "<div id='counter'>" );
ikkun
parents:
diff changeset
24
ikkun
parents:
diff changeset
25 this.counterUpdate();
ikkun
parents:
diff changeset
26 }
ikkun
parents:
diff changeset
27
ikkun
parents:
diff changeset
28 Slideshow.counterDebugOn = function()
ikkun
parents:
diff changeset
29 {
ikkun
parents:
diff changeset
30 this.debug( 'calling counterDebugOn()' );
ikkun
parents:
diff changeset
31 $( '#counter' ).addClass( 'debug' );
ikkun
parents:
diff changeset
32 }
ikkun
parents:
diff changeset
33
ikkun
parents:
diff changeset
34 Slideshow.counterDebugOff = function()
ikkun
parents:
diff changeset
35 {
ikkun
parents:
diff changeset
36 this.debug( 'calling counterDebugOff()' );
ikkun
parents:
diff changeset
37 $( '#counter' ).removeClass( 'debug' );
ikkun
parents:
diff changeset
38 }
ikkun
parents:
diff changeset
39
ikkun
parents:
diff changeset
40 Slideshow.counterKeys = function( event, key )
ikkun
parents:
diff changeset
41 {
ikkun
parents:
diff changeset
42 this.debug( 'calling counterKeys()' );
ikkun
parents:
diff changeset
43
ikkun
parents:
diff changeset
44 switch( key.which ) {
ikkun
parents:
diff changeset
45 case 78: // n
ikkun
parents:
diff changeset
46 this.counterToggle();
ikkun
parents:
diff changeset
47 break;
ikkun
parents:
diff changeset
48 }
ikkun
parents:
diff changeset
49 }
ikkun
parents:
diff changeset
50
ikkun
parents:
diff changeset
51 Slideshow.counterChange = function()
ikkun
parents:
diff changeset
52 {
ikkun
parents:
diff changeset
53 this.debug( 'calling counterChange()' );
ikkun
parents:
diff changeset
54 this.counterUpdate();
ikkun
parents:
diff changeset
55 }
ikkun
parents:
diff changeset
56
ikkun
parents:
diff changeset
57 // ------------------------------------------------
ikkun
parents:
diff changeset
58
ikkun
parents:
diff changeset
59 Slideshow.counterUpdate = function()
ikkun
parents:
diff changeset
60 {
ikkun
parents:
diff changeset
61 $( '#counter' ).html( this.snum + '/' + this.smax );
ikkun
parents:
diff changeset
62 }
ikkun
parents:
diff changeset
63
ikkun
parents:
diff changeset
64
ikkun
parents:
diff changeset
65 Slideshow.counterToggle = function()
ikkun
parents:
diff changeset
66 {
ikkun
parents:
diff changeset
67 // toggle slide number/counter
ikkun
parents:
diff changeset
68
ikkun
parents:
diff changeset
69 // todo/fix: note jquery sets inline css (e.g. display: block)
ikkun
parents:
diff changeset
70 // but css won't get scoped for media (e.g. projection, screen, etc)
ikkun
parents:
diff changeset
71 // thus, css changes "spill over" to all media types
ikkun
parents:
diff changeset
72
ikkun
parents:
diff changeset
73 $( '#counter' ).toggle();
ikkun
parents:
diff changeset
74 }
ikkun
parents:
diff changeset
75
ikkun
parents:
diff changeset
76 // ------------------------------------------------
ikkun
parents:
diff changeset
77
ikkun
parents:
diff changeset
78 Slideshow.counterAddEvents = function()
ikkun
parents:
diff changeset
79 {
ikkun
parents:
diff changeset
80 $( document ).on( 'slideshow.init', $.proxy( Slideshow.counterInit, this ));
ikkun
parents:
diff changeset
81 $( document ).on( 'slideshow.debug.on', $.proxy( Slideshow.counterDebugOn, this ));
ikkun
parents:
diff changeset
82 $( document ).on( 'slideshow.debug.off', $.proxy( Slideshow.counterDebugOff, this ));
ikkun
parents:
diff changeset
83 $( document ).on( 'slideshow.keys', $.proxy( Slideshow.counterKeys, this ));
ikkun
parents:
diff changeset
84 $( document ).on( 'slideshow.change', $.proxy( Slideshow.counterChange, this ));
ikkun
parents:
diff changeset
85 }
ikkun
parents:
diff changeset
86
ikkun
parents:
diff changeset
87 Slideshow.counterAddStyles = function() {
ikkun
parents:
diff changeset
88 this.debug( 'add builtin counter css via inline style elements' );
ikkun
parents:
diff changeset
89
ikkun
parents:
diff changeset
90 var styleProjection =
ikkun
parents:
diff changeset
91 "<style media='screen,projection'> \n"+
ikkun
parents:
diff changeset
92 " \n"+
ikkun
parents:
diff changeset
93 " #counter.debug { background: #FFC; } \n"+
ikkun
parents:
diff changeset
94 " \n"+
ikkun
parents:
diff changeset
95 " #counter { position: fixed; \n"+
ikkun
parents:
diff changeset
96 " left: 45%; bottom: 1em; \n"+
ikkun
parents:
diff changeset
97 " width: 10%; \n"+
ikkun
parents:
diff changeset
98 " z-index: 10; \n"+
ikkun
parents:
diff changeset
99 " text-align: center; \n"+
ikkun
parents:
diff changeset
100 " font-size: 80%; \n"+
ikkun
parents:
diff changeset
101 " } \n"+
ikkun
parents:
diff changeset
102 " \n"+
ikkun
parents:
diff changeset
103 " #counter :link, \n"+
ikkun
parents:
diff changeset
104 " #counter :visited { text-decoration: none; } \n"+
ikkun
parents:
diff changeset
105 " \n"+
ikkun
parents:
diff changeset
106 "</style>";
ikkun
parents:
diff changeset
107
ikkun
parents:
diff changeset
108 var styleScreen =
ikkun
parents:
diff changeset
109 "<style media='screen'> \n"+
ikkun
parents:
diff changeset
110 " #counter { display: none !important; } \n"+
ikkun
parents:
diff changeset
111 "</style>";
ikkun
parents:
diff changeset
112
ikkun
parents:
diff changeset
113 $( 'head' ).append( styleProjection );
ikkun
parents:
diff changeset
114 $( 'head' ).append( styleScreen );
ikkun
parents:
diff changeset
115 }
ikkun
parents:
diff changeset
116
ikkun
parents:
diff changeset
117 Slideshow.counterAddStyles();
ikkun
parents:
diff changeset
118 Slideshow.counterAddEvents();