﻿var GWconsole, GWConsole_content, GWconsole_input; var GWconsole_visible = false; var GWConsoleCommands = [{ name: "Auto Complete Form", command: "ac", func: GWConsole_Command_AutoComplete }, { name: "Reset form", command: "resetform", func: GWConsole_Command_ClearForm }, { name: "Change console colour", command: "colour", func: GWConsole_Command_ChangeColour }, { name: "Exit Console", command: "exit", func: GWConsole_Command_Close }, { name: "Show this help", command: "help", func: GWConsole_OutputCommmands }, { name: "Clear Console", command: "cls", func: GWConsole_Clear}]; var welcomeTxt = "GradWeb 2.0 Console - Copyright (c) 2009 GradWeb Ltd."; function GWConsole_Setup() { $(document).keyup(GWConsole_CheckKeySequence) } var seq = [38, 38, 40, 40, 37, 39, 37, 39]; var seqPos = 0; var seqTimeout = null; function GWConsole_CheckKeySequence(b) { var a = b.keyCode; if (seq[seqPos] == a) { if (seqPos == seq.length - 1) { seqPos = 0; clearTimeout(seqTimeout); GWConsole_Toggle() } else { if (seqTimeout) { clearTimeout(seqTimeout) } seqTimeout = setTimeout(GWConsole_SequenceTimeout, 750); seqPos++ } } else { seqPos = 0 } } function GWConsole_SequenceTimeout() { seqPos = 0; seqTimeout = null } function GWConsole_Toggle() { if (!GWconsole_visible) { if (GWconsole === undefined) { var b = "<div id='GWconsole'><div id='GWConsoleContainer'><div id='GWConsoleContent'></div><div> &gt; <input type='text' id='GWConsole_Input' /></div></div></div>"; var a = $(document).width(); $("body").prepend(b); GWconsole = document.getElementById("GWconsole"); GWconsole_input = document.getElementById("GWConsole_Input"); GWConsole_content = document.getElementById("GWConsoleContent"); var c = readCookie("GWCONSOLE_COLOUR"); if (c !== null) { GWConsole_Command_ChangeColour(c) } } GWConsole_UpdateWidth(); $(window).resize(GWConsole_UpdateWidth); $(GWconsole_input).keyup(GWConsole_InputKeyUp); $(GWconsole).click(GWConsole_Clicked); GWconsole_visible = true; GWConsole_Clear(); GWConsole_Output("Welcome to GradWeb Console! Please enter a command. (For a list of commands type 'help') "); $(GWconsole).slideDown("normal", function() { GWconsole_input.focus() }) } else { $(GWconsole).slideUp(); $(window).unbind("resize"); $(GWconsole_input).unbind("keyup"); $(GWconsole).unbind("click"); GWconsole_visible = false; GWConsole_Setup() } } function GWConsole_OutputCommmands() { for (i = 0; i < GWConsoleCommands.length; i++) { var a = GWConsoleCommands[i]; if (a.hidden !== true) { GWConsole_Output(a.command + " - " + a.name) } } GWConsole_ScrollBottom() } function GWConsole_InputKeyUp(a) { switch (a.keyCode) { case 13: GWConsole_ProcessCommand(); break; case 27: GWConsole_Toggle(); break } } function GWConsole_ProcessCommand() { var b = new RegExp(/([a-z]+)(?: ([a-z\-]+))?/i); var a = b.exec(GWconsole_input.value); GWconsole_input.value = ""; if (a === null) { return } var e = a[1]; var d = a[2]; var c = null; jQuery.each(GWConsoleCommands, function() { if (e == this.command) { c = this } }); if (c == null) { GWConsole_Output("Command '" + e + "' not found. Type 'help' for a list of commands") } else { c.func(d) } } function GWConsole_UpdateWidth() { var a = $(document).width(); $(GWconsole).width(a) } function GWConsole_Output(a) { $("#GWConsoleContent").append("<p>" + a + "</p>") } function GWConsole_Clicked(a) { GWConsole_ScrollBottom() } function GWConsole_ScrollBottom() { $(GWconsole).attr({ scrollTop: $(GWconsole).attr("scrollHeight") }); GWconsole_input.focus() } function GWConsole_Clear() { $("#GWConsoleContent").html(""); $("#GWConsoleContent").append("<p><strong>" + welcomeTxt + "</strong></p>") } function GWConsole_Command_ChangeColour(b) { if (b === undefined) { GWConsole_Output("You need to choose a colour!"); GWConsole_Output("Type 'colour [colourChoice]' (options are green and pink)"); GWConsole_ScrollBottom(); return } var a; switch (b) { case "pink": a = "#FF38DE"; break; case "green": default: a = "lime"; b = "green"; break } $(GWconsole).css("color", a); $(GWconsole_input).css("color", a); createCookie("GWCONSOLE_COLOUR", b) } function GWConsole_Command_AutoComplete() { GWConsole_Clear(); GWConsole_Output("GradWeb AutoComplete"); var c = $("form#frmMain input").each(AutoComplete_Input).length; GWConsole_Output("AutoFilled " + c + " input fields"); var b = $("form#frmMain select").each(AutoComplete_Select).length; GWConsole_Output("AutoFilled " + b + " select fields"); var a = $("form#frmMain textarea").each(AutoComplete_Textarea).length; GWConsole_Output("AutoFilled " + a + " textareas"); GWConsole_Output("AutoComplete Complete - Type exit to close the console"); GWConsole_ScrollBottom() } function GWConsole_Command_Close() { GWConsole_Toggle() } function AutoComplete_Input() { var a = this; switch (a.type) { case "text": var b; if ($(a).hasClass("dateObject")) { b = "17/03/89" } else { b = AutoComplete_GenerateWords(5) } a.value = b; break; case "checkbox": case "radio": if (a.parentNode.className != "UDFDeleteCheckbox") { a.checked = true } break } } function AutoComplete_Select() { var b = this; var a = Math.ceil(Math.random() * (b.length - 1)); b.selectedIndex = a } function AutoComplete_Textarea() { var c = this; var d = new RegExp(/count\[([0-9]+)\]/); var b = d.exec(c.className); var a; if (b === null) { a = 10 } else { a = parseInt(b[1], 10) } c.value = AutoComplete_GenerateWords(a); c.focus(); c.blur() } var words = ["apple", "ball", "car", "dog", "dinosaur", "lollypop", "water", "phone", "socks", "face", "glass", "heart", "trousers", "job", "zebra", "lake", "monkey", "nice", "olive", "presto", "queen", "ready", "solid", "time"]; function AutoComplete_GenerateWords(a) { var c = ""; for (i = 0; i < a; i++) { var b = Math.floor(Math.random() * (words.length - 1)); c += words[b] + " " } return c } function createCookie(c, d) { var b = new Date(); b.setTime(b.getTime() + 31536000000); var a = "; expires=" + b.toGMTString(); document.cookie = c + "=" + d + a + "; path=/" } function readCookie(b) { var e = b + "="; var a = document.cookie.split(";"); for (var d = 0; d < a.length; d++) { var f = a[d]; while (f.charAt(0) == " ") { f = f.substring(1, f.length) } if (f.indexOf(e) == 0) { return f.substring(e.length, f.length) } } return null } function GWConsole_Command_ClearForm() { $("form#frmMain input").each(Clear_Input); $("form#frmMain select").each(Clear_Select); $("form#frmMain textarea").each(Clear_Textarea); GWConsole_Output("Form Reset - Type exit to close the console"); GWConsole_ScrollBottom() } function Clear_Input() { var a = this; switch (a.type) { case "text": a.value = ""; break; case "checkbox": case "radio": a.checked = false; break } } function Clear_Textarea() { this.value = "" } function Clear_Select() { this.selectedIndex = 0 };
