mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Remove unnecessary overrides of selectstart dragstart on view.
And simplify DomEvent.add() / remove(), as we don't need support for multiple types in one entry anymore.
This commit is contained in:
parent
8b0340e6df
commit
0780a87429
2 changed files with 29 additions and 45 deletions
|
@ -17,21 +17,13 @@
|
||||||
*/
|
*/
|
||||||
var DomEvent = /** @lends DomEvent */{
|
var DomEvent = /** @lends DomEvent */{
|
||||||
add: function(el, events) {
|
add: function(el, events) {
|
||||||
for (var type in events) {
|
for (var type in events)
|
||||||
var func = events[type],
|
el.addEventListener(type, events[type], false);
|
||||||
parts = type.split(/[\s,]+/g);
|
|
||||||
for (var i = 0, l = parts.length; i < l; i++)
|
|
||||||
el.addEventListener(parts[i], func, false);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function(el, events) {
|
remove: function(el, events) {
|
||||||
for (var type in events) {
|
for (var type in events)
|
||||||
var func = events[type],
|
el.removeEventListener(type, events[type], false);
|
||||||
parts = type.split(/[\s,]+/g);
|
|
||||||
for (var i = 0, l = parts.length; i < l; i++)
|
|
||||||
el.removeEventListener(parts[i], func, false);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getPoint: function(event) {
|
getPoint: function(event) {
|
||||||
|
|
|
@ -43,10 +43,10 @@ var View = Base.extend(Emitter, /** @lends View# */{
|
||||||
// Borrowed from Hammer.js:
|
// Borrowed from Hammer.js:
|
||||||
var none = 'none';
|
var none = 'none';
|
||||||
DomElement.setPrefixed(element.style, {
|
DomElement.setPrefixed(element.style, {
|
||||||
|
userDrag: none,
|
||||||
userSelect: none,
|
userSelect: none,
|
||||||
touchCallout: none,
|
touchCallout: none,
|
||||||
contentZooming: none,
|
contentZooming: none,
|
||||||
userDrag: none,
|
|
||||||
tapHighlightColor: 'rgba(0,0,0,0)'
|
tapHighlightColor: 'rgba(0,0,0,0)'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -786,39 +786,31 @@ new function() { // Injection scope for mouse events on the browser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewEvents = {
|
var viewEvents = {},
|
||||||
'selectstart dragstart': function(event) {
|
docEvents = {
|
||||||
// Only stop this even if we're mouseDown already, since otherwise
|
// NOTE: mouseleave does not seem to work on document in IE:
|
||||||
// no text whatsoever can be selected on the page.
|
mouseout: function(event) {
|
||||||
if (mouseDown)
|
// When the moues leaves the document, fire one last mousemove
|
||||||
event.preventDefault();
|
// event, to give items the change to receive a mouseleave, etc.
|
||||||
}
|
var view = View._focused,
|
||||||
};
|
target = DomEvent.getRelatedTarget(event);
|
||||||
|
if (view && (!target || target.nodeName === 'HTML')) {
|
||||||
|
// See #800 for this bizarre workaround for an issue of
|
||||||
|
// Chrome on Windows:
|
||||||
|
// TODO: Remove again after Dec 2016, once fixed in Chrome.
|
||||||
|
var offset = DomEvent.getOffset(event, view._element),
|
||||||
|
x = offset.x,
|
||||||
|
abs = Math.abs,
|
||||||
|
ax = abs(x),
|
||||||
|
max = 1 << 25,
|
||||||
|
diff = ax - max;
|
||||||
|
offset.x = abs(diff) < ax ? diff * (x < 0 ? -1 : 1) : x;
|
||||||
|
handleMouseMove(view, event, view.viewToProject(offset));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
var docEvents = {
|
scroll: updateFocus
|
||||||
// NOTE: mouseleave does not seem to work on document in IE:
|
};
|
||||||
mouseout: function(event) {
|
|
||||||
// When the moues leaves the document, fire one last mousemove
|
|
||||||
// event, to give items the change to receive a mouseleave, etc.
|
|
||||||
var view = View._focused,
|
|
||||||
target = DomEvent.getRelatedTarget(event);
|
|
||||||
if (view && (!target || target.nodeName === 'HTML')) {
|
|
||||||
// See #800 for this bizarre workaround for an issue of Chrome
|
|
||||||
// on Windows:
|
|
||||||
// TODO: Remove again after Dec 2016 once it is fixed in Chrome.
|
|
||||||
var offset = DomEvent.getOffset(event, view._element),
|
|
||||||
x = offset.x,
|
|
||||||
abs = Math.abs,
|
|
||||||
ax = abs(x),
|
|
||||||
max = 1 << 25,
|
|
||||||
diff = ax - max;
|
|
||||||
offset.x = abs(diff) < ax ? diff * (x < 0 ? -1 : 1) : x;
|
|
||||||
handleMouseMove(view, event, view.viewToProject(offset));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
scroll: updateFocus
|
|
||||||
};
|
|
||||||
|
|
||||||
// mousemove and mouseup events need to be installed on document, not the
|
// mousemove and mouseup events need to be installed on document, not the
|
||||||
// view element, since we want to catch the end of drag events even outside
|
// view element, since we want to catch the end of drag events even outside
|
||||||
|
|
Loading…
Reference in a new issue