function applyFilter(thisdir) { var pattern = prepareSearchPattern(); var translations = jQuery.parseJSON(localStorage.getItem('CSTRtrans')).translations; updateDisplay(pattern, translations); filterTableElements(pattern); filterOtherElements(pattern, translations, thisdir); } // called everytime the user makes an input into the search field function updateDisplay(pattern, translations) { var header1 = document.getElementById('searchtitle'); if (pattern.source == '(?:)'){ header1.style.display = 'none'; } else { // remove escape symbol for better readability header1.innerHTML = translations.results+' '+pattern.source.replace('\\',''); header1.style.display = ''; } } // filters the contents table of the authoring space to only show matching resources in the current dir function filterTableElements(pattern) { var list = document.getElementsByClassName('LC_data_table')[0].childNodes[1].children; // i=2 to skip searchtitle and header for (var i = 2; i < list.length; i++){ // get filename: table column, , , name var resname = list[i].children[2].children[0].children[0].innerHTML; var restitle; // check if resource has title and get it var titleColumn = list[i].children[3].children; if (titleColumn.length > 2){ restitle = titleColumn[0].innerHTML; } else { restitle = ''; } // match in filename OR resource title OR if search string is empty if ( pattern.test(resname) || pattern.test(restitle) || pattern.source == '' ){ list[i].style.display = ''; // show element } else { list[i].style.display = 'none'; // hide element } } } // this is the search function for resources in other locations. // pattern - the search pattern given by the user // translations - loncapa generated translation object for the user interface // thisdir - dir the user is currently in, used to generate relativ links for found files function filterOtherElements (pattern, translations, thisdir) { var otherfiles = jQuery.parseJSON(sessionStorage.getItem('CSTRcache')).resources; if (pattern.source == '(?:)'){ document.getElementById('otherplaces').style.display = 'none'; return; } var hits = new Array(); for (var i = 0; i < otherfiles.length; i++){ if (otherfiles[i].title == '[untitled]'){ otherfiles[i].title = ''; } if ( pattern.test(otherfiles[i].name) || pattern.test(otherfiles[i].title) ){ hits.push(otherfiles[i]); } } if (hits.length < 1){ document.getElementById('otherplaces').style.display = 'none'; } else { document.getElementById('otherplaces').style.display = ''; var element = document.getElementsByName("otherplacescontent"); // remove all old children for (index = element.length - 1; index >= 0; index--){ element[index].parentNode.removeChild(element[index]); } // add new children for (var i = 0; i < hits.length; i ++){ document.getElementById('otherplacestable').parentNode.appendChild(renderRow(hits[i], i, translations, thisdir)); } } } // adds an row to the other places result table, used by filterOtherElements() function renderRow(element, i, translations, thisdir) { var isdir = false; var row = ''; // icon row += '