From 97d2ea7f877c59fcbd72310579f8f5bda6eee573 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 30 Oct 2015 13:04:55 +0800 Subject: [PATCH 1/2] MDL-51970 autocomplete: Add an option to hide the suggestions This is used by tags when official tags are disabled. --- lib/amd/build/form-autocomplete.min.js | 2 +- lib/amd/src/form-autocomplete.js | 72 +++++++++++-------- lib/form/autocomplete.php | 8 ++- lib/form/tags.php | 1 + .../form_autocomplete_input.mustache | 5 ++ 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/lib/amd/build/form-autocomplete.min.js b/lib/amd/build/form-autocomplete.min.js index c3b3a5ff12b..22d47c943c6 100644 --- a/lib/amd/build/form-autocomplete.min.js +++ b/lib/amd/build/form-autocomplete.min.js @@ -1 +1 @@ -define(["jquery","core/log","core/str","core/templates","core/notification"],function(a,b,c,d,e){var f={DOWN:40,ENTER:13,SPACE:32,ESCAPE:27,COMMA:188,UP:38},g=null,h=function(b,c){var d=a(document.getElementById(c)),e=d.children("[aria-selected=true]").length;for(b%=e;0>b;)b+=e;var f=a(d.children("[aria-selected=true]").get(b)),g=c+"-"+b;d.children().attr("data-active-selection",!1).attr("id",""),f.attr("data-active-selection",!0).attr("id",g),d.attr("aria-activedescendant",g)},i=function(b,c,d,e,f){var g=a(d).attr("data-value");f&&e.children("option").each(function(b,c){a(c).attr("value")==g&&(a(c).prop("selected",!1),a(c).attr("data-iscustom")&&a(c).remove())}),r(c,b,e,f)},j=function(b,c,d){var e=a(document.getElementById(c)),f=a(document.getElementById(d)),g=f.children("[aria-hidden=false]").length;for(b%=g;0>b;)b+=g;var h=a(f.children("[aria-hidden=false]").get(b)),i=a(f.children("[role=option]")).index(h),j=d+"-"+i;f.children().attr("aria-selected",!1).attr("id",""),h.attr("aria-selected",!0).attr("id",j),e.attr("aria-activedescendant",j);var k=h.offset().top-f.offset().top+f.scrollTop()-f.height()/2;f.animate({scrollTop:k},100)},k=function(b,c){var d=a(document.getElementById(c)),e=d.children("[aria-selected=true]"),f=d.children("[aria-hidden=false]").index(e);j(f+1,b,c)},l=function(b){var c=a(document.getElementById(b)),d=c.children("[data-active-selection=true]");if(!d)return void h(0,b);var e=c.children("[aria-selected=true]").index(d);h(e-1,b)},m=function(b){var c=a(document.getElementById(b)),d=c.children("[data-active-selection=true]");if(!d)return void h(0,b);var e=c.children("[aria-selected=true]").index(d);h(e+1,b)},n=function(b,c){var d=a(document.getElementById(c)),e=d.children("[aria-selected=true]"),f=d.children("[aria-hidden=false]").index(e);j(f-1,b,c)},o=function(b,c,d){var e=a(document.getElementById(b)),f=a(document.getElementById(c));e.attr("aria-expanded",!1).attr("aria-activedescendant",d),f.hide().attr("aria-hidden",!0)},p=function(b,f,g,h,i,k,l){var m=a(document.getElementById(f)),n=a(document.getElementById(g)),o=!1,p=[];h.children("option").each(function(b,c){a(c).prop("selected")!==!0&&(p[p.length]={label:c.innerHTML,value:a(c).attr("value")})});var q=l?b:b.toLocaleLowerCase();d.render("core/form_autocomplete_suggestions",{inputId:f,suggestionsId:g,options:p,multiple:i}).done(function(b){n.replaceWith(b),n=a(document.getElementById(g)),n.show().attr("aria-hidden",!1),n.children().each(function(b,c){c=a(c),l&&c.text().indexOf(q)>-1||!l&&c.text().toLocaleLowerCase().indexOf(q)>-1?(c.show().attr("aria-hidden",!1),o=!0):c.hide().attr("aria-hidden",!0)}),m.attr("aria-expanded",!0),o?k||j(0,f,g):c.get_string("nosuggestions","form").done(function(a){n.html(a)})}).fail(e.exception)},q=function(b,c,d,e,f){var g=a(document.getElementById(b)),h=g.val(),i=h.split(","),j=!1;a.each(i,function(b,c){if(c=c.trim(),""!==c&&(e||f.children("option").prop("selected",!1),f.children("option").each(function(b,d){a(d).attr("value")==c&&(j=!0,a(d).prop("selected",!0))}),!j)){var d=a("