(function($){ window.initializeFilters = function() { // Bail early for Konqueror and IE5.2/Mac, which don't fully support dynamic // creation of form controls try { var test = document.createElement("input"); test.type = "button"; if (test.type != "button") throw Error(); } catch (e) { return; } // Removes an existing row from the filters table function removeRow(button, propertyName) { var tr = getAncestorByTagName(button, "tr"); var mode = null; var selects = tr.getElementsByTagName("select"); for (var i = 0; i < selects.length; i++) { if (selects[i].name == propertyName + "_mode") { mode = selects[i]; break; } } if (mode && (getAncestorByTagName(mode, "tr") == tr)) { // Check whether there are more 'or' rows for this filter var next = tr.nextSibling; if (next && (next.className == propertyName)) { function getChildElementAt(e, idx) { e = e.firstChild; var cur = 0; while (cur <= idx) { while (e && e.nodeType != 1) e = e.nextSibling; if (cur++ == idx) break; e = e.nextSibling; } return e; } var thisTh = getChildElementAt(tr, 0); var nextTh = getChildElementAt(next, 0); next.insertBefore(thisTh, nextTh); nextTh.colSpan = 1; thisTd = getChildElementAt(tr, 0); nextTd = getChildElementAt(next, 1); next.replaceChild(thisTd, nextTd); } } var tBody = tr.parentNode; tBody.deleteRow(tr.sectionRowIndex); if (!tBody.rows.length) { tBody.parentNode.removeChild(tBody); } if (propertyName) { var select = document.forms["query"].elements["add_filter"]; for (var i = 0; i < select.options.length; i++) { var option = select.options[i]; if (option.value == propertyName) option.disabled = false; } } } // Initializes a filter row, the 'input' parameter is the submit // button for removing the filter function initializeFilter(input) { var removeButton = document.createElement("input"); removeButton.type = "button"; removeButton.value = input.value; if (input.name.substr(0, 10) == "rm_filter_") { removeButton.onclick = function() { var endIndex = input.name.search(/_\d+$/); if (endIndex < 0) endIndex = input.name.length; removeRow(removeButton, input.name.substring(10, endIndex)); return false; } } else { removeButton.onclick = function() { removeRow(removeButton); return false; } } input.parentNode.replaceChild(removeButton, input); } // Make the submit buttons for removing filters client-side triggers var filters = document.getElementById("filters"); var inputs = filters.getElementsByTagName("input"); for (var i = 0; i < inputs.length; i++) { var input = inputs[i]; if (input.type == "submit" && input.name && input.name.match(/^rm_filter_/)) { initializeFilter(input); } } // Make the drop-down menu for adding a filter a client-side trigger var addButton = document.forms["query"].elements["add"]; addButton.parentNode.removeChild(addButton); var select = document.getElementById("add_filter"); select.onchange = function() { if (select.selectedIndex < 1) return; if (select.options[select.selectedIndex].disabled) { // Neither IE nor Safari supported disabled options at the time this was // written, so alert the user alert("A filter already exists for that property"); return; } // Convenience function for creating a