Skip to content

Instantly share code, notes, and snippets.

@abrkn
Created September 20, 2012 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrkn/3755445 to your computer and use it in GitHub Desktop.
Save abrkn/3755445 to your computer and use it in GitHub Desktop.
COFFEE-fied
App.Meta = Backbone.Model.extend(initialize: ->
# Locate tags and find current values.
@$titleTag = $("title")
@$titleTag = $("<title></title>").appendTo($("head")) unless @$titleTag.length
@$descriptionTag = $("meta[name=\"description\"]")
@$descriptionTag = $("<meta name=\"description\" content=\"\" />").appendTo("head") unless @$descriptionTag.length
@attributes.title = window.title or @$titleTag.text()
@attributes.description = @$descriptionTag.attr("content")
@attributes.rendered = false
# Subscribe to events
@on "change:title", (model, title) ->
model.$titleTag.val title
document.title = title
@on "change:description", (model, description) ->
model.$descriptionTag.attr "content", description
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment