kamishibai 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/LICENSE +29 -0
  4. data/README.md +91 -0
  5. data/bin/kamishibai +59 -0
  6. data/changelogs.txt +6 -0
  7. data/images/reading.jpg +0 -0
  8. data/images/settings.jpg +0 -0
  9. data/images/view_browse.jpg +0 -0
  10. data/images/view_dir.jpg +0 -0
  11. data/kamishibai.gemspec +31 -0
  12. data/lib/kamishibai.rb +35 -0
  13. data/lib/kamishibai/book.rb +97 -0
  14. data/lib/kamishibai/config.rb +90 -0
  15. data/lib/kamishibai/database.rb +330 -0
  16. data/lib/kamishibai/functions.rb +332 -0
  17. data/lib/kamishibai/patches.rb +58 -0
  18. data/lib/kamishibai/version.rb +7 -0
  19. data/lib/kamishibai/webserver.rb +502 -0
  20. data/lib/kamishibai/webserver_cmds.rb +26 -0
  21. data/lib/kamishibai/webserver_config.rb +91 -0
  22. data/lib/kamishibai/webserver_filemanager.rb +29 -0
  23. data/lib/kamishibai/webserver_tablet.rb +259 -0
  24. data/lib/kamishibai/workers.rb +39 -0
  25. data/public/css/browse.css +390 -0
  26. data/public/css/config.css +3 -0
  27. data/public/css/reader.css +119 -0
  28. data/public/css/styles.css +30 -0
  29. data/public/css/tablet_browse.css +247 -0
  30. data/public/css/tablet_reader.css +323 -0
  31. data/public/css/tablet_reader_input.css +191 -0
  32. data/public/images/ajax-loader.gif +0 -0
  33. data/public/images/delete.png +0 -0
  34. data/public/images/folder-mini-up.png +0 -0
  35. data/public/images/folder-mini.png +0 -0
  36. data/public/images/spinner.gif +0 -0
  37. data/public/images/trash-empty-mini.png +0 -0
  38. data/public/images/trash-full-mini.png +0 -0
  39. data/public/js/browse.js +391 -0
  40. data/public/js/config.js +190 -0
  41. data/public/js/reader.js +497 -0
  42. data/public/js/swipeview-k.js +478 -0
  43. data/public/js/tablet3.js +241 -0
  44. data/public/js/tablet3_browse.js +173 -0
  45. data/public/js/tablet3_reader.js +534 -0
  46. data/public/js/utilities.js +170 -0
  47. data/public/lang/k-cn.json +82 -0
  48. data/public/lang/k-en.json +82 -0
  49. data/public/lang/k-ja.json +82 -0
  50. data/public/vendor/css/bootstrap-slider.css +252 -0
  51. data/public/vendor/css/bootstrap-theme.css +476 -0
  52. data/public/vendor/css/bootstrap-theme.css.map +1 -0
  53. data/public/vendor/css/bootstrap-theme.min.css +5 -0
  54. data/public/vendor/css/bootstrap.css +6584 -0
  55. data/public/vendor/css/bootstrap.css.map +1 -0
  56. data/public/vendor/css/bootstrap.min.css +5 -0
  57. data/public/vendor/css/jquery-ui-1.10.0.custom.css +1614 -0
  58. data/public/vendor/css/jquery.mobile-1.3.1.min.css +3 -0
  59. data/public/vendor/css/jqueryFileTree.css +91 -0
  60. data/public/vendor/fonts/glyphicons-halflings-regular.eot +0 -0
  61. data/public/vendor/fonts/glyphicons-halflings-regular.svg +288 -0
  62. data/public/vendor/fonts/glyphicons-halflings-regular.ttf +0 -0
  63. data/public/vendor/fonts/glyphicons-halflings-regular.woff +0 -0
  64. data/public/vendor/fonts/glyphicons-halflings-regular.woff2 +0 -0
  65. data/public/vendor/images/application.png +0 -0
  66. data/public/vendor/images/code.png +0 -0
  67. data/public/vendor/images/css.png +0 -0
  68. data/public/vendor/images/db.png +0 -0
  69. data/public/vendor/images/dim.png +0 -0
  70. data/public/vendor/images/directory.png +0 -0
  71. data/public/vendor/images/doc.png +0 -0
  72. data/public/vendor/images/file.png +0 -0
  73. data/public/vendor/images/film.png +0 -0
  74. data/public/vendor/images/flash.png +0 -0
  75. data/public/vendor/images/folder_open.png +0 -0
  76. data/public/vendor/images/grey.png +0 -0
  77. data/public/vendor/images/html.png +0 -0
  78. data/public/vendor/images/icons-18-black.png +0 -0
  79. data/public/vendor/images/icons-18-white.png +0 -0
  80. data/public/vendor/images/icons-36-black.png +0 -0
  81. data/public/vendor/images/icons-36-white.png +0 -0
  82. data/public/vendor/images/java.png +0 -0
  83. data/public/vendor/images/linux.png +0 -0
  84. data/public/vendor/images/music.png +0 -0
  85. data/public/vendor/images/pdf.png +0 -0
  86. data/public/vendor/images/php.png +0 -0
  87. data/public/vendor/images/picture.png +0 -0
  88. data/public/vendor/images/ppt.png +0 -0
  89. data/public/vendor/images/psd.png +0 -0
  90. data/public/vendor/images/ruby.png +0 -0
  91. data/public/vendor/images/script.png +0 -0
  92. data/public/vendor/images/spinner.gif +0 -0
  93. data/public/vendor/images/txt.png +0 -0
  94. data/public/vendor/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  95. data/public/vendor/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  96. data/public/vendor/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  97. data/public/vendor/images/ui-bg_flat_10_000000_40x100.png +0 -0
  98. data/public/vendor/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
  99. data/public/vendor/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
  100. data/public/vendor/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
  101. data/public/vendor/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  102. data/public/vendor/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  103. data/public/vendor/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  104. data/public/vendor/images/ui-bg_glass_20_555555_1x400.png +0 -0
  105. data/public/vendor/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
  106. data/public/vendor/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
  107. data/public/vendor/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  108. data/public/vendor/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  109. data/public/vendor/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  110. data/public/vendor/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  111. data/public/vendor/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  112. data/public/vendor/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  113. data/public/vendor/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  114. data/public/vendor/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
  115. data/public/vendor/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  116. data/public/vendor/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  117. data/public/vendor/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  118. data/public/vendor/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  119. data/public/vendor/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  120. data/public/vendor/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
  121. data/public/vendor/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  122. data/public/vendor/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  123. data/public/vendor/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
  124. data/public/vendor/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
  125. data/public/vendor/images/ui-icons_217bc0_256x240.png +0 -0
  126. data/public/vendor/images/ui-icons_222222_256x240.png +0 -0
  127. data/public/vendor/images/ui-icons_228ef1_256x240.png +0 -0
  128. data/public/vendor/images/ui-icons_2e83ff_256x240.png +0 -0
  129. data/public/vendor/images/ui-icons_454545_256x240.png +0 -0
  130. data/public/vendor/images/ui-icons_469bdd_256x240.png +0 -0
  131. data/public/vendor/images/ui-icons_4b8e0b_256x240.png +0 -0
  132. data/public/vendor/images/ui-icons_6da8d5_256x240.png +0 -0
  133. data/public/vendor/images/ui-icons_888888_256x240.png +0 -0
  134. data/public/vendor/images/ui-icons_a83300_256x240.png +0 -0
  135. data/public/vendor/images/ui-icons_cccccc_256x240.png +0 -0
  136. data/public/vendor/images/ui-icons_cd0a0a_256x240.png +0 -0
  137. data/public/vendor/images/ui-icons_d8e7f3_256x240.png +0 -0
  138. data/public/vendor/images/ui-icons_ef8c08_256x240.png +0 -0
  139. data/public/vendor/images/ui-icons_f9bd01_256x240.png +0 -0
  140. data/public/vendor/images/ui-icons_ffd27a_256x240.png +0 -0
  141. data/public/vendor/images/ui-icons_ffffff_256x240.png +0 -0
  142. data/public/vendor/images/xls.png +0 -0
  143. data/public/vendor/images/zip.png +0 -0
  144. data/public/vendor/js/bootstrap-slider.js +1550 -0
  145. data/public/vendor/js/bootstrap.js +2317 -0
  146. data/public/vendor/js/bootstrap.min.js +7 -0
  147. data/public/vendor/js/jquery-2.1.4.js +9210 -0
  148. data/public/vendor/js/jquery-2.1.4.min.js +4 -0
  149. data/public/vendor/js/jquery-2.1.4.min.map +1 -0
  150. data/public/vendor/js/jquery-ui-1.10.2.custom.min.js +7 -0
  151. data/public/vendor/js/jquery.cookie.js +72 -0
  152. data/public/vendor/js/jquery.hammer.min.js +7 -0
  153. data/public/vendor/js/jquery.lazyload.min.js +15 -0
  154. data/public/vendor/js/jquery.localize.js +180 -0
  155. data/public/vendor/js/jquery.mobile-1.3.1.min.js +7 -0
  156. data/public/vendor/js/jquery.scrollTo-1.4.3.1.js +218 -0
  157. data/public/vendor/js/jqueryFileTree.js +95 -0
  158. data/public/vendor/js/swipeview.js +471 -0
  159. data/views/browse.haml +97 -0
  160. data/views/config.haml +115 -0
  161. data/views/layout.haml +12 -0
  162. data/views/login.haml +51 -0
  163. data/views/reader.haml +70 -0
  164. data/views/statistics.haml +108 -0
  165. data/views/tablet3.haml +80 -0
  166. metadata +334 -0
@@ -0,0 +1,95 @@
1
+ // jQuery File Tree Plugin
2
+ //
3
+ // Version 1.01
4
+ //
5
+ // Cory S.N. LaViska
6
+ // A Beautiful Site (http://abeautifulsite.net/)
7
+ // 24 March 2008
8
+ //
9
+ // Visit http://abeautifulsite.net/notebook.php?article=58 for more information
10
+ //
11
+ // Usage: $('.fileTreeDemo').fileTree( options, callback )
12
+ //
13
+ // Options: root - root folder to display; default = /
14
+ // script - location of the serverside AJAX file to use; default = jqueryFileTree.php
15
+ // folderEvent - event to trigger expand/collapse; default = click
16
+ // expandSpeed - default = 500 (ms); use -1 for no animation
17
+ // collapseSpeed - default = 500 (ms); use -1 for no animation
18
+ // expandEasing - easing function to use on expand (optional)
19
+ // collapseEasing - easing function to use on collapse (optional)
20
+ // multiFolder - whether or not to limit the browser to one subfolder at a time
21
+ // loadMessage - Message to display while initial tree loads (can be HTML)
22
+ //
23
+ // History:
24
+ //
25
+ // 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
26
+ // 1.00 - released (24 March 2008)
27
+ //
28
+ // TERMS OF USE
29
+ //
30
+ // This plugin is dual-licensed under the GNU General Public License and the MIT License and
31
+ // is copyright 2008 A Beautiful Site, LLC.
32
+ //
33
+ if(jQuery) (function($){
34
+
35
+ $.extend($.fn, {
36
+ fileTree: function(o, h) {
37
+ // Defaults
38
+ if( !o ) var o = {};
39
+ if( o.root == undefined ) o.root = '/';
40
+ if( o.script == undefined ) o.script = 'jqueryFileTree.php';
41
+ if( o.folderEvent == undefined ) o.folderEvent = 'click';
42
+ if( o.expandSpeed == undefined ) o.expandSpeed= 500;
43
+ if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
44
+ if( o.expandEasing == undefined ) o.expandEasing = null;
45
+ if( o.collapseEasing == undefined ) o.collapseEasing = null;
46
+ if( o.multiFolder == undefined ) o.multiFolder = true;
47
+ if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';
48
+
49
+ $(this).each( function() {
50
+
51
+ function showTree(c, t) {
52
+ $(c).addClass('wait');
53
+ $(".jqueryFileTree.start").remove();
54
+ $.post(o.script, { dir: t }, function(data) {
55
+ $(c).find('.start').html('');
56
+ $(c).removeClass('wait').append(data);
57
+ if( o.root == t ) $(c).find('UL:hidden').show(); else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
58
+ bindTree(c);
59
+ });
60
+ }
61
+
62
+ function bindTree(t) {
63
+ $(t).find('LI A').bind(o.folderEvent, function() {
64
+ if( $(this).parent().hasClass('directory') ) {
65
+ if( $(this).parent().hasClass('collapsed') ) {
66
+ // Expand
67
+ if( !o.multiFolder ) {
68
+ $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
69
+ $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
70
+ }
71
+ $(this).parent().find('UL').remove(); // cleanup
72
+ showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) );
73
+ $(this).parent().removeClass('collapsed').addClass('expanded');
74
+ } else {
75
+ // Collapse
76
+ $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
77
+ $(this).parent().removeClass('expanded').addClass('collapsed');
78
+ }
79
+ } else {
80
+ h($(this).attr('rel'));
81
+ }
82
+ return false;
83
+ });
84
+ // Prevent A from triggering the # on non-click events
85
+ if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; });
86
+ }
87
+ // Loading message
88
+ $(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>');
89
+ // Get the initial file list
90
+ showTree( $(this), escape(o.root) );
91
+ });
92
+ }
93
+ });
94
+
95
+ })(jQuery);
@@ -0,0 +1,471 @@
1
+ /*!
2
+ * SwipeView v1.0 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
3
+ * Released under MIT license, http://cubiq.org/license
4
+ */
5
+ var SwipeView = (function (window, document) {
6
+ var dummyStyle = document.createElement('div').style,
7
+ vendor = (function () {
8
+ var vendors = 't,webkitT,MozT,msT,OT'.split(','),
9
+ t,
10
+ i = 0,
11
+ l = vendors.length;
12
+
13
+ for ( ; i < l; i++ ) {
14
+ t = vendors[i] + 'ransform';
15
+ if ( t in dummyStyle ) {
16
+ return vendors[i].substr(0, vendors[i].length - 1);
17
+ }
18
+ }
19
+
20
+ return false;
21
+ })(),
22
+ cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '',
23
+
24
+ // Style properties
25
+ transform = prefixStyle('transform'),
26
+ transitionDuration = prefixStyle('transitionDuration'),
27
+
28
+ // Browser capabilities
29
+ has3d = prefixStyle('perspective') in dummyStyle,
30
+ hasTouch = 'ontouchstart' in window,
31
+ hasTransform = !!vendor,
32
+ hasTransitionEnd = prefixStyle('transition') in dummyStyle,
33
+
34
+ // Helpers
35
+ translateZ = has3d ? ' translateZ(0)' : '',
36
+
37
+ // Events
38
+ resizeEvent = 'onorientationchange' in window ? 'orientationchange' : 'resize',
39
+ startEvent = hasTouch ? 'touchstart' : 'mousedown',
40
+ moveEvent = hasTouch ? 'touchmove' : 'mousemove',
41
+ endEvent = hasTouch ? 'touchend' : 'mouseup',
42
+ cancelEvent = hasTouch ? 'touchcancel' : 'mouseup',
43
+ transitionEndEvent = (function () {
44
+ if ( vendor === false ) return false;
45
+
46
+ var transitionEnd = {
47
+ '' : 'transitionend',
48
+ 'webkit' : 'webkitTransitionEnd',
49
+ 'Moz' : 'transitionend',
50
+ 'O' : 'oTransitionEnd',
51
+ 'ms' : 'MSTransitionEnd'
52
+ };
53
+
54
+ return transitionEnd[vendor];
55
+ })(),
56
+
57
+ SwipeView = function (el, options) {
58
+ var i,
59
+ div,
60
+ className,
61
+ pageIndex;
62
+
63
+ this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
64
+ this.options = {
65
+ text: null,
66
+ numberOfPages: 3,
67
+ snapThreshold: null,
68
+ hastyPageFlip: false,
69
+ loop: true
70
+ };
71
+
72
+ // User defined options
73
+ for (i in options) this.options[i] = options[i];
74
+
75
+ this.wrapper.style.overflow = 'hidden';
76
+ this.wrapper.style.position = 'relative';
77
+
78
+ this.masterPages = [];
79
+
80
+ div = document.createElement('div');
81
+ div.id = 'swipeview-slider';
82
+ div.style.cssText = 'position:relative;top:0;height:100%;width:100%;' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform:translateZ(0);' + cssVendor + 'transition-timing-function:ease-out';
83
+ this.wrapper.appendChild(div);
84
+ this.slider = div;
85
+
86
+ this.refreshSize();
87
+
88
+ for (i=-1; i<2; i++) {
89
+ div = document.createElement('div');
90
+ div.id = 'swipeview-masterpage-' + (i+1);
91
+ div.style.cssText = cssVendor + 'transform:translateZ(0);position:absolute;top:0;height:100%;width:100%;left:' + i*100 + '%';
92
+ if (!div.dataset) div.dataset = {};
93
+ pageIndex = i == -1 ? this.options.numberOfPages - 1 : i;
94
+ div.dataset.pageIndex = pageIndex;
95
+ div.dataset.upcomingPageIndex = pageIndex;
96
+
97
+ if (!this.options.loop && i == -1) div.style.visibility = 'hidden';
98
+
99
+ this.slider.appendChild(div);
100
+ this.masterPages.push(div);
101
+ }
102
+
103
+ className = this.masterPages[1].className;
104
+ this.masterPages[1].className = !className ? 'swipeview-active' : className + ' swipeview-active';
105
+
106
+ window.addEventListener(resizeEvent, this, false);
107
+ this.wrapper.addEventListener(startEvent, this, false);
108
+ this.wrapper.addEventListener(moveEvent, this, false);
109
+ this.wrapper.addEventListener(endEvent, this, false);
110
+ this.slider.addEventListener(transitionEndEvent, this, false);
111
+ // in Opera >= 12 the transitionend event is lowercase so we register both events
112
+ if ( vendor == 'O' ) this.slider.addEventListener(transitionEndEvent.toLowerCase(), this, false);
113
+
114
+ /* if (!hasTouch) {
115
+ this.wrapper.addEventListener('mouseout', this, false);
116
+ }*/
117
+ };
118
+
119
+ SwipeView.prototype = {
120
+ currentMasterPage: 1,
121
+ x: 0,
122
+ page: 0,
123
+ pageIndex: 0,
124
+ customEvents: [],
125
+
126
+ onFlip: function (fn) {
127
+ this.wrapper.addEventListener('swipeview-flip', fn, false);
128
+ this.customEvents.push(['flip', fn]);
129
+ },
130
+
131
+ onMoveOut: function (fn) {
132
+ this.wrapper.addEventListener('swipeview-moveout', fn, false);
133
+ this.customEvents.push(['moveout', fn]);
134
+ },
135
+
136
+ onMoveIn: function (fn) {
137
+ this.wrapper.addEventListener('swipeview-movein', fn, false);
138
+ this.customEvents.push(['movein', fn]);
139
+ },
140
+
141
+ onTouchStart: function (fn) {
142
+ this.wrapper.addEventListener('swipeview-touchstart', fn, false);
143
+ this.customEvents.push(['touchstart', fn]);
144
+ },
145
+
146
+ destroy: function () {
147
+ while ( this.customEvents.length ) {
148
+ this.wrapper.removeEventListener('swipeview-' + this.customEvents[0][0], this.customEvents[0][1], false);
149
+ this.customEvents.shift();
150
+ }
151
+
152
+ // Remove the event listeners
153
+ window.removeEventListener(resizeEvent, this, false);
154
+ this.wrapper.removeEventListener(startEvent, this, false);
155
+ this.wrapper.removeEventListener(moveEvent, this, false);
156
+ this.wrapper.removeEventListener(endEvent, this, false);
157
+ this.slider.removeEventListener(transitionEndEvent, this, false);
158
+
159
+ /* if (!hasTouch) {
160
+ this.wrapper.removeEventListener('mouseout', this, false);
161
+ }*/
162
+ },
163
+
164
+ refreshSize: function () {
165
+ this.wrapperWidth = this.wrapper.clientWidth;
166
+ this.wrapperHeight = this.wrapper.clientHeight;
167
+ this.pageWidth = this.wrapperWidth;
168
+ this.maxX = -this.options.numberOfPages * this.pageWidth + this.wrapperWidth;
169
+ this.snapThreshold = this.options.snapThreshold === null ?
170
+ Math.round(this.pageWidth * 0.15) :
171
+ /%/.test(this.options.snapThreshold) ?
172
+ Math.round(this.pageWidth * this.options.snapThreshold.replace('%', '') / 100) :
173
+ this.options.snapThreshold;
174
+ },
175
+
176
+ updatePageCount: function (n) {
177
+ this.options.numberOfPages = n;
178
+ this.maxX = -this.options.numberOfPages * this.pageWidth + this.wrapperWidth;
179
+ },
180
+
181
+ goToPage: function (p) {
182
+ var i;
183
+
184
+ this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, '');
185
+ for (i=0; i<3; i++) {
186
+ className = this.masterPages[i].className;
187
+ /(^|\s)swipeview-loading(\s|$)/.test(className) || (this.masterPages[i].className = !className ? 'swipeview-loading' : className + ' swipeview-loading');
188
+ }
189
+
190
+ p = p < 0 ? 0 : p > this.options.numberOfPages-1 ? this.options.numberOfPages-1 : p;
191
+ this.page = p;
192
+ this.pageIndex = p;
193
+ this.slider.style[transitionDuration] = '0s';
194
+ this.__pos(-p * this.pageWidth);
195
+
196
+ this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3;
197
+
198
+ this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className + ' swipeview-active';
199
+
200
+ if (this.currentMasterPage === 0) {
201
+ this.masterPages[2].style.left = this.page * 100 - 100 + '%';
202
+ this.masterPages[0].style.left = this.page * 100 + '%';
203
+ this.masterPages[1].style.left = this.page * 100 + 100 + '%';
204
+
205
+ this.masterPages[2].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1;
206
+ this.masterPages[0].dataset.upcomingPageIndex = this.page;
207
+ this.masterPages[1].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1;
208
+ } else if (this.currentMasterPage == 1) {
209
+ this.masterPages[0].style.left = this.page * 100 - 100 + '%';
210
+ this.masterPages[1].style.left = this.page * 100 + '%';
211
+ this.masterPages[2].style.left = this.page * 100 + 100 + '%';
212
+
213
+ this.masterPages[0].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1;
214
+ this.masterPages[1].dataset.upcomingPageIndex = this.page;
215
+ this.masterPages[2].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1;
216
+ } else {
217
+ this.masterPages[1].style.left = this.page * 100 - 100 + '%';
218
+ this.masterPages[2].style.left = this.page * 100 + '%';
219
+ this.masterPages[0].style.left = this.page * 100 + 100 + '%';
220
+
221
+ this.masterPages[1].dataset.upcomingPageIndex = this.page === 0 ? this.options.numberOfPages-1 : this.page - 1;
222
+ this.masterPages[2].dataset.upcomingPageIndex = this.page;
223
+ this.masterPages[0].dataset.upcomingPageIndex = this.page == this.options.numberOfPages-1 ? 0 : this.page + 1;
224
+ }
225
+
226
+ this.__flip();
227
+ },
228
+
229
+ next: function () {
230
+ if (!this.options.loop && this.x == this.maxX) return;
231
+
232
+ this.directionX = -1;
233
+ this.x -= 1;
234
+ this.__checkPosition();
235
+ },
236
+
237
+ prev: function () {
238
+ if (!this.options.loop && this.x === 0) return;
239
+
240
+ this.directionX = 1;
241
+ this.x += 1;
242
+ this.__checkPosition();
243
+ },
244
+
245
+ handleEvent: function (e) {
246
+ switch (e.type) {
247
+ case startEvent:
248
+ this.__start(e);
249
+ break;
250
+ case moveEvent:
251
+ this.__move(e);
252
+ break;
253
+ case cancelEvent:
254
+ case endEvent:
255
+ this.__end(e);
256
+ break;
257
+ case resizeEvent:
258
+ this.__resize();
259
+ break;
260
+ case transitionEndEvent:
261
+ case 'otransitionend':
262
+ if (e.target == this.slider && !this.options.hastyPageFlip) this.__flip();
263
+ break;
264
+ }
265
+ },
266
+
267
+
268
+ /**
269
+ *
270
+ * Pseudo private methods
271
+ *
272
+ */
273
+ __pos: function (x) {
274
+ this.x = x;
275
+ this.slider.style[transform] = 'translate(' + x + 'px,0)' + translateZ;
276
+ },
277
+
278
+ __resize: function () {
279
+ this.refreshSize();
280
+ this.slider.style[transitionDuration] = '0s';
281
+ this.__pos(-this.page * this.pageWidth);
282
+ },
283
+
284
+ __start: function (e) {
285
+ //e.preventDefault();
286
+
287
+ if (this.initiated) return;
288
+
289
+ var point = hasTouch ? e.touches[0] : e;
290
+
291
+ this.initiated = true;
292
+ this.moved = false;
293
+ this.thresholdExceeded = false;
294
+ this.startX = point.pageX;
295
+ this.startY = point.pageY;
296
+ this.pointX = point.pageX;
297
+ this.pointY = point.pageY;
298
+ this.stepsX = 0;
299
+ this.stepsY = 0;
300
+ this.directionX = 0;
301
+ this.directionLocked = false;
302
+
303
+ /* var matrix = getComputedStyle(this.slider, null).webkitTransform.replace(/[^0-9-.,]/g, '').split(',');
304
+ this.x = matrix[4] * 1;*/
305
+
306
+ this.slider.style[transitionDuration] = '0s';
307
+
308
+ this.__event('touchstart');
309
+ },
310
+
311
+ __move: function (e) {
312
+ if (!this.initiated) return;
313
+
314
+ var point = hasTouch ? e.touches[0] : e,
315
+ deltaX = point.pageX - this.pointX,
316
+ deltaY = point.pageY - this.pointY,
317
+ newX = this.x + deltaX,
318
+ dist = Math.abs(point.pageX - this.startX);
319
+
320
+ this.moved = true;
321
+ this.pointX = point.pageX;
322
+ this.pointY = point.pageY;
323
+ this.directionX = deltaX > 0 ? 1 : deltaX < 0 ? -1 : 0;
324
+ this.stepsX += Math.abs(deltaX);
325
+ this.stepsY += Math.abs(deltaY);
326
+
327
+ // We take a 10px buffer to figure out the direction of the swipe
328
+ if (this.stepsX < 10 && this.stepsY < 10) {
329
+ // e.preventDefault();
330
+ return;
331
+ }
332
+
333
+ // We are scrolling vertically, so skip SwipeView and give the control back to the browser
334
+ if (!this.directionLocked && this.stepsY > this.stepsX) {
335
+ this.initiated = false;
336
+ return;
337
+ }
338
+
339
+ e.preventDefault();
340
+
341
+ this.directionLocked = true;
342
+
343
+ if (!this.options.loop && (newX > 0 || newX < this.maxX)) {
344
+ newX = this.x + (deltaX / 2);
345
+ }
346
+
347
+ if (!this.thresholdExceeded && dist >= this.snapThreshold) {
348
+ this.thresholdExceeded = true;
349
+ this.__event('moveout');
350
+ } else if (this.thresholdExceeded && dist < this.snapThreshold) {
351
+ this.thresholdExceeded = false;
352
+ this.__event('movein');
353
+ }
354
+
355
+ /* if (newX > 0 || newX < this.maxX) {
356
+ newX = this.x + (deltaX / 2);
357
+ }*/
358
+
359
+ this.__pos(newX);
360
+ },
361
+
362
+ __end: function (e) {
363
+ if (!this.initiated) return;
364
+
365
+ var point = hasTouch ? e.changedTouches[0] : e,
366
+ dist = Math.abs(point.pageX - this.startX);
367
+
368
+ this.initiated = false;
369
+
370
+ if (!this.moved) return;
371
+
372
+ if (!this.options.loop && (this.x > 0 || this.x < this.maxX)) {
373
+ dist = 0;
374
+ this.__event('movein');
375
+ }
376
+
377
+ // Check if we exceeded the snap threshold
378
+ if (dist < this.snapThreshold) {
379
+ this.slider.style[transitionDuration] = Math.floor(300 * dist / this.snapThreshold) + 'ms';
380
+ this.__pos(-this.page * this.pageWidth);
381
+ return;
382
+ }
383
+
384
+ this.__checkPosition();
385
+ },
386
+
387
+ __checkPosition: function () {
388
+ var pageFlip,
389
+ pageFlipIndex,
390
+ className;
391
+
392
+ this.masterPages[this.currentMasterPage].className = this.masterPages[this.currentMasterPage].className.replace(/(^|\s)swipeview-active(\s|$)/, '');
393
+
394
+ // Flip the page
395
+ if (this.directionX > 0) {
396
+ this.page = -Math.ceil(this.x / this.pageWidth);
397
+ this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3;
398
+ this.pageIndex = this.pageIndex === 0 ? this.options.numberOfPages - 1 : this.pageIndex - 1;
399
+
400
+ pageFlip = this.currentMasterPage - 1;
401
+ pageFlip = pageFlip < 0 ? 2 : pageFlip;
402
+ this.masterPages[pageFlip].style.left = this.page * 100 - 100 + '%';
403
+
404
+ pageFlipIndex = this.page - 1;
405
+ } else {
406
+ this.page = -Math.floor(this.x / this.pageWidth);
407
+ this.currentMasterPage = (this.page + 1) - Math.floor((this.page + 1) / 3) * 3;
408
+ this.pageIndex = this.pageIndex == this.options.numberOfPages - 1 ? 0 : this.pageIndex + 1;
409
+
410
+ pageFlip = this.currentMasterPage + 1;
411
+ pageFlip = pageFlip > 2 ? 0 : pageFlip;
412
+ this.masterPages[pageFlip].style.left = this.page * 100 + 100 + '%';
413
+
414
+ pageFlipIndex = this.page + 1;
415
+ }
416
+
417
+ // Add active class to current page
418
+ className = this.masterPages[this.currentMasterPage].className;
419
+ /(^|\s)swipeview-active(\s|$)/.test(className) || (this.masterPages[this.currentMasterPage].className = !className ? 'swipeview-active' : className + ' swipeview-active');
420
+
421
+ // Add loading class to flipped page
422
+ className = this.masterPages[pageFlip].className;
423
+ /(^|\s)swipeview-loading(\s|$)/.test(className) || (this.masterPages[pageFlip].className = !className ? 'swipeview-loading' : className + ' swipeview-loading');
424
+
425
+ pageFlipIndex = pageFlipIndex - Math.floor(pageFlipIndex / this.options.numberOfPages) * this.options.numberOfPages;
426
+ this.masterPages[pageFlip].dataset.upcomingPageIndex = pageFlipIndex; // Index to be loaded in the newly flipped page
427
+
428
+ newX = -this.page * this.pageWidth;
429
+
430
+ this.slider.style[transitionDuration] = Math.floor(500 * Math.abs(this.x - newX) / this.pageWidth) + 'ms';
431
+
432
+ // Hide the next page if we decided to disable looping
433
+ if (!this.options.loop) {
434
+ this.masterPages[pageFlip].style.visibility = newX === 0 || newX == this.maxX ? 'hidden' : '';
435
+ }
436
+
437
+ if (this.x == newX) {
438
+ this.__flip(); // If we swiped all the way long to the next page (extremely rare but still)
439
+ } else {
440
+ this.__pos(newX);
441
+ if (this.options.hastyPageFlip) this.__flip();
442
+ }
443
+ },
444
+
445
+ __flip: function () {
446
+ this.__event('flip');
447
+
448
+ for (var i=0; i<3; i++) {
449
+ this.masterPages[i].className = this.masterPages[i].className.replace(/(^|\s)swipeview-loading(\s|$)/, ''); // Remove the loading class
450
+ this.masterPages[i].dataset.pageIndex = this.masterPages[i].dataset.upcomingPageIndex;
451
+ }
452
+ },
453
+
454
+ __event: function (type) {
455
+ var ev = document.createEvent("Event");
456
+
457
+ ev.initEvent('swipeview-' + type, true, true);
458
+
459
+ this.wrapper.dispatchEvent(ev);
460
+ }
461
+ };
462
+
463
+ function prefixStyle (style) {
464
+ if ( vendor === '' ) return style;
465
+
466
+ style = style.charAt(0).toUpperCase() + style.substr(1);
467
+ return vendor + style;
468
+ }
469
+
470
+ return SwipeView;
471
+ })(window, document);