mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Improve handling of temporary view focus switch in mousemove.
Closes #841
This commit is contained in:
parent
edcb2a3868
commit
cee3959bfa
2 changed files with 25 additions and 5 deletions
|
@ -84,14 +84,14 @@ var DomElement = new function() {
|
|||
},
|
||||
|
||||
/**
|
||||
* Checks if element is invisibile (display: none, ...)
|
||||
* Checks if element is invisibile (display: none, ...).
|
||||
*/
|
||||
isInvisible: function(el) {
|
||||
return DomElement.getSize(el).equals(new Size(0, 0));
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if element is visibile in current viewport
|
||||
* Checks if element is visibile in current viewport.
|
||||
*/
|
||||
isInView: function(el) {
|
||||
// See if the viewport bounds intersect with the windows rectangle
|
||||
|
@ -101,6 +101,13 @@ var DomElement = new function() {
|
|||
DomElement.getBounds(el, true));
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if element is inside the DOM.
|
||||
*/
|
||||
isInserted: function(el) {
|
||||
return document.body.contains(el);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the given property from the element, trying out all browser
|
||||
* prefix variants.
|
||||
|
|
|
@ -407,12 +407,21 @@ var View = Base.extend(Emitter, /** @lends View# */{
|
|||
* Checks whether the view is currently visible within the current browser
|
||||
* viewport.
|
||||
*
|
||||
* @return {Boolean} whether the view is visible
|
||||
* @return {Boolean} {@true if the view is visible}
|
||||
*/
|
||||
isVisible: function() {
|
||||
return DomElement.isInView(this._element);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the view is inserted into the browser DOM.
|
||||
*
|
||||
* @return {Boolean} {@true if the view is inserted}
|
||||
*/
|
||||
isInserted: function() {
|
||||
return DomElement.isInserted(this._element);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scrolls the view by the given vector.
|
||||
*
|
||||
|
@ -799,12 +808,16 @@ new function() { // Injection scope for mouse events on the browser
|
|||
// Key events are handled too during the mouse over.
|
||||
// As we switch view, fire one last mousemove in the old
|
||||
// view, to let items receive receive a mouseleave, etc.
|
||||
handleMouseMove(view, event);
|
||||
if (view)
|
||||
handleMouseMove(view, event);
|
||||
prevFocus = view;
|
||||
view = View._focused = tempFocus = target;
|
||||
}
|
||||
} else if (tempFocus && tempFocus === view) {
|
||||
// Clear temporary focus again and update it.
|
||||
// Clear temporary focus again and switch back to previous focus
|
||||
// but only if it is still valid (still in the DOM).
|
||||
if (prevFocus && !prevFocus.isInserted())
|
||||
prevFocus = null;
|
||||
view = View._focused = prevFocus;
|
||||
updateFocus();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue