* working on fb integration
This commit is contained in:
parent
0d0ed1de5e
commit
eadeb5888f
|
|
@ -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);
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
//= require utils
|
||||
//= require ga
|
||||
//= require jam_rest
|
||||
//= require facebook_rest
|
||||
//= require landing/init
|
||||
//= require landing/signup
|
||||
//= require web/downloads
|
||||
|
|
|
|||
|
|
@ -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" %>
|
||||
<input type="checkbox" />
|
||||
<%= image_tag "content/icon_twitter.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle", :class => "share-with-twitter" %>
|
||||
<input type="checkbox" />
|
||||
<%= image_tag "content/icon_google.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle", :class => "share-with-google" %>
|
||||
<input type="checkbox" class="share-with-facebook"/>
|
||||
<%= image_tag "content/icon_facebook.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>
|
||||
<input type="checkbox" class="share-with-twitter" />
|
||||
<%= image_tag "content/icon_twitter.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>
|
||||
<input type="checkbox" class="share-with-google" />
|
||||
<%= image_tag "content/icon_google.png", :size => "24x24", :align => "absmiddle", :alt => "", :style => "vertical-align:middle" %>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue