56 lines
1.2 KiB
Haxe
56 lines
1.2 KiB
Haxe
package leenkx.logicnode;
|
|
|
|
|
|
class CreateStyleNode extends LogicNode {
|
|
public var cls: String;
|
|
public var style: String;
|
|
public var css: String;
|
|
public var property0: String;
|
|
public var property1: String;
|
|
public var property2: Bool;
|
|
|
|
|
|
public function new(tree:LogicTree) {
|
|
super(tree);
|
|
}
|
|
|
|
override function get(from: Int): Dynamic {
|
|
|
|
css = '';
|
|
css = '.' + inputs[0].get() + '{';
|
|
for (i in 0...inputs.length){
|
|
var input = property1.split(':');
|
|
if (i != 0){
|
|
css += input[i - 1] + ':' + inputs[i].get() + ';';
|
|
}
|
|
}
|
|
css += '}';
|
|
if(property2){
|
|
#if js
|
|
var script = "try{var html = document.createElement('div');html.innerHTML = `<style>" + css + "</style>`;document.getElementsByTagName('head')[0].appendChild(html.childNodes[0]);}catch(e){console.log('Error: ' + e);}";
|
|
js.Syntax.code('(1, eval)({0})', script.toString());
|
|
#end
|
|
}
|
|
|
|
return switch (from) {
|
|
case 0:
|
|
cls = inputs[0].get();
|
|
cls;
|
|
case 1:
|
|
style = '';
|
|
for (i in 0...inputs.length){
|
|
var input = property1.split(':');
|
|
if (i != 0){
|
|
style += input[i - 1] + ':' + inputs[i].get() + ';';
|
|
}
|
|
}
|
|
style;
|
|
case 2:
|
|
css;
|
|
default: throw "Unreachable";
|
|
}
|
|
}
|
|
|
|
|
|
}
|