| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('settings', function() { |
| 6 /** |
| 7 * Class for navigable routes. May only be instantiated within this file. |
| 8 * @constructor |
| 9 * @param {string} url |
| 10 * @private |
| 11 */ |
| 12 var Route = function(url) { |
| 13 this.url = url; |
| 14 |
| 15 /** @private {?settings.Route} */ |
| 16 this.parent_ = null; |
| 17 |
| 18 // Below are all legacy properties to provide compatibility with the old |
| 19 // routing system. TODO(tommycli): Remove once routing refactor complete. |
| 20 this.page = ''; |
| 21 this.section = ''; |
| 22 /** @type {!Array<string>} */ this.subpage = []; |
| 23 this.dialog = false; |
| 24 }; |
| 25 |
| 26 Route.prototype = { |
| 27 /** |
| 28 * Returns a new Route instance that's a child of this route. |
| 29 * @param {string} url |
| 30 * @param {string=} opt_subpageName |
| 31 * @return {!settings.Route} |
| 32 * @private |
| 33 */ |
| 34 createChild: function(url, opt_subpageName) { |
| 35 var route = new Route(url); |
| 36 route.parent_ = this; |
| 37 route.page = this.page; |
| 38 route.section = this.section; |
| 39 route.subpage = this.subpage.slice(); // Shallow copy. |
| 40 |
| 41 if (opt_subpageName) |
| 42 route.subpage.push(opt_subpageName); |
| 43 |
| 44 return route; |
| 45 }, |
| 46 |
| 47 /** |
| 48 * Returns a new Route instance that's a child dialog of this route. |
| 49 * @param {string} url |
| 50 * @return {!settings.Route} |
| 51 * @private |
| 52 */ |
| 53 createDialog: function(url) { |
| 54 var route = this.createChild(url); |
| 55 route.dialog = true; |
| 56 return route; |
| 57 }, |
| 58 |
| 59 /** |
| 60 * Returns true if this route is a descendant of the parameter. |
| 61 * @param {!settings.Route} route |
| 62 * @return {boolean} |
| 63 */ |
| 64 isDescendantOf: function(route) { |
| 65 for (var parent = this.parent_; parent != null; parent = parent.parent_) { |
| 66 if (route == parent) |
| 67 return true; |
| 68 } |
| 69 |
| 70 return false; |
| 71 }, |
| 72 }; |
| 73 |
| 74 return { |
| 75 Route: Route, |
| 76 }; |
| 77 }); |
| OLD | NEW |