/**
* easyXDM
* http://easyxdm.net/
* Copyright(c) 2009-2011, Øyvind Sean Kinsey, oyvind@kinsey.no.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*jslint browser: true, immed: true, passfail: true, undef: true, newcap: true*/
/*global easyXDM, window */
/**
* easyXDM
* http://easyxdm.net/
* Copyright(c) 2009-2011, Øyvind Sean Kinsey, oyvind@kinsey.no.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @class easyXDM.WidgetManager
* A class for managing widgets.
* Handles initializing widgets, and does all of the message distribution.
_widgetManager = new easyXDM.WidgetManager({
local: "../hash.html",
container: document.getElementById("defaultcontainer")
},function(){
_widgetManager.addWidget("http://provider.easyxdm.net/example/widget.html",{});
});
* Widgets can by dynamically added using the addWidget method
_widgetManager.addWidget("http://provider.easyxdm.net/example/widget.html",{
container document.getElementById("widgetcontainer")
});
* @constructor
* @param {Object} config The WidgetManagers configuration
* @namespace easyXDM
*/
easyXDM.WidgetManager = function(config){
var WidgetManager = this, _hashUrl = config.local, _channelNr = 0;
var Events = {
WidgetInitialized: "widgetinitialized",
WidgetFailed: "widgetfailed"
};
var _widgets = {}, _subscribers = {};
var _widgetSettings = {
hosturl: location.href
};
easyXDM.apply(_widgetSettings, config.widgetSettings);
var _container = config.container || document.body;
/**
* @private
* Raises the specified event
* @param {String} event The raised event
* @param {Object} arg
*/
function _raiseEvent(event, arg){
if (config.listeners && config.listeners[event]) {
config.listeners[event](WidgetManager, arg);
}
}
/**
* @private
* Adds the widghet to the list of subscribers for the given topic
* @param {String} url The widgets url
* @param {String} topic The topic to subscribe to
*/
function _subscribe(url, topic){
if (!(topic in _subscribers)) {
_subscribers[topic] = [];
}
_subscribers[topic].push(url);
}
/**
* @private
* Initialized the widget.