Completed
Push — master ( f3b15c...eb239f )
by Dmitry
07:18
created

?!?.?!?   C

Complexity

Conditions 8
Paths 16

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
c 1
b 0
f 0
nc 16
nop 0
dl 0
loc 30
rs 5.3846

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/******/ (function(modules) { // webpackBootstrap
2
/******/ 	// The module cache
3
/******/ 	var installedModules = {};
4
5
/******/ 	// The require function
6
/******/ 	function __webpack_require__(moduleId) {
7
8
/******/ 		// Check if module is in cache
9
/******/ 		if(installedModules[moduleId])
10
/******/ 			return installedModules[moduleId].exports;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
11
12
/******/ 		// Create a new module (and put it into the cache)
13
/******/ 		var module = installedModules[moduleId] = {
14
/******/ 			exports: {},
15
/******/ 			id: moduleId,
16
/******/ 			loaded: false
17
/******/ 		};
18
19
/******/ 		// Execute the module function
20
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
22
/******/ 		// Flag the module as loaded
23
/******/ 		module.loaded = true;
24
25
/******/ 		// Return the exports of the module
26
/******/ 		return module.exports;
27
/******/ 	}
28
29
30
/******/ 	// expose the modules object (__webpack_modules__)
31
/******/ 	__webpack_require__.m = modules;
32
33
/******/ 	// expose the module cache
34
/******/ 	__webpack_require__.c = installedModules;
35
36
/******/ 	// __webpack_public_path__
37
/******/ 	__webpack_require__.p = "";
38
39
/******/ 	// Load entry module and return exports
40
/******/ 	return __webpack_require__(0);
41
/******/ })
42
/************************************************************************/
43
/******/ ({
44
45
/***/ 0:
46
/***/ function(module, exports, __webpack_require__) {
47
48
	"use strict";
49
50
	var _sf = __webpack_require__(162);
51
52
	var _sf2 = _interopRequireDefault(_sf);
53
54
	var _listing = __webpack_require__(163);
55
56
	var _listing2 = _interopRequireDefault(_listing);
57
58
	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
60
	__webpack_require__(164); //resolved by webpack's "externals"
61
62
63
	_sf2.default.instancesController.registerInstanceType(_listing2.default, "js-sf-listing");
64
	module.exports = _listing2.default; // ES6 default export will not expose us as global
65
66
/***/ },
67
68
/***/ 162:
69
/***/ function(module, exports) {
70
71
	module.exports = sf;
0 ignored issues
show
Bug introduced by
The variable sf seems to be never declared. If this is a global, consider adding a /** global: sf */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
72
73
/***/ },
74
75
/***/ 163:
76
/***/ function(module, exports, __webpack_require__) {
77
78
	"use strict";
79
80
	var _sf = __webpack_require__(162);
81
82
	var _sf2 = _interopRequireDefault(_sf);
83
84
	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
85
86
	//resolved by webpack's "externals"
87
88
	var Listing = function Listing(sf, node, options) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable Listing already seems to be declared on line 88. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
89
	    this._construct(sf, node, options);
90
	};
91
92
	Listing.prototype = _sf2.default.createModulePrototype();
93
94
	Listing.prototype.name = "listing";
95
96
	Listing.prototype._construct = function (sf, node, options) {
97
	    this.restoreParams();
98
99
	    this.init(sf, node, options);
100
101
	    if (options) {
102
	        //if we pass options extend all options by passed options
103
	        this.options = Object.assign(this.options, options);
104
	    }
105
106
	    this.listingID = node.id;
107
108
	    this.els = {
109
	        node: node,
110
	        sorters: node.querySelectorAll('[data-sorter]'),
111
	        form: document.querySelector('[data-listing-id="' + this.listingID + '"]') || false,
112
	        reset: document.querySelector('.sf-listing-reset')
113
	    };
114
	    window.form = this.els.form;
115
116
	    this.searchRegexp = new RegExp(this.options.config.namespace + '\\[filters\\]\\[\\d+\\]', "i");
117
118
	    this.updateControls();
119
120
	    this.addEventListeners();
121
	};
122
123
	Listing.prototype.optionsToGrab = {
124
	    /**
125
	     *  Pass data in JSON-encoded format <b>Default: false</b>
126
	     */
127
	    config: {
128
	        value: false,
129
	        domAttr: "data-config",
130
	        processor: function processor(node, val) {
131
	            if (!val) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
132
	            if (typeof val == "string") {
133
	                try {
134
	                    val = JSON.parse(val);
135
	                } catch (e) {
136
	                    console.error("Listing config JSON.parse error: ", e);
137
	                }
138
	            }
139
	            return val;
140
	        }
141
	    },
142
	    iconASC: {
143
	        value: '<i class="toolkit-icon-sort-up"></i>',
144
	        domAttr: "data-icon-asc"
145
	    },
146
	    iconDESC: {
147
	        value: '<i class="toolkit-icon-sort-down"></i>',
148
	        domAttr: "data-icon-asc"
149
	    },
150
	    iconSorter: {
151
	        value: '<i class="toolkit-icon-down"></i>',
152
	        domAttr: "data-icon-sorter"
153
	    },
154
	    pagination: {
155
	        value: true,
156
	        domAttr: "data-pagination",
157
	        "processor": function processor(node, val) {
158
	            if (typeof val === "boolean") return val;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
159
160
	            val = val !== void 0 && val !== null ? val.toLowerCase() : '';
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
161
	            if (val === 'false') {
162
	                val = false;
163
	            } else if (val === 'true') {
164
	                val = true;
165
	            } else {
166
	                val = this.value;
167
	            }
168
	            return val;
169
	        }
170
	    },
171
	    paginationPages: {
172
	        value: 7,
173
	        domAttr: "data-pagination-pages"
174
	    },
175
	    paginationWrapperClass: {
176
	        value: 'pagination js-sf-listing-pagination row center-align',
177
	        domAttr: "data-pagination-wrapper"
178
	    },
179
	    paginationPageClass: {
180
	        value: 'waves-effect',
181
	        domAttr: "data-pagination-page-class"
182
	    },
183
	    paginationActiveClass: {
184
	        value: 'active',
185
	        domAttr: "data-pagination-active-class"
186
	    },
187
	    paginationDisabledClass: {
188
	        value: 'disabled',
189
	        domAttr: "data-pagination-disabled-class"
190
	    },
191
	    paginationPrevContent: {
192
	        value: '<i class="toolkit-icon-left"></i>',
193
	        domAttr: "data-pagination-prev"
194
	    },
195
	    paginationNextContent: {
196
	        value: '<i class="toolkit-icon-right"></i>',
197
	        domAttr: "data-pagination-next"
198
	    },
199
	    paginationFirstContent: {
200
	        value: '<i class="toolkit-icon-left stacked"></i><i class="toolkit-icon-left stacked"></i>',
201
	        domAttr: "data-pagination-first"
202
	    },
203
	    paginationLastContent: {
204
	        value: '<i class="toolkit-icon-right stacked"></i><i class="toolkit-icon-right stacked"></i>',
205
	        domAttr: "data-pagination-last"
206
	    },
207
	    limits: {
208
	        value: true,
209
	        domAttr: "data-limits",
210
	        "processor": function processor(node, val) {
211
	            if (typeof val === "boolean") return val;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
212
213
	            val = val !== void 0 && val !== null ? val.toLowerCase() : '';
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
214
	            if (val === 'false') {
215
	                val = false;
216
	            } else if (val === 'true') {
217
	                val = true;
218
	            } else {
219
	                val = this.value;
220
	            }
221
	            return val;
222
	        }
223
	    },
224
	    limitsWrapperClass: {
225
	        value: 'js-sf-listing-limits right input-field item-form col s2',
226
	        domAttr: "data-limits-wrapper"
227
	    },
228
	    limitsLabel: {
229
	        value: '<span class="label">Show: </span>',
230
	        domAttr: "data-limits-label"
231
	    }
232
	};
233
234
	Listing.prototype.updateControls = function () {
235
236
	    if (this.options.pagination) this.generatePagination();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
237
	    if (this.options.limits) {
238
	        this.els.limits = {
239
	            wrapper: document.createElement('div'),
240
	            select: document.createElement('select')
241
	        };
242
	        for (var i = 0; i < this.options.config.pagination.limits.length; i++) {
243
	            var option = document.createElement("option");
244
	            option.value = this.options.config.pagination.limits[i];
245
	            option.text = this.options.config.pagination.limits[i];
246
	            option.selected = this.options.config.pagination.limits[i] === this.options.config.pagination.limit;
247
	            this.els.limits.select.appendChild(option);
248
	        }
249
	        this.els.limits.wrapper.setAttribute("class", this.options.limitsWrapperClass);
250
251
	        this.els.limits.wrapper.innerHTML = this.options.limitsLabel;
252
	        this.els.limits.wrapper.appendChild(this.els.limits.select);
253
	        this.els.node.parentNode.appendChild(this.els.limits.wrapper, this.els.node);
254
	        if (this.options.pagination) this.els.limits.wrapper.classList.add('stacked-right');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
255
	        if (jQuery && typeof jQuery(this.els.limits.select).material_select === "function") {
256
	            //just to make it work with materialize
257
	            jQuery(this.els.limits.select).material_select(this.performLimits.bind(this));
258
	        }
259
	    }
260
261
	    //fill values
262
	    if (this.els.form) {
263
	        var that = this;
264
	        [].forEach.call(this.els.form.querySelectorAll('input, select'), function (input) {
265
	            if (that.options.config.filters && that.options.config.filters[input.name]) input.value = that.options.config.filters[input.name];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
266
	        });
267
	    }
268
269
	    for (var _i = 0; _i < this.els.sorters.length; ++_i) {
270
	        //add asc-desc icon
271
	        if (this.els.sorters[_i].dataset.sorter === this.options.config.sorting.sorter) {
272
	            this.els.sorters[_i].innerHTML += this.options.config.sorting.direction === "asc" ? this.options.iconASC : this.options.iconDESC;
273
	        } else {
274
	            this.els.sorters[_i].innerHTML += this.options.iconSorter;
275
	        }
276
	    }
277
	};
278
279
	Listing.prototype.generatePagination = function () {
280
	    var that = this,
281
	        pageCounter = 1,
282
	        lastLeft = this.options.config.pagination.page,
283
	        lastRight = this.options.config.pagination.page;
284
285
	    this.els.pagination = {
286
	        wrapper: document.createElement('ul'),
287
	        firstPage: document.createElement('li'),
288
	        prevPage: document.createElement('li'),
289
	        page: document.createElement('li'),
290
	        nextPage: document.createElement('li'),
291
	        lastPage: document.createElement('li')
292
	    };
293
294
	    this.pagination = {
295
	        prevPages: [],
296
	        currentPage: this.options.config.pagination.page,
297
	        nextPages: []
298
	    };
299
300
	    while (pageCounter < this.options.paginationPages) {
301
	        if (lastLeft - 1 >= 1) {
302
	            lastLeft--;
303
	            this.pagination.prevPages.unshift(lastLeft);
304
	            pageCounter++;
305
	        }
306
	        if (lastRight + 1 <= this.options.config.pagination.countPages) {
307
	            lastRight++;
308
	            this.pagination.nextPages.push(lastRight);
309
	            pageCounter++;
310
	        }
311
	        if (lastLeft - 1 < 1 && lastRight + 1 > this.options.config.pagination.countPages) break;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
312
	    }
313
314
	    this.els.pagination.wrapper.setAttribute("class", this.options.paginationWrapperClass);
315
316
	    this.els.pagination.firstPage.setAttribute("class", this.options.config.pagination.previousPage ? this.options.paginationPageClass : this.options.paginationDisabledClass);
317
	    this.els.pagination.firstPage.innerHTML = '<a>' + this.options.paginationFirstContent + '</a>';
318
	    this.els.pagination.firstPage.dataset.page = 1;
319
320
	    this.els.pagination.lastPage.setAttribute("class", this.options.config.pagination.nextPage ? this.options.paginationPageClass : this.options.paginationDisabledClass);
321
	    this.els.pagination.lastPage.innerHTML = '<a>' + this.options.paginationLastContent + '</a>';
322
	    this.els.pagination.lastPage.dataset.page = this.options.config.pagination.countPages;
323
324
	    this.els.pagination.prevPage.setAttribute("class", this.options.config.pagination.previousPage ? this.options.paginationPageClass : this.options.paginationDisabledClass);
325
	    this.els.pagination.prevPage.innerHTML = '<a>' + this.options.paginationPrevContent + '</a>';
326
	    this.els.pagination.prevPage.dataset.page = this.pagination.currentPage - 1;
327
328
	    this.els.pagination.nextPage.setAttribute("class", this.options.config.pagination.nextPage ? this.options.paginationPageClass : this.options.paginationDisabledClass);
329
	    this.els.pagination.nextPage.innerHTML = '<a>' + this.options.paginationNextContent + '</a>';
330
	    this.els.pagination.nextPage.dataset.page = this.pagination.currentPage + 1;
331
332
	    this.els.pagination.wrapper.appendChild(this.els.pagination.firstPage);
333
	    this.els.pagination.wrapper.appendChild(this.els.pagination.prevPage);
334
	    this.pagination.prevPages.concat(this.pagination.currentPage, this.pagination.nextPages).forEach(function (val) {
335
	        that.els.pagination.page.dataset.page = val;
336
	        that.els.pagination.page.innerHTML = '<a>' + val + '</a>';
337
	        that.els.pagination.page.setAttribute("class", val === that.pagination.currentPage ? that.options.paginationActiveClass : that.options.paginationPageClass);
338
	        that.els.pagination.wrapper.appendChild(that.els.pagination.page.cloneNode(true));
339
	    });
340
	    this.els.pagination.wrapper.appendChild(this.els.pagination.nextPage);
341
	    this.els.pagination.wrapper.appendChild(this.els.pagination.lastPage);
342
343
	    this.els.node.parentNode.insertBefore(this.els.pagination.wrapper, this.els.node.nextSibling);
344
	    this.els.pagination.activePages = this.els.pagination.wrapper.querySelectorAll('.' + this.options.paginationPageClass);
345
	};
346
347
	Listing.prototype.performSorting = function (sorter) {
348
349
	    this.searchQuery = this.getQueryParams();
350
	    this.searchQuery[this.options.config.namespace + '[sortBy]'] = sorter.dataset.sorter;
351
352
	    //click on active sorter changes direction, otherwise direction will be asc
353
	    if (this.options.config.sorting.sorter === sorter.dataset.sorter) {
354
	        this.searchQuery[this.options.config.namespace + '[order]'] = this.searchQuery[this.options.config.namespace + '[order]'] === 'asc' || !this.searchQuery[this.options.config.namespace + '[order]'] ? 'desc' : 'asc';
355
	    } else {
356
	        this.searchQuery[this.options.config.namespace + '[order]'] = 'asc';
357
	    }
358
	    this.searchQuery[this.options.config.namespace + '[sortBy]'] = sorter.dataset.sorter;
359
	    this.updateListing();
360
	};
361
362
	Listing.prototype.performFilters = function (e) {
363
	    if (e.target.tagName && e.target.tagName === "INPUT" && (e.which ? e.which : e.keyCode) !== 13) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
364
	    this.searchQuery = this.getQueryParams();
365
	    if (e.target.value) {
366
	        if (typeof this.options.config.filters[e.target.name] === "undefined") {
367
	            this.searchQuery[this.options.config.namespace + '[filters][' + this.newFilterIndex() + ']'] = e.target.name;
368
	        }
369
	        this.searchQuery[this.options.config.namespace + '[values][' + e.target.name + ']'] = e.target.value;
370
	    } else {
371
	        this.clearFilter(e);
372
	    }
373
374
	    this.compactFilterIndexes();
375
	    this.clearPagination();
376
	    this.updateListing();
377
	};
378
379
	Listing.prototype.clearFilter = function (e) {
380
	    this.searchQuery = this.getQueryParams();
381
382
	    for (var key in this.searchQuery) {
383
	        if (this.searchQuery.hasOwnProperty(key) && this.searchRegexp.test(key) && this.searchQuery[key] === e.target.name) {
384
	            delete this.searchQuery[key];
385
	            break;
386
	        }
387
	    }
388
389
	    delete this.searchQuery[this.options.config.namespace + '[values][' + e.target.name + ']'];
390
	};
391
392
	/**
393
	 * Update filters' indexes to go in order without gaps. Expl: namespace[filter][2] => namespace[filter][0]
394
	 */
395
	Listing.prototype.compactFilterIndexes = function () {
396
	    var filtersObj = {},
397
	        i = 0;
398
399
	    for (var key in this.searchQuery) {
400
	        if (this.searchQuery.hasOwnProperty(key) && this.searchRegexp.test(key)) {
401
	            filtersObj[key] = this.searchQuery[key];
402
	            delete this.searchQuery[key];
403
	        }
404
	    }
405
406
	    for (key in filtersObj) {
407
	        if (filtersObj.hasOwnProperty(key)) {
408
	            this.searchQuery[key.substr(0, key.lastIndexOf('[') + 1) + i + key.substr(key.lastIndexOf(']'))] = filtersObj[key];
409
	            i++;
410
	        }
411
	    }
412
	};
413
414
	Listing.prototype.newFilterIndex = function () {
415
	    var i = 0,
416
	        index = null;
417
418
	    while (!index) {
419
	        if (this.searchQuery[this.options.config.namespace + '[filters][' + i + ']']) {
420
	            i++;
421
	        } else {
422
	            index = i;
423
	            break;
424
	        }
425
	    }
426
427
	    return index;
428
	};
429
430
	Listing.prototype.performPagination = function (pageNode) {
431
432
	    this.searchQuery = this.getQueryParams();
433
	    if (+pageNode.dataset.page === 1) {
434
	        this.clearPagination();
435
	    } else {
436
	        this.searchQuery[this.options.config.namespace + '[page]'] = pageNode.dataset.page;
437
	    }
438
439
	    this.updateListing();
440
	};
441
442
	Listing.prototype.performLimits = function () {
443
444
	    this.searchQuery = this.getQueryParams();
445
	    if (+this.els.limits.select.value === this.options.config.pagination.limits[0]) {
446
	        delete this.searchQuery[this.options.config.namespace + '[limit]'];
447
	    } else {
448
	        this.searchQuery[this.options.config.namespace + '[limit]'] = this.els.limits.select.value;
449
	    }
450
451
	    this.updateListing();
452
	};
453
454
	Listing.prototype.clearPagination = function () {
455
456
	    delete this.searchQuery[this.options.config.namespace + '[page]'];
457
	};
458
459
	Listing.prototype.getQueryParams = function (str) {
460
461
	    return str || document.location.search ? (str || document.location.search).replace(/(^\?)/, '').split("&").map(function (n) {
462
	        return n = n.split("="), this[n[0]] = n[1], this;
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
463
	    }.bind({}))[0] : {};
464
	};
465
466
	Listing.prototype.stringifyObject = function (obj) {
467
468
	    if (Object.getOwnPropertyNames(obj).length === 0) return "";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
469
470
	    var query = "?";
471
472
	    for (var key in obj) {
473
	        if (obj.hasOwnProperty(key)) {
474
	            query += key + '=' + obj[key] + "&";
475
	        }
476
	    }
477
478
	    return query.slice(0, -1);
479
	};
480
481
	Listing.prototype.updateListing = function () {
482
	    this.storeParams();
483
	    location.search = this.stringifyObject(this.searchQuery);
484
	};
485
486
	Listing.prototype.storeParams = function () {
487
	    var currentStore = JSON.parse(localStorage.getItem('spiral-listing') || '{}'),
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
488
	        currentListing = {};
489
490
	    currentListing[location.pathname] = this.stringifyObject(this.searchQuery);
491
492
	    Object.assign(currentStore, currentListing);
493
	    localStorage.setItem('spiral-listing', JSON.stringify(currentStore));
494
	};
495
496
	Listing.prototype.restoreParams = function () {
497
	    if (location.search) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
498
499
	    var currentStore = JSON.parse(localStorage.getItem('spiral-listing') || '{}');
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
500
	    if (currentStore[location.pathname]) location.search = currentStore[location.pathname];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
501
	};
502
503
	Listing.prototype.resetParams = function () {
504
	    var currentStore = JSON.parse(localStorage.getItem('spiral-listing') || '{}'),
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
505
	        currentListing = {};
0 ignored issues
show
Unused Code introduced by
The variable currentListing seems to be never used. Consider removing it.
Loading history...
506
	    if (currentStore[location.pathname]) delete currentStore[location.pathname];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
507
	    localStorage.setItem('spiral-listing', JSON.stringify(currentStore));
508
	    location.search = "";
509
	};
510
511
	Listing.prototype.addEventListeners = function () {
512
	    var that = this;
513
514
	    this._performSorting = function (e) {
515
	        that.performSorting(e.target);
516
	    };
517
	    this._performFilters = function (e) {
518
	        that.performFilters(e);
519
	    };
520
	    this._performPagination = function (e) {
521
	        that.performPagination(e.target);
522
	    };
523
	    this._performLimits = function () {
524
	        that.performLimits();
525
	    };
526
527
	    this._resetParams = function () {
528
	        that.resetParams();
529
	    };
530
531
	    if (this.els.sorters) {
532
	        for (var i = 0; i < this.els.sorters.length; ++i) {
533
	            this.els.sorters[i].addEventListener('click', that._performSorting);
534
	        }
535
	    }
536
537
	    if (this.els.reset) {
538
	        this.els.reset.addEventListener('click', that._resetParams);
539
	    }
540
541
	    if (this.els.pagination && this.els.pagination.activePages) {
542
	        for (var _i2 = 0; _i2 < this.els.pagination.activePages.length; ++_i2) {
543
	            this.els.pagination.activePages[_i2].addEventListener('click', that._performPagination);
544
	        }
545
	    }
546
547
	    if (this.els.form) {
548
549
	        [].forEach.call(this.els.form.querySelectorAll('select'), function (el) {
550
	            el.addEventListener('change', that._performFilters);
551
	            if (jQuery && typeof jQuery('select').material_select === "function") jQuery(el).on('change', that._performFilters); //just to make it work with materialize
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
552
	        });
553
554
	        [].forEach.call(this.els.form.querySelectorAll('input:not(.js-sf-autocomplete)'), function (el) {
555
	            el.addEventListener('keydown', that._performFilters);
556
	        });
557
558
	        [].forEach.call(this.els.form.querySelectorAll('input.js-sf-autocomplete'), function (el) {
559
	            var autocomplete = _sf2.default.getInstance('autocomplete', el);
560
	            autocomplete.retrieveValueByKey();
561
	            if (!autocomplete || !autocomplete.events) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
562
563
	            autocomplete.events.on("select", function (instance) {
564
	                var autocompleteData = {
565
	                    target: {
566
	                        name: instance.els.hidden.name,
567
	                        value: instance.els.hidden.value
568
	                    }
569
	                };
570
	                that._performFilters(autocompleteData);
571
	            });
572
	            autocomplete.events.on("clear", function (instance) {
573
	                var autocompleteData = {
574
	                    target: {
575
	                        name: instance.els.hidden.name,
576
	                        value: ""
577
	                    }
578
	                };
579
	                that._performFilters(autocompleteData);
580
	            });
581
	        });
582
	    }
583
584
	    if (this.els.limits) {
585
	        this.els.limits.select.addEventListener('change', that._performLimits);
586
	    }
587
	};
588
589
	Listing.prototype.removeEventListeners = function () {
590
	    var that = this;
591
592
	    if (this.els.sorters) {
593
	        for (var i = 0; i < this.els.sorters.length; ++i) {
594
	            this.els.sorters[i].removeEventListeners('click', that._performSorting);
595
	        }
596
	    }
597
598
	    if (this.els.pagination && this.els.pagination.activePages) {
599
	        for (var _i3 = 0; _i3 < this.els.pagination.activePages.length; ++_i3) {
600
	            this.els.pagination.activePages[_i3].removeEventListener('click', that._performPagination);
601
	        }
602
	    }
603
604
	    if (this.els.limits) {
605
	        this.els.limits.select.removeEventListener('change', that._performLimits);
606
	    }
607
608
	    if (this.els.form) {
609
610
	        [].forEach.call(this.els.form.querySelectorAll('select'), function (el) {
611
	            el.removeEventListeners('change', that._performFilters);
612
	        });
613
614
	        [].forEach.call(this.els.form.querySelectorAll('input'), function (el) {
615
	            el.removeEventListeners('keydown', that._performFilters);
616
	        });
617
	    }
618
	};
619
620
	Listing.prototype.die = function () {
621
	    this.removeEventListeners();
622
	    delete this;
623
	};
624
625
	module.exports = Listing;
626
627
/***/ },
628
629
/***/ 164:
630
/***/ function(module, exports, __webpack_require__) {
631
632
	// style-loader: Adds some css to the DOM by adding a <style> tag
633
634
	// load the styles
635
	var content = __webpack_require__(165);
636
	if(typeof content === 'string') content = [[module.id, content, '']];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
637
	// add the styles to the DOM
638
	var update = __webpack_require__(167)(content, {});
639
	if(content.locals) module.exports = content.locals;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
640
	// Hot Module Replacement
641
	if(false) {
642
		// When the styles change, update the <style> tags
643
		if(!content.locals) {
644
			module.hot.accept("!!./../../../node_modules/css-loader/index.js?minimize!./../../../node_modules/less-loader/index.js!./listing.less", function() {
645
				var newContent = require("!!./../../../node_modules/css-loader/index.js?minimize!./../../../node_modules/less-loader/index.js!./listing.less");
646
				if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
647
				update(newContent);
648
			});
649
		}
650
		// When the module is disposed, remove the <style> tags
651
		module.hot.dispose(function() { update(); });
652
	}
653
654
/***/ },
655
656
/***/ 165:
657
/***/ function(module, exports, __webpack_require__) {
658
659
	exports = module.exports = __webpack_require__(166)();
660
	// imports
661
662
663
	// module
664
	exports.push([module.id, ".js-sf-listing [data-sorter]{cursor:pointer;white-space:nowrap}.js-sf-listing [data-sorter] i{pointer-events:none}.js-sf-listing [data-sorter]:hover{background-color:#f2f2f2}.js-sf-listing-search i{position:absolute;line-height:38px;left:17px}.js-sf-listing-search input{padding-left:30px}.js-sf-listing-pagination li:first-child{border:none}.js-sf-listing-pagination li a{pointer-events:none}.js-sf-listing-pagination li i{font-size:.65rem}.js-sf-listing-pagination li i.stacked:before{margin:-.25em}.js-sf-listing-limits.stacked-right{margin-bottom:-50px;bottom:70px}.js-sf-listing-limits .label{position:absolute;left:-45px;line-height:38px}.listing-form .item-state-search .btn-icon{top:3px}.listing-form .btn-icon{height:100%;bottom:0;top:0}.listing-form .btn-icon:focus{background-color:transparent}", ""]);
665
666
	// exports
667
668
669
/***/ },
670
671
/***/ 166:
672
/***/ function(module, exports) {
673
674
	"use strict";
675
676
	/*
677
		MIT License http://www.opensource.org/licenses/mit-license.php
678
		Author Tobias Koppers @sokra
679
	*/
680
	// css base code, injected by the css-loader
681
	module.exports = function () {
682
		var list = [];
683
684
		// return the list of modules as css string
685
		list.toString = function toString() {
686
			var result = [];
687
			for (var i = 0; i < this.length; i++) {
688
				var item = this[i];
689
				if (item[2]) {
690
					result.push("@media " + item[2] + "{" + item[1] + "}");
691
				} else {
692
					result.push(item[1]);
693
				}
694
			}
695
			return result.join("");
696
		};
697
698
		// import a list of modules into the list
699
		list.i = function (modules, mediaQuery) {
700
			if (typeof modules === "string") modules = [[null, modules, ""]];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
701
			var alreadyImportedModules = {};
702
			for (var i = 0; i < this.length; i++) {
703
				var id = this[i][0];
704
				if (typeof id === "number") alreadyImportedModules[id] = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
705
			}
706
			for (i = 0; i < modules.length; i++) {
707
				var item = modules[i];
708
				// skip already imported module
709
				// this implementation is not 100% perfect for weird media query combinations
710
				//  when a module is imported multiple times with different media queries.
711
				//  I hope this will never occur (Hey this way we have smaller bundles)
712
				if (typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
713
					if (mediaQuery && !item[2]) {
714
						item[2] = mediaQuery;
715
					} else if (mediaQuery) {
716
						item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
717
					}
718
					list.push(item);
719
				}
720
			}
721
		};
722
		return list;
723
	};
724
725
/***/ },
726
727
/***/ 167:
728
/***/ function(module, exports, __webpack_require__) {
0 ignored issues
show
Unused Code introduced by
The parameter __webpack_require__ is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
729
730
	/*
731
		MIT License http://www.opensource.org/licenses/mit-license.php
732
		Author Tobias Koppers @sokra
733
	*/
734
	var stylesInDom = {},
735
		memoize = function(fn) {
736
			var memo;
737
			return function () {
738
				if (typeof memo === "undefined") memo = fn.apply(this, arguments);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
739
				return memo;
0 ignored issues
show
Bug introduced by
The variable memo does not seem to be initialized in case typeof memo === "undefined" on line 738 is false. Are you sure this can never be the case?
Loading history...
740
			};
741
		},
742
		isOldIE = memoize(function() {
743
			return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase());
744
		}),
745
		getHeadElement = memoize(function () {
746
			return document.head || document.getElementsByTagName("head")[0];
747
		}),
748
		singletonElement = null,
749
		singletonCounter = 0,
750
		styleElementsInsertedAtTop = [];
751
752
	module.exports = function(list, options) {
753
		if(false) {
754
			if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
755
		}
756
757
		options = options || {};
758
		// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
759
		// tags it will allow on a page
760
		if (typeof options.singleton === "undefined") options.singleton = isOldIE();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
761
762
		// By default, add <style> tags to the bottom of <head>.
763
		if (typeof options.insertAt === "undefined") options.insertAt = "bottom";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
764
765
		var styles = listToStyles(list);
766
		addStylesToDom(styles, options);
767
768
		return function update(newList) {
769
			var mayRemove = [];
770
			for(var i = 0; i < styles.length; i++) {
771
				var item = styles[i];
772
				var domStyle = stylesInDom[item.id];
773
				domStyle.refs--;
774
				mayRemove.push(domStyle);
775
			}
776
			if(newList) {
777
				var newStyles = listToStyles(newList);
778
				addStylesToDom(newStyles, options);
779
			}
780
			for(var i = 0; i < mayRemove.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 770. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
781
				var domStyle = mayRemove[i];
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable domStyle already seems to be declared on line 772. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
782
				if(domStyle.refs === 0) {
783
					for(var j = 0; j < domStyle.parts.length; j++)
784
						domStyle.parts[j]();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
785
					delete stylesInDom[domStyle.id];
786
				}
787
			}
788
		};
789
	}
790
791
	function addStylesToDom(styles, options) {
792
		for(var i = 0; i < styles.length; i++) {
793
			var item = styles[i];
794
			var domStyle = stylesInDom[item.id];
795
			if(domStyle) {
796
				domStyle.refs++;
797
				for(var j = 0; j < domStyle.parts.length; j++) {
798
					domStyle.parts[j](item.parts[j]);
799
				}
800
				for(; j < item.parts.length; j++) {
801
					domStyle.parts.push(addStyle(item.parts[j], options));
802
				}
803
			} else {
804
				var parts = [];
805
				for(var j = 0; j < item.parts.length; j++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable j already seems to be declared on line 797. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
806
					parts.push(addStyle(item.parts[j], options));
807
				}
808
				stylesInDom[item.id] = {id: item.id, refs: 1, parts: parts};
809
			}
810
		}
811
	}
812
813
	function listToStyles(list) {
814
		var styles = [];
815
		var newStyles = {};
816
		for(var i = 0; i < list.length; i++) {
817
			var item = list[i];
818
			var id = item[0];
819
			var css = item[1];
820
			var media = item[2];
821
			var sourceMap = item[3];
822
			var part = {css: css, media: media, sourceMap: sourceMap};
823
			if(!newStyles[id])
824
				styles.push(newStyles[id] = {id: id, parts: [part]});
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
825
			else
826
				newStyles[id].parts.push(part);
827
		}
828
		return styles;
829
	}
830
831
	function insertStyleElement(options, styleElement) {
832
		var head = getHeadElement();
833
		var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1];
834
		if (options.insertAt === "top") {
835
			if(!lastStyleElementInsertedAtTop) {
836
				head.insertBefore(styleElement, head.firstChild);
837
			} else if(lastStyleElementInsertedAtTop.nextSibling) {
838
				head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling);
839
			} else {
840
				head.appendChild(styleElement);
841
			}
842
			styleElementsInsertedAtTop.push(styleElement);
843
		} else if (options.insertAt === "bottom") {
844
			head.appendChild(styleElement);
845
		} else {
846
			throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");
847
		}
