Created
February 28, 2011 19:54
-
-
Save jeffremer/847908 to your computer and use it in GitHub Desktop.
Age Gate
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
/* | |
.card .x-panel-body { | |
text-align: center; | |
font-size: 24px; | |
line-height: 26px; | |
font-weight: bold; | |
color: rgba(0,0,0,.4); | |
text-shadow: rgba(255,255,255,.2) 0 1px 0; | |
background-color: #ccc; | |
padding: 1em 5%; | |
} | |
*/ | |
{ | |
suppressNavigationItem: true, | |
setup: function() { | |
this.ageGateCookieName = [Wbx.app.instFriendlyId, this.id, 'age_gate'].join('_'); | |
}, | |
index: function(interaction) { | |
if(this.isOldEnough(Wbx.utils.CookieUtils.getCookie(this.ageGateCookieName)) || this.oldEnough) { | |
var thisIndex = Wbx.controllers.getControllerIndex(Wbx.controllers.getControllerById(this.id)), | |
controller = Wbx.controllers.getControllerByIndex(++thisIndex); | |
Wbx.dispatch({ | |
controller: controller, | |
action: 'index', | |
historyUrl: [controller.id,'index'].join('/') | |
}); | |
} else { | |
// Not cookied | |
// Hide the nav | |
this.panel = new Wbx.views.AbstractView({ | |
scroll: false, | |
cls: 'card', | |
html: '<p>Enter your birthday to continue.</p><small>You must be at least 18 to view this content.</small>' | |
}); | |
this.datePicker = new Wbx.views.DatePicker({ | |
cancelButton: null, | |
doneButton: { | |
text: 'OK', | |
scope: this, | |
handler: function() { | |
var val = this.datePicker.getValue(); | |
if(this.isOldEnough(val.getTime())) { | |
Wbx.utils.CookieUtils.setCookie(this.ageGateCookieName, val.getTime()); | |
this.oldEnough = true; | |
this.datePicker.hide(); | |
Wbx.dispatch({ | |
controller: this, | |
action: 'index', | |
historyUrl: this.id + '/index' | |
}) | |
} else { | |
Wbx.views.Msg.alert('Error', 'You are not old enough!', Ext.emptyFn); | |
} | |
} | |
} | |
}); | |
this.datePicker.show(); | |
this.renderIndex(this.panel, interaction); | |
} | |
}, | |
isOldEnough: function(time) { | |
return ((new Date().getTime() - parseInt(time)) / 31536000000) >= 18; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment