More actions
(add JS to create dropdown filters) |
m (try hiding unselected elements instead) Tags: mobile edit mobile web edit |
||
Line 84: | Line 84: | ||
if (element.nodeName == "DIV") { | if (element.nodeName == "DIV") { | ||
if (!applyFilter) { | if (!applyFilter) { | ||
element.style. | element.style.display = "none"; | ||
} else { | } else { | ||
element.style. | element.style.display = "inline-block"; | ||
} | } | ||
} | } | ||
Line 95: | Line 95: | ||
for (var i = 0; i < elementsToFilter.length; i++) { | for (var i = 0; i < elementsToFilter.length; i++) { | ||
if (elementsToFilter[i].nodeName == "DIV") { | if (elementsToFilter[i].nodeName == "DIV") { | ||
elementsToFilter[i].style.opacity = " | elementsToFilter[i].style.opacity = "inline-block"; | ||
} | } | ||
} | } | ||
} | } |
Revision as of 06:21, 3 September 2018
/* Any JavaScript here will be loaded for users using the mobile site */
// For filtering items
var elementsToFilter = {};
var gameSelectOptions = '{ \
"name":"gameSelect",\
"attribute":"data-game",\
"options":[ \
["Game", ""],\
["BBCT", ""],\
["BBCS", ""],\
["BBCSEX", ""],\
["BBCP", ""],\
["BBCPEX", ""],\
["BBCF", ""],\
["BBTAG", ""]\
]\
}';
$(document).ready(function() {
// For filtering items
elementsToFilter = document.getElementsByClassName("filter-element");
createDropdownSelects();
});
function createDropdownSelects() {
var selectRowElement = document.getElementById("selectRow");
if (!selectRowElement) {
return;
}
selectRowElement.setAttribute("style", "padding: 6px;");
var gameSelect = document.getElementById('gameSelectDiv');
createDropdownSelect(gameSelect, gameSelectOptions);
}
function createDropdownSelect(dropdownDiv, optionList) {
var i = 0;
var dropdown = JSON.parse(optionList);
var html = "<select id=\"" + dropdown.name + "\" name=\"" + dropdown.name + "\" class=\"form-control\" onchange=\"filter('" + dropdown.name + "','" + dropdown.attribute + "'" + ")\">";
for (i; i < dropdown.options.length; i++) {
html += "<option ";
if (i === 0) {
html += "selected=\"selected\"";
}
if (dropdown.options[i][1] !== "") {
html += "disabled=\"" + dropdown.options[i][1] + "\"";
}
html += "value=\"" + dropdown.options[i][0] + "\">"
+ dropdown.options[i][0] + "</option>";
}
dropdownDiv.innerHTML += html;
}
// Check each row to see if it is in the filter
// Filters only one dropdown
function filter(filterDiv, attribute) {
resetFiltersApplied();
var filterValue = document.getElementById(filterDiv).value;
// Go through all the hero grid icons
for (var i = 0; i < elementsToFilter.length; i++) {
var data = elementsToFilter[i].getAttribute(attribute);
var words = data.split(' ');
var showRow = false;
for (var w in words) {
showRow = showRow || (words[w] == filterValue);
// console.log(filterValue + " " + words[w] + " " + showRow);
}
// Apply the filter
applyFilterAction(elementsToFilter[i], showRow);
}
}
// This method handlecs the CSS changes if an icon/row matches the filter
function applyFilterAction(element, applyFilter) {
if (element.nodeName == "DIV") {
if (!applyFilter) {
element.style.display = "none";
} else {
element.style.display = "inline-block";
}
}
}
// Reset any filters applied to elements.
function resetFiltersApplied() {
for (var i = 0; i < elementsToFilter.length; i++) {
if (elementsToFilter[i].nodeName == "DIV") {
elementsToFilter[i].style.opacity = "inline-block";
}
}
}