Skip to content

Commit

Permalink
Core: Fixed .disableSelect() and .enableSelect() in all browsers. Fix…
Browse files Browse the repository at this point in the history
…es #5723 - disableSelection() doesn't work cross-browser.
  • Loading branch information
scottgonzalez committed Aug 27, 2010
1 parent a3d9a91 commit 16e93d5
Showing 1 changed file with 51 additions and 12 deletions.
63 changes: 51 additions & 12 deletions ui/jquery.ui.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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(),
Expand Down

1 comment on commit 16e93d5

@jzaefferer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crazy. Good thing we got this fixed finally, guess also kudos to Karl.

Please sign in to comment.