rails_admin 3.0.0.beta2 → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails_admin might be problematic. Click here for more details.

Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/Rakefile +11 -0
  4. data/app/assets/javascripts/rails_admin.js +4 -4
  5. data/app/assets/stylesheets/rails_admin.scss +31 -0
  6. data/app/controllers/rails_admin/application_controller.rb +1 -1
  7. data/app/controllers/rails_admin/main_controller.rb +10 -18
  8. data/app/helpers/rails_admin/application_helper.rb +12 -13
  9. data/app/helpers/rails_admin/form_builder.rb +3 -3
  10. data/app/helpers/rails_admin/main_helper.rb +1 -1
  11. data/app/views/kaminari/ra-twitter-bootstrap/_gap.html.erb +2 -2
  12. data/app/views/kaminari/ra-twitter-bootstrap/_next_page.html.erb +4 -4
  13. data/app/views/kaminari/ra-twitter-bootstrap/_page.html.erb +4 -4
  14. data/app/views/kaminari/ra-twitter-bootstrap/_paginator.html.erb +12 -10
  15. data/app/views/kaminari/ra-twitter-bootstrap/_prev_page.html.erb +4 -4
  16. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_next_page.html.erb +4 -4
  17. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_paginator.html.erb +6 -4
  18. data/app/views/kaminari/ra-twitter-bootstrap/without_count/_prev_page.html.erb +4 -4
  19. data/app/views/layouts/rails_admin/_navigation.html.erb +12 -16
  20. data/app/views/layouts/rails_admin/_secondary_navigation.html.erb +8 -8
  21. data/app/views/layouts/rails_admin/_sidebar_navigation.html.erb +1 -5
  22. data/app/views/layouts/rails_admin/application.html.erb +4 -7
  23. data/app/views/layouts/rails_admin/{pjax.html.erb → content.html.erb} +7 -5
  24. data/app/views/layouts/rails_admin/modal.js.erb +1 -1
  25. data/app/views/rails_admin/main/_dashboard_history.html.erb +1 -1
  26. data/app/views/rails_admin/main/_delete_notice.html.erb +2 -2
  27. data/app/views/rails_admin/main/_form_boolean.html.erb +6 -8
  28. data/app/views/rails_admin/main/_form_colorpicker.html.erb +5 -1
  29. data/app/views/rails_admin/main/_form_datetime.html.erb +8 -7
  30. data/app/views/rails_admin/main/_form_enumeration.html.erb +5 -1
  31. data/app/views/rails_admin/main/_form_file_upload.html.erb +1 -1
  32. data/app/views/rails_admin/main/_form_filtering_multiselect.html.erb +14 -14
  33. data/app/views/rails_admin/main/_form_filtering_select.html.erb +16 -21
  34. data/app/views/rails_admin/main/_form_multiple_file_upload.html.erb +1 -1
  35. data/app/views/rails_admin/main/_form_nested_many.html.erb +4 -4
  36. data/app/views/rails_admin/main/_form_nested_one.html.erb +4 -4
  37. data/app/views/rails_admin/main/_form_polymorphic_association.html.erb +11 -6
  38. data/app/views/rails_admin/main/_submit_buttons.html.erb +8 -8
  39. data/app/views/rails_admin/main/bulk_delete.html.erb +1 -1
  40. data/app/views/rails_admin/main/dashboard.html.erb +4 -4
  41. data/app/views/rails_admin/main/delete.html.erb +1 -1
  42. data/app/views/rails_admin/main/edit.html.erb +1 -1
  43. data/app/views/rails_admin/main/export.html.erb +35 -32
  44. data/app/views/rails_admin/main/history.html.erb +16 -14
  45. data/app/views/rails_admin/main/index.html.erb +38 -35
  46. data/app/views/rails_admin/main/new.html.erb +1 -1
  47. data/config/locales/rails_admin.en.yml +0 -1
  48. data/lib/generators/rails_admin/install_generator.rb +0 -1
  49. data/lib/generators/rails_admin/templates/webpack.config.js +0 -3
  50. data/lib/rails_admin/adapters/active_record/object_extension.rb +1 -1
  51. data/lib/rails_admin/adapters/active_record/property.rb +1 -1
  52. data/lib/rails_admin/adapters/active_record.rb +7 -3
  53. data/lib/rails_admin/adapters/mongoid/property.rb +3 -3
  54. data/lib/rails_admin/adapters/mongoid.rb +2 -2
  55. data/lib/rails_admin/config/actions/base.rb +1 -6
  56. data/lib/rails_admin/config/actions/dashboard.rb +13 -9
  57. data/lib/rails_admin/config/actions/delete.rb +4 -0
  58. data/lib/rails_admin/config/actions/edit.rb +4 -0
  59. data/lib/rails_admin/config/actions/new.rb +5 -0
  60. data/lib/rails_admin/config/actions/show_in_app.rb +0 -4
  61. data/lib/rails_admin/config/fields/association.rb +6 -1
  62. data/lib/rails_admin/config/fields/base.rb +1 -1
  63. data/lib/rails_admin/config/fields/types/action_text.rb +1 -1
  64. data/lib/rails_admin/config/fields/types/date.rb +7 -0
  65. data/lib/rails_admin/config/fields/types/datetime.rb +9 -4
  66. data/lib/rails_admin/config/fields/types/has_many_association.rb +4 -0
  67. data/lib/rails_admin/config/fields/types/has_one_association.rb +4 -0
  68. data/lib/rails_admin/config/fields/types/time.rb +9 -0
  69. data/lib/rails_admin/config/has_fields.rb +4 -0
  70. data/lib/rails_admin/config/model.rb +8 -0
  71. data/lib/rails_admin/config/sections/list.rb +4 -4
  72. data/lib/rails_admin/config.rb +4 -1
  73. data/lib/rails_admin/engine.rb +2 -5
  74. data/lib/rails_admin/support/datetime.rb +50 -53
  75. data/lib/rails_admin/support/esmodule_preprocessor.rb +2 -1
  76. data/lib/rails_admin/version.rb +1 -1
  77. data/package.json +7 -5
  78. data/src/rails_admin/base.js +3 -6
  79. data/src/rails_admin/filter-box.js +36 -37
  80. data/src/rails_admin/filtering-select.js +3 -6
  81. data/src/rails_admin/i18n.js +0 -3
  82. data/src/rails_admin/nested-form-hooks.js +16 -8
  83. data/src/rails_admin/remote-form.js +18 -15
  84. data/src/rails_admin/styles/base/theming.scss +80 -155
  85. data/src/rails_admin/styles/base/variables.scss +2 -0
  86. data/src/rails_admin/styles/base.scss +8 -45
  87. data/src/rails_admin/styles/filtering-multiselect.scss +2 -2
  88. data/src/rails_admin/styles/filtering-select.scss +1 -1
  89. data/src/rails_admin/styles/widgets.scss +1 -10
  90. data/src/rails_admin/ui.js +4 -54
  91. data/src/rails_admin/widgets.js +38 -48
  92. data/vendor/assets/javascripts/rails_admin/bootstrap.js +5046 -0
  93. data/vendor/assets/javascripts/rails_admin/flatpickr-with-locales.js +10683 -0
  94. data/vendor/assets/javascripts/rails_admin/popper.js +1974 -0
  95. data/vendor/assets/stylesheets/rails_admin/bootstrap/_accordion.scss +118 -0
  96. data/vendor/assets/stylesheets/rails_admin/bootstrap/_alert.scss +57 -0
  97. data/vendor/assets/stylesheets/rails_admin/bootstrap/_badge.scss +29 -0
  98. data/vendor/assets/stylesheets/rails_admin/bootstrap/_breadcrumb.scss +28 -0
  99. data/vendor/assets/stylesheets/rails_admin/bootstrap/_button-group.scss +139 -0
  100. data/vendor/assets/stylesheets/rails_admin/bootstrap/_buttons.scss +64 -110
  101. data/vendor/assets/stylesheets/rails_admin/bootstrap/_card.scss +216 -0
  102. data/vendor/assets/stylesheets/rails_admin/bootstrap/_carousel.scss +162 -176
  103. data/vendor/assets/stylesheets/rails_admin/bootstrap/_close.scss +31 -26
  104. data/vendor/assets/stylesheets/rails_admin/bootstrap/_containers.scss +41 -0
  105. data/vendor/assets/stylesheets/rails_admin/bootstrap/_dropdown.scss +240 -0
  106. data/vendor/assets/stylesheets/rails_admin/bootstrap/_forms.scss +9 -538
  107. data/vendor/assets/stylesheets/rails_admin/bootstrap/_functions.scss +302 -0
  108. data/vendor/assets/stylesheets/rails_admin/bootstrap/_grid.scss +18 -69
  109. data/vendor/assets/stylesheets/rails_admin/bootstrap/_helpers.scss +9 -0
  110. data/vendor/assets/stylesheets/rails_admin/bootstrap/_images.scss +42 -0
  111. data/vendor/assets/stylesheets/rails_admin/bootstrap/_list-group.scss +127 -84
  112. data/vendor/assets/stylesheets/rails_admin/bootstrap/_mixins.scss +26 -22
  113. data/vendor/assets/stylesheets/rails_admin/bootstrap/_modal.scss +209 -0
  114. data/vendor/assets/stylesheets/rails_admin/bootstrap/_nav.scss +139 -0
  115. data/vendor/assets/stylesheets/rails_admin/bootstrap/_navbar.scss +218 -542
  116. data/vendor/assets/stylesheets/rails_admin/bootstrap/_offcanvas.scss +83 -0
  117. data/vendor/assets/stylesheets/rails_admin/bootstrap/_pagination.scss +46 -70
  118. data/vendor/assets/stylesheets/rails_admin/bootstrap/_placeholders.scss +51 -0
  119. data/vendor/assets/stylesheets/rails_admin/bootstrap/_popover.scss +158 -0
  120. data/vendor/assets/stylesheets/rails_admin/bootstrap/_progress.scss +48 -0
  121. data/vendor/assets/stylesheets/rails_admin/bootstrap/_reboot.scss +625 -0
  122. data/vendor/assets/stylesheets/rails_admin/bootstrap/_root.scss +54 -0
  123. data/vendor/assets/stylesheets/rails_admin/bootstrap/_spinners.scss +69 -0
  124. data/vendor/assets/stylesheets/rails_admin/bootstrap/_tables.scss +100 -178
  125. data/vendor/assets/stylesheets/rails_admin/bootstrap/_toasts.scss +51 -0
  126. data/vendor/assets/stylesheets/rails_admin/bootstrap/_tooltip.scss +97 -77
  127. data/vendor/assets/stylesheets/rails_admin/bootstrap/_transitions.scss +27 -0
  128. data/vendor/assets/stylesheets/rails_admin/bootstrap/_type.scss +54 -254
  129. data/vendor/assets/stylesheets/rails_admin/bootstrap/_utilities.scss +628 -55
  130. data/vendor/assets/stylesheets/rails_admin/bootstrap/_variables.scss +1572 -781
  131. data/vendor/assets/stylesheets/rails_admin/bootstrap/bootstrap.scss +38 -35
  132. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_floating-labels.scss +63 -0
  133. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_form-check.scss +152 -0
  134. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_form-control.scss +219 -0
  135. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_form-range.scss +91 -0
  136. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_form-select.scss +72 -0
  137. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_form-text.scss +11 -0
  138. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_input-group.scss +121 -0
  139. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_labels.scss +36 -0
  140. data/vendor/assets/stylesheets/rails_admin/bootstrap/forms/_validation.scss +12 -0
  141. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_clearfix.scss +3 -0
  142. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_colored-links.scss +12 -0
  143. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_position.scss +30 -0
  144. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_ratio.scss +26 -0
  145. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_stacks.scss +15 -0
  146. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_stretched-link.scss +15 -0
  147. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_text-truncation.scss +7 -0
  148. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_visually-hidden.scss +8 -0
  149. data/vendor/assets/stylesheets/rails_admin/bootstrap/helpers/_vr.scss +8 -0
  150. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_alert.scss +11 -0
  151. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_backdrop.scss +14 -0
  152. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_border-radius.scss +72 -12
  153. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_box-shadow.scss +18 -0
  154. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_breakpoints.scss +127 -0
  155. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_buttons.scss +113 -30
  156. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_caret.scss +64 -0
  157. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_clearfix.scss +5 -18
  158. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_color-scheme.scss +7 -0
  159. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_container.scss +9 -0
  160. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_deprecate.scss +10 -0
  161. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_forms.scss +130 -70
  162. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_gradients.scss +27 -38
  163. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_grid.scss +127 -98
  164. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_image.scss +6 -24
  165. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_list-group.scss +13 -20
  166. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_lists.scss +7 -0
  167. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_pagination.scss +24 -16
  168. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_reset-text.scss +17 -0
  169. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_resize.scss +1 -1
  170. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_table-variants.scss +21 -0
  171. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/{_text-overflow.scss → _text-truncate.scss} +2 -2
  172. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_transition.scss +26 -0
  173. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_utilities.scss +89 -0
  174. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_visually-hidden.scss +29 -0
  175. data/vendor/assets/stylesheets/rails_admin/bootstrap/utilities/_api.scss +47 -0
  176. data/vendor/assets/stylesheets/rails_admin/bootstrap/vendor/_rfs.scss +354 -0
  177. data/vendor/assets/stylesheets/rails_admin/flatpickr.css +791 -0
  178. metadata +80 -91
  179. data/app/assets/stylesheets/rails_admin.scss.erb +0 -76
  180. data/lib/generators/rails_admin/templates/environment.js +0 -6
  181. data/src/rails_admin/styles/themes/cerulean/mixins.scss +0 -0
  182. data/src/rails_admin/styles/themes/cerulean/theming.scss +0 -135
  183. data/src/rails_admin/styles/themes/cerulean/variables.scss +0 -830
  184. data/src/rails_admin/styles/themes/default/mixins.scss +0 -8
  185. data/src/rails_admin/styles/themes/default/theming.scss +0 -11
  186. data/src/rails_admin/styles/themes/default/variables.scss +0 -12
  187. data/src/rails_admin/vendor/jquery.pjax.js +0 -899
  188. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-affix.js +0 -164
  189. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-alert.js +0 -95
  190. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-button.js +0 -125
  191. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-carousel.js +0 -246
  192. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-collapse.js +0 -212
  193. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-dropdown.js +0 -165
  194. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-modal.js +0 -358
  195. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-popover.js +0 -123
  196. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-scrollspy.js +0 -172
  197. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-tab.js +0 -155
  198. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-tooltip.js +0 -677
  199. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-transition.js +0 -59
  200. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap-typeahead.js +0 -1782
  201. data/vendor/assets/javascripts/rails_admin/bootstrap/bootstrap.js +0 -13
  202. data/vendor/assets/javascripts/rails_admin/bootstrap-datetimepicker.js +0 -2611
  203. data/vendor/assets/javascripts/rails_admin/jquery.pjax.js +0 -898
  204. data/vendor/assets/javascripts/rails_admin/moment-with-locales.js +0 -18085
  205. data/vendor/assets/stylesheets/rails_admin/_bootstrap-datetimepicker.scss +0 -343
  206. data/vendor/assets/stylesheets/rails_admin/bootstrap/_alerts.scss +0 -68
  207. data/vendor/assets/stylesheets/rails_admin/bootstrap/_badges.scss +0 -57
  208. data/vendor/assets/stylesheets/rails_admin/bootstrap/_breadcrumbs.scss +0 -26
  209. data/vendor/assets/stylesheets/rails_admin/bootstrap/_button-groups.scss +0 -240
  210. data/vendor/assets/stylesheets/rails_admin/bootstrap/_code.scss +0 -68
  211. data/vendor/assets/stylesheets/rails_admin/bootstrap/_component-animations.scss +0 -35
  212. data/vendor/assets/stylesheets/rails_admin/bootstrap/_dropdowns.scss +0 -215
  213. data/vendor/assets/stylesheets/rails_admin/bootstrap/_glyphicons.scss +0 -237
  214. data/vendor/assets/stylesheets/rails_admin/bootstrap/_input-groups.scss +0 -166
  215. data/vendor/assets/stylesheets/rails_admin/bootstrap/_jumbotron.scss +0 -48
  216. data/vendor/assets/stylesheets/rails_admin/bootstrap/_labels.scss +0 -66
  217. data/vendor/assets/stylesheets/rails_admin/bootstrap/_media.scss +0 -56
  218. data/vendor/assets/stylesheets/rails_admin/bootstrap/_modals.scss +0 -150
  219. data/vendor/assets/stylesheets/rails_admin/bootstrap/_navs.scss +0 -242
  220. data/vendor/assets/stylesheets/rails_admin/bootstrap/_normalize.scss +0 -425
  221. data/vendor/assets/stylesheets/rails_admin/bootstrap/_pager.scss +0 -55
  222. data/vendor/assets/stylesheets/rails_admin/bootstrap/_panels.scss +0 -243
  223. data/vendor/assets/stylesheets/rails_admin/bootstrap/_popovers.scss +0 -133
  224. data/vendor/assets/stylesheets/rails_admin/bootstrap/_print.scss +0 -101
  225. data/vendor/assets/stylesheets/rails_admin/bootstrap/_progress-bars.scss +0 -105
  226. data/vendor/assets/stylesheets/rails_admin/bootstrap/_responsive-embed.scss +0 -34
  227. data/vendor/assets/stylesheets/rails_admin/bootstrap/_responsive-utilities.scss +0 -174
  228. data/vendor/assets/stylesheets/rails_admin/bootstrap/_scaffolding.scss +0 -150
  229. data/vendor/assets/stylesheets/rails_admin/bootstrap/_theme.scss +0 -258
  230. data/vendor/assets/stylesheets/rails_admin/bootstrap/_thumbnails.scss +0 -38
  231. data/vendor/assets/stylesheets/rails_admin/bootstrap/_wells.scss +0 -29
  232. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_alerts.scss +0 -14
  233. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_background-variant.scss +0 -11
  234. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_center-block.scss +0 -7
  235. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_grid-framework.scss +0 -81
  236. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_hide-text.scss +0 -21
  237. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_labels.scss +0 -12
  238. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_nav-divider.scss +0 -10
  239. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_nav-vertical-align.scss +0 -9
  240. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_opacity.scss +0 -8
  241. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_panels.scss +0 -24
  242. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_progress-bar.scss +0 -10
  243. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_reset-filter.scss +0 -8
  244. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_responsive-visibility.scss +0 -21
  245. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_size.scss +0 -10
  246. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_tab-focus.scss +0 -9
  247. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_table-row.scss +0 -28
  248. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_text-emphasis.scss +0 -11
  249. data/vendor/assets/stylesheets/rails_admin/bootstrap/mixins/_vendor-prefixes.scss +0 -219
  250. data/vendor/assets/stylesheets/rails_admin/bootstrap-datetimepicker-build.scss +0 -16
@@ -1,899 +0,0 @@
1
- /*!
2
- * Copyright 2012, Chris Wanstrath
3
- * Released under the MIT License
4
- * https://github.com/defunkt/jquery-pjax
5
- */
6
- import jQuery from 'jquery';
7
-
8
- (function($){
9
-
10
- // When called on a container with a selector, fetches the href with
11
- // ajax into the container or with the data-pjax attribute on the link
12
- // itself.
13
- //
14
- // Tries to make sure the back button and ctrl+click work the way
15
- // you'd expect.
16
- //
17
- // Exported as $.fn.pjax
18
- //
19
- // Accepts a jQuery ajax options object that may include these
20
- // pjax specific options:
21
- //
22
- //
23
- // container - String selector for the element where to place the response body.
24
- // push - Whether to pushState the URL. Defaults to true (of course).
25
- // replace - Want to use replaceState instead? That's cool.
26
- //
27
- // For convenience the second parameter can be either the container or
28
- // the options object.
29
- //
30
- // Returns the jQuery object
31
- function fnPjax(selector, container, options) {
32
- options = optionsFor(container, options)
33
- return this.on('click.pjax', selector, function(event) {
34
- var opts = options
35
- if (!opts.container) {
36
- opts = $.extend({}, options)
37
- opts.container = $(this).attr('data-pjax')
38
- }
39
- handleClick(event, opts)
40
- })
41
- }
42
-
43
- // Public: pjax on click handler
44
- //
45
- // Exported as $.pjax.click.
46
- //
47
- // event - "click" jQuery.Event
48
- // options - pjax options
49
- //
50
- // Examples
51
- //
52
- // $(document).on('click', 'a', $.pjax.click)
53
- // // is the same as
54
- // $(document).pjax('a')
55
- //
56
- // Returns nothing.
57
- function handleClick(event, container, options) {
58
- options = optionsFor(container, options)
59
-
60
- var link = event.currentTarget
61
- var $link = $(link)
62
-
63
- if (link.tagName.toUpperCase() !== 'A')
64
- throw "$.fn.pjax or $.pjax.click requires an anchor element"
65
-
66
- // Middle click, cmd click, and ctrl click should open
67
- // links in a new tab as normal.
68
- if ( event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey )
69
- return
70
-
71
- // Ignore cross origin links
72
- if ( location.protocol !== link.protocol || location.hostname !== link.hostname )
73
- return
74
-
75
- // Ignore case when a hash is being tacked on the current URL
76
- if ( link.href.indexOf('#') > -1 && stripHash(link) == stripHash(location) )
77
- return
78
-
79
- // Ignore event with default prevented
80
- if (event.isDefaultPrevented())
81
- return
82
-
83
- var defaults = {
84
- url: link.href,
85
- container: $link.attr('data-pjax'),
86
- target: link
87
- }
88
-
89
- var opts = $.extend({}, defaults, options)
90
- var clickEvent = $.Event('pjax:click')
91
- $link.trigger(clickEvent, [opts])
92
-
93
- if (!clickEvent.isDefaultPrevented()) {
94
- pjax(opts)
95
- event.preventDefault()
96
- $link.trigger('pjax:clicked', [opts])
97
- }
98
- }
99
-
100
- // Public: pjax on form submit handler
101
- //
102
- // Exported as $.pjax.submit
103
- //
104
- // event - "click" jQuery.Event
105
- // options - pjax options
106
- //
107
- // Examples
108
- //
109
- // $(document).on('submit', 'form', function(event) {
110
- // $.pjax.submit(event, '[data-pjax-container]')
111
- // })
112
- //
113
- // Returns nothing.
114
- function handleSubmit(event, container, options) {
115
- options = optionsFor(container, options)
116
-
117
- var form = event.currentTarget
118
- var $form = $(form)
119
-
120
- if (form.tagName.toUpperCase() !== 'FORM')
121
- throw "$.pjax.submit requires a form element"
122
-
123
- var defaults = {
124
- type: ($form.attr('method') || 'GET').toUpperCase(),
125
- url: $form.attr('action'),
126
- container: $form.attr('data-pjax'),
127
- target: form
128
- }
129
-
130
- if (defaults.type !== 'GET' && window.FormData !== undefined) {
131
- defaults.data = new FormData(form)
132
- defaults.processData = false
133
- defaults.contentType = false
134
- } else {
135
- // Can't handle file uploads, exit
136
- if ($form.find(':file').length) {
137
- return
138
- }
139
-
140
- // Fallback to manually serializing the fields
141
- defaults.data = $form.serializeArray()
142
- }
143
-
144
- pjax($.extend({}, defaults, options))
145
-
146
- event.preventDefault()
147
- }
148
-
149
- // Loads a URL with ajax, puts the response body inside a container,
150
- // then pushState()'s the loaded URL.
151
- //
152
- // Works just like $.ajax in that it accepts a jQuery ajax
153
- // settings object (with keys like url, type, data, etc).
154
- //
155
- // Accepts these extra keys:
156
- //
157
- // container - String selector for where to stick the response body.
158
- // push - Whether to pushState the URL. Defaults to true (of course).
159
- // replace - Want to use replaceState instead? That's cool.
160
- //
161
- // Use it just like $.ajax:
162
- //
163
- // var xhr = $.pjax({ url: this.href, container: '#main' })
164
- // console.log( xhr.readyState )
165
- //
166
- // Returns whatever $.ajax returns.
167
- function pjax(options) {
168
- options = $.extend(true, {}, $.ajaxSettings, pjax.defaults, options)
169
-
170
- if ($.isFunction(options.url)) {
171
- options.url = options.url()
172
- }
173
-
174
- var hash = parseURL(options.url).hash
175
-
176
- var containerType = $.type(options.container)
177
- if (containerType !== 'string') {
178
- throw "expected string value for 'container' option; got " + containerType
179
- }
180
- var context = options.context = $(options.container)
181
- if (!context.length) {
182
- throw "the container selector '" + options.container + "' did not match anything"
183
- }
184
-
185
- // We want the browser to maintain two separate internal caches: one
186
- // for pjax'd partial page loads and one for normal page loads.
187
- // Without adding this secret parameter, some browsers will often
188
- // confuse the two.
189
- if (!options.data) options.data = {}
190
- if ($.isArray(options.data)) {
191
- options.data.push({name: '_pjax', value: options.container})
192
- } else {
193
- options.data._pjax = options.container
194
- }
195
-
196
- function fire(type, args, props) {
197
- if (!props) props = {}
198
- props.relatedTarget = options.target
199
- var event = $.Event(type, props)
200
- context.trigger(event, args)
201
- return !event.isDefaultPrevented()
202
- }
203
-
204
- var timeoutTimer
205
-
206
- options.beforeSend = function(xhr, settings) {
207
- // No timeout for non-GET requests
208
- // Its not safe to request the resource again with a fallback method.
209
- if (settings.type !== 'GET') {
210
- settings.timeout = 0
211
- }
212
-
213
- xhr.setRequestHeader('X-PJAX', 'true')
214
- xhr.setRequestHeader('X-PJAX-Container', options.container)
215
-
216
- if (!fire('pjax:beforeSend', [xhr, settings]))
217
- return false
218
-
219
- if (settings.timeout > 0) {
220
- timeoutTimer = setTimeout(function() {
221
- if (fire('pjax:timeout', [xhr, options]))
222
- xhr.abort('timeout')
223
- }, settings.timeout)
224
-
225
- // Clear timeout setting so jquerys internal timeout isn't invoked
226
- settings.timeout = 0
227
- }
228
-
229
- var url = parseURL(settings.url)
230
- if (hash) url.hash = hash
231
- options.requestUrl = stripInternalParams(url)
232
- }
233
-
234
- options.complete = function(xhr, textStatus) {
235
- if (timeoutTimer)
236
- clearTimeout(timeoutTimer)
237
-
238
- fire('pjax:complete', [xhr, textStatus, options])
239
-
240
- fire('pjax:end', [xhr, options])
241
- }
242
-
243
- options.error = function(xhr, textStatus, errorThrown) {
244
- var container = extractContainer("", xhr, options)
245
-
246
- var allowed = fire('pjax:error', [xhr, textStatus, errorThrown, options])
247
- if (options.type == 'GET' && textStatus !== 'abort' && allowed) {
248
- locationReplace(container.url)
249
- }
250
- }
251
-
252
- options.success = function(data, status, xhr) {
253
- var previousState = pjax.state
254
-
255
- // If $.pjax.defaults.version is a function, invoke it first.
256
- // Otherwise it can be a static string.
257
- var currentVersion = (typeof $.pjax.defaults.version === 'function') ?
258
- $.pjax.defaults.version() :
259
- $.pjax.defaults.version
260
-
261
- var latestVersion = xhr.getResponseHeader('X-PJAX-Version')
262
-
263
- var container = extractContainer(data, xhr, options)
264
-
265
- var url = parseURL(container.url)
266
- if (hash) {
267
- url.hash = hash
268
- container.url = url.href
269
- }
270
-
271
- // If there is a layout version mismatch, hard load the new url
272
- if (currentVersion && latestVersion && currentVersion !== latestVersion) {
273
- locationReplace(container.url)
274
- return
275
- }
276
-
277
- // If the new response is missing a body, hard load the page
278
- if (!container.contents) {
279
- locationReplace(container.url)
280
- return
281
- }
282
-
283
- pjax.state = {
284
- id: options.id || uniqueId(),
285
- url: container.url,
286
- title: container.title,
287
- container: options.container,
288
- fragment: options.fragment,
289
- timeout: options.timeout
290
- }
291
-
292
- if (options.push || options.replace) {
293
- window.history.replaceState(pjax.state, container.title, container.url)
294
- }
295
-
296
- // Only blur the focus if the focused element is within the container.
297
- var blurFocus = $.contains(options.container, document.activeElement)
298
-
299
- // Clear out any focused controls before inserting new page contents.
300
- if (blurFocus) {
301
- try {
302
- document.activeElement.blur()
303
- } catch (e) { }
304
- }
305
-
306
- if (container.title) document.title = container.title
307
-
308
- fire('pjax:beforeReplace', [container.contents, options], {
309
- state: pjax.state,
310
- previousState: previousState
311
- })
312
- context.html(container.contents)
313
-
314
- // FF bug: Won't autofocus fields that are inserted via JS.
315
- // This behavior is incorrect. So if theres no current focus, autofocus
316
- // the last field.
317
- //
318
- // http://www.w3.org/html/wg/drafts/html/master/forms.html
319
- var autofocusEl = context.find('input[autofocus], textarea[autofocus]').last()[0]
320
- if (autofocusEl && document.activeElement !== autofocusEl) {
321
- autofocusEl.focus()
322
- }
323
-
324
- executeScriptTags(container.scripts)
325
-
326
- var scrollTo = options.scrollTo
327
-
328
- // Ensure browser scrolls to the element referenced by the URL anchor
329
- if (hash) {
330
- var name = decodeURIComponent(hash.slice(1))
331
- var target = document.getElementById(name) || document.getElementsByName(name)[0]
332
- if (target) scrollTo = $(target).offset().top
333
- }
334
-
335
- if (typeof scrollTo == 'number') $(window).scrollTop(scrollTo)
336
-
337
- fire('pjax:success', [data, status, xhr, options])
338
- }
339
-
340
-
341
- // Initialize pjax.state for the initial page load. Assume we're
342
- // using the container and options of the link we're loading for the
343
- // back button to the initial page. This ensures good back button
344
- // behavior.
345
- if (!pjax.state) {
346
- pjax.state = {
347
- id: uniqueId(),
348
- url: window.location.href,
349
- title: document.title,
350
- container: options.container,
351
- fragment: options.fragment,
352
- timeout: options.timeout
353
- }
354
- window.history.replaceState(pjax.state, document.title)
355
- }
356
-
357
- // Cancel the current request if we're already pjaxing
358
- abortXHR(pjax.xhr)
359
-
360
- pjax.options = options
361
- var xhr = pjax.xhr = $.ajax(options)
362
-
363
- if (xhr.readyState > 0) {
364
- if (options.push && !options.replace) {
365
- // Cache current container element before replacing it
366
- cachePush(pjax.state.id, [options.container, cloneContents(context)])
367
-
368
- window.history.pushState(null, "", options.requestUrl)
369
- }
370
-
371
- fire('pjax:start', [xhr, options])
372
- fire('pjax:send', [xhr, options])
373
- }
374
-
375
- return pjax.xhr
376
- }
377
-
378
- // Public: Reload current page with pjax.
379
- //
380
- // Returns whatever $.pjax returns.
381
- function pjaxReload(container, options) {
382
- var defaults = {
383
- url: window.location.href,
384
- push: false,
385
- replace: true,
386
- scrollTo: false
387
- }
388
-
389
- return pjax($.extend(defaults, optionsFor(container, options)))
390
- }
391
-
392
- // Internal: Hard replace current state with url.
393
- //
394
- // Work for around WebKit
395
- // https://bugs.webkit.org/show_bug.cgi?id=93506
396
- //
397
- // Returns nothing.
398
- function locationReplace(url) {
399
- window.history.replaceState(null, "", pjax.state.url)
400
- window.location.replace(url)
401
- }
402
-
403
-
404
- var initialPop = true
405
- var initialURL = window.location.href
406
- var initialState = window.history.state
407
-
408
- // Initialize $.pjax.state if possible
409
- // Happens when reloading a page and coming forward from a different
410
- // session history.
411
- if (initialState && initialState.container) {
412
- pjax.state = initialState
413
- }
414
-
415
- // Non-webkit browsers don't fire an initial popstate event
416
- if ('state' in window.history) {
417
- initialPop = false
418
- }
419
-
420
- // popstate handler takes care of the back and forward buttons
421
- //
422
- // You probably shouldn't use pjax on pages with other pushState
423
- // stuff yet.
424
- function onPjaxPopstate(event) {
425
-
426
- // Hitting back or forward should override any pending PJAX request.
427
- if (!initialPop) {
428
- abortXHR(pjax.xhr)
429
- }
430
-
431
- var previousState = pjax.state
432
- var state = event.state
433
- var direction
434
-
435
- if (state && state.container) {
436
- // When coming forward from a separate history session, will get an
437
- // initial pop with a state we are already at. Skip reloading the current
438
- // page.
439
- if (initialPop && initialURL == state.url) return
440
-
441
- if (previousState) {
442
- // If popping back to the same state, just skip.
443
- // Could be clicking back from hashchange rather than a pushState.
444
- if (previousState.id === state.id) return
445
-
446
- // Since state IDs always increase, we can deduce the navigation direction
447
- direction = previousState.id < state.id ? 'forward' : 'back'
448
- }
449
-
450
- var cache = cacheMapping[state.id] || []
451
- var containerSelector = cache[0] || state.container
452
- var container = $(containerSelector), contents = cache[1]
453
-
454
- if (container.length) {
455
- if (previousState) {
456
- // Cache current container before replacement and inform the
457
- // cache which direction the history shifted.
458
- cachePop(direction, previousState.id, [containerSelector, cloneContents(container)])
459
- }
460
-
461
- var popstateEvent = $.Event('pjax:popstate', {
462
- state: state,
463
- direction: direction
464
- })
465
- container.trigger(popstateEvent)
466
-
467
- var options = {
468
- id: state.id,
469
- url: state.url,
470
- container: containerSelector,
471
- push: false,
472
- fragment: state.fragment,
473
- timeout: state.timeout,
474
- scrollTo: false
475
- }
476
-
477
- if (contents) {
478
- container.trigger('pjax:start', [null, options])
479
-
480
- pjax.state = state
481
- if (state.title) document.title = state.title
482
- var beforeReplaceEvent = $.Event('pjax:beforeReplace', {
483
- state: state,
484
- previousState: previousState
485
- })
486
- container.trigger(beforeReplaceEvent, [contents, options])
487
- container.html(contents)
488
-
489
- container.trigger('pjax:end', [null, options])
490
- } else {
491
- pjax(options)
492
- }
493
-
494
- // Force reflow/relayout before the browser tries to restore the
495
- // scroll position.
496
- container[0].offsetHeight
497
- } else {
498
- locationReplace(location.href)
499
- }
500
- }
501
- initialPop = false
502
- }
503
-
504
- // Fallback version of main pjax function for browsers that don't
505
- // support pushState.
506
- //
507
- // Returns nothing since it retriggers a hard form submission.
508
- function fallbackPjax(options) {
509
- var url = $.isFunction(options.url) ? options.url() : options.url,
510
- method = options.type ? options.type.toUpperCase() : 'GET'
511
-
512
- var form = $('<form>', {
513
- method: method === 'GET' ? 'GET' : 'POST',
514
- action: url,
515
- style: 'display:none'
516
- })
517
-
518
- if (method !== 'GET' && method !== 'POST') {
519
- form.append($('<input>', {
520
- type: 'hidden',
521
- name: '_method',
522
- value: method.toLowerCase()
523
- }))
524
- }
525
-
526
- var data = options.data
527
- if (typeof data === 'string') {
528
- $.each(data.split('&'), function(index, value) {
529
- var pair = value.split('=')
530
- form.append($('<input>', {type: 'hidden', name: pair[0], value: pair[1]}))
531
- })
532
- } else if ($.isArray(data)) {
533
- $.each(data, function(index, value) {
534
- form.append($('<input>', {type: 'hidden', name: value.name, value: value.value}))
535
- })
536
- } else if (typeof data === 'object') {
537
- var key
538
- for (key in data)
539
- form.append($('<input>', {type: 'hidden', name: key, value: data[key]}))
540
- }
541
-
542
- $(document.body).append(form)
543
- form.submit()
544
- }
545
-
546
- // Internal: Abort an XmlHttpRequest if it hasn't been completed,
547
- // also removing its event handlers.
548
- function abortXHR(xhr) {
549
- if ( xhr && xhr.readyState < 4) {
550
- xhr.onreadystatechange = $.noop
551
- xhr.abort()
552
- }
553
- }
554
-
555
- // Internal: Generate unique id for state object.
556
- //
557
- // Use a timestamp instead of a counter since ids should still be
558
- // unique across page loads.
559
- //
560
- // Returns Number.
561
- function uniqueId() {
562
- return (new Date).getTime()
563
- }
564
-
565
- function cloneContents(container) {
566
- var cloned = container.clone()
567
- // Unmark script tags as already being eval'd so they can get executed again
568
- // when restored from cache. HAXX: Uses jQuery internal method.
569
- cloned.find('script').each(function(){
570
- if (!this.src) jQuery._data(this, 'globalEval', false)
571
- })
572
- return cloned.contents()
573
- }
574
-
575
- // Internal: Strip internal query params from parsed URL.
576
- //
577
- // Returns sanitized url.href String.
578
- function stripInternalParams(url) {
579
- url.search = url.search.replace(/([?&])(_pjax|_)=[^&]*/g, '')
580
- return url.href.replace(/\?($|#)/, '$1')
581
- }
582
-
583
- // Internal: Parse URL components and returns a Locationish object.
584
- //
585
- // url - String URL
586
- //
587
- // Returns HTMLAnchorElement that acts like Location.
588
- function parseURL(url) {
589
- var a = document.createElement('a')
590
- a.href = url
591
- return a
592
- }
593
-
594
- // Internal: Return the `href` component of given URL object with the hash
595
- // portion removed.
596
- //
597
- // location - Location or HTMLAnchorElement
598
- //
599
- // Returns String
600
- function stripHash(location) {
601
- return location.href.replace(/#.*/, '')
602
- }
603
-
604
- // Internal: Build options Object for arguments.
605
- //
606
- // For convenience the first parameter can be either the container or
607
- // the options object.
608
- //
609
- // Examples
610
- //
611
- // optionsFor('#container')
612
- // // => {container: '#container'}
613
- //
614
- // optionsFor('#container', {push: true})
615
- // // => {container: '#container', push: true}
616
- //
617
- // optionsFor({container: '#container', push: true})
618
- // // => {container: '#container', push: true}
619
- //
620
- // Returns options Object.
621
- function optionsFor(container, options) {
622
- if (container && options) {
623
- options = $.extend({}, options)
624
- options.container = container
625
- return options
626
- } else if ($.isPlainObject(container)) {
627
- return container
628
- } else {
629
- return {container: container}
630
- }
631
- }
632
-
633
- // Internal: Filter and find all elements matching the selector.
634
- //
635
- // Where $.fn.find only matches descendants, findAll will test all the
636
- // top level elements in the jQuery object as well.
637
- //
638
- // elems - jQuery object of Elements
639
- // selector - String selector to match
640
- //
641
- // Returns a jQuery object.
642
- function findAll(elems, selector) {
643
- return elems.filter(selector).add(elems.find(selector))
644
- }
645
-
646
- function parseHTML(html) {
647
- return $.parseHTML(html, document, true)
648
- }
649
-
650
- // Internal: Extracts container and metadata from response.
651
- //
652
- // 1. Extracts X-PJAX-URL header if set
653
- // 2. Extracts inline <title> tags
654
- // 3. Builds response Element and extracts fragment if set
655
- //
656
- // data - String response data
657
- // xhr - XHR response
658
- // options - pjax options Object
659
- //
660
- // Returns an Object with url, title, and contents keys.
661
- function extractContainer(data, xhr, options) {
662
- var obj = {}, fullDocument = /<html/i.test(data)
663
-
664
- // Prefer X-PJAX-URL header if it was set, otherwise fallback to
665
- // using the original requested url.
666
- var serverUrl = xhr.getResponseHeader('X-PJAX-URL')
667
- obj.url = serverUrl ? stripInternalParams(parseURL(serverUrl)) : options.requestUrl
668
-
669
- // Attempt to parse response html into elements
670
- if (fullDocument) {
671
- var $head = $(parseHTML(data.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0]))
672
- var $body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
673
- } else {
674
- var $head = $body = $(parseHTML(data))
675
- }
676
-
677
- // If response data is empty, return fast
678
- if ($body.length === 0)
679
- return obj
680
-
681
- // If there's a <title> tag in the header, use it as
682
- // the page's title.
683
- obj.title = findAll($head, 'title').last().text()
684
-
685
- if (options.fragment) {
686
- // If they specified a fragment, look for it in the response
687
- // and pull it out.
688
- if (options.fragment === 'body') {
689
- var $fragment = $body
690
- } else {
691
- var $fragment = findAll($body, options.fragment).first()
692
- }
693
-
694
- if ($fragment.length) {
695
- obj.contents = options.fragment === 'body' ? $fragment : $fragment.contents()
696
-
697
- // If there's no title, look for data-title and title attributes
698
- // on the fragment
699
- if (!obj.title)
700
- obj.title = $fragment.attr('title') || $fragment.data('title')
701
- }
702
-
703
- } else if (!fullDocument) {
704
- obj.contents = $body
705
- }
706
-
707
- // Clean up any <title> tags
708
- if (obj.contents) {
709
- // Remove any parent title elements
710
- obj.contents = obj.contents.not(function() { return $(this).is('title') })
711
-
712
- // Then scrub any titles from their descendants
713
- obj.contents.find('title').remove()
714
-
715
- // Gather all script[src] elements
716
- obj.scripts = findAll(obj.contents, 'script[src]').remove()
717
- obj.contents = obj.contents.not(obj.scripts)
718
- }
719
-
720
- // Trim any whitespace off the title
721
- if (obj.title) obj.title = $.trim(obj.title)
722
-
723
- return obj
724
- }
725
-
726
- // Load an execute scripts using standard script request.
727
- //
728
- // Avoids jQuery's traditional $.getScript which does a XHR request and
729
- // globalEval.
730
- //
731
- // scripts - jQuery object of script Elements
732
- //
733
- // Returns nothing.
734
- function executeScriptTags(scripts) {
735
- if (!scripts) return
736
-
737
- var existingScripts = $('script[src]')
738
-
739
- scripts.each(function() {
740
- var src = this.src
741
- var matchedScripts = existingScripts.filter(function() {
742
- return this.src === src
743
- })
744
- if (matchedScripts.length) return
745
-
746
- var script = document.createElement('script')
747
- var type = $(this).attr('type')
748
- if (type) script.type = type
749
- script.src = $(this).attr('src')
750
- document.head.appendChild(script)
751
- })
752
- }
753
-
754
- // Internal: History DOM caching class.
755
- var cacheMapping = {}
756
- var cacheForwardStack = []
757
- var cacheBackStack = []
758
-
759
- // Push previous state id and container contents into the history
760
- // cache. Should be called in conjunction with `pushState` to save the
761
- // previous container contents.
762
- //
763
- // id - State ID Number
764
- // value - DOM Element to cache
765
- //
766
- // Returns nothing.
767
- function cachePush(id, value) {
768
- cacheMapping[id] = value
769
- cacheBackStack.push(id)
770
-
771
- // Remove all entries in forward history stack after pushing a new page.
772
- trimCacheStack(cacheForwardStack, 0)
773
-
774
- // Trim back history stack to max cache length.
775
- trimCacheStack(cacheBackStack, pjax.defaults.maxCacheLength)
776
- }
777
-
778
- // Shifts cache from directional history cache. Should be
779
- // called on `popstate` with the previous state id and container
780
- // contents.
781
- //
782
- // direction - "forward" or "back" String
783
- // id - State ID Number
784
- // value - DOM Element to cache
785
- //
786
- // Returns nothing.
787
- function cachePop(direction, id, value) {
788
- var pushStack, popStack
789
- cacheMapping[id] = value
790
-
791
- if (direction === 'forward') {
792
- pushStack = cacheBackStack
793
- popStack = cacheForwardStack
794
- } else {
795
- pushStack = cacheForwardStack
796
- popStack = cacheBackStack
797
- }
798
-
799
- pushStack.push(id)
800
- if (id = popStack.pop())
801
- delete cacheMapping[id]
802
-
803
- // Trim whichever stack we just pushed to to max cache length.
804
- trimCacheStack(pushStack, pjax.defaults.maxCacheLength)
805
- }
806
-
807
- // Trim a cache stack (either cacheBackStack or cacheForwardStack) to be no
808
- // longer than the specified length, deleting cached DOM elements as necessary.
809
- //
810
- // stack - Array of state IDs
811
- // length - Maximum length to trim to
812
- //
813
- // Returns nothing.
814
- function trimCacheStack(stack, length) {
815
- while (stack.length > length)
816
- delete cacheMapping[stack.shift()]
817
- }
818
-
819
- // Public: Find version identifier for the initial page load.
820
- //
821
- // Returns String version or undefined.
822
- function findVersion() {
823
- return $('meta').filter(function() {
824
- var name = $(this).attr('http-equiv')
825
- return name && name.toUpperCase() === 'X-PJAX-VERSION'
826
- }).attr('content')
827
- }
828
-
829
- // Install pjax functions on $.pjax to enable pushState behavior.
830
- //
831
- // Does nothing if already enabled.
832
- //
833
- // Examples
834
- //
835
- // $.pjax.enable()
836
- //
837
- // Returns nothing.
838
- function enable() {
839
- $.fn.pjax = fnPjax
840
- $.pjax = pjax
841
- $.pjax.enable = $.noop
842
- $.pjax.disable = disable
843
- $.pjax.click = handleClick
844
- $.pjax.submit = handleSubmit
845
- $.pjax.reload = pjaxReload
846
- $.pjax.defaults = {
847
- timeout: 650,
848
- push: true,
849
- replace: false,
850
- type: 'GET',
851
- dataType: 'html',
852
- scrollTo: 0,
853
- maxCacheLength: 20,
854
- version: findVersion
855
- }
856
- $(window).on('popstate.pjax', onPjaxPopstate)
857
- }
858
-
859
- // Disable pushState behavior.
860
- //
861
- // This is the case when a browser doesn't support pushState. It is
862
- // sometimes useful to disable pushState for debugging on a modern
863
- // browser.
864
- //
865
- // Examples
866
- //
867
- // $.pjax.disable()
868
- //
869
- // Returns nothing.
870
- function disable() {
871
- $.fn.pjax = function() { return this }
872
- $.pjax = fallbackPjax
873
- $.pjax.enable = enable
874
- $.pjax.disable = $.noop
875
- $.pjax.click = $.noop
876
- $.pjax.submit = $.noop
877
- $.pjax.reload = function() { window.location.reload() }
878
-
879
- $(window).off('popstate.pjax', onPjaxPopstate)
880
- }
881
-
882
-
883
- // Add the state property to jQuery's event object so we can use it in
884
- // $(window).bind('popstate')
885
- if ($.event.props && $.inArray('state', $.event.props) < 0) {
886
- $.event.props.push('state')
887
- } else if (!('state' in $.Event.prototype)) {
888
- $.event.addProp('state')
889
- }
890
-
891
- // Is pjax supported by this browser?
892
- $.support.pjax =
893
- window.history && window.history.pushState && window.history.replaceState &&
894
- // pushState isn't reliable on iOS until 5.
895
- !navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/)
896
-
897
- $.support.pjax ? enable() : disable()
898
-
899
- })(jQuery)