848
	}
849
850
	function removeStyleElement(styleElement) {
851
		styleElement.parentNode.removeChild(styleElement);
852
		var idx = styleElementsInsertedAtTop.indexOf(styleElement);
853
		if(idx >= 0) {
854
			styleElementsInsertedAtTop.splice(idx, 1);
855
		}
856
	}
857
858
	function createStyleElement(options) {
859
		var styleElement = document.createElement("style");
860
		styleElement.type = "text/css";
861
		insertStyleElement(options, styleElement);
862
		return styleElement;
863
	}
864
865
	function createLinkElement(options) {
866
		var linkElement = document.createElement("link");
867
		linkElement.rel = "stylesheet";
868
		insertStyleElement(options, linkElement);
869
		return linkElement;
870
	}
871
872
	function addStyle(obj, options) {
873
		var styleElement, update, remove;
874
875
		if (options.singleton) {
876
			var styleIndex = singletonCounter++;
877
			styleElement = singletonElement || (singletonElement = createStyleElement(options));
878
			update = applyToSingletonTag.bind(null, styleElement, styleIndex, false);
0 ignored issues
show
Unused Code introduced by
The call to bind does not seem necessary since the function applyToSingletonTag declared on line 923 does not use this.
Loading history...
879
			remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true);
0 ignored issues
show
Unused Code introduced by
The call to bind does not seem necessary since the function applyToSingletonTag declared on line 923 does not use this.
Loading history...
880
		} else if(obj.sourceMap &&
881
			typeof URL === "function" &&
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
882
			typeof URL.createObjectURL === "function" &&
883
			typeof URL.revokeObjectURL === "function" &&
884
			typeof Blob === "function" &&
0 ignored issues
show
Bug introduced by
The variable Blob seems to be never declared. If this is a global, consider adding a /** global: Blob */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
885
			typeof btoa === "function") {
0 ignored issues
show
Bug introduced by
The variable btoa seems to be never declared. If this is a global, consider adding a /** global: btoa */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
886
			styleElement = createLinkElement(options);
887
			update = updateLink.bind(null, styleElement);
0 ignored issues
show
Unused Code introduced by
The call to bind does not seem necessary since the function updateLink declared on line 958 does not use this.
Loading history...
888
			remove = function() {
889
				removeStyleElement(styleElement);
890
				if(styleElement.href)
891
					URL.revokeObjectURL(styleElement.href);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
892
			};
893
		} else {
894
			styleElement = createStyleElement(options);
895
			update = applyToTag.bind(null, styleElement);
0 ignored issues
show
Unused Code introduced by
The call to bind does not seem necessary since the function applyToTag declared on line 940 does not use this.
Loading history...
896
			remove = function() {
897
				removeStyleElement(styleElement);
898
			};
899
		}
900
901
		update(obj);
902
903
		return function updateStyle(newObj) {
904
			if(newObj) {
905
				if(newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap)
906
					return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
907
				update(obj = newObj);
908
			} else {
909
				remove();
910
			}
911
		};
912
	}
913
914
	var replaceText = (function () {
915
		var textStore = [];
916
917
		return function (index, replacement) {
918
			textStore[index] = replacement;
919
			return textStore.filter(Boolean).join('\n');
920
		};
921
	})();
922
923
	function applyToSingletonTag(styleElement, index, remove, obj) {
924
		var css = remove ? "" : obj.css;
925
926
		if (styleElement.styleSheet) {
927
			styleElement.styleSheet.cssText = replaceText(index, css);
928
		} else {
929
			var cssNode = document.createTextNode(css);
930
			var childNodes = styleElement.childNodes;
931
			if (childNodes[index]) styleElement.removeChild(childNodes[index]);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
932
			if (childNodes.length) {
933
				styleElement.insertBefore(cssNode, childNodes[index]);
934
			} else {
935
				styleElement.appendChild(cssNode);
936
			}
937
		}
938
	}
939
940
	function applyToTag(styleElement, obj) {
941
		var css = obj.css;
942
		var media = obj.media;
943
944
		if(media) {
945
			styleElement.setAttribute("media", media)
946
		}
947
948
		if(styleElement.styleSheet) {
949
			styleElement.styleSheet.cssText = css;
950
		} else {
951
			while(styleElement.firstChild) {
952
				styleElement.removeChild(styleElement.firstChild);
953
			}
954
			styleElement.appendChild(document.createTextNode(css));
955
		}
956
	}
957
958
	function updateLink(linkElement, obj) {
959
		var css = obj.css;
960
		var sourceMap = obj.sourceMap;
961
962
		if(sourceMap) {
963
			// http://stackoverflow.com/a/26603875
964
			css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + " */";
965
		}
966
967
		var blob = new Blob([css], { type: "text/css" });
0 ignored issues
show
Bug introduced by
The variable Blob seems to be never declared. If this is a global, consider adding a /** global: Blob */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
968
969
		var oldSrc = linkElement.href;
970
971
		linkElement.href = URL.createObjectURL(blob);
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
972
973
		if(oldSrc)
974
			URL.revokeObjectURL(oldSrc);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
975
	}
976
977
978
/***/ }
979
980
/******/ });