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 /** | 10 /** |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 /** | 562 /** |
563 * Makes filesystem: URL from the path. | 563 * Makes filesystem: URL from the path. |
564 * @param {string} path File or directory path. | 564 * @param {string} path File or directory path. |
565 * @return {string} URL. | 565 * @return {string} URL. |
566 */ | 566 */ |
567 util.makeFilesystemUrl = function(path) { | 567 util.makeFilesystemUrl = function(path) { |
568 return 'filesystem:' + chrome.extension.getURL('external' + path); | 568 return 'filesystem:' + chrome.extension.getURL('external' + path); |
569 }; | 569 }; |
570 | 570 |
571 /** | 571 /** |
| 572 * @return {string} Id of the current Chrome extension. |
| 573 */ |
| 574 util.getExtensionId = function() { |
| 575 return chrome.extension.getURL('').split('/')[2]; |
| 576 }; |
| 577 |
| 578 /** |
572 * Traverses a tree up to a certain depth. | 579 * Traverses a tree up to a certain depth. |
573 * @param {FileEntry} root Root entry. | 580 * @param {FileEntry} root Root entry. |
574 * @param {function(Array.<Entry>)} callback The callback is called at the very | 581 * @param {function(Array.<Entry>)} callback The callback is called at the very |
575 * end with a list of entries found. | 582 * end with a list of entries found. |
576 * @param {number?} max_depth Maximum depth. Pass zero to traverse everything. | 583 * @param {number?} max_depth Maximum depth. Pass zero to traverse everything. |
577 */ | 584 */ |
578 util.traverseTree = function(root, callback, max_depth) { | 585 util.traverseTree = function(root, callback, max_depth) { |
579 if (root.isFile) { | 586 if (root.isFile) { |
580 callback([root]); | 587 callback([root]); |
581 return; | 588 return; |
(...skipping 23 matching lines...) Expand all Loading... |
605 } else { | 612 } else { |
606 readEntry(childEntry, depth + 1); | 613 readEntry(childEntry, depth + 1); |
607 } | 614 } |
608 }); | 615 }); |
609 } | 616 } |
610 | 617 |
611 readEntry(root, 0); | 618 readEntry(root, 0); |
612 }; | 619 }; |
613 | 620 |
614 /** | 621 /** |
| 622 * A shortcut function to create a child element with given tag and class. |
| 623 * |
| 624 * @param {HTMLElement} parent Parent element. |
| 625 * @param {string} opt_className Class name. |
| 626 * @param {string} opt_tag Element tag, DIV is omitted. |
| 627 * @return {Element} Newly created element. |
| 628 */ |
| 629 util.createChild = function(parent, opt_className, opt_tag) { |
| 630 var child = parent.ownerDocument.createElement(opt_tag || 'div'); |
| 631 if (opt_className) |
| 632 child.className = opt_className; |
| 633 parent.appendChild(child); |
| 634 return child; |
| 635 }; |
| 636 |
| 637 /** |
615 * Return a translated string. | 638 * Return a translated string. |
616 * | 639 * |
617 * Wrapper function to make dealing with translated strings more concise. | 640 * Wrapper function to make dealing with translated strings more concise. |
618 * Equivalent to loadTimeData.getString(id). | 641 * Equivalent to loadTimeData.getString(id). |
619 * | 642 * |
620 * @param {string} id The id of the string to return. | 643 * @param {string} id The id of the string to return. |
621 * @return {string} The translated string. | 644 * @return {string} The translated string. |
622 */ | 645 */ |
623 function str(id) { | 646 function str(id) { |
624 return loadTimeData.getString(id); | 647 return loadTimeData.getString(id); |
625 } | 648 } |
626 | 649 |
627 /** | 650 /** |
628 * Return a translated string with arguments replaced. | 651 * Return a translated string with arguments replaced. |
629 * | 652 * |
630 * Wrapper function to make dealing with translated strings more concise. | 653 * Wrapper function to make dealing with translated strings more concise. |
631 * Equivilant to loadTimeData.getStringF(id, ...). | 654 * Equivilant to loadTimeData.getStringF(id, ...). |
632 * | 655 * |
633 * @param {string} id The id of the string to return. | 656 * @param {string} id The id of the string to return. |
634 * @param {...string} var_args The values to replace into the string. | 657 * @param {...string} var_args The values to replace into the string. |
635 * @return {string} The translated string with replaced values. | 658 * @return {string} The translated string with replaced values. |
636 */ | 659 */ |
637 function strf(id, var_args) { | 660 function strf(id, var_args) { |
638 return loadTimeData.getStringF.apply(loadTimeData, arguments); | 661 return loadTimeData.getStringF.apply(loadTimeData, arguments); |
639 } | 662 } |
640 | |
OLD | NEW |