Skip to content

Instantly share code, notes, and snippets.

@rpearce
Created September 22, 2012 17:33
Show Gist options
  • Save rpearce/3767010 to your computer and use it in GitHub Desktop.
Save rpearce/3767010 to your computer and use it in GitHub Desktop.
// ...
render: function() {
this.setMetaTags();
// ...
},
setMetaTags: function() {
var self, title, url, tags;
self = this;
title = {'metaName': 'property', 'name': 'og:title', 'value': this.model.get('location_from') + ' to ' + this.model.get('location_to')}
url = {'metaName': 'property', 'name': 'og:url', 'value': app_uri + '/#posts/' + this.model.get('id')}
tags = [title, url];
_.each(tags, function(item) {
self.setOrCreateMetaTag(item.metaName, item.name, item.value);
});
},
setOrCreateMetaTag: function(metaName, name, value) {
var t = 'meta['+metaName+'="'+name+'"]';
var mt = $(t);
if (mt.length === 0) {
t = '<meta '+metaName+'="'+name+'" />';
mt = $(t).appendTo('head');
}
mt.attr('content', value);
return mt;
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment