jinda 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/generators/jinda/config_generator.rb +7 -0
  4. data/lib/generators/jinda/install_generator.rb +45 -42
  5. data/lib/generators/jinda/templates/app/assets/javascripts/application.js +1 -10
  6. data/lib/generators/jinda/templates/app/assets/stylesheets/application.css.scss +1 -20
  7. data/lib/jinda.rb +2 -1
  8. data/lib/jinda/date_helpers.rb +109 -0
  9. data/lib/jinda/{gemhelpers.rb → gem_helpers.rb} +0 -1
  10. data/lib/jinda/gen_class.rb +13 -0
  11. data/lib/jinda/gen_controller.rb +10 -0
  12. data/lib/jinda/gen_freemind.rb +33 -0
  13. data/lib/jinda/gen_helpers.rb +141 -0
  14. data/lib/jinda/gen_models.rb +137 -0
  15. data/lib/jinda/gen_runseq.rb +71 -0
  16. data/lib/jinda/gen_services.rb +90 -0
  17. data/lib/jinda/gen_xmain.rb +38 -0
  18. data/lib/jinda/get_app.rb +34 -0
  19. data/lib/jinda/helpers.rb +17 -998
  20. data/lib/jinda/init_vars.rb +36 -0
  21. data/lib/jinda/rake_views.rb +59 -0
  22. data/lib/jinda/refresh.rb +67 -0
  23. data/lib/jinda/themes.rb +163 -0
  24. data/lib/jinda/version.rb +1 -1
  25. data/test/dummy/Rakefile +6 -0
  26. data/test/dummy/app/assets/config/manifest.js +3 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  29. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  30. data/test/dummy/app/controllers/application_controller.rb +2 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/javascript/packs/application.js +15 -0
  33. data/test/dummy/app/jobs/application_job.rb +7 -0
  34. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  35. data/test/dummy/app/models/application_record.rb +3 -0
  36. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  38. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  39. data/test/dummy/bin/rails +4 -0
  40. data/test/dummy/bin/rake +4 -0
  41. data/test/dummy/bin/setup +33 -0
  42. data/test/dummy/config.ru +5 -0
  43. data/test/dummy/config/application.rb +19 -0
  44. data/test/dummy/config/boot.rb +5 -0
  45. data/test/dummy/config/cable.yml +10 -0
  46. data/test/dummy/config/database.yml +25 -0
  47. data/test/dummy/config/environment.rb +5 -0
  48. data/test/dummy/config/environments/development.rb +62 -0
  49. data/test/dummy/config/environments/production.rb +112 -0
  50. data/test/dummy/config/environments/test.rb +49 -0
  51. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  52. data/test/dummy/config/initializers/assets.rb +12 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  55. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  56. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/test/dummy/config/initializers/inflections.rb +16 -0
  58. data/test/dummy/config/initializers/mime_types.rb +4 -0
  59. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/test/dummy/config/locales/en.yml +33 -0
  61. data/test/dummy/config/puma.rb +38 -0
  62. data/test/dummy/config/routes.rb +3 -0
  63. data/test/dummy/config/spring.rb +6 -0
  64. data/test/dummy/config/storage.yml +34 -0
  65. data/test/dummy/db/development.sqlite3 +0 -0
  66. data/test/dummy/log/development.log +8 -0
  67. data/test/dummy/public/404.html +67 -0
  68. data/test/dummy/public/422.html +67 -0
  69. data/test/dummy/public/500.html +66 -0
  70. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  71. data/test/dummy/public/apple-touch-icon.png +0 -0
  72. data/test/dummy/public/favicon.ico +0 -0
  73. data/test/dummy/tmp/development_secret.txt +1 -0
  74. data/test/integration/navigation_test.rb +7 -0
  75. data/test/jinda_test.rb +7 -0
  76. data/test/test_helper.rb +19 -0
  77. metadata +84 -141
  78. data/lib/generators/jinda/templates/app/assets/images/4dcity-old.ico +0 -0
  79. data/lib/generators/jinda/templates/app/assets/images/4dcity.ico +0 -0
  80. data/lib/generators/jinda/templates/app/assets/images/account.png +0 -0
  81. data/lib/generators/jinda/templates/app/assets/images/add.png +0 -0
  82. data/lib/generators/jinda/templates/app/assets/images/ajax-loader-circle.gif +0 -0
  83. data/lib/generators/jinda/templates/app/assets/images/ajax-loader.gif +0 -0
  84. data/lib/generators/jinda/templates/app/assets/images/anchor.png +0 -0
  85. data/lib/generators/jinda/templates/app/assets/images/application_double.png +0 -0
  86. data/lib/generators/jinda/templates/app/assets/images/application_form_edit.png +0 -0
  87. data/lib/generators/jinda/templates/app/assets/images/arrow_left.png +0 -0
  88. data/lib/generators/jinda/templates/app/assets/images/arrow_right.png +0 -0
  89. data/lib/generators/jinda/templates/app/assets/images/arrow_turn_left.png +0 -0
  90. data/lib/generators/jinda/templates/app/assets/images/arrow_turn_right.png +0 -0
  91. data/lib/generators/jinda/templates/app/assets/images/calendar.png +0 -0
  92. data/lib/generators/jinda/templates/app/assets/images/cancel.png +0 -0
  93. data/lib/generators/jinda/templates/app/assets/images/chart_bar.png +0 -0
  94. data/lib/generators/jinda/templates/app/assets/images/clock.png +0 -0
  95. data/lib/generators/jinda/templates/app/assets/images/cog.png +0 -0
  96. data/lib/generators/jinda/templates/app/assets/images/control_fastforward.png +0 -0
  97. data/lib/generators/jinda/templates/app/assets/images/control_play.png +0 -0
  98. data/lib/generators/jinda/templates/app/assets/images/cross.png +0 -0
  99. data/lib/generators/jinda/templates/app/assets/images/delete.png +0 -0
  100. data/lib/generators/jinda/templates/app/assets/images/external-link.png +0 -0
  101. data/lib/generators/jinda/templates/app/assets/images/facebook-continue-button.png +0 -0
  102. data/lib/generators/jinda/templates/app/assets/images/facebooksmall.png +0 -0
  103. data/lib/generators/jinda/templates/app/assets/images/favicon.ico +0 -0
  104. data/lib/generators/jinda/templates/app/assets/images/freemind(mm).png +0 -0
  105. data/lib/generators/jinda/templates/app/assets/images/google-continue-button.png +0 -0
  106. data/lib/generators/jinda/templates/app/assets/images/help.png +0 -0
  107. data/lib/generators/jinda/templates/app/assets/images/highway-menu.png +0 -0
  108. data/lib/generators/jinda/templates/app/assets/images/highway.png +0 -0
  109. data/lib/generators/jinda/templates/app/assets/images/house.png +0 -0
  110. data/lib/generators/jinda/templates/app/assets/images/icons-18-black.png +0 -0
  111. data/lib/generators/jinda/templates/app/assets/images/icons-18-white.png +0 -0
  112. data/lib/generators/jinda/templates/app/assets/images/icons-36-black.png +0 -0
  113. data/lib/generators/jinda/templates/app/assets/images/icons-36-white.png +0 -0
  114. data/lib/generators/jinda/templates/app/assets/images/logo.png +0 -0
  115. data/lib/generators/jinda/templates/app/assets/images/logo_jinda.png +0 -0
  116. data/lib/generators/jinda/templates/app/assets/images/logout.png +0 -0
  117. data/lib/generators/jinda/templates/app/assets/images/new.gif +0 -0
  118. data/lib/generators/jinda/templates/app/assets/images/new.png +0 -0
  119. data/lib/generators/jinda/templates/app/assets/images/page.png +0 -0
  120. data/lib/generators/jinda/templates/app/assets/images/page_attach.png +0 -0
  121. data/lib/generators/jinda/templates/app/assets/images/page_green.png +0 -0
  122. data/lib/generators/jinda/templates/app/assets/images/page_output.png +0 -0
  123. data/lib/generators/jinda/templates/app/assets/images/page_pdf.png +0 -0
  124. data/lib/generators/jinda/templates/app/assets/images/pencil.png +0 -0
  125. data/lib/generators/jinda/templates/app/assets/images/printer.png +0 -0
  126. data/lib/generators/jinda/templates/app/assets/images/refresh.png +0 -0
  127. data/lib/generators/jinda/templates/app/assets/images/report.png +0 -0
  128. data/lib/generators/jinda/templates/app/assets/images/rssmall.png +0 -0
  129. data/lib/generators/jinda/templates/app/assets/images/tick.png +0 -0
  130. data/lib/generators/jinda/templates/app/assets/images/twittersmall.png +0 -0
  131. data/lib/generators/jinda/templates/app/assets/images/user.png +0 -0
  132. data/lib/generators/jinda/templates/app/assets/images/user_admin_gear.png +0 -0
  133. data/lib/generators/jinda/templates/app/assets/images/view_code.png +0 -0
  134. data/lib/generators/jinda/templates/app/assets/javascripts/application.js-jqm +0 -27
  135. data/lib/generators/jinda/templates/app/assets/javascripts/cable.js +0 -13
  136. data/lib/generators/jinda/templates/app/assets/javascripts/disable_enter_key.js +0 -10
  137. data/lib/generators/jinda/templates/app/assets/javascripts/iscroll-wrapper.js +0 -32
  138. data/lib/generators/jinda/templates/app/assets/javascripts/iscroll.js +0 -1084
  139. data/lib/generators/jinda/templates/app/assets/javascripts/jinda.js +0 -14
  140. data/lib/generators/jinda/templates/app/assets/javascripts/jquery.mobile-1.2.1.js +0 -9272
  141. data/lib/generators/jinda/templates/app/assets/javascripts/jquery.mobile.datebox.js +0 -1778
  142. data/lib/generators/jinda/templates/app/assets/javascripts/jquery.mobile.splitview.js +0 -695
  143. data/lib/generators/jinda/templates/app/assets/stylesheets/app.scss +0 -90
  144. data/lib/generators/jinda/templates/app/assets/stylesheets/articles.scss +0 -94
  145. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun.eot +0 -0
  146. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun.ttf +0 -0
  147. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun.woff +0 -0
  148. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun_bold.ttf +0 -0
  149. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun_bolditalic.ttf +0 -0
  150. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/sarabun_italic.ttf +0 -0
  151. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew-webfont.eot +0 -0
  152. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew-webfont.ttf +0 -0
  153. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew-webfont.woff +0 -0
  154. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew.css +0 -47
  155. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bold-webfont.eot +0 -0
  156. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bold-webfont.ttf +0 -0
  157. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bold-webfont.woff +0 -0
  158. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bolditalic-webfont.eot +0 -0
  159. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bolditalic-webfont.ttf +0 -0
  160. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_bolditalic-webfont.woff +0 -0
  161. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_italic-webfont.eot +0 -0
  162. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_italic-webfont.ttf +0 -0
  163. data/lib/generators/jinda/templates/app/assets/stylesheets/fonts/thsarabunnew_italic-webfont.woff +0 -0
  164. data/lib/generators/jinda/templates/app/assets/stylesheets/images/ajax-loader.gif +0 -0
  165. data/lib/generators/jinda/templates/app/assets/stylesheets/images/button_black.png +0 -0
  166. data/lib/generators/jinda/templates/app/assets/stylesheets/images/button_blue.png +0 -0
  167. data/lib/generators/jinda/templates/app/assets/stylesheets/images/button_red.png +0 -0
  168. data/lib/generators/jinda/templates/app/assets/stylesheets/images/icons-18-black.png +0 -0
  169. data/lib/generators/jinda/templates/app/assets/stylesheets/images/icons-18-white.png +0 -0
  170. data/lib/generators/jinda/templates/app/assets/stylesheets/images/icons-36-black.png +0 -0
  171. data/lib/generators/jinda/templates/app/assets/stylesheets/images/icons-36-white.png +0 -0
  172. data/lib/generators/jinda/templates/app/assets/stylesheets/images/indicator.gif +0 -0
  173. data/lib/generators/jinda/templates/app/assets/stylesheets/jinda.css +0 -52
  174. data/lib/generators/jinda/templates/app/assets/stylesheets/jquery.mobile-1.2.1.css +0 -2339
  175. data/lib/generators/jinda/templates/app/assets/stylesheets/jquery.mobile.datebox.css +0 -65
  176. data/lib/generators/jinda/templates/app/assets/stylesheets/jquery.mobile.grids.collapsible.css +0 -122
  177. data/lib/generators/jinda/templates/app/assets/stylesheets/jquery.mobile.splitview.css +0 -128
  178. data/lib/generators/jinda/templates/app/assets/stylesheets/kul-4.2.css +0 -1516
  179. data/lib/generators/jinda/templates/app/assets/stylesheets/kul-4.2.min.css +0 -11
  180. data/lib/generators/jinda/templates/app/assets/stylesheets/modules.scss +0 -84
  181. data/lib/generators/jinda/templates/app/assets/stylesheets/sarabun.css +0 -37
  182. data/lib/generators/jinda/templates/app/assets/stylesheets/social.scss +0 -133
  183. data/lib/generators/jinda/templates/app/controllers/concerns/jinda_general_concern.rb +0 -179
  184. data/lib/generators/jinda/templates/app/controllers/concerns/jinda_run_concern.rb +0 -365
  185. data/lib/generators/jinda/templates/app/controllers/jinda_org/devs_controller.rb +0 -2
  186. data/lib/generators/jinda/templates/app/controllers/jinda_org/jinda_controller.rb +0 -66
  187. data/lib/generators/jinda/templates/app/views/jinda/_activity.md +0 -10
  188. data/lib/generators/jinda/templates/app/views/jinda/_menu.haml +0 -27
  189. data/lib/generators/jinda/templates/app/views/jinda/_menu_mm.haml +0 -44
  190. data/lib/generators/jinda/templates/app/views/jinda/_model.md +0 -5
  191. data/lib/generators/jinda/templates/app/views/jinda/_modul.md +0 -9
  192. data/lib/generators/jinda/templates/app/views/jinda/_pending_home.haml +0 -5
  193. data/lib/generators/jinda/templates/app/views/jinda/_pending_page.haml +0 -24
  194. data/lib/generators/jinda/templates/app/views/jinda/_service.md +0 -24
  195. data/lib/generators/jinda/templates/app/views/jinda/_static.haml +0 -13
  196. data/lib/generators/jinda/templates/app/views/jinda/doc-thai.md +0 -37
  197. data/lib/generators/jinda/templates/app/views/jinda/doc.md +0 -36
  198. data/lib/generators/jinda/templates/app/views/jinda/error_logs.haml +0 -22
  199. data/lib/generators/jinda/templates/app/views/jinda/feed.rss.builder +0 -27
  200. data/lib/generators/jinda/templates/app/views/jinda/help.haml +0 -20
  201. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +0 -53
  202. data/lib/generators/jinda/templates/app/views/jinda/logs.haml +0 -22
  203. data/lib/generators/jinda/templates/app/views/jinda/notice_logs.haml +0 -18
  204. data/lib/generators/jinda/templates/app/views/jinda/pending.haml +0 -1
  205. data/lib/generators/jinda/templates/app/views/jinda/run_form.haml +0 -42
  206. data/lib/generators/jinda/templates/app/views/jinda/run_output.haml +0 -38
  207. data/lib/generators/jinda/templates/app/views/jinda/search.haml +0 -20
  208. data/lib/generators/jinda/templates/app/views/jinda/status.haml +0 -61
@@ -1,27 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require jquery
14
- //= require jquery.turbolinks
15
- //= require jquery_ujs
16
- //= require jqm/jquery.mobile.splitview
17
- //= require jqm/jquery.mobile-1.2.1
18
- //= require jqm/jquery.mobile.datebox
19
- //= require jqm/iscroll-wrapper
20
- //= require jqm/iscroll
21
- //= require jqm/jinda
22
- //= require turbolinks
23
- //= require jqm/disable_enter_key.js
24
- //= require disable_enter_key.js
25
- //= require notes.js
26
-
27
-
@@ -1,13 +0,0 @@
1
- // Action Cable provides the framework to deal with WebSockets in Rails.
2
- // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
- //
4
- //= require action_cable
5
- //= require_self
6
- //= require_tree ./channels
7
-
8
- (function() {
9
- this.App || (this.App = {});
10
-
11
- App.cable = ActionCable.createConsumer();
12
-
13
- }).call(this);
@@ -1,10 +0,0 @@
1
- $(function() {
2
- $("input").keypress(function (evt) {
3
- //Deterime where our character code is coming from within the event
4
- var charCode = evt.charCode || evt.keyCode;
5
- if (charCode == 13) { //Enter key's keycode
6
- alert("Please click the button");
7
- return false;
8
- }
9
- });
10
- })
@@ -1,32 +0,0 @@
1
- /*
2
- * iscroll-wrapper for jQquery.
3
- * http://sanraul.com/projects/jqloader/
4
- *
5
- * Copyright (c) 2011 Raul Sanchez (http://www.sanraul.com)
6
- *
7
- * Dual licensed under the MIT and GPL licenses:
8
- * http://www.opensource.org/licenses/mit-license.php
9
- * http://www.gnu.org/licenses/gpl.html
10
- */
11
-
12
- (function($){
13
- $.fn.iscroll = function(options){
14
- if(this.data('iScrollReady') == null){
15
- var that = this;
16
- var options = $.extend({}, options);
17
- options.onScrollEnd = function(){
18
- that.triggerHandler('onScrollEnd', [this]);
19
- };
20
- arguments.callee.object = new iScroll(this.get(0), options);
21
- // NOTE: for some reason in a complex page the plugin does not register
22
- // the size of the element. This will fix that in the meantime.
23
- setTimeout(function(scroller){
24
- scroller.refresh();
25
- }, 1000, arguments.callee.object);
26
- this.data('iScrollReady', true);
27
- }else{
28
- arguments.callee.object.refresh();
29
- }
30
- return arguments.callee.object;
31
- };
32
- })(jQuery);
@@ -1,1084 +0,0 @@
1
- /*!
2
- * iScroll v4.1.9 ~ Copyright (c) 2011 Matteo Spinelli, http://cubiq.org
3
- * Released under MIT license, http://cubiq.org/license
4
- */
5
- (function(){
6
- var m = Math,
7
- mround = function (r) { return r >> 0; },
8
- vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' :
9
- (/firefox/i).test(navigator.userAgent) ? 'Moz' :
10
- 'opera' in window ? 'O' : '',
11
-
12
- // Browser capabilities
13
- isAndroid = (/android/gi).test(navigator.appVersion),
14
- isIDevice = (/iphone|ipad/gi).test(navigator.appVersion),
15
- isPlaybook = (/playbook/gi).test(navigator.appVersion),
16
- isTouchPad = (/hp-tablet/gi).test(navigator.appVersion),
17
-
18
- has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(),
19
- hasTouch = 'ontouchstart' in window && !isTouchPad,
20
- hasTransform = vendor + 'Transform' in document.documentElement.style,
21
- hasTransitionEnd = isIDevice || isPlaybook,
22
-
23
- nextFrame = (function() {
24
- return window.requestAnimationFrame
25
- || window.webkitRequestAnimationFrame
26
- || window.mozRequestAnimationFrame
27
- || window.oRequestAnimationFrame
28
- || window.msRequestAnimationFrame
29
- || function(callback) { return setTimeout(callback, 1); }
30
- })(),
31
- cancelFrame = (function () {
32
- return window.cancelRequestAnimationFrame
33
- || window.webkitCancelRequestAnimationFrame
34
- || window.mozCancelRequestAnimationFrame
35
- || window.oCancelRequestAnimationFrame
36
- || window.msCancelRequestAnimationFrame
37
- || clearTimeout
38
- })(),
39
-
40
- // Events
41
- RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize',
42
- START_EV = hasTouch ? 'touchstart' : 'mousedown',
43
- MOVE_EV = hasTouch ? 'touchmove' : 'mousemove',
44
- END_EV = hasTouch ? 'touchend' : 'mouseup',
45
- CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup',
46
- WHEEL_EV = vendor == 'Moz' ? 'DOMMouseScroll' : 'mousewheel',
47
-
48
- // Helpers
49
- trnOpen = 'translate' + (has3d ? '3d(' : '('),
50
- trnClose = has3d ? ',0)' : ')',
51
-
52
- // Constructor
53
- iScroll = function (el, options) {
54
- var that = this,
55
- doc = document,
56
- i;
57
-
58
- that.wrapper = typeof el == 'object' ? el : doc.getElementById(el);
59
- that.wrapper.style.overflow = 'hidden';
60
- that.scroller = that.wrapper.children[0];
61
-
62
- // Default options
63
- that.options = {
64
- hScroll: true,
65
- vScroll: true,
66
- x: 0,
67
- y: 0,
68
- bounce: true,
69
- bounceLock: false,
70
- momentum: true,
71
- lockDirection: true,
72
- useTransform: true,
73
- useTransition: false,
74
- topOffset: 0,
75
- checkDOMChanges: false, // Experimental
76
-
77
- // Scrollbar
78
- hScrollbar: true,
79
- vScrollbar: true,
80
- fixedScrollbar: isAndroid,
81
- hideScrollbar: isIDevice,
82
- fadeScrollbar: isIDevice && has3d,
83
- scrollbarClass: '',
84
-
85
- // Zoom
86
- zoom: false,
87
- zoomMin: 1,
88
- zoomMax: 4,
89
- doubleTapZoom: 2,
90
- wheelAction: 'scroll',
91
-
92
- // Snap
93
- snap: false,
94
- snapThreshold: 1,
95
-
96
- // Events
97
- onRefresh: null,
98
- onBeforeScrollStart: function (e) { e.preventDefault(); },
99
- onScrollStart: null,
100
- onBeforeScrollMove: null,
101
- onScrollMove: null,
102
- onBeforeScrollEnd: null,
103
- onScrollEnd: null,
104
- onTouchEnd: null,
105
- onDestroy: null,
106
- onZoomStart: null,
107
- onZoom: null,
108
- onZoomEnd: null
109
- };
110
-
111
- // User defined options
112
- for (i in options) that.options[i] = options[i];
113
-
114
- // Set starting position
115
- that.x = that.options.x;
116
- that.y = that.options.y;
117
-
118
- // Normalize options
119
- that.options.useTransform = hasTransform ? that.options.useTransform : false;
120
- that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar;
121
- that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar;
122
- that.options.zoom = that.options.useTransform && that.options.zoom;
123
- that.options.useTransition = hasTransitionEnd && that.options.useTransition;
124
-
125
- // Helpers FIX ANDROID BUG!
126
- // translate3d and scale doesn't work together!
127
- // Ignoring 3d ONLY WHEN YOU SET that.options.zoom
128
- if ( that.options.zoom && isAndroid ){
129
- trnOpen = 'translate(';
130
- trnClose = ')';
131
- }
132
-
133
- // Set some default styles
134
- that.scroller.style[vendor + 'TransitionProperty'] = that.options.useTransform ? '-' + vendor.toLowerCase() + '-transform' : 'top left';
135
- that.scroller.style[vendor + 'TransitionDuration'] = '0';
136
- that.scroller.style[vendor + 'TransformOrigin'] = '0 0';
137
- if (that.options.useTransition) that.scroller.style[vendor + 'TransitionTimingFunction'] = 'cubic-bezier(0.33,0.66,0.66,1)';
138
-
139
- if (that.options.useTransform) that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose;
140
- else that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px';
141
-
142
- if (that.options.useTransition) that.options.fixedScrollbar = true;
143
-
144
- that.refresh();
145
-
146
- that._bind(RESIZE_EV, window);
147
- that._bind(START_EV);
148
- if (!hasTouch) {
149
- that._bind('mouseout', that.wrapper);
150
- if (that.options.wheelAction != 'none')
151
- that._bind(WHEEL_EV);
152
- }
153
-
154
- if (that.options.checkDOMChanges) that.checkDOMTime = setInterval(function () {
155
- that._checkDOMChanges();
156
- }, 500);
157
- };
158
-
159
- // Prototype
160
- iScroll.prototype = {
161
- enabled: true,
162
- x: 0,
163
- y: 0,
164
- steps: [],
165
- scale: 1,
166
- currPageX: 0, currPageY: 0,
167
- pagesX: [], pagesY: [],
168
- aniTime: null,
169
- wheelZoomCount: 0,
170
-
171
- handleEvent: function (e) {
172
- var that = this;
173
- switch(e.type) {
174
- case START_EV:
175
- if (!hasTouch && e.button !== 0) return;
176
- that._start(e);
177
- break;
178
- case MOVE_EV: that._move(e); break;
179
- case END_EV:
180
- case CANCEL_EV: that._end(e); break;
181
- case RESIZE_EV: that._resize(); break;
182
- case WHEEL_EV: that._wheel(e); break;
183
- case 'mouseout': that._mouseout(e); break;
184
- case 'webkitTransitionEnd': that._transitionEnd(e); break;
185
- }
186
- },
187
-
188
- _checkDOMChanges: function () {
189
- if (this.moved || this.zoomed || this.animating ||
190
- (this.scrollerW == this.scroller.offsetWidth * this.scale && this.scrollerH == this.scroller.offsetHeight * this.scale)) return;
191
-
192
- this.refresh();
193
- },
194
-
195
- _scrollbar: function (dir) {
196
- var that = this,
197
- doc = document,
198
- bar;
199
-
200
- if (!that[dir + 'Scrollbar']) {
201
- if (that[dir + 'ScrollbarWrapper']) {
202
- if (hasTransform) that[dir + 'ScrollbarIndicator'].style[vendor + 'Transform'] = '';
203
- that[dir + 'ScrollbarWrapper'].parentNode.removeChild(that[dir + 'ScrollbarWrapper']);
204
- that[dir + 'ScrollbarWrapper'] = null;
205
- that[dir + 'ScrollbarIndicator'] = null;
206
- }
207
-
208
- return;
209
- }
210
-
211
- if (!that[dir + 'ScrollbarWrapper']) {
212
- // Create the scrollbar wrapper
213
- bar = doc.createElement('div');
214
-
215
- if (that.options.scrollbarClass) bar.className = that.options.scrollbarClass + dir.toUpperCase();
216
- else bar.style.cssText = 'position:absolute;z-index:100;' + (dir == 'h' ? 'height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px' : 'width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px');
217
-
218
- bar.style.cssText += ';pointer-events:none;-' + vendor + '-transition-property:opacity;-' + vendor + '-transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1');
219
-
220
- that.wrapper.appendChild(bar);
221
- that[dir + 'ScrollbarWrapper'] = bar;
222
-
223
- // Create the scrollbar indicator
224
- bar = doc.createElement('div');
225
- if (!that.options.scrollbarClass) {
226
- bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);-' + vendor + '-background-clip:padding-box;-' + vendor + '-box-sizing:border-box;' + (dir == 'h' ? 'height:100%' : 'width:100%') + ';-' + vendor + '-border-radius:3px;border-radius:3px';
227
- }
228
- bar.style.cssText += ';pointer-events:none;-' + vendor + '-transition-property:-' + vendor + '-transform;-' + vendor + '-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);-' + vendor + '-transition-duration:0;-' + vendor + '-transform:' + trnOpen + '0,0' + trnClose;
229
- if (that.options.useTransition) bar.style.cssText += ';-' + vendor + '-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)';
230
-
231
- that[dir + 'ScrollbarWrapper'].appendChild(bar);
232
- that[dir + 'ScrollbarIndicator'] = bar;
233
- }
234
-
235
- if (dir == 'h') {
236
- that.hScrollbarSize = that.hScrollbarWrapper.clientWidth;
237
- that.hScrollbarIndicatorSize = m.max(mround(that.hScrollbarSize * that.hScrollbarSize / that.scrollerW), 8);
238
- that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px';
239
- that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize;
240
- that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX;
241
- } else {
242
- that.vScrollbarSize = that.vScrollbarWrapper.clientHeight;
243
- that.vScrollbarIndicatorSize = m.max(mround(that.vScrollbarSize * that.vScrollbarSize / that.scrollerH), 8);
244
- that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px';
245
- that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize;
246
- that.vScrollbarProp = that.vScrollbarMaxScroll / that.maxScrollY;
247
- }
248
-
249
- // Reset position
250
- that._scrollbarPos(dir, true);
251
- },
252
-
253
- _resize: function () {
254
- var that = this;
255
- setTimeout(function () { that.refresh(); }, isAndroid ? 200 : 0);
256
- },
257
-
258
- _pos: function (x, y) {
259
- x = this.hScroll ? x : 0;
260
- y = this.vScroll ? y : 0;
261
-
262
- if (this.options.useTransform) {
263
- this.scroller.style[vendor + 'Transform'] = trnOpen + x + 'px,' + y + 'px' + trnClose + ' scale(' + this.scale + ')';
264
- } else {
265
- x = mround(x);
266
- y = mround(y);
267
- this.scroller.style.left = x + 'px';
268
- this.scroller.style.top = y + 'px';
269
- }
270
-
271
- this.x = x;
272
- this.y = y;
273
-
274
- this._scrollbarPos('h');
275
- this._scrollbarPos('v');
276
- },
277
-
278
- _scrollbarPos: function (dir, hidden) {
279
- var that = this,
280
- pos = dir == 'h' ? that.x : that.y,
281
- size;
282
-
283
- if (!that[dir + 'Scrollbar']) return;
284
-
285
- pos = that[dir + 'ScrollbarProp'] * pos;
286
-
287
- if (pos < 0) {
288
- if (!that.options.fixedScrollbar) {
289
- size = that[dir + 'ScrollbarIndicatorSize'] + mround(pos * 3);
290
- if (size < 8) size = 8;
291
- that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
292
- }
293
- pos = 0;
294
- } else if (pos > that[dir + 'ScrollbarMaxScroll']) {
295
- if (!that.options.fixedScrollbar) {
296
- size = that[dir + 'ScrollbarIndicatorSize'] - mround((pos - that[dir + 'ScrollbarMaxScroll']) * 3);
297
- if (size < 8) size = 8;
298
- that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
299
- pos = that[dir + 'ScrollbarMaxScroll'] + (that[dir + 'ScrollbarIndicatorSize'] - size);
300
- } else {
301
- pos = that[dir + 'ScrollbarMaxScroll'];
302
- }
303
- }
304
-
305
- that[dir + 'ScrollbarWrapper'].style[vendor + 'TransitionDelay'] = '0';
306
- that[dir + 'ScrollbarWrapper'].style.opacity = hidden && that.options.hideScrollbar ? '0' : '1';
307
- that[dir + 'ScrollbarIndicator'].style[vendor + 'Transform'] = trnOpen + (dir == 'h' ? pos + 'px,0' : '0,' + pos + 'px') + trnClose;
308
- },
309
-
310
- _start: function (e) {
311
- var that = this,
312
- point = hasTouch ? e.touches[0] : e,
313
- matrix, x, y,
314
- c1, c2,
315
- tagName = e.target.nodeName.toLowerCase();
316
-
317
- if (tagName === "select" || tagName === "input" || tagName === "textarea") {
318
- e.target.focus();
319
- that.focusedInput = e.target;
320
- return;
321
- }
322
-
323
- if (that.focusedInput){
324
- that.focusedInput.blur();
325
- that.focusedInput = false;
326
- }
327
-
328
- if (!that.enabled) return;
329
-
330
- if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e);
331
-
332
- if (that.options.useTransition || that.options.zoom) that._transitionTime(0);
333
-
334
- that.moved = false;
335
- that.animating = false;
336
- that.zoomed = false;
337
- that.distX = 0;
338
- that.distY = 0;
339
- that.absDistX = 0;
340
- that.absDistY = 0;
341
- that.dirX = 0;
342
- that.dirY = 0;
343
-
344
- // Gesture start
345
- if (that.options.zoom && hasTouch && e.touches.length > 1) {
346
- c1 = m.abs(e.touches[0].pageX-e.touches[1].pageX);
347
- c2 = m.abs(e.touches[0].pageY-e.touches[1].pageY);
348
- that.touchesDistStart = m.sqrt(c1 * c1 + c2 * c2);
349
-
350
- that.originX = m.abs(e.touches[0].pageX + e.touches[1].pageX - that.wrapperOffsetLeft * 2) / 2 - that.x;
351
- that.originY = m.abs(e.touches[0].pageY + e.touches[1].pageY - that.wrapperOffsetTop * 2) / 2 - that.y;
352
-
353
- if (that.options.onZoomStart) that.options.onZoomStart.call(that, e);
354
- }
355
-
356
- if (that.options.momentum) {
357
- if (that.options.useTransform) {
358
- // Very lame general purpose alternative to CSSMatrix
359
- matrix = getComputedStyle(that.scroller, null)[vendor + 'Transform'].replace(/[^0-9-.,]/g, '').split(',');
360
- x = matrix[4] * 1;
361
- y = matrix[5] * 1;
362
- } else {
363
- x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1;
364
- y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1;
365
- }
366
-
367
- if (x != that.x || y != that.y) {
368
- if (that.options.useTransition) that._unbind('webkitTransitionEnd');
369
- else cancelFrame(that.aniTime);
370
- that.steps = [];
371
- that._pos(x, y);
372
- }
373
- }
374
-
375
- that.absStartX = that.x; // Needed by snap threshold
376
- that.absStartY = that.y;
377
-
378
- that.startX = that.x;
379
- that.startY = that.y;
380
- that.pointX = point.pageX;
381
- that.pointY = point.pageY;
382
-
383
- that.startTime = e.timeStamp || Date.now();
384
-
385
- if (that.options.onScrollStart) that.options.onScrollStart.call(that, e);
386
-
387
- that._bind(MOVE_EV);
388
- that._bind(END_EV);
389
- that._bind(CANCEL_EV);
390
- },
391
-
392
- _move: function (e) {
393
- var that = this,
394
- point = hasTouch ? e.touches[0] : e,
395
- deltaX = point.pageX - that.pointX,
396
- deltaY = point.pageY - that.pointY,
397
- newX = that.x + deltaX,
398
- newY = that.y + deltaY,
399
- c1, c2, scale,
400
- timestamp = e.timeStamp || Date.now();
401
-
402
- if (that.options.onBeforeScrollMove) that.options.onBeforeScrollMove.call(that, e);
403
-
404
- // Zoom
405
- if (that.options.zoom && hasTouch && e.touches.length > 1) {
406
- c1 = m.abs(e.touches[0].pageX - e.touches[1].pageX);
407
- c2 = m.abs(e.touches[0].pageY - e.touches[1].pageY);
408
- that.touchesDist = m.sqrt(c1*c1+c2*c2);
409
-
410
- that.zoomed = true;
411
-
412
- scale = 1 / that.touchesDistStart * that.touchesDist * this.scale;
413
-
414
- if (scale < that.options.zoomMin) scale = 0.5 * that.options.zoomMin * Math.pow(2.0, scale / that.options.zoomMin);
415
- else if (scale > that.options.zoomMax) scale = 2.0 * that.options.zoomMax * Math.pow(0.5, that.options.zoomMax / scale);
416
-
417
- that.lastScale = scale / this.scale;
418
-
419
- newX = this.originX - this.originX * that.lastScale + this.x,
420
- newY = this.originY - this.originY * that.lastScale + this.y;
421
-
422
- this.scroller.style[vendor + 'Transform'] = trnOpen + newX + 'px,' + newY + 'px' + trnClose + ' scale(' + scale + ')';
423
-
424
- if (that.options.onZoom) that.options.onZoom.call(that, e);
425
- return;
426
- }
427
-
428
- that.pointX = point.pageX;
429
- that.pointY = point.pageY;
430
-
431
- // Slow down if outside of the boundaries
432
- if (newX > 0 || newX < that.maxScrollX) {
433
- newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX;
434
- }
435
- if (newY > that.minScrollY || newY < that.maxScrollY) {
436
- newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY;
437
- }
438
-
439
- if (that.absDistX < 6 && that.absDistY < 6) {
440
- that.distX += deltaX;
441
- that.distY += deltaY;
442
- that.absDistX = m.abs(that.distX);
443
- that.absDistY = m.abs(that.distY);
444
-
445
- return;
446
- }
447
-
448
- // Lock direction
449
- if (that.options.lockDirection) {
450
- if (that.absDistX > that.absDistY + 5) {
451
- newY = that.y;
452
- deltaY = 0;
453
- } else if (that.absDistY > that.absDistX + 5) {
454
- newX = that.x;
455
- deltaX = 0;
456
- }
457
- }
458
-
459
- that.moved = true;
460
- that._pos(newX, newY);
461
- that.dirX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
462
- that.dirY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
463
-
464
- if (timestamp - that.startTime > 300) {
465
- that.startTime = timestamp;
466
- that.startX = that.x;
467
- that.startY = that.y;
468
- }
469
-
470
- if (that.options.onScrollMove) that.options.onScrollMove.call(that, e);
471
- },
472
-
473
- _end: function (e) {
474
- if (hasTouch && e.touches.length != 0) return;
475
-
476
- var that = this,
477
- point = hasTouch ? e.changedTouches[0] : e,
478
- target, ev,
479
- momentumX = { dist:0, time:0 },
480
- momentumY = { dist:0, time:0 },
481
- duration = (e.timeStamp || Date.now()) - that.startTime,
482
- newPosX = that.x,
483
- newPosY = that.y,
484
- distX, distY,
485
- newDuration,
486
- snap,
487
- scale;
488
-
489
- that._unbind(MOVE_EV);
490
- that._unbind(END_EV);
491
- that._unbind(CANCEL_EV);
492
-
493
- if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e);
494
-
495
- if (that.zoomed) {
496
- scale = that.scale * that.lastScale;
497
- scale = Math.max(that.options.zoomMin, scale);
498
- scale = Math.min(that.options.zoomMax, scale);
499
- that.lastScale = scale / that.scale;
500
- that.scale = scale;
501
-
502
- that.x = that.originX - that.originX * that.lastScale + that.x;
503
- that.y = that.originY - that.originY * that.lastScale + that.y;
504
-
505
- that.scroller.style[vendor + 'TransitionDuration'] = '200ms';
506
- that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose + ' scale(' + that.scale + ')';
507
-
508
- that.zoomed = false;
509
- that.refresh();
510
-
511
- if (that.options.onZoomEnd) that.options.onZoomEnd.call(that, e);
512
- return;
513
- }
514
-
515
- if (!that.moved) {
516
- if (hasTouch) {
517
- if (that.doubleTapTimer && that.options.zoom) {
518
- // Double tapped
519
- clearTimeout(that.doubleTapTimer);
520
- that.doubleTapTimer = null;
521
- if (that.options.onZoomStart) that.options.onZoomStart.call(that, e);
522
- that.zoom(that.pointX, that.pointY, that.scale == 1 ? that.options.doubleTapZoom : 1);
523
- if (that.options.onZoomEnd) {
524
- setTimeout(function() {
525
- that.options.onZoomEnd.call(that, e);
526
- }, 200); // 200 is default zoom duration
527
- }
528
- } else {
529
- that.doubleTapTimer = setTimeout(function () {
530
- that.doubleTapTimer = null;
531
-
532
- // Find the last touched element
533
- target = point.target;
534
- while (target.nodeType != 1) target = target.parentNode;
535
-
536
- if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') {
537
- ev = document.createEvent('MouseEvents');
538
- ev.initMouseEvent('click', true, true, e.view, 1,
539
- point.screenX, point.screenY, point.clientX, point.clientY,
540
- e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
541
- 0, null);
542
- ev._fake = true;
543
- target.dispatchEvent(ev);
544
- }
545
- }, that.options.zoom ? 250 : 0);
546
- }
547
- }
548
-
549
- that._resetPos(200);
550
-
551
- if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
552
- return;
553
- }
554
-
555
- if (duration < 300 && that.options.momentum) {
556
- momentumX = newPosX ? that._momentum(newPosX - that.startX, duration, -that.x, that.scrollerW - that.wrapperW + that.x, that.options.bounce ? that.wrapperW : 0) : momentumX;
557
- momentumY = newPosY ? that._momentum(newPosY - that.startY, duration, -that.y, (that.maxScrollY < 0 ? that.scrollerH - that.wrapperH + that.y - that.minScrollY : 0), that.options.bounce ? that.wrapperH : 0) : momentumY;
558
-
559
- newPosX = that.x + momentumX.dist;
560
- newPosY = that.y + momentumY.dist;
561
-
562
- if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist:0, time:0 };
563
- if ((that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist:0, time:0 };
564
- }
565
-
566
- if (momentumX.dist || momentumY.dist) {
567
- newDuration = m.max(m.max(momentumX.time, momentumY.time), 10);
568
-
569
- // Do we need to snap?
570
- if (that.options.snap) {
571
- distX = newPosX - that.absStartX;
572
- distY = newPosY - that.absStartY;
573
- if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) { that.scrollTo(that.absStartX, that.absStartY, 200); }
574
- else {
575
- snap = that._snap(newPosX, newPosY);
576
- newPosX = snap.x;
577
- newPosY = snap.y;
578
- newDuration = m.max(snap.time, newDuration);
579
- }
580
- }
581
-
582
- that.scrollTo(mround(newPosX), mround(newPosY), newDuration);
583
-
584
- if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
585
- return;
586
- }
587
-
588
- // Do we need to snap?
589
- if (that.options.snap) {
590
- distX = newPosX - that.absStartX;
591
- distY = newPosY - that.absStartY;
592
- if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) that.scrollTo(that.absStartX, that.absStartY, 200);
593
- else {
594
- snap = that._snap(that.x, that.y);
595
- if (snap.x != that.x || snap.y != that.y) that.scrollTo(snap.x, snap.y, snap.time);
596
- }
597
-
598
- if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
599
- return;
600
- }
601
-
602
- that._resetPos(200);
603
- if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
604
- },
605
-
606
- _resetPos: function (time) {
607
- var that = this,
608
- resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
609
- resetY = that.y >= that.minScrollY || that.maxScrollY > 0 ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
610
-
611
- if (resetX == that.x && resetY == that.y) {
612
- if (that.moved) {
613
- that.moved = false;
614
- if (that.options.onScrollEnd) that.options.onScrollEnd.call(that); // Execute custom code on scroll end
615
- }
616
-
617
- if (that.hScrollbar && that.options.hideScrollbar) {
618
- if (vendor == 'webkit') that.hScrollbarWrapper.style[vendor + 'TransitionDelay'] = '300ms';
619
- that.hScrollbarWrapper.style.opacity = '0';
620
- }
621
- if (that.vScrollbar && that.options.hideScrollbar) {
622
- if (vendor == 'webkit') that.vScrollbarWrapper.style[vendor + 'TransitionDelay'] = '300ms';
623
- that.vScrollbarWrapper.style.opacity = '0';
624
- }
625
-
626
- return;
627
- }
628
-
629
- that.scrollTo(resetX, resetY, time || 0);
630
- },
631
-
632
- _wheel: function (e) {
633
- var that = this,
634
- wheelDeltaX, wheelDeltaY,
635
- deltaX, deltaY,
636
- deltaScale;
637
-
638
- if ('wheelDeltaX' in e) {
639
- wheelDeltaX = e.wheelDeltaX / 12;
640
- wheelDeltaY = e.wheelDeltaY / 12;
641
- } else if ('detail' in e) {
642
- wheelDeltaX = wheelDeltaY = -e.detail * 3;
643
- } else {
644
- wheelDeltaX = wheelDeltaY = -e.wheelDelta;
645
- }
646
-
647
- if (that.options.wheelAction == 'zoom') {
648
- deltaScale = that.scale * Math.pow(2, 1/3 * (wheelDeltaY ? wheelDeltaY / Math.abs(wheelDeltaY) : 0));
649
- if (deltaScale < that.options.zoomMin) deltaScale = that.options.zoomMin;
650
- if (deltaScale > that.options.zoomMax) deltaScale = that.options.zoomMax;
651
-
652
- if (deltaScale != that.scale) {
653
- if (!that.wheelZoomCount && that.options.onZoomStart) that.options.onZoomStart.call(that, e);
654
- that.wheelZoomCount++;
655
-
656
- that.zoom(e.pageX, e.pageY, deltaScale, 400);
657
-
658
- setTimeout(function() {
659
- that.wheelZoomCount--;
660
- if (!that.wheelZoomCount && that.options.onZoomEnd) that.options.onZoomEnd.call(that, e);
661
- }, 400);
662
- }
663
-
664
- return;
665
- }
666
-
667
- deltaX = that.x + wheelDeltaX;
668
- deltaY = that.y + wheelDeltaY;
669
-
670
- if (deltaX > 0) deltaX = 0;
671
- else if (deltaX < that.maxScrollX) deltaX = that.maxScrollX;
672
-
673
- if (deltaY > that.minScrollY) deltaY = that.minScrollY;
674
- else if (deltaY < that.maxScrollY) deltaY = that.maxScrollY;
675
-
676
- that.scrollTo(deltaX, deltaY, 0);
677
- },
678
-
679
- _mouseout: function (e) {
680
- var t = e.relatedTarget;
681
-
682
- if (!t) {
683
- this._end(e);
684
- return;
685
- }
686
-
687
- while (t = t.parentNode) if (t == this.wrapper) return;
688
-
689
- this._end(e);
690
- },
691
-
692
- _transitionEnd: function (e) {
693
- var that = this;
694
-
695
- if (e.target != that.scroller) return;
696
-
697
- that._unbind('webkitTransitionEnd');
698
-
699
- that._startAni();
700
- },
701
-
702
-
703
- /**
704
- *
705
- * Utilities
706
- *
707
- */
708
- _startAni: function () {
709
- var that = this,
710
- startX = that.x, startY = that.y,
711
- startTime = Date.now(),
712
- step, easeOut,
713
- animate;
714
-
715
- if (that.animating) return;
716
-
717
- if (!that.steps.length) {
718
- that._resetPos(400);
719
- return;
720
- }
721
-
722
- step = that.steps.shift();
723
-
724
- if (step.x == startX && step.y == startY) step.time = 0;
725
-
726
- that.animating = true;
727
- that.moved = true;
728
-
729
- if (that.options.useTransition) {
730
- that._transitionTime(step.time);
731
- that._pos(step.x, step.y);
732
- that.animating = false;
733
- if (step.time) that._bind('webkitTransitionEnd');
734
- else that._resetPos(0);
735
- return;
736
- }
737
-
738
- animate = function () {
739
- var now = Date.now(),
740
- newX, newY;
741
-
742
- if (now >= startTime + step.time) {
743
- that._pos(step.x, step.y);
744
- that.animating = false;
745
- if (that.options.onAnimationEnd) that.options.onAnimationEnd.call(that); // Execute custom code on animation end
746
- that._startAni();
747
- return;
748
- }
749
-
750
- now = (now - startTime) / step.time - 1;
751
- easeOut = m.sqrt(1 - now * now);
752
- newX = (step.x - startX) * easeOut + startX;
753
- newY = (step.y - startY) * easeOut + startY;
754
- that._pos(newX, newY);
755
- if (that.animating) that.aniTime = nextFrame(animate);
756
- };
757
-
758
- animate();
759
- },
760
-
761
- _transitionTime: function (time) {
762
- time += 'ms';
763
- this.scroller.style[vendor + 'TransitionDuration'] = time;
764
- if (this.hScrollbar) this.hScrollbarIndicator.style[vendor + 'TransitionDuration'] = time;
765
- if (this.vScrollbar) this.vScrollbarIndicator.style[vendor + 'TransitionDuration'] = time;
766
- },
767
-
768
- _momentum: function (dist, time, maxDistUpper, maxDistLower, size) {
769
- var deceleration = 0.0006,
770
- speed = m.abs(dist) / time,
771
- newDist = (speed * speed) / (2 * deceleration),
772
- newTime = 0, outsideDist = 0;
773
-
774
- // Proportinally reduce speed if we are outside of the boundaries
775
- if (dist > 0 && newDist > maxDistUpper) {
776
- outsideDist = size / (6 / (newDist / speed * deceleration));
777
- maxDistUpper = maxDistUpper + outsideDist;
778
- speed = speed * maxDistUpper / newDist;
779
- newDist = maxDistUpper;
780
- } else if (dist < 0 && newDist > maxDistLower) {
781
- outsideDist = size / (6 / (newDist / speed * deceleration));
782
- maxDistLower = maxDistLower + outsideDist;
783
- speed = speed * maxDistLower / newDist;
784
- newDist = maxDistLower;
785
- }
786
-
787
- newDist = newDist * (dist < 0 ? -1 : 1);
788
- newTime = speed / deceleration;
789
-
790
- return { dist: newDist, time: mround(newTime) };
791
- },
792
-
793
- _offset: function (el) {
794
- var left = -el.offsetLeft,
795
- top = -el.offsetTop;
796
-
797
- while (el = el.offsetParent) {
798
- left -= el.offsetLeft;
799
- top -= el.offsetTop;
800
- }
801
-
802
- if (el != this.wrapper) {
803
- left *= this.scale;
804
- top *= this.scale;
805
- }
806
-
807
- return { left: left, top: top };
808
- },
809
-
810
- _snap: function (x, y) {
811
- var that = this,
812
- i, l,
813
- page, time,
814
- sizeX, sizeY;
815
-
816
- // Check page X
817
- page = that.pagesX.length - 1;
818
- for (i=0, l=that.pagesX.length; i<l; i++) {
819
- if (x >= that.pagesX[i]) {
820
- page = i;
821
- break;
822
- }
823
- }
824
- if (page == that.currPageX && page > 0 && that.dirX < 0) page--;
825
- x = that.pagesX[page];
826
- sizeX = m.abs(x - that.pagesX[that.currPageX]);
827
- sizeX = sizeX ? m.abs(that.x - x) / sizeX * 500 : 0;
828
- that.currPageX = page;
829
-
830
- // Check page Y
831
- page = that.pagesY.length-1;
832
- for (i=0; i<page; i++) {
833
- if (y >= that.pagesY[i]) {
834
- page = i;
835
- break;
836
- }
837
- }
838
- if (page == that.currPageY && page > 0 && that.dirY < 0) page--;
839
- y = that.pagesY[page];
840
- sizeY = m.abs(y - that.pagesY[that.currPageY]);
841
- sizeY = sizeY ? m.abs(that.y - y) / sizeY * 500 : 0;
842
- that.currPageY = page;
843
-
844
- // Snap with constant speed (proportional duration)
845
- time = mround(m.max(sizeX, sizeY)) || 200;
846
-
847
- return { x: x, y: y, time: time };
848
- },
849
-
850
- _bind: function (type, el, bubble) {
851
- (el || this.scroller).addEventListener(type, this, !!bubble);
852
- },
853
-
854
- _unbind: function (type, el, bubble) {
855
- (el || this.scroller).removeEventListener(type, this, !!bubble);
856
- },
857
-
858
-
859
- /**
860
- *
861
- * Public methods
862
- *
863
- */
864
- destroy: function () {
865
- var that = this;
866
-
867
- that.scroller.style[vendor + 'Transform'] = '';
868
-
869
- // Remove the scrollbars
870
- that.hScrollbar = false;
871
- that.vScrollbar = false;
872
- that._scrollbar('h');
873
- that._scrollbar('v');
874
-
875
- // Remove the event listeners
876
- that._unbind(RESIZE_EV, window);
877
- that._unbind(START_EV);
878
- that._unbind(MOVE_EV);
879
- that._unbind(END_EV);
880
- that._unbind(CANCEL_EV);
881
-
882
- if (!that.options.hasTouch) {
883
- that._unbind('mouseout', that.wrapper);
884
- that._unbind(WHEEL_EV);
885
- }
886
-
887
- if (that.options.useTransition) that._unbind('webkitTransitionEnd');
888
-
889
- if (that.options.checkDOMChanges) clearInterval(that.checkDOMTime);
890
-
891
- if (that.options.onDestroy) that.options.onDestroy.call(that);
892
- },
893
-
894
- refresh: function () {
895
- var that = this,
896
- offset,
897
- i, l,
898
- els,
899
- pos = 0,
900
- page = 0;
901
-
902
- if (that.scale < that.options.zoomMin) that.scale = that.options.zoomMin;
903
- that.wrapperW = that.wrapper.clientWidth || 1;
904
- that.wrapperH = that.wrapper.clientHeight || 1;
905
-
906
- that.minScrollY = -that.options.topOffset || 0;
907
- that.scrollerW = mround(that.scroller.offsetWidth * that.scale);
908
- that.scrollerH = mround((that.scroller.offsetHeight + that.minScrollY) * that.scale);
909
- that.maxScrollX = that.wrapperW - that.scrollerW;
910
- that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY;
911
- that.dirX = 0;
912
- that.dirY = 0;
913
-
914
- if (that.options.onRefresh) that.options.onRefresh.call(that);
915
-
916
- that.hScroll = that.options.hScroll && that.maxScrollX < 0;
917
- that.vScroll = that.options.vScroll && (!that.options.bounceLock && !that.hScroll || that.scrollerH > that.wrapperH);
918
-
919
- that.hScrollbar = that.hScroll && that.options.hScrollbar;
920
- that.vScrollbar = that.vScroll && that.options.vScrollbar && that.scrollerH > that.wrapperH;
921
-
922
- offset = that._offset(that.wrapper);
923
- that.wrapperOffsetLeft = -offset.left;
924
- that.wrapperOffsetTop = -offset.top;
925
-
926
- // Prepare snap
927
- if (typeof that.options.snap == 'string') {
928
- that.pagesX = [];
929
- that.pagesY = [];
930
- els = that.scroller.querySelectorAll(that.options.snap);
931
- for (i=0, l=els.length; i<l; i++) {
932
- pos = that._offset(els[i]);
933
- pos.left += that.wrapperOffsetLeft;
934
- pos.top += that.wrapperOffsetTop;
935
- that.pagesX[i] = pos.left < that.maxScrollX ? that.maxScrollX : pos.left * that.scale;
936
- that.pagesY[i] = pos.top < that.maxScrollY ? that.maxScrollY : pos.top * that.scale;
937
- }
938
- } else if (that.options.snap) {
939
- that.pagesX = [];
940
- while (pos >= that.maxScrollX) {
941
- that.pagesX[page] = pos;
942
- pos = pos - that.wrapperW;
943
- page++;
944
- }
945
- if (that.maxScrollX%that.wrapperW) that.pagesX[that.pagesX.length] = that.maxScrollX - that.pagesX[that.pagesX.length-1] + that.pagesX[that.pagesX.length-1];
946
-
947
- pos = 0;
948
- page = 0;
949
- that.pagesY = [];
950
- while (pos >= that.maxScrollY) {
951
- that.pagesY[page] = pos;
952
- pos = pos - that.wrapperH;
953
- page++;
954
- }
955
- if (that.maxScrollY%that.wrapperH) that.pagesY[that.pagesY.length] = that.maxScrollY - that.pagesY[that.pagesY.length-1] + that.pagesY[that.pagesY.length-1];
956
- }
957
-
958
- // Prepare the scrollbars
959
- that._scrollbar('h');
960
- that._scrollbar('v');
961
-
962
- if (!that.zoomed) {
963
- that.scroller.style[vendor + 'TransitionDuration'] = '0';
964
- that._resetPos(200);
965
- }
966
- },
967
-
968
- scrollTo: function (x, y, time, relative) {
969
- var that = this,
970
- step = x,
971
- i, l;
972
-
973
- that.stop();
974
-
975
- if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];
976
-
977
- for (i=0, l=step.length; i<l; i++) {
978
- if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
979
- that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
980
- }
981
-
982
- that._startAni();
983
- },
984
-
985
- scrollToElement: function (el, time) {
986
- var that = this, pos;
987
- el = el.nodeType ? el : that.scroller.querySelector(el);
988
- if (!el) return;
989
-
990
- pos = that._offset(el);
991
- pos.left += that.wrapperOffsetLeft;
992
- pos.top += that.wrapperOffsetTop;
993
-
994
- pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left;
995
- pos.top = pos.top > that.minScrollY ? that.minScrollY : pos.top < that.maxScrollY ? that.maxScrollY : pos.top;
996
- time = time === undefined ? m.max(m.abs(pos.left)*2, m.abs(pos.top)*2) : time;
997
-
998
- that.scrollTo(pos.left, pos.top, time);
999
- },
1000
-
1001
- scrollToPage: function (pageX, pageY, time) {
1002
- var that = this, x, y;
1003
-
1004
- time = time === undefined ? 400 : time;
1005
-
1006
- if (that.options.onScrollStart) that.options.onScrollStart.call(that);
1007
-
1008
- if (that.options.snap) {
1009
- pageX = pageX == 'next' ? that.currPageX+1 : pageX == 'prev' ? that.currPageX-1 : pageX;
1010
- pageY = pageY == 'next' ? that.currPageY+1 : pageY == 'prev' ? that.currPageY-1 : pageY;
1011
-
1012
- pageX = pageX < 0 ? 0 : pageX > that.pagesX.length-1 ? that.pagesX.length-1 : pageX;
1013
- pageY = pageY < 0 ? 0 : pageY > that.pagesY.length-1 ? that.pagesY.length-1 : pageY;
1014
-
1015
- that.currPageX = pageX;
1016
- that.currPageY = pageY;
1017
- x = that.pagesX[pageX];
1018
- y = that.pagesY[pageY];
1019
- } else {
1020
- x = -that.wrapperW * pageX;
1021
- y = -that.wrapperH * pageY;
1022
- if (x < that.maxScrollX) x = that.maxScrollX;
1023
- if (y < that.maxScrollY) y = that.maxScrollY;
1024
- }
1025
-
1026
- that.scrollTo(x, y, time);
1027
- },
1028
-
1029
- disable: function () {
1030
- this.stop();
1031
- this._resetPos(0);
1032
- this.enabled = false;
1033
-
1034
- // If disabled after touchstart we make sure that there are no left over events
1035
- this._unbind(MOVE_EV);
1036
- this._unbind(END_EV);
1037
- this._unbind(CANCEL_EV);
1038
- },
1039
-
1040
- enable: function () {
1041
- this.enabled = true;
1042
- },
1043
-
1044
- stop: function () {
1045
- if (this.options.useTransition) this._unbind('webkitTransitionEnd');
1046
- else cancelFrame(this.aniTime);
1047
- this.steps = [];
1048
- this.moved = false;
1049
- this.animating = false;
1050
- },
1051
-
1052
- zoom: function (x, y, scale, time) {
1053
- var that = this,
1054
- relScale = scale / that.scale;
1055
-
1056
- if (!that.options.useTransform) return;
1057
-
1058
- that.zoomed = true;
1059
- time = time === undefined ? 200 : time;
1060
- x = x - that.wrapperOffsetLeft - that.x;
1061
- y = y - that.wrapperOffsetTop - that.y;
1062
- that.x = x - x * relScale + that.x;
1063
- that.y = y - y * relScale + that.y;
1064
-
1065
- that.scale = scale;
1066
- that.refresh();
1067
-
1068
- that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x;
1069
- that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
1070
-
1071
- that.scroller.style[vendor + 'TransitionDuration'] = time + 'ms';
1072
- that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose + ' scale(' + scale + ')';
1073
- that.zoomed = false;
1074
- },
1075
-
1076
- isReady: function () {
1077
- return !this.moved && !this.zoomed && !this.animating;
1078
- }
1079
- };
1080
-
1081
- if (typeof exports !== 'undefined') exports.iScroll = iScroll;
1082
- else window.iScroll = iScroll;
1083
-
1084
- })();