j1-template 2020.0.22 → 2020.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/_includes/themes/j1/layouts/content_generator_page.html +1 -1
  3. data/_includes/themes/j1/layouts/content_generator_post.html +63 -161
  4. data/_includes/themes/j1/modules/connectors/ad/google-adsense.html +14 -0
  5. data/_includes/themes/j1/modules/connectors/analytic/google-analytics.html +1 -3
  6. data/_includes/themes/j1/modules/connectors/comment/disqus.html +37 -24
  7. data/_includes/themes/j1/modules/navigator/generator.html +8 -3
  8. data/_includes/themes/j1/modules/navigator/procedures/topsearch.proc +36 -26
  9. data/_includes/themes/j1/procedures/layouts/module_writer.proc +1 -1
  10. data/_includes/themes/j1/procedures/posts/create_series_header.proc +9 -5
  11. data/assets/data/banner.html +1 -1
  12. data/assets/data/fam.html +124 -0
  13. data/assets/data/mmenu_sidebar.html +3 -3
  14. data/assets/data/panel.html +9 -9
  15. data/assets/data/quicklinks.html +13 -13
  16. data/assets/error_pages/HTTP204.html +1 -0
  17. data/assets/error_pages/HTTP400.html +3 -2
  18. data/assets/error_pages/HTTP401.html +3 -2
  19. data/assets/error_pages/HTTP403.html +3 -2
  20. data/assets/error_pages/HTTP404.html +3 -2
  21. data/assets/error_pages/HTTP500.html +3 -2
  22. data/assets/error_pages/HTTP501.html +3 -2
  23. data/assets/error_pages/HTTP502.html +3 -2
  24. data/assets/error_pages/HTTP503.html +3 -2
  25. data/assets/error_pages/HTTP520.html +3 -2
  26. data/assets/error_pages/HTTP521.html +3 -2
  27. data/assets/error_pages/HTTP533.html +3 -2
  28. data/assets/themes/j1/adapter/js/{ssm.js → fam.js} +248 -138
  29. data/assets/themes/j1/adapter/js/framer.js +72 -56
  30. data/assets/themes/j1/adapter/js/gallery_customizer.js +2 -1
  31. data/assets/themes/j1/adapter/js/j1.js +8 -2
  32. data/assets/themes/j1/adapter/js/{searcher.js → lunr_search.js} +68 -65
  33. data/assets/themes/j1/adapter/js/toccer.js +62 -30
  34. data/assets/themes/j1/core/css/bootstrap.css +7154 -0
  35. data/assets/themes/j1/core/css/bootstrap.min.css +6 -0
  36. data/assets/themes/j1/core/css/custom.scss +28 -0
  37. data/assets/themes/j1/core/css/globals.css +14523 -0
  38. data/assets/themes/j1/core/css/globals.min.css +1 -0
  39. data/assets/themes/j1/core/css/globals.scss +28 -0
  40. data/assets/themes/j1/core/css/theme_extensions.css +11558 -0
  41. data/assets/themes/j1/core/css/theme_extensions.min.css +1 -0
  42. data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.css +7 -4
  43. data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.min.css +2 -2
  44. data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.css +7 -4
  45. data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.min.css +2 -2
  46. data/assets/themes/j1/core/css/themes/uno-light/bootstrap.css +514 -417
  47. data/assets/themes/j1/core/css/themes/uno-light/bootstrap.min.css +2 -2
  48. data/assets/themes/j1/core/css/uno.css +11823 -0
  49. data/assets/themes/j1/core/css/uno.min.css +1 -0
  50. data/assets/themes/j1/core/css/uno.scss +28 -0
  51. data/assets/themes/j1/core/css/vendor.css +5 -4
  52. data/assets/themes/j1/core/css/vendor.min.css +1 -1
  53. data/assets/themes/j1/core/css/vendor.scss +28 -0
  54. data/assets/themes/j1/core/js/template.js +6 -11
  55. data/assets/themes/j1/core/js/template.js.map +1 -1
  56. data/assets/themes/j1/core/js/template.min.js +1 -1
  57. data/assets/themes/j1/modules/bmd/js/bootstrap-material-design.js +6 -0
  58. data/assets/themes/j1/modules/cash/js/cash.js +1374 -0
  59. data/assets/themes/j1/modules/cash/js/cash.min.js +42 -0
  60. data/assets/themes/j1/modules/fam/css/uno/fam.css +369 -0
  61. data/assets/themes/j1/modules/fam/js/fam.js +477 -0
  62. data/assets/themes/j1/modules/iframeResizer/examples/frame.nested.html +1 -1
  63. data/assets/themes/j1/modules/iframeResizer/js/{iframeResizer.js → resizer.js} +0 -0
  64. data/assets/themes/j1/modules/iframeResizer/js/{iframeResizer.map → resizer.map} +0 -0
  65. data/assets/themes/j1/modules/iframeResizer/js/{iframeResizer.min.js → resizer.min.js} +0 -0
  66. data/assets/themes/j1/modules/jquery/js/require.js +2145 -0
  67. data/assets/themes/j1/modules/jquery/js/require.min.js +5 -0
  68. data/assets/themes/j1/modules/lunrSearch/css/lunr_search.css +32 -0
  69. data/assets/themes/j1/modules/lunrSearch/css/lunr_search.min.css +25 -0
  70. data/assets/themes/j1/modules/lunrSearch/js/dateformat.js +125 -0
  71. data/assets/themes/j1/modules/lunrSearch/js/dateformat.min.js +14 -0
  72. data/assets/themes/j1/modules/lunrSearch/js/lunr.js +3475 -0
  73. data/assets/themes/j1/modules/lunrSearch/js/lunr.min.js +51 -0
  74. data/assets/themes/j1/modules/lunrSearch/js/lunr_search.js +184 -0
  75. data/assets/themes/j1/modules/lunrSearch/js/lunr_search.min.js +17 -0
  76. data/assets/themes/j1/modules/lunrSearch/js/mustache.js +772 -0
  77. data/assets/themes/j1/modules/lunrSearch/js/mustache.min.js +772 -0
  78. data/assets/themes/j1/modules/lunrSearch/js/uri.js +2340 -0
  79. data/assets/themes/j1/modules/lunrSearch/js/uri.min.js +93 -0
  80. data/assets/themes/j1/modules/materialize/js/anime.js +1283 -0
  81. data/assets/themes/j1/modules/materialize/js/anime.min.js +34 -0
  82. data/assets/themes/j1/modules/materialize/js/autocomplete.js +450 -0
  83. data/assets/themes/j1/modules/materialize/js/buttons.js +409 -0
  84. data/assets/themes/j1/modules/materialize/js/cards.js +40 -0
  85. data/assets/themes/j1/modules/materialize/js/carousel.js +717 -0
  86. data/assets/themes/j1/modules/materialize/js/cash-dom.js +1044 -0
  87. data/assets/themes/j1/modules/materialize/js/cash.js +960 -0
  88. data/assets/themes/j1/modules/materialize/js/characterCounter.js +136 -0
  89. data/assets/themes/j1/modules/materialize/js/chips.js +481 -0
  90. data/assets/themes/j1/modules/materialize/js/collapsible.js +275 -0
  91. data/assets/themes/j1/modules/materialize/js/component.js +44 -0
  92. data/assets/themes/j1/modules/materialize/js/datepicker.js +975 -0
  93. data/assets/themes/j1/modules/materialize/js/dropdown.js +617 -0
  94. data/assets/themes/j1/modules/materialize/js/forms.js +275 -0
  95. data/assets/themes/j1/modules/materialize/js/global.js +427 -0
  96. data/assets/themes/j1/modules/materialize/js/materialbox.js +453 -0
  97. data/assets/themes/j1/modules/materialize/js/modal.js +382 -0
  98. data/assets/themes/j1/modules/materialize/js/parallax.js +138 -0
  99. data/assets/themes/j1/modules/materialize/js/pushpin.js +145 -0
  100. data/assets/themes/j1/modules/materialize/js/range.js +263 -0
  101. data/assets/themes/j1/modules/materialize/js/ripple.js +335 -0
  102. data/assets/themes/j1/modules/materialize/js/scrollspy.js +295 -0
  103. data/assets/themes/j1/modules/materialize/js/select.js +432 -0
  104. data/assets/themes/j1/modules/materialize/js/sidenav.js +580 -0
  105. data/assets/themes/j1/modules/materialize/js/slider.js +359 -0
  106. data/assets/themes/j1/modules/materialize/js/tabs.js +402 -0
  107. data/assets/themes/j1/modules/materialize/js/tapTarget.js +314 -0
  108. data/assets/themes/j1/modules/materialize/js/timepicker.js +647 -0
  109. data/assets/themes/j1/modules/materialize/js/toasts.js +310 -0
  110. data/assets/themes/j1/modules/materialize/js/tooltip.js +303 -0
  111. data/assets/themes/j1/modules/materialize/js/waves.js +335 -0
  112. data/assets/themes/j1/modules/materialize/scss/components/_badges.scss +55 -0
  113. data/assets/themes/j1/modules/materialize/scss/components/_buttons.scss +322 -0
  114. data/assets/themes/j1/modules/materialize/scss/components/_cards.scss +195 -0
  115. data/assets/themes/j1/modules/materialize/scss/components/_carousel.scss +90 -0
  116. data/assets/themes/j1/modules/materialize/scss/components/_chips.scss +90 -0
  117. data/assets/themes/j1/modules/materialize/scss/components/_collapsible.scss +91 -0
  118. data/assets/themes/j1/modules/materialize/scss/components/_color-classes.scss +32 -0
  119. data/assets/themes/j1/modules/materialize/scss/components/_color-variables.scss +370 -0
  120. data/assets/themes/j1/modules/materialize/scss/components/_datepicker.scss +191 -0
  121. data/assets/themes/j1/modules/materialize/scss/components/_dropdown.scss +85 -0
  122. data/assets/themes/j1/modules/materialize/scss/components/_global.scss +769 -0
  123. data/assets/themes/j1/modules/materialize/scss/components/_grid.scss +156 -0
  124. data/assets/themes/j1/modules/materialize/scss/components/_icons-material-design.scss +5 -0
  125. data/assets/themes/j1/modules/materialize/scss/components/_materialbox.scss +43 -0
  126. data/assets/themes/j1/modules/materialize/scss/components/_modal.scss +94 -0
  127. data/assets/themes/j1/modules/materialize/scss/components/_navbar.scss +208 -0
  128. data/assets/themes/j1/modules/materialize/scss/components/_normalize.scss +447 -0
  129. data/assets/themes/j1/modules/materialize/scss/components/_preloader.scss +334 -0
  130. data/assets/themes/j1/modules/materialize/scss/components/_pulse.scss +34 -0
  131. data/assets/themes/j1/modules/materialize/scss/components/_sidenav.scss +216 -0
  132. data/assets/themes/j1/modules/materialize/scss/components/_slider.scss +92 -0
  133. data/assets/themes/j1/modules/materialize/scss/components/_table_of_contents.scss +33 -0
  134. data/assets/themes/j1/modules/materialize/scss/components/_tabs.scss +99 -0
  135. data/assets/themes/j1/modules/materialize/scss/components/_tapTarget.scss +103 -0
  136. data/assets/themes/j1/modules/materialize/scss/components/_timepicker.scss +183 -0
  137. data/assets/themes/j1/modules/materialize/scss/components/_toast.scss +58 -0
  138. data/assets/themes/j1/modules/materialize/scss/components/_tooltip.scss +32 -0
  139. data/assets/themes/j1/modules/materialize/scss/components/_transitions.scss +13 -0
  140. data/assets/themes/j1/modules/materialize/scss/components/_typography.scss +60 -0
  141. data/assets/themes/j1/modules/materialize/scss/components/_variables.scss +349 -0
  142. data/assets/themes/j1/modules/materialize/scss/components/_waves.scss +114 -0
  143. data/assets/themes/j1/modules/materialize/scss/components/forms/_checkboxes.scss +200 -0
  144. data/assets/themes/j1/modules/materialize/scss/components/forms/_file-input.scss +44 -0
  145. data/assets/themes/j1/modules/materialize/scss/components/forms/_forms.scss +22 -0
  146. data/assets/themes/j1/modules/materialize/scss/components/forms/_input-fields.scss +354 -0
  147. data/assets/themes/j1/modules/materialize/scss/components/forms/_radio-buttons.scss +115 -0
  148. data/assets/themes/j1/modules/materialize/scss/components/forms/_range.scss +161 -0
  149. data/assets/themes/j1/modules/materialize/scss/components/forms/_select.scss +180 -0
  150. data/assets/themes/j1/modules/materialize/scss/components/forms/_switches.scss +89 -0
  151. data/assets/themes/j1/modules/materialize/scss/materialize.scss +41 -0
  152. data/assets/themes/j1/modules/{bsThemeSwitcher → themeSwitcher}/js/switcher.js +0 -0
  153. data/assets/themes/j1/modules/{bsThemeSwitcher → themeSwitcher}/js/switcher.min.js +0 -0
  154. data/lib/j1/version.rb +1 -1
  155. data/lib/starter_web/Gemfile +12 -16
  156. data/lib/starter_web/_config.yml +95 -21
  157. data/lib/starter_web/_data/blocks/banner.yml +1 -1
  158. data/lib/starter_web/_data/blocks/panel.yml +6 -6
  159. data/lib/starter_web/_data/j1_config.yml +7 -6
  160. data/lib/starter_web/_data/layouts/home.yml +13 -3
  161. data/lib/starter_web/_data/layouts/page.yml +10 -0
  162. data/lib/starter_web/_data/layouts/post.yml +10 -0
  163. data/lib/starter_web/_data/modules/defaults/{ssm.yml → fam.yml} +12 -15
  164. data/lib/starter_web/_data/modules/defaults/lunr_search.yml +171 -0
  165. data/lib/starter_web/_data/modules/defaults/navigator.yml +4 -4
  166. data/lib/starter_web/_data/modules/defaults/toccer.yml +4 -2
  167. data/lib/starter_web/_data/modules/fam.yml +158 -0
  168. data/lib/starter_web/_data/modules/{back2top.yml → lunr_search.yml} +15 -9
  169. data/lib/starter_web/_data/modules/navigator.yml +2 -2
  170. data/lib/starter_web/_data/modules/navigator_menu.yml +57 -6
  171. data/lib/starter_web/_data/modules/toccer.yml +0 -73
  172. data/lib/starter_web/_data/resources.yml +151 -104
  173. data/lib/starter_web/_includes/attributes.asciidoc +2 -2
  174. data/lib/starter_web/_includes/breadcrumbs.html +11 -0
  175. data/lib/starter_web/_plugins/debug.rb +0 -1
  176. data/lib/starter_web/_plugins/filters.rb +0 -1
  177. data/lib/starter_web/_plugins/{lorem-inline.rb → lorem_inline.rb} +1 -2
  178. data/lib/starter_web/_plugins/lunr_index.rb +313 -0
  179. data/lib/starter_web/_plugins/prettify.rb +0 -3
  180. data/lib/starter_web/_plugins/simple_search_filter.rb +0 -1
  181. data/lib/starter_web/_plugins/symlink_watcher.rb +2 -3
  182. data/lib/starter_web/assets/images/modules/attics/banner/lunr-banner-1280x800.jpg +0 -0
  183. data/lib/starter_web/assets/images/pages/winlogbeat/coordinate-map.png +0 -0
  184. data/lib/starter_web/assets/images/pages/winlogbeat/kibana-powershell.jpg +0 -0
  185. data/lib/starter_web/assets/images/pages/winlogbeat/option_ignore_outgoing.png +0 -0
  186. data/lib/starter_web/assets/images/pages/winlogbeat/winlogbeat-dashboard.png +0 -0
  187. data/lib/starter_web/collections/posts/public/featured/_posts/2018-05-01-confusion-about-base-url.adoc +2 -4
  188. data/lib/starter_web/collections/posts/public/featured/_posts/2019-05-01-top-open-source-static-site-generators.adoc +4 -2
  189. data/lib/starter_web/collections/posts/public/featured/_posts/2019-06-01-about-cookies.adoc +3 -2
  190. data/lib/starter_web/collections/posts/public/series/_posts/2018-11-01-docker-using-shared-folders.adoc +5 -4
  191. data/lib/starter_web/collections/posts/public/series/_posts/2020-01-01-post-test-series.adoc +144 -0
  192. data/lib/starter_web/collections/posts/public/series/_posts/2020-01-02-post-test-series.adoc +146 -0
  193. data/lib/starter_web/collections/posts/public/series/_posts/2020-01-03-post-test-series.adoc +146 -0
  194. data/lib/starter_web/collections/posts/public/series/_posts/2020-01-04-post-test-series.adoc +146 -0
  195. data/lib/starter_web/collections/posts/public/test_posts/_posts/2020-09-11-test_post.adoc +2 -4
  196. data/lib/starter_web/collections/posts/public/wikipedia/_posts/2016-11-20-minneapolis.adoc +2 -3
  197. data/lib/starter_web/collections/posts/public/wikipedia/_posts/2016-11-24-narcisse-snake-dens.adoc +2 -7
  198. data/lib/starter_web/collections/posts/public/wikipedia/_posts/2016-11-26-columbia-river.adoc +2 -6
  199. data/lib/starter_web/index.html +16 -10
  200. data/lib/starter_web/package.json +5 -2
  201. data/lib/starter_web/pages/public/about/about_site.adoc +0 -2
  202. data/lib/starter_web/pages/public/about/become_a_patron.adoc +1 -3
  203. data/lib/starter_web/pages/public/blog/navigator/archive.html +8 -1
  204. data/lib/starter_web/pages/public/blog/navigator/archive/categoryview.html +7 -3
  205. data/lib/starter_web/pages/public/blog/navigator/archive/dateview.html +8 -1
  206. data/lib/starter_web/pages/public/blog/navigator/archive/tagview.html +7 -2
  207. data/lib/starter_web/pages/public/blog/navigator/index.html +6 -2
  208. data/lib/starter_web/pages/public/learn/kickstarter/web_in_a_day/100_meet_and_greet_jekyll.adoc +3 -4
  209. data/lib/starter_web/pages/public/learn/kickstarter/web_in_a_day/200_preparations.adoc +3 -4
  210. data/lib/starter_web/pages/public/learn/kickstarter/web_in_a_day/300_first_awesome_web.adoc +3 -4
  211. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.adoc +25 -20
  212. data/lib/starter_web/pages/public/learn/roundtrip/100_present_videos.adoc +14 -12
  213. data/lib/starter_web/pages/public/learn/roundtrip/200_typography.adoc +20 -20
  214. data/lib/starter_web/pages/public/learn/roundtrip/300_icon_fonts.adoc +13 -8
  215. data/lib/starter_web/pages/public/learn/roundtrip/400_asciidoc_extensions.adoc +14 -9
  216. data/lib/starter_web/pages/public/learn/roundtrip/410_bs_modals_extentions.adoc +9 -6
  217. data/lib/starter_web/pages/public/learn/roundtrip/420_responsive_tables_extensions.adoc +62 -8
  218. data/lib/starter_web/pages/public/learn/roundtrip/500_themes.adoc +9 -7
  219. data/lib/starter_web/pages/public/learn/roundtrip/600_lunr.adoc +237 -0
  220. data/lib/starter_web/pages/public/learn/roundtrip/610_fam.adoc +302 -0
  221. data/lib/starter_web/pages/public/learn/where_to_go.adoc +3 -7
  222. data/lib/starter_web/pages/public/legal/de/100_impress.adoc +3 -2
  223. data/lib/starter_web/pages/public/legal/de/200_terms_of_use.adoc +2 -1
  224. data/lib/starter_web/pages/public/legal/de/300_privacy.adoc +2 -1
  225. data/lib/starter_web/pages/public/legal/de/400_license_agreement.adoc +2 -1
  226. data/lib/starter_web/pages/public/legal/de/500_support.adoc +2 -1
  227. data/lib/starter_web/pages/public/legal/en/000_copyright.adoc +30 -27
  228. data/lib/starter_web/pages/public/legal/en/100_impress.adoc +8 -5
  229. data/lib/starter_web/pages/public/legal/en/200_terms_of_use.adoc +12 -8
  230. data/lib/starter_web/pages/public/legal/en/300_privacy.adoc +7 -0
  231. data/lib/starter_web/pages/public/legal/en/400_license_agreement.adoc +8 -1
  232. data/lib/starter_web/pages/public/legal/en/500_support.adoc +8 -1
  233. data/lib/starter_web/pages/public/previewer/bootstrap_theme.adoc +3 -1
  234. data/lib/starter_web/pages/public/previewer/iframer.adoc +36 -28
  235. data/lib/starter_web/pages/public/previewer/justified_gallery.html +2 -1
  236. data/lib/starter_web/pages/public/previewer/mdi_icons_preview.adoc +2 -1
  237. data/lib/starter_web/pages/public/previewer/rouge.adoc +4 -2
  238. data/lib/starter_web/pages/public/previewer/twitter_emoji_preview.adoc +2 -1
  239. data/lib/starter_web/pages/public/test_pages/breadcrumbs_tester.adoc +62 -0
  240. data/lib/starter_web/pages/public/test_pages/deck_of_posts.adoc +3 -0
  241. data/lib/starter_web/pages/public/test_pages/floating_actions_button.adoc +523 -0
  242. data/lib/starter_web/pages/public/test_pages/floating_ad.adoc +1 -0
  243. data/lib/starter_web/pages/public/test_pages/floating_div.adoc +1 -0
  244. data/lib/starter_web/pages/public/test_pages/lunr_tester.adoc +89 -0
  245. data/lib/starter_web/pages/public/test_pages/nav_pagination_tester.adoc +1 -0
  246. data/lib/starter_web/pages/public/test_pages/page_attribute_tester.adoc +1 -0
  247. data/lib/starter_web/pages/public/test_pages/responsive_images.adoc +3 -2
  248. data/lib/starter_web/pages/public/test_pages/responsive_tables.adoc +1 -0
  249. data/lib/starter_web/pages/public/test_pages/toccer_tester.adoc +2245 -0
  250. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  251. data/lib/starter_web/utilsrv/package.json +1 -1
  252. metadata +137 -29
  253. data/assets/data/search.json +0 -165
  254. data/assets/data/ssm.html +0 -242
  255. data/assets/themes/j1/adapter/js/back2top.js +0 -231
  256. data/assets/themes/j1/modules/jekyllSearch/js/simple-jekyll-search.js +0 -468
  257. data/assets/themes/j1/modules/jekyllSearch/js/simple-jekyll-search.min.js +0 -6
  258. data/assets/themes/j1/modules/tocbot/css/theme/uno.css +0 -95
  259. data/assets/themes/j1/modules/tocbot/css/theme/uno.min.css +0 -15
  260. data/assets/themes/j1/modules/tocbot/css/tocbot.css +0 -75
  261. data/assets/themes/j1/modules/tocbot/css/tocbot.min.css +0 -19
  262. data/assets/themes/j1/modules/tocbot/js/tocbot.js +0 -19
  263. data/assets/themes/j1/modules/tocbot/js/tocbot.min.js +0 -19
  264. data/lib/starter_web/_data/modules/defaults/back2top.yml +0 -146
  265. data/lib/starter_web/_data/modules/defaults/stickybits.yml +0 -36
  266. data/lib/starter_web/_data/modules/ssm.yml +0 -142
@@ -0,0 +1,2340 @@
1
+ /*!
2
+ * URI.js - Mutating URLs
3
+ *
4
+ * Version: 1.19.2
5
+ *
6
+ * Author: Rodney Rehm
7
+ * Web: http://medialize.github.io/URI.js/
8
+ *
9
+ * Licensed under
10
+ * MIT License http://www.opensource.org/licenses/mit-license
11
+ *
12
+ */
13
+ (function (root, factory) {
14
+ 'use strict';
15
+ // https://github.com/umdjs/umd/blob/master/returnExports.js
16
+ if (typeof module === 'object' && module.exports) {
17
+ // Node
18
+ module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));
19
+ } else if (typeof define === 'function' && define.amd) {
20
+ // AMD. Register as an anonymous module.
21
+ define(['./punycode', './IPv6', './SecondLevelDomains'], factory);
22
+ } else {
23
+ // Browser globals (root is window)
24
+ root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains, root);
25
+ }
26
+ }(this, function (punycode, IPv6, SLD, root) {
27
+ 'use strict';
28
+ /*global location, escape, unescape */
29
+ // FIXME: v2.0.0 renamce non-camelCase properties to uppercase
30
+ /*jshint camelcase: false */
31
+
32
+ // save current URI variable, if any
33
+ var _URI = root && root.URI;
34
+
35
+ function URI(url, base) {
36
+ var _urlSupplied = arguments.length >= 1;
37
+ var _baseSupplied = arguments.length >= 2;
38
+
39
+ // Allow instantiation without the 'new' keyword
40
+ if (!(this instanceof URI)) {
41
+ if (_urlSupplied) {
42
+ if (_baseSupplied) {
43
+ return new URI(url, base);
44
+ }
45
+
46
+ return new URI(url);
47
+ }
48
+
49
+ return new URI();
50
+ }
51
+
52
+ if (url === undefined) {
53
+ if (_urlSupplied) {
54
+ throw new TypeError('undefined is not a valid argument for URI');
55
+ }
56
+
57
+ if (typeof location !== 'undefined') {
58
+ url = location.href + '';
59
+ } else {
60
+ url = '';
61
+ }
62
+ }
63
+
64
+ if (url === null) {
65
+ if (_urlSupplied) {
66
+ throw new TypeError('null is not a valid argument for URI');
67
+ }
68
+ }
69
+
70
+ this.href(url);
71
+
72
+ // resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
73
+ if (base !== undefined) {
74
+ return this.absoluteTo(base);
75
+ }
76
+
77
+ return this;
78
+ }
79
+
80
+ function isInteger(value) {
81
+ return /^[0-9]+$/.test(value);
82
+ }
83
+
84
+ URI.version = '1.19.2';
85
+
86
+ var p = URI.prototype;
87
+ var hasOwn = Object.prototype.hasOwnProperty;
88
+
89
+ function escapeRegEx(string) {
90
+ // https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963
91
+ return string.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
92
+ }
93
+
94
+ function getType(value) {
95
+ // IE8 doesn't return [Object Undefined] but [Object Object] for undefined value
96
+ if (value === undefined) {
97
+ return 'Undefined';
98
+ }
99
+
100
+ return String(Object.prototype.toString.call(value)).slice(8, -1);
101
+ }
102
+
103
+ function isArray(obj) {
104
+ return getType(obj) === 'Array';
105
+ }
106
+
107
+ function filterArrayValues(data, value) {
108
+ var lookup = {};
109
+ var i, length;
110
+
111
+ if (getType(value) === 'RegExp') {
112
+ lookup = null;
113
+ } else if (isArray(value)) {
114
+ for (i = 0, length = value.length; i < length; i++) {
115
+ lookup[value[i]] = true;
116
+ }
117
+ } else {
118
+ lookup[value] = true;
119
+ }
120
+
121
+ for (i = 0, length = data.length; i < length; i++) {
122
+ /*jshint laxbreak: true */
123
+ var _match = lookup && lookup[data[i]] !== undefined
124
+ || !lookup && value.test(data[i]);
125
+ /*jshint laxbreak: false */
126
+ if (_match) {
127
+ data.splice(i, 1);
128
+ length--;
129
+ i--;
130
+ }
131
+ }
132
+
133
+ return data;
134
+ }
135
+
136
+ function arrayContains(list, value) {
137
+ var i, length;
138
+
139
+ // value may be string, number, array, regexp
140
+ if (isArray(value)) {
141
+ // Note: this can be optimized to O(n) (instead of current O(m * n))
142
+ for (i = 0, length = value.length; i < length; i++) {
143
+ if (!arrayContains(list, value[i])) {
144
+ return false;
145
+ }
146
+ }
147
+
148
+ return true;
149
+ }
150
+
151
+ var _type = getType(value);
152
+ for (i = 0, length = list.length; i < length; i++) {
153
+ if (_type === 'RegExp') {
154
+ if (typeof list[i] === 'string' && list[i].match(value)) {
155
+ return true;
156
+ }
157
+ } else if (list[i] === value) {
158
+ return true;
159
+ }
160
+ }
161
+
162
+ return false;
163
+ }
164
+
165
+ function arraysEqual(one, two) {
166
+ if (!isArray(one) || !isArray(two)) {
167
+ return false;
168
+ }
169
+
170
+ // arrays can't be equal if they have different amount of content
171
+ if (one.length !== two.length) {
172
+ return false;
173
+ }
174
+
175
+ one.sort();
176
+ two.sort();
177
+
178
+ for (var i = 0, l = one.length; i < l; i++) {
179
+ if (one[i] !== two[i]) {
180
+ return false;
181
+ }
182
+ }
183
+
184
+ return true;
185
+ }
186
+
187
+ function trimSlashes(text) {
188
+ var trim_expression = /^\/+|\/+$/g;
189
+ return text.replace(trim_expression, '');
190
+ }
191
+
192
+ URI._parts = function() {
193
+ return {
194
+ protocol: null,
195
+ username: null,
196
+ password: null,
197
+ hostname: null,
198
+ urn: null,
199
+ port: null,
200
+ path: null,
201
+ query: null,
202
+ fragment: null,
203
+ // state
204
+ preventInvalidHostname: URI.preventInvalidHostname,
205
+ duplicateQueryParameters: URI.duplicateQueryParameters,
206
+ escapeQuerySpace: URI.escapeQuerySpace
207
+ };
208
+ };
209
+ // state: throw on invalid hostname
210
+ // see https://github.com/medialize/URI.js/pull/345
211
+ // and https://github.com/medialize/URI.js/issues/354
212
+ URI.preventInvalidHostname = false;
213
+ // state: allow duplicate query parameters (a=1&a=1)
214
+ URI.duplicateQueryParameters = false;
215
+ // state: replaces + with %20 (space in query strings)
216
+ URI.escapeQuerySpace = true;
217
+ // static properties
218
+ URI.protocol_expression = /^[a-z][a-z0-9.+-]*$/i;
219
+ URI.idn_expression = /[^a-z0-9\._-]/i;
220
+ URI.punycode_expression = /(xn--)/i;
221
+ // well, 333.444.555.666 matches, but it sure ain't no IPv4 - do we care?
222
+ URI.ip4_expression = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
223
+ // credits to Rich Brown
224
+ // source: http://forums.intermapper.com/viewtopic.php?p=1096#1096
225
+ // specification: http://www.ietf.org/rfc/rfc4291.txt
226
+ URI.ip6_expression = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
227
+ // expression used is "gruber revised" (@gruber v2) determined to be the
228
+ // best solution in a regex-golf we did a couple of ages ago at
229
+ // * http://mathiasbynens.be/demo/url-regex
230
+ // * http://rodneyrehm.de/t/url-regex.html
231
+ URI.find_uri_expression = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;
232
+ URI.findUri = {
233
+ // valid "scheme://" or "www."
234
+ start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,
235
+ // everything up to the next whitespace
236
+ end: /[\s\r\n]|$/,
237
+ // trim trailing punctuation captured by end RegExp
238
+ trim: /[`!()\[\]{};:'".,<>?«»“”„‘’]+$/,
239
+ // balanced parens inclusion (), [], {}, <>
240
+ parens: /(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g,
241
+ };
242
+ // http://www.iana.org/assignments/uri-schemes.html
243
+ // http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
244
+ URI.defaultPorts = {
245
+ http: '80',
246
+ https: '443',
247
+ ftp: '21',
248
+ gopher: '70',
249
+ ws: '80',
250
+ wss: '443'
251
+ };
252
+ // list of protocols which always require a hostname
253
+ URI.hostProtocols = [
254
+ 'http',
255
+ 'https'
256
+ ];
257
+
258
+ // allowed hostname characters according to RFC 3986
259
+ // ALPHA DIGIT "-" "." "_" "~" "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" %encoded
260
+ // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - _
261
+ URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:_]/;
262
+ // map DOM Elements to their URI attribute
263
+ URI.domAttributes = {
264
+ 'a': 'href',
265
+ 'blockquote': 'cite',
266
+ 'link': 'href',
267
+ 'base': 'href',
268
+ 'script': 'src',
269
+ 'form': 'action',
270
+ 'img': 'src',
271
+ 'area': 'href',
272
+ 'iframe': 'src',
273
+ 'embed': 'src',
274
+ 'source': 'src',
275
+ 'track': 'src',
276
+ 'input': 'src', // but only if type="image"
277
+ 'audio': 'src',
278
+ 'video': 'src'
279
+ };
280
+ URI.getDomAttribute = function(node) {
281
+ if (!node || !node.nodeName) {
282
+ return undefined;
283
+ }
284
+
285
+ var nodeName = node.nodeName.toLowerCase();
286
+ // <input> should only expose src for type="image"
287
+ if (nodeName === 'input' && node.type !== 'image') {
288
+ return undefined;
289
+ }
290
+
291
+ return URI.domAttributes[nodeName];
292
+ };
293
+
294
+ function escapeForDumbFirefox36(value) {
295
+ // https://github.com/medialize/URI.js/issues/91
296
+ return escape(value);
297
+ }
298
+
299
+ // encoding / decoding according to RFC3986
300
+ function strictEncodeURIComponent(string) {
301
+ // see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
302
+ return encodeURIComponent(string)
303
+ .replace(/[!'()*]/g, escapeForDumbFirefox36)
304
+ .replace(/\*/g, '%2A');
305
+ }
306
+ URI.encode = strictEncodeURIComponent;
307
+ URI.decode = decodeURIComponent;
308
+ URI.iso8859 = function() {
309
+ URI.encode = escape;
310
+ URI.decode = unescape;
311
+ };
312
+ URI.unicode = function() {
313
+ URI.encode = strictEncodeURIComponent;
314
+ URI.decode = decodeURIComponent;
315
+ };
316
+ URI.characters = {
317
+ pathname: {
318
+ encode: {
319
+ // RFC3986 2.1: For consistency, URI producers and normalizers should
320
+ // use uppercase hexadecimal digits for all percent-encodings.
321
+ expression: /%(24|26|2B|2C|3B|3D|3A|40)/ig,
322
+ map: {
323
+ // -._~!'()*
324
+ '%24': '$',
325
+ '%26': '&',
326
+ '%2B': '+',
327
+ '%2C': ',',
328
+ '%3B': ';',
329
+ '%3D': '=',
330
+ '%3A': ':',
331
+ '%40': '@'
332
+ }
333
+ },
334
+ decode: {
335
+ expression: /[\/\?#]/g,
336
+ map: {
337
+ '/': '%2F',
338
+ '?': '%3F',
339
+ '#': '%23'
340
+ }
341
+ }
342
+ },
343
+ reserved: {
344
+ encode: {
345
+ // RFC3986 2.1: For consistency, URI producers and normalizers should
346
+ // use uppercase hexadecimal digits for all percent-encodings.
347
+ expression: /%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,
348
+ map: {
349
+ // gen-delims
350
+ '%3A': ':',
351
+ '%2F': '/',
352
+ '%3F': '?',
353
+ '%23': '#',
354
+ '%5B': '[',
355
+ '%5D': ']',
356
+ '%40': '@',
357
+ // sub-delims
358
+ '%21': '!',
359
+ '%24': '$',
360
+ '%26': '&',
361
+ '%27': '\'',
362
+ '%28': '(',
363
+ '%29': ')',
364
+ '%2A': '*',
365
+ '%2B': '+',
366
+ '%2C': ',',
367
+ '%3B': ';',
368
+ '%3D': '='
369
+ }
370
+ }
371
+ },
372
+ urnpath: {
373
+ // The characters under `encode` are the characters called out by RFC 2141 as being acceptable
374
+ // for usage in a URN. RFC2141 also calls out "-", ".", and "_" as acceptable characters, but
375
+ // these aren't encoded by encodeURIComponent, so we don't have to call them out here. Also
376
+ // note that the colon character is not featured in the encoding map; this is because URI.js
377
+ // gives the colons in URNs semantic meaning as the delimiters of path segements, and so it
378
+ // should not appear unencoded in a segment itself.
379
+ // See also the note above about RFC3986 and capitalalized hex digits.
380
+ encode: {
381
+ expression: /%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,
382
+ map: {
383
+ '%21': '!',
384
+ '%24': '$',
385
+ '%27': '\'',
386
+ '%28': '(',
387
+ '%29': ')',
388
+ '%2A': '*',
389
+ '%2B': '+',
390
+ '%2C': ',',
391
+ '%3B': ';',
392
+ '%3D': '=',
393
+ '%40': '@'
394
+ }
395
+ },
396
+ // These characters are the characters called out by RFC2141 as "reserved" characters that
397
+ // should never appear in a URN, plus the colon character (see note above).
398
+ decode: {
399
+ expression: /[\/\?#:]/g,
400
+ map: {
401
+ '/': '%2F',
402
+ '?': '%3F',
403
+ '#': '%23',
404
+ ':': '%3A'
405
+ }
406
+ }
407
+ }
408
+ };
409
+ URI.encodeQuery = function(string, escapeQuerySpace) {
410
+ var escaped = URI.encode(string + '');
411
+ if (escapeQuerySpace === undefined) {
412
+ escapeQuerySpace = URI.escapeQuerySpace;
413
+ }
414
+
415
+ return escapeQuerySpace ? escaped.replace(/%20/g, '+') : escaped;
416
+ };
417
+ URI.decodeQuery = function(string, escapeQuerySpace) {
418
+ string += '';
419
+ if (escapeQuerySpace === undefined) {
420
+ escapeQuerySpace = URI.escapeQuerySpace;
421
+ }
422
+
423
+ try {
424
+ return URI.decode(escapeQuerySpace ? string.replace(/\+/g, '%20') : string);
425
+ } catch(e) {
426
+ // we're not going to mess with weird encodings,
427
+ // give up and return the undecoded original string
428
+ // see https://github.com/medialize/URI.js/issues/87
429
+ // see https://github.com/medialize/URI.js/issues/92
430
+ return string;
431
+ }
432
+ };
433
+ // generate encode/decode path functions
434
+ var _parts = {'encode':'encode', 'decode':'decode'};
435
+ var _part;
436
+ var generateAccessor = function(_group, _part) {
437
+ return function(string) {
438
+ try {
439
+ return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function(c) {
440
+ return URI.characters[_group][_part].map[c];
441
+ });
442
+ } catch (e) {
443
+ // we're not going to mess with weird encodings,
444
+ // give up and return the undecoded original string
445
+ // see https://github.com/medialize/URI.js/issues/87
446
+ // see https://github.com/medialize/URI.js/issues/92
447
+ return string;
448
+ }
449
+ };
450
+ };
451
+
452
+ for (_part in _parts) {
453
+ URI[_part + 'PathSegment'] = generateAccessor('pathname', _parts[_part]);
454
+ URI[_part + 'UrnPathSegment'] = generateAccessor('urnpath', _parts[_part]);
455
+ }
456
+
457
+ var generateSegmentedPathFunction = function(_sep, _codingFuncName, _innerCodingFuncName) {
458
+ return function(string) {
459
+ // Why pass in names of functions, rather than the function objects themselves? The
460
+ // definitions of some functions (but in particular, URI.decode) will occasionally change due
461
+ // to URI.js having ISO8859 and Unicode modes. Passing in the name and getting it will ensure
462
+ // that the functions we use here are "fresh".
463
+ var actualCodingFunc;
464
+ if (!_innerCodingFuncName) {
465
+ actualCodingFunc = URI[_codingFuncName];
466
+ } else {
467
+ actualCodingFunc = function(string) {
468
+ return URI[_codingFuncName](URI[_innerCodingFuncName](string));
469
+ };
470
+ }
471
+
472
+ var segments = (string + '').split(_sep);
473
+
474
+ for (var i = 0, length = segments.length; i < length; i++) {
475
+ segments[i] = actualCodingFunc(segments[i]);
476
+ }
477
+
478
+ return segments.join(_sep);
479
+ };
480
+ };
481
+
482
+ // This takes place outside the above loop because we don't want, e.g., encodeUrnPath functions.
483
+ URI.decodePath = generateSegmentedPathFunction('/', 'decodePathSegment');
484
+ URI.decodeUrnPath = generateSegmentedPathFunction(':', 'decodeUrnPathSegment');
485
+ URI.recodePath = generateSegmentedPathFunction('/', 'encodePathSegment', 'decode');
486
+ URI.recodeUrnPath = generateSegmentedPathFunction(':', 'encodeUrnPathSegment', 'decode');
487
+
488
+ URI.encodeReserved = generateAccessor('reserved', 'encode');
489
+
490
+ URI.parse = function(string, parts) {
491
+ var pos;
492
+ if (!parts) {
493
+ parts = {
494
+ preventInvalidHostname: URI.preventInvalidHostname
495
+ };
496
+ }
497
+ // [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
498
+
499
+ // extract fragment
500
+ pos = string.indexOf('#');
501
+ if (pos > -1) {
502
+ // escaping?
503
+ parts.fragment = string.substring(pos + 1) || null;
504
+ string = string.substring(0, pos);
505
+ }
506
+
507
+ // extract query
508
+ pos = string.indexOf('?');
509
+ if (pos > -1) {
510
+ // escaping?
511
+ parts.query = string.substring(pos + 1) || null;
512
+ string = string.substring(0, pos);
513
+ }
514
+
515
+ // extract protocol
516
+ if (string.substring(0, 2) === '//') {
517
+ // relative-scheme
518
+ parts.protocol = null;
519
+ string = string.substring(2);
520
+ // extract "user:pass@host:port"
521
+ string = URI.parseAuthority(string, parts);
522
+ } else {
523
+ pos = string.indexOf(':');
524
+ if (pos > -1) {
525
+ parts.protocol = string.substring(0, pos) || null;
526
+ if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
527
+ // : may be within the path
528
+ parts.protocol = undefined;
529
+ } else if (string.substring(pos + 1, pos + 3) === '//') {
530
+ string = string.substring(pos + 3);
531
+
532
+ // extract "user:pass@host:port"
533
+ string = URI.parseAuthority(string, parts);
534
+ } else {
535
+ string = string.substring(pos + 1);
536
+ parts.urn = true;
537
+ }
538
+ }
539
+ }
540
+
541
+ // what's left must be the path
542
+ parts.path = string;
543
+
544
+ // and we're done
545
+ return parts;
546
+ };
547
+ URI.parseHost = function(string, parts) {
548
+ if (!string) {
549
+ string = '';
550
+ }
551
+
552
+ // Copy chrome, IE, opera backslash-handling behavior.
553
+ // Back slashes before the query string get converted to forward slashes
554
+ // See: https://github.com/joyent/node/blob/386fd24f49b0e9d1a8a076592a404168faeecc34/lib/url.js#L115-L124
555
+ // See: https://code.google.com/p/chromium/issues/detail?id=25916
556
+ // https://github.com/medialize/URI.js/pull/233
557
+ string = string.replace(/\\/g, '/');
558
+
559
+ // extract host:port
560
+ var pos = string.indexOf('/');
561
+ var bracketPos;
562
+ var t;
563
+
564
+ if (pos === -1) {
565
+ pos = string.length;
566
+ }
567
+
568
+ if (string.charAt(0) === '[') {
569
+ // IPv6 host - http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04#section-6
570
+ // I claim most client software breaks on IPv6 anyways. To simplify things, URI only accepts
571
+ // IPv6+port in the format [2001:db8::1]:80 (for the time being)
572
+ bracketPos = string.indexOf(']');
573
+ parts.hostname = string.substring(1, bracketPos) || null;
574
+ parts.port = string.substring(bracketPos + 2, pos) || null;
575
+ if (parts.port === '/') {
576
+ parts.port = null;
577
+ }
578
+ } else {
579
+ var firstColon = string.indexOf(':');
580
+ var firstSlash = string.indexOf('/');
581
+ var nextColon = string.indexOf(':', firstColon + 1);
582
+ if (nextColon !== -1 && (firstSlash === -1 || nextColon < firstSlash)) {
583
+ // IPv6 host contains multiple colons - but no port
584
+ // this notation is actually not allowed by RFC 3986, but we're a liberal parser
585
+ parts.hostname = string.substring(0, pos) || null;
586
+ parts.port = null;
587
+ } else {
588
+ t = string.substring(0, pos).split(':');
589
+ parts.hostname = t[0] || null;
590
+ parts.port = t[1] || null;
591
+ }
592
+ }
593
+
594
+ if (parts.hostname && string.substring(pos).charAt(0) !== '/') {
595
+ pos++;
596
+ string = '/' + string;
597
+ }
598
+
599
+ if (parts.preventInvalidHostname) {
600
+ URI.ensureValidHostname(parts.hostname, parts.protocol);
601
+ }
602
+
603
+ if (parts.port) {
604
+ URI.ensureValidPort(parts.port);
605
+ }
606
+
607
+ return string.substring(pos) || '/';
608
+ };
609
+ URI.parseAuthority = function(string, parts) {
610
+ string = URI.parseUserinfo(string, parts);
611
+ return URI.parseHost(string, parts);
612
+ };
613
+ URI.parseUserinfo = function(string, parts) {
614
+ // extract username:password
615
+ var firstSlash = string.indexOf('/');
616
+ var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1);
617
+ var t;
618
+
619
+ // authority@ must come before /path
620
+ if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) {
621
+ t = string.substring(0, pos).split(':');
622
+ parts.username = t[0] ? URI.decode(t[0]) : null;
623
+ t.shift();
624
+ parts.password = t[0] ? URI.decode(t.join(':')) : null;
625
+ string = string.substring(pos + 1);
626
+ } else {
627
+ parts.username = null;
628
+ parts.password = null;
629
+ }
630
+
631
+ return string;
632
+ };
633
+ URI.parseQuery = function(string, escapeQuerySpace) {
634
+ if (!string) {
635
+ return {};
636
+ }
637
+
638
+ // throw out the funky business - "?"[name"="value"&"]+
639
+ string = string.replace(/&+/g, '&').replace(/^\?*&*|&+$/g, '');
640
+
641
+ if (!string) {
642
+ return {};
643
+ }
644
+
645
+ var items = {};
646
+ var splits = string.split('&');
647
+ var length = splits.length;
648
+ var v, name, value;
649
+
650
+ for (var i = 0; i < length; i++) {
651
+ v = splits[i].split('=');
652
+ name = URI.decodeQuery(v.shift(), escapeQuerySpace);
653
+ // no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
654
+ value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;
655
+
656
+ if (hasOwn.call(items, name)) {
657
+ if (typeof items[name] === 'string' || items[name] === null) {
658
+ items[name] = [items[name]];
659
+ }
660
+
661
+ items[name].push(value);
662
+ } else {
663
+ items[name] = value;
664
+ }
665
+ }
666
+
667
+ return items;
668
+ };
669
+
670
+ URI.build = function(parts) {
671
+ var t = '';
672
+ var requireAbsolutePath = false
673
+
674
+ if (parts.protocol) {
675
+ t += parts.protocol + ':';
676
+ }
677
+
678
+ if (!parts.urn && (t || parts.hostname)) {
679
+ t += '//';
680
+ requireAbsolutePath = true
681
+ }
682
+
683
+ t += (URI.buildAuthority(parts) || '');
684
+
685
+ if (typeof parts.path === 'string') {
686
+ if (parts.path.charAt(0) !== '/' && requireAbsolutePath) {
687
+ t += '/';
688
+ }
689
+
690
+ t += parts.path;
691
+ }
692
+
693
+ if (typeof parts.query === 'string' && parts.query) {
694
+ t += '?' + parts.query;
695
+ }
696
+
697
+ if (typeof parts.fragment === 'string' && parts.fragment) {
698
+ t += '#' + parts.fragment;
699
+ }
700
+ return t;
701
+ };
702
+ URI.buildHost = function(parts) {
703
+ var t = '';
704
+
705
+ if (!parts.hostname) {
706
+ return '';
707
+ } else if (URI.ip6_expression.test(parts.hostname)) {
708
+ t += '[' + parts.hostname + ']';
709
+ } else {
710
+ t += parts.hostname;
711
+ }
712
+
713
+ if (parts.port) {
714
+ t += ':' + parts.port;
715
+ }
716
+
717
+ return t;
718
+ };
719
+ URI.buildAuthority = function(parts) {
720
+ return URI.buildUserinfo(parts) + URI.buildHost(parts);
721
+ };
722
+ URI.buildUserinfo = function(parts) {
723
+ var t = '';
724
+
725
+ if (parts.username) {
726
+ t += URI.encode(parts.username);
727
+ }
728
+
729
+ if (parts.password) {
730
+ t += ':' + URI.encode(parts.password);
731
+ }
732
+
733
+ if (t) {
734
+ t += '@';
735
+ }
736
+
737
+ return t;
738
+ };
739
+ URI.buildQuery = function(data, duplicateQueryParameters, escapeQuerySpace) {
740
+ // according to http://tools.ietf.org/html/rfc3986 or http://labs.apache.org/webarch/uri/rfc/rfc3986.html
741
+ // being »-._~!$&'()*+,;=:@/?« %HEX and alnum are allowed
742
+ // the RFC explicitly states ?/foo being a valid use case, no mention of parameter syntax!
743
+ // URI.js treats the query string as being application/x-www-form-urlencoded
744
+ // see http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type
745
+
746
+ var t = '';
747
+ var unique, key, i, length;
748
+ for (key in data) {
749
+ if (hasOwn.call(data, key)) {
750
+ if (isArray(data[key])) {
751
+ unique = {};
752
+ for (i = 0, length = data[key].length; i < length; i++) {
753
+ if (data[key][i] !== undefined && unique[data[key][i] + ''] === undefined) {
754
+ t += '&' + URI.buildQueryParameter(key, data[key][i], escapeQuerySpace);
755
+ if (duplicateQueryParameters !== true) {
756
+ unique[data[key][i] + ''] = true;
757
+ }
758
+ }
759
+ }
760
+ } else if (data[key] !== undefined) {
761
+ t += '&' + URI.buildQueryParameter(key, data[key], escapeQuerySpace);
762
+ }
763
+ }
764
+ }
765
+
766
+ return t.substring(1);
767
+ };
768
+ URI.buildQueryParameter = function(name, value, escapeQuerySpace) {
769
+ // http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type -- application/x-www-form-urlencoded
770
+ // don't append "=" for null values, according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#url-parameter-serialization
771
+ return URI.encodeQuery(name, escapeQuerySpace) + (value !== null ? '=' + URI.encodeQuery(value, escapeQuerySpace) : '');
772
+ };
773
+
774
+ URI.addQuery = function(data, name, value) {
775
+ if (typeof name === 'object') {
776
+ for (var key in name) {
777
+ if (hasOwn.call(name, key)) {
778
+ URI.addQuery(data, key, name[key]);
779
+ }
780
+ }
781
+ } else if (typeof name === 'string') {
782
+ if (data[name] === undefined) {
783
+ data[name] = value;
784
+ return;
785
+ } else if (typeof data[name] === 'string') {
786
+ data[name] = [data[name]];
787
+ }
788
+
789
+ if (!isArray(value)) {
790
+ value = [value];
791
+ }
792
+
793
+ data[name] = (data[name] || []).concat(value);
794
+ } else {
795
+ throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
796
+ }
797
+ };
798
+
799
+ URI.setQuery = function(data, name, value) {
800
+ if (typeof name === 'object') {
801
+ for (var key in name) {
802
+ if (hasOwn.call(name, key)) {
803
+ URI.setQuery(data, key, name[key]);
804
+ }
805
+ }
806
+ } else if (typeof name === 'string') {
807
+ data[name] = value === undefined ? null : value;
808
+ } else {
809
+ throw new TypeError('URI.setQuery() accepts an object, string as the name parameter');
810
+ }
811
+ };
812
+
813
+ URI.removeQuery = function(data, name, value) {
814
+ var i, length, key;
815
+
816
+ if (isArray(name)) {
817
+ for (i = 0, length = name.length; i < length; i++) {
818
+ data[name[i]] = undefined;
819
+ }
820
+ } else if (getType(name) === 'RegExp') {
821
+ for (key in data) {
822
+ if (name.test(key)) {
823
+ data[key] = undefined;
824
+ }
825
+ }
826
+ } else if (typeof name === 'object') {
827
+ for (key in name) {
828
+ if (hasOwn.call(name, key)) {
829
+ URI.removeQuery(data, key, name[key]);
830
+ }
831
+ }
832
+ } else if (typeof name === 'string') {
833
+ if (value !== undefined) {
834
+ if (getType(value) === 'RegExp') {
835
+ if (!isArray(data[name]) && value.test(data[name])) {
836
+ data[name] = undefined;
837
+ } else {
838
+ data[name] = filterArrayValues(data[name], value);
839
+ }
840
+ } else if (data[name] === String(value) && (!isArray(value) || value.length === 1)) {
841
+ data[name] = undefined;
842
+ } else if (isArray(data[name])) {
843
+ data[name] = filterArrayValues(data[name], value);
844
+ }
845
+ } else {
846
+ data[name] = undefined;
847
+ }
848
+ } else {
849
+ throw new TypeError('URI.removeQuery() accepts an object, string, RegExp as the first parameter');
850
+ }
851
+ };
852
+ URI.hasQuery = function(data, name, value, withinArray) {
853
+ switch (getType(name)) {
854
+ case 'String':
855
+ // Nothing to do here
856
+ break;
857
+
858
+ case 'RegExp':
859
+ for (var key in data) {
860
+ if (hasOwn.call(data, key)) {
861
+ if (name.test(key) && (value === undefined || URI.hasQuery(data, key, value))) {
862
+ return true;
863
+ }
864
+ }
865
+ }
866
+
867
+ return false;
868
+
869
+ case 'Object':
870
+ for (var _key in name) {
871
+ if (hasOwn.call(name, _key)) {
872
+ if (!URI.hasQuery(data, _key, name[_key])) {
873
+ return false;
874
+ }
875
+ }
876
+ }
877
+
878
+ return true;
879
+
880
+ default:
881
+ throw new TypeError('URI.hasQuery() accepts a string, regular expression or object as the name parameter');
882
+ }
883
+
884
+ switch (getType(value)) {
885
+ case 'Undefined':
886
+ // true if exists (but may be empty)
887
+ return name in data; // data[name] !== undefined;
888
+
889
+ case 'Boolean':
890
+ // true if exists and non-empty
891
+ var _booly = Boolean(isArray(data[name]) ? data[name].length : data[name]);
892
+ return value === _booly;
893
+
894
+ case 'Function':
895
+ // allow complex comparison
896
+ return !!value(data[name], name, data);
897
+
898
+ case 'Array':
899
+ if (!isArray(data[name])) {
900
+ return false;
901
+ }
902
+
903
+ var op = withinArray ? arrayContains : arraysEqual;
904
+ return op(data[name], value);
905
+
906
+ case 'RegExp':
907
+ if (!isArray(data[name])) {
908
+ return Boolean(data[name] && data[name].match(value));
909
+ }
910
+
911
+ if (!withinArray) {
912
+ return false;
913
+ }
914
+
915
+ return arrayContains(data[name], value);
916
+
917
+ case 'Number':
918
+ value = String(value);
919
+ /* falls through */
920
+ case 'String':
921
+ if (!isArray(data[name])) {
922
+ return data[name] === value;
923
+ }
924
+
925
+ if (!withinArray) {
926
+ return false;
927
+ }
928
+
929
+ return arrayContains(data[name], value);
930
+
931
+ default:
932
+ throw new TypeError('URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter');
933
+ }
934
+ };
935
+
936
+
937
+ URI.joinPaths = function() {
938
+ var input = [];
939
+ var segments = [];
940
+ var nonEmptySegments = 0;
941
+
942
+ for (var i = 0; i < arguments.length; i++) {
943
+ var url = new URI(arguments[i]);
944
+ input.push(url);
945
+ var _segments = url.segment();
946
+ for (var s = 0; s < _segments.length; s++) {
947
+ if (typeof _segments[s] === 'string') {
948
+ segments.push(_segments[s]);
949
+ }
950
+
951
+ if (_segments[s]) {
952
+ nonEmptySegments++;
953
+ }
954
+ }
955
+ }
956
+
957
+ if (!segments.length || !nonEmptySegments) {
958
+ return new URI('');
959
+ }
960
+
961
+ var uri = new URI('').segment(segments);
962
+
963
+ if (input[0].path() === '' || input[0].path().slice(0, 1) === '/') {
964
+ uri.path('/' + uri.path());
965
+ }
966
+
967
+ return uri.normalize();
968
+ };
969
+
970
+ URI.commonPath = function(one, two) {
971
+ var length = Math.min(one.length, two.length);
972
+ var pos;
973
+
974
+ // find first non-matching character
975
+ for (pos = 0; pos < length; pos++) {
976
+ if (one.charAt(pos) !== two.charAt(pos)) {
977
+ pos--;
978
+ break;
979
+ }
980
+ }
981
+
982
+ if (pos < 1) {
983
+ return one.charAt(0) === two.charAt(0) && one.charAt(0) === '/' ? '/' : '';
984
+ }
985
+
986
+ // revert to last /
987
+ if (one.charAt(pos) !== '/' || two.charAt(pos) !== '/') {
988
+ pos = one.substring(0, pos).lastIndexOf('/');
989
+ }
990
+
991
+ return one.substring(0, pos + 1);
992
+ };
993
+
994
+ URI.withinString = function(string, callback, options) {
995
+ options || (options = {});
996
+ var _start = options.start || URI.findUri.start;
997
+ var _end = options.end || URI.findUri.end;
998
+ var _trim = options.trim || URI.findUri.trim;
999
+ var _parens = options.parens || URI.findUri.parens;
1000
+ var _attributeOpen = /[a-z0-9-]=["']?$/i;
1001
+
1002
+ _start.lastIndex = 0;
1003
+ while (true) {
1004
+ var match = _start.exec(string);
1005
+ if (!match) {
1006
+ break;
1007
+ }
1008
+
1009
+ var start = match.index;
1010
+ if (options.ignoreHtml) {
1011
+ // attribut(e=["']?$)
1012
+ var attributeOpen = string.slice(Math.max(start - 3, 0), start);
1013
+ if (attributeOpen && _attributeOpen.test(attributeOpen)) {
1014
+ continue;
1015
+ }
1016
+ }
1017
+
1018
+ var end = start + string.slice(start).search(_end);
1019
+ var slice = string.slice(start, end);
1020
+ // make sure we include well balanced parens
1021
+ var parensEnd = -1;
1022
+ while (true) {
1023
+ var parensMatch = _parens.exec(slice);
1024
+ if (!parensMatch) {
1025
+ break;
1026
+ }
1027
+
1028
+ var parensMatchEnd = parensMatch.index + parensMatch[0].length;
1029
+ parensEnd = Math.max(parensEnd, parensMatchEnd);
1030
+ }
1031
+
1032
+ if (parensEnd > -1) {
1033
+ slice = slice.slice(0, parensEnd) + slice.slice(parensEnd).replace(_trim, '');
1034
+ } else {
1035
+ slice = slice.replace(_trim, '');
1036
+ }
1037
+
1038
+ if (slice.length <= match[0].length) {
1039
+ // the extract only contains the starting marker of a URI,
1040
+ // e.g. "www" or "http://"
1041
+ continue;
1042
+ }
1043
+
1044
+ if (options.ignore && options.ignore.test(slice)) {
1045
+ continue;
1046
+ }
1047
+
1048
+ end = start + slice.length;
1049
+ var result = callback(slice, start, end, string);
1050
+ if (result === undefined) {
1051
+ _start.lastIndex = end;
1052
+ continue;
1053
+ }
1054
+
1055
+ result = String(result);
1056
+ string = string.slice(0, start) + result + string.slice(end);
1057
+ _start.lastIndex = start + result.length;
1058
+ }
1059
+
1060
+ _start.lastIndex = 0;
1061
+ return string;
1062
+ };
1063
+
1064
+ URI.ensureValidHostname = function(v, protocol) {
1065
+ // Theoretically URIs allow percent-encoding in Hostnames (according to RFC 3986)
1066
+ // they are not part of DNS and therefore ignored by URI.js
1067
+
1068
+ var hasHostname = !!v; // not null and not an empty string
1069
+ var hasProtocol = !!protocol;
1070
+ var rejectEmptyHostname = false;
1071
+
1072
+ if (hasProtocol) {
1073
+ rejectEmptyHostname = arrayContains(URI.hostProtocols, protocol);
1074
+ }
1075
+
1076
+ if (rejectEmptyHostname && !hasHostname) {
1077
+ throw new TypeError('Hostname cannot be empty, if protocol is ' + protocol);
1078
+ } else if (v && v.match(URI.invalid_hostname_characters)) {
1079
+ // test punycode
1080
+ if (!punycode) {
1081
+ throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available');
1082
+ }
1083
+ if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) {
1084
+ throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-:_]');
1085
+ }
1086
+ }
1087
+ };
1088
+
1089
+ URI.ensureValidPort = function (v) {
1090
+ if (!v) {
1091
+ return;
1092
+ }
1093
+
1094
+ var port = Number(v);
1095
+ if (isInteger(port) && (port > 0) && (port < 65536)) {
1096
+ return;
1097
+ }
1098
+
1099
+ throw new TypeError('Port "' + v + '" is not a valid port');
1100
+ };
1101
+
1102
+ // noConflict
1103
+ URI.noConflict = function(removeAll) {
1104
+ if (removeAll) {
1105
+ var unconflicted = {
1106
+ URI: this.noConflict()
1107
+ };
1108
+
1109
+ if (root.URITemplate && typeof root.URITemplate.noConflict === 'function') {
1110
+ unconflicted.URITemplate = root.URITemplate.noConflict();
1111
+ }
1112
+
1113
+ if (root.IPv6 && typeof root.IPv6.noConflict === 'function') {
1114
+ unconflicted.IPv6 = root.IPv6.noConflict();
1115
+ }
1116
+
1117
+ if (root.SecondLevelDomains && typeof root.SecondLevelDomains.noConflict === 'function') {
1118
+ unconflicted.SecondLevelDomains = root.SecondLevelDomains.noConflict();
1119
+ }
1120
+
1121
+ return unconflicted;
1122
+ } else if (root.URI === this) {
1123
+ root.URI = _URI;
1124
+ }
1125
+
1126
+ return this;
1127
+ };
1128
+
1129
+ p.build = function(deferBuild) {
1130
+ if (deferBuild === true) {
1131
+ this._deferred_build = true;
1132
+ } else if (deferBuild === undefined || this._deferred_build) {
1133
+ this._string = URI.build(this._parts);
1134
+ this._deferred_build = false;
1135
+ }
1136
+
1137
+ return this;
1138
+ };
1139
+
1140
+ p.clone = function() {
1141
+ return new URI(this);
1142
+ };
1143
+
1144
+ p.valueOf = p.toString = function() {
1145
+ return this.build(false)._string;
1146
+ };
1147
+
1148
+
1149
+ function generateSimpleAccessor(_part){
1150
+ return function(v, build) {
1151
+ if (v === undefined) {
1152
+ return this._parts[_part] || '';
1153
+ } else {
1154
+ this._parts[_part] = v || null;
1155
+ this.build(!build);
1156
+ return this;
1157
+ }
1158
+ };
1159
+ }
1160
+
1161
+ function generatePrefixAccessor(_part, _key){
1162
+ return function(v, build) {
1163
+ if (v === undefined) {
1164
+ return this._parts[_part] || '';
1165
+ } else {
1166
+ if (v !== null) {
1167
+ v = v + '';
1168
+ if (v.charAt(0) === _key) {
1169
+ v = v.substring(1);
1170
+ }
1171
+ }
1172
+
1173
+ this._parts[_part] = v;
1174
+ this.build(!build);
1175
+ return this;
1176
+ }
1177
+ };
1178
+ }
1179
+
1180
+ p.protocol = generateSimpleAccessor('protocol');
1181
+ p.username = generateSimpleAccessor('username');
1182
+ p.password = generateSimpleAccessor('password');
1183
+ p.hostname = generateSimpleAccessor('hostname');
1184
+ p.port = generateSimpleAccessor('port');
1185
+ p.query = generatePrefixAccessor('query', '?');
1186
+ p.fragment = generatePrefixAccessor('fragment', '#');
1187
+
1188
+ p.search = function(v, build) {
1189
+ var t = this.query(v, build);
1190
+ return typeof t === 'string' && t.length ? ('?' + t) : t;
1191
+ };
1192
+ p.hash = function(v, build) {
1193
+ var t = this.fragment(v, build);
1194
+ return typeof t === 'string' && t.length ? ('#' + t) : t;
1195
+ };
1196
+
1197
+ p.pathname = function(v, build) {
1198
+ if (v === undefined || v === true) {
1199
+ var res = this._parts.path || (this._parts.hostname ? '/' : '');
1200
+ return v ? (this._parts.urn ? URI.decodeUrnPath : URI.decodePath)(res) : res;
1201
+ } else {
1202
+ if (this._parts.urn) {
1203
+ this._parts.path = v ? URI.recodeUrnPath(v) : '';
1204
+ } else {
1205
+ this._parts.path = v ? URI.recodePath(v) : '/';
1206
+ }
1207
+ this.build(!build);
1208
+ return this;
1209
+ }
1210
+ };
1211
+ p.path = p.pathname;
1212
+ p.href = function(href, build) {
1213
+ var key;
1214
+
1215
+ if (href === undefined) {
1216
+ return this.toString();
1217
+ }
1218
+
1219
+ this._string = '';
1220
+ this._parts = URI._parts();
1221
+
1222
+ var _URI = href instanceof URI;
1223
+ var _object = typeof href === 'object' && (href.hostname || href.path || href.pathname);
1224
+ if (href.nodeName) {
1225
+ var attribute = URI.getDomAttribute(href);
1226
+ href = href[attribute] || '';
1227
+ _object = false;
1228
+ }
1229
+
1230
+ // window.location is reported to be an object, but it's not the sort
1231
+ // of object we're looking for:
1232
+ // * location.protocol ends with a colon
1233
+ // * location.query != object.search
1234
+ // * location.hash != object.fragment
1235
+ // simply serializing the unknown object should do the trick
1236
+ // (for location, not for everything...)
1237
+ if (!_URI && _object && href.pathname !== undefined) {
1238
+ href = href.toString();
1239
+ }
1240
+
1241
+ if (typeof href === 'string' || href instanceof String) {
1242
+ this._parts = URI.parse(String(href), this._parts);
1243
+ } else if (_URI || _object) {
1244
+ var src = _URI ? href._parts : href;
1245
+ for (key in src) {
1246
+ if (key === 'query') { continue; }
1247
+ if (hasOwn.call(this._parts, key)) {
1248
+ this._parts[key] = src[key];
1249
+ }
1250
+ }
1251
+ if (src.query) {
1252
+ this.query(src.query, false);
1253
+ }
1254
+ } else {
1255
+ throw new TypeError('invalid input');
1256
+ }
1257
+
1258
+ this.build(!build);
1259
+ return this;
1260
+ };
1261
+
1262
+ // identification accessors
1263
+ p.is = function(what) {
1264
+ var ip = false;
1265
+ var ip4 = false;
1266
+ var ip6 = false;
1267
+ var name = false;
1268
+ var sld = false;
1269
+ var idn = false;
1270
+ var punycode = false;
1271
+ var relative = !this._parts.urn;
1272
+
1273
+ if (this._parts.hostname) {
1274
+ relative = false;
1275
+ ip4 = URI.ip4_expression.test(this._parts.hostname);
1276
+ ip6 = URI.ip6_expression.test(this._parts.hostname);
1277
+ ip = ip4 || ip6;
1278
+ name = !ip;
1279
+ sld = name && SLD && SLD.has(this._parts.hostname);
1280
+ idn = name && URI.idn_expression.test(this._parts.hostname);
1281
+ punycode = name && URI.punycode_expression.test(this._parts.hostname);
1282
+ }
1283
+
1284
+ switch (what.toLowerCase()) {
1285
+ case 'relative':
1286
+ return relative;
1287
+
1288
+ case 'absolute':
1289
+ return !relative;
1290
+
1291
+ // hostname identification
1292
+ case 'domain':
1293
+ case 'name':
1294
+ return name;
1295
+
1296
+ case 'sld':
1297
+ return sld;
1298
+
1299
+ case 'ip':
1300
+ return ip;
1301
+
1302
+ case 'ip4':
1303
+ case 'ipv4':
1304
+ case 'inet4':
1305
+ return ip4;
1306
+
1307
+ case 'ip6':
1308
+ case 'ipv6':
1309
+ case 'inet6':
1310
+ return ip6;
1311
+
1312
+ case 'idn':
1313
+ return idn;
1314
+
1315
+ case 'url':
1316
+ return !this._parts.urn;
1317
+
1318
+ case 'urn':
1319
+ return !!this._parts.urn;
1320
+
1321
+ case 'punycode':
1322
+ return punycode;
1323
+ }
1324
+
1325
+ return null;
1326
+ };
1327
+
1328
+ // component specific input validation
1329
+ var _protocol = p.protocol;
1330
+ var _port = p.port;
1331
+ var _hostname = p.hostname;
1332
+
1333
+ p.protocol = function(v, build) {
1334
+ if (v) {
1335
+ // accept trailing ://
1336
+ v = v.replace(/:(\/\/)?$/, '');
1337
+
1338
+ if (!v.match(URI.protocol_expression)) {
1339
+ throw new TypeError('Protocol "' + v + '" contains characters other than [A-Z0-9.+-] or doesn\'t start with [A-Z]');
1340
+ }
1341
+ }
1342
+
1343
+ return _protocol.call(this, v, build);
1344
+ };
1345
+ p.scheme = p.protocol;
1346
+ p.port = function(v, build) {
1347
+ if (this._parts.urn) {
1348
+ return v === undefined ? '' : this;
1349
+ }
1350
+
1351
+ if (v !== undefined) {
1352
+ if (v === 0) {
1353
+ v = null;
1354
+ }
1355
+
1356
+ if (v) {
1357
+ v += '';
1358
+ if (v.charAt(0) === ':') {
1359
+ v = v.substring(1);
1360
+ }
1361
+
1362
+ URI.ensureValidPort(v);
1363
+ }
1364
+ }
1365
+ return _port.call(this, v, build);
1366
+ };
1367
+ p.hostname = function(v, build) {
1368
+ if (this._parts.urn) {
1369
+ return v === undefined ? '' : this;
1370
+ }
1371
+
1372
+ if (v !== undefined) {
1373
+ var x = { preventInvalidHostname: this._parts.preventInvalidHostname };
1374
+ var res = URI.parseHost(v, x);
1375
+ if (res !== '/') {
1376
+ throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
1377
+ }
1378
+
1379
+ v = x.hostname;
1380
+ if (this._parts.preventInvalidHostname) {
1381
+ URI.ensureValidHostname(v, this._parts.protocol);
1382
+ }
1383
+ }
1384
+
1385
+ return _hostname.call(this, v, build);
1386
+ };
1387
+
1388
+ // compound accessors
1389
+ p.origin = function(v, build) {
1390
+ if (this._parts.urn) {
1391
+ return v === undefined ? '' : this;
1392
+ }
1393
+
1394
+ if (v === undefined) {
1395
+ var protocol = this.protocol();
1396
+ var authority = this.authority();
1397
+ if (!authority) {
1398
+ return '';
1399
+ }
1400
+
1401
+ return (protocol ? protocol + '://' : '') + this.authority();
1402
+ } else {
1403
+ var origin = URI(v);
1404
+ this
1405
+ .protocol(origin.protocol())
1406
+ .authority(origin.authority())
1407
+ .build(!build);
1408
+ return this;
1409
+ }
1410
+ };
1411
+ p.host = function(v, build) {
1412
+ if (this._parts.urn) {
1413
+ return v === undefined ? '' : this;
1414
+ }
1415
+
1416
+ if (v === undefined) {
1417
+ return this._parts.hostname ? URI.buildHost(this._parts) : '';
1418
+ } else {
1419
+ var res = URI.parseHost(v, this._parts);
1420
+ if (res !== '/') {
1421
+ throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
1422
+ }
1423
+
1424
+ this.build(!build);
1425
+ return this;
1426
+ }
1427
+ };
1428
+ p.authority = function(v, build) {
1429
+ if (this._parts.urn) {
1430
+ return v === undefined ? '' : this;
1431
+ }
1432
+
1433
+ if (v === undefined) {
1434
+ return this._parts.hostname ? URI.buildAuthority(this._parts) : '';
1435
+ } else {
1436
+ var res = URI.parseAuthority(v, this._parts);
1437
+ if (res !== '/') {
1438
+ throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
1439
+ }
1440
+
1441
+ this.build(!build);
1442
+ return this;
1443
+ }
1444
+ };
1445
+ p.userinfo = function(v, build) {
1446
+ if (this._parts.urn) {
1447
+ return v === undefined ? '' : this;
1448
+ }
1449
+
1450
+ if (v === undefined) {
1451
+ var t = URI.buildUserinfo(this._parts);
1452
+ return t ? t.substring(0, t.length -1) : t;
1453
+ } else {
1454
+ if (v[v.length-1] !== '@') {
1455
+ v += '@';
1456
+ }
1457
+
1458
+ URI.parseUserinfo(v, this._parts);
1459
+ this.build(!build);
1460
+ return this;
1461
+ }
1462
+ };
1463
+ p.resource = function(v, build) {
1464
+ var parts;
1465
+
1466
+ if (v === undefined) {
1467
+ return this.path() + this.search() + this.hash();
1468
+ }
1469
+
1470
+ parts = URI.parse(v);
1471
+ this._parts.path = parts.path;
1472
+ this._parts.query = parts.query;
1473
+ this._parts.fragment = parts.fragment;
1474
+ this.build(!build);
1475
+ return this;
1476
+ };
1477
+
1478
+ // fraction accessors
1479
+ p.subdomain = function(v, build) {
1480
+ if (this._parts.urn) {
1481
+ return v === undefined ? '' : this;
1482
+ }
1483
+
1484
+ // convenience, return "www" from "www.example.org"
1485
+ if (v === undefined) {
1486
+ if (!this._parts.hostname || this.is('IP')) {
1487
+ return '';
1488
+ }
1489
+
1490
+ // grab domain and add another segment
1491
+ var end = this._parts.hostname.length - this.domain().length - 1;
1492
+ return this._parts.hostname.substring(0, end) || '';
1493
+ } else {
1494
+ var e = this._parts.hostname.length - this.domain().length;
1495
+ var sub = this._parts.hostname.substring(0, e);
1496
+ var replace = new RegExp('^' + escapeRegEx(sub));
1497
+
1498
+ if (v && v.charAt(v.length - 1) !== '.') {
1499
+ v += '.';
1500
+ }
1501
+
1502
+ if (v.indexOf(':') !== -1) {
1503
+ throw new TypeError('Domains cannot contain colons');
1504
+ }
1505
+
1506
+ if (v) {
1507
+ URI.ensureValidHostname(v, this._parts.protocol);
1508
+ }
1509
+
1510
+ this._parts.hostname = this._parts.hostname.replace(replace, v);
1511
+ this.build(!build);
1512
+ return this;
1513
+ }
1514
+ };
1515
+ p.domain = function(v, build) {
1516
+ if (this._parts.urn) {
1517
+ return v === undefined ? '' : this;
1518
+ }
1519
+
1520
+ if (typeof v === 'boolean') {
1521
+ build = v;
1522
+ v = undefined;
1523
+ }
1524
+
1525
+ // convenience, return "example.org" from "www.example.org"
1526
+ if (v === undefined) {
1527
+ if (!this._parts.hostname || this.is('IP')) {
1528
+ return '';
1529
+ }
1530
+
1531
+ // if hostname consists of 1 or 2 segments, it must be the domain
1532
+ var t = this._parts.hostname.match(/\./g);
1533
+ if (t && t.length < 2) {
1534
+ return this._parts.hostname;
1535
+ }
1536
+
1537
+ // grab tld and add another segment
1538
+ var end = this._parts.hostname.length - this.tld(build).length - 1;
1539
+ end = this._parts.hostname.lastIndexOf('.', end -1) + 1;
1540
+ return this._parts.hostname.substring(end) || '';
1541
+ } else {
1542
+ if (!v) {
1543
+ throw new TypeError('cannot set domain empty');
1544
+ }
1545
+
1546
+ if (v.indexOf(':') !== -1) {
1547
+ throw new TypeError('Domains cannot contain colons');
1548
+ }
1549
+
1550
+ URI.ensureValidHostname(v, this._parts.protocol);
1551
+
1552
+ if (!this._parts.hostname || this.is('IP')) {
1553
+ this._parts.hostname = v;
1554
+ } else {
1555
+ var replace = new RegExp(escapeRegEx(this.domain()) + '$');
1556
+ this._parts.hostname = this._parts.hostname.replace(replace, v);
1557
+ }
1558
+
1559
+ this.build(!build);
1560
+ return this;
1561
+ }
1562
+ };
1563
+ p.tld = function(v, build) {
1564
+ if (this._parts.urn) {
1565
+ return v === undefined ? '' : this;
1566
+ }
1567
+
1568
+ if (typeof v === 'boolean') {
1569
+ build = v;
1570
+ v = undefined;
1571
+ }
1572
+
1573
+ // return "org" from "www.example.org"
1574
+ if (v === undefined) {
1575
+ if (!this._parts.hostname || this.is('IP')) {
1576
+ return '';
1577
+ }
1578
+
1579
+ var pos = this._parts.hostname.lastIndexOf('.');
1580
+ var tld = this._parts.hostname.substring(pos + 1);
1581
+
1582
+ if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {
1583
+ return SLD.get(this._parts.hostname) || tld;
1584
+ }
1585
+
1586
+ return tld;
1587
+ } else {
1588
+ var replace;
1589
+
1590
+ if (!v) {
1591
+ throw new TypeError('cannot set TLD empty');
1592
+ } else if (v.match(/[^a-zA-Z0-9-]/)) {
1593
+ if (SLD && SLD.is(v)) {
1594
+ replace = new RegExp(escapeRegEx(this.tld()) + '$');
1595
+ this._parts.hostname = this._parts.hostname.replace(replace, v);
1596
+ } else {
1597
+ throw new TypeError('TLD "' + v + '" contains characters other than [A-Z0-9]');
1598
+ }
1599
+ } else if (!this._parts.hostname || this.is('IP')) {
1600
+ throw new ReferenceError('cannot set TLD on non-domain host');
1601
+ } else {
1602
+ replace = new RegExp(escapeRegEx(this.tld()) + '$');
1603
+ this._parts.hostname = this._parts.hostname.replace(replace, v);
1604
+ }
1605
+
1606
+ this.build(!build);
1607
+ return this;
1608
+ }
1609
+ };
1610
+ p.directory = function(v, build) {
1611
+ if (this._parts.urn) {
1612
+ return v === undefined ? '' : this;
1613
+ }
1614
+
1615
+ if (v === undefined || v === true) {
1616
+ if (!this._parts.path && !this._parts.hostname) {
1617
+ return '';
1618
+ }
1619
+
1620
+ if (this._parts.path === '/') {
1621
+ return '/';
1622
+ }
1623
+
1624
+ var end = this._parts.path.length - this.filename().length - 1;
1625
+ var res = this._parts.path.substring(0, end) || (this._parts.hostname ? '/' : '');
1626
+
1627
+ return v ? URI.decodePath(res) : res;
1628
+
1629
+ } else {
1630
+ var e = this._parts.path.length - this.filename().length;
1631
+ var directory = this._parts.path.substring(0, e);
1632
+ var replace = new RegExp('^' + escapeRegEx(directory));
1633
+
1634
+ // fully qualifier directories begin with a slash
1635
+ if (!this.is('relative')) {
1636
+ if (!v) {
1637
+ v = '/';
1638
+ }
1639
+
1640
+ if (v.charAt(0) !== '/') {
1641
+ v = '/' + v;
1642
+ }
1643
+ }
1644
+
1645
+ // directories always end with a slash
1646
+ if (v && v.charAt(v.length - 1) !== '/') {
1647
+ v += '/';
1648
+ }
1649
+
1650
+ v = URI.recodePath(v);
1651
+ this._parts.path = this._parts.path.replace(replace, v);
1652
+ this.build(!build);
1653
+ return this;
1654
+ }
1655
+ };
1656
+ p.filename = function(v, build) {
1657
+ if (this._parts.urn) {
1658
+ return v === undefined ? '' : this;
1659
+ }
1660
+
1661
+ if (typeof v !== 'string') {
1662
+ if (!this._parts.path || this._parts.path === '/') {
1663
+ return '';
1664
+ }
1665
+
1666
+ var pos = this._parts.path.lastIndexOf('/');
1667
+ var res = this._parts.path.substring(pos+1);
1668
+
1669
+ return v ? URI.decodePathSegment(res) : res;
1670
+ } else {
1671
+ var mutatedDirectory = false;
1672
+
1673
+ if (v.charAt(0) === '/') {
1674
+ v = v.substring(1);
1675
+ }
1676
+
1677
+ if (v.match(/\.?\//)) {
1678
+ mutatedDirectory = true;
1679
+ }
1680
+
1681
+ var replace = new RegExp(escapeRegEx(this.filename()) + '$');
1682
+ v = URI.recodePath(v);
1683
+ this._parts.path = this._parts.path.replace(replace, v);
1684
+
1685
+ if (mutatedDirectory) {
1686
+ this.normalizePath(build);
1687
+ } else {
1688
+ this.build(!build);
1689
+ }
1690
+
1691
+ return this;
1692
+ }
1693
+ };
1694
+ p.suffix = function(v, build) {
1695
+ if (this._parts.urn) {
1696
+ return v === undefined ? '' : this;
1697
+ }
1698
+
1699
+ if (v === undefined || v === true) {
1700
+ if (!this._parts.path || this._parts.path === '/') {
1701
+ return '';
1702
+ }
1703
+
1704
+ var filename = this.filename();
1705
+ var pos = filename.lastIndexOf('.');
1706
+ var s, res;
1707
+
1708
+ if (pos === -1) {
1709
+ return '';
1710
+ }
1711
+
1712
+ // suffix may only contain alnum characters (yup, I made this up.)
1713
+ s = filename.substring(pos+1);
1714
+ res = (/^[a-z0-9%]+$/i).test(s) ? s : '';
1715
+ return v ? URI.decodePathSegment(res) : res;
1716
+ } else {
1717
+ if (v.charAt(0) === '.') {
1718
+ v = v.substring(1);
1719
+ }
1720
+
1721
+ var suffix = this.suffix();
1722
+ var replace;
1723
+
1724
+ if (!suffix) {
1725
+ if (!v) {
1726
+ return this;
1727
+ }
1728
+
1729
+ this._parts.path += '.' + URI.recodePath(v);
1730
+ } else if (!v) {
1731
+ replace = new RegExp(escapeRegEx('.' + suffix) + '$');
1732
+ } else {
1733
+ replace = new RegExp(escapeRegEx(suffix) + '$');
1734
+ }
1735
+
1736
+ if (replace) {
1737
+ v = URI.recodePath(v);
1738
+ this._parts.path = this._parts.path.replace(replace, v);
1739
+ }
1740
+
1741
+ this.build(!build);
1742
+ return this;
1743
+ }
1744
+ };
1745
+ p.segment = function(segment, v, build) {
1746
+ var separator = this._parts.urn ? ':' : '/';
1747
+ var path = this.path();
1748
+ var absolute = path.substring(0, 1) === '/';
1749
+ var segments = path.split(separator);
1750
+
1751
+ if (segment !== undefined && typeof segment !== 'number') {
1752
+ build = v;
1753
+ v = segment;
1754
+ segment = undefined;
1755
+ }
1756
+
1757
+ if (segment !== undefined && typeof segment !== 'number') {
1758
+ throw new Error('Bad segment "' + segment + '", must be 0-based integer');
1759
+ }
1760
+
1761
+ if (absolute) {
1762
+ segments.shift();
1763
+ }
1764
+
1765
+ if (segment < 0) {
1766
+ // allow negative indexes to address from the end
1767
+ segment = Math.max(segments.length + segment, 0);
1768
+ }
1769
+
1770
+ if (v === undefined) {
1771
+ /*jshint laxbreak: true */
1772
+ return segment === undefined
1773
+ ? segments
1774
+ : segments[segment];
1775
+ /*jshint laxbreak: false */
1776
+ } else if (segment === null || segments[segment] === undefined) {
1777
+ if (isArray(v)) {
1778
+ segments = [];
1779
+ // collapse empty elements within array
1780
+ for (var i=0, l=v.length; i < l; i++) {
1781
+ if (!v[i].length && (!segments.length || !segments[segments.length -1].length)) {
1782
+ continue;
1783
+ }
1784
+
1785
+ if (segments.length && !segments[segments.length -1].length) {
1786
+ segments.pop();
1787
+ }
1788
+
1789
+ segments.push(trimSlashes(v[i]));
1790
+ }
1791
+ } else if (v || typeof v === 'string') {
1792
+ v = trimSlashes(v);
1793
+ if (segments[segments.length -1] === '') {
1794
+ // empty trailing elements have to be overwritten
1795
+ // to prevent results such as /foo//bar
1796
+ segments[segments.length -1] = v;
1797
+ } else {
1798
+ segments.push(v);
1799
+ }
1800
+ }
1801
+ } else {
1802
+ if (v) {
1803
+ segments[segment] = trimSlashes(v);
1804
+ } else {
1805
+ segments.splice(segment, 1);
1806
+ }
1807
+ }
1808
+
1809
+ if (absolute) {
1810
+ segments.unshift('');
1811
+ }
1812
+
1813
+ return this.path(segments.join(separator), build);
1814
+ };
1815
+ p.segmentCoded = function(segment, v, build) {
1816
+ var segments, i, l;
1817
+
1818
+ if (typeof segment !== 'number') {
1819
+ build = v;
1820
+ v = segment;
1821
+ segment = undefined;
1822
+ }
1823
+
1824
+ if (v === undefined) {
1825
+ segments = this.segment(segment, v, build);
1826
+ if (!isArray(segments)) {
1827
+ segments = segments !== undefined ? URI.decode(segments) : undefined;
1828
+ } else {
1829
+ for (i = 0, l = segments.length; i < l; i++) {
1830
+ segments[i] = URI.decode(segments[i]);
1831
+ }
1832
+ }
1833
+
1834
+ return segments;
1835
+ }
1836
+
1837
+ if (!isArray(v)) {
1838
+ v = (typeof v === 'string' || v instanceof String) ? URI.encode(v) : v;
1839
+ } else {
1840
+ for (i = 0, l = v.length; i < l; i++) {
1841
+ v[i] = URI.encode(v[i]);
1842
+ }
1843
+ }
1844
+
1845
+ return this.segment(segment, v, build);
1846
+ };
1847
+
1848
+ // mutating query string
1849
+ var q = p.query;
1850
+ p.query = function(v, build) {
1851
+ if (v === true) {
1852
+ return URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1853
+ } else if (typeof v === 'function') {
1854
+ var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1855
+ var result = v.call(this, data);
1856
+ this._parts.query = URI.buildQuery(result || data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
1857
+ this.build(!build);
1858
+ return this;
1859
+ } else if (v !== undefined && typeof v !== 'string') {
1860
+ this._parts.query = URI.buildQuery(v, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
1861
+ this.build(!build);
1862
+ return this;
1863
+ } else {
1864
+ return q.call(this, v, build);
1865
+ }
1866
+ };
1867
+ p.setQuery = function(name, value, build) {
1868
+ var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1869
+
1870
+ if (typeof name === 'string' || name instanceof String) {
1871
+ data[name] = value !== undefined ? value : null;
1872
+ } else if (typeof name === 'object') {
1873
+ for (var key in name) {
1874
+ if (hasOwn.call(name, key)) {
1875
+ data[key] = name[key];
1876
+ }
1877
+ }
1878
+ } else {
1879
+ throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
1880
+ }
1881
+
1882
+ this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
1883
+ if (typeof name !== 'string') {
1884
+ build = value;
1885
+ }
1886
+
1887
+ this.build(!build);
1888
+ return this;
1889
+ };
1890
+ p.addQuery = function(name, value, build) {
1891
+ var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1892
+ URI.addQuery(data, name, value === undefined ? null : value);
1893
+ this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
1894
+ if (typeof name !== 'string') {
1895
+ build = value;
1896
+ }
1897
+
1898
+ this.build(!build);
1899
+ return this;
1900
+ };
1901
+ p.removeQuery = function(name, value, build) {
1902
+ var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1903
+ URI.removeQuery(data, name, value);
1904
+ this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
1905
+ if (typeof name !== 'string') {
1906
+ build = value;
1907
+ }
1908
+
1909
+ this.build(!build);
1910
+ return this;
1911
+ };
1912
+ p.hasQuery = function(name, value, withinArray) {
1913
+ var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
1914
+ return URI.hasQuery(data, name, value, withinArray);
1915
+ };
1916
+ p.setSearch = p.setQuery;
1917
+ p.addSearch = p.addQuery;
1918
+ p.removeSearch = p.removeQuery;
1919
+ p.hasSearch = p.hasQuery;
1920
+
1921
+ // sanitizing URLs
1922
+ p.normalize = function() {
1923
+ if (this._parts.urn) {
1924
+ return this
1925
+ .normalizeProtocol(false)
1926
+ .normalizePath(false)
1927
+ .normalizeQuery(false)
1928
+ .normalizeFragment(false)
1929
+ .build();
1930
+ }
1931
+
1932
+ return this
1933
+ .normalizeProtocol(false)
1934
+ .normalizeHostname(false)
1935
+ .normalizePort(false)
1936
+ .normalizePath(false)
1937
+ .normalizeQuery(false)
1938
+ .normalizeFragment(false)
1939
+ .build();
1940
+ };
1941
+ p.normalizeProtocol = function(build) {
1942
+ if (typeof this._parts.protocol === 'string') {
1943
+ this._parts.protocol = this._parts.protocol.toLowerCase();
1944
+ this.build(!build);
1945
+ }
1946
+
1947
+ return this;
1948
+ };
1949
+ p.normalizeHostname = function(build) {
1950
+ if (this._parts.hostname) {
1951
+ if (this.is('IDN') && punycode) {
1952
+ this._parts.hostname = punycode.toASCII(this._parts.hostname);
1953
+ } else if (this.is('IPv6') && IPv6) {
1954
+ this._parts.hostname = IPv6.best(this._parts.hostname);
1955
+ }
1956
+
1957
+ this._parts.hostname = this._parts.hostname.toLowerCase();
1958
+ this.build(!build);
1959
+ }
1960
+
1961
+ return this;
1962
+ };
1963
+ p.normalizePort = function(build) {
1964
+ // remove port of it's the protocol's default
1965
+ if (typeof this._parts.protocol === 'string' && this._parts.port === URI.defaultPorts[this._parts.protocol]) {
1966
+ this._parts.port = null;
1967
+ this.build(!build);
1968
+ }
1969
+
1970
+ return this;
1971
+ };
1972
+ p.normalizePath = function(build) {
1973
+ var _path = this._parts.path;
1974
+ if (!_path) {
1975
+ return this;
1976
+ }
1977
+
1978
+ if (this._parts.urn) {
1979
+ this._parts.path = URI.recodeUrnPath(this._parts.path);
1980
+ this.build(!build);
1981
+ return this;
1982
+ }
1983
+
1984
+ if (this._parts.path === '/') {
1985
+ return this;
1986
+ }
1987
+
1988
+ _path = URI.recodePath(_path);
1989
+
1990
+ var _was_relative;
1991
+ var _leadingParents = '';
1992
+ var _parent, _pos;
1993
+
1994
+ // handle relative paths
1995
+ if (_path.charAt(0) !== '/') {
1996
+ _was_relative = true;
1997
+ _path = '/' + _path;
1998
+ }
1999
+
2000
+ // handle relative files (as opposed to directories)
2001
+ if (_path.slice(-3) === '/..' || _path.slice(-2) === '/.') {
2002
+ _path += '/';
2003
+ }
2004
+
2005
+ // resolve simples
2006
+ _path = _path
2007
+ .replace(/(\/(\.\/)+)|(\/\.$)/g, '/')
2008
+ .replace(/\/{2,}/g, '/');
2009
+
2010
+ // remember leading parents
2011
+ if (_was_relative) {
2012
+ _leadingParents = _path.substring(1).match(/^(\.\.\/)+/) || '';
2013
+ if (_leadingParents) {
2014
+ _leadingParents = _leadingParents[0];
2015
+ }
2016
+ }
2017
+
2018
+ // resolve parents
2019
+ while (true) {
2020
+ _parent = _path.search(/\/\.\.(\/|$)/);
2021
+ if (_parent === -1) {
2022
+ // no more ../ to resolve
2023
+ break;
2024
+ } else if (_parent === 0) {
2025
+ // top level cannot be relative, skip it
2026
+ _path = _path.substring(3);
2027
+ continue;
2028
+ }
2029
+
2030
+ _pos = _path.substring(0, _parent).lastIndexOf('/');
2031
+ if (_pos === -1) {
2032
+ _pos = _parent;
2033
+ }
2034
+ _path = _path.substring(0, _pos) + _path.substring(_parent + 3);
2035
+ }
2036
+
2037
+ // revert to relative
2038
+ if (_was_relative && this.is('relative')) {
2039
+ _path = _leadingParents + _path.substring(1);
2040
+ }
2041
+
2042
+ this._parts.path = _path;
2043
+ this.build(!build);
2044
+ return this;
2045
+ };
2046
+ p.normalizePathname = p.normalizePath;
2047
+ p.normalizeQuery = function(build) {
2048
+ if (typeof this._parts.query === 'string') {
2049
+ if (!this._parts.query.length) {
2050
+ this._parts.query = null;
2051
+ } else {
2052
+ this.query(URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace));
2053
+ }
2054
+
2055
+ this.build(!build);
2056
+ }
2057
+
2058
+ return this;
2059
+ };
2060
+ p.normalizeFragment = function(build) {
2061
+ if (!this._parts.fragment) {
2062
+ this._parts.fragment = null;
2063
+ this.build(!build);
2064
+ }
2065
+
2066
+ return this;
2067
+ };
2068
+ p.normalizeSearch = p.normalizeQuery;
2069
+ p.normalizeHash = p.normalizeFragment;
2070
+
2071
+ p.iso8859 = function() {
2072
+ // expect unicode input, iso8859 output
2073
+ var e = URI.encode;
2074
+ var d = URI.decode;
2075
+
2076
+ URI.encode = escape;
2077
+ URI.decode = decodeURIComponent;
2078
+ try {
2079
+ this.normalize();
2080
+ } finally {
2081
+ URI.encode = e;
2082
+ URI.decode = d;
2083
+ }
2084
+ return this;
2085
+ };
2086
+
2087
+ p.unicode = function() {
2088
+ // expect iso8859 input, unicode output
2089
+ var e = URI.encode;
2090
+ var d = URI.decode;
2091
+
2092
+ URI.encode = strictEncodeURIComponent;
2093
+ URI.decode = unescape;
2094
+ try {
2095
+ this.normalize();
2096
+ } finally {
2097
+ URI.encode = e;
2098
+ URI.decode = d;
2099
+ }
2100
+ return this;
2101
+ };
2102
+
2103
+ p.readable = function() {
2104
+ var uri = this.clone();
2105
+ // removing username, password, because they shouldn't be displayed according to RFC 3986
2106
+ uri.username('').password('').normalize();
2107
+ var t = '';
2108
+ if (uri._parts.protocol) {
2109
+ t += uri._parts.protocol + '://';
2110
+ }
2111
+
2112
+ if (uri._parts.hostname) {
2113
+ if (uri.is('punycode') && punycode) {
2114
+ t += punycode.toUnicode(uri._parts.hostname);
2115
+ if (uri._parts.port) {
2116
+ t += ':' + uri._parts.port;
2117
+ }
2118
+ } else {
2119
+ t += uri.host();
2120
+ }
2121
+ }
2122
+
2123
+ if (uri._parts.hostname && uri._parts.path && uri._parts.path.charAt(0) !== '/') {
2124
+ t += '/';
2125
+ }
2126
+
2127
+ t += uri.path(true);
2128
+ if (uri._parts.query) {
2129
+ var q = '';
2130
+ for (var i = 0, qp = uri._parts.query.split('&'), l = qp.length; i < l; i++) {
2131
+ var kv = (qp[i] || '').split('=');
2132
+ q += '&' + URI.decodeQuery(kv[0], this._parts.escapeQuerySpace)
2133
+ .replace(/&/g, '%26');
2134
+
2135
+ if (kv[1] !== undefined) {
2136
+ q += '=' + URI.decodeQuery(kv[1], this._parts.escapeQuerySpace)
2137
+ .replace(/&/g, '%26');
2138
+ }
2139
+ }
2140
+ t += '?' + q.substring(1);
2141
+ }
2142
+
2143
+ t += URI.decodeQuery(uri.hash(), true);
2144
+ return t;
2145
+ };
2146
+
2147
+ // resolving relative and absolute URLs
2148
+ p.absoluteTo = function(base) {
2149
+ var resolved = this.clone();
2150
+ var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
2151
+ var basedir, i, p;
2152
+
2153
+ if (this._parts.urn) {
2154
+ throw new Error('URNs do not have any generally defined hierarchical components');
2155
+ }
2156
+
2157
+ if (!(base instanceof URI)) {
2158
+ base = new URI(base);
2159
+ }
2160
+
2161
+ if (resolved._parts.protocol) {
2162
+ // Directly returns even if this._parts.hostname is empty.
2163
+ return resolved;
2164
+ } else {
2165
+ resolved._parts.protocol = base._parts.protocol;
2166
+ }
2167
+
2168
+ if (this._parts.hostname) {
2169
+ return resolved;
2170
+ }
2171
+
2172
+ for (i = 0; (p = properties[i]); i++) {
2173
+ resolved._parts[p] = base._parts[p];
2174
+ }
2175
+
2176
+ if (!resolved._parts.path) {
2177
+ resolved._parts.path = base._parts.path;
2178
+ if (!resolved._parts.query) {
2179
+ resolved._parts.query = base._parts.query;
2180
+ }
2181
+ } else {
2182
+ if (resolved._parts.path.substring(-2) === '..') {
2183
+ resolved._parts.path += '/';
2184
+ }
2185
+
2186
+ if (resolved.path().charAt(0) !== '/') {
2187
+ basedir = base.directory();
2188
+ basedir = basedir ? basedir : base.path().indexOf('/') === 0 ? '/' : '';
2189
+ resolved._parts.path = (basedir ? (basedir + '/') : '') + resolved._parts.path;
2190
+ resolved.normalizePath();
2191
+ }
2192
+ }
2193
+
2194
+ resolved.build();
2195
+ return resolved;
2196
+ };
2197
+ p.relativeTo = function(base) {
2198
+ var relative = this.clone().normalize();
2199
+ var relativeParts, baseParts, common, relativePath, basePath;
2200
+
2201
+ if (relative._parts.urn) {
2202
+ throw new Error('URNs do not have any generally defined hierarchical components');
2203
+ }
2204
+
2205
+ base = new URI(base).normalize();
2206
+ relativeParts = relative._parts;
2207
+ baseParts = base._parts;
2208
+ relativePath = relative.path();
2209
+ basePath = base.path();
2210
+
2211
+ if (relativePath.charAt(0) !== '/') {
2212
+ throw new Error('URI is already relative');
2213
+ }
2214
+
2215
+ if (basePath.charAt(0) !== '/') {
2216
+ throw new Error('Cannot calculate a URI relative to another relative URI');
2217
+ }
2218
+
2219
+ if (relativeParts.protocol === baseParts.protocol) {
2220
+ relativeParts.protocol = null;
2221
+ }
2222
+
2223
+ if (relativeParts.username !== baseParts.username || relativeParts.password !== baseParts.password) {
2224
+ return relative.build();
2225
+ }
2226
+
2227
+ if (relativeParts.protocol !== null || relativeParts.username !== null || relativeParts.password !== null) {
2228
+ return relative.build();
2229
+ }
2230
+
2231
+ if (relativeParts.hostname === baseParts.hostname && relativeParts.port === baseParts.port) {
2232
+ relativeParts.hostname = null;
2233
+ relativeParts.port = null;
2234
+ } else {
2235
+ return relative.build();
2236
+ }
2237
+
2238
+ if (relativePath === basePath) {
2239
+ relativeParts.path = '';
2240
+ return relative.build();
2241
+ }
2242
+
2243
+ // determine common sub path
2244
+ common = URI.commonPath(relativePath, basePath);
2245
+
2246
+ // If the paths have nothing in common, return a relative URL with the absolute path.
2247
+ if (!common) {
2248
+ return relative.build();
2249
+ }
2250
+
2251
+ var parents = baseParts.path
2252
+ .substring(common.length)
2253
+ .replace(/[^\/]*$/, '')
2254
+ .replace(/.*?\//g, '../');
2255
+
2256
+ relativeParts.path = (parents + relativeParts.path.substring(common.length)) || './';
2257
+
2258
+ return relative.build();
2259
+ };
2260
+
2261
+ // comparing URIs
2262
+ p.equals = function(uri) {
2263
+ var one = this.clone();
2264
+ var two = new URI(uri);
2265
+ var one_map = {};
2266
+ var two_map = {};
2267
+ var checked = {};
2268
+ var one_query, two_query, key;
2269
+
2270
+ one.normalize();
2271
+ two.normalize();
2272
+
2273
+ // exact match
2274
+ if (one.toString() === two.toString()) {
2275
+ return true;
2276
+ }
2277
+
2278
+ // extract query string
2279
+ one_query = one.query();
2280
+ two_query = two.query();
2281
+ one.query('');
2282
+ two.query('');
2283
+
2284
+ // definitely not equal if not even non-query parts match
2285
+ if (one.toString() !== two.toString()) {
2286
+ return false;
2287
+ }
2288
+
2289
+ // query parameters have the same length, even if they're permuted
2290
+ if (one_query.length !== two_query.length) {
2291
+ return false;
2292
+ }
2293
+
2294
+ one_map = URI.parseQuery(one_query, this._parts.escapeQuerySpace);
2295
+ two_map = URI.parseQuery(two_query, this._parts.escapeQuerySpace);
2296
+
2297
+ for (key in one_map) {
2298
+ if (hasOwn.call(one_map, key)) {
2299
+ if (!isArray(one_map[key])) {
2300
+ if (one_map[key] !== two_map[key]) {
2301
+ return false;
2302
+ }
2303
+ } else if (!arraysEqual(one_map[key], two_map[key])) {
2304
+ return false;
2305
+ }
2306
+
2307
+ checked[key] = true;
2308
+ }
2309
+ }
2310
+
2311
+ for (key in two_map) {
2312
+ if (hasOwn.call(two_map, key)) {
2313
+ if (!checked[key]) {
2314
+ // two contains a parameter not present in one
2315
+ return false;
2316
+ }
2317
+ }
2318
+ }
2319
+
2320
+ return true;
2321
+ };
2322
+
2323
+ // state
2324
+ p.preventInvalidHostname = function(v) {
2325
+ this._parts.preventInvalidHostname = !!v;
2326
+ return this;
2327
+ };
2328
+
2329
+ p.duplicateQueryParameters = function(v) {
2330
+ this._parts.duplicateQueryParameters = !!v;
2331
+ return this;
2332
+ };
2333
+
2334
+ p.escapeQuerySpace = function(v) {
2335
+ this._parts.escapeQuerySpace = !!v;
2336
+ return this;
2337
+ };
2338
+
2339
+ return URI;
2340
+ }));