| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var MIN_VERSION_TAB_CLOSE = 25; | 5 var MIN_VERSION_TAB_CLOSE = 25; |
| 6 var MIN_VERSION_TARGET_ID = 26; | 6 var MIN_VERSION_TARGET_ID = 26; |
| 7 var MIN_VERSION_NEW_TAB = 29; | 7 var MIN_VERSION_NEW_TAB = 29; |
| 8 var MIN_VERSION_TAB_ACTIVATE = 30; | 8 var MIN_VERSION_TAB_ACTIVATE = 30; |
| 9 var WEBRTC_SERIAL = 'WEBRTC'; | 9 var WEBRTC_SERIAL = 'WEBRTC'; |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 var hash = window.location.hash.slice(1).toLowerCase(); | 67 var hash = window.location.hash.slice(1).toLowerCase(); |
| 68 if (!selectTab(hash)) | 68 if (!selectTab(hash)) |
| 69 selectTab('devices'); | 69 selectTab('devices'); |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * @param {string} id Tab id. | 73 * @param {string} id Tab id. |
| 74 * @return {boolean} True if successful. | 74 * @return {boolean} True if successful. |
| 75 */ | 75 */ |
| 76 function selectTab(id) { | 76 function selectTab(id) { |
| 77 closePortForwardingConfig(); | |
| 78 | |
| 79 var tabContents = document.querySelectorAll('#content > div'); | 77 var tabContents = document.querySelectorAll('#content > div'); |
| 80 var tabHeaders = $('navigation').querySelectorAll('.tab-header'); | 78 var tabHeaders = $('navigation').querySelectorAll('.tab-header'); |
| 81 var found = false; | 79 var found = false; |
| 82 for (var i = 0; i != tabContents.length; i++) { | 80 for (var i = 0; i != tabContents.length; i++) { |
| 83 var tabContent = tabContents[i]; | 81 var tabContent = tabContents[i]; |
| 84 var tabHeader = tabHeaders[i]; | 82 var tabHeader = tabHeaders[i]; |
| 85 if (tabContent.id == id) { | 83 if (tabContent.id == id) { |
| 86 tabContent.classList.add('selected'); | 84 tabContent.classList.add('selected'); |
| 87 tabHeader.classList.add('selected'); | 85 tabHeader.classList.add('selected'); |
| 88 found = true; | 86 found = true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 var browserUser = browserSection.querySelector('.browser-user'); | 165 var browserUser = browserSection.querySelector('.browser-user'); |
| 168 if (browserUser) | 166 if (browserUser) |
| 169 browserUser.hidden = hasSingleUser; | 167 browserUser.hidden = hasSingleUser; |
| 170 }); | 168 }); |
| 171 } | 169 } |
| 172 | 170 |
| 173 function populateRemoteTargets(devices) { | 171 function populateRemoteTargets(devices) { |
| 174 if (!devices) | 172 if (!devices) |
| 175 return; | 173 return; |
| 176 | 174 |
| 177 if ($('port-forwarding-config').open) { | 175 if ($('config-dialog').open) { |
| 178 window.holdDevices = devices; | 176 window.holdDevices = devices; |
| 179 return; | 177 return; |
| 180 } | 178 } |
| 181 | 179 |
| 182 function browserCompare(a, b) { | 180 function browserCompare(a, b) { |
| 183 if (a.adbBrowserName != b.adbBrowserName) | 181 if (a.adbBrowserName != b.adbBrowserName) |
| 184 return a.adbBrowserName < b.adbBrowserName; | 182 return a.adbBrowserName < b.adbBrowserName; |
| 185 if (a.adbBrowserVersion != b.adbBrowserVersion) | 183 if (a.adbBrowserVersion != b.adbBrowserVersion) |
| 186 return a.adbBrowserVersion < b.adbBrowserVersion; | 184 return a.adbBrowserVersion < b.adbBrowserVersion; |
| 187 return a.id < b.id; | 185 return a.id < b.id; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 function handleKey(e) { | 590 function handleKey(e) { |
| 593 if (e.key == 'Enter' || e.key == ' ') { | 591 if (e.key == 'Enter' || e.key == ' ') { |
| 594 e.preventDefault(); | 592 e.preventDefault(); |
| 595 handler(); | 593 handler(); |
| 596 } | 594 } |
| 597 } | 595 } |
| 598 link.addEventListener('keydown', handleKey, true); | 596 link.addEventListener('keydown', handleKey, true); |
| 599 row.querySelector('.actions').appendChild(link); | 597 row.querySelector('.actions').appendChild(link); |
| 600 } | 598 } |
| 601 | 599 |
| 600 function initSettings() { |
| 601 checkboxSendsCommand('discover-usb-devices-enable', |
| 602 'set-discover-usb-devices-enabled'); |
| 603 checkboxSendsCommand('port-forwarding-enable', 'set-port-forwarding-enabled'); |
| 604 checkboxSendsCommand('discover-tcp-devices-enable', |
| 605 'set-discover-tcp-targets-enabled'); |
| 602 | 606 |
| 603 function initSettings() { | |
| 604 $('discover-usb-devices-enable').addEventListener('change', | |
| 605 enableDiscoverUsbDevices); | |
| 606 | |
| 607 $('port-forwarding-enable').addEventListener('change', enablePortForwarding); | |
| 608 $('port-forwarding-config-open').addEventListener( | 607 $('port-forwarding-config-open').addEventListener( |
| 609 'click', openPortForwardingConfig); | 608 'click', openPortForwardingConfig); |
| 610 $('port-forwarding-config-close').addEventListener( | 609 $('tcp-discovery-config-open').addEventListener( |
| 611 'click', closePortForwardingConfig); | 610 'click', openTargetsConfig); |
| 612 $('port-forwarding-config-done').addEventListener( | 611 $('config-dialog-close').addEventListener('click', function() { |
| 613 'click', commitPortForwardingConfig.bind(null, true)); | 612 $('config-dialog').commit(true); |
| 613 }); |
| 614 } | 614 } |
| 615 | 615 |
| 616 function enableDiscoverUsbDevices(event) { | 616 function checkboxHandler(command, event) { |
| 617 sendCommand('set-discover-usb-devices-enabled', event.target.checked); | 617 sendCommand(command, event.target.checked); |
| 618 } | 618 } |
| 619 | 619 |
| 620 function enablePortForwarding(event) { | 620 function checkboxSendsCommand(id, command) { |
| 621 sendCommand('set-port-forwarding-enabled', event.target.checked); | 621 $(id).addEventListener('change', checkboxHandler.bind(null, command)); |
| 622 } | 622 } |
| 623 | 623 |
| 624 function handleKey(event) { | 624 function handleKey(event) { |
| 625 switch (event.keyCode) { | 625 switch (event.keyCode) { |
| 626 case 13: // Enter | 626 case 13: // Enter |
| 627 var dialog = $('config-dialog'); |
| 627 if (event.target.nodeName == 'INPUT') { | 628 if (event.target.nodeName == 'INPUT') { |
| 628 var line = event.target.parentNode; | 629 var line = event.target.parentNode; |
| 629 if (!line.classList.contains('fresh') || | 630 if (!line.classList.contains('fresh') || |
| 630 line.classList.contains('empty')) { | 631 line.classList.contains('empty')) { |
| 631 commitPortForwardingConfig(true); | 632 dialog.commit(true); |
| 632 } else { | 633 } else { |
| 633 commitFreshLineIfValid(true /* select new line */); | 634 commitFreshLineIfValid(true /* select new line */); |
| 634 commitPortForwardingConfig(false); | 635 dialog.commit(false); |
| 635 } | 636 } |
| 636 } else { | 637 } else { |
| 637 commitPortForwardingConfig(true); | 638 dialog.commit(true); |
| 638 } | 639 } |
| 639 break; | 640 break; |
| 640 } | 641 } |
| 641 } | 642 } |
| 642 | 643 |
| 643 function openPortForwardingConfig() { | 644 function commitDialog(commitHandler, shouldClose) { |
| 644 loadPortForwardingConfig(window.portForwardingConfig); | 645 var element = $('config-dialog'); |
| 645 | 646 if (element.open && shouldClose) { |
| 646 $('port-forwarding-config').showModal(); | 647 element.onclose = null; |
| 647 document.addEventListener('keyup', handleKey); | 648 element.close(); |
| 648 $('port-forwarding-config').onclose = function() { | 649 document.removeEventListener('keyup', handleKey); |
| 649 commitPortForwardingConfig(true); | 650 if (window.holdDevices) { |
| 650 }; | 651 populateRemoteTargets(window.holdDevices); |
| 651 | 652 delete window.holdDevices; |
| 652 var freshPort = document.querySelector('.fresh .port'); | 653 } |
| 653 if (freshPort) | 654 } |
| 654 freshPort.focus(); | 655 commitFreshLineIfValid(); |
| 655 else | 656 commitHandler(); |
| 656 $('port-forwarding-config-done').focus(); | |
| 657 } | 657 } |
| 658 | 658 |
| 659 function closePortForwardingConfig() { | 659 function openConfigDialog(dialogClass, commitHandler, lineFactory, data) { |
| 660 if (!$('port-forwarding-config').open) | 660 var dialog = $('config-dialog'); |
| 661 if (dialog.open) |
| 661 return; | 662 return; |
| 662 | 663 |
| 663 $('port-forwarding-config').onclose = null; | 664 dialog.className = dialogClass; |
| 664 $('port-forwarding-config').close(); | 665 dialog.classList.add('config'); |
| 665 document.removeEventListener('keyup', handleKey); | |
| 666 | 666 |
| 667 if (window.holdDevices) { | 667 document.addEventListener('keyup', handleKey); |
| 668 populateRemoteTargets(window.holdDevices); | 668 dialog.commit = commitDialog.bind(null, commitHandler); |
| 669 delete window.holdDevices; | 669 dialog.onclose = commitDialog.bind(null, commitHandler, true); |
| 670 $('button-done').onclick = dialog.onclose; |
| 671 |
| 672 var list = $('config-dialog').querySelector('.list'); |
| 673 list.textContent = ''; |
| 674 |
| 675 list.createRow = appendRow.bind(null, list, lineFactory); |
| 676 for (var key in data) |
| 677 list.createRow(key, data[key]); |
| 678 list.createRow(null, null); |
| 679 |
| 680 dialog.showModal(); |
| 681 var defaultFocus = dialog.querySelector('.fresh .preselected'); |
| 682 if (defaultFocus) |
| 683 defaultFocus.focus(); |
| 684 else |
| 685 doneButton.focus(); |
| 686 |
| 687 } |
| 688 |
| 689 function openPortForwardingConfig() { |
| 690 function createPortForwardingConfigLine(port, location) { |
| 691 var line = document.createElement('div'); |
| 692 line.className = 'port-forwarding-pair config-list-row'; |
| 693 |
| 694 var portInput = createConfigField(port, 'port preselected', |
| 695 'Port', validatePort); |
| 696 line.appendChild(portInput); |
| 697 |
| 698 var locationInput = createConfigField( |
| 699 location, 'location', 'IP address and port', validateLocation); |
| 700 locationInput.classList.add('primary'); |
| 701 line.appendChild(locationInput); |
| 702 return line; |
| 703 } |
| 704 |
| 705 function commitPortForwardingConfig() { |
| 706 var config = {}; |
| 707 filterList(['.port', '.location'], function(port, location) { |
| 708 config[port] = location; |
| 709 }); |
| 710 sendCommand('set-port-forwarding-config', config); |
| 711 } |
| 712 |
| 713 openConfigDialog('port-forwarding', |
| 714 commitPortForwardingConfig, |
| 715 createPortForwardingConfigLine, |
| 716 window.portForwardingConfig); |
| 717 } |
| 718 |
| 719 function openTargetsConfig() { |
| 720 function createTargetDiscoveryConfigLine(index, targetDiscovery) { |
| 721 var line = document.createElement('div'); |
| 722 line.className = 'target-discovery-line config-list-row'; |
| 723 |
| 724 var locationInput = createConfigField( |
| 725 targetDiscovery, 'location preselected', 'IP address and port', |
| 726 validateLocation); |
| 727 locationInput.classList.add('primary'); |
| 728 line.appendChild(locationInput); |
| 729 return line; |
| 730 } |
| 731 |
| 732 function commitTargetDiscoveryConfig() { |
| 733 var entries = []; |
| 734 filterList(['.location'], function(location) { |
| 735 entries.push(location); |
| 736 }); |
| 737 sendCommand('set-tcp-discovery-config', entries); |
| 738 } |
| 739 |
| 740 openConfigDialog('target-discovery', |
| 741 commitTargetDiscoveryConfig, |
| 742 createTargetDiscoveryConfigLine, |
| 743 window.targetDiscoveryConfig); |
| 744 } |
| 745 |
| 746 function filterList(fieldSelectors, callback) { |
| 747 var lines = $('config-dialog').querySelectorAll('.config-list-row'); |
| 748 for (var i = 0; i != lines.length; i++) { |
| 749 var line = lines[i]; |
| 750 var values = []; |
| 751 for (var selector of fieldSelectors) { |
| 752 var input = line.querySelector(selector); |
| 753 var value = input.classList.contains('invalid') ? |
| 754 input.lastValidValue : |
| 755 input.value; |
| 756 if (!value) |
| 757 break; |
| 758 values.push(value); |
| 759 } |
| 760 if (values.length == fieldSelectors.length) |
| 761 callback.apply(null, values); |
| 670 } | 762 } |
| 671 } | 763 } |
| 672 | 764 |
| 673 function loadPortForwardingConfig(config) { | 765 function updateCheckbox(id, enabled) { |
| 674 var list = $('port-forwarding-config-list'); | 766 var checkbox = $(id); |
| 675 list.textContent = ''; | |
| 676 for (var port in config) | |
| 677 list.appendChild(createConfigLine(port, config[port])); | |
| 678 list.appendChild(createEmptyConfigLine()); | |
| 679 } | |
| 680 | |
| 681 function commitPortForwardingConfig(closeConfig) { | |
| 682 if (closeConfig) | |
| 683 closePortForwardingConfig(); | |
| 684 | |
| 685 commitFreshLineIfValid(); | |
| 686 var lines = document.querySelectorAll('.port-forwarding-pair'); | |
| 687 var config = {}; | |
| 688 for (var i = 0; i != lines.length; i++) { | |
| 689 var line = lines[i]; | |
| 690 var portInput = line.querySelector('.port'); | |
| 691 var locationInput = line.querySelector('.location'); | |
| 692 | |
| 693 var port = portInput.classList.contains('invalid') ? | |
| 694 portInput.lastValidValue : | |
| 695 portInput.value; | |
| 696 | |
| 697 var location = locationInput.classList.contains('invalid') ? | |
| 698 locationInput.lastValidValue : | |
| 699 locationInput.value; | |
| 700 | |
| 701 if (port && location) | |
| 702 config[port] = location; | |
| 703 } | |
| 704 sendCommand('set-port-forwarding-config', config); | |
| 705 } | |
| 706 | |
| 707 function updateDiscoverUsbDevicesEnabled(enabled) { | |
| 708 var checkbox = $('discover-usb-devices-enable'); | |
| 709 checkbox.checked = !!enabled; | 767 checkbox.checked = !!enabled; |
| 710 checkbox.disabled = false; | 768 checkbox.disabled = false; |
| 711 } | 769 } |
| 712 | 770 |
| 771 function updateDiscoverUsbDevicesEnabled(enabled) { |
| 772 updateCheckbox('discover-usb-devices-enable', enabled); |
| 773 } |
| 774 |
| 713 function updatePortForwardingEnabled(enabled) { | 775 function updatePortForwardingEnabled(enabled) { |
| 714 var checkbox = $('port-forwarding-enable'); | 776 updateCheckbox('port-forwarding-enable', enabled); |
| 715 checkbox.checked = !!enabled; | |
| 716 checkbox.disabled = false; | |
| 717 } | 777 } |
| 718 | 778 |
| 719 function updatePortForwardingConfig(config) { | 779 function updatePortForwardingConfig(config) { |
| 720 window.portForwardingConfig = config; | 780 window.portForwardingConfig = config; |
| 721 $('port-forwarding-config-open').disabled = !config; | 781 $('port-forwarding-config-open').disabled = !config; |
| 722 } | 782 } |
| 723 | 783 |
| 724 function createConfigLine(port, location) { | 784 function updateTCPDiscoveryEnabled(enabled) { |
| 725 var line = document.createElement('div'); | 785 updateCheckbox('discover-tcp-devices-enable', enabled); |
| 726 line.className = 'port-forwarding-pair'; | 786 } |
| 727 | 787 |
| 728 var portInput = createConfigField(port, 'port', 'Port', validatePort); | 788 function updateTCPDiscoveryConfig(config) { |
| 729 line.appendChild(portInput); | 789 window.targetDiscoveryConfig = config; |
| 790 $('tcp-discovery-config-open').disabled = !config; |
| 791 } |
| 730 | 792 |
| 731 var locationInput = createConfigField( | 793 function appendRow(list, lineFactory, key, value) { |
| 732 location, 'location', 'IP address and port', validateLocation); | 794 var line = lineFactory(key, value); |
| 733 line.appendChild(locationInput); | 795 line.lastElementChild.addEventListener('keydown', function(e) { |
| 734 locationInput.addEventListener('keydown', function(e) { | |
| 735 if (e.key == 'Tab' && | 796 if (e.key == 'Tab' && |
| 736 !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey && | 797 !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey && |
| 737 line.classList.contains('fresh') && | 798 line.classList.contains('fresh') && |
| 738 !line.classList.contains('empty')) { | 799 !line.classList.contains('empty')) { |
| 739 // Tabbing forward on the fresh line, try create a new empty one. | 800 // Tabbing forward on the fresh line, try create a new empty one. |
| 740 if (commitFreshLineIfValid(true)) | 801 if (commitFreshLineIfValid(true)) |
| 741 e.preventDefault(); | 802 e.preventDefault(); |
| 742 } | 803 } |
| 743 }); | 804 }); |
| 744 | 805 |
| 745 var lineDelete = document.createElement('div'); | 806 var lineDelete = document.createElement('div'); |
| 746 lineDelete.className = 'close-button'; | 807 lineDelete.className = 'close-button'; |
| 747 lineDelete.addEventListener('click', function() { | 808 lineDelete.addEventListener('click', function() { |
| 748 var newSelection = line.nextElementSibling; | 809 var newSelection = line.nextElementSibling || line.previousElementSibling; |
| 810 selectLine(newSelection, true); |
| 749 line.parentNode.removeChild(line); | 811 line.parentNode.removeChild(line); |
| 750 selectLine(newSelection); | 812 $('config-dialog').commit(false); |
| 751 commitPortForwardingConfig(false); | |
| 752 }); | 813 }); |
| 753 line.appendChild(lineDelete); | 814 line.appendChild(lineDelete); |
| 754 | 815 |
| 755 line.addEventListener('click', selectLine.bind(null, line)); | 816 line.addEventListener( |
| 756 line.addEventListener('focus', selectLine.bind(null, line)); | 817 'click', selectLine.bind(null, line, true)); |
| 757 | 818 line.addEventListener( |
| 819 'focus', selectLine.bind(null, line, true)); |
| 758 checkEmptyLine(line); | 820 checkEmptyLine(line); |
| 759 | 821 |
| 760 return line; | 822 if (!key && !value) |
| 823 line.classList.add('fresh'); |
| 824 |
| 825 return list.appendChild(line); |
| 761 } | 826 } |
| 762 | 827 |
| 763 function validatePort(input) { | 828 function validatePort(input) { |
| 764 var match = input.value.match(/^(\d+)$/); | 829 var match = input.value.match(/^(\d+)$/); |
| 765 if (!match) | 830 if (!match) |
| 766 return false; | 831 return false; |
| 767 var port = parseInt(match[1]); | 832 var port = parseInt(match[1]); |
| 768 if (port < 1024 || 65535 < port) | 833 if (port < 1024 || 65535 < port) |
| 769 return false; | 834 return false; |
| 770 | 835 |
| 771 var inputs = document.querySelectorAll('input.port:not(.invalid)'); | 836 var inputs = document.querySelectorAll('input.port:not(.invalid)'); |
| 772 for (var i = 0; i != inputs.length; ++i) { | 837 for (var i = 0; i != inputs.length; ++i) { |
| 773 if (inputs[i] == input) | 838 if (inputs[i] == input) |
| 774 break; | 839 break; |
| 775 if (parseInt(inputs[i].value) == port) | 840 if (parseInt(inputs[i].value) == port) |
| 776 return false; | 841 return false; |
| 777 } | 842 } |
| 778 return true; | 843 return true; |
| 779 } | 844 } |
| 780 | 845 |
| 781 function validateLocation(input) { | 846 function validateLocation(input) { |
| 782 var match = input.value.match(/^([a-zA-Z0-9\.\-_]+):(\d+)$/); | 847 var match = input.value.match(/^([a-zA-Z0-9\.\-_]+):(\d+)$/); |
| 783 if (!match) | 848 if (!match) |
| 784 return false; | 849 return false; |
| 785 var port = parseInt(match[2]); | 850 var port = parseInt(match[2]); |
| 786 return port <= 65535; | 851 return port <= 65535; |
| 787 } | 852 } |
| 788 | 853 |
| 789 function createEmptyConfigLine() { | |
| 790 var line = createConfigLine('', ''); | |
| 791 line.classList.add('fresh'); | |
| 792 return line; | |
| 793 } | |
| 794 | |
| 795 function createConfigField(value, className, hint, validate) { | 854 function createConfigField(value, className, hint, validate) { |
| 796 var input = document.createElement('input'); | 855 var input = document.createElement('input'); |
| 797 input.className = className; | 856 input.className = className; |
| 798 input.type = 'text'; | 857 input.type = 'text'; |
| 799 input.placeholder = hint; | 858 input.placeholder = hint; |
| 800 input.value = value; | 859 input.value = value || ''; |
| 801 input.lastValidValue = value; | 860 input.lastValidValue = value || ''; |
| 802 | 861 |
| 803 function checkInput() { | 862 function checkInput() { |
| 804 if (validate(input)) | 863 if (validate(input)) |
| 805 input.classList.remove('invalid'); | 864 input.classList.remove('invalid'); |
| 806 else | 865 else |
| 807 input.classList.add('invalid'); | 866 input.classList.add('invalid'); |
| 808 if (input.parentNode) | 867 if (input.parentNode) |
| 809 checkEmptyLine(input.parentNode); | 868 checkEmptyLine(input.parentNode); |
| 810 } | 869 } |
| 811 checkInput(); | 870 checkInput(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 829 for (var i = 0; i != inputs.length; i++) { | 888 for (var i = 0; i != inputs.length; i++) { |
| 830 if (inputs[i].value != '') | 889 if (inputs[i].value != '') |
| 831 empty = false; | 890 empty = false; |
| 832 } | 891 } |
| 833 if (empty) | 892 if (empty) |
| 834 line.classList.add('empty'); | 893 line.classList.add('empty'); |
| 835 else | 894 else |
| 836 line.classList.remove('empty'); | 895 line.classList.remove('empty'); |
| 837 } | 896 } |
| 838 | 897 |
| 839 function selectLine(line) { | 898 function selectLine(line, opt_focusInput) { |
| 840 if (line.classList.contains('selected')) | 899 if (line.classList.contains('selected')) |
| 841 return; | 900 return; |
| 842 unselectLine(); | 901 var selected = |
| 902 line.parentElement && line.parentElement.querySelector('.selected'); |
| 903 if (selected) |
| 904 selected.classList.remove('selected'); |
| 843 line.classList.add('selected'); | 905 line.classList.add('selected'); |
| 844 } | 906 if (opt_focusInput) { |
| 845 | 907 var el = line.querySelector('.preselected'); |
| 846 function unselectLine() { | 908 if (el) { |
| 847 var line = document.querySelector('.port-forwarding-pair.selected'); | 909 line.firstChild.select(); |
| 848 if (!line) | 910 line.firstChild.focus(); |
| 849 return; | 911 } |
| 850 line.classList.remove('selected'); | 912 } |
| 851 commitFreshLineIfValid(); | |
| 852 } | 913 } |
| 853 | 914 |
| 854 function commitFreshLineIfValid(opt_selectNew) { | 915 function commitFreshLineIfValid(opt_selectNew) { |
| 855 var line = document.querySelector('.port-forwarding-pair.fresh'); | 916 var line = $('config-dialog').querySelector('.config-list-row.fresh'); |
| 856 if (line.querySelector('.invalid')) | 917 if (line.querySelector('.invalid')) |
| 857 return false; | 918 return false; |
| 858 line.classList.remove('fresh'); | 919 line.classList.remove('fresh'); |
| 859 var freshLine = createEmptyConfigLine(); | 920 var freshLine = line.parentElement.createRow(); |
| 860 line.parentNode.appendChild(freshLine); | |
| 861 if (opt_selectNew) | 921 if (opt_selectNew) |
| 862 freshLine.querySelector('.port').focus(); | 922 freshLine.querySelector('.preselected').focus(); |
| 863 return true; | 923 return true; |
| 864 } | 924 } |
| 865 | 925 |
| 866 function populatePortStatus(devicesStatusMap) { | 926 function populatePortStatus(devicesStatusMap) { |
| 867 for (var deviceId in devicesStatusMap) { | 927 for (var deviceId in devicesStatusMap) { |
| 868 if (!devicesStatusMap.hasOwnProperty(deviceId)) | 928 if (!devicesStatusMap.hasOwnProperty(deviceId)) |
| 869 continue; | 929 continue; |
| 870 var deviceStatus = devicesStatusMap[deviceId]; | 930 var deviceStatus = devicesStatusMap[deviceId]; |
| 871 var deviceStatusMap = deviceStatus.ports; | 931 var deviceStatusMap = deviceStatus.ports; |
| 872 | 932 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 deviceSection.querySelectorAll('.browser'), clearBrowserPorts); | 990 deviceSection.querySelectorAll('.browser'), clearBrowserPorts); |
| 931 } | 991 } |
| 932 | 992 |
| 933 Array.prototype.forEach.call( | 993 Array.prototype.forEach.call( |
| 934 document.querySelectorAll('.device'), clearPorts); | 994 document.querySelectorAll('.device'), clearPorts); |
| 935 } | 995 } |
| 936 | 996 |
| 937 document.addEventListener('DOMContentLoaded', onload); | 997 document.addEventListener('DOMContentLoaded', onload); |
| 938 | 998 |
| 939 window.addEventListener('hashchange', onHashChange); | 999 window.addEventListener('hashchange', onHashChange); |
| OLD | NEW |