adding Events mootool class

This commit is contained in:
Ezequiel Bergamaschi 2014-03-15 03:55:42 -03:00
parent 3e0d84392b
commit 8115b50556
6 changed files with 68 additions and 4 deletions

View File

@ -124,6 +124,7 @@
<inputDir>${basedir}/target/compress</inputDir> <inputDir>${basedir}/target/compress</inputDir>
<includes> <includes>
<include>header.js</include> <include>header.js</include>
<include>Events.js</include>
<include>${basedir}/../web2d/target/classes/web2d.svg-min.js</include> <include>${basedir}/../web2d/target/classes/web2d.svg-min.js</include>
<include>Messages.js</include> <include>Messages.js</include>
<include>TopicEventDispatcher.js</include> <include>TopicEventDispatcher.js</include>

View File

@ -17,7 +17,7 @@
*/ */
mindplot.Designer = new Class({ mindplot.Designer = new Class({
Extends:Events, Extends: mindplot.Events,
initialize:function (options, divElement) { initialize:function (options, divElement) {
$assert(options, "options must be defined"); $assert(options, "options must be defined");
$assert(options.zoom, "zoom must be defined"); $assert(options.zoom, "zoom must be defined");

View File

@ -0,0 +1,63 @@
mindplot.Events = new Class({
$events: {},
_removeOn: function(string){
return string.replace(/^on([A-Z])/, function(full, first){
return first.toLowerCase();
});
},
addEvent: function(type, fn, internal){
type = this._removeOn(type);
this.$events[type] = (this.$events[type] || []).include(fn);
if (internal) fn.internal = true;
return this;
},
addEvents: function(events){
for (var type in events) this.addEvent(type, events[type]);
return this;
},
fireEvent: function(type, args, delay){
type = this._removeOn(type);
var events = this.$events[type];
if (!events) return this;
args = Array.from(args);
events.each(function(fn){
if (delay) fn.delay(delay, this, args);
else fn.apply(this, args);
}, this);
return this;
},
removeEvent: function(type, fn){
type = this._removeOn(type);
var events = this.$events[type];
if (events && !fn.internal){
var index = events.indexOf(fn);
if (index != -1) delete events[index];
}
return this;
},
removeEvents: function(events){
var type;
if (typeOf(events) == 'object'){
for (type in events) this.removeEvent(type, events[type]);
return this;
}
if (events) events = removeOn(events);
for (type in this.$events){
if (events && events != type) continue;
var fns = this.$events[type];
for (var i = fns.length; i--;) if (i in fns){
this.removeEvent(type, fns[i]);
}
}
return this;
}
});

View File

@ -17,7 +17,7 @@
*/ */
mindplot.MultilineTextEditor = new Class({ mindplot.MultilineTextEditor = new Class({
Extends:Events, Extends: mindplot.Events,
initialize:function () { initialize:function () {
this._topic = null; this._topic = null;
this._timeoutId = -1; this._timeoutId = -1;

View File

@ -17,7 +17,7 @@
*/ */
mindplot.TopicEventDispatcher = new Class({ mindplot.TopicEventDispatcher = new Class({
Extends: Events, Extends: mindplot.Events,
Static: { Static: {
_instance: null, _instance: null,

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.layout.LayoutManager = new Class({ mindplot.layout.LayoutManager = new Class({
Extends: Events, Extends: mindplot.Events,
initialize: function(rootNodeId, rootSize) { initialize: function(rootNodeId, rootSize) {
$assert($defined(rootNodeId), "rootNodeId can not be null"); $assert($defined(rootNodeId), "rootNodeId can not be null");
$assert(rootSize, "rootSize can not be null"); $assert(rootSize, "rootSize can not be null");