mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Define view.updateFocus(), to loop through all scopes and their views and set the focus on the first active one, and call it whenever the browser is scrolled.
This commit is contained in:
parent
8002ede7bd
commit
1d9bad5d01
2 changed files with 32 additions and 2 deletions
|
@ -132,7 +132,9 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{
|
|||
},
|
||||
|
||||
evaluate: function(code) {
|
||||
return PaperScript.evaluate(code, this);
|
||||
var res = PaperScript.evaluate(code, this);
|
||||
View.updateFocus();
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -184,6 +186,13 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{
|
|||
if (typeof id === 'object')
|
||||
id = id.getAttribute('id');
|
||||
return this._scopes[id] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* A way to iterate over all active scopes without accessing _scopes
|
||||
*/
|
||||
each: function(iter) {
|
||||
Base.each(this._scopes, iter);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -423,6 +423,18 @@ var View = this.View = Base.extend({
|
|||
DomEvent.stop(event);
|
||||
}
|
||||
|
||||
function updateFocus() {
|
||||
PaperScope.each(function(scope) {
|
||||
for (var i = 0, l = scope.views.length; i < l; i++) {
|
||||
var view = scope.views[i];
|
||||
if (view.isVisible()) {
|
||||
View.focused = view;
|
||||
throw Base.stop;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// mousemove and mouseup events need to be installed on document, not the
|
||||
// view canvas, since we want to catch the end of drag events even outside
|
||||
// our view. Only the mousedown events are installed on the view, as handled
|
||||
|
@ -433,7 +445,8 @@ var View = this.View = Base.extend({
|
|||
mouseup: mouseup,
|
||||
touchmove: mousemove,
|
||||
touchend: mouseup,
|
||||
selectstart: selectstart
|
||||
selectstart: selectstart,
|
||||
scroll: updateFocus
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -458,6 +471,14 @@ var View = this.View = Base.extend({
|
|||
touchstart: mousedown,
|
||||
selectstart: selectstart
|
||||
};
|
||||
},
|
||||
|
||||
statics: {
|
||||
/**
|
||||
* Loops through all scopes and their views and sets the focus on
|
||||
* the first active one.
|
||||
*/
|
||||
updateFocus: updateFocus
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue