Update Deprecated code in October into (event.key) (#4489)

Update Deprecated code in October into (event.key)
This commit is contained in:
Samuel Georges 2019-09-11 21:35:18 +10:00 committed by GitHub
parent 72123943de
commit 3291e07191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 83 additions and 89 deletions

View File

@ -172,7 +172,7 @@
}
Flyout.prototype.onDocumentKeydown = function(ev) {
if (ev.which == 27) {
if (ev.key === 'Escape') {
this.hide();
}
}

View File

@ -85,28 +85,24 @@
}
function _handleUiBlocksKeydown(ev) {
if (ev.which == 40 || ev.which == 38 || ev.which == 8 || ev.which == 46) {
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp' || ev.key === 'Backspace' || ev.key === 'Delete') {
var $block = $(editor.selection.element())
if ($block.is('br')) {
$block = $block.parent()
}
if (!!$block.length) {
switch (ev.which) {
case 38:
// Up arrow
switch (ev.key) {
case 'ArrowUp':
_handleUiBlockCaretIn($block.prev())
break
case 40:
// Down arrow
case 'ArrowDown':
_handleUiBlockCaretIn($block.next())
break
case 46:
// Delete key
case 'Delete':
_handleUiBlockCaretClearEmpty($block.next(), $block)
break
case 8:
// Backspace key
case 'Backspace':
_handleUiBlockCaretClearEmpty($block.prev(), $block)
break
}
@ -133,27 +129,23 @@
}
function _uiBlockKeyDown(ev, block) {
if (ev.which == 40 || ev.which == 38 || ev.which == 13 || ev.which == 8 || ev.which == 46) {
switch (ev.which) {
case 40:
// Down arrow
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp' || ev.key === 'Enter' || ev.key === 'Backspace' || ev.key === 'Delete') {
switch (ev.key) {
case 'ArrowDown':
_focusUiBlockOrText($(block).next(), true)
break
case 38:
// Up arrow
case 'ArrowUp':
_focusUiBlockOrText($(block).prev(), false)
break
case 13:
// Enter key
case 'Enter':
var $paragraph = $('<p><br/></p>')
$paragraph.insertAfter(block)
editor.selection.setAfter(block)
editor.selection.restore()
editor.undo.saveStep()
break
case 8:
case 46:
// Delete / Backspace key
case 'Backspace':
case 'Delete':
var $nextFocus = $(block).next(),
gotoStart = true

View File

@ -454,13 +454,13 @@ MediaManager.prototype.onSortingChanged=function(ev){var $target=$(ev.target),da
if($target.data('sort')=='by'){data.sortBy=$target.val();}else if($target.data('sort')=='direction'){data.sortDirection=$target.val()}
this.execNavigationRequest('onSetSorting',data)}
MediaManager.prototype.onKeyDown=function(ev){var eventHandled=false
switch(ev.which){case 13:var items=this.getSelectedItems(true,true)
switch(ev.key){case 'Enter':var items=this.getSelectedItems(true,true)
if(items.length>0)
this.navigateToItem($(items[0]))
eventHandled=true
break;case 39:case 40:this.selectRelative(true,ev.shiftKey)
break;case 'ArrowRight':case 'ArrowDown':this.selectRelative(true,ev.shiftKey)
eventHandled=true
break;case 37:case 38:this.selectRelative(false,ev.shiftKey)
break;case 'ArrowLeft':case 'ArrowUp':this.selectRelative(false,ev.shiftKey)
eventHandled=true
break;}
if(eventHandled){ev.preventDefault()

View File

@ -1025,6 +1025,7 @@
var item = items[i],
path = item.getAttribute('data-path')
if (item.getAttribute('data-item-type') == 'folder')
data.folders.push(path)
else
@ -1250,21 +1251,22 @@
MediaManager.prototype.onKeyDown = function(ev) {
var eventHandled = false
switch (ev.which) {
case 13:
switch (ev.key) {
case 'Enter':
var items = this.getSelectedItems(true, true)
if (items.length > 0)
this.navigateToItem($(items[0]))
eventHandled = true
break;
case 39:
case 40:
case 'ArrowRight':
case 'ArrowDown':
this.selectRelative(true, ev.shiftKey)
eventHandled = true
break;
case 37:
case 38:
case 'ArrowLeft':
case 'ArrowUp':
this.selectRelative(false, ev.shiftKey)
eventHandled = true
break;

View File

@ -269,11 +269,11 @@ var target=this.getEventTarget(ev,'TD')
if(!target){this.unfocusTable();return;}
if(target.tagName!='TD'){this.unfocusTable();return;}
this.focusCell(target,true)}
Table.prototype.onKeydown=function(ev){if(ev.keyCode==65&&ev.altKey&&this.options.adding){if(!ev.shiftKey){this.addRecord('below')}
Table.prototype.onKeydown=function(ev){if((ev.key==='a'||ev.key==='A')&&ev.altKey&&this.options.adding){if(!ev.shiftKey){this.addRecord('below')}
else{this.addRecord('above')}
this.stopEvent(ev)
return}
if(ev.keyCode==68&&ev.altKey&&this.options.deleting){this.deleteRecord()
if((ev.key==='d'||ev.key==='D')&&ev.altKey&&this.options.deleting){this.deleteRecord()
this.stopEvent(ev)
return}
for(var i=0,len=this.options.columns.length;i<len;i++){var column=this.options.columns[i].key
@ -527,15 +527,15 @@ if(focusRow)
this.focusCell(focusRow,cellIndex)
else
this.focusCell('top',cellIndex)}}
Navigation.prototype.onKeydown=function(ev){if(ev.keyCode==40)
Navigation.prototype.onKeydown=function(ev){if(ev.key==='ArrowDown')
return this.navigateDown(ev)
else if(ev.keyCode==38)
else if(ev.key==='ArrowUp')
return this.navigateUp(ev)
else if(ev.keyCode==37)
else if(ev.key==='ArrowLeft')
return this.navigateLeft(ev)
if(ev.keyCode==39)
if(ev.key==='ArrowRight')
return this.navigateRight(ev)
if(ev.keyCode==9)
if(ev.key==='Tab')
return this.navigateNext(ev)}
Navigation.prototype.onClick=function(ev){var target=this.tableObj.getEventTarget(ev,'A')
if(!target||!$(target).hasClass('pagination-link'))
@ -570,7 +570,7 @@ Search.prototype.searchEnabled=function(){return this.tableObj.options.searching
Search.prototype.performSearch=function(query,onSuccess){var isDirty=this.activeQuery!=query
this.activeQuery=query
if(isDirty){this.tableObj.updateDataTable(onSuccess)}}
Search.prototype.onKeydown=function(ev){if(ev.keyCode==9){this.onClick(ev)
Search.prototype.onKeydown=function(ev){if(ev.key==='Tab'){this.onClick(ev)
return}
if(!this.isActive){return}
var self=this
@ -765,7 +765,7 @@ checkbox.setAttribute('tabindex','0')
if(value&&value!=0&&value!="false"){checkbox.setAttribute('class','checked')}
cellContentContainer.appendChild(checkbox)}
CheckboxProcessor.prototype.onFocus=function(cellElement,isClick){cellElement.querySelector('div[data-checkbox-element]').focus()}
CheckboxProcessor.prototype.onKeyDown=function(ev){if(ev.keyCode==32)
CheckboxProcessor.prototype.onKeyDown=function(ev){if(ev.key==='(Space character)'||ev.key==='Spacebar'||ev.key===' ')
this.onClick(ev)}
CheckboxProcessor.prototype.onClick=function(ev){var target=this.tableObj.getEventTarget(ev,'DIV')
if(target.getAttribute('data-checkbox-element')){var container=this.getCheckboxContainerNode(target)
@ -887,20 +887,20 @@ if(target.tagName=='LI'){target.focus();this.updateCellFromFocusedItem()
this.hideDropdown()}}
DropdownProcessor.prototype.onItemKeyDown=function(ev){if(!this.itemListElement)
return
if(ev.keyCode==40||ev.keyCode==38)
if(ev.key==='ArrowDown'||ev.key==='ArrowUp')
{var focused=this.findFocusedItem(),newFocusedItem=focused.nextElementSibling
if(ev.keyCode==38)
if(ev.key==='ArrowUp')
newFocusedItem=focused.previousElementSibling
if(newFocusedItem){newFocusedItem.focus()}
return}
if(ev.keyCode==13||ev.keyCode==32){this.updateCellFromFocusedItem()
if(ev.key==='Enter'||ev.key==='(Space character)'||ev.key==='Spacebar'||ev.key===' '){this.updateCellFromFocusedItem()
this.hideDropdown()
return}
if(ev.keyCode==9){this.updateCellFromFocusedItem()
if(ev.key==='Tab'){this.updateCellFromFocusedItem()
this.tableObj.navigation.navigateNext(ev)
this.tableObj.stopEvent(ev)
return}
if(ev.keyCode==27){this.hideDropdown()
if(ev.key==='Escape'){this.hideDropdown()
return}
this.searchByTextInput(ev,true);}
DropdownProcessor.prototype.onItemMouseMove=function(ev){if(!this.itemListElement)
@ -909,9 +909,9 @@ var target=this.tableObj.getEventTarget(ev)
if(target.tagName=='LI'){target.focus();}}
DropdownProcessor.prototype.onKeyDown=function(ev){if(!this.itemListElement)
return
if(ev.keyCode==32&&!this.searching){this.showDropdown()}else if(ev.keyCode==40||ev.keyCode==38){var selected=this.findSelectedItem(),newSelectedItem;if(!selected){if(ev.keyCode==38){return false}
if((ev.key==='(Space character)'||ev.key==='Spacebar'||ev.key===' ')&&!this.searching){this.showDropdown()}else if(ev.key==='ArrowDown'||ev.key==='ArrowUp'){var selected=this.findSelectedItem(),newSelectedItem;if(!selected){if(ev.key=='ArrowUp'){return false}
newSelectedItem=this.itemListElement.querySelector('ul li:first-child')}else{newSelectedItem=selected.nextElementSibling
if(ev.keyCode==38)
if(ev.key==='ArrowUp')
newSelectedItem=selected.previousElementSibling}
if(newSelectedItem){this.setSelectedItem(newSelectedItem);}
return false}else{this.searchByTextInput(ev);}}

View File

@ -386,17 +386,17 @@
// The navigation object uses the table's keydown handler
// and doesn't register own handler.
if (ev.keyCode == 40)
if (ev.key === 'ArrowDown')
return this.navigateDown(ev)
else if (ev.keyCode == 38)
else if (ev.key === 'ArrowUp')
return this.navigateUp(ev)
else if (ev.keyCode == 37)
else if (ev.key === 'ArrowLeft')
return this.navigateLeft(ev)
if (ev.keyCode == 39)
if (ev.key === 'ArrowRight')
return this.navigateRight(ev)
if (ev.keyCode == 9)
if (ev.key === 'Tab')
return this.navigateNext(ev)
}

View File

@ -91,7 +91,7 @@
// and doesn't register own handler.
// Tab pressed
if (ev.keyCode == 9) {
if (ev.key === 'Tab') {
this.onClick(ev)
return
}

View File

@ -756,7 +756,7 @@
}
Table.prototype.onKeydown = function(ev) {
if (ev.keyCode == 65 && ev.altKey && this.options.adding) {
if ((ev.key === 'a' || ev.key === 'A') && ev.altKey && this.options.adding) {
if (!ev.shiftKey) {
// alt+a - add record below
this.addRecord('below')
@ -770,7 +770,7 @@
return
}
if (ev.keyCode == 68 && ev.altKey && this.options.deleting) {
if ((ev.key === 'd' || ev.key === 'D') && ev.altKey && this.options.deleting) {
// alt+d - delete record
this.deleteRecord()

View File

@ -68,7 +68,7 @@
* for all processors.
*/
CheckboxProcessor.prototype.onKeyDown = function(ev) {
if (ev.keyCode == 32)
if (ev.key === '(Space character)' || ev.key === 'Spacebar' || ev.key === ' ')
this.onClick(ev)
}

View File

@ -318,13 +318,13 @@
if (!this.itemListElement)
return
if (ev.keyCode == 40 || ev.keyCode == 38)
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp')
{
// Up or down keys - find previous/next list item and select it
var focused = this.findFocusedItem(),
newFocusedItem = focused.nextElementSibling
if (ev.keyCode == 38)
if (ev.key === 'ArrowUp')
newFocusedItem = focused.previousElementSibling
if (newFocusedItem) {
@ -334,14 +334,14 @@
return
}
if (ev.keyCode == 13 || ev.keyCode == 32) {
if (ev.key === 'Enter' || ev.key === '(Space character)' || ev.key === 'Spacebar' || ev.key === ' ') {
// Return or space keys - update the selected value and hide the editor
this.updateCellFromFocusedItem()
this.hideDropdown()
return
}
if (ev.keyCode == 9) {
if (ev.key === 'Tab') {
// Tab - update the selected value and pass control to the table navigation
this.updateCellFromFocusedItem()
this.tableObj.navigation.navigateNext(ev)
@ -349,7 +349,7 @@
return
}
if (ev.keyCode == 27) {
if (ev.key === 'Escape') {
// Esc - hide the drop-down
this.hideDropdown()
return
@ -380,14 +380,14 @@
if (!this.itemListElement)
return
if (ev.keyCode == 32 && !this.searching) { // Spacebar
if ((ev.key === '(Space character)' || ev.key === 'Spacebar' || ev.key === ' ') && !this.searching) { // Spacebar
this.showDropdown()
} else if (ev.keyCode == 40 || ev.keyCode == 38) { // Up and down arrow keys
} else if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') { // Up and down arrow keys
var selected = this.findSelectedItem(),
newSelectedItem;
if (!selected) {
if (ev.keyCode == 38) {
if (ev.key === 'ArrowUp') {
// Only show an initial item when the down array key is pressed
return false
}
@ -395,7 +395,7 @@
} else {
newSelectedItem = selected.nextElementSibling
if (ev.keyCode == 38)
if (ev.key === 'ArrowUp')
newSelectedItem = selected.previousElementSibling
}

View File

@ -117,7 +117,7 @@ $(document).on('click','a[data-request], button[data-request], input[type=button
$(this).request()
if($(this).is('[type=submit]'))
return false})
$(document).on('keydown','input[type=text][data-request], input[type=submit][data-request], input[type=password][data-request]',function documentOnKeydown(e){if(e.keyCode==13){if(this.dataTrackInputTimer!==undefined)
$(document).on('keydown','input[type=text][data-request], input[type=submit][data-request], input[type=password][data-request]',function documentOnKeydown(e){if(e.key==='Enter'){if(this.dataTrackInputTimer!==undefined)
window.clearTimeout(this.dataTrackInputTimer)
$(this).request()
return false}})

View File

@ -117,7 +117,7 @@ $(document).on('click','a[data-request], button[data-request], input[type=button
$(this).request()
if($(this).is('[type=submit]'))
return false})
$(document).on('keydown','input[type=text][data-request], input[type=submit][data-request], input[type=password][data-request]',function documentOnKeydown(e){if(e.keyCode==13){if(this.dataTrackInputTimer!==undefined)
$(document).on('keydown','input[type=text][data-request], input[type=submit][data-request], input[type=password][data-request]',function documentOnKeydown(e){if(e.key==='Enter'){if(this.dataTrackInputTimer!==undefined)
window.clearTimeout(this.dataTrackInputTimer)
$(this).request()
return false}})

View File

@ -479,7 +479,7 @@ if (window.jQuery.request !== undefined) {
})
$(document).on('keydown', 'input[type=text][data-request], input[type=submit][data-request], input[type=password][data-request]', function documentOnKeydown(e) {
if (e.keyCode == 13) {
if (e.key === 'Enter') {
if (this.dataTrackInputTimer !== undefined)
window.clearTimeout(this.dataTrackInputTimer)

View File

@ -233,19 +233,19 @@
move: function (e) {
if (!this.shown) return
switch(e.keyCode) {
case 9: // tab
case 13: // enter
case 27: // escape
switch(e.key) {
case 'Tab':
case 'Enter':
case 'Escape':
e.preventDefault()
break
case 38: // up arrow
case 'ArrowUp':
e.preventDefault()
this.prev()
break
case 40: // down arrow
case 'ArrowDown':
e.preventDefault()
this.next()
break
@ -255,7 +255,7 @@
},
keydown: function (e) {
this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27])
this.suppressKeyPressRepeat = ~$.inArray(e.key, ['ArrowDown','ArrowUp','Tab','Enter','Escape'])
this.move(e)
},

View File

@ -6,12 +6,12 @@
(function($) {
$(document).on('keydown', 'div.custom-checkbox', function(e) {
if (e.keyCode == 32)
if (e.key === '(Space character)' || e.key === 'Spacebar' || e.key === ' ')
e.preventDefault()
})
$(document).on('input', 'div.custom-checkbox', function(e) {
if (e.keyCode == 32) {
if (e.key === '(Space character)' || e.key === 'Spacebar' || e.key === ' ')
var $cb = $('input', this)
if ($cb.data('oc-space-timestamp') == e.timeStamp)

View File

@ -149,11 +149,11 @@
for (var i = 0, len = this.keyConditions.length; i < len; i++) {
var condition = this.keyConditions[i]
if (ev.which == condition.specific
&& ev.originalEvent.shiftKey == condition.shift
&& ev.originalEvent.ctrlKey == condition.ctrl
&& ev.originalEvent.metaKey == condition.cmd
&& ev.originalEvent.altKey == condition.alt) {
if (ev.key === condition.specific
&& ev.originalEvent.shiftKey === condition.shift
&& ev.originalEvent.ctrlKey === condition.ctrl
&& ev.originalEvent.metaKey === condition.cmd
&& ev.originalEvent.altKey === condition.alt) {
return true
}
}

View File

@ -438,10 +438,10 @@
}
DictionaryEditor.prototype.onKeyDown = function(ev) {
if (ev.keyCode == 40) {
if (ev.key === 'ArrowDown') {
return this.navigateDown(ev)
}
else if (ev.keyCode == 38) {
else if (ev.key === 'ArrowUp') {
return this.navigateUp(ev)
}
}

View File

@ -537,10 +537,10 @@
}
StringListAutocomplete.prototype.onKeyDown = function(ev) {
if (ev.keyCode == 40) {
if (ev.key === 'ArrowDown') {
return this.navigateDown(ev)
}
else if (ev.keyCode == 38) {
else if (ev.key === 'ArrowUp') {
return this.navigateUp(ev)
}
}

View File

@ -188,7 +188,7 @@
}
InspectorPopup.prototype.onPopoverKeyDown = function(ev) {
if(ev.keyCode == 13) {
if(ev.key === 'Enter') {
$(ev.currentTarget).trigger('close.oc.popover')
}
}

View File

@ -155,7 +155,7 @@
return false
}
if (e.keyCode == 27) {
if (e.key === 'Escape') {
self.hide()
return false
}

View File

@ -40,7 +40,7 @@
})
this.$el.on('mousedown', "li[data-tab-id]", function (ev) {
if (ev.which === 2) {
if (ev.key === '2') {
$(ev.target).trigger('close.oc.tab');
}
})