Moving some initialization logic to its own module
This commit is contained in:
parent
b67bb6105f
commit
1292e5ab3f
@ -79,24 +79,16 @@
|
|||||||
<!-- JQuery doesn't load so our squishy boi of the the collapsable menu literally doesn't work-->
|
<!-- JQuery doesn't load so our squishy boi of the the collapsable menu literally doesn't work-->
|
||||||
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script>
|
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script>
|
||||||
<script>window.jQuery = window.$ = require('jquery')</script>
|
<script>window.jQuery = window.$ = require('jquery')</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="../node_modules/popper.js/dist/umd/popper.js"></script>
|
<script type="text/javascript" src="../node_modules/popper.js/dist/umd/popper.js"></script>
|
||||||
<script type="text/javascript" src="../node_modules/popper.js/dist/umd/popper-utils.js"></script>
|
<script type="text/javascript" src="../node_modules/popper.js/dist/umd/popper-utils.js"></script>
|
||||||
<script type="text/javascript" src="../node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>
|
<script type="text/javascript" src="../node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const { ipcRenderer } = require('electron')
|
const { ipcRenderer } = require('electron')
|
||||||
const config = ipcRenderer.sendSync('config-request', 'benis')
|
const config = ipcRenderer.sendSync('config-request')
|
||||||
// only put things like the server list up if theres anythng to put in there
|
const html = require('../src/html.js')
|
||||||
if(config['servers']) {
|
|
||||||
let parent = document.getElementById('server-list')
|
html.build_server_list(config, 'server-list')
|
||||||
for(const server of config['servers']) {
|
|
||||||
let node = document.createElement('button')
|
|
||||||
node.classList.add('btn', 'btn-outline-secondary', 'btn-nav-settings')
|
|
||||||
node.type = 'button'
|
|
||||||
node.textContent = server['name']
|
|
||||||
node.id = server['ip'] || server['url'] // perfer the ip to avoid dns
|
|
||||||
parent.appendChild(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
44
freechat-client/src/html.js
Normal file
44
freechat-client/src/html.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* {String} id | id for the
|
||||||
|
* {Object} attrs | config object with the following valid fields and their types
|
||||||
|
*
|
||||||
|
* NOTE: all these fields are optional
|
||||||
|
* {Array<String>} attrs.class | classes to apply to the new node
|
||||||
|
* {String} attrs.textContent | Textual content to write
|
||||||
|
*/
|
||||||
|
exports.new_node = function(id, type, attrs) {
|
||||||
|
let node = document.createElement(type)
|
||||||
|
if(id) { node.id = id; }
|
||||||
|
|
||||||
|
for(const key in attrs) {
|
||||||
|
if(key == 'classList') {
|
||||||
|
attrs['classList'].forEach(cls => node.classList.add(cls))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
node[key] = attrs[key]
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {Config} config | configuration object passed from the ipc
|
||||||
|
* {String} dom_id | element container for the server list itself
|
||||||
|
* */
|
||||||
|
exports.build_server_list = function (config, dom_id) {
|
||||||
|
if(!config['servers']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let container = document.getElementById(dom_id)
|
||||||
|
|
||||||
|
for(const server of config['servers']) {
|
||||||
|
let child = html.new_node(server['ip'] || server['url'], 'button', {
|
||||||
|
'classList': ['btn', 'btn-outline-secondary', 'btn-nav-settings'],
|
||||||
|
'textContent': server['name'],
|
||||||
|
'type': 'button'
|
||||||
|
})
|
||||||
|
container.appendChild(child)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user