How to unregister a Magento prototype event handler

Hello folks, in this article we’ll describe how to unregister an existing Magento prototype event handler and replace it with your custom one. For example, we will replace a Magento default search pop-up using better way.

Screenshot Default Search Pop-up

First of all, you should know the search field id and the event that you want to replace. In our case, the id is “search” and the event is “keydown”. Here is how we can do it:

  //unbind system keydown action

After this, you can set your custom handler to the keydown action. Please, look through the following example:

 //new keydown action
var PrettyPopup = Class.create();

PrettyPopup.prototype = {

    getResponse: function(data)
        //Show response
        $('search_autocomplete').innerHTML = data.responseText;
        //Restore default icon in search field
        $('search').setStyle({background: 'white'});

    showPopup: function() {
        //hide pop-up
        //search criteria
        var textQuery = $(;
        //check if exist value
        if (textQuery == '') {
            return false;

        //reset timer

        var nested = this;

        this.searchTimer = setTimeout(function() {
            //show loading icon
            $({ background:  "white url(" + atwixImagePath + "opc-ajax-loader.gif) no-repeat right" });
            //AJAX request
            new Ajax.Request(
                atwixBasePath + "catalogsearch/ajax/suggest/",
                {method: 'get', parameters: "q=" + textQuery, onComplete: nested.getResponse}

        return true;


    initialize: function(id) { = id;
        //unbind system keydown action
        //init timer variable
        this.searchTimer = 1;
        Event.observe(, 'keyup', this.showPopup.bind(this));

Event.observe(document, 'dom:loaded', function(){
    new PrettyPopup('search');

We have created a module which is called “Pretty Popup Search” (community edition compatible) with the described feature. You can download it on GitHub and check it out, see the link

At final, we have got something like this:
Screenshot with result. Search popup

Thank you for attention, always glad to read your comments :)