Merge pull request #1200 from killercup/feature/gh-pages-fixes

Tweak HTML version of docs with scroll to lints
This commit is contained in:
Martin Carton 2016-08-29 14:19:08 +02:00 committed by GitHub
commit b38a86a145

View File

@ -62,7 +62,8 @@
</div>
</div>
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id">
<article class="panel panel-default" id="{{lint.id}}"
ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id" on-finish-render="ngRepeatFinished">
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
<span ng-show="open[lint.id]">&minus;</span>
@ -77,11 +78,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}}
@ -96,7 +97,7 @@
<a href="https://github.com/Manishearth/rust-clippy">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/7.0.0/markdown-it.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js"></script>
@ -120,6 +121,21 @@
}
});
function scrollToLint(lintId) {
var target = document.getElementById(lintId);
if (!target) {
return;
}
target.scrollIntoView();
}
function scrollToLintByURL($scope) {
var removeListener = $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
scrollToLint(window.location.hash.slice(1));
removeListener();
});
}
angular.module("clippy", [])
.filter('markdown', function ($sce) {
return function (text) {
@ -130,9 +146,22 @@
);
};
})
.controller("lintList", function ($scope, $http) {
.directive('onFinishRender', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function () {
scope.$emit(attr.onFinishRender);
});
}
}
};
})
.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,17 +170,37 @@
$scope.open = {};
$scope.loading = true;
if (window.location.hash.length > 1) {
$scope.search = window.location.hash.slice(1);
$scope.open[window.location.hash.slice(1)] = true;
scrollToLintByURL($scope);
}
$http.get('./lints.json')
.success(function (data) {
$scope.data = data;
$scope.loading = false;
scrollToLintByURL($scope);
})
.error(function (data) {
$scope.error = data;
$scope.loading = false;
});
})
window.addEventListener('hashchange', function () {
// trigger re-render
$timeout(function () {
$scope.levels = LEVEL_FILTERS_DEFAULT;
$scope.search = window.location.hash.slice(1);
$scope.open[window.location.hash.slice(1)] = true;
scrollToLintByURL($scope);
});
return true;
}, false);
});
})();
</script>
</body>
</html>
</html>