|
| 1 | +/** |
| 2 | + * Copyright JS Foundation and other contributors, http://js.foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + **/ |
| 16 | + |
| 17 | +RED.userSettings = (function() { |
| 18 | + |
| 19 | + var trayWidth = null; |
| 20 | + var settingsVisible = false; |
| 21 | + |
| 22 | + function show() { |
| 23 | + if (settingsVisible) { |
| 24 | + return; |
| 25 | + } |
| 26 | + settingsVisible = true; |
| 27 | + |
| 28 | + var trayOptions = { |
| 29 | + title: "User Settings", |
| 30 | + buttons: [ |
| 31 | + { |
| 32 | + id: "node-dialog-ok", |
| 33 | + text: RED._("common.label.close"), |
| 34 | + class: "primary", |
| 35 | + click: function() { |
| 36 | + RED.tray.close(); |
| 37 | + } |
| 38 | + } |
| 39 | + ], |
| 40 | + resize: function(dimensions) { |
| 41 | + trayWidth = dimensions.width; |
| 42 | + }, |
| 43 | + open: function(tray) { |
| 44 | + var trayBody = tray.find('.editor-tray-body'); |
| 45 | + |
| 46 | + $('<ul></ul>',{id:"user-settings-tabs"}).appendTo(trayBody); |
| 47 | + var tabContents = $('<div></div>',{id:"user-settings-tabs-content"}).appendTo(trayBody); |
| 48 | + |
| 49 | + $('<div class="hide" id="user-settings-tab-view">View Tab</div>').appendTo(tabContents); |
| 50 | + $('<div class="hide" id="user-settings-tab-keyboard">Keyboard Tab</div>').appendTo(tabContents); |
| 51 | + $('<div class="hide" id="user-settings-tab-something">Something Tab</div>').appendTo(tabContents); |
| 52 | + |
| 53 | + |
| 54 | + var tabs = RED.tabs.create({ |
| 55 | + id: "user-settings-tabs", |
| 56 | + onchange: function(tab) { |
| 57 | + $("#user-settings-tabs-content").children().hide(); |
| 58 | + $("#" + tab.id).show(); |
| 59 | + } |
| 60 | + }); |
| 61 | + tabs.addTab({ |
| 62 | + id: "user-settings-tab-view", |
| 63 | + label: "View" |
| 64 | + }); |
| 65 | + tabs.addTab({ |
| 66 | + id: "user-settings-tab-keyboard", |
| 67 | + label: "Keyboard Shortcuts" |
| 68 | + }); |
| 69 | + tabs.addTab({ |
| 70 | + id: "user-settings-tab-something", |
| 71 | + label: "Something Else" |
| 72 | + }); |
| 73 | + }, |
| 74 | + close: function() { |
| 75 | + settingsVisible = false; |
| 76 | + }, |
| 77 | + show: function() {} |
| 78 | + } |
| 79 | + if (trayWidth !== null) { |
| 80 | + trayOptions.width = trayWidth; |
| 81 | + } |
| 82 | + RED.tray.show(trayOptions); |
| 83 | + } |
| 84 | + |
| 85 | + function init() { |
| 86 | + RED.actions.add("core:show-user-settings",show); |
| 87 | + } |
| 88 | + return { |
| 89 | + init: init |
| 90 | + }; |
| 91 | +})(); |
0 commit comments