Skip to content

Instantly share code, notes, and snippets.

@kkemple
Last active July 9, 2021 20:14
Show Gist options
  • Save kkemple/8bdc20cae7cdda6b7e53 to your computer and use it in GitHub Desktop.
Save kkemple/8bdc20cae7cdda6b7e53 to your computer and use it in GitHub Desktop.
Konami code Marionette Behavior
'use strict';
var Marionette = require('backbone.marionette'),
Konami;
Konami = Marionette.Behavior.extend({
defaults: {
code : [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]
},
events: {
'keyup': '_konami',
},
initialize: function() {
this.cache = [];
},
_konami: function(e) {
if (this.options.code.length > this.cache.push(e.which)) return;
if (this.options.code.length < this.cache.length) this.cache.shift();
if (this.options.code.toString() !== this.cache.toString()) return;
this.view.trigger('konami');
this.view.triggerMethod('konami');
}
});
module.exports = Konami;
/**
* Usage:
*
* var View = Marionette.ItemView.extend({
* ...
* behaviors: {
* Konami: {
* behaviorClass: Konami
* }
* },
* onKonami: function() {
* // easter egg!
* }
* });
*/
@jamiebuilds
Copy link

I love this.

@kkemple
Copy link
Author

kkemple commented Jan 4, 2015

thanks, yeah i made a vanilla JS version like a year ago, I figured why not port it over to Marionette 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment