PageSourceSearch

https://angular-translate.github.io/docs/plato/assets/scripts/plato-sortable-file-list.js

js angular-translate.github.io collected 2026-10-03 08:37:44 UTC 2,978 bytes, 125 lines download raw bytes

1/* global $:false, _:false */
2/* jshint browser:true */
3
4/*
5  author: david linse <[email protected]>
6  version: 0.0.1
7
8  A very first draft to add the ability to sort
9  the "file-list" by the displayed 'numbers' for:
10
11   + lint-errors
12   + complexity
13   + lines of code
14   + estimated errors
15
16  A group of buttons is added to the template above
17  to trigger the update of the file-list.
18*/
19
20$(function sortable_file_list () {
21
22  "use strict";
23
24    var file_list = $('ul.file-list');
25
26    var files = file_list.find('li');
27
28    // work-horse
29    // @param:  key  The 'data-<key>' to sort by
30    // @return: descending sorted array of <li> elements
31    //
32    var _sortBy = function (key) {
33        return _.sortBy(files, function (el) {
34            return Number($(el).find('span[data-lint]').attr(key)) * -1;
35        });
36    };
37
38    // sorter
39
40    var _sortByLintErr = function _sortByLintErr () {
41        return _sortBy('data-lint');
42    };
43
44    var _sortBySLOC = function _sortBySLOC () {
45        return _sortBy('data-sloc');
46    };
47
48    var _sortByBugs = function _sortByBugs () {
49        return _sortBy('data-bugs');
50    };
51
52    var _sortByComplexity = function _sortByComplexity () {
53        return _sortBy('data-complexity');
54    };
55
56    // appends the 'list' of '<li>' elements
57    // to its parent '<ul>'.
58    // @param: a list of '<li>'' elements
59    //
60    var _update_list = function _update_list (list) {
61      file_list.append($(list));
62    };
63
64
65    var _update_metrics_order = function _update_metrics_order (metric_name) {
66
67      var reorder = function reorder () {
68
69        var metric = $(this).children().find('label').filter(function() {
70          return $(this).text() === metric_name;
71        }).parent();
72
73        $(metric).prependTo($(this));
74      };
75
76      $("div [class*='js-file-chart']").each(reorder);
77    };
78
79    // button event-handler
80
81    var _byComplexity = function () {
82      _update_list(_sortByComplexity());
83      _update_metrics_order('complexity');
84    };
85
86    var _byBugs = function () {
87      _update_list(_sortByBugs());
88      _update_metrics_order('est errors');
89    };
90
91    var _bySLOC = function () {
92      _update_list(_sortBySLOC());
93      _update_metrics_order('sloc');
94    };
95
96    var _byLint = function () {
97      _update_list(_sortByLintErr());
98      _update_metrics_order('lint errors');
99    };
100
101    // styling
102
103    var _update_state = function _update_state (target) {
104
105        var prev = $('button.on');
106            prev.removeClass('on');
107
108        var current = $(target);
109            current.addClass('on');
110    };
111
112    // setup button events
113
114    $('button#button-complexity').on('click', _byComplexity);
115    $('button#button-bugs').on('click', _byBugs);
116    $('button#button-sloc').on('click', _bySLOC);
117    $('button#button-lint').on('click', _byLint);
118
119    // styling update for buttons
120
121    var all = $('button.btn');
122        all.on('click', function (evt) {
123          _update_state(evt.target);
124        });
125});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.