/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ RED.commandPrompt = (function() { var disabled = false; var dialog = null; var searchInput; var searchResults; var selected = -1; var visible = false; var results = []; var scopes = {}; function search(val) { scopes = {}; results = []; selected = -1; val = val ||""; searchResults.editableList('empty'); var actions = RED.actions.list(); actions.sort(function(A,B) { return A.id.localeCompare(B.id); }); val = val.trim().toLowerCase(); actions.forEach(function(action) { action.label = action.id.replace(/:/,": ").replace(/-/g," ").replace(/(^| )./g,function() { return arguments[0].toUpperCase()}); if (val !== "" && action.label.toLowerCase().indexOf(val) === -1) { return; } results.push(action); searchResults.editableList('addItem',action) }) } function ensureSelectedIsVisible() { var selectedEntry = searchResults.find("li.selected"); if (selectedEntry.length === 1) { var scrollWindow = searchResults.parent(); var scrollHeight = scrollWindow.height(); var scrollOffset = scrollWindow.scrollTop(); var y = selectedEntry.position().top; var h = selectedEntry.height(); if (y+h > scrollHeight) { scrollWindow.animate({scrollTop: '-='+(scrollHeight-(y+h)-10)},50); } else if (y<0) { scrollWindow.animate({scrollTop: '+='+(y-10)},50); } } } function createDialog() { dialog = $("