-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathide.js
58 lines (51 loc) · 1.68 KB
/
ide.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
/* globals VERSION */
import React from 'react'
import {getElement} from './lib'
import IDE from 'components/ide/ide'
import translations from './translations/ide/index'
import {render} from 'react-dom'
import {currentScript} from './utils/compat'
import {t, language} from './utils/i18n'
import {convertToMap} from './utils/maps'
// we import the IDE styles here
import './scss/ide.scss'
const trans = convertToMap(translations)
let defaultConfig
export function renderIDE(config){
const lang = language(config)
const element = getElement(config, true)
const tt = (...args) => t(trans, lang, config.fallbackLang || 'en', ...args)
const ide = render(<IDE t={tt} lang={lang} config={config} />, element)
return ide
}
export function show(conf){
conf = conf || defaultConfig
renderIDE(conf)
}
export function version(){
// we remove the 'v'
if (VERSION[0] === 'v')
return VERSION.slice(1)
return VERSION
}
function initialize(){
show()
}
function setup(){
const script = currentScript("klaro");
if (script !== undefined){
const configName = script.getAttribute('data-config') || "klaroConfig"
defaultConfig = window[configName]
// deprecated: config settings should only be loaded via the config
const scriptStylePrefix = script.getAttribute('data-style-prefix')
if (scriptStylePrefix === undefined)
defaultConfig.stylePrefix = scriptStylePrefix
if (defaultConfig !== undefined){
if (/complete|interactive|loaded/.test(document.readyState))
initialize()
else
window.addEventListener('DOMContentLoaded', initialize)
}
}
}
setup()