cheat code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent d8bf59d · Browse files · 3 files·+130 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+130 added−4 removed
- other:+130 added−4 removed
Provenance
- Commit
1b1f4ac- Tree
37da3af- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent
d8bf59d
3 files changed+130 added−4 removed
added:docs/_static/konami.js+116 added
1+/*2+ * Konami-JS ~3+ * :: Now with support for touch events and multiple instances for4+ * :: those situations that call for multiple easter eggs!5+ * Code: http://konami-js.googlecode.com/6+ * Examples: http://www.snaptortoise.com/konami-js7+ * Copyright (c) 2009 George Mandis (georgemandis.com, snaptortoise.com)8+ * Version: 1.4.2 (9/2/2013)9+ * Licensed under the MIT License (http://opensource.org/licenses/MIT)10+ * Tested in: Safari 4+, Google Chrome 4+, Firefox 3+, IE7+, Mobile Safari 2.2.1 and Dolphin Browser11+ */12+13+var Konami = function (callback) {14+ var konami = {15+ addEvent: function (obj, type, fn, ref_obj) {16+ if (obj.addEventListener)17+ obj.addEventListener(type, fn, false);18+ else if (obj.attachEvent) {19+ // IE20+ obj["e" + type + fn] = fn;21+ obj[type + fn] = function () {22+ obj["e" + type + fn](window.event, ref_obj);23+ };24+ obj.attachEvent("on" + type, obj[type + fn]);25+ }26+ },27+ input: "",28+ pattern: "38384040373937396665",29+ load: function (link) {30+ this.addEvent(document, "keydown", function (e, ref_obj) {31+ if (ref_obj) konami = ref_obj; // IE32+ konami.input += e ? e.keyCode : event.keyCode;33+ if (konami.input.length > konami.pattern.length)34+ konami.input = konami.input.substr((konami.input.length - konami.pattern.length));35+ if (konami.input == konami.pattern) {36+ konami.code(link);37+ konami.input = "";38+ e.preventDefault();39+ return false;40+ }41+ }, this);42+ this.iphone.load(link);43+ },44+ code: function (link) {45+ window.location = link46+ },47+ iphone: {48+ start_x: 0,49+ start_y: 0,50+ stop_x: 0,51+ stop_y: 0,52+ tapTolerance: 8,53+ capture: false,54+ orig_keys: "",55+ keys: ["UP", "UP", "DOWN", "DOWN", "LEFT", "RIGHT", "LEFT", "RIGHT", "TAP", "TAP"],56+ code: function (link) {57+ konami.code(link);58+ },59+ touchCapture: function(evt) {60+ konami.iphone.start_x = evt.changedTouches[0].pageX;61+ konami.iphone.start_y = evt.changedTouches[0].pageY;62+ konami.iphone.capture = true; 63+ },64+ load: function (link) {65+ this.orig_keys = this.keys;66+ konami.addEvent(document, "touchmove", function (e) {67+ if (e.touches.length == 1 && konami.iphone.capture == true) {68+ var touch = e.touches[0];69+ konami.iphone.stop_x = touch.pageX;70+ konami.iphone.stop_y = touch.pageY;71+ konami.iphone.check_direction();72+ }73+ });74+ konami.addEvent(document, "touchend", function (evt) {75+ konami.touchCapture(evt);76+ konami.iphone.check_direction(link);77+ }, false);78+ konami.addEvent(document, "touchstart", function (evt) {79+ konami.touchCapture(evt);80+ });81+ },82+ check_direction: function (link) {83+ var x_magnitude = Math.abs(this.start_x - this.stop_x);84+ var y_magnitude = Math.abs(this.start_y - this.stop_y);85+ var hasMoved = (x_magnitude > this.tapTolerance || y_magnitude > this.tapTolerance);86+ var result;87+ if (this.capture === true && hasMoved) {88+ this.capture = false;89+ var x = ((this.start_x - this.stop_x) < 0) ? "RIGHT" : "LEFT";90+ var y = ((this.start_y - this.stop_y) < 0) ? "DOWN" : "UP";91+ var result = (x_magnitude > y_magnitude) ? x : y;92+ }93+ else if (this.capture === false && !hasMoved) {94+ result = (this.tap == true) ? "TAP" : result;95+ result = "TAP";96+ }97+ if (result) {98+ if (result == this.keys[0]) this.keys = this.keys.slice(1, this.keys.length);99+ else this.keys = this.orig_keys;100+ }101+ if (this.keys.length == 0) {102+ this.keys = this.orig_keys;103+ this.code(link);104+ }105+ }106+ }107+ }108+109+ typeof callback === "string" && konami.load(callback);110+ if (typeof callback === "function") {111+ konami.code = callback;112+ konami.load();113+ }114+115+ return konami;116+};modified:docs/_templates/hacks.html+8 added-1 removed
42 unmodified lines4344454647474849505152535442 unmodified lines</script>
<!-- There are no more hacks. --><!-- இڿڰۣ-ڰۣ— --><!-- Love, Kenneth Reitz -->No newline at end of file<!-- Love, Kenneth Reitz -->
<script src="{{ pathto('_static/', 1) }}/konami.js"></script><script> var easter_egg = new Konami('http://fortunes.herokuapp.com/random/raw');</script>
<!-- That was not a hack. That was art. -->No newline at end of filemodified:docs/index.rst+6 added-3 removed
122 unmodified lines123 community/vulnerabilities124 community/updates125 community/release-process126 127-API Documentation128------------------127+API Documentation / Guide128+-------------------------129 130 If you are looking for information on a specific function, class or method,131 this part of the documentation is for you.132 9 unmodified lines142 If you want to contribute to the project, this part of the documentation is for143 you.144 145 .. toctree::146- :maxdepth: 1146+ :maxdepth: 2147 148 dev/contributing149 dev/philosophy150 dev/todo151 dev/authors152+153+There are no more guides. You are now guideless.154+Good luck.