// Define global variables var alertBarSlider; var windowId; var posts = {}; // Remember to declare the page-specific JS file before this one!!! window.addEvent('domready', function() { // Initiate Facebook JS SDK FB.JSON.stringify = function (value) { return JSON.encode(value);}; // If we don't do this (line above), we will get errors in streampublish. This overwrites JS SDK JSON with MooTools JSON // Source: http://forum.developers.facebook.com/viewtopic.php?pid=237121 FB.init({ appId : fbappid, status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); FB.getLoginStatus(function(response) { if (response.status == 'connected') { // Get user info logUser(function(){ // Fire this when done logging in and setting user vars in PHP_session and DB // This function is prepared and fired when we have all data so no timing issues will occur // Add anything to this function that should run in JS immediately if page is loaded // use: window.addEvent('jsReady', function() { }); this is called after the jsReadyPrepare function window.fireEvent('jsReadyPrepare'); }); } else { $('fbApp').loggedin = false; $('fbApp').fbuser = ''; // Fire manually added events (declare what to do in the javascript libs or page code. Can be added unlimited times window.fireEvent('jsReadyPrepare'); } // Disabled for 2 reasons: // 1. A FB bug displays the publish_stream dialog on 50% of iframe height this often shows outside the user screen area // 2. When scrolled down and you click a product you need to scroll up to see it FB.Canvas.setSize({height: 1000}); FB.Canvas.setAutoResize(); // Checks length of content every few milliseconds and edjusts the iframe if needed }); // Don't add stuff here unless you really need to! Want to add anything that runs if Dom is ready, add the jsReady }); function checkCookies() { Cookie.write('cookiesAccepted', '1', {duration: 1, domain: '.soshareit.com'}); if (Cookie.read('cookiesAccepted') == 1) { Cookie.dispose('cookiesAccepted', {domain: '.soshareit.com'}); new Request({url: sid('actions/session.php?action=setAcceptCookies')}).post({'acceptCookies': 1}); $('fbApp').acceptCookies = 1; } else { new Request({url: sid('actions/session.php?action=setAcceptCookies')}).post({'acceptCookies': 0}); $('fbApp').acceptCookies = 0; } } function blockBack(back) { if (! back) { back = 'fbApp'; } if ($('bgBlocker') !== null) { $('bgBlocker').dispose(); } var bgBlocker = new Element('div', { 'id' : 'bgBlocker', 'class' : 'bgBlocker', 'styles' : {'opacity': '0'} }); bgBlocker.setStyle('height',$(back).getSize().y); // Expand background over entire element bgBlocker.inject(back); $('bgBlocker').fade(0.9); } function unblockBack() { $('bgBlocker').fade(0); // Chain dispose sis not work - chucked the dive on start so we will remove it on creating a new one if exists } function makePopup(newId,title,content) { blockBack(); // Hide and lock the background var popup1 = new Element('div', { 'id' : newId, 'class' : 'popupHolder', 'styles' : {'opacity': '0'} } ); var popup2 = new Element('div', { 'class' : 'box', 'styles' : {'width' : '700px'} }); var popup3 = new Element('div', { 'class' : 'header', 'style' : 'cursor: move'}); var popup4 = new Element('div', { 'class' : 'left'}); var popup5 = new Element('div', { 'class' : 'right'}); var popup6 = new Element('div', { 'class' : 'title'}); var popup7 = new Element('div', { 'class' : 'link'}); var popup8 = new Element('div', { 'class' : 'content', 'styles' : {'padding': '5px'}}); popup6.innerHTML = title; popup7.innerHTML = "sluiten"; popup8.innerHTML = content; popup4.inject(popup3); popup5.inject(popup3); popup6.inject(popup3); popup7.inject(popup3); popup3.inject(popup2); popup8.inject(popup2); popup2.inject(popup1); new Drag(popup1, { snap: 0, limit: { 'x':[0,40], 'y':[0,1000] }, handle: popup3, onComplete: function(el) { el.removeClass('dragging'); } }); popup1.inject(document.body); $(newId).fade(1); } function closePopup(popupId) { unblockBack(); var tempFx = new Fx.Tween(popupId, { 'link':'chain', 'duration':'short'}); tempFx.start('opacity', '0').chain(function() { $(popupId).destroy(); }); } function closeAlert() { if (alertBarSlider !== undefined) { alertBarSlider.slideOut().chain(function() { if ($('alertBar') !== null) { $('alertBar').destroy(); } }); } else { if ($('alertBar') !== null) { $('alertBar').destroy(); } } } function showAlert(content) { if ($('alertBar') !== null) { // Old one still exists, restart timeout and replace text clearTimeout($('alertBar').timeout); alertBarSlider.slideOut().chain(function () { $('alertBarTxt').innerHTML = content; alertBarSlider.slideIn(); }); $('alertBar').timeout = setTimeout(closeAlert,15000); return; } var alertBar = new Element('div', { 'id' : 'alertBar', 'class' : 'alertBar' }); new Element('div', { 'class' : 'alertBarP1' }).inject(alertBar); new Element('div', { 'class' : 'alertBarP2' }).inject(alertBar); new Element('div', { 'class' : 'alertBarP3' }).inject(alertBar); new Element('div', { 'class' : 'alertBarP4' }).inject(alertBar); new Element('div', { 'class' : 'alertBarP5' }).inject(alertBar); new Element('div', { 'class' : 'alertBarP6' }).inject(alertBar); var alertBarClose = new Element('div', { 'class' : 'alertBarClose' }); var alertBarTxt = new Element('div', { 'id' : 'alertBarTxt' , 'class' : 'alertBarTxt' }); alertBarClose.addEvent('click', function(e) { e.stop(); closeAlert(); }); alertBarTxt.innerHTML = content; alertBarTxt.inject(alertBar); alertBarClose.inject(alertBar); alertBar.setStyle('display','none'); alertBar.inject('prodBlock','before'); alertBarSlider = new Fx.Slide('alertBar', { 'link':'chain', 'duration':'short'}); alertBarSlider.hide(); $('alertBar').setStyle('display','block'); alertBarSlider.slideIn(); $('alertBar').timeout = setTimeout(closeAlert,15000); } function showLoader(id,obj,where,pos) { // id of the loader (must be unique and different if multiple loaders at same time // obj is the obj where you wish to place the loader in, before or after // where the loader should be in relation to the obj - top, bottom in obj or before, after obj, replace object // pos of the loader - it is absolute and format is: 10,20 => left: 10px; top: 20px; left can also be center if (where == 'replace') { where = 'top'; $(obj).removeEvents(); // Make sure it doesn't respond to anything anymore $(obj).setStyle('background-image','none'); } pos = pos.split(','); var myStyle = 'top: ' + pos[1] + 'px;'; if (pos[0] == 'center') { myStyle += 'left: 50%; margin-left: -8px;'; } else { myStyle += 'left: ' + pos[0] + 'px;'; } var loader = new Element('div', { 'id':id, 'class':'loader', 'style':myStyle } ); loader.close = function () { this.destroy(); }; loader.inject(obj,where); } function detectBuyWindowClose(start) { if (start==undefined) start=0; start++; if (windowId && windowId.closed) { if (start > 60) { // Get product info and publish story new Request({url: sid('actions/getProduct.php?action=feedData&prodid='+buyPid),onSuccess: function(response) { eval(response); if (returned.product_id !== undefined) { var stream = { method: 'stream.publish', message: '', attachment: { name: returned.name, caption: 'Beschikbaar op So Share It', description: (returned.description), href: 'http://apps.facebook.com/soshareit/product/' + returned.product_id, media: [{ type: 'image', src: 'http://www.soshareit.com/' + returned.imageURL, href: 'http://apps.facebook.com/soshareit/product/' + returned.product_id }] }, action_links: [{ text: 'So Share It', href: 'http://apps.facebook.com/soshareit/' }], user_message_prompt: 'Post dit op je Wall' }; FB.ui(stream, function(FBresponse) { if (FBresponse && FBresponse.post_id) { showAlert('Bedankt voor je share...'); } }); } else { showAlert('Kon het product niet plaatsen'); } }}).get(); } } else { setTimeout('detectBuyWindowClose(' + start + ')', 1050); } } function loginBefore(whenLoggedin,error) { // Checks if loggein. if yes it continues to process the functions feeded as var, if not // It asks to login in popup, stores login data to _SESSION on PHP and dbase and executes function if ($('fbApp').loggedin === true) { // Loggedin already - continue whenLoggedin(); } else { // Not loggedin, call login popup FB.login(function(response) { if (response.session) { // User loggedin - log user to dbase and continue when done logUser(function(){ whenLoggedin(); }); } else { // User not loggedin if (! error) { error = 'Log eerst in voordat je deze feature kunt gebruiken'; } showAlert(error); } }); } } function logUser(funcWhenDone) { // Get loggedin user info and store in fbApp, PHP session and Database var query = FB.Data.query("SELECT uid,first_name,last_name,name,username,email FROM user WHERE uid = me()"); query.wait(function(data) { data = data[0]; data.action = 'loggedin'; $('fbApp').loggedin = true; $('fbApp').fbuser = data.uid; // Store loggedin user in dbase & set session vars new Request({url: sid('actions/session.php?action=loggedin'), onSuccess: function(response) { funcWhenDone(); }}).post(data); }); } function needPermissions(perm,doneFunction,errorFunction) { // Check if we have the permission needed // If not existing we will request it if asked or return without executing the function var getPerm = function() { FB.login(function(response) { if (response.session) { if (response.perms == perm) { doneFunction(); } else { if (errorFunction === undefined) { showAlert('Zonder de juiste permissies kun je deze feature niet gebruiken'); } else { errorFunction(); } } } else { if (errorFunction === undefined) { showAlert('Log eerst in voordat je deze feature kunt gebruiken'); } else { errorFunction(); } } }, {perms: perm}); }; if ($('fbApp').loggedin == true) { var query = FB.Data.query('select publish_stream from permissions where uid = me()'); query.wait(function(data) { data = data[0]; if (data[perm] == 1) { doneFunction(); } else { getPerm(); } }); } else { getPerm(); } } function sid(url) { // Some borwsers don't accept 3rd party cookies - in that case we need to add the sid to all links :-( if ($('fbApp') !== null) { if ($('fbApp').acceptCookies !== undefined) { if ($('fbApp').acceptCookies == 1) { return url; } } } if (url.indexOf('?') == -1) { return url + '?PHPSESSID=' + $('fbApp').sessionID; } else { return url + '&PHPSESSID=' + $('fbApp').sessionID; } } function track(pageName) { _gaq.push(['_trackPageview', pageName]) }