Skip to content

Commit b38a86a

Browse files
authored
Merge pull request #1200 from killercup/feature/gh-pages-fixes
Tweak HTML version of docs with scroll to lints
2 parents c54457c + 3e2bb3f commit b38a86a

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

util/gh-pages/index.html

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ <h1>ALL the Clippy Lints</h1>
6262
</div>
6363
</div>
6464

65-
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id">
65+
<article class="panel panel-default" id="{{lint.id}}"
66+
ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id" on-finish-render="ngRepeatFinished">
6667
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
6768
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
6869
<span ng-show="open[lint.id]">&minus;</span>
@@ -77,11 +78,11 @@ <h2 class="panel-title">
7778
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
7879
<span ng-if="lint.level == 'Deprecated'" class="label label-default">Deprecated</span>
7980

80-
<a href="#{{lint.id}}" class="anchor label label-default">&para;</a>
81+
<a href="#{{lint.id}}" class="anchor label label-default" ng-click="open[lint.id] = true; $event.stopPropagation()">&para;</a>
8182
</h2>
8283
</header>
8384

84-
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
85+
<ul class="list-group lint-docs" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
8586
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
8687
<h4 class="list-group-item-heading">
8788
{{title}}
@@ -96,7 +97,7 @@ <h4 class="list-group-item-heading">
9697
<a href="https://github.com/Manishearth/rust-clippy">
9798
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
9899
</a>
99-
100+
100101
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/7.0.0/markdown-it.min.js"></script>
101102
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
102103
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js"></script>
@@ -120,6 +121,21 @@ <h4 class="list-group-item-heading">
120121
}
121122
});
122123

124+
function scrollToLint(lintId) {
125+
var target = document.getElementById(lintId);
126+
if (!target) {
127+
return;
128+
}
129+
target.scrollIntoView();
130+
}
131+
132+
function scrollToLintByURL($scope) {
133+
var removeListener = $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
134+
scrollToLint(window.location.hash.slice(1));
135+
removeListener();
136+
});
137+
}
138+
123139
angular.module("clippy", [])
124140
.filter('markdown', function ($sce) {
125141
return function (text) {
@@ -130,9 +146,22 @@ <h4 class="list-group-item-heading">
130146
);
131147
};
132148
})
133-
.controller("lintList", function ($scope, $http) {
149+
.directive('onFinishRender', function ($timeout) {
150+
return {
151+
restrict: 'A',
152+
link: function (scope, element, attr) {
153+
if (scope.$last === true) {
154+
$timeout(function () {
155+
scope.$emit(attr.onFinishRender);
156+
});
157+
}
158+
}
159+
};
160+
})
161+
.controller("lintList", function ($scope, $http, $timeout) {
134162
// Level filter
135-
$scope.levels = {Allow: true, Warn: true, Deny: true, Deprecated: true};
163+
var LEVEL_FILTERS_DEFAULT = {Allow: true, Warn: true, Deny: true, Deprecated: true};
164+
$scope.levels = LEVEL_FILTERS_DEFAULT;
136165
$scope.byLevels = function (lint) {
137166
return $scope.levels[lint.level];
138167
};
@@ -141,17 +170,37 @@ <h4 class="list-group-item-heading">
141170
$scope.open = {};
142171
$scope.loading = true;
143172

173+
if (window.location.hash.length > 1) {
174+
$scope.search = window.location.hash.slice(1);
175+
$scope.open[window.location.hash.slice(1)] = true;
176+
scrollToLintByURL($scope);
177+
}
178+
144179
$http.get('./lints.json')
145180
.success(function (data) {
146181
$scope.data = data;
147182
$scope.loading = false;
183+
184+
scrollToLintByURL($scope);
148185
})
149186
.error(function (data) {
150187
$scope.error = data;
151188
$scope.loading = false;
152189
});
153-
})
190+
191+
window.addEventListener('hashchange', function () {
192+
// trigger re-render
193+
$timeout(function () {
194+
$scope.levels = LEVEL_FILTERS_DEFAULT;
195+
$scope.search = window.location.hash.slice(1);
196+
$scope.open[window.location.hash.slice(1)] = true;
197+
198+
scrollToLintByURL($scope);
199+
});
200+
return true;
201+
}, false);
202+
});
154203
})();
155204
</script>
156205
</body>
157-
</html>
206+
</html>

0 commit comments

Comments
 (0)