varChannel=function(){"use strict";functiona(a,b,c,d){functionf(b){for(varc=0;c<b.length;c++)if(b[c].win===a)return!0;return!1}varg=!1;if("*"===b){for(varhine)if(e.hasOwnProperty(h)&&"*"!==h&&"object"==typeofe[h][c]&&(g=f(e[h][c])))break}elsee["*"]&&e["*"][c]&&(g=f(e["*"][c])),!g&&e[b]&&e[b][c]&&(g=f(e[b][c]));if(g)throw"A channel is already bound to the same window which overlaps with origin '"+b+"' and has scope '"+c+"'";"object"!=typeofe[b]&&(e[b]={}),"object"!=typeofe[b][c]&&(e[b][c]=[]),e[b][c].push({win:a,handler:d})}functionb(a,b,c){for(vard=e[b][c],f=0;f<d.length;f++)d[f].win===a&&d.splice(f,1);0===e[b][c].length&&deletee[b][c]}functionc(a){returnArray.isArray?Array.isArray(a):-1!=a.constructor.toString().indexOf("Array")}vard=Math.floor(1000001*Math.random()),e={},f={},g=function(a){try{varb=JSON.parse(a.data);if("object"!=typeofb||null===b)throw"malformed"}catch(a){return}varc,d,g,h=a.source,i=a.origin;if("string"==typeofb.method){varj=b.method.split("::");2==j.length?(c=j[0],g=j[1]):g=b.method}if("undefined"!=typeofb.id&&(d=b.id),"string"==typeofg){vark=!1;if(e[i]&&e[i][c])for(varl=0;l<e[i][c].length;l++)if(e[i][c][l].win===h){e[i][c][l].handler(i,g,b),k=!0;break}if(!k&&e["*"]&&e["*"][c])for(varl=0;l<e["*"][c].length;l++)if(e["*"][c][l].win===h){e["*"][c][l].handler(i,g,b);break}}else"undefined"!=typeofd&&f[d]&&f[d](i,g,b)};returnwindow.addEventListener?window.addEventListener("message",g,!1):window.attachEvent&&window.attachEvent("onmessage",g),{build:function(e){varg=function(a){if(e.debugOutput&&window.console&&window.console.log){try{"string"!=typeofa&&(a=JSON.stringify(a))}catch(b){}console.log("["+j+"] "+a)}};if(!window.postMessage)throw"jschannel cannot run this browser, no postMessage";if(!window.JSON||!window.JSON.stringify||!window.JSON.parse)throw"jschannel cannot run this browser, no JSON parsing/serialization";if("object"!=typeofe)throw"Channel build invoked without a proper object argument";if(!e.window||!e.window.postMessage)throw"Channel.build() called without a valid window argument";if(window===e.window)throw"target window is same as present window -- not allowed";varh=!1;if("string"==typeofe.origin){vari;"*"===e.origin?h=!0:null!==(i=e.origin.match(/^https?:\/\/(?:[-a-zA-Z0-9_\.])+(?::\d+)?/))&&(e.origin=i[0].toLowerCase(),h=!0)}if(!h)throw"Channel.build() called with an invalid origin";if("undefined"!=typeofe.scope){if("string"!=typeofe.scope)throw"scope, when specified, must be a string";if(e.scope.split("::").length>1)throw"scope may not contain double colons: '::'"}varj=function(){for(vara="",b="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",c=0;5>c;c++)a+=b.charAt(Math.floor(Math.random()*b.length));returna}(),k={},l={},m={},n=!1,o=[],p=function(a,b,c){vard=!1,e=!1;return{origin:b,invoke:function(b,d){if(!m[a])throw"attempting to invoke a callback of a nonexistent transaction: "+a;for(vare=!1,f=0;f<c.length;f++)if(b===c[f]){e=!0;break}if(!e)throw"request supports no such callback '"+b+"'";t({id:a,callback:b,params:d})},error:function(b,c){if(e=!0,!m[a])throw"error called for nonexistent message: "+a;deletem[a],t({id:a,error:b,message:c})},complete:function(b){if(e=!0,!m[a])throw"complete called for nonexistent message: "+a;deletem[a],t({id:a,result:b})},delayReturn:function(a){return"boolean"==typeofa&&(d=a===!0),d},completed:function(){returne}}},q=function(a,b,c){returnwindow.setTimeout(function(){if(l[a]){vard="timeout ("+b+"ms) exceeded on method '"+c+"'";l[a].error("timeout_error",d),deletel[a],deletef[a]}},b)},r=function(a,b,d){if("function"==typeofe.gotMessageObserver)try{e.gotMessageObserver(a,d)}catch(h){g("gotMessageObserver() raised an exception: "+h.toString())}if(d.id&&b){if(k[b]){vari=p(d.id,a,d.callbacks?d.callbacks:[]);m[d.id]={};try{if(d.callbacks&&c(d.callbacks)&&d.callbacks.length>0)for(varj=0;j<d.callbacks.length;j++){for(varn=d.callbacks[j],o=d.params,q=n.split("/"),r=0;r<q.length-1;r++){vars=q[r];"object"!=typeofo[s]&&(o[s]={}),o=o[s]}o[q[q.length-1]]=function(){vara=n;returnfunction(b){returni.invoke(a,b)}}()}vart=k[b](i,d.params);i.delayReturn()||i.completed()||i.complete(t)}catch(h){varu="runtime_error",v=null;if("string"==typeofh?v=h:"object"==typeofh&&(h&&c(h)&&2==h.length?(u=h[0],v=h[1]):"string"==typeofh.error&&(u=h.error,h.message?"string"==typeofh.message?v=h.message:h=h.message:v="")),null===v)try{v=JSON.stringify(h),"undefined"==typeofv&&(v=h.toString())}catch(w){v=h.toString()}i.error(u,v)}}}elsed.id&&d.callback?l[d.id]&&l[d.id].callbacks&&l[d.id].callbacks[d.callback]?l[d.id].callbacks[d.callback](d.params):g("ignoring invalid callback, id:"+d.id+" ("+d.callback+")"):d.id?l[d.id]?(d.error?l[d.id].error(d.error,d.message):void0!==d.result?l[d.id].success(d.result):l[d.id].success(),deletel[d.id],deletef[d.id]):g("ignoring invalid response: "+d.id):b&&k[b]&&k[b]({origin:a},d.params)};a(e.window,e.origin,"string"==typeofe.scope?e.scope:"",r);vars=function(a){return"string"==typeofe.scope&&e.scope.length&&(a=[e.scope,a].join("::")),a},t=function(a,b){if(!a)throw"postMessage called with null message";varc=n?"post ":"queue ";if(g(c+" message: "+JSON.stringify(a)),b||n){if("function"==typeofe.postMessageObserver)try{e.postMessageObserver(e.origin,a)}catch(d){g("postMessageObserver() raised an exception: "+d.toString())}e.window.postMessage(JSON.stringify(a),e.origin)}elseo.push(a)},u=function(a,b){if(g("ready msg received"),n)throw"received ready message while in ready state. help!";for(j+="ping"===b?"-R":"-L",v.unbind("__ready"),n=!0,g("ready msg accepted."),"ping"===b&&v.notify({method:"__ready",params:"pong"});o.length;)t(o.pop());"function"==typeofe.onReady&&e.onReady(v)},v={unbind:function(a){if(k[a]){if(!deletek[a])throw"can't delete method: "+a;return!0}return!1},bind:function(a,b){if(!a||"string"!=typeofa)throw"'method' argument to bind must be string";if(!b||"function"!=typeofb)throw"callback missing from bind params";if(k[a])throw"method '"+a+"' is already bound!";returnk[a]=b,this},call:function(a){if(!a)throw"missing arguments to call function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to call must be string";if(!a.success||"function"!=typeofa.success)throw"'success' callback missing from call";varb={},c=[],e=function(a,d){if("object"==typeofd)for(varfind)if(d.hasOwnProperty(f)){varg=a+(a.length?"/":"")+f;"function"==typeofd[f]?(b[g]=d[f],c.push(g),deleted[f]):"object"==typeofd[f]&&e(g,d[f])}};e("",a.params);varg={id:d,method:s(a.method),params:a.params};c.length&&(g.callbacks=c),a.timeout&&q(d,a.timeout,s(a.method)),l[d]={callbacks:b,error:a.error,success:a.success},f[d]=r,d++,t(g)},notify:function(a){if(!a)throw"missing arguments to notify function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to notify must be string";t({method:s(a.method),params:a.params})},destroy:function(){b(e.window,e.origin,"string"==typeofe.scope?e.scope:""),window.removeEventListener?window.removeEventListener("message",r,!1):window.detachEvent&&window.detachEvent("onmessage",r),n=!1,k={},m={},l={},e.origin=null,o=[],g("channel destroyed"),j=""}};returnv.bind("__ready",u),setTimeout(function(){t({method:s("__ready"),params:"ping"},!0)},0),v}}}();!function(a){"use strict";varb=a.prototype,c=b.parseFromString;try{if((newa).parseFromString("","text/html"))return}catch(d){}b.parseFromString=function(a,b){vard,e,f,g;return/^\s*text\/html\s*(?:;|$)/i.test(b)?(e=document.implementation.createHTMLDocument(""),f=e.documentElement,f.innerHTML=a,g=f.firstElementChild,1===f.childElementCount&&"html"===g.localName.toLowerCase()&&e.replaceChild(g,f),d=e):d=c.apply(this,arguments),d}}(DOMParser),function(a,b,c,d,e,f){"use strict";functiong(){returnthisinstanceofg?void0:newg}functionh(){returnthisinstanceofh?(g.call(this),void0):newh}functioni(b,d){functione(a,b){returnfunction(){returna(b)}}varg;returnd.element===f&&(d.element=a.createElement("div")),(newc.Queue).push(function(){returno.declareGadgetKlass(b)}).push(function(a){varb,e=a.template_element.body.childNodes;for(m=a,g=newa,g.element=d.element,b=0;b<e.length;b+=1)g.element.appendChild(e[b].cloneNode(!0));returnc.all([g.getRequiredJSList(),g.getRequiredCSSList()])}).push(function(a){varb,d=newc.Queue;for(b=0;b<a[0].length;b+=1)d.push(e(o.declareJS,a[0][b]));for(b=0;b<a[1].length;b+=1)d.push(e(o.declareCSS,a[1][b]));returnd}).push(function(){returng})}functionj(){returnthisinstanceofj?(g.call(this),void0):newj}functionk(b,d){varg,h,i,k=c.defer();if(d.element===f)thrownewError("DOM element is required to create Iframe Gadget "+b);for(i=d.element.parentNode;null!==i&&i!==a;)i=i.parentNode;if(null===i)thrownewError("The parent element is not attached to the DOM for "+b);returng=newj,h=a.createElement("iframe"),h.setAttribute("src",b),g.path=b,g.element=d.element,d.element.appendChild(h),g.chan=e.build({window:h.contentWindow,origin:"*",scope:"renderJS"}),g.chan.bind("declareMethod",function(a,b){returng[b]=function(){vara=arguments;returnnewc.Promise(function(c,d){g.chan.call({method:"methodCall",params:[b,Array.prototype.slice.call(a,0)],success:function(a){c(a)},error:function(a){d(a)}})})},"OK"}),g.chan.bind("ready",function(){returnk.resolve(g),"OK"}),g.chan.bind("failed",function(a,b){returnk.reject(b),"OK"}),g.chan.bind("trigger",function(a,b){returng.trigger(b.event_name,b.options)}),c.any([k.promise,c.timeout(5e3)])}functionl(){vard,i,j,k,l,s,t=b.location.href,u=0,v=!1;if(p.hasOwnProperty(t))thrownewError("bootstrap should not be called twice");n=newc.Promise(function(n,w){functionx(){varb,e,g=o.parseGadgetHTMLDocument(a);for(eing)g.hasOwnProperty(e)&&(d.prototype[e]=g[e]);for(d.template_element=a.createElement("div"),i.element=a.body,b=0;b<i.element.childNodes.length;b+=1)d.template_element.appendChild(i.element.childNodes[b].cloneNode(!0));c.all([i.getRequiredJSList(),i.getRequiredCSSList()]).then(function(a){functionb(){returni}vare,g,h=a[0],j=a[1];for(e=0;e<h.length;e+=1)q[h[e]]=null;for(e=0;e<j.length;e+=1)r[j[e]]=null;for(m=f,g=newc.Queue,g.push(b),e=0;e<d.ready_list.length;e+=1)g.push(d.ready_list[e]).push(b);returng.push(n,function(a){throww(a),a}),g}).fail(function(a){w(a),console.error(a)})}b.self===b.top?(d=function(){g.call(this)},d.declareMethod=g.declareMethod,d.ready_list=[],d.ready=g.ready,d.prototype=newg,d.prototype.constructor=d,d.prototype.path=t,p[t]=d,i=newp[t]):(j=e.build({window:b.parent,origin:"*",scope:"renderJS"}),d=h,i=newh,j.bind("methodCall",function(a,b){i[b[0]].apply(i,b[1]).then(function(b){a.complete(b)}).fail(function(b){a.error(b.toString())}),a.delayReturn(!0)}),k=function(){0===u&&v===!0&&j.notify({method:"ready"})},l=function(a){u+=1,j.call({method:"declareMethod",params:a,success:function(){u-=1,k()},error:function(){u-=1}})},l("getInterfaceList"),l("getRequiredCSSList"),l("getRequiredJSList"),l("getPath"),l("getTitle"),d.declareMethod=function(a,b){varc=g.declareMethod.apply(this,[a,b]);returnl(a),c},s=function(a,b){j.notify({method:"trigger",params:{event_name:a,options:b}})},d.prototype.trigger=function(a,b){varc=g.prototype.trigger.apply(this,[a,b]);returns(a,b),c}),m=d,a.addEventListener("DOMContentLoaded",x,!1)}),b.self!==b.top&&n.then(function(){v=!0,k()}).fail(function(a){throwj.notify({method:"failed",params:a.toString()}),a})}varm,n,o,p={},q={},r={};g.prototype.title="",g.prototype.interface_list=[],g.prototype.path="",g.prototype.html="",g.prototype.required_css_list=[],g.prototype.required_js_list=[],c.EventTarget.mixin(g.prototype),g.ready_list=[],g.ready=function(a){returnthis.ready_list.push(a),this},g.declareMethod=function(a,b){returnthis.prototype[a]=function(){vara=this,d=arguments;return(newc.Queue).push(function(){returnb.apply(a,d)})},this},g.declareMethod("getInterfaceList",function(){returnthis.interface_list}).declareMethod("getRequiredCSSList",function(){returnthis.required_css_list}).declareMethod("getRequiredJSList",function(){returnthis.required_js_list}).declareMethod("getPath",function(){returnthis.path}).declareMethod("getTitle",function(){returnthis.title}).declareMethod("getElement",function(){if(this.element===f)thrownewError("No element defined");returnthis.element}),h.ready_list=[],h.ready=g.ready,h.prototype=newg,h.prototype.constructor=h,j.ready_list=[],j.ready=g.ready,j.prototype=newg,j.prototype.constructor=j,g.prototype.declareGadget=function(a,b){vard,e=n;returnb===f&&(b={}),b.sandbox===f&&(b.sandbox="public"),d=(newc.Queue).push(function(){returne}).push(f,function(){}).push(function(){varc;if("public"===b.sandbox)c=i;else{if("iframe"!==b.sandbox)thrownewError("Unsupported sandbox options '"+b.sandbox+"'");c=k}returnc(a,b)}).push(function(a){functionb(){returna}varc;for(m=f,c=0;c<a.constructor.ready_list.length;c+=1)d.push(a.constructor.ready_list[c]),d.push(b);returna}).push(f,function(a){throwm=f,a}),n=d},o=function(a){varc;if(a===b&&(c=m),c===f)thrownewError("Unknown selector '"+a+"'");returnc},o.declareJS=function(b){vard;returnd=q.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("script"),e.type="text/javascript",e.src=b,e.onload=function(){q[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareCSS=function(b){vard;returnd=r.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("link"),e.rel="stylesheet",e.type="text/css",e.href=b,e.onload=function(){r[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareGadgetKlass=function(a){functionb(){varb,c,e;if(!p.hasOwnProperty(a)){b=function(){g.call(this)},b.ready_list=[],b.declareMethod=g.declareMethod,b.ready=g.ready,b.prototype=newg,b.prototype.constructor=b,b.prototype.path=a,b.template_element=(newd).parseFromString(j.responseText,"text/html"),e=o.parseGadgetHTMLDocument(b.template_element);for(cine)e.hasOwnProperty(c)&&(b.prototype[c]=e[c]);p[a]=b}returnp[a]}functione(c,d){functione(){vara;try{0===j.readyState?d(j):4===j.readyState&&(j.status<200||j.status>=300||!/^text\/html[;]?/.test(j.getResponseHeader("Content-Type")||"")?d(j):(a=b(),c(a)))}catch(e){d(e)}}j=newXMLHttpRequest,j.open("GET",a),j.onreadystatechange=e,j.setRequestHeader("Accept","text/html"),j.withCredentials=!0,j.send()}functionh(){j!==f&&j.readyState!==j.DONE&&j.abort()}vari,j;returni=p.hasOwnProperty(a)?c.resolve(p[a]):newc.Promise(e,h)},o.clearGadgetKlassList=function(){p={},q={},r={}},o.parseGadgetHTMLDocument=function(a){varb,c,d={title:"",interface_list:[],required_css_list:[],required_js_list:[]};if(9!==a.nodeType)thrownewError("The first parameter should be an HTMLDocument");for(d.title=a.title,b=0;b<a.head.children.length;b+=1)c=a.head.children[b],null!==c.href&&("stylesheet"===c.rel?d.required_css_list.push(c.getAttribute("href")):"text/javascript"===c.type?d.required_js_list.push(c.getAttribute("src")):"http://www.renderjs.org/rel/interface"===c.rel&&d.interface_list.push(c.getAttribute("href")));returnd},b.rJS=b.renderJS=o,b.RenderJSGadget=g,b.RenderJSEmbeddedGadget=h,b.RenderJSIframeGadget=j,l()}(document,window,RSVP,DOMParser,Channel);
varChannel=function(){"use strict";functiona(a,b,c,d){functionf(b){for(varc=0;c<b.length;c++)if(b[c].win===a)return!0;return!1}varg=!1;if("*"===b){for(varhine)if(e.hasOwnProperty(h)&&"*"!==h&&"object"==typeofe[h][c]&&(g=f(e[h][c])))break}elsee["*"]&&e["*"][c]&&(g=f(e["*"][c])),!g&&e[b]&&e[b][c]&&(g=f(e[b][c]));if(g)throw"A channel is already bound to the same window which overlaps with origin '"+b+"' and has scope '"+c+"'";"object"!=typeofe[b]&&(e[b]={}),"object"!=typeofe[b][c]&&(e[b][c]=[]),e[b][c].push({win:a,handler:d})}functionb(a,b,c){for(vard=e[b][c],f=0;f<d.length;f++)d[f].win===a&&d.splice(f,1);0===e[b][c].length&&deletee[b][c]}functionc(a){returnArray.isArray?Array.isArray(a):-1!=a.constructor.toString().indexOf("Array")}vard=Math.floor(1000001*Math.random()),e={},f={},g=function(a){try{varb=JSON.parse(a.data);if("object"!=typeofb||null===b)throw"malformed"}catch(a){return}varc,d,g,h=a.source,i=a.origin;if("string"==typeofb.method){varj=b.method.split("::");2==j.length?(c=j[0],g=j[1]):g=b.method}if("undefined"!=typeofb.id&&(d=b.id),"string"==typeofg){vark=!1;if(e[i]&&e[i][c])for(varl=0;l<e[i][c].length;l++)if(e[i][c][l].win===h){e[i][c][l].handler(i,g,b),k=!0;break}if(!k&&e["*"]&&e["*"][c])for(varl=0;l<e["*"][c].length;l++)if(e["*"][c][l].win===h){e["*"][c][l].handler(i,g,b);break}}else"undefined"!=typeofd&&f[d]&&f[d](i,g,b)};returnwindow.addEventListener?window.addEventListener("message",g,!1):window.attachEvent&&window.attachEvent("onmessage",g),{build:function(e){varg=function(a){if(e.debugOutput&&window.console&&window.console.log){try{"string"!=typeofa&&(a=JSON.stringify(a))}catch(b){}console.log("["+j+"] "+a)}};if(!window.postMessage)throw"jschannel cannot run this browser, no postMessage";if(!window.JSON||!window.JSON.stringify||!window.JSON.parse)throw"jschannel cannot run this browser, no JSON parsing/serialization";if("object"!=typeofe)throw"Channel build invoked without a proper object argument";if(!e.window||!e.window.postMessage)throw"Channel.build() called without a valid window argument";if(window===e.window)throw"target window is same as present window -- not allowed";varh=!1;if("string"==typeofe.origin){vari;"*"===e.origin?h=!0:null!==(i=e.origin.match(/^https?:\/\/(?:[-a-zA-Z0-9_\.])+(?::\d+)?/))&&(e.origin=i[0].toLowerCase(),h=!0)}if(!h)throw"Channel.build() called with an invalid origin";if("undefined"!=typeofe.scope){if("string"!=typeofe.scope)throw"scope, when specified, must be a string";if(e.scope.split("::").length>1)throw"scope may not contain double colons: '::'"}varj=function(){for(vara="",b="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",c=0;5>c;c++)a+=b.charAt(Math.floor(Math.random()*b.length));returna}(),k={},l={},m={},n=!1,o=[],p=function(a,b,c){vard=!1,e=!1;return{origin:b,invoke:function(b,d){if(!m[a])throw"attempting to invoke a callback of a nonexistent transaction: "+a;for(vare=!1,f=0;f<c.length;f++)if(b===c[f]){e=!0;break}if(!e)throw"request supports no such callback '"+b+"'";t({id:a,callback:b,params:d})},error:function(b,c){if(e=!0,!m[a])throw"error called for nonexistent message: "+a;deletem[a],t({id:a,error:b,message:c})},complete:function(b){if(e=!0,!m[a])throw"complete called for nonexistent message: "+a;deletem[a],t({id:a,result:b})},delayReturn:function(a){return"boolean"==typeofa&&(d=a===!0),d},completed:function(){returne}}},q=function(a,b,c){returnwindow.setTimeout(function(){if(l[a]){vard="timeout ("+b+"ms) exceeded on method '"+c+"'";l[a].error("timeout_error",d),deletel[a],deletef[a]}},b)},r=function(a,b,d){if("function"==typeofe.gotMessageObserver)try{e.gotMessageObserver(a,d)}catch(h){g("gotMessageObserver() raised an exception: "+h.toString())}if(d.id&&b){if(k[b]){vari=p(d.id,a,d.callbacks?d.callbacks:[]);m[d.id]={};try{if(d.callbacks&&c(d.callbacks)&&d.callbacks.length>0)for(varj=0;j<d.callbacks.length;j++){for(varn=d.callbacks[j],o=d.params,q=n.split("/"),r=0;r<q.length-1;r++){vars=q[r];"object"!=typeofo[s]&&(o[s]={}),o=o[s]}o[q[q.length-1]]=function(){vara=n;returnfunction(b){returni.invoke(a,b)}}()}vart=k[b](i,d.params);i.delayReturn()||i.completed()||i.complete(t)}catch(h){varu="runtime_error",v=null;if("string"==typeofh?v=h:"object"==typeofh&&(h&&c(h)&&2==h.length?(u=h[0],v=h[1]):"string"==typeofh.error&&(u=h.error,h.message?"string"==typeofh.message?v=h.message:h=h.message:v="")),null===v)try{v=JSON.stringify(h),"undefined"==typeofv&&(v=h.toString())}catch(w){v=h.toString()}i.error(u,v)}}}elsed.id&&d.callback?l[d.id]&&l[d.id].callbacks&&l[d.id].callbacks[d.callback]?l[d.id].callbacks[d.callback](d.params):g("ignoring invalid callback, id:"+d.id+" ("+d.callback+")"):d.id?l[d.id]?(d.error?l[d.id].error(d.error,d.message):void0!==d.result?l[d.id].success(d.result):l[d.id].success(),deletel[d.id],deletef[d.id]):g("ignoring invalid response: "+d.id):b&&k[b]&&k[b]({origin:a},d.params)};a(e.window,e.origin,"string"==typeofe.scope?e.scope:"",r);vars=function(a){return"string"==typeofe.scope&&e.scope.length&&(a=[e.scope,a].join("::")),a},t=function(a,b){if(!a)throw"postMessage called with null message";varc=n?"post ":"queue ";if(g(c+" message: "+JSON.stringify(a)),b||n){if("function"==typeofe.postMessageObserver)try{e.postMessageObserver(e.origin,a)}catch(d){g("postMessageObserver() raised an exception: "+d.toString())}e.window.postMessage(JSON.stringify(a),e.origin)}elseo.push(a)},u=function(a,b){if(g("ready msg received"),n)throw"received ready message while in ready state. help!";for(j+="ping"===b?"-R":"-L",v.unbind("__ready"),n=!0,g("ready msg accepted."),"ping"===b&&v.notify({method:"__ready",params:"pong"});o.length;)t(o.pop());"function"==typeofe.onReady&&e.onReady(v)},v={unbind:function(a){if(k[a]){if(!deletek[a])throw"can't delete method: "+a;return!0}return!1},bind:function(a,b){if(!a||"string"!=typeofa)throw"'method' argument to bind must be string";if(!b||"function"!=typeofb)throw"callback missing from bind params";if(k[a])throw"method '"+a+"' is already bound!";returnk[a]=b,this},call:function(a){if(!a)throw"missing arguments to call function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to call must be string";if(!a.success||"function"!=typeofa.success)throw"'success' callback missing from call";varb={},c=[],e=function(a,d){if("object"==typeofd)for(varfind)if(d.hasOwnProperty(f)){varg=a+(a.length?"/":"")+f;"function"==typeofd[f]?(b[g]=d[f],c.push(g),deleted[f]):"object"==typeofd[f]&&e(g,d[f])}};e("",a.params);varg={id:d,method:s(a.method),params:a.params};c.length&&(g.callbacks=c),a.timeout&&q(d,a.timeout,s(a.method)),l[d]={callbacks:b,error:a.error,success:a.success},f[d]=r,d++,t(g)},notify:function(a){if(!a)throw"missing arguments to notify function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to notify must be string";t({method:s(a.method),params:a.params})},destroy:function(){b(e.window,e.origin,"string"==typeofe.scope?e.scope:""),window.removeEventListener?window.removeEventListener("message",r,!1):window.detachEvent&&window.detachEvent("onmessage",r),n=!1,k={},m={},l={},e.origin=null,o=[],g("channel destroyed"),j=""}};returnv.bind("__ready",u),setTimeout(function(){t({method:s("__ready"),params:"ping"},!0)},0),v}}}();!function(a){"use strict";varb=a.prototype,c=b.parseFromString;try{if((newa).parseFromString("","text/html"))return}catch(d){}b.parseFromString=function(a,b){vard,e,f,g;return/^\s*text\/html\s*(?:;|$)/i.test(b)?(e=document.implementation.createHTMLDocument(""),f=e.documentElement,f.innerHTML=a,g=f.firstElementChild,1===f.childElementCount&&"html"===g.localName.toLowerCase()&&e.replaceChild(g,f),d=e):d=c.apply(this,arguments),d}}(DOMParser),function(a,b,c,d,e,f){"use strict";functiong(){returnthisinstanceofg?void0:newg}functionh(){returnthisinstanceofh?(g.call(this),void0):newh}functioni(b,d){functione(a,b){returnfunction(){returna(b)}}varg;returnd.element===f&&(d.element=a.createElement("div")),(newc.Queue).push(function(){returno.declareGadgetKlass(b)}).push(function(a){varb,e=a.template_element.body.childNodes;for(m=a,g=newa,g.element=d.element,b=0;b<e.length;b+=1)g.element.appendChild(e[b].cloneNode(!0));returnc.all([g.getRequiredJSList(),g.getRequiredCSSList()])}).push(function(a){varb,d=newc.Queue;for(b=0;b<a[0].length;b+=1)d.push(e(o.declareJS,a[0][b]));for(b=0;b<a[1].length;b+=1)d.push(e(o.declareCSS,a[1][b]));returnd}).push(function(){returng})}functionj(){returnthisinstanceofj?(g.call(this),void0):newj}functionk(b,d){varg,h,i,k=c.defer();if(d.element===f)thrownewError("DOM element is required to create Iframe Gadget "+b);for(i=d.element.parentNode;null!==i&&i!==a;)i=i.parentNode;if(null===i)thrownewError("The parent element is not attached to the DOM for "+b);returng=newj,h=a.createElement("iframe"),h.setAttribute("src",b),g.path=b,g.element=d.element,d.element.appendChild(h),g.chan=e.build({window:h.contentWindow,origin:"*",scope:"renderJS"}),g.chan.bind("declareMethod",function(a,b){returng[b]=function(){vara=arguments;returnnewc.Promise(function(c,d){g.chan.call({method:"methodCall",params:[b,Array.prototype.slice.call(a,0)],success:function(a){c(a)},error:function(a){d(a)}})})},"OK"}),g.chan.bind("ready",function(){returnk.resolve(g),"OK"}),g.chan.bind("failed",function(a,b){returnk.reject(b),"OK"}),g.chan.bind("trigger",function(a,b){returng.trigger(b.event_name,b.options)}),c.any([k.promise,c.timeout(5e3)])}functionl(){vard,i,j,k,l,s,t=b.location.href,u=0,v=!1;if(p.hasOwnProperty(t))thrownewError("bootstrap should not be called twice");n=newc.Promise(function(n,w){functionx(){varb,e,g=o.parseGadgetHTMLDocument(a);for(eing)g.hasOwnProperty(e)&&(d.prototype[e]=g[e]);for(d.template_element=a.createElement("div"),i.element=a.body,b=0;b<i.element.childNodes.length;b+=1)d.template_element.appendChild(i.element.childNodes[b].cloneNode(!0));c.all([i.getRequiredJSList(),i.getRequiredCSSList()]).then(function(a){functionb(){returni}vare,g,h=a[0],j=a[1];for(e=0;e<h.length;e+=1)q[h[e]]=null;for(e=0;e<j.length;e+=1)r[j[e]]=null;for(m=f,g=newc.Queue,g.push(b),e=0;e<d.ready_list.length;e+=1)g.push(d.ready_list[e]).push(b);returng.push(n,function(a){throww(a),a}),g}).fail(function(a){w(a),console.error(a)})}b.self===b.top?(d=function(){g.call(this)},d.declareMethod=g.declareMethod,d.ready_list=[],d.ready=g.ready,d.prototype=newg,d.prototype.constructor=d,d.prototype.path=t,p[t]=d,i=newp[t]):(j=e.build({window:b.parent,origin:"*",scope:"renderJS"}),d=h,i=newh,j.bind("methodCall",function(a,b){i[b[0]].apply(i,b[1]).then(function(b){a.complete(b)}).fail(function(b){a.error(b.toString())}),a.delayReturn(!0)}),k=function(){0===u&&v===!0&&j.notify({method:"ready"})},l=function(a){u+=1,j.call({method:"declareMethod",params:a,success:function(){u-=1,k()},error:function(){u-=1}})},l("getInterfaceList"),l("getRequiredCSSList"),l("getRequiredJSList"),l("getPath"),l("getTitle"),d.declareMethod=function(a,b){varc=g.declareMethod.apply(this,[a,b]);returnl(a),c},s=function(a,b){j.notify({method:"trigger",params:{event_name:a,options:b}})},d.prototype.trigger=function(a,b){varc=g.prototype.trigger.apply(this,[a,b]);returns(a,b),c}),m=d,a.addEventListener("DOMContentLoaded",x,!1)}),b.self!==b.top&&n.then(function(){v=!0,k()}).fail(function(a){throwj.notify({method:"failed",params:a.toString()}),a})}varm,n,o,p={},q={},r={};g.prototype.title="",g.prototype.interface_list=[],g.prototype.path="",g.prototype.html="",g.prototype.required_css_list=[],g.prototype.required_js_list=[],c.EventTarget.mixin(g.prototype),g.ready_list=[],g.ready=function(a){returnthis.ready_list.push(a),this},g.declareMethod=function(a,b){returnthis.prototype[a]=function(){vara=this,d=arguments;return(newc.Queue).push(function(){returnb.apply(a,d)})},this},g.declareMethod("getInterfaceList",function(){returnthis.interface_list}).declareMethod("getRequiredCSSList",function(){returnthis.required_css_list}).declareMethod("getRequiredJSList",function(){returnthis.required_js_list}).declareMethod("getPath",function(){returnthis.path}).declareMethod("getTitle",function(){returnthis.title}).declareMethod("getElement",function(){if(this.element===f)thrownewError("No element defined");returnthis.element}),h.ready_list=[],h.ready=g.ready,h.prototype=newg,h.prototype.constructor=h,j.ready_list=[],j.ready=g.ready,j.prototype=newg,j.prototype.constructor=j,g.prototype.declareGadget=function(a,b){vard,e=n;returnb===f&&(b={}),b.sandbox===f&&(b.sandbox="public"),d=(newc.Queue).push(function(){returne}).push(f,function(){}).push(function(){varc;if("public"===b.sandbox)c=i;else{if("iframe"!==b.sandbox)thrownewError("Unsupported sandbox options '"+b.sandbox+"'");c=k}returnc(a,b)}).push(function(a){functionb(){returna}varc;for(m=f,c=0;c<a.constructor.ready_list.length;c+=1)d.push(a.constructor.ready_list[c]),d.push(b);returna}).push(f,function(a){throwm=f,a}),n=d},o=function(a){varc;if(a===b?c=m:ainstanceofg&&(c=a),c===f)thrownewError("Unknown selector '"+a+"'");returnc},o.declareJS=function(b){vard;returnd=q.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("script"),e.type="text/javascript",e.src=b,e.onload=function(){q[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareCSS=function(b){vard;returnd=r.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("link"),e.rel="stylesheet",e.type="text/css",e.href=b,e.onload=function(){r[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareGadgetKlass=function(a){functionb(){varb,c,e;if(!p.hasOwnProperty(a)){b=function(){g.call(this)},b.ready_list=[],b.declareMethod=g.declareMethod,b.ready=g.ready,b.prototype=newg,b.prototype.constructor=b,b.prototype.path=a,b.template_element=(newd).parseFromString(j.responseText,"text/html"),e=o.parseGadgetHTMLDocument(b.template_element);for(cine)e.hasOwnProperty(c)&&(b.prototype[c]=e[c]);p[a]=b}returnp[a]}functione(c,d){functione(){vara;try{0===j.readyState?d(j):4===j.readyState&&(j.status<200||j.status>=300||!/^text\/html[;]?/.test(j.getResponseHeader("Content-Type")||"")?d(j):(a=b(),c(a)))}catch(e){d(e)}}j=newXMLHttpRequest,j.open("GET",a),j.onreadystatechange=e,j.setRequestHeader("Accept","text/html"),j.withCredentials=!0,j.send()}functionh(){j!==f&&j.readyState!==j.DONE&&j.abort()}vari,j;returni=p.hasOwnProperty(a)?c.resolve(p[a]):newc.Promise(e,h)},o.clearGadgetKlassList=function(){p={},q={},r={}},o.parseGadgetHTMLDocument=function(a){varb,c,d={title:"",interface_list:[],required_css_list:[],required_js_list:[]};if(9!==a.nodeType)thrownewError("The first parameter should be an HTMLDocument");for(d.title=a.title,b=0;b<a.head.children.length;b+=1)c=a.head.children[b],null!==c.href&&("stylesheet"===c.rel?d.required_css_list.push(c.getAttribute("href")):"text/javascript"===c.type?d.required_js_list.push(c.getAttribute("src")):"http://www.renderjs.org/rel/interface"===c.rel&&d.interface_list.push(c.getAttribute("href")));returnd},b.rJS=b.renderJS=o,b.RenderJSGadget=g,b.RenderJSEmbeddedGadget=h,b.RenderJSIframeGadget=j,l()}(document,window,RSVP,DOMParser,Channel);
\ No newline at end of file
varChannel=function(){"use strict";functiona(a,b,c,d){functionf(b){for(varc=0;c<b.length;c++)if(b[c].win===a)return!0;return!1}varg=!1;if("*"===b){for(varhine)if(e.hasOwnProperty(h)&&"*"!==h&&"object"==typeofe[h][c]&&(g=f(e[h][c])))break}elsee["*"]&&e["*"][c]&&(g=f(e["*"][c])),!g&&e[b]&&e[b][c]&&(g=f(e[b][c]));if(g)throw"A channel is already bound to the same window which overlaps with origin '"+b+"' and has scope '"+c+"'";"object"!=typeofe[b]&&(e[b]={}),"object"!=typeofe[b][c]&&(e[b][c]=[]),e[b][c].push({win:a,handler:d})}functionb(a,b,c){for(vard=e[b][c],f=0;f<d.length;f++)d[f].win===a&&d.splice(f,1);0===e[b][c].length&&deletee[b][c]}functionc(a){returnArray.isArray?Array.isArray(a):-1!=a.constructor.toString().indexOf("Array")}vard=Math.floor(1000001*Math.random()),e={},f={},g=function(a){try{varb=JSON.parse(a.data);if("object"!=typeofb||null===b)throw"malformed"}catch(a){return}varc,d,g,h=a.source,i=a.origin;if("string"==typeofb.method){varj=b.method.split("::");2==j.length?(c=j[0],g=j[1]):g=b.method}if("undefined"!=typeofb.id&&(d=b.id),"string"==typeofg){vark=!1;if(e[i]&&e[i][c])for(varl=0;l<e[i][c].length;l++)if(e[i][c][l].win===h){e[i][c][l].handler(i,g,b),k=!0;break}if(!k&&e["*"]&&e["*"][c])for(varl=0;l<e["*"][c].length;l++)if(e["*"][c][l].win===h){e["*"][c][l].handler(i,g,b);break}}else"undefined"!=typeofd&&f[d]&&f[d](i,g,b)};returnwindow.addEventListener?window.addEventListener("message",g,!1):window.attachEvent&&window.attachEvent("onmessage",g),{build:function(e){varg=function(a){if(e.debugOutput&&window.console&&window.console.log){try{"string"!=typeofa&&(a=JSON.stringify(a))}catch(b){}console.log("["+j+"] "+a)}};if(!window.postMessage)throw"jschannel cannot run this browser, no postMessage";if(!window.JSON||!window.JSON.stringify||!window.JSON.parse)throw"jschannel cannot run this browser, no JSON parsing/serialization";if("object"!=typeofe)throw"Channel build invoked without a proper object argument";if(!e.window||!e.window.postMessage)throw"Channel.build() called without a valid window argument";if(window===e.window)throw"target window is same as present window -- not allowed";varh=!1;if("string"==typeofe.origin){vari;"*"===e.origin?h=!0:null!==(i=e.origin.match(/^https?:\/\/(?:[-a-zA-Z0-9_\.])+(?::\d+)?/))&&(e.origin=i[0].toLowerCase(),h=!0)}if(!h)throw"Channel.build() called with an invalid origin";if("undefined"!=typeofe.scope){if("string"!=typeofe.scope)throw"scope, when specified, must be a string";if(e.scope.split("::").length>1)throw"scope may not contain double colons: '::'"}varj=function(){for(vara="",b="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",c=0;5>c;c++)a+=b.charAt(Math.floor(Math.random()*b.length));returna}(),k={},l={},m={},n=!1,o=[],p=function(a,b,c){vard=!1,e=!1;return{origin:b,invoke:function(b,d){if(!m[a])throw"attempting to invoke a callback of a nonexistent transaction: "+a;for(vare=!1,f=0;f<c.length;f++)if(b===c[f]){e=!0;break}if(!e)throw"request supports no such callback '"+b+"'";t({id:a,callback:b,params:d})},error:function(b,c){if(e=!0,!m[a])throw"error called for nonexistent message: "+a;deletem[a],t({id:a,error:b,message:c})},complete:function(b){if(e=!0,!m[a])throw"complete called for nonexistent message: "+a;deletem[a],t({id:a,result:b})},delayReturn:function(a){return"boolean"==typeofa&&(d=a===!0),d},completed:function(){returne}}},q=function(a,b,c){returnwindow.setTimeout(function(){if(l[a]){vard="timeout ("+b+"ms) exceeded on method '"+c+"'";l[a].error("timeout_error",d),deletel[a],deletef[a]}},b)},r=function(a,b,d){if("function"==typeofe.gotMessageObserver)try{e.gotMessageObserver(a,d)}catch(h){g("gotMessageObserver() raised an exception: "+h.toString())}if(d.id&&b){if(k[b]){vari=p(d.id,a,d.callbacks?d.callbacks:[]);m[d.id]={};try{if(d.callbacks&&c(d.callbacks)&&d.callbacks.length>0)for(varj=0;j<d.callbacks.length;j++){for(varn=d.callbacks[j],o=d.params,q=n.split("/"),r=0;r<q.length-1;r++){vars=q[r];"object"!=typeofo[s]&&(o[s]={}),o=o[s]}o[q[q.length-1]]=function(){vara=n;returnfunction(b){returni.invoke(a,b)}}()}vart=k[b](i,d.params);i.delayReturn()||i.completed()||i.complete(t)}catch(h){varu="runtime_error",v=null;if("string"==typeofh?v=h:"object"==typeofh&&(h&&c(h)&&2==h.length?(u=h[0],v=h[1]):"string"==typeofh.error&&(u=h.error,h.message?"string"==typeofh.message?v=h.message:h=h.message:v="")),null===v)try{v=JSON.stringify(h),"undefined"==typeofv&&(v=h.toString())}catch(w){v=h.toString()}i.error(u,v)}}}elsed.id&&d.callback?l[d.id]&&l[d.id].callbacks&&l[d.id].callbacks[d.callback]?l[d.id].callbacks[d.callback](d.params):g("ignoring invalid callback, id:"+d.id+" ("+d.callback+")"):d.id?l[d.id]?(d.error?l[d.id].error(d.error,d.message):void0!==d.result?l[d.id].success(d.result):l[d.id].success(),deletel[d.id],deletef[d.id]):g("ignoring invalid response: "+d.id):b&&k[b]&&k[b]({origin:a},d.params)};a(e.window,e.origin,"string"==typeofe.scope?e.scope:"",r);vars=function(a){return"string"==typeofe.scope&&e.scope.length&&(a=[e.scope,a].join("::")),a},t=function(a,b){if(!a)throw"postMessage called with null message";varc=n?"post ":"queue ";if(g(c+" message: "+JSON.stringify(a)),b||n){if("function"==typeofe.postMessageObserver)try{e.postMessageObserver(e.origin,a)}catch(d){g("postMessageObserver() raised an exception: "+d.toString())}e.window.postMessage(JSON.stringify(a),e.origin)}elseo.push(a)},u=function(a,b){if(g("ready msg received"),n)throw"received ready message while in ready state. help!";for(j+="ping"===b?"-R":"-L",v.unbind("__ready"),n=!0,g("ready msg accepted."),"ping"===b&&v.notify({method:"__ready",params:"pong"});o.length;)t(o.pop());"function"==typeofe.onReady&&e.onReady(v)},v={unbind:function(a){if(k[a]){if(!deletek[a])throw"can't delete method: "+a;return!0}return!1},bind:function(a,b){if(!a||"string"!=typeofa)throw"'method' argument to bind must be string";if(!b||"function"!=typeofb)throw"callback missing from bind params";if(k[a])throw"method '"+a+"' is already bound!";returnk[a]=b,this},call:function(a){if(!a)throw"missing arguments to call function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to call must be string";if(!a.success||"function"!=typeofa.success)throw"'success' callback missing from call";varb={},c=[],e=function(a,d){if("object"==typeofd)for(varfind)if(d.hasOwnProperty(f)){varg=a+(a.length?"/":"")+f;"function"==typeofd[f]?(b[g]=d[f],c.push(g),deleted[f]):"object"==typeofd[f]&&e(g,d[f])}};e("",a.params);varg={id:d,method:s(a.method),params:a.params};c.length&&(g.callbacks=c),a.timeout&&q(d,a.timeout,s(a.method)),l[d]={callbacks:b,error:a.error,success:a.success},f[d]=r,d++,t(g)},notify:function(a){if(!a)throw"missing arguments to notify function";if(!a.method||"string"!=typeofa.method)throw"'method' argument to notify must be string";t({method:s(a.method),params:a.params})},destroy:function(){b(e.window,e.origin,"string"==typeofe.scope?e.scope:""),window.removeEventListener?window.removeEventListener("message",r,!1):window.detachEvent&&window.detachEvent("onmessage",r),n=!1,k={},m={},l={},e.origin=null,o=[],g("channel destroyed"),j=""}};returnv.bind("__ready",u),setTimeout(function(){t({method:s("__ready"),params:"ping"},!0)},0),v}}}();!function(a){"use strict";varb=a.prototype,c=b.parseFromString;try{if((newa).parseFromString("","text/html"))return}catch(d){}b.parseFromString=function(a,b){vard,e,f,g;return/^\s*text\/html\s*(?:;|$)/i.test(b)?(e=document.implementation.createHTMLDocument(""),f=e.documentElement,f.innerHTML=a,g=f.firstElementChild,1===f.childElementCount&&"html"===g.localName.toLowerCase()&&e.replaceChild(g,f),d=e):d=c.apply(this,arguments),d}}(DOMParser),function(a,b,c,d,e,f){"use strict";functiong(){returnthisinstanceofg?void0:newg}functionh(){returnthisinstanceofh?(g.call(this),void0):newh}functioni(b,d){functione(a,b){returnfunction(){returna(b)}}varg;returnd.element===f&&(d.element=a.createElement("div")),(newc.Queue).push(function(){returno.declareGadgetKlass(b)}).push(function(a){varb,e=a.template_element.body.childNodes;for(m=a,g=newa,g.element=d.element,b=0;b<e.length;b+=1)g.element.appendChild(e[b].cloneNode(!0));returnc.all([g.getRequiredJSList(),g.getRequiredCSSList()])}).push(function(a){varb,d=newc.Queue;for(b=0;b<a[0].length;b+=1)d.push(e(o.declareJS,a[0][b]));for(b=0;b<a[1].length;b+=1)d.push(e(o.declareCSS,a[1][b]));returnd}).push(function(){returng})}functionj(){returnthisinstanceofj?(g.call(this),void0):newj}functionk(b,d){varg,h,i,k=c.defer();if(d.element===f)thrownewError("DOM element is required to create Iframe Gadget "+b);for(i=d.element.parentNode;null!==i&&i!==a;)i=i.parentNode;if(null===i)thrownewError("The parent element is not attached to the DOM for "+b);returng=newj,h=a.createElement("iframe"),h.setAttribute("src",b),g.path=b,g.element=d.element,d.element.appendChild(h),g.chan=e.build({window:h.contentWindow,origin:"*",scope:"renderJS"}),g.chan.bind("declareMethod",function(a,b){returng[b]=function(){vara=arguments;returnnewc.Promise(function(c,d){g.chan.call({method:"methodCall",params:[b,Array.prototype.slice.call(a,0)],success:function(a){c(a)},error:function(a){d(a)}})})},"OK"}),g.chan.bind("ready",function(){returnk.resolve(g),"OK"}),g.chan.bind("failed",function(a,b){returnk.reject(b),"OK"}),g.chan.bind("trigger",function(a,b){returng.trigger(b.event_name,b.options)}),c.any([k.promise,c.timeout(5e3)])}functionl(){vard,i,j,k,l,s,t=b.location.href,u=0,v=!1;if(p.hasOwnProperty(t))thrownewError("bootstrap should not be called twice");n=newc.Promise(function(n,w){functionx(){varb,e,g=o.parseGadgetHTMLDocument(a);for(eing)g.hasOwnProperty(e)&&(d.prototype[e]=g[e]);for(d.template_element=a.createElement("div"),i.element=a.body,b=0;b<i.element.childNodes.length;b+=1)d.template_element.appendChild(i.element.childNodes[b].cloneNode(!0));c.all([i.getRequiredJSList(),i.getRequiredCSSList()]).then(function(a){functionb(){returni}vare,g,h=a[0],j=a[1];for(e=0;e<h.length;e+=1)q[h[e]]=null;for(e=0;e<j.length;e+=1)r[j[e]]=null;for(m=f,g=newc.Queue,g.push(b),e=0;e<d.ready_list.length;e+=1)g.push(d.ready_list[e]).push(b);returng.push(n,function(a){throww(a),a}),g}).fail(function(a){w(a),console.error(a)})}b.self===b.top?(d=function(){g.call(this)},d.declareMethod=g.declareMethod,d.ready_list=[],d.ready=g.ready,d.prototype=newg,d.prototype.constructor=d,d.prototype.path=t,p[t]=d,i=newp[t]):(j=e.build({window:b.parent,origin:"*",scope:"renderJS"}),d=h,i=newh,j.bind("methodCall",function(a,b){i[b[0]].apply(i,b[1]).then(function(b){a.complete(b)}).fail(function(b){a.error(b.toString())}),a.delayReturn(!0)}),k=function(){0===u&&v===!0&&j.notify({method:"ready"})},l=function(a){u+=1,j.call({method:"declareMethod",params:a,success:function(){u-=1,k()},error:function(){u-=1}})},l("getInterfaceList"),l("getRequiredCSSList"),l("getRequiredJSList"),l("getPath"),l("getTitle"),d.declareMethod=function(a,b){varc=g.declareMethod.apply(this,[a,b]);returnl(a),c},s=function(a,b){j.notify({method:"trigger",params:{event_name:a,options:b}})},d.prototype.trigger=function(a,b){varc=g.prototype.trigger.apply(this,[a,b]);returns(a,b),c}),m=d,a.addEventListener("DOMContentLoaded",x,!1)}),b.self!==b.top&&n.then(function(){v=!0,k()}).fail(function(a){throwj.notify({method:"failed",params:a.toString()}),a})}varm,n,o,p={},q={},r={};g.prototype.title="",g.prototype.interface_list=[],g.prototype.path="",g.prototype.html="",g.prototype.required_css_list=[],g.prototype.required_js_list=[],c.EventTarget.mixin(g.prototype),g.ready_list=[],g.ready=function(a){returnthis.ready_list.push(a),this},g.declareMethod=function(a,b){returnthis.prototype[a]=function(){vara=this,d=arguments;return(newc.Queue).push(function(){returnb.apply(a,d)})},this},g.declareMethod("getInterfaceList",function(){returnthis.interface_list}).declareMethod("getRequiredCSSList",function(){returnthis.required_css_list}).declareMethod("getRequiredJSList",function(){returnthis.required_js_list}).declareMethod("getPath",function(){returnthis.path}).declareMethod("getTitle",function(){returnthis.title}).declareMethod("getElement",function(){if(this.element===f)thrownewError("No element defined");returnthis.element}),h.ready_list=[],h.ready=g.ready,h.prototype=newg,h.prototype.constructor=h,j.ready_list=[],j.ready=g.ready,j.prototype=newg,j.prototype.constructor=j,g.prototype.declareGadget=function(a,b){vard,e=n;returnb===f&&(b={}),b.sandbox===f&&(b.sandbox="public"),d=(newc.Queue).push(function(){returne}).push(f,function(){}).push(function(){varc;if("public"===b.sandbox)c=i;else{if("iframe"!==b.sandbox)thrownewError("Unsupported sandbox options '"+b.sandbox+"'");c=k}returnc(a,b)}).push(function(a){functionb(){returna}varc;for(m=f,c=0;c<a.constructor.ready_list.length;c+=1)d.push(a.constructor.ready_list[c]),d.push(b);returna}).push(f,function(a){throwm=f,a}),n=d},o=function(a){varc;if(a===b&&(c=m),c===f)thrownewError("Unknown selector '"+a+"'");returnc},o.declareJS=function(b){vard;returnd=q.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("script"),e.type="text/javascript",e.src=b,e.onload=function(){q[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareCSS=function(b){vard;returnd=r.hasOwnProperty(b)?c.resolve():newc.Promise(function(c,d){vare;e=a.createElement("link"),e.rel="stylesheet",e.type="text/css",e.href=b,e.onload=function(){r[b]=null,c()},e.onerror=function(a){d(a)},a.head.appendChild(e)})},o.declareGadgetKlass=function(a){functionb(){varb,c,e;if(!p.hasOwnProperty(a)){b=function(){g.call(this)},b.ready_list=[],b.declareMethod=g.declareMethod,b.ready=g.ready,b.prototype=newg,b.prototype.constructor=b,b.prototype.path=a,b.template_element=(newd).parseFromString(j.responseText,"text/html"),e=o.parseGadgetHTMLDocument(b.template_element);for(cine)e.hasOwnProperty(c)&&(b.prototype[c]=e[c]);p[a]=b}returnp[a]}functione(c,d){functione(){vara;try{0===j.readyState?d(j):4===j.readyState&&(j.status<200||j.status>=300||!/^text\/html[;]?/.test(j.getResponseHeader("Content-Type")||"")?d(j):(a=b(),c(a)))}catch(e){d(e)}}j=newXMLHttpRequest,j.open("GET",a),j.onreadystatechange=e,j.setRequestHeader("Accept","text/html"),j.withCredentials=!0,j.send()}functionh(){j!==f&&j.readyState!==j.DONE&&j.abort()}vari,j;returni=p.hasOwnProperty(a)?c.resolve(p[a]):newc.Promise(e,h)},o.clearGadgetKlassList=function(){p={},q={},r={}},o.parseGadgetHTMLDocument=function(a){varb,c,d={title:"",interface_list:[],required_css_list:[],required_js_list:[]};if(9!==a.nodeType)thrownewError("The first parameter should be an HTMLDocument");for(d.title=a.title,b=0;b<a.head.children.length;b+=1)c=a.head.children[b],null!==c.href&&("stylesheet"===c.rel?d.required_css_list.push(c.getAttribute("href")):"text/javascript"===c.type?d.required_js_list.push(c.getAttribute("src")):"http://www.renderjs.org/rel/interface"===c.rel&&d.interface_list.push(c.getAttribute("href")));returnd},b.rJS=b.renderJS=o,b.RenderJSGadget=g,b.RenderJSEmbeddedGadget=h,b.RenderJSIframeGadget=j,l()}(document,window,RSVP,DOMParser,Channel);