Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added spinner, fixed the suggested friends logic for facebook recomme…

…ndation app
  • Loading branch information...
commit 77e68043ce4129a3625ea05453b75337abf615e1 1 parent d16c186
@michdsouza michdsouza authored
View
1  app/assets/javascripts/application.js
@@ -24,6 +24,7 @@
//= require petition_editor
//= require facebook_share_widget/application
//= require chosen.jquery
+//= require spin.min
//= require_tree .
var VK = VK || {};
View
78 app/assets/javascripts/facebook_recommendation.js
@@ -1,3 +1,5 @@
+var spinner;
+
function diff(array1, array2) {
var a1 = $.map(array1, function(item) {return item.uid;});
var a2 = $.map(array2, function(item) {return item.uid;});
@@ -7,12 +9,33 @@ function diff(array1, array2) {
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() {
$(VK.recommended_friends).each(function(index, item) {
- var suggested = item.suggested;
var checked = item.preselect ? 'checked' : '';
var li = $('<li><input type="checkbox" '+checked+' value="'+item.uid+'"/>'+item.name+'</li>');
- var id = suggested ? '#suggested' : '#other';
+ var id = '#' + item.type;
$('.facebook_friend_widget ' + id + ' ul').append(li);
$(id).removeClass('hide');
});
@@ -23,27 +46,44 @@ function findRecommendedFriends(groups) {
var friends_not_involved = diff(groups.friends, groups.friends_involved);
var tier2 = diff(friends_not_involved, tier1);
var tier3 = diff(groups.friends, tier1.concat(tier2));
- console.log("Tier1: ", tier1);
- console.log("Tier2: ", tier2);
- console.log("Tier3: ", tier3);
VK.recommended_friends = [];
- $(tier1).each(function(index, friend){
- VK.recommended_friends.push({uid: friend.uid, name: friend.name, type: 'suggested', preselect: true});
- });
+ var suggested = tier1.concat(tier2);
+ remaining = suggested.slice(25);
+ suggested = suggested.slice(0, 25);
+ remaining = remaining.concat(tier3);
- $(tier2).each(function(index, friend){
- VK.recommended_friends.push({uid: friend.uid, name: friend.name, type: 'suggested', preselect: false});
+ $(suggested).each(function(index, friend){
+ VK.recommended_friends.push({uid: friend.uid, name: friend.name, type: 'suggested', preselect: true});
});
- $(tier3).each(function(index, friend){
+ $(remaining).each(function(index, friend){
VK.recommended_friends.push({uid: friend.uid, name: friend.name, type: 'other', preselect: false});
});
buildMultiFriendSelector();
+ spinner.stop();
+ // $('.btn-success').click(function(event){
+ // alert("blah");
+ // //post on friend's timeline
+ // });
}
-function query_facebook(query, groups) {
+// function postOnFriendsTimeline()
+// {
+// FB.api(
+// '/me/watchdognet:sign',
+// 'post',
+// {
+// petition: $('meta[property="og:url"]').attr("content")
+// },
+// function (response) {
+// console.log(response.id);
+// }
+// );
+// }
+
+function queryFacebook(query, groups) {
FB.api("/fql?q=" + encodeURIComponent(JSON.stringify(query)),
function(response) {
$(response.data).each(function(index, object) {
@@ -71,23 +111,27 @@ function getFriendsWithAppInstalled() {
"friend_ids":"select uid2 from friend where uid1 = me()",
"friends_notifying":"select name, uid from user where uid "+
"in (select sender_id from notification where recipient_id = me()) "+
- "order by profile_update_time desc limit 50",
+ // "order by profile_update_time desc limit 50",
+ "order by profile_update_time desc",
"friends_involved":"select name, uid from user where uid in "+
"(select user_id from url_like where user_id in (select uid2 from #friend_ids) "+
- "and strpos(url, \'watchdog.net\') > 0) order by profile_update_time desc limit 50",
+ // "and strpos(url, 'watchdog.net') > 0) order by profile_update_time desc limit 50",
+ "and strpos(url, 'watchdog.net') > 0) order by profile_update_time desc",
"friends":"select name, uid from user where uid in (select uid2 from #friend_ids) "+
- "order by profile_update_time desc limit 50"
+ // "order by profile_update_time desc limit 50"
+ "order by profile_update_time desc"
};
- query_facebook(query, groups);
+ queryFacebook(query, groups);
}
function submitAppRequest() {
$("#thanksModal").modal('toggle');
FB.login(function (response) {
if (response.authResponse) {
- getFriendsWithAppInstalled();
$('#facebookFriendsModal').modal('toggle');
+ spinner = createSpinner();
+ getFriendsWithAppInstalled();
}
}, {scope: 'publish_actions, manage_notifications'});
}
View
3  app/assets/javascripts/petition.js
@@ -214,7 +214,6 @@ function submitFacebookAction() {
$('.fb_share_message').text("Please try again.");
} else {
setupSocialTrackingControllerRequest('share', response.id, '', '');
- inviteToShareOnTwitter();
}
}
);
@@ -439,7 +438,7 @@ function initSharePetition() {
bindFacebookWidgetButton();
bindFacebookRequestButton();
bindFacebookRequestAutofillFriendsButton();
- //bindFacebookAppRequestButton();
+ // bindFacebookAppRequestButton();
if ($("#mobile_thanks").length > 0 && wasSigned()) {
$('body').animate({ scrollTop: '-40px' }, '0');
}
View
2  app/views/petitions/_facebook_friend_widget.html.haml
@@ -1,5 +1,6 @@
.facebook_friend_widget
%h3 Spread the word by inviting up to 25 friends
+
#suggested.hide
%h4 Suggested Friends
%ul
@@ -10,4 +11,3 @@
- content_for :javascripts do
$('a.close').click(function(){$('#facebookFriendsModal').hide();});
- / $(document).ready(showRecommendedFriends);
View
2  vendor/assets/javascripts/spin.min.js
@@ -0,0 +1,2 @@
+//fgnass.github.com/spin.js#v1.2.6
+!function(e,t,n){function o(e,n){var r=t.createElement(e||"div"),i;for(i in n)r[i]=n[i];return r}function u(e){for(var t=1,n=arguments.length;t<n;t++)e.appendChild(arguments[t]);return e}function f(e,t,n,r){var o=["opacity",t,~~(e*100),n,r].join("-"),u=.01+n/r*100,f=Math.max(1-(1-e)/t*(100-u),e),l=s.substring(0,s.indexOf("Animation")).toLowerCase(),c=l&&"-"+l+"-"||"";return i[o]||(a.insertRule("@"+c+"keyframes "+o+"{"+"0%{opacity:"+f+"}"+u+"%{opacity:"+e+"}"+(u+.01)+"%{opacity:1}"+(u+t)%100+"%{opacity:"+e+"}"+"100%{opacity:"+f+"}"+"}",a.cssRules.length),i[o]=1),o}function l(e,t){var i=e.style,s,o;if(i[t]!==n)return t;t=t.charAt(0).toUpperCase()+t.slice(1);for(o=0;o<r.length;o++){s=r[o]+t;if(i[s]!==n)return s}}function c(e,t){for(var n in t)e.style[l(e,n)||n]=t[n];return e}function h(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)e[i]===n&&(e[i]=r[i])}return e}function p(e){var t={x:e.offsetLeft,y:e.offsetTop};while(e=e.offsetParent)t.x+=e.offsetLeft,t.y+=e.offsetTop;return t}var r=["webkit","Moz","ms","O"],i={},s,a=function(){var e=o("style",{type:"text/css"});return u(t.getElementsByTagName("head")[0],e),e.sheet||e.styleSheet}(),d={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",speed:1,trail:100,opacity:.25,fps:20,zIndex:2e9,className:"spinner",top:"auto",left:"auto"},v=function m(e){if(!this.spin)return new m(e);this.opts=h(e||{},m.defaults,d)};v.defaults={},h(v.prototype,{spin:function(e){this.stop();var t=this,n=t.opts,r=t.el=c(o(0,{className:n.className}),{position:"relative",width:0,zIndex:n.zIndex}),i=n.radius+n.length+n.width,u,a;e&&(e.insertBefore(r,e.firstChild||null),a=p(e),u=p(r),c(r,{left:(n.left=="auto"?a.x-u.x+(e.offsetWidth>>1):parseInt(n.left,10)+i)+"px",top:(n.top=="auto"?a.y-u.y+(e.offsetHeight>>1):parseInt(n.top,10)+i)+"px"})),r.setAttribute("aria-role","progressbar"),t.lines(r,t.opts);if(!s){var f=0,l=n.fps,h=l/n.speed,d=(1-n.opacity)/(h*n.trail/100),v=h/n.lines;(function m(){f++;for(var e=n.lines;e;e--){var i=Math.max(1-(f+e*v)%h*d,n.opacity);t.opacity(r,n.lines-e,i,n)}t.timeout=t.el&&setTimeout(m,~~(1e3/l))})()}return t},stop:function(){var e=this.el;return e&&(clearTimeout(this.timeout),e.parentNode&&e.parentNode.removeChild(e),this.el=n),this},lines:function(e,t){function i(e,r){return c(o(),{position:"absolute",width:t.length+t.width+"px",height:t.width+"px",background:e,boxShadow:r,transformOrigin:"left",transform:"rotate("+~~(360/t.lines*n+t.rotate)+"deg) translate("+t.radius+"px"+",0)",borderRadius:(t.corners*t.width>>1)+"px"})}var n=0,r;for(;n<t.lines;n++)r=c(o(),{position:"absolute",top:1+~(t.width/2)+"px",transform:t.hwaccel?"translate3d(0,0,0)":"",opacity:t.opacity,animation:s&&f(t.opacity,t.trail,n,t.lines)+" "+1/t.speed+"s linear infinite"}),t.shadow&&u(r,c(i("#000","0 0 4px #000"),{top:"2px"})),u(e,u(r,i(t.color,"0 0 1px rgba(0,0,0,.1)")));return e},opacity:function(e,t,n){t<e.childNodes.length&&(e.childNodes[t].style.opacity=n)}}),function(){function e(e,t){return o("<"+e+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',t)}var t=c(o("group"),{behavior:"url(#default#VML)"});!l(t,"transform")&&t.adj?(a.addRule(".spin-vml","behavior:url(#default#VML)"),v.prototype.lines=function(t,n){function s(){return c(e("group",{coordsize:i+" "+i,coordorigin:-r+" "+ -r}),{width:i,height:i})}function l(t,i,o){u(a,u(c(s(),{rotation:360/n.lines*t+"deg",left:~~i}),u(c(e("roundrect",{arcsize:n.corners}),{width:r,height:n.width,left:n.radius,top:-n.width>>1,filter:o}),e("fill",{color:n.color,opacity:n.opacity}),e("stroke",{opacity:0}))))}var r=n.length+n.width,i=2*r,o=-(n.width+n.length)*2+"px",a=c(s(),{position:"absolute",top:o,left:o}),f;if(n.shadow)for(f=1;f<=n.lines;f++)l(f,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(f=1;f<=n.lines;f++)l(f);return u(t,a)},v.prototype.opacity=function(e,t,n,r){var i=e.firstChild;r=r.shadow&&r.lines||0,i&&t+r<i.childNodes.length&&(i=i.childNodes[t+r],i=i&&i.firstChild,i=i&&i.firstChild,i&&(i.opacity=n))}):s=l(t,"animation")}(),typeof define=="function"&&define.amd?define(function(){return v}):e.Spinner=v}(window,document);
Please sign in to comment.
Something went wrong with that request. Please try again.