1 | (function () {
|
2 | var createApplication = function() {
|
3 | var div;
|
4 | var location = window.location;
|
5 | var parent = location.protocol + '//' + location.host;
|
6 | var settings = {
|
7 | width: '100%',
|
8 | height: '100%',
|
9 | frameborder: '0',
|
10 | scrolling: 'auto'
|
11 | };
|
12 | var url = '{{widgetURL}}';
|
13 | url = url.replace(new RegExp('([\\?&]parent=)[^&]+'), '$1' + encodeURIComponent(parent));
|
14 |
|
15 | div = document.getElementById('{{widgetUrn}}');
|
16 | div.setAttribute('id', div.getAttribute('id') + appstore.util.guid());
|
17 | appstore.addApplication('{{widgetName}}' + '-' + appstore.util.guid(), div.getAttribute('id'), settings, url);
|
18 | };
|
19 |
|
20 | var addScriptLoadHandler = function (script, handler) {
|
21 | var scriptIsLoaded = false;
|
22 | var previousHandler = script.onload;
|
23 |
|
24 | // IE8 hack
|
25 | script.onload = script.onerror = script.onreadystatechange = function () {
|
26 | if (!scriptIsLoaded && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
|
27 | scriptIsLoaded = true;
|
28 |
|
29 | if (previousHandler) {
|
30 | previousHandler.call(script);
|
31 | }
|
32 |
|
33 | handler.call(script);
|
34 |
|
35 | // IE8 memory leak fix
|
36 | script.onload = script.onerror = script.onreadystatechange = null;
|
37 | }
|
38 | };
|
39 | };
|
40 | var createScript = function(callback) {
|
41 | var scriptId = 'appstore-container-api';
|
42 | var script;
|
43 |
|
44 | script = document.getElementById(scriptId);
|
45 | if (script) {
|
46 | if (window.appstore && window.appstore.apiVersion === 'container') {
|
47 | callback();
|
48 | } else {
|
49 | addScriptLoadHandler(script, function () {
|
50 | callback();
|
51 | });
|
52 | }
|
53 | } else {
|
54 | script = document.createElement('script');
|
55 | script.src = '{{viewerEndpoint}}/content/js/appsngen.container.api.js';
|
56 | script.setAttribute('id', scriptId);
|
57 | addScriptLoadHandler(script, function () {
|
58 | callback();
|
59 | });
|
60 |
|
61 | document.body.appendChild(script);
|
62 | }
|
63 | };
|
64 | var container = document.createElement("div");
|
65 | container.id = '{{widgetUrn}}';
|
66 | document.body.appendChild(container);
|
67 |
|
68 | if (window.appstore && window.appstore.apiVersion === 'widget') {
|
69 | appstore.ready(createApplication);
|
70 | } else if (window.appstore && window.appstore.apiVersion === 'container'){
|
71 | createApplication();
|
72 | } else {
|
73 | createScript(function () {
|
74 | if (window.appstore) {
|
75 | createApplication();
|
76 | } else if (window.console && window.console.error) {
|
77 | window.console.error('Cannot render widget: appsngen api loading failure');
|
78 | }
|
79 | });
|
80 | }
|
81 | }()); |
\ | No newline at end of file |