diff options
author | hirono <hirono@chromium.org> | 2015-03-23 02:03:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-23 09:04:43 +0000 |
commit | 494e865c17e7d0467ac1f101206868d7663b5067 (patch) | |
tree | 47e5e127e8ae13226f9a30d01a02fc8f585d966e /ui | |
parent | 191e1b98d161acba462a293f9fe52366eda5ae75 (diff) | |
download | chromium_src-494e865c17e7d0467ac1f101206868d7663b5067.zip chromium_src-494e865c17e7d0467ac1f101206868d7663b5067.tar.gz chromium_src-494e865c17e7d0467ac1f101206868d7663b5067.tar.bz2 |
Remove dependency from file_type.js to util.js.
In the next CL, image loader extension needs to import file_type.js but it does
not need to import util.js. The CL remove dependency as preparation.
BUG=396702
TEST=None
Review URL: https://codereview.chromium.org/1027913003
Cr-Commit-Position: refs/heads/master@{#321748}
Diffstat (limited to 'ui')
4 files changed, 19 insertions, 18 deletions
diff --git a/ui/file_manager/file_manager/common/js/file_type.js b/ui/file_manager/file_manager/common/js/file_type.js index 2c6b08b..d3771db 100644 --- a/ui/file_manager/file_manager/common/js/file_type.js +++ b/ui/file_manager/file_manager/common/js/file_type.js @@ -250,7 +250,7 @@ FileType.getExtension = function(entry) { * if possible, since this method can't recognize directories. * * @param {string} name Name of the file. - * @return {Object} The matching file type object or an empty object. + * @return {!Object} The matching file type object or an empty object. */ FileType.getTypeForName = function(name) { var types = FileType.types; @@ -260,7 +260,8 @@ FileType.getTypeForName = function(name) { } // Unknown file type. - var extension = util.splitExtension(name)[1]; + var match = /\.[^\/\.]+$/.exec(name); + var extension = match ? match[0] : ''; if (extension === '') { return { name: 'NO_EXTENSION_FILE_TYPE', type: 'UNKNOWN', icon: '' }; } @@ -274,7 +275,7 @@ FileType.getTypeForName = function(name) { /** * Gets the file type object for a given file. * @param {Entry} entry Reference to the file. - * @return {Object} The matching file type object or an empty object. + * @return {!Object} The matching file type object or an empty object. */ FileType.getType = function(entry) { if (entry.isDirectory) @@ -299,17 +300,6 @@ FileType.getType = function(entry) { }; /** - * @param {Object} fileType Type object returned by FileType.getType(). - * @return {string} Localized string representation of file type. - */ -FileType.typeToString = function(fileType) { - if (fileType.subtype) - return strf(fileType.name, fileType.subtype); - else - return str(fileType.name); -}; - -/** * Gets the media type for a given file. * * @param {Entry} entry Reference to the file. diff --git a/ui/file_manager/file_manager/foreground/js/directory_contents.js b/ui/file_manager/file_manager/foreground/js/directory_contents.js index 8e8f53f..84328fd 100644 --- a/ui/file_manager/file_manager/foreground/js/directory_contents.js +++ b/ui/file_manager/file_manager/foreground/js/directory_contents.js @@ -424,6 +424,17 @@ function FileListModel(metadataModel) { this.isDescendingOrder_ = false; } +/** + * @param {!Object} fileType Type object returned by FileType.getType(). + * @return {string} Localized string representation of file type. + */ +FileListModel.getFileTypeString = function(fileType) { + if (fileType.subtype) + return strf(fileType.name, fileType.subtype); + else + return str(fileType.name); +}; + FileListModel.prototype = { __proto__: cr.ui.ArrayDataModel.prototype }; @@ -527,8 +538,8 @@ FileListModel.prototype.compareType_ = function(a, b) { if (a.isDirectory !== b.isDirectory) return a.isDirectory === this.isDescendingOrder_ ? 1 : -1; - var aType = FileType.typeToString(FileType.getType(a)); - var bType = FileType.typeToString(FileType.getType(b)); + var aType = FileListModel.getFileTypeString(FileType.getType(a)); + var bType = FileListModel.getFileTypeString(FileType.getType(b)); var result = util.collator.compare(aType, bType); return result !== 0 ? result : util.compareName(a, b); diff --git a/ui/file_manager/file_manager/foreground/js/ui/dialog_footer.js b/ui/file_manager/file_manager/foreground/js/ui/dialog_footer.js index 53b89c5..fed3d81 100644 --- a/ui/file_manager/file_manager/foreground/js/ui/dialog_footer.js +++ b/ui/file_manager/file_manager/foreground/js/ui/dialog_footer.js @@ -134,7 +134,7 @@ DialogFooter.prototype.initFileTypeFilter = function( if (!description) { // See if all the extensions in the group have the same description. for (var j = 0; j !== fileType.extensions.length; j++) { - var currentDescription = FileType.typeToString( + var currentDescription = FileListModel.getFileTypeString( FileType.getTypeForName('.' + fileType.extensions[j])); if (!description) { // Set the first time. diff --git a/ui/file_manager/file_manager/foreground/js/ui/file_table.js b/ui/file_manager/file_manager/foreground/js/ui/file_table.js index b66f9ec..d71b031 100644 --- a/ui/file_manager/file_manager/foreground/js/ui/file_table.js +++ b/ui/file_manager/file_manager/foreground/js/ui/file_table.js @@ -815,7 +815,7 @@ FileTable.prototype.renderType_ = function(entry, columnId, table) { var div = /** @type {!HTMLDivElement} */ (this.ownerDocument.createElement('div')); div.className = 'type'; - div.textContent = FileType.typeToString(FileType.getType(entry)); + div.textContent = FileListModel.getFileTypeString(FileType.getType(entry)); return div; }; |