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 /** | 5 /** |
6 * Namespace for utility functions. | 6 * Namespace for utility functions. |
7 */ | 7 */ |
8 var util = { | 8 var util = { |
9 /** | 9 /** |
10 * Returns a function that console.log's its arguments, prefixed by |msg|. | 10 * Returns a function that console.log's its arguments, prefixed by |msg|. |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 (event.shiftKey ? 'Shift-' : '') + | 492 (event.shiftKey ? 'Shift-' : '') + |
493 (event.metaKey ? 'Meta-' : ''); | 493 (event.metaKey ? 'Meta-' : ''); |
494 }, | 494 }, |
495 | 495 |
496 /** | 496 /** |
497 * A wrapper for navigator.onLine that allows for easy debug override. | 497 * A wrapper for navigator.onLine that allows for easy debug override. |
498 * @return {boolean} True if offline. | 498 * @return {boolean} True if offline. |
499 */ | 499 */ |
500 isOffline: function() { | 500 isOffline: function() { |
501 return !navigator.onLine; | 501 return !navigator.onLine; |
502 }, | |
503 | |
504 /* | |
505 * Returns root path used for displaying gdata content search results. | |
506 * Search results will be shown in directory gdataSearchRootPath/query. | |
507 * | |
508 * @return {string} | |
509 */ | |
510 getGDataSearchRootPath: function() { | |
Oleg Eterevsky
2012/05/03 15:52:24
Define constants instead?
/**
* @const
* @type
tbarzic
2012/05/03 19:16:02
Done.
| |
511 return '/gdata/.search'; | |
512 }, | |
513 | |
514 /* | |
515 * Creates directory path in which gdata content search results for |query| | |
516 * should be displayed. | |
517 * | |
518 * @param {string} Search query. | |
Oleg Eterevsky
2012/05/03 15:52:24
Please add the parameter name:
@param {string} qu
tbarzic
2012/05/03 19:16:02
Done.
| |
519 * @return {string} Virtual directory path for search results. | |
520 */ | |
521 createGDataSearchPath: function(query) { | |
522 return this.getGDataSearchRootPath() + '/' + query; | |
523 }, | |
524 | |
525 /* | |
526 * Tests if we can create new entries on gdata search path. If the provided | |
527 * path is not gdata path, it returns true. | |
528 * | |
529 * @param {string} Path which is being tested. | |
Oleg Eterevsky
2012/05/03 15:52:24
Please add the parameter name:
@param {string} pa
tbarzic
2012/05/03 19:16:02
Done.
| |
530 * @return {boolean} Test result. | |
531 */ | |
532 shouldCreateOnGDataPath: function(path) { | |
533 var gdataSearchRootPath = this.getGDataSearchRootPath(); | |
534 // If the path is not search root or it's child, we're fine. | |
535 if (path.search(gdataSearchRootPath) != 0) | |
536 return true; | |
537 | |
538 var pathComponents = path.split('/'); | |
539 var searchRootComponents = gdataSearchRootPath.split('/'); | |
540 | |
541 // We should not create entries on path if it's either gdata search root, | |
542 // or its immediate child. | |
543 return pathComponents.length != searchRootComponents.length && | |
544 pathComponents.length != searchRootComponents.length + 1; | |
545 }, | |
546 | |
547 /* | |
548 * Tests if the given path is a gdata search result path, and if it is returns | |
549 * files fileName in virtual search file system, and display name we that | |
Oleg Eterevsky
2012/05/03 15:52:24
... display name that ...
tbarzic
2012/05/03 19:16:02
Done.
| |
550 * should be used when the file is shown in file browser. | |
551 * | |
552 * @param {string} The potential gdata search result path. | |
Oleg Eterevsky
2012/05/03 15:52:24
Please add the parameter name.
tbarzic
2012/05/03 19:16:02
Done.
| |
553 * @return {object} Object that will contain file's fileName and displayName, | |
554 * or undefined if the path is not gdata search result path. | |
dgozman
2012/05/03 11:21:47
Use null instead of undefined.
Oleg Eterevsky
2012/05/03 15:52:24
@return {Object.<string,string>?}
tbarzic
2012/05/03 19:16:02
Done.
tbarzic
2012/05/03 19:16:02
Done.
| |
555 */ | |
556 getFileAndDisplayNameForGDataSearchResult: function(path) { | |
557 var gdataSearchRootPath = this.getGDataSearchRootPath(); | |
558 | |
559 // Nothing to do it the path is not under gdata search root path. | |
Oleg Eterevsky
2012/05/03 15:52:24
... to do IF the path ...
tbarzic
2012/05/03 19:16:02
Done.
| |
560 if (path.search(gdataSearchRootPath) != 0) | |
561 return undefined; | |
562 | |
563 var pathComponents = path.split('/'); | |
564 var searchRootComponents = gdataSearchRootPath.split('/'); | |
565 | |
566 // Search result should be formated like: | |
Oleg Eterevsky
2012/05/03 15:52:24
formatted
tbarzic
2012/05/03 19:16:02
Done.
| |
567 // gdataSearchRoot/query/result | |
568 if (pathComponents.length != searchRootComponents.length + 2) | |
569 return undefined; | |
570 for (var i = 0; i < searchRootComponents.length; i++) { | |
571 if (pathComponents[i] != searchRootComponents[i]) | |
572 return undefined; | |
573 } | |
574 | |
575 // Search result file name should be formatted like: | |
576 // resource_id.referenced_file_name | |
577 // We should display referenced file name only. | |
578 var result = {}; | |
579 result.fileName = pathComponents.pop(); | |
580 result.displayName = | |
581 result.fileName.slice(result.fileName.indexOf('.') + 1); | |
582 result.resourceId = | |
583 result.fileName.substr(0, result.fileName.indexOf('.')); | |
584 | |
585 if (result.fileName.length > 0 && result.displayName.length > 0) { | |
586 return result; | |
587 } else { | |
588 return undefined; | |
589 } | |
502 } | 590 } |
503 }; | 591 }; |
OLD | NEW |