Skip to content

Commit 5de8ced

Browse files
committed
Core: Refactored .disableSelection() and .enableSelection().
1 parent 95a3459 commit 5de8ced

File tree

1 file changed

+12
-51
lines changed

1 file changed

+12
-51
lines changed

ui/jquery.ui.core.js

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -115,59 +115,20 @@ $.fn.extend({
115115
}
116116

117117
return 0;
118-
}
119-
});
120-
121-
(function() {
122-
var elem = document.createElement( "div" ),
123-
style = elem.style,
124-
userSelectProp = "userSelect" in style && "userSelect";
118+
},
119+
120+
disableSelection: function() {
121+
return this.bind(
122+
"mousedown.ui-disableSelection selectstart.ui-disableSelection",
123+
function( event ) {
124+
event.preventDefault();
125+
});
126+
},
125127

126-
if ( !userSelectProp ) {
127-
$.each( [ "Moz", "Webkit", "Khtml" ], function( i, prefix ) {
128-
var vendorProp = prefix + "UserSelect";
129-
if ( vendorProp in style ) {
130-
userSelectProp = vendorProp;
131-
return false;
132-
}
133-
});
128+
enableSelection: function() {
129+
return this.unbind( ".ui-disableSelection" );
134130
}
135-
var selectStart = !userSelectProp && "onselectstart" in elem && "selectstart.mouse";
136-
137-
elem = null;
138-
139-
$.fn.extend({
140-
disableSelection: function() {
141-
if ( userSelectProp ) {
142-
this.css( userSelectProp, "none" );
143-
} else {
144-
this.find( "*" ).andSelf().attr( "unselectable", "on" );
145-
}
146-
147-
if ( selectStart ) {
148-
this.bind( selectStart, function() {
149-
return false;
150-
});
151-
}
152-
153-
return this;
154-
},
155-
156-
enableSelection: function() {
157-
if ( userSelectProp ) {
158-
this.css( userSelectProp, "" );
159-
} else {
160-
this.find( "*" ).andSelf().attr( "unselectable", "off" );
161-
}
162-
163-
if ( selectStart ) {
164-
this.unbind( selectStart );
165-
}
166-
167-
return this;
168-
}
169-
});
170-
})();
131+
});
171132

172133
$.each( [ "Width", "Height" ], function( i, name ) {
173134
var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],

0 commit comments

Comments
 (0)