diff options
Diffstat (limited to 'sitestatic/archweb.js')
-rw-r--r-- | sitestatic/archweb.js | 226 |
1 files changed, 188 insertions, 38 deletions
diff --git a/sitestatic/archweb.js b/sitestatic/archweb.js index f5a682d6..f7be50d8 100644 --- a/sitestatic/archweb.js +++ b/sitestatic/archweb.js @@ -1,6 +1,6 @@ /* archweb.js * Homepage: https://projects.archlinux.org/archweb.git/ - * Copyright: 2007-2011 The Archweb Team + * Copyright: 2007-2013 The Archweb Team * License: GPLv2 * * This file is part of Archweb. @@ -18,9 +18,10 @@ * along with Archweb. If not, see <http://www.gnu.org/licenses/>. */ +/*'use strict';*/ /* tablesorter custom parsers for various pages: * devel/index.html, mirrors/status.html, todolists/view.html */ -if (typeof $.tablesorter !== 'undefined') { +if (typeof $ !== 'undefined' && typeof $.tablesorter !== 'undefined') { $.tablesorter.addParser({ id: 'pkgcount', is: function(s) { return false; }, @@ -34,7 +35,12 @@ if (typeof $.tablesorter !== 'undefined') { id: 'todostatus', is: function(s) { return false; }, format: function(s) { - return s.match(/incomplete/i) ? 1 : 0; + if (s.match(/incomplete/i)) { + return 1; + } else if (s.match(/in-progress/i)) { + return 0.5; + } + return 0; }, type: 'numeric' }); @@ -46,11 +52,11 @@ if (typeof $.tablesorter !== 'undefined') { var c = table.config; return ($.inArray(s, this.special) > -1) || $.tablesorter.isDigit(s, c); }, - format: function(s) { + format: function(s, t) { if ($.inArray(s, this.special) > -1) { return Number.MAX_VALUE; } - return $.tablesorter.formatFloat(s); + return $.tablesorter.formatFloat(s, t); }, type: 'numeric' }); @@ -80,7 +86,7 @@ if (typeof $.tablesorter !== 'undefined') { format: function(s, t, c) { /* TODO: this assumes our magic class is the only one */ var epoch = $(c).attr('class'); - if (!epoch.indexOf('epoch-') == 0) { + if (epoch.indexOf('epoch-') !== 0) { return 0; } return epoch.slice(6); @@ -93,7 +99,7 @@ if (typeof $.tablesorter !== 'undefined') { is: function(s) { return this.re.test(s); }, - format: function(s) { + format: function(s, t) { var matches = this.re.exec(s); if (!matches) { return 0; @@ -106,13 +112,13 @@ if (typeof $.tablesorter !== 'undefined') { * between 0-11, because things have to be difficult. */ var date = new Date(matches[1], matches[2] - 1, matches[3], matches[4], matches[5], matches[7]); - return $.tablesorter.formatFloat(date.getTime()); + return $.tablesorter.formatFloat(date.getTime(), t); }, type: 'numeric' }); $.tablesorter.addParser({ id: 'filesize', - re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB|PB)$/, + re: /^(\d+(?:\.\d+)?) (bytes?|[KMGTPEZY]i?B)$/, is: function(s) { return this.re.test(s); }, @@ -121,20 +127,34 @@ if (typeof $.tablesorter !== 'undefined') { if (!matches) { return 0; } - var size = parseFloat(matches[1]); - var suffix = matches[2]; + var size = parseFloat(matches[1]), + suffix = matches[2]; switch(suffix) { /* intentional fall-through at each level */ + case 'YB': + case 'YiB': + size *= 1024; + case 'ZB': + case 'ZiB': + size *= 1024; + case 'EB': + case 'EiB': + size *= 1024; case 'PB': + case 'PiB': size *= 1024; case 'TB': + case 'TiB': size *= 1024; case 'GB': + case 'GiB': size *= 1024; case 'MB': + case 'MiB': size *= 1024; case 'KB': + case 'KiB': size *= 1024; } return size; @@ -145,13 +165,12 @@ if (typeof $.tablesorter !== 'undefined') { (function($) { $.fn.enableCheckboxRangeSelection = function() { - var lastCheckbox = null; - var lastElement = null; + var lastCheckbox = null, + spec = this; - var spec = this; spec.unbind("click.checkboxrange"); spec.bind("click.checkboxrange", function(e) { - if (lastCheckbox != null && e.shiftKey) { + if (lastCheckbox !== null && e.shiftKey) { spec.slice( Math.min(spec.index(lastCheckbox), spec.index(e.target)), Math.max(spec.index(lastCheckbox), spec.index(e.target)) + 1 @@ -184,8 +203,67 @@ function enablePreview() { function ajaxifyFiles() { $('#filelink').click(function(event) { event.preventDefault(); - $.get(this.href, function(data) { - $('#pkgfilelist').html(data); + $.getJSON(this.href + 'json/', function(data) { + // Map each file item into an <li/> with the correct class + var list_items = $.map(data.files, function(value, i) { + var cls = value.match(/\/$/) ? 'd' : 'f'; + return ['<li class="', cls, '">', value, '</li>']; + }); + $('#pkgfilelist').empty(); + if (data.pkg_last_update > data.files_last_update) { + $('#pkgfilelist').append('<p class="message">Note: This file list was generated from a previous version of the package; it may be out of date.</p>'); + } + if (list_items.length > 0) { + $('#pkgfilelist').append('<ul>' + list_items.join('') + '</ul>'); + } else if (data.files_last_update === null) { + $('#pkgfilelist').append('<p class="message">No file list available.</p>'); + } else { + $('#pkgfilelist').append('<p class="message">Package has no files.</p>'); + } + }); + }); +} + +function collapseDependsList(list) { + list = $(list); + // Hide everything past a given limit. Don't do anything if we don't have + // enough items, or the link already exists. + var limit = 20, + linkid = list.attr('id') + 'link', + items = list.find('li').slice(limit); + if (items.length <= 1 || $('#' + linkid).length > 0) { + return; + } + items.hide(); + list.after('<p><a id="' + linkid + '" href="#">Show More…</a></p>'); + + // add link and wire it up to show the hidden items + $('#' + linkid).click(function(event) { + event.preventDefault(); + list.find('li').show(); + // remove the full <p/> node from the DOM + $(this).parent().remove(); + }); +} + +function collapseRelatedTo(elements) { + var limit = 5; + $(elements).each(function(idx, ele) { + ele = $(ele); + // Hide everything past a given limit. Don't do anything if we don't + // have enough items, or the link already exists. + var items = ele.find('span.related').slice(limit); + if (items.length <= 1 || ele.find('a.morelink').length > 0) { + return; + } + items.hide(); + ele.append('<a class="morelink" href="#">More…</a>'); + + // add link and wire it up to show the hidden items + ele.find('a.morelink').click(function(event) { + event.preventDefault(); + ele.find('span.related').show(); + $(this).remove(); }); }); } @@ -193,8 +271,8 @@ function ajaxifyFiles() { /* packages/differences.html */ function filter_packages() { /* start with all rows, and then remove ones we shouldn't show */ - var rows = $('#tbody_differences').children(); - var all_rows = rows; + var rows = $('#tbody_differences').children(), + all_rows = rows; if (!$('#id_multilib').is(':checked')) { rows = rows.not('.multilib').not('.multilib-testing'); } @@ -236,7 +314,7 @@ function filter_packages() { all_rows.hide(); rows.show(); /* make sure we update the odd/even styling from sorting */ - $('.results').trigger('applyWidgets'); + $('.results').trigger('applyWidgets', [false]); } function filter_packages_reset() { $('#id_archonly').val('both'); @@ -247,32 +325,64 @@ function filter_packages_reset() { /* todolists/view.html */ function todolist_flag() { + // TODO: fix usage of this var link = this; $.getJSON(link.href, function(data) { - if (data.complete) { - $(link).text('Complete').addClass( - 'complete').removeClass('incomplete'); - } else { - $(link).text('Incomplete').addClass( - 'incomplete').removeClass('complete'); - } + $(link).text(data.status).removeClass( + 'complete inprogress incomplete').addClass( + data.css_class.toLowerCase()); /* let tablesorter know the cell value has changed */ - $('.results').trigger('updateCell', $(link).closest('td')); + $('.results').trigger('updateCell', [$(link).closest('td')[0], false, null]); }); return false; } +function filter_pkgs_list(filter_ele, tbody_ele) { + /* start with all rows, and then remove ones we shouldn't show */ + var rows = $(tbody_ele).children(), + all_rows = rows; + /* apply the filters, cheaper ones first */ + if ($('#id_mine_only').is(':checked')) { + rows = rows.filter('.mine'); + } + /* apply arch and repo filters */ + $(filter_ele + ' .arch_filter').add( + filter_ele + ' .repo_filter').each(function() { + if (!$(this).is(':checked')) { + rows = rows.not('.' + $(this).val()); + } + }); + /* more expensive filter because of 'has' call */ + if ($('#id_incomplete').is(':checked')) { + rows = rows.has('.incomplete'); + } + /* hide all rows, then show the set we care about */ + all_rows.hide(); + rows.show(); + $('#filter-count').text(rows.length); + /* make sure we update the odd/even styling from sorting */ + $('.results').trigger('applyWidgets', [false]); +} +function filter_pkgs_reset(callback) { + $('#id_incomplete').removeAttr('checked'); + $('#id_mine_only').removeAttr('checked'); + $('.arch_filter').attr('checked', 'checked'); + $('.repo_filter').attr('checked', 'checked'); + callback(); +} + /* signoffs.html */ function signoff_package() { + // TODO: fix usage of this var link = this; $.getJSON(link.href, function(data) { link = $(link); - var signoff = null; - var cell = link.closest('td'); + var signoff = null, + cell = link.closest('td'); if (data.created) { signoff = $('<li>').addClass('signed-username').text(data.user); var list = cell.children('ul.signoff-list'); - if (list.size() == 0) { + if (list.size() === 0) { list = $('<ul class="signoff-list">').prependTo(cell); } list.append(signoff); @@ -286,7 +396,7 @@ function signoff_package() { } /* update the approved column to reflect reality */ var approved = link.closest('tr').children('.approval'); - approved.attr('class', ''); + approved.attr('class', 'approval'); if (data.known_bad) { approved.text('Bad').addClass('signoff-bad'); } else if (!data.enabled) { @@ -311,15 +421,16 @@ function signoff_package() { link.text('Revoke Signoff'); link.attr('href', base_href + '/signoff/revoke/'); } - $('.results').trigger('updateCell', approved); + /* let tablesorter know the cell value has changed */ + $('.results').trigger('updateCell', [approved[0], false, null]); }); return false; } function filter_signoffs() { /* start with all rows, and then remove ones we shouldn't show */ - var rows = $('#tbody_signoffs').children(); - var all_rows = rows; + var rows = $('#tbody_signoffs').children(), + all_rows = rows; /* apply arch and repo filters */ $('#signoffs_filter .arch_filter').add( '#signoffs_filter .repo_filter').each(function() { @@ -336,7 +447,7 @@ function filter_signoffs() { rows.show(); $('#filter-count').text(rows.length); /* make sure we update the odd/even styling from sorting */ - $('.results').trigger('applyWidgets'); + $('.results').trigger('applyWidgets', [false]); } function filter_signoffs_reset() { $('#signoffs_filter .arch_filter').attr('checked', 'checked'); @@ -345,11 +456,40 @@ function filter_signoffs_reset() { filter_signoffs(); } +function collapseNotes(elements) { + // Remove any trailing <br/> tags from the note contents + $(elements).children('br').filter(':last-child').filter(function(i, e) { return !e.nextSibling; }).remove(); + + var maxElements = 8; + $(elements).each(function(idx, ele) { + ele = $(ele); + // Hide everything past a given limit. Don't do anything if we don't + // have enough items, or the link already exists. + var contents = ele.contents(); + if (contents.length <= maxElements || ele.find('a.morelink').length > 0) { + return; + } + contents.slice(maxElements).wrapAll('<div class="hide"/>'); + ele.append('<br class="morelink-spacer"/><a class="morelink" href="#">Show More…</a>'); + + // add link and wire it up to show the hidden items + ele.find('a.morelink').click(function(event) { + event.preventDefault(); + $(this).remove(); + ele.find('br.morelink-spacer').remove(); + // move the div contents back and delete the empty div + var hidden = ele.find('div.hide'); + hidden.contents().appendTo(ele); + hidden.remove(); + }); + }); +} + /* visualizations */ function format_filesize(size, decimals) { /*var labels = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];*/ - var labels = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - var label = 0; + var labels = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], + label = 0; while (size > 2048.0 && label < labels.length - 1) { label++; @@ -361,3 +501,13 @@ function format_filesize(size, decimals) { return size.toFixed(decimals) + ' ' + labels[label]; } + +/* HTML5 input type and attribute enhancements */ +function modify_attributes(to_change) { + /* jQuery doesn't let us change the 'type' attribute directly due to IE + woes, so instead we can clone and replace, setting the type. */ + $.each(to_change, function(id, attrs) { + var obj = $(id); + obj.replaceWith(obj.clone().attr(attrs)); + }); +} |