heron
heron

Reputation: 3659

Javascript function work on all page except textareas, text boxes

My function (which is shown below) dedicated for "copy-protecting" page.(actually it's only visual thing. Advanced user can get from source code.) What I want to do get this function work on all page parts except textareas, textboxes. How can I achieve this result?

(function($){

    $.fn.ctrl = function(key, callback) {
        if(typeof key != 'object') key = [key];
        callback = callback || function(){
            return false;
        }
        return $(this).keydown(function(e) {
            var ret = true;
            $.each(key,function(i,k){
                if(e.keyCode == k.toUpperCase().charCodeAt(0) && e.ctrlKey) {
                    ret = callback(e);
                }
            });
            return ret;
        });
    };


    $.fn.disableSelection = function() {
        $(window).ctrl(['a','s','c']);
        return this.each(function() {           
            $(this).attr('unselectable', 'on')
            .css({
                '-moz-user-select':'none',
                '-o-user-select':'none',
                '-khtml-user-select':'none',
                '-webkit-user-select':'none',
                '-ms-user-select':'none',
                'user-select':'none'
            })
            .each(function() {
                $(this).attr('unselectable','on')
                .bind('selectstart',function(){
                    return false;
                });
            });
        });
    }
})(jQuery);

Upvotes: 0

Views: 133

Answers (1)

Jamiec
Jamiec

Reputation: 136154

You should be able to do

$('*').not('textarea, input[type="text"]').disableSelection();

Upvotes: 2

Related Questions