From d04d732a084f07ca88fdfa82653bdfd2d6798374 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 24 Jan 2015 20:27:08 +0100 Subject: First website mockup --- public/javascripts/cheat.js | 29 ++++++++++++ public/javascripts/hello.js | 3 -- public/javascripts/konami.js | 105 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 public/javascripts/cheat.js delete mode 100644 public/javascripts/hello.js create mode 100644 public/javascripts/konami.js (limited to 'public/javascripts') 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 @@ +var konamiActivated = false; + +new Konami(function () { + + if (konamiActivated) return; + konamiActivated = true; + + console.log('Cheat console activated. Have fun!'); + + // play nice soundtrack + (new Audio('/assets/medias/sims2-university-theme.ogg')).play(); + + // display cheat console + var form = document.createElement('form'); + form.classList.add('cheat-form'); + form.setAttribute('method', 'post'); + form.setAttribute('action', '/console'); + + var field = document.createElement('input'); + field.setAttribute('type', 'text'); + field.setAttribute('name', 'command'); + field.setAttribute('autocomplete', 'off'); + + form.appendChild(field); + document.getElementsByTagName('body')[0].appendChild(form); + + field.focus(); + +}); 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 @@ -if (window.console) { - console.log("Welcome to your Play application's JavaScript!"); -} \ 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 @@ +/* + * Konami-JS ~ + * :: Now with support for touch events and multiple instances for + * :: those situations that call for multiple easter eggs! + * Code: http://konami-js.googlecode.com/ + * Examples: http://www.snaptortoise.com/konami-js + * Copyright (c) 2009 George Mandis (georgemandis.com, snaptortoise.com) + * Version: 1.4.2 (9/2/2013) + * Licensed under the MIT License (http://opensource.org/licenses/MIT) + * Tested in: Safari 4+, Google Chrome 4+, Firefox 3+, IE7+, Mobile Safari 2.2.1 and Dolphin Browser + */ + +var Konami = function (callback) { + var konami = { + addEvent: function (obj, type, fn, ref_obj) { + if (obj.addEventListener) + obj.addEventListener(type, fn, false); + else if (obj.attachEvent) { + // IE + obj["e" + type + fn] = fn; + obj[type + fn] = function () { + obj["e" + type + fn](window.event, ref_obj); + } + obj.attachEvent("on" + type, obj[type + fn]); + } + }, + input: "", + pattern: "38384040373937396665", + load: function (link) { + this.addEvent(document, "keydown", function (e, ref_obj) { + if (ref_obj) konami = ref_obj; // IE + konami.input += e ? e.keyCode : event.keyCode; + if (konami.input.length > konami.pattern.length) + konami.input = konami.input.substr((konami.input.length - konami.pattern.length)); + if (konami.input == konami.pattern) { + konami.code(link); + konami.input = ""; + e.preventDefault(); + return false; + } + }, this); + this.iphone.load(link); + }, + code: function (link) { + window.location = link + }, + iphone: { + start_x: 0, + start_y: 0, + stop_x: 0, + stop_y: 0, + tap: false, + capture: false, + orig_keys: "", + keys: ["UP", "UP", "DOWN", "DOWN", "LEFT", "RIGHT", "LEFT", "RIGHT", "TAP", "TAP"], + code: function (link) { + konami.code(link); + }, + load: function (link) { + this.orig_keys = this.keys; + konami.addEvent(document, "touchmove", function (e) { + if (e.touches.length == 1 && konami.iphone.capture == true) { + var touch = e.touches[0]; + konami.iphone.stop_x = touch.pageX; + konami.iphone.stop_y = touch.pageY; + konami.iphone.tap = false; + konami.iphone.capture = false; + konami.iphone.check_direction(); + } + }); + konami.addEvent(document, "touchend", function (evt) { + if (konami.iphone.tap == true) konami.iphone.check_direction(link); + }, false); + konami.addEvent(document, "touchstart", function (evt) { + konami.iphone.start_x = evt.changedTouches[0].pageX; + konami.iphone.start_y = evt.changedTouches[0].pageY; + konami.iphone.tap = true; + konami.iphone.capture = true; + }); + }, + check_direction: function (link) { + x_magnitude = Math.abs(this.start_x - this.stop_x); + y_magnitude = Math.abs(this.start_y - this.stop_y); + x = ((this.start_x - this.stop_x) < 0) ? "RIGHT" : "LEFT"; + y = ((this.start_y - this.stop_y) < 0) ? "DOWN" : "UP"; + result = (x_magnitude > y_magnitude) ? x : y; + result = (this.tap == true) ? "TAP" : result; + + if (result == this.keys[0]) this.keys = this.keys.slice(1, this.keys.length); + if (this.keys.length == 0) { + this.keys = this.orig_keys; + this.code(link); + } + } + } + } + + typeof callback === "string" && konami.load(callback); + if (typeof callback === "function") { + konami.code = callback; + konami.load(); + } + + return konami; +}; -- cgit v1.2.3