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:
Pascal Hertleif 2016-08-28 17:04:54 +02:00
parent b2aaa2a51c
commit 816cf56b89

View File

@ -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">&para;</a>
<a href="#{{lint.id}}" class="anchor label label-default" ng-click="open[lint.id] = true; $event.stopPropagation()">&para;</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>