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 String findLocation() { | |
Emily Fortuna
2014/02/04 01:47:51
add a comment to this function and add a newline
Alan Knight
2014/02/04 18:08:14
Done.
| |
425 var hash = window.location.hash; | |
426 var query = window.location.search; | |
427 if (query.startsWith(_ESCAPED_FRAGMENT)) { | |
428 return query.substring(_ESCAPED_FRAGMENT.length, query.length); | |
429 } else { | |
430 return locationDeprefixed(hash); | |
431 } | |
432 } | |
433 | |
420 /// Listens for browser navigation and acts accordingly. | 434 /// Listens for browser navigation and acts accordingly. |
421 void startHistory() { | 435 void startHistory() { |
422 location = window.location.hash.replaceFirst('#', ''); | 436 location = findLocation(); |
423 windowLocation.changes.listen(navigate); | 437 windowLocation.changes.listen(navigate); |
424 } | 438 } |
425 | 439 |
426 void navigate(event) { | 440 void navigate(event) { |
427 // TODO(alanknight): Should we be URI encoding/decoding this? | 441 // TODO(alanknight): Should we be URI encoding/decoding this? |
428 var newLocation = window.location.hash.replaceFirst('#', ''); | 442 var newLocation = findLocation(); |
429 if (viewer.homePage != null) { | 443 if (viewer.homePage != null) { |
430 viewer.handleLink(newLocation); | 444 viewer.handleLink(newLocation); |
431 } | 445 } |
432 } | 446 } |
433 | 447 |
434 /// Handles browser navigation. | 448 /// Handles browser navigation. |
435 @initMethod _init() { | 449 @initMethod _init() { |
436 window.onResize.listen((event) { | 450 window.onResize.listen((event) { |
437 viewer.isDesktop = window.innerWidth > desktopSizeBoundary; | 451 viewer.isDesktop = window.innerWidth > desktopSizeBoundary; |
438 dartdocMain.collapseSearchAndOptionsIfNeeded(); | 452 dartdocMain.collapseSearchAndOptionsIfNeeded(); |
(...skipping 22 matching lines...) Expand all Loading... | |
461 main() => initPolymer(); | 475 main() => initPolymer(); |
462 | 476 |
463 | 477 |
464 final defaultSyntax = new _DefaultSyntaxWithEvents(); | 478 final defaultSyntax = new _DefaultSyntaxWithEvents(); |
465 | 479 |
466 // TODO(jmesserly): for now we disable polymer expressions | 480 // TODO(jmesserly): for now we disable polymer expressions |
467 class _DefaultSyntaxWithEvents extends BindingDelegate { | 481 class _DefaultSyntaxWithEvents extends BindingDelegate { |
468 prepareBinding(String path, name, node) => | 482 prepareBinding(String path, name, node) => |
469 Polymer.prepareBinding(path, name, node, super.prepareBinding); | 483 Polymer.prepareBinding(path, name, node, super.prepareBinding); |
470 } | 484 } |
OLD | NEW |