liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<script type="text/javascript">
    RED.nodes.registerType('ui_colour_picker',{
        category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
        color: 'rgb(176, 223, 227)',
        defaults: {
            name: {value: ''},
            label: {value: ''},
            group: {type: 'ui_group', required: true},
            format: {value: 'hex'},
            outformat: {value: 'string'},
            showSwatch: {value: true},
            showPicker: {value: false},
            showValue: {value: false},
            showHue: {value: false},
            showAlpha: {value: false},
            showLightness: {value: true},
            square: {value: "false"},
            dynOutput: {value: "false"},
            order: {value: 0},
            width: {value: 0, validate: function(v) {
                    var width = v||0;
                    var currentGroup = $('#node-input-group').val()||this.group;
                    var groupNode = RED.nodes.node(currentGroup);
                    var valid = !groupNode || +width <= +groupNode.width;
                    $("#node-input-size").toggleClass("input-error",!valid);
                    return valid;
                }
            },
            height: {value: 0},
            passthru: {value: true},
            topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
            topicType: {value: 'msg'},
            className: {value: ''}
        },
        inputs:1,
        outputs:1,
        outputLabels: function() { return this.format; },
        icon: "ui_colour_picker.png",
        paletteLabel: 'colour picker',
        label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'colour picker'; },
        labelStyle: function() { return this.name?"node_label_italic":""; },
        oneditprepare: function() {
            if (this.square === undefined) {
                this.square = "false";
                $("#node-input-square").val("false");
            }
            $("#node-input-square").on("change", function() {
                if ($("#node-input-square").val() === "false") {
                    $("#node-input-showLightness").prop('checked', true);
                    $("#node-input-showHue").prop('checked', false);
                }
                else {
                    $("#node-input-showLightness").prop('checked', false);
                    $("#node-input-showHue").prop('checked', true);
                }
            });
            $("#node-input-size").elementSizer({
                width: "#node-input-width",
                height: "#node-input-height",
                group: "#node-input-group"
            });
            $("#node-input-format").on("change", function() {
                if ($(this).val() === "hex") {
                    $("#node-alpha-control").hide();
                }
                else {
                    $("#node-alpha-control").show();
                }
            });
            $('#node-input-topic').typedInput({
                default: 'str',
                typeField: $("#node-input-topicType"),
                types: ['str','msg','flow','global']
            });
        },
        oneditsave: function() {
            if (!$("#node-input-showPicker").is(':checked') && !$("#node-input-showValue").is(':checked')) {
                $("#node-input-showSwatch").prop('checked', true);
                this.showSwatch = true;
            }
        }
    });
</script>
 
<script type="text/html" data-template-name="ui_colour_picker">
    <div class="form-row">
        <label for="node-input-group"><i class="fa fa-table"></i> Group</label>
        <input type="text" id="node-input-group">
    </div>
    <div class="form-row">
        <label><i class="fa fa-object-group"></i> Size</label>
        <input type="hidden" id="node-input-width">
        <input type="hidden" id="node-input-height">
        <button class="editor-button" id="node-input-size"></button>
    </div>
    <div class="form-row">
        <label for="node-input-label"><i class="fa fa-i-cursor"></i> Label</label>
        <input type="text" id="node-input-label">
    </div>
    <div class="form-row">
        <label for="node-input-format"><i class="fa fa-keyboard-o"></i> Format</label>
        <select id="node-input-format" style="width:156px;">
            <option value="hex">hex</option>
            <option value="hex8">hex8</option>
            <option value="hsl">hsl</option>
            <option value="hsv">hsv</option>
            <option value="rgb">rgb</option>
        </select>
        <select id="node-input-square" style="width:130px; margin-left:30px">
            <option value="false">round</option>
            <option value="true">square</option>
        </select>
    </div>
    <div class="form-row">
        <label>&nbsp;</label> Show hue slider : <input type="checkbox" id="node-input-showHue" style="display:inline-block; width:auto; vertical-align:baseline;">
        <br/>
        <label>&nbsp;</label> Show lightness slider : <input type="checkbox" id="node-input-showLightness" style="display:inline-block; width:auto; vertical-align:baseline;">
        <br/>
        <span id="node-alpha-control"><label>&nbsp;</label> Show transparency slider : <input type="checkbox" id="node-input-showAlpha" style="display:inline-block; width:auto; vertical-align:baseline;"></span>
    </div>
    <div class="form-row">
        If width is 4 or greater:<br/>
        <label>&nbsp;</label>
        Always show swatch : <input type="checkbox" checked id="node-input-showSwatch" style="display:inline-block; width:auto; vertical-align:top;">
        <br/>
        <label>&nbsp;</label>
        Always show picker : <input type="checkbox" checked id="node-input-showPicker" style="display:inline-block; width:auto; vertical-align:top;">
        <br/>
        <label>&nbsp;</label>
        Always show value field : <input type="checkbox" checked id="node-input-showValue" style="display:inline-block; width:auto; vertical-align:top;">
    </div>
    <div class="form-row">
        <label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> If <code>msg</code> arrives on input, pass through to output: </label>
        <input type="checkbox" checked id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
    </div>
    <div class="form-row">
        <label for="node-input-dynOutput"><i class="fa fa-envelope-o"></i> Send</label>
        <select id="node-input-dynOutput" style="width:60%">
            <option value="false">one value when released/closed</option>
            <option value="true">multiple values during editing</option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-outformat" style="padding-left: 25px; margin-right: -25px">Payload</label>
        <select id="node-input-outformat" style="width:60%">
            <option value="string">current value as a string</option>
            <option value="object">current value as an object</option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-topic" style="padding-left: 25px; margin-right: -25px">Topic</label>
        <input type="text" id="node-input-topic" placeholder="optional topic">
        <input type="hidden" id="node-input-topicType">
    </div>
    <div class="form-row">
        <label for="node-input-className"><i class="fa fa-code"></i>  Class</label>
        <input type="text" id="node-input-className" placeholder="Optional CSS class name(s) for widget"/>
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name">
    </div>
</script>