Best JavaScript code snippet using best
node-red-contrib-zway-helpers.js
Source:node-red-contrib-zway-helpers.js  
1function zway_gatewayScanner(nodeItem, selectedItemElementName, options = {}) {2    $.getJSON('zway/gwscanner', {})3        .done(function (data, textStatus, jqXHR) {4            console.log(data);5        }).fail(function (jqXHR, textStatus, errorThrown) {});6}7function zway_getItemList(nodeItem, selectedItemElementName, options = {}) {8    9    options = $.extend({10        filterType:'',11        disableReadonly:false,12        refresh:false,13        allowEmpty:false,14        deviceType:false,15        batteryFilter:false,16    }, options);17    function zway_updateItemList(controller, selectedItemElement, itemName, refresh = false) {18        // Remove all previous and/or static (if any) elements from 'select' input element19        selectedItemElement.children().remove();20        if (controller) {21            $.getJSON('zway/itemlist', {22                controllerID: controller.id,23                forceRefresh: refresh24            })25                .done(function (data, textStatus, jqXHR) {26                    try {27                        var disabled = '';28                        var nameSuffix = '';29                        var prevName = '';30                        var itemList = [];31                        32                        $.each(data.items, function(index, value) {33                            itemList.push(value)34                        });35                        var itemsByName = itemList.slice(0);36                        itemsByName.sort(function(a,b) {37                            var x = a.device_name.toLowerCase();38                            var y = b.device_name.toLowerCase();39                            return x < y ? -1 : x > y ? 1 : 0;40                        });41                        $.each(itemsByName, function(index, value) {42                            disabled = '';43                            nameSuffix = '';44                            if (value.meta === undefined) {45                                return true;46                            }47                            if (options.deviceType && options.deviceType != value.meta.deviceType) {48                                return true;49                            }50                            if (value.meta.deviceType === "text") {51                                return true;52                            }53                            if (options.batteryFilter && value.meta.deviceType !== "battery") {54                                return true;55                            }56                            var parentElement = selectedItemElement;57                            $('<option'+ disabled+' value="' + value.uniqueid +'">● ' + value.meta.metrics.title + (nameSuffix?' ('+nameSuffix+')':'') +'</option>').appendTo(parentElement);58                        });59                        // Enable item selection60                        selectedItemElement.multipleSelect('enable');61                        // Finally, set the value of the input select to the selected value62                        selectedItemElement.val(itemName);63                        // // Rebuild bootstrap multiselect form64                        selectedItemElement.multipleSelect('refresh');65                        // // Trim selected item string length with elipsis66                        var selectItemSpanElement = $(`span.multiselect-selected-text:contains("${itemName}")`);67                        var sHTML = selectItemSpanElement.html();68                        selectItemSpanElement.html(zway_truncateWithEllipses(sHTML, 35));69                    } catch (error) {70                        console.error('Error #4534');   71                        console.log(error);72                    }73                })74                .fail(function (jqXHR, textStatus, errorThrown) {75                    // Disable item selection if no items were retrieved76                    selectedItemElement.multipleSelect('disable');77                    selectedItemElement.multipleSelect('refresh');78                    //console.error(`Error: ${errorThrown}`);79                });80        } else {81            // Disable item selection if no (valid) controller was selected82            selectedItemElement.multipleSelect('disable');83            selectedItemElement.multipleSelect('refresh');84        }85    }86    var deServerElement = $('#node-input-server');87    var refreshListElement = $('#force-refresh');88    var selectedItemElement = $(selectedItemElementName);89    // Initialize bootstrap multiselect form90    selectedItemElement.multipleSelect({91        maxHeight: 300,92        dropWidth: 320,93        width: 320,94        single: !(typeof $(this).attr('multiple') !== typeof undefined && $(this).attr('multiple') !== false),95        filter: true,96        filterPlaceholder: RED._("node-red-contrib-zway/in:multiselect.filter_devices"),97        includeResetOption: true,98        includeResetDivider: true,99        resetText: RED._("node-red-contrib-zway/in:multiselect.refresh"),100        numberDisplayed: 1,101        disableIfEmpty: true,102        nSelectedText: 'selected',103        nonSelectedText: RED._("node-red-contrib-zway/in:multiselect.none_selected")104    });105    // Initial call to populate item list106    zway_updateItemList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem, false);107    // onChange event handler in case a new controller gets selected108    deServerElement.change(function (event) {109        zway_updateItemList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem, true);110    });111    refreshListElement.click(function (event) {112        // Force a refresh of the item list113        zway_updateItemList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem, true);114    });115}116function zway_getItemStateList(nodeItem, selectedItemElementName, options = {}) {117    options = $.extend({118        filterType:'',119        disableReadonly:false,120        refresh:false121    }, options);122    function zway_updateItemStateList(controller, selectedItemElement, itemName) {123        // Remove all previous and/or static (if any) elements from 'select' input element124        selectedItemElement.children().remove();125        var uniqueId = $('#node-input-device').val();126        if (controller && uniqueId) {127            $.getJSON('zway/statelist', {128                controllerID: controller.id,129                uniqueid:uniqueId130            })131                .done(function (data, textStatus, jqXHR) {132                    try {133                        selectedItemElement.html('<option value="0">'+ RED._("node-red-contrib-zway/in:multiselect.complete_payload")+'</option>');134                        $.each(data, function(index, value) {135                            // $('<option  value="' + index +'">'+index+'</option>').appendTo(selectedItemElement);136                            $('<option  value="' + index +'">'+index+' ('+value+')</option>').appendTo(selectedItemElement);137                        });138                        // Enable item selection139                        selectedItemElement.multipleSelect('enable');140                        // Finally, set the value of the input select to the selected value141                        selectedItemElement.val(itemName);142                        // Rebuild bootstrap multiselect form143                        selectedItemElement.multipleSelect('refresh');144                        // Trim selected item string length with elipsis145                        var selectItemSpanElement = $(`span.multiselect-selected-text:contains("${itemName}")`);146                        var sHTML = selectItemSpanElement.html();147                        selectItemSpanElement.html(zway_truncateWithEllipses(sHTML, 35));148                    } catch (error) {149                        console.error('Error #4534');150                        console.log(error);151                    }152                })153                .fail(function (jqXHR, textStatus, errorThrown) {154                    // Disable item selection if no items were retrieved155                    selectedItemElement.multipleSelect('disable');156                    selectedItemElement.multipleSelect('refresh');157                    //console.error(`Error: ${errorThrown}`);158                });159        } else {160            // Disable item selection if no (valid) controller was selected161            selectedItemElement.multipleSelect('disable');162            selectedItemElement.multipleSelect('refresh');163        }164    }165    var deServerElement = $('#node-input-server');166    var selectedItemElement = $(selectedItemElementName);167    var attr = $(this).attr('multiple');168    // Initialize bootstrap multiselect form169    selectedItemElement.multipleSelect({170        maxHeight: 300,171        dropWidth: 320,172        width: 320,173        single: !(typeof $(this).attr('multiple') !== typeof undefined && $(this).attr('multiple') !== false),174        filter: true,175        filterPlaceholder: RED._("node-red-contrib-zway/in:multiselect.filter_devices"),176        includeResetOption: true,177        includeResetDivider: true,178        resetText: RED._("node-red-contrib-zway/in:multiselect.refresh"),179        numberDisplayed: 1,180        disableIfEmpty: true,181        nSelectedText: 'selected',182        nonSelectedText: RED._("node-red-contrib-zway/in:multiselect.none_selected")183    });184    // Initial call to populate item list185    zway_updateItemStateList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem);186    // onChange event handler in case a new controller gets selected187    deServerElement.change(function (event) {188        zway_updateItemStateList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem);189    });190}191/**192 * truncateWithEllipses193 *194 * Utility function to truncate long strings with elipsis ('...')195 *196 */197function zway_truncateWithEllipses(text, max = 30) {198    if (text) {199        return text.substr(0, max - 1) + (text.length > max ? '…' : '');200    } else {201        return text;202    }203}204function zway_filterDeviceName(name) {205    var result =  name.replace(/ *\([^)]*\) */g, ""); //remove (lights: 1)206    result = result.replace(new RegExp('â', 'g'), '');207    result = result.trim();208    return result;...node-red-contrib-zwavejs2mqtt2-helpers.js
Source:node-red-contrib-zwavejs2mqtt2-helpers.js  
1function z2m_getItemList(nodeItem, selectedItemElementName, options = {}) {2    options = $.extend({3        filterType:'',4        disableReadonly:false,5        refresh:false,6        allowEmpty:false7    }, options);8    function z2m_updateItemList(controller, selectedItemElement, itemName, refresh = false) {9        // Remove all previous and/or static (if any) elements from 'select' input element10        selectedItemElement.children().remove();11        if (controller) {12            selectedItemElement.multipleSelect('disable');13            $.getJSON('zwavejs2mqtt2/getDevices', {14                controllerID: controller.id,15                forceRefresh: refresh16            })17                .done(function (data, textStatus, jqXHR) {18                    try {19                        if (options.allowEmpty) {20                            selectedItemElement.html('<option value="">--Select device</option>');21                        }22                        var optgroup = '';23                        var disabled = '';24                        var nameSuffix = '';25                        // var selected = false;26                        var groupHtml = '';27                        var names = {};28                        var devices = data[0];29                       // var groups = data[1];30                        //groups31                        /*32                        groupHtml = $('<optgroup/>', {label: RED._("node-red-contrib-zwavejs2mqtt2/in:multiselect.groups")});33                        groupHtml.appendTo(selectedItemElement);34                        $.each(groups, function(index, value) {35                            names[value.ID] = value.name;36                            var text = '';37                            if ("devices" in value && typeof(value.devices) != 'undefined' && value.devices.length > 0) {38                                text = ' ('+value.devices.length+')';39                            }40                            $('<option value="' + value.ID + '" data-friendly_name="'+value.name+'">' + value.name + text + '</option>').appendTo(groupHtml);41                        });42                        */43                        //devices44                        groupHtml = $('<optgroup/>', {label: RED._("node-red-contrib-zwavejs2mqtt2/in:multiselect.devices")});45                        groupHtml.appendTo(selectedItemElement);46                        $.each(devices, function(index, value) {47                            names[value.id] = value.name;48                            var model = '';49                         //   if ("modelID" in value && typeof(value.modelID) != undefined) {50                                model = ' (' + value.productDescription + ')';51                         //   }52                            $('<option value="' + value.id + '" data-friendly_name="'+value.name+'">' + value.name + model + '</option>').appendTo(groupHtml);53                        });54                        // Enable item selection55                        selectedItemElement.multipleSelect('enable');56                        // Finally, set the value of the input select to the selected value57                        selectedItemElement.val(itemName);58                        // Rebuild bootstrap multiselect form59                        selectedItemElement.multipleSelect('refresh');60                        // // Trim selected item string length with elipsis61                        var selectItemSpanElement = $(`span.multiselect-selected-text:contains("${itemName}")`);62                        var sHTML = selectItemSpanElement.html();63                        selectItemSpanElement.html(z2m_truncateWithEllipses(sHTML, 35));64                        $('#node-input-friendly_name').val(names[itemName]);65                    } catch (error) {66                        console.error('Error #4534');67                        console.log(error);68                    }69                })70                .fail(function (jqXHR, textStatus, errorThrown) {71                    // Disable item selection if no items were retrieved72                    selectedItemElement.multipleSelect('disable');73                    selectedItemElement.multipleSelect('refresh');74                    //console.error(`Error: ${errorThrown}`);75                });76        } else {77            // Disable item selection if no (valid) controller was selected78            selectedItemElement.multipleSelect('disable');79            selectedItemElement.multipleSelect('refresh');80        }81    }82    var ServerElement = $('#node-input-server');83    var refreshListElement = $('#force-refresh');84    var selectedItemElement = $(selectedItemElementName);85    // Initialize  multiselect86    selectedItemElement.multipleSelect({87        maxHeight: 300,88        dropWidth: 320,89        width: 320,90        filter: true91    });92    var values = [];93    var isMultiple = selectedItemElement.attr('multiple')!==undefined;94    if (isMultiple) {95        values = selectedItemElement.val().length ? selectedItemElement.val() : nodeItem;96    } else {97        values = selectedItemElement.val() || nodeItem;98    }99    // Initial call to populate item list100    z2m_updateItemList(RED.nodes.node(ServerElement.val()), selectedItemElement, values, false);101    // onChange event handler in case a new controller gets selected102    ServerElement.change(function (event) {103        z2m_updateItemList(RED.nodes.node(ServerElement.val()), selectedItemElement, values, true);104    });105    refreshListElement.click(function (event) {106        // Force a refresh of the item list107        z2m_updateItemList(RED.nodes.node(ServerElement.val()), selectedItemElement, values, true);108    });109}110function z2m_truncateWithEllipses(text, max = 30) {111    if (text) {112        return text.substr(0, max - 1) + (text.length > max ? '…' : '');113    } else {114        return text;115    }116}117function z2m_getItemStateList(nodeItem, selectedItemElementName, options = {}) {118    options = $.extend({119        filterType:'',120        disableReadonly:false,121        refresh:false122    }, options);123    function z2m_updateItemStateList(controller, selectedItemElement, itemName) {124        // Remove all previous and/or static (if any) elements from 'select' input element125        selectedItemElement.children().remove();126        var uniqueId = $('#node-input-device_id').val();127        if (controller && uniqueId) {128            $.getJSON('zwavejs2mqtt2/getLastStateById', {129                controllerID: controller.id,130                device_id:uniqueId131            })132                .done(function (data, textStatus, jqXHR) {133                    try {134                        selectedItemElement.html('<option value="0">'+ RED._("node-red-contrib-zwavejs2mqtt2/in:multiselect.complete_payload")+'</option>');135                        var groupHtml = '';136                        if (data[0] && Object.keys(data[0]).length) {137                            groupHtml = $('<optgroup/>', {label: RED._("node-red-contrib-zwavejs2mqtt2/in:multiselect.zwavejs2mqtt2")});138                            groupHtml.appendTo(selectedItemElement);139                            $.each(data[0], function (index, value) {140                                var text = index;141                                if (typeof (value) != 'object') text += ' (' + value + ')';142                                $('<option  value="' + index + '">' + text + '</option>').appendTo(groupHtml);143                            });144                        }145                       146                        // Enable item selection147                        selectedItemElement.multipleSelect('enable');148                        // console.log('=======>');console.log(itemName);149                        // Finally, set the value of the input select to the selected value150                        if (selectedItemElement.find('option[value='+itemName+']').length) {151                            selectedItemElement.val(itemName);152                        } else {153                            selectedItemElement.val(selectedItemElement.find('option').eq(0).attr('value'));154                        }155                        selectedItemElement.multipleSelect('destroy');156                        // Trim selected item string length with elipsis157                        var selectItemSpanElement = $(`span.multiselect-selected-text:contains("${itemName}")`);158                        var sHTML = selectItemSpanElement.html();159                        selectItemSpanElement.html(z2m_truncateWithEllipses(sHTML, 35));160                    } catch (error) {161                        console.error('Error #4534');162                        console.log(error);163                    }164                })165                .fail(function (jqXHR, textStatus, errorThrown) {166                    // Disable item selection if no items were retrieved167                    selectedItemElement.multipleSelect('disable');168                    selectedItemElement.multipleSelect('refresh');169                    //console.error(`Error: ${errorThrown}`);170                });171        } else {172            // Disable item selection if no (valid) controller was selected173            selectedItemElement.multipleSelect('disable');174            selectedItemElement.multipleSelect('refresh');175        }176    }177    var deServerElement = $('#node-input-server');178    var selectedItemElement = $(selectedItemElementName);179    // Initialize bootstrap multiselect form180    selectedItemElement.multipleSelect('destroy');181    selectedItemElement.multipleSelect({182        numberDisplayed: 1,183        dropWidth: 320,184        width: 320,185        single: !(typeof $(this).attr('multiple') !== typeof undefined && $(this).attr('multiple') !== false)186    });187    // Initial call to populate item list188    z2m_updateItemStateList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem);189    // onChange event handler in case a new controller gets selected190    deServerElement.change(function (event) {191        z2m_updateItemStateList(RED.nodes.node(deServerElement.val()), selectedItemElement, selectedItemElement.val() || nodeItem);192    });...CompletionSuggestionsView.js
Source:CompletionSuggestionsView.js  
...148            this._containerElement.appendChild(itemElement);149        }150    },151    // Private152    get _selectedItemElement()153    {154        if (isNaN(this._selectedIndex))155            return null;156        var element = this._containerElement.children[this._selectedIndex] || null;157        console.assert(element);158        return element;159    },160    _mouseDown: function(event)161    {162        if (event.button !== 0)163            return;164        this._mouseIsDown = true;165    },166    _mouseUp: function(event)...Using AI Code Generation
1var selectedElement = BestInPlaceEditor.selectedItemElement();2var selectedValue = BestInPlaceEditor.selectedItemValue();3var selectedId = BestInPlaceEditor.selectedItemId();4var selectedClass = BestInPlaceEditor.selectedItemClass();5var selectedData = BestInPlaceEditor.selectedItemData();6var selectedData = BestInPlaceEditor.selectedItemData();7var selectedData = BestInPlaceEditor.selectedItemData();8var selectedData = BestInPlaceEditor.selectedItemData();9var selectedData = BestInPlaceEditor.selectedItemData();10var selectedData = BestInPlaceEditor.selectedItemData();11var selectedData = BestInPlaceEditor.selectedItemData();12var selectedData = BestInPlaceEditor.selectedItemData();13var selectedData = BestInPlaceEditor.selectedItemData();14var selectedData = BestInPlaceEditor.selectedItemData();15var selectedData = BestInPlaceEditor.selectedItemData();Using AI Code Generation
1var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');2editor.selectedItemElement().html("My new text");3editor.selectedItemElement().css("color", "red");4editor.selectedItemElement().css("font-weight", "bold");5var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');6var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');7var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');8var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');9var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');10var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');11var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');12var editor = $('#myBestInPlaceEditor').data('bestInPlaceEditor');13var editor = $('#myBestInPlaceEditor').data('bestInPlaceUsing AI Code Generation
1var editor = BestInPlaceEditor.selectedItemElement();2var element = editor.element;3var value = editor.getValue();4editor.abort();5editor.update();6editor.activateForm();7editor.activateInPlaceEditor();8editor.loadSuccess();9editor.loadFailure();10editor.abortFailure();11editor.updateFailure();12editor.activateFailure();13editor.activateInPlaceEditorFailure();14editor.loadRemoteData();15editor.updateRemoteData();16editor.updateRemoteDataSuccess();17editor.updateRemoteDataFailure();18editor.loadRemoteDataSuccess();19editor.loadRemoteDataFailure();20editor.abortRemoteData();21editor.abortRemoteDataSuccess();22editor.abortRemoteDataFailure();23editor.activateRemoteData();24editor.activateRemoteDataSuccess();25editor.activateRemoteDataFailure();26editor.activateInPlaceEditorRemoteData();27editor.activateInPlaceEditorRemoteDataSuccess();28editor.activateInPlaceEditorRemoteDataFailure();29editor.loadRemoteData();30editor.loadRemoteDataSuccess();31editor.loadRemoteDataFailure();32editor.updateRemoteData();33editor.updateRemoteDataSuccess();34editor.updateRemoteDataFailure();35editor.abortRemoteData();36editor.abortRemoteDataSuccess();37editor.abortRemoteDataFailure();38editor.activateRemoteData();39editor.activateRemoteDataSuccess();40editor.activateRemoteDataFailure();41editor.activateInPlaceEditorRemoteData();42editor.activateInPlaceEditorRemoteDataSuccess();43editor.activateInPlaceEditorRemoteDataFailure();44editor.activateInPlaceEditor();45editor.activateInPlaceEditorSuccess();46editor.activateInPlaceEditorFailure();47editor.loadRemoteData();48editor.loadRemoteDataSuccess();49editor.loadRemoteDataFailure();50editor.updateRemoteData();51editor.updateRemoteDataSuccess();52editor.updateRemoteDataFailure();53editor.abortRemoteData();Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
