mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-20 03:32:52 +00:00
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 #1181
This commit is contained in:
parent
b2aaa2a51c
commit
816cf56b89
@ -77,11 +77,11 @@
|
||||
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
|
||||
<span ng-if="lint.level == 'Deprecated'" class="label label-default">Deprecated</span>
|
||||
|
||||
<a href="#{{lint.id}}" class="anchor label label-default">¶</a>
|
||||
<a href="#{{lint.id}}" class="anchor label label-default" ng-click="open[lint.id] = true; $event.stopPropagation()">¶</a>
|
||||
</h2>
|
||||
</header>
|
||||
|
||||
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
|
||||
<ul class="list-group lint-docs" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
|
||||
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
|
||||
<h4 class="list-group-item-heading">
|
||||
{{title}}
|
||||
@ -120,6 +120,12 @@
|
||||
}
|
||||
});
|
||||
|
||||
function scrollToLint(lintId) {
|
||||
var target = document.getElementById(lintId);
|
||||
if (!target) { return; }
|
||||
document.body.scrollTop = target.offsetTop;
|
||||
}
|
||||
|
||||
angular.module("clippy", [])
|
||||
.filter('markdown', function ($sce) {
|
||||
return function (text) {
|
||||
@ -130,9 +136,10 @@
|
||||
);
|
||||
};
|
||||
})
|
||||
.controller("lintList", function ($scope, $http) {
|
||||
.controller("lintList", function ($scope, $http, $timeout) {
|
||||
// Level filter
|
||||
$scope.levels = {Allow: true, Warn: true, Deny: true, Deprecated: true};
|
||||
var LEVEL_FILTERS_DEFAULT = {Allow: true, Warn: true, Deny: true, Deprecated: true};
|
||||
$scope.levels = LEVEL_FILTERS_DEFAULT;
|
||||
$scope.byLevels = function (lint) {
|
||||
return $scope.levels[lint.level];
|
||||
};
|
||||
@ -141,16 +148,37 @@
|
||||
$scope.open = {};
|
||||
$scope.loading = true;
|
||||
|
||||
if (window.location.hash.length > 1) {
|
||||
$scope.open[window.location.hash.slice(1)] = true;
|
||||
}
|
||||
|
||||
$http.get('./lints.json')
|
||||
.success(function (data) {
|
||||
$scope.data = data;
|
||||
$scope.loading = false;
|
||||
|
||||
$timeout(function () {
|
||||
scrollToLint(window.location.hash.slice(1));
|
||||
}, 100);
|
||||
})
|
||||
.error(function (data) {
|
||||
$scope.error = data;
|
||||
$scope.loading = false;
|
||||
});
|
||||
})
|
||||
|
||||
window.addEventListener('hashchange', function () {
|
||||
// trigger re-render
|
||||
$timeout(function () {
|
||||
$scope.search = "";
|
||||
$scope.levels = LEVEL_FILTERS_DEFAULT;
|
||||
// quick n dirty: wait for re-render to finish
|
||||
$timeout(function () {
|
||||
scrollToLint(window.location.hash.slice(1));
|
||||
}, 100);
|
||||
});
|
||||
return true;
|
||||
}, false);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user