Created
February 3, 2012 13:55
-
-
Save nalanj/1730273 to your computer and use it in GitHub Desktop.
Class for disabling and re-enabling text selection across the entire document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var TextSelection; | |
| TextSelection = (function() { | |
| function TextSelection() {} | |
| TextSelection.returnFalse = function() { | |
| return false; | |
| }; | |
| TextSelection.disable = function() { | |
| $('body').css({ | |
| "-moz-user-select": "none", | |
| "-webkit-user-select": "none", | |
| "-ms-user-select": "none" | |
| }); | |
| $(document).mousedown(function() { | |
| return this.returnFalse; | |
| }); | |
| if ($.browser.msie || $.browser.opera) { | |
| return $('*').attr("unselectable", "on"); | |
| } | |
| }; | |
| TextSelection.enable = function() { | |
| $('body').css({ | |
| "-moz-user-select": "auto", | |
| "-webkit-user-select": "auto", | |
| "-ms-user-select": "auto" | |
| }); | |
| if ($.browser.msie || $.browser.opera) { | |
| return $('*').attr("unselectable", "off"); | |
| } | |
| }; | |
| return TextSelection; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment