lady_josephine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/app/assets/fonts/lady_josephine/icons/icons.eot +0 -0
  5. data/app/assets/fonts/lady_josephine/icons/icons.svg +215 -0
  6. data/app/assets/fonts/lady_josephine/icons/icons.ttf +0 -0
  7. data/app/assets/fonts/lady_josephine/icons/icons.woff +0 -0
  8. data/app/assets/javascripts/lady_josephine/blocks/facebook.js +25 -0
  9. data/app/assets/javascripts/lady_josephine/blocks/instagram.js +22 -0
  10. data/app/assets/javascripts/lady_josephine/blocks/soundcloud.js +24 -0
  11. data/app/assets/javascripts/lady_josephine/blocks/twitter.js +25 -0
  12. data/app/assets/javascripts/lady_josephine/blocks/vimeo.js +55 -0
  13. data/app/assets/javascripts/lady_josephine/blocks/youtube.js +64 -0
  14. data/app/assets/javascripts/lady_josephine/editor.js +40 -0
  15. data/app/assets/javascripts/lady_josephine/lady_josephine.js +4 -0
  16. data/app/assets/javascripts/lady_josephine/lady_josephine_view.js +6 -0
  17. data/app/assets/stylesheets/lady_josephine/content.sass +33 -0
  18. data/app/assets/stylesheets/lady_josephine/icons.sass +175 -0
  19. data/app/assets/stylesheets/lady_josephine/lady_josephine.sass +6 -0
  20. data/app/assets/stylesheets/lady_josephine/sir_trevor.sass +619 -0
  21. data/app/assets/stylesheets/lady_josephine/vars.sass +36 -0
  22. data/app/controllers/lady_josephine/application_controller.rb +4 -0
  23. data/app/controllers/lady_josephine/editor_controller.rb +40 -0
  24. data/app/controllers/lady_josephine/images_controller.rb +26 -0
  25. data/app/helpers/lady_josephine/helper.rb +25 -0
  26. data/app/helpers/lady_josephine/sir_trevor_helper.rb +172 -0
  27. data/app/models/lady_josephine/concerns/model.rb +29 -0
  28. data/app/models/lady_josephine/concerns/pingable.rb +28 -0
  29. data/app/models/lady_josephine/concerns/server_uuid.rb +24 -0
  30. data/app/models/lady_josephine/concerns/sir_trevor_images.rb +38 -0
  31. data/app/models/lady_josephine/image.rb +41 -0
  32. data/app/uploader/lady_josephine/base_uploader.rb +47 -0
  33. data/app/uploader/lady_josephine/image_uploader.rb +149 -0
  34. data/app/views/lady_josephine/blocks/_audio_block.haml +2 -0
  35. data/app/views/lady_josephine/blocks/_definition_block.haml +4 -0
  36. data/app/views/lady_josephine/blocks/_divider_block.haml +2 -0
  37. data/app/views/lady_josephine/blocks/_extended_image_block.haml +63 -0
  38. data/app/views/lady_josephine/blocks/_extended_quote_block.haml +5 -0
  39. data/app/views/lady_josephine/blocks/_extended_tweet_block.haml +2 -0
  40. data/app/views/lady_josephine/blocks/_facebook_post_block.haml +2 -0
  41. data/app/views/lady_josephine/blocks/_heading_block.haml +2 -0
  42. data/app/views/lady_josephine/blocks/_html_block.haml +1 -0
  43. data/app/views/lady_josephine/blocks/_instagram_block.haml +2 -0
  44. data/app/views/lady_josephine/blocks/_list_block.haml +3 -0
  45. data/app/views/lady_josephine/blocks/_quote_block.haml +5 -0
  46. data/app/views/lady_josephine/blocks/_text_block.html.haml +2 -0
  47. data/app/views/lady_josephine/blocks/_video_block.haml +9 -0
  48. data/config/routes.rb +9 -0
  49. data/db/migrate/20160222151500_lady_josephine_image.rb +18 -0
  50. data/lib/generators/lady_josephine_migration/USAGE +9 -0
  51. data/lib/generators/lady_josephine_migration/lady_josephine_migration_generator.rb +17 -0
  52. data/lib/generators/lady_josephine_migration/templates/migration.rb +9 -0
  53. data/lib/lady_josephine.rb +18 -0
  54. data/lib/lady_josephine/engine.rb +18 -0
  55. data/lib/lady_josephine/redcarpet/custom_markdown_formatter.rb +63 -0
  56. data/lib/lady_josephine/renderer/sir_trevor_renderer.rb +16 -0
  57. data/lib/lady_josephine/version.rb +3 -0
  58. data/lib/lady_josephine/whitelist.rb +26 -0
  59. data/lib/tasks/lady_josephine_tasks.rake +4 -0
  60. data/spec/controllers/lady_josephine/editor_controller_spec.rb +58 -0
  61. data/spec/dummy/README.rdoc +28 -0
  62. data/spec/dummy/Rakefile +6 -0
  63. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  65. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  66. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  67. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/spec/dummy/bin/bundle +3 -0
  69. data/spec/dummy/bin/rails +4 -0
  70. data/spec/dummy/bin/rake +4 -0
  71. data/spec/dummy/bin/setup +29 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/config/application.rb +26 -0
  74. data/spec/dummy/config/boot.rb +5 -0
  75. data/spec/dummy/config/database.yml +25 -0
  76. data/spec/dummy/config/environment.rb +5 -0
  77. data/spec/dummy/config/environments/development.rb +41 -0
  78. data/spec/dummy/config/environments/production.rb +79 -0
  79. data/spec/dummy/config/environments/test.rb +42 -0
  80. data/spec/dummy/config/initializers/assets.rb +11 -0
  81. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/spec/dummy/config/initializers/inflections.rb +16 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  86. data/spec/dummy/config/initializers/session_store.rb +3 -0
  87. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/spec/dummy/config/locales/en.yml +23 -0
  89. data/spec/dummy/config/routes.rb +4 -0
  90. data/spec/dummy/config/secrets.yml +22 -0
  91. data/spec/dummy/db/development.sqlite3 +0 -0
  92. data/spec/dummy/db/schema.rb +16 -0
  93. data/spec/dummy/db/test.sqlite3 +0 -0
  94. data/spec/dummy/log/bla +0 -0
  95. data/spec/dummy/public/404.html +67 -0
  96. data/spec/dummy/public/422.html +67 -0
  97. data/spec/dummy/public/500.html +66 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/spec_helper.rb +17 -0
  100. data/vendor/assets/components/Eventable/README.md +12 -0
  101. data/vendor/assets/components/Eventable/bower.json +10 -0
  102. data/vendor/assets/components/Eventable/component.json +11 -0
  103. data/vendor/assets/components/Eventable/eventable.js +207 -0
  104. data/vendor/assets/components/Eventable/package.json +15 -0
  105. data/vendor/assets/components/jquery-autosize/bower.json +30 -0
  106. data/vendor/assets/components/jquery-autosize/demo.html +36 -0
  107. data/vendor/assets/components/jquery-autosize/jquery.autosize.js +273 -0
  108. data/vendor/assets/components/jquery-autosize/jquery.autosize.min.js +6 -0
  109. data/vendor/assets/components/jquery-autosize/package.json +32 -0
  110. data/vendor/assets/components/jquery-autosize/readme.md +216 -0
  111. data/vendor/assets/components/jquery/AUTHORS.txt +163 -0
  112. data/vendor/assets/components/jquery/CONTRIBUTING.md +216 -0
  113. data/vendor/assets/components/jquery/Gruntfile.js +496 -0
  114. data/vendor/assets/components/jquery/MIT-LICENSE.txt +21 -0
  115. data/vendor/assets/components/jquery/README.md +415 -0
  116. data/vendor/assets/components/jquery/build/release-notes.js +59 -0
  117. data/vendor/assets/components/jquery/build/release.js +246 -0
  118. data/vendor/assets/components/jquery/component.json +13 -0
  119. data/vendor/assets/components/jquery/composer.json +35 -0
  120. data/vendor/assets/components/jquery/jquery-migrate.js +496 -0
  121. data/vendor/assets/components/jquery/jquery-migrate.min.js +3 -0
  122. data/vendor/assets/components/jquery/jquery.js +9597 -0
  123. data/vendor/assets/components/jquery/jquery.min.js +5 -0
  124. data/vendor/assets/components/jquery/jquery.min.map +1 -0
  125. data/vendor/assets/components/jquery/package.json +39 -0
  126. data/vendor/assets/components/jquery/speed/benchmark.js +15 -0
  127. data/vendor/assets/components/jquery/speed/benchmarker.css +65 -0
  128. data/vendor/assets/components/jquery/speed/benchmarker.js +181 -0
  129. data/vendor/assets/components/jquery/speed/closest.html +39 -0
  130. data/vendor/assets/components/jquery/speed/css.html +82 -0
  131. data/vendor/assets/components/jquery/speed/event.html +58 -0
  132. data/vendor/assets/components/jquery/speed/filter.html +183 -0
  133. data/vendor/assets/components/jquery/speed/find.html +179 -0
  134. data/vendor/assets/components/jquery/speed/index.html +72 -0
  135. data/vendor/assets/components/jquery/speed/jquery-basis.js +6238 -0
  136. data/vendor/assets/components/jquery/speed/slice.vs.concat.html +47 -0
  137. data/vendor/assets/components/jquery/src/ajax.js +851 -0
  138. data/vendor/assets/components/jquery/src/ajax/jsonp.js +80 -0
  139. data/vendor/assets/components/jquery/src/ajax/script.js +86 -0
  140. data/vendor/assets/components/jquery/src/ajax/xhr.js +207 -0
  141. data/vendor/assets/components/jquery/src/attributes.js +661 -0
  142. data/vendor/assets/components/jquery/src/callbacks.js +196 -0
  143. data/vendor/assets/components/jquery/src/core.js +949 -0
  144. data/vendor/assets/components/jquery/src/css.js +679 -0
  145. data/vendor/assets/components/jquery/src/data.js +340 -0
  146. data/vendor/assets/components/jquery/src/deferred.js +141 -0
  147. data/vendor/assets/components/jquery/src/deprecated.js +4 -0
  148. data/vendor/assets/components/jquery/src/dimensions.js +41 -0
  149. data/vendor/assets/components/jquery/src/effects.js +730 -0
  150. data/vendor/assets/components/jquery/src/event-alias.js +15 -0
  151. data/vendor/assets/components/jquery/src/event.js +991 -0
  152. data/vendor/assets/components/jquery/src/exports.js +18 -0
  153. data/vendor/assets/components/jquery/src/intro.js +20 -0
  154. data/vendor/assets/components/jquery/src/manipulation.js +796 -0
  155. data/vendor/assets/components/jquery/src/offset.js +169 -0
  156. data/vendor/assets/components/jquery/src/outro.js +2 -0
  157. data/vendor/assets/components/jquery/src/queue.js +147 -0
  158. data/vendor/assets/components/jquery/src/serialize.js +99 -0
  159. data/vendor/assets/components/jquery/src/sizzle-jquery.js +9 -0
  160. data/vendor/assets/components/jquery/src/support.js +241 -0
  161. data/vendor/assets/components/jquery/src/traversing.js +275 -0
  162. data/vendor/assets/components/jquery/test/csp.php +16 -0
  163. data/vendor/assets/components/jquery/test/data/1x1.jpg +0 -0
  164. data/vendor/assets/components/jquery/test/data/ajax/unreleasedXHR.html +25 -0
  165. data/vendor/assets/components/jquery/test/data/atom+xml.php +4 -0
  166. data/vendor/assets/components/jquery/test/data/badcall.js +1 -0
  167. data/vendor/assets/components/jquery/test/data/badjson.js +1 -0
  168. data/vendor/assets/components/jquery/test/data/cleanScript.html +10 -0
  169. data/vendor/assets/components/jquery/test/data/core/cc_on.html +22 -0
  170. data/vendor/assets/components/jquery/test/data/dashboard.xml +11 -0
  171. data/vendor/assets/components/jquery/test/data/dimensions/documentLarge.html +17 -0
  172. data/vendor/assets/components/jquery/test/data/dimensions/documentSmall.html +21 -0
  173. data/vendor/assets/components/jquery/test/data/echoData.php +1 -0
  174. data/vendor/assets/components/jquery/test/data/echoQuery.php +1 -0
  175. data/vendor/assets/components/jquery/test/data/errorWithText.php +5 -0
  176. data/vendor/assets/components/jquery/test/data/etag.php +21 -0
  177. data/vendor/assets/components/jquery/test/data/evalScript.php +1 -0
  178. data/vendor/assets/components/jquery/test/data/event/longLoadScript.php +4 -0
  179. data/vendor/assets/components/jquery/test/data/event/promiseReady.html +17 -0
  180. data/vendor/assets/components/jquery/test/data/event/syncReady.html +23 -0
  181. data/vendor/assets/components/jquery/test/data/headers.php +18 -0
  182. data/vendor/assets/components/jquery/test/data/if_modified_since.php +20 -0
  183. data/vendor/assets/components/jquery/test/data/iframe.html +8 -0
  184. data/vendor/assets/components/jquery/test/data/jquery-1.8.2.ajax_xhr.min.js +2 -0
  185. data/vendor/assets/components/jquery/test/data/json.php +13 -0
  186. data/vendor/assets/components/jquery/test/data/json_obj.js +1 -0
  187. data/vendor/assets/components/jquery/test/data/jsonp.php +14 -0
  188. data/vendor/assets/components/jquery/test/data/manipulation/iframe-denied.html +36 -0
  189. data/vendor/assets/components/jquery/test/data/name.html +1 -0
  190. data/vendor/assets/components/jquery/test/data/name.php +24 -0
  191. data/vendor/assets/components/jquery/test/data/nocontent.php +5 -0
  192. data/vendor/assets/components/jquery/test/data/offset/absolute.html +41 -0
  193. data/vendor/assets/components/jquery/test/data/offset/body.html +26 -0
  194. data/vendor/assets/components/jquery/test/data/offset/fixed.html +34 -0
  195. data/vendor/assets/components/jquery/test/data/offset/relative.html +31 -0
  196. data/vendor/assets/components/jquery/test/data/offset/scroll.html +39 -0
  197. data/vendor/assets/components/jquery/test/data/offset/static.html +31 -0
  198. data/vendor/assets/components/jquery/test/data/offset/table.html +43 -0
  199. data/vendor/assets/components/jquery/test/data/params_html.php +12 -0
  200. data/vendor/assets/components/jquery/test/data/readywaitasset.js +1 -0
  201. data/vendor/assets/components/jquery/test/data/readywaitloader.js +25 -0
  202. data/vendor/assets/components/jquery/test/data/script.php +11 -0
  203. data/vendor/assets/components/jquery/test/data/selector/html5_selector.html +114 -0
  204. data/vendor/assets/components/jquery/test/data/selector/sizzle_cache.html +21 -0
  205. data/vendor/assets/components/jquery/test/data/statusText.php +5 -0
  206. data/vendor/assets/components/jquery/test/data/support/bodyBackground.html +28 -0
  207. data/vendor/assets/components/jquery/test/data/support/shrinkWrapBlocks.html +23 -0
  208. data/vendor/assets/components/jquery/test/data/support/testElementCrash.html +17 -0
  209. data/vendor/assets/components/jquery/test/data/test.html +7 -0
  210. data/vendor/assets/components/jquery/test/data/test.js +3 -0
  211. data/vendor/assets/components/jquery/test/data/test.php +7 -0
  212. data/vendor/assets/components/jquery/test/data/test2.html +5 -0
  213. data/vendor/assets/components/jquery/test/data/test3.html +3 -0
  214. data/vendor/assets/components/jquery/test/data/testinit.js +269 -0
  215. data/vendor/assets/components/jquery/test/data/testrunner.js +368 -0
  216. data/vendor/assets/components/jquery/test/data/testsuite.css +155 -0
  217. data/vendor/assets/components/jquery/test/data/text.php +12 -0
  218. data/vendor/assets/components/jquery/test/data/ua.txt +272 -0
  219. data/vendor/assets/components/jquery/test/data/with_fries.xml +25 -0
  220. data/vendor/assets/components/jquery/test/data/with_fries_over_jsonp.php +7 -0
  221. data/vendor/assets/components/jquery/test/delegatetest.html +228 -0
  222. data/vendor/assets/components/jquery/test/hovertest.html +158 -0
  223. data/vendor/assets/components/jquery/test/index.html +330 -0
  224. data/vendor/assets/components/jquery/test/localfile.html +75 -0
  225. data/vendor/assets/components/jquery/test/networkerror.html +84 -0
  226. data/vendor/assets/components/jquery/test/polluted.php +110 -0
  227. data/vendor/assets/components/jquery/test/readywait.html +70 -0
  228. data/vendor/assets/components/jquery/test/unit/ajax.js +1971 -0
  229. data/vendor/assets/components/jquery/test/unit/attributes.js +1332 -0
  230. data/vendor/assets/components/jquery/test/unit/callbacks.js +326 -0
  231. data/vendor/assets/components/jquery/test/unit/core.js +1332 -0
  232. data/vendor/assets/components/jquery/test/unit/css.js +1036 -0
  233. data/vendor/assets/components/jquery/test/unit/data.js +636 -0
  234. data/vendor/assets/components/jquery/test/unit/deferred.js +440 -0
  235. data/vendor/assets/components/jquery/test/unit/deprecated.js +1 -0
  236. data/vendor/assets/components/jquery/test/unit/dimensions.js +461 -0
  237. data/vendor/assets/components/jquery/test/unit/effects.js +2050 -0
  238. data/vendor/assets/components/jquery/test/unit/event.js +2690 -0
  239. data/vendor/assets/components/jquery/test/unit/exports.js +7 -0
  240. data/vendor/assets/components/jquery/test/unit/manipulation.js +2242 -0
  241. data/vendor/assets/components/jquery/test/unit/offset.js +549 -0
  242. data/vendor/assets/components/jquery/test/unit/queue.js +316 -0
  243. data/vendor/assets/components/jquery/test/unit/selector.js +185 -0
  244. data/vendor/assets/components/jquery/test/unit/serialize.js +146 -0
  245. data/vendor/assets/components/jquery/test/unit/support.js +384 -0
  246. data/vendor/assets/components/jquery/test/unit/traversing.js +667 -0
  247. data/vendor/assets/components/jquery/test/xhtml.php +5 -0
  248. data/vendor/assets/components/sir-trevor-js/CHANGELOG.md +44 -0
  249. data/vendor/assets/components/sir-trevor-js/Gemfile +3 -0
  250. data/vendor/assets/components/sir-trevor-js/Gemfile.lock +10 -0
  251. data/vendor/assets/components/sir-trevor-js/Gruntfile.js +109 -0
  252. data/vendor/assets/components/sir-trevor-js/MIT-LICENCE +20 -0
  253. data/vendor/assets/components/sir-trevor-js/Readme.md +84 -0
  254. data/vendor/assets/components/sir-trevor-js/bower.json +21 -0
  255. data/vendor/assets/components/sir-trevor-js/component.json +42 -0
  256. data/vendor/assets/components/sir-trevor-js/contributing.md +74 -0
  257. data/vendor/assets/components/sir-trevor-js/examples-component/component.json +14 -0
  258. data/vendor/assets/components/sir-trevor-js/examples-component/index.html +33 -0
  259. data/vendor/assets/components/sir-trevor-js/examples-component/index.js +29 -0
  260. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/example_block.js +203 -0
  261. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/limit_chars.js +46 -0
  262. data/vendor/assets/components/sir-trevor-js/examples-component/sir-trevor.gif +0 -0
  263. data/vendor/assets/components/sir-trevor-js/locales/cn.js +51 -0
  264. data/vendor/assets/components/sir-trevor-js/locales/de.js +51 -0
  265. data/vendor/assets/components/sir-trevor-js/locales/es.js +51 -0
  266. data/vendor/assets/components/sir-trevor-js/locales/fi.js +51 -0
  267. data/vendor/assets/components/sir-trevor-js/locales/fr.js +51 -0
  268. data/vendor/assets/components/sir-trevor-js/locales/pt.js +52 -0
  269. data/vendor/assets/components/sir-trevor-js/package.json +23 -0
  270. data/vendor/assets/components/sir-trevor-js/sir-trevor-icons.css +6 -0
  271. data/vendor/assets/components/sir-trevor-js/sir-trevor.css +393 -0
  272. data/vendor/assets/components/sir-trevor-js/sir-trevor.css.map +7 -0
  273. data/vendor/assets/components/sir-trevor-js/sir-trevor.js +5481 -0
  274. data/vendor/assets/components/sir-trevor-js/sir-trevor.min.js +13 -0
  275. data/vendor/assets/components/underscore/CNAME +1 -0
  276. data/vendor/assets/components/underscore/CONTRIBUTING.md +9 -0
  277. data/vendor/assets/components/underscore/LICENSE +22 -0
  278. data/vendor/assets/components/underscore/README.md +19 -0
  279. data/vendor/assets/components/underscore/Rakefile +10 -0
  280. data/vendor/assets/components/underscore/docs/docco.css +192 -0
  281. data/vendor/assets/components/underscore/docs/favicon.ico +0 -0
  282. data/vendor/assets/components/underscore/docs/images/background.png +0 -0
  283. data/vendor/assets/components/underscore/docs/images/underscore.png +0 -0
  284. data/vendor/assets/components/underscore/docs/underscore.html +823 -0
  285. data/vendor/assets/components/underscore/favicon.ico +0 -0
  286. data/vendor/assets/components/underscore/index.html +2467 -0
  287. data/vendor/assets/components/underscore/index.js +1 -0
  288. data/vendor/assets/components/underscore/package.json +16 -0
  289. data/vendor/assets/components/underscore/test/arrays.js +200 -0
  290. data/vendor/assets/components/underscore/test/chaining.js +59 -0
  291. data/vendor/assets/components/underscore/test/collections.js +453 -0
  292. data/vendor/assets/components/underscore/test/functions.js +265 -0
  293. data/vendor/assets/components/underscore/test/index.html +44 -0
  294. data/vendor/assets/components/underscore/test/objects.js +570 -0
  295. data/vendor/assets/components/underscore/test/speed.js +75 -0
  296. data/vendor/assets/components/underscore/test/utility.js +266 -0
  297. data/vendor/assets/components/underscore/test/vendor/jquery.js +9404 -0
  298. data/vendor/assets/components/underscore/test/vendor/jslitmus.js +670 -0
  299. data/vendor/assets/components/underscore/test/vendor/qunit.css +235 -0
  300. data/vendor/assets/components/underscore/test/vendor/qunit.js +1977 -0
  301. data/vendor/assets/components/underscore/test/vendor/runner.js +98 -0
  302. data/vendor/assets/components/underscore/underscore-min.js +1 -0
  303. data/vendor/assets/components/underscore/underscore.js +1226 -0
  304. metadata +473 -0
@@ -0,0 +1,98 @@
1
+ /*
2
+ * Qt+WebKit powered headless test runner using Phantomjs
3
+ *
4
+ * Phantomjs installation: http://code.google.com/p/phantomjs/wiki/BuildInstructions
5
+ *
6
+ * Run with:
7
+ * phantomjs runner.js [url-of-your-qunit-testsuite]
8
+ *
9
+ * E.g.
10
+ * phantomjs runner.js http://localhost/qunit/test
11
+ */
12
+
13
+ /*jshint latedef:false */
14
+ /*global phantom:true require:true console:true */
15
+ var url = phantom.args[0],
16
+ page = require('webpage').create();
17
+
18
+ // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
19
+ page.onConsoleMessage = function(msg) {
20
+ console.log(msg);
21
+ };
22
+
23
+ page.onInitialized = function() {
24
+ page.evaluate(addLogging);
25
+ };
26
+ page.open(url, function(status){
27
+ if (status !== "success") {
28
+ console.log("Unable to access network: " + status);
29
+ phantom.exit(1);
30
+ } else {
31
+ // page.evaluate(addLogging);
32
+ var interval = setInterval(function() {
33
+ if (finished()) {
34
+ clearInterval(interval);
35
+ onfinishedTests();
36
+ }
37
+ }, 500);
38
+ }
39
+ });
40
+
41
+ function finished() {
42
+ return page.evaluate(function(){
43
+ return !!window.qunitDone;
44
+ });
45
+ }
46
+
47
+ function onfinishedTests() {
48
+ var output = page.evaluate(function() {
49
+ return JSON.stringify(window.qunitDone);
50
+ });
51
+ phantom.exit(JSON.parse(output).failed > 0 ? 1 : 0);
52
+ }
53
+
54
+ function addLogging() {
55
+ window.document.addEventListener( "DOMContentLoaded", function() {
56
+ var current_test_assertions = [];
57
+
58
+ QUnit.testDone(function(result) {
59
+ var i,
60
+ name = result.module + ': ' + result.name;
61
+
62
+ if (result.failed) {
63
+ console.log('Assertion Failed: ' + name);
64
+
65
+ for (i = 0; i < current_test_assertions.length; i++) {
66
+ console.log(' ' + current_test_assertions[i]);
67
+ }
68
+ }
69
+
70
+ current_test_assertions = [];
71
+ });
72
+
73
+ QUnit.log(function(details) {
74
+ var response;
75
+
76
+ if (details.result) {
77
+ return;
78
+ }
79
+
80
+ response = details.message || '';
81
+
82
+ if (typeof details.expected !== 'undefined') {
83
+ if (response) {
84
+ response += ', ';
85
+ }
86
+
87
+ response += 'expected: ' + details.expected + ', but was: ' + details.actual;
88
+ }
89
+
90
+ current_test_assertions.push('Failed assertion: ' + response);
91
+ });
92
+
93
+ QUnit.done(function(result){
94
+ console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.');
95
+ window.qunitDone = result;
96
+ });
97
+ }, false );
98
+ }
@@ -0,0 +1 @@
1
+ (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,d=e.filter,g=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,_=Object.keys,j=i.bind,w=function(n){return n instanceof w?n:this instanceof w?(this._wrapped=n,void 0):new w(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=w),exports._=w):n._=w,w.VERSION="1.4.4";var A=w.each=w.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a in n)if(w.has(n,a)&&t.call(e,n[a],a,n)===r)return};w.map=w.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e[e.length]=t.call(r,n,u,i)}),e)};var O="Reduce of empty array with no initial value";w.reduce=w.foldl=w.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=w.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(O);return r},w.reduceRight=w.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=w.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=w.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(O);return r},w.find=w.detect=function(n,t,r){var e;return E(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},w.filter=w.select=function(n,t,r){var e=[];return null==n?e:d&&n.filter===d?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&(e[e.length]=n)}),e)},w.reject=function(n,t,r){return w.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},w.every=w.all=function(n,t,e){t||(t=w.identity);var u=!0;return null==n?u:g&&n.every===g?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var E=w.some=w.any=function(n,t,e){t||(t=w.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};w.contains=w.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:E(n,function(n){return n===t})},w.invoke=function(n,t){var r=o.call(arguments,2),e=w.isFunction(t);return w.map(n,function(n){return(e?t:n[t]).apply(n,r)})},w.pluck=function(n,t){return w.map(n,function(n){return n[t]})},w.where=function(n,t,r){return w.isEmpty(t)?r?null:[]:w[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},w.findWhere=function(n,t){return w.where(n,t,!0)},w.max=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.max.apply(Math,n);if(!t&&w.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>=e.computed&&(e={value:n,computed:a})}),e.value},w.min=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.min.apply(Math,n);if(!t&&w.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;e.computed>a&&(e={value:n,computed:a})}),e.value},w.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=w.random(r++),e[r-1]=e[t],e[t]=n}),e};var k=function(n){return w.isFunction(n)?n:function(t){return t[n]}};w.sortBy=function(n,t,r){var e=k(t);return w.pluck(w.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index<t.index?-1:1}),"value")};var F=function(n,t,r,e){var u={},i=k(t||w.identity);return A(n,function(t,a){var o=i.call(r,t,a,n);e(u,o,t)}),u};w.groupBy=function(n,t,r){return F(n,t,r,function(n,t,r){(w.has(n,t)?n[t]:n[t]=[]).push(r)})},w.countBy=function(n,t,r){return F(n,t,r,function(n,t){w.has(n,t)||(n[t]=0),n[t]++})},w.sortedIndex=function(n,t,r,e){r=null==r?w.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;u>r.call(e,n[o])?i=o+1:a=o}return i},w.toArray=function(n){return n?w.isArray(n)?o.call(n):n.length===+n.length?w.map(n,w.identity):w.values(n):[]},w.size=function(n){return null==n?0:n.length===+n.length?n.length:w.keys(n).length},w.first=w.head=w.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},w.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},w.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},w.rest=w.tail=w.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},w.compact=function(n){return w.filter(n,w.identity)};var R=function(n,t,r){return A(n,function(n){w.isArray(n)?t?a.apply(r,n):R(n,t,r):r.push(n)}),r};w.flatten=function(n,t){return R(n,t,[])},w.without=function(n){return w.difference(n,o.call(arguments,1))},w.uniq=w.unique=function(n,t,r,e){w.isFunction(t)&&(e=r,r=t,t=!1);var u=r?w.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:w.contains(a,r))||(a.push(r),i.push(n[e]))}),i},w.union=function(){return w.uniq(c.apply(e,arguments))},w.intersection=function(n){var t=o.call(arguments,1);return w.filter(w.uniq(n),function(n){return w.every(t,function(t){return w.indexOf(t,n)>=0})})},w.difference=function(n){var t=c.apply(e,o.call(arguments,1));return w.filter(n,function(n){return!w.contains(t,n)})},w.zip=function(){for(var n=o.call(arguments),t=w.max(w.pluck(n,"length")),r=Array(t),e=0;t>e;e++)r[e]=w.pluck(n,""+e);return r},w.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},w.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=w.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},w.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},w.range=function(n,t,r){1>=arguments.length&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=Array(e);e>u;)i[u++]=n,n+=r;return i},w.bind=function(n,t){if(n.bind===j&&j)return j.apply(n,o.call(arguments,1));var r=o.call(arguments,2);return function(){return n.apply(t,r.concat(o.call(arguments)))}},w.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},w.bindAll=function(n){var t=o.call(arguments,1);return 0===t.length&&(t=w.functions(n)),A(t,function(t){n[t]=w.bind(n[t],n)}),n},w.memoize=function(n,t){var r={};return t||(t=w.identity),function(){var e=t.apply(this,arguments);return w.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},w.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},w.defer=function(n){return w.delay.apply(w,[n,1].concat(o.call(arguments,1)))},w.throttle=function(n,t){var r,e,u,i,a=0,o=function(){a=new Date,u=null,i=n.apply(r,e)};return function(){var c=new Date,l=t-(c-a);return r=this,e=arguments,0>=l?(clearTimeout(u),u=null,a=c,i=n.apply(r,e)):u||(u=setTimeout(o,l)),i}},w.debounce=function(n,t,r){var e,u;return function(){var i=this,a=arguments,o=function(){e=null,r||(u=n.apply(i,a))},c=r&&!e;return clearTimeout(e),e=setTimeout(o,t),c&&(u=n.apply(i,a)),u}},w.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},w.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},w.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},w.after=function(n,t){return 0>=n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},w.keys=_||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)w.has(n,r)&&(t[t.length]=r);return t},w.values=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push(n[r]);return t},w.pairs=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push([r,n[r]]);return t},w.invert=function(n){var t={};for(var r in n)w.has(n,r)&&(t[n[r]]=r);return t},w.functions=w.methods=function(n){var t=[];for(var r in n)w.isFunction(n[r])&&t.push(r);return t.sort()},w.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},w.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},w.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)w.contains(r,u)||(t[u]=n[u]);return t},w.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)null==n[r]&&(n[r]=t[r])}),n},w.clone=function(n){return w.isObject(n)?w.isArray(n)?n.slice():w.extend({},n):n},w.tap=function(n,t){return t(n),n};var I=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof w&&(n=n._wrapped),t instanceof w&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==t+"";case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;r.push(n),e.push(t);var a=0,o=!0;if("[object Array]"==u){if(a=n.length,o=a==t.length)for(;a--&&(o=I(n[a],t[a],r,e)););}else{var c=n.constructor,f=t.constructor;if(c!==f&&!(w.isFunction(c)&&c instanceof c&&w.isFunction(f)&&f instanceof f))return!1;for(var s in n)if(w.has(n,s)&&(a++,!(o=w.has(t,s)&&I(n[s],t[s],r,e))))break;if(o){for(s in t)if(w.has(t,s)&&!a--)break;o=!a}}return r.pop(),e.pop(),o};w.isEqual=function(n,t){return I(n,t,[],[])},w.isEmpty=function(n){if(null==n)return!0;if(w.isArray(n)||w.isString(n))return 0===n.length;for(var t in n)if(w.has(n,t))return!1;return!0},w.isElement=function(n){return!(!n||1!==n.nodeType)},w.isArray=x||function(n){return"[object Array]"==l.call(n)},w.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){w["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),w.isArguments(arguments)||(w.isArguments=function(n){return!(!n||!w.has(n,"callee"))}),"function"!=typeof/./&&(w.isFunction=function(n){return"function"==typeof n}),w.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},w.isNaN=function(n){return w.isNumber(n)&&n!=+n},w.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},w.isNull=function(n){return null===n},w.isUndefined=function(n){return n===void 0},w.has=function(n,t){return f.call(n,t)},w.noConflict=function(){return n._=t,this},w.identity=function(n){return n},w.times=function(n,t,r){for(var e=Array(n),u=0;n>u;u++)e[u]=t.call(r,u);return e},w.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var M={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};M.unescape=w.invert(M.escape);var S={escape:RegExp("["+w.keys(M.escape).join("")+"]","g"),unescape:RegExp("("+w.keys(M.unescape).join("|")+")","g")};w.each(["escape","unescape"],function(n){w[n]=function(t){return null==t?"":(""+t).replace(S[n],function(t){return M[n][t]})}}),w.result=function(n,t){if(null==n)return null;var r=n[t];return w.isFunction(r)?r.call(n):r},w.mixin=function(n){A(w.functions(n),function(t){var r=w[t]=n[t];w.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),D.call(this,r.apply(w,n))}})};var N=0;w.uniqueId=function(n){var t=++N+"";return n?n+t:t},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var T=/(.)^/,q={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},B=/\\|'|\r|\n|\t|\u2028|\u2029/g;w.template=function(n,t,r){var e;r=w.defaults({},r,w.templateSettings);var u=RegExp([(r.escape||T).source,(r.interpolate||T).source,(r.evaluate||T).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(B,function(n){return"\\"+q[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,w);var c=function(n){return e.call(this,n,w)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},w.chain=function(n){return w(n).chain()};var D=function(n){return this._chain?w(n).chain():n};w.mixin(w),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];w.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],D.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];w.prototype[n]=function(){return D.call(this,t.apply(this._wrapped,arguments))}}),w.extend(w.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
@@ -0,0 +1,1226 @@
1
+ // Underscore.js 1.4.4
2
+ // http://underscorejs.org
3
+ // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
4
+ // Underscore may be freely distributed under the MIT license.
5
+
6
+ (function() {
7
+
8
+ // Baseline setup
9
+ // --------------
10
+
11
+ // Establish the root object, `window` in the browser, or `global` on the server.
12
+ var root = this;
13
+
14
+ // Save the previous value of the `_` variable.
15
+ var previousUnderscore = root._;
16
+
17
+ // Establish the object that gets returned to break out of a loop iteration.
18
+ var breaker = {};
19
+
20
+ // Save bytes in the minified (but not gzipped) version:
21
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
22
+
23
+ // Create quick reference variables for speed access to core prototypes.
24
+ var push = ArrayProto.push,
25
+ slice = ArrayProto.slice,
26
+ concat = ArrayProto.concat,
27
+ toString = ObjProto.toString,
28
+ hasOwnProperty = ObjProto.hasOwnProperty;
29
+
30
+ // All **ECMAScript 5** native function implementations that we hope to use
31
+ // are declared here.
32
+ var
33
+ nativeForEach = ArrayProto.forEach,
34
+ nativeMap = ArrayProto.map,
35
+ nativeReduce = ArrayProto.reduce,
36
+ nativeReduceRight = ArrayProto.reduceRight,
37
+ nativeFilter = ArrayProto.filter,
38
+ nativeEvery = ArrayProto.every,
39
+ nativeSome = ArrayProto.some,
40
+ nativeIndexOf = ArrayProto.indexOf,
41
+ nativeLastIndexOf = ArrayProto.lastIndexOf,
42
+ nativeIsArray = Array.isArray,
43
+ nativeKeys = Object.keys,
44
+ nativeBind = FuncProto.bind;
45
+
46
+ // Create a safe reference to the Underscore object for use below.
47
+ var _ = function(obj) {
48
+ if (obj instanceof _) return obj;
49
+ if (!(this instanceof _)) return new _(obj);
50
+ this._wrapped = obj;
51
+ };
52
+
53
+ // Export the Underscore object for **Node.js**, with
54
+ // backwards-compatibility for the old `require()` API. If we're in
55
+ // the browser, add `_` as a global object via a string identifier,
56
+ // for Closure Compiler "advanced" mode.
57
+ if (typeof exports !== 'undefined') {
58
+ if (typeof module !== 'undefined' && module.exports) {
59
+ exports = module.exports = _;
60
+ }
61
+ exports._ = _;
62
+ } else {
63
+ root._ = _;
64
+ }
65
+
66
+ // Current version.
67
+ _.VERSION = '1.4.4';
68
+
69
+ // Collection Functions
70
+ // --------------------
71
+
72
+ // The cornerstone, an `each` implementation, aka `forEach`.
73
+ // Handles objects with the built-in `forEach`, arrays, and raw objects.
74
+ // Delegates to **ECMAScript 5**'s native `forEach` if available.
75
+ var each = _.each = _.forEach = function(obj, iterator, context) {
76
+ if (obj == null) return;
77
+ if (nativeForEach && obj.forEach === nativeForEach) {
78
+ obj.forEach(iterator, context);
79
+ } else if (obj.length === +obj.length) {
80
+ for (var i = 0, l = obj.length; i < l; i++) {
81
+ if (iterator.call(context, obj[i], i, obj) === breaker) return;
82
+ }
83
+ } else {
84
+ for (var key in obj) {
85
+ if (_.has(obj, key)) {
86
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
87
+ }
88
+ }
89
+ }
90
+ };
91
+
92
+ // Return the results of applying the iterator to each element.
93
+ // Delegates to **ECMAScript 5**'s native `map` if available.
94
+ _.map = _.collect = function(obj, iterator, context) {
95
+ var results = [];
96
+ if (obj == null) return results;
97
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
98
+ each(obj, function(value, index, list) {
99
+ results[results.length] = iterator.call(context, value, index, list);
100
+ });
101
+ return results;
102
+ };
103
+
104
+ var reduceError = 'Reduce of empty array with no initial value';
105
+
106
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
107
+ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
108
+ _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
109
+ var initial = arguments.length > 2;
110
+ if (obj == null) obj = [];
111
+ if (nativeReduce && obj.reduce === nativeReduce) {
112
+ if (context) iterator = _.bind(iterator, context);
113
+ return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
114
+ }
115
+ each(obj, function(value, index, list) {
116
+ if (!initial) {
117
+ memo = value;
118
+ initial = true;
119
+ } else {
120
+ memo = iterator.call(context, memo, value, index, list);
121
+ }
122
+ });
123
+ if (!initial) throw new TypeError(reduceError);
124
+ return memo;
125
+ };
126
+
127
+ // The right-associative version of reduce, also known as `foldr`.
128
+ // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
129
+ _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
130
+ var initial = arguments.length > 2;
131
+ if (obj == null) obj = [];
132
+ if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
133
+ if (context) iterator = _.bind(iterator, context);
134
+ return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
135
+ }
136
+ var length = obj.length;
137
+ if (length !== +length) {
138
+ var keys = _.keys(obj);
139
+ length = keys.length;
140
+ }
141
+ each(obj, function(value, index, list) {
142
+ index = keys ? keys[--length] : --length;
143
+ if (!initial) {
144
+ memo = obj[index];
145
+ initial = true;
146
+ } else {
147
+ memo = iterator.call(context, memo, obj[index], index, list);
148
+ }
149
+ });
150
+ if (!initial) throw new TypeError(reduceError);
151
+ return memo;
152
+ };
153
+
154
+ // Return the first value which passes a truth test. Aliased as `detect`.
155
+ _.find = _.detect = function(obj, iterator, context) {
156
+ var result;
157
+ any(obj, function(value, index, list) {
158
+ if (iterator.call(context, value, index, list)) {
159
+ result = value;
160
+ return true;
161
+ }
162
+ });
163
+ return result;
164
+ };
165
+
166
+ // Return all the elements that pass a truth test.
167
+ // Delegates to **ECMAScript 5**'s native `filter` if available.
168
+ // Aliased as `select`.
169
+ _.filter = _.select = function(obj, iterator, context) {
170
+ var results = [];
171
+ if (obj == null) return results;
172
+ if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
173
+ each(obj, function(value, index, list) {
174
+ if (iterator.call(context, value, index, list)) results[results.length] = value;
175
+ });
176
+ return results;
177
+ };
178
+
179
+ // Return all the elements for which a truth test fails.
180
+ _.reject = function(obj, iterator, context) {
181
+ return _.filter(obj, function(value, index, list) {
182
+ return !iterator.call(context, value, index, list);
183
+ }, context);
184
+ };
185
+
186
+ // Determine whether all of the elements match a truth test.
187
+ // Delegates to **ECMAScript 5**'s native `every` if available.
188
+ // Aliased as `all`.
189
+ _.every = _.all = function(obj, iterator, context) {
190
+ iterator || (iterator = _.identity);
191
+ var result = true;
192
+ if (obj == null) return result;
193
+ if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
194
+ each(obj, function(value, index, list) {
195
+ if (!(result = result && iterator.call(context, value, index, list))) return breaker;
196
+ });
197
+ return !!result;
198
+ };
199
+
200
+ // Determine if at least one element in the object matches a truth test.
201
+ // Delegates to **ECMAScript 5**'s native `some` if available.
202
+ // Aliased as `any`.
203
+ var any = _.some = _.any = function(obj, iterator, context) {
204
+ iterator || (iterator = _.identity);
205
+ var result = false;
206
+ if (obj == null) return result;
207
+ if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
208
+ each(obj, function(value, index, list) {
209
+ if (result || (result = iterator.call(context, value, index, list))) return breaker;
210
+ });
211
+ return !!result;
212
+ };
213
+
214
+ // Determine if the array or object contains a given value (using `===`).
215
+ // Aliased as `include`.
216
+ _.contains = _.include = function(obj, target) {
217
+ if (obj == null) return false;
218
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
219
+ return any(obj, function(value) {
220
+ return value === target;
221
+ });
222
+ };
223
+
224
+ // Invoke a method (with arguments) on every item in a collection.
225
+ _.invoke = function(obj, method) {
226
+ var args = slice.call(arguments, 2);
227
+ var isFunc = _.isFunction(method);
228
+ return _.map(obj, function(value) {
229
+ return (isFunc ? method : value[method]).apply(value, args);
230
+ });
231
+ };
232
+
233
+ // Convenience version of a common use case of `map`: fetching a property.
234
+ _.pluck = function(obj, key) {
235
+ return _.map(obj, function(value){ return value[key]; });
236
+ };
237
+
238
+ // Convenience version of a common use case of `filter`: selecting only objects
239
+ // containing specific `key:value` pairs.
240
+ _.where = function(obj, attrs, first) {
241
+ if (_.isEmpty(attrs)) return first ? null : [];
242
+ return _[first ? 'find' : 'filter'](obj, function(value) {
243
+ for (var key in attrs) {
244
+ if (attrs[key] !== value[key]) return false;
245
+ }
246
+ return true;
247
+ });
248
+ };
249
+
250
+ // Convenience version of a common use case of `find`: getting the first object
251
+ // containing specific `key:value` pairs.
252
+ _.findWhere = function(obj, attrs) {
253
+ return _.where(obj, attrs, true);
254
+ };
255
+
256
+ // Return the maximum element or (element-based computation).
257
+ // Can't optimize arrays of integers longer than 65,535 elements.
258
+ // See: https://bugs.webkit.org/show_bug.cgi?id=80797
259
+ _.max = function(obj, iterator, context) {
260
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
261
+ return Math.max.apply(Math, obj);
262
+ }
263
+ if (!iterator && _.isEmpty(obj)) return -Infinity;
264
+ var result = {computed : -Infinity, value: -Infinity};
265
+ each(obj, function(value, index, list) {
266
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
267
+ computed >= result.computed && (result = {value : value, computed : computed});
268
+ });
269
+ return result.value;
270
+ };
271
+
272
+ // Return the minimum element (or element-based computation).
273
+ _.min = function(obj, iterator, context) {
274
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
275
+ return Math.min.apply(Math, obj);
276
+ }
277
+ if (!iterator && _.isEmpty(obj)) return Infinity;
278
+ var result = {computed : Infinity, value: Infinity};
279
+ each(obj, function(value, index, list) {
280
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
281
+ computed < result.computed && (result = {value : value, computed : computed});
282
+ });
283
+ return result.value;
284
+ };
285
+
286
+ // Shuffle an array.
287
+ _.shuffle = function(obj) {
288
+ var rand;
289
+ var index = 0;
290
+ var shuffled = [];
291
+ each(obj, function(value) {
292
+ rand = _.random(index++);
293
+ shuffled[index - 1] = shuffled[rand];
294
+ shuffled[rand] = value;
295
+ });
296
+ return shuffled;
297
+ };
298
+
299
+ // An internal function to generate lookup iterators.
300
+ var lookupIterator = function(value) {
301
+ return _.isFunction(value) ? value : function(obj){ return obj[value]; };
302
+ };
303
+
304
+ // Sort the object's values by a criterion produced by an iterator.
305
+ _.sortBy = function(obj, value, context) {
306
+ var iterator = lookupIterator(value);
307
+ return _.pluck(_.map(obj, function(value, index, list) {
308
+ return {
309
+ value : value,
310
+ index : index,
311
+ criteria : iterator.call(context, value, index, list)
312
+ };
313
+ }).sort(function(left, right) {
314
+ var a = left.criteria;
315
+ var b = right.criteria;
316
+ if (a !== b) {
317
+ if (a > b || a === void 0) return 1;
318
+ if (a < b || b === void 0) return -1;
319
+ }
320
+ return left.index < right.index ? -1 : 1;
321
+ }), 'value');
322
+ };
323
+
324
+ // An internal function used for aggregate "group by" operations.
325
+ var group = function(obj, value, context, behavior) {
326
+ var result = {};
327
+ var iterator = lookupIterator(value || _.identity);
328
+ each(obj, function(value, index) {
329
+ var key = iterator.call(context, value, index, obj);
330
+ behavior(result, key, value);
331
+ });
332
+ return result;
333
+ };
334
+
335
+ // Groups the object's values by a criterion. Pass either a string attribute
336
+ // to group by, or a function that returns the criterion.
337
+ _.groupBy = function(obj, value, context) {
338
+ return group(obj, value, context, function(result, key, value) {
339
+ (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
340
+ });
341
+ };
342
+
343
+ // Counts instances of an object that group by a certain criterion. Pass
344
+ // either a string attribute to count by, or a function that returns the
345
+ // criterion.
346
+ _.countBy = function(obj, value, context) {
347
+ return group(obj, value, context, function(result, key) {
348
+ if (!_.has(result, key)) result[key] = 0;
349
+ result[key]++;
350
+ });
351
+ };
352
+
353
+ // Use a comparator function to figure out the smallest index at which
354
+ // an object should be inserted so as to maintain order. Uses binary search.
355
+ _.sortedIndex = function(array, obj, iterator, context) {
356
+ iterator = iterator == null ? _.identity : lookupIterator(iterator);
357
+ var value = iterator.call(context, obj);
358
+ var low = 0, high = array.length;
359
+ while (low < high) {
360
+ var mid = (low + high) >>> 1;
361
+ iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
362
+ }
363
+ return low;
364
+ };
365
+
366
+ // Safely convert anything iterable into a real, live array.
367
+ _.toArray = function(obj) {
368
+ if (!obj) return [];
369
+ if (_.isArray(obj)) return slice.call(obj);
370
+ if (obj.length === +obj.length) return _.map(obj, _.identity);
371
+ return _.values(obj);
372
+ };
373
+
374
+ // Return the number of elements in an object.
375
+ _.size = function(obj) {
376
+ if (obj == null) return 0;
377
+ return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
378
+ };
379
+
380
+ // Array Functions
381
+ // ---------------
382
+
383
+ // Get the first element of an array. Passing **n** will return the first N
384
+ // values in the array. Aliased as `head` and `take`. The **guard** check
385
+ // allows it to work with `_.map`.
386
+ _.first = _.head = _.take = function(array, n, guard) {
387
+ if (array == null) return void 0;
388
+ return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
389
+ };
390
+
391
+ // Returns everything but the last entry of the array. Especially useful on
392
+ // the arguments object. Passing **n** will return all the values in
393
+ // the array, excluding the last N. The **guard** check allows it to work with
394
+ // `_.map`.
395
+ _.initial = function(array, n, guard) {
396
+ return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
397
+ };
398
+
399
+ // Get the last element of an array. Passing **n** will return the last N
400
+ // values in the array. The **guard** check allows it to work with `_.map`.
401
+ _.last = function(array, n, guard) {
402
+ if (array == null) return void 0;
403
+ if ((n != null) && !guard) {
404
+ return slice.call(array, Math.max(array.length - n, 0));
405
+ } else {
406
+ return array[array.length - 1];
407
+ }
408
+ };
409
+
410
+ // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
411
+ // Especially useful on the arguments object. Passing an **n** will return
412
+ // the rest N values in the array. The **guard**
413
+ // check allows it to work with `_.map`.
414
+ _.rest = _.tail = _.drop = function(array, n, guard) {
415
+ return slice.call(array, (n == null) || guard ? 1 : n);
416
+ };
417
+
418
+ // Trim out all falsy values from an array.
419
+ _.compact = function(array) {
420
+ return _.filter(array, _.identity);
421
+ };
422
+
423
+ // Internal implementation of a recursive `flatten` function.
424
+ var flatten = function(input, shallow, output) {
425
+ each(input, function(value) {
426
+ if (_.isArray(value)) {
427
+ shallow ? push.apply(output, value) : flatten(value, shallow, output);
428
+ } else {
429
+ output.push(value);
430
+ }
431
+ });
432
+ return output;
433
+ };
434
+
435
+ // Return a completely flattened version of an array.
436
+ _.flatten = function(array, shallow) {
437
+ return flatten(array, shallow, []);
438
+ };
439
+
440
+ // Return a version of the array that does not contain the specified value(s).
441
+ _.without = function(array) {
442
+ return _.difference(array, slice.call(arguments, 1));
443
+ };
444
+
445
+ // Produce a duplicate-free version of the array. If the array has already
446
+ // been sorted, you have the option of using a faster algorithm.
447
+ // Aliased as `unique`.
448
+ _.uniq = _.unique = function(array, isSorted, iterator, context) {
449
+ if (_.isFunction(isSorted)) {
450
+ context = iterator;
451
+ iterator = isSorted;
452
+ isSorted = false;
453
+ }
454
+ var initial = iterator ? _.map(array, iterator, context) : array;
455
+ var results = [];
456
+ var seen = [];
457
+ each(initial, function(value, index) {
458
+ if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
459
+ seen.push(value);
460
+ results.push(array[index]);
461
+ }
462
+ });
463
+ return results;
464
+ };
465
+
466
+ // Produce an array that contains the union: each distinct element from all of
467
+ // the passed-in arrays.
468
+ _.union = function() {
469
+ return _.uniq(concat.apply(ArrayProto, arguments));
470
+ };
471
+
472
+ // Produce an array that contains every item shared between all the
473
+ // passed-in arrays.
474
+ _.intersection = function(array) {
475
+ var rest = slice.call(arguments, 1);
476
+ return _.filter(_.uniq(array), function(item) {
477
+ return _.every(rest, function(other) {
478
+ return _.indexOf(other, item) >= 0;
479
+ });
480
+ });
481
+ };
482
+
483
+ // Take the difference between one array and a number of other arrays.
484
+ // Only the elements present in just the first array will remain.
485
+ _.difference = function(array) {
486
+ var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
487
+ return _.filter(array, function(value){ return !_.contains(rest, value); });
488
+ };
489
+
490
+ // Zip together multiple lists into a single array -- elements that share
491
+ // an index go together.
492
+ _.zip = function() {
493
+ var args = slice.call(arguments);
494
+ var length = _.max(_.pluck(args, 'length'));
495
+ var results = new Array(length);
496
+ for (var i = 0; i < length; i++) {
497
+ results[i] = _.pluck(args, "" + i);
498
+ }
499
+ return results;
500
+ };
501
+
502
+ // Converts lists into objects. Pass either a single array of `[key, value]`
503
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
504
+ // the corresponding values.
505
+ _.object = function(list, values) {
506
+ if (list == null) return {};
507
+ var result = {};
508
+ for (var i = 0, l = list.length; i < l; i++) {
509
+ if (values) {
510
+ result[list[i]] = values[i];
511
+ } else {
512
+ result[list[i][0]] = list[i][1];
513
+ }
514
+ }
515
+ return result;
516
+ };
517
+
518
+ // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
519
+ // we need this function. Return the position of the first occurrence of an
520
+ // item in an array, or -1 if the item is not included in the array.
521
+ // Delegates to **ECMAScript 5**'s native `indexOf` if available.
522
+ // If the array is large and already in sort order, pass `true`
523
+ // for **isSorted** to use binary search.
524
+ _.indexOf = function(array, item, isSorted) {
525
+ if (array == null) return -1;
526
+ var i = 0, l = array.length;
527
+ if (isSorted) {
528
+ if (typeof isSorted == 'number') {
529
+ i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
530
+ } else {
531
+ i = _.sortedIndex(array, item);
532
+ return array[i] === item ? i : -1;
533
+ }
534
+ }
535
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
536
+ for (; i < l; i++) if (array[i] === item) return i;
537
+ return -1;
538
+ };
539
+
540
+ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
541
+ _.lastIndexOf = function(array, item, from) {
542
+ if (array == null) return -1;
543
+ var hasIndex = from != null;
544
+ if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
545
+ return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
546
+ }
547
+ var i = (hasIndex ? from : array.length);
548
+ while (i--) if (array[i] === item) return i;
549
+ return -1;
550
+ };
551
+
552
+ // Generate an integer Array containing an arithmetic progression. A port of
553
+ // the native Python `range()` function. See
554
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
555
+ _.range = function(start, stop, step) {
556
+ if (arguments.length <= 1) {
557
+ stop = start || 0;
558
+ start = 0;
559
+ }
560
+ step = arguments[2] || 1;
561
+
562
+ var len = Math.max(Math.ceil((stop - start) / step), 0);
563
+ var idx = 0;
564
+ var range = new Array(len);
565
+
566
+ while(idx < len) {
567
+ range[idx++] = start;
568
+ start += step;
569
+ }
570
+
571
+ return range;
572
+ };
573
+
574
+ // Function (ahem) Functions
575
+ // ------------------
576
+
577
+ // Create a function bound to a given object (assigning `this`, and arguments,
578
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
579
+ // available.
580
+ _.bind = function(func, context) {
581
+ if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
582
+ var args = slice.call(arguments, 2);
583
+ return function() {
584
+ return func.apply(context, args.concat(slice.call(arguments)));
585
+ };
586
+ };
587
+
588
+ // Partially apply a function by creating a version that has had some of its
589
+ // arguments pre-filled, without changing its dynamic `this` context.
590
+ _.partial = function(func) {
591
+ var args = slice.call(arguments, 1);
592
+ return function() {
593
+ return func.apply(this, args.concat(slice.call(arguments)));
594
+ };
595
+ };
596
+
597
+ // Bind all of an object's methods to that object. Useful for ensuring that
598
+ // all callbacks defined on an object belong to it.
599
+ _.bindAll = function(obj) {
600
+ var funcs = slice.call(arguments, 1);
601
+ if (funcs.length === 0) funcs = _.functions(obj);
602
+ each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
603
+ return obj;
604
+ };
605
+
606
+ // Memoize an expensive function by storing its results.
607
+ _.memoize = function(func, hasher) {
608
+ var memo = {};
609
+ hasher || (hasher = _.identity);
610
+ return function() {
611
+ var key = hasher.apply(this, arguments);
612
+ return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
613
+ };
614
+ };
615
+
616
+ // Delays a function for the given number of milliseconds, and then calls
617
+ // it with the arguments supplied.
618
+ _.delay = function(func, wait) {
619
+ var args = slice.call(arguments, 2);
620
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
621
+ };
622
+
623
+ // Defers a function, scheduling it to run after the current call stack has
624
+ // cleared.
625
+ _.defer = function(func) {
626
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
627
+ };
628
+
629
+ // Returns a function, that, when invoked, will only be triggered at most once
630
+ // during a given window of time.
631
+ _.throttle = function(func, wait) {
632
+ var context, args, timeout, result;
633
+ var previous = 0;
634
+ var later = function() {
635
+ previous = new Date;
636
+ timeout = null;
637
+ result = func.apply(context, args);
638
+ };
639
+ return function() {
640
+ var now = new Date;
641
+ var remaining = wait - (now - previous);
642
+ context = this;
643
+ args = arguments;
644
+ if (remaining <= 0) {
645
+ clearTimeout(timeout);
646
+ timeout = null;
647
+ previous = now;
648
+ result = func.apply(context, args);
649
+ } else if (!timeout) {
650
+ timeout = setTimeout(later, remaining);
651
+ }
652
+ return result;
653
+ };
654
+ };
655
+
656
+ // Returns a function, that, as long as it continues to be invoked, will not
657
+ // be triggered. The function will be called after it stops being called for
658
+ // N milliseconds. If `immediate` is passed, trigger the function on the
659
+ // leading edge, instead of the trailing.
660
+ _.debounce = function(func, wait, immediate) {
661
+ var timeout, result;
662
+ return function() {
663
+ var context = this, args = arguments;
664
+ var later = function() {
665
+ timeout = null;
666
+ if (!immediate) result = func.apply(context, args);
667
+ };
668
+ var callNow = immediate && !timeout;
669
+ clearTimeout(timeout);
670
+ timeout = setTimeout(later, wait);
671
+ if (callNow) result = func.apply(context, args);
672
+ return result;
673
+ };
674
+ };
675
+
676
+ // Returns a function that will be executed at most one time, no matter how
677
+ // often you call it. Useful for lazy initialization.
678
+ _.once = function(func) {
679
+ var ran = false, memo;
680
+ return function() {
681
+ if (ran) return memo;
682
+ ran = true;
683
+ memo = func.apply(this, arguments);
684
+ func = null;
685
+ return memo;
686
+ };
687
+ };
688
+
689
+ // Returns the first function passed as an argument to the second,
690
+ // allowing you to adjust arguments, run code before and after, and
691
+ // conditionally execute the original function.
692
+ _.wrap = function(func, wrapper) {
693
+ return function() {
694
+ var args = [func];
695
+ push.apply(args, arguments);
696
+ return wrapper.apply(this, args);
697
+ };
698
+ };
699
+
700
+ // Returns a function that is the composition of a list of functions, each
701
+ // consuming the return value of the function that follows.
702
+ _.compose = function() {
703
+ var funcs = arguments;
704
+ return function() {
705
+ var args = arguments;
706
+ for (var i = funcs.length - 1; i >= 0; i--) {
707
+ args = [funcs[i].apply(this, args)];
708
+ }
709
+ return args[0];
710
+ };
711
+ };
712
+
713
+ // Returns a function that will only be executed after being called N times.
714
+ _.after = function(times, func) {
715
+ if (times <= 0) return func();
716
+ return function() {
717
+ if (--times < 1) {
718
+ return func.apply(this, arguments);
719
+ }
720
+ };
721
+ };
722
+
723
+ // Object Functions
724
+ // ----------------
725
+
726
+ // Retrieve the names of an object's properties.
727
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
728
+ _.keys = nativeKeys || function(obj) {
729
+ if (obj !== Object(obj)) throw new TypeError('Invalid object');
730
+ var keys = [];
731
+ for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
732
+ return keys;
733
+ };
734
+
735
+ // Retrieve the values of an object's properties.
736
+ _.values = function(obj) {
737
+ var values = [];
738
+ for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
739
+ return values;
740
+ };
741
+
742
+ // Convert an object into a list of `[key, value]` pairs.
743
+ _.pairs = function(obj) {
744
+ var pairs = [];
745
+ for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
746
+ return pairs;
747
+ };
748
+
749
+ // Invert the keys and values of an object. The values must be serializable.
750
+ _.invert = function(obj) {
751
+ var result = {};
752
+ for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
753
+ return result;
754
+ };
755
+
756
+ // Return a sorted list of the function names available on the object.
757
+ // Aliased as `methods`
758
+ _.functions = _.methods = function(obj) {
759
+ var names = [];
760
+ for (var key in obj) {
761
+ if (_.isFunction(obj[key])) names.push(key);
762
+ }
763
+ return names.sort();
764
+ };
765
+
766
+ // Extend a given object with all the properties in passed-in object(s).
767
+ _.extend = function(obj) {
768
+ each(slice.call(arguments, 1), function(source) {
769
+ if (source) {
770
+ for (var prop in source) {
771
+ obj[prop] = source[prop];
772
+ }
773
+ }
774
+ });
775
+ return obj;
776
+ };
777
+
778
+ // Return a copy of the object only containing the whitelisted properties.
779
+ _.pick = function(obj) {
780
+ var copy = {};
781
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
782
+ each(keys, function(key) {
783
+ if (key in obj) copy[key] = obj[key];
784
+ });
785
+ return copy;
786
+ };
787
+
788
+ // Return a copy of the object without the blacklisted properties.
789
+ _.omit = function(obj) {
790
+ var copy = {};
791
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
792
+ for (var key in obj) {
793
+ if (!_.contains(keys, key)) copy[key] = obj[key];
794
+ }
795
+ return copy;
796
+ };
797
+
798
+ // Fill in a given object with default properties.
799
+ _.defaults = function(obj) {
800
+ each(slice.call(arguments, 1), function(source) {
801
+ if (source) {
802
+ for (var prop in source) {
803
+ if (obj[prop] == null) obj[prop] = source[prop];
804
+ }
805
+ }
806
+ });
807
+ return obj;
808
+ };
809
+
810
+ // Create a (shallow-cloned) duplicate of an object.
811
+ _.clone = function(obj) {
812
+ if (!_.isObject(obj)) return obj;
813
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
814
+ };
815
+
816
+ // Invokes interceptor with the obj, and then returns obj.
817
+ // The primary purpose of this method is to "tap into" a method chain, in
818
+ // order to perform operations on intermediate results within the chain.
819
+ _.tap = function(obj, interceptor) {
820
+ interceptor(obj);
821
+ return obj;
822
+ };
823
+
824
+ // Internal recursive comparison function for `isEqual`.
825
+ var eq = function(a, b, aStack, bStack) {
826
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
827
+ // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
828
+ if (a === b) return a !== 0 || 1 / a == 1 / b;
829
+ // A strict comparison is necessary because `null == undefined`.
830
+ if (a == null || b == null) return a === b;
831
+ // Unwrap any wrapped objects.
832
+ if (a instanceof _) a = a._wrapped;
833
+ if (b instanceof _) b = b._wrapped;
834
+ // Compare `[[Class]]` names.
835
+ var className = toString.call(a);
836
+ if (className != toString.call(b)) return false;
837
+ switch (className) {
838
+ // Strings, numbers, dates, and booleans are compared by value.
839
+ case '[object String]':
840
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
841
+ // equivalent to `new String("5")`.
842
+ return a == String(b);
843
+ case '[object Number]':
844
+ // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
845
+ // other numeric values.
846
+ return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
847
+ case '[object Date]':
848
+ case '[object Boolean]':
849
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
850
+ // millisecond representations. Note that invalid dates with millisecond representations
851
+ // of `NaN` are not equivalent.
852
+ return +a == +b;
853
+ // RegExps are compared by their source patterns and flags.
854
+ case '[object RegExp]':
855
+ return a.source == b.source &&
856
+ a.global == b.global &&
857
+ a.multiline == b.multiline &&
858
+ a.ignoreCase == b.ignoreCase;
859
+ }
860
+ if (typeof a != 'object' || typeof b != 'object') return false;
861
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
862
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
863
+ var length = aStack.length;
864
+ while (length--) {
865
+ // Linear search. Performance is inversely proportional to the number of
866
+ // unique nested structures.
867
+ if (aStack[length] == a) return bStack[length] == b;
868
+ }
869
+ // Add the first object to the stack of traversed objects.
870
+ aStack.push(a);
871
+ bStack.push(b);
872
+ var size = 0, result = true;
873
+ // Recursively compare objects and arrays.
874
+ if (className == '[object Array]') {
875
+ // Compare array lengths to determine if a deep comparison is necessary.
876
+ size = a.length;
877
+ result = size == b.length;
878
+ if (result) {
879
+ // Deep compare the contents, ignoring non-numeric properties.
880
+ while (size--) {
881
+ if (!(result = eq(a[size], b[size], aStack, bStack))) break;
882
+ }
883
+ }
884
+ } else {
885
+ // Objects with different constructors are not equivalent, but `Object`s
886
+ // from different frames are.
887
+ var aCtor = a.constructor, bCtor = b.constructor;
888
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
889
+ _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
890
+ return false;
891
+ }
892
+ // Deep compare objects.
893
+ for (var key in a) {
894
+ if (_.has(a, key)) {
895
+ // Count the expected number of properties.
896
+ size++;
897
+ // Deep compare each member.
898
+ if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
899
+ }
900
+ }
901
+ // Ensure that both objects contain the same number of properties.
902
+ if (result) {
903
+ for (key in b) {
904
+ if (_.has(b, key) && !(size--)) break;
905
+ }
906
+ result = !size;
907
+ }
908
+ }
909
+ // Remove the first object from the stack of traversed objects.
910
+ aStack.pop();
911
+ bStack.pop();
912
+ return result;
913
+ };
914
+
915
+ // Perform a deep comparison to check if two objects are equal.
916
+ _.isEqual = function(a, b) {
917
+ return eq(a, b, [], []);
918
+ };
919
+
920
+ // Is a given array, string, or object empty?
921
+ // An "empty" object has no enumerable own-properties.
922
+ _.isEmpty = function(obj) {
923
+ if (obj == null) return true;
924
+ if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
925
+ for (var key in obj) if (_.has(obj, key)) return false;
926
+ return true;
927
+ };
928
+
929
+ // Is a given value a DOM element?
930
+ _.isElement = function(obj) {
931
+ return !!(obj && obj.nodeType === 1);
932
+ };
933
+
934
+ // Is a given value an array?
935
+ // Delegates to ECMA5's native Array.isArray
936
+ _.isArray = nativeIsArray || function(obj) {
937
+ return toString.call(obj) == '[object Array]';
938
+ };
939
+
940
+ // Is a given variable an object?
941
+ _.isObject = function(obj) {
942
+ return obj === Object(obj);
943
+ };
944
+
945
+ // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
946
+ each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
947
+ _['is' + name] = function(obj) {
948
+ return toString.call(obj) == '[object ' + name + ']';
949
+ };
950
+ });
951
+
952
+ // Define a fallback version of the method in browsers (ahem, IE), where
953
+ // there isn't any inspectable "Arguments" type.
954
+ if (!_.isArguments(arguments)) {
955
+ _.isArguments = function(obj) {
956
+ return !!(obj && _.has(obj, 'callee'));
957
+ };
958
+ }
959
+
960
+ // Optimize `isFunction` if appropriate.
961
+ if (typeof (/./) !== 'function') {
962
+ _.isFunction = function(obj) {
963
+ return typeof obj === 'function';
964
+ };
965
+ }
966
+
967
+ // Is a given object a finite number?
968
+ _.isFinite = function(obj) {
969
+ return isFinite(obj) && !isNaN(parseFloat(obj));
970
+ };
971
+
972
+ // Is the given value `NaN`? (NaN is the only number which does not equal itself).
973
+ _.isNaN = function(obj) {
974
+ return _.isNumber(obj) && obj != +obj;
975
+ };
976
+
977
+ // Is a given value a boolean?
978
+ _.isBoolean = function(obj) {
979
+ return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
980
+ };
981
+
982
+ // Is a given value equal to null?
983
+ _.isNull = function(obj) {
984
+ return obj === null;
985
+ };
986
+
987
+ // Is a given variable undefined?
988
+ _.isUndefined = function(obj) {
989
+ return obj === void 0;
990
+ };
991
+
992
+ // Shortcut function for checking if an object has a given property directly
993
+ // on itself (in other words, not on a prototype).
994
+ _.has = function(obj, key) {
995
+ return hasOwnProperty.call(obj, key);
996
+ };
997
+
998
+ // Utility Functions
999
+ // -----------------
1000
+
1001
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
1002
+ // previous owner. Returns a reference to the Underscore object.
1003
+ _.noConflict = function() {
1004
+ root._ = previousUnderscore;
1005
+ return this;
1006
+ };
1007
+
1008
+ // Keep the identity function around for default iterators.
1009
+ _.identity = function(value) {
1010
+ return value;
1011
+ };
1012
+
1013
+ // Run a function **n** times.
1014
+ _.times = function(n, iterator, context) {
1015
+ var accum = Array(n);
1016
+ for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
1017
+ return accum;
1018
+ };
1019
+
1020
+ // Return a random integer between min and max (inclusive).
1021
+ _.random = function(min, max) {
1022
+ if (max == null) {
1023
+ max = min;
1024
+ min = 0;
1025
+ }
1026
+ return min + Math.floor(Math.random() * (max - min + 1));
1027
+ };
1028
+
1029
+ // List of HTML entities for escaping.
1030
+ var entityMap = {
1031
+ escape: {
1032
+ '&': '&amp;',
1033
+ '<': '&lt;',
1034
+ '>': '&gt;',
1035
+ '"': '&quot;',
1036
+ "'": '&#x27;',
1037
+ '/': '&#x2F;'
1038
+ }
1039
+ };
1040
+ entityMap.unescape = _.invert(entityMap.escape);
1041
+
1042
+ // Regexes containing the keys and values listed immediately above.
1043
+ var entityRegexes = {
1044
+ escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
1045
+ unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
1046
+ };
1047
+
1048
+ // Functions for escaping and unescaping strings to/from HTML interpolation.
1049
+ _.each(['escape', 'unescape'], function(method) {
1050
+ _[method] = function(string) {
1051
+ if (string == null) return '';
1052
+ return ('' + string).replace(entityRegexes[method], function(match) {
1053
+ return entityMap[method][match];
1054
+ });
1055
+ };
1056
+ });
1057
+
1058
+ // If the value of the named property is a function then invoke it;
1059
+ // otherwise, return it.
1060
+ _.result = function(object, property) {
1061
+ if (object == null) return null;
1062
+ var value = object[property];
1063
+ return _.isFunction(value) ? value.call(object) : value;
1064
+ };
1065
+
1066
+ // Add your own custom functions to the Underscore object.
1067
+ _.mixin = function(obj) {
1068
+ each(_.functions(obj), function(name){
1069
+ var func = _[name] = obj[name];
1070
+ _.prototype[name] = function() {
1071
+ var args = [this._wrapped];
1072
+ push.apply(args, arguments);
1073
+ return result.call(this, func.apply(_, args));
1074
+ };
1075
+ });
1076
+ };
1077
+
1078
+ // Generate a unique integer id (unique within the entire client session).
1079
+ // Useful for temporary DOM ids.
1080
+ var idCounter = 0;
1081
+ _.uniqueId = function(prefix) {
1082
+ var id = ++idCounter + '';
1083
+ return prefix ? prefix + id : id;
1084
+ };
1085
+
1086
+ // By default, Underscore uses ERB-style template delimiters, change the
1087
+ // following template settings to use alternative delimiters.
1088
+ _.templateSettings = {
1089
+ evaluate : /<%([\s\S]+?)%>/g,
1090
+ interpolate : /<%=([\s\S]+?)%>/g,
1091
+ escape : /<%-([\s\S]+?)%>/g
1092
+ };
1093
+
1094
+ // When customizing `templateSettings`, if you don't want to define an
1095
+ // interpolation, evaluation or escaping regex, we need one that is
1096
+ // guaranteed not to match.
1097
+ var noMatch = /(.)^/;
1098
+
1099
+ // Certain characters need to be escaped so that they can be put into a
1100
+ // string literal.
1101
+ var escapes = {
1102
+ "'": "'",
1103
+ '\\': '\\',
1104
+ '\r': 'r',
1105
+ '\n': 'n',
1106
+ '\t': 't',
1107
+ '\u2028': 'u2028',
1108
+ '\u2029': 'u2029'
1109
+ };
1110
+
1111
+ var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
1112
+
1113
+ // JavaScript micro-templating, similar to John Resig's implementation.
1114
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
1115
+ // and correctly escapes quotes within interpolated code.
1116
+ _.template = function(text, data, settings) {
1117
+ var render;
1118
+ settings = _.defaults({}, settings, _.templateSettings);
1119
+
1120
+ // Combine delimiters into one regular expression via alternation.
1121
+ var matcher = new RegExp([
1122
+ (settings.escape || noMatch).source,
1123
+ (settings.interpolate || noMatch).source,
1124
+ (settings.evaluate || noMatch).source
1125
+ ].join('|') + '|$', 'g');
1126
+
1127
+ // Compile the template source, escaping string literals appropriately.
1128
+ var index = 0;
1129
+ var source = "__p+='";
1130
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
1131
+ source += text.slice(index, offset)
1132
+ .replace(escaper, function(match) { return '\\' + escapes[match]; });
1133
+
1134
+ if (escape) {
1135
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
1136
+ }
1137
+ if (interpolate) {
1138
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
1139
+ }
1140
+ if (evaluate) {
1141
+ source += "';\n" + evaluate + "\n__p+='";
1142
+ }
1143
+ index = offset + match.length;
1144
+ return match;
1145
+ });
1146
+ source += "';\n";
1147
+
1148
+ // If a variable is not specified, place data values in local scope.
1149
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
1150
+
1151
+ source = "var __t,__p='',__j=Array.prototype.join," +
1152
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
1153
+ source + "return __p;\n";
1154
+
1155
+ try {
1156
+ render = new Function(settings.variable || 'obj', '_', source);
1157
+ } catch (e) {
1158
+ e.source = source;
1159
+ throw e;
1160
+ }
1161
+
1162
+ if (data) return render(data, _);
1163
+ var template = function(data) {
1164
+ return render.call(this, data, _);
1165
+ };
1166
+
1167
+ // Provide the compiled function source as a convenience for precompilation.
1168
+ template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
1169
+
1170
+ return template;
1171
+ };
1172
+
1173
+ // Add a "chain" function, which will delegate to the wrapper.
1174
+ _.chain = function(obj) {
1175
+ return _(obj).chain();
1176
+ };
1177
+
1178
+ // OOP
1179
+ // ---------------
1180
+ // If Underscore is called as a function, it returns a wrapped object that
1181
+ // can be used OO-style. This wrapper holds altered versions of all the
1182
+ // underscore functions. Wrapped objects may be chained.
1183
+
1184
+ // Helper function to continue chaining intermediate results.
1185
+ var result = function(obj) {
1186
+ return this._chain ? _(obj).chain() : obj;
1187
+ };
1188
+
1189
+ // Add all of the Underscore functions to the wrapper object.
1190
+ _.mixin(_);
1191
+
1192
+ // Add all mutator Array functions to the wrapper.
1193
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1194
+ var method = ArrayProto[name];
1195
+ _.prototype[name] = function() {
1196
+ var obj = this._wrapped;
1197
+ method.apply(obj, arguments);
1198
+ if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
1199
+ return result.call(this, obj);
1200
+ };
1201
+ });
1202
+
1203
+ // Add all accessor Array functions to the wrapper.
1204
+ each(['concat', 'join', 'slice'], function(name) {
1205
+ var method = ArrayProto[name];
1206
+ _.prototype[name] = function() {
1207
+ return result.call(this, method.apply(this._wrapped, arguments));
1208
+ };
1209
+ });
1210
+
1211
+ _.extend(_.prototype, {
1212
+
1213
+ // Start chaining a wrapped Underscore object.
1214
+ chain: function() {
1215
+ this._chain = true;
1216
+ return this;
1217
+ },
1218
+
1219
+ // Extracts the result from a wrapped and chained object.
1220
+ value: function() {
1221
+ return this._wrapped;
1222
+ }
1223
+
1224
+ });
1225
+
1226
+ }).call(this);