'use strict';
require('jsdom-global')();
const renderElement = (html) => {
const temp = document.createElement('div');
temp.innerHTML = html;
return temp.firstElementChild;
};
module.exports = {
getContainer() {
return renderElement('
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
');
},
getEmptyContainer() {
return renderElement('');
},
getFilterControls() {
return renderElement('' +
'
All
' +
'
None
' +
'
Category A
' +
'
Category B
' +
'
Category C
' +
'
Category D
' +
'
Category A OR B
' +
'
Category A AND C
' +
'
Category A (attribute)
' +
'
Category A OR B (attribute)
' +
'
Category A AND C (attribute)
' +
'
Category A
' +
'
Category B
' +
'
Category C
' +
'
');
},
getFilterControl() {
return renderElement('Category D
');
},
getToggleControl() {
return renderElement('Category B
');
},
getSortControl() {
return renderElement('Views (desc) Published (asc)
');
},
getSortControls() {
return renderElement('' +
'
Default
' +
'
Default Ascending
' +
'
Default Descending
' +
'
Random
' +
'
Published Date
' +
'
Views
' +
'
Published (asc) Views (desc)
' +
'
');
},
getMultimixControls() {
return renderElement('' +
'
All / Default
' +
'
Category B / Published
' +
'
');
},
getTotalWhitespace(html) {
let re = /[>? ]( )[ ]/g;
let totalWhitespace = 0;
let matches;
while (matches = re.exec(html)) {
totalWhitespace++;
}
return totalWhitespace;
},
Item: class Item {
constructor(data) {
this.id = typeof data !== 'undefined' ? data.id : undefined;
this.categories = Array.prototype.slice.call(data.categories) || [];
this.published = typeof data.published === 'string' ? data.published : '';
this.views = typeof data.views === 'number' ? data.views : 0;
Object.seal(this);
}
get classList() {
return 'mix ' + this.categories.map(category => 'category-' + category).join(' ');
}
get categoryList() {
return this.categories.join(' ');
}
},
ITEM_TEMPLATE: '',
ITEM_TEMPLATE_ALT: ''
};