Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Created August 4, 2014 21:52
Show Gist options
  • Save rogeruiz/2a314ba81b881bc118b9 to your computer and use it in GitHub Desktop.
Save rogeruiz/2a314ba81b881bc118b9 to your computer and use it in GitHub Desktop.
EmberJS Social Initializer for Controllers [Sketch]
Social = Em.Object.extend
title: null
url: null
image: null
description: null
facebook: (->
endpoint = 'https://www.facebook.com/dialog/feed?'
return endpoint + Em.$.param
app_id: Vidz.get('facebookAppId')
display: 'popup'
link: this.get('url')
picture: this.get('image')
redirect_uri: "#{window.location.origin}/close_popup.html"
).property('title', 'url', 'description', 'image')
twitter: (->
endpoint = 'https://www.twitter.com/share?'
return endpoint + Em.$.param
text: this.get('title')
related: "#{Vidz.get('twitterHandle')},CNE"
via: Vidz.get('twitterHandle')
url: this.get('url')
).property('title', 'url')
googleplus: (->
endpoint = 'https://plus.google.com/share?'
return endpoint + Em.$.param
url: this.get('url')
).property('url')
network: null
createWindow: (->
return unless this.get('network')?
url = this.get(this.get('network'))
window.open url, 'Share', 'height=340, width=530, scrollbars=no, status=no'
# TODO This should really by happening on the specific controller that uses
# this Class. Reset network to null to allow multiple shares.
this.set('network', null)
).observes('network')
Em.Application.initializer
name: 'social'
initialize: (container, application) ->
application.register 'social:basic', Social
application.inject 'controller', 'social', 'social:basic'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment