[Pkg-javascript-commits] [leaflet] 195/301: Prefer selectstart to user-select
Jonas Smedegaard
js at moszumanska.debian.org
Mon Jan 27 22:22:50 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet.
commit dd063b26a1cbd05cd072d21afb7436b60735c8d1
Author: John Firebaugh <john.firebaugh at gmail.com>
Date: Wed Nov 6 16:04:27 2013 -0800
Prefer selectstart to user-select
Rather than both setting user-select to none and suppressing the selectstart
event, we now prefer to suppress the selectstart event if supported. This avoids
redundantly setting the user-select style, which can be slow. Fixes #2163.
---
src/dom/DomUtil.js | 50 +++++++++++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js
index 6874a6c..186cfde 100644
--- a/src/dom/DomUtil.js
+++ b/src/dom/DomUtil.js
@@ -224,27 +224,39 @@ L.DomUtil.TRANSITION_END =
L.DomUtil.TRANSITION + 'End' : 'transitionend';
(function () {
- var userSelectProperty = L.DomUtil.testProp(
- ['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']);
+ if ('onselectstart' in document) {
+ L.extend(L.DomUtil, {
+ disableTextSelection: function () {
+ L.DomEvent.on(window, 'selectstart', L.DomEvent.preventDefault);
+ },
+
+ enableTextSelection: function () {
+ L.DomEvent.off(window, 'selectstart', L.DomEvent.preventDefault);
+ }
+ });
+ } else {
+ var userSelectProperty = L.DomUtil.testProp(
+ ['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']);
+
+ L.extend(L.DomUtil, {
+ disableTextSelection: function () {
+ if (userSelectProperty) {
+ var style = document.documentElement.style;
+ this._userSelect = style[userSelectProperty];
+ style[userSelectProperty] = 'none';
+ }
+ },
+
+ enableTextSelection: function () {
+ if (userSelectProperty) {
+ document.documentElement.style[userSelectProperty] = this._userSelect;
+ delete this._userSelect;
+ }
+ }
+ });
+ }
L.extend(L.DomUtil, {
- disableTextSelection: function () {
- L.DomEvent.on(window, 'selectstart', L.DomEvent.preventDefault);
- if (userSelectProperty) {
- var style = document.documentElement.style;
- this._userSelect = style[userSelectProperty];
- style[userSelectProperty] = 'none';
- }
- },
-
- enableTextSelection: function () {
- L.DomEvent.off(window, 'selectstart', L.DomEvent.preventDefault);
- if (userSelectProperty) {
- document.documentElement.style[userSelectProperty] = this._userSelect;
- delete this._userSelect;
- }
- },
-
disableImageDrag: function () {
L.DomEvent.on(window, 'dragstart', L.DomEvent.preventDefault);
},
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git
More information about the Pkg-javascript-commits
mailing list