1var fbState = 'unknown'; 2 3// <editor-fold defaultstate="collapsed" desc="PRIVATE"> 4 5function GetURLParameter(sParam) { 6 var sPageURL = window.location.search.substring(1); 7 var sURLVariables = sPageURL.split('&'); 8 for (var i = 0; i < sURLVariables.length; i++) { 9 var sParameterName = sURLVariables[i].split('='); 10 if (sParameterName[0] === sParam) { 11 return sParameterName[1]; 12 } 13 } 14} 15 16function fbLoginState(callback) { 17 if (fbState != 'connected') { 18 FB.login(function (response) { 19 if (response.authResponse) { 20 fbState = response.status; 21 callback(); 22 } 23 }, {scope: 'email,user_friends,public_profile'}); 24 } else { 25 callback(); 26 } 27} 28 29// </editor-fold> 30 31// <editor-fold defaultstate="collapsed" desc="PUBLIC"> 32 33function fbConnect(btn) { 34 fbLoginState(function () { 35 FB.api('/me?fields=email,first_name,last_name,locale', function (user) { 36 console.log(user); 37 console.log(!user.error); 38 if (user && !user.error) { 39 $.ajax({ 40 url: baseUrl + '/facebook/connect', 41 type: "POST", 42 dataType: 'json', 43 data: { 44 facebook_id: user.id, 45 email: user.email, 46 firstname: user.first_name, 47 lastname: user.last_name, 48 // birthday: user.birthday, 49 // language: (user.locale).substring(0, 2), 50 // country: ((user.locale).substring(3, 5)).toLowerCase(), 51 timezone: $('#Profile_timezone').val(), 52 aff: GetURLParameter('aff'), 53 rf: GetURLParameter('rf'), 54 in: GetURLParameter('in'), 55 to: GetURLParameter('to'), 56 lp: GetURLParameter('lp') 57 }, 58 success: function (response) { 59 if (response.type === 'error') { 60 $(btn).html($(btn).attr(response.status)); 61 setTimeout(function () { 62 $(btn).html($(btn).attr('reset')); 63 }, 3000); 64 return; 65 } 66 var redirect = '/dashboard/index'; 67 if (response.type === 'registration' && response.status === 'completed' || response.type === 'login' && response.firsttime === 'yes') { 68 redirect = '/welcome/index'; 69 } 70 window.location.replace(baseUrl + redirect); 71 } 72 }); 73 } 74 }, {scope: 'email,first_name,last_name,locale'}); 75 }); 76} 77 78function fbUpdate(callback) { 79 FB.api('/me?fields=email,first_name,last_name,locale', function (user) { 80 if (user && !user.error) { 81 $.ajax({ 82 url: baseUrl + '/facebook/update', 83 type: "POST", 84 dataType: 'json', 85 data: { 86 facebook_id: user.id, 87 email: user.email, 88 firstname: user.first_name, 89 lastname: user.last_name, 90 // birthday: user.birthday, 91 // language: (user.locale).substring(0, 2), 92 // country: ((user.locale).substring(3, 5)).toLowerCase(), 93 timezone: $('#Profile_timezone').val(), 94 aff: GetURLParameter('aff'), 95 rf: GetURLParameter('rf'), 96 lp: GetURLParameter('lp') 97 }, 98 success: function (response) { 99 callback(response); 100 } 101 }); 102 } 103 }); 104} 105 106function fbSoundcoins(btn) { 107 fbLoginState(function () { 108 fbUpdate(function (response) { 109 if (response.status === 'saved') {
110 //fbPicture(); 111 $(btn).html($(btn).attr('success')); 112 setTimeout(function () { 113 $(btn).hide(); 114 $(btn).next('.confirmed').show(); 115 }, 3000); 116 } else if (response.status === 'exist') { 117 $(btn).html($(btn).attr('exist')); 118 setTimeout(function () { 119 $(btn).html($(btn).attr('reset')); 120 }, 3000); 121 } else { 122 $(btn).html($(btn).attr('error')); 123 setTimeout(function () { 124 $(btn).html($(btn).attr('reset')); 125 }, 3000); 126 } 127 }); 128 }); 129} 130 131function fbShare(btn, description) { 132 fbLoginState(function () { 133 fbUpdate(function (response) { 134 if (response.status === 'exist') { 135 $(btn).html($(btn).attr('exist')); 136 setTimeout(function () { 137 $(btn).html($(btn).attr('reset')); 138 }, 3000); 139 return; 140 } 141 //fbPicture(); 142 FB.ui({ 143 method: 'feed', 144 name: $(btn).attr('fbname'), 145 caption: $(btn).attr('fbcaption'), 146 description: $(btn).attr('fbdescription'), 147 picture: $(btn).attr('fbpicture'), 148 link: $(btn).attr('fblink') 149 }, function (response) { 150 if (isset(response.error_code)) { 151 $(btn).html($(btn).attr('error')); 152 setTimeout(function () { 153 $(btn).html($(btn).attr('reset')); 154 }, 3000); 155 } else { 156 $(btn).html($(btn).attr('success')); 157 setTimeout(function () { 158 $(btn).hide(); 159 $(btn).next('.confirmed').show(); 160 }, 3000); 161 } 162 }); 163 }); 164 }); 165} 166 167function fbShareSimple(btn, description) { 168 fbLoginState(function () { 169 FB.ui({ 170 method: 'feed', 171 name: $(btn).attr('fbname'), 172 caption: $(btn).attr('fbcaption'), 173 description: $(btn).attr('fbdescription'), 174 picture: $(btn).attr('fbpicture'), 175 link: $(btn).attr('fblink') 176 }, function (response) { 177 if (response && response.post_id) { 178 $(btn).html($(btn).attr('success')); 179 setTimeout(function () { 180 $(btn).html($(btn).attr('reset')).prop('disabled', true).addClass('disabled'); 181 }, 3000); 182 } else { 183 $(btn).html($(btn).attr('error')); 184 setTimeout(function () { 185 $(btn).html($(btn).attr('reset')); 186 }, 3000); 187 } 188 }); 189 }); 190} 191 192function fbShareCurrentUrl() { 193 FB.ui({ 194 method: 'share', 195 href: window.location.href, 196 }, function (response) { 197 console.log(response); 198 }); 199} 200 201function fbInvite(btn, description) { 202 $('#facebookFriendsModal').modal('hide'); 203 fbLoginState(function () { 204 fbUpdate(function (response) { 205 if (response.status === 'exist') { 206 $(btn).html($(btn).attr('exist')); 207 setTimeout(function () { 208 $(btn).html($(btn).attr('reset')); 209 }, 3000); 210 return; 211 } 212 //fbPicture(); 213 FB.ui({ 214 method: 'send', 215 link: $(btn).attr('fblink') 216 }, function (response) { 217 // TODO 218 }); 219 }); 220 }); 221} 222 223function fbWelcome() { 224 fbLoginState(function () { 225 fbUpdate(function (response) { 226 //fbPicture(); 227 }); 228 }); 229} 230 231function findFriends() { 232 var ele = $('#fbFriendsFinder'); 233 fbLoginState(function () { 234 fbUpdate(function () { 235 //fbPicture(); 236 ele.html(ele.attr('loading')); 237 $('#facebookFriendsModal').modal('show'); 238 getFriendsList(ele); 239 }); 240 }); 241} 242 243function showFacebookFriendsIfConnected() { 244 var ele = $('#fbFriendsFinder'); 245 if (fbState == 'connected') { 246 ele.html(ele.attr('loading')); 247 getFriendsList(ele); 248 } else { 249 $('#connectBtn').show(); 250 } 251} 252 253function getFriendsList(ele) { 254 FB.api('/me/friends?fields=email,first_name,last_name,locale', function (response) { 255 if (response && !response.error) { 256 if (response.data.length !== 0) { 257 $.ajax({ 258 url: baseUrl + '/dashboard/findFriends', 259 type: "POST", 260 data: {friends: response.data}, 261 success: function (data) { 262 if (data == '') { 263 ele.html(ele.attr('empty')); 264 } else { 265 ele.html(data); 266 } 267 } 268 }); 269 } else { 270 ele.html(ele.attr('empty')); 271 } 272 } else { 273 ele.html(ele.attr('error')); 274 } 275 }); 276} 277 278// </editor-fold> 279 280$(function () { 281 $.ajaxSetup({cache: true}); 282 $.getScript('https://connect.facebook.net/en_US/sdk.js', function () { 283 FB.init({ 284 appId: facebookAppId, 285 version: 'v3.3', 286 cookie: true 287 }); 288 FB.Canvas.setSize({width: 900, height: 480}); 289 FB.getLoginStatus(function (response) { 290 fbState = response.status; 291 }, true); 292 }); 293 } 294);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.