Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(app): refactor the Docs App based on the MD prototype #10341

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
737 changes: 101 additions & 636 deletions docs/app/assets/css/docs.css

Large diffs are not rendered by default.

696 changes: 696 additions & 0 deletions docs/app/assets/css/docs_old.css

Large diffs are not rendered by default.

1,672 changes: 1,672 additions & 0 deletions docs/app/assets/font-awesome/css/font-awesome.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/app/assets/font-awesome/css/font-awesome.min.css

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
520 changes: 520 additions & 0 deletions docs/app/assets/font-awesome/fonts/fontawesome-webfont.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion docs/app/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

angular.module('docsApp', [
'ngMaterial',
'HeaderController',
'FooterController',
'DocsController',
'ViewUtils',
'versionsData',
'pagesData',
'navData',
Expand All @@ -9,7 +14,8 @@ angular.module('docsApp', [
'examples',
'search',
'tutorials',
'versions'
'versions',
'responsiveMenu'
])

.config(['$locationProvider', function($locationProvider) {
Expand Down
44 changes: 30 additions & 14 deletions docs/app/src/directives.js
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();
}
}
}
Copy link
Contributor

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?

Copy link
Member Author

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 😉

};
}])


.directive('code', function() {
.directive('code', ['$window', function($window) {
return {
restrict: 'E',
terminal: true,
Expand All @@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
};
}]);
20 changes: 12 additions & 8 deletions docs/app/src/docs.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
angular.module('DocsController', [])
angular.module('DocsController', ['ViewUtils'])

.controller('DocsController', [
'$scope', '$rootScope', '$location', '$window', 'openPlunkr',
'$scope', '$rootScope', '$location', '$window', 'openPlunkr', 'ViewUtils',
'NG_PAGES', 'NG_NAVIGATION', 'NG_VERSION',
function($scope, $rootScope, $location, $window, openPlunkr,
function($scope, $rootScope, $location, $window, openPlunkr, ViewUtils,
NG_PAGES, NG_NAVIGATION, NG_VERSION) {

$scope.vu = ViewUtils;

$scope.openPlunkr = openPlunkr;

$scope.docsVersion = NG_VERSION.isSnapshot ? 'snapshot' : NG_VERSION.version;

$scope.isCurrentPath = function(path) {
return this.currentPage && path && (this.currentPage.path === path);
};

$scope.navClass = function(navItem) {
return {
active: navItem.href && this.currentPage && this.currentPage.path,
Expand All @@ -25,13 +31,13 @@ angular.module('DocsController', [])
$window._gaq.push(['_trackPageview', pagePath]);
});

$scope.$watch(function docsPathWatch() {return $location.path(); }, function docsPathWatchAction(path) {
$scope.$watch(function docsPathWatch() { return $location.path(); }, function docsPathWatchAction(path) {

path = path.replace(/^\/?(.+?)(\/index)?\/?$/, '$1');

currentPage = $scope.currentPage = NG_PAGES[path];
var currentPage = $scope.currentPage = NG_PAGES[path];

if ( currentPage ) {
if (currentPage) {
$scope.partialPath = 'partials/' + path + '.html';
$scope.currentArea = NG_NAVIGATION[currentPage.area];
var pathParts = currentPage.path.split('/');
Expand All @@ -53,8 +59,6 @@ angular.module('DocsController', [])
Initialize
***********************************/

$scope.versionNumber = angular.version.full;
$scope.version = angular.version.full + " " + angular.version.codeName;
$scope.loading = 0;


Expand Down
14 changes: 7 additions & 7 deletions docs/app/src/errors.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
angular.module('errors', ['ngSanitize'])

.filter('errorLink', ['$sanitize', function ($sanitize) {
.filter('errorLink', ['$sanitize', function($sanitize) {
var LINKY_URL_REGEXP = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}<>]/g,
MAILTO_REGEXP = /^mailto:/,
STACK_TRACE_REGEXP = /:\d+:\d+$/;

var truncate = function (text, nchars) {
var truncate = function(text, nchars) {
if (text.length > nchars) {
return text.substr(0, nchars - 3) + '...';
}
return text;
};

return function (text, target) {
return function(text, target) {
var targetHtml = target ? ' target="' + target + '"' : '';

if (!text) return text;

return $sanitize(text.replace(LINKY_URL_REGEXP, function (url) {
return $sanitize(text.replace(LINKY_URL_REGEXP, function(url) {
if (STACK_TRACE_REGEXP.test(url)) {
return url;
}
Expand Down Expand Up @@ -48,10 +48,10 @@ angular.module('errors', ['ngSanitize'])
};

return {
link: function (scope, element, attrs) {
link: function(scope, element, attrs) {
var search = $location.search(),
formatArgs = [attrs.errorDisplay],
i;
formatArgs = [attrs.errorDisplay],
i;

for (i = 0; angular.isDefined(search['p'+i]); i++) {
formatArgs.push(search['p'+i]);
Expand Down
4 changes: 2 additions & 2 deletions docs/app/src/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('examples', [])

.factory('formPostData', ['$document', function($document) {
return function(url, fields) {
/**
/*
* Form previously posted to target="_blank", but pop-up blockers were causing this to not work.
* If a user chose to bypass pop-up blocker one time and click the link, they would arrive at
* a new default plnkr, not a plnkr with the desired template.
Expand Down Expand Up @@ -48,7 +48,7 @@ angular.module('examples', [])
// The manifests provide the production index file but Plunkr wants
// a straight index.html
if (filename === "index-production.html") {
filename = "index.html"
filename = "index.html";
}

return {
Expand Down
9 changes: 9 additions & 0 deletions docs/app/src/footer-conroller.js
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 FooterController to the global namespace.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it this way adds FooterController to the global namespace.

easy way around that: wrap docs.js in an IIFE (as is done in angular.js)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we were to wrap everything in a immediately called anonymous function it doesn't provide much benefit IMO.

It's easier to read and prevent from being broken

Copy link
Member Author

Choose a reason for hiding this comment

The 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.
(I think I heard somewhere that @btford is working with @johnpapa on a style-guide for Angular, so I figured this must be mainstream :). Could it be on an ng-conf video. Or I might be remembering totally wrong; can't really recall.)

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed line 5 :)

35 changes: 35 additions & 0 deletions docs/app/src/header-conroller.js
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'},
];
}
55 changes: 55 additions & 0 deletions docs/app/src/responsive-menu.js
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');
}
Loading