ajaxify_rails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,7 +10,7 @@ Also form submissions are automatically turned into Ajax requests.
10
10
  Features:
11
11
 
12
12
  - Uses the html5 history interface for changing the url and making the browser's back and forward buttons work with Ajax.
13
- - Falls back to a hash based approach for browsers without the history interface (like Internet Explorer version <10).
13
+ - Falls back to a hash based URL approach for browsers without the history interface (like Internet Explorer version <10).
14
14
  - Hash based and non-hash URLs are interchangeable.
15
15
  - Transparently handles redirects and supports page titles and flash messages.
16
16
  - Tested with Chrome, Firefox, Safari and Internet Explorer 8+.
@@ -107,7 +107,7 @@ Also make sure that you supply invisible wrapper tags in your layout for each fl
107
107
  #notice{ style: "#{'display:none' unless flash[:notice]}" }
108
108
  = flash[:notice]
109
109
 
110
- ### Links or Forms that need to trigger full Page Reloads
110
+ ### Full Page Reloads
111
111
 
112
112
  Sometimes requests change the layout of the page so significantly that loading only the main content via Ajax
113
113
  and doing some minor layout tweaks here and there are simply not sufficient.
@@ -178,8 +178,9 @@ Ajaxify provides a few jQuery events you can bind to:
178
178
 
179
179
  ### Javascript
180
180
 
181
- Put your javascript into an `ajaxify:content_loaded` event handler, to make sure it is executed after content has
182
- loaded via Ajaxify. You can't use dom ready for example as that only gets triggered for full page relaods.
181
+ In addition to calling your javascript e.g. in a dom ready event handler (or in your layout), you should also
182
+ call it in an `ajaxify:content_loaded` event handler, to make sure it is executed after content has
183
+ loaded via Ajaxify.
183
184
 
184
185
 
185
186
  ### Toggle Ajaxify
@@ -1,3 +1,3 @@
1
1
  module AjaxifyRails
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -12,6 +12,8 @@ initial_history_state =
12
12
  data:
13
13
  ajaxified: true
14
14
 
15
+ base_path_regexp_cache = null
16
+
15
17
 
16
18
  activate = (new_active = true) ->
17
19
  active = new_active
@@ -78,12 +80,23 @@ ajaxify = ->
78
80
  ignore_hash_change = false
79
81
 
80
82
 
83
+ base_path_regexp = ->
84
+ return null unless base_paths
85
+ return base_path_regexp_cache if base_path_regexp_cache
86
+ # match starting and ending with base path, e.g. "^\/en$" (i.e. we are at the base path root) or
87
+ # starting with base path and continuing with '/', e.g. "^\/en\/" (i.e. we are NOT at the base path root) or
88
+ # starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
89
+ base_path_regexp_cache = new RegExp("^\/(#{ $.map(base_paths, (el) ->
90
+ el = regexp_escape el
91
+ "##{el}($|\/|\\?)"
92
+ ).join('|')})", 'i')
93
+
94
+
81
95
  # load content from url hash (non history interface browsers)
82
96
  on_hash_change = ->
83
97
  url = window.location.hash.replace(/#/, "")
84
98
 
85
- base_path_regexp = base_path_regexp()
86
- if match = window.location.pathname.match(base_path_regexp)
99
+ if match = window.location.pathname.match(base_path_regexp())
87
100
  url = match[0] + url
88
101
 
89
102
  url = '/' if url == ''
@@ -192,25 +205,13 @@ update_url = (options, pop_state = false) ->
192
205
  ignore_hash_change = true # for non histroy interface browsers: avoids loading the page for hash changes caused by link clicks
193
206
  hash = "#{options.url.replace(new RegExp(protocol_with_host()), '')}"
194
207
 
195
- base_path_regexp = base_path_regexp()
196
- if base_path_regexp
197
- hash = hash.replace(base_path_regexp, '')
208
+ if base_path_regexp()
209
+ hash = hash.replace(base_path_regexp(), '')
198
210
  hash = "/#{hash}" unless hash == '' or hash.indexOf('/') == 0
199
211
 
200
212
  window.location.hash = hash
201
213
 
202
214
 
203
- base_path_regexp = ->
204
- return null unless base_paths
205
- # match starting and ending with base path, e.g. "^\/en$" (i.e. we are at the base path root) or
206
- # starting with base path and continuing with '/', e.g. "^\/en\/" (i.e. we are NOT at the base path root) or
207
- # starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
208
- new RegExp("^\/(#{ $.map(base_paths, (el) ->
209
- el = regexp_escape el
210
- "##{el}($|\/|\\?)"
211
- ).join('|')})", 'i')
212
-
213
-
214
215
  correct_url = ->
215
216
  if active
216
217
 
@@ -234,8 +235,7 @@ correct_url = ->
234
235
  window.location.href = "#{protocol_with_host()}/#/#{window.location.search}" # move search behind #
235
236
  return
236
237
 
237
- base_path_regexp = base_path_regexp()
238
- if base_path_regexp and (match = window.location.pathname.match(base_path_regexp))
238
+ if base_path_regexp() and (match = window.location.pathname.match(base_path_regexp()))
239
239
  if match[0] == window.location.pathname
240
240
  if window.location.search == ''
241
241
  return # we are on a base path here already, so don't do anything
@@ -270,7 +270,7 @@ protocol_with_host = ->
270
270
  "#{loc.protocol}//#{loc.host}"
271
271
 
272
272
 
273
- @Ajaxify = { init, ajaxify, load, activate, set_content_container, get_content_container }
273
+ @Ajaxify = { init, ajaxify, load, update_url, activate, set_content_container, get_content_container }
274
274
 
275
275
 
276
276
  jQuery ->
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajaxify_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-08 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  segments:
68
68
  - 0
69
- hash: 2019060543339106194
69
+ hash: -684738438102731951
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: 2019060543339106194
78
+ hash: -684738438102731951
79
79
  requirements: []
80
80
  rubyforge_project:
81
81
  rubygems_version: 1.8.24