aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2010-08-27 12:00:59 -0400
committerScott González <scott.gonzalez@gmail.com>2010-08-27 12:00:59 -0400
commit16e93d5189a5aed10df23e85b5d40b14d126eede (patch)
tree48fe8c2a4a4934d28b4fa1d09a551ea68e97d4b2
parenta3d9a91661f83e1f890d079181d58cb195c96d44 (diff)
downloadjquery-ui-16e93d5189a5aed10df23e85b5d40b14d126eede.tar.gz
jquery-ui-16e93d5189a5aed10df23e85b5d40b14d126eede.zip
Core: Fixed .disableSelect() and .enableSelect() in all browsers. Fixes #5723 - disableSelection() doesn't work cross-browser.
-rw-r--r--ui/jquery.ui.core.js63
1 files changed, 51 insertions, 12 deletions
diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js
index 3199e7ff7..364d7b668 100644
--- a/ui/jquery.ui.core.js
+++ b/ui/jquery.ui.core.js
@@ -73,18 +73,6 @@ $.fn.extend({
this._focus.apply( this, arguments );
},
- enableSelection: function() {
- return this
- .attr( "unselectable", "off" )
- .css( "MozUserSelect", "" );
- },
-
- disableSelection: function() {
- return this
- .attr( "unselectable", "on" )
- .css( "MozUserSelect", "none" );
- },
-
scrollParent: function() {
var scrollParent;
if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
@@ -130,6 +118,57 @@ $.fn.extend({
}
});
+(function() {
+ var elem = document.createElement( "div" ),
+ style = elem.style,
+ userSelectProp = "userSelect" in style && "userSelect";
+
+ if ( !userSelectProp ) {
+ $.each( [ "Moz", "Webkit", "Khtml" ], function( i, prefix ) {
+ var vendorProp = prefix + "UserSelect";
+ if ( vendorProp in style ) {
+ userSelectProp = vendorProp;
+ return false;
+ }
+ });
+ }
+ var selectStart = !userSelectProp && "onselectstart" in elem && "selectstart.mouse";
+
+ elem = null;
+
+ $.fn.extend({
+ disableSelection: function() {
+ if ( userSelectProp ) {
+ this.css( userSelectProp, "none" );
+ } else {
+ this.find( "*" ).andSelf().attr( "unselectable", "on" );
+ }
+
+ if ( selectStart ) {
+ this.bind( selectStart, function() {
+ return false;
+ });
+ }
+
+ return this;
+ },
+
+ enableSelection: function() {
+ if ( userSelectProp ) {
+ this.css( userSelectProp, "" );
+ } else {
+ this.find( "*" ).andSelf().attr( "unselectable", "off" );
+ }
+
+ if ( selectStart ) {
+ this.unbind( selectStart );
+ }
+
+ return this;
+ }
+ });
+})();
+
$.each( [ "Width", "Height" ], function( i, name ) {
var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
type = name.toLowerCase(),