Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: chrome/browser/resources/file_manager/js/breadcrumbs_controller.js

Issue 10823119: Enable drag and drop on breadcrumbs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends cr.EventTarget 7 * @extends cr.EventTarget
8 * @param {HTMLDivElement} div Div container for breadcrumbs. 8 * @param {HTMLDivElement} div Div container for breadcrumbs.
9 */ 9 */
10 function BreadcrumbsController(div) { 10 function BreadcrumbsController(div) {
11 this.bc_ = div; 11 this.bc_ = div;
12 this.hideLast_ = false; 12 this.hideLast_ = false;
13 div.addEventListener('click', this.onClick_.bind(this));
13 } 14 }
14 15
15 /** 16 /**
16 * Extends cr.EventTarget. 17 * Extends cr.EventTarget.
17 */ 18 */
18 BreadcrumbsController.prototype.__proto__ = cr.EventTarget.prototype; 19 BreadcrumbsController.prototype.__proto__ = cr.EventTarget.prototype;
19 20
20 /** 21 /**
21 * Whether to hide the last part of the path. 22 * Whether to hide the last part of the path.
22 * @param {boolean} value True if hide. 23 * @param {boolean} value True if hide.
23 */ 24 */
24 BreadcrumbsController.prototype.setHideLast = function(value) { 25 BreadcrumbsController.prototype.setHideLast = function(value) {
25 this.hideLast_ = value; 26 this.hideLast_ = value;
26 }; 27 };
27 28
28 /** 29 /**
29 * Update the breadcrumb display. 30 * Update the breadcrumb display.
30 * @param {string} rootPath Path to root. 31 * @param {string} rootPath Path to root.
31 * @param {string} path Path to directory. 32 * @param {string} path Path to directory.
32 */ 33 */
33 BreadcrumbsController.prototype.update = function(rootPath, path) { 34 BreadcrumbsController.prototype.update = function(rootPath, path) {
34 this.bc_.textContent = ''; 35 this.bc_.textContent = '';
36 this.rootPath_ = rootPath;
35 37
36 var relativePath = path.substring(rootPath.length).replace(/\/$/, ''); 38 var relativePath = path.substring(rootPath.length).replace(/\/$/, '');
37 var pathNames = relativePath.split('/'); 39 var pathNames = relativePath.split('/');
38 if (pathNames[0] == '') 40 if (pathNames[0] == '')
39 pathNames.splice(0, 1); 41 pathNames.splice(0, 1);
40 42
41 // We need a first breadcrumb for root, so placing last name from 43 // We need a first breadcrumb for root, so placing last name from
42 // rootPath as first name of relativePath. 44 // rootPath as first name of relativePath.
43 var rootPathNames = rootPath.replace(/\/$/, '').split('/'); 45 var rootPathNames = rootPath.replace(/\/$/, '').split('/');
44 pathNames.splice(0, 0, rootPathNames[rootPathNames.length - 1]); 46 pathNames.splice(0, 0, rootPathNames[rootPathNames.length - 1]);
(...skipping 12 matching lines...) Expand all
57 } 59 }
58 var pathName = pathNames[i]; 60 var pathName = pathNames[i];
59 path += pathName; 61 path += pathName;
60 62
61 var div = doc.createElement('div'); 63 var div = doc.createElement('div');
62 64
63 div.className = 'breadcrumb-path'; 65 div.className = 'breadcrumb-path';
64 div.textContent = i == 0 ? PathUtil.getRootLabel(path) : pathName; 66 div.textContent = i == 0 ? PathUtil.getRootLabel(path) : pathName;
65 67
66 path = path + '/'; 68 path = path + '/';
67 div.path = path;
68 69
69 this.bc_.appendChild(div); 70 this.bc_.appendChild(div);
70 71
71 if (i == pathNames.length - 1) { 72 if (i == pathNames.length - 1)
72 div.classList.add('breadcrumb-last'); 73 div.classList.add('breadcrumb-last');
73 } else {
74 div.addEventListener('click', this.onClick_.bind(this));
75 }
76 } 74 }
77 this.truncate(); 75 this.truncate();
78 }; 76 };
79 77
80 /** 78 /**
81 * Updates breadcrumbs widths in order to truncate it properly. 79 * Updates breadcrumbs widths in order to truncate it properly.
82 */ 80 */
83 BreadcrumbsController.prototype.truncate = function() { 81 BreadcrumbsController.prototype.truncate = function() {
84 if (!this.bc_.firstChild) 82 if (!this.bc_.firstChild)
85 return; 83 return;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 BreadcrumbsController.prototype.hide = function() { 179 BreadcrumbsController.prototype.hide = function() {
182 this.bc_.style.display = 'none'; 180 this.bc_.style.display = 'none';
183 }; 181 };
184 182
185 /** 183 /**
186 * Handle a click event on a breadcrumb element. 184 * Handle a click event on a breadcrumb element.
187 * @private 185 * @private
188 * @param {Event} event The click event. 186 * @param {Event} event The click event.
189 */ 187 */
190 BreadcrumbsController.prototype.onClick_ = function(event) { 188 BreadcrumbsController.prototype.onClick_ = function(event) {
189 var path = this.getTargetPath(event);
190 if (!path)
191 return;
192
191 var newEvent = new cr.Event('pathclick'); 193 var newEvent = new cr.Event('pathclick');
192 newEvent.path = event.srcElement.path; 194 newEvent.path = path;
193 this.dispatchEvent(newEvent); 195 this.dispatchEvent(newEvent);
194 }; 196 };
195 197
198 /**
199 * Returns path associated with the event target. Returns empty string for
200 * inactive elements: separators, empty space and the last chunk.
201 * @param {Event} event The UI event.
202 * @return {string} Full path or empty string.
203 */
204 BreadcrumbsController.prototype.getTargetPath = function(event) {
205 if (!event.target.classList.contains('breadcrumb-path') ||
206 event.target.classList.contains('breadcrumb-last')) {
207 return '';
208 }
209
210 var items = this.bc_.querySelectorAll('.breadcrumb-path');
211 var path = this.rootPath_;
212
213 if (event.target != items[0]) {
214 for (var i = 1; items[i - 1] != event.target; i++) {
Oleg Eterevsky 2012/08/01 14:56:52 You can use PathUtil.join() instead of this loop.
SeRya 2012/08/01 15:23:44 Join is not enough, textContent also need to be re
215 path += '/' + items[i].textContent;
216 }
217 }
218 return path;
219 };
220
221 /**
222 * Returns the breadcrumbs container.
223 * @return {HTMLElement} Breadcumbs container HTML element.
224 */
225 BreadcrumbsController.prototype.getContainer = function() {
226 return this.bc_;
227 };
228
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698