mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #4513 from gorenje/html_node_content_and_attributes
HTML node: add option for collecting attributes and content
This commit is contained in:
commit
0b9dd11fff
@ -14,6 +14,7 @@
|
|||||||
<option value="html" data-i18n="html.output.html"></option>
|
<option value="html" data-i18n="html.output.html"></option>
|
||||||
<option value="text" data-i18n="html.output.text"></option>
|
<option value="text" data-i18n="html.output.text"></option>
|
||||||
<option value="attr" data-i18n="html.output.attr"></option>
|
<option value="attr" data-i18n="html.output.attr"></option>
|
||||||
|
<option value="compl" data-i18n="html.output.compl"></option>
|
||||||
<!-- <option value="val">return the value from a form element</option> -->
|
<!-- <option value="val">return the value from a form element</option> -->
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -28,6 +29,10 @@
|
|||||||
<label for="node-input-outproperty"> </label>
|
<label for="node-input-outproperty"> </label>
|
||||||
<span data-i18n="html.label.in" style="padding-left:8px; padding-right:2px; vertical-align:-1px;"></span> <input type="text" id="node-input-outproperty" style="width:64%">
|
<span data-i18n="html.label.in" style="padding-left:8px; padding-right:2px; vertical-align:-1px;"></span> <input type="text" id="node-input-outproperty" style="width:64%">
|
||||||
</div>
|
</div>
|
||||||
|
<div id='html-prefix-row' class="form-row" style="display: none;">
|
||||||
|
<label for="node-input-chr" style="width: 230px;"><i class="fa fa-tag"></i> <span data-i18n="html.label.prefix"></span></label>
|
||||||
|
<input type="text" id="node-input-chr" style="text-align:center; width: 40px;" placeholder="_">
|
||||||
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
@ -45,7 +50,8 @@
|
|||||||
outproperty: {value:"payload", validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true }) },
|
outproperty: {value:"payload", validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true }) },
|
||||||
tag: {value:""},
|
tag: {value:""},
|
||||||
ret: {value:"html"},
|
ret: {value:"html"},
|
||||||
as: {value:"single"}
|
as: {value:"single"},
|
||||||
|
chr: { value: "_" }
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
@ -59,6 +65,13 @@
|
|||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||||
$("#node-input-outproperty").typedInput({default:'msg',types:['msg']});
|
$("#node-input-outproperty").typedInput({default:'msg',types:['msg']});
|
||||||
|
$('#node-input-ret').on( 'change', () => {
|
||||||
|
if ( $('#node-input-ret').val() == "compl" ) {
|
||||||
|
$('#html-prefix-row').show()
|
||||||
|
} else {
|
||||||
|
$('#html-prefix-row').hide()
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -25,6 +25,7 @@ module.exports = function(RED) {
|
|||||||
this.tag = n.tag;
|
this.tag = n.tag;
|
||||||
this.ret = n.ret || "html";
|
this.ret = n.ret || "html";
|
||||||
this.as = n.as || "single";
|
this.as = n.as || "single";
|
||||||
|
this.chr = n.chr || "_";
|
||||||
var node = this;
|
var node = this;
|
||||||
this.on("input", function(msg,send,done) {
|
this.on("input", function(msg,send,done) {
|
||||||
var value = RED.util.getMessageProperty(msg,node.property);
|
var value = RED.util.getMessageProperty(msg,node.property);
|
||||||
@ -47,6 +48,11 @@ module.exports = function(RED) {
|
|||||||
if (node.ret === "attr") {
|
if (node.ret === "attr") {
|
||||||
pay2 = Object.assign({},this.attribs);
|
pay2 = Object.assign({},this.attribs);
|
||||||
}
|
}
|
||||||
|
if (node.ret === "compl") {
|
||||||
|
var bse = {}
|
||||||
|
bse[node.chr] = $(this).html().trim()
|
||||||
|
pay2 = Object.assign(bse, this.attribs);
|
||||||
|
}
|
||||||
//if (node.ret === "val") { pay2 = $(this).val(); }
|
//if (node.ret === "val") { pay2 = $(this).val(); }
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (pay2) {
|
if (pay2) {
|
||||||
@ -69,6 +75,11 @@ module.exports = function(RED) {
|
|||||||
var attribs = Object.assign({},this.attribs);
|
var attribs = Object.assign({},this.attribs);
|
||||||
pay.push( attribs );
|
pay.push( attribs );
|
||||||
}
|
}
|
||||||
|
if (node.ret === "compl") {
|
||||||
|
var bse = {}
|
||||||
|
bse[node.chr] = $(this).html().trim()
|
||||||
|
pay.push( Object.assign(bse, this.attribs) )
|
||||||
|
}
|
||||||
//if (node.ret === "val") { pay.push( $(this).val() ); }
|
//if (node.ret === "val") { pay.push( $(this).val() ); }
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
@ -894,12 +894,14 @@
|
|||||||
"label": {
|
"label": {
|
||||||
"select": "Selector",
|
"select": "Selector",
|
||||||
"output": "Output",
|
"output": "Output",
|
||||||
"in": "in"
|
"in": "in",
|
||||||
|
"prefix": "Property name for HTML content"
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"html": "the html content of the elements",
|
"html": "the html content of the elements",
|
||||||
"text": "only the text content of the elements",
|
"text": "only the text content of the elements",
|
||||||
"attr": "an object of any attributes of the elements"
|
"attr": "an object of any attributes of the elements",
|
||||||
|
"compl": "an object of any attributes of the elements and html contents"
|
||||||
},
|
},
|
||||||
"format": {
|
"format": {
|
||||||
"single": "as a single message containing an array",
|
"single": "as a single message containing an array",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user