-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(app): refactor the Docs App based on the MD prototype #10341
Changes from all commits
e674142
3904cd5
7a51d5d
caed914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
angular.module('directives', []) | ||
|
||
/** | ||
* backToTop Directive | ||
* @param {Function} $anchorScroll | ||
* scrollTo Directive | ||
* | ||
* @description Ensure that the browser scrolls when the anchor is clicked | ||
* @description | ||
* Upon click, scroll to the target element (identified by the selector provided via the `scroll-to` | ||
* attribute). | ||
*/ | ||
.directive('backToTop', ['$anchorScroll', '$location', function($anchorScroll, $location) { | ||
return function link(scope, element) { | ||
element.on('click', function(event) { | ||
$location.hash(''); | ||
scope.$apply($anchorScroll); | ||
}); | ||
.directive('scrollTo', ['$document', '$location', function($document, $location) { | ||
var doc = $document[0]; | ||
|
||
return { | ||
restrict: 'A', | ||
link: function scrollToPostLink(scope, elem, attrs) { | ||
elem.on('click', onClick); | ||
|
||
function onClick() { | ||
var targetSelector = attrs.scrollTo; | ||
var targetElem = doc.querySelector(targetSelector); | ||
|
||
if (targetElem) { | ||
targetElem.scrollIntoView(); | ||
} | ||
} | ||
} | ||
}; | ||
}]) | ||
|
||
|
||
.directive('code', function() { | ||
.directive('code', ['$window', function($window) { | ||
return { | ||
restrict: 'E', | ||
terminal: true, | ||
|
@@ -25,13 +37,17 @@ angular.module('directives', []) | |
var match = /lang-(\S+)/.exec(element[0].className); | ||
var lang = match && match[1]; | ||
var html = element.html(); | ||
element.html(window.prettyPrintOne(html, lang, linenums)); | ||
element.html($window.prettyPrintOne(html, lang, linenums)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
} | ||
}; | ||
}) | ||
}]) | ||
|
||
|
||
// TODO: Probably not needed any more | ||
.directive('scrollYOffsetElement', ['$anchorScroll', function($anchorScroll) { | ||
return function(scope, element) { | ||
$anchorScroll.yOffset = element; | ||
return { | ||
link: function(scope, element) { | ||
$anchorScroll.yOffset = element; | ||
} | ||
}; | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
angular. | ||
module('FooterController', []). | ||
controller('FooterController', FooterController); | ||
|
||
function FooterController() { | ||
var v = angular.version; | ||
this.versionNumber = v.full; | ||
this.version = v.full + ' ' + v.codeName; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why declare the controller function this way rather than an inline function? Doing it this way adds Even if we were to wrap everything in a immediately called anonymous function it doesn't provide much benefit IMO. Is it to emulate where we are going with Angular V2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
easy way around that: wrap docs.js in an IIFE (as is done in angular.js) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's easier to read and prevent from being broken There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm...no IIFE ? Really ? 😃 I usually wrapped each module in an IIFE and try not to use inline functions for the reasons mentioned by @caitp. I do the same thing with functions inside controllers/services etc: I have the public "API" declared at the top and then have functions defined below. Basically, I am trying to follow johnpapa's style guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for johnpapa's style guide. We usually wrap all our modules in an IIFE. I'm not sure if line 5 is needed since it isn't actually injecting anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed line 5 :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
angular. | ||
module('HeaderController', []). | ||
controller('HeaderController', HeaderController); | ||
|
||
HeaderController.$inject = []; | ||
function HeaderController() { | ||
this.learnItems = [ | ||
{label: 'Why AngularJS?', url: '//angularjs.org/'}, | ||
{label: 'Watch', url: '//www.youtube.com/user/angularjs'}, | ||
{label: 'Tutorial', url: 'tutorial'}, | ||
{label: 'Case Studies', url: '//builtwith.angularjs.org/'}, | ||
{label: 'Seed App project template', url: '//github.com/angular/angular-seed'}, | ||
{label: 'FAQ', url: 'misc/faq'} | ||
]; | ||
|
||
this.developItems = [ | ||
{label: 'Why AngularJS?', url: '//angularjs.org/'}, | ||
{label: 'Tutorial', url: 'tutorial'}, | ||
{label: 'Developer Guide', url: 'guide'}, | ||
{label: 'API Reference', url: 'api'}, | ||
{label: 'Error Reference', url: 'error'}, | ||
{label: 'Contribute', url: 'misc/contribute'}, | ||
{label: 'Download', url: '//code.angularjs.org/'} | ||
]; | ||
|
||
this.discussItems = [ | ||
{label: 'Blog', url: '//blog.angularjs.org'}, | ||
{label: 'Mailing List', url: '//groups.google.com/group/angular'}, | ||
{label: 'Chat Room', url: '//webchat.freenode.net/?channels=angularjs&uio=d4'}, | ||
{label: 'Twitter', url: '//twitter.com/#!/angularjs'}, | ||
{label: 'Google+', url: '//plus.google.com/110323587230527980117'}, | ||
{label: 'GitHub', url: '//github.com/angular/angular.js'}, | ||
{label: 'Issue Tracker', url: '//github.com/angular/angular.js/issues'}, | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
angular. | ||
module('responsiveMenu', ['ngMaterial', 'ViewUtils']). | ||
directive('responsiveMenu', responsiveMenuDirective); | ||
|
||
responsiveMenuDirective.$inject = ['$mdBottomSheet', 'ViewUtils']; | ||
function responsiveMenuDirective($mdBottomSheet, ViewUtils) { | ||
// TODO: Create showFns for various sizes (not necessarily all) | ||
var showFns = { | ||
// 'gt-lg': '', | ||
// 'lg': '', | ||
// 'md': '', | ||
'sm': function showSmFn(items) { | ||
$mdBottomSheet.show({ | ||
template: _getResponsiveMenuSmTemplate(), | ||
controller: ['$mdBottomSheet', '$scope', | ||
function ResponsiveMenuSmController($mdBottomSheet, $scope) { | ||
$scope.items = items; | ||
$scope.onItemClick = $mdBottomSheet.hide.bind($mdBottomSheet); | ||
} | ||
] | ||
}); | ||
} | ||
}; | ||
|
||
var defaultShowFn = showFns.sm; | ||
|
||
return { | ||
restrict: 'A', | ||
scope: { | ||
items: '=rmItems' | ||
}, | ||
controller: ['$element', '$scope', function ResponsiveMenuController($element, $scope) { | ||
$element.on('click', onClick.bind(this)); | ||
|
||
function onClick(evt) { | ||
var showFn = ViewUtils.getValueForSize(showFns, defaultShowFn); | ||
showFn($scope.items); | ||
} | ||
}] | ||
}; | ||
} | ||
|
||
function _getResponsiveMenuSmTemplate() { | ||
return [ | ||
'<md-bottom-sheet>', | ||
' <md-list>', | ||
' <md-item ng-repeat="item in items">', | ||
' <md-button aria-label="{{item.label}}" ng-click="onItemClick(item)">', | ||
' <a ng-href="{{item.url}}">{{item.label}}</a>', | ||
' </md-button>', | ||
' </md-item>', | ||
' </md-list>', | ||
'</md-bottom-sheet>', | ||
''].join('\n'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not using
$anchorScroll
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because scrolling does not happen on the window level (but a nested element), we don't want to scroll to top. Thus we need to tell
$anchorScroll
which element we want it to scroll to and the only way is to set$location.hash
to its ID (e.g.top-anchor
). And that wouldn't look nice imo.BTW, I think there is an awesome PR that adds support for providing an explicit hash to
$anchorScroll
, in case we don't want it to scroll to$location.hash()
.There it is: #9596 😉