Commit 24704223 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] ES6 convert var to let/const file selection files

CL 1 of 4, CLs:
1. Convert var to const/let.
2. Convert arrow functions.
3. Convert to ES6.
4. Reformat files.

Bug: 778674
Change-Id: I4c9bae5f47ffe89380936c37e3fef950d5a3dbde
Reviewed-on: https://chromium-review.googlesource.com/c/1460198
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630160}
parent c37d3541
...@@ -35,9 +35,9 @@ class FileListSelectionModel extends cr.ui.ListSelectionModel { ...@@ -35,9 +35,9 @@ class FileListSelectionModel extends cr.ui.ListSelectionModel {
*/ */
adjustToReordering(permutation) { adjustToReordering(permutation) {
// Look at the old state. // Look at the old state.
var oldSelectedItemsCount = this.selectedIndexes.length; const oldSelectedItemsCount = this.selectedIndexes.length;
var oldLeadIndex = this.leadIndex; const oldLeadIndex = this.leadIndex;
var newSelectedItemsCount = const newSelectedItemsCount =
this.selectedIndexes.filter(i => permutation[i] != -1).length; this.selectedIndexes.filter(i => permutation[i] != -1).length;
// Call the superclass function. // Call the superclass function.
super.adjustToReordering(permutation); super.adjustToReordering(permutation);
...@@ -59,7 +59,7 @@ class FileListSelectionModel extends cr.ui.ListSelectionModel { ...@@ -59,7 +59,7 @@ class FileListSelectionModel extends cr.ui.ListSelectionModel {
// mode. When the number of selected item is one, the mode depends on the // mode. When the number of selected item is one, the mode depends on the
// last keyboard/mouse operation. In this case, the mode is controlled from // last keyboard/mouse operation. In this case, the mode is controlled from
// outside. See filelist.handlePointerDownUp and filelist.handleKeyDown. // outside. See filelist.handlePointerDownUp and filelist.handleKeyDown.
var selectedIndexes = this.selectedIndexes; const selectedIndexes = this.selectedIndexes;
if (selectedIndexes.length === 0) { if (selectedIndexes.length === 0) {
this.isCheckSelectMode_ = false; this.isCheckSelectMode_ = false;
} else if (selectedIndexes.length >= 2) { } else if (selectedIndexes.length >= 2) {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/** /**
* Namespace for utility functions. * Namespace for utility functions.
*/ */
var filelist = {}; const filelist = {};
/** /**
* File table list. * File table list.
...@@ -48,12 +48,12 @@ FileTableList.prototype.mergeItems = function(beginIndex, endIndex) { ...@@ -48,12 +48,12 @@ FileTableList.prototype.mergeItems = function(beginIndex, endIndex) {
// Make sure that list item's selected attribute is updated just after the // Make sure that list item's selected attribute is updated just after the
// mergeItems operation is done. This prevents checkmarks on selected items // mergeItems operation is done. This prevents checkmarks on selected items
// from being animated unintentionally by redraw. // from being animated unintentionally by redraw.
for (var i = beginIndex; i < endIndex; i++) { for (let i = beginIndex; i < endIndex; i++) {
var item = this.getListItemByIndex(i); const item = this.getListItemByIndex(i);
if (!item) { if (!item) {
continue; continue;
} }
var isSelected = this.selectionModel.getIndexSelected(i); const isSelected = this.selectionModel.getIndexSelected(i);
if (item.selected != isSelected) { if (item.selected != isSelected) {
item.selected = isSelected; item.selected = isSelected;
} }
...@@ -136,7 +136,7 @@ filelist.decorateListItem = function(li, entry, metadataModel) { ...@@ -136,7 +136,7 @@ filelist.decorateListItem = function(li, entry, metadataModel) {
// The metadata may not yet be ready. In that case, the list item will be // The metadata may not yet be ready. In that case, the list item will be
// updated when the metadata is ready via updateListItemsMetadata. For files // updated when the metadata is ready via updateListItemsMetadata. For files
// not on an external backend, externalProps is not available. // not on an external backend, externalProps is not available.
var externalProps = metadataModel.getCache([entry], [ const externalProps = metadataModel.getCache([entry], [
'hosted', 'availableOffline', 'customIconUrl', 'shared', 'isMachineRoot', 'hosted', 'availableOffline', 'customIconUrl', 'shared', 'isMachineRoot',
'isExternalMedia' 'isExternalMedia'
])[0]; ])[0];
...@@ -179,7 +179,7 @@ filelist.decorateListItem = function(li, entry, metadataModel) { ...@@ -179,7 +179,7 @@ filelist.decorateListItem = function(li, entry, metadataModel) {
* @return {!HTMLDivElement} Created element. * @return {!HTMLDivElement} Created element.
*/ */
filelist.renderFileTypeIcon = function(doc, entry, locationInfo, opt_mimeType) { filelist.renderFileTypeIcon = function(doc, entry, locationInfo, opt_mimeType) {
var icon = /** @type {!HTMLDivElement} */ (doc.createElement('div')); const icon = /** @type {!HTMLDivElement} */ (doc.createElement('div'));
icon.className = 'detail-icon'; icon.className = 'detail-icon';
icon.setAttribute( icon.setAttribute(
'file-type-icon', 'file-type-icon',
...@@ -197,9 +197,9 @@ filelist.renderFileTypeIcon = function(doc, entry, locationInfo, opt_mimeType) { ...@@ -197,9 +197,9 @@ filelist.renderFileTypeIcon = function(doc, entry, locationInfo, opt_mimeType) {
filelist.renderFileNameLabel = function(doc, entry, locationInfo) { filelist.renderFileNameLabel = function(doc, entry, locationInfo) {
// Filename need to be in a '.filename-label' container for correct // Filename need to be in a '.filename-label' container for correct
// work of inplace renaming. // work of inplace renaming.
var box = /** @type {!HTMLDivElement} */ (doc.createElement('div')); const box = /** @type {!HTMLDivElement} */ (doc.createElement('div'));
box.className = 'filename-label'; box.className = 'filename-label';
var fileName = doc.createElement('span'); const fileName = doc.createElement('span');
fileName.className = 'entry-name'; fileName.className = 'entry-name';
fileName.textContent = util.getEntryLabel(locationInfo, entry); fileName.textContent = util.getEntryLabel(locationInfo, entry);
box.appendChild(fileName); box.appendChild(fileName);
...@@ -231,7 +231,7 @@ filelist.updateListItemExternalProps = function( ...@@ -231,7 +231,7 @@ filelist.updateListItemExternalProps = function(
} }
} }
var iconDiv = li.querySelector('.detail-icon'); const iconDiv = li.querySelector('.detail-icon');
if (!iconDiv) { if (!iconDiv) {
return; return;
} }
...@@ -263,7 +263,7 @@ filelist.updateListItemExternalProps = function( ...@@ -263,7 +263,7 @@ filelist.updateListItemExternalProps = function(
* @this {cr.ui.ListSelectionController} * @this {cr.ui.ListSelectionController}
*/ */
filelist.handleTap = function(e, index, eventType) { filelist.handleTap = function(e, index, eventType) {
var sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */ const sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */
(this.selectionModel); (this.selectionModel);
if (eventType == FileTapHandler.TapEvent.TWO_FINGER_TAP) { if (eventType == FileTapHandler.TapEvent.TWO_FINGER_TAP) {
// Prepare to open the context menu in the same manner as the right click. // Prepare to open the context menu in the same manner as the right click.
...@@ -276,7 +276,7 @@ filelist.handleTap = function(e, index, eventType) { ...@@ -276,7 +276,7 @@ filelist.handleTap = function(e, index, eventType) {
// not produce mousedown/click events. // not produce mousedown/click events.
sm.unselectAll(); sm.unselectAll();
} else { } else {
var indexSelected = sm.getIndexSelected(index); const indexSelected = sm.getIndexSelected(index);
if (!indexSelected) { if (!indexSelected) {
// Prepare to open context menu of the new item by selecting only it. // Prepare to open context menu of the new item by selecting only it.
if (sm.getCheckSelectMode()) { if (sm.getCheckSelectMode()) {
...@@ -297,13 +297,13 @@ filelist.handleTap = function(e, index, eventType) { ...@@ -297,13 +297,13 @@ filelist.handleTap = function(e, index, eventType) {
if (index == -1) { if (index == -1) {
return false; return false;
} }
var isTap = eventType == FileTapHandler.TapEvent.TAP || const isTap = eventType == FileTapHandler.TapEvent.TAP ||
eventType == FileTapHandler.TapEvent.LONG_TAP; eventType == FileTapHandler.TapEvent.LONG_TAP;
// Revert to click handling for single tap on checkbox or tap during rename. // Revert to click handling for single tap on checkbox or tap during rename.
// Single tap on the checkbox in the list view mode should toggle select. // Single tap on the checkbox in the list view mode should toggle select.
// Single tap on input for rename should focus on input. // Single tap on input for rename should focus on input.
var isCheckbox = e.target.classList.contains('detail-checkmark'); const isCheckbox = e.target.classList.contains('detail-checkmark');
var isRename = e.target.localName == 'input'; const isRename = e.target.localName == 'input';
if (eventType == FileTapHandler.TapEvent.TAP && (isCheckbox || isRename)) { if (eventType == FileTapHandler.TapEvent.TAP && (isCheckbox || isRename)) {
return false; return false;
} }
...@@ -361,17 +361,17 @@ filelist.handleTap = function(e, index, eventType) { ...@@ -361,17 +361,17 @@ filelist.handleTap = function(e, index, eventType) {
* @this {cr.ui.ListSelectionController} * @this {cr.ui.ListSelectionController}
*/ */
filelist.handlePointerDownUp = function(e, index) { filelist.handlePointerDownUp = function(e, index) {
var sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */ const sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */
(this.selectionModel); (this.selectionModel);
var anchorIndex = sm.anchorIndex; const anchorIndex = sm.anchorIndex;
var isDown = (e.type == 'mousedown'); const isDown = (e.type == 'mousedown');
var isTargetCheckmark = e.target.classList.contains('detail-checkmark') || const isTargetCheckmark = e.target.classList.contains('detail-checkmark') ||
e.target.classList.contains('checkmark'); e.target.classList.contains('checkmark');
// If multiple selection is allowed and the checkmark is clicked without // If multiple selection is allowed and the checkmark is clicked without
// modifiers(Ctrl/Shift), the click should toggle the item's selection. // modifiers(Ctrl/Shift), the click should toggle the item's selection.
// (i.e. same behavior as Ctrl+Click) // (i.e. same behavior as Ctrl+Click)
var isClickOnCheckmark = isTargetCheckmark && sm.multiple && index != -1 && const isClickOnCheckmark = isTargetCheckmark && sm.multiple && index != -1 &&
!e.shiftKey && !e.ctrlKey && e.button == 0; !e.shiftKey && !e.ctrlKey && e.button == 0;
sm.beginChange(); sm.beginChange();
...@@ -414,10 +414,10 @@ filelist.handlePointerDownUp = function(e, index) { ...@@ -414,10 +414,10 @@ filelist.handlePointerDownUp = function(e, index) {
} }
} else { } else {
// Right click for a context menu needs to not clear the selection. // Right click for a context menu needs to not clear the selection.
var isRightClick = e.button == 2; const isRightClick = e.button == 2;
// If the index is selected this is handled in mouseup. // If the index is selected this is handled in mouseup.
var indexSelected = sm.getIndexSelected(index); const indexSelected = sm.getIndexSelected(index);
if ((indexSelected && !isDown || !indexSelected && isDown) && if ((indexSelected && !isDown || !indexSelected && isDown) &&
!(indexSelected && isRightClick)) { !(indexSelected && isRightClick)) {
// 2) When non-checkmark area is clicked in check-select mode, disable // 2) When non-checkmark area is clicked in check-select mode, disable
...@@ -450,14 +450,14 @@ filelist.handlePointerDownUp = function(e, index) { ...@@ -450,14 +450,14 @@ filelist.handlePointerDownUp = function(e, index) {
* @this {cr.ui.ListSelectionController} * @this {cr.ui.ListSelectionController}
*/ */
filelist.handleKeyDown = function(e) { filelist.handleKeyDown = function(e) {
var SPACE_KEY_CODE = 32; const SPACE_KEY_CODE = 32;
var tagName = e.target.tagName; const tagName = e.target.tagName;
// If focus is in an input field of some kind, only handle navigation keys // If focus is in an input field of some kind, only handle navigation keys
// that aren't likely to conflict with input interaction (e.g., text // that aren't likely to conflict with input interaction (e.g., text
// editing, or changing the value of a checkbox or select). // editing, or changing the value of a checkbox or select).
if (tagName == 'INPUT') { if (tagName == 'INPUT') {
var inputType = e.target.type; const inputType = e.target.type;
// Just protect space (for toggling) for checkbox and radio. // Just protect space (for toggling) for checkbox and radio.
if (inputType == 'checkbox' || inputType == 'radio') { if (inputType == 'checkbox' || inputType == 'radio') {
if (e.keyCode == SPACE_KEY_CODE) { if (e.keyCode == SPACE_KEY_CODE) {
...@@ -473,11 +473,11 @@ filelist.handleKeyDown = function(e) { ...@@ -473,11 +473,11 @@ filelist.handleKeyDown = function(e) {
return; return;
} }
var sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */ const sm = /** @type {!FileListSelectionModel|!FileListSingleSelectionModel} */
(this.selectionModel); (this.selectionModel);
var newIndex = -1; let newIndex = -1;
var leadIndex = sm.leadIndex; const leadIndex = sm.leadIndex;
var prevent = true; let prevent = true;
// Ctrl/Meta+A // Ctrl/Meta+A
if (sm.multiple && e.keyCode == 65 && if (sm.multiple && e.keyCode == 65 &&
...@@ -498,7 +498,7 @@ filelist.handleKeyDown = function(e) { ...@@ -498,7 +498,7 @@ filelist.handleKeyDown = function(e) {
// Space // Space
if (e.keyCode == SPACE_KEY_CODE) { if (e.keyCode == SPACE_KEY_CODE) {
if (leadIndex != -1) { if (leadIndex != -1) {
var selected = sm.getIndexSelected(leadIndex); const selected = sm.getIndexSelected(leadIndex);
if (e.ctrlKey || !selected) { if (e.ctrlKey || !selected) {
sm.setIndexSelected(leadIndex, !selected || !sm.multiple); sm.setIndexSelected(leadIndex, !selected || !sm.multiple);
return; return;
...@@ -540,7 +540,7 @@ filelist.handleKeyDown = function(e) { ...@@ -540,7 +540,7 @@ filelist.handleKeyDown = function(e) {
sm.leadIndex = newIndex; sm.leadIndex = newIndex;
if (e.shiftKey) { if (e.shiftKey) {
var anchorIndex = sm.anchorIndex; const anchorIndex = sm.anchorIndex;
if (sm.multiple) { if (sm.multiple) {
sm.unselectAll(); sm.unselectAll();
} }
...@@ -575,7 +575,7 @@ filelist.handleKeyDown = function(e) { ...@@ -575,7 +575,7 @@ filelist.handleKeyDown = function(e) {
* @param {!Event} event the touch event. * @param {!Event} event the touch event.
*/ */
filelist.focusParentList = function(event) { filelist.focusParentList = function(event) {
var element = event.target; let element = event.target;
while (element && !(element instanceof cr.ui.List)) { while (element && !(element instanceof cr.ui.List)) {
element = element.parentElement; element = element.parentElement;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment