mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Introduce Item._itemHandlers to remove code redundancy.
This commit is contained in:
parent
ed8a904b74
commit
3276616f53
2 changed files with 39 additions and 32 deletions
|
@ -67,8 +67,44 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
selected: false,
|
selected: false,
|
||||||
clipMask: false,
|
clipMask: false,
|
||||||
data: {}
|
data: {}
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
new function() { // // Scope to inject various item event handlers
|
||||||
|
var handles = ['onMouseDown', 'onMouseUp', 'onMouseDrag', 'onClick',
|
||||||
|
'onDoubleClick', 'onMouseMove', 'onMouseEnter', 'onMouseLeave'];
|
||||||
|
return Base.each(handles,
|
||||||
|
function(name) {
|
||||||
|
this._events[name] = {
|
||||||
|
install: function(type) {
|
||||||
|
this.getView()._countItemEvent(type, 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
uninstall: function(type) {
|
||||||
|
this.getView()._countItemEvent(type, -1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, {
|
||||||
|
_events: {
|
||||||
|
onFrame: {
|
||||||
|
install: function() {
|
||||||
|
this.getView()._animateItem(this, true);
|
||||||
|
},
|
||||||
|
|
||||||
|
uninstall: function() {
|
||||||
|
this.getView()._animateItem(this, false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Only for external sources, e.g. Raster
|
||||||
|
onLoad: {},
|
||||||
|
onError: {}
|
||||||
|
},
|
||||||
|
statics: {
|
||||||
|
_itemHandlers: handles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, /** @lends Item# */{
|
||||||
initialize: function Item() {
|
initialize: function Item() {
|
||||||
// Do nothing, but declare it for named constructors.
|
// Do nothing, but declare it for named constructors.
|
||||||
},
|
},
|
||||||
|
@ -121,35 +157,6 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
return hasProps;
|
return hasProps;
|
||||||
},
|
},
|
||||||
|
|
||||||
_events: Base.each(['onMouseDown', 'onMouseUp', 'onMouseDrag', 'onClick',
|
|
||||||
'onDoubleClick', 'onMouseMove', 'onMouseEnter', 'onMouseLeave'],
|
|
||||||
function(name) {
|
|
||||||
this[name] = {
|
|
||||||
install: function(type) {
|
|
||||||
this.getView()._countItemEvent(type, 1);
|
|
||||||
},
|
|
||||||
|
|
||||||
uninstall: function(type) {
|
|
||||||
this.getView()._countItemEvent(type, -1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, {
|
|
||||||
onFrame: {
|
|
||||||
install: function() {
|
|
||||||
this.getView()._animateItem(this, true);
|
|
||||||
},
|
|
||||||
|
|
||||||
uninstall: function() {
|
|
||||||
this.getView()._animateItem(this, false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Only for external sources, e.g. Raster
|
|
||||||
onLoad: {},
|
|
||||||
onError: {}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
|
|
||||||
_serialize: function(options, dictionary) {
|
_serialize: function(options, dictionary) {
|
||||||
var props = {},
|
var props = {},
|
||||||
that = this;
|
that = this;
|
||||||
|
|
|
@ -136,8 +136,8 @@ var View = Base.extend(Emitter, /** @lends View# */{
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_events: Base.each(['onResize', 'onMouseDown', 'onMouseUp', 'onMouseMove',
|
_events: Base.each(
|
||||||
'onMouseDrag', 'onMouseEnter', 'onMouseLeave'],
|
Item._itemHandlers.concat(['onResize', 'onKeyDown', 'onKeyUp']),
|
||||||
function(name) {
|
function(name) {
|
||||||
this[name] = {};
|
this[name] = {};
|
||||||
}, {
|
}, {
|
||||||
|
|
Loading…
Reference in a new issue