PageSourceSearch

https://www.localconditions.com/lib/datatables-helper/js/datatables-helper.js

js localconditions.com collected 2026-10-03 21:41:57 UTC 4,151 bytes, 141 lines download raw bytes

1(function ($) {
2
3  $.dataTableHelper = function (el, options) {
4    var base = this;
5
6    base.$el = $(el);
7    base.el = el;
8
9    base.init = function () {
10      base.metadata = base.$el.data ()
11
12      base.options = $.extend({},$.dataTableHelper.defaultOptions, options, base.metadata);
13
14      base.options.ordering = true    
15      base.options.searching = true
16    };
17
18    base.init();
19
20    var sortableArray = []
21
22    base.$el.find ('thead th').each (function (i) {
23      var bool = ($(this).data ('sortable')) ? true : false
24      sortableArray.push ({ orderable: bool })
25    })
26
27    base.options.columns = sortableArray
28
29      base.options.initComplete = function () {
30
31        var api = this.api ()
32            , row = $('<tr>')
33            , orderArray = []
34            , filterCount = 0
35
36        api.columns ().indexes ().flatten ().each (function (colIndex) {
37          var column = api.column (colIndex)
38              , $col = $(column.header ())
39              , th = $('<th>&nbsp;</th>')
40
41          if ($col.data ('filterable') == 'text') {
42            var input = $('<input type="text" class="form-control input-sm" />')
43                .appendTo(th.empty ())
44                .on ('keyup change', function () {
45                  api
46                    .column (colIndex)
47                    .search (this.value)
48                    .draw ()
49
50                var nodes = $(column.nodes ())
51                    , index = $col.index () + 1
52
53
54                highlightColumn (column, index, this.value)                  
55            })                  
56
57            filterCount++
58          }
59
60          if ($col.data ('filterable') == 'select') {
61            var select = $('<select class="form-control input-sm"><option value=""></option></select>')
62                .appendTo(th.empty ())
63                .on( 'change', function () {
64                  var val = $(this).val()
65                      , index = $col.index () + 1
66
67                  column
68                    .search( val ? '^'+val+'$' : '', true, false )
69                    .draw()
70
71                  highlightColumn (column, index, val)
72                })
73
74            column.data ().unique ().sort ().each (function (d, j) {
75              select.append('<option value="' + d + '">' + d + '</option>')
76            })              
77
78            filterCount++
79          }
80
81          base.$el.find ('thead th').each (function (i) {              
82            if ($(this).data ('sort-order') === undefined) { $(this).data ('sort-order', 1000) }
83          }).sort (sortLI).each (function () {
84            orderArray.push ([$(this).index (), $(this).data ('direction') ])
85          })
86
87          row.append (th)                                                                                                                                       
88        })
89
90        if (orderArray.length > 0) {
91          api.order (orderArray).draw ()
92        }
93
94        if (filterCount) {
95          base.$el.find ('thead').append (row)
96        }
97
98        api.draw ()
99      }
100      
101      var $thisTable = base.$el.dataTable (base.options).addClass ('dataTable-helper')
102
103      if (!base.options.globalSearch) {
104        $thisTable.parents ('.dataTables_wrapper').find ('.dataTables_filter').remove ()
105      } 
106
107
108  };
109
110  function sortLI (a, b) {
111      return ($(b).data ('sort-order')) < ($(a).data ('sort-order')) ? 1 : -1;    
112    }
113
114    function highlightColumn (column, index, val) {
115      console.log (column)
116      if (val == '') {
117        $(column.header ()).removeClass ('highlight')
118        $(column.nodes ()).removeClass ('highlight')
119        $(column.footer ()).removeClass ('highlight')
120      } else {
121        $(column.header ()).addClass ('highlight')
122        $(column.nodes ()).addClass ('highlight')
123        $(column.footer ()).addClass ('highlight')        
124      }
125    }
126
127  $.dataTableHelper.defaultOptions = {
128    paging: false
129    , globalSearch: false
130    , info: false
131    , lengthChange: false
132    , pageLength: 10
133  };
134
135  $.fn.dataTableHelper = function (options) {
136    return this.each (function () {
137      (new $.dataTableHelper(this, options));
138    });
139  };
140
141})(jQuery);

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.