Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A lookup helper function to find the first node that has an id (starting | 9 * A lookup helper function to find the first node that has an id (starting |
| 10 * at |node| and going up the parent chain). | 10 * at |node| and going up the parent chain). |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 /** @inheritDoc */ | 33 /** @inheritDoc */ |
| 34 decorate: function() { | 34 decorate: function() { |
| 35 this.initControlsAndHandlers_(); | 35 this.initControlsAndHandlers_(); |
| 36 | 36 |
| 37 var showingDetails = []; | 37 var showingDetails = []; |
| 38 var showingWarning = []; | 38 var showingWarning = []; |
| 39 this.deleteExistingExtensionNodes_(showingDetails, showingWarning); | 39 this.deleteExistingExtensionNodes_(showingDetails, showingWarning); |
| 40 | 40 |
| 41 this.showExtensionNodes_(showingDetails, showingWarning); | 41 this.showExtensionNodes_(showingDetails, showingWarning); |
| 42 | |
| 43 // Support full keyboard accessibility without making things ugly | |
| 44 // for users who click, by hiding some focus outlines when the user | |
| 45 // clicks anywhere, but showing them when the user presses any key. | |
| 46 document.body.classList.add('hide-some-focus-outlines'); | |
| 47 document.addEventListener('click', function(e) { | |
| 48 document.body.classList.add('hide-some-focus-outlines'); | |
| 49 return true; | |
| 50 }, true); | |
| 51 document.addEventListener('keydown', function(e) { | |
| 52 document.body.classList.remove('hide-some-focus-outlines'); | |
| 53 return true; | |
| 54 }, true); | |
|
Finnur
2011/10/21 09:35:46
I think decorate is called more than once, so why
dmazzoni
2011/10/21 16:29:38
Done.
| |
| 42 }, | 55 }, |
| 43 | 56 |
| 44 /** | 57 /** |
| 45 * Initializes the controls (toggle section and button) and installs | 58 * Initializes the controls (toggle section and button) and installs |
| 46 * handlers. | 59 * handlers. |
| 47 * @private | 60 * @private |
| 48 */ | 61 */ |
| 49 initControlsAndHandlers_: function() { | 62 initControlsAndHandlers_: function() { |
| 50 // Make sure developer mode section is set correctly as per saved setting. | 63 // Make sure developer mode section is set correctly as per saved setting. |
| 51 var toggleButton = $('toggle-dev-on'); | 64 var toggleButton = $('toggle-dev-on'); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 wrapper.appendChild(vboxOuter); | 164 wrapper.appendChild(vboxOuter); |
| 152 | 165 |
| 153 var hbox = this.ownerDocument.createElement('div'); | 166 var hbox = this.ownerDocument.createElement('div'); |
| 154 hbox.classList.add('hbox'); | 167 hbox.classList.add('hbox'); |
| 155 vboxOuter.appendChild(hbox); | 168 vboxOuter.appendChild(hbox); |
| 156 | 169 |
| 157 // Add a container div for the zippy, so we can extend the hit area. | 170 // Add a container div for the zippy, so we can extend the hit area. |
| 158 var container = this.ownerDocument.createElement('div'); | 171 var container = this.ownerDocument.createElement('div'); |
| 159 // Clicking anywhere on the div expands/collapses the details. | 172 // Clicking anywhere on the div expands/collapses the details. |
| 160 container.classList.add('extension-zippy-container'); | 173 container.classList.add('extension-zippy-container'); |
| 174 container.href = '#'; | |
|
Finnur
2011/10/21 09:35:46
container is a div...
dmazzoni
2011/10/21 16:29:38
Oops! As you can see, I initially experimented wit
| |
| 175 container.title = expanded ? | |
| 176 localStrings.getString('extensionSettingsHideDetails') : | |
| 177 localStrings.getString('extensionSettingsShowDetails'); | |
| 178 container.tabIndex = 0; | |
| 179 container.setAttribute('role', 'button'); | |
| 180 container.setAttribute('aria-controls', extension.id + '_details'); | |
|
Finnur
2011/10/21 09:35:46
aria-controls? what's that?
dmazzoni
2011/10/21 16:29:38
http://www.w3.org/TR/wai-aria/states_and_propertie
| |
| 181 container.setAttribute('aria-expanded', expanded); | |
| 161 container.addEventListener('click', this.handleZippyClick_.bind(this)); | 182 container.addEventListener('click', this.handleZippyClick_.bind(this)); |
| 183 container.addEventListener('keydown', | |
| 184 this.handleZippyKeyDown_.bind(this)); | |
| 162 hbox.appendChild(container); | 185 hbox.appendChild(container); |
| 163 | 186 |
| 164 // On the far left we have the zippy icon. | 187 // On the far left we have the zippy icon. |
| 165 var div = this.ownerDocument.createElement('div'); | 188 var div = this.ownerDocument.createElement('div'); |
| 166 div.id = id + '_zippy'; | 189 div.id = id + '_zippy'; |
| 167 div.classList.add('extension-zippy-default'); | 190 div.classList.add('extension-zippy-default'); |
| 168 div.classList.add(expanded ? 'extension-zippy-expanded' : | 191 div.classList.add(expanded ? 'extension-zippy-expanded' : |
| 169 'extension-zippy-collapsed'); | 192 'extension-zippy-collapsed'); |
| 170 container.appendChild(div); | 193 container.appendChild(div); |
| 171 | 194 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 */ | 568 */ |
| 546 getExtensionWithId_: function(id) { | 569 getExtensionWithId_: function(id) { |
| 547 for (var i = 0; i < this.data_.extensions.length; ++i) { | 570 for (var i = 0; i < this.data_.extensions.length; ++i) { |
| 548 if (this.data_.extensions[i].id == id) | 571 if (this.data_.extensions[i].id == id) |
| 549 return this.data_.extensions[i]; | 572 return this.data_.extensions[i]; |
| 550 } | 573 } |
| 551 return null; | 574 return null; |
| 552 }, | 575 }, |
| 553 | 576 |
| 554 /** | 577 /** |
| 578 * Handles a key down on the zippy icon. | |
| 579 * @param {Event} e Key event. | |
| 580 * @private | |
| 581 */ | |
| 582 handleZippyKeyDown_: function(e) { | |
| 583 if (e.keyCode == 13 || e.keyCode == 32) // Enter or Space | |
|
Finnur
2011/10/21 09:35:46
nit: End all comments with punctuation marks (peri
dmazzoni
2011/10/21 16:29:38
Done.
| |
| 584 this.handleZippyClick_(e); | |
| 585 }, | |
| 586 | |
| 587 /** | |
| 555 * Handles the mouseclick on the zippy icon (that expands and collapses the | 588 * Handles the mouseclick on the zippy icon (that expands and collapses the |
| 556 * details section). | 589 * details section). |
| 557 * @param {Event} e Change event. | 590 * @param {Event} e Mouse event. |
| 558 * @private | 591 * @private |
| 559 */ | 592 */ |
| 560 handleZippyClick_: function(e) { | 593 handleZippyClick_: function(e) { |
| 561 var node = findIdNode(e.target.parentNode); | 594 var node = findIdNode(e.target.parentNode); |
| 562 var iter = this.firstChild; | 595 var iter = this.firstChild; |
| 563 while (iter) { | 596 while (iter) { |
| 564 var zippy = $(iter.id + '_zippy'); | 597 var zippy = $(iter.id + '_zippy'); |
| 565 var details = $(iter.id + '_details'); | 598 var details = $(iter.id + '_details'); |
| 599 var container = zippy.parentElement; | |
| 566 if (iter.id == node.id) { | 600 if (iter.id == node.id) { |
| 567 // Toggle visibility. | 601 // Toggle visibility. |
| 568 if (iter.classList.contains('extension-list-item-expanded')) { | 602 if (iter.classList.contains('extension-list-item-expanded')) { |
| 569 // Hide yo kids! Hide yo wife! | 603 // Hide yo kids! Hide yo wife! |
| 570 zippy.classList.remove('extension-zippy-expanded'); | 604 zippy.classList.remove('extension-zippy-expanded'); |
| 571 zippy.classList.add('extension-zippy-collapsed'); | 605 zippy.classList.add('extension-zippy-collapsed'); |
| 572 details.classList.remove('extension-details-visible'); | 606 details.classList.remove('extension-details-visible'); |
| 573 details.classList.add('extension-details-hidden'); | 607 details.classList.add('extension-details-hidden'); |
| 574 iter.classList.remove('extension-list-item-expanded'); | 608 iter.classList.remove('extension-list-item-expanded'); |
| 575 iter.classList.add('extension-list-item-collaped'); | 609 iter.classList.add('extension-list-item-collaped'); |
| 610 container.setAttribute('aria-expanded', 'false'); | |
| 611 container.title = | |
| 612 localStrings.getString('extensionSettingsShowDetails'); | |
| 613 var detailsControls = details.querySelectorAll('a, input'); | |
| 614 for (var i = 0; i < detailsControls.length; i++) | |
| 615 detailsControls[i].tabIndex = -1; | |
| 576 | 616 |
| 577 // Hide yo incognito warning. | 617 // Hide yo incognito warning. |
| 578 var butterBar = | 618 var butterBar = |
| 579 this.querySelector('#' + iter.id + '_incognitoWarning'); | 619 this.querySelector('#' + iter.id + '_incognitoWarning'); |
| 580 if (!(butterBar === null)) | 620 if (!(butterBar === null)) |
| 581 butterBar.hidden = true; | 621 butterBar.hidden = true; |
| 582 } else { | 622 } else { |
| 583 // Show the contents. | 623 // Show the contents. |
| 584 zippy.classList.remove('extension-zippy-collapsed'); | 624 zippy.classList.remove('extension-zippy-collapsed'); |
| 585 zippy.classList.add('extension-zippy-expanded'); | 625 zippy.classList.add('extension-zippy-expanded'); |
| 586 details.classList.remove('extension-details-hidden'); | 626 details.classList.remove('extension-details-hidden'); |
| 587 details.classList.add('extension-details-visible'); | 627 details.classList.add('extension-details-visible'); |
| 588 iter.classList.remove('extension-list-item-collaped'); | 628 iter.classList.remove('extension-list-item-collaped'); |
| 589 iter.classList.add('extension-list-item-expanded'); | 629 iter.classList.add('extension-list-item-expanded'); |
| 630 container.setAttribute('aria-expanded', 'true'); | |
| 631 container.title = | |
| 632 localStrings.getString('extensionSettingsHideDetails'); | |
| 633 var detailsControls = details.querySelectorAll('a, input'); | |
| 634 for (var i = 0; i < detailsControls.length; i++) | |
| 635 detailsControls[i].tabIndex = 0; | |
| 590 } | 636 } |
| 591 } | 637 } |
| 592 iter = iter.nextSibling; | 638 iter = iter.nextSibling; |
| 593 } | 639 } |
| 594 }, | 640 }, |
| 595 | 641 |
| 596 /** | 642 /** |
| 597 * Handles the mouse-up and keyboard-up events. This is used to limit the | 643 * Handles the mouse-up and keyboard-up events. This is used to limit the |
| 598 * number of items to show in the list, when the user is searching for items | 644 * number of items to show in the list, when the user is searching for items |
| 599 * with the search box. Otherwise, if one match is found, the whole list of | 645 * with the search box. Otherwise, if one match is found, the whole list of |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 ]); | 772 ]); |
| 727 } | 773 } |
| 728 } | 774 } |
| 729 }, | 775 }, |
| 730 }; | 776 }; |
| 731 | 777 |
| 732 return { | 778 return { |
| 733 ExtensionsList: ExtensionsList | 779 ExtensionsList: ExtensionsList |
| 734 }; | 780 }; |
| 735 }); | 781 }); |
| OLD | NEW |