This commit is contained in:
Daniel Camargo 2013-07-23 17:56:11 -03:00
commit c90c6c8572
9 changed files with 216 additions and 29 deletions

View File

@ -41,8 +41,8 @@ if ($this->community) {
<script src="/assets/js/jquery.cookie.js"></script>
<script src="/assets/js/jquery.totalstorage.js"></script>
<script src="/assets/js/date.js"></script>
<script src="/assets/js/TimeMachine.js"></script>
<script src="/assets/js/jquery.browser.mobile.js"></script>
@ -137,19 +137,7 @@ $(function() {
<script src="/assets/js/services.support.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/js/services.order.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script type="text/javascript">
(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");
b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+
'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';d=c.getElementsByTagName("script")[0];
d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){
var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(
Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f?g=a[f]=[]:
f="mixpanel";g.people=g.people||[];h=['disable','track','track_pageview','track_links',
'track_forms','register','register_once','unregister','identify','alias','name_tag',
'set_config','people.set','people.increment','people.track_charge','people.append'];
for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.2;})(document,window.mixpanel||[]);
mixpanel.init("6eb260b54eecfd293d50b5f1423c6e98");
</script>
<script type="application/x-javascript">
addEventListener('touchstart',function(){}); addEventListener('load', function(event) {setTimeout(scrollTo, 80, 0, 1);}, false);
</script>

View File

@ -122,6 +122,20 @@ if (App){
</script>
<? endif ; ?>
<script type="text/javascript">
(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");
b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+
'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';d=c.getElementsByTagName("script")[0];
d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){
var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(
Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f?g=a[f]=[]:
f="mixpanel";g.people=g.people||[];h=['disable','track','track_pageview','track_links',
'track_forms','register','register_once','unregister','identify','alias','name_tag',
'set_config','people.set','people.increment','people.track_charge','people.append'];
for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.2;})(document,window.mixpanel||[]);
mixpanel.init("6eb260b54eecfd293d50b5f1423c6e98");
</script>
<div id="small-dialog" class="zoom-anim-dialog mfp-hide">
<h1>Dialog example</h1>
<p>This is dummy copy. It is not meant to be read. It has been placed here solely to demonstrate the look and feel of finished, typeset text. Only for show. He who searches for meaning here will be sorely disappointed.</p>

View File

@ -23,8 +23,8 @@ function TimeMachine() {
*/
this.__construct = function()
{
if ($.cookie('TimeMachine')) {
_fixedTime = $.cookie('TimeMachine');
if ($.totalStorage('TimeMachine')) {
_fixedTime = $.totalStorage('TimeMachine');
}
}
@ -52,7 +52,7 @@ function TimeMachine() {
this.toBeContinued = function()
{
$.cookie('TimeMachine', _fixedTime);
$.totalStorage('TimeMachine', _fixedTime);
}
/**

View File

@ -44,9 +44,11 @@ var App = {
crunchSoundAlreadyPlayed : false,
useCompleteAddress : false, /* if true it means the address field will be fill with the address found by google api */
completeAddressWithZipCode : true,
boundingBoxMeters : 8000
boundingBoxMeters : 8000,
localStorage: false
};
App.alert = function(txt) {
setTimeout(function() {
alert(txt);
@ -386,9 +388,9 @@ App.test = {
App.alert(JSON.stringify(App.cart.items));
},
clearloc: function() {
$.cookie('community', '', { expires: new Date(3000,01,01), path: '/'});
$.cookie('location_lat', '', { expires: new Date(3000,01,01), path: '/'});
$.cookie('location_lon', '', { expires: new Date(3000,01,01), path: '/'});
$.totalstorage('community',null);
$.totalstorage('location_lat',null);
$.totalstorage('location_lon',null);
location.href = '/';
},
init: function() {
@ -481,6 +483,8 @@ App.trigger = {
*/
$(function() {
$.totalStorage.ls(App.localStorage);
App.processConfig(App.config);
App._init = true;
App.NGinit();
@ -807,7 +811,6 @@ App.getCommunityById = function( id ){
*/
App.dialog = {
show: function() {
console.log('arguments',arguments);
if (arguments[1]) {
// its a title and message
var src = '<div class="zoom-anim-dialog small-container">' +

View File

@ -697,7 +697,7 @@ App.isDeliveryAddressOk = true;
} else {
if (json.token) {
$.cookie('token', json.token, { expires: new Date(3000,01,01), path: '/'});
$.totalStorage('token', json.token);
}
$('.link-orders').show();

View File

@ -129,7 +129,7 @@ App.facebook.registerToken = function( token ){
if( !App.facebook.token ){
App.facebook.token = token;
var url = App.service + App.facebook.api.token;
$.cookie( 'fbtoken', token, { expires: new Date(3000,01,01), path: '/'});
$.totalStorage( 'fbtoken', token);
}
}

View File

@ -0,0 +1,182 @@
/**
* TotalStorage
*
* Copyright (c) 2012 Jared Novack & Upstatement (upstatement.com)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Total Storage is the conceptual the love child of jStorage by Andris Reinman,
* and Cookie by Klaus Hartl -- though this is not connected to either project.
*/
/**
* Create a local storage parameter
*
== What makes it TOTAL Storage? ==
* The browser doesn't support local storage it will fall-back to cookies! (Using the
wonderful $.cookie plugin).
* Send it strings, numbers even complex object arrays! TotalStorage does not care.
Your efforts to defeat it will prove futile.
* Simple as shit. jStorage and some other very well-written plugins provide a bevy of
options for expiration, security and so forth. Frequently this is more power than you
need and vulnerable to confusion if you're just want it to work (JWITW)
* @desc Set the value of a key to a string
* @example $.totalStorage('the_key', 'the_value');
* @desc Set the value of a key to a number
* @example $.totalStorage('the_key', 800.2);
* @desc Set the value of a key to a complex Array
* @example var myArray = new Array();
* myArray.push({name:'Jared', company:'Upstatement', zip:63124});
myArray.push({name:'McGruff', company:'Police', zip:60652};
$.totalStorage('people', myArray);
//to return:
$.totalStorage('people');
*
* @name $.totalStorage
* @cat Plugins/Cookie
* @author Jared Novack/jared@upstatement.com
* @version 1.1.2
* @url http://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/
*/
;(function($, undefined){
/* Variables I'll need throghout */
var supported, ls;
if ('localStorage' in window){
try {
ls = (typeof window.localStorage === 'undefined') ? undefined : window.localStorage;
if (typeof ls == 'undefined' || typeof window.JSON == 'undefined'){
supported = false;
} else {
supported = true;
}
}
catch (err){
supported = false;
}
}
/* Make the methods public */
$.totalStorage = function(key, value, options){
return $.totalStorage.impl.init(key, value);
};
$.totalStorage.setItem = function(key, value){
return $.totalStorage.impl.setItem(key, value);
};
$.totalStorage.getItem = function(key){
return $.totalStorage.impl.getItem(key);
};
$.totalStorage.getAll = function(){
return $.totalStorage.impl.getAll();
};
$.totalStorage.deleteItem = function(key){
return $.totalStorage.impl.deleteItem(key);
};
$.totalStorage.ls = function(value){
supported = value ? true : false;
};
/* Object to hold all methods: public and private */
$.totalStorage.impl = {
init: function(key, value){
if (typeof value != 'undefined') {
return this.setItem(key, value);
} else {
return this.getItem(key);
}
},
setItem: function(key, value){
if (!supported){
try {
$.cookie(key, JSON.stringify(value));
return value;
} catch(e){
console.log('Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie');
}
}
var saver = JSON.stringify(value);
ls.setItem(key, saver);
return this.parseResult(saver);
},
getItem: function(key){
if (!supported){
try {
return this.parseResult($.cookie(key));
} catch(e){
return null;
}
}
var item = ls.getItem(key);
return this.parseResult(item);
},
deleteItem: function(key){
if (!supported){
try {
$.cookie(key, null);
return true;
} catch(e){
return false;
}
}
ls.removeItem(key);
return true;
},
getAll: function(){
var items = [];
if (!supported){
try {
var pairs = document.cookie.split(";");
for (var i = 0; i<pairs.length; i++){
var pair = pairs[i].split('=');
var key = pair[0];
items.push({key:key, value:this.parseResult($.cookie(key))});
}
} catch(e){
return null;
}
} else {
for (var j in ls){
if (j.length){
items.push({key:j, value:this.parseResult(ls.getItem(j))});
}
}
}
return items;
},
parseResult: function(res){
var ret;
try {
ret = JSON.parse(res);
if (typeof ret == 'undefined'){
ret = res;
}
if (ret == 'true'){
ret = true;
}
if (ret == 'false'){
ret = false;
}
if (parseFloat(ret) == ret && typeof ret != "object"){
ret = parseFloat(ret);
}
} catch(e){
ret = res;
}
return ret;
}
};
})(jQuery);

View File

@ -12,7 +12,7 @@ NGApp.factory( 'PositionsService', function(){
// Resets the restaurant's list
App.restaurants.forceLoad = true;
service.locs.push( loc );
$.cookie('locsv2', JSON.stringify(service.locs), { expires: new Date(3000,01,01), path: '/'});
$.totalStorage('locsv2', service.locs);
}
/**
@ -143,8 +143,8 @@ NGApp.factory( 'LocationService', function( $location, RestaurantsService, Posit
}
// 2) retrieve and set location date from cookies
var cookieLocs = $.cookie('locsv2') ? JSON.parse($.cookie('locsv2')) : null;
var cookieBounding = $.cookie('boundingv2') ? JSON.parse($.cookie('boundingv2')) : null;
var cookieLocs = $.totalStorage('locsv2');
var cookieBounding = $.totalStorage('boundingv2');
if ( cookieLocs ) {
for( var x in cookieLocs ) {
@ -418,7 +418,7 @@ NGApp.factory( 'LocationService', function( $location, RestaurantsService, Posit
service.geocode(address, function(loc) {
service.position.addLocation(loc);
success();
$.cookie('boundingv2', JSON.stringify(service.bounding), { expires: new Date(3000,01,01), path: '/'});
$.totalStorage('boundingv2', service.bounding);
}, error);
}
//service.geocode(address, success, error);

View File

@ -359,7 +359,7 @@ NGApp.factory( 'AccountSignOut', function( $http, AccountFacebookService ){
// Force to remove the cookies
$.each( [ 'token', 'location', 'PHPSESSID' ], function( index, value ){
$.cookie( value, null );
$.totalStorage(value, null);
} );
var signout = function(){