]> source.dussan.org Git - jquery-ui.git/commitdiff
Core: Fixed .disableSelect() and .enableSelect() in all browsers. Fixes #5723 - disab...
authorScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 16:00:59 +0000 (12:00 -0400)
committerScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 16:00:59 +0000 (12:00 -0400)
ui/jquery.ui.core.js

index 3199e7ff7fa42ac59cbb528ce4ba2a1659bb55fa..364d7b668e6120a2db74e1bef30e4de3e275ecc4 100644 (file)
@@ -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(),