spree_backend 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (370) hide show
  1. checksums.yaml +15 -0
  2. data/app/assets/images/admin/bg/spree_50.png +0 -0
  3. data/app/assets/images/admin/payment_banner.png +0 -0
  4. data/app/assets/images/admin/progress.gif +0 -0
  5. data/app/assets/javascripts/admin/address_states.js +27 -0
  6. data/app/assets/javascripts/admin/admin.js.erb +283 -0
  7. data/app/assets/javascripts/admin/calculator.js +16 -0
  8. data/app/assets/javascripts/admin/checkouts/edit.js +94 -0
  9. data/app/assets/javascripts/admin/gateway.js +13 -0
  10. data/app/assets/javascripts/admin/image_settings.js.erb +62 -0
  11. data/app/assets/javascripts/admin/images/index.js.coffee +15 -0
  12. data/app/assets/javascripts/admin/images/new.js.coffee +7 -0
  13. data/app/assets/javascripts/admin/nested-attribute.js +23 -0
  14. data/app/assets/javascripts/admin/option_type_autocomplete.js.erb +35 -0
  15. data/app/assets/javascripts/admin/orders/edit.js +17 -0
  16. data/app/assets/javascripts/admin/orders/edit_form.js +16 -0
  17. data/app/assets/javascripts/admin/payments/new.js +16 -0
  18. data/app/assets/javascripts/admin/product_picker.js +37 -0
  19. data/app/assets/javascripts/admin/progress.coffee +27 -0
  20. data/app/assets/javascripts/admin/promotions.js +98 -0
  21. data/app/assets/javascripts/admin/shipments.js.erb +66 -0
  22. data/app/assets/javascripts/admin/spree-select2.js.erb +22 -0
  23. data/app/assets/javascripts/admin/spree_backend.js +19 -0
  24. data/app/assets/javascripts/admin/states.js +9 -0
  25. data/app/assets/javascripts/admin/stock_management.js.coffee +9 -0
  26. data/app/assets/javascripts/admin/stock_transfer.js.coffee +181 -0
  27. data/app/assets/javascripts/admin/taxon_autocomplete.js.erb +32 -0
  28. data/app/assets/javascripts/admin/taxon_tree_menu.js.coffee +22 -0
  29. data/app/assets/javascripts/admin/taxonomy.js.coffee +127 -0
  30. data/app/assets/javascripts/admin/underscore-min.js +1227 -0
  31. data/app/assets/javascripts/admin/user_picker.js +31 -0
  32. data/app/assets/javascripts/admin/variant_autocomplete.js.erb +180 -0
  33. data/app/assets/javascripts/admin/zone.js.coffee +39 -0
  34. data/app/assets/javascripts/store/backend.js +1 -0
  35. data/app/assets/stylesheets/admin/components/_actions.scss +31 -0
  36. data/app/assets/stylesheets/admin/components/_date-picker.scss +154 -0
  37. data/app/assets/stylesheets/admin/components/_messages.scss +43 -0
  38. data/app/assets/stylesheets/admin/components/_navigation.scss +150 -0
  39. data/app/assets/stylesheets/admin/components/_pagination.scss +17 -0
  40. data/app/assets/stylesheets/admin/components/_product_autocomplete.scss +29 -0
  41. data/app/assets/stylesheets/admin/components/_progress.scss +35 -0
  42. data/app/assets/stylesheets/admin/components/_sidebar.scss +24 -0
  43. data/app/assets/stylesheets/admin/components/_states.scss +34 -0
  44. data/app/assets/stylesheets/admin/components/_table-filter.scss +14 -0
  45. data/app/assets/stylesheets/admin/globals/_functions.scss +25 -0
  46. data/app/assets/stylesheets/admin/globals/_mixins.scss +25 -0
  47. data/app/assets/stylesheets/admin/globals/_variables.scss +142 -0
  48. data/app/assets/stylesheets/admin/globals/_variables_override.scss +7 -0
  49. data/app/assets/stylesheets/admin/hacks/_ie.scss +73 -0
  50. data/app/assets/stylesheets/admin/hacks/_mozilla.scss +32 -0
  51. data/app/assets/stylesheets/admin/hacks/_opera.scss +17 -0
  52. data/app/assets/stylesheets/admin/plugins/_jstree.scss +132 -0
  53. data/app/assets/stylesheets/admin/plugins/_powertip.scss +86 -0
  54. data/app/assets/stylesheets/admin/plugins/_select2.scss +176 -0
  55. data/app/assets/stylesheets/admin/plugins/_token-input.scss +110 -0
  56. data/app/assets/stylesheets/admin/plugins/font-awesome.scss +303 -0
  57. data/app/assets/stylesheets/admin/sections/_bulk_transfer.scss +8 -0
  58. data/app/assets/stylesheets/admin/sections/_edit_checkouts.scss +72 -0
  59. data/app/assets/stylesheets/admin/sections/_image_settings.scss +3 -0
  60. data/app/assets/stylesheets/admin/sections/_orders.scss +54 -0
  61. data/app/assets/stylesheets/admin/sections/_overview.scss +86 -0
  62. data/app/assets/stylesheets/admin/sections/_products.scss +113 -0
  63. data/app/assets/stylesheets/admin/sections/_promotions.scss +100 -0
  64. data/app/assets/stylesheets/admin/shared/_forms.scss +262 -0
  65. data/app/assets/stylesheets/admin/shared/_icons.scss +22 -0
  66. data/app/assets/stylesheets/admin/shared/_layout.scss +91 -0
  67. data/app/assets/stylesheets/admin/shared/_tables.scss +198 -0
  68. data/app/assets/stylesheets/admin/shared/_typography.scss +132 -0
  69. data/app/assets/stylesheets/admin/spree_admin.scss +39 -0
  70. data/app/assets/stylesheets/admin/spree_backend.css +16 -0
  71. data/app/assets/stylesheets/store/backend.css +1 -0
  72. data/app/controllers/spree/admin/adjustments_controller.rb +30 -0
  73. data/app/controllers/spree/admin/banners_controller.rb +14 -0
  74. data/app/controllers/spree/admin/base_controller.rb +92 -0
  75. data/app/controllers/spree/admin/countries_controller.rb +11 -0
  76. data/app/controllers/spree/admin/general_settings_controller.rb +34 -0
  77. data/app/controllers/spree/admin/image_settings_controller.rb +66 -0
  78. data/app/controllers/spree/admin/images_controller.rb +35 -0
  79. data/app/controllers/spree/admin/inventory_units_controller.rb +6 -0
  80. data/app/controllers/spree/admin/line_items_controller.rb +49 -0
  81. data/app/controllers/spree/admin/mail_methods_controller.rb +38 -0
  82. data/app/controllers/spree/admin/option_types_controller.rb +46 -0
  83. data/app/controllers/spree/admin/option_values_controller.rb +11 -0
  84. data/app/controllers/spree/admin/orders/customer_details_controller.rb +40 -0
  85. data/app/controllers/spree/admin/orders_controller.rb +133 -0
  86. data/app/controllers/spree/admin/overview_controller.rb +13 -0
  87. data/app/controllers/spree/admin/payment_methods_controller.rb +65 -0
  88. data/app/controllers/spree/admin/payments_controller.rb +111 -0
  89. data/app/controllers/spree/admin/product_properties_controller.rb +18 -0
  90. data/app/controllers/spree/admin/products_controller.rb +115 -0
  91. data/app/controllers/spree/admin/promotion_actions_controller.rb +45 -0
  92. data/app/controllers/spree/admin/promotion_rules_controller.rb +50 -0
  93. data/app/controllers/spree/admin/promotions_controller.rb +23 -0
  94. data/app/controllers/spree/admin/properties_controller.rb +12 -0
  95. data/app/controllers/spree/admin/prototypes_controller.rb +27 -0
  96. data/app/controllers/spree/admin/reports_controller.rb +55 -0
  97. data/app/controllers/spree/admin/resource_controller.rb +261 -0
  98. data/app/controllers/spree/admin/return_authorizations_controller.rb +21 -0
  99. data/app/controllers/spree/admin/search_controller.rb +27 -0
  100. data/app/controllers/spree/admin/shipping_categories_controller.rb +6 -0
  101. data/app/controllers/spree/admin/shipping_methods_controller.rb +45 -0
  102. data/app/controllers/spree/admin/states_controller.rb +29 -0
  103. data/app/controllers/spree/admin/stock_items_controller.rb +24 -0
  104. data/app/controllers/spree/admin/stock_locations_controller.rb +7 -0
  105. data/app/controllers/spree/admin/stock_movements_controller.rb +60 -0
  106. data/app/controllers/spree/admin/stock_transfers_controller.rb +53 -0
  107. data/app/controllers/spree/admin/tax_categories_controller.rb +19 -0
  108. data/app/controllers/spree/admin/tax_rates_controller.rb +26 -0
  109. data/app/controllers/spree/admin/tax_settings_controller.rb +17 -0
  110. data/app/controllers/spree/admin/taxonomies_controller.rb +21 -0
  111. data/app/controllers/spree/admin/taxons_controller.rb +112 -0
  112. data/app/controllers/spree/admin/trackers_controller.rb +6 -0
  113. data/app/controllers/spree/admin/variants_controller.rb +44 -0
  114. data/app/controllers/spree/admin/zones_controller.rb +26 -0
  115. data/app/helpers/spree/admin/base_helper.rb +168 -0
  116. data/app/helpers/spree/admin/general_settings_helper.rb +13 -0
  117. data/app/helpers/spree/admin/inventory_settings_helper.rb +9 -0
  118. data/app/helpers/spree/admin/navigation_helper.rb +154 -0
  119. data/app/helpers/spree/admin/orders_helper.rb +19 -0
  120. data/app/helpers/spree/admin/payments_helper.rb +11 -0
  121. data/app/helpers/spree/admin/products_helper.rb +27 -0
  122. data/app/helpers/spree/admin/stock_movements_helper.rb +13 -0
  123. data/app/helpers/spree/admin/tables_helper.rb +15 -0
  124. data/app/helpers/spree/admin/taxons_helper.rb +9 -0
  125. data/app/helpers/spree/promotion_rules_helper.rb +13 -0
  126. data/app/models/spree/backend_configuration.rb +5 -0
  127. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +36 -0
  128. data/app/views/spree/admin/adjustments/_form.html.erb +16 -0
  129. data/app/views/spree/admin/adjustments/edit.html.erb +22 -0
  130. data/app/views/spree/admin/adjustments/index.html.erb +14 -0
  131. data/app/views/spree/admin/adjustments/new.html.erb +23 -0
  132. data/app/views/spree/admin/banners/_gateway.html.erb +16 -0
  133. data/app/views/spree/admin/countries/_form.html.erb +22 -0
  134. data/app/views/spree/admin/countries/edit.html.erb +21 -0
  135. data/app/views/spree/admin/countries/index.html.erb +34 -0
  136. data/app/views/spree/admin/general_settings/edit.html.erb +92 -0
  137. data/app/views/spree/admin/image_settings/edit.html.erb +126 -0
  138. data/app/views/spree/admin/images/_form.html.erb +18 -0
  139. data/app/views/spree/admin/images/edit.html.erb +28 -0
  140. data/app/views/spree/admin/images/index.html.erb +58 -0
  141. data/app/views/spree/admin/images/new.html.erb +15 -0
  142. data/app/views/spree/admin/inventory_units/adjust.html.erb +31 -0
  143. data/app/views/spree/admin/line_items/create.js.erb +1 -0
  144. data/app/views/spree/admin/line_items/destroy.js.erb +1 -0
  145. data/app/views/spree/admin/mail_methods/_form.html.erb +80 -0
  146. data/app/views/spree/admin/mail_methods/edit.html.erb +21 -0
  147. data/app/views/spree/admin/option_types/_form.html.erb +17 -0
  148. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +9 -0
  149. data/app/views/spree/admin/option_types/edit.html.erb +50 -0
  150. data/app/views/spree/admin/option_types/index.html.erb +40 -0
  151. data/app/views/spree/admin/option_types/new.html.erb +11 -0
  152. data/app/views/spree/admin/option_types/new.js.erb +2 -0
  153. data/app/views/spree/admin/orders/_add_product.html.erb +15 -0
  154. data/app/views/spree/admin/orders/_form.html.erb +45 -0
  155. data/app/views/spree/admin/orders/_line_item.html.erb +9 -0
  156. data/app/views/spree/admin/orders/_shipment.html.erb +148 -0
  157. data/app/views/spree/admin/orders/customer_details/_form.html.erb +66 -0
  158. data/app/views/spree/admin/orders/customer_details/edit.html.erb +27 -0
  159. data/app/views/spree/admin/orders/edit.html.erb +30 -0
  160. data/app/views/spree/admin/orders/index.html.erb +134 -0
  161. data/app/views/spree/admin/payment_methods/_form.html.erb +57 -0
  162. data/app/views/spree/admin/payment_methods/edit.html.erb +23 -0
  163. data/app/views/spree/admin/payment_methods/index.html.erb +52 -0
  164. data/app/views/spree/admin/payment_methods/new.html.erb +22 -0
  165. data/app/views/spree/admin/payments/_bill_address_form.html.erb +9 -0
  166. data/app/views/spree/admin/payments/_form.html.erb +28 -0
  167. data/app/views/spree/admin/payments/_list.html.erb +26 -0
  168. data/app/views/spree/admin/payments/credit.html.erb +18 -0
  169. data/app/views/spree/admin/payments/index.html.erb +24 -0
  170. data/app/views/spree/admin/payments/new.html.erb +26 -0
  171. data/app/views/spree/admin/payments/show.html.erb +18 -0
  172. data/app/views/spree/admin/payments/source_forms/_check.html.erb +0 -0
  173. data/app/views/spree/admin/payments/source_forms/_gateway.html.erb +50 -0
  174. data/app/views/spree/admin/payments/source_views/_check.html.erb +0 -0
  175. data/app/views/spree/admin/payments/source_views/_gateway.html.erb +29 -0
  176. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +17 -0
  177. data/app/views/spree/admin/product_properties/index.html.erb +59 -0
  178. data/app/views/spree/admin/products/_add_stock_form.html.erb +6 -0
  179. data/app/views/spree/admin/products/_form.html.erb +128 -0
  180. data/app/views/spree/admin/products/_properties_form.erb +10 -0
  181. data/app/views/spree/admin/products/edit.html.erb +18 -0
  182. data/app/views/spree/admin/products/index.html.erb +102 -0
  183. data/app/views/spree/admin/products/new.html.erb +81 -0
  184. data/app/views/spree/admin/products/new.js.erb +7 -0
  185. data/app/views/spree/admin/products/stock.html.erb +79 -0
  186. data/app/views/spree/admin/promotion_actions/create.js.erb +13 -0
  187. data/app/views/spree/admin/promotion_actions/destroy.js.erb +1 -0
  188. data/app/views/spree/admin/promotion_rules/create.js.erb +7 -0
  189. data/app/views/spree/admin/promotion_rules/destroy.js.erb +3 -0
  190. data/app/views/spree/admin/promotions/_actions.html.erb +32 -0
  191. data/app/views/spree/admin/promotions/_form.html.erb +56 -0
  192. data/app/views/spree/admin/promotions/_promotion_action.html.erb +11 -0
  193. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +9 -0
  194. data/app/views/spree/admin/promotions/_rules.html.erb +45 -0
  195. data/app/views/spree/admin/promotions/_tab.html.erb +1 -0
  196. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +26 -0
  197. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +22 -0
  198. data/app/views/spree/admin/promotions/edit.html.erb +28 -0
  199. data/app/views/spree/admin/promotions/index.html.erb +52 -0
  200. data/app/views/spree/admin/promotions/new.html.erb +16 -0
  201. data/app/views/spree/admin/promotions/rules/_first_order.html.erb +0 -0
  202. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +6 -0
  203. data/app/views/spree/admin/promotions/rules/_landing_page.html.erb +5 -0
  204. data/app/views/spree/admin/promotions/rules/_product.html.erb +9 -0
  205. data/app/views/spree/admin/promotions/rules/_user.html.erb +4 -0
  206. data/app/views/spree/admin/promotions/rules/_user_logged_in.html.erb +0 -0
  207. data/app/views/spree/admin/properties/_form.html.erb +16 -0
  208. data/app/views/spree/admin/properties/edit.html.erb +18 -0
  209. data/app/views/spree/admin/properties/filtered.html.erb +1 -0
  210. data/app/views/spree/admin/properties/index.html.erb +41 -0
  211. data/app/views/spree/admin/properties/new.html.erb +13 -0
  212. data/app/views/spree/admin/properties/new.js.erb +2 -0
  213. data/app/views/spree/admin/prototypes/_form.html.erb +25 -0
  214. data/app/views/spree/admin/prototypes/_prototypes.html.erb +25 -0
  215. data/app/views/spree/admin/prototypes/available.js.erb +2 -0
  216. data/app/views/spree/admin/prototypes/edit.html.erb +20 -0
  217. data/app/views/spree/admin/prototypes/index.html.erb +40 -0
  218. data/app/views/spree/admin/prototypes/new.html.erb +11 -0
  219. data/app/views/spree/admin/prototypes/new.js.erb +5 -0
  220. data/app/views/spree/admin/prototypes/select.js.erb +4 -0
  221. data/app/views/spree/admin/prototypes/show.html.erb +42 -0
  222. data/app/views/spree/admin/reports/index.html.erb +21 -0
  223. data/app/views/spree/admin/reports/sales_total.html.erb +37 -0
  224. data/app/views/spree/admin/return_authorizations/_form.html.erb +78 -0
  225. data/app/views/spree/admin/return_authorizations/edit.html.erb +32 -0
  226. data/app/views/spree/admin/return_authorizations/index.html.erb +52 -0
  227. data/app/views/spree/admin/return_authorizations/new.html.erb +22 -0
  228. data/app/views/spree/admin/search/users.rabl +30 -0
  229. data/app/views/spree/admin/shared/_address.html.erb +6 -0
  230. data/app/views/spree/admin/shared/_address_form.html.erb +72 -0
  231. data/app/views/spree/admin/shared/_alert.html.erb +5 -0
  232. data/app/views/spree/admin/shared/_calculator_fields.html.erb +22 -0
  233. data/app/views/spree/admin/shared/_configuration_menu.html.erb +30 -0
  234. data/app/views/spree/admin/shared/_destroy.js.erb +16 -0
  235. data/app/views/spree/admin/shared/_edit_resource_links.html.erb +5 -0
  236. data/app/views/spree/admin/shared/_head.html.erb +25 -0
  237. data/app/views/spree/admin/shared/_new_resource_links.html.erb +5 -0
  238. data/app/views/spree/admin/shared/_order_details.html.erb +56 -0
  239. data/app/views/spree/admin/shared/_order_tabs.html.erb +75 -0
  240. data/app/views/spree/admin/shared/_product_sub_menu.html.erb +8 -0
  241. data/app/views/spree/admin/shared/_product_tabs.html.erb +30 -0
  242. data/app/views/spree/admin/shared/_report_criteria.html.erb +17 -0
  243. data/app/views/spree/admin/shared/_routes.html.erb +8 -0
  244. data/app/views/spree/admin/shared/_show_resource_links.html.erb +5 -0
  245. data/app/views/spree/admin/shared/_stock_movement_form.html.erb +30 -0
  246. data/app/views/spree/admin/shared/_tabs.html.erb +14 -0
  247. data/app/views/spree/admin/shared/_translations.html.erb +32 -0
  248. data/app/views/spree/admin/shared/_update_order_state.js +7 -0
  249. data/app/views/spree/admin/shipping_categories/_form.html.erb +6 -0
  250. data/app/views/spree/admin/shipping_categories/edit.html.erb +20 -0
  251. data/app/views/spree/admin/shipping_categories/index.html.erb +35 -0
  252. data/app/views/spree/admin/shipping_categories/new.html.erb +20 -0
  253. data/app/views/spree/admin/shipping_methods/_form.html.erb +58 -0
  254. data/app/views/spree/admin/shipping_methods/edit.html.erb +29 -0
  255. data/app/views/spree/admin/shipping_methods/index.html.erb +48 -0
  256. data/app/views/spree/admin/shipping_methods/new.html.erb +29 -0
  257. data/app/views/spree/admin/states/_form.html.erb +14 -0
  258. data/app/views/spree/admin/states/_state_list.html.erb +31 -0
  259. data/app/views/spree/admin/states/edit.html.erb +20 -0
  260. data/app/views/spree/admin/states/index.html.erb +24 -0
  261. data/app/views/spree/admin/states/new.html.erb +15 -0
  262. data/app/views/spree/admin/states/new.js.erb +2 -0
  263. data/app/views/spree/admin/stock_locations/_form.html.erb +87 -0
  264. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +39 -0
  265. data/app/views/spree/admin/stock_locations/edit.html.erb +17 -0
  266. data/app/views/spree/admin/stock_locations/index.html.erb +49 -0
  267. data/app/views/spree/admin/stock_locations/new.html.erb +16 -0
  268. data/app/views/spree/admin/stock_movements/_form.html.erb +13 -0
  269. data/app/views/spree/admin/stock_movements/edit.html.erb +16 -0
  270. data/app/views/spree/admin/stock_movements/index.html.erb +43 -0
  271. data/app/views/spree/admin/stock_movements/new.html.erb +16 -0
  272. data/app/views/spree/admin/stock_transfers/_stock_movements.html.erb +27 -0
  273. data/app/views/spree/admin/stock_transfers/index.html.erb +94 -0
  274. data/app/views/spree/admin/stock_transfers/new.html.erb +108 -0
  275. data/app/views/spree/admin/stock_transfers/show.html.erb +48 -0
  276. data/app/views/spree/admin/tax_categories/_form.html.erb +24 -0
  277. data/app/views/spree/admin/tax_categories/edit.html.erb +18 -0
  278. data/app/views/spree/admin/tax_categories/index.html.erb +48 -0
  279. data/app/views/spree/admin/tax_categories/new.html.erb +19 -0
  280. data/app/views/spree/admin/tax_categories/show.html.erb +1 -0
  281. data/app/views/spree/admin/tax_rates/_form.html.erb +42 -0
  282. data/app/views/spree/admin/tax_rates/edit.html.erb +21 -0
  283. data/app/views/spree/admin/tax_rates/index.html.erb +59 -0
  284. data/app/views/spree/admin/tax_rates/new.html.erb +25 -0
  285. data/app/views/spree/admin/tax_settings/edit.html.erb +18 -0
  286. data/app/views/spree/admin/taxonomies/_form.html.erb +7 -0
  287. data/app/views/spree/admin/taxonomies/_js_head.html.erb +13 -0
  288. data/app/views/spree/admin/taxonomies/_list.html.erb +26 -0
  289. data/app/views/spree/admin/taxonomies/_taxon.html.erb +12 -0
  290. data/app/views/spree/admin/taxonomies/edit.erb +42 -0
  291. data/app/views/spree/admin/taxonomies/index.html.erb +15 -0
  292. data/app/views/spree/admin/taxonomies/new.html.erb +22 -0
  293. data/app/views/spree/admin/taxons/_form.html.erb +44 -0
  294. data/app/views/spree/admin/taxons/_taxon_table.html.erb +23 -0
  295. data/app/views/spree/admin/taxons/edit.html.erb +23 -0
  296. data/app/views/spree/admin/taxons/search.rabl +5 -0
  297. data/app/views/spree/admin/trackers/_form.html.erb +34 -0
  298. data/app/views/spree/admin/trackers/edit.html.erb +20 -0
  299. data/app/views/spree/admin/trackers/index.html.erb +48 -0
  300. data/app/views/spree/admin/trackers/new.html.erb +20 -0
  301. data/app/views/spree/admin/variants/_autocomplete.js.erb +67 -0
  302. data/app/views/spree/admin/variants/_form.html.erb +37 -0
  303. data/app/views/spree/admin/variants/edit.html.erb +15 -0
  304. data/app/views/spree/admin/variants/index.html.erb +74 -0
  305. data/app/views/spree/admin/variants/new.html.erb +9 -0
  306. data/app/views/spree/admin/variants/new.js.erb +3 -0
  307. data/app/views/spree/admin/zones/_country_member.html.erb +5 -0
  308. data/app/views/spree/admin/zones/_form.html.erb +34 -0
  309. data/app/views/spree/admin/zones/_member_type.html.erb +19 -0
  310. data/app/views/spree/admin/zones/_state_member.html.erb +5 -0
  311. data/app/views/spree/admin/zones/edit.html.erb +23 -0
  312. data/app/views/spree/admin/zones/index.html.erb +53 -0
  313. data/app/views/spree/admin/zones/new.html.erb +21 -0
  314. data/app/views/spree/layouts/admin.html.erb +135 -0
  315. data/app/views/spree/test_mailer/test_email.text.erb +4 -0
  316. data/config/initializers/form_builder.rb +15 -0
  317. data/config/routes.rb +159 -0
  318. data/lib/spree/backend.rb +21 -0
  319. data/lib/spree/backend/action_callbacks.rb +26 -0
  320. data/lib/spree/backend/engine.rb +41 -0
  321. data/lib/spree_backend.rb +1 -0
  322. data/vendor/assets/fonts/fontawesome-webfont.eot +0 -0
  323. data/vendor/assets/fonts/fontawesome-webfont.svg +255 -0
  324. data/vendor/assets/fonts/fontawesome-webfont.ttf +0 -0
  325. data/vendor/assets/fonts/fontawesome-webfont.woff +0 -0
  326. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  327. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  328. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  329. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  330. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  331. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  332. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  333. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  334. data/vendor/assets/images/jquery-ui/ui-icons_0073ea_256x240.png +0 -0
  335. data/vendor/assets/images/jquery-ui/ui-icons_454545_256x240.png +0 -0
  336. data/vendor/assets/images/jquery-ui/ui-icons_666666_256x240.png +0 -0
  337. data/vendor/assets/images/jquery-ui/ui-icons_ff0084_256x240.png +0 -0
  338. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  339. data/vendor/assets/images/jquery.alerts/images/help.gif +0 -0
  340. data/vendor/assets/images/jquery.alerts/images/important.gif +0 -0
  341. data/vendor/assets/images/jquery.alerts/images/info.gif +0 -0
  342. data/vendor/assets/images/jquery.alerts/images/title.gif +0 -0
  343. data/vendor/assets/javascripts/css_browser_selector_dev.js +156 -0
  344. data/vendor/assets/javascripts/equalize.js +41 -0
  345. data/vendor/assets/javascripts/handlebars.js +1920 -0
  346. data/vendor/assets/javascripts/jquery.adaptivemenu.js +60 -0
  347. data/vendor/assets/javascripts/jquery.alerts/jquery.alerts.js +235 -0
  348. data/vendor/assets/javascripts/jquery.cookie.js +41 -0
  349. data/vendor/assets/javascripts/jquery.delayedobserver.js +35 -0
  350. data/vendor/assets/javascripts/jquery.horizontalNav.js +141 -0
  351. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +4540 -0
  352. data/vendor/assets/javascripts/jquery.jstree/themes/apple/bg.jpg +0 -0
  353. data/vendor/assets/javascripts/jquery.jstree/themes/apple/d.png +0 -0
  354. data/vendor/assets/javascripts/jquery.jstree/themes/apple/dot_for_ie.gif +0 -0
  355. data/vendor/assets/javascripts/jquery.jstree/themes/apple/style.css +61 -0
  356. data/vendor/assets/javascripts/jquery.jstree/themes/apple/throbber.gif +0 -0
  357. data/vendor/assets/javascripts/jquery.powertip.js +796 -0
  358. data/vendor/assets/javascripts/jquery.vAlign.js +11 -0
  359. data/vendor/assets/javascripts/modernizr.js +4 -0
  360. data/vendor/assets/javascripts/responsive-tables.js +42 -0
  361. data/vendor/assets/javascripts/spin.js +319 -0
  362. data/vendor/assets/javascripts/trunk8.js +233 -0
  363. data/vendor/assets/stylesheets/font-awesome-ie7.css +645 -0
  364. data/vendor/assets/stylesheets/font-awesome.css.erb +303 -0
  365. data/vendor/assets/stylesheets/jquery-ui.datepicker.css.erb +357 -0
  366. data/vendor/assets/stylesheets/jquery.alerts/jquery.alerts.css.erb +57 -0
  367. data/vendor/assets/stylesheets/jquery.alerts/jquery.alerts.spree.css +29 -0
  368. data/vendor/assets/stylesheets/jquery.powertip.css +85 -0
  369. data/vendor/assets/stylesheets/responsive-tables.css +21 -0
  370. metadata +509 -0
