* 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.
*/
easyXDM.WidgetManager=function(e){varh=this,b=e.local,k=0;varn={WidgetInitialized:"widgetinitialized",WidgetFailed:"widgetfailed"};varj={},d={};vari={hosturl:location.href};easyXDM.apply(i,e.widgetSettings);varg=e.container||document.body;functionf(p,o){if(e.listeners&&e.listeners.event){e.listeners.event(h,o)}}functionc(p,o){if(!(oind)){d[o]=[]}d[o].push(p)}functionm(p,o,q){p.initialize(i,function(r){if(r.isInitialized){j[o]=p;vars=r.subscriptions.length;while(s--){c(o,r.subscriptions[s])}f(n.WidgetInitialized,{url:o})}else{p.destroy();f(n.WidgetFailed,{url:o})}})}functiona(p,o,r){vars=d[o];if(s){varq=s.length,t;while(q--){t=s[q];if(t!==p){j[t].send(p,o,r)}}}}functionl(o,q){varp=neweasyXDM.Rpc({channel:"widget"+k++,local:b,remote:o,container:q.container||g,swf:e.swf,onReady:function(){m(p,o,q)}},{local:{subscribe:{isVoid:true,method:function(r){c(o,r)}},publish:{isVoid:true,method:function(r,s){a(o,r,s)}}},remote:{initialize:{},send:{isVoid:true}}})}this.addWidget=function(o,p){if(oinj){thrownewError("A widget with this url has already been initialized")}l(o,p)};this.removeWidget=function(p){if(pinj){for(varoind){if(d.hasOwnProperty(o)){varr=d[o],q=r.length;while(q--){if(r[q]===p){r.splice(q,1);break}}}}j[p].destroy();deletej[p]}};this.publish=function(o,p){a("",o,p)};this.broadcast=function(p){for(varoinj){if(j.hasOwnPropert(o)){j[o].send({url:"",topic:"broadcast",data:p})}}}};easyXDM.Widget=function(c){vara=this;varb;vard=neweasyXDM.Rpc({swf:c.swf},{remote:{subscribe:{isVoid:true},publish:{isVoid:true}},local:{initialize:{method:function(e){c.initialized(a,d);return{isInitialized:true,subscriptions:c.subscriptions}}},send:{isVoid:true,method:function(f,e,g){b(f,e,g)}}}});window.onunload=function(){d.destroy()};this.publish=function(e,f){d.publish(e,f)};this.subscribe=function(e){d.subscribe(e)};this.registerMessageHandler=function(e){b=e};c.initialize(this,d)};