MCPcopy
hub / github.com/NeXTs/Clusterize.js / Clusterize

Function Clusterize

clusterize.js:24–151  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

22 }()),
23 is_mac = navigator.platform.toLowerCase().indexOf('mac') + 1;
24 var Clusterize = function(data) {
25 if( ! (this instanceof Clusterize))
26 return new Clusterize(data);
27 var self = this;
28
29 var defaults = {
30 rows_in_block: 50,
31 blocks_in_cluster: 4,
32 tag: null,
33 show_no_data_row: true,
34 no_data_class: 'clusterize-no-data',
35 no_data_text: 'No data',
36 keep_parity: true,
37 callbacks: {}
38 }
39
40 // public parameters
41 self.options = {};
42 var options = ['rows_in_block', 'blocks_in_cluster', 'show_no_data_row', 'no_data_class', 'no_data_text', 'keep_parity', 'tag', 'callbacks'];
43 for(var i = 0, option; option = options[i]; i++) {
44 self.options[option] = typeof data[option] != 'undefined' && data[option] != null
45 ? data[option]
46 : defaults[option];
47 }
48
49 var elems = ['scroll', 'content'];
50 for(var i = 0, elem; elem = elems[i]; i++) {
51 self[elem + '_elem'] = data[elem + 'Id']
52 ? document.getElementById(data[elem + 'Id'])
53 : data[elem + 'Elem'];
54 if( ! self[elem + '_elem'])
55 throw new Error("Error! Could not find " + elem + " element");
56 }
57
58 // tabindex forces the browser to keep focus on the scrolling list, fixes #11
59 if( ! self.content_elem.hasAttribute('tabindex'))
60 self.content_elem.setAttribute('tabindex', 0);
61
62 // private parameters
63 var rows = isArray(data.rows)
64 ? data.rows
65 : self.fetchMarkup(),
66 cache = {},
67 scroll_top = self.scroll_elem.scrollTop;
68
69 // append initial data
70 self.insertToDOM(rows, cache);
71
72 // restore the scroll position
73 self.scroll_elem.scrollTop = scroll_top;
74
75 // adding scroll handler
76 var last_cluster = false,
77 scroll_debounce = 0,
78 pointer_events_set = false,
79 scrollEv = function() {
80 // fixes scrolling issue on Mac #3
81 if (is_mac) {

Callers

nothing calls this directly

Calls 4

isArrayFunction · 0.85
onFunction · 0.85
offFunction · 0.85
addFunction · 0.85

Tested by

no test coverage detected