| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 goog.provide('cvox.ChromeVoxHTMLDateWidget'); | 5 goog.provide('cvox.ChromeVoxHTMLDateWidget'); |
| 6 | 6 |
| 7 goog.require('Msgs'); | 7 goog.require('Msgs'); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * @fileoverview Gives the user spoken feedback as they interact with the date | 10 * @fileoverview Gives the user spoken feedback as they interact with the date |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Ensure we have a reasonable value to start with. | 86 // Ensure we have a reasonable value to start with. |
| 87 if (this.dateElem_.value.length == 0) { | 87 if (this.dateElem_.value.length == 0) { |
| 88 this.forceInitTime_(); | 88 this.forceInitTime_(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Move the cursor to the first position so that we are guaranteed to start | 91 // Move the cursor to the first position so that we are guaranteed to start |
| 92 // off at the hours position. | 92 // off at the hours position. |
| 93 for (var i = 0; i < this.maxPos_; i++) { | 93 for (var i = 0; i < this.maxPos_; i++) { |
| 94 var evt = document.createEvent('KeyboardEvent'); | 94 var evt = document.createEvent('KeyboardEvent'); |
| 95 evt.initKeyboardEvent( | 95 evt.initKeyboardEvent( |
| 96 'keydown', true, true, window, 'Left', 0, false, false, false, false); | 96 'keydown', true, true, window, 'Left', 0, false, false, false, false); |
| 97 this.dateElem_.dispatchEvent(evt); | 97 this.dateElem_.dispatchEvent(evt); |
| 98 evt = document.createEvent('KeyboardEvent'); | 98 evt = document.createEvent('KeyboardEvent'); |
| 99 evt.initKeyboardEvent( | 99 evt.initKeyboardEvent( |
| 100 'keyup', true, true, window, 'Left', 0, false, false, false, false); | 100 'keyup', true, true, window, 'Left', 0, false, false, false, false); |
| 101 this.dateElem_.dispatchEvent(evt); | 101 this.dateElem_.dispatchEvent(evt); |
| 102 } | 102 } |
| 103 | 103 |
| 104 this.dateElem_.addEventListener('keydown', this.keyListener_, false); | 104 this.dateElem_.addEventListener('keydown', this.keyListener_, false); |
| 105 this.dateElem_.addEventListener('keyup', this.keyListener_, false); | 105 this.dateElem_.addEventListener('keyup', this.keyListener_, false); |
| 106 this.dateElem_.addEventListener('blur', this.blurListener_, false); | 106 this.dateElem_.addEventListener('blur', this.blurListener_, false); |
| 107 this.update_(true); | 107 this.update_(true); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 /** | 110 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 * @private | 123 * @private |
| 124 */ | 124 */ |
| 125 cvox.ChromeVoxHTMLDateWidget.prototype.forceInitTime_ = function() { | 125 cvox.ChromeVoxHTMLDateWidget.prototype.forceInitTime_ = function() { |
| 126 var currentDate = new Date(); | 126 var currentDate = new Date(); |
| 127 var valueString = ''; | 127 var valueString = ''; |
| 128 var yearString = currentDate.getFullYear() + ''; | 128 var yearString = currentDate.getFullYear() + ''; |
| 129 // Date.getMonth starts at 0, but the value for the HTML5 date widget needs to | 129 // Date.getMonth starts at 0, but the value for the HTML5 date widget needs to |
| 130 // start at 1. | 130 // start at 1. |
| 131 var monthString = currentDate.getMonth() + 1 + ''; | 131 var monthString = currentDate.getMonth() + 1 + ''; |
| 132 if (monthString.length < 2) { | 132 if (monthString.length < 2) { |
| 133 monthString = '0' + monthString; // Month format is MM. | 133 monthString = '0' + monthString; // Month format is MM. |
| 134 } | 134 } |
| 135 var dayString = currentDate.getDate() + ''; | 135 var dayString = currentDate.getDate() + ''; |
| 136 | 136 |
| 137 switch (this.dateElem_.type) { | 137 switch (this.dateElem_.type) { |
| 138 case 'month': | 138 case 'month': |
| 139 valueString = yearString + '-' + monthString; | 139 valueString = yearString + '-' + monthString; |
| 140 break; | 140 break; |
| 141 case 'week': | 141 case 'week': |
| 142 // Based on info from: http://www.merlyn.demon.co.uk/weekcalc.htm#WNR | 142 // Based on info from: http://www.merlyn.demon.co.uk/weekcalc.htm#WNR |
| 143 currentDate.setHours(0, 0, 0); | 143 currentDate.setHours(0, 0, 0); |
| 144 // Set to nearest Thursday: current date + 4 - current day number | 144 // Set to nearest Thursday: current date + 4 - current day number |
| 145 // Make Sunday's day number 7 | 145 // Make Sunday's day number 7 |
| 146 currentDate.setDate( | 146 currentDate.setDate( |
| 147 currentDate.getDate() + 4 - (currentDate.getDay() || 7)); | 147 currentDate.getDate() + 4 - (currentDate.getDay() || 7)); |
| 148 // Get first day of year | 148 // Get first day of year |
| 149 var yearStart = new Date(currentDate.getFullYear(), 0, 1); | 149 var yearStart = new Date(currentDate.getFullYear(), 0, 1); |
| 150 // Calculate full weeks to nearest Thursday | 150 // Calculate full weeks to nearest Thursday |
| 151 var weekString = | 151 var weekString = |
| 152 Math.ceil((((currentDate - yearStart) / 86400000) + 1) / 7) + ''; | 152 Math.ceil((((currentDate - yearStart) / 86400000) + 1) / 7) + ''; |
| 153 if (weekString.length < 2) { | 153 if (weekString.length < 2) { |
| 154 weekString = '0' + weekString; // Week format is WXX. | 154 weekString = '0' + weekString; // Week format is WXX. |
| 155 } | 155 } |
| 156 weekString = 'W' + weekString; | 156 weekString = 'W' + weekString; |
| 157 valueString = yearString + '-' + weekString; | 157 valueString = yearString + '-' + weekString; |
| 158 break; | 158 break; |
| 159 default: | 159 default: |
| 160 valueString = yearString + '-' + monthString + '-' + dayString; | 160 valueString = yearString + '-' + monthString + '-' + dayString; |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 this.dateElem_.setAttribute('value', valueString); | 163 this.dateElem_.setAttribute('value', valueString); |
| 164 }; | 164 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 month = parseInt(splitDate[1], 10); | 224 month = parseInt(splitDate[1], 10); |
| 225 } | 225 } |
| 226 | 226 |
| 227 var changeMessage = ''; | 227 var changeMessage = ''; |
| 228 | 228 |
| 229 if (shouldSpeakLabel) { | 229 if (shouldSpeakLabel) { |
| 230 changeMessage = cvox.DomUtil.getName(this.dateElem_, true, true) + '\n'; | 230 changeMessage = cvox.DomUtil.getName(this.dateElem_, true, true) + '\n'; |
| 231 } | 231 } |
| 232 | 232 |
| 233 if (week != this.pWeek_) { | 233 if (week != this.pWeek_) { |
| 234 changeMessage = changeMessage + | 234 changeMessage = |
| 235 Msgs.getMsg('datewidget_week') + week + '\n'; | 235 changeMessage + Msgs.getMsg('datewidget_week') + week + '\n'; |
| 236 this.pWeek_ = week; | 236 this.pWeek_ = week; |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (month != this.pMonth_) { | 239 if (month != this.pMonth_) { |
| 240 var monthName = ''; | 240 var monthName = ''; |
| 241 switch (month) { | 241 switch (month) { |
| 242 case 1: | 242 case 1: |
| 243 monthName = Msgs.getMsg('datewidget_january'); | 243 monthName = Msgs.getMsg('datewidget_january'); |
| 244 break; | 244 break; |
| 245 case 2: | 245 case 2: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) { | 313 if (((evt.keyCode == 9) && evt.shiftKey) || (evt.keyCode == 37)) { |
| 314 this.pos_--; | 314 this.pos_--; |
| 315 this.handlePosChange_(); | 315 this.handlePosChange_(); |
| 316 shouldSpeakLabel = true; | 316 shouldSpeakLabel = true; |
| 317 } | 317 } |
| 318 // For all other cases, fall through and let update_ decide if there are any | 318 // For all other cases, fall through and let update_ decide if there are any |
| 319 // changes that need to be spoken. | 319 // changes that need to be spoken. |
| 320 } | 320 } |
| 321 this.update_(shouldSpeakLabel); | 321 this.update_(shouldSpeakLabel); |
| 322 }; | 322 }; |
| OLD | NEW |