1/** 2 * @file 3 */ 4 5Drupal.behaviors.download_panel = function ($, Drupal) { 6 'use strict'; 7 var download_url = Drupal.url('listing/download/document/'), 8 selectedIds = {}, 9 totalSize = 0, 10 addItem = function (item) { 11 selectedIds[item.id] = item.id.toString(36); 12 totalSize = totalSize + parseInt(item.size, 10); 13 }, 14 removeItem = function (item) { 15 delete selectedIds[item.id]; 16 if (Object.keys(selectedIds).length) { 17 totalSize = totalSize - parseInt(item.size, 10); 18 } 19 else { 20 totalSize = 0; 21 } 22 }, 23 getPanel = function () { 24 var $panel = null; 25 return function () { 26 if (!$panel) { 27 $panel = $('.mass-download.info-block'); 28 } 29 return $panel; 30 }; 31 }(), 32 formatBytes = function (a, b) { 33 var i, c = 1024, d = b || 2, f = 0, s = [], e = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; 34 for (i = 0; i < e.length; i = i + 1) { 35 s[i] = '@file_size' + e[i]; 36 } 37 if (a > 0) { 38 f = Math.floor(Math.log(a) / Math.log(c)); 39 a = parseFloat((a / Math.pow(c, f)).toFixed(d)); 40 } 41 return Drupal.t(s[f], {'@file_size' : a}); 42 }, 43 updatePanel = function () { 44 var $p = getPanel(), $link, 45 selected_number = Object.keys(selectedIds).length; 46 if (selected_number) { 47 $p.find('div.quantity').text(Drupal.formatPlural(selected_number, '1 item selected', '@count items selected')); 48 $link = $p.find('div.container a.cta-button'); 49 $link.text(Drupal.t('Download (@size)', { '@size': formatBytes(totalSize, 1) })); 50 $link.attr('href', download_url + Object.keys(selectedIds).map(function (itm) { return selectedIds[itm]; }).join(',')); 51 if (!$p.is(':visible')) { 52 $p.fadeIn('slow'); 53 } 54 } 55 else { 56 if ($p.is(':visible')) { 57 $p.fadeOut(); 58 } 59 } 60 }, 61 resetPanel = function () { 62 selectedIds = {}; 63 totalSize = 0; 64 updatePanel(); 65 }; 66 67 return { 68 attach: function (context) { 69 $(once('massDownload', '.download-checkbox [type="checkbox"]', context)).each(function () { 70 $(this).click(function () { 71 var $this = $(this); 72 if ($this.prop('checked')) { 73 addItem($this.data()); 74 } 75 else { 76 removeItem($this.data()); 77 } 78 updatePanel(); 79 }); 80 }); 81 $(once('massDownload', '.views-exposed-form .form-actions input[type="submit"]', context)).each(function () { 82 $(this).click(resetPanel); 83 }); 84 } 85 }; 86}(jQuery, Drupal);
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.