]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/plato-sortable-file-list.js
1 /* global $:false, _:false */
2 /* jshint browser:true */
5 author: david linse <davidlinse@gmail.com>
8 A very first draft to add the ability to sort
9 the "file-list" by the displayed 'numbers' for:
16 A group of buttons is added to the template above
17 to trigger the update of the file-list.
20 $(function sortable_file_list () {
24 var file_list
= $('ul.file-list');
26 var files
= file_list
.find('li');
29 // @param: key The 'data-<key>' to sort by
30 // @return: descending sorted array of <li> elements
32 var _sortBy = function (key
) {
33 return _
.sortBy(files
, function (el
) {
34 return Number($(el
).find('span[data-lint]').attr(key
)) * -1;
40 var _sortByLintErr
= function _sortByLintErr () {
41 return _sortBy('data-lint');
44 var _sortBySLOC
= function _sortBySLOC () {
45 return _sortBy('data-sloc');
48 var _sortByBugs
= function _sortByBugs () {
49 return _sortBy('data-bugs');
52 var _sortByComplexity
= function _sortByComplexity () {
53 return _sortBy('data-complexity');
56 // appends the 'list' of '<li>' elements
57 // to its parent '<ul>'.
58 // @param: a list of '<li>'' elements
60 var _update_list
= function _update_list (list
) {
61 file_list
.append($(list
));
64 // button event-handler
66 var _byComplexity = function () {
67 _update_list(_sortByComplexity());
70 var _byBugs = function () {
71 _update_list(_sortByBugs());
74 var _bySLOC = function () {
75 _update_list(_sortBySLOC());
78 var _byLint = function () {
79 _update_list(_sortByLintErr());
84 var _update_state
= function _update_state (target
) {
86 var prev
= $('button.on');
87 prev
.removeClass('on');
89 var current
= $(target
);
90 current
.addClass('on');
93 // setup button events
95 $('button#button-complexity').on('click', _byComplexity
);
96 $('button#button-bugs').on('click', _byBugs
);
97 $('button#button-sloc').on('click', _bySLOC
);
98 $('button#button-lint').on('click', _byLint
);
100 // styling update for buttons
102 var all
= $('button.btn');
103 all
.on('click', function (evt
) {
104 _update_state(evt
.target
);