move text selection to draggable private methods
This commit is contained in:
parent
9cbf2f5a41
commit
8313ea5497
@ -30,14 +30,14 @@ L.DomUtil = {
|
|||||||
return new L.Point(left, top);
|
return new L.Point(left, top);
|
||||||
},
|
},
|
||||||
|
|
||||||
translateOpen: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
|
TRANSLATE_OPEN: 'translate' + (L.Browser.webkit3d ? '3d(' : '('),
|
||||||
translateClose: L.Browser.webkit3d ? ',0)' : ')',
|
TRANSLATE_CLOSE: L.Browser.webkit3d ? ',0)' : ')',
|
||||||
|
|
||||||
setPosition: function(el, point) {
|
setPosition: function(el, point) {
|
||||||
el._leaflet_pos = point;
|
el._leaflet_pos = point;
|
||||||
if (L.Browser.webkit) {
|
if (L.Browser.webkit) {
|
||||||
el.style.webkitTransform = L.DomUtil.translateOpen +
|
el.style.webkitTransform = L.DomUtil.TRANSLATE_OPEN +
|
||||||
point.x + 'px,' + point.y + 'px' + L.DomUtil.translateClose;
|
point.x + 'px,' + point.y + 'px' + L.DomUtil.TRANSLATE_CLOSE;
|
||||||
} else {
|
} else {
|
||||||
el.style.left = point.x + 'px';
|
el.style.left = point.x + 'px';
|
||||||
el.style.top = point.y + 'px';
|
el.style.top = point.y + 'px';
|
||||||
@ -46,20 +46,5 @@ L.DomUtil = {
|
|||||||
|
|
||||||
getPosition: function(el) {
|
getPosition: function(el) {
|
||||||
return el._leaflet_pos;
|
return el._leaflet_pos;
|
||||||
},
|
|
||||||
|
|
||||||
// used for disabling text selection while dragging
|
|
||||||
disableTextSelection: function() {
|
|
||||||
if (document.selection && document.selection.empty) {
|
|
||||||
document.selection.empty();
|
|
||||||
}
|
|
||||||
if (!L.DomUtil._onselectstart) {
|
|
||||||
L.DomUtil._onselectstart = document.onselectstart;
|
|
||||||
document.onselectstart = function() { return false; };
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enableTextSelection: function() {
|
|
||||||
document.onselectstart = L.DomUtil._onselectstart;
|
|
||||||
L.DomUtil._onselectstart = null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* L.Draggable allows you to add dragging capabilities to any element. Supports mobile devices too.
|
||||||
|
*/
|
||||||
|
|
||||||
L.Draggable = L.Class.extend({
|
L.Draggable = L.Class.extend({
|
||||||
includes: L.Mixin.Events,
|
includes: L.Mixin.Events,
|
||||||
|
|
||||||
@ -10,8 +14,6 @@ L.Draggable = L.Class.extend({
|
|||||||
initialize: function(element, dragStartTarget) {
|
initialize: function(element, dragStartTarget) {
|
||||||
this._element = element;
|
this._element = element;
|
||||||
this._dragStartTarget = dragStartTarget || element;
|
this._dragStartTarget = dragStartTarget || element;
|
||||||
|
|
||||||
this.enable();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
enable: function() {
|
enable: function() {
|
||||||
@ -31,16 +33,14 @@ L.Draggable = L.Class.extend({
|
|||||||
|
|
||||||
L.DomEvent.preventDefault(e);
|
L.DomEvent.preventDefault(e);
|
||||||
|
|
||||||
if (e.touches) {
|
if (e.touches && e.touches.length > 1) { return; }
|
||||||
if (e.touches.length == 1) { e = e.touches[0]; }
|
if (e.touches && e.touches.length == 1) { e = e.touches[0]; }
|
||||||
else return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dragStartPos = L.DomUtil.getPosition(this._element);
|
this._dragStartPos = L.DomUtil.getPosition(this._element);
|
||||||
this._startX = e.clientX;
|
this._startX = e.clientX;
|
||||||
this._startY = e.clientY;
|
this._startY = e.clientY;
|
||||||
|
|
||||||
L.DomUtil.disableTextSelection();
|
this._disableTextSelection();
|
||||||
|
|
||||||
this._setMovingCursor();
|
this._setMovingCursor();
|
||||||
|
|
||||||
@ -51,10 +51,8 @@ L.Draggable = L.Class.extend({
|
|||||||
_onMove: function(e) {
|
_onMove: function(e) {
|
||||||
L.DomEvent.preventDefault(e);
|
L.DomEvent.preventDefault(e);
|
||||||
|
|
||||||
if (e.touches) {
|
if (e.touches && e.touches.length > 1) { return; }
|
||||||
if (e.touches.length == 1) { e = e.touches[0]; }
|
if (e.touches && e.touches.length == 1) { e = e.touches[0]; }
|
||||||
else return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var offset = new L.Point(e.clientX - this._startX, e.clientY - this._startY),
|
var offset = new L.Point(e.clientX - this._startX, e.clientY - this._startY),
|
||||||
newPos = this._dragStartPos.add(offset);
|
newPos = this._dragStartPos.add(offset);
|
||||||
@ -70,7 +68,7 @@ L.Draggable = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_onUp: function(e) {
|
_onUp: function(e) {
|
||||||
L.DomUtil.enableTextSelection();
|
this._enableTextSelection();
|
||||||
|
|
||||||
this._restoreCursor();
|
this._restoreCursor();
|
||||||
|
|
||||||
@ -87,5 +85,20 @@ L.Draggable = L.Class.extend({
|
|||||||
|
|
||||||
_restoreCursor: function() {
|
_restoreCursor: function() {
|
||||||
document.body.style.cursor = this._bodyCursor;
|
document.body.style.cursor = this._bodyCursor;
|
||||||
|
},
|
||||||
|
|
||||||
|
_disableTextSelection: function() {
|
||||||
|
if (document.selection && document.selection.empty) {
|
||||||
|
document.selection.empty();
|
||||||
|
}
|
||||||
|
if (!this._onselectstart) {
|
||||||
|
this._onselectstart = document.onselectstart;
|
||||||
|
document.onselectstart = L.Util.falseFn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_enableTextSelection: function() {
|
||||||
|
document.onselectstart = this._onselectstart;
|
||||||
|
this._onselectstart = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user