mm_os 1.3.4 → 1.3.6

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 (368) hide show
  1. package/README.en.md +36 -0
  2. package/README.md +25 -166
  3. package/conf.json +3 -0
  4. package/core/base/index.js +29 -0
  5. package/core/base/mqtt/index.js +268 -0
  6. package/core/base/mqtt/lib.js +40 -0
  7. package/core/base/web/index.js +110 -0
  8. package/core/com/api/com.json +4 -0
  9. package/{bin → core}/com/api/config.tpl.json +9 -7
  10. package/{bin → core}/com/api/drive.js +239 -64
  11. package/{bin → core}/com/api/index.js +8 -9
  12. package/{bin → core}/com/api/oauth.js +23 -14
  13. package/core/com/api/script.js +32 -0
  14. package/core/com/db/com.json +4 -0
  15. package/{bin → core}/com/db/drive.js +99 -65
  16. package/{bin → core}/com/db/index.js +2 -2
  17. package/core/com/event/com.json +4 -0
  18. package/{bin → core}/com/event/config.tpl.json +2 -2
  19. package/core/com/event/drive.js +125 -0
  20. package/{bin → core}/com/event/index.js +5 -10
  21. package/core/com/event/script.js +26 -0
  22. package/core/com/eventer/com.js +450 -0
  23. package/core/com/eventer/com.json +4 -0
  24. package/core/com/middleware/com.js +128 -0
  25. package/core/com/middleware/com.json +4 -0
  26. package/core/com/middleware/config.tpl.json +8 -0
  27. package/core/com/middleware/script.js +9 -0
  28. package/core/com/mqtt/com.json +4 -0
  29. package/core/com/mqtt/config.tpl.json +12 -0
  30. package/core/com/mqtt/drive.js +139 -0
  31. package/core/com/mqtt/index.js +138 -0
  32. package/core/com/mqtt/script.js +33 -0
  33. package/core/com/msg/com.js +296 -0
  34. package/core/com/msg/com.json +4 -0
  35. package/{bin → core}/com/nav/drive.js +42 -17
  36. package/{bin → core}/com/nav/index.js +4 -4
  37. package/core/com/nav/tpl/admin_pc/page_channel.vue +299 -0
  38. package/core/com/nav/tpl/admin_pc/page_config.vue +279 -0
  39. package/core/com/nav/tpl/admin_pc/page_config_form.vue +194 -0
  40. package/core/com/nav/tpl/admin_pc/page_default.vue +287 -0
  41. package/core/com/nav/tpl/admin_pc/page_form.vue +180 -0
  42. package/core/com/nav/tpl/admin_pc/page_lang.vue +265 -0
  43. package/core/com/nav/tpl/admin_pc/page_nav.vue +313 -0
  44. package/core/com/nav/tpl/admin_pc/page_table.vue +285 -0
  45. package/core/com/nav/tpl/admin_pc/page_type.vue +313 -0
  46. package/core/com/nav/tpl/dev_pc/page_channel.vue +253 -0
  47. package/core/com/nav/tpl/dev_pc/page_config.vue +253 -0
  48. package/core/com/nav/tpl/dev_pc/page_default.vue +247 -0
  49. package/core/com/nav/tpl/dev_pc/page_form.vue +162 -0
  50. package/core/com/nav/tpl/dev_pc/page_nav.vue +253 -0
  51. package/core/com/nav/tpl/dev_pc/page_table.vue +247 -0
  52. package/core/com/nav/tpl/dev_pc/page_type.vue +253 -0
  53. package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_channel.vue +231 -231
  54. package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_default.vue +231 -231
  55. package/{bin → core}/com/nav/tpl/home_pc/page_form.vue +9 -9
  56. package/{bin → core}/com/nav/tpl/home_pc/page_list.vue +231 -231
  57. package/{bin → core}/com/nav/tpl/home_pc/page_nav.vue +221 -221
  58. package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_type.vue +231 -231
  59. package/{bin → core}/com/nav/tpl/home_pc/page_view.vue +8 -8
  60. package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_channel.vue +231 -231
  61. package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_default.vue +231 -231
  62. package/{bin → core}/com/nav/tpl/home_phone/page_form.vue +9 -9
  63. package/{bin → core}/com/nav/tpl/home_phone/page_list.vue +231 -231
  64. package/{bin/com/nav/tpl/admin_pc → core/com/nav/tpl/home_phone}/page_nav.vue +236 -220
  65. package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_type.vue +231 -231
  66. package/{bin → core}/com/nav/tpl/home_phone/page_view.vue +8 -8
  67. package/core/com/nav/viewmodel.js +296 -0
  68. package/{bin → core}/com/param/config.tpl.json +24 -0
  69. package/{bin → core}/com/param/drive.js +47 -15
  70. package/core/com/plugin/com.json +4 -0
  71. package/core/com/plugin/config.tpl.json +20 -0
  72. package/{bin → core}/com/plugin/drive.js +5 -8
  73. package/{bin → core}/com/plugin/index.js +11 -56
  74. package/core/com/socket/README.md +47 -0
  75. package/core/com/socket/com.json +4 -0
  76. package/core/com/socket/config.tpl.json +14 -0
  77. package/{bin → core}/com/socket/drive.js +74 -51
  78. package/{bin → core}/com/socket/index.js +4 -2
  79. package/{bin → core}/com/socket/script.js +8 -6
  80. package/core/com/sql/config.tpl.json +70 -0
  81. package/{bin → core}/com/sql/drive.js +281 -58
  82. package/core/com/static/com.json +4 -0
  83. package/core/com/static/config.tpl.json +20 -0
  84. package/{bin → core}/com/static/drive.js +6 -4
  85. package/{bin → core}/com/static/index.js +5 -1
  86. package/core/com/task/com.json +4 -0
  87. package/core/com/task/config.tpl.json +24 -0
  88. package/core/com/task/drive.js +374 -0
  89. package/{bin → core}/com/task/index.js +14 -20
  90. package/core/com/task/script.js +37 -0
  91. package/core/com/timer/com.js +217 -0
  92. package/core/com/timer/com.json +4 -0
  93. package/core/com/tpl/com.js +19 -0
  94. package/core/com/tpl/com.json +4 -0
  95. package/index.js +161 -740
  96. package/lib/actions.js +50 -0
  97. package/lib/app.js +73 -0
  98. package/lib/base.js +355 -0
  99. package/lib/com.js +31 -0
  100. package/lib/game.js +31 -0
  101. package/lib/ref.js +121 -0
  102. package/middleware/cors/index.js +57 -0
  103. package/middleware/cors/middleware.json +7 -0
  104. package/middleware/mqtt_base/index.js +10 -0
  105. package/middleware/mqtt_base/middleware.json +8 -0
  106. package/{waf.js → middleware/waf/index.js} +12 -2
  107. package/middleware/waf/middleware.json +9 -0
  108. package/middleware/web_base/index.js +67 -0
  109. package/middleware/web_base/middleware.json +9 -0
  110. package/middleware/web_event/index.js +411 -0
  111. package/middleware/web_event/middleware.json +10 -0
  112. package/middleware/web_proxy/index.js +24 -0
  113. package/middleware/web_proxy/middleware.json +9 -0
  114. package/middleware/web_router/index.js +33 -0
  115. package/middleware/web_router/middleware.json +10 -0
  116. package/middleware/web_socket/index.js +21 -0
  117. package/middleware/web_socket/middleware.json +9 -0
  118. package/middleware/web_static/index.js +26 -0
  119. package/middleware/web_static/middleware.json +9 -0
  120. package/nodemon.json +12 -2
  121. package/package.json +56 -66
  122. package/.gitattributes +0 -5
  123. package/bin/com/README.md +0 -2
  124. package/bin/com/api/script.js +0 -14
  125. package/bin/com/cmd/README.md +0 -3
  126. package/bin/com/cmd/config.tpl.json +0 -41
  127. package/bin/com/cmd/drive.js +0 -512
  128. package/bin/com/cmd/index.js +0 -213
  129. package/bin/com/cmd/old/5w2h.js +0 -54
  130. package/bin/com/cmd/old/drive.js +0 -423
  131. package/bin/com/cmd/script.js +0 -11
  132. package/bin/com/event/drive.js +0 -69
  133. package/bin/com/event/script.js +0 -12
  134. package/bin/com/nav/tpl/admin_pc/page_channel.vue +0 -234
  135. package/bin/com/nav/tpl/admin_pc/page_default.vue +0 -236
  136. package/bin/com/nav/tpl/admin_pc/page_form.vue +0 -152
  137. package/bin/com/nav/tpl/admin_pc/page_table.vue +0 -236
  138. package/bin/com/nav/tpl/admin_pc/page_type.vue +0 -234
  139. package/bin/com/nav/tpl/home_phone/page_nav.vue +0 -221
  140. package/bin/com/nav/viewmodel.js +0 -161
  141. package/bin/com/plugin/config.tpl.json +0 -11
  142. package/bin/com/socket/config.tpl.json +0 -8
  143. package/bin/com/sql/config.tpl.json +0 -34
  144. package/bin/com/static/config.tpl.json +0 -11
  145. package/bin/com/task/config.tpl.json +0 -13
  146. package/bin/com/task/drive.js +0 -288
  147. package/bin/com/task/script.js +0 -38
  148. package/bin/com.js +0 -74
  149. package/bin/mm.conf +0 -48
  150. package/bin/static/404.html +0 -52
  151. package/bin/static/README.md +0 -1
  152. package/bin/static/css/font-awesome.min.css +0 -7
  153. package/bin/static/css/mm_base.css +0 -220
  154. package/bin/static/css/mm_common.css +0 -518
  155. package/bin/static/css/mm_component.css +0 -307
  156. package/bin/static/css/mm_expand.css +0 -634
  157. package/bin/static/css/mm_theme.css +0 -291
  158. package/bin/static/css/new_file.css +0 -79
  159. package/bin/static/css/swiper.min.css +0 -12
  160. package/bin/static/favicon.ico +0 -0
  161. package/bin/static/font/FontAwesome.otf +0 -0
  162. package/bin/static/font/HelveticaNeue.eot +0 -0
  163. package/bin/static/font/HelveticaNeue.otf +0 -0
  164. package/bin/static/font/HelveticaNeue.svg +0 -1273
  165. package/bin/static/font/HelveticaNeue.woff +0 -0
  166. package/bin/static/font/HelveticaNeue.woff2 +0 -0
  167. package/bin/static/font/fontawesome-webfont.eot +0 -0
  168. package/bin/static/font/fontawesome-webfont.svg +0 -2671
  169. package/bin/static/font/fontawesome-webfont.ttf +0 -0
  170. package/bin/static/font/fontawesome-webfont.woff +0 -0
  171. package/bin/static/font/fontawesome-webfont.woff2 +0 -0
  172. package/bin/static/h5.html +0 -325
  173. package/bin/static/highlight/highlight.pack.js +0 -2
  174. package/bin/static/highlight/styles/a11y-dark.css +0 -99
  175. package/bin/static/highlight/styles/a11y-light.css +0 -99
  176. package/bin/static/highlight/styles/agate.css +0 -108
  177. package/bin/static/highlight/styles/an-old-hope.css +0 -89
  178. package/bin/static/highlight/styles/androidstudio.css +0 -66
  179. package/bin/static/highlight/styles/arduino-light.css +0 -88
  180. package/bin/static/highlight/styles/arta.css +0 -73
  181. package/bin/static/highlight/styles/ascetic.css +0 -45
  182. package/bin/static/highlight/styles/atelier-cave-dark.css +0 -83
  183. package/bin/static/highlight/styles/atelier-cave-light.css +0 -85
  184. package/bin/static/highlight/styles/atelier-dune-dark.css +0 -69
  185. package/bin/static/highlight/styles/atelier-dune-light.css +0 -69
  186. package/bin/static/highlight/styles/atelier-estuary-dark.css +0 -84
  187. package/bin/static/highlight/styles/atelier-estuary-light.css +0 -84
  188. package/bin/static/highlight/styles/atelier-forest-dark.css +0 -69
  189. package/bin/static/highlight/styles/atelier-forest-light.css +0 -69
  190. package/bin/static/highlight/styles/atelier-heath-dark.css +0 -69
  191. package/bin/static/highlight/styles/atelier-heath-light.css +0 -69
  192. package/bin/static/highlight/styles/atelier-lakeside-dark.css +0 -69
  193. package/bin/static/highlight/styles/atelier-lakeside-light.css +0 -69
  194. package/bin/static/highlight/styles/atelier-plateau-dark.css +0 -84
  195. package/bin/static/highlight/styles/atelier-plateau-light.css +0 -84
  196. package/bin/static/highlight/styles/atelier-savanna-dark.css +0 -84
  197. package/bin/static/highlight/styles/atelier-savanna-light.css +0 -84
  198. package/bin/static/highlight/styles/atelier-seaside-dark.css +0 -69
  199. package/bin/static/highlight/styles/atelier-seaside-light.css +0 -69
  200. package/bin/static/highlight/styles/atelier-sulphurpool-dark.css +0 -69
  201. package/bin/static/highlight/styles/atelier-sulphurpool-light.css +0 -69
  202. package/bin/static/highlight/styles/atom-one-dark-reasonable.css +0 -77
  203. package/bin/static/highlight/styles/atom-one-dark.css +0 -96
  204. package/bin/static/highlight/styles/atom-one-light.css +0 -96
  205. package/bin/static/highlight/styles/brown-paper.css +0 -64
  206. package/bin/static/highlight/styles/brown-papersq.png +0 -0
  207. package/bin/static/highlight/styles/codepen-embed.css +0 -60
  208. package/bin/static/highlight/styles/color-brewer.css +0 -71
  209. package/bin/static/highlight/styles/darcula.css +0 -77
  210. package/bin/static/highlight/styles/dark.css +0 -63
  211. package/bin/static/highlight/styles/darkula.css +0 -6
  212. package/bin/static/highlight/styles/default.css +0 -99
  213. package/bin/static/highlight/styles/docco.css +0 -97
  214. package/bin/static/highlight/styles/dracula.css +0 -76
  215. package/bin/static/highlight/styles/far.css +0 -71
  216. package/bin/static/highlight/styles/foundation.css +0 -88
  217. package/bin/static/highlight/styles/github-gist.css +0 -79
  218. package/bin/static/highlight/styles/github.css +0 -99
  219. package/bin/static/highlight/styles/gml.css +0 -78
  220. package/bin/static/highlight/styles/googlecode.css +0 -89
  221. package/bin/static/highlight/styles/grayscale.css +0 -101
  222. package/bin/static/highlight/styles/gruvbox-dark.css +0 -108
  223. package/bin/static/highlight/styles/gruvbox-light.css +0 -108
  224. package/bin/static/highlight/styles/hopscotch.css +0 -83
  225. package/bin/static/highlight/styles/hybrid.css +0 -102
  226. package/bin/static/highlight/styles/idea.css +0 -97
  227. package/bin/static/highlight/styles/ir-black.css +0 -73
  228. package/bin/static/highlight/styles/isbl-editor-dark.css +0 -112
  229. package/bin/static/highlight/styles/isbl-editor-light.css +0 -112
  230. package/bin/static/highlight/styles/kimbie.dark.css +0 -74
  231. package/bin/static/highlight/styles/kimbie.light.css +0 -74
  232. package/bin/static/highlight/styles/lightfair.css +0 -87
  233. package/bin/static/highlight/styles/magula.css +0 -70
  234. package/bin/static/highlight/styles/mono-blue.css +0 -59
  235. package/bin/static/highlight/styles/monokai-sublime.css +0 -83
  236. package/bin/static/highlight/styles/monokai.css +0 -70
  237. package/bin/static/highlight/styles/nord.css +0 -309
  238. package/bin/static/highlight/styles/obsidian.css +0 -88
  239. package/bin/static/highlight/styles/ocean.css +0 -74
  240. package/bin/static/highlight/styles/paraiso-dark.css +0 -72
  241. package/bin/static/highlight/styles/paraiso-light.css +0 -72
  242. package/bin/static/highlight/styles/pojoaque.css +0 -83
  243. package/bin/static/highlight/styles/pojoaque.jpg +0 -0
  244. package/bin/static/highlight/styles/purebasic.css +0 -96
  245. package/bin/static/highlight/styles/qtcreator_dark.css +0 -83
  246. package/bin/static/highlight/styles/qtcreator_light.css +0 -83
  247. package/bin/static/highlight/styles/railscasts.css +0 -106
  248. package/bin/static/highlight/styles/rainbow.css +0 -85
  249. package/bin/static/highlight/styles/routeros.css +0 -108
  250. package/bin/static/highlight/styles/school-book.css +0 -69
  251. package/bin/static/highlight/styles/school-book.png +0 -0
  252. package/bin/static/highlight/styles/shades-of-purple.css +0 -97
  253. package/bin/static/highlight/styles/solarized-dark.css +0 -84
  254. package/bin/static/highlight/styles/solarized-light.css +0 -84
  255. package/bin/static/highlight/styles/sunburst.css +0 -102
  256. package/bin/static/highlight/styles/tomorrow-night-blue.css +0 -75
  257. package/bin/static/highlight/styles/tomorrow-night-bright.css +0 -74
  258. package/bin/static/highlight/styles/tomorrow-night-eighties.css +0 -74
  259. package/bin/static/highlight/styles/tomorrow-night.css +0 -75
  260. package/bin/static/highlight/styles/tomorrow.css +0 -72
  261. package/bin/static/highlight/styles/vs.css +0 -68
  262. package/bin/static/highlight/styles/vs2015.css +0 -115
  263. package/bin/static/highlight/styles/xcode.css +0 -104
  264. package/bin/static/highlight/styles/xt256.css +0 -92
  265. package/bin/static/highlight/styles/zenburn.css +0 -80
  266. package/bin/static/highlight/vue-highlight.js +0 -29
  267. package/bin/static/ifame.html +0 -24
  268. package/bin/static/img/add.png +0 -0
  269. package/bin/static/img/avatar.png +0 -0
  270. package/bin/static/img/banner_2.png +0 -0
  271. package/bin/static/img/default.png +0 -0
  272. package/bin/static/img/loading.svg +0 -1
  273. package/bin/static/img/logo.png +0 -0
  274. package/bin/static/img/logo1.png +0 -0
  275. package/bin/static/img/logo_gray.png +0 -0
  276. package/bin/static/img/logo_round.png +0 -0
  277. package/bin/static/img/mm.ico +0 -0
  278. package/bin/static/img/mm.jpg +0 -0
  279. package/bin/static/img/select.png +0 -0
  280. package/bin/static/img/web.png +0 -0
  281. package/bin/static/index.html +0 -12
  282. package/bin/static/js/clipboard.min.js +0 -257
  283. package/bin/static/js/css.min.js +0 -1
  284. package/bin/static/js/echarts.js +0 -22
  285. package/bin/static/js/html5.min.js +0 -1
  286. package/bin/static/js/jquery.lazyload.min.js +0 -2
  287. package/bin/static/js/jquery.min.js +0 -4189
  288. package/bin/static/js/jquery.scrollstop.min.js +0 -2
  289. package/bin/static/js/mm-requirejs-vue.js +0 -283
  290. package/bin/static/js/mm_check.js +0 -490
  291. package/bin/static/js/mm_flexble.js +0 -112
  292. package/bin/static/js/mm_picker.js +0 -1417
  293. package/bin/static/js/mm_pinyinlite.js +0 -873
  294. package/bin/static/js/mm_sdk.js +0 -2841
  295. package/bin/static/js/mm_ui_expand.js +0 -468
  296. package/bin/static/js/mm_vue.js +0 -376
  297. package/bin/static/js/mm_vue_ui.js +0 -2375
  298. package/bin/static/js/mm_websocket.js +0 -145
  299. package/bin/static/js/require.js +0 -5
  300. package/bin/static/js/sortable.min.js +0 -3
  301. package/bin/static/js/swiper.min.js +0 -13
  302. package/bin/static/js/text.min.js +0 -1
  303. package/bin/static/js/vue-router.min.js +0 -6
  304. package/bin/static/js/vue.js +0 -12338
  305. package/bin/static/js/vuedraggable.min.js +0 -2
  306. package/bin/static/js/vuex.min.js +0 -6
  307. package/bin/static/src/components/bar/mm_action.vue +0 -19
  308. package/bin/static/src/components/bar/mm_buy.vue +0 -19
  309. package/bin/static/src/components/bar/mm_chat.vue +0 -18
  310. package/bin/static/src/components/bar/mm_count.vue +0 -18
  311. package/bin/static/src/components/bar/mm_filter.vue +0 -18
  312. package/bin/static/src/components/bar/mm_search.vue +0 -18
  313. package/bin/static/src/components/bar/mm_sort.vue +0 -18
  314. package/bin/static/src/components/bar/mm_tag.vue +0 -18
  315. package/bin/static/src/components/bar/mm_title.vue +0 -19
  316. package/bin/static/src/components/content/mm_pre.vue +0 -70
  317. package/bin/static/src/components/expand/mm_drag.vue +0 -39
  318. package/bin/static/src/components/item/mm_article.vue +0 -115
  319. package/bin/static/src/components/item/mm_base.vue +0 -26
  320. package/bin/static/src/components/item/mm_contact.vue +0 -25
  321. package/bin/static/src/components/item/mm_goods.vue +0 -23
  322. package/bin/static/src/components/item/mm_img.vue +0 -21
  323. package/bin/static/src/components/item/mm_media.vue +0 -18
  324. package/bin/static/src/components/item/mm_message.vue +0 -18
  325. package/bin/static/src/components/item/mm_music.vue +0 -95
  326. package/bin/static/src/components/item/mm_news.vue +0 -22
  327. package/bin/static/src/components/item/mm_number.vue +0 -26
  328. package/bin/static/src/components/item/mm_question.vue +0 -35
  329. package/bin/static/src/components/item/mm_user.vue +0 -22
  330. package/bin/static/src/components/item/mm_video.vue +0 -95
  331. package/bin/static/src/components/slide/mm_slide_card.vue +0 -64
  332. package/bin/static/src/components/slide/mm_slide_img.vue +0 -47
  333. package/bin/static/src/components/slide/mm_slide_page.vue +0 -8
  334. package/bin/static/src/components/slide/mm_slide_text.vue +0 -54
  335. package/bin/static/src/main.js +0 -84
  336. package/bin/static/src/mixins/form.js +0 -223
  337. package/bin/static/src/mixins/item.js +0 -242
  338. package/bin/static/src/mixins/list.js +0 -244
  339. package/bin/static/src/mixins/page.js +0 -1011
  340. package/bin/static/src/mm_component.js +0 -74
  341. package/bin/static/src/router.js +0 -72
  342. package/bin/static/src/store/user.js +0 -75
  343. package/bin/static/src/store/web.js +0 -50
  344. package/bin/static/user/1/number_info.xlsx +0 -0
  345. package/bin/static/w3c.html +0 -94
  346. package/init.js +0 -55
  347. package/update.md +0 -1
  348. /package/{bin → core}/com/api/README.md +0 -0
  349. /package/{bin → core}/com/api/rpc.js +0 -0
  350. /package/{bin → core}/com/db/README.md +0 -0
  351. /package/{bin → core}/com/event/README.md +0 -0
  352. /package/{bin/com/socket → core/com/mqtt}/README.md +0 -0
  353. /package/{bin → core}/com/nav/README.md +0 -0
  354. /package/{bin → core}/com/nav/config.tpl.json +0 -0
  355. /package/{bin → core}/com/param/README.md +0 -0
  356. /package/{bin → core}/com/param/index.js +0 -0
  357. /package/{bin → core}/com/param/script.js +0 -0
  358. /package/{bin → core}/com/param/test.js +0 -0
  359. /package/{bin → core}/com/plugin/README.md +0 -0
  360. /package/{bin → core}/com/plugin/script.js +0 -0
  361. /package/{bin → core}/com/sql/README.md +0 -0
  362. /package/{bin → core}/com/sql/index.js +0 -0
  363. /package/{bin → core}/com/sql/script.js +0 -0
  364. /package/{bin → core}/com/static/README.md +0 -0
  365. /package/{bin → core}/com/static/script.js +0 -0
  366. /package/{bin → core}/com/task/README.md +0 -0
  367. /package/{bin/rps.bat → rps.bat} +0 -0
  368. /package/{bin/tps.bat → tps.bat} +0 -0
@@ -1,1417 +0,0 @@
1
-
2
- /*======================================================
3
- ************ Calendar ************
4
- ======================================================*/
5
- /*jshint unused: false*/
6
- +function ($) {
7
- "use strict";
8
- var rtl = false;
9
- var Calendar = function (params) {
10
- var p = this;
11
- var defaults = {
12
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月' , '九月' , '十月', '十一月', '十二月'],
13
- monthNamesShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月' , '九月' , '十月', '十一月', '十二月'],
14
- dayNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
15
- dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
16
- firstDay: 1, // First day of the week, Monday
17
- weekendDays: [0, 6], // Sunday and Saturday
18
- multiple: false,
19
- dateFormat: 'yyyy-mm-dd',
20
- direction: 'horizontal', // or 'vertical'
21
- minDate: null,
22
- maxDate: null,
23
- touchMove: true,
24
- animate: true,
25
- closeOnSelect: true,
26
- monthPicker: true,
27
- monthPickerTemplate:
28
- '<div class="picker-calendar-month-picker">' +
29
- '<a href="#" class="link icon-only picker-calendar-prev-month"><i class="icon icon-prev"></i></a>' +
30
- '<div class="current-month-value"></div>' +
31
- '<a href="#" class="link icon-only picker-calendar-next-month"><i class="icon icon-next"></i></a>' +
32
- '</div>',
33
- yearPicker: true,
34
- yearPickerTemplate:
35
- '<div class="picker-calendar-year-picker">' +
36
- '<a href="#" class="link icon-only picker-calendar-prev-year"><i class="icon icon-prev"></i></a>' +
37
- '<span class="current-year-value"></span>' +
38
- '<a href="#" class="link icon-only picker-calendar-next-year"><i class="icon icon-next"></i></a>' +
39
- '</div>',
40
- weekHeader: true,
41
- // Common settings
42
- scrollToInput: true,
43
- inputReadOnly: true,
44
- toolbar: true,
45
- toolbarCloseText: 'Done',
46
- toolbarTemplate:
47
- '<div class="toolbar">' +
48
- '<div class="toolbar-inner">' +
49
- '{{monthPicker}}' +
50
- '{{yearPicker}}' +
51
- // '<a href="#" class="link close-picker">{{closeText}}</a>' +
52
- '</div>' +
53
- '</div>',
54
- /* Callbacks
55
- onMonthAdd
56
- onChange
57
- onOpen
58
- onClose
59
- onDayClick
60
- onMonthYearChangeStart
61
- onMonthYearChangeEnd
62
- */
63
- };
64
- params = params || {};
65
- for (var def in defaults) {
66
- if (typeof params[def] === 'undefined') {
67
- params[def] = defaults[def];
68
- }
69
- }
70
- p.params = params;
71
- p.initialized = false;
72
-
73
- // Inline flag
74
- p.inline = p.params.container ? true : false;
75
-
76
- // Is horizontal
77
- p.isH = p.params.direction === 'horizontal';
78
-
79
- // RTL inverter
80
- var inverter = p.isH ? (rtl ? -1 : 1) : 1;
81
-
82
- // Animating flag
83
- p.animating = false;
84
-
85
- // Format date
86
- function formatDate(date) {
87
- date = new Date(date);
88
- var year = date.getFullYear();
89
- var month = date.getMonth();
90
- var month1 = month + 1;
91
- var day = date.getDate();
92
- var weekDay = date.getDay();
93
- return p.params.dateFormat
94
- .replace(/yyyy/g, year)
95
- .replace(/yy/g, (year + '').substring(2))
96
- .replace(/mm/g, month1 < 10 ? '0' + month1 : month1)
97
- .replace(/m/g, month1)
98
- .replace(/MM/g, p.params.monthNames[month])
99
- .replace(/M/g, p.params.monthNamesShort[month])
100
- .replace(/dd/g, day < 10 ? '0' + day : day)
101
- .replace(/d/g, day)
102
- .replace(/DD/g, p.params.dayNames[weekDay])
103
- .replace(/D/g, p.params.dayNamesShort[weekDay]);
104
- }
105
-
106
-
107
- // Value
108
- p.addValue = function (value) {
109
- if (p.params.multiple) {
110
- if (!p.value) p.value = [];
111
- var inValuesIndex;
112
- for (var i = 0; i < p.value.length; i++) {
113
- if (new Date(value).getTime() === new Date(p.value[i]).getTime()) {
114
- inValuesIndex = i;
115
- }
116
- }
117
- if (typeof inValuesIndex === 'undefined') {
118
- p.value.push(value);
119
- }
120
- else {
121
- p.value.splice(inValuesIndex, 1);
122
- }
123
- p.updateValue();
124
- }
125
- else {
126
- p.value = [value];
127
- p.updateValue();
128
- }
129
- };
130
- p.setValue = function (arrValues) {
131
- p.value = arrValues;
132
- p.updateValue();
133
- };
134
- p.updateValue = function () {
135
- p.wrapper.find('.picker-calendar-day-selected').removeClass('picker-calendar-day-selected');
136
- var i, inputValue;
137
- for (i = 0; i < p.value.length; i++) {
138
- var valueDate = new Date(p.value[i]);
139
- p.wrapper.find('.picker-calendar-day[data-date="' + valueDate.getFullYear() + '-' + valueDate.getMonth() + '-' + valueDate.getDate() + '"]').addClass('picker-calendar-day-selected');
140
- }
141
- if (p.params.onChange) {
142
- p.params.onChange(p, p.value, p.value.map(formatDate));
143
- }
144
- if (p.input && p.input.length > 0) {
145
- if (p.params.formatValue) inputValue = p.params.formatValue(p, p.value);
146
- else {
147
- inputValue = [];
148
- for (i = 0; i < p.value.length; i++) {
149
- inputValue.push(formatDate(p.value[i]));
150
- }
151
- inputValue = inputValue.join(', ');
152
- }
153
- $(p.input).val(inputValue);
154
- $(p.input).trigger('change');
155
- }
156
- };
157
-
158
- // Columns Handlers
159
- p.initCalendarEvents = function () {
160
- var col;
161
- var allowItemClick = true;
162
- var isTouched, isMoved, touchStartX, touchStartY, touchCurrentX, touchCurrentY, touchStartTime, touchEndTime, startTranslate, currentTranslate, wrapperWidth, wrapperHeight, percentage, touchesDiff, isScrolling;
163
- function handleTouchStart (e) {
164
- if (isMoved || isTouched) return;
165
- // e.preventDefault();
166
- isTouched = true;
167
- touchStartX = touchCurrentY = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
168
- touchStartY = touchCurrentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
169
- touchStartTime = (new Date()).getTime();
170
- percentage = 0;
171
- allowItemClick = true;
172
- isScrolling = undefined;
173
- startTranslate = currentTranslate = p.monthsTranslate;
174
- }
175
- function handleTouchMove (e) {
176
- if (!isTouched) return;
177
-
178
- touchCurrentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
179
- touchCurrentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
180
- if (typeof isScrolling === 'undefined') {
181
- isScrolling = !!(isScrolling || Math.abs(touchCurrentY - touchStartY) > Math.abs(touchCurrentX - touchStartX));
182
- }
183
- if (p.isH && isScrolling) {
184
- isTouched = false;
185
- return;
186
- }
187
- e.preventDefault();
188
- if (p.animating) {
189
- isTouched = false;
190
- return;
191
- }
192
- allowItemClick = false;
193
- if (!isMoved) {
194
- // First move
195
- isMoved = true;
196
- wrapperWidth = p.wrapper[0].offsetWidth;
197
- wrapperHeight = p.wrapper[0].offsetHeight;
198
- p.wrapper.transition(0);
199
- }
200
- e.preventDefault();
201
-
202
- touchesDiff = p.isH ? touchCurrentX - touchStartX : touchCurrentY - touchStartY;
203
- percentage = touchesDiff/(p.isH ? wrapperWidth : wrapperHeight);
204
- currentTranslate = (p.monthsTranslate * inverter + percentage) * 100;
205
-
206
- // Transform wrapper
207
- p.wrapper.transform('translate3d(' + (p.isH ? currentTranslate : 0) + '%, ' + (p.isH ? 0 : currentTranslate) + '%, 0)');
208
-
209
- }
210
- function handleTouchEnd (e) {
211
- if (!isTouched || !isMoved) {
212
- isTouched = isMoved = false;
213
- return;
214
- }
215
- isTouched = isMoved = false;
216
-
217
- touchEndTime = new Date().getTime();
218
- if (touchEndTime - touchStartTime < 300) {
219
- if (Math.abs(touchesDiff) < 10) {
220
- p.resetMonth();
221
- }
222
- else if (touchesDiff >= 10) {
223
- if (rtl) p.nextMonth();
224
- else p.prevMonth();
225
- }
226
- else {
227
- if (rtl) p.prevMonth();
228
- else p.nextMonth();
229
- }
230
- }
231
- else {
232
- if (percentage <= -0.5) {
233
- if (rtl) p.prevMonth();
234
- else p.nextMonth();
235
- }
236
- else if (percentage >= 0.5) {
237
- if (rtl) p.nextMonth();
238
- else p.prevMonth();
239
- }
240
- else {
241
- p.resetMonth();
242
- }
243
- }
244
-
245
- // Allow click
246
- setTimeout(function () {
247
- allowItemClick = true;
248
- }, 100);
249
- }
250
-
251
- function handleDayClick(e) {
252
- if (!allowItemClick) return;
253
- var day = $(e.target).parents('.picker-calendar-day');
254
- if (day.length === 0 && $(e.target).hasClass('picker-calendar-day')) {
255
- day = $(e.target);
256
- }
257
- if (day.length === 0) return;
258
- if (day.hasClass('picker-calendar-day-selected') && !p.params.multiple) return;
259
- if (day.hasClass('picker-calendar-day-disabled')) return;
260
- if (day.hasClass('picker-calendar-day-next')) p.nextMonth();
261
- if (day.hasClass('picker-calendar-day-prev')) p.prevMonth();
262
- var dateYear = day.attr('data-year');
263
- var dateMonth = day.attr('data-month');
264
- var dateDay = day.attr('data-day');
265
- if (p.params.onDayClick) {
266
- p.params.onDayClick(p, day[0], dateYear, dateMonth, dateDay);
267
- }
268
- p.addValue(new Date(dateYear, dateMonth, dateDay).getTime());
269
- if (p.params.closeOnSelect) p.close();
270
- }
271
-
272
- p.container.find('.picker-calendar-prev-month').on('click', p.prevMonth);
273
- p.container.find('.picker-calendar-next-month').on('click', p.nextMonth);
274
- p.container.find('.picker-calendar-prev-year').on('click', p.prevYear);
275
- p.container.find('.picker-calendar-next-year').on('click', p.nextYear);
276
- p.wrapper.on('click', handleDayClick);
277
- if (p.params.touchMove) {
278
- p.wrapper.on($.touchEvents.start, handleTouchStart);
279
- p.wrapper.on($.touchEvents.move, handleTouchMove);
280
- p.wrapper.on($.touchEvents.end, handleTouchEnd);
281
- }
282
-
283
- p.container[0].f7DestroyCalendarEvents = function () {
284
- p.container.find('.picker-calendar-prev-month').off('click', p.prevMonth);
285
- p.container.find('.picker-calendar-next-month').off('click', p.nextMonth);
286
- p.container.find('.picker-calendar-prev-year').off('click', p.prevYear);
287
- p.container.find('.picker-calendar-next-year').off('click', p.nextYear);
288
- p.wrapper.off('click', handleDayClick);
289
- if (p.params.touchMove) {
290
- p.wrapper.off($.touchEvents.start, handleTouchStart);
291
- p.wrapper.off($.touchEvents.move, handleTouchMove);
292
- p.wrapper.off($.touchEvents.end, handleTouchEnd);
293
- }
294
- };
295
-
296
-
297
- };
298
- p.destroyCalendarEvents = function (colContainer) {
299
- if ('f7DestroyCalendarEvents' in p.container[0]) p.container[0].f7DestroyCalendarEvents();
300
- };
301
-
302
- // Calendar Methods
303
- p.daysInMonth = function (date) {
304
- var d = new Date(date);
305
- return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
306
- };
307
- p.monthHTML = function (date, offset) {
308
- date = new Date(date);
309
- var year = date.getFullYear(),
310
- month = date.getMonth(),
311
- day = date.getDate();
312
- if (offset === 'next') {
313
- if (month === 11) date = new Date(year + 1, 0);
314
- else date = new Date(year, month + 1, 1);
315
- }
316
- if (offset === 'prev') {
317
- if (month === 0) date = new Date(year - 1, 11);
318
- else date = new Date(year, month - 1, 1);
319
- }
320
- if (offset === 'next' || offset === 'prev') {
321
- month = date.getMonth();
322
- year = date.getFullYear();
323
- }
324
- var daysInPrevMonth = p.daysInMonth(new Date(date.getFullYear(), date.getMonth()).getTime() - 10 * 24 * 60 * 60 * 1000),
325
- daysInMonth = p.daysInMonth(date),
326
- firstDayOfMonthIndex = new Date(date.getFullYear(), date.getMonth()).getDay();
327
- if (firstDayOfMonthIndex === 0) firstDayOfMonthIndex = 7;
328
-
329
- var dayDate, currentValues = [], i, j,
330
- rows = 6, cols = 7,
331
- monthHTML = '',
332
- dayIndex = 0 + (p.params.firstDay - 1),
333
- today = new Date().setHours(0,0,0,0),
334
- minDate = p.params.minDate ? new Date(p.params.minDate).getTime() : null,
335
- maxDate = p.params.maxDate ? new Date(p.params.maxDate).getTime() : null;
336
-
337
- if (p.value && p.value.length) {
338
- for (i = 0; i < p.value.length; i++) {
339
- currentValues.push(new Date(p.value[i]).setHours(0,0,0,0));
340
- }
341
- }
342
-
343
- for (i = 1; i <= rows; i++) {
344
- var rowHTML = '';
345
- var row = i;
346
- for (j = 1; j <= cols; j++) {
347
- var col = j;
348
- dayIndex ++;
349
- var dayNumber = dayIndex - firstDayOfMonthIndex;
350
- var addClass = '';
351
- if (dayNumber < 0) {
352
- dayNumber = daysInPrevMonth + dayNumber + 1;
353
- addClass += ' picker-calendar-day-prev';
354
- dayDate = new Date(month - 1 < 0 ? year - 1 : year, month - 1 < 0 ? 11 : month - 1, dayNumber).getTime();
355
- }
356
- else {
357
- dayNumber = dayNumber + 1;
358
- if (dayNumber > daysInMonth) {
359
- dayNumber = dayNumber - daysInMonth;
360
- addClass += ' picker-calendar-day-next';
361
- dayDate = new Date(month + 1 > 11 ? year + 1 : year, month + 1 > 11 ? 0 : month + 1, dayNumber).getTime();
362
- }
363
- else {
364
- dayDate = new Date(year, month, dayNumber).getTime();
365
- }
366
- }
367
- // Today
368
- if (dayDate === today) addClass += ' picker-calendar-day-today';
369
- // Selected
370
- if (currentValues.indexOf(dayDate) >= 0) addClass += ' picker-calendar-day-selected';
371
- // Weekend
372
- if (p.params.weekendDays.indexOf(col - 1) >= 0) {
373
- addClass += ' picker-calendar-day-weekend';
374
- }
375
- // Disabled
376
- if ((minDate && dayDate < minDate) || (maxDate && dayDate > maxDate)) {
377
- addClass += ' picker-calendar-day-disabled';
378
- }
379
-
380
- dayDate = new Date(dayDate);
381
- var dayYear = dayDate.getFullYear();
382
- var dayMonth = dayDate.getMonth();
383
- rowHTML += '<div data-year="' + dayYear + '" data-month="' + dayMonth + '" data-day="' + dayNumber + '" class="picker-calendar-day' + (addClass) + '" data-date="' + (dayYear + '-' + dayMonth + '-' + dayNumber) + '"><span>'+dayNumber+'</span></div>';
384
- }
385
- monthHTML += '<div class="picker-calendar-row">' + rowHTML + '</div>';
386
- }
387
- monthHTML = '<div class="picker-calendar-month" data-year="' + year + '" data-month="' + month + '">' + monthHTML + '</div>';
388
- return monthHTML;
389
- };
390
- p.animating = false;
391
- p.updateCurrentMonthYear = function (dir) {
392
- if (typeof dir === 'undefined') {
393
- p.currentMonth = parseInt(p.months.eq(1).attr('data-month'), 10);
394
- p.currentYear = parseInt(p.months.eq(1).attr('data-year'), 10);
395
- }
396
- else {
397
- p.currentMonth = parseInt(p.months.eq(dir === 'next' ? (p.months.length - 1) : 0).attr('data-month'), 10);
398
- p.currentYear = parseInt(p.months.eq(dir === 'next' ? (p.months.length - 1) : 0).attr('data-year'), 10);
399
- }
400
- p.container.find('.current-month-value').text(p.params.monthNames[p.currentMonth]);
401
- p.container.find('.current-year-value').text(p.currentYear);
402
-
403
- };
404
- p.onMonthChangeStart = function (dir) {
405
- p.updateCurrentMonthYear(dir);
406
- p.months.removeClass('picker-calendar-month-current picker-calendar-month-prev picker-calendar-month-next');
407
- var currentIndex = dir === 'next' ? p.months.length - 1 : 0;
408
-
409
- p.months.eq(currentIndex).addClass('picker-calendar-month-current');
410
- p.months.eq(dir === 'next' ? currentIndex - 1 : currentIndex + 1).addClass(dir === 'next' ? 'picker-calendar-month-prev' : 'picker-calendar-month-next');
411
-
412
- if (p.params.onMonthYearChangeStart) {
413
- p.params.onMonthYearChangeStart(p, p.currentYear, p.currentMonth);
414
- }
415
- };
416
- p.onMonthChangeEnd = function (dir, rebuildBoth) {
417
- p.animating = false;
418
- var nextMonthHTML, prevMonthHTML, newMonthHTML;
419
- p.wrapper.find('.picker-calendar-month:not(.picker-calendar-month-prev):not(.picker-calendar-month-current):not(.picker-calendar-month-next)').remove();
420
-
421
- if (typeof dir === 'undefined') {
422
- dir = 'next';
423
- rebuildBoth = true;
424
- }
425
- if (!rebuildBoth) {
426
- newMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), dir);
427
- }
428
- else {
429
- p.wrapper.find('.picker-calendar-month-next, .picker-calendar-month-prev').remove();
430
- prevMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), 'prev');
431
- nextMonthHTML = p.monthHTML(new Date(p.currentYear, p.currentMonth), 'next');
432
- }
433
- if (dir === 'next' || rebuildBoth) {
434
- p.wrapper.append(newMonthHTML || nextMonthHTML);
435
- }
436
- if (dir === 'prev' || rebuildBoth) {
437
- p.wrapper.prepend(newMonthHTML || prevMonthHTML);
438
- }
439
- p.months = p.wrapper.find('.picker-calendar-month');
440
- p.setMonthsTranslate(p.monthsTranslate);
441
- if (p.params.onMonthAdd) {
442
- p.params.onMonthAdd(p, dir === 'next' ? p.months.eq(p.months.length - 1)[0] : p.months.eq(0)[0]);
443
- }
444
- if (p.params.onMonthYearChangeEnd) {
445
- p.params.onMonthYearChangeEnd(p, p.currentYear, p.currentMonth);
446
- }
447
- };
448
- p.setMonthsTranslate = function (translate) {
449
- translate = translate || p.monthsTranslate || 0;
450
- if (typeof p.monthsTranslate === 'undefined') p.monthsTranslate = translate;
451
- p.months.removeClass('picker-calendar-month-current picker-calendar-month-prev picker-calendar-month-next');
452
- var prevMonthTranslate = -(translate + 1) * 100 * inverter;
453
- var currentMonthTranslate = -translate * 100 * inverter;
454
- var nextMonthTranslate = -(translate - 1) * 100 * inverter;
455
- p.months.eq(0).transform('translate3d(' + (p.isH ? prevMonthTranslate : 0) + '%, ' + (p.isH ? 0 : prevMonthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
456
- p.months.eq(1).transform('translate3d(' + (p.isH ? currentMonthTranslate : 0) + '%, ' + (p.isH ? 0 : currentMonthTranslate) + '%, 0)').addClass('picker-calendar-month-current');
457
- p.months.eq(2).transform('translate3d(' + (p.isH ? nextMonthTranslate : 0) + '%, ' + (p.isH ? 0 : nextMonthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
458
- };
459
- p.nextMonth = function (transition) {
460
- if (typeof transition === 'undefined' || typeof transition === 'object') {
461
- transition = '';
462
- if (!p.params.animate) transition = 0;
463
- }
464
- var nextMonth = parseInt(p.months.eq(p.months.length - 1).attr('data-month'), 10);
465
- var nextYear = parseInt(p.months.eq(p.months.length - 1).attr('data-year'), 10);
466
- var nextDate = new Date(nextYear, nextMonth);
467
- var nextDateTime = nextDate.getTime();
468
- var transitionEndCallback = p.animating ? false : true;
469
- if (p.params.maxDate) {
470
- if (nextDateTime > new Date(p.params.maxDate).getTime()) {
471
- return p.resetMonth();
472
- }
473
- }
474
- p.monthsTranslate --;
475
- if (nextMonth === p.currentMonth) {
476
- var nextMonthTranslate = -(p.monthsTranslate) * 100 * inverter;
477
- var nextMonthHTML = $(p.monthHTML(nextDateTime, 'next')).transform('translate3d(' + (p.isH ? nextMonthTranslate : 0) + '%, ' + (p.isH ? 0 : nextMonthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
478
- p.wrapper.append(nextMonthHTML[0]);
479
- p.months = p.wrapper.find('.picker-calendar-month');
480
- if (p.params.onMonthAdd) {
481
- p.params.onMonthAdd(p, p.months.eq(p.months.length - 1)[0]);
482
- }
483
- }
484
- p.animating = true;
485
- p.onMonthChangeStart('next');
486
- var translate = (p.monthsTranslate * 100) * inverter;
487
-
488
- p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
489
- if (transitionEndCallback) {
490
- p.wrapper.transitionEnd(function () {
491
- p.onMonthChangeEnd('next');
492
- });
493
- }
494
- if (!p.params.animate) {
495
- p.onMonthChangeEnd('next');
496
- }
497
- };
498
- p.prevMonth = function (transition) {
499
- if (typeof transition === 'undefined' || typeof transition === 'object') {
500
- transition = '';
501
- if (!p.params.animate) transition = 0;
502
- }
503
- var prevMonth = parseInt(p.months.eq(0).attr('data-month'), 10);
504
- var prevYear = parseInt(p.months.eq(0).attr('data-year'), 10);
505
- var prevDate = new Date(prevYear, prevMonth + 1, -1);
506
- var prevDateTime = prevDate.getTime();
507
- var transitionEndCallback = p.animating ? false : true;
508
- if (p.params.minDate) {
509
- if (prevDateTime < new Date(p.params.minDate).getTime()) {
510
- return p.resetMonth();
511
- }
512
- }
513
- p.monthsTranslate ++;
514
- if (prevMonth === p.currentMonth) {
515
- var prevMonthTranslate = -(p.monthsTranslate) * 100 * inverter;
516
- var prevMonthHTML = $(p.monthHTML(prevDateTime, 'prev')).transform('translate3d(' + (p.isH ? prevMonthTranslate : 0) + '%, ' + (p.isH ? 0 : prevMonthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
517
- p.wrapper.prepend(prevMonthHTML[0]);
518
- p.months = p.wrapper.find('.picker-calendar-month');
519
- if (p.params.onMonthAdd) {
520
- p.params.onMonthAdd(p, p.months.eq(0)[0]);
521
- }
522
- }
523
- p.animating = true;
524
- p.onMonthChangeStart('prev');
525
- var translate = (p.monthsTranslate * 100) * inverter;
526
- p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
527
- if (transitionEndCallback) {
528
- p.wrapper.transitionEnd(function () {
529
- p.onMonthChangeEnd('prev');
530
- });
531
- }
532
- if (!p.params.animate) {
533
- p.onMonthChangeEnd('prev');
534
- }
535
- };
536
- p.resetMonth = function (transition) {
537
- if (typeof transition === 'undefined') transition = '';
538
- var translate = (p.monthsTranslate * 100) * inverter;
539
- p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? translate : 0) + '%, ' + (p.isH ? 0 : translate) + '%, 0)');
540
- };
541
- p.setYearMonth = function (year, month, transition) {
542
- if (typeof year === 'undefined') year = p.currentYear;
543
- if (typeof month === 'undefined') month = p.currentMonth;
544
- if (typeof transition === 'undefined' || typeof transition === 'object') {
545
- transition = '';
546
- if (!p.params.animate) transition = 0;
547
- }
548
- var targetDate;
549
- if (year < p.currentYear) {
550
- targetDate = new Date(year, month + 1, -1).getTime();
551
- }
552
- else {
553
- targetDate = new Date(year, month).getTime();
554
- }
555
- if (p.params.maxDate && targetDate > new Date(p.params.maxDate).getTime()) {
556
- return false;
557
- }
558
- if (p.params.minDate && targetDate < new Date(p.params.minDate).getTime()) {
559
- return false;
560
- }
561
- var currentDate = new Date(p.currentYear, p.currentMonth).getTime();
562
- var dir = targetDate > currentDate ? 'next' : 'prev';
563
- var newMonthHTML = p.monthHTML(new Date(year, month));
564
- p.monthsTranslate = p.monthsTranslate || 0;
565
- var prevTranslate = p.monthsTranslate;
566
- var monthTranslate, wrapperTranslate;
567
- var transitionEndCallback = p.animating ? false : true;
568
- if (targetDate > currentDate) {
569
- // To next
570
- p.monthsTranslate --;
571
- if (!p.animating) p.months.eq(p.months.length - 1).remove();
572
- p.wrapper.append(newMonthHTML);
573
- p.months = p.wrapper.find('.picker-calendar-month');
574
- monthTranslate = -(prevTranslate - 1) * 100 * inverter;
575
- p.months.eq(p.months.length - 1).transform('translate3d(' + (p.isH ? monthTranslate : 0) + '%, ' + (p.isH ? 0 : monthTranslate) + '%, 0)').addClass('picker-calendar-month-next');
576
- }
577
- else {
578
- // To prev
579
- p.monthsTranslate ++;
580
- if (!p.animating) p.months.eq(0).remove();
581
- p.wrapper.prepend(newMonthHTML);
582
- p.months = p.wrapper.find('.picker-calendar-month');
583
- monthTranslate = -(prevTranslate + 1) * 100 * inverter;
584
- p.months.eq(0).transform('translate3d(' + (p.isH ? monthTranslate : 0) + '%, ' + (p.isH ? 0 : monthTranslate) + '%, 0)').addClass('picker-calendar-month-prev');
585
- }
586
- if (p.params.onMonthAdd) {
587
- p.params.onMonthAdd(p, dir === 'next' ? p.months.eq(p.months.length - 1)[0] : p.months.eq(0)[0]);
588
- }
589
- p.animating = true;
590
- p.onMonthChangeStart(dir);
591
- wrapperTranslate = (p.monthsTranslate * 100) * inverter;
592
- p.wrapper.transition(transition).transform('translate3d(' + (p.isH ? wrapperTranslate : 0) + '%, ' + (p.isH ? 0 : wrapperTranslate) + '%, 0)');
593
- if (transitionEndCallback) {
594
- p.wrapper.transitionEnd(function () {
595
- p.onMonthChangeEnd(dir, true);
596
- });
597
- }
598
- if (!p.params.animate) {
599
- p.onMonthChangeEnd(dir);
600
- }
601
- };
602
- p.nextYear = function () {
603
- p.setYearMonth(p.currentYear + 1);
604
- };
605
- p.prevYear = function () {
606
- p.setYearMonth(p.currentYear - 1);
607
- };
608
-
609
-
610
- // HTML Layout
611
- p.layout = function () {
612
- var pickerHTML = '';
613
- var pickerClass = '';
614
- var i;
615
-
616
- var layoutDate = p.value && p.value.length ? p.value[0] : new Date().setHours(0,0,0,0);
617
- var prevMonthHTML = p.monthHTML(layoutDate, 'prev');
618
- var currentMonthHTML = p.monthHTML(layoutDate);
619
- var nextMonthHTML = p.monthHTML(layoutDate, 'next');
620
- var monthsHTML = '<div class="picker-calendar-months"><div class="picker-calendar-months-wrapper">' + (prevMonthHTML + currentMonthHTML + nextMonthHTML) + '</div></div>';
621
- // Week days header
622
- var weekHeaderHTML = '';
623
- if (p.params.weekHeader) {
624
- for (i = 0; i < 7; i++) {
625
- var weekDayIndex = (i + p.params.firstDay > 6) ? (i - 7 + p.params.firstDay) : (i + p.params.firstDay);
626
- var dayName = p.params.dayNamesShort[weekDayIndex];
627
- weekHeaderHTML += '<div class="picker-calendar-week-day ' + ((p.params.weekendDays.indexOf(weekDayIndex) >= 0) ? 'picker-calendar-week-day-weekend' : '') + '"> ' + dayName + '</div>';
628
-
629
- }
630
- weekHeaderHTML = '<div class="picker-calendar-week-days">' + weekHeaderHTML + '</div>';
631
- }
632
- pickerClass = 'picker-modal picker-calendar ' + (p.params.cssClass || '');
633
- var toolbarHTML = p.params.toolbar ? p.params.toolbarTemplate.replace(/{{closeText}}/g, p.params.toolbarCloseText) : '';
634
- if (p.params.toolbar) {
635
- toolbarHTML = p.params.toolbarTemplate
636
- .replace(/{{closeText}}/g, p.params.toolbarCloseText)
637
- .replace(/{{monthPicker}}/g, (p.params.monthPicker ? p.params.monthPickerTemplate : ''))
638
- .replace(/{{yearPicker}}/g, (p.params.yearPicker ? p.params.yearPickerTemplate : ''));
639
- }
640
-
641
- pickerHTML =
642
- '<div class="' + (pickerClass) + '">' +
643
- toolbarHTML +
644
- '<div class="picker-modal-inner">' +
645
- weekHeaderHTML +
646
- monthsHTML +
647
- '</div>' +
648
- '</div>';
649
-
650
-
651
- p.pickerHTML = pickerHTML;
652
- };
653
-
654
- // Input Events
655
- function openOnInput(e) {
656
- e.preventDefault();
657
- // 安卓微信webviewreadonly的input依然弹出软键盘问题修复
658
- if ($.device.isWeixin && $.device.android && p.params.inputReadOnly) {
659
- /*jshint validthis:true */
660
- this.focus();
661
- this.blur();
662
- }
663
- if (p.opened) return;
664
- p.open();
665
- if (p.params.scrollToInput) {
666
- var pageContent = p.input.parents('.content');
667
- if (pageContent.length === 0) return;
668
-
669
- var paddingTop = parseInt(pageContent.css('padding-top'), 10),
670
- paddingBottom = parseInt(pageContent.css('padding-bottom'), 10),
671
- pageHeight = pageContent[0].offsetHeight - paddingTop - p.container.height(),
672
- pageScrollHeight = pageContent[0].scrollHeight - paddingTop - p.container.height(),
673
- newPaddingBottom;
674
-
675
- var inputTop = p.input.offset().top - paddingTop + p.input[0].offsetHeight;
676
- if (inputTop > pageHeight) {
677
- var scrollTop = pageContent.scrollTop() + inputTop - pageHeight;
678
- if (scrollTop + pageHeight > pageScrollHeight) {
679
- newPaddingBottom = scrollTop + pageHeight - pageScrollHeight + paddingBottom;
680
- if (pageHeight === pageScrollHeight) {
681
- newPaddingBottom = p.container.height();
682
- }
683
- pageContent.css({'padding-bottom': (newPaddingBottom) + 'px'});
684
- }
685
- pageContent.scrollTop(scrollTop, 300);
686
- }
687
- }
688
- }
689
- function closeOnHTMLClick(e) {
690
- if (p.input && p.input.length > 0) {
691
- if (e.target !== p.input[0] && $(e.target).parents('.picker-modal').length === 0) p.close();
692
- }
693
- else {
694
- if ($(e.target).parents('.picker-modal').length === 0) p.close();
695
- }
696
- }
697
-
698
- if (p.params.input) {
699
- p.input = $(p.params.input);
700
- if (p.input.length > 0) {
701
- if (p.params.inputReadOnly) p.input.prop('readOnly', true);
702
- if (!p.inline) {
703
- p.input.on('click', openOnInput);
704
- }
705
- }
706
-
707
- }
708
-
709
- if (!p.inline) $('html').on('click', closeOnHTMLClick);
710
-
711
- // Open
712
- function onPickerClose() {
713
- p.opened = false;
714
- if (p.input && p.input.length > 0) p.input.parents('.content').css({'padding-bottom': ''});
715
- if (p.params.onClose) p.params.onClose(p);
716
-
717
- // Destroy events
718
- p.destroyCalendarEvents();
719
- }
720
-
721
- p.opened = false;
722
- p.open = function () {
723
- var updateValue = false;
724
- if (!p.opened) {
725
- // Set date value
726
- if (!p.value) {
727
- if (p.params.value) {
728
- p.value = p.params.value;
729
- updateValue = true;
730
- }
731
- }
732
-
733
- // Layout
734
- p.layout();
735
-
736
- // Append
737
- if (p.inline) {
738
- p.container = $(p.pickerHTML);
739
- p.container.addClass('picker-modal-inline');
740
- $(p.params.container).append(p.container);
741
- }
742
- else {
743
- p.container = $($.pickerModal(p.pickerHTML));
744
- $(p.container)
745
- .on('close', function () {
746
- onPickerClose();
747
- });
748
- }
749
-
750
- // Store calendar instance
751
- p.container[0].f7Calendar = p;
752
- p.wrapper = p.container.find('.picker-calendar-months-wrapper');
753
-
754
- // Months
755
- p.months = p.wrapper.find('.picker-calendar-month');
756
-
757
- // Update current month and year
758
- p.updateCurrentMonthYear();
759
-
760
- // Set initial translate
761
- p.monthsTranslate = 0;
762
- p.setMonthsTranslate();
763
-
764
- // Init events
765
- p.initCalendarEvents();
766
-
767
- // Update input value
768
- if (updateValue) p.updateValue();
769
-
770
- }
771
-
772
- // Set flag
773
- p.opened = true;
774
- p.initialized = true;
775
- if (p.params.onMonthAdd) {
776
- p.months.each(function () {
777
- p.params.onMonthAdd(p, this);
778
- });
779
- }
780
- if (p.params.onOpen) p.params.onOpen(p);
781
- };
782
-
783
- // Close
784
- p.close = function () {
785
- if (!p.opened || p.inline) return;
786
- $.closeModal(p.container);
787
- return;
788
- };
789
-
790
- // Destroy
791
- p.destroy = function () {
792
- p.close();
793
- if (p.params.input && p.input.length > 0) {
794
- p.input.off('click', openOnInput);
795
- }
796
- $('html').off('click', closeOnHTMLClick);
797
- };
798
-
799
- if (p.inline) {
800
- p.open();
801
- }
802
-
803
- return p;
804
- };
805
- $.fn.calendar = function (params) {
806
- return this.each(function() {
807
- var $this = $(this);
808
- if(!$this[0]) return;
809
- var p = {};
810
- if($this[0].tagName.toUpperCase() === "INPUT") {
811
- p.input = $this;
812
- } else {
813
- p.container = $this;
814
- }
815
- new Calendar($.extend(p, params));
816
- });
817
- };
818
-
819
- $.initCalendar = function(content) {
820
- var $content = content ? $(content) : $(document.body);
821
- $content.find("[data-toggle='date']").each(function() {
822
- $(this).calendar();
823
- });
824
- };
825
- }(Zepto);
826
-
827
- /*======================================================
828
- ************ Picker ************
829
- ======================================================*/
830
- /* jshint unused:false */
831
- /* jshint multistr:true */
832
- + function($) {
833
- "use strict";
834
- var Picker = function (params) {
835
- var p = this;
836
- var defaults = {
837
- updateValuesOnMomentum: false,
838
- updateValuesOnTouchmove: true,
839
- rotateEffect: false,
840
- momentumRatio: 7,
841
- freeMode: false,
842
- // Common settings
843
- scrollToInput: true,
844
- inputReadOnly: true,
845
- toolbar: true,
846
- toolbarCloseText: '确定',
847
- toolbarTemplate: '<header class="bar bar-nav">\
848
- <nav>\
849
- <div class="fr">\
850
- <button class="btn btn-link pull-right close-picker">确定</button>\
851
- </div>\
852
- <div class="fm">请选择</div>\
853
- </nav>\
854
- </header>',
855
- };
856
- params = params || {};
857
- for (var def in defaults) {
858
- if (typeof params[def] === 'undefined') {
859
- params[def] = defaults[def];
860
- }
861
- }
862
- p.params = params;
863
- p.cols = [];
864
- p.initialized = false;
865
-
866
- // Inline flag
867
- p.inline = p.params.container ? true : false;
868
-
869
- // 3D Transforms origin bug, only on safari
870
- var originBug = $.device.ios || (navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && navigator.userAgent.toLowerCase().indexOf('chrome') < 0) && !$.device.android;
871
-
872
- // Value
873
- p.setValue = function (arrValues, transition) {
874
- var valueIndex = 0;
875
- for (var i = 0; i < p.cols.length; i++) {
876
- if (p.cols[i] && !p.cols[i].divider) {
877
- p.cols[i].setValue(arrValues[valueIndex], transition);
878
- valueIndex++;
879
- }
880
- }
881
- };
882
- p.updateValue = function () {
883
- var newValue = [];
884
- var newDisplayValue = [];
885
- for (var i = 0; i < p.cols.length; i++) {
886
- if (!p.cols[i].divider) {
887
- newValue.push(p.cols[i].value);
888
- newDisplayValue.push(p.cols[i].displayValue);
889
- }
890
- }
891
- if (newValue.indexOf(undefined) >= 0) {
892
- return;
893
- }
894
- p.value = newValue;
895
- p.displayValue = newDisplayValue;
896
- if (p.params.onChange) {
897
- p.params.onChange(p, p.value, p.displayValue);
898
- }
899
- if (p.input && p.input.length > 0) {
900
- $(p.input).val(p.params.formatValue ? p.params.formatValue(p, p.value, p.displayValue) : p.value.join(' '));
901
- $(p.input).trigger('change');
902
- }
903
- };
904
-
905
- // Columns Handlers
906
- p.initPickerCol = function (colElement, updateItems) {
907
- var colContainer = $(colElement);
908
- var colIndex = colContainer.index();
909
- var col = p.cols[colIndex];
910
- if (col.divider) return;
911
- col.container = colContainer;
912
- col.wrapper = col.container.find('.picker-items-col-wrapper');
913
- col.items = col.wrapper.find('.picker-item');
914
-
915
- var i, j;
916
- var wrapperHeight, itemHeight, itemsHeight, minTranslate, maxTranslate;
917
- col.replaceValues = function (values, displayValues) {
918
- col.destroyEvents();
919
- col.values = values;
920
- col.displayValues = displayValues;
921
- var newItemsHTML = p.columnHTML(col, true);
922
- col.wrapper.html(newItemsHTML);
923
- col.items = col.wrapper.find('.picker-item');
924
- col.calcSize();
925
- col.setValue(col.values[0], 0, true);
926
- col.initEvents();
927
- };
928
- col.calcSize = function () {
929
- if (p.params.rotateEffect) {
930
- col.container.removeClass('picker-items-col-absolute');
931
- if (!col.width) col.container.css({width:''});
932
- }
933
- var colWidth, colHeight;
934
- colWidth = 0;
935
- colHeight = col.container[0].offsetHeight;
936
- wrapperHeight = col.wrapper[0].offsetHeight;
937
- itemHeight = col.items[0].offsetHeight;
938
- itemsHeight = itemHeight * col.items.length;
939
- minTranslate = colHeight / 2 - itemsHeight + itemHeight / 2;
940
- maxTranslate = colHeight / 2 - itemHeight / 2;
941
- if (col.width) {
942
- colWidth = col.width;
943
- if (parseInt(colWidth, 10) === colWidth) colWidth = colWidth + 'px';
944
- col.container.css({width: colWidth});
945
- }
946
- if (p.params.rotateEffect) {
947
- if (!col.width) {
948
- col.items.each(function () {
949
- var item = $(this);
950
- item.css({width:'auto'});
951
- colWidth = Math.max(colWidth, item[0].offsetWidth);
952
- item.css({width:''});
953
- });
954
- col.container.css({width: (colWidth + 2) + 'px'});
955
- }
956
- col.container.addClass('picker-items-col-absolute');
957
- }
958
- };
959
- col.calcSize();
960
-
961
- col.wrapper.transform('translate3d(0,' + maxTranslate + 'px,0)').transition(0);
962
-
963
-
964
- var activeIndex = 0;
965
- var animationFrameId;
966
-
967
- // Set Value Function
968
- col.setValue = function (newValue, transition, valueCallbacks) {
969
- if (typeof transition === 'undefined') transition = '';
970
- var newActiveIndex = col.wrapper.find('.picker-item[data-picker-value="' + newValue + '"]').index();
971
- if(typeof newActiveIndex === 'undefined' || newActiveIndex === -1) {
972
- return;
973
- }
974
- var newTranslate = -newActiveIndex * itemHeight + maxTranslate;
975
- // Update wrapper
976
- col.wrapper.transition(transition);
977
- col.wrapper.transform('translate3d(0,' + (newTranslate) + 'px,0)');
978
-
979
- // Watch items
980
- if (p.params.updateValuesOnMomentum && col.activeIndex && col.activeIndex !== newActiveIndex ) {
981
- $.cancelAnimationFrame(animationFrameId);
982
- col.wrapper.transitionEnd(function(){
983
- $.cancelAnimationFrame(animationFrameId);
984
- });
985
- updateDuringScroll();
986
- }
987
-
988
- // Update items
989
- col.updateItems(newActiveIndex, newTranslate, transition, valueCallbacks);
990
- };
991
-
992
- col.updateItems = function (activeIndex, translate, transition, valueCallbacks) {
993
- if (typeof translate === 'undefined') {
994
- translate = $.getTranslate(col.wrapper[0], 'y');
995
- }
996
- if(typeof activeIndex === 'undefined') activeIndex = -Math.round((translate - maxTranslate)/itemHeight);
997
- if (activeIndex < 0) activeIndex = 0;
998
- if (activeIndex >= col.items.length) activeIndex = col.items.length - 1;
999
- var previousActiveIndex = col.activeIndex;
1000
- col.activeIndex = activeIndex;
1001
- /*
1002
- col.wrapper.find('.picker-selected, .picker-after-selected, .picker-before-selected').removeClass('picker-selected picker-after-selected picker-before-selected');
1003
-
1004
- col.items.transition(transition);
1005
- var selectedItem = col.items.eq(activeIndex).addClass('picker-selected').transform('');
1006
- var prevItems = selectedItem.prevAll().addClass('picker-before-selected');
1007
- var nextItems = selectedItem.nextAll().addClass('picker-after-selected');
1008
- */
1009
- //去掉 .picker-after-selected, .picker-before-selected 以提高性能
1010
- col.wrapper.find('.picker-selected').removeClass('picker-selected');
1011
- if (p.params.rotateEffect) {
1012
- col.items.transition(transition);
1013
- }
1014
- var selectedItem = col.items.eq(activeIndex).addClass('picker-selected').transform('');
1015
-
1016
- if (valueCallbacks || typeof valueCallbacks === 'undefined') {
1017
- // Update values
1018
- col.value = selectedItem.attr('data-picker-value');
1019
- col.displayValue = col.displayValues ? col.displayValues[activeIndex] : col.value;
1020
- // On change callback
1021
- if (previousActiveIndex !== activeIndex) {
1022
- if (col.onChange) {
1023
- col.onChange(p, col.value, col.displayValue);
1024
- }
1025
- p.updateValue();
1026
- }
1027
- }
1028
-
1029
- // Set 3D rotate effect
1030
- if (!p.params.rotateEffect) {
1031
- return;
1032
- }
1033
- var percentage = (translate - (Math.floor((translate - maxTranslate)/itemHeight) * itemHeight + maxTranslate)) / itemHeight;
1034
-
1035
- col.items.each(function () {
1036
- var item = $(this);
1037
- var itemOffsetTop = item.index() * itemHeight;
1038
- var translateOffset = maxTranslate - translate;
1039
- var itemOffset = itemOffsetTop - translateOffset;
1040
- var percentage = itemOffset / itemHeight;
1041
-
1042
- var itemsFit = Math.ceil(col.height / itemHeight / 2) + 1;
1043
-
1044
- var angle = (-18*percentage);
1045
- if (angle > 180) angle = 180;
1046
- if (angle < -180) angle = -180;
1047
- // Far class
1048
- if (Math.abs(percentage) > itemsFit) item.addClass('picker-item-far');
1049
- else item.removeClass('picker-item-far');
1050
- // Set transform
1051
- item.transform('translate3d(0, ' + (-translate + maxTranslate) + 'px, ' + (originBug ? -110 : 0) + 'px) rotateX(' + angle + 'deg)');
1052
- });
1053
- };
1054
-
1055
- function updateDuringScroll() {
1056
- animationFrameId = $.requestAnimationFrame(function () {
1057
- col.updateItems(undefined, undefined, 0);
1058
- updateDuringScroll();
1059
- });
1060
- }
1061
-
1062
- // Update items on init
1063
- if (updateItems) col.updateItems(0, maxTranslate, 0);
1064
-
1065
- var allowItemClick = true;
1066
- var isTouched, isMoved, touchStartY, touchCurrentY, touchStartTime, touchEndTime, startTranslate, returnTo, currentTranslate, prevTranslate, velocityTranslate, velocityTime;
1067
- function handleTouchStart (e) {
1068
- if (isMoved || isTouched) return;
1069
- e.preventDefault();
1070
- isTouched = true;
1071
- touchStartY = touchCurrentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
1072
- touchStartTime = (new Date()).getTime();
1073
-
1074
- allowItemClick = true;
1075
- startTranslate = currentTranslate = $.getTranslate(col.wrapper[0], 'y');
1076
- }
1077
- function handleTouchMove (e) {
1078
- if (!isTouched) return;
1079
- e.preventDefault();
1080
- allowItemClick = false;
1081
- touchCurrentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
1082
- if (!isMoved) {
1083
- // First move
1084
- $.cancelAnimationFrame(animationFrameId);
1085
- isMoved = true;
1086
- startTranslate = currentTranslate = $.getTranslate(col.wrapper[0], 'y');
1087
- col.wrapper.transition(0);
1088
- }
1089
- e.preventDefault();
1090
-
1091
- var diff = touchCurrentY - touchStartY;
1092
- currentTranslate = startTranslate + diff;
1093
- returnTo = undefined;
1094
-
1095
- // Normalize translate
1096
- if (currentTranslate < minTranslate) {
1097
- currentTranslate = minTranslate - Math.pow(minTranslate - currentTranslate, 0.8);
1098
- returnTo = 'min';
1099
- }
1100
- if (currentTranslate > maxTranslate) {
1101
- currentTranslate = maxTranslate + Math.pow(currentTranslate - maxTranslate, 0.8);
1102
- returnTo = 'max';
1103
- }
1104
- // Transform wrapper
1105
- col.wrapper.transform('translate3d(0,' + currentTranslate + 'px,0)');
1106
-
1107
- // Update items
1108
- col.updateItems(undefined, currentTranslate, 0, p.params.updateValuesOnTouchmove);
1109
-
1110
- // Calc velocity
1111
- velocityTranslate = currentTranslate - prevTranslate || currentTranslate;
1112
- velocityTime = (new Date()).getTime();
1113
- prevTranslate = currentTranslate;
1114
- }
1115
- function handleTouchEnd (e) {
1116
- if (!isTouched || !isMoved) {
1117
- isTouched = isMoved = false;
1118
- return;
1119
- }
1120
- isTouched = isMoved = false;
1121
- col.wrapper.transition('');
1122
- if (returnTo) {
1123
- if (returnTo === 'min') {
1124
- col.wrapper.transform('translate3d(0,' + minTranslate + 'px,0)');
1125
- }
1126
- else col.wrapper.transform('translate3d(0,' + maxTranslate + 'px,0)');
1127
- }
1128
- touchEndTime = new Date().getTime();
1129
- var velocity, newTranslate;
1130
- if (touchEndTime - touchStartTime > 300) {
1131
- newTranslate = currentTranslate;
1132
- }
1133
- else {
1134
- velocity = Math.abs(velocityTranslate / (touchEndTime - velocityTime));
1135
- newTranslate = currentTranslate + velocityTranslate * p.params.momentumRatio;
1136
- }
1137
-
1138
- newTranslate = Math.max(Math.min(newTranslate, maxTranslate), minTranslate);
1139
-
1140
- // Active Index
1141
- var activeIndex = -Math.floor((newTranslate - maxTranslate)/itemHeight);
1142
-
1143
- // Normalize translate
1144
- if (!p.params.freeMode) newTranslate = -activeIndex * itemHeight + maxTranslate;
1145
-
1146
- // Transform wrapper
1147
- col.wrapper.transform('translate3d(0,' + (parseInt(newTranslate,10)) + 'px,0)');
1148
-
1149
- // Update items
1150
- col.updateItems(activeIndex, newTranslate, '', true);
1151
-
1152
- // Watch items
1153
- if (p.params.updateValuesOnMomentum) {
1154
- updateDuringScroll();
1155
- col.wrapper.transitionEnd(function(){
1156
- $.cancelAnimationFrame(animationFrameId);
1157
- });
1158
- }
1159
-
1160
- // Allow click
1161
- setTimeout(function () {
1162
- allowItemClick = true;
1163
- }, 100);
1164
- }
1165
-
1166
- function handleClick(e) {
1167
- if (!allowItemClick) return;
1168
- $.cancelAnimationFrame(animationFrameId);
1169
- /*jshint validthis:true */
1170
- var value = $(this).attr('data-picker-value');
1171
- col.setValue(value);
1172
- }
1173
-
1174
- col.initEvents = function (detach) {
1175
- var method = detach ? 'off' : 'on';
1176
- col.container[method]($.touchEvents.start, handleTouchStart);
1177
- col.container[method]($.touchEvents.move, handleTouchMove);
1178
- col.container[method]($.touchEvents.end, handleTouchEnd);
1179
- col.items[method]('click', handleClick);
1180
- };
1181
- col.destroyEvents = function () {
1182
- col.initEvents(true);
1183
- };
1184
-
1185
- col.container[0].f7DestroyPickerCol = function () {
1186
- col.destroyEvents();
1187
- };
1188
-
1189
- col.initEvents();
1190
-
1191
- };
1192
- p.destroyPickerCol = function (colContainer) {
1193
- colContainer = $(colContainer);
1194
- if ('f7DestroyPickerCol' in colContainer[0]) colContainer[0].f7DestroyPickerCol();
1195
- };
1196
- // Resize cols
1197
- function resizeCols() {
1198
- if (!p.opened) return;
1199
- for (var i = 0; i < p.cols.length; i++) {
1200
- if (!p.cols[i].divider) {
1201
- p.cols[i].calcSize();
1202
- p.cols[i].setValue(p.cols[i].value, 0, false);
1203
- }
1204
- }
1205
- }
1206
- $(window).on('resize', resizeCols);
1207
-
1208
- // HTML Layout
1209
- p.columnHTML = function (col, onlyItems) {
1210
- var columnItemsHTML = '';
1211
- var columnHTML = '';
1212
- if (col.divider) {
1213
- columnHTML += '<div class="picker-items-col picker-items-col-divider ' + (col.textAlign ? 'picker-items-col-' + col.textAlign : '') + ' ' + (col.cssClass || '') + '">' + col.content + '</div>';
1214
- }
1215
- else {
1216
- for (var j = 0; j < col.values.length; j++) {
1217
- columnItemsHTML += '<div class="picker-item" data-picker-value="' + col.values[j] + '">' + (col.displayValues ? col.displayValues[j] : col.values[j]) + '</div>';
1218
- }
1219
-
1220
- columnHTML += '<div class="picker-items-col ' + (col.textAlign ? 'picker-items-col-' + col.textAlign : '') + ' ' + (col.cssClass || '') + '"><div class="picker-items-col-wrapper">' + columnItemsHTML + '</div></div>';
1221
- }
1222
- return onlyItems ? columnItemsHTML : columnHTML;
1223
- };
1224
- p.layout = function () {
1225
- var pickerHTML = '';
1226
- var pickerClass = '';
1227
- var i;
1228
- p.cols = [];
1229
- var colsHTML = '';
1230
- for (i = 0; i < p.params.cols.length; i++) {
1231
- var col = p.params.cols[i];
1232
- colsHTML += p.columnHTML(p.params.cols[i]);
1233
- p.cols.push(col);
1234
- }
1235
- pickerClass = 'picker-modal picker-columns ' + (p.params.cssClass || '') + (p.params.rotateEffect ? ' picker-3d' : '');
1236
- pickerHTML =
1237
- '<div class="' + (pickerClass) + '">' +
1238
- (p.params.toolbar ? p.params.toolbarTemplate.replace(/{{closeText}}/g, p.params.toolbarCloseText) : '') +
1239
- '<div class="picker-modal-inner picker-items">' +
1240
- colsHTML +
1241
- '<div class="picker-center-highlight"></div>' +
1242
- '</div>' +
1243
- '</div>';
1244
-
1245
- p.pickerHTML = pickerHTML;
1246
- };
1247
-
1248
- // Input Events
1249
- function openOnInput(e) {
1250
- e.preventDefault();
1251
- // 安卓微信webviewreadonly的input依然弹出软键盘问题修复
1252
- if ($.device.isWeixin && $.device.android && p.params.inputReadOnly) {
1253
- /*jshint validthis:true */
1254
- this.focus();
1255
- this.blur();
1256
- }
1257
- if (p.opened) return;
1258
- p.open();
1259
- if (p.params.scrollToInput) {
1260
- var pageContent = p.input.parents('.content');
1261
- if (pageContent.length === 0) return;
1262
-
1263
- var paddingTop = parseInt(pageContent.css('padding-top'), 10),
1264
- paddingBottom = parseInt(pageContent.css('padding-bottom'), 10),
1265
- pageHeight = pageContent[0].offsetHeight - paddingTop - p.container.height(),
1266
- pageScrollHeight = pageContent[0].scrollHeight - paddingTop - p.container.height(),
1267
- newPaddingBottom;
1268
- var inputTop = p.input.offset().top - paddingTop + p.input[0].offsetHeight;
1269
- if (inputTop > pageHeight) {
1270
- var scrollTop = pageContent.scrollTop() + inputTop - pageHeight;
1271
- if (scrollTop + pageHeight > pageScrollHeight) {
1272
- newPaddingBottom = scrollTop + pageHeight - pageScrollHeight + paddingBottom;
1273
- if (pageHeight === pageScrollHeight) {
1274
- newPaddingBottom = p.container.height();
1275
- }
1276
- pageContent.css({'padding-bottom': (newPaddingBottom) + 'px'});
1277
- }
1278
- pageContent.scrollTop(scrollTop, 300);
1279
- }
1280
- }
1281
- }
1282
- function closeOnHTMLClick(e) {
1283
- if (!p.opened) return;
1284
- if (p.input && p.input.length > 0) {
1285
- if (e.target !== p.input[0] && $(e.target).parents('.picker-modal').length === 0) p.close();
1286
- }
1287
- else {
1288
- if ($(e.target).parents('.picker-modal').length === 0) p.close();
1289
- }
1290
- }
1291
-
1292
- if (p.params.input) {
1293
- p.input = $(p.params.input);
1294
- if (p.input.length > 0) {
1295
- if (p.params.inputReadOnly) p.input.prop('readOnly', true);
1296
- if (!p.inline) {
1297
- p.input.on('click', openOnInput);
1298
- }
1299
- }
1300
- }
1301
-
1302
- if (!p.inline) $('html').on('click', closeOnHTMLClick);
1303
-
1304
- // Open
1305
- function onPickerClose() {
1306
- p.opened = false;
1307
- if (p.input && p.input.length > 0) p.input.parents('.content').css({'padding-bottom': ''});
1308
- if (p.params.onClose) p.params.onClose(p);
1309
-
1310
- // Destroy events
1311
- p.container.find('.picker-items-col').each(function () {
1312
- p.destroyPickerCol(this);
1313
- });
1314
- }
1315
-
1316
- p.opened = false;
1317
- p.open = function () {
1318
- if (!p.opened) {
1319
-
1320
- // Layout
1321
- p.layout();
1322
-
1323
- // Append
1324
- if (p.inline) {
1325
- p.container = $(p.pickerHTML);
1326
- p.container.addClass('picker-modal-inline');
1327
- $(p.params.container).append(p.container);
1328
- p.opened = true;
1329
- }
1330
- else {
1331
- p.container = $($.pickerModal(p.pickerHTML));
1332
- $(p.container)
1333
- .one('opened', function() {
1334
- p.opened = true;
1335
- })
1336
- .on('close', function () {
1337
- onPickerClose();
1338
- });
1339
- }
1340
-
1341
- // Store picker instance
1342
- p.container[0].f7Picker = p;
1343
-
1344
- // Init Events
1345
- p.container.find('.picker-items-col').each(function () {
1346
- var updateItems = true;
1347
- if ((!p.initialized && p.params.value) || (p.initialized && p.value)) updateItems = false;
1348
- p.initPickerCol(this, updateItems);
1349
- });
1350
-
1351
- // Set value
1352
- if (!p.initialized) {
1353
- if (p.params.value) {
1354
- p.setValue(p.params.value, 0);
1355
- }
1356
- }
1357
- else {
1358
- if (p.value) p.setValue(p.value, 0);
1359
- }
1360
- }
1361
-
1362
- // Set flag
1363
- p.initialized = true;
1364
-
1365
- if (p.params.onOpen) p.params.onOpen(p);
1366
- };
1367
-
1368
- // Close
1369
- p.close = function () {
1370
- if (!p.opened || p.inline) return;
1371
- $.closeModal(p.container);
1372
- return;
1373
- };
1374
-
1375
- // Destroy
1376
- p.destroy = function () {
1377
- p.close();
1378
- if (p.params.input && p.input.length > 0) {
1379
- p.input.off('click', openOnInput);
1380
- }
1381
- $('html').off('click', closeOnHTMLClick);
1382
- $(window).off('resize', resizeCols);
1383
- };
1384
-
1385
- if (p.inline) {
1386
- p.open();
1387
- }
1388
-
1389
- return p;
1390
- };
1391
-
1392
- $(document).on("click", ".close-picker", function() {
1393
- var pickerToClose = $('.picker-modal.modal-in');
1394
- $.closeModal(pickerToClose);
1395
- });
1396
-
1397
- $.fn.picker = function(params) {
1398
- var args = arguments;
1399
- return this.each(function() {
1400
- if(!this) return;
1401
- var $this = $(this);
1402
-
1403
- var picker = $this.data("picker");
1404
- if(!picker) {
1405
- var p = $.extend({
1406
- input: this,
1407
- value: $this.val() ? $this.val().split(' ') : ''
1408
- }, params);
1409
- picker = new Picker(p);
1410
- $this.data("picker", picker);
1411
- }
1412
- if(typeof params === typeof "a") {
1413
- picker[params].apply(picker, Array.prototype.slice.call(args, 1));
1414
- }
1415
- });
1416
- };
1417
- }(Zepto);