Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 document.addEventListener('DOMContentLoaded', function() { | 5 document.addEventListener('DOMContentLoaded', function() { |
| 6 ActionChoice.load(); | 6 ActionChoice.load(); |
| 7 }); | 7 }); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * The main ActionChoice object. | 10 * The main ActionChoice object. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 this.document_.querySelectorAll('.choices input')[0].focus(); | 96 this.document_.querySelectorAll('.choices input')[0].focus(); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * Load the source contents. | 100 * Load the source contents. |
| 101 * @param {string} source Path to source. | 101 * @param {string} source Path to source. |
| 102 * @private | 102 * @private |
| 103 */ | 103 */ |
| 104 ActionChoice.prototype.loadSource_ = function(source) { | 104 ActionChoice.prototype.loadSource_ = function(source) { |
| 105 var onTraversed = function(results) { | 105 var onTraversed = function(results) { |
| 106 this.previews_.removeAttribute('loading'); | 106 var videos = results.filter(FileType.isVideo); |
| 107 var videoLabel = this.dom_.querySelector('label[for=watch-single-video]'); | |
| 108 if (videos.length == 1) { | |
| 109 var name = videos[0].name; | |
| 110 var extPos = name.lastIndexOf('.'); | |
|
Vladislav Kaznacheev
2012/09/17 19:46:14
We have a function that does this in ImageUtil. Pl
dgozman
2012/09/18 11:28:09
Yeah, I just didn't want to include ImageUtil here
| |
| 111 if (extPos != -1) | |
| 112 name = name.substring(0, extPos); | |
| 113 videoLabel.textContent = loadTimeData.getStringF( | |
| 114 'ACTION_CHOICE_WATCH_SINGLE_VIDEO', name); | |
| 115 this.singleVideo_ = videos[0]; | |
| 116 } else { | |
| 117 videoLabel.parentNode.style.display = 'none'; | |
| 118 } | |
| 119 | |
| 107 var mediaFiles = results.filter(FileType.isImageOrVideo); | 120 var mediaFiles = results.filter(FileType.isImageOrVideo); |
| 121 if (mediaFiles.length == 0) { | |
| 122 this.dom_.querySelector('#import-photos-to-drive').parentNode. | |
|
Vladislav Kaznacheev
2012/09/17 19:46:14
This branch will be executed if we have a single v
dgozman
2012/09/18 11:28:09
Why not? We still can backup it from the device to
| |
| 123 style.display = 'none'; | |
| 124 } | |
| 108 | 125 |
| 126 var previews = results; | |
| 109 if (mediaFiles.length < ActionChoice.PREVIEW_COUNT) { | 127 if (mediaFiles.length < ActionChoice.PREVIEW_COUNT) { |
| 110 this.counter_.textContent = loadTimeData.getStringF( | 128 this.counter_.textContent = loadTimeData.getStringF( |
| 111 'ACTION_CHOICE_COUNTER_NO_MEDIA', results.length); | 129 'ACTION_CHOICE_COUNTER_NO_MEDIA', results.length); |
| 112 } else { | 130 } else { |
| 113 this.counter_.textContent = loadTimeData.getStringF( | 131 this.counter_.textContent = loadTimeData.getStringF( |
| 114 'ACTION_CHOICE_COUNTER', results.length, mediaFiles.length); | 132 'ACTION_CHOICE_COUNTER', results.length, mediaFiles.length); |
| 115 results = mediaFiles; | 133 previews = mediaFiles; |
| 116 } | 134 } |
| 117 | 135 this.previews_.removeAttribute('loading'); |
| 118 var count = Math.min(results.length, ActionChoice.PREVIEW_COUNT); | 136 var count = Math.min(previews.length, ActionChoice.PREVIEW_COUNT); |
| 119 for (var index = 0; index < count; index++) { | 137 for (var index = 0; index < count; index++) { |
| 120 this.renderPreview_(results[index]); | 138 this.renderPreview_(previews[index]); |
| 121 } | 139 } |
| 122 }.bind(this); | 140 }.bind(this); |
| 123 | 141 |
| 124 var onEntry = function(entry) { | 142 var onEntry = function(entry) { |
| 125 this.sourceEntry_ = entry; | 143 this.sourceEntry_ = entry; |
| 126 // TODO(dgozman): add icon. | 144 // TODO(dgozman): add icon. |
| 127 this.title_.textContent = entry.name; | 145 this.title_.textContent = entry.name; |
| 146 this.document_.querySelector('title').textContent = entry.name; | |
| 128 util.traverseTree(entry, onTraversed, 0 /* infinite depth */); | 147 util.traverseTree(entry, onTraversed, 0 /* infinite depth */); |
| 129 }.bind(this); | 148 }.bind(this); |
| 130 | 149 |
| 131 this.sourceEntry_ = null; | 150 this.sourceEntry_ = null; |
| 132 util.resolvePath(this.filesystem_.root, source, onEntry, this.closeBound_); | 151 util.resolvePath(this.filesystem_.root, source, onEntry, this.closeBound_); |
| 133 }; | 152 }; |
| 134 | 153 |
| 135 /** | 154 /** |
| 136 * Renders a preview for a media entry. | 155 * Renders a preview for a media entry. |
| 137 * @param {FileEntry} entry The entry. | 156 * @param {FileEntry} entry The entry. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 */ | 197 */ |
| 179 ActionChoice.prototype.onOk_ = function() { | 198 ActionChoice.prototype.onOk_ = function() { |
| 180 if (this.document_.querySelector('#import-photos-to-drive').checked) { | 199 if (this.document_.querySelector('#import-photos-to-drive').checked) { |
| 181 var url = chrome.extension.getURL('photo_import.html') + | 200 var url = chrome.extension.getURL('photo_import.html') + |
| 182 '#' + this.sourceEntry_.fullPath; | 201 '#' + this.sourceEntry_.fullPath; |
| 183 chrome.windows.create({url: url, type: 'popup'}); | 202 chrome.windows.create({url: url, type: 'popup'}); |
| 184 } else if (this.document_.querySelector('#view-files').checked) { | 203 } else if (this.document_.querySelector('#view-files').checked) { |
| 185 var url = chrome.extension.getURL('main.html') + | 204 var url = chrome.extension.getURL('main.html') + |
| 186 '#' + this.sourceEntry_.fullPath; | 205 '#' + this.sourceEntry_.fullPath; |
| 187 chrome.windows.create({url: url, type: 'popup'}); | 206 chrome.windows.create({url: url, type: 'popup'}); |
| 207 } else if (this.document_.querySelector('#watch-single-video').checked) { | |
| 208 chrome.fileBrowserPrivate.viewFiles([this.singleVideo_.toURL()], 'watch', | |
| 209 function(success) {}); | |
| 188 } | 210 } |
| 189 this.close_(); | 211 this.close_(); |
| 190 }; | 212 }; |
| OLD | NEW |