source: Dev/branches/rest-dojo-ui/client/dojo/Evented.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 972 bytes
Line 
1define(["./aspect", "./on"], function(aspect, on){
2        // summary:
3        //              The export of this module is a class that can be used as a mixin or base class,
4        //              to add on() and emit() methods to a class
5        //              for listening for events and emiting events:
6        //              |define(["dojo/Evented"], function(Evented){
7        //              |       var EventedWidget = dojo.declare([Evented, dijit._Widget], {...});
8        //              |       widget = new EventedWidget();
9        //              |       widget.on("open", function(event){
10        //              |       ... do something with event
11        //              |        });
12        //              |
13        //              |       widget.emit("open", {name:"some event", ...});
14
15        "use strict";
16        var after = aspect.after;
17        function Evented(){
18        }
19        Evented.prototype = {
20                on: function(type, listener){
21                        return on.parse(this, type, listener, function(target, type){
22                                return after(target, 'on' + type, listener, true);
23                        });
24                },
25                emit: function(type, event){
26                        var args = [this];
27                        args.push.apply(args, arguments);
28                        return on.emit.apply(on, args);
29                }
30        };
31        return Evented;
32});
Note: See TracBrowser for help on using the repository browser.