| 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('.'); |
| 111 // TODO(dgozman): use GetFileNameFromFullName once it is moved to |
| 112 // appropriate place. |
| 113 if (extPos != -1) |
| 114 name = name.substring(0, extPos); |
| 115 videoLabel.textContent = loadTimeData.getStringF( |
| 116 'ACTION_CHOICE_WATCH_SINGLE_VIDEO', name); |
| 117 this.singleVideo_ = videos[0]; |
| 118 } else { |
| 119 videoLabel.parentNode.style.display = 'none'; |
| 120 } |
| 121 |
| 107 var mediaFiles = results.filter(FileType.isImageOrVideo); | 122 var mediaFiles = results.filter(FileType.isImageOrVideo); |
| 123 if (mediaFiles.length == 0) { |
| 124 this.dom_.querySelector('#import-photos-to-drive').parentNode. |
| 125 style.display = 'none'; |
| 126 } |
| 108 | 127 |
| 128 var previews = results; |
| 109 if (mediaFiles.length < ActionChoice.PREVIEW_COUNT) { | 129 if (mediaFiles.length < ActionChoice.PREVIEW_COUNT) { |
| 110 this.counter_.textContent = loadTimeData.getStringF( | 130 this.counter_.textContent = loadTimeData.getStringF( |
| 111 'ACTION_CHOICE_COUNTER_NO_MEDIA', results.length); | 131 'ACTION_CHOICE_COUNTER_NO_MEDIA', results.length); |
| 112 } else { | 132 } else { |
| 113 this.counter_.textContent = loadTimeData.getStringF( | 133 this.counter_.textContent = loadTimeData.getStringF( |
| 114 'ACTION_CHOICE_COUNTER', results.length, mediaFiles.length); | 134 'ACTION_CHOICE_COUNTER', results.length, mediaFiles.length); |
| 115 results = mediaFiles; | 135 previews = mediaFiles; |
| 116 } | 136 } |
| 117 | 137 this.previews_.removeAttribute('loading'); |
| 118 var count = Math.min(results.length, ActionChoice.PREVIEW_COUNT); | 138 var count = Math.min(previews.length, ActionChoice.PREVIEW_COUNT); |
| 119 for (var index = 0; index < count; index++) { | 139 for (var index = 0; index < count; index++) { |
| 120 this.renderPreview_(results[index]); | 140 this.renderPreview_(previews[index]); |
| 121 } | 141 } |
| 122 }.bind(this); | 142 }.bind(this); |
| 123 | 143 |
| 124 var onEntry = function(entry) { | 144 var onEntry = function(entry) { |
| 125 this.sourceEntry_ = entry; | 145 this.sourceEntry_ = entry; |
| 126 // TODO(dgozman): add icon. | 146 // TODO(dgozman): add icon. |
| 127 this.title_.textContent = entry.name; | 147 this.title_.textContent = entry.name; |
| 148 this.document_.querySelector('title').textContent = entry.name; |
| 128 util.traverseTree(entry, onTraversed, 0 /* infinite depth */); | 149 util.traverseTree(entry, onTraversed, 0 /* infinite depth */); |
| 129 }.bind(this); | 150 }.bind(this); |
| 130 | 151 |
| 131 this.sourceEntry_ = null; | 152 this.sourceEntry_ = null; |
| 132 util.resolvePath(this.filesystem_.root, source, onEntry, this.closeBound_); | 153 util.resolvePath(this.filesystem_.root, source, onEntry, this.closeBound_); |
| 133 }; | 154 }; |
| 134 | 155 |
| 135 /** | 156 /** |
| 136 * Renders a preview for a media entry. | 157 * Renders a preview for a media entry. |
| 137 * @param {FileEntry} entry The entry. | 158 * @param {FileEntry} entry The entry. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 */ | 199 */ |
| 179 ActionChoice.prototype.onOk_ = function() { | 200 ActionChoice.prototype.onOk_ = function() { |
| 180 if (this.document_.querySelector('#import-photos-to-drive').checked) { | 201 if (this.document_.querySelector('#import-photos-to-drive').checked) { |
| 181 var url = chrome.extension.getURL('photo_import.html') + | 202 var url = chrome.extension.getURL('photo_import.html') + |
| 182 '#' + this.sourceEntry_.fullPath; | 203 '#' + this.sourceEntry_.fullPath; |
| 183 chrome.windows.create({url: url, type: 'popup'}); | 204 chrome.windows.create({url: url, type: 'popup'}); |
| 184 } else if (this.document_.querySelector('#view-files').checked) { | 205 } else if (this.document_.querySelector('#view-files').checked) { |
| 185 var url = chrome.extension.getURL('main.html') + | 206 var url = chrome.extension.getURL('main.html') + |
| 186 '#' + this.sourceEntry_.fullPath; | 207 '#' + this.sourceEntry_.fullPath; |
| 187 chrome.windows.create({url: url, type: 'popup'}); | 208 chrome.windows.create({url: url, type: 'popup'}); |
| 209 } else if (this.document_.querySelector('#watch-single-video').checked) { |
| 210 chrome.fileBrowserPrivate.viewFiles([this.singleVideo_.toURL()], 'watch', |
| 211 function(success) {}); |
| 188 } | 212 } |
| 189 this.close_(); | 213 this.close_(); |
| 190 }; | 214 }; |
| OLD | NEW |