javascript - Only show YUI autocomplete footer when there are 5 results -
i autocomplete display footer says displaying top 5 results
when there 5 results being displayed.
so far, have set won't display if @ first there less 5 results, once 5 results have been loaded footer displays, regardless of how many results being displayed.
please excuse silly flip
gimmick.
oac.formatresult = function(oresultdata, squery, sresultmatch) { var skey = sresultmatch // extract part of match user did not type var skeyremainder = skey.substr(squery.length); oac.setfooter(""); var amarkup = ["<div class='mycustomresult'>", "<span style='font-weight:bold'>", squery, "</span>", skeyremainder, "<br>", "</div>"]; if (oresultdata[2] >= 4) { flip = true; } if (flip) { oac.setfooter("<div style=\"margin-left:5px;\"><span style=\"font-weight:bold;\">see more results " + squery + "</span><br>showing top 5 results</div>"); } return (amarkup.join("")); };
instead of trying set in formatresult
function, tried using dobeforeexpandcontainer
function, , works charm.
oac.formatresult = function(oresultdata, squery, sresultmatch) { var skey = sresultmatch // extract part of match user did not type var skeyremainder = skey.substr(squery.length); oac.setfooter(""); var amarkup = ["<div class='mycustomresult'>", "<span style='font-weight:bold'>", squery, "</span>", skeyremainder, "<br>", "</div>"]; oac.setfooter("<div class=\"ac-footer\"><div class=\"ac-footer-content\"><a class=\"ac-footer-link\" href=\"#\" onclick=\"spandex(this,event,'filter-company');return false;\">see more results <b>" + squery + "</b></a><br><span class=\"ac-footer-sub\">showing top 5 results</span></div></div>"); return (amarkup.join("")); }; oac.dobeforeexpandcontainer = function(squery, oresponse) { if (oac._ndisplayeditems <= 5) { oac.setfooter(""); } return true; }
dobeforeexpandcontainer
called every time container opens (just expect to) , _ndisplayeditems
how many items going displayed in list (also expect).
so when results retrieved, footer added every time. then, before box shows, if there 5 or less results, footer removed.
Comments
Post a Comment