~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/helioviewer/UIElement.js

  • Committer: V. Keith Hughitt
  • Date: 2009-04-01 21:08:05 UTC
  • Revision ID: hughitt1@kore-20090401210805-372f7dgih07vxk42
nightly build 04-01-2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @fileOverview Contains the class definition for an UIElement class.
 
3
 * @author <a href="mailto:patrick.schmiedel@gmx.net">Patrick Schmiedel</a>
 
4
 */
 
5
 /*global Class, $A */
 
6
var UIElement = Class.create(
 
7
        /** @lends UIElement.prototype */
 
8
        {
 
9
        /**
 
10
         * @description Enables inheriting classes to use the "event/notification" system
 
11
         * @constructs
 
12
         */
 
13
        initialize: function () {},
 
14
        
 
15
        /**
 
16
         * @description Adds an event observer
 
17
         * @param {String} eventName The name of the event to look for 
 
18
         * @param {Function} callback The function to execute when the event occurs
 
19
         */
 
20
        addObserver: function (eventName, callback) {
 
21
            if (!this.observers) {
 
22
                this.observers = [];
 
23
            }
 
24
            if (!this.observers[eventName]) {
 
25
                    this.observers[eventName] = $A([]);
 
26
            }
 
27
            this.observers[eventName].push(callback);
 
28
            return this;
 
29
        },
 
30
 
 
31
        /**
 
32
         * @describe Fires a specific event
 
33
         * @param {String} eventName The name of the event to trigger
 
34
         * @param {Object} eventParameters The parameters to pass along with the event
 
35
         */
 
36
        fire: function (eventName, eventParameters) {
 
37
                //$('output').innerHTML = eventName + ': ' + eventParameters;
 
38
            if (!this.observers || !this.observers[eventName] || this.observers[eventName].length === 0) {
 
39
                        return this;
 
40
            }
 
41
            this.observers[eventName].each(function (callback) {
 
42
                callback(eventParameters);
 
43
            });
 
44
            return this;
 
45
        }
 
46
});
 
 
b'\\ No newline at end of file'