Skip to content

Instantly share code, notes, and snippets.

@nalanj
Created February 3, 2012 13:55
Show Gist options
  • Select an option

  • Save nalanj/1730273 to your computer and use it in GitHub Desktop.

Select an option

Save nalanj/1730273 to your computer and use it in GitHub Desktop.
Class for disabling and re-enabling text selection across the entire document
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