Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview Introduces users to ChromeVox. | 6 * @fileoverview Introduces users to ChromeVox. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('Tutorial'); | 9 goog.provide('Tutorial'); |
| 10 | 10 |
| 11 goog.require('Msgs'); | 11 goog.require('Msgs'); |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * @constructor | 14 * @constructor |
| 15 */ | 15 */ |
| 16 Tutorial = function() { | 16 Tutorial = function() { |
| 17 /** | 17 /** |
| 18 * The 0-based index of the current page of the tutorial. | 18 * The 0-based index of the current page of the tutorial. |
| 19 * @type {number} | 19 * @type {number} |
| 20 * @private | 20 * @private |
| 21 */ | 21 */ |
| 22 this.page_ = 0; | 22 this.page_; |
| 23 | |
| 24 this.page = sessionStorage['tutorial_page_pos'] !== undefined ? | |
| 25 sessionStorage['tutorial_page_pos'] : 0; | |
| 23 }; | 26 }; |
| 24 | 27 |
| 25 /** | 28 /** |
| 26 * Data for the ChromeVox tutorial consisting of a list of pages, | 29 * Data for the ChromeVox tutorial consisting of a list of pages, |
| 27 * each one of which contains a list of objects, where each object has | 30 * each one of which contains a list of objects, where each object has |
| 28 * a message ID for some text, and optional attributes indicating if it's | 31 * a message ID for some text, and optional attributes indicating if it's |
| 29 * a heading, link, text for only one platform, etc. | 32 * a heading, link, text for only one platform, etc. |
| 30 * | 33 * |
| 31 * @type Array<Object> | 34 * @type Array<Object> |
| 32 */ | 35 */ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 60 { msgid: 'tutorial_click_next' }, | 63 { msgid: 'tutorial_click_next' }, |
| 61 ], | 64 ], |
| 62 [ | 65 [ |
| 63 { msgid: 'tutorial_menus_heading', heading: true }, | 66 { msgid: 'tutorial_menus_heading', heading: true }, |
| 64 { msgid: 'tutorial_menus' }, | 67 { msgid: 'tutorial_menus' }, |
| 65 { msgid: 'tutorial_click_next' }, | 68 { msgid: 'tutorial_click_next' }, |
| 66 ], | 69 ], |
| 67 [ | 70 [ |
| 68 { msgid: 'tutorial_chrome_shortcuts_heading', heading: true }, | 71 { msgid: 'tutorial_chrome_shortcuts_heading', heading: true }, |
| 69 { msgid: 'tutorial_chrome_shortcuts' }, | 72 { msgid: 'tutorial_chrome_shortcuts' }, |
| 70 { msgid: 'tutorial_chromebook_ctrl_forward', chromebookOnly: true }, | 73 { msgid: 'tutorial_chromebook_ctrl_forward', chromebookOnly: true } |
| 71 { msgid: 'tutorial_chromeos_ctrl_f2', chromebookOnly: false }, | |
| 72 ], | 74 ], |
| 73 [ | 75 [ |
| 74 { msgid: 'tutorial_learn_more_heading', heading: true }, | 76 { msgid: 'tutorial_learn_more_heading', heading: true }, |
| 75 { msgid: 'tutorial_learn_more' }, | 77 { msgid: 'tutorial_learn_more' }, |
| 76 { msgid: 'next_command_reference', | 78 { msgid: 'next_command_reference', |
| 77 link: 'http://www.chromevox.com/next_keyboard_shortcuts.html' }, | 79 link: 'http://www.chromevox.com/next_keyboard_shortcuts.html' }, |
| 78 { msgid: 'chrome_keyboard_shortcuts', | 80 { msgid: 'chrome_keyboard_shortcuts', |
| 79 link: 'https://support.google.com/chromebook/answer/183101?hl=en' }, | 81 link: 'https://support.google.com/chromebook/answer/183101?hl=en' }, |
| 80 { msgid: 'touchscreen_accessibility', | 82 { msgid: 'touchscreen_accessibility', |
| 81 link: 'https://support.google.com/chromebook/answer/6103702?hl=en' }, | 83 link: 'https://support.google.com/chromebook/answer/6103702?hl=en' }, |
| 82 ], | 84 ], |
| 83 ]; | 85 ]; |
| 84 | 86 |
| 85 Tutorial.prototype = { | 87 Tutorial.prototype = { |
| 86 /** Open the first page in the tutorial. */ | 88 /** Open the last viewed page in the tutorial. */ |
| 87 firstPage: function() { | 89 lastViewedPage: function() { |
| 88 this.page_ = 0; | 90 this.page = sessionStorage['tutorial_page_pos'] !== undefined ? |
| 91 sessionStorage['tutorial_page_pos'] : 0; | |
| 89 this.showPage_(); | 92 this.showPage_(); |
| 90 }, | 93 }, |
| 91 | 94 |
| 92 /** Move to the next page in the tutorial. */ | 95 /** Move to the next page in the tutorial. */ |
| 93 nextPage: function() { | 96 nextPage: function() { |
| 94 if (this.page_ < Tutorial.PAGES.length - 1) { | 97 if (this.page < Tutorial.PAGES.length - 1) { |
| 95 this.page_++; | 98 this.page++; |
| 96 this.showPage_(); | 99 this.showPage_(); |
| 97 } | 100 } |
| 98 }, | 101 }, |
| 99 | 102 |
| 100 /** Move to the previous page in the tutorial. */ | 103 /** Move to the previous page in the tutorial. */ |
| 101 previousPage: function() { | 104 previousPage: function() { |
| 102 if (this.page_ > 0) { | 105 if (this.page > 0) { |
| 103 this.page_--; | 106 this.page--; |
| 104 this.showPage_(); | 107 this.showPage_(); |
| 105 } | 108 } |
| 106 }, | 109 }, |
| 107 | 110 |
| 108 /** | 111 /** |
| 109 * Recreate the tutorial DOM for page |this.page_|. | 112 * Recreate the tutorial DOM for page |this.page_|. |
| 110 * @private | 113 * @private |
| 111 */ | 114 */ |
| 112 showPage_: function() { | 115 showPage_: function() { |
| 113 var tutorialContainer = $('tutorial_main'); | 116 var tutorialContainer = $('tutorial_main'); |
| 114 tutorialContainer.innerHTML = ''; | 117 tutorialContainer.innerHTML = ''; |
| 115 | 118 |
| 116 var pageElements = Tutorial.PAGES[this.page_]; | 119 var pageElements = Tutorial.PAGES[this.page]; |
| 120 var focus; | |
| 117 for (var i = 0; i < pageElements.length; ++i) { | 121 for (var i = 0; i < pageElements.length; ++i) { |
| 118 var pageElement = pageElements[i]; | 122 var pageElement = pageElements[i]; |
| 119 var msgid = pageElement.msgid; | 123 var msgid = pageElement.msgid; |
| 120 var text = Msgs.getMsg(msgid); | 124 var text = Msgs.getMsg(msgid); |
| 121 var element; | 125 var element; |
| 122 if (pageElement.heading) { | 126 if (pageElement.heading) { |
| 123 element = document.createElement('h2'); | 127 element = document.createElement('h2'); |
| 128 element.setAttribute('tabindex', -1); | |
|
dmazzoni
2016/11/07 07:46:01
Let's add a css rule so this doesn't show a focus
David Tseng
2016/11/07 19:43:29
Done.
| |
| 129 focus = element; | |
| 124 } else if (pageElement.link) { | 130 } else if (pageElement.link) { |
| 125 element = document.createElement('a'); | 131 element = document.createElement('a'); |
| 126 element.href = pageElement.link; | 132 element.href = pageElement.link; |
| 127 element.target = '_blank'; | 133 element.target = '_blank'; |
| 128 } else { | 134 } else { |
| 129 element = document.createElement('p'); | 135 element = document.createElement('p'); |
| 130 } | 136 } |
| 131 element.innerText = text; | 137 element.innerText = text; |
| 132 tutorialContainer.appendChild(element); | 138 tutorialContainer.appendChild(element); |
| 133 } | 139 } |
| 140 if (focus) | |
| 141 focus.focus(); | |
| 142 | |
| 143 var disableNext = this.page == (Tutorial.PAGES.length - 1); | |
| 144 var disablePrevious = this.page == 0; | |
| 145 $('tutorial_next').setAttribute('aria-disabled', disableNext); | |
|
dmazzoni
2016/11/07 07:46:01
Do this with the regular disabled attribute rather
David Tseng
2016/11/07 19:43:29
I totally would, ecept for
crbug.com/662974
which
| |
| 146 $('tutorial_previous').setAttribute('aria-disabled', disablePrevious); | |
| 147 }, | |
| 148 | |
| 149 get page() { | |
| 150 return this.page_; | |
| 151 }, | |
| 152 | |
| 153 set page(val) { | |
| 154 this.page_ = val; | |
| 155 sessionStorage['tutorial_page_pos'] = this.page_; | |
| 134 } | 156 } |
| 135 }; | 157 }; |
| OLD | NEW |