Created
August 27, 2010 15:24
-
-
Save kswedberg/553566 to your computer and use it in GitHub Desktop.
This file contains 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 elem = document.createElement("div"), | |
style = elem.style, | |
userSelectProp = "userSelect" in style && "userSelect"; | |
if (!userSelectProp) { | |
$.each("Moz Webkit Khtml O".split(" "), function(i, v) { | |
var vendorProp = v + "UserSelect"; | |
if ( vendorProp in style ) { | |
userSelectProp = vendorProp; | |
return false; | |
} | |
}); | |
} | |
var selectStart = !userSelectProp && "onselectstart" in elem && "selectstart.mouse"; | |
elem = null; | |
$.fn.extend({ | |
disableSelection: function() { | |
if (unselectableProp) { | |
this.css(userSelectProp, "none"); | |
} else { | |
this.find( "*" ).andSelf().attr( "unselectable", "on" ); | |
} | |
if (selectStart) { | |
this.bind(selectStart, function() { | |
return false; | |
}); | |
} | |
return this; | |
}, | |
enableSelection: function() { | |
if (unselectableProp) { | |
this.css(userSelectProp, ""); | |
} else { | |
this.find( "*" ).andSelf().attr( "unselectable", "off" ); | |
} | |
if (selectStart) { | |
this.unbind(selectStart); | |
} | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment