Skip to content

Commit

Permalink
Added user persistence, as per issue #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesronan committed Jun 24, 2013
1 parent 64cd756 commit d8e3244
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ due to the components that power it.
Prereqs
-------

Requires [Perl Dancer](http://perldancer.org), and its
[Database Plugin](https://metacpan.org/module/Dancer::Plugin::Database), to run.
The app has several JS libs bundled in. Please pay attention to the licensing on those
Requires [Perl Dancer](http://perldancer.org), and its
[Database Plugin](https://metacpan.org/module/Dancer::Plugin::Database), to run.
The app has several JS libs bundled in. Please pay attention to the licensing on those
libs before you go hacking on that code :)


Expand All @@ -28,7 +28,8 @@ people's work. I just moshed it all together with voodoo of my own.
* [Backbone](http://backbonejs.org)
* [Underscore](http://underscorejs.org)
* [jQuery](http://jquery.com/)
* [jQuery's Validation Plugin](http://jqueryvalidation.org/)
* [jQuery Validation Plugin](http://jqueryvalidation.org/)
* [jQuery Cookie Plugin](http://plugins.jquery.com/jcookie/)
* [Twitter's Bootstrap](http://twitter.github.io/bootstrap/)
* [Moment.js](http://momentjs.com/)
* [Mustache Templates](http://mustache.github.io/)
Expand Down
19 changes: 19 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,28 @@
Mosh.Views.NewMosh = Backbone.View.extend({
template: Mosh.template('new-mosh'),
windowTitle: 'SpinalTapCodeMosh - Collaborative code paste binning.',
events: {
'keyup input#poster': 'updateNameCookie',
'click input#persistname': 'updateNameCookie',
},
updateNameCookie: function() {
if (this.$el.find('input#persistname').prop('checked') === true) {
$.jCookie('poster', this.$el.find('input#poster').val()); // Set the cookie
} else {
$.jCookie('poster',null); // Delete the cookie.
}
},
render: function() {
window.document.title = this.windowTitle;
this.$el.html( this.template(this) );

// Update the poster box and checkbox if we have a persistance
// cookie.
if ($.jCookie('poster')) {
this.$el.find('input#poster').val($.jCookie('poster'));
this.$el.find('input#persistname').attr('checked','checked');
}

this.$el.find('form').validate({
rules: {
subject: { required: 1 },
Expand Down
1 change: 1 addition & 0 deletions views/js.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script type="text/javascript" src="/js/lib/jquery.js"></script>
<script type="text/javascript" src="/js/lib/jquery.validate.min.js"></script>
<script type="text/javascript" src="/js/lib/jcookie-min.js"></script>
<script type="text/javascript" src="/js/lib/underscore.js"></script>
<script type="text/javascript" src="/js/lib/bootstrap.js"></script>
<script type="text/javascript" src="/js/lib/backbone.js"></script>
Expand Down
1 change: 1 addition & 0 deletions views/mustache-templates.tt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<br>
<label for="poster">Name:</label>
<input type="text" id="poster" name="poster" placeholder="Guest" value="">
<span><input type="checkbox" id="persistname" name="persistname"> Remember Me</span>
<br>
<button type="submit" id="submit" name="submit" class="btn btn-action" autocomplete="off"
data-loading-text="Posting" data-complete-text="Posted!" data-error-text="Failed :(">
Expand Down

0 comments on commit d8e3244

Please sign in to comment.