bebraw
11/7/2010 - 12:12 PM

disabletextselection.js

        // http://stackoverflow.com/questions/891581
        var stopDefault = function(e) {
            if('target' in e._) {
                var targetName = e._.target.tagName;

                if(targetName == 'INPUT' || targetName == 'TEXTAREA') {
                    return;
                }
            }

            // XXX: preventDefault doesn't obviously let focusing work (input still remains focused)
            // any ideas how to work past this issue?

            if(e.preventDefault) {
                e.preventDefault();
            }
            else {
                document.event.returnValue = false;
            }
        }

        // http://stackoverflow.com/questions/3375056
        $(document).on('selectstart', stopDefault); // ie
        $(document).on('mousedown', stopDefault); // mozilla