Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixes https://app.asana.com/0/1328982439263/2397880387313

  • Loading branch information...
commit 9bacdffd0e1599b3c8751e3606a57eab8a827bab 1 parent d984c85
@vvgomes vvgomes authored
View
2  app/assets/javascripts/application.js
@@ -19,6 +19,8 @@
//= require jquery.flot
//= require jquery.mailcheck
//= require jquery.counter
+//= require facebook_recommendation
+//= require facebook
//= require petition
//= require global
//= require petition_editor
View
10 app/assets/javascripts/facebook.js
@@ -18,7 +18,7 @@ var socialTracking = (function() {
}
function trackStatus(status) {
- sendRequest({ facebook_action: 'status', facebook_status: data });
+ sendRequest({ facebook_action: 'status', facebook_status: status });
}
function trackSharing(action, actionId, requestId, friendIds) {
@@ -49,7 +49,7 @@ var socialTracking = (function() {
var facebook = (function(socialTracking, recommendation) {
function init() {
- iniApp();
+ initApp();
setupShare();
setupPopup();
setupDialog();
@@ -105,7 +105,7 @@ var facebook = (function(socialTracking, recommendation) {
$('.fb_popup_btn').click(function() {
openPopup();
socialTracking.trackSharing('popup');
- $('.giantbox').hide();
+ closeThanksModal();
});
function openPopup() {
@@ -121,7 +121,7 @@ var facebook = (function(socialTracking, recommendation) {
$('.fb_dialog_btn').click(function() {
openDialog();
socialTracking.trackSharing('dialog');
- $('.giantbox').hide();
+ closeThanksModal();
});
function openDialog() {
@@ -151,6 +151,7 @@ var facebook = (function(socialTracking, recommendation) {
socialTracking.trackSharing('request', '', res.request, res.to);
}
});
+ closeThanksModal();
});
}
@@ -165,6 +166,7 @@ var facebook = (function(socialTracking, recommendation) {
socialTracking.trackSharing('autofill_request', '', res.request, '');
}
});
+ closeThanksModal();
});
}
View
325 app/assets/javascripts/facebook_recommendation.js
@@ -1,171 +1,170 @@
-recommended_friends = [];
-var spinner;
-
-function diff(array1, array2) {
- var a1 = $.map(array1, function(item) {return item.uid;});
- var a2 = $.map(array2, function(item) {return item.uid;});
- var uids = a1.filter(function(i) {
- return a2.indexOf(i) < 0;
- });
- return array1.filter(function(i) { return uids.indexOf(i.uid) >= 0; });
-}
-
-function createSpinner() {
- var opts = {
- lines: 13, // The number of lines to draw
- length: 7, // The length of each line
- width: 4, // The line thickness
- radius: 10, // The radius of the inner circle
- corners: 1, // Corner roundness (0..1)
- rotate: 0, // The rotation offset
- color: '#000', // #rgb or #rrggbb
- speed: 1, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- className: 'spinner', // The CSS class to assign to the spinner
- zIndex: 2e9, // The z-index (defaults to 2000000000)
- top: 'auto', // Top position relative to parent in px
- left: 'auto' // Left position relative to parent in px
- };
- var target = $('#facebookFriendsModal .modal-body').get(0);
- return new Spinner(opts).spin(target);
-}
-
-function buildMultiFriendSelector() {
- $(recommended_friends).each(function(index, item) {
- var checked = item.preselect ? 'checked' : '';
- var friend = $(
- '<div class="friend">'+
- '<input type="checkbox" '+checked+' value="'+item.uid+'"/>'+
- '<div class="name">'+item.name+'</div>'+
- '</div>'
- );
- var id = '#' + item.type;
- $('.facebook_friend_widget ' + id + ' .friend_list').append(friend);
- $(id).removeClass('hide');
- });
-}
-
-function postToMeAndFriends() {
- var domain = location.href.replace(/\?.*/,"");
- var referralCode = (VK.ref_code === '' ? $.cookie('ref_code') : VK.ref_code);
- var url = [domain, '?recommend_ref=', referralCode].join('');
- var message = $('#message-to-friends').val();
-
- var friends = (function() {
- return $('.friend_lists input[type="checkbox"]')
- .filter(function() { return $(this).attr('checked'); })
- .map(function() { return $(this).val(); });
- })().toArray().concat(['me']);
-
- (function send(i) {
- if(!(uid = friends[i])) { return; }
- FB.api('/'+uid+'/feed', 'post', {link: url, message: message}, function(res){
- send(i+1);
+var recommendation = (function() {
+ var recommended_friends = [];
+ var spinner;
+
+ function diff(array1, array2) {
+ var a1 = $.map(array1, function(item) {return item.uid;});
+ var a2 = $.map(array2, function(item) {return item.uid;});
+ var uids = a1.filter(function(i) {
+ return a2.indexOf(i) < 0;
});
- })(0);
-
- $('#facebookFriendsModal').modal('toggle');
- $('#thanksAfterSharingModal').modal('toggle');
-}
-
-function findRecommendedFriends(groups) {
- var tier1 = diff(groups.interacted, groups.sympathetic);
- var friends_not_involved = diff(groups.friends, groups.sympathetic);
- var tier2 = diff(friends_not_involved, tier1);
- var tier3 = diff(groups.friends, tier1.concat(tier2));
- var suggested = tier1.concat(tier2);
- remaining = suggested.slice(25);
- suggested = suggested.slice(0, 25);
- remaining = remaining.concat(tier3);
-
- recommended_friends = $.map(suggested, function(friend) {
- return {uid: friend.uid, name: friend.name, type: 'suggested', preselect: true};
- });
-
- $(remaining).each(function(index, friend){
- recommended_friends.push({uid: friend.uid, name: friend.name, type: 'other', preselect: false});
- });
-
- buildMultiFriendSelector();
- spinner.stop();
- $('.btn-success').click(postToMeAndFriends);
-}
-
-function queryFacebook(query, groups) {
- FB.api('/fql?q='+encodeURIComponent(JSON.stringify(query)), function(response) {
- $(response.data).each(function(index, object) {
- var name = object.name;
- var resultSet = object.fql_result_set;
- $(resultSet).each(function(i, friend) {
- if(!groups[name]) { return; }
- groups[name].push(friend);
- });
+ return array1.filter(function(i) { return uids.indexOf(i.uid) >= 0; });
+ }
+
+ function createSpinner() {
+ var opts = {
+ lines: 13, // The number of lines to draw
+ length: 7, // The length of each line
+ width: 4, // The line thickness
+ radius: 10, // The radius of the inner circle
+ corners: 1, // Corner roundness (0..1)
+ rotate: 0, // The rotation offset
+ color: '#000', // #rgb or #rrggbb
+ speed: 1, // Rounds per second
+ trail: 60, // Afterglow percentage
+ shadow: false, // Whether to render a shadow
+ hwaccel: false, // Whether to use hardware acceleration
+ className: 'spinner', // The CSS class to assign to the spinner
+ zIndex: 2e9, // The z-index (defaults to 2000000000)
+ top: 'auto', // Top position relative to parent in px
+ left: 'auto' // Left position relative to parent in px
+ };
+ var target = $('#facebookFriendsModal .modal-body').get(0);
+ return new Spinner(opts).spin(target);
+ }
+
+ function buildMultiFriendSelector() {
+ $(recommended_friends).each(function(index, item) {
+ var checked = item.preselect ? 'checked' : '';
+ var friend = $(
+ '<div class="friend">'+
+ '<input type="checkbox" '+checked+' value="'+item.uid+'"/>'+
+ '<div class="name">'+item.name+'</div>'+
+ '</div>'
+ );
+ var id = '#' + item.type;
+ $('.facebook_friend_widget ' + id + ' .friend_list').append(friend);
+ $(id).removeClass('hide');
});
- findRecommendedFriends(groups);
- });
-}
-
-function getFriendsWithAppInstalled() {
- spinner = createSpinner();
-
- var groups = {
- interacted: [],
- sympathetic: [],
- friends: []
- };
-
- var query = {
- "interacted":"select fromid from comment where post_id in "+
- "(select post_id from stream where source_id = me() limit 200) limit 25",
- "friend_ids":"select uid2 from friend where uid1 = me()",
- "sympathetic":"select user_id from url_like where user_id in "+
- "(select uid2 from #friend_ids) and strpos(url, 'watchdog.net') > 0",
- "friends":"select name, uid from user where uid in (select uid2 from #friend_ids) "+
- "order by profile_update_time desc"
- };
-
- queryFacebook(query, groups);
-}
-
-function checkPermissions() {
- function proceedSharing() {
+ }
+
+ function postToMeAndFriends() {
+ var domain = location.href.replace(/\?.*/,"");
+ var referralCode = (VK.ref_code === '' ? $.cookie('ref_code') : VK.ref_code);
+ var url = [domain, '?recommend_ref=', referralCode].join('');
+ var message = $('#message-to-friends').val();
+
+ var friends = (function() {
+ return $('.friend_lists input[type="checkbox"]')
+ .filter(function() { return $(this).attr('checked'); })
+ .map(function() { return $(this).val(); });
+ })().toArray().concat(['me']);
+
+ (function send(i) {
+ if(!(uid = friends[i])) { return; }
+ FB.api('/'+uid+'/feed', 'post', {link: url, message: message}, function(res){
+ send(i+1);
+ });
+ })(0);
+
$('#facebookFriendsModal').modal('toggle');
- if(recommended_friends.length === 0) { getFriendsWithAppInstalled(); }
- setupSocialTrackingControllerRequest('recommend');
+ $('#thanksAfterSharingModal').modal('toggle');
}
- function abortSharing() {
+ function findRecommendedFriends(groups) {
+ var tier1 = diff(groups.interacted, groups.sympathetic);
+ var friends_not_involved = diff(groups.friends, groups.sympathetic);
+ var tier2 = diff(friends_not_involved, tier1);
+ var tier3 = diff(groups.friends, tier1.concat(tier2));
+ var suggested = tier1.concat(tier2);
+ remaining = suggested.slice(25);
+ suggested = suggested.slice(0, 25);
+ remaining = remaining.concat(tier3);
+
+ recommended_friends = $.map(suggested, function(friend) {
+ return {uid: friend.uid, name: friend.name, type: 'suggested', preselect: true};
+ });
+
+ $(remaining).each(function(index, friend){
+ recommended_friends.push({uid: friend.uid, name: friend.name, type: 'other', preselect: false});
+ });
+
+ buildMultiFriendSelector();
+ spinner.stop();
+ $('.btn-success').click(postToMeAndFriends);
+ }
+
+ function queryFacebook(query, groups) {
+ FB.api('/fql?q='+encodeURIComponent(JSON.stringify(query)), function(response) {
+ $(response.data).each(function(index, object) {
+ var name = object.name;
+ var resultSet = object.fql_result_set;
+ $(resultSet).each(function(i, friend) {
+ if(!groups[name]) { return; }
+ groups[name].push(friend);
+ });
+ });
+ findRecommendedFriends(groups);
+ });
+ }
+
+ function getFriendsWithAppInstalled() {
+ spinner = createSpinner();
+
+ var groups = {
+ interacted: [],
+ sympathetic: [],
+ friends: []
+ };
+
+ var query = {
+ "interacted":"select fromid from comment where post_id in "+
+ "(select post_id from stream where source_id = me() limit 200) limit 25",
+ "friend_ids":"select uid2 from friend where uid1 = me()",
+ "sympathetic":"select user_id from url_like where user_id in "+
+ "(select uid2 from #friend_ids) and strpos(url, 'watchdog.net') > 0",
+ "friends":"select name, uid from user where uid in (select uid2 from #friend_ids) "+
+ "order by profile_update_time desc"
+ };
+
+ queryFacebook(query, groups);
+ }
+
+ function checkPermissions() {
+ function proceedSharing() {
+ $('#facebookFriendsModal').modal('toggle');
+ if(recommended_friends.length === 0) { getFriendsWithAppInstalled(); }
+ setupSocialTrackingControllerRequest('recommend');
+ }
+
+ function abortSharing() {
+ $('#abortSharingModal').modal('toggle');
+ }
+
+ FB.api('/me/permissions', function(res) {
+ var d = res.data[0];
+ return (d.publish_actions && d.read_stream && d.publish_stream) ?
+ proceedSharing() : abortSharing();
+ });
+ }
+
+ function submitAppRequest() {
+ closeThanksModal();
+ FB.login(function (response) {
+ if (response.authResponse) {
+ checkPermissions();
+ }
+ }, {scope: 'publish_actions, read_stream, publish_stream'});
+ }
+
+ function tryAgain() {
+ $('#the-one-in-the-side').trigger('click');
$('#abortSharingModal').modal('toggle');
}
- FB.api('/me/permissions', function(res) {
- var d = res.data[0];
- return (d.publish_actions && d.read_stream && d.publish_stream) ?
- proceedSharing() : abortSharing();
- });
-}
-
-function closeThanksModal() {
- $("#thanksModal").modal('hide');
-}
-
-function submitAppRequest() {
- closeThanksModal();
- FB.login(function (response) {
- if (response.authResponse) {
- checkPermissions();
- }
- }, {scope: 'publish_actions, read_stream, publish_stream'});
-}
-
-function tryAgain() {
- $('#the-one-in-the-side').trigger('click');
- $('#abortSharingModal').modal('toggle');
-}
-
-function bindFacebookRecommendationButton() {
- $('.fb_recommend_btn').click(submitAppRequest);
- $('#try-again').click(tryAgain);
-}
+ function bind() {
+ $('.fb_recommend_btn').click(submitAppRequest);
+ $('#try-again').click(tryAgain);
+ }
+ return { init: bind };
+})();
View
184 app/assets/javascripts/petition.js
@@ -1,95 +1,5 @@
-function trackFacebookStatus(facebookStatus) {
- VK.facebook_login_status = facebookStatus.status;
-
- $.ajax({
- type: 'post',
- url: VK.social_tracking_url,
- data: {facebook_action: "status", facebook_status: facebookStatus.status}
- });
-}
-
-function initFacebookApp() {
- var appId = $('meta[property="fb:app_id"]').attr('content');
- FB.init({
- appId: appId,
- status: true, // check login status
- cookie: true, // enable cookies to allow the server to access the session
- xfbml: true, // parse XFBML
- frictionless: true // for facebook request dialog
- });
-
- if (FB.getLoginStatus) { FB.getLoginStatus(trackFacebookStatus); }
-}
-
-function socialTrackingParams(facebook_action, action_id, request_id, request_to_ids) {
- var params = { petition_id: VK.petition_id, facebook_action: facebook_action };
-
- if (VK.signature_id !== "") { params.signature_id = VK.signature_id; }
- if (action_id !== "") { params.action_id = action_id; }
- if (request_id !== "") { params.request_id = request_id; }
- if (request_to_ids !== "") { params.friend_ids = request_to_ids; }
-
- return params;
-}
-
-function setupSocialTrackingControllerRequest(facebook_action, action_id, request_id, request_to_ids) {
- $.ajax({
- type: 'post',
- url: VK.social_tracking_url,
- data: socialTrackingParams(facebook_action, action_id, request_id, request_to_ids)
- });
-}
-
-function setupSocialTracking() {
- try {
- if (FB && FB.Event && FB.Event.subscribe) {
- FB.Event.subscribe('edge.create', function (targetUrl) {
- targetUrl = targetUrl + "?f=" + VK.ref_code;
- _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
-
- //Google doesn't export social event data yet, so we have to track social actions as events too
- _gaq.push(['_trackEvent', 'facebook', 'like', targetUrl]);
- setupSocialTrackingControllerRequest('like');
- });
- FB.Event.subscribe('edge.remove', function (targetUrl) {
- _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
- _gaq.push(['_trackEvent', 'facebook', 'unlike', targetUrl]);
- });
- }
- } catch (e) {
- }
-}
-
-function submitFacebookAction() {
- FB.login(function (response) {
- if (response.authResponse) {
- FB.api(
- '/me/watchdognet:sign',
- 'post',
- {
- petition: $('meta[property="og:url"]').attr("content")
- },
- function (response) {
- if (!response || response.error) {
- $('.fb_share_message').text("Please try again.");
- } else {
- setupSocialTrackingControllerRequest('share', response.id, '', '');
- }
- }
- );
- } else {
- $('.fb_share_message').hide();
- }
- }, {scope: 'publish_actions'});
-}
-
-function setupShareFacebookButton() {
- var shareButton = $('.fb_share.btn');
- shareButton.click(function (event) {
- $('.fb_share_message').text("Connecting to Facebook...");
- $('.fb_share_message').show();
- submitFacebookAction();
- });
+function closeThanksModal() {
+ $("#thanksModal").modal('hide');
}
function preventWhitespaceOn(input) {
@@ -131,85 +41,6 @@ function EmailSuggestions() {
};
}
-function bindFacebookPopupButton() {
- function openPopup() {
- var sharer = "https://www.facebook.com/sharer/sharer.php?u=";
- var domain = location.href.replace(/\?.*/,"");
- var referralCode = (VK.ref_code === '' ? $.cookie('ref_code') : VK.ref_code);
-
- var url = sharer + encodeURIComponent(domain + '?share_ref=' + referralCode);
- window.open(url , 'sharer', 'width=626,height=436');
- }
-
- $('.fb_popup_btn').click(function() {
- openPopup();
- setupSocialTrackingControllerRequest('popup');
- //$('.giantbox').hide();
- closeThanksModal();
- });
-}
-
-function bindFacebookDialogButton() {
- function getProperty(propertyName) {
- return encodeURIComponent($('meta[property="' + propertyName + '"]').attr('content'));
- }
-
- function openDialog() {
- var domain = location.href.replace(/\?.*/,"");
- var referralCode = (VK.ref_code === '' ? $.cookie('ref_code') : VK.ref_code);
- var link = [domain, '?fd=', referralCode].join('');
- var dialog = "https://www.facebook.com/dialog/feed?" +
- "app_id=" + getProperty('fb:app_id') + "&" +
- "link=" + encodeURIComponent(link) + "&" +
- "picture=" + getProperty('og:image') + "&" +
- "name=" + getProperty('og:title') + "&" +
- "description=" + getProperty('og:description') + "&" +
- "redirect_uri=http://" + location.host + "/close.html&" +
- "display=popup";
- window.open(dialog , 'dialog', 'width=626,height=436');
- }
-
- $('.fb_dialog_btn').click(function() {
- openDialog();
- setupSocialTrackingControllerRequest('dialog');
- $('.giantbox').hide();
- });
-}
-
-
-function bindFacebookRequestButton() {
- function requestCallbackForSendRequest(response) {
- if(response && response.request) {
- setupSocialTrackingControllerRequest('request', '', response.request, response.to);
- }
- }
-
- function sendRequestViaMultiFriendSelector() {
- FB.ui({method: 'apprequests',
- message: VK.petition_title
- }, requestCallbackForSendRequest);
- }
-
- $('.fb_request_btn').click(sendRequestViaMultiFriendSelector);
-}
-
-function bindFacebookRequestAutofillFriendsButton() {
- function requestCallbackForAutofillFriendsRequest(response) {
- if(response && response.request) {
- setupSocialTrackingControllerRequest('autofill_request', '', response.request, '');
- }
- }
-
- function sendAutofillFriendRequests() {
- FB.ui({method: 'apprequests',
- message: VK.petition_title,
- to: VK.facebook_friend_ids
- }, requestCallbackForAutofillFriendsRequest);
- }
-
- $('.fb_autofill_request_btn').click(sendAutofillFriendRequests);
-}
-
function wasSigned() {
return $("#petition_page").hasClass("was_signed");
}
@@ -263,7 +94,7 @@ function initShowPetition() {
mobileSignErrorHandling();
initMobileSign();
preventWhitespaceOn('#signature_email');
- setupSocialTracking();
+ socialTracking.init();
$('form').on("submit", function (event) {
if (!VK.signing_from_email) {
@@ -296,14 +127,7 @@ function updateCounter() {
function initSharePetition() {
initModalColor();
- initFacebookApp();
- setupSocialTracking();
- setupShareFacebookButton();
- bindFacebookPopupButton();
- bindFacebookDialogButton();
- bindFacebookRequestButton();
- bindFacebookRequestAutofillFriendsButton();
- bindFacebookRecommendationButton();
+ facebook.init();
if ($("#mobile_thanks").length > 0 && wasSigned()) {
$('body').animate({ scrollTop: '-40px' }, '0');
}
View
1  public/close.html
@@ -5,7 +5,6 @@
</head>
<body>
<script>
- window.opener.closeThanksModal();
window.close();
</script>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.