mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	HTML node: add option to for attribites and content
This commit is contained in:
		| @@ -14,6 +14,7 @@ | ||||
|             <option value="html" data-i18n="html.output.html"></option> | ||||
|             <option value="text" data-i18n="html.output.text"></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> --> | ||||
|         </select> | ||||
|     </div> | ||||
| @@ -28,6 +29,10 @@ | ||||
|         <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%"> | ||||
|     </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/> | ||||
|     <div class="form-row"> | ||||
|         <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 }) }, | ||||
|             tag: {value:""}, | ||||
|             ret: {value:"html"}, | ||||
|             as: {value:"single"} | ||||
|             as: {value:"single"}, | ||||
|             chr: { value: "_" } | ||||
|         }, | ||||
|         inputs:1, | ||||
|         outputs:1, | ||||
| @@ -59,6 +65,13 @@ | ||||
|         oneditprepare: function() { | ||||
|             $("#node-input-property").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> | ||||
|   | ||||
| @@ -25,6 +25,7 @@ module.exports = function(RED) { | ||||
|         this.tag = n.tag; | ||||
|         this.ret = n.ret || "html"; | ||||
|         this.as = n.as || "single"; | ||||
|         this.chr = n.chr || "_"; | ||||
|         var node = this; | ||||
|         this.on("input", function(msg,send,done) { | ||||
|             var value = RED.util.getMessageProperty(msg,node.property); | ||||
| @@ -47,6 +48,11 @@ module.exports = function(RED) { | ||||
|                             if (node.ret === "attr") { | ||||
|                                 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(); } | ||||
|                             /* istanbul ignore else */ | ||||
|                             if (pay2) { | ||||
| @@ -69,6 +75,11 @@ module.exports = function(RED) { | ||||
|                                 var attribs = Object.assign({},this.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() ); } | ||||
|                         } | ||||
|                         index++; | ||||
|   | ||||
| @@ -887,12 +887,14 @@ | ||||
|         "label": { | ||||
|             "select": "Selector", | ||||
|             "output": "Output", | ||||
|             "in": "in" | ||||
|             "in": "in", | ||||
|             "prefix": "Property name for HTML content" | ||||
|         }, | ||||
|         "output": { | ||||
|             "html": "the html 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": { | ||||
|             "single": "as a single message containing an array", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user