Skip to content

Commit

Permalink
Fix #1203: Selection: Make Edge ignore user-select
Browse files Browse the repository at this point in the history
Edge fools feature detection by populating both msUserSelect and
WebkitUserSelect.  This change forces Edge down the same code path as IE,
and removes redundant code that is already present in all versions of
Dojo that dgrid supports now.

(cherry picked from commit 7211f6d)
  • Loading branch information
Kenneth G. Franqueiro committed Jan 4, 2016
1 parent a32ae09 commit 689b997
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Alternatively, dgrid and its dependencies can be downloaded individually:
* [xstyle](https://github.com/kriszyp/xstyle)
* [put-selector](https://github.com/kriszyp/put-selector)
* [dstore](https://github.com/SitePen/dstore) for store-backed grids
* [The Dojo Toolkit](http://dojotoolkit.org) SDK version 1.8 or higher
* [The Dojo Toolkit](http://dojotoolkit.org) SDK version 1.8.2 or higher
* Out of the DTK components, Dojo core is the only hard dependency for dgrid;
however, some of the test pages also use components from Dijit, and
Dojox (namely grid for a comparison test, and mobile for a mobile page).
Expand Down Expand Up @@ -91,7 +91,7 @@ packages: [

# Browser and Dojo Version Support

dgrid 0.4 works with Dojo 1.8 or higher, and supports the following browsers:
dgrid 0.4 works with Dojo 1.8.2 or higher, and supports the following browsers:

* IE 8+
* Firefox latest + ESR
Expand Down
32 changes: 9 additions & 23 deletions Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,15 @@ define([
'dojo/has!touch?./util/touch',
'put-selector/put',
'dojo/query',
'dojo/_base/sniff'
'dojo/_base/sniff',
'dojo/dom' // for has('css-user-select') in 1.8.2+
], function (declare, on, has, aspect, List, touchUtil, put) {

has.add('dom-comparedocumentposition', function (global, doc, element) {
return !!element.compareDocumentPosition;
});

// Add feature test for user-select CSS property for optionally disabling
// text selection.
// (Can't use dom.setSelectable prior to 1.8.2 because of bad sniffs, see #15990)
has.add('css-user-select', function (global, doc, element) {
var style = element.style,
prefixes = ['Khtml', 'O', 'ms', 'Moz', 'Webkit'],
i = prefixes.length,
name = 'userSelect';

// Iterate prefixes from most to least likely
do {
if (typeof style[name] !== 'undefined') {
// Supported; return property name
return name;
}
} while (i-- && (name = prefixes[i] + 'UserSelect'));

// Not supported if we didn't return before now
return false;
});

// Also add a feature test for the onselectstart event, which offers a more
// Add a feature test for the onselectstart event, which offers a more
// graceful fallback solution than node.unselectable.
has.add('dom-selectstart', typeof document.onselectstart !== 'undefined');

Expand All @@ -46,6 +26,11 @@ define([
downType = hasPointer ? hasPointer + (hasMSPointer ? 'Down' : 'down') : 'mousedown',
upType = hasPointer ? hasPointer + (hasMSPointer ? 'Up' : 'up') : 'mouseup';

if (hasUserSelect === 'WebkitUserSelect' && typeof document.documentElement.style.msUserSelect !== 'undefined') {
// Edge defines both webkit and ms prefixes, rendering feature detects as brittle as UA sniffs...
hasUserSelect = false;
}

function makeUnselectable(node, unselectable) {
// Utility function used in fallback path for recursively setting unselectable
var value = node.unselectable = unselectable ? 'on' : '',
Expand Down Expand Up @@ -74,6 +59,7 @@ define([
// When using a modifier key, IE will select text inside of the element as well
// as outside of the element, because it thinks the selection started outside.
// Therefore, fall back to other means of blocking selection for IE10+.
// Newer versions of Dojo do not even report msUserSelect (see https://github.com/dojo/dojo/commit/7ae2a43).
if (hasUserSelect && hasUserSelect !== 'msUserSelect') {
node.style[hasUserSelect] = value;
}
Expand Down

0 comments on commit 689b997

Please sign in to comment.