Project

General

Profile

Feature #1718 » wiki-table-column-sorting.patch

Kevin Fischer, 2020-02-19 11:14

View differences:

app/helpers/application_helper.rb
1619 1619
  # Returns the javascript tags that are included in the html layout head
1620 1620
  def javascript_heads
1621
    tags = javascript_include_tag('jquery-2.2.4-ui-1.11.0-ujs-5.2.3', 'tribute-3.7.3.min', 'application', 'responsive')
1621
    tags = javascript_include_tag('jquery-2.2.4-ui-1.11.0-ujs-5.2.3', 'tribute-3.7.3.min', 'tablesort-5.1.0.min', 'application', 'responsive')
1622 1622
    unless User.current.pref.warn_on_leaving_unsaved == '0'
1623 1623
      tags << "\n".html_safe + javascript_tag("$(window).on('load', function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
1624 1624
    end
app/views/journals/update.js.erb
7 7
  $("#journal-<%= @journal.id %>-notes").replaceWith('<%= escape_javascript(render_notes(@journal.issue, @journal, :reply_links => authorize_for('issues', 'edit'))) %>');
8 8
  $("#journal-<%= @journal.id %>-notes").show();
9 9
  $("#journal-<%= @journal.id %>-form").remove();
10
  setupWikiTableSortableHeader();
10 11
<% end %>
11 12
<%= call_hook(:view_journals_update_js_bottom, { :journal => @journal }) %>
app/views/layouts/base.html.erb
9 9
<meta name="keywords" content="issue,bug,tracker" />
10 10
<%= csrf_meta_tag %>
11 11
<%= favicon %>
12
<%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'tribute-3.7.3', 'application', 'responsive', :media => 'all' %>
12
<%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'tribute-3.7.3', 'tablesort-5.1.0', 'application', 'responsive', :media => 'all' %>
13 13
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
14 14
<%= javascript_heads %>
15 15
<%= heads_for_theme %>
public/javascripts/application.js
954 954
      data: "text=" + element + '&' + attachments,
955 955
      success: function(data){
956 956
        jstBlock.find('.wiki-preview').html(data);
957
        setupWikiTableSortableHeader();
957 958
      }
958 959
    });
959 960
  });
......
995 996
  $(window).resize(setFilecontentContainerHeight);
996 997
}
998
function setupWikiTableSortableHeader() {
999
  $('div.wiki table').each(function(i, table){
1000
    if (table.rows.length < 3) return true;
1001
    var tr = $(table.rows).first();
1002
    if (tr.find("TH").length > 0) {
1003
      tr.attr('data-sort-method', 'none');
1004
      tr.find("TD").attr('data-sort-method', 'none');
1005
      new Tablesort(table);
1006
    }
1007
  });
1008
}
997 1009
$(function () {
998 1010
    $('[title]').tooltip({
......
1062 1074
$(document).ready(setupAttachmentDetail);
1063 1075
$(document).ready(setupTabs);
1064 1076
$(document).ready(setupFilePreviewNavigation);
1077
$(document).ready(setupWikiTableSortableHeader);
1065 1078
$(document).on('focus', '[data-auto-complete=true]', function(event) {
1066 1079
  inlineAutoComplete(event.target);
1067 1080
});
public/javascripts/tablesort-5.1.0.min.js
1
/*!
2
 * tablesort v5.1.0 (2018-09-14)
3
 * http://tristen.ca/tablesort/demo/
4
 * Copyright (c) 2018 ; Licensed MIT
5
*/
6
!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||"TABLE"!==b.tagName)throw new Error("Element must be a table");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&"function"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent("CustomEvent"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute("data-sort")||a.textContent||a.innerText||""},e=function(a,b){return a=a.trim().toLowerCase(),b=b.trim().toLowerCase(),a===b?0:a<b?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if("function"!=typeof c||"function"!=typeof d)throw new Error("Pattern and sort must be a function");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if("thead"===a.tHead.rows[e].getAttribute("data-sort-method")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&g.current.removeAttribute("aria-sort"),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.setAttribute("role","columnheader"),"none"!==f.getAttribute("data-sort-method")&&(f.tabindex=0,f.addEventListener("click",h,!1),null!==f.getAttribute("data-sort-default")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h=this,i=a.cellIndex,j=e,k="",l=[],m=h.thead?0:1,n=a.getAttribute("data-sort-method"),o=a.getAttribute("aria-sort");if(h.table.dispatchEvent(c("beforeSort")),g||(o="ascending"===o?"descending":"descending"===o?"ascending":h.options.descending?"descending":"ascending",a.setAttribute("aria-sort",o)),!(h.table.rows.length<2)){if(!n){for(;l.length<3&&m<h.table.tBodies[0].rows.length;)k=d(h.table.tBodies[0].rows[m].cells[i]),k=k.trim(),k.length>0&&l.push(k),m++;if(!l)return}for(m=0;m<b.length;m++)if(k=b[m],n){if(k.name===n){j=k.sort;break}}else if(l.every(k.pattern)){j=k.sort;break}for(h.col=i,m=0;m<h.table.tBodies.length;m++){var p,q=[],r={},s=0,t=0;if(!(h.table.tBodies[m].rows.length<2)){for(p=0;p<h.table.tBodies[m].rows.length;p++)k=h.table.tBodies[m].rows[p],"none"===k.getAttribute("data-sort-method")?r[s]=k:q.push({tr:k,td:d(k.cells[h.col]),index:s}),s++;for("descending"===o?q.sort(f(j,!0)):(q.sort(f(j,!1)),q.reverse()),p=0;p<s;p++)r[p]?(k=r[p],t++):k=q[p-t].tr,h.table.tBodies[m].appendChild(k)}}h.table.dispatchEvent(c("afterSort"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();
public/stylesheets/tablesort-5.1.0.css
1
th[role=columnheader]:not(.no-sort) {
2
    cursor: pointer;
3
}
4

  
5
th[role=columnheader]:not(.no-sort):after {
6
    content: '';
7
    float: right;
8
    margin-top: 7px;
9
    border-width: 0 4px 4px;
10
    border-style: solid;
11
    border-color: #404040 transparent;
12
    visibility: hidden;
13
    opacity: 0;
14
    -ms-user-select: none;
15
    -webkit-user-select: none;
16
    -moz-user-select: none;
17
    user-select: none;
18
}
19

  
20
th[aria-sort=ascending]:not(.no-sort):after {
21
    border-bottom: none;
22
    border-width: 4px 4px 0;
23
}
24

  
25
th[aria-sort]:not(.no-sort):after {
26
    visibility: visible;
27
    opacity: 0.4;
28
}
29

  
30
th[role=columnheader]:not(.no-sort):hover:after {
31
    visibility: visible;
32
    opacity: 1;
33
}
(2-2/6)