web 2.0

Tuesday, November 24, 2009

Konami Code & Dynamics CRM

There's a buzz going around something called "Konami Code". I've recently heard of it from a colleague who entered the Code on Facebook and got a bunch of spins and circles (type the following keys while on your facebook Page, wait a bit and then scroll up and down the page: "UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","B","A","ENTER KEY") - Pretty Cool !! 

Following a small search on the net, it turns out that the code is purely Jscript and the same code can be used in CRM forms to enable/disable functionality if needed - for example you can alter the script and set up your own code to hide/unhide tabs and fields, trigger hidden functionality perhaps.

I am listing below the code i found, i updated the pattern to remove the "A" & "B" key strikes (you will see that it was made with "iphone" support, but it still works - of course you can amend the code and I am sure you can find another version on the Net as well):
------------------------------------------------------------------------
var konami = {
    input:"",
    pattern:"383840403739373913",
    clear:setTimeout('konami.clear_input()',2000),
    load: function(link) {
        window.document.onkeydown = function(e) {
            konami.input+= e ? e.keyCode : event.keyCode;
            if (konami.input == konami.pattern) {
                konami.code(link);
                clearTimeout(konami.clear);
                return;
                }
            clearTimeout(konami.clear);
            konami.clear = setTimeout("konami.clear_input()",2000);
            }
            this.iphone.load(link)
        },
    code: function(link) { window.location=link},
    clear_input: function() {
        konami.input="";
        clearTimeout(konami.clear);
        },
    iphone:{
        start_x:0,
        start_y:0,
        stop_x:0,
        stop_y:0,
        tap:false,
        capture:false,
        keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT"],
        code: function(link) { window.location=link},
        load: function(link){
            document.ontouchmove = function(e){
              if(e.touches.length == 1 && konami.iphone.capture==true){ // Only deal with one finger
                var touch = e.touches[0]; // Get info for finger #1
                konami.iphone.stop_x = touch.pageX;
                konami.iphone.stop_y = touch.pageY;
                konami.iphone.tap = false;
                konami.iphone.capture=false;
                konami.iphone.check_direction();
                  }
                }      
            document.ontouchend = function(evt){
                if (konami.iphone.tap==true) konami.iphone.check_direction();      
                }
            document.ontouchstart = 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(){
            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.code(this.link)
            }
        }
}
konami.code = function() {
// CRM Code Goes here -


// Dummy Sample to enter & display  firstname and lastname in the contact entity:


crmForm.firstname.DataValue = "First Name";
crmForm.lastname.DataValue = "Last Name";
        }
    konami.load()

------------------------------------------------------------------------
Cheers,
M.G

No comments:

Post a Comment