Skip to content

Commit 816cf56

Browse files
committed
Tweak HTML version of docs with scroll to lints
Uses good old DOM events and wibbly-wobbly timeouts to wait for angular to render this huge list of lints. Fixes rust-lang#1181
1 parent b2aaa2a commit 816cf56

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

util/gh-pages/index.html

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ <h2 class="panel-title">
7777
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
7878
<span ng-if="lint.level == 'Deprecated'" class="label label-default">Deprecated</span>
7979

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

84-
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
84+
<ul class="list-group lint-docs" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
8585
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
8686
<h4 class="list-group-item-heading">
8787
{{title}}
@@ -120,6 +120,12 @@ <h4 class="list-group-item-heading">
120120
}
121121
});
122122

123+
function scrollToLint(lintId) {
124+
var target = document.getElementById(lintId);
125+
if (!target) { return; }
126+
document.body.scrollTop = target.offsetTop;
127+
}
128+
123129
angular.module("clippy", [])
124130
.filter('markdown', function ($sce) {
125131
return function (text) {
@@ -130,9 +136,10 @@ <h4 class="list-group-item-heading">
130136
);
131137
};
132138
})
133-
.controller("lintList", function ($scope, $http) {
139+
.controller("lintList", function ($scope, $http, $timeout) {
134140
// Level filter
135-
$scope.levels = {Allow: true, Warn: true, Deny: true, Deprecated: true};
141+
var LEVEL_FILTERS_DEFAULT = {Allow: true, Warn: true, Deny: true, Deprecated: true};
142+
$scope.levels = LEVEL_FILTERS_DEFAULT;
136143
$scope.byLevels = function (lint) {
137144
return $scope.levels[lint.level];
138145
};
@@ -141,16 +148,37 @@ <h4 class="list-group-item-heading">
141148
$scope.open = {};
142149
$scope.loading = true;
143150

151+
if (window.location.hash.length > 1) {
152+
$scope.open[window.location.hash.slice(1)] = true;
153+
}
154+
144155
$http.get('./lints.json')
145156
.success(function (data) {
146157
$scope.data = data;
147158
$scope.loading = false;
159+
160+
$timeout(function () {
161+
scrollToLint(window.location.hash.slice(1));
162+
}, 100);
148163
})
149164
.error(function (data) {
150165
$scope.error = data;
151166
$scope.loading = false;
152167
});
153-
})
168+
169+
window.addEventListener('hashchange', function () {
170+
// trigger re-render
171+
$timeout(function () {
172+
$scope.search = "";
173+
$scope.levels = LEVEL_FILTERS_DEFAULT;
174+
// quick n dirty: wait for re-render to finish
175+
$timeout(function () {
176+
scrollToLint(window.location.hash.slice(1));
177+
}, 100);
178+
});
179+
return true;
180+
}, false);
181+
});
154182
})();
155183
</script>
156184
</body>

0 commit comments

Comments
 (0)