* working on fb integration

This commit is contained in:
Seth Call 2014-02-05 03:17:19 +00:00
parent 0d0ed1de5e
commit eadeb5888f
4 changed files with 84 additions and 8 deletions

View File

@ -0,0 +1,40 @@
(function(context,$) {
/**
* Javascript wrappers for the REST API
*/
"use strict";
context.JK = context.JK || {};
context.JK.FacebookRest = function() {
var self = this;
var logger = context.JK.logger;
// https://developers.facebook.com/docs/reference/api/post
function post(options) {
var d = $.Deferred();
FB.api(
'https://graph.facebook.com/me/feed',
'post',
options,
function(response) {
if (!response || response.error) {
d.reject(response)
} else {
d.resolve(response);
}
}
)
return d;
}
this.post = post;
return this;
};
})(window,jQuery);

View File

@ -5,6 +5,31 @@
context.JK.ShareDialog = function(app, entityId, entityType) {
var logger = context.JK.logger;
var rest = context.JK.Rest();
var facebookRest = context.JK.FacebookRest();
var facebookHelper = null;
function handleShareWithFacebook() {
facebookHelper.promptLogin()
.done(function(response) {
if(response.status == "connected") {
facebookRest.post({
access_token: response.authResponse.accessToken,
message: 'A Message',
caption: 'A Caption',
description: 'A description',
link: 'http://staging.jamkazam.com',
name: 'JamKazam',
picture: 'http://staging.jamkazam.com/assets/logo.png'
})
.done(function(response) {
alert("zong")
})
.fail(function(response) {
console.log("failed %o", response);
})
}
})
}
function socialShare() {
var shareWithFacebook = $('.share-with-facebook').is(':checked');
@ -13,6 +38,14 @@
if(!shareWithFacebook && !shareWithGoogle && !shareWithTwitter) {
$('.share-options').addClass('error')
return;
}
else {
$('.share-options').removeClass('error')
}
if(shareWithFacebook) {
handleShareWithFacebook();
}
}
function registerEvents(onOff) {
@ -91,7 +124,7 @@
}
function beforeShow() {
$('.share-with-selectors').removeClass('error');
$('.share-options').removeClass('error');
registerEvents(true);
}
@ -99,7 +132,9 @@
registerEvents(false);
}
function initialize(facebookHelper){
function initialize(_facebookHelper){
facebookHelper = _facebookHelper;
var dialogBindings = {
'beforeShow' : beforeShow,
'afterHide': afterHide

View File

@ -16,6 +16,7 @@
//= require utils
//= require ga
//= require jam_rest
//= require facebook_rest
//= require landing/init
//= require landing/signup
//= require web/downloads

View File

@ -8,12 +8,12 @@
<td valign="top" width="45%" class="border-right"><h3 class="mb5">Share to Social Media:</h3>
<textarea class="w95" rows="3">Add a Message...</textarea><br />
<div class="left share-options">
<input type="checkbox" />
<%= image_tag "content/icon_facebook.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle", :class => "share-with-facebook" %>&nbsp;
<input type="checkbox" />
<%= image_tag "content/icon_twitter.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle", :class => "share-with-twitter" %>&nbsp;
<input type="checkbox" />
<%= image_tag "content/icon_google.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle", :class => "share-with-google" %>&nbsp;
<input type="checkbox" class="share-with-facebook"/>
<%= image_tag "content/icon_facebook.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>&nbsp;
<input type="checkbox" class="share-with-twitter" />
<%= image_tag "content/icon_twitter.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>&nbsp;
<input type="checkbox" class="share-with-google" />
<%= image_tag "content/icon_google.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>&nbsp;
<div class="error-msg">Please select at least one</div>
</div>
<div class=" right mr10 mt5"><a class="button-orange dialog-share-button">SHARE</a></div>