forked from info-beamer/package-scheduled-player
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hosted.js
138 lines (124 loc) · 4.74 KB
/
hosted.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* info-beamer hosted.js Mockup for local development.
* You can find the latest version of this file at:
*
* https://github.com/info-beamer/package-sdk
*
* BSD 2-Clause License
*
* Copyright (c) 2017-2019 Florian Wesch <fw@info-beamer.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
(function() {
var head = document.getElementsByTagName("head")[0];
var asset_root = "https://cdn.infobeamer.com/s/mock-use-latest/";
function setupResources(js, css) {
for (var idx = 0; idx < js.length; idx++) {
var script = document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src", asset_root + 'js/' + js[idx]);
head.appendChild(script);
}
for (var idx = css.length-1; idx >= 0; idx--) {
var link = document.createElement('link')
link.setAttribute('rel', 'stylesheet')
link.setAttribute('type', 'text/css')
link.setAttribute('href', asset_root + 'css/' + css[idx])
head.insertBefore(link, head.firstChild);
}
}
var style = document.createElement('style');
var rules = document.createTextNode(
"body { width: 750px; margin: auto; }"
)
style.type = 'text/css';
style.appendChild(rules);
head.appendChild(style);
if (window.MOCK_ASSETS == undefined)
console.error("[MOCK HOSTED.JS] window.MOCK_ASSETS undefined");
if (window.MOCK_NODE_ASSETS == undefined)
console.error("[MOCK HOSTED.JS] window.MOCK_NODE_ASSETS undefined");
if (window.MOCK_DEVICES == undefined)
console.error("[MOCK HOSTED.JS] window.MOCK_DEVICES undefined");
if (window.MOCK_CONFIG == undefined)
console.error("[MOCK HOSTED.JS] window.MOCK_CONFIG undefined");
var ib = {
assets: window.MOCK_ASSETS,
node_assets: window.MOCK_NODE_ASSETS,
config: window.MOCK_CONFIG,
devices: window.MOCK_DEVICES,
doc_link_base: 'data:text/plain,This would have opened the package documentation for ',
apis: {
geo: {
get: function(params) {
if (!params.q) {
console.error("no q parameter for weather query");
}
return new Promise(function(resolve, reject) {
setTimeout(function() { // simulate latency
resolve({"hits":[
{"lat":49.00937,"lon":8.40444,"name":"Karlsruhe (Baden-W\u00fcrttemberg, Germany)"},
{"lat":48.09001,"lon":-100.62042,"name":"Karlsruhe (North Dakota, United States)"}
]})
}, 800);
})
},
}
}
}
ib.setDefaultStyle = function() {
setupResources([], ['reset.css', 'bootstrap.css'])
}
var asset_chooser_response = window.MOCK_ASSET_CHOOSER_RESPONSE
if (asset_chooser_response) {
console.log("[MOCK HOSTED.JS] emulating asset chooser");
ib.assetChooser = function() {
console.log("[MOCK HOSTED.JS] asset chooser mockup returns", asset_chooser_response);
return new Promise(function(resolve) {
resolve(asset_chooser_response);
})
}
}
ib.setConfig = function(config) {
var as_string = JSON.stringify(config);
ib.config = JSON.parse(as_string);
console.log("[MOCK HOSTED.JS] setConfig", as_string);
}
ib.getConfig = function(cb) {
console.warn("[MOCK HOSTED.JS] using .getConfig is deprecated. Use .ready.then(...) instead");
cb(ib.config);
}
ib.getDocLink = function(name) {
return ib.doc_link_base + name;
}
ib.onAssetUpdate = function(cb) {
console.warn("[MOCK HOSTED.JS] onAssetUpdate is a no-op in the mock environment");
}
ib.ready = new Promise(function(resolve) {
console.log("[MOCK HOSTED.JS] ready");
resolve(ib.config);
})
window.infobeamer = window.ib = ib;
})();