rmails 0.1.1

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 (332) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +167 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.markdown +9 -0
  7. data/Rakefile +31 -0
  8. data/Rakefile1 +9 -0
  9. data/Vagrantfile +51 -0
  10. data/app/assets/images/arrow_bottom.gif +0 -0
  11. data/app/assets/images/arrow_right.gif +0 -0
  12. data/app/assets/images/at-sign.png +0 -0
  13. data/app/assets/images/checkerboard.gif +0 -0
  14. data/app/assets/images/glyphicons-halflings-white.png +0 -0
  15. data/app/assets/images/glyphicons-halflings.png +0 -0
  16. data/app/assets/images/icon_draft.gif +0 -0
  17. data/app/assets/images/icon_layout.gif +0 -0
  18. data/app/assets/images/icon_move.gif +0 -0
  19. data/app/assets/images/icon_regular.gif +0 -0
  20. data/app/assets/images/icon_snippet.gif +0 -0
  21. data/app/assets/images/nav_arrow.png +0 -0
  22. data/app/assets/images/x.png +0 -0
  23. data/app/assets/javascripts/application.coffee.erb +27 -0
  24. data/app/assets/javascripts/canjs/can.construct.proxy.js +60 -0
  25. data/app/assets/javascripts/canjs/can.construct.super.js +44 -0
  26. data/app/assets/javascripts/canjs/can.control.plugin.js +245 -0
  27. data/app/assets/javascripts/canjs/can.control.view.js +88 -0
  28. data/app/assets/javascripts/canjs/can.dojo.js +3669 -0
  29. data/app/assets/javascripts/canjs/can.dojo.min.js +66 -0
  30. data/app/assets/javascripts/canjs/can.fixture.js +1020 -0
  31. data/app/assets/javascripts/canjs/can.jquery.js +2995 -0
  32. data/app/assets/javascripts/canjs/can.jquery.min.js +52 -0
  33. data/app/assets/javascripts/canjs/can.mootools.js +3462 -0
  34. data/app/assets/javascripts/canjs/can.mootools.min.js +63 -0
  35. data/app/assets/javascripts/canjs/can.observe.attributes.js +293 -0
  36. data/app/assets/javascripts/canjs/can.observe.backup.js +368 -0
  37. data/app/assets/javascripts/canjs/can.observe.delegate.js +359 -0
  38. data/app/assets/javascripts/canjs/can.observe.setter.js +58 -0
  39. data/app/assets/javascripts/canjs/can.observe.validations.js +374 -0
  40. data/app/assets/javascripts/canjs/can.view.modifiers.js +292 -0
  41. data/app/assets/javascripts/canjs/can.yui.js +3530 -0
  42. data/app/assets/javascripts/canjs/can.yui.min.js +65 -0
  43. data/app/assets/javascripts/canjs/can.zepto.js +3426 -0
  44. data/app/assets/javascripts/canjs/can.zepto.min.js +62 -0
  45. data/app/assets/javascripts/controls/admins.coffee.erb +105 -0
  46. data/app/assets/javascripts/controls/aliases.coffee.erb +91 -0
  47. data/app/assets/javascripts/controls/domains.coffee.erb +115 -0
  48. data/app/assets/javascripts/controls/settings.coffee.erb +47 -0
  49. data/app/assets/javascripts/controls/users.coffee.erb +94 -0
  50. data/app/assets/javascripts/lib/facebox.js +311 -0
  51. data/app/assets/javascripts/lib/html5.js +2 -0
  52. data/app/assets/javascripts/lib/jquery.js +9301 -0
  53. data/app/assets/javascripts/lib/jquery_formparams.js +108 -0
  54. data/app/assets/javascripts/lib/jquery_input_hint.js +20 -0
  55. data/app/assets/javascripts/lib/jquery_paginate.js +120 -0
  56. data/app/assets/javascripts/lib/jquery_ui_custom.js +6 -0
  57. data/app/assets/javascripts/lib/json2.js +487 -0
  58. data/app/assets/javascripts/lib/utils.coffee.erb +48 -0
  59. data/app/assets/javascripts/models/admin.coffee.erb +42 -0
  60. data/app/assets/javascripts/models/alias.coffee.erb +28 -0
  61. data/app/assets/javascripts/models/domain.coffee.erb +39 -0
  62. data/app/assets/javascripts/models/property.coffee.erb +18 -0
  63. data/app/assets/javascripts/models/user.coffee.erb +29 -0
  64. data/app/assets/stylesheets/application.sass +156 -0
  65. data/app/assets/stylesheets/base.css.sass +243 -0
  66. data/app/assets/stylesheets/facebox.css +80 -0
  67. data/app/assets/stylesheets/lib/bootstrap.css +9 -0
  68. data/app/assets/stylesheets/twitter/bootstrap-responsive.scss +1 -0
  69. data/app/assets/stylesheets/twitter/bootstrap.scss +63 -0
  70. data/app/assets/stylesheets/twitter/bootstrap/_accordion.scss +34 -0
  71. data/app/assets/stylesheets/twitter/bootstrap/_alerts.scss +79 -0
  72. data/app/assets/stylesheets/twitter/bootstrap/_breadcrumbs.scss +24 -0
  73. data/app/assets/stylesheets/twitter/bootstrap/_button-groups.scss +229 -0
  74. data/app/assets/stylesheets/twitter/bootstrap/_buttons.scss +228 -0
  75. data/app/assets/stylesheets/twitter/bootstrap/_carousel.scss +158 -0
  76. data/app/assets/stylesheets/twitter/bootstrap/_close.scss +32 -0
  77. data/app/assets/stylesheets/twitter/bootstrap/_code.scss +61 -0
  78. data/app/assets/stylesheets/twitter/bootstrap/_component-animations.scss +22 -0
  79. data/app/assets/stylesheets/twitter/bootstrap/_dropdowns.scss +237 -0
  80. data/app/assets/stylesheets/twitter/bootstrap/_forms.scss +689 -0
  81. data/app/assets/stylesheets/twitter/bootstrap/_grid.scss +21 -0
  82. data/app/assets/stylesheets/twitter/bootstrap/_hero-unit.scss +25 -0
  83. data/app/assets/stylesheets/twitter/bootstrap/_labels-badges.scss +83 -0
  84. data/app/assets/stylesheets/twitter/bootstrap/_layouts.scss +16 -0
  85. data/app/assets/stylesheets/twitter/bootstrap/_media.scss +55 -0
  86. data/app/assets/stylesheets/twitter/bootstrap/_mixins.scss +690 -0
  87. data/app/assets/stylesheets/twitter/bootstrap/_modals.scss +95 -0
  88. data/app/assets/stylesheets/twitter/bootstrap/_navbar.scss +497 -0
  89. data/app/assets/stylesheets/twitter/bootstrap/_navs.scss +409 -0
  90. data/app/assets/stylesheets/twitter/bootstrap/_pager.scss +43 -0
  91. data/app/assets/stylesheets/twitter/bootstrap/_pagination.scss +123 -0
  92. data/app/assets/stylesheets/twitter/bootstrap/_popovers.scss +133 -0
  93. data/app/assets/stylesheets/twitter/bootstrap/_progress-bars.scss +122 -0
  94. data/app/assets/stylesheets/twitter/bootstrap/_reset.scss +216 -0
  95. data/app/assets/stylesheets/twitter/bootstrap/_responsive-1200px-min.scss +28 -0
  96. data/app/assets/stylesheets/twitter/bootstrap/_responsive-767px-max.scss +193 -0
  97. data/app/assets/stylesheets/twitter/bootstrap/_responsive-768px-979px.scss +19 -0
  98. data/app/assets/stylesheets/twitter/bootstrap/_responsive-navbar.scss +189 -0
  99. data/app/assets/stylesheets/twitter/bootstrap/_responsive-utilities.scss +74 -0
  100. data/app/assets/stylesheets/twitter/bootstrap/_scaffolding.scss +53 -0
  101. data/app/assets/stylesheets/twitter/bootstrap/_sprites.scss +197 -0
  102. data/app/assets/stylesheets/twitter/bootstrap/_tables.scss +235 -0
  103. data/app/assets/stylesheets/twitter/bootstrap/_thumbnails.scss +53 -0
  104. data/app/assets/stylesheets/twitter/bootstrap/_tooltip.scss +70 -0
  105. data/app/assets/stylesheets/twitter/bootstrap/_type.scss +247 -0
  106. data/app/assets/stylesheets/twitter/bootstrap/_utilities.scss +45 -0
  107. data/app/assets/stylesheets/twitter/bootstrap/_variables.scss +301 -0
  108. data/app/assets/stylesheets/twitter/bootstrap/_wells.scss +29 -0
  109. data/app/assets/stylesheets/twitter/bootstrap/responsive.scss +48 -0
  110. data/app/controllers/admin_users_controller.rb +62 -0
  111. data/app/controllers/aliases_controller.rb +35 -0
  112. data/app/controllers/application_controller.rb +20 -0
  113. data/app/controllers/domains_controller.rb +48 -0
  114. data/app/controllers/server_controller.rb +28 -0
  115. data/app/controllers/users_controller.rb +35 -0
  116. data/app/helpers/admin_users_helper.rb +11 -0
  117. data/app/helpers/application_helper.rb +2 -0
  118. data/app/helpers/domains_helper.rb +25 -0
  119. data/app/helpers/server_helper.rb +30 -0
  120. data/app/mailers/.gitkeep +0 -0
  121. data/app/models/.gitkeep +0 -0
  122. data/app/models/admin_user.rb +54 -0
  123. data/app/models/certificate_manager.rb +46 -0
  124. data/app/models/property.rb +103 -0
  125. data/app/models/property/awstats.rb +15 -0
  126. data/app/models/property/dovecot.rb +61 -0
  127. data/app/models/property/dspam.rb +45 -0
  128. data/app/models/property/nginx.rb +47 -0
  129. data/app/models/property/postfix.rb +64 -0
  130. data/app/models/property_value_validator.rb +41 -0
  131. data/app/models/system_manager.rb +88 -0
  132. data/app/models/virtual_alias.rb +13 -0
  133. data/app/models/virtual_domain.rb +15 -0
  134. data/app/models/virtual_user.rb +51 -0
  135. data/app/views/admin_users/_form.html.haml +21 -0
  136. data/app/views/admin_users/first.html.haml +12 -0
  137. data/app/views/admin_users/index.html.haml +61 -0
  138. data/app/views/aliases/_form.html.haml +11 -0
  139. data/app/views/aliases/_list.html.haml +0 -0
  140. data/app/views/devise/confirmations/new.html.haml +9 -0
  141. data/app/views/devise/mailer/confirmation_instructions.html.haml +4 -0
  142. data/app/views/devise/mailer/reset_password_instructions.html.haml +6 -0
  143. data/app/views/devise/mailer/unlock_instructions.html.haml +5 -0
  144. data/app/views/devise/passwords/edit.html.haml +14 -0
  145. data/app/views/devise/passwords/new.html.haml +12 -0
  146. data/app/views/devise/registrations/edit.html.haml +18 -0
  147. data/app/views/devise/registrations/new.html.haml +10 -0
  148. data/app/views/devise/sessions/new.html.haml +16 -0
  149. data/app/views/devise/shared/_links.haml +17 -0
  150. data/app/views/devise/unlocks/new.html.haml +11 -0
  151. data/app/views/domains/_fields.html.haml +0 -0
  152. data/app/views/domains/_form.html.haml +7 -0
  153. data/app/views/domains/index.html.haml +133 -0
  154. data/app/views/domains/show.html.haml +1 -0
  155. data/app/views/layouts/_nav.html.haml +3 -0
  156. data/app/views/layouts/application.html.haml +29 -0
  157. data/app/views/server/_certificates.html.haml +10 -0
  158. data/app/views/server/_dovecot.html.haml +27 -0
  159. data/app/views/server/_dspam.html.haml +9 -0
  160. data/app/views/server/_postfix_info.html.haml +5 -0
  161. data/app/views/server/_postfix_test.html.haml +5 -0
  162. data/app/views/server/_status.html.haml +11 -0
  163. data/app/views/server/index.html.haml +36 -0
  164. data/app/views/users/_form.html.haml +11 -0
  165. data/app/views/users/_list.html.haml +0 -0
  166. data/bin/rmails +43 -0
  167. data/config.ru +4 -0
  168. data/config/application.rb +62 -0
  169. data/config/boot.rb +6 -0
  170. data/config/environment.rb +5 -0
  171. data/config/environments/development.rb +37 -0
  172. data/config/environments/production.rb +67 -0
  173. data/config/environments/test.rb +37 -0
  174. data/config/initializers/backtrace_silencers.rb +7 -0
  175. data/config/initializers/devise.rb +240 -0
  176. data/config/initializers/devise_encryptable.rb +37 -0
  177. data/config/initializers/devise_models.rb +86 -0
  178. data/config/initializers/inflections.rb +15 -0
  179. data/config/initializers/mime_types.rb +5 -0
  180. data/config/initializers/secret_token.rb +7 -0
  181. data/config/initializers/session_store.rb +8 -0
  182. data/config/initializers/simple_form.rb +142 -0
  183. data/config/initializers/simple_form_bootstrap.rb +45 -0
  184. data/config/initializers/wrap_parameters.rb +14 -0
  185. data/config/locales/cz.yml +45 -0
  186. data/config/locales/devise.cz.yml +47 -0
  187. data/config/locales/devise.en.yml +60 -0
  188. data/config/locales/en.yml +5 -0
  189. data/config/locales/server/cz.yml +14 -0
  190. data/config/locales/server/en.yml +7 -0
  191. data/config/locales/server/help/dovecot/cz.yml +21 -0
  192. data/config/locales/server/help/dovecot/en.yml +18 -0
  193. data/config/locales/server/help/dspam/cz.yml +10 -0
  194. data/config/locales/server/help/dspam/en.yml +4 -0
  195. data/config/locales/server/key/dovecot/cz.yml +23 -0
  196. data/config/locales/server/key/dovecot/en.yml +20 -0
  197. data/config/locales/server/key/dspam/cz.yml +10 -0
  198. data/config/locales/server/key/dspam/en.yml +4 -0
  199. data/config/locales/simple_form.en.yml +26 -0
  200. data/config/locales/views/admin_users/cz.yml +25 -0
  201. data/config/locales/views/admin_users/en.yml +5 -0
  202. data/config/locales/views/aliases/cz.yml +17 -0
  203. data/config/locales/views/aliases/en.yml +1 -0
  204. data/config/locales/views/devise/cz.yml +26 -0
  205. data/config/locales/views/devise/en.yml +13 -0
  206. data/config/locales/views/domains/cz.yml +15 -0
  207. data/config/locales/views/domains/en.yml +15 -0
  208. data/config/locales/views/server/cz.yml +19 -0
  209. data/config/locales/views/server/en.yml +3 -0
  210. data/config/locales/views/users/cz.yml +18 -0
  211. data/config/locales/views/users/en.yml +1 -0
  212. data/config/routes.rb +80 -0
  213. data/db/migrate/20121112201233_virtual_domain.rb +11 -0
  214. data/db/migrate/20121112201247_virtual_alias.rb +10 -0
  215. data/db/migrate/20121112201341_virtual_user.rb +34 -0
  216. data/db/migrate/20121112201359_create_admin_user.rb +30 -0
  217. data/db/migrate/20121112201411_server_configuration.rb +13 -0
  218. data/db/migrate/20130304083938_join_domains_users.rb +12 -0
  219. data/db/migrate/20130311214040_create_versions.rb +18 -0
  220. data/db/seeds.rb +45 -0
  221. data/lib/devise-encryptable.rb +1 -0
  222. data/lib/rmails.rb +5 -0
  223. data/lib/rmails/installer.rb +37 -0
  224. data/lib/rmails/version.rb +3 -0
  225. data/lib/tasks/.gitkeep +0 -0
  226. data/lib/templates/haml/scaffold/_form.html.haml +10 -0
  227. data/locals +0 -0
  228. data/log/.gitkeep +0 -0
  229. data/public/404.html +26 -0
  230. data/public/422.html +26 -0
  231. data/public/500.html +25 -0
  232. data/public/favicon.ico +0 -0
  233. data/public/fonts/London.eot +0 -0
  234. data/public/fonts/London.otf +0 -0
  235. data/public/fonts/London.woff +0 -0
  236. data/public/fonts/LondonBold.otf +0 -0
  237. data/public/robots.txt +5 -0
  238. data/rmails.gemspec +35 -0
  239. data/script/prepflog.pl +576 -0
  240. data/script/rails +6 -0
  241. data/system/config/automateit_env.rb +16 -0
  242. data/system/config/fields.yml +48 -0
  243. data/system/config/tags.yml +39 -0
  244. data/system/dist/README_AutomateIt_dist.txt +20 -0
  245. data/system/dist/amavis/spamassassin.cf.erb +85 -0
  246. data/system/dist/amavis/user.erb +33 -0
  247. data/system/dist/awstats/awstats.mail.conf.erb +41 -0
  248. data/system/dist/awstats/prepflog.pl +576 -0
  249. data/system/dist/dovecot/dovecot-sql.conf.ext.erb +14 -0
  250. data/system/dist/dovecot/dovecot.conf.erb +297 -0
  251. data/system/dist/dovecot/old_dovecot.conf.erb +63 -0
  252. data/system/dist/dspam/conf.erb +96 -0
  253. data/system/dist/dspam/pgsql.conf +33 -0
  254. data/system/dist/nginx/awstats.erb +17 -0
  255. data/system/dist/nginx/rmails.erb +40 -0
  256. data/system/dist/postfix/email2email.cf.erb +5 -0
  257. data/system/dist/postfix/main.cf.erb +118 -0
  258. data/system/dist/postfix/master.cf.erb +74 -0
  259. data/system/dist/postfix/sasl.conf.erb +3 -0
  260. data/system/dist/postfix/sender_login_maps.cf.erb +5 -0
  261. data/system/dist/postfix/virtual_alias_maps.cf.erb +5 -0
  262. data/system/dist/postfix/virtual_mailbox_domains.cf.erb +5 -0
  263. data/system/dist/postfix/virtual_mailbox_maps.cf.erb +5 -0
  264. data/system/dist/postgresql/postgresql.conf.erb +54 -0
  265. data/system/dist/rmails/Gemfile.1 +8 -0
  266. data/system/dist/rmails/Gemfile.2 +24 -0
  267. data/system/dist/rmails/database.yml.erb +15 -0
  268. data/system/dist/sudoers +37 -0
  269. data/system/lib/README_AutomateIt_lib.txt +22 -0
  270. data/system/lib/dkim_key.rb +9 -0
  271. data/system/lib/smtpd_key.rb +39 -0
  272. data/system/lib/ssl.rb +23 -0
  273. data/system/recipes/01_prepare_server.rb +84 -0
  274. data/system/recipes/02_setup_database.rb +65 -0
  275. data/system/recipes/03_setup_postfix.rb +124 -0
  276. data/system/recipes/04_setup_dovecot.rb +78 -0
  277. data/system/recipes/05_setup_nginx.rb +29 -0
  278. data/system/recipes/06_setup_dspam.rb +24 -0
  279. data/system/recipes/07_setup_amavis.rb +16 -0
  280. data/system/recipes/08_setup_spamassassin.rb +22 -0
  281. data/system/recipes/09_setup_awstats.rb +49 -0
  282. data/system/recipes/XX_start_services.rb +5 -0
  283. data/test/fixtures/.gitkeep +0 -0
  284. data/test/functional/.gitkeep +0 -0
  285. data/test/functional/aliases_controller_test.rb +7 -0
  286. data/test/functional/domains_controller_test.rb +7 -0
  287. data/test/functional/users_controller_test.rb +7 -0
  288. data/test/integration/.gitkeep +0 -0
  289. data/test/performance/browsing_test.rb +12 -0
  290. data/test/test_helper.rb +13 -0
  291. data/test/unit/.gitkeep +0 -0
  292. data/test/unit/helpers/aliases_helper_test.rb +4 -0
  293. data/test/unit/helpers/domains_helper_test.rb +4 -0
  294. data/test/unit/helpers/users_helper_test.rb +4 -0
  295. data/vendor/assets/javascripts/.gitkeep +0 -0
  296. data/vendor/assets/javascripts/canjs/can.construct.proxy.js +60 -0
  297. data/vendor/assets/javascripts/canjs/can.construct.super.js +44 -0
  298. data/vendor/assets/javascripts/canjs/can.control.plugin.js +245 -0
  299. data/vendor/assets/javascripts/canjs/can.control.view.js +88 -0
  300. data/vendor/assets/javascripts/canjs/can.dojo.js +3669 -0
  301. data/vendor/assets/javascripts/canjs/can.dojo.min.js +66 -0
  302. data/vendor/assets/javascripts/canjs/can.fixture.js +1020 -0
  303. data/vendor/assets/javascripts/canjs/can.jquery.js +2995 -0
  304. data/vendor/assets/javascripts/canjs/can.jquery.min.js +52 -0
  305. data/vendor/assets/javascripts/canjs/can.mootools.js +3462 -0
  306. data/vendor/assets/javascripts/canjs/can.mootools.min.js +63 -0
  307. data/vendor/assets/javascripts/canjs/can.observe.attributes.js +293 -0
  308. data/vendor/assets/javascripts/canjs/can.observe.backup.js +368 -0
  309. data/vendor/assets/javascripts/canjs/can.observe.delegate.js +359 -0
  310. data/vendor/assets/javascripts/canjs/can.observe.setter.js +58 -0
  311. data/vendor/assets/javascripts/canjs/can.observe.validations.js +374 -0
  312. data/vendor/assets/javascripts/canjs/can.view.modifiers.js +292 -0
  313. data/vendor/assets/javascripts/canjs/can.yui.js +3530 -0
  314. data/vendor/assets/javascripts/canjs/can.yui.min.js +65 -0
  315. data/vendor/assets/javascripts/canjs/can.zepto.js +3426 -0
  316. data/vendor/assets/javascripts/canjs/can.zepto.min.js +62 -0
  317. data/vendor/assets/javascripts/twitter/bootstrap-affix.js +104 -0
  318. data/vendor/assets/javascripts/twitter/bootstrap-alert.js +90 -0
  319. data/vendor/assets/javascripts/twitter/bootstrap-button.js +96 -0
  320. data/vendor/assets/javascripts/twitter/bootstrap-carousel.js +176 -0
  321. data/vendor/assets/javascripts/twitter/bootstrap-collapse.js +158 -0
  322. data/vendor/assets/javascripts/twitter/bootstrap-dropdown.js +150 -0
  323. data/vendor/assets/javascripts/twitter/bootstrap-modal.js +239 -0
  324. data/vendor/assets/javascripts/twitter/bootstrap-popover.js +103 -0
  325. data/vendor/assets/javascripts/twitter/bootstrap-scrollspy.js +151 -0
  326. data/vendor/assets/javascripts/twitter/bootstrap-tab.js +135 -0
  327. data/vendor/assets/javascripts/twitter/bootstrap-tooltip.js +275 -0
  328. data/vendor/assets/javascripts/twitter/bootstrap-transition.js +60 -0
  329. data/vendor/assets/javascripts/twitter/bootstrap-typeahead.js +300 -0
  330. data/vendor/assets/javascripts/twitter/my/bootstrap-typeahead.js +311 -0
  331. data/vendor/assets/stylesheets/.gitkeep +0 -0
  332. metadata +470 -0
@@ -0,0 +1,52 @@
1
+ (function(c,n,l){$.extend(c,jQuery,{trigger:function(a,b,d){a.trigger?a.trigger(b,d):$.event.trigger(b,d,a,!0)},addEvent:function(a,b){$([this]).bind(a,b);return this},removeEvent:function(a,b){$([this]).unbind(a,b);return this},buildFragment:function(a,b){var d=$.buildFragment([a],[b]);return d.cacheable?$.clone(d.fragment):d.fragment},$:jQuery});$.each(["bind","unbind","undelegate","delegate"],function(a,b){c[b]=function(){var a=this[b]?this:$([this]);a[b].apply(a,arguments);return this}});$.each("append filter addClass remove data get".split(" "),
2
+ function(a,b){c[b]=function(a){return a[b].apply(a,c.makeArray(arguments).slice(1))}});var pa=$.cleanData;$.cleanData=function(a){$.each(a,function(a,d){c.trigger(d,"destroyed",[],!1)});pa(a)};c.each=function(a,b,d){var c=0,e;if(a)if("number"==typeof a.length&&a.pop){a.attr&&a.attr("length");for(e=a.length;c<e&&!1!==b.call(d||a[c],a[c],c,a);c++);}else for(e in a)if(!1===b.call(d||a[c],a[e],e,a))break;return a};var qa=/==/,ra=/([A-Z]+)([A-Z][a-z])/g,sa=/([a-z\d])([A-Z])/g,ta=/([a-z\d])([A-Z])/g,P=
3
+ /\{([^\}]+)\}/g,s=/"/g,ua=/'/g;c.extend(c,{esc:function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(s,"&#34;").replace(ua,"&#39;")},getObject:function(a,b,d){var a=a?a.split("."):[],f=a.length,e,g=0,h,i,b=c.isArray(b)?b:[b||n];if(!f)return b[0];for(;e=b[g++];){for(i=0;i<f-1&&/^f|^o/.test(typeof e);i++)e=a[i]in e?e[a[i]]:d&&(e[a[i]]={});if(/^f|^o/.test(typeof e)&&(h=a[i]in e?e[a[i]]:d&&(e[a[i]]={}),h!==l))return!1===d&&delete e[a[i]],h}},capitalize:function(a){return a.charAt(0).toUpperCase()+
4
+ a.slice(1)},underscore:function(a){return a.replace(qa,"/").replace(ra,"$1_$2").replace(sa,"$1_$2").replace(ta,"_").toLowerCase()},sub:function(a,b,d){var f=[];f.push(a.replace(P,function(a,g){var h=c.getObject(g,b,d===l?d:!d);return/^f|^o/.test(typeof h)?(f.push(h),""):""+h}));return 1>=f.length?f[0]:f},replacer:P,undHash:/_|-/});var F=0;c.Construct=function(){if(arguments.length)return c.Construct.extend.apply(c.Construct,arguments)};c.extend(c.Construct,{newInstance:function(){var a=this.instance(),
5
+ b;a.setup&&(b=a.setup.apply(a,arguments));a.init&&a.init.apply(a,b||arguments);return a},_inherit:function(a,b,d){c.extend(d||a,a||{})},_overwrite:function(a,b,d,c){a[d]=c},setup:function(a){this.defaults=c.extend(!0,{},a.defaults,this.defaults)},instance:function(){F=1;var a=new this;F=0;return a},extend:function(a,b,d){function f(){if(!F)return this.constructor!==f&&arguments.length?arguments.callee.extend.apply(arguments.callee,arguments):this.constructor.newInstance.apply(this.constructor,arguments)}
6
+ "string"!=typeof a&&(d=b,b=a,a=null);d||(d=b,b=null);var d=d||{},e=this.prototype,g,h,i,j;j=this.instance();c.Construct._inherit(d,e,j);for(g in this)this.hasOwnProperty(g)&&(f[g]=this[g]);c.Construct._inherit(b,this,f);if(a){i=a.split(".");h=i.pop();i=e=c.getObject(i.join("."),n,!0);var o=c.underscore(a.replace(/\./g,"_")),z=c.underscore(h);e[h]=f}c.extend(f,{constructor:f,prototype:j,namespace:i,shortName:h,_shortName:z,fullName:a,_fullName:o});f.prototype.constructor=f;h=[this].concat(c.makeArray(arguments));
7
+ j=f.setup.apply(f,h);f.init&&f.init.apply(f,j||h);return f}});var q=function(a){return a&&"object"===typeof a&&!(a instanceof Date)},G=function(a,b){return c.each(a,function(a){a&&a.unbind&&a.unbind("change"+b)})},H=function(a,b,d){a instanceof u?G([a],d._namespace):a=c.isArray(a)?new u.List(a):new u(a);a.bind("change"+d._namespace,function(f,e){var g=c.makeArray(arguments),f=g.shift();g[0]="*"===b?d.indexOf(a)+"."+g[0]:b+"."+g[0];f.triggeredNS=f.triggeredNS||{};f.triggeredNS[d._namespace]||(f.triggeredNS[d._namespace]=
8
+ !0,c.trigger(d,f,g),c.trigger(d,g[0],g))});return a},Q=0,v=l,R=function(){if(!v)return v=[],!0},p=function(a,b,d){if(!a._init)if(v)v.push([a,{type:b,batchNum:S},d]);else return c.trigger(a,b,d)},S=1,T=function(){var a=v.slice(0);v=l;S++;c.each(a,function(a){c.trigger.apply(c,a)})},C=function(a,b,d){a.each(function(a,e){d[e]=q(a)&&c.isFunction(a[b])?a[b]():a});return d},A=function(a){return function(){return c[a].apply(this,arguments)}},U=A("addEvent"),A=A("removeEvent"),I=function(a){return c.isArray(a)?
9
+ a:(""+a).split(".")},u=c.Construct("can.Observe",{setup:function(){c.Construct.setup.apply(this,arguments)},bind:U,unbind:A,id:"id"},{setup:function(a){this._data={};this._namespace=".observe"+ ++Q;this._init=1;this.attr(a);delete this._init},attr:function(a,b){if(~"ns".indexOf((typeof a).charAt(0))){if(b===l)return u.__reading&&u.__reading(this,a),this._get(a);this._set(a,b);return this}return this._attrs(a,b)},each:function(){return c.each.apply(l,[this.__get()].concat(c.makeArray(arguments)))},
10
+ removeAttr:function(a){var a=I(a),b=a.shift(),d=this._data[b];if(a.length)return d.removeAttr(a);delete this._data[b];b in this.constructor.prototype||delete this[b];p(this,"change",[b,"remove",l,d]);p(this,b,[l,d]);return d},_get:function(a){var a=I(a),b=this.__get(a.shift());return a.length?b?b._get(a):l:b},__get:function(a){return a?this._data[a]:this._data},_set:function(a,b){var d=I(a),c=d.shift(),e=this.__get(c);if(q(e)&&d.length)e._set(d,b);else{if(d.length)throw"can.Observe: Object does not exist";
11
+ this.__convert&&(b=this.__convert(c,b));this.__set(c,b,e)}},__set:function(a,b,c){if(b!==c){var f=this.__get().hasOwnProperty(a)?"set":"add";this.___set(a,q(b)?H(b,a,this):b);p(this,"change",[a,f,b,c]);p(this,a,[b,c]);c&&G([c],this._namespace)}},___set:function(a,b){this._data[a]=b;a in this.constructor.prototype||(this[a]=b)},bind:U,unbind:A,serialize:function(){return C(this,"serialize",{})},_attrs:function(a,b){if(a===l)return C(this,"attr",{});var a=c.extend(!0,{},a),d,f=R(),e=this,g;this.each(function(c,
12
+ d){g=a[d];g===l?b&&e.removeAttr(d):(q(c)&&q(g)?c.attr(g,b):c!=g&&e._set(d,g),delete a[d])});for(d in a)g=a[d],this._set(d,g);f&&T();return this}}),va=[].splice,J=u("can.Observe.List",{setup:function(a,b){this.length=0;this._namespace=".observe"+ ++Q;this._init=1;this.bind("change",c.proxy(this._changes,this));this.push.apply(this,c.makeArray(a||[]));c.extend(this,b);delete this._init},_changes:function(a,b,c,f,e){~b.indexOf(".")||("add"===c?(p(this,c,[f,+b]),p(this,"length",[this.length])):"remove"===
13
+ c?(p(this,c,[e,+b]),p(this,"length",[this.length])):p(this,c,[f,+b]))},__get:function(a){return a?this[a]:this},___set:function(a,b){this[a]=b;+a>=this.length&&(this.length=+a+1)},serialize:function(){return C(this,"serialize",[])},splice:function(a,b){var d=c.makeArray(arguments),f;for(f=2;f<d.length;f++){var e=d[f];q(e)&&(d[f]=H(e,"*",this))}b===l&&(b=d[1]=this.length-a);f=va.apply(this,d);0<b&&(p(this,"change",[""+a,"remove",l,f]),G(f,this._namespace));2<d.length&&p(this,"change",[""+a,"add",d.slice(2),
14
+ f]);return f},_attrs:function(a,b){if(a===l)return C(this,"attr",[]);var a=a.slice(0),c=Math.min(a.length,this.length),f=R(),e;for(e=0;e<c;e++){var g=this[e],h=a[e];q(g)&&q(h)?g.attr(h,b):g!=h&&this._set(e,h)}a.length>this.length?this.push(a.slice(this.length)):a.length<this.length&&b&&this.splice(a.length);f&&T()}});c.each({push:"length",unshift:0},function(a,b){J.prototype[b]=function(){for(var d=arguments[0]&&c.isArray(arguments[0])?arguments[0]:c.makeArray(arguments),f=a?this.length:0,e=0;e<d.length;e++){var g=
15
+ d[e];q(g)&&(d[e]=H(g,"*",this))}e=[][b].apply(this,d);(!this.comparator||!d.length)&&p(this,"change",[""+f,"add",d,l]);return e}});c.each({pop:"length",shift:0},function(a,b){J.prototype[b]=function(){var d=arguments[0]&&c.isArray(arguments[0])?arguments[0]:c.makeArray(arguments),f=a&&this.length?this.length-1:0,d=[][b].apply(this,d);p(this,"change",[""+f,"remove",l,[d]]);d&&d.unbind&&d.unbind("change"+this._namespace);return d}});J.prototype.indexOf=[].indexOf||function(a){return c.inArray(a,this)};
16
+ var wa=function(a,b,d){var f=new c.Deferred;a.then(function(){arguments[0]=b[d](arguments[0]);f.resolve.apply(f,arguments)},function(){f.rejectWith.apply(this,arguments)});return f},xa=0,V=/change.observe\d+/,W=function(a,b,c,f,e){var g;g=[a.serialize()];var h=a.constructor,i;"destroy"==b&&g.shift();"create"!==b&&g.unshift(a[a.constructor.id]);i=h[b].apply(h,g);g=i.pipe(function(c){a[e||b+"d"](c,i);return a});i.abort&&(g.abort=function(){i.abort()});return g.then(c,f)},ya={create:{url:"_shortName",
17
+ type:"post"},update:{data:function(a,b){var b=b||{},d=this.id;b[d]&&b[d]!==a&&(b["new"+c.capitalize(a)]=b[d],delete b[d]);b[d]=a;return b},type:"put"},destroy:{type:"delete",data:function(a){var b={};b[this.id]=a;return b}},findAll:{url:"_shortName"},findOne:{}},X=function(a,b){return function(d){var d=a.data?a.data.apply(this,arguments):d,f=b||this[a.url||"_url"],e=d,g=a.type||"get";if("string"==typeof f){var h=f.split(" "),f={url:h.pop()};h.length&&(f.type=h.pop())}f.data="object"==typeof e&&!c.isArray(e)?
18
+ c.extend(f.data||{},e):e;f.url=c.sub(f.url,f.data,!0);return c.ajax(c.extend({type:g||"post",dataType:"json",success:void 0,error:void 0},f))}};c.Observe("can.Model",{setup:function(a){c.Observe.apply(this,arguments);if(this!==c.Model){var b=this,d=c.proxy(this._clean,b);c.each(ya,function(f,e){c.isFunction(b[e])||(b[e]=X(f,b[e]));if(b["make"+c.capitalize(e)]){var g=b["make"+c.capitalize(e)](b[e]);c.Construct._overwrite(b,a,e,function(){this._super;this._reqs++;return g.apply(this,arguments).then(d,
19
+ d)})}});if(!b.fullName||b.fullName==a.fullName)b.fullName=b._shortName="Model"+ ++xa;this.store={};this._reqs=0;this._url=this._shortName+"/{"+this.id+"}"}},_ajax:X,_clean:function(){this._reqs--;if(!this._reqs)for(var a in this.store)this.store[a]._bindings||delete this.store[a]},models:function(a){if(a){if(a instanceof this.List)return a;var b=this,d=new (b.List||Y),f=c.isArray(a),e=a instanceof Y,e=f?a:e?a.serialize():a.data;c.each(e,function(a){d.push(b.model(a))});f||c.each(a,function(a,b){"data"!==
20
+ b&&(d[b]=a)});return d}},model:function(a){if(a){a instanceof this&&(a=a.serialize());var b=this.store[a[this.id]]?this.store[a[this.id]].attr(a):new this(a);this._reqs&&(this.store[a[this.id]]=b);return b}}},{isNew:function(){var a=this[this.constructor.id];return!(a||0===a)},save:function(a,b){return W(this,this.isNew()?"create":"update",a,b)},destroy:function(a,b){return W(this,"destroy",a,b,"destroyed")},bind:function(a){V.test(a)||(this._bindings||(this.constructor.store[this[this.constructor.id]]=
21
+ this,this._bindings=0),this._bindings++);return c.Observe.prototype.bind.apply(this,arguments)},unbind:function(a){V.test(a)||(this._bindings--,this._bindings||delete this.constructor.store[this[this.constructor.id]]);return c.Observe.prototype.unbind.apply(this,arguments)},___set:function(a,b){c.Observe.prototype.___set.call(this,a,b);a===this.constructor.id&&this._bindings&&(this.constructor.store[this[this.constructor.id]]=this)}});c.each({makeFindAll:"models",makeFindOne:"model"},function(a,b){c.Model[b]=
22
+ function(b){return function(c,e,g){return wa(b.call(this,c),this,a).then(e,g)}}});c.each(["created","updated","destroyed"],function(a){c.Model.prototype[a]=function(b){var d=this.constructor;b&&"object"==typeof b&&this.attr(b.attr?b.attr():b);c.trigger(this,a);c.trigger(this,"change",a);c.trigger(d,a,this)}});var Y=c.Observe.List("can.Model.List",{setup:function(){c.Observe.List.prototype.setup.apply(this,arguments);var a=this;this.bind("change",function(b,c){/\w+\.destroyed/.test(c)&&a.splice(a.indexOf(b.target),
23
+ 1)})}}),za=/^\d+$/,Aa=/([^\[\]]+)|(\[\])/g,Ba=/([^?#]*)(#.*)?$/,Z=function(a){return decodeURIComponent(a.replace(/\+/g," "))};c.extend(c,{deparam:function(a){var b={},d;a&&Ba.test(a)&&(a=a.split("&"),c.each(a,function(a){var a=a.split("="),c=Z(a.shift()),g=Z(a.join("="));current=b;for(var a=c.match(Aa),c=0,h=a.length-1;c<h;c++)current[a[c]]||(current[a[c]]=za.test(a[c+1])||"[]"==a[c+1]?[]:{}),current=current[a[c]];d=a.pop();"[]"==d?current.push(g):current[d]=g}));return b}});var aa=/\:([\w\.]+)/g,
24
+ ba=/^(?:&[^=]+=[^&]*)+/,Ca=function(a){var b=[];c.each(a,function(a,f){b.push(("className"===f?"class":f)+'="'+("href"===f?a:c.esc(a))+'"')});return b.join(" ")},ca=function(a,b){var c=0,f=0,e={},g;for(g in a.defaults)a.defaults[g]===b[g]&&(e[g]=1,c++);for(;f<a.names.length;f++){if(!b.hasOwnProperty(a.names[f]))return-1;e[a.names[f]]||c++}return c},da=!0,K=n.location,w=c.each,t=c.extend;c.route=function(a,b){var b=b||{},d=[],f=a.replace(aa,function(c,f,h){d.push(f);return"([^\\"+(a.substr(h+c.length,
25
+ 1)||"&")+"]"+(b[f]?"*":"+")+")"});c.route.routes[a]={test:RegExp("^"+f+"($|&)"),route:a,names:d,defaults:b,length:a.split("/").length};return c.route};t(c.route,{param:function(a,b){var d,f=0,e,g=a.route,h=0;delete a.route;w(a,function(){h++});w(c.route.routes,function(c){e=ca(c,a);e>f&&(d=c,f=e);if(e>=h)return!1});c.route.routes[g]&&ca(c.route.routes[g],a)===f&&(d=c.route.routes[g]);if(d){var i=t({},a),g=d.route.replace(aa,function(c,b){delete i[b];return a[b]===d.defaults[b]?"":encodeURIComponent(a[b])}),
26
+ j;w(d.defaults,function(a,b){i[b]===a&&delete i[b]});j=c.param(i);b&&c.route.attr("route",d.route);return g+(j?"&"+j:"")}return c.isEmptyObject(a)?"":"&"+c.param(a)},deparam:function(a){var b={length:-1};w(c.route.routes,function(c){c.test.test(a)&&c.length>b.length&&(b=c)});if(-1<b.length){var d=a.match(b.test),f=d.shift(),e=(f=a.substr(f.length-("&"===d[d.length-1]?1:0)))&&ba.test(f)?c.deparam(f.slice(1)):{},e=t(!0,{},b.defaults,e);w(d,function(a,c){a&&"&"!==a&&(e[b.names[c]]=decodeURIComponent(a))});
27
+ e.route=b.route;return e}"&"!==a.charAt(0)&&(a="&"+a);return ba.test(a)?c.deparam(a.slice(1)):{}},data:new c.Observe({}),routes:{},ready:function(a){!1===a&&(da=a);(!0===a||!0===da)&&ea();return c.route},url:function(a,b){b&&(a=t({},L,a));return"#!"+c.route.param(a)},link:function(a,b,d,f){return"<a "+Ca(t({href:c.route.url(b,f)},d))+">"+a+"</a>"},current:function(a){return K.hash=="#!"+c.route.param(a)}});w("bind unbind delegate undelegate attr removeAttr".split(" "),function(a){c.route[a]=function(){return c.route.data[a].apply(c.route.data,
28
+ arguments)}});var fa,L,ea=function(){var a=K.href.split(/#!?/)[1]||"";L=c.route.deparam(a);(!M||a!==ga)&&c.route.attr(L,!0)},ga,M;c.bind.call(n,"hashchange",ea);c.route.bind("change",function(){M=1;clearTimeout(fa);fa=setTimeout(function(){M=0;var a=c.route.data.serialize();K.hash="#!"+(ga=c.route.param(a,!0))},1)});c.bind.call(document,"ready",c.route.ready);(function(){var a=function(a,b,d){c.bind.call(a,b,d);return function(){c.unbind.call(a,b,d)}},b=c.isFunction,d=c.extend,f=c.each,e=[].slice,
29
+ g=/\{([^\}]+)\}/g,h=c.getObject("$.event.special")||{},i=function(a,b,d,f){c.delegate.call(a,b,d,f);return function(){c.undelegate.call(a,b,d,f)}},j=function(a,d){var f="string"==typeof d?a[d]:d;b(f)||(f=a[f]);return function(){a.called=d;return f.apply(a,[this.nodeName?c.$(this):this].concat(e.call(arguments,0)))}},o;c.Construct("can.Control",{setup:function(){c.Construct.setup.apply(this,arguments);if(this!==c.Control){var a;this.actions={};for(a in this.prototype)this._isAction(a)&&(this.actions[a]=
30
+ this._action(a))}},_isAction:function(a){var c=this.prototype[a],d=typeof c;return"constructor"!==a&&("function"==d||"string"==d&&b(this.prototype[c]))&&!(!h[a]&&!z[a]&&!/[^\w]/.test(a))},_action:function(a,b){g.lastIndex=0;if(b||!g.test(a)){var d=b?c.sub(a,[b,n]):a,f=c.isArray(d),e=(f?d[1]:d).match(/^(?:(.*?)\s)?([\w\.\:>]+)$/);return{processor:z[e[2]]||o,parts:e,delegate:f?d[0]:l}}},processors:{},defaults:{}},{setup:function(a,b){var f=this.constructor,e=f.pluginName||f._fullName;this.element=c.$(a);
31
+ e&&"can_control"!==e&&this.element.addClass(e);(e=c.data(this.element,"controls"))||c.data(this.element,"controls",e=[]);e.push(this);this.options=d({},f.defaults,b);this.on();return[this.element,this.options]},on:function(b,d,f,e){if(!b){this.off();var b=this.constructor,d=this._bindings,f=b.actions,e=this.element,g=j(this,"destroy"),h,o;for(h in f)f.hasOwnProperty(h)&&(o=f[h]||b._action(h,this.options),d.push(o.processor(o.delegate||e,o.parts[2],o.parts[1],h,this)));c.bind.call(e,"destroyed",g);
32
+ d.push(function(a){c.unbind.call(a,"destroyed",g)});return d.length}"string"==typeof b&&(e=f,f=d,d=b,b=this.element);"string"==typeof e&&(e=j(this,e));this._bindings.push(d?i(b,c.trim(d),f,e):a(b,f,e));return this._bindings.length},off:function(){var a=this.element[0];f(this._bindings||[],function(b){b(a)});this._bindings=[]},destroy:function(){var a=this.constructor,a=a.pluginName||a._fullName;this.off();a&&"can_control"!==a&&this.element.removeClass(a);a=c.data(this.element,"controls");a.splice(c.inArray(this,
33
+ a),1);c.trigger(this,"destroyed");this.element=null}});var z=c.Control.processors;o=function(b,d,f,e,g){e=j(g,e);return f?i(b,c.trim(f),d,e):a(b,d,e)};f("change click contextmenu dblclick keydown keyup keypress mousedown mousemove mouseout mouseover mouseup reset resize scroll select submit focusin focusout mouseenter mouseleave".split(" "),function(a){z[a]=o})})();c.Control.processors.route=function(a,b,d,f,e){c.route(d||"");var g,h=function(a){if(c.route.attr("route")===(d||"")&&(a.batchNum===l||
34
+ a.batchNum!==g))if(g=a.batchNum,a=c.route.attr(),delete a.route,c.isFunction(e[f]))e[f](a);else e[e[f]](a)};c.route.bind("change",h);return function(){c.route.unbind("change",h)}};var D=c.isFunction,Da=c.makeArray,ha=1,k=c.view=function(a,b,d,f){a=k.render(a,b,d,f);return c.isDeferred(a)?a.pipe(function(a){return k.frag(a)}):k.frag(a)};c.extend(k,{frag:function(a,b){return k.hookup(k.fragment(a),b)},fragment:function(a){a=c.buildFragment(a,document.body);a.childNodes.length||a.appendChild(document.createTextNode(""));
35
+ return a},toId:function(a){return c.map(a.toString().split(/\/|\./g),function(a){if(a)return a}).join("_")},hookup:function(a,b){var d=[],f,e,g,h=0;for(c.each(a.childNodes?c.makeArray(a.childNodes):a,function(a){1===a.nodeType&&(d.push(a),d.push.apply(d,c.makeArray(a.getElementsByTagName("*"))))});g=d[h++];)if(g.getAttribute&&(f=g.getAttribute("data-view-id"))&&(e=k.hookups[f]))e(g,b,f),delete k.hookups[f],g.removeAttribute("data-view-id");return a},hookups:{},hook:function(a){k.hookups[++ha]=a;return" data-view-id='"+
36
+ ha+"'"},cached:{},cache:!0,register:function(a){this.types["."+a.suffix]=a},types:{},ext:".ejs",registerScript:function(){},preload:function(){},render:function(a,b,d,f){D(d)&&(f=d,d=l);var e=Ea(b);if(e.length){var g=new c.Deferred;e.push(ia(a,!0));c.when.apply(c,e).then(function(a){var e=Da(arguments),h=e.pop();if(c.isDeferred(b))b=ja(a);else for(var l in b)c.isDeferred(b[l])&&(b[l]=ja(e.shift()));e=h(b,d);g.resolve(e);f&&f(e)});return g}var h,e=D(f),g=ia(a,e);e?(h=g,g.then(function(a){f(a(b,d))})):
37
+ g.then(function(a){h=a(b,d)});return h}});c.isDeferred=function(a){return a&&D(a.then)&&D(a.pipe)};var ka=function(a,b){if(!a.length)throw"can.view: No template or empty template:"+b;},ia=function(a,b){var d=a.match(/\.[\w\d]+$/),f,e,g,h=function(a){var a=f.renderer(g,a),b=new c.Deferred;b.resolve(a);k.cache&&(k.cached[g]=b);return b};a.match(/^#/)&&(a=a.substr(1));if(e=document.getElementById(a))d="."+e.type.match(/\/(x\-)?(.+)/)[2];!d&&!k.cached[a]&&(a+=d=k.ext);c.isArray(d)&&(d=d[0]);g=c.view.toId(a);
38
+ if(a.match(/^\/\//))var i=a.substr(2),a=!n.steal?"/"+i:steal.root.mapJoin(i);f=k.types[d];if(k.cached[g])return k.cached[g];if(e)return h(e.innerHTML);var j=new c.Deferred;c.ajax({async:b,url:a,dataType:"text",error:function(b){ka("",a);j.reject(b)},success:function(b){ka(b,a);j.resolve(f.renderer(g,b));k.cache&&(k.cached[g]=j)}});return j},Ea=function(a){var b=[];if(c.isDeferred(a))return[a];for(var d in a)c.isDeferred(a[d])&&b.push(a[d]);return b},ja=function(a){return c.isArray(a)&&"success"===
39
+ a[1]?a[0]:a};n.steal&&steal.type("view js",function(a,b){var d=c.view.types["."+a.type],f=c.view.toId(a.rootSrc);a.text="steal('"+(d.plugin||"can/view/"+a.type)+"').then(function($){can.view.preload('"+f+"',"+a.text+");\n})";b()});c.extend(c.view,{register:function(a){this.types["."+a.suffix]=a;n.steal&&steal.type(a.suffix+" view js",function(a,d){var f=c.view.types["."+a.type],e=c.view.toId(a.rootSrc+"");a.text=f.script(e,a.text);d()});c.view[a.suffix]=function(b,c){k.preload(b,a.renderer(b,c))}},
40
+ registerScript:function(a,b,c){return"can.view.preload('"+b+"',"+k.types["."+a].script(b,c)+");"},preload:function(a,b){c.view.cached[a]=(new c.Deferred).resolve(function(a,c){return b.call(a,a,c)})}});var Fa=function(a,b){var d;c.Observe&&(d=c.Observe.__reading,c.Observe.__reading=function(a,b){f.push({obj:a,attr:b})});var f=[],e=a.call(b);c.Observe&&(c.Observe.__reading=d);return{value:e,observed:f}},la=function(a,b,d){var f={},e=!0,g={value:l,teardown:function(){for(var a in f){var b=f[a];b.observe.obj.unbind(b.observe.attr,
41
+ h);delete f[a]}}},h=function(){var a=g.value,b=i();g.value=b;b!==a&&d(b,a)},i=function(){var d=Fa(a,b),g=d.observed,d=d.value;e=!e;c.each(g,function(a){f[a.obj._namespace+"|"+a.attr]?f[a.obj._namespace+"|"+a.attr].matched=e:(f[a.obj._namespace+"|"+a.attr]={matched:e,observe:a},a.obj.bind(a.attr,h))});for(var i in f)g=f[i],g.matched!==e&&(g.observe.obj.unbind(g.observe.attr,h),delete f[i]);return d};g.value=i();g.isListening=!c.isEmptyObject(f);return g};c.compute=function(a,b){if(a.isComputed)return a;
42
+ var d,f=0,e,g=!0;"function"===typeof a?e=function(c){return c===l?d?d.value:a.call(b||this):a.apply(b||this,arguments)}:(e=function(b){if(b===l)return a;var d=a;a=b;d!==b&&c.trigger(e,"change",[b,d]);return b},g=!1);e.isComputed=!0;e.bind=function(h,i){c.addEvent.apply(e,arguments);f===0&&g&&(d=la(a,b||this,function(a,b){c.trigger(e,"change",[a,b])}));f++};e.unbind=function(a,b){c.removeEvent.apply(e,arguments);f--;f===0&&g&&d.teardown()};return e};c.compute.binder=la;var Ga=function(a){eval(a)},
43
+ t=c.extend,ma=/\s*\(([\$\w]+)\)\s*->([^\n]*)/,na=/([^\s]+)=$/,Ha=/(\r|\n)+/g,Ia=/__!!__/g,Ja={"":"span",table:"tr",tr:"td",ol:"li",ul:"li",tbody:"tr",thead:"tr",tfoot:"tr"},B={"class":"className"},oa=c.each(["checked","disabled","readonly","required"],function(a){B[a]=a}),N=function(a,b,d){B[b]?a[B[b]]=-1<c.inArray(b,oa)?!0:d:a.setAttribute(b,d)},Ka=function(a){return"string"==typeof a||"number"==typeof a?c.esc(a):O(a)},O=function(a){if("string"==typeof a)return a;if(!a&&0!=a)return"";var b=a.hookup&&
44
+ function(b,c){a.hookup.call(a,b,c)}||"function"==typeof a&&a;return b?(x.push(b),""):""+a},m=function(a){if(this.constructor!=m){var b=new m(a);return function(a,c){return b.render(a,c)}}"function"==typeof a?this.template={fn:a}:(t(this,a),this.template=La(this.text,this.name))};c.EJS=m;m.prototype.render=function(a,b){a=a||{};return this.template.fn.call(a,a,new m.Helpers(a,b||{}))};t(m,{txt:function(a,b,d,f,e){var g=c.compute.binder(e,f,function(a,b){o(a,b)});if(!g.isListening)return(a||0!==d?Ka:
45
+ O)(g.value);var h,i=function(a){c.bind.call(a,"destroyed",g.teardown);h=a},j=function(a){a||(g.teardown(),c.unbind.call(h,"destroyed",g.teardown))},b=Ja[b]||"span",o;if(0==d)return"<"+b+c.view.hook(a?function(a,b){o=function(a){d.nodeValue=""+a;j(d.parentNode)};var c=b&&11===a.parentNode.nodeType?b:a.parentNode,d=document.createTextNode(g.value);c.insertBefore(d,a);c.removeChild(a);i(c)}:function(a,b){o=function(a){e[0].parentNode&&(e=d(a,e));j(e[0].parentNode)};var b=b&&11===a.parentNode.nodeType?
46
+ b:a.parentNode,d=function(a,d){var e=c.view.frag(a,b),f=c.map(e.childNodes,function(a){return a}),g=d[d.length-1];g.nextSibling?g.parentNode.insertBefore(e,g.nextSibling):g.parentNode.appendChild(e);c.remove(c.$(d));return f},e=d(g.value,[a]);i(b)})+"></"+b+">";if(1===d){var k=g.value.replace(/['"]/g,"").split("=")[0];x.push(function(a){o=function(b){var b=(b||"").replace(/['"]/g,"").split("="),d=b[0];if(d!=k&&k){var e=k;-1<c.inArray(e,oa)?a[e]=!1:a.removeAttribute(e)}d&&(N(a,d,b[1]),k=d)};i(a)});
47
+ return g.value}x.push(function(a){o=function(){N(a,d,h.render())};var b=c.$(a),e;(e=c.data(b,"hooks"))||c.data(b,"hooks",e={});var f=B[d]?a[B[d]]:a.getAttribute(d),b=f.split("__!!__"),h;e[d]?e[d].bindings.push(g):e[d]={render:function(){var a=0;return f.replace(Ia,function(){return O(h.bindings[a++].value)})},bindings:[g],batchNum:l};h=e[d];b.splice(1,0,g.value);N(a,d,b.join(""));i(a)});return"__!!__"},pending:function(){if(x.length){var a=x.slice(0);x=[];return c.view.hook(function(b){c.each(a,function(a){a(b)})})}return""}});
48
+ var Ma=RegExp("(<%%|%%>|<%==|<%=|<%#|<%|%>|<|>|\"|')","g"),y=null,E=s=null,x=[],La=function(a,b){var c=[],f=0,a=a.replace(Ha,"\n");a.replace(Ma,function(b,e,g){g>f&&c.push(a.substring(f,g));c.push(e);f=g+e.length});f<a.length&&c.push(a.substr(f));var e="",g=["var ___v1ew = [];"],h=function(a,b){g.push("___v1ew.push(",'"',a.split("\\").join("\\\\").split("\n").join("\\n").split('"').join('\\"').split("\t").join("\\t"),'"'+(b||"")+");")},i=[],j,k=null,p=!1,m="",n=[],q=0,r;for(y=s=E=null;(r=c[q++])!==
49
+ l;){if(null===k)switch(r){case "<%":case "<%=":case "<%==":p=1;case "<%#":k=r;e.length&&h(e);e="";break;case "<%%":e+="<%";break;case "<":0!==c[q].indexOf("!--")&&(y=1,p=0);e+=r;break;case ">":y=0;p?(h(e,',can.EJS.pending(),">"'),e=""):e+=r;"/"==j.substr(-1)&&(n.pop(),m=n[n.length-1]);break;case "'":case '"':y&&(s&&s===r?s=null:null===s&&(s=r,E=j));default:"<"===j&&(m=r.split(" ")[0],0===m.indexOf("/")&&n.pop()===m.substr(1)?m=n[n.length-1]||m.substr(1):n.push(m)),e+=r}else switch(r){case "%>":switch(k){case "<%":j=
50
+ --e.split("{").length- --e.split("}").length;1==j?(g.push("___v1ew.push(","can.EJS.txt(0,'"+m+"',"+(s?"'"+E.match(na)[1]+"'":y?1:0)+",this,function(){","var ___v1ew = [];",e),i.push({before:"",after:"return ___v1ew.join('')}));\n"})):(f=i.length&&-1==j?i.pop():{after:";"},f.before&&g.push(f.before),g.push(e,";",f.after));break;case "<%=":case "<%==":(j=--e.split("{").length- --e.split("}").length)&&i.push({before:"return ___v1ew.join('')",after:"}));"}),ma.test(e)&&(e=e.match(ma),e="function(__){var "+
51
+ e[1]+"=can.$(__);"+e[2]+"}"),g.push("___v1ew.push(","can.EJS.txt("+("<%="===k?1:0)+",'"+m+"',"+(s?"'"+E.match(na)[1]+"'":y?1:0)+",this,function(){ return ",e,j?"var ___v1ew = [];":"}));")}k=null;e="";break;case "<%%":e+="<%";break;default:e+=r}j=r}e.length&&h(e);g.push(";");h={out:"with(_VIEW) { with (_CONTEXT) {"+g.join("")+" return ___v1ew.join('')}}"};Ga.call(h,"this.fn = (function(_CONTEXT,_VIEW){"+h.out+"});\r\n//@ sourceURL="+b+".js");return h};m.Helpers=function(a,b){this._data=a;this._extras=
52
+ b;t(this,b)};m.Helpers.prototype={list:function(a,b){c.each(a,function(c,f){b(c,f,a)})}};c.view.register({suffix:"ejs",script:function(a,b){return"can.EJS(function(_CONTEXT,_VIEW) { "+(new m({text:b,name:a})).template.out+" })"},renderer:function(a,b){return m({text:b,name:a})}});"function"===typeof define&&define.amd?define("can",[],function(){return c}):n.can=c})(can={},this);
@@ -0,0 +1,3462 @@
1
+ (function(can, window, undefined){
2
+
3
+ // event.js
4
+ // ---------
5
+ // _Basic event wrapper._
6
+ can.addEvent = function(event, fn){
7
+ if(!this.__bindEvents){
8
+ this.__bindEvents = {};
9
+ }
10
+ var eventName = event.split(".")[0];
11
+
12
+ if(!this.__bindEvents[eventName]){
13
+ this.__bindEvents[eventName] = [];
14
+ }
15
+ this.__bindEvents[eventName].push({
16
+ handler: fn,
17
+ name: event
18
+ });
19
+ return this;
20
+ };
21
+ can.removeEvent = function(event, fn){
22
+ if(!this.__bindEvents){
23
+ return;
24
+ }
25
+ var i =0,
26
+ events = this.__bindEvents[event.split(".")[0]],
27
+ ev;
28
+ while(i < events.length){
29
+ ev = events[i]
30
+ if((fn && ev.handler === fn) || (!fn && ev.name === event)){
31
+ events.splice(i, 1);
32
+ } else {
33
+ i++;
34
+ }
35
+ }
36
+ return this;
37
+ };
38
+ can.dispatch = function(event){
39
+ if(!this.__bindEvents){
40
+ return;
41
+ }
42
+
43
+ var eventName = event.type.split(".")[0],
44
+ handlers = (this.__bindEvents[eventName] || []).slice(0),
45
+ self= this,
46
+ args = [event].concat(event.data || []);
47
+
48
+ can.each(handlers, function(ev){
49
+ event.data = args.slice(1);
50
+ ev.handler.apply(self, args);
51
+ });
52
+ }
53
+
54
+ ;
55
+
56
+ // fragment.js
57
+ // ---------
58
+ // _DOM Fragment support._
59
+
60
+ var table = document.createElement('table'),
61
+ tableRow = document.createElement('tr'),
62
+ containers = {
63
+ 'tr': document.createElement('tbody'),
64
+ 'tbody': table, 'thead': table, 'tfoot': table,
65
+ 'td': tableRow, 'th': tableRow,
66
+ '*': document.createElement('div')
67
+ },
68
+ fragmentRE = /^\s*<(\w+)[^>]*>/,
69
+ fragment = function(html, name) {
70
+ if (name === undefined) {
71
+ name = fragmentRE.test(html) && RegExp.$1;
72
+ }
73
+ if (!(name in containers)) name = '*';
74
+ var container = containers[name];
75
+ // IE's parser will strip any `<tr><td>` tags when `innerHTML`
76
+ // is called on a `tbody`. To get around this, we construct a
77
+ // valid table with a `tbody` that has the `innerHTML` we want.
78
+ // Then the container is the `firstChild` of the `tbody`.
79
+ // [source](http://www.ericvasilik.com/2006/07/code-karma.html).
80
+ if(name === "tr") {
81
+ var temp = document.createElement('div');
82
+ temp.innerHTML = "<table><tbody>" + html + "</tbody></table>";
83
+ container = temp.firstChild.firstChild;
84
+ } else {
85
+ container.innerHTML = '' + html;
86
+ }
87
+ // IE8 barfs if you pass slice a `childNodes` object, so make a copy.
88
+ var tmp = {},
89
+ children = container.childNodes;
90
+ tmp.length = children.length;
91
+ for(var i=0; i<children.length; i++){
92
+ tmp[i] = children[i];
93
+ }
94
+ return [].slice.call(tmp);
95
+ }
96
+
97
+ can.buildFragment = function(html, nodes){
98
+ var parts = fragment(html),
99
+ frag = document.createDocumentFragment();
100
+ parts.forEach(function(part){
101
+ frag.appendChild(part);
102
+ })
103
+ return frag;
104
+ };
105
+
106
+ can.each = function (elements, callback, context) {
107
+ var i = 0,
108
+ key;
109
+ if (elements) {
110
+ if (typeof elements.length == 'number' && elements.pop) {
111
+ elements.attr && elements.attr('length');
112
+ for (var len = elements.length; i < len; i++) {
113
+ if (callback.call(context || elements[i], elements[i], i, elements) === false) {
114
+ break;
115
+ }
116
+ }
117
+ } else {
118
+ for (key in elements) {
119
+ if (callback.call(context || elements[i], elements[key], key, elements) === false) {
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ }
125
+ return elements;
126
+ }
127
+ ;
128
+
129
+ // mootools.js
130
+ // ---------
131
+ // _MooTools node list._
132
+ //
133
+ // Map string helpers.
134
+ can.trim = function(s){
135
+ return s && s.trim()
136
+ }
137
+
138
+ // Map array helpers.
139
+ can.makeArray = Array.from;
140
+ can.isArray = function(arr){
141
+ return typeOf(arr) === 'array'
142
+ };
143
+ can.inArray = function(item,arr){
144
+ return arr.indexOf(item)
145
+ }
146
+ can.map = function(arr, fn){
147
+ return Array.from(arr||[]).map(fn);
148
+ }
149
+
150
+ // Map object helpers.
151
+ can.extend = function(first){
152
+ if(first === true){
153
+ var args = can.makeArray(arguments);
154
+ args.shift();
155
+ return Object.merge.apply(Object, args)
156
+ }
157
+ return Object.append.apply(Object, arguments)
158
+ }
159
+ can.param = function(object){
160
+ return Object.toQueryString(object)
161
+ }
162
+ can.isEmptyObject = function(object){
163
+ return Object.keys(object).length === 0;
164
+ }
165
+ // Map function helpers.
166
+ can.proxy = function(func){
167
+ var args = can.makeArray(arguments),
168
+ func = args.shift();
169
+
170
+ return func.bind.apply(func, args)
171
+ }
172
+ can.isFunction = function(f){
173
+ return typeOf(f) == 'function'
174
+ }
175
+ // Make this object so you can bind on it.
176
+ can.bind = function( ev, cb){
177
+ // If we can bind to it...
178
+ if(this.bind && this.bind !== can.bind){
179
+ this.bind(ev, cb)
180
+ } else if(this.addEvent) {
181
+ this.addEvent(ev, cb)
182
+ } else {
183
+ // Make it bind-able...
184
+ can.addEvent.call(this, ev, cb)
185
+ }
186
+ return this;
187
+ }
188
+ can.unbind = function(ev, cb){
189
+ // If we can bind to it...
190
+ if(this.unbind && this.unbind !== can.unbind){
191
+ this.unbind(ev, cb)
192
+ } else if(this.removeEvent) {
193
+ this.removeEvent(ev, cb)
194
+ } else {
195
+ // Make it bind-able...
196
+ can.removeEvent.call(this, ev, cb)
197
+ }
198
+ return this;
199
+ }
200
+ can.trigger = function(item, event, args, bubble){
201
+ // Defaults to `true`.
202
+ bubble = (bubble === undefined ? true : bubble);
203
+ args = args || []
204
+ if(item.fireEvent){
205
+ item = item[0] || item;
206
+ // walk up parents to simulate bubbling .
207
+ while(item) {
208
+ // Handle walking yourself.
209
+ if(!event.type){
210
+ event = {
211
+ type : event,
212
+ target : item
213
+ }
214
+ }
215
+ var events = (item !== window ?
216
+ can.$(item).retrieve('events')[0] :
217
+ item.retrieve('events') );
218
+ if (events && events[event.type]) {
219
+ events[event.type].keys.each(function(fn){
220
+ fn.apply(this, [event].concat(args));
221
+ }, this);
222
+ }
223
+ // If we are bubbling, get parent node.
224
+ if(bubble && item.parentNode){
225
+ item = item.parentNode
226
+ } else {
227
+ item = null;
228
+ }
229
+
230
+ }
231
+
232
+
233
+ } else {
234
+ if(typeof event === 'string'){
235
+ event = {type: event}
236
+ }
237
+ event.target = event.target || item;
238
+ event.data = args
239
+ can.dispatch.call(item, event)
240
+ }
241
+ }
242
+ can.delegate = function(selector, ev , cb){
243
+ if(this.delegate) {
244
+ this.delegate(selector, ev , cb)
245
+ }
246
+ else if(this.addEvent) {
247
+ this.addEvent(ev+":relay("+selector+")", cb)
248
+ } else {
249
+ // make it bind-able ...
250
+ }
251
+ return this;
252
+ }
253
+ can.undelegate = function(selector, ev , cb){
254
+ if(this.undelegate) {
255
+ this.undelegate(selector, ev , cb)
256
+ }
257
+ else if(this.removeEvent) {
258
+ this.removeEvent(ev+":relay("+selector+")", cb)
259
+ } else {
260
+ // make it bind-able ...
261
+
262
+ }
263
+ return this;
264
+ }
265
+ var optionsMap = {
266
+ type:"method",
267
+ success : undefined,
268
+ error: undefined
269
+ }
270
+ var updateDeferred = function(xhr, d){
271
+ for(var prop in xhr){
272
+ if(typeof d[prop] == 'function'){
273
+ d[prop] = function(){
274
+ xhr[prop].apply(xhr, arguments)
275
+ }
276
+ } else {
277
+ d[prop] = prop[xhr]
278
+ }
279
+ }
280
+ }
281
+ can.ajax = function(options){
282
+ var d = can.Deferred(),
283
+ requestOptions = can.extend({}, options);
284
+ // Map jQuery options to MooTools options.
285
+
286
+ for(var option in optionsMap){
287
+ if(requestOptions[option] !== undefined){
288
+ requestOptions[optionsMap[option]] = requestOptions[option];
289
+ delete requestOptions[option]
290
+ }
291
+ }
292
+ // Mootools defaults to 'post', but Can expects a default of 'get'
293
+ requestOptions.method = requestOptions.method || 'get';
294
+
295
+ var success = options.success,
296
+ error = options.error;
297
+
298
+ requestOptions.onSuccess = function(responseText, xml){
299
+ var data = responseText;
300
+ if(options.dataType ==='json'){
301
+ data = eval("("+data+")")
302
+ }
303
+ updateDeferred(request.xhr, d);
304
+ d.resolve(data,"success",request.xhr);
305
+ success && success(data,"success",request.xhr);
306
+ }
307
+ requestOptions.onError = function(){
308
+ updateDeferred(request.xhr, d);
309
+ d.reject(request.xhr,"error");
310
+ error(request.xhr,"error");
311
+ }
312
+
313
+ var request = new Request(requestOptions);
314
+ request.send();
315
+ updateDeferred(request.xhr, d);
316
+ return d;
317
+
318
+ }
319
+ // Element -- get the wrapped helper.
320
+ can.$ = function(selector){
321
+ if(selector === window){
322
+ return window;
323
+ }
324
+ return $$(selector)
325
+ }
326
+
327
+ // Add `document` fragment support.
328
+ var old = document.id;
329
+ document.id = function(el){
330
+ if(el && el.nodeType === 11){
331
+ return el
332
+ } else{
333
+ return old.apply(document, arguments);
334
+ }
335
+ };
336
+ can.append = function(wrapped, html){
337
+ if(typeof html === 'string'){
338
+ html = can.buildFragment(html)
339
+ }
340
+ return wrapped.grab(html)
341
+ }
342
+ can.filter = function(wrapped, filter){
343
+ return wrapped.filter(filter);
344
+ }
345
+ can.data = function(wrapped, key, value){
346
+ if(value === undefined){
347
+ return wrapped[0].retrieve(key)
348
+ } else {
349
+ return wrapped.store(key, value)
350
+ }
351
+ }
352
+ can.addClass = function(wrapped, className){
353
+ return wrapped.addClass(className);
354
+ }
355
+ can.remove = function(wrapped){
356
+ // We need to remove text nodes ourselves.
357
+ var filtered = wrapped.filter(function(node){
358
+ if(node.nodeType !== 1){
359
+ node.parentNode.removeChild(node);
360
+ } else {
361
+ return true;
362
+ }
363
+ })
364
+ filtered.destroy();
365
+ return filtered;
366
+ }
367
+
368
+ // Destroyed method.
369
+ var destroy = Element.prototype.destroy;
370
+ Element.implement({
371
+ destroy : function(){
372
+ can.trigger(this,"destroyed",[],false)
373
+ var elems = this.getElementsByTagName("*");
374
+ for ( var i = 0, elem; (elem = elems[i]) !== undefined; i++ ) {
375
+ can.trigger(elem,"destroyed",[],false);
376
+ }
377
+ destroy.apply(this, arguments)
378
+ }
379
+ });
380
+ can.get = function(wrapped, index){
381
+ return wrapped[index];
382
+ }
383
+
384
+ // Overwrite to handle IE not having an id.
385
+ // IE barfs if text node.
386
+ var idOf = Slick.uidOf;
387
+ Slick.uidOf = function(node){
388
+ if(node.nodeType === 1 || node === window){
389
+ return idOf(node);
390
+ } else {
391
+ return Math.random();
392
+ }
393
+
394
+
395
+ }
396
+ ;
397
+
398
+ // deferred.js
399
+ // ---------
400
+ // _Lightweight, jQuery style deferreds._
401
+
402
+ var Deferred = function( func ) {
403
+ if ( ! ( this instanceof Deferred ))
404
+ return new Deferred();
405
+
406
+ this._doneFuncs = [];
407
+ this._failFuncs = [];
408
+ this._resultArgs = null;
409
+ this._status = "";
410
+
411
+ // Check for option `function` -- call it with this as context and as first
412
+ // parameter, as specified in jQuery API.
413
+ func && func.call(this, this);
414
+ };
415
+ can.Deferred = Deferred;
416
+ can.when = Deferred.when = function() {
417
+ var args = can.makeArray( arguments );
418
+ if (args.length < 2) {
419
+ var obj = args[0];
420
+ if (obj && ( can.isFunction( obj.isResolved ) && can.isFunction( obj.isRejected ))) {
421
+ return obj;
422
+ } else {
423
+ return Deferred().resolve(obj);
424
+ }
425
+ } else {
426
+
427
+ var df = Deferred(),
428
+ done = 0,
429
+ // Resolve params -- params of each resolve, we need to track them down
430
+ // to be able to pass them in the correct order if the master
431
+ // needs to be resolved.
432
+ rp = [];
433
+
434
+ can.each(args, function(arg, j){
435
+ arg.done(function() {
436
+ rp[j] = (arguments.length < 2) ? arguments[0] : arguments;
437
+ if (++done == args.length) {
438
+ df.resolve.apply(df, rp);
439
+ }
440
+ }).fail(function() {
441
+ df.reject(arguments);
442
+ });
443
+ });
444
+
445
+ return df;
446
+
447
+ }
448
+ }
449
+
450
+ var resolveFunc = function(type, _status){
451
+ return function(context){
452
+ var args = this._resultArgs = (arguments.length > 1) ? arguments[1] : [];
453
+ return this.exec(context, this[type], args, _status);
454
+ }
455
+ },
456
+ doneFunc = function(type, _status){
457
+ return function(){
458
+ var self = this;
459
+ // In Safari, the properties of the `arguments` object are not enumerable,
460
+ // so we have to convert arguments to an `Array` that allows `can.each` to loop over them.
461
+ can.each(Array.prototype.slice.call(arguments), function( v, i, args ) {
462
+ if ( ! v )
463
+ return;
464
+ if ( v.constructor === Array ) {
465
+ args.callee.apply(self, v)
466
+ } else {
467
+ // Immediately call the `function` if the deferred has been resolved.
468
+ if (self._status === _status)
469
+ v.apply(self, self._resultArgs || []);
470
+
471
+ self[type].push(v);
472
+ }
473
+ });
474
+ return this;
475
+ }
476
+ };
477
+
478
+ can.extend( Deferred.prototype, {
479
+ pipe : function(done, fail){
480
+ var d = can.Deferred();
481
+ this.done(function(){
482
+ d.resolve( done.apply(this, arguments) );
483
+ });
484
+
485
+ this.fail(function(){
486
+ if(fail){
487
+ d.reject( fail.apply(this, arguments) );
488
+ } else {
489
+ d.reject.apply(d, arguments);
490
+ }
491
+ });
492
+ return d;
493
+ },
494
+ resolveWith : resolveFunc("_doneFuncs","rs"),
495
+ rejectWith : resolveFunc("_failFuncs","rj"),
496
+ done : doneFunc("_doneFuncs","rs"),
497
+ fail : doneFunc("_failFuncs","rj"),
498
+ always : function() {
499
+ var args = can.makeArray(arguments);
500
+ if (args.length && args[0])
501
+ this.done(args[0]).fail(args[0]);
502
+
503
+ return this;
504
+ },
505
+
506
+ then : function() {
507
+ var args = can.makeArray( arguments );
508
+ // Fail `function`(s)
509
+ if (args.length > 1 && args[1])
510
+ this.fail(args[1]);
511
+
512
+ // Done `function`(s)
513
+ if (args.length && args[0])
514
+ this.done(args[0]);
515
+
516
+ return this;
517
+ },
518
+
519
+ isResolved : function() {
520
+ return this._status === "rs";
521
+ },
522
+
523
+ isRejected : function() {
524
+ return this._status === "rj";
525
+ },
526
+
527
+ reject : function() {
528
+ return this.rejectWith(this, arguments);
529
+ },
530
+
531
+ resolve : function() {
532
+ return this.resolveWith(this, arguments);
533
+ },
534
+
535
+ exec : function(context, dst, args, st) {
536
+ if (this._status !== "")
537
+ return this;
538
+
539
+ this._status = st;
540
+
541
+ can.each(dst, function(d){
542
+ d.apply(context, args);
543
+ });
544
+
545
+ return this;
546
+ }
547
+ });
548
+
549
+ // ##string.js
550
+ // _Miscellaneous string utility functions._
551
+
552
+ // Several of the methods in this plugin use code adapated from Prototype
553
+ // Prototype JavaScript framework, version 1.6.0.1.
554
+ // © 2005-2007 Sam Stephenson
555
+ var undHash = /_|-/,
556
+ colons = /==/,
557
+ words = /([A-Z]+)([A-Z][a-z])/g,
558
+ lowUp = /([a-z\d])([A-Z])/g,
559
+ dash = /([a-z\d])([A-Z])/g,
560
+ replacer = /\{([^\}]+)\}/g,
561
+ quote = /"/g,
562
+ singleQuote = /'/g,
563
+
564
+ // Returns the `prop` property from `obj`.
565
+ // If `add` is true and `prop` doesn't exist in `obj`, create it as an
566
+ // empty object.
567
+ getNext = function( obj, prop, add ) {
568
+ return prop in obj ?
569
+ obj[ prop ] :
570
+ ( add && ( obj[ prop ] = {} ));
571
+ },
572
+
573
+ // Returns `true` if the object can have properties (no `null`s).
574
+ isContainer = function( current ) {
575
+ return /^f|^o/.test( typeof current );
576
+ };
577
+
578
+ can.extend(can, {
579
+ // Escapes strings for HTML.
580
+ esc : function( content ) {
581
+ return ( "" + content )
582
+ .replace(/&/g, '&amp;')
583
+ .replace(/</g, '&lt;')
584
+ .replace(/>/g, '&gt;')
585
+ .replace(quote, '&#34;')
586
+ .replace(singleQuote, "&#39;");
587
+ },
588
+
589
+ getObject : function( name, roots, add ) {
590
+
591
+ // The parts of the name we are looking up
592
+ // `['App','Models','Recipe']`
593
+ var parts = name ? name.split('.') : [],
594
+ length = parts.length,
595
+ current,
596
+ r = 0,
597
+ ret, i;
598
+
599
+ // Make sure roots is an `array`.
600
+ roots = can.isArray(roots) ? roots : [roots || window];
601
+
602
+ if ( ! length ) {
603
+ return roots[0];
604
+ }
605
+
606
+ // For each root, mark it as current.
607
+ while( current = roots[r++] ) {
608
+
609
+ // Walk current to the 2nd to last object or until there
610
+ // is not a container.
611
+ for (i =0; i < length - 1 && isContainer( current ); i++ ) {
612
+ current = getNext( current, parts[i], add );
613
+ }
614
+
615
+ // If we can get a property from the 2nd to last object...
616
+ if( isContainer(current) ) {
617
+
618
+ // Get (and possibly set) the property.
619
+ ret = getNext(current, parts[i], add);
620
+
621
+ // If there is a value, we exit.
622
+ if ( ret !== undefined ) {
623
+ // If `add` is `false`, delete the property
624
+ if ( add === false ) {
625
+ delete current[parts[i]];
626
+ }
627
+ return ret;
628
+
629
+ }
630
+ }
631
+ }
632
+ },
633
+ // Capitalizes a string.
634
+ capitalize: function( s, cache ) {
635
+ // Used to make newId.
636
+ return s.charAt(0).toUpperCase() + s.slice(1);
637
+ },
638
+
639
+ // Underscores a string.
640
+ underscore: function( s ) {
641
+ return s
642
+ .replace(colons, '/')
643
+ .replace(words, '$1_$2')
644
+ .replace(lowUp, '$1_$2')
645
+ .replace(dash, '_')
646
+ .toLowerCase();
647
+ },
648
+ // Micro-templating.
649
+ sub: function( str, data, remove ) {
650
+
651
+ var obs = [];
652
+
653
+ obs.push( str.replace( replacer, function( whole, inside ) {
654
+
655
+ // Convert inside to type.
656
+ var ob = can.getObject( inside, data, remove === undefined? remove : !remove );
657
+
658
+ // If a container, push into objs (which will return objects found).
659
+ if ( isContainer( ob ) ) {
660
+ obs.push( ob );
661
+ return "";
662
+ } else {
663
+ return "" + ob;
664
+ }
665
+ }));
666
+
667
+ return obs.length <= 1 ? obs[0] : obs;
668
+ },
669
+
670
+ // These regex's are used throughout the rest of can, so let's make
671
+ // them available.
672
+ replacer : replacer,
673
+ undHash : undHash
674
+ });
675
+
676
+ // ## construct.js
677
+ // `can.Construct`
678
+ // _This is a modified version of
679
+ // [John Resig's class](http://ejohn.org/blog/simple-javascript-inheritance/).
680
+ // It provides class level inheritance and callbacks._
681
+
682
+ // A private flag used to initialize a new class instance without
683
+ // initializing it's bindings.
684
+ var initializing = 0;
685
+
686
+ can.Construct = function() {
687
+ if (arguments.length) {
688
+ return can.Construct.extend.apply(can.Construct, arguments);
689
+ }
690
+ };
691
+
692
+ can.extend(can.Construct, {
693
+ newInstance: function() {
694
+ // Get a raw instance object (`init` is not called).
695
+ var inst = this.instance(),
696
+ arg = arguments,
697
+ args;
698
+
699
+ // Call `setup` if there is a `setup`
700
+ if ( inst.setup ) {
701
+ args = inst.setup.apply(inst, arguments);
702
+ }
703
+
704
+ // Call `init` if there is an `init`
705
+ // If `setup` returned `args`, use those as the arguments
706
+ if ( inst.init ) {
707
+ inst.init.apply(inst, args || arguments);
708
+ }
709
+
710
+ return inst;
711
+ },
712
+ // Overwrites an object with methods. Used in the `super` plugin.
713
+ // `newProps` - New properties to add.
714
+ // `oldProps` - Where the old properties might be (used with `super`).
715
+ // `addTo` - What we are adding to.
716
+ _inherit: function( newProps, oldProps, addTo ) {
717
+ can.extend(addTo || newProps, newProps || {})
718
+ },
719
+ // used for overwriting a single property.
720
+ // this should be used for patching other objects
721
+ // the super plugin overwrites this
722
+ _overwrite : function(what, oldProps, propName, val){
723
+ what[propName] = val;
724
+ },
725
+ // Set `defaults` as the merger of the parent `defaults` and this
726
+ // object's `defaults`. If you overwrite this method, make sure to
727
+ // include option merging logic.
728
+ setup: function( base, fullName ) {
729
+ this.defaults = can.extend(true,{}, base.defaults, this.defaults);
730
+ },
731
+ // Create's a new `class` instance without initializing by setting the
732
+ // `initializing` flag.
733
+ instance: function() {
734
+
735
+ // Prevents running `init`.
736
+ initializing = 1;
737
+
738
+ var inst = new this();
739
+
740
+ // Allow running `init`.
741
+ initializing = 0;
742
+
743
+ return inst;
744
+ },
745
+ // Extends classes.
746
+ extend: function( fullName, klass, proto ) {
747
+ // Figure out what was passed and normalize it.
748
+ if ( typeof fullName != 'string' ) {
749
+ proto = klass;
750
+ klass = fullName;
751
+ fullName = null;
752
+ }
753
+
754
+ if ( ! proto ) {
755
+ proto = klass;
756
+ klass = null;
757
+ }
758
+ proto = proto || {};
759
+
760
+ var _super_class = this,
761
+ _super = this.prototype,
762
+ name, shortName, namespace, prototype;
763
+
764
+ // Instantiate a base class (but only create the instance,
765
+ // don't run the init constructor).
766
+ prototype = this.instance();
767
+
768
+ // Copy the properties over onto the new prototype.
769
+ can.Construct._inherit(proto, _super, prototype);
770
+
771
+ // The dummy class constructor.
772
+ function Constructor() {
773
+ // All construction is actually done in the init method.
774
+ if ( ! initializing ) {
775
+ return this.constructor !== Constructor && arguments.length ?
776
+ // We are being called without `new` or we are extending.
777
+ arguments.callee.extend.apply(arguments.callee, arguments) :
778
+ // We are being called with `new`.
779
+ this.constructor.newInstance.apply(this.constructor, arguments);
780
+ }
781
+ }
782
+
783
+ // Copy old stuff onto class (can probably be merged w/ inherit)
784
+ for ( name in _super_class ) {
785
+ if ( _super_class.hasOwnProperty(name) ) {
786
+ Constructor[name] = _super_class[name];
787
+ }
788
+ }
789
+
790
+ // Copy new static properties on class.
791
+ can.Construct._inherit(klass, _super_class, Constructor);
792
+
793
+ // Setup namespaces.
794
+ if ( fullName ) {
795
+
796
+ var parts = fullName.split('.'),
797
+ shortName = parts.pop(),
798
+ current = can.getObject(parts.join('.'), window, true),
799
+ namespace = current,
800
+ _fullName = can.underscore(fullName.replace(/\./g, "_")),
801
+ _shortName = can.underscore(shortName);
802
+
803
+ //@steal-remove-start
804
+ if(current[shortName]){
805
+
806
+ }
807
+ //@steal-remove-end
808
+
809
+ current[shortName] = Constructor;
810
+ }
811
+
812
+ // Set things that shouldn't be overwritten.
813
+ can.extend(Constructor, {
814
+ constructor: Constructor,
815
+ prototype: prototype,
816
+ namespace: namespace,
817
+ shortName: shortName,
818
+ _shortName : _shortName,
819
+ fullName: fullName,
820
+ _fullName: _fullName
821
+ });
822
+
823
+ // Make sure our prototype looks nice.
824
+ Constructor.prototype.constructor = Constructor;
825
+
826
+
827
+ // Call the class `setup` and `init`
828
+ var t = [_super_class].concat(can.makeArray(arguments)),
829
+ args = Constructor.setup.apply(Constructor, t );
830
+
831
+ if ( Constructor.init ) {
832
+ Constructor.init.apply(Constructor, args || t );
833
+ }
834
+
835
+ return Constructor;
836
+ //
837
+ //
838
+ }
839
+
840
+ });
841
+
842
+ // ## observe.js
843
+ // `can.Observe`
844
+ // _Provides the observable pattern for JavaScript Objects._
845
+ //
846
+ // Returns `true` if something is an object with properties of its own.
847
+ var canMakeObserve = function( obj ) {
848
+ return obj && typeof obj === 'object' && !(obj instanceof Date);
849
+ },
850
+
851
+ // Removes all listeners.
852
+ unhookup = function(items, namespace){
853
+ return can.each(items, function(item){
854
+ if(item && item.unbind){
855
+ item.unbind("change" + namespace);
856
+ }
857
+ });
858
+ },
859
+ // Listens to changes on `val` and "bubbles" the event up.
860
+ // `val` - The object to listen for changes on.
861
+ // `prop` - The property name is at on.
862
+ // `parent` - The parent object of prop.
863
+ hookupBubble = function( val, prop, parent ) {
864
+ // If it's an `array` make a list, otherwise a val.
865
+ if (val instanceof Observe){
866
+ // We have an `observe` already...
867
+ // Make sure it is not listening to this already
868
+ unhookup([val], parent._namespace);
869
+ } else if ( can.isArray(val) ) {
870
+ val = new Observe.List(val);
871
+ } else {
872
+ val = new Observe(val);
873
+ }
874
+
875
+ // Listen to all changes and `batchTrigger` upwards.
876
+ val.bind("change" + parent._namespace, function( ev, attr ) {
877
+ // `batchTrigger` the type on this...
878
+ var args = can.makeArray(arguments),
879
+ ev = args.shift();
880
+ args[0] = prop === "*" ?
881
+ parent.indexOf(val)+"." + args[0] :
882
+ prop + "." + args[0];
883
+ // track objects dispatched on this observe
884
+ ev.triggeredNS = ev.triggeredNS || {};
885
+ // if it has already been dispatched exit
886
+ if (ev.triggeredNS[parent._namespace]) {
887
+ return;
888
+ }
889
+ ev.triggeredNS[parent._namespace] = true;
890
+
891
+ can.trigger(parent, ev, args);
892
+ can.trigger(parent,args[0],args);
893
+ });
894
+
895
+ return val;
896
+ },
897
+
898
+ // An `id` to track events for a given observe.
899
+ observeId = 0,
900
+ // A reference to an `array` of events that will be dispatched.
901
+ collecting = undefined,
902
+ // Call to start collecting events (`Observe` sends all events at
903
+ // once).
904
+ collect = function() {
905
+ if (!collecting ) {
906
+ collecting = [];
907
+ return true;
908
+ }
909
+ },
910
+ // Creates an event on item, but will not send immediately
911
+ // if collecting events.
912
+ // `item` - The item the event should happen on.
913
+ // `event` - The event name, ex: `change`.
914
+ // `args` - Tn array of arguments.
915
+ batchTrigger = function( item, event, args ) {
916
+ // Don't send events if initalizing.
917
+ if ( ! item._init) {
918
+ if (!collecting ) {
919
+ return can.trigger(item, event, args);
920
+ } else {
921
+ collecting.push([
922
+ item,
923
+ {
924
+ type: event,
925
+ batchNum : batchNum
926
+ },
927
+ args ] );
928
+ }
929
+ }
930
+ },
931
+ // Which batch of events this is for -- might not want to send multiple
932
+ // messages on the same batch. This is mostly for event delegation.
933
+ batchNum = 1,
934
+ // Sends all pending events.
935
+ sendCollection = function() {
936
+ var items = collecting.slice(0);
937
+ collecting = undefined;
938
+ batchNum++;
939
+ can.each(items, function( item ) {
940
+ can.trigger.apply(can, item)
941
+ })
942
+
943
+ },
944
+ // A helper used to serialize an `Observe` or `Observe.List`.
945
+ // `observe` - The observable.
946
+ // `how` - To serialize with `attr` or `serialize`.
947
+ // `where` - To put properties, in an `{}` or `[]`.
948
+ serialize = function( observe, how, where ) {
949
+ // Go through each property.
950
+ observe.each(function( val, name ) {
951
+ // If the value is an `object`, and has an `attrs` or `serialize` function.
952
+ where[name] = canMakeObserve(val) && can.isFunction( val[how] ) ?
953
+ // Call `attrs` or `serialize` to get the original data back.
954
+ val[how]() :
955
+ // Otherwise return the value.
956
+ val
957
+ })
958
+ return where;
959
+ },
960
+ $method = function( name ) {
961
+ return function() {
962
+ return can[name].apply(this, arguments );
963
+ }
964
+ },
965
+ bind = $method('addEvent'),
966
+ unbind = $method('removeEvent'),
967
+ attrParts = function(attr){
968
+ return can.isArray(attr) ? attr : (""+attr).split(".")
969
+ };
970
+ var Observe = can.Construct('can.Observe', {
971
+ // keep so it can be overwritten
972
+ setup : function(){
973
+ can.Construct.setup.apply(this, arguments)
974
+ },
975
+ bind : bind,
976
+ unbind: unbind,
977
+ id: "id"
978
+ },
979
+ {
980
+ setup: function( obj ) {
981
+ // `_data` is where we keep the properties.
982
+ this._data = {};
983
+ // The namespace this `object` uses to listen to events.
984
+ this._namespace = ".observe" + (++observeId);
985
+ // Sets all `attrs`.
986
+ this._init = 1;
987
+ this.attr(obj);
988
+ delete this._init;
989
+ },
990
+ attr: function( attr, val ) {
991
+ // This is super obfuscated for space -- basically, we're checking
992
+ // if the type of the attribute is not a `number` or a `string`.
993
+ if ( !~ "ns".indexOf((typeof attr).charAt(0))) {
994
+ return this._attrs(attr, val)
995
+ } else if ( val === undefined ) {// If we are getting a value.
996
+ // Let people know we are reading.
997
+ Observe.__reading && Observe.__reading(this, attr)
998
+ return this._get(attr)
999
+ } else {
1000
+ // Otherwise we are setting.
1001
+ this._set(attr, val);
1002
+ return this;
1003
+ }
1004
+ },
1005
+ each: function() {
1006
+ return can.each.apply(undefined, [this.__get()].concat(can.makeArray(arguments)))
1007
+ },
1008
+ removeAttr: function( attr ) {
1009
+ // Convert the `attr` into parts (if nested).
1010
+ var parts = attrParts(attr),
1011
+ // The actual property to remove.
1012
+ prop = parts.shift(),
1013
+ // The current value.
1014
+ current = this._data[prop];
1015
+
1016
+ // If we have more parts, call `removeAttr` on that part.
1017
+ if ( parts.length ) {
1018
+ return current.removeAttr(parts)
1019
+ } else {
1020
+ // Otherwise, `delete`.
1021
+ delete this._data[prop];
1022
+ // Create the event.
1023
+ if (!(prop in this.constructor.prototype)) {
1024
+ delete this[prop]
1025
+ }
1026
+ batchTrigger(this, "change", [prop, "remove", undefined, current]);
1027
+ batchTrigger(this, prop, [undefined, current]);
1028
+ return current;
1029
+ }
1030
+ },
1031
+ // Reads a property from the `object`.
1032
+ _get: function( attr ) {
1033
+ var parts = attrParts(attr),
1034
+ current = this.__get(parts.shift());
1035
+ return parts.length ? current ? current._get(parts) : undefined : current;
1036
+ },
1037
+ // Reads a property directly if an `attr` is provided, otherwise
1038
+ // returns the "real" data object itself.
1039
+ __get: function( attr ) {
1040
+ return attr ? this._data[attr] : this._data;
1041
+ },
1042
+ // Sets `attr` prop as value on this object where.
1043
+ // `attr` - Is a string of properties or an array of property values.
1044
+ // `value` - The raw value to set.
1045
+ _set: function( attr, value ) {
1046
+ // Convert `attr` to attr parts (if it isn't already).
1047
+ var parts = attrParts(attr),
1048
+ // The immediate prop we are setting.
1049
+ prop = parts.shift(),
1050
+ // The current value.
1051
+ current = this.__get(prop);
1052
+
1053
+ // If we have an `object` and remaining parts.
1054
+ if ( canMakeObserve(current) && parts.length ) {
1055
+ // That `object` should set it (this might need to call attr).
1056
+ current._set(parts, value)
1057
+ } else if (!parts.length ) {
1058
+ // We're in "real" set territory.
1059
+ if(this.__convert){
1060
+ value = this.__convert(prop, value)
1061
+ }
1062
+ this.__set(prop, value, current)
1063
+
1064
+ } else {
1065
+ throw "can.Observe: Object does not exist"
1066
+ }
1067
+ },
1068
+ __set : function(prop, value, current){
1069
+
1070
+ // Otherwise, we are setting it on this `object`.
1071
+ // TODO: Check if value is object and transform
1072
+ // are we changing the value.
1073
+ if ( value !== current ) {
1074
+
1075
+ // Check if we are adding this for the first time --
1076
+ // if we are, we need to create an `add` event.
1077
+ var changeType = this.__get().hasOwnProperty(prop) ? "set" : "add";
1078
+
1079
+ // Set the value on data.
1080
+ this.___set(prop,
1081
+
1082
+ // If we are getting an object.
1083
+ canMakeObserve(value) ?
1084
+
1085
+ // Hook it up to send event.
1086
+ hookupBubble(value, prop, this) :
1087
+ // Value is normal.
1088
+ value);
1089
+
1090
+ // `batchTrigger` the change event.
1091
+ batchTrigger(this, "change", [prop, changeType, value, current]);
1092
+ batchTrigger(this, prop, [value, current]);
1093
+ // If we can stop listening to our old value, do it.
1094
+ current && unhookup([current], this._namespace);
1095
+ }
1096
+
1097
+ },
1098
+ // Directly sets a property on this `object`.
1099
+ ___set: function( prop, val ) {
1100
+ this._data[prop] = val;
1101
+ // Add property directly for easy writing.
1102
+ // Check if its on the `prototype` so we don't overwrite methods like `attrs`.
1103
+ if (!(prop in this.constructor.prototype)) {
1104
+ this[prop] = val
1105
+ }
1106
+ },
1107
+ bind: bind,
1108
+ unbind: unbind,
1109
+ serialize: function() {
1110
+ return serialize(this, 'serialize', {});
1111
+ },
1112
+ _attrs: function( props, remove ) {
1113
+ if ( props === undefined ) {
1114
+ return serialize(this, 'attr', {})
1115
+ }
1116
+
1117
+ props = can.extend(true, {}, props);
1118
+ var prop,
1119
+ collectingStarted = collect(),
1120
+ self = this,
1121
+ newVal;
1122
+
1123
+ this.each(function(curVal, prop){
1124
+ newVal = props[prop];
1125
+
1126
+ // If we are merging...
1127
+ if ( newVal === undefined ) {
1128
+ remove && self.removeAttr(prop);
1129
+ return;
1130
+ }
1131
+ if ( canMakeObserve(curVal) && canMakeObserve(newVal) ) {
1132
+ curVal.attr(newVal, remove)
1133
+ } else if ( curVal != newVal ) {
1134
+ self._set(prop, newVal)
1135
+ } else {
1136
+
1137
+ }
1138
+ delete props[prop];
1139
+ })
1140
+ // Add remaining props.
1141
+ for ( var prop in props ) {
1142
+ newVal = props[prop];
1143
+ this._set(prop, newVal)
1144
+ }
1145
+ if ( collectingStarted ) {
1146
+ sendCollection();
1147
+ }
1148
+ return this;
1149
+ }
1150
+ });
1151
+ // Helpers for `observable` lists.
1152
+ var splice = [].splice,
1153
+ list = Observe('can.Observe.List',
1154
+ {
1155
+ setup: function( instances, options ) {
1156
+ this.length = 0;
1157
+ this._namespace = ".observe" + (++observeId);
1158
+ this._init = 1;
1159
+ this.bind('change',can.proxy(this._changes,this));
1160
+ this.push.apply(this, can.makeArray(instances || []));
1161
+ can.extend(this, options);
1162
+ delete this._init;
1163
+ },
1164
+ _changes : function(ev, attr, how, newVal, oldVal){
1165
+ // `batchTrigger` direct add and remove events...
1166
+ if ( !~ attr.indexOf('.')){
1167
+
1168
+ if( how === 'add' ) {
1169
+ batchTrigger(this, how, [newVal,+attr]);
1170
+ batchTrigger(this,'length',[this.length]);
1171
+ } else if( how === 'remove' ) {
1172
+ batchTrigger(this, how, [oldVal, +attr]);
1173
+ batchTrigger(this,'length',[this.length]);
1174
+ } else {
1175
+ batchTrigger(this,how,[newVal, +attr])
1176
+ }
1177
+
1178
+ }
1179
+ },
1180
+ __get : function(attr){
1181
+ return attr ? this[attr] : this;
1182
+ },
1183
+ ___set : function(attr, val){
1184
+ this[attr] = val;
1185
+ if(+attr >= this.length){
1186
+ this.length = (+attr+1)
1187
+ }
1188
+ },
1189
+ // Returns the serialized form of this list.
1190
+ serialize: function() {
1191
+ return serialize(this, 'serialize', []);
1192
+ },
1193
+ //
1194
+ splice: function( index, howMany ) {
1195
+ var args = can.makeArray(arguments),
1196
+ i;
1197
+
1198
+ for ( i = 2; i < args.length; i++ ) {
1199
+ var val = args[i];
1200
+ if ( canMakeObserve(val) ) {
1201
+ args[i] = hookupBubble(val, "*", this)
1202
+ }
1203
+ }
1204
+ if ( howMany === undefined ) {
1205
+ howMany = args[1] = this.length - index;
1206
+ }
1207
+ var removed = splice.apply(this, args);
1208
+ if ( howMany > 0 ) {
1209
+ batchTrigger(this, "change", [""+index, "remove", undefined, removed]);
1210
+ unhookup(removed, this._namespace);
1211
+ }
1212
+ if ( args.length > 2 ) {
1213
+ batchTrigger(this, "change", [""+index, "add", args.slice(2), removed]);
1214
+ }
1215
+ return removed;
1216
+ },
1217
+ _attrs: function( props, remove ) {
1218
+ if ( props === undefined ) {
1219
+ return serialize(this, 'attr', []);
1220
+ }
1221
+
1222
+ // Create a copy.
1223
+ props = props.slice(0);
1224
+
1225
+ var len = Math.min(props.length, this.length),
1226
+ collectingStarted = collect(),
1227
+ prop;
1228
+
1229
+ for ( var prop = 0; prop < len; prop++ ) {
1230
+ var curVal = this[prop],
1231
+ newVal = props[prop];
1232
+
1233
+ if ( canMakeObserve(curVal) && canMakeObserve(newVal) ) {
1234
+ curVal.attr(newVal, remove)
1235
+ } else if ( curVal != newVal ) {
1236
+ this._set(prop, newVal)
1237
+ } else {
1238
+
1239
+ }
1240
+ }
1241
+ if ( props.length > this.length ) {
1242
+ // Add in the remaining props.
1243
+ this.push(props.slice(this.length))
1244
+ } else if ( props.length < this.length && remove ) {
1245
+ this.splice(props.length)
1246
+ }
1247
+
1248
+ if ( collectingStarted ) {
1249
+ sendCollection()
1250
+ }
1251
+ }
1252
+ }),
1253
+
1254
+ // Converts to an `array` of arguments.
1255
+ getArgs = function( args ) {
1256
+ return args[0] && can.isArray(args[0]) ?
1257
+ args[0] :
1258
+ can.makeArray(args);
1259
+ };
1260
+ // Create `push`, `pop`, `shift`, and `unshift`
1261
+ can.each({
1262
+ push: "length",
1263
+ unshift: 0
1264
+ },
1265
+ // Adds a method
1266
+ // `name` - The method name.
1267
+ // `where` - Where items in the `array` should be added.
1268
+ function( where, name ) {
1269
+ list.prototype[name] = function() {
1270
+ // Get the items being added.
1271
+ var args = getArgs(arguments),
1272
+ // Where we are going to add items.
1273
+ len = where ? this.length : 0;
1274
+
1275
+ // Go through and convert anything to an `observe` that needs to be converted.
1276
+ for ( var i = 0; i < args.length; i++ ) {
1277
+ var val = args[i];
1278
+ if ( canMakeObserve(val) ) {
1279
+ args[i] = hookupBubble(val, "*", this)
1280
+ }
1281
+ }
1282
+
1283
+ // Call the original method.
1284
+ var res = [][name].apply(this, args);
1285
+
1286
+ if ( !this.comparator || !args.length ) {
1287
+ batchTrigger(this, "change", [""+len, "add", args, undefined])
1288
+ }
1289
+
1290
+ return res;
1291
+ }
1292
+ });
1293
+
1294
+ can.each({
1295
+ pop: "length",
1296
+ shift: 0
1297
+ },
1298
+ // Creates a `remove` type method
1299
+ function( where, name ) {
1300
+ list.prototype[name] = function() {
1301
+
1302
+ var args = getArgs(arguments),
1303
+ len = where && this.length ? this.length - 1 : 0;
1304
+
1305
+ var res = [][name].apply(this, args)
1306
+
1307
+ // Create a change where the args are
1308
+ // `*` - Change on potentially multiple properties.
1309
+ // `remove` - Items removed.
1310
+ // `undefined` - The new values (there are none).
1311
+ // `res` - The old, removed values (should these be unbound).
1312
+ // `len` - Where these items were removed.
1313
+ batchTrigger(this, "change", [""+len, "remove", undefined, [res]])
1314
+
1315
+ if ( res && res.unbind ) {
1316
+ res.unbind("change" + this._namespace)
1317
+ }
1318
+ return res;
1319
+ }
1320
+ });
1321
+
1322
+ list.prototype.
1323
+ indexOf = [].indexOf || function(item){
1324
+ return can.inArray(item, this)
1325
+ };
1326
+
1327
+
1328
+ // ## model.js
1329
+ // `can.Model`
1330
+ // _A `can.Observe` that connects to a RESTful interface._
1331
+ //
1332
+ // Generic deferred piping function
1333
+ var pipe = function( def, model, func ) {
1334
+ var d = new can.Deferred();
1335
+ def.then(function(){
1336
+ arguments[0] = model[func](arguments[0])
1337
+ d.resolve.apply(d, arguments)
1338
+ },function(){
1339
+ d.rejectWith.apply(this,arguments)
1340
+ })
1341
+ return d;
1342
+ },
1343
+ modelNum = 0,
1344
+ ignoreHookup = /change.observe\d+/,
1345
+ getId = function( inst ) {
1346
+ return inst[inst.constructor.id]
1347
+ },
1348
+ // Ajax `options` generator function
1349
+ ajax = function( ajaxOb, data, type, dataType, success, error ) {
1350
+
1351
+
1352
+ // If we get a string, handle it.
1353
+ if ( typeof ajaxOb == "string" ) {
1354
+ // If there's a space, it's probably the type.
1355
+ var parts = ajaxOb.split(" ")
1356
+ ajaxOb = {
1357
+ url : parts.pop()
1358
+ };
1359
+ if(parts.length){
1360
+ ajaxOb.type = parts.pop();
1361
+ }
1362
+ }
1363
+
1364
+ // If we are a non-array object, copy to a new attrs.
1365
+ ajaxOb.data = typeof data == "object" && !can.isArray(data) ?
1366
+ can.extend(ajaxOb.data || {}, data) : data;
1367
+
1368
+
1369
+ // Get the url with any templated values filled out.
1370
+ ajaxOb.url = can.sub(ajaxOb.url, ajaxOb.data, true);
1371
+
1372
+ return can.ajax(can.extend({
1373
+ type: type || "post",
1374
+ dataType: dataType ||"json",
1375
+ success : success,
1376
+ error: error
1377
+ }, ajaxOb ));
1378
+ },
1379
+ makeRequest = function( self, type, success, error, method ) {
1380
+ var deferred ,
1381
+ args = [self.serialize()],
1382
+ // The model.
1383
+ model = self.constructor,
1384
+ jqXHR;
1385
+
1386
+ // `destroy` does not need data.
1387
+ if ( type == 'destroy' ) {
1388
+ args.shift();
1389
+ }
1390
+ // `update` and `destroy` need the `id`.
1391
+ if ( type !== 'create' ) {
1392
+ args.unshift(getId(self))
1393
+ }
1394
+
1395
+ jqXHR = model[type].apply(model, args);
1396
+
1397
+ deferred = jqXHR.pipe(function(data){
1398
+ self[method || type + "d"](data, jqXHR);
1399
+ return self
1400
+ })
1401
+
1402
+ // Hook up `abort`
1403
+ if(jqXHR.abort){
1404
+ deferred.abort = function(){
1405
+ jqXHR.abort();
1406
+ }
1407
+ }
1408
+
1409
+ return deferred.then(success,error);
1410
+ },
1411
+
1412
+ // This object describes how to make an ajax request for each ajax method.
1413
+ // The available properties are:
1414
+ // `url` - The default url to use as indicated as a property on the model.
1415
+ // `type` - The default http request type
1416
+ // `data` - A method that takes the `arguments` and returns `data` used for ajax.
1417
+ //
1418
+ //
1419
+ //
1420
+ ajaxMethods = {
1421
+ create : {
1422
+ url : "_shortName",
1423
+ type :"post"
1424
+ },
1425
+ update : {
1426
+ data : function(id, attrs){
1427
+ attrs = attrs || {};
1428
+ var identity = this.id;
1429
+ if ( attrs[identity] && attrs[identity] !== id ) {
1430
+ attrs["new" + can.capitalize(id)] = attrs[identity];
1431
+ delete attrs[identity];
1432
+ }
1433
+ attrs[identity] = id;
1434
+ return attrs;
1435
+ },
1436
+ type : "put"
1437
+ },
1438
+ destroy : {
1439
+ type : "delete",
1440
+ data : function(id){
1441
+ var args = {};
1442
+ args[this.id] = id;
1443
+ return args;
1444
+ }
1445
+ },
1446
+ findAll : {
1447
+ url : "_shortName"
1448
+ },
1449
+ findOne: {}
1450
+ },
1451
+ // Makes an ajax request `function` from a string.
1452
+ // `ajaxMethod` - The `ajaxMethod` object defined above.
1453
+ // `str` - The string the user provided. Ex: `findAll: "/recipes.json"`.
1454
+ ajaxMaker = function(ajaxMethod, str){
1455
+ // Return a `function` that serves as the ajax method.
1456
+ return function(data){
1457
+ // If the ajax method has it's own way of getting `data`, use that.
1458
+ data = ajaxMethod.data ?
1459
+ ajaxMethod.data.apply(this, arguments) :
1460
+ // Otherwise use the data passed in.
1461
+ data;
1462
+ // Return the ajax method with `data` and the `type` provided.
1463
+ return ajax(str || this[ajaxMethod.url || "_url"], data, ajaxMethod.type || "get")
1464
+ }
1465
+ }
1466
+
1467
+
1468
+
1469
+ can.Observe("can.Model",{
1470
+ setup : function(base){
1471
+ can.Observe.apply(this, arguments);
1472
+ if(this === can.Model){
1473
+ return;
1474
+ }
1475
+ var self = this,
1476
+ clean = can.proxy(this._clean, self);
1477
+
1478
+ can.each(ajaxMethods, function(method, name){
1479
+ if ( ! can.isFunction( self[name] )) {
1480
+ self[name] = ajaxMaker(method, self[name]);
1481
+ }
1482
+ if (self["make"+can.capitalize(name)]){
1483
+ var newMethod = self["make"+can.capitalize(name)](self[name]);
1484
+ can.Construct._overwrite(self, base, name,function(){
1485
+ this._super;
1486
+ this._reqs++;
1487
+ return newMethod.apply(this, arguments).then(clean, clean);
1488
+ })
1489
+ }
1490
+ });
1491
+
1492
+ if(!self.fullName || self.fullName == base.fullName){
1493
+ self.fullName = self._shortName = "Model"+(++modelNum);
1494
+ }
1495
+ // Ddd ajax converters.
1496
+ this.store = {};
1497
+ this._reqs = 0;
1498
+ this._url = this._shortName+"/{"+this.id+"}"
1499
+ },
1500
+ _ajax : ajaxMaker,
1501
+ _clean : function(){
1502
+ this._reqs--;
1503
+ if(!this._reqs){
1504
+ for(var id in this.store) {
1505
+ if(!this.store[id]._bindings){
1506
+ delete this.store[id];
1507
+ }
1508
+ }
1509
+ }
1510
+ },
1511
+ models: function( instancesRawData ) {
1512
+
1513
+ if ( ! instancesRawData ) {
1514
+ return;
1515
+ }
1516
+
1517
+ if ( instancesRawData instanceof this.List ) {
1518
+ return instancesRawData;
1519
+ }
1520
+
1521
+ // Get the list type.
1522
+ var self = this,
1523
+ res = new( self.List || ML),
1524
+ // Did we get an `array`?
1525
+ arr = can.isArray(instancesRawData),
1526
+
1527
+ // Did we get a model list?
1528
+ ml = (instancesRawData instanceof ML),
1529
+
1530
+ // Get the raw `array` of objects.
1531
+ raw = arr ?
1532
+
1533
+ // If an `array`, return the `array`.
1534
+ instancesRawData :
1535
+
1536
+ // Otherwise if a model list.
1537
+ (ml ?
1538
+
1539
+ // Get the raw objects from the list.
1540
+ instancesRawData.serialize() :
1541
+
1542
+ // Get the object's data.
1543
+ instancesRawData.data),
1544
+ i = 0;
1545
+
1546
+
1547
+
1548
+ can.each(raw, function( rawPart ) {
1549
+ res.push( self.model( rawPart ));
1550
+ });
1551
+
1552
+ if ( ! arr ) { // Push other stuff onto `array`.
1553
+ can.each(instancesRawData, function(val, prop){
1554
+ if ( prop !== 'data' ) {
1555
+ res[prop] = val;
1556
+ }
1557
+ })
1558
+ }
1559
+ return res;
1560
+ },
1561
+ model: function( attributes ) {
1562
+ if (!attributes ) {
1563
+ return;
1564
+ }
1565
+ if ( attributes instanceof this ) {
1566
+ attributes = attributes.serialize();
1567
+ }
1568
+ var model = this.store[attributes[this.id]] ? this.store[attributes[this.id]].attr(attributes) : new this( attributes );
1569
+ if(this._reqs){
1570
+ this.store[attributes[this.id]] = model;
1571
+ }
1572
+ return model;
1573
+ }
1574
+ },
1575
+ {
1576
+ isNew: function() {
1577
+ var id = getId(this);
1578
+ return ! ( id || id === 0 ); // If `null` or `undefined`
1579
+ },
1580
+ save: function( success, error ) {
1581
+ return makeRequest(this, this.isNew() ? 'create' : 'update', success, error);
1582
+ },
1583
+ destroy: function( success, error ) {
1584
+ return makeRequest(this, 'destroy', success, error, 'destroyed');
1585
+ },
1586
+ bind : function(eventName){
1587
+ if ( ! ignoreHookup.test( eventName )) {
1588
+ if ( ! this._bindings ) {
1589
+ this.constructor.store[getId(this)] = this;
1590
+ this._bindings = 0;
1591
+ }
1592
+ this._bindings++;
1593
+ }
1594
+
1595
+ return can.Observe.prototype.bind.apply( this, arguments );
1596
+ },
1597
+ unbind : function(eventName){
1598
+ if(!ignoreHookup.test(eventName)) {
1599
+ this._bindings--;
1600
+ if(!this._bindings){
1601
+ delete this.constructor.store[getId(this)];
1602
+ }
1603
+ }
1604
+ return can.Observe.prototype.unbind.apply(this, arguments);
1605
+ },
1606
+ // Change `id`.
1607
+ ___set: function( prop, val ) {
1608
+ can.Observe.prototype.___set.call(this,prop, val)
1609
+ // If we add an `id`, move it to the store.
1610
+ if(prop === this.constructor.id && this._bindings){
1611
+ this.constructor.store[getId(this)] = this;
1612
+ }
1613
+ }
1614
+ });
1615
+
1616
+
1617
+
1618
+
1619
+ can.each({makeFindAll : "models", makeFindOne: "model"}, function(method, name){
1620
+ can.Model[name] = function(oldFind){
1621
+ return function(params, success, error){
1622
+ return pipe( oldFind.call( this, params ),
1623
+ this,
1624
+ method ).then(success,error)
1625
+ }
1626
+ };
1627
+ });
1628
+
1629
+ can.each([
1630
+ "created",
1631
+ "updated",
1632
+ "destroyed"], function( funcName ) {
1633
+ can.Model.prototype[funcName] = function( attrs ) {
1634
+ var stub,
1635
+ constructor = this.constructor;
1636
+
1637
+ // Update attributes if attributes have been passed
1638
+ stub = attrs && typeof attrs == 'object' && this.attr(attrs.attr ? attrs.attr() : attrs);
1639
+
1640
+ // Call event on the instance
1641
+ can.trigger(this,funcName);
1642
+ can.trigger(this,"change",funcName)
1643
+
1644
+
1645
+ // Call event on the instance's Class
1646
+ can.trigger(constructor,funcName, this);
1647
+ };
1648
+ });
1649
+
1650
+ // Model lists are just like `Observe.List` except that when their items are
1651
+ // destroyed, it automatically gets removed from the list.
1652
+ var ML = can.Observe.List('can.Model.List',{
1653
+ setup : function(){
1654
+ can.Observe.List.prototype.setup.apply(this, arguments );
1655
+ // Send destroy events.
1656
+ var self = this;
1657
+ this.bind('change', function(ev, how){
1658
+ if(/\w+\.destroyed/.test(how)){
1659
+ self.splice(self.indexOf(ev.target),1);
1660
+ }
1661
+ })
1662
+ }
1663
+ })
1664
+
1665
+ ;
1666
+
1667
+
1668
+ // ## deparam.js
1669
+ // `can.deparam`
1670
+ // _Takes a string of name value pairs and returns a Object literal that represents those params._
1671
+ var digitTest = /^\d+$/,
1672
+ keyBreaker = /([^\[\]]+)|(\[\])/g,
1673
+ paramTest = /([^?#]*)(#.*)?$/,
1674
+ prep = function( str ) {
1675
+ return decodeURIComponent( str.replace(/\+/g, " ") );
1676
+ }
1677
+
1678
+
1679
+ can.extend(can, {
1680
+ deparam: function(params){
1681
+
1682
+ var data = {},
1683
+ pairs, lastPart;
1684
+
1685
+ if ( params && paramTest.test( params )) {
1686
+
1687
+ pairs = params.split('&'),
1688
+
1689
+ can.each( pairs, function( pair ) {
1690
+
1691
+ var parts = pair.split('='),
1692
+ key = prep( parts.shift() ),
1693
+ value = prep( parts.join("=") );
1694
+
1695
+ current = data;
1696
+ parts = key.match(keyBreaker);
1697
+
1698
+ for ( var j = 0, l = parts.length - 1; j < l; j++ ) {
1699
+ if (!current[parts[j]] ) {
1700
+ // If what we are pointing to looks like an `array`
1701
+ current[parts[j]] = digitTest.test(parts[j+1]) || parts[j+1] == "[]" ? [] : {}
1702
+ }
1703
+ current = current[parts[j]];
1704
+ }
1705
+ lastPart = parts.pop()
1706
+ if ( lastPart == "[]" ) {
1707
+ current.push(value)
1708
+ } else {
1709
+ current[lastPart] = value;
1710
+ }
1711
+ });
1712
+ }
1713
+ return data;
1714
+ }
1715
+ });
1716
+
1717
+ // ## route.js
1718
+ // `can.route`
1719
+ // _Helps manage browser history (and client state) by synchronizing the
1720
+ // `window.location.hash` with a `can.Observe`._
1721
+ //
1722
+ // Helper methods used for matching routes.
1723
+ var
1724
+ // `RegExp` used to match route variables of the type ':name'.
1725
+ // Any word character or a period is matched.
1726
+ matcher = /\:([\w\.]+)/g,
1727
+ // Regular expression for identifying &amp;key=value lists.
1728
+ paramsMatcher = /^(?:&[^=]+=[^&]*)+/,
1729
+ // Converts a JS Object into a list of parameters that can be
1730
+ // inserted into an html element tag.
1731
+ makeProps = function( props ) {
1732
+ var tags = [];
1733
+ can.each(props, function(val, name){
1734
+ tags.push( ( name === 'className' ? 'class' : name )+ '="' +
1735
+ (name === "href" ? val : can.esc(val) ) + '"');
1736
+ });
1737
+ return tags.join(" ");
1738
+ },
1739
+ // Checks if a route matches the data provided. If any route variable
1740
+ // is not present in the data, the route does not match. If all route
1741
+ // variables are present in the data, the number of matches is returned
1742
+ // to allow discerning between general and more specific routes.
1743
+ matchesData = function(route, data) {
1744
+ var count = 0, i = 0, defaults = {};
1745
+ // look at default values, if they match ...
1746
+ for( var name in route.defaults ) {
1747
+ if(route.defaults[name] === data[name]){
1748
+ // mark as matched
1749
+ defaults[name] = 1;
1750
+ count++;
1751
+ }
1752
+ }
1753
+ for (; i < route.names.length; i++ ) {
1754
+ if (!data.hasOwnProperty(route.names[i]) ) {
1755
+ return -1;
1756
+ }
1757
+ if(!defaults[route.names[i]]){
1758
+ count++;
1759
+ }
1760
+
1761
+ }
1762
+
1763
+ return count;
1764
+ },
1765
+ onready = !0,
1766
+ location = window.location,
1767
+ each = can.each,
1768
+ extend = can.extend;
1769
+
1770
+ can.route = function( url, defaults ) {
1771
+ defaults = defaults || {}
1772
+ // Extract the variable names and replace with `RegExp` that will match
1773
+ // an atual URL with values.
1774
+ var names = [],
1775
+ test = url.replace(matcher, function( whole, name, i ) {
1776
+ names.push(name);
1777
+ var next = "\\"+( url.substr(i+whole.length,1) || "&" )
1778
+ // a name without a default value HAS to have a value
1779
+ // a name that has a default value can be empty
1780
+ // The `\\` is for string-escaping giving single `\` for `RegExp` escaping.
1781
+ return "([^" +next+"]"+(defaults[name] ? "*" : "+")+")"
1782
+ });
1783
+
1784
+ // Add route in a form that can be easily figured out.
1785
+ can.route.routes[url] = {
1786
+ // A regular expression that will match the route when variable values
1787
+ // are present; i.e. for `:page/:type` the `RegExp` is `/([\w\.]*)/([\w\.]*)/` which
1788
+ // will match for any value of `:page` and `:type` (word chars or period).
1789
+ test: new RegExp("^" + test+"($|&)"),
1790
+ // The original URL, same as the index for this entry in routes.
1791
+ route: url,
1792
+ // An `array` of all the variable names in this route.
1793
+ names: names,
1794
+ // Default values provided for the variables.
1795
+ defaults: defaults,
1796
+ // The number of parts in the URL separated by `/`.
1797
+ length: url.split('/').length
1798
+ }
1799
+ return can.route;
1800
+ };
1801
+
1802
+ extend(can.route, {
1803
+ param: function( data , _setRoute ) {
1804
+ // Check if the provided data keys match the names in any routes;
1805
+ // Get the one with the most matches.
1806
+ var route,
1807
+ // Need to have at least 1 match.
1808
+ matches = 0,
1809
+ matchCount,
1810
+ routeName = data.route,
1811
+ propCount = 0;
1812
+
1813
+ delete data.route;
1814
+
1815
+ each(data, function(){propCount++});
1816
+ // Otherwise find route.
1817
+ each(can.route.routes, function(temp, name){
1818
+ // best route is the first with all defaults matching
1819
+
1820
+
1821
+ matchCount = matchesData(temp, data);
1822
+ if ( matchCount > matches ) {
1823
+ route = temp;
1824
+ matches = matchCount
1825
+ }
1826
+ if(matchCount >= propCount){
1827
+ return false;
1828
+ }
1829
+ });
1830
+ // If we have a route name in our `can.route` data, and it's
1831
+ // just as good as what currently matches, use that
1832
+ if (can.route.routes[routeName] && matchesData(can.route.routes[routeName], data ) === matches) {
1833
+ route = can.route.routes[routeName];
1834
+ }
1835
+ // If this is match...
1836
+ if ( route ) {
1837
+ var cpy = extend({}, data),
1838
+ // Create the url by replacing the var names with the provided data.
1839
+ // If the default value is found an empty string is inserted.
1840
+ res = route.route.replace(matcher, function( whole, name ) {
1841
+ delete cpy[name];
1842
+ return data[name] === route.defaults[name] ? "" : encodeURIComponent( data[name] );
1843
+ }),
1844
+ after;
1845
+ // Remove matching default values
1846
+ each(route.defaults, function(val,name){
1847
+ if(cpy[name] === val) {
1848
+ delete cpy[name]
1849
+ }
1850
+ })
1851
+
1852
+ // The remaining elements of data are added as
1853
+ // `&amp;` separated parameters to the url.
1854
+ after = can.param(cpy);
1855
+ // if we are paraming for setting the hash
1856
+ // we also want to make sure the route value is updated
1857
+ if(_setRoute){
1858
+ can.route.attr('route',route.route);
1859
+ }
1860
+ return res + (after ? "&" + after : "")
1861
+ }
1862
+ // If no route was found, there is no hash URL, only paramters.
1863
+ return can.isEmptyObject(data) ? "" : "&" + can.param(data);
1864
+ },
1865
+ deparam: function( url ) {
1866
+ // See if the url matches any routes by testing it against the `route.test` `RegExp`.
1867
+ // By comparing the URL length the most specialized route that matches is used.
1868
+ var route = {
1869
+ length: -1
1870
+ };
1871
+ each(can.route.routes, function(temp, name){
1872
+ if ( temp.test.test(url) && temp.length > route.length ) {
1873
+ route = temp;
1874
+ }
1875
+ });
1876
+ // If a route was matched.
1877
+ if ( route.length > -1 ) {
1878
+ var // Since `RegExp` backreferences are used in `route.test` (parens)
1879
+ // the parts will contain the full matched string and each variable (back-referenced) value.
1880
+ parts = url.match(route.test),
1881
+ // Start will contain the full matched string; parts contain the variable values.
1882
+ start = parts.shift(),
1883
+ // The remainder will be the `&amp;key=value` list at the end of the URL.
1884
+ remainder = url.substr(start.length - (parts[parts.length-1] === "&" ? 1 : 0) ),
1885
+ // If there is a remainder and it contains a `&amp;key=value` list deparam it.
1886
+ obj = (remainder && paramsMatcher.test(remainder)) ? can.deparam( remainder.slice(1) ) : {};
1887
+
1888
+ // Add the default values for this route.
1889
+ obj = extend(true, {}, route.defaults, obj);
1890
+ // Overwrite each of the default values in `obj` with those in
1891
+ // parts if that part is not empty.
1892
+ each(parts,function(part, i){
1893
+ if ( part && part !== '&') {
1894
+ obj[route.names[i]] = decodeURIComponent( part );
1895
+ }
1896
+ });
1897
+ obj.route = route.route;
1898
+ return obj;
1899
+ }
1900
+ // If no route was matched, it is parsed as a `&amp;key=value` list.
1901
+ if ( url.charAt(0) !== '&' ) {
1902
+ url = '&' + url;
1903
+ }
1904
+ return paramsMatcher.test(url) ? can.deparam( url.slice(1) ) : {};
1905
+ },
1906
+ data: new can.Observe({}),
1907
+ routes: {},
1908
+ ready: function(val) {
1909
+ if( val === false ) {
1910
+ onready = val;
1911
+ }
1912
+ if( val === true || onready === true ) {
1913
+ setState();
1914
+ }
1915
+ return can.route;
1916
+ },
1917
+ url: function( options, merge ) {
1918
+ if (merge) {
1919
+ options = extend({}, curParams, options)
1920
+ }
1921
+ return "#!" + can.route.param(options)
1922
+ },
1923
+ link: function( name, options, props, merge ) {
1924
+ return "<a " + makeProps(
1925
+ extend({
1926
+ href: can.route.url(options, merge)
1927
+ }, props)) + ">" + name + "</a>";
1928
+ },
1929
+ current: function( options ) {
1930
+ return location.hash == "#!" + can.route.param(options)
1931
+ }
1932
+ });
1933
+
1934
+
1935
+ // The functions in the following list applied to `can.route` (e.g. `can.route.attr('...')`) will
1936
+ // instead act on the `can.route.data` observe.
1937
+ each(['bind','unbind','delegate','undelegate','attr','removeAttr'], function(name){
1938
+ can.route[name] = function(){
1939
+ return can.route.data[name].apply(can.route.data, arguments)
1940
+ }
1941
+ })
1942
+
1943
+ var // A ~~throttled~~ debounced function called multiple times will only fire once the
1944
+ // timer runs down. Each call resets the timer.
1945
+ timer,
1946
+ // Intermediate storage for `can.route.data`.
1947
+ curParams,
1948
+ // Deparameterizes the portion of the hash of interest and assign the
1949
+ // values to the `can.route.data` removing existing values no longer in the hash.
1950
+ // setState is called typically by hashchange which fires asynchronously
1951
+ // So it's possible that someone started changing the data before the
1952
+ // hashchange event fired. For this reason, it will not set the route data
1953
+ // if the data is changing and the hash already matches the hash that was set.
1954
+ setState = function() {
1955
+ var hash = location.href.split(/#!?/)[1] || ""
1956
+ curParams = can.route.deparam( hash );
1957
+
1958
+
1959
+ // if the hash data is currently changing, and
1960
+ // the hash is what we set it to anyway, do NOT change the hash
1961
+ if(!changingData || hash !== lastHash){
1962
+ can.route.attr(curParams, true);
1963
+ }
1964
+ },
1965
+ // The last hash caused by a data change
1966
+ lastHash,
1967
+ // Are data changes pending that haven't yet updated the hash
1968
+ changingData;
1969
+
1970
+ // If the hash changes, update the `can.route.data`.
1971
+ can.bind.call(window,'hashchange', setState);
1972
+
1973
+ // If the `can.route.data` changes, update the hash.
1974
+ // Using `.serialize()` retrieves the raw data contained in the `observable`.
1975
+ // This function is ~~throttled~~ debounced so it only updates once even if multiple values changed.
1976
+ // This might be able to use batchNum and avoid this.
1977
+ can.route.bind("change", function(ev, attr) {
1978
+ // indicate that data is changing
1979
+ changingData = 1;
1980
+ clearTimeout( timer );
1981
+ timer = setTimeout(function() {
1982
+ // indicate that the hash is set to look like the data
1983
+ changingData = 0;
1984
+ var serialized = can.route.data.serialize();
1985
+ location.hash = "#!" + (lastHash = can.route.param(serialized, true))
1986
+ }, 1);
1987
+ });
1988
+ // `onready` event...
1989
+ can.bind.call(document,"ready",can.route.ready);
1990
+
1991
+ (function() {
1992
+
1993
+
1994
+ // ## control.js
1995
+ // `can.Control`
1996
+ // _Controller_
1997
+
1998
+ // Binds an element, returns a function that unbinds.
1999
+ var bind = function( el, ev, callback ) {
2000
+
2001
+ can.bind.call( el, ev, callback )
2002
+
2003
+ return function() {
2004
+ can.unbind.call(el, ev, callback);
2005
+ };
2006
+ },
2007
+ isFunction = can.isFunction,
2008
+ extend = can.extend,
2009
+ each = can.each,
2010
+ slice = [].slice,
2011
+ paramReplacer = /\{([^\}]+)\}/g,
2012
+ special = can.getObject("$.event.special") || {},
2013
+
2014
+ // Binds an element, returns a function that unbinds.
2015
+ delegate = function( el, selector, ev, callback ) {
2016
+ can.delegate.call(el, selector, ev, callback)
2017
+ return function() {
2018
+ can.undelegate.call(el, selector, ev, callback);
2019
+ };
2020
+ },
2021
+
2022
+ // Calls bind or unbind depending if there is a selector.
2023
+ binder = function( el, ev, callback, selector ) {
2024
+ return selector ?
2025
+ delegate( el, can.trim( selector ), ev, callback ) :
2026
+ bind( el, ev, callback );
2027
+ },
2028
+
2029
+ // Moves `this` to the first argument, wraps it with `jQuery` if it's an element
2030
+ shifter = function shifter(context, name) {
2031
+ var method = typeof name == "string" ? context[name] : name;
2032
+ if(!isFunction(method)){
2033
+ method = context[method];
2034
+ }
2035
+ return function() {
2036
+ context.called = name;
2037
+ return method.apply(context, [this.nodeName ? can.$(this) : this].concat( slice.call(arguments, 0)));
2038
+ };
2039
+ },
2040
+ basicProcessor;
2041
+
2042
+ can.Construct("can.Control",
2043
+ {
2044
+ // Setup pre-processes which methods are event listeners.
2045
+ setup: function() {
2046
+
2047
+ // Allow contollers to inherit "defaults" from super-classes as it
2048
+ // done in `can.Construct`
2049
+ can.Construct.setup.apply( this, arguments );
2050
+
2051
+ // If you didn't provide a name, or are `control`, don't do anything.
2052
+ if ( this !== can.Control ) {
2053
+
2054
+ // Cache the underscored names.
2055
+ var control = this,
2056
+ funcName;
2057
+
2058
+ // Calculate and cache actions.
2059
+ control.actions = {};
2060
+ for ( funcName in control.prototype ) {
2061
+ if ( control._isAction(funcName) ) {
2062
+ control.actions[funcName] = control._action(funcName);
2063
+ }
2064
+ }
2065
+ }
2066
+ },
2067
+ // Return `true` if is an action.
2068
+ _isAction: function( methodName ) {
2069
+
2070
+ var val = this.prototype[methodName],
2071
+ type = typeof val;
2072
+ // if not the constructor
2073
+ return (methodName !== 'constructor') &&
2074
+ // and is a function or links to a function
2075
+ ( type == "function" || (type == "string" && isFunction(this.prototype[val] ) ) ) &&
2076
+ // and is in special, a processor, or has a funny character
2077
+ !! ( special[methodName] || processors[methodName] || /[^\w]/.test(methodName) );
2078
+ },
2079
+ // Takes a method name and the options passed to a control
2080
+ // and tries to return the data necessary to pass to a processor
2081
+ // (something that binds things).
2082
+ _action: function( methodName, options ) {
2083
+
2084
+ // If we don't have options (a `control` instance), we'll run this
2085
+ // later.
2086
+ paramReplacer.lastIndex = 0;
2087
+ if ( options || ! paramReplacer.test( methodName )) {
2088
+ // If we have options, run sub to replace templates `{}` with a
2089
+ // value from the options or the window
2090
+ var convertedName = options ? can.sub(methodName, [options, window]) : methodName,
2091
+
2092
+ // If a `{}` resolves to an object, `convertedName` will be
2093
+ // an array
2094
+ arr = can.isArray(convertedName),
2095
+
2096
+ // Get the parts of the function
2097
+ // `[convertedName, delegatePart, eventPart]`
2098
+ // `/^(?:(.*?)\s)?([\w\.\:>]+)$/` - Breaker `RegExp`.
2099
+ parts = (arr ? convertedName[1] : convertedName).match(/^(?:(.*?)\s)?([\w\.\:>]+)$/);
2100
+
2101
+ var event = parts[2],
2102
+ processor = processors[event] || basicProcessor;
2103
+ return {
2104
+ processor: processor,
2105
+ parts: parts,
2106
+ delegate : arr ? convertedName[0] : undefined
2107
+ };
2108
+ }
2109
+ },
2110
+ // An object of `{eventName : function}` pairs that Control uses to
2111
+ // hook up events auto-magically.
2112
+ processors: {},
2113
+ // A object of name-value pairs that act as default values for a
2114
+ // control instance
2115
+ defaults: {}
2116
+ },
2117
+ {
2118
+ // Sets `this.element`, saves the control in `data, binds event
2119
+ // handlers.
2120
+ setup: function( element, options ) {
2121
+
2122
+ var cls = this.constructor,
2123
+ pluginname = cls.pluginName || cls._fullName,
2124
+ arr;
2125
+
2126
+ // Want the raw element here.
2127
+ this.element = can.$(element)
2128
+
2129
+ if ( pluginname && pluginname !== 'can_control') {
2130
+ // Set element and `className` on element.
2131
+ this.element.addClass(pluginname);
2132
+ }
2133
+
2134
+ (arr = can.data(this.element,"controls")) || can.data(this.element,"controls",arr = []);
2135
+ arr.push(this);
2136
+
2137
+ // Option merging.
2138
+ this.options = extend({}, cls.defaults, options);
2139
+
2140
+ // Bind all event handlers.
2141
+ this.on();
2142
+
2143
+ // Get's passed into `init`.
2144
+ return [this.element, this.options];
2145
+ },
2146
+ on: function( el, selector, eventName, func ) {
2147
+
2148
+ if ( ! el ) {
2149
+
2150
+ // Adds bindings.
2151
+ this.off();
2152
+
2153
+ // Go through the cached list of actions and use the processor
2154
+ // to bind
2155
+ var cls = this.constructor,
2156
+ bindings = this._bindings,
2157
+ actions = cls.actions,
2158
+ element = this.element,
2159
+ destroyCB = shifter(this,"destroy"),
2160
+ funcName, ready;
2161
+
2162
+ for ( funcName in actions ) {
2163
+ if ( actions.hasOwnProperty( funcName )) {
2164
+ ready = actions[funcName] || cls._action(funcName, this.options);
2165
+ bindings.push(
2166
+ ready.processor(ready.delegate || element,
2167
+ ready.parts[2],
2168
+ ready.parts[1],
2169
+ funcName,
2170
+ this));
2171
+ }
2172
+ }
2173
+
2174
+
2175
+ // Setup to be destroyed...
2176
+ // don't bind because we don't want to remove it.
2177
+ can.bind.call(element,"destroyed", destroyCB);
2178
+ bindings.push(function( el ) {
2179
+ can.unbind.call(el,"destroyed", destroyCB);
2180
+ });
2181
+ return bindings.length;
2182
+ }
2183
+
2184
+ if ( typeof el == 'string' ) {
2185
+ func = eventName;
2186
+ eventName = selector;
2187
+ selector = el;
2188
+ el = this.element;
2189
+ }
2190
+
2191
+ if ( typeof func == 'string' ) {
2192
+ func = shifter(this,func);
2193
+ }
2194
+
2195
+ this._bindings.push( binder( el, eventName, func, selector ));
2196
+
2197
+ return this._bindings.length;
2198
+ },
2199
+ // Unbinds all event handlers on the controller.
2200
+ off : function(){
2201
+ var el = this.element[0]
2202
+ each(this._bindings || [], function( value ) {
2203
+ value(el);
2204
+ });
2205
+ // Adds bindings.
2206
+ this._bindings = [];
2207
+ },
2208
+ // Prepares a `control` for garbage collection
2209
+ destroy: function() {
2210
+ var Class = this.constructor,
2211
+ pluginName = Class.pluginName || Class._fullName,
2212
+ controls;
2213
+
2214
+ // Unbind bindings.
2215
+ this.off();
2216
+
2217
+ if(pluginName && pluginName !== 'can_control'){
2218
+ // Remove the `className`.
2219
+ this.element.removeClass(pluginName);
2220
+ }
2221
+
2222
+ // Remove from `data`.
2223
+ controls = can.data(this.element,"controls");
2224
+ controls.splice(can.inArray(this, controls),1);
2225
+
2226
+ can.trigger( this, "destroyed"); // In case we want to know if the `control` is removed.
2227
+
2228
+ this.element = null;
2229
+ }
2230
+ });
2231
+
2232
+ var processors = can.Control.processors,
2233
+
2234
+ // Processors do the binding.
2235
+ // They return a function that unbinds when called.
2236
+ //
2237
+ // The basic processor that binds events.
2238
+ basicProcessor = function( el, event, selector, methodName, control ) {
2239
+ return binder( el, event, shifter(control, methodName), selector);
2240
+ };
2241
+
2242
+ // Set common events to be processed as a `basicProcessor`
2243
+ each(["change", "click", "contextmenu", "dblclick", "keydown", "keyup",
2244
+ "keypress", "mousedown", "mousemove", "mouseout", "mouseover",
2245
+ "mouseup", "reset", "resize", "scroll", "select", "submit", "focusin",
2246
+ "focusout", "mouseenter", "mouseleave"], function( v ) {
2247
+ processors[v] = basicProcessor;
2248
+ });
2249
+
2250
+ }());
2251
+
2252
+
2253
+ // ## control/route.js
2254
+ // _Controller route integration._
2255
+
2256
+ can.Control.processors.route = function( el, event, selector, funcName, controller ) {
2257
+ can.route( selector || "" )
2258
+ var batchNum,
2259
+ check = function( ev, attr, how ) {
2260
+ if ( can.route.attr('route') === ( selector || "" ) &&
2261
+ ( ev.batchNum === undefined || ev.batchNum !== batchNum ) ) {
2262
+
2263
+ batchNum = ev.batchNum;
2264
+
2265
+ var d = can.route.attr();
2266
+ delete d.route;
2267
+ if(can.isFunction(controller[funcName])){
2268
+ controller[funcName]( d )
2269
+ }else {
2270
+ controller[controller[funcName]](d)
2271
+ }
2272
+
2273
+ }
2274
+ }
2275
+ can.route.bind( 'change', check );
2276
+ return function() {
2277
+ can.route.unbind( 'change', check )
2278
+ }
2279
+ }
2280
+ ;
2281
+
2282
+ // ## view.js
2283
+ // `can.view`
2284
+ // _Templating abstraction._
2285
+
2286
+ var isFunction = can.isFunction,
2287
+ makeArray = can.makeArray,
2288
+ // Used for hookup `id`s.
2289
+ hookupId = 1,
2290
+ $view = can.view = function(view, data, helpers, callback){
2291
+ // Get the result.
2292
+ var result = $view.render(view, data, helpers, callback);
2293
+ if(can.isDeferred(result)){
2294
+ return result.pipe(function(result){
2295
+ return $view.frag(result);
2296
+ })
2297
+ }
2298
+
2299
+ // Convert it into a dom frag.
2300
+ return $view.frag(result);
2301
+ };
2302
+
2303
+ can.extend( $view, {
2304
+ // creates a frag and hooks it up all at once
2305
+ frag: function(result, parentNode ){
2306
+ return $view.hookup( $view.fragment(result), parentNode );
2307
+ },
2308
+ // simply creates a frag
2309
+ // this is used internally to create a frag
2310
+ // insert it
2311
+ // then hook it up
2312
+ fragment: function(result){
2313
+ var frag = can.buildFragment(result,document.body);
2314
+ // If we have an empty frag...
2315
+ if(!frag.childNodes.length) {
2316
+ frag.appendChild(document.createTextNode(''))
2317
+ }
2318
+ return frag;
2319
+ },
2320
+ // Convert a path like string into something that's ok for an `element` ID.
2321
+ toId : function( src ) {
2322
+ return can.map(src.toString().split(/\/|\./g), function( part ) {
2323
+ // Dont include empty strings in toId functions
2324
+ if ( part ) {
2325
+ return part;
2326
+ }
2327
+ }).join("_");
2328
+ },
2329
+ hookup: function(fragment, parentNode ){
2330
+ var hookupEls = [],
2331
+ id,
2332
+ func,
2333
+ el,
2334
+ i=0;
2335
+
2336
+ // Get all `childNodes`.
2337
+ can.each(fragment.childNodes ? can.makeArray(fragment.childNodes) : fragment, function(node){
2338
+ if(node.nodeType === 1){
2339
+ hookupEls.push(node)
2340
+ hookupEls.push.apply(hookupEls, can.makeArray( node.getElementsByTagName('*')))
2341
+ }
2342
+ });
2343
+ // Filter by `data-view-id` attribute.
2344
+ for (; el = hookupEls[i++]; ) {
2345
+
2346
+ if ( el.getAttribute && (id = el.getAttribute('data-view-id')) && (func = $view.hookups[id]) ) {
2347
+ func(el, parentNode, id);
2348
+ delete $view.hookups[id];
2349
+ el.removeAttribute('data-view-id');
2350
+ }
2351
+ }
2352
+ return fragment;
2353
+ },
2354
+ hookups: {},
2355
+ hook: function( cb ) {
2356
+ $view.hookups[++hookupId] = cb;
2357
+ return " data-view-id='"+hookupId+"'";
2358
+ },
2359
+ cached: {},
2360
+ cache: true,
2361
+ register: function( info ) {
2362
+ this.types["." + info.suffix] = info;
2363
+ },
2364
+ types: {},
2365
+ ext: ".ejs",
2366
+ registerScript: function() {},
2367
+ preload: function( ) {},
2368
+ render: function( view, data, helpers, callback ) {
2369
+ // If helpers is a `function`, it is actually a callback.
2370
+ if ( isFunction( helpers )) {
2371
+ callback = helpers;
2372
+ helpers = undefined;
2373
+ }
2374
+
2375
+ // See if we got passed any deferreds.
2376
+ var deferreds = getDeferreds(data);
2377
+
2378
+
2379
+ if ( deferreds.length ) { // Does data contain any deferreds?
2380
+ // The deferred that resolves into the rendered content...
2381
+ var deferred = new can.Deferred();
2382
+
2383
+ // Add the view request to the list of deferreds.
2384
+ deferreds.push(get(view, true))
2385
+
2386
+ // Wait for the view and all deferreds to finish...
2387
+ can.when.apply(can, deferreds).then(function( resolved ) {
2388
+ // Get all the resolved deferreds.
2389
+ var objs = makeArray(arguments),
2390
+ // Renderer is the last index of the data.
2391
+ renderer = objs.pop(),
2392
+ // The result of the template rendering with data.
2393
+ result;
2394
+
2395
+ // Make data look like the resolved deferreds.
2396
+ if ( can.isDeferred(data) ) {
2397
+ data = usefulPart(resolved);
2398
+ }
2399
+ else {
2400
+ // Go through each prop in data again and
2401
+ // replace the defferreds with what they resolved to.
2402
+ for ( var prop in data ) {
2403
+ if ( can.isDeferred(data[prop]) ) {
2404
+ data[prop] = usefulPart(objs.shift());
2405
+ }
2406
+ }
2407
+ }
2408
+ // Get the rendered result.
2409
+ result = renderer(data, helpers);
2410
+
2411
+ // Resolve with the rendered view.
2412
+ deferred.resolve(result);
2413
+ // If there's a `callback`, call it back with the result.
2414
+ callback && callback(result);
2415
+ });
2416
+ // Return the deferred...
2417
+ return deferred;
2418
+ }
2419
+ else {
2420
+ // No deferreds! Render this bad boy.
2421
+ var response,
2422
+ // If there's a `callback` function
2423
+ async = isFunction( callback ),
2424
+ // Get the `view` type
2425
+ deferred = get(view, async);
2426
+
2427
+ // If we are `async`...
2428
+ if ( async ) {
2429
+ // Return the deferred
2430
+ response = deferred;
2431
+ // And fire callback with the rendered result.
2432
+ deferred.then(function( renderer ) {
2433
+ callback(renderer(data, helpers))
2434
+ })
2435
+ } else {
2436
+ // Otherwise, the deferred is complete, so
2437
+ // set response to the result of the rendering.
2438
+ deferred.then(function( renderer ) {
2439
+ response = renderer(data, helpers);
2440
+ });
2441
+ }
2442
+
2443
+ return response;
2444
+ }
2445
+ }
2446
+ });
2447
+ // Returns `true` if something looks like a deferred.
2448
+ can.isDeferred = function( obj ) {
2449
+ return obj && isFunction(obj.then) && isFunction(obj.pipe) // Check if `obj` is a `can.Deferred`.
2450
+ }
2451
+ // Makes sure there's a template, if not, have `steal` provide a warning.
2452
+ var checkText = function( text, url ) {
2453
+ if ( ! text.length ) {
2454
+ //@steal-remove-start
2455
+ //@steal-remove-end
2456
+ throw "can.view: No template or empty template:" + url;
2457
+ }
2458
+ },
2459
+ // `Returns a `view` renderer deferred.
2460
+ // `url` - The url to the template.
2461
+ // `async` - If the ajax request should be asynchronous.
2462
+ // Returns a deferred.
2463
+ get = function( url, async ) {
2464
+
2465
+
2466
+ var suffix = url.match(/\.[\w\d]+$/),
2467
+ type,
2468
+ // If we are reading a script element for the content of the template,
2469
+ // `el` will be set to that script element.
2470
+ el,
2471
+ // A unique identifier for the view (used for caching).
2472
+ // This is typically derived from the element id or
2473
+ // the url for the template.
2474
+ id,
2475
+ // The ajax request used to retrieve the template content.
2476
+ jqXHR,
2477
+ // Used to generate the response.
2478
+ response = function( text ) {
2479
+ // Get the renderer function.
2480
+ var func = type.renderer(id, text),
2481
+ d = new can.Deferred();
2482
+ d.resolve(func)
2483
+ // Cache if we are caching.
2484
+ if ( $view.cache ) {
2485
+ $view.cached[id] = d;
2486
+ }
2487
+ // Return the objects for the response's `dataTypes`
2488
+ // (in this case view).
2489
+ return d;
2490
+ };
2491
+
2492
+ //If the url has a #, we assume we want to use an inline template
2493
+ //from a script element and not current page's HTML
2494
+ if( url.match(/^#/) ) {
2495
+ url = url.substr(1);
2496
+ }
2497
+ // If we have an inline template, derive the suffix from the `text/???` part.
2498
+ // This only supports `<script>` tags.
2499
+ if ( el = document.getElementById(url) ) {
2500
+ suffix = "."+el.type.match(/\/(x\-)?(.+)/)[2];
2501
+ }
2502
+
2503
+ // If there is no suffix, add one.
2504
+ if (!suffix && !$view.cached[url] ) {
2505
+ url += ( suffix = $view.ext );
2506
+ }
2507
+
2508
+ if ( can.isArray( suffix )) {
2509
+ suffix = suffix[0]
2510
+ }
2511
+
2512
+ // Convert to a unique and valid id.
2513
+ id = can.view.toId(url);
2514
+
2515
+ // If an absolute path, use `steal` to get it.
2516
+ // You should only be using `//` if you are using `steal`.
2517
+ if ( url.match(/^\/\//) ) {
2518
+ var sub = url.substr(2);
2519
+ url = ! window.steal ?
2520
+ "/" + sub :
2521
+ steal.root.mapJoin(sub);
2522
+ }
2523
+
2524
+ // Set the template engine type.
2525
+ type = $view.types[suffix];
2526
+
2527
+ // If it is cached,
2528
+ if ( $view.cached[id] ) {
2529
+ // Return the cached deferred renderer.
2530
+ return $view.cached[id];
2531
+
2532
+ // Otherwise if we are getting this from a `<script>` element.
2533
+ } else if ( el ) {
2534
+ // Resolve immediately with the element's `innerHTML`.
2535
+ return response(el.innerHTML);
2536
+ } else {
2537
+ // Make an ajax request for text.
2538
+ var d = new can.Deferred();
2539
+ can.ajax({
2540
+ async: async,
2541
+ url: url,
2542
+ dataType: "text",
2543
+ error: function(jqXHR) {
2544
+ checkText("", url);
2545
+ d.reject(jqXHR);
2546
+ },
2547
+ success: function( text ) {
2548
+ // Make sure we got some text back.
2549
+ checkText(text, url);
2550
+ d.resolve(type.renderer(id, text))
2551
+ // Cache if if we are caching.
2552
+ if ( $view.cache ) {
2553
+ $view.cached[id] = d;
2554
+ }
2555
+
2556
+ }
2557
+ });
2558
+ return d;
2559
+ }
2560
+ },
2561
+ // Gets an `array` of deferreds from an `object`.
2562
+ // This only goes one level deep.
2563
+ getDeferreds = function( data ) {
2564
+ var deferreds = [];
2565
+
2566
+ // pull out deferreds
2567
+ if ( can.isDeferred(data) ) {
2568
+ return [data]
2569
+ } else {
2570
+ for ( var prop in data ) {
2571
+ if ( can.isDeferred(data[prop]) ) {
2572
+ deferreds.push(data[prop]);
2573
+ }
2574
+ }
2575
+ }
2576
+ return deferreds;
2577
+ },
2578
+ // Gets the useful part of a resolved deferred.
2579
+ // This is for `model`s and `can.ajax` that resolve to an `array`.
2580
+ usefulPart = function( resolved ) {
2581
+ return can.isArray(resolved) && resolved[1] === 'success' ? resolved[0] : resolved
2582
+ };
2583
+
2584
+
2585
+ if ( window.steal ) {
2586
+ steal.type("view js", function( options, success, error ) {
2587
+ var type = can.view.types["." + options.type],
2588
+ id = can.view.toId(options.rootSrc);
2589
+
2590
+ options.text = "steal('" + (type.plugin || "can/view/" + options.type) + "').then(function($){" + "can.view.preload('" + id + "'," + options.text + ");\n})";
2591
+ success();
2592
+ })
2593
+ }
2594
+
2595
+ //!steal-pluginify-remove-start
2596
+ can.extend(can.view, {
2597
+ register: function( info ) {
2598
+ this.types["." + info.suffix] = info;
2599
+
2600
+ if ( window.steal ) {
2601
+ steal.type(info.suffix + " view js", function( options, success, error ) {
2602
+ var type = can.view.types["." + options.type],
2603
+ id = can.view.toId(options.rootSrc+'');
2604
+
2605
+ options.text = type.script(id, options.text)
2606
+ success();
2607
+ })
2608
+ }
2609
+ can.view[info.suffix] = function(id, text){
2610
+ $view.preload(id, info.renderer(id, text) )
2611
+ }
2612
+ },
2613
+ registerScript: function( type, id, src ) {
2614
+ return "can.view.preload('" + id + "'," + $view.types["." + type].script(id, src) + ");";
2615
+ },
2616
+ preload: function( id, renderer ) {
2617
+ can.view.cached[id] = new can.Deferred().resolve(function( data, helpers ) {
2618
+ return renderer.call(data, data, helpers);
2619
+ });
2620
+ }
2621
+
2622
+ });
2623
+ //!steal-pluginify-remove-end
2624
+
2625
+
2626
+ // returns the
2627
+ // - observes and attr methods are called by func
2628
+ // - the value returned by func
2629
+ // ex: `{value: 100, observed: [{obs: o, attr: "completed"}]}`
2630
+ var getValueAndObserved = function(func, self){
2631
+
2632
+ var oldReading;
2633
+ if (can.Observe) {
2634
+ // Set a callback on can.Observe to know
2635
+ // when an attr is read.
2636
+ // Keep a reference to the old reader
2637
+ // if there is one. This is used
2638
+ // for nested live binding.
2639
+ oldReading = can.Observe.__reading;
2640
+ can.Observe.__reading = function(obj, attr){
2641
+ // Add the observe and attr that was read
2642
+ // to `observed`
2643
+ observed.push({
2644
+ obj: obj,
2645
+ attr: attr
2646
+ });
2647
+ }
2648
+ }
2649
+
2650
+ var observed = [],
2651
+ // Call the "wrapping" function to get the value. `observed`
2652
+ // will have the observe/attribute pairs that were read.
2653
+ value = func.call(self);
2654
+
2655
+ // Set back so we are no longer reading.
2656
+ if(can.Observe){
2657
+ can.Observe.__reading = oldReading;
2658
+ }
2659
+ return {
2660
+ value : value,
2661
+ observed : observed
2662
+ }
2663
+ },
2664
+ // Calls `callback(newVal, oldVal)` everytime an observed property
2665
+ // called within `getterSetter` is changed and creates a new result of `getterSetter`.
2666
+ // Also returns an object that can teardown all event handlers.
2667
+ computeBinder = function(getterSetter, context, callback){
2668
+ // track what we are observing
2669
+ var observing = {},
2670
+ // a flag indicating if this observe/attr pair is already bound
2671
+ matched = true,
2672
+ // the data to return
2673
+ data = {
2674
+ // we will maintain the value while live-binding is taking place
2675
+ value : undefined,
2676
+ // a teardown method that stops listening
2677
+ teardown: function(){
2678
+ for ( var name in observing ) {
2679
+ var ob = observing[name];
2680
+ ob.observe.obj.unbind(ob.observe.attr, onchanged);
2681
+ delete observing[name];
2682
+ }
2683
+ }
2684
+ };
2685
+
2686
+ // when a property value is cahnged
2687
+ var onchanged = function(){
2688
+ // store the old value
2689
+ var oldValue = data.value,
2690
+ // get the new value
2691
+ newvalue = getValueAndBind();
2692
+ // update the value reference (in case someone reads)
2693
+ data.value = newvalue
2694
+ // if a change happened
2695
+ if(newvalue !== oldValue){
2696
+ callback(newvalue, oldValue);
2697
+ };
2698
+ };
2699
+
2700
+ // gets the value returned by `getterSetter` and also binds to any attributes
2701
+ // read by the call
2702
+ var getValueAndBind = function(){
2703
+ var info = getValueAndObserved( getterSetter, context ),
2704
+ newObserveSet = info.observed;
2705
+
2706
+ var value = info.value;
2707
+ matched = !matched;
2708
+
2709
+ // go through every attribute read by this observe
2710
+ can.each(newObserveSet, function(ob){
2711
+ // if the observe/attribute pair is being observed
2712
+ if(observing[ob.obj._namespace+"|"+ob.attr]){
2713
+ // mark at as observed
2714
+ observing[ob.obj._namespace+"|"+ob.attr].matched = matched;
2715
+ } else {
2716
+ // otherwise, set the observe/attribute on oldObserved, marking it as being observed
2717
+ observing[ob.obj._namespace+"|"+ob.attr] = {
2718
+ matched: matched,
2719
+ observe: ob
2720
+ };
2721
+ ob.obj.bind(ob.attr, onchanged)
2722
+ }
2723
+ });
2724
+
2725
+ // Iterate through oldObserved, looking for observe/attributes
2726
+ // that are no longer being bound and unbind them
2727
+ for ( var name in observing ) {
2728
+ var ob = observing[name];
2729
+ if(ob.matched !== matched){
2730
+ ob.observe.obj.unbind(ob.observe.attr, onchanged);
2731
+ delete observing[name];
2732
+ }
2733
+ }
2734
+ return value;
2735
+ }
2736
+ // set the initial value
2737
+ data.value = getValueAndBind();
2738
+ data.isListening = ! can.isEmptyObject(observing);
2739
+ return data;
2740
+ }
2741
+
2742
+ // if no one is listening ... we can not calculate every time
2743
+ can.compute = function(getterSetter, context){
2744
+ if(getterSetter.isComputed){
2745
+ return getterSetter;
2746
+ }
2747
+ // get the value right away
2748
+ // TODO: eventually we can defer this until a bind or a read
2749
+ var computedData,
2750
+ bindings = 0,
2751
+ computed,
2752
+ canbind = true;
2753
+ if(typeof getterSetter === "function"){
2754
+ computed = function(value){
2755
+ if(value === undefined){
2756
+ // we are reading
2757
+ if(computedData){
2758
+ return computedData.value;
2759
+ } else {
2760
+ return getterSetter.call(context || this)
2761
+ }
2762
+ } else {
2763
+ return getterSetter.apply(context || this, arguments)
2764
+ }
2765
+ }
2766
+
2767
+ } else {
2768
+ // we just gave it a value
2769
+ computed = function(val){
2770
+ if(val === undefined){
2771
+ return getterSetter;
2772
+ } else {
2773
+ var old = getterSetter;
2774
+ getterSetter = val;
2775
+ if( old !== val){
2776
+ can.trigger(computed, "change",[val, old]);
2777
+ }
2778
+
2779
+ return val;
2780
+ }
2781
+
2782
+ }
2783
+ canbind = false;
2784
+ }
2785
+ computed.isComputed = true;
2786
+
2787
+
2788
+ computed.bind = function(ev, handler){
2789
+ can.addEvent.apply(computed, arguments);
2790
+ if( bindings === 0 && canbind){
2791
+ // setup live-binding
2792
+ computedData = computeBinder(getterSetter, context || this, function(newValue, oldValue){
2793
+ can.trigger(computed, "change",[newValue, oldValue])
2794
+ });
2795
+ }
2796
+ bindings++;
2797
+ }
2798
+ computed.unbind = function(ev, handler){
2799
+ can.removeEvent.apply(computed, arguments);
2800
+ bindings--;
2801
+ if( bindings === 0 && canbind){
2802
+ computedData.teardown();
2803
+ }
2804
+
2805
+ };
2806
+ return computed;
2807
+ };
2808
+ can.compute.binder = computeBinder;
2809
+
2810
+ // ## ejs.js
2811
+ // `can.EJS`
2812
+ // _Embedded JavaScript Templates._
2813
+
2814
+ // Helper methods.
2815
+ var myEval = function( script ) {
2816
+ eval(script);
2817
+ },
2818
+ extend = can.extend,
2819
+ // Regular expressions for caching.
2820
+ quickFunc = /\s*\(([\$\w]+)\)\s*->([^\n]*)/,
2821
+ attrReg = /([^\s]+)=$/,
2822
+ newLine = /(\r|\n)+/g,
2823
+ attributeReplace = /__!!__/g,
2824
+ tagMap = {
2825
+ "": "span",
2826
+ table: "tr",
2827
+ tr: "td",
2828
+ ol: "li",
2829
+ ul: "li",
2830
+ tbody: "tr",
2831
+ thead: "tr",
2832
+ tfoot: "tr"
2833
+ },
2834
+ // Escapes characters starting with `\`.
2835
+ clean = function( content ) {
2836
+ return content
2837
+ .split('\\').join("\\\\")
2838
+ .split("\n").join("\\n")
2839
+ .split('"').join('\\"')
2840
+ .split("\t").join("\\t");
2841
+ },
2842
+ bracketNum = function(content){
2843
+ return (--content.split("{").length) - (--content.split("}").length);
2844
+ },
2845
+ // Cross-browser attribute methods.
2846
+ // These should be mapped to the underlying library.
2847
+ attrMap = {
2848
+ "class" : "className"
2849
+ },
2850
+ bool = can.each(["checked","disabled","readonly","required"], function(n){
2851
+ attrMap[n] = n;
2852
+ }),
2853
+ setAttr = function(el, attrName, val){
2854
+ attrMap[attrName] ?
2855
+ (el[attrMap[attrName]] = can.inArray(attrName,bool) > -1? true : val):
2856
+ el.setAttribute(attrName, val);
2857
+ },
2858
+ getAttr = function(el, attrName){
2859
+ return attrMap[attrName]?
2860
+ el[attrMap[attrName]]:
2861
+ el.getAttribute(attrName);
2862
+ },
2863
+ removeAttr = function(el, attrName){
2864
+ if(can.inArray(attrName,bool) > -1){
2865
+ el[attrName] = false;
2866
+ } else{
2867
+ el.removeAttribute(attrName)
2868
+ }
2869
+ },
2870
+ // a helper to get the parentNode for a given element el
2871
+ // if el is in a documentFragment, it will return defaultParentNode
2872
+ getParentNode = function(el, defaultParentNode){
2873
+ return defaultParentNode && el.parentNode.nodeType === 11 ? defaultParentNode : el.parentNode;
2874
+ },
2875
+ // helper to know if property is not an expando on oldObserved's list of observes
2876
+ // this should probably be removed and oldObserved should just have a
2877
+ // property with observes
2878
+ observeProp = function(name){
2879
+ return name.indexOf("|") >= 0;
2880
+ },
2881
+ // Returns escaped/sanatized content for anything other than a live-binding
2882
+ contentEscape = function( txt ) {
2883
+ return (typeof txt == 'string' || typeof txt == 'number') ?
2884
+ can.esc( txt ) :
2885
+ contentText(txt);
2886
+ },
2887
+ // Returns text content for anything other than a live-binding
2888
+ contentText = function( input ) {
2889
+
2890
+ // If it's a string, return.
2891
+ if ( typeof input == 'string' ) {
2892
+ return input;
2893
+ }
2894
+ // If has no value, return an empty string.
2895
+ if ( !input && input != 0 ) {
2896
+ return '';
2897
+ }
2898
+
2899
+ // If it's an object, and it has a hookup method.
2900
+ var hook = (input.hookup &&
2901
+
2902
+ // Make a function call the hookup method.
2903
+ function( el, id ) {
2904
+ input.hookup.call(input, el, id);
2905
+ }) ||
2906
+
2907
+ // Or if it's a `function`, just use the input.
2908
+ (typeof input == 'function' && input);
2909
+
2910
+ // Finally, if there is a `function` to hookup on some dom,
2911
+ // add it to pending hookups.
2912
+ if ( hook ) {
2913
+ pendingHookups.push(hook);
2914
+ return '';
2915
+ }
2916
+
2917
+ // Finally, if all else is `false`, `toString()` it.
2918
+ return "" + input;
2919
+ },
2920
+ // The EJS constructor function
2921
+ EJS = function( options ) {
2922
+ // Supports calling EJS without the constructor
2923
+ // This returns a function that renders the template.
2924
+ if ( this.constructor != EJS ) {
2925
+ var ejs = new EJS(options);
2926
+ return function( data, helpers ) {
2927
+ return ejs.render(data, helpers);
2928
+ };
2929
+ }
2930
+ // If we get a `function` directly, it probably is coming from
2931
+ // a `steal`-packaged view.
2932
+ if ( typeof options == "function" ) {
2933
+ this.template = {
2934
+ fn: options
2935
+ };
2936
+ return;
2937
+ }
2938
+ // Set options on self.
2939
+ extend(this, options);
2940
+ this.template = scan(this.text, this.name);
2941
+ };
2942
+
2943
+ can.EJS = EJS;
2944
+ EJS.prototype.
2945
+ render = function( object, extraHelpers ) {
2946
+ object = object || {};
2947
+ return this.template.fn.call(object, object, new EJS.Helpers(object, extraHelpers || {}));
2948
+ };
2949
+ extend(EJS, {
2950
+ // Called to return the content within a magic tag like `<%= %>`.
2951
+ // - escape - if the content returned should be escaped
2952
+ // - tagName - the tag name the magic tag is within or the one that proceeds the magic tag
2953
+ // - status - where the tag is in. The status can be:
2954
+ // - _STRING_ - The name of the attribute the magic tag is within
2955
+ // - `1` - The magic tag is within a tag like `<div <%= %>>`
2956
+ // - `0` - The magic tag is outside (or between) tags like `<div><%= %></div>`
2957
+ // - self - the `this` the template was called with
2958
+ // - func - the "wrapping" function. For example: `<%= task.attr('name') %>` becomes
2959
+ // `(function(){return task.attr('name')})
2960
+ txt : function(escape, tagName, status, self, func){
2961
+ // call the "wrapping" function and get the binding information
2962
+ var binding = can.compute.binder(func, self, function(newVal, oldVal){
2963
+ // call the update method we will define for each
2964
+ // type of attribute
2965
+ update(newVal, oldVal)
2966
+ });
2967
+
2968
+ // If we had no observes just return the value returned by func.
2969
+ if(!binding.isListening){
2970
+ return (escape || status !== 0? contentEscape : contentText)(binding.value);
2971
+ }
2972
+ // The following are helper methods or varaibles that will
2973
+ // be defined by one of the various live-updating schemes.
2974
+
2975
+ // The parent element we are listening to for teardown
2976
+ var parentElement,
2977
+ // if the parent element is removed, teardown the binding
2978
+ setupTeardownOnDestroy = function(el){
2979
+ can.bind.call(el,'destroyed', binding.teardown)
2980
+ parentElement = el;
2981
+ },
2982
+ // if there is no parent, undo bindings
2983
+ teardownCheck = function(parent){
2984
+ if(!parent){
2985
+ binding.teardown();
2986
+ can.unbind.call(parentElement,'destroyed', binding.teardown)
2987
+ }
2988
+ },
2989
+ // the tag type to insert
2990
+ tag = (tagMap[tagName] || "span"),
2991
+ // this will be filled in if binding.isListening
2992
+ update;
2993
+
2994
+
2995
+ // The magic tag is outside or between tags.
2996
+ if(status == 0){
2997
+ // Return an element tag with a hookup in place of the content
2998
+ return "<" +tag+can.view.hook(
2999
+ escape ?
3000
+ // If we are escaping, replace the parentNode with
3001
+ // a text node who's value is `func`'s return value.
3002
+ function(el, parentNode){
3003
+ // updates the text of the text node
3004
+ update = function(newVal){
3005
+ node.nodeValue = ""+newVal;
3006
+ teardownCheck(node.parentNode);
3007
+ };
3008
+
3009
+ var parent = getParentNode(el, parentNode),
3010
+ node = document.createTextNode(binding.value);
3011
+
3012
+ parent.insertBefore(node, el);
3013
+ parent.removeChild(el);
3014
+ setupTeardownOnDestroy(parent);
3015
+ }
3016
+ :
3017
+ // If we are not escaping, replace the parentNode with a
3018
+ // documentFragment created as with `func`'s return value.
3019
+ function(span, parentNode){
3020
+ // updates the elements with the new content
3021
+ update = function(newVal){
3022
+ // is this still part of the DOM?
3023
+ var attached = nodes[0].parentNode;
3024
+ // update the nodes in the DOM with the new rendered value
3025
+ if( attached ) {
3026
+ nodes = makeAndPut(newVal, nodes);
3027
+ }
3028
+ teardownCheck(nodes[0].parentNode)
3029
+ }
3030
+
3031
+ // make sure we have a valid parentNode
3032
+ parentNode = getParentNode(span, parentNode)
3033
+ // A helper function to manage inserting the contents
3034
+ // and removing the old contents
3035
+ var makeAndPut = function(val, remove){
3036
+ // create the fragment, but don't hook it up
3037
+ // we need to insert it into the document first
3038
+
3039
+ var frag = can.view.frag(val, parentNode),
3040
+ // keep a reference to each node
3041
+ nodes = can.map(frag.childNodes,function(node){
3042
+ return node;
3043
+ }),
3044
+ last = remove[remove.length - 1];
3045
+
3046
+ // Insert it in the `document` or `documentFragment`
3047
+ if( last.nextSibling ){
3048
+ last.parentNode.insertBefore(frag, last.nextSibling)
3049
+ } else {
3050
+ last.parentNode.appendChild(frag)
3051
+ }
3052
+ // Remove the old content.
3053
+ can.remove( can.$(remove) );
3054
+
3055
+ return nodes;
3056
+ },
3057
+ // nodes are the nodes that any updates will replace
3058
+ // at this point, these nodes could be part of a documentFragment
3059
+ nodes = makeAndPut(binding.value, [span]);
3060
+
3061
+
3062
+ setupTeardownOnDestroy(parentNode);
3063
+
3064
+ }) + "></" +tag+">";
3065
+ // In a tag, but not in an attribute
3066
+ } else if(status === 1){
3067
+ // remember the old attr name
3068
+ var attrName = binding.value.replace(/['"]/g, '').split('=')[0];
3069
+ pendingHookups.push(function(el) {
3070
+ update = function(newVal){
3071
+ var parts = (newVal|| "").replace(/['"]/g, '').split('='),
3072
+ newAttrName = parts[0];
3073
+
3074
+ // Remove if we have a change and used to have an `attrName`.
3075
+ if((newAttrName != attrName) && attrName){
3076
+ removeAttr(el,attrName)
3077
+ }
3078
+ // Set if we have a new `attrName`.
3079
+ if(newAttrName){
3080
+ setAttr(el, newAttrName, parts[1]);
3081
+ attrName = newAttrName;
3082
+ }
3083
+ }
3084
+ setupTeardownOnDestroy(el);
3085
+ });
3086
+
3087
+ return binding.value;
3088
+ } else { // In an attribute...
3089
+ pendingHookups.push(function(el){
3090
+ // update will call this attribute's render method
3091
+ // and set the attribute accordingly
3092
+ update = function(){
3093
+ setAttr(el, status, hook.render())
3094
+ }
3095
+
3096
+ var wrapped = can.$(el),
3097
+ hooks;
3098
+
3099
+ // Get the list of hookups or create one for this element.
3100
+ // Hooks is a map of attribute names to hookup `data`s.
3101
+ // Each hookup data has:
3102
+ // `render` - A `function` to render the value of the attribute.
3103
+ // `funcs` - A list of hookup `function`s on that attribute.
3104
+ // `batchNum` - The last event `batchNum`, used for performance.
3105
+ (hooks = can.data(wrapped,'hooks')) || can.data(wrapped, 'hooks', hooks = {});
3106
+
3107
+ // Get the attribute value.
3108
+ var attr = getAttr(el, status),
3109
+ // Split the attribute value by the template.
3110
+ parts = attr.split("__!!__"),
3111
+ hook;
3112
+
3113
+
3114
+ // If we already had a hookup for this attribute...
3115
+ if(hooks[status]) {
3116
+ // Just add to that attribute's list of `function`s.
3117
+ hooks[status].bindings.push(binding);
3118
+ }
3119
+ else {
3120
+ // Create the hookup data.
3121
+ hooks[status] = {
3122
+ render: function() {
3123
+ var i =0,
3124
+ newAttr = attr.replace(attributeReplace, function() {
3125
+ return contentText( hook.bindings[i++].value );
3126
+ });
3127
+ return newAttr;
3128
+ },
3129
+ bindings: [binding],
3130
+ batchNum : undefined
3131
+ };
3132
+ };
3133
+
3134
+ // Save the hook for slightly faster performance.
3135
+ hook = hooks[status];
3136
+
3137
+ // Insert the value in parts.
3138
+ parts.splice(1,0,binding.value);
3139
+
3140
+ // Set the attribute.
3141
+ setAttr(el, status, parts.join(""));
3142
+
3143
+ // Bind on change.
3144
+ //liveBind(observed, el, binder,oldObserved);
3145
+ setupTeardownOnDestroy(el)
3146
+ })
3147
+ return "__!!__";
3148
+ }
3149
+ },
3150
+ pending: function() {
3151
+ if(pendingHookups.length) {
3152
+ var hooks = pendingHookups.slice(0);
3153
+
3154
+ pendingHookups = [];
3155
+ return can.view.hook(function(el){
3156
+ can.each(hooks, function(fn){
3157
+ fn(el);
3158
+ })
3159
+ });
3160
+ }else {
3161
+ return "";
3162
+ }
3163
+ }
3164
+ });
3165
+ // Start scanning code.
3166
+ var tokenReg = new RegExp("(" +[ "<%%", "%%>", "<%==", "<%=",
3167
+ "<%#", "<%", "%>", "<", ">", '"', "'"].join("|")+")","g"),
3168
+ // Commands for caching.
3169
+ startTxt = 'var ___v1ew = [];',
3170
+ finishTxt = "return ___v1ew.join('')",
3171
+ put_cmd = "___v1ew.push(",
3172
+ insert_cmd = put_cmd,
3173
+ // Global controls (used by other functions to know where we are).
3174
+ //
3175
+ // Are we inside a tag?
3176
+ htmlTag = null,
3177
+ // Are we within a quote within a tag?
3178
+ quote = null,
3179
+ // What was the text before the current quote? (used to get the `attr` name)
3180
+ beforeQuote = null,
3181
+ // Used to mark where the element is.
3182
+ status = function(){
3183
+ // `t` - `1`.
3184
+ // `h` - `0`.
3185
+ // `q` - String `beforeQuote`.
3186
+ return quote ? "'"+beforeQuote.match(attrReg)[1]+"'" : (htmlTag ? 1 : 0)
3187
+ },
3188
+ pendingHookups = [],
3189
+ scan = function(source, name){
3190
+ var tokens = [],
3191
+ last = 0;
3192
+
3193
+ source = source.replace(newLine, "\n");
3194
+ source.replace(tokenReg, function(whole, part, offset){
3195
+ // if the next token starts after the last token ends
3196
+ // push what's in between
3197
+ if(offset > last){
3198
+ tokens.push( source.substring(last, offset) );
3199
+ }
3200
+ // push the token
3201
+ tokens.push(part);
3202
+ // update the position of the last part of the last token
3203
+ last = offset+part.length;
3204
+ })
3205
+ // if there's something at the end, add it
3206
+ if(last < source.length){
3207
+ tokens.push(source.substr(last))
3208
+ }
3209
+
3210
+ var content = '',
3211
+ buff = [startTxt],
3212
+ // Helper `function` for putting stuff in the view concat.
3213
+ put = function( content, bonus ) {
3214
+ buff.push(put_cmd, '"', clean(content), '"'+(bonus||'')+');');
3215
+ },
3216
+ // A stack used to keep track of how we should end a bracket
3217
+ // `}`.
3218
+ // Once we have a `<%= %>` with a `leftBracket`,
3219
+ // we store how the file should end here (either `))` or `;`).
3220
+ endStack =[],
3221
+ // The last token, used to remember which tag we are in.
3222
+ lastToken,
3223
+ // The corresponding magic tag.
3224
+ startTag = null,
3225
+ // Was there a magic tag inside an html tag?
3226
+ magicInTag = false,
3227
+ // The current tag name.
3228
+ tagName = '',
3229
+ // stack of tagNames
3230
+ tagNames = [],
3231
+ // Declared here.
3232
+ bracketCount,
3233
+ i = 0,
3234
+ token;
3235
+
3236
+ // Reinitialize the tag state goodness.
3237
+ htmlTag = quote = beforeQuote = null;
3238
+
3239
+ for (; (token = tokens[i++]) !== undefined;) {
3240
+
3241
+ if ( startTag === null ) {
3242
+ switch ( token ) {
3243
+ case '<%':
3244
+ case '<%=':
3245
+ case '<%==':
3246
+ magicInTag = 1;
3247
+ case '<%#':
3248
+ // A new line -- just add whatever content within a clean.
3249
+ // Reset everything.
3250
+ startTag = token;
3251
+ if ( content.length ) {
3252
+ put(content);
3253
+ }
3254
+ content = '';
3255
+ break;
3256
+
3257
+ case '<%%':
3258
+ // Replace `<%%` with `<%`.
3259
+ content += '<%';
3260
+ break;
3261
+ case '<':
3262
+ // Make sure we are not in a comment.
3263
+ if(tokens[i].indexOf("!--") !== 0) {
3264
+ htmlTag = 1;
3265
+ magicInTag = 0;
3266
+ }
3267
+ content += token;
3268
+ break;
3269
+ case '>':
3270
+ htmlTag = 0;
3271
+ // TODO: all `<%=` in tags should be added to pending hookups.
3272
+ if(magicInTag){
3273
+ put(content, ",can.EJS.pending(),\">\"");
3274
+ content = '';
3275
+ } else {
3276
+ content += token;
3277
+ }
3278
+ // if it's a tag like <input/>
3279
+ if(lastToken.substr(-1) == "/"){
3280
+ // remove the current tag in the stack
3281
+ tagNames.pop();
3282
+ // set the current tag to the previous parent
3283
+ tagName = tagNames[tagNames.length-1];
3284
+ }
3285
+ break;
3286
+ case "'":
3287
+ case '"':
3288
+ // If we are in an html tag, finding matching quotes.
3289
+ if(htmlTag){
3290
+ // We have a quote and it matches.
3291
+ if(quote && quote === token){
3292
+ // We are exiting the quote.
3293
+ quote = null;
3294
+ // Otherwise we are creating a quote.
3295
+ // TODO: does this handle `\`?
3296
+ } else if(quote === null){
3297
+ quote = token;
3298
+ beforeQuote = lastToken;
3299
+ }
3300
+ }
3301
+ default:
3302
+ // Track the current tag
3303
+ if(lastToken === '<'){
3304
+ tagName = token.split(' ')[0];
3305
+ // If
3306
+ if( tagName.indexOf("/") === 0 && tagNames.pop() === tagName.substr(1) ) {
3307
+ tagName = tagNames[tagNames.length-1]|| tagName.substr(1)
3308
+ } else {
3309
+ tagNames.push(tagName);
3310
+ }
3311
+ }
3312
+ content += token;
3313
+ break;
3314
+ }
3315
+ }
3316
+ else {
3317
+ // We have a start tag.
3318
+ switch ( token ) {
3319
+ case '%>':
3320
+ // `%>`
3321
+ switch ( startTag ) {
3322
+ case '<%':
3323
+ // `<%`
3324
+
3325
+ // Get the number of `{ minus }`
3326
+ bracketCount = bracketNum(content);
3327
+
3328
+ // We are ending a block.
3329
+ if (bracketCount == 1) {
3330
+
3331
+ // We are starting on.
3332
+ buff.push(insert_cmd, "can.EJS.txt(0,'"+tagName+"'," + status() + ",this,function(){", startTxt, content);
3333
+
3334
+ endStack.push({
3335
+ before: "",
3336
+ after: finishTxt+"}));\n"
3337
+ })
3338
+ }
3339
+ else {
3340
+
3341
+ // How are we ending this statement?
3342
+ var last = // If the stack has value and we are ending a block...
3343
+ endStack.length && bracketCount == -1 ? // Use the last item in the block stack.
3344
+ endStack.pop() : // Or use the default ending.
3345
+ {
3346
+ after: ";"
3347
+ };
3348
+
3349
+ // If we are ending a returning block,
3350
+ // add the finish text which returns the result of the
3351
+ // block.
3352
+ if (last.before) {
3353
+ buff.push(last.before)
3354
+ }
3355
+ // Add the remaining content.
3356
+ buff.push(content, ";",last.after);
3357
+ }
3358
+ break;
3359
+ case '<%=':
3360
+ case '<%==':
3361
+ // We have an extra `{` -> `block`.
3362
+ // Get the number of `{ minus }`.
3363
+ bracketCount = bracketNum(content);
3364
+ // If we have more `{`, it means there is a block.
3365
+ if( bracketCount ){
3366
+ // When we return to the same # of `{` vs `}` end with a `doubleParent`.
3367
+ endStack.push({
3368
+ before : finishTxt,
3369
+ after: "}));"
3370
+ })
3371
+ }
3372
+ // Check if its a func like `()->`
3373
+ if(quickFunc.test(content)){
3374
+ var parts = content.match(quickFunc)
3375
+ content = "function(__){var "+parts[1]+"=can.$(__);"+parts[2]+"}"
3376
+ }
3377
+
3378
+ // If we have `<%== a(function(){ %>` then we want
3379
+ // `can.EJS.text(0,this, function(){ return a(function(){ var _v1ew = [];`.
3380
+ buff.push(insert_cmd, "can.EJS.txt("+(startTag === '<%=' ? 1 : 0)+",'"+tagName+"'," + status()+",this,function(){ return ", content,
3381
+ // If we have a block.
3382
+ bracketCount ?
3383
+ // Start with startTxt `"var _v1ew = [];"`.
3384
+ startTxt :
3385
+ // If not, add `doubleParent` to close push and text.
3386
+ "}));"
3387
+ );
3388
+ break;
3389
+ }
3390
+ startTag = null;
3391
+ content = '';
3392
+ break;
3393
+ case '<%%':
3394
+ content += '<%';
3395
+ break;
3396
+ default:
3397
+ content += token;
3398
+ break;
3399
+ }
3400
+
3401
+ }
3402
+ lastToken = token;
3403
+ }
3404
+
3405
+ // Put it together...
3406
+ if ( content.length ) {
3407
+ // Should be `content.dump` in Ruby.
3408
+ put(content)
3409
+ }
3410
+ buff.push(";")
3411
+
3412
+ var template = buff.join(''),
3413
+ out = {
3414
+ out: 'with(_VIEW) { with (_CONTEXT) {' + template + " "+finishTxt+"}}"
3415
+ };
3416
+ // Use `eval` instead of creating a function, because it is easier to debug.
3417
+ myEval.call(out, 'this.fn = (function(_CONTEXT,_VIEW){' + out.out + '});\r\n//@ sourceURL=' + name + ".js");
3418
+ return out;
3419
+ };
3420
+
3421
+
3422
+
3423
+ EJS.Helpers = function( data, extras ) {
3424
+ this._data = data;
3425
+ this._extras = extras;
3426
+ extend(this, extras);
3427
+ };
3428
+ EJS.Helpers.prototype = {
3429
+ // TODO Deprecated!!
3430
+ list : function(list, cb){
3431
+ can.each(list, function(item, i){
3432
+ cb(item, i, list)
3433
+ })
3434
+ }
3435
+ };
3436
+
3437
+ // Options for `steal`'s build.
3438
+ can.view.register({
3439
+ suffix: "ejs",
3440
+ // returns a `function` that renders the view.
3441
+ script: function( id, src ) {
3442
+ return "can.EJS(function(_CONTEXT,_VIEW) { " + new EJS({
3443
+ text: src,
3444
+ name: id
3445
+ }).template.out + " })";
3446
+ },
3447
+ renderer: function( id, text ) {
3448
+ return EJS({
3449
+ text: text,
3450
+ name: id
3451
+ });
3452
+ }
3453
+ });
3454
+
3455
+ // Register as an AMD module if supported, otherwise attach to the window
3456
+ if ( typeof define === "function" && define.amd ) {
3457
+ define( "can", [], function () { return can; } );
3458
+ } else {
3459
+ window.can = can;
3460
+ }
3461
+
3462
+ })(can = {}, this )