1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Obtains the entry set from the entries passed from onLaunched events.
9 * If an single entry is specified, the function returns all entries in the same
10 * directory. Otherwise the function returns the passed entries.
12 * The function also filters non-image items and hidden items.
14 * @param {!Array<!FileEntry>} originalEntries Entries passed from onLaunched
16 * @return {!Promise} Promise to be fulfilled with entry array.
18 GalleryUtil.createEntrySet = function(originalEntries) {
20 if (originalEntries.length === 1) {
22 new Promise(originalEntries[0].getParent.bind(originalEntries[0]));
23 entriesPromise = parentPromise.then(function(parent) {
24 var reader = parent.createReader();
25 var readEntries = function() {
26 return new Promise(reader.readEntries.bind(reader)).then(
28 if (entries.length === 0)
30 return readEntries().then(function(nextEntries) {
31 return entries.concat(nextEntries);
36 }).then(function(entries) {
37 return entries.filter(function(entry) {
38 return originalEntries[0].toURL() === entry.toURL() ||
39 entry.name[0] !== '.';
43 entriesPromise = Promise.resolve(originalEntries);
46 return entriesPromise.then(function(entries) {
47 return entries.filter(function(entry) {
48 // Currently the gallery doesn't support mime types, so checking by
49 // file extensions is enough.
50 return FileType.isImage(entry) || FileType.isRaw(entry);
51 }).sort(function(a, b) {
52 return util.compareName(a, b);
58 * Returns true if entry is on MTP volume.
59 * @param {!Entry} entry An entry.
60 * @param {!VolumeManagerWrapper} volumeManager Volume manager.
61 * @return True if entry is on MTP volume.
63 GalleryUtil.isOnMTPVolume = function(entry, volumeManager) {
64 var volumeInfo = volumeManager.getVolumeInfo(entry);
66 volumeInfo.volumeType === VolumeManagerCommon.VolumeType.MTP;
70 * Decorates an element to handle mouse focus specific logic. The element
71 * becomes to have using-mouse class when it is focused by mouse.
72 * @param {!HTMLElement} element
74 GalleryUtil.decorateMouseFocusHandling = function(element) {
75 element.addEventListener('mousedown',
76 element.classList.toggle.bind(element.classList, 'using-mouse', true));
77 element.addEventListener('blur',
78 element.classList.toggle.bind(element.classList, 'using-mouse', false));