Created
June 23, 2014 12:36
-
-
Save sonodar/dfde21b0363b1753ef66 to your computer and use it in GitHub Desktop.
Revisions
-
Sonoda Ryohei revised this gist
Jul 7, 2014 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,22 @@ # 関数化、リトライ対応版 # ほぼTwitterのソースだけど class CommandWatcher constructor: (commands) -> @keys = [] @length = commands.length @command = commands.join ',' watch: (handler) => watcher = @ $(document).on 'keydown', (event) -> watcher.keys.push event.which # マッチしたら実行後、即return if watcher.keys.length is watcher.length and watcher.keys.join(',') is watcher.command handler() watcher.keys = [] return # マッチしなかったらリセット if watcher.command.indexOf(watcher.keys.join(',')) isnt 0 watcher.keys = [] return new CommandWatcher([38,38,40,40,37,39,37,39,66,65]).watch -> -
Sonoda Ryohei revised this gist
Jun 26, 2014 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # 関数化、リトライ対応版 # ほぼTwitterのソースだけど若干パフォーマンスいいかも class CommandWatcher constructor: (commands) -> @keys = [] @length = commands.length @command = commands.join ',' watch: (handler) => $(document).on('keydown', (event) -> @keys.push event.which # マッチしたら実行後、即return if @keys.length is @length and keys.join(',') is @command handler() @keys = [] return # マッチしなかったらリセット if @command.indexOf(@keys.join(',')) isnt 0 @keys = [] return new CommandWatcher([38,38,40,40,37,39,37,39,66,65]).watch -> # ここにコナミコマンドのイベントを実装 -
Sonoda Ryohei revised this gist
Jun 25, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ (function(cmd, fire) { var keys = []; var l = cmd.length, CMD = cmd.join(','); $(document).on('keydown', function(event) { keys.push(event.which); if (keys.length < l) return true; if (keys.join(',') === CMD) fire(); keys = []; }); })([38,38,40,40,37,39,37,39,66,65], function(){ // ここにコナミコマンドのイベントを実装 }); -
Sonoda Ryohei revised this gist
Jun 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,6 @@ if (keys.join(',') === CMD) fire(); keys = []; }); })(function(){ // ここにコナミコマンドのイベントを実装 }); -
Sonoda Ryohei revised this gist
Jun 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ var l = cmd.length, CMD = cmd.join(','); $(document).on('keydown', function(event) { keys.push(event.which); if (keys.length < l) return true; if (keys.join(',') === CMD) fire(); keys = []; }); -
Sonoda Ryohei revised this gist
Jun 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ var cmd = [38,38,40,40,37,39,37,39,66,65], keys = []; var l = cmd.length, CMD = cmd.join(','); $(document).on('keydown', function(event) { keys.push(event.which); if (keys.lenght < l) return true; if (keys.join(',') === CMD) fire(); keys = []; -
Sonoda Ryohei revised this gist
Jun 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ (function(fire) { var cmd = [38,38,40,40,37,39,37,39,66,65], keys = []; var l = cmd.length, CMD = cmd.join(','); $(document).on('keydown', function(event) { keys.puhs(event.which); -
Sonoda Ryohei revised this gist
Jun 23, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ (function(fire) { var cmd = ['38,38,40,40,37,39,37,39,66,65'], keys = []; var l = cmd.length, CMD = cmd.join(','); $(document).on('keydown', function(event) { keys.puhs(event.which); if (keys.lenght < l) return true; if (keys.join(',') === CMD) fire(); keys = []; }); )(function(){ -
Sonoda Ryohei created this gist
Jun 23, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ (function(fire) { var cmd = '38,38,40,40,37,39,37,39,66,65', keys = []; var l = cmd.length; $(document).on('keydown', function(event) { keys.puhs(event.which); if (keys.lenght < l) return true; if (keys.join(',') === cmd) fire(); keys = []; }); )(function(){ // ここにコナミコマンドのイベントを実装 });