You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openNG/src/elements/router.coffee

35 lines
715 B
CoffeeScript

__ = require "lodash"
Polymer "openng-router",
_lastNavigatedURL: ""
_lastNavigatedMethod: ""
publish:
url: ""
'external-handler': null
navigate: (url, method = "GET", options = {}) ->
if url == ""
return
options.type ?= method
$.ajax url, options
.done (data, textStatus, xhr) =>
$(this).html(data)
ready: ->
self = this
$(this)
.on "click", "a", (event) ->
event.preventDefault()
url = $(this).attr("href")
if $(this).attr("target") == "_blank" and self['external-handler']?
self['external-handler'](url)
else
self.navigate url
@navigate(@url)
urlChanged: (oldValue, newValue) ->
console.log "URL CHANGED", this.url, oldValue, newValue