@@ -0,0 +1,22 @@
1
+ //= require select2
2
+ jQuery(function($) {
3
+ // Make select beautiful
4
+ $('select.select2').select2({
5
+ allowClear: true
6
+ });
7
+
8
+ function format_taxons(taxon) {
9
+ new_taxon = taxon.text.replace('->', '<i class="icon-arrow-right">')
10
+ return new_taxon;
11
+ }
12
+
13
+ $("#product_taxon_ids").on({
14
+ change: function(e){
15
+ $('.select2-search-choice .with-tip').powerTip({
16
+ smartPlacement: true,
17
+ fadeInTime: 50,
18
+ fadeOutTime: 50
19
+ })
20
+ }
21
+ })
22
+ })
@@ -0,0 +1,19 @@
1
+ //= require jquery-migrate-1.0.0
2
+ //= require jquery-ui
3
+ //= require modernizr
4
+ //= require jquery.cookie
5
+ //= require jquery.delayedobserver
6
+ //= require jquery.jstree/jquery.jstree
7
+ //= require jquery.alerts/jquery.alerts
8
+ //= require jquery.powertip
9
+ //= require jquery.vAlign
10
+ //= require css_browser_selector_dev
11
+ //= require spin
12
+ //= require trunk8
13
+ //= require jquery.adaptivemenu
14
+ //= require equalize
15
+ //= require responsive-tables
16
+ //= require jquery.horizontalNav
17
+ //= require spree
18
+ //= require_tree .
19
+
@@ -0,0 +1,9 @@
1
+ $(document).ready(function() {
2
+ $("#country").change(function() {
3
+ var new_state_link_href = $('#new_state_link a').attr('href');
4
+ var selected_country_id = $('#country option:selected').attr('value');
5
+ var new_link = new_state_link_href.replace(/countries\/(\d+)/,
6
+ 'countries/'+selected_country_id);
7
+ $('#new_state_link a').attr('href', new_link);
8
+ });
9
+ });
@@ -0,0 +1,9 @@
1
+ jQuery ->
2
+ $('.stock_item_backorderable').live 'click', ->
3
+ $(@).parent('form').submit()
4
+ $('.toggle_stock_item_backorderable').submit ->
5
+ $.ajax
6
+ type: @method
7
+ url: @action
8
+ data: $(@).serialize()
9
+ false
@@ -0,0 +1,181 @@
1
+ $ ->
2
+ # Base Model for transfer line items
3
+ class TransferVariant
4
+ constructor: (@variant) ->
5
+ @id = @variant.id
6
+ @name = "#{@variant.name} - #{@variant.sku}"
7
+ @quantity = 0
8
+
9
+ add: (quantity) ->
10
+ @quantity += quantity
11
+
12
+ # Model for stock items which validate quantity with count on hand
13
+ class TransferStockItem extends TransferVariant
14
+ constructor: (@stock_item) ->
15
+ super(@stock_item.variant)
16
+ @count_on_hand = @stock_item.count_on_hand
17
+ @name = "#{@variant.name} - #{@variant.sku} (#{@count_on_hand})"
18
+
19
+ add: (quantity) ->
20
+ @quantity += quantity
21
+ @quantity = @count_on_hand if @quantity > @count_on_hand
22
+
23
+ # Manages source and destination selections
24
+ class TransferLocations
25
+ constructor: ->
26
+ @source = $('#transfer_source_location_id')
27
+ @destination = $('#transfer_destination_location_id')
28
+
29
+ @source.change => @populate_destination()
30
+
31
+ $('#transfer_receive_stock').change (event) => @receive_stock_change(event)
32
+
33
+ $.getJSON "/api/stock_locations", (data) =>
34
+ @locations = (location for location in data.stock_locations)
35
+ @force_receive_stock() if @locations.length < 2
36
+
37
+ @populate_source()
38
+ @populate_destination()
39
+
40
+ force_receive_stock: ->
41
+ $('#receive_stock_field').hide()
42
+ $('#transfer_receive_stock').prop('checked', true)
43
+ @toggle_source_location true
44
+
45
+ is_source_location_hidden: ->
46
+ $('#transfer_source_location_id_field').css('visibility') == 'hidden'
47
+
48
+ toggle_source_location: (hide=false) ->
49
+ @source.trigger('change')
50
+ if @is_source_location_hidden() and not hide
51
+ $('#transfer_source_location_id_field').css('visibility', 'visible')
52
+ else
53
+ $('#transfer_source_location_id_field').css('visibility', 'hidden')
54
+
55
+ receive_stock_change: (event) ->
56
+ @toggle_source_location event.target.checked
57
+ @populate_destination(!event.target.checked)
58
+
59
+ populate_source: ->
60
+ @populate_select @source
61
+ @source.trigger('change')
62
+
63
+ populate_destination: (except_source=true) ->
64
+ if @is_source_location_hidden()
65
+ @populate_select @destination
66
+ else
67
+ @populate_select @destination, parseInt(@source.val())
68
+
69
+ populate_select: (select, except=0) ->
70
+ select.children('option').remove()
71
+ for location in @locations when location.id isnt except
72
+ select.append $('<option></option>')
73
+ .text(location.name)
74
+ .attr('value', location.id)
75
+ select.select2()
76
+
77
+ # Populates variants drop down
78
+ class TransferVariants
79
+ constructor: ->
80
+ $('#transfer_source_location_id').change => @refresh_variants()
81
+
82
+ receiving_stock: ->
83
+ $( "#transfer_receive_stock:checked" ).length > 0
84
+
85
+ refresh_variants: ->
86
+ if @receiving_stock()
87
+ @_refresh_transfer_variants()
88
+ else
89
+ @_refresh_transfer_stock_items()
90
+
91
+ _refresh_transfer_variants: ->
92
+ if @cached_variants?
93
+ @populate_select @cached_variants
94
+ else
95
+ $.getJSON "/api/variants", (data) =>
96
+ @cached_variants = _.map(data.variants, (variant) -> new TransferVariant(variant))
97
+ @populate_select @cached_variants
98
+
99
+ _refresh_transfer_stock_items: ->
100
+ stock_location_id = $('#transfer_source_location_id').val()
101
+ $.getJSON "/api/stock_locations/#{stock_location_id}/stock_items", (data) =>
102
+ @populate_select _.map(data.stock_items, (stock_item) -> new TransferStockItem(stock_item))
103
+
104
+ populate_select: (variants) ->
105
+ $('#transfer_variant').children('option').remove()
106
+
107
+ for variant in variants
108
+ $('#transfer_variant').append($('<option></option>')
109
+ .text(variant.name)
110
+ .attr('value', variant.id)
111
+ .data('variant', variant))
112
+
113
+ $('#transfer_variant').select2()
114
+
115
+ # Add/Remove variant line items
116
+ class TransferAddVariants
117
+ constructor: ->
118
+ @variants = []
119
+ @template = Handlebars.compile $('#transfer_variant_template').html()
120
+
121
+ $('#transfer_source_location_id').change (event) => @clear_variants()
122
+
123
+ $('button.transfer_add_variant').click (event) =>
124
+ event.preventDefault()
125
+ @add_variant()
126
+
127
+ $('#transfer-variants-table').on 'click', '.transfer_remove_variant', (event) =>
128
+ event.preventDefault()
129
+ @remove_variant $(event.target)
130
+
131
+ $('button.transfer_transfer').click =>
132
+ unless @variants.length > 0
133
+ alert('no variants to transfer')
134
+ false
135
+
136
+ add_variant: ->
137
+ variant = $('#transfer_variant option:selected').data('variant')
138
+ quantity = parseInt $('#transfer_variant_quantity').val()
139
+
140
+ variant = @find_or_add(variant)
141
+ variant.add(quantity)
142
+ @render()
143
+
144
+ find_or_add: (variant) ->
145
+ if existing = _.find(@variants, (v) -> v.id == variant.id)
146
+ return existing
147
+ else
148
+ variant = $.extend({}, variant)
149
+ @variants.push variant
150
+ return variant
151
+
152
+ remove_variant: (target) ->
153
+ variant_id = parseInt(target.data('variantId'))
154
+ @variants = (v for v in @variants when v.id isnt variant_id)
155
+ @render()
156
+
157
+ clear_variants: ->
158
+ @variants = []
159
+ @render()
160
+
161
+ contains: (id) ->
162
+ _.contains(_.pluck(@variants, 'id'), id)
163
+
164
+ render: ->
165
+ if @variants.length is 0
166
+ $('#transfer-variants-table').hide()
167
+ $('.no-objects-found').show()
168
+ else
169
+ $('#transfer-variants-table').show()
170
+ $('.no-objects-found').hide()
171
+
172
+ rendered = @template { variants: @variants }
173
+ $('#transfer_variants_tbody').html(rendered)
174
+
175
+ # Main
176
+ if $('#transfer_source_location_id').length > 0
177
+ transfer_locations = new TransferLocations
178
+ transfer_variants = new TransferVariants
179
+ transfer_add_variants = new TransferAddVariants
180
+
181
+
@@ -0,0 +1,32 @@
1
+ $(document).ready(function() {
2
+ if ($("#product_taxon_ids").length > 0) {
3
+ $("#product_taxon_ids").select2({
4
+ placeholder: Spree.translations.taxon_placeholder,
5
+ multiple: true,
6
+ initSelection: function(element, callback) {
7
+ url = Spree.url(Spree.routes.taxons_search, { ids: element.val() })
8
+ return $.getJSON(url, null, function(data) {
9
+ return callback(data);
10
+ })
11
+ },
12
+ ajax: {
13
+ url: Spree.routes.taxons_search,
14
+ datatype: 'json',
15
+ data: function(term, page) {
16
+ return { q:
17
+ { name_cont: term }
18
+ }
19
+ },
20
+ results: function (data, page) {
21
+ return { results: data }
22
+ }
23
+ },
24
+ formatResult: function(taxon) {
25
+ return taxon.pretty_name
26
+ },
27
+ formatSelection: function(taxon) {
28
+ return taxon.pretty_name
29
+ }
30
+ })
31
+ }
32
+ })
@@ -0,0 +1,22 @@
1
+ root = exports ? this
2
+
3
+ root.taxon_tree_menu = (obj, context) ->
4
+
5
+ base_url = Spree.url(Spree.routes.taxonomy_taxons_path)
6
+ admin_base_url = Spree.url(Spree.routes.admin_taxonomy_taxons_path)
7
+ edit_url = admin_base_url.clone()
8
+ edit_url.setPath(edit_url.path() + '/' + obj.attr("id") + "/edit");
9
+
10
+ create:
11
+ label: "<i class='icon-plus'></i> " + Spree.translations.add,
12
+ action: (obj) -> context.create(obj)
13
+ rename:
14
+ label: "<i class='icon-pencil'></i> " + Spree.translations.rename,
15
+ action: (obj) -> context.rename(obj)
16
+ remove:
17
+ label: "<i class='icon-trash'></i> " + Spree.translations.remove,
18
+ action: (obj) -> context.remove(obj)
19
+ edit:
20
+ separator_before: true,
21
+ label: "<i class='icon-edit'></i> " + Spree.translations.edit,
22
+ action: (obj) -> window.location = edit_url.toString()
@@ -0,0 +1,127 @@
1
+ handle_ajax_error = (XMLHttpRequest, textStatus, errorThrown) ->
2
+ $.jstree.rollback(last_rollback)
3
+ $("#ajax_error").show().html("<strong>" + server_error + "</strong><br />" + taxonomy_tree_error)
4
+
5
+ handle_move = (e, data) ->
6
+ last_rollback = data.rlbk
7
+ position = data.rslt.cp
8
+ node = data.rslt.o
9
+ new_parent = data.rslt.np
10
+
11
+ url = Spree.url(base_url).clone()
12
+ url.setPath url.path() + '/' + node.attr("id")
13
+ $.ajax
14
+ type: "POST",
15
+ dataType: "json",
16
+ url: url.toString(),
17
+ data: ({_method: "put", "taxon[parent_id]": new_parent.attr("id"), "taxon[position]": position }),
18
+ error: handle_ajax_error
19
+
20
+ true
21
+
22
+ handle_create = (e, data) ->
23
+ last_rollback = data.rlbk
24
+ node = data.rslt.obj
25
+ name = data.rslt.name
26
+ position = data.rslt.position
27
+ new_parent = data.rslt.parent
28
+
29
+ $.ajax
30
+ type: "POST",
31
+ dataType: "json",
32
+ url: base_url.toString(),
33
+ data: ({"taxon[name]": name, "taxon[parent_id]": new_parent.attr("id"), "taxon[position]": position }),
34
+ error: handle_ajax_error,
35
+ success: (data,result) ->
36
+ node.attr('id', data.id)
37
+
38
+ handle_rename = (e, data) ->
39
+ last_rollback = data.rlbk
40
+ node = data.rslt.obj
41
+ name = data.rslt.new_name
42
+
43
+ url = Spree.url(base_url).clone()
44
+ url.setPath(url.path() + '/' + node.attr("id"))
45
+
46
+ $.ajax
47
+ type: "POST",
48
+ dataType: "json",
49
+ url: url.toString(),
50
+ data: {_method: "put", "taxon[name]": name },
51
+ error: handle_ajax_error
52
+
53
+ handle_delete = (e, data) ->
54
+ last_rollback = data.rlb
55
+ node = data.rslt.ob
56
+ delete_url = base_url.clone()
57
+ delete_url.setPath delete_url.path() + '/' + node.attr("id")
58
+ jConfirm Spree.translations.are_you_sure_delete, Spree.translations.confirm_delete, (r) ->
59
+ if r
60
+ $.ajax
61
+ type: "POST",
62
+ dataType: "json",
63
+ url: delete_url.toString(),
64
+ data: {_method: "delete"},
65
+ error: handle_ajax_error
66
+ else
67
+ $.jstree.rollback(last_rollback)
68
+ last_rollback = null
69
+
70
+ root = exports ? this
71
+ root.setup_taxonomy_tree = (taxonomy_id) ->
72
+ if taxonomy_id != undefined
73
+ $.ajax
74
+ url: '/api/taxonomies/' + taxonomy_id + '/jstree',
75
+ success: (taxonomy) ->
76
+ # this is defined within admin/taxonomies/edit
77
+ root.base_url = Spree.url(Spree.routes.taxonomy_taxons_path)
78
+ last_rollback = null
79
+
80
+ conf =
81
+ json_data:
82
+ data: taxonomy,
83
+ ajax:
84
+ url: (e) ->
85
+ '/api/taxonomies/' + taxonomy_id + '/taxons/' + e.attr('id') + '/jstree'
86
+ themes:
87
+ theme: "apple",
88
+ url: "/assets/jquery.jstree/themes/apple/style.css"
89
+ strings:
90
+ new_node: new_taxon,
91
+ loading: Spree.translations.loading + "..."
92
+ crrm:
93
+ move:
94
+ check_move: (m) ->
95
+ position = m.cp
96
+ node = m.o
97
+ new_parent = m.np
98
+
99
+ # no parent or cant drag and drop
100
+ if !new_parent || node.attr("rel") == "root"
101
+ return false
102
+
103
+ # can't drop before root
104
+ if new_parent.attr("id") == "taxonomy_tree" && position == 0
105
+ return false
106
+
107
+ true
108
+ contextmenu:
109
+ items: (obj) ->
110
+ taxon_tree_menu(obj, this)
111
+ plugins: ["themes", "json_data", "dnd", "crrm", "contextmenu"]
112
+
113
+ $("#taxonomy_tree").jstree(conf)
114
+ .bind("move_node.jstree", handle_move)
115
+ .bind("remove.jstree", handle_delete)
116
+ .bind("create.jstree", handle_create)
117
+ .bind("rename.jstree", handle_rename)
118
+ .bind "loaded.jstree", ->
119
+ $(this).jstree("core").toggle_node($('.jstree-icon').first())
120
+
121
+ $("#taxonomy_tree a").on "dblclick", (e) ->
122
+ $("#taxonomy_tree").jstree("rename", this)
123
+
124
+ # surpress form submit on enter/return
125
+ $(document).keypress (e) ->
126
+ if e.keyCode == 13
127
+ e.preventDefault()
@@ -0,0 +1,1227 @@
1
+ // Underscore.js 1.4.4
2
+ // ===================
3
+
4
+ // > http://underscorejs.org
5
+ // > (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
6
+ // > Underscore may be freely distributed under the MIT license.
7
+
8
+ // Baseline setup
9
+ // --------------
10
+ (function() {
11
+
12
+ // Establish the root object, `window` in the browser, or `global` on the server.
13
+ var root = this;
14
+
15
+ // Save the previous value of the `_` variable.
16
+ var previousUnderscore = root._;
17
+
18
+ // Establish the object that gets returned to break out of a loop iteration.
19
+ var breaker = {};
20
+
21
+ // Save bytes in the minified (but not gzipped) version:
22
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
23
+
24
+ // Create quick reference variables for speed access to core prototypes.
25
+ var push = ArrayProto.push,
26
+ slice = ArrayProto.slice,
27
+ concat = ArrayProto.concat,
28
+ toString = ObjProto.toString,
29
+ hasOwnProperty = ObjProto.hasOwnProperty;
30
+
31
+ // All **ECMAScript 5** native function implementations that we hope to use
32
+ // are declared here.
33
+ var
34
+ nativeForEach = ArrayProto.forEach,
35
+ nativeMap = ArrayProto.map,
36
+ nativeReduce = ArrayProto.reduce,
37
+ nativeReduceRight = ArrayProto.reduceRight,
38
+ nativeFilter = ArrayProto.filter,
39
+ nativeEvery = ArrayProto.every,
40
+ nativeSome = ArrayProto.some,
41
+ nativeIndexOf = ArrayProto.indexOf,
42
+ nativeLastIndexOf = ArrayProto.lastIndexOf,
43
+ nativeIsArray = Array.isArray,
44
+ nativeKeys = Object.keys,
45
+ nativeBind = FuncProto.bind;
46
+
47
+ // Create a safe reference to the Underscore object for use below.
48
+ var _ = function(obj) {
49
+ if (obj instanceof _) return obj;
50
+ if (!(this instanceof _)) return new _(obj);
51
+ this._wrapped = obj;
52
+ };
53
+
54
+ // Export the Underscore object for **Node.js**, with
55
+ // backwards-compatibility for the old `require()` API. If we're in
56
+ // the browser, add `_` as a global object via a string identifier,
57
+ // for Closure Compiler "advanced" mode.
58
+ if (typeof exports !== 'undefined') {
59
+ if (typeof module !== 'undefined' && module.exports) {
60
+ exports = module.exports = _;
61
+ }
62
+ exports._ = _;
63
+ } else {
64
+ root._ = _;
65
+ }
66
+
67
+ // Current version.
68
+ _.VERSION = '1.4.4';
69
+
70
+ // Collection Functions
71
+ // --------------------
72
+
73
+ // The cornerstone, an `each` implementation, aka `forEach`.
74
+ // Handles objects with the built-in `forEach`, arrays, and raw objects.
75
+ // Delegates to **ECMAScript 5**'s native `forEach` if available.
76
+ var each = _.each = _.forEach = function(obj, iterator, context) {
77
+ if (obj == null) return;
78
+ if (nativeForEach && obj.forEach === nativeForEach) {
79
+ obj.forEach(iterator, context);
80
+ } else if (obj.length === +obj.length) {
81
+ for (var i = 0, l = obj.length; i < l; i++) {
82
+ if (iterator.call(context, obj[i], i, obj) === breaker) return;
83
+ }
84
+ } else {
85
+ for (var key in obj) {
86
+ if (_.has(obj, key)) {
87
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
88
+ }
89
+ }
90
+ }
91
+ };
92
+
93
+ // Return the results of applying the iterator to each element.
94
+ // Delegates to **ECMAScript 5**'s native `map` if available.
95
+ _.map = _.collect = function(obj, iterator, context) {
96
+ var results = [];
97
+ if (obj == null) return results;
98
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
99
+ each(obj, function(value, index, list) {
100
+ results[results.length] = iterator.call(context, value, index, list);
101
+ });
102
+ return results;
103
+ };
104
+
105
+ var reduceError = 'Reduce of empty array with no initial value';
106
+
107
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
108
+ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
109
+ _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
110
+ var initial = arguments.length > 2;
111
+ if (obj == null) obj = [];
112
+ if (nativeReduce && obj.reduce === nativeReduce) {
113
+ if (context) iterator = _.bind(iterator, context);
114
+ return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
115
+ }
116
+ each(obj, function(value, index, list) {
117
+ if (!initial) {
118
+ memo = value;
119
+ initial = true;
120
+ } else {
121
+ memo = iterator.call(context, memo, value, index, list);
122
+ }
123
+ });
124
+ if (!initial) throw new TypeError(reduceError);
125
+ return memo;
126
+ };
127
+
128
+ // The right-associative version of reduce, also known as `foldr`.
129
+ // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
130
+ _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
131
+ var initial = arguments.length > 2;
132
+ if (obj == null) obj = [];
133
+ if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
134
+ if (context) iterator = _.bind(iterator, context);
135
+ return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
136
+ }
137
+ var length = obj.length;
138
+ if (length !== +length) {
139
+ var keys = _.keys(obj);
140
+ length = keys.length;
141
+ }
142
+ each(obj, function(value, index, list) {
143
+ index = keys ? keys[--length] : --length;
144
+ if (!initial) {
145
+ memo = obj[index];
146
+ initial = true;
147
+ } else {
148
+ memo = iterator.call(context, memo, obj[index], index, list);
149
+ }
150
+ });
151
+ if (!initial) throw new TypeError(reduceError);
152
+ return memo;
153
+ };
154
+
155
+ // Return the first value which passes a truth test. Aliased as `detect`.
156
+ _.find = _.detect = function(obj, iterator, context) {
157
+ var result;
158
+ any(obj, function(value, index, list) {
159
+ if (iterator.call(context, value, index, list)) {
160
+ result = value;
161
+ return true;
162
+ }
163
+ });
164
+ return result;
165
+ };
166
+
167
+ // Return all the elements that pass a truth test.
168
+ // Delegates to **ECMAScript 5**'s native `filter` if available.
169
+ // Aliased as `select`.
170
+ _.filter = _.select = function(obj, iterator, context) {
171
+ var results = [];
172
+ if (obj == null) return results;
173
+ if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
174
+ each(obj, function(value, index, list) {
175
+ if (iterator.call(context, value, index, list)) results[results.length] = value;
176
+ });
177
+ return results;
178
+ };
179
+
180
+ // Return all the elements for which a truth test fails.
181
+ _.reject = function(obj, iterator, context) {
182
+ return _.filter(obj, function(value, index, list) {
183
+ return !iterator.call(context, value, index, list);
184
+ }, context);
185
+ };
186
+
187
+ // Determine whether all of the elements match a truth test.
188
+ // Delegates to **ECMAScript 5**'s native `every` if available.
189
+ // Aliased as `all`.
190
+ _.every = _.all = function(obj, iterator, context) {
191
+ iterator || (iterator = _.identity);
192
+ var result = true;
193
+ if (obj == null) return result;
194
+ if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
195
+ each(obj, function(value, index, list) {
196
+ if (!(result = result && iterator.call(context, value, index, list))) return breaker;
197
+ });
198
+ return !!result;
199
+ };
200
+
201
+ // Determine if at least one element in the object matches a truth test.
202
+ // Delegates to **ECMAScript 5**'s native `some` if available.
203
+ // Aliased as `any`.
204
+ var any = _.some = _.any = function(obj, iterator, context) {
205
+ iterator || (iterator = _.identity);
206
+ var result = false;
207
+ if (obj == null) return result;
208
+ if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
209
+ each(obj, function(value, index, list) {
210
+ if (result || (result = iterator.call(context, value, index, list))) return breaker;
211
+ });
212
+ return !!result;
213
+ };
214
+
215
+ // Determine if the array or object contains a given value (using `===`).
216
+ // Aliased as `include`.
217
+ _.contains = _.include = function(obj, target) {
218
+ if (obj == null) return false;
219
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
220
+ return any(obj, function(value) {
221
+ return value === target;
222
+ });
223
+ };
224
+
225
+ // Invoke a method (with arguments) on every item in a collection.
226
+ _.invoke = function(obj, method) {
227
+ var args = slice.call(arguments, 2);
228
+ var isFunc = _.isFunction(method);
229
+ return _.map(obj, function(value) {
230
+ return (isFunc ? method : value[method]).apply(value, args);
231
+ });
232
+ };
233
+
234
+ // Convenience version of a common use case of `map`: fetching a property.
235
+ _.pluck = function(obj, key) {
236
+ return _.map(obj, function(value){ return value[key]; });
237
+ };
238
+
239
+ // Convenience version of a common use case of `filter`: selecting only objects
240
+ // containing specific `key:value` pairs.
241
+ _.where = function(obj, attrs, first) {
242
+ if (_.isEmpty(attrs)) return first ? null : [];
243
+ return _[first ? 'find' : 'filter'](obj, function(value) {
244
+ for (var key in attrs) {
245
+ if (attrs[key] !== value[key]) return false;
246
+ }
247
+ return true;
248
+ });
249
+ };
250
+
251
+ // Convenience version of a common use case of `find`: getting the first object
252
+ // containing specific `key:value` pairs.
253
+ _.findWhere = function(obj, attrs) {
254
+ return _.where(obj, attrs, true);
255
+ };
256
+
257
+ // Return the maximum element or (element-based computation).
258
+ // Can't optimize arrays of integers longer than 65,535 elements.
259
+ // See: https://bugs.webkit.org/show_bug.cgi?id=80797
260
+ _.max = function(obj, iterator, context) {
261
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
262
+ return Math.max.apply(Math, obj);
263
+ }
264
+ if (!iterator && _.isEmpty(obj)) return -Infinity;
265
+ var result = {computed : -Infinity, value: -Infinity};
266
+ each(obj, function(value, index, list) {
267
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
268
+ computed >= result.computed && (result = {value : value, computed : computed});
269
+ });
270
+ return result.value;
271
+ };
272
+
273
+ // Return the minimum element (or element-based computation).
274
+ _.min = function(obj, iterator, context) {
275
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
276
+ return Math.min.apply(Math, obj);
277
+ }
278
+ if (!iterator && _.isEmpty(obj)) return Infinity;
279
+ var result = {computed : Infinity, value: Infinity};
280
+ each(obj, function(value, index, list) {
281
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
282
+ computed < result.computed && (result = {value : value, computed : computed});
283
+ });
284
+ return result.value;
285
+ };
286
+
287
+ // Shuffle an array.
288
+ _.shuffle = function(obj) {
289
+ var rand;
290
+ var index = 0;
291
+ var shuffled = [];
292
+ each(obj, function(value) {
293
+ rand = _.random(index++);
294
+ shuffled[index - 1] = shuffled[rand];
295
+ shuffled[rand] = value;
296
+ });
297
+ return shuffled;
298
+ };
299
+
300
+ // An internal function to generate lookup iterators.
301
+ var lookupIterator = function(value) {
302
+ return _.isFunction(value) ? value : function(obj){ return obj[value]; };
303
+ };
304
+
305
+ // Sort the object's values by a criterion produced by an iterator.
306
+ _.sortBy = function(obj, value, context) {
307
+ var iterator = lookupIterator(value);
308
+ return _.pluck(_.map(obj, function(value, index, list) {
309
+ return {
310
+ value : value,
311
+ index : index,
312
+ criteria : iterator.call(context, value, index, list)
313
+ };
314
+ }).sort(function(left, right) {
315
+ var a = left.criteria;
316
+ var b = right.criteria;
317
+ if (a !== b) {
318
+ if (a > b || a === void 0) return 1;
319
+ if (a < b || b === void 0) return -1;
320
+ }
321
+ return left.index < right.index ? -1 : 1;
322
+ }), 'value');
323
+ };
324
+
325
+ // An internal function used for aggregate "group by" operations.
326
+ var group = function(obj, value, context, behavior) {
327
+ var result = {};
328
+ var iterator = lookupIterator(value || _.identity);
329
+ each(obj, function(value, index) {
330
+ var key = iterator.call(context, value, index, obj);
331
+ behavior(result, key, value);
332
+ });
333
+ return result;
334
+ };
335
+
336
+ // Groups the object's values by a criterion. Pass either a string attribute
337
+ // to group by, or a function that returns the criterion.
338
+ _.groupBy = function(obj, value, context) {
339
+ return group(obj, value, context, function(result, key, value) {
340
+ (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
341
+ });
342
+ };
343
+
344
+ // Counts instances of an object that group by a certain criterion. Pass
345
+ // either a string attribute to count by, or a function that returns the
346
+ // criterion.
347
+ _.countBy = function(obj, value, context) {
348
+ return group(obj, value, context, function(result, key) {
349
+ if (!_.has(result, key)) result[key] = 0;
350
+ result[key]++;
351
+ });
352
+ };
353
+
354
+ // Use a comparator function to figure out the smallest index at which
355
+ // an object should be inserted so as to maintain order. Uses binary search.
356
+ _.sortedIndex = function(array, obj, iterator, context) {
357
+ iterator = iterator == null ? _.identity : lookupIterator(iterator);
358
+ var value = iterator.call(context, obj);
359
+ var low = 0, high = array.length;
360
+ while (low < high) {
361
+ var mid = (low + high) >>> 1;
362
+ iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
363
+ }
364
+ return low;
365
+ };
366
+
367
+ // Safely convert anything iterable into a real, live array.
368
+ _.toArray = function(obj) {
369
+ if (!obj) return [];
370
+ if (_.isArray(obj)) return slice.call(obj);
371
+ if (obj.length === +obj.length) return _.map(obj, _.identity);
372
+ return _.values(obj);
373
+ };
374
+
375
+ // Return the number of elements in an object.
376
+ _.size = function(obj) {
377
+ if (obj == null) return 0;
378
+ return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
379
+ };
380
+
381
+ // Array Functions
382
+ // ---------------
383
+
384
+ // Get the first element of an array. Passing **n** will return the first N
385
+ // values in the array. Aliased as `head` and `take`. The **guard** check
386
+ // allows it to work with `_.map`.
387
+ _.first = _.head = _.take = function(array, n, guard) {
388
+ if (array == null) return void 0;
389
+ return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
390
+ };
391
+
392
+ // Returns everything but the last entry of the array. Especially useful on
393
+ // the arguments object. Passing **n** will return all the values in
394
+ // the array, excluding the last N. The **guard** check allows it to work with
395
+ // `_.map`.
396
+ _.initial = function(array, n, guard) {
397
+ return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
398
+ };
399
+
400
+ // Get the last element of an array. Passing **n** will return the last N
401
+ // values in the array. The **guard** check allows it to work with `_.map`.
402
+ _.last = function(array, n, guard) {
403
+ if (array == null) return void 0;
404
+ if ((n != null) && !guard) {
405
+ return slice.call(array, Math.max(array.length - n, 0));
406
+ } else {
407
+ return array[array.length - 1];
408
+ }
409
+ };
410
+
411
+ // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
412
+ // Especially useful on the arguments object. Passing an **n** will return
413
+ // the rest N values in the array. The **guard**
414
+ // check allows it to work with `_.map`.
415
+ _.rest = _.tail = _.drop = function(array, n, guard) {
416
+ return slice.call(array, (n == null) || guard ? 1 : n);
417
+ };
418
+
419
+ // Trim out all falsy values from an array.
420
+ _.compact = function(array) {
421
+ return _.filter(array, _.identity);
422
+ };
423
+
424
+ // Internal implementation of a recursive `flatten` function.
425
+ var flatten = function(input, shallow, output) {
426
+ each(input, function(value) {
427
+ if (_.isArray(value)) {
428
+ shallow ? push.apply(output, value) : flatten(value, shallow, output);
429
+ } else {
430
+ output.push(value);
431
+ }
432
+ });
433
+ return output;
434
+ };
435
+
436
+ // Return a completely flattened version of an array.
437
+ _.flatten = function(array, shallow) {
438
+ return flatten(array, shallow, []);
439
+ };
440
+
441
+ // Return a version of the array that does not contain the specified value(s).
442
+ _.without = function(array) {
443
+ return _.difference(array, slice.call(arguments, 1));
444
+ };
445
+
446
+ // Produce a duplicate-free version of the array. If the array has already
447
+ // been sorted, you have the option of using a faster algorithm.
448
+ // Aliased as `unique`.
449
+ _.uniq = _.unique = function(array, isSorted, iterator, context) {
450
+ if (_.isFunction(isSorted)) {
451
+ context = iterator;
452
+ iterator = isSorted;
453
+ isSorted = false;
454
+ }
455
+ var initial = iterator ? _.map(array, iterator, context) : array;
456
+ var results = [];
457
+ var seen = [];
458
+ each(initial, function(value, index) {
459
+ if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
460
+ seen.push(value);
461
+ results.push(array[index]);
462
+ }
463
+ });
464
+ return results;
465
+ };
466
+
467
+ // Produce an array that contains the union: each distinct element from all of
468
+ // the passed-in arrays.
469
+ _.union = function() {
470
+ return _.uniq(concat.apply(ArrayProto, arguments));
471
+ };
472
+
473
+ // Produce an array that contains every item shared between all the
474
+ // passed-in arrays.
475
+ _.intersection = function(array) {
476
+ var rest = slice.call(arguments, 1);
477
+ return _.filter(_.uniq(array), function(item) {
478
+ return _.every(rest, function(other) {
479
+ return _.indexOf(other, item) >= 0;
480
+ });
481
+ });
482
+ };
483
+
484
+ // Take the difference between one array and a number of other arrays.
485
+ // Only the elements present in just the first array will remain.
486
+ _.difference = function(array) {
487
+ var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
488
+ return _.filter(array, function(value){ return !_.contains(rest, value); });
489
+ };
490
+
491
+ // Zip together multiple lists into a single array -- elements that share
492
+ // an index go together.
493
+ _.zip = function() {
494
+ var args = slice.call(arguments);
495
+ var length = _.max(_.pluck(args, 'length'));
496
+ var results = new Array(length);
497
+ for (var i = 0; i < length; i++) {
498
+ results[i] = _.pluck(args, "" + i);
499
+ }
500
+ return results;
501
+ };
502
+
503
+ // Converts lists into objects. Pass either a single array of `[key, value]`
504
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
505
+ // the corresponding values.
506
+ _.object = function(list, values) {
507
+ if (list == null) return {};
508
+ var result = {};
509
+ for (var i = 0, l = list.length; i < l; i++) {
510
+ if (values) {
511
+ result[list[i]] = values[i];
512
+ } else {
513
+ result[list[i][0]] = list[i][1];
514
+ }
515
+ }
516
+ return result;
517
+ };
518
+
519
+ // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
520
+ // we need this function. Return the position of the first occurrence of an
521
+ // item in an array, or -1 if the item is not included in the array.
522
+ // Delegates to **ECMAScript 5**'s native `indexOf` if available.
523
+ // If the array is large and already in sort order, pass `true`
524
+ // for **isSorted** to use binary search.
525
+ _.indexOf = function(array, item, isSorted) {
526
+ if (array == null) return -1;
527
+ var i = 0, l = array.length;
528
+ if (isSorted) {
529
+ if (typeof isSorted == 'number') {
530
+ i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
531
+ } else {
532
+ i = _.sortedIndex(array, item);
533
+ return array[i] === item ? i : -1;
534
+ }
535
+ }
536
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
537
+ for (; i < l; i++) if (array[i] === item) return i;
538
+ return -1;
539
+ };
540
+
541
+ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
542
+ _.lastIndexOf = function(array, item, from) {
543
+ if (array == null) return -1;
544
+ var hasIndex = from != null;
545
+ if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
546
+ return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
547
+ }
548
+ var i = (hasIndex ? from : array.length);
549
+ while (i--) if (array[i] === item) return i;
550
+ return -1;
551
+ };
552
+
553
+ // Generate an integer Array containing an arithmetic progression. A port of
554
+ // the native Python `range()` function. See
555
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
556
+ _.range = function(start, stop, step) {
557
+ if (arguments.length <= 1) {
558
+ stop = start || 0;
559
+ start = 0;
560
+ }
561
+ step = arguments[2] || 1;
562
+
563
+ var len = Math.max(Math.ceil((stop - start) / step), 0);
564
+ var idx = 0;
565
+ var range = new Array(len);
566
+
567
+ while(idx < len) {
568
+ range[idx++] = start;
569
+ start += step;
570
+ }
571
+
572
+ return range;
573
+ };
574
+
575
+ // Function (ahem) Functions
576
+ // ------------------
577
+
578
+ // Create a function bound to a given object (assigning `this`, and arguments,
579
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
580
+ // available.
581
+ _.bind = function(func, context) {
582
+ if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
583
+ var args = slice.call(arguments, 2);
584
+ return function() {
585
+ return func.apply(context, args.concat(slice.call(arguments)));
586
+ };
587
+ };
588
+
589
+ // Partially apply a function by creating a version that has had some of its
590
+ // arguments pre-filled, without changing its dynamic `this` context.
591
+ _.partial = function(func) {
592
+ var args = slice.call(arguments, 1);
593
+ return function() {
594
+ return func.apply(this, args.concat(slice.call(arguments)));
595
+ };
596
+ };
597
+
598
+ // Bind all of an object's methods to that object. Useful for ensuring that
599
+ // all callbacks defined on an object belong to it.
600
+ _.bindAll = function(obj) {
601
+ var funcs = slice.call(arguments, 1);
602
+ if (funcs.length === 0) funcs = _.functions(obj);
603
+ each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
604
+ return obj;
605
+ };
606
+
607
+ // Memoize an expensive function by storing its results.
608
+ _.memoize = function(func, hasher) {
609
+ var memo = {};
610
+ hasher || (hasher = _.identity);
611
+ return function() {
612
+ var key = hasher.apply(this, arguments);
613
+ return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
614
+ };
615
+ };
616
+
617
+ // Delays a function for the given number of milliseconds, and then calls
618
+ // it with the arguments supplied.
619
+ _.delay = function(func, wait) {
620
+ var args = slice.call(arguments, 2);
621
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
622
+ };
623
+
624
+ // Defers a function, scheduling it to run after the current call stack has
625
+ // cleared.
626
+ _.defer = function(func) {
627
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
628
+ };
629
+
630
+ // Returns a function, that, when invoked, will only be triggered at most once
631
+ // during a given window of time.
632
+ _.throttle = function(func, wait) {
633
+ var context, args, timeout, result;
634
+ var previous = 0;
635
+ var later = function() {
636
+ previous = new Date;
637
+ timeout = null;
638
+ result = func.apply(context, args);
639
+ };
640
+ return function() {
641
+ var now = new Date;
642
+ var remaining = wait - (now - previous);
643
+ context = this;
644
+ args = arguments;
645
+ if (remaining <= 0) {
646
+ clearTimeout(timeout);
647
+ timeout = null;
648
+ previous = now;
649
+ result = func.apply(context, args);
650
+ } else if (!timeout) {
651
+ timeout = setTimeout(later, remaining);
652
+ }
653
+ return result;
654
+ };
655
+ };
656
+
657
+ // Returns a function, that, as long as it continues to be invoked, will not
658
+ // be triggered. The function will be called after it stops being called for
659
+ // N milliseconds. If `immediate` is passed, trigger the function on the
660
+ // leading edge, instead of the trailing.
661
+ _.debounce = function(func, wait, immediate) {
662
+ var timeout, result;
663
+ return function() {
664
+ var context = this, args = arguments;
665
+ var later = function() {
666
+ timeout = null;
667
+ if (!immediate) result = func.apply(context, args);
668
+ };
669
+ var callNow = immediate && !timeout;
670
+ clearTimeout(timeout);
671
+ timeout = setTimeout(later, wait);
672
+ if (callNow) result = func.apply(context, args);
673
+ return result;
674
+ };
675
+ };
676
+
677
+ // Returns a function that will be executed at most one time, no matter how
678
+ // often you call it. Useful for lazy initialization.
679
+ _.once = function(func) {
680
+ var ran = false, memo;
681
+ return function() {
682
+ if (ran) return memo;
683
+ ran = true;
684
+ memo = func.apply(this, arguments);
685
+ func = null;
686
+ return memo;
687
+ };
688
+ };
689
+
690
+ // Returns the first function passed as an argument to the second,
691
+ // allowing you to adjust arguments, run code before and after, and
692
+ // conditionally execute the original function.
693
+ _.wrap = function(func, wrapper) {
694
+ return function() {
695
+ var args = [func];
696
+ push.apply(args, arguments);
697
+ return wrapper.apply(this, args);
698
+ };
699
+ };
700
+
701
+ // Returns a function that is the composition of a list of functions, each
702
+ // consuming the return value of the function that follows.
703
+ _.compose = function() {
704
+ var funcs = arguments;
705
+ return function() {
706
+ var args = arguments;
707
+ for (var i = funcs.length - 1; i >= 0; i--) {
708
+ args = [funcs[i].apply(this, args)];
709
+ }
710
+ return args[0];
711
+ };
712
+ };
713
+
714
+ // Returns a function that will only be executed after being called N times.
715
+ _.after = function(times, func) {
716
+ if (times <= 0) return func();
717
+ return function() {
718
+ if (--times < 1) {
719
+ return func.apply(this, arguments);
720
+ }
721
+ };
722
+ };
723
+
724
+ // Object Functions
725
+ // ----------------
726
+
727
+ // Retrieve the names of an object's properties.
728
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
729
+ _.keys = nativeKeys || function(obj) {
730
+ if (obj !== Object(obj)) throw new TypeError('Invalid object');
731
+ var keys = [];
732
+ for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
733
+ return keys;
734
+ };
735
+
736
+ // Retrieve the values of an object's properties.
737
+ _.values = function(obj) {
738
+ var values = [];
739
+ for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
740
+ return values;
741
+ };
742
+
743
+ // Convert an object into a list of `[key, value]` pairs.
744
+ _.pairs = function(obj) {
745
+ var pairs = [];
746
+ for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
747
+ return pairs;
748
+ };
749
+
750
+ // Invert the keys and values of an object. The values must be serializable.
751
+ _.invert = function(obj) {
752
+ var result = {};
753
+ for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
754
+ return result;
755
+ };
756
+
757
+ // Return a sorted list of the function names available on the object.
758
+ // Aliased as `methods`
759
+ _.functions = _.methods = function(obj) {
760
+ var names = [];
761
+ for (var key in obj) {
762
+ if (_.isFunction(obj[key])) names.push(key);
763
+ }
764
+ return names.sort();
765
+ };
766
+
767
+ // Extend a given object with all the properties in passed-in object(s).
768
+ _.extend = function(obj) {
769
+ each(slice.call(arguments, 1), function(source) {
770
+ if (source) {
771
+ for (var prop in source) {
772
+ obj[prop] = source[prop];
773
+ }
774
+ }
775
+ });
776
+ return obj;
777
+ };
778
+
779
+ // Return a copy of the object only containing the whitelisted properties.
780
+ _.pick = function(obj) {
781
+ var copy = {};
782
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
783
+ each(keys, function(key) {
784
+ if (key in obj) copy[key] = obj[key];
785
+ });
786
+ return copy;
787
+ };
788
+
789
+ // Return a copy of the object without the blacklisted properties.
790
+ _.omit = function(obj) {
791
+ var copy = {};
792
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
793
+ for (var key in obj) {
794
+ if (!_.contains(keys, key)) copy[key] = obj[key];
795
+ }
796
+ return copy;
797
+ };
798
+
799
+ // Fill in a given object with default properties.
800
+ _.defaults = function(obj) {
801
+ each(slice.call(arguments, 1), function(source) {
802
+ if (source) {
803
+ for (var prop in source) {
804
+ if (obj[prop] == null) obj[prop] = source[prop];
805
+ }
806
+ }
807
+ });
808
+ return obj;
809
+ };
810
+
811
+ // Create a (shallow-cloned) duplicate of an object.
812
+ _.clone = function(obj) {
813
+ if (!_.isObject(obj)) return obj;
814
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
815
+ };
816
+
817
+ // Invokes interceptor with the obj, and then returns obj.
818
+ // The primary purpose of this method is to "tap into" a method chain, in
819
+ // order to perform operations on intermediate results within the chain.
820
+ _.tap = function(obj, interceptor) {
821
+ interceptor(obj);
822
+ return obj;
823
+ };
824
+
825
+ // Internal recursive comparison function for `isEqual`.
826
+ var eq = function(a, b, aStack, bStack) {
827
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
828
+ // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
829
+ if (a === b) return a !== 0 || 1 / a == 1 / b;
830
+ // A strict comparison is necessary because `null == undefined`.
831
+ if (a == null || b == null) return a === b;
832
+ // Unwrap any wrapped objects.
833
+ if (a instanceof _) a = a._wrapped;
834
+ if (b instanceof _) b = b._wrapped;
835
+ // Compare `[[Class]]` names.
836
+ var className = toString.call(a);
837
+ if (className != toString.call(b)) return false;
838
+ switch (className) {
839
+ // Strings, numbers, dates, and booleans are compared by value.
840
+ case '[object String]':
841
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
842
+ // equivalent to `new String("5")`.
843
+ return a == String(b);
844
+ case '[object Number]':
845
+ // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
846
+ // other numeric values.
847
+ return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
848
+ case '[object Date]':
849
+ case '[object Boolean]':
850
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
851
+ // millisecond representations. Note that invalid dates with millisecond representations
852
+ // of `NaN` are not equivalent.
853
+ return +a == +b;
854
+ // RegExps are compared by their source patterns and flags.
855
+ case '[object RegExp]':
856
+ return a.source == b.source &&
857
+ a.global == b.global &&
858
+ a.multiline == b.multiline &&
859
+ a.ignoreCase == b.ignoreCase;
860
+ }
861
+ if (typeof a != 'object' || typeof b != 'object') return false;
862
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
863
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
864
+ var length = aStack.length;
865
+ while (length--) {
866
+ // Linear search. Performance is inversely proportional to the number of
867
+ // unique nested structures.
868
+ if (aStack[length] == a) return bStack[length] == b;
869
+ }
870
+ // Add the first object to the stack of traversed objects.
871
+ aStack.push(a);
872
+ bStack.push(b);
873
+ var size = 0, result = true;
874
+ // Recursively compare objects and arrays.
875
+ if (className == '[object Array]') {
876
+ // Compare array lengths to determine if a deep comparison is necessary.
877
+ size = a.length;
878
+ result = size == b.length;
879
+ if (result) {
880
+ // Deep compare the contents, ignoring non-numeric properties.
881
+ while (size--) {
882
+ if (!(result = eq(a[size], b[size], aStack, bStack))) break;
883
+ }
884
+ }
885
+ } else {
886
+ // Objects with different constructors are not equivalent, but `Object`s
887
+ // from different frames are.
888
+ var aCtor = a.constructor, bCtor = b.constructor;
889
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
890
+ _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
891
+ return false;
892
+ }
893
+ // Deep compare objects.
894
+ for (var key in a) {
895
+ if (_.has(a, key)) {
896
+ // Count the expected number of properties.
897
+ size++;
898
+ // Deep compare each member.
899
+ if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
900
+ }
901
+ }
902
+ // Ensure that both objects contain the same number of properties.
903
+ if (result) {
904
+ for (key in b) {
905
+ if (_.has(b, key) && !(size--)) break;
906
+ }
907
+ result = !size;
908
+ }
909
+ }
910
+ // Remove the first object from the stack of traversed objects.
911
+ aStack.pop();
912
+ bStack.pop();
913
+ return result;
914
+ };
915
+
916
+ // Perform a deep comparison to check if two objects are equal.
917
+ _.isEqual = function(a, b) {
918
+ return eq(a, b, [], []);
919
+ };
920
+
921
+ // Is a given array, string, or object empty?
922
+ // An "empty" object has no enumerable own-properties.
923
+ _.isEmpty = function(obj) {
924
+ if (obj == null) return true;
925
+ if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
926
+ for (var key in obj) if (_.has(obj, key)) return false;
927
+ return true;
928
+ };
929
+
930
+ // Is a given value a DOM element?
931
+ _.isElement = function(obj) {
932
+ return !!(obj && obj.nodeType === 1);
933
+ };
934
+
935
+ // Is a given value an array?
936
+ // Delegates to ECMA5's native Array.isArray
937
+ _.isArray = nativeIsArray || function(obj) {
938
+ return toString.call(obj) == '[object Array]';
939
+ };
940
+
941
+ // Is a given variable an object?
942
+ _.isObject = function(obj) {
943
+ return obj === Object(obj);
944
+ };
945
+
946
+ // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
947
+ each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
948
+ _['is' + name] = function(obj) {
949
+ return toString.call(obj) == '[object ' + name + ']';
950
+ };
951
+ });
952
+
953
+ // Define a fallback version of the method in browsers (ahem, IE), where
954
+ // there isn't any inspectable "Arguments" type.
955
+ if (!_.isArguments(arguments)) {
956
+ _.isArguments = function(obj) {
957
+ return !!(obj && _.has(obj, 'callee'));
958
+ };
959
+ }
960
+
961
+ // Optimize `isFunction` if appropriate.
962
+ if (typeof (/./) !== 'function') {
963
+ _.isFunction = function(obj) {
964
+ return typeof obj === 'function';
965
+ };
966
+ }
967
+
968
+ // Is a given object a finite number?
969
+ _.isFinite = function(obj) {
970
+ return isFinite(obj) && !isNaN(parseFloat(obj));
971
+ };
972
+
973
+ // Is the given value `NaN`? (NaN is the only number which does not equal itself).
974
+ _.isNaN = function(obj) {
975
+ return _.isNumber(obj) && obj != +obj;
976
+ };
977
+
978
+ // Is a given value a boolean?
979
+ _.isBoolean = function(obj) {
980
+ return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
981
+ };
982
+
983
+ // Is a given value equal to null?
984
+ _.isNull = function(obj) {
985
+ return obj === null;
986
+ };
987
+
988
+ // Is a given variable undefined?
989
+ _.isUndefined = function(obj) {
990
+ return obj === void 0;
991
+ };
992
+
993
+ // Shortcut function for checking if an object has a given property directly
994
+ // on itself (in other words, not on a prototype).
995
+ _.has = function(obj, key) {
996
+ return hasOwnProperty.call(obj, key);
997
+ };
998
+
999
+ // Utility Functions
1000
+ // -----------------
1001
+
1002
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
1003
+ // previous owner. Returns a reference to the Underscore object.
1004
+ _.noConflict = function() {
1005
+ root._ = previousUnderscore;
1006
+ return this;
1007
+ };
1008
+
1009
+ // Keep the identity function around for default iterators.
1010
+ _.identity = function(value) {
1011
+ return value;
1012
+ };
1013
+
1014
+ // Run a function **n** times.
1015
+ _.times = function(n, iterator, context) {
1016
+ var accum = Array(n);
1017
+ for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
1018
+ return accum;
1019
+ };
1020
+
1021
+ // Return a random integer between min and max (inclusive).
1022
+ _.random = function(min, max) {
1023
+ if (max == null) {
1024
+ max = min;
1025
+ min = 0;
1026
+ }
1027
+ return min + Math.floor(Math.random() * (max - min + 1));
1028
+ };
1029
+
1030
+ // List of HTML entities for escaping.
1031
+ var entityMap = {
1032
+ escape: {
1033
+ '&': '&amp;',
1034
+ '<': '&lt;',
1035
+ '>': '&gt;',
1036
+ '"': '&quot;',
1037
+ "'": '&#x27;',
1038
+ '/': '&#x2F;'
1039
+ }
1040
+ };
1041
+ entityMap.unescape = _.invert(entityMap.escape);
1042
+
1043
+ // Regexes containing the keys and values listed immediately above.
1044
+ var entityRegexes = {
1045
+ escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
1046
+ unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
1047
+ };
1048
+
1049
+ // Functions for escaping and unescaping strings to/from HTML interpolation.
1050
+ _.each(['escape', 'unescape'], function(method) {
1051
+ _[method] = function(string) {
1052
+ if (string == null) return '';
1053
+ return ('' + string).replace(entityRegexes[method], function(match) {
1054
+ return entityMap[method][match];
1055
+ });
1056
+ };
1057
+ });
1058
+
1059
+ // If the value of the named property is a function then invoke it;
1060
+ // otherwise, return it.
1061
+ _.result = function(object, property) {
1062
+ if (object == null) return null;
1063
+ var value = object[property];
1064
+ return _.isFunction(value) ? value.call(object) : value;
1065
+ };
1066
+
1067
+ // Add your own custom functions to the Underscore object.
1068
+ _.mixin = function(obj) {
1069
+ each(_.functions(obj), function(name){
1070
+ var func = _[name] = obj[name];
1071
+ _.prototype[name] = function() {
1072
+ var args = [this._wrapped];
1073
+ push.apply(args, arguments);
1074
+ return result.call(this, func.apply(_, args));
1075
+ };
1076
+ });
1077
+ };
1078
+
1079
+ // Generate a unique integer id (unique within the entire client session).
1080
+ // Useful for temporary DOM ids.
1081
+ var idCounter = 0;
1082
+ _.uniqueId = function(prefix) {
1083
+ var id = ++idCounter + '';
1084
+ return prefix ? prefix + id : id;
1085
+ };
1086
+
1087
+ // By default, Underscore uses ERB-style template delimiters, change the
1088
+ // following template settings to use alternative delimiters.
1089
+ _.templateSettings = {
1090
+ evaluate : /<%([\s\S]+?)%>/g,
1091
+ interpolate : /<%=([\s\S]+?)%>/g,
1092
+ escape : /<%-([\s\S]+?)%>/g
1093
+ };
1094
+
1095
+ // When customizing `templateSettings`, if you don't want to define an
1096
+ // interpolation, evaluation or escaping regex, we need one that is
1097
+ // guaranteed not to match.
1098
+ var noMatch = /(.)^/;
1099
+
1100
+ // Certain characters need to be escaped so that they can be put into a
1101
+ // string literal.
1102
+ var escapes = {
1103
+ "'": "'",
1104
+ '\\': '\\',
1105
+ '\r': 'r',
1106
+ '\n': 'n',
1107
+ '\t': 't',
1108
+ '\u2028': 'u2028',
1109
+ '\u2029': 'u2029'
1110
+ };
1111
+
1112
+ var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
1113
+
1114
+ // JavaScript micro-templating, similar to John Resig's implementation.
1115
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
1116
+ // and correctly escapes quotes within interpolated code.
1117
+ _.template = function(text, data, settings) {
1118
+ var render;
1119
+ settings = _.defaults({}, settings, _.templateSettings);
1120
+
1121
+ // Combine delimiters into one regular expression via alternation.
1122
+ var matcher = new RegExp([
1123
+ (settings.escape || noMatch).source,
1124
+ (settings.interpolate || noMatch).source,
1125
+ (settings.evaluate || noMatch).source
1126
+ ].join('|') + '|$', 'g');
1127
+
1128
+ // Compile the template source, escaping string literals appropriately.
1129
+ var index = 0;
1130
+ var source = "__p+='";
1131
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
1132
+ source += text.slice(index, offset)
1133
+ .replace(escaper, function(match) { return '\\' + escapes[match]; });
1134
+
1135
+ if (escape) {
1136
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
1137
+ }
1138
+ if (interpolate) {
1139
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
1140
+ }
1141
+ if (evaluate) {
1142
+ source += "';\n" + evaluate + "\n__p+='";
1143
+ }
1144
+ index = offset + match.length;
1145
+ return match;
1146
+ });
1147
+ source += "';\n";
1148
+
1149
+ // If a variable is not specified, place data values in local scope.
1150
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
1151
+
1152
+ source = "var __t,__p='',__j=Array.prototype.join," +
1153
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
1154
+ source + "return __p;\n";
1155
+
1156
+ try {
1157
+ render = new Function(settings.variable || 'obj', '_', source);
1158
+ } catch (e) {
1159
+ e.source = source;
1160
+ throw e;
1161
+ }
1162
+
1163
+ if (data) return render(data, _);
1164
+ var template = function(data) {
1165
+ return render.call(this, data, _);
1166
+ };
1167
+
1168
+ // Provide the compiled function source as a convenience for precompilation.
1169
+ template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
1170
+
1171
+ return template;
1172
+ };
1173
+
1174
+ // Add a "chain" function, which will delegate to the wrapper.
1175
+ _.chain = function(obj) {
1176
+ return _(obj).chain();
1177
+ };
1178
+
1179
+ // OOP
1180
+ // ---------------
1181
+ // If Underscore is called as a function, it returns a wrapped object that
1182
+ // can be used OO-style. This wrapper holds altered versions of all the
1183
+ // underscore functions. Wrapped objects may be chained.
1184
+
1185
+ // Helper function to continue chaining intermediate results.
1186
+ var result = function(obj) {
1187
+ return this._chain ? _(obj).chain() : obj;
1188
+ };
1189
+
1190
+ // Add all of the Underscore functions to the wrapper object.
1191
+ _.mixin(_);
1192
+
1193
+ // Add all mutator Array functions to the wrapper.
1194
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1195
+ var method = ArrayProto[name];
1196
+ _.prototype[name] = function() {
1197
+ var obj = this._wrapped;
1198
+ method.apply(obj, arguments);
1199
+ if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
1200
+ return result.call(this, obj);
1201
+ };
1202
+ });
1203
+
1204
+ // Add all accessor Array functions to the wrapper.
1205
+ each(['concat', 'join', 'slice'], function(name) {
1206
+ var method = ArrayProto[name];
1207
+ _.prototype[name] = function() {
1208
+ return result.call(this, method.apply(this._wrapped, arguments));
1209
+ };
1210
+ });
1211
+
1212
+ _.extend(_.prototype, {
1213
+
1214
+ // Start chaining a wrapped Underscore object.
1215
+ chain: function() {
1216
+ this._chain = true;
1217
+ return this;
1218
+ },
1219
+
1220
+ // Extracts the result from a wrapped and chained object.
1221
+ value: function() {
1222
+ return this._wrapped;
1223
+ }
1224
+
1225
+ });
1226
+
1227
+ }).call(this);