| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This application displays documentation generated by the docgen tool | 6 * This application displays documentation generated by the docgen tool |
| 7 * found at dart-repo/dart/pkg/docgen. | 7 * found at dart-repo/dart/pkg/docgen. |
| 8 * | 8 * |
| 9 * The Yaml file outputted by the docgen tool will be read in to | 9 * The Yaml file outputted by the docgen tool will be read in to |
| 10 * generate [Page] and [Category] and [CompositeContainer]. | 10 * generate [Page] and [Category] and [CompositeContainer]. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (location.subMemberName == null) return location; | 243 if (location.subMemberName == null) return location; |
| 244 var newLocation = new DocsLocation(location.parentQualifiedName); | 244 var newLocation = new DocsLocation(location.parentQualifiedName); |
| 245 newLocation.anchor = newLocation.toHash(location.subMemberName); | 245 newLocation.anchor = newLocation.toHash(location.subMemberName); |
| 246 return newLocation; | 246 return newLocation; |
| 247 } | 247 } |
| 248 | 248 |
| 249 /// Replace the window location with [location] | 249 /// Replace the window location with [location] |
| 250 String _replaceLocation(DocsLocation location) { | 250 String _replaceLocation(DocsLocation location) { |
| 251 var newUri = location.withAnchor; | 251 var newUri = location.withAnchor; |
| 252 var encoded = Uri.encodeFull(newUri); | 252 var encoded = Uri.encodeFull(newUri); |
| 253 window.location.replace("#$encoded"); | 253 window.location.replace(locationPrefixed(encoded)); |
| 254 return encoded; | 254 return encoded; |
| 255 } | 255 } |
| 256 | 256 |
| 257 /// Loads the [libraryName] [Library] and [className] [Class] if necessary | 257 /// Loads the [libraryName] [Library] and [className] [Class] if necessary |
| 258 /// and updates the current page to the member described by [location] | 258 /// and updates the current page to the member described by [location] |
| 259 /// once the correct member is found and loaded. | 259 /// once the correct member is found and loaded. |
| 260 Future _loadAndUpdatePage(DocsLocation location) { | 260 Future _loadAndUpdatePage(DocsLocation location) { |
| 261 // If it's loaded, it will be in the index. | 261 // If it's loaded, it will be in the index. |
| 262 var destination = pageIndex[location.withoutAnchor]; | 262 var destination = pageIndex[location.withoutAnchor]; |
| 263 if (destination == null) { | 263 if (destination == null) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 338 |
| 339 /// Looks for the correct [Item] described by [location]. If it is found, | 339 /// Looks for the correct [Item] described by [location]. If it is found, |
| 340 /// [currentPage] is updated and state is not pushed to the history api. | 340 /// [currentPage] is updated and state is not pushed to the history api. |
| 341 /// Returns a [Future] to determine if a link was found or not. | 341 /// Returns a [Future] to determine if a link was found or not. |
| 342 /// [location] is a [String] path to the location (either a qualified name | 342 /// [location] is a [String] path to the location (either a qualified name |
| 343 /// or a url path). | 343 /// or a url path). |
| 344 Future handleLink(String uri) { | 344 Future handleLink(String uri) { |
| 345 // Links are the hash part of the URI without the leading #. | 345 // Links are the hash part of the URI without the leading #. |
| 346 // Valid forms for links are | 346 // Valid forms for links are |
| 347 // home - the global home page | 347 // home - the global home page |
| 348 // library.memberName.subMember#anchor | 348 // library.memberName.subMember@anchor |
| 349 // where #anchor is optional and library can be any of | 349 // where @anchor is optional and library can be any of |
| 350 // dart:library, library-foo, package-foo/library-bar | 350 // dart:library, library-foo, package-foo/library-bar |
| 351 // So we need an unambiguous form. | 351 // So we need an unambiguous form. |
| 352 // [package/]libraryWithDashes[.class.method]#anchor | 352 // [package/]libraryWithDashes[.class.method]@anchor |
| 353 | 353 |
| 354 // We will tolerate colons in the location instead of dashes, though | 354 // We will tolerate colons in the location instead of dashes, though |
| 355 var decoded = Uri.decodeFull(uri); | 355 var decoded = Uri.decodeFull(uri); |
| 356 var location = new DocsLocation(decoded); | 356 var location = new DocsLocation(decoded); |
| 357 | 357 |
| 358 if (location.libraryName == 'home') { | 358 if (location.libraryName == 'home') { |
| 359 _updatePage(viewer.homePage, location); | 359 _updatePage(viewer.homePage, location); |
| 360 return new Future.value(true); | 360 return new Future.value(true); |
| 361 } | 361 } |
| 362 showLoadIndicator(); | 362 showLoadIndicator(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 /// Hide the indicator that we're loading data. | 410 /// Hide the indicator that we're loading data. |
| 411 hideLoadIndicator() => loadIndicator.style.display = 'none'; | 411 hideLoadIndicator() => loadIndicator.style.display = 'none'; |
| 412 } | 412 } |
| 413 | 413 |
| 414 /// The path of this app on startup. | 414 /// The path of this app on startup. |
| 415 String _pathname; | 415 String _pathname; |
| 416 | 416 |
| 417 /// The latest url reached by a popState event. | 417 /// The latest url reached by a popState event. |
| 418 String location; | 418 String location; |
| 419 | 419 |
| 420 /// The google crawler will try to translate #! anchors into query parameters |
| 421 /// with an _escaped_fragment_ in front of them. Assume that's the only query |
| 422 /// parameter. |
| 423 const _ESCAPED_FRAGMENT = '?_escaped_fragment_='; |
| 424 |
| 425 /// From the URL, determine what location it corresponds to. We will |
| 426 /// accept hashes that start with [AJAX_LOCATION_PREFIX], |
| 427 /// [BASIC_LOCATION_PREFIX], and [_ESCAPED_FRAGMENT]. |
| 428 String findLocation() { |
| 429 var hash = window.location.hash; |
| 430 var query = window.location.search; |
| 431 if (query.startsWith(_ESCAPED_FRAGMENT)) { |
| 432 return query.substring(_ESCAPED_FRAGMENT.length, query.length); |
| 433 } else { |
| 434 return locationDeprefixed(hash); |
| 435 } |
| 436 } |
| 437 |
| 420 /// Listens for browser navigation and acts accordingly. | 438 /// Listens for browser navigation and acts accordingly. |
| 421 void startHistory() { | 439 void startHistory() { |
| 422 location = window.location.hash.replaceFirst('#', ''); | 440 location = findLocation(); |
| 423 windowLocation.changes.listen(navigate); | 441 windowLocation.changes.listen(navigate); |
| 424 } | 442 } |
| 425 | 443 |
| 426 void navigate(event) { | 444 void navigate(event) { |
| 427 // TODO(alanknight): Should we be URI encoding/decoding this? | 445 // TODO(alanknight): Should we be URI encoding/decoding this? |
| 428 var newLocation = window.location.hash.replaceFirst('#', ''); | 446 var newLocation = findLocation(); |
| 429 if (viewer.homePage != null) { | 447 if (viewer.homePage != null) { |
| 430 viewer.handleLink(newLocation); | 448 viewer.handleLink(newLocation); |
| 431 } | 449 } |
| 432 } | 450 } |
| 433 | 451 |
| 434 /// Handles browser navigation. | 452 /// Handles browser navigation. |
| 435 @initMethod _init() { | 453 @initMethod _init() { |
| 436 window.onResize.listen((event) { | 454 window.onResize.listen((event) { |
| 437 viewer.isDesktop = window.innerWidth > desktopSizeBoundary; | 455 viewer.isDesktop = window.innerWidth > desktopSizeBoundary; |
| 438 dartdocMain.collapseSearchAndOptionsIfNeeded(); | 456 dartdocMain.collapseSearchAndOptionsIfNeeded(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 461 main() => initPolymer(); | 479 main() => initPolymer(); |
| 462 | 480 |
| 463 | 481 |
| 464 final defaultSyntax = new _DefaultSyntaxWithEvents(); | 482 final defaultSyntax = new _DefaultSyntaxWithEvents(); |
| 465 | 483 |
| 466 // TODO(jmesserly): for now we disable polymer expressions | 484 // TODO(jmesserly): for now we disable polymer expressions |
| 467 class _DefaultSyntaxWithEvents extends BindingDelegate { | 485 class _DefaultSyntaxWithEvents extends BindingDelegate { |
| 468 prepareBinding(String path, name, node) => | 486 prepareBinding(String path, name, node) => |
| 469 Polymer.prepareBinding(path, name, node, super.prepareBinding); | 487 Polymer.prepareBinding(path, name, node, super.prepareBinding); |
| 470 } | 488 } |
| OLD | NEW |