Created
March 12, 2012 15:34
-
-
Save agustinhaller/2022685 to your computer and use it in GitHub Desktop.
testing gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@include "https://chkin.at/static/css/style.css" | |
@include "https://chkin.at/static/js/jquery-ui-1.8.17.custom.min.js" | |
@include "https://chkin.at/static/js/geoplugin.js" | |
//window.onerror = function(){return true;}; | |
var sites_list = [], | |
excluded_list = [], | |
site_id = null, | |
$ = $jquery, | |
BASE_URL = "http://dev.chkin.at", | |
STATIC_URL = "http://dev.chkin.at/static"; | |
// -- AUX FUNCTIONS -- | |
function loadGeoData() | |
{ | |
var myGeoData = appAPI.db.get('user_geo'); | |
if(myGeoData == null) | |
{ //that means we don't have the data locally in our db | |
appAPI.geoplugin( | |
{ callback: function(myData) { | |
//save the result only for the next 7 days | |
appAPI.db.set('user_geo', myData, appAPI.time.daysFromNow(7)); | |
//and show it to the user | |
console.log("No existing geo data, getting it ..."); | |
// Save data in the server | |
$.getJSON( | |
BASE_URL+"/save_geo.php", | |
{ | |
city: myData.geoplugin_city, | |
country: myData.geoplugin_countryName, | |
latitude: myData.geoplugin_latitude, | |
longitude: myData.geoplugin_longitude, | |
currency: myData.geoplugin_currencyCode | |
}, | |
function(data){ | |
console.log("SAVING GEO DATA... -> ",data.response); | |
if(data.response == "OK") | |
{ | |
appAPI.db.set('geo_data_setted', true); | |
} | |
} | |
); | |
}, | |
currency: "EUR" //optional (default value is "USD") | |
}); | |
} | |
else | |
{ | |
//we have the data locally in our db so we don't need to fetch it remotely | |
console.log("Retriving existing geo data ..."); | |
// Check if we have already set the geo data in the server | |
var geo_data_setted = appAPI.db.get('geo_data_setted'); | |
// If we dont, then try to set it again | |
if(geo_data_setted==null) | |
{ | |
// Save data in the server | |
$.getJSON( | |
BASE_URL+"/save_geo.php", | |
{ | |
city: myGeoData.geoplugin_city, | |
country: myGeoData.geoplugin_countryName, | |
latitude: myGeoData.geoplugin_latitude, | |
longitude: myGeoData.geoplugin_longitude, | |
currency: myGeoData.geoplugin_currencyCode | |
}, | |
function(data){ | |
console.log("SAVING GEO DATA... -> ",data.response); | |
if(data.response == "OK") | |
{ | |
appAPI.db.set('geo_data_setted', true); | |
} | |
} | |
); | |
} | |
} | |
} | |
function getBaseUrl() | |
{ | |
url = document.location.href; | |
tmp = url.split("/"); | |
url_base_tmp = tmp[2].split("."); | |
if(url_base_tmp[url_base_tmp.length-1].length>2) | |
{ | |
url_base = url_base_tmp[url_base_tmp.length-2] + "." + url_base_tmp[url_base_tmp.length-1]; | |
} | |
else | |
{ | |
url_base = url_base_tmp[url_base_tmp.length-3] + "." + url_base_tmp[url_base_tmp.length-2] + "." + url_base_tmp[url_base_tmp.length-1]; | |
} | |
return url_base.replace("www",""); | |
} | |
function hasCheckedIn(disabled_sites_list) | |
{ | |
// disabled_sites_list reffers to the list where the user has recently checked in, | |
// so we should hide them unitl "hours to check in gain" | |
//Here we must look at the array of sites and check if the current site is on the list. | |
var is_excluded = false, | |
tmp_url = document.location.href.replace("http://","").replace("https://","").split("/"), | |
this_base_url = tmp_url[0], | |
possible_sites = [], | |
this_base_url_clean = this_base_url.replace("www.",""); | |
console.log(disabled_sites_list, "CHECKED IN SITES - hasCheckedIn()"); | |
var base_url = getBaseUrl(); | |
console.log(base_url, "getBaseUrl - hasCheckedIn()"); | |
console.log(this_base_url_clean, "clean url - hasCheckedIn()"); | |
//CHECK IF IS EXCLUDED | |
if(disabled_sites_list!=undefined && disabled_sites_list!=null && disabled_sites_list.length>0){ | |
for(var i=0;i<disabled_sites_list.length;i++){ | |
if(this_base_url_clean == disabled_sites_list[i].domain_base){ | |
is_excluded = true; | |
} | |
} | |
} | |
return is_excluded; | |
} | |
function getCurrentSiteId(sites_list,excluded_list) | |
{ | |
//Here we must look at the array of sites and check if the current site is on the list. | |
var tmp_url = document.location.href.replace("http://","").replace("https://","").split("/"); | |
var this_base_url = tmp_url[0]; | |
var possible_sites = []; | |
//CHECK IF IS EXCLUDED | |
this_base_url_clean = this_base_url.replace("www.",""); | |
if(excluded_list!=undefined && excluded_list!=null && excluded_list.length>0){ | |
for(var i=0;i<excluded_list.length;i++){ | |
if(this_base_url_clean == excluded_list[i].domain_base){ | |
return null; | |
} | |
} | |
} | |
//COLLECT ALL THE POSSIBILITES | |
if(sites_list!=undefined && sites_list!=null && sites_list.length>0){ | |
for(var i=0;i<sites_list.length; i++) | |
{ | |
if(this_base_url.search(sites_list[i].domain_base)!=-1) | |
{ | |
possible_sites.push(sites_list[i]); | |
} | |
} | |
} | |
if(possible_sites.length>1){ | |
for(var i=0;i<possible_sites.length;i++){ | |
if(this_base_url_clean == possible_sites[i].domain_base){ | |
return possible_sites[i].id; | |
} | |
} | |
}else if(possible_sites.length>0){ | |
return possible_sites[0].id; | |
} | |
return null; | |
} | |
function isSiteUnlocked(all_sites_list) | |
{ | |
//Here we must look at the array of sites and check if the current site is on the list. | |
var tmp_url = document.location.href.replace("http://","").replace("https://","").split("/"), | |
this_base_url = tmp_url[0], | |
this_base_url_clean = this_base_url.replace("www.",""), | |
all_sites_length = all_sites_list.length; | |
//CHECK IF IT IS ON THE LIST | |
if(all_sites_list!=undefined && all_sites_list!=null && all_sites_length>0) | |
{ | |
for(var i=0;i<all_sites_length;i++) | |
{ | |
if(this_base_url_clean == all_sites_list[i].domain_base) | |
{ | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
function isExcluded() | |
{ | |
if(appAPI.db.get("sites_excluded")!=null) | |
{ | |
sites_excluded = appAPI.db.get("sites_excluded"); | |
console.log(sites_excluded, "EXCLUDED SITES IN APP DB - isExcluded()"); | |
var base_url = getBaseUrl(); | |
console.log(base_url, "getBaseUrl - isExcluded()"); | |
for(var i=0;i<sites_excluded.length;i++) | |
{ | |
if(sites_excluded[i].url == getBaseUrl()) | |
{ | |
console.log("This site is excluded!"); | |
return true; | |
} | |
} | |
} | |
if(appAPI.db.get("sites_excluded_forever")!=null) | |
{ | |
sites_excluded_forever = appAPI.db.get("sites_excluded_forever"); | |
for(var i=0;i<sites_excluded_forever.length;i++) | |
{ | |
if(sites_excluded_forever[i].url == getBaseUrl()) | |
{ | |
console.log("This site is excluded!"); | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
// -- END AUX FUNCTIONS -- | |
// -- MAIN SCRIPT -- | |
$(document).ready(function(){ | |
// Append a div in order to serve as a flag to detect if the app is installed or not | |
$('body').append('<div id="crossrider-app-installed"></div>'); | |
var settings = appAPI.db.get('is_disabled'); | |
console.log(settings); | |
if(document.location.href.search(BASE_URL)!=-1 || document.location.href.search(BASE_URL.replace("http:","https:"))!=-1){ | |
console.log("DISABLED 24hs : ",appAPI.db.get("exclude_all_sites")); | |
console.log("DISABLED ALWAYS: ",appAPI.db.get("is_disabled")); | |
if(settings!=null && settings!=undefined) | |
{ | |
if(appAPI.db.get("exclude_all_sites").enabled==true) | |
{ | |
$("#web-chkinat-hide_for_all_sites").attr('checked',true); | |
} | |
if(appAPI.db.get("is_disabled")==true) | |
{ | |
$("#web-chkinat-disable_app").attr('checked',true); | |
} | |
} | |
$("#web-chkinat-hide_for_all_sites").click(function(){ | |
var vals = {'enabled':$("#web-chkinat-hide_for_all_sites").attr('checked'),'exclude_time':new Date().getTime()}; | |
appAPI.db.set("exclude_all_sites",vals); | |
}); | |
$("#web-chkinat-disable_app").click(function(){ | |
appAPI.db.set("is_disabled",$("#web-chkinat-disable_app").attr('checked')); | |
}); | |
} | |
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); | |
// -- HANDLE THE OPTION TO HIDE SITE / ALL SITES FOR 24hs -- | |
var EXCLUDE_TIME = 60*60*24, | |
LAST_EXPIRED_TIME = (new Date().getTime()) - EXCLUDE_TIME, | |
sites_excluded = [], | |
exclude_all_sites = {'enabled':false,'exclude_time':new Date().getTime()}, | |
is_disabled = false; | |
if(appAPI.db.get("is_disabled")!=null) | |
{ | |
if(appAPI.db.get("is_disabled")) | |
{ | |
console.log("The extension is disabled for ever..."); | |
return; | |
} | |
} | |
if(appAPI.db.get("exclude_all_sites")!=null) | |
{ | |
exclude_all_sites = appAPI.db.get("exclude_all_sites"); | |
//IF STILL DISABLED WE JUST EXIT | |
if(exclude_all_sites.enabled && exclude_all_sites.exclude_time > LAST_EXPIRED_TIME) | |
{ | |
console.log("The extension is disabled for today..."); | |
return; | |
}else if(exclude_all_sites.enabled && exclude_all_sites.exclude_time < LAST_EXPIRED_TIME) | |
{ | |
// IF IT WAS DISABLED BUT IT'S TIME TO RE ENABLE IT, LET'S DO IT! | |
exclude_all_sites.enabled = false; | |
appAPI.db.set("exclude_all_sites",exclude_all_sites); | |
} | |
} | |
if(appAPI.db.get("sites_excluded")!=null) | |
{ | |
sites_excluded = appAPI.db.get("sites_excluded"); | |
//Let's clean the list | |
for(var i=0;i<sites_excluded.length;i++) | |
{ | |
if(sites_excluded[i].exclude_time < LAST_EXPIRED_TIME ) | |
{ | |
sites_excluded.splice(i,1); | |
} | |
} | |
//AFTER CLEANING WE MUST SAVE THE SITE LIST | |
appAPI.db.set("sites_excluded",sites_excluded); | |
} | |
// -- END HANDLE THE OPTION TO HIDE SITE / ALL SITES FOR 24hs -- | |
// -- TOP BAR OBJECT -- | |
var logged = false; | |
var top_bar = (function(){ | |
var status = { | |
open:false, | |
enlarged:false | |
}; | |
return{ | |
loadSettings : function(){ | |
var settings = appAPI.db.get('settings'); | |
if(settings==null || settings==undefined) | |
{ | |
console.log("Let's write default settings..."); | |
settings = {}; | |
settings["chkinat-hide_for_this_site"] = 0; | |
settings["chkinat-hide_for_this_site_forever"] = 0; | |
settings["chkinat-hide_for_all_sites"] = 0; | |
settings["chkinat-disable_app"] = 0; | |
settings["chkinat-disable_twitter_events"] = 0; | |
appAPI.db.set('settings',settings); | |
} | |
$(".chkinat-app_setting_checkbox").each(function(){ | |
$(this).click(function(){ | |
if($(this).attr('checked')==true) | |
{ | |
//SET THE BEHAVIOUR FOR THE OPTION HIDE THIS SITE FOR 24HS BECAUSE IT's PER WEBSITE | |
if($(this).attr('id')=="chkinat-hide_for_this_site") | |
{ | |
sites_excluded = appAPI.db.get("sites_excluded"); | |
console.log(sites_excluded); | |
if(sites_excluded==undefined || sites_excluded==null) | |
{ | |
sites_excluded = []; | |
} | |
sites_excluded.push({'exclude_time':new Date().getTime(),'url':getBaseUrl()}); | |
appAPI.db.set('sites_excluded',sites_excluded); | |
console.log("The site : " + getBaseUrl() + " has been excluded for the next 24hrs"); | |
}else if($(this).attr('id')=="chkinat-hide_for_this_site_forever") | |
{ | |
sites_excluded_forever = appAPI.db.get("sites_excluded_forever"); | |
console.log(sites_excluded_forever); | |
if(sites_excluded_forever==undefined || sites_excluded_forever==null) | |
{ | |
sites_excluded_forever = []; | |
} | |
sites_excluded_forever.push({'url':getBaseUrl()}); | |
appAPI.db.set('sites_excluded_forever',sites_excluded_forever); | |
console.log("The site : " + getBaseUrl() + " has been excluded forever"); | |
}else if($(this).attr('id')=="chkinat-hide_for_all_sites") | |
{ | |
exclude_all_sites = {'enabled':true,'exclude_time':new Date().getTime()}; | |
appAPI.db.set("exclude_all_sites",exclude_all_sites); | |
console.log("Extension disabled for all sites..."); | |
}else if($(this).attr('id')=="chkinat-disable_app") | |
{ | |
is_disabled = true; | |
appAPI.db.set("is_disabled",is_disabled); | |
console.log("Extension disabled for ever"); | |
}else | |
{ | |
//SET THE BEHAVIOUR FOR THE OTHER OPTIONS | |
settings[$(this).attr('id')] = 1; | |
} | |
} | |
else | |
{ | |
if($(this).attr('id')=="chkinat-hide_for_this_site") | |
{ | |
sites_excluded = appAPI.db.get("sites_excluded"); | |
if(sites_excluded!=undefined && sites_excluded!=null) | |
{ | |
for(var i=0;i<sites_excluded.length;i++) | |
{ | |
if(sites_excluded[i].url == getBaseUrl()) | |
{ | |
sites_excluded.splice(i,1); | |
} | |
appAPI.db.set('sites_excluded',sites_excluded); | |
console.log("The site : "+getBaseUrl()+" has been removed from the exclude list"); | |
} | |
} | |
}else if($(this).attr('id')=="chkinat-hide_for_this_site_forever") | |
{ | |
sites_excluded_forever = appAPI.db.get("sites_excluded_forever"); | |
if(sites_excluded_forever!=undefined && sites_excluded_forever!=null) | |
{ | |
for(var i=0;i<sites_excluded_forever.length;i++) | |
{ | |
if(sites_excluded_forever[i].url == getBaseUrl()) | |
{ | |
sites_excluded_forever.splice(i,1); | |
} | |
appAPI.db.set('sites_excluded',sites_excluded_forever); | |
console.log("The site : "+getBaseUrl()+" has been removed from the excluded forever list"); | |
} | |
} | |
}else if($(this).attr('id')=="chkinat-hide_for_all_sites") | |
{ | |
exclude_all_sites = {'enabled':false,'exclude_time':new Date().getTime()}; | |
appAPI.db.set("exclude_all_sites",exclude_all_sites); | |
console.log("Extension re-enabled for all sites..."); | |
}else if($(this).attr('id')=="chkinat-disable_app") | |
{ | |
is_disabled = false; | |
appAPI.db.set("is_disabled",false); | |
console.log("Extension is now enabled"); | |
}else{ | |
settings[$(this).attr('id')] = 0; | |
} | |
} | |
//RESAVE THE SETTINGS | |
console.log("Settings updated..."); | |
appAPI.db.set('settings',settings); | |
}); | |
if(settings[$(this).attr('id')]==1) | |
{ | |
$(this).attr('checked',true); | |
} | |
}); | |
}, | |
init : function(){ | |
var iframe_src = (site_id!=null) ? BASE_URL+'/twitter/auth?site_id='+site_id+'&url='+document.location.href : "#" ; | |
var settings_content = "<fieldset><legend>Settings</legend><ul>"+ | |
"<li><input type='checkbox' id='chkinat-hide_for_this_site' name='hide_for_this_site' class='chkinat-app_setting_checkbox' />Hide it for this site (24hrs)</li>"+ | |
"<li><input type='checkbox' id='chkinat-hide_for_this_site_forever' name='hide_for_this_site_forever' class='chkinat-app_setting_checkbox' />Hide it for this site (Forever)</li>"+ | |
"<li><input type='checkbox' id='chkinat-hide_for_all_sites' name='hide_for_all_sites' class='chkinat-app_setting_checkbox' />Hide it for every site (24hrs)</li>"+ | |
"<li><input type='checkbox' id='chkinat-disable_app' name='disable_app' class='chkinat-app_setting_checkbox' />Disable for ever</li>"+ | |
"<li><input type='checkbox' id='chkinat-disable_twitter_events' name='disable_twitter_events' class='chkinat-app_setting_checkbox' />Don't publish app events on twitter</li>"+ | |
"</ul></fieldset>"+ | |
"<div align='center' id='chkinat-logout-btn-wrapper'><a class='chkinat-chkin-btn' id='chkinat-logout-btn' >Logout</a></div>"; | |
var html = '<div id="chkinat-top-bar" class="chkinat-silent-mode">'+ | |
'<div id="chkinat-header-container" class="chkinat-silent-mode">'+ | |
'<div id="chkinat-bar-handle" class="chkinat-open chkinat-bar-handler">'+ | |
'</div>'+ | |
'<a id="chkinat-start-btn" href="#" class="chkinat-bar-handler">'+ | |
'<h3>Click to Check-in here!</h3>'+ | |
'</a>'+ | |
'<a id="chkinat-check-in-logo" href="#" class="chkinat-bar-handler">'+ | |
'<img src="'+STATIC_URL+'/images/logo-chkinat.png" height="17" />'+ | |
//'<img style="margin-left: 5px;" src="'+STATIC_URL+'/images/beta.png"/>'+ | |
'</a>'+ | |
'<a id="chkinat-settings-logo" href="#"></a>'+ | |
'<a id="chkinat-close-logo" href="#"></a>'+ | |
'<div style="clear:both;"></div>'+ | |
'</div>'+ | |
'<div id="chkinat-iframe-content" >'+ | |
'<iframe id="chkinat-iframe-test" src="'+iframe_src+'"></iframe>'+ | |
'</div>'+ | |
'<div id="chkinat-settings-content" >'+ | |
settings_content+ | |
'</div>'+ | |
'</div>'+ | |
'</div>'; | |
$('body').append(html); | |
this.loadSettings(); | |
already_clicked = appAPI.db.get("has_clicked"); | |
if(already_clicked==null) | |
{ | |
//SHOW TOOLBAR LONG AND SHORT WITH MESSAGE | |
$("#chkinat-top-bar").css({'right':'0px'}); | |
$("#chkinat-check-in-logo").hide(); | |
$("#chkinat-start-btn").css({'display':'block'}); | |
$("#chkinat-settings-logo").css({'display':'none'}); | |
$("#chkinat-close-logo").css({'display':'none'}); | |
$("#chkinat-top-bar").removeClass("chkinat-silent-mode"); | |
$("#chkinat-header-container").removeClass("chkinat-silent-mode"); | |
} | |
}, | |
toggle : function(){ | |
var $top_bar = $("#chkinat-top-bar"), | |
$bar_handle = $("#chkinat-bar-handle"), | |
$iframe_content = $("#chkinat-iframe-content"), | |
$iframe_site = $("#chkinat-iframe-test"), | |
$chk_logo = $("#chkinat-check-in-logo"), | |
$chk_btn = $("#chkinat-start-btn"); | |
//CLOSE THE BAR | |
if(status.open) | |
{ | |
//IT WAS WITH SETTINGS, WE SHOULD RESTORE THE APP VIEW AND DON'T CLOSE IT | |
if(document.getElementById("chkinat-settings-content").style.display!="none") | |
{ | |
//ALWAYS HIDE THE SETTINGS | |
$("#chkinat-settings-content").hide(); | |
$iframe_content.show(); | |
} | |
else | |
{ | |
//If the bar is enlarged, then shrink it | |
if(status.enlarged) | |
{ | |
if($.browser.chrome) | |
{ | |
$top_bar.animate({'height':'30px'},500); | |
} | |
else | |
{ | |
$top_bar.css({'height':'30px'}); | |
} | |
status.enlarged=false; | |
$iframe_content.hide(); | |
} | |
$chk_btn.hide(); | |
if($.browser.chrome) | |
{ | |
$top_bar.animate({'right':'-205px'},500); | |
} | |
else | |
{ | |
$top_bar.css({'right':'-205px'}); | |
} | |
status.open=false; | |
$iframe_content.show(); | |
if($.browser.chrome) | |
{ | |
$top_bar.animate({'height':'30px'},500); | |
} | |
else | |
{ | |
$top_bar.css({'height':'30px'}); | |
} | |
status.enlarged=false; | |
$iframe_content.hide(); | |
$iframe_site.hide(); | |
$chk_logo.hide(); | |
$("#chkinat-settings-logo").hide(); | |
$("#chkinat-close-logo").hide(); | |
$top_bar.addClass("chkinat-silent-mode"); | |
$("#chkinat-header-container").addClass("chkinat-silent-mode"); | |
} | |
} | |
//OPEN THE BAR | |
else | |
{ | |
$chk_btn.hide(); | |
$chk_logo.show(); | |
$("#chkinat-settings-logo").show(); | |
$("#chkinat-close-logo").show(); | |
console.log("show settings"); | |
if($.browser.chrome) | |
{ | |
$top_bar.animate({'right':'0px'},500); | |
} | |
else | |
{ | |
$top_bar.css({'right':'0px'}); | |
} | |
$top_bar.removeClass("chkinat-silent-mode"); | |
$("#chkinat-header-container").removeClass("chkinat-silent-mode"); | |
status.open=true; | |
if($.browser.chrome) | |
{ | |
$top_bar.animate({'height':'256px'},500,function(){ | |
//ANMIATION COMPLETE | |
$iframe_content.show(); | |
$iframe_site.show(); | |
}); | |
} | |
else | |
{ | |
$top_bar.css({'height':'256px'}); | |
$iframe_content.show(); | |
$iframe_site.show(); | |
} | |
status.enlarged=true; | |
} | |
} | |
} | |
}()); | |
// -- END TOP BAR OBJECT -- | |
appAPI.analytics.settings.domain = 'chkin.at'; | |
appAPI.analytics.settings.account = 'UA-29120270-1'; | |
appAPI.analytics.trackUrl(document.location.href); | |
var var_aux = new Date().getTime(); | |
// First we need to get the site_list with jsonp | |
$.getJSON( | |
BASE_URL+"/resources/site_list.json?"+var_aux+"=1", | |
function(data){ | |
sites_list= data.sites_list; | |
// Excluded list are the sites where the user has recently checked in, | |
// the sites that should be hidden until "hours_to_check_in_again" | |
excluded_list = data.excluded_list; | |
// This functions returns null if the site is not in any list | |
var all_sites_list = data.all_sites_list, | |
site_exists = isSiteUnlocked(all_sites_list), | |
has_checked_in = hasCheckedIn(excluded_list); | |
site_id = getCurrentSiteId(sites_list,excluded_list); | |
console.log(all_sites_list, "Todos los sitios: "); | |
console.log(excluded_list, "EXCLUDED: "); | |
// This should be the first thing to load | |
if(document.location.href.search("chkin.at/twitter/success")!=-1) | |
{ | |
appAPI.message.toAllTabs({action:'reload-iframe'}); | |
if(!$.browser.chrome) | |
{ | |
alert("Your account was succesfully authenticated please close this tab and then reload the page in order to start checking in"); | |
} | |
window.close(); | |
} | |
else | |
{ | |
// If we are not in twitter oauth | |
if(document.location.href.search("api.twitter.com")==-1) | |
{ | |
// Proceed with the normal flow | |
console.log("NORMAL FLOW"); | |
// DO everything here, if not we will have timing issues when loading site_list with jsonp | |
console.log(has_checked_in,"normal flow - already checked in here?"); | |
//if(site_id!=null && !isExcluded())//Old code | |
if(!has_checked_in && !isExcluded())// If site_id is null, then init top_bar but with no iframe | |
{ | |
if(site_id!=null && $.browser.chrome) | |
{ | |
appAPI.message.addListener(function(msg) | |
{ | |
if (msg.action == "reload-iframe") | |
{ | |
$("#chkinat-iframe-test").remove(); | |
var new_src = BASE_URL+"/checkin?site_id="+site_id+"&url="+document.location.href; | |
$("#chkinat-iframe-content").html('<iframe id="chkinat-iframe-test" src="'+ new_src + '" ></iframe>'); | |
} | |
}); | |
} | |
// WE SHOULD REPEAT THIS CHUNK OF CODE DUE TO TIMING ISSUES | |
console.log("That's one small step for [a] man, one giant leap for mankind"); | |
console.log(site_id); | |
top_bar.init(); | |
$("#chkinat-top-bar").delegate(".chkinat-bar-handler", "click", function(event){ | |
event.preventDefault(); | |
appAPI.db.set("has_clicked",1); | |
// ACA DEBO PREGUNTAR SI EL SITIO EXISTE Y SINO AGREGARLO | |
// If the current site is not in any list, then we should add it to the db | |
if(!site_exists) | |
{ | |
console.log("adding the site to the db!"); | |
var tmp_url = document.location.href.replace("http://","").replace("https://","").split("/"), | |
current_base_url = tmp_url[0], | |
current_base_url_clean = current_base_url.replace("www.",""); | |
//current_site_name = current_base_url_clean.charAt(0).toUpperCase() + current_base_url_clean.slice(1); | |
console.log(current_base_url_clean,"base url"); | |
//console.log(current_site_name,"site name"); | |
// Add site on the server | |
$.getJSON( | |
BASE_URL+"/save_site.php", | |
{ | |
domain_base: current_base_url_clean | |
}, | |
function(data){ | |
console.log("SAVING SITE DATA... -> ",data.response); | |
// If the we insert it OK, then load an iframe with the new site_id | |
if(data.response=="OK") | |
{ | |
console.log(data.site_id, "SITE ID"); | |
site_id = data.site_id; | |
// DO everything here, if not we will have timing issues when loading site_list with jsonp | |
if(site_id!=null && !isExcluded()) | |
{ | |
var new_src = BASE_URL+"/checkin?site_id="+site_id+"&url="+document.location.href; | |
if($.browser.chrome) | |
{ | |
appAPI.message.addListener(function(msg) | |
{ | |
if (msg.action == "reload-iframe") | |
{ | |
$("#chkinat-iframe-test").remove(); | |
$("#chkinat-iframe-content").html('<iframe id="chkinat-iframe-test" src="'+ new_src + '" ></iframe>'); | |
} | |
}); | |
} | |
// WE SHOULD CHANGE IFRAME SRC | |
$("#chkinat-iframe-test").attr("src", new_src); | |
// THEN SHOW IT | |
top_bar.toggle(); | |
$("#chkinat-settings-btn").css({'display':'block'}); | |
}// END SITE != NULL | |
}// END RESPONSE = OK | |
}// END SUCCESS JSONP | |
);// END JSONP | |
}// END SITE ! EXISTS | |
else | |
{ | |
top_bar.toggle(); | |
$("#chkinat-settings-btn").css({'display':'block'}); | |
} | |
}); | |
$("#chkinat-top-bar").delegate("#chkinat-settings-logo", "click", function(event){ | |
event.preventDefault(); | |
$("#chkinat-iframe-content").hide(); | |
$("#chkinat-settings-content").show(); | |
}); | |
$("#chkinat-top-bar").delegate("#chkinat-close-logo", "click", function(event){ | |
event.preventDefault(); | |
top_bar.toggle(); | |
}); | |
$("#chkinat-top-bar").delegate("#chkinat-logout-btn", "click", function(event){ | |
$.getJSON( | |
BASE_URL+"/logout", | |
function(data){ | |
$("#chkinat-iframe-test").remove(); | |
var new_src = BASE_URL+"/checkin?site_id="+site_id+"&url="+document.location.href; | |
$("#chkinat-iframe-content").html('<iframe id="chkinat-iframe-test" src="'+ new_src + '" ></iframe>'); | |
} | |
); | |
}); | |
}// END NORMAL FLOW | |
// GEO | |
loadGeoData(); | |
// END GEO | |
}// END IF TWITTER | |
}// END ELSE TWITTER SUCCESS | |
}// END JSONP SUCCESS CALLBACK FUNCTION | |
);// END JSONP | |
});// END DOCUMENT READY | |
// -- END MAIN SCRIPT -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment