1/** 2 * @package JFBConnect 3 * @copyright (C) 2009-2013 by Source Coast - All rights reserved 4 * @website http://www.sourcecoast.com/ 5 * @website http://www.sourcecoast.com/jfbconnect/ 6 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 7 */ 8 9/** 10 * Ensure global _gaq Google Anlaytics queue has be initialized. 11 * @type {Array} 12 */ 13var _gaq = _gaq || []; 14 15var jfbc = { 16 base:null, 17 return_url:null, 18 login:{ 19 show_modal:false, 20 scope:null, 21 logout_facebook:false, 22 login_started:false, // Prevents multiple concurrent login attempts, mainly caused by the auto-login feature enabled 23 // login_custom is used for non XFBML login requests (custom image buttons) 24 login_custom:function () 25 { 26 FB.login(function (response) 27 { 28 jfbc.login.on_login(); 29 }, { 30 scope:jfbc.login.scope 31 }); 32 }, 33 // Action to perform after authentication on FB has occurred 34 on_login:function () 35 { 36 if (!jfbc.login.login_started) 37 { 38 jfbc.login.login_started = true; 39 FB.getLoginStatus(function (response) 40 { 41 if (response.status === 'connected') 42 { 43 // Check that permissions have been granted properly: 44 FB.api('/me/permissions', function (response) 45 { 46 /* var requiredScope = jfbc.login.scope.split(','); 47 if (requiredScope.length == 0) 48 return; // We always want at least email, so something is wrong in this case*/ 49 50 if (!response || response.error || response.data[0].length == 0) 51 return; // Again, should at least get something as well as the email permission returned 52 53 /* for (var i = 0; i < requiredScope.length; i++) 54 { 55 var scope = requiredScope[i]; 56 if (response.data[0][scope] != 1) 57 return; // Permission wasn't granted. Need to click 58 }*/ 59 // check just email perm as some other perms may be denied by the user, but still should be able to login.. 60 if (response.data[0]['email'] != 1) 61 return; 62 63 // Check if the publish_actions scope is something that should be requested, and check to make sure it's enabled 64 // This was added in JFBC v4.3, so many sites/users who logged in before this release won't have this perm. 65 if (jfbc.login.auto && jfbc.login.scope.indexOf('publish_actions') !== -1) 66 { 67 if (response.data[0]['publish_actions'] != 1) 68 { 69 //console.log("Auto-login failed. publish_actions was requested, but not granted"); 70 return; 71 } 72 } 73 74 if (jfbc.login.show_modal == '1') 75 SqueezeBox.fromElement('jfbcLoginModal', {handler:'adopt', size:{x:500, y:50}}); 76 var d = new Date(); 77 self.location = jfbc.base + 'index.php?option=com_jfbconnect&task=loginFacebookUser&return=' + jfbc.return_url + '&cb=' + d.getTime(); 78 }); 79 80 } 81 }); 82 } 83 jfbc.login.login_started = false; 84 }, 85 86 // Deprecated, used on_login() 87 login_button_click:function () 88 { 89 jfbc.login.on_login(); 90 }, 91 92 logout_button_click:function () 93 { 94 if (jfbc.login.logout_facebook) 95 { 96 FB.getLoginStatus(function (response) 97 { 98 if (response.status === 'connected') 99 { 100 FB.logout(function (response) 101 { 102 jfbc.login.redirect_to_logout(); 103 }); 104 } 105 else 106 { 107 jfbc.login.redirect_to_logout(); 108 } 109 }); 110 } 111 else 112 { 113 jfbc.login.redirect_to_logout(); 114 } 115 }, 116 117 redirect_to_logout:function () 118 { 119 self.location = jfbc.base + 'index.php?option=com_jfbconnect&task=logout&return=' + jfbc.return_url; 120 } 121 }, 122 123 register:{ 124 checkUsernameAvailable:function () 125 { 126 var testName = $('username').value; 127 if (testName != '') 128 var myXHR = new XHR({ 129 method:'get', 130 onSuccess:jfbc.register.showUsernameSuccess 131 }).send('index.php', 'option=com_jfbconnect&view=loginregister&task=checkUsernameAvailable&username=' + testName); 132 }, 133 134 checkPassword:function () 135 { 136 var testPassword = $('password').value; 137 var passwordSuccessElement = $('jfbcPasswordSuccess'); 138 var val = ""; 139 if (testPassword.length < 6) 140 val = '<img src="' + jfbc.base + 'images/cancel_f2.png" width="20" height="20">' + jfbcPasswordInvalid; 141 passwordSuccessElement.innerHTML = val; 142 }, 143 144 checkPassword2:function () 145 { 146 var testPassword = $('password').value; 147 var testPassword2 = $('password2').value; 148 var passwordSuccessElement = $('jfbcPassword2Success'); 149 var val = ""; 150 if (testPassword != testPassword2) 151 val = '<img src="' + jfbc.base + 'images/cancel_f2.png" width="20" height="20">' + jfbcPassword2NoMatch; 152 passwordSuccessElement.innerHTML = val; 153 }, 154 155 showUsernameSuccess:function (req) 156 { 157 var usernameSuccessElement = $('jfbcUsernameSuccess'); 158 if (req == 1) 159 { 160 usernameSuccessElement.innerHTML = '<img src="' + jfbc.base + 'images/apply_f2.png" width="20" height="20">' + jfbcUsernameIsAvailable; 161 } 162 else 163 { 164 usernameSuccessElement.innerHTML = '<img src="' + jfbc.base + 'images/cancel_f2.png" width="20" height="20">' + jfbcUsernameIsInUse; 165 } 166 167 }, 168 169 checkEmailAvailable:function () 170 { 171 var testEmail = $('email').value; 172 if (testEmail != '' && jfbc.register.isEmail(testEmail)) 173 var myXHR = new XHR({ 174 method:'get', 175 onSuccess:jfbc.register.showEmailSuccess 176 }).send('index.php', 'option=com_jfbconnect&view=loginregister&task=checkEmailAvailable&email=' + testEmail); 177 }, 178 179 showEmailSuccess:function (req) 180 { 181 emailSuccessElement = document.getElementById('jfbcEmailSuccess'); 182 if (req == 1) 183 { 184 emailSuccessElement.innerHTML = '<img src="' + jfbc.base + 'images/apply_f2.png" width="20" height="20">' + jfbcEmailIsAvailable; 185 } 186 else 187 { 188 emailSuccessElement.innerHTML = '<img src="' + jfbc.base + 'images/cancel_f2.png" width="20" height="20">' + jfbcEmailIsInUse; 189 } 190 }, 191 192 isEmail:function (text) 193 { 194 var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$"; 195 var regex = new RegExp(pattern); 196 return regex.test(text); 197 } 198 }, 199 200 social:{ 201 comment:{ 202 create:function (response) 203 { 204 var url = 'option=com_jfbconnect&controller=social&task=commentCreate&href=' + encodeURIComponent(escape(response.href)) + '&commentID=' + response.commentID + '&title=' + document.title; 205 jfbc.ajax(url, null); 206 } 207 }, 208 like:{ 209 create:function (response) 210 { 211 var url = 'option=com_jfbconnect&controller=social&task=likeCreate&href=' + encodeURIComponent(escape(response)) + '&title=' + document.title; 212 jfbc.ajax(url, null); 213 } 214 }, 215 /** 216 * Tracks Facebook likes, unlikes and sends by suscribing to the Facebook 217 * JSAPI event model. Note: This will not track facebook buttons using the 218 * iFrame method. 219 */ 220 googleAnalytics:{ 221 trackFacebook:function () 222 { 223 var opt_pageUrl = window.location; 224 try 225 { 226 if (FB && FB.Event && FB.Event.subscribe) 227 { 228 FB.Event.subscribe('edge.create', function (targetUrl) 229 {
230 _gaq.push(['_trackSocial', 'facebook', 'like', 231 targetUrl, opt_pageUrl]); 232 }); 233 FB.Event.subscribe('edge.remove', function (targetUrl) 234 { 235 _gaq.push(['_trackSocial', 'facebook', 'unlike', 236 targetUrl, opt_pageUrl]); 237 }); 238 FB.Event.subscribe('message.send', function (targetUrl) 239 { 240 _gaq.push(['_trackSocial', 'facebook', 'send', 241 targetUrl, opt_pageUrl]); 242 }); 243 FB.Event.subscribe('comment.create', function (targetUrl) 244 { 245 _gaq.push(['_trackSocial', 'facebook', 'comment', 246 targetUrl, opt_pageUrl]); 247 }); 248 FB.Event.subscribe('comment.remove', function (targetUrl) 249 { 250 _gaq.push(['_trackSocial', 'facebook', 'uncomment', 251 targetUrl, opt_pageUrl]); 252 }); 253 } 254 } 255 catch (e) 256 { 257 } 258 } 259 }, 260 261 // Not published yet. Need to figure out the best way to incorporate this into pages 262 feedPost:function (title, caption, description, url, picture) 263 { 264// javascript:jfbc.social.feedPost('SourceCoast JE', 'My caption', 'Great extensions!', 'http://www.sourcecoast.com/', 'https://www.sourcecoast.com/images/stories/extensions/jfbconnect/home_jfbconn.png'); 265 var obj = { 266 method:'feed', 267 link:url, 268 picture:picture, 269 name:title, // page title? 270 caption:caption, 271 description:description 272 }; 273 274 function callback(response) 275 { 276 } 277 278 FB.ui(obj, callback); 279 } 280 }, 281 282 canvas:{ 283 checkFrame:function () 284 { 285 if (top == window) 286 { // crude check for any frame 287 if (window.location.search == "") 288 top.location.href = window.location.href + '?jfbcCanvasBreakout=1'; 289 else 290 top.location.href = window.location.href + '&jfbcCanvasBreakout=1'; 291 } 292 } 293 }, 294 295 request:{ 296 currentId:null, 297 popup:function (jfbcReqId) 298 { 299 jfbc.request.currentId = jfbcReqId; 300 data = jfbcRequests[jfbcReqId]; 301 FB.ui({method:'apprequests', display:'popup', 302 message:data.message, 303 title:data.title, 304 data:jfbcReqId 305 }, jfbc.request.fbCallback); 306 307 }, 308 309 fbCallback:function (response) 310 { 311 if (response != null) 312 { 313 var rId = response.request; 314 var to = response.to; 315 316 var toQuery = ""; 317 for (var i = 0; i < to.length; i++) 318 toQuery += "&to[]=" + to[i]; 319 320 var query = 'option=com_jfbconnect&controller=request&task=requestSent&requestId=' + rId + toQuery + '&jfbcId=' + jfbc.request.currentId; 321 jfbc.ajax(query, jfbc.request.redirectToThanks); 322 } 323 }, 324 325 redirectToThanks:function () 326 { 327 data = jfbcRequests[jfbc.request.currentId]; 328 if (data.thanksUrl != "" && (window.location.href != data.thanksUrl)) 329 window.location.href = data.thanksUrl; 330 } 331 }, 332 333 opengraph:{ 334 triggerAction:function (action, href) 335 { 336 var url = 'option=com_jfbconnect&controller=opengraph&task=ajaxAction&action=' + action + '&href=' + encodeURIComponent(href); 337 jfbc.ajax(url, jfbc.opengraph.actionPopup); 338 }, 339 actionPopup:function (message) 340 { 341 if (message != '') 342 { 343 var newDiv = document.createElement('div'); 344 newDiv.innerHTML = '<div id="ogActionPopup">'+message+'</div>'; 345 document.body.appendChild(newDiv); 346 $('ogActionPopup').fade('in'); 347 setTimeout("$('ogActionPopup').fade('out')", 15000); 348 } 349 } 350 }, 351 352 ajax:function (url, callback) 353 { 354 var mooVer = MooTools.version.split("."); 355 if (mooVer[1] == '2' || mooVer[1] == '3' || mooVer[1] == '4') // Joomla 1.5 w/mtupgrade or J1.6+ 356 {
357 var req = new Request({ 358 method:'get', 359 url:jfbc.base + 'index.php?' + url, 360 onSuccess:callback 361 }).send(); 362 } 363 else 364 { 365 var myXHR = new XHR({ 366 method:'get', 367 onSuccess:callback 368 }).send(jfbc.base + 'index.php', url); 369 } 370 } 371};
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.