Skip to content

Commit

Permalink
fixes, make Ajaxify.update_url available, readme, version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ncri committed Oct 17, 2012
1 parent 94962f4 commit ad78392
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -178,8 +178,9 @@ Ajaxify provides a few jQuery events you can bind to:


### Javascript ### Javascript


Put your javascript into an `ajaxify:content_loaded` event handler, to make sure it is executed after content has In addition to calling your javascript e.g. in a dom ready event handler (or in your layout), you should also
loaded via Ajaxify. You can't use dom ready for example as that only gets triggered for full page reloads. call it in an `ajaxify:content_loaded` event handler, to make sure it is executed after content has
loaded via Ajaxify.




### Toggle Ajaxify ### Toggle Ajaxify
Expand Down
2 changes: 1 addition & 1 deletion lib/ajaxify_rails/version.rb
@@ -1,3 +1,3 @@
module AjaxifyRails module AjaxifyRails
VERSION = "0.1.2" VERSION = "0.1.3"
end end
38 changes: 19 additions & 19 deletions vendor/assets/javascripts/ajaxify_rails.js.coffee
Expand Up @@ -12,6 +12,8 @@ initial_history_state =
data: data:
ajaxified: true ajaxified: true


base_path_regexp_cache = null



activate = (new_active = true) -> activate = (new_active = true) ->
active = new_active active = new_active
Expand Down Expand Up @@ -78,12 +80,23 @@ ajaxify = ->
ignore_hash_change = false ignore_hash_change = false




base_path_regexp = ->
return null unless base_paths
return base_path_regexp_cache if base_path_regexp_cache
# match starting and ending with base path, e.g. "^\/en$" (i.e. we are at the base path root) or
# starting with base path and continuing with '/', e.g. "^\/en\/" (i.e. we are NOT at the base path root) or
# starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
base_path_regexp_cache = new RegExp("^\/(#{ $.map(base_paths, (el) ->
el = regexp_escape el
"##{el}($|\/|\\?)"
).join('|')})", 'i')


# load content from url hash (non history interface browsers) # load content from url hash (non history interface browsers)
on_hash_change = -> on_hash_change = ->
url = window.location.hash.replace(/#/, "") url = window.location.hash.replace(/#/, "")


base_path_regexp = base_path_regexp() if match = window.location.pathname.match(base_path_regexp())
if match = window.location.pathname.match(base_path_regexp)
url = match[0] + url url = match[0] + url


url = '/' if url == '' url = '/' if url == ''
Expand Down Expand Up @@ -192,25 +205,13 @@ update_url = (options, pop_state = false) ->
ignore_hash_change = true # for non histroy interface browsers: avoids loading the page for hash changes caused by link clicks ignore_hash_change = true # for non histroy interface browsers: avoids loading the page for hash changes caused by link clicks
hash = "#{options.url.replace(new RegExp(protocol_with_host()), '')}" hash = "#{options.url.replace(new RegExp(protocol_with_host()), '')}"


base_path_regexp = base_path_regexp() if base_path_regexp()
if base_path_regexp hash = hash.replace(base_path_regexp(), '')
hash = hash.replace(base_path_regexp, '')
hash = "/#{hash}" unless hash == '' or hash.indexOf('/') == 0 hash = "/#{hash}" unless hash == '' or hash.indexOf('/') == 0


window.location.hash = hash window.location.hash = hash




base_path_regexp = ->
return null unless base_paths
# match starting and ending with base path, e.g. "^\/en$" (i.e. we are at the base path root) or
# starting with base path and continuing with '/', e.g. "^\/en\/" (i.e. we are NOT at the base path root) or
# starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
new RegExp("^\/(#{ $.map(base_paths, (el) ->
el = regexp_escape el
"##{el}($|\/|\\?)"
).join('|')})", 'i')


correct_url = -> correct_url = ->
if active if active


Expand All @@ -234,8 +235,7 @@ correct_url = ->
window.location.href = "#{protocol_with_host()}/#/#{window.location.search}" # move search behind # window.location.href = "#{protocol_with_host()}/#/#{window.location.search}" # move search behind #
return return


base_path_regexp = base_path_regexp() if base_path_regexp() and (match = window.location.pathname.match(base_path_regexp()))
if base_path_regexp and (match = window.location.pathname.match(base_path_regexp))
if match[0] == window.location.pathname if match[0] == window.location.pathname
if window.location.search == '' if window.location.search == ''
return # we are on a base path here already, so don't do anything return # we are on a base path here already, so don't do anything
Expand Down Expand Up @@ -270,7 +270,7 @@ protocol_with_host = ->
"#{loc.protocol}//#{loc.host}" "#{loc.protocol}//#{loc.host}"




@Ajaxify = { init, ajaxify, load, activate, set_content_container, get_content_container } @Ajaxify = { init, ajaxify, load, update_url, activate, set_content_container, get_content_container }




jQuery -> jQuery ->
Expand Down

0 comments on commit ad78392

Please sign in to comment.