Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and bug fixes for side navigation #1034

Merged
merged 7 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/app/css/styleguide-app.css
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ Styleguide 3.1.1
display: inline-block;
width: 30%;
opacity: 1;
height: 500px;
overflow-y: scroll;
@media (--mobile) {
width: 100%;
padding-top: 30px;
Expand Down
2 changes: 1 addition & 1 deletion lib/app/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" ng-app="sgApp">
<html lang="en" ng-app="sgApp" route-css-class>
<head>
<meta charset="UTF-8">
<link rel="icon" href="{{{appRoot}}}/assets/img/favicon.ico">
Expand Down
6 changes: 6 additions & 0 deletions lib/app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ angular.module('sgApp', deps)
url: '/section/:section',
templateUrl: 'views/sections.html',
controller: 'SectionsCtrl',
viewClass: 'view-section',
resolve: {
loadLazyModule: function($$animateJs, $ocLazyLoad) {
return loadModule($$animateJs, $ocLazyLoad);
Expand All @@ -59,6 +60,7 @@ angular.module('sgApp', deps)
.state('app.index.overview', {
url: '/',
templateUrl: 'overview.html',
viewClass: 'view-overview',
controller: function($rootScope, Styleguide) {
$rootScope.currentSection = 'overview';
// Update current reference to update the designer tool view
Expand Down Expand Up @@ -131,6 +133,10 @@ angular.module('sgApp', deps)
}
};

$rootScope.$on('$stateChangeSuccess',function(event, toState){
$rootScope.viewClass = toState.viewClass;
});

// Create global throttled scorll
function broadcastScrollEvent(event) {
$rootScope.$broadcast('scroll', event);
Expand Down
5 changes: 0 additions & 5 deletions lib/app/js/controllers/appCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ angular.module('sgApp')
ngProgress.setHeight('');
ngProgress.setColor('');

// Scroll top when page is changed
$scope.$on('$viewContentLoaded', function() {
window.scrollTo(0, 0);
});

$scope.$on('progress start', function() {
ngProgress.start();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/app/js/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('sgApp')
};

$scope.isSideNav = function() {
if($scope.config.data && $scope.config.data.sideNav) {
if ($scope.config.data && $scope.config.data.sideNav) {
return 'sideNav';
} else if ($scope.config.data && !$scope.config.data.sideNav) {
return 'topNav';
Expand Down
28 changes: 28 additions & 0 deletions lib/app/js/directives/rootCssClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

angular.module('sgApp')
.directive('routeCssClass', function($rootScope) {
return {
restrict: 'A',
scope: {},
link: function (scope, elem) {
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
var fromClassnames = angular.isDefined(fromState.viewClass) && angular.isDefined(fromState.viewClass) ? fromState.viewClass : null;
var toClassnames = angular.isDefined(toState.viewClass) && angular.isDefined(toState.viewClass) ? toState.viewClass : null;

fromClassnames = 'root-' + fromClassnames;
toClassnames = 'root-' + toClassnames;
// don't do anything if they are the same
if (fromClassnames !== toClassnames) {
if (fromClassnames) {
elem.removeClass(fromClassnames);
}

if (toClassnames) {
elem.addClass(toClassnames);
}
}
});
}
};
});
3 changes: 2 additions & 1 deletion lib/app/views/main.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="{{viewClass}}">
<div id="socketDisconnection" class="sg disconnection-icon" title="no socket connection" ng-hide="socketService.isConnected()" ng-if="socketService.isAvailable()">
<i class="fa fa-chain-broken"></i>
</div>
Expand Down Expand Up @@ -118,7 +119,7 @@ <h1 ng-if="status.hasError">Error: {{status.error.name}}</h1>
</div>

<div sg-design></div>

</div>
<footer class="sg sg-footer">
<div class="sg sg-content">
<p>
Expand Down
3 changes: 2 additions & 1 deletion lib/app/views/sections.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
</a>
</li>
</ul>
</div>
</div>
<section class="sg sg-after-sections" ng-bind-html="config.data.afterSections | unsafe"></section>
1 change: 1 addition & 0 deletions lib/modules/cli/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function(argLib) {
.describe('extraHead', 'These HTML elements are injected inside the style guide head-tag')
.describe('beforeBody', 'These HTML elements are injected inside the style guide body tag, before any other content')
.describe('afterBody', 'These HTML elements are injected inside the style guide body tag, after any other content')
.describe('afterSections', 'These HTML elements are injected after the sections, after all the section content')
.describe('sideNav', 'This bool use to switch navigation to side nav')
.describe('commonClass', 'The provided classes are added to all preview blocks in the generated style guide')
.describe('appRoot', 'Define the appRoot parameter if you are hosting the style guide from a directory other than the root directory of the HTTP server')
Expand Down
1 change: 1 addition & 0 deletions lib/modules/cli/styleguide-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function(argv) {
extraHead: argv.extraHead,
beforeBody: argv.beforeBody,
afterBody: argv.afterBody,
afterSections: argv.afterSections,
sideNav: argv.sideNav,
commonClass: argv.commonClass,
appRoot: argv.appRoot,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function sanitizeOptions(opt) {
extraHead: (typeof opt.extraHead === 'object') ? opt.extraHead.join('\n') : opt.extraHead,
beforeBody: (typeof opt.beforeBody === 'object') ? opt.beforeBody.join('\n') : opt.beforeBody,
afterBody: (typeof opt.afterBody === 'object') ? opt.afterBody.join('\n') : opt.afterBody,
afterSections: (typeof opt.afterSections === 'object') ? opt.afterSections.join('\n') : opt.afterSections,
additionalNgDependencies: opt.additionalNgDependencies || false,
sideNav: opt.sideNav || false,
disableEncapsulation: opt.disableEncapsulation || false,
Expand Down
6 changes: 3 additions & 3 deletions lib/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function replaceSectionReferences(json) {
}

function copyUsedOptionsToJsonConfig(opt, json) {
var used = ['appRoot', 'extraHead', 'beforeBody', 'afterBody', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly', 'sideNav', 'additionalNgDependencies'];
var used = ['appRoot', 'extraHead', 'beforeBody', 'afterBody', 'commonClass', 'title', 'disableEncapsulation', 'disableHtml5Mode', 'readOnly', 'sideNav', 'afterSections', 'additionalNgDependencies'];
json.config = {};
used.forEach(function(prop) {
json.config[prop] = _.cloneDeep(opt[prop]);
Expand All @@ -158,7 +158,7 @@ function copyUsedOptionsToJsonConfig(opt, json) {
}

function copyUsedOptionsToInlineJsonConfig(opt, json) {
var used = ['title', 'disableEncapsulation', 'disableHtml5Mode', 'sideNav', 'additionalNgDependencies'];
var used = ['title', 'disableEncapsulation', 'disableHtml5Mode', 'sideNav', 'afterSections', 'additionalNgDependencies'];
json.config = {};
used.forEach(function(prop) {
json.config[prop] = _.cloneDeep(opt[prop]);
Expand Down Expand Up @@ -329,7 +329,6 @@ module.exports.generate = function(options) {
indexHtmlProcessed;

overviewProcessed = processOverviewMarkdown(opt);

var cssSrc = [distPath + '/css/styleguide-app.css', distPath + '/css/styleguide_helper_elements.css'];

// Copy all files (except index.html) from dist from to output stream
Expand Down Expand Up @@ -389,6 +388,7 @@ module.exports.generate = function(options) {
title: opt.title,
extraHead: opt.extraHead,
beforeBody: opt.beforeBody,
afterSections: opt.afterSections,
afterBody: opt.afterBody,
sideNav: opt.sideNav,
styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config),
Expand Down