Skip to content

Commit

Permalink
Core: Refactored .disableSelection() and .enableSelection().
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Sep 1, 2010
1 parent 95a3459 commit 5de8ced
Showing 1 changed file with 12 additions and 51 deletions.
63 changes: 12 additions & 51 deletions ui/jquery.ui.core.js
Expand Up @@ -115,59 +115,20 @@ $.fn.extend({
}

return 0;
}
});

(function() {
var elem = document.createElement( "div" ),
style = elem.style,
userSelectProp = "userSelect" in style && "userSelect";
},

disableSelection: function() {
return this.bind(
"mousedown.ui-disableSelection selectstart.ui-disableSelection",
function( event ) {
event.preventDefault();
});
},

if ( !userSelectProp ) {
$.each( [ "Moz", "Webkit", "Khtml" ], function( i, prefix ) {
var vendorProp = prefix + "UserSelect";
if ( vendorProp in style ) {
userSelectProp = vendorProp;
return false;
}
});
enableSelection: function() {
return this.unbind( ".ui-disableSelection" );
}
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" ],
Expand Down

2 comments on commit 5de8ced

@rdworth
Copy link
Contributor

@rdworth rdworth commented on 5de8ced Sep 1, 2010

Choose a reason for hiding this comment

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

Beautiful!

@jzaefferer
Copy link
Member

Choose a reason for hiding this comment

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

Wait, thats all?

Please sign in to comment.