1 /* registry.js is part of Aloha Editor project http://aloha-editor.org
  2  *
  3  * Aloha Editor is a WYSIWYG HTML5 inline editing library and editor. 
  4  * Copyright (c) 2010-2012 Gentics Software GmbH, Vienna, Austria.
  5  * Contributors http://aloha-editor.org/contribution.php 
  6  * 
  7  * Aloha Editor is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU General Public License
  9  * as published by the Free Software Foundation; either version 2
 10  * of the License, or any later version.
 11  *
 12  * Aloha Editor is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU General Public License
 18  * along with this program; if not, write to the Free Software
 19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 20  * 
 21  * As an additional permission to the GNU GPL version 2, you may distribute
 22  * non-source (e.g., minimized or compacted) forms of the Aloha-Editor
 23  * source code without the copy of the GNU GPL normally required,
 24  * provided you include this license notice and a URL through which
 25  * recipients can access the Corresponding Source.
 26  */
 27 /**
 28  * Registry base class.
 29  * TODO: document that it also contains Observable.
 30  *
 31  */
 32 define(
 33 ['jquery', 'aloha/observable', 'util/class'],
 34 function(jQuery, Observable, Class) {
 35 	"use strict";
 36 
 37 	return Class.extend(Observable, {
 38 
 39 		_entries: null,
 40 
 41 		_constructor: function() {
 42 			this._entries = {};
 43 		},
 44 
 45 		/**
 46 		 * @event register
 47 		 * @param entry
 48 		 * @param id
 49 		 */
 50 		register: function(id, entry) {
 51 			this._entries[id] = entry;
 52 			this.trigger('register', entry, id);
 53 		},
 54 
 55 		/**
 56 		 * @event unregister
 57 		 * @param id
 58 		 */
 59 		unregister: function(id) {
 60 			var oldEntry = this._entries[id];
 61 			delete this._entries[id];
 62 			this.trigger('unregister', oldEntry, id);
 63 		},
 64 		
 65 		get: function(id) {
 66 			return this._entries[id];
 67 		},
 68  69 		
 70 		has: function(id) {
 71 			return (this._entries[id] ? true : false);
 72 		},
 73 		
 74 		getEntries: function() {
 75 			// clone the entries so the user does not accidentally modify our _entries object.
 76 			return jQuery.extend({}, this._entries);
 77 		}
 78 	});
 79 });
 80