aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-01-24 20:27:08 +0100
committerPacien TRAN-GIRARD2015-01-25 23:47:13 +0100
commitd04d732a084f07ca88fdfa82653bdfd2d6798374 (patch)
treed4b03c921e5fa98e9fb731d1549fbc8dbdc6b9fe /public/javascripts
parent2f6780969318c08c7a0a0e8e52a7dad33ff53786 (diff)
downloadminibay-d04d732a084f07ca88fdfa82653bdfd2d6798374.tar.gz
First website mockup
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/cheat.js29
-rw-r--r--public/javascripts/hello.js3
-rw-r--r--public/javascripts/konami.js105
3 files changed, 134 insertions, 3 deletions
diff --git a/public/javascripts/cheat.js b/public/javascripts/cheat.js
new file mode 100644
index 0000000..863e53a
--- /dev/null
+++ b/public/javascripts/cheat.js
@@ -0,0 +1,29 @@
1var konamiActivated = false;
2
3new Konami(function () {
4
5 if (konamiActivated) return;
6 konamiActivated = true;
7
8 console.log('Cheat console activated. Have fun!');
9
10 // play nice soundtrack
11 (new Audio('/assets/medias/sims2-university-theme.ogg')).play();
12
13 // display cheat console
14 var form = document.createElement('form');
15 form.classList.add('cheat-form');
16 form.setAttribute('method', 'post');
17 form.setAttribute('action', '/console');
18
19 var field = document.createElement('input');
20 field.setAttribute('type', 'text');
21 field.setAttribute('name', 'command');
22 field.setAttribute('autocomplete', 'off');
23
24 form.appendChild(field);
25 document.getElementsByTagName('body')[0].appendChild(form);
26
27 field.focus();
28
29});
diff --git a/public/javascripts/hello.js b/public/javascripts/hello.js
deleted file mode 100644
index 209fbee..0000000
--- a/public/javascripts/hello.js
+++ /dev/null
@@ -1,3 +0,0 @@
1if (window.console) {
2 console.log("Welcome to your Play application's JavaScript!");
3} \ No newline at end of file
diff --git a/public/javascripts/konami.js b/public/javascripts/konami.js
new file mode 100644
index 0000000..15882b9
--- /dev/null
+++ b/public/javascripts/konami.js
@@ -0,0 +1,105 @@
1/*
2 * Konami-JS ~
3 * :: Now with support for touch events and multiple instances for
4 * :: those situations that call for multiple easter eggs!
5 * Code: http://konami-js.googlecode.com/
6 * Examples: http://www.snaptortoise.com/konami-js
7 * 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 Browser
11 */
12
13var 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 // IE
20 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; // IE
32 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 = link
46 },
47 iphone: {
48 start_x: 0,
49 start_y: 0,
50 stop_x: 0,
51 stop_y: 0,
52 tap: false,
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 load: function (link) {
60 this.orig_keys = this.keys;
61 konami.addEvent(document, "touchmove", function (e) {
62 if (e.touches.length == 1 && konami.iphone.capture == true) {
63 var touch = e.touches[0];
64 konami.iphone.stop_x = touch.pageX;
65 konami.iphone.stop_y = touch.pageY;
66 konami.iphone.tap = false;
67 konami.iphone.capture = false;
68 konami.iphone.check_direction();
69 }
70 });
71 konami.addEvent(document, "touchend", function (evt) {
72 if (konami.iphone.tap == true) konami.iphone.check_direction(link);
73 }, false);
74 konami.addEvent(document, "touchstart", function (evt) {
75 konami.iphone.start_x = evt.changedTouches[0].pageX;
76 konami.iphone.start_y = evt.changedTouches[0].pageY;
77 konami.iphone.tap = true;
78 konami.iphone.capture = true;
79 });
80 },
81 check_direction: function (link) {
82 x_magnitude = Math.abs(this.start_x - this.stop_x);
83 y_magnitude = Math.abs(this.start_y - this.stop_y);
84 x = ((this.start_x - this.stop_x) < 0) ? "RIGHT" : "LEFT";
85 y = ((this.start_y - this.stop_y) < 0) ? "DOWN" : "UP";
86 result = (x_magnitude > y_magnitude) ? x : y;
87 result = (this.tap == true) ? "TAP" : result;
88
89 if (result == this.keys[0]) this.keys = this.keys.slice(1, this.keys.length);
90 if (this.keys.length == 0) {
91 this.keys = this.orig_keys;
92 this.code(link);
93 }
94 }
95 }
96 }
97
98 typeof callback === "string" && konami.load(callback);
99 if (typeof callback === "function") {
100 konami.code = callback;
101 konami.load();
102 }
103
104 return konami;
105};