Skip to content

Commit 5b162a3

Browse files
committed
Merge pull request #788 from hannu/recursive-examples
Possibility to include all section elements in fullscreen mode
2 parents a1be4f7 + 0b1ebcd commit 5b162a3

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

lib/app/js/controllers/element.js

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('sgApp')
2-
.controller('ElementCtrl', function($scope, $rootScope, $stateParams, $state, Styleguide, Variables, $filter) {
2+
.controller('ElementCtrl', function($scope, $rootScope, $stateParams, $state, Styleguide, Variables, $filter, $location) {
33

44
var section = $stateParams.section.split('-'),
55
reference = section[0],
@@ -70,16 +70,30 @@ angular.module('sgApp')
7070
}
7171
}
7272

73+
function getSectionMarkup(section) {
74+
return $filter('setVariables')($filter('setModifierClass')(section.renderMarkup, section.className), $scope.variables);
75+
}
76+
7377
function updatePageData() {
74-
var sections, result, element, modifierStr;
78+
var recursive = $location.search().recursive,
79+
separator = '<br>',
80+
sections, result, element, markup, modifierStr;
81+
7582
if (!Styleguide.sections.data) {
7683
return;
7784
}
7885
sections = Styleguide.sections.data;
7986

8087
// Find correct element definition from styleguide data
81-
result = sections.filter(function(item) {
82-
return reference === item.reference;
88+
result = sections.filter(function(section) {
89+
if (reference === 'all') {
90+
return true;
91+
}
92+
if (recursive) {
93+
return new RegExp('^' + reference + '(\\D|$)').test(section.reference);
94+
} else {
95+
return reference === section.reference;
96+
}
8397
});
8498

8599
if (result.length > 0) {
@@ -91,17 +105,35 @@ angular.module('sgApp')
91105
$rootScope.pageTitle = element.reference + modifierStr + ' ' + element.header + ' - ' + Styleguide.config.data.title;
92106
}
93107

94-
// Select correct modifier element if one is defined
95-
if (modifier) {
96-
element = element.modifiers[modifier - 1];
97-
}
98-
99108
// Set the actual page content
100109
$scope.previousSection = previousSection(sections, result);
101110
$scope.nextSection = nextSection(sections, result);
102-
$scope.section = element;
103111
$scope.variables = Variables.variables;
104-
$scope.markup = $filter('setVariables')($filter('setModifierClass')(element.renderMarkup, element.className), $scope.variables);
112+
113+
// Collect every component markup when using recursive mode
114+
if (recursive) {
115+
markup = '';
116+
angular.forEach(result, function(section) {
117+
if (section.modifiers && section.modifiers.length > 0) {
118+
// If section contains modifier, render every modifier
119+
angular.forEach(section.modifiers, function(modifier) {
120+
markup += getSectionMarkup(modifier) + separator;
121+
});
122+
} else {
123+
// Otherwise just render the element
124+
markup += getSectionMarkup(section) + separator;
125+
}
126+
});
127+
} else {
128+
// Select correct modifier element if one is defined
129+
if (modifier) {
130+
element = element.modifiers[modifier - 1];
131+
}
132+
markup = getSectionMarkup(element);
133+
}
134+
135+
$scope.section = element;
136+
$scope.markup = markup;
105137
}
106138
}
107139
});

0 commit comments

Comments
 (0)