diff --git a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js index b4659ac9..8f9d6233 100644 --- a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js +++ b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js @@ -109,6 +109,7 @@ var InputfieldPageAutocomplete = { // AND words mode term = term.replace(/\s+/, ','); } + term = encodeURIComponent(term); var ajaxURL = url + '&' + searchField + operator + term; $.getJSON(ajaxURL, function(data) { diff --git a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.min.js b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.min.js index 0435b908..e0b44c5f 100644 --- a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.min.js +++ b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.min.js @@ -1 +1 @@ -var InputfieldPageAutocomplete={init:function(r,e,i,q,k){var f=$("#"+r);var l=$("#"+r+"_items");var c=$("#"+r+"_input");var a=c.parent().find(".InputfieldPageAutocompleteStatus");var j=c.parent().find(".InputfieldPageAutocompleteNote");var h=0;var n=0;var s=c.attr("data-disablechars");var b=c.hasClass("no_list");var m=a.height();if(m){var g=a.parent().height();var o=((g-m)/2);a.css("top",o+"px");a.css("left",(o/2)+"px")}else{}function p(w){if(!s||!s.length){return false}var v=false;for(var x=0;x-1){v=true;break}}return v}if(b){c.attr("data-selectedLabel",c.val());var d=c.siblings(".InputfieldPageAutocompleteRemove");d.click(function(){f.val("").change();c.val("").attr("placeholder","").attr("data-selectedLabel","").change().focus();c.trigger("keydown")});c.change(function(){if($(this).val().length==0){d.hide()}else{d.show()}});c.focus(function(){var v=f.val();if(!v.length){return}if(p(v)){return}if($(this).hasClass("added_item")){return}$(this).attr("placeholder",$(this).attr("data-selectedLabel"));$(this).val("")}).blur(function(){setTimeout(function(){},200)})}a.click(function(){c.focus()});a.attr("data-class",a.attr("class"));function u(){var v=$("#_"+r.replace("Inputfield_","")+"_add_items").size()>0;return v}c.autocomplete({minLength:2,source:function(x,v){var w=x.term;if(p(w)){v([]);return}a.attr("class","fa fa-fw fa-spin fa-spinner");if(c.hasClass("and_words")&&w.indexOf(" ")>0){w=w.replace(/\s+/,",")}var y=e+"&"+q+k+w;$.getJSON(y,function(z){a.attr("class",a.attr("data-class"));n=z.total;if(z.total>0){a.attr("class","fa fa-fw fa-angle-double-down")}else{if(u()){a.attr("class","fa fa-fw fa-plus-circle");j.show()}else{a.attr("class","fa fa-fw fa-frown-o")}}v($.map(z.matches,function(A){return{label:A[i],value:A[i],page_id:A.id}}))})},select:function(v,w){if(!w.item){return}var x=$(this);if(x.hasClass("no_list")){x.val(w.item.label).change();x.attr("data-selectedLabel",w.item.label);x.closest(".InputfieldPageAutocomplete").find(".InputfieldPageAutocompleteData").val(w.item.page_id).change();x.blur();return false}else{InputfieldPageAutocomplete.pageSelected(l,w.item);x.val("").focus();return false}}}).blur(function(){var v=$(this);a.attr("class",a.attr("data-class"));j.hide();if(v.hasClass("no_list")){if(f.val().length||v.val().length){if(v.hasClass("allow_any")||v.hasClass("added_item")){}else{v.val(v.attr("data-selectedLabel")).attr("placeholder","")}}else{v.val("").attr("placeholder","").attr("data-selectedLabel","")}}}).keyup(function(){a.attr("class",a.attr("data-class"))}).keydown(function(w){if(w.keyCode==13){w.preventDefault();if(u()){if($.trim(c.val()).length<1){c.blur();return false}h++;var x={page_id:(-1*h),label:c.val()};if(b){f.val(x.page_id);$("#_"+r.replace("Inputfield_","")+"_add_items").val(x.label);c.addClass("added_item").blur();var v=j.siblings(".InputfieldPageAutocompleteNoteAdd");if(!v.length){var v=$("
");j.after(v)}v.text(j.attr("data-adding")+" "+x.label);v.show()}else{InputfieldPageAutocomplete.pageSelected(l,x);c.val("").blur().focus()}j.hide()}else{$(this).blur()}return false}if(h&&b){var v=j.siblings(".InputfieldPageAutocompleteNoteAdd");var y=$("#_"+r.replace("Inputfield_","")+"_add_items");if(v.length&&y.val()!=$(this).val()){v.remove();f.val("");y.val("");$("#_"+r.replace("Inputfield_","")+"_add_items").val("");h--}}});var t=function(v){v.sortable({axis:"y",update:function(x,w){InputfieldPageAutocomplete.rebuildInput($(this))},start:function(x,w){w.item.addClass("ui-state-highlight")},stop:function(x,w){w.item.removeClass("ui-state-highlight")}});v.addClass("InputfieldPageAutocompleteSortable")};$("#"+l.attr("id")).on("mouseover",">li",function(){$(this).removeClass("ui-state-default").addClass("ui-state-hover");t(l)}).on("mouseout",">li",function(){$(this).removeClass("ui-state-hover").addClass("ui-state-default")})},initFromInputfield:function(a){var b=a.find(".InputfieldPageAutocompleteData");if(!b.length){return}if(b.hasClass("InputfieldPageAutocompleteInit")){return}InputfieldPageAutocomplete.init(b.attr("id"),b.attr("data-url"),b.attr("data-label"),b.attr("data-search"),b.attr("data-operator"));b.addClass("InputfieldPageAutocompleteInit")},pageSelected:function(a,d){var c=false;a.children("li").each(function(){var f=parseInt($(this).children(".itemValue").text());if(f==d.page_id){c=$(this)}});var b=$("#"+a.attr("data-id")+"_input");b.blur();if(c){c.effect("highlight");return}var e=a.children(".itemTemplate").clone();e.removeClass("itemTemplate");e.children(".itemValue").text(d.page_id);e.children(".itemLabel").text(d.label);a.append(e);InputfieldPageAutocomplete.rebuildInput(a)},rebuildInput:function(d){var b=d.attr("data-id");var a=d.attr("data-name");var f=$("#"+b);var h="";var c="";var g=parseInt(f.attr("data-max"));var i=d.children(":not(.itemTemplate)");if(g>0&&i.size()>g){while(i.size()>g){i=i.slice(1)}d.children(":not(.itemTemplate)").replaceWith(i)}i.each(function(){var j=parseInt($(this).children(".itemValue").text());if(j>0){h+=","+j}else{if(j<0){h+=","+j;c+=$(this).children(".itemLabel").text()+"\n"}}});f.val(h);var e=$("#_"+a+"_add_items");if(e.size()>0){e.val(c)}}};$(document).ready(function(){$(".InputfieldPageAutocomplete").each(function(){InputfieldPageAutocomplete.initFromInputfield($(this))});$(document).on("reloaded",".InputfieldPageAutocomplete, .InputfieldPage",function(){InputfieldPageAutocomplete.initFromInputfield($(this))});$(document).on("click",".InputfieldPageAutocomplete ol a.itemRemove",function(){var c=$(this).parent();var a=c.parent();var b=c.children(".itemValue").text();c.remove();InputfieldPageAutocomplete.rebuildInput(a);return false})}); \ No newline at end of file +var InputfieldPageAutocomplete={init:function(r,e,i,q,k){var f=$("#"+r);var l=$("#"+r+"_items");var c=$("#"+r+"_input");var a=c.parent().find(".InputfieldPageAutocompleteStatus");var j=c.parent().find(".InputfieldPageAutocompleteNote");var h=0;var n=0;var s=c.attr("data-disablechars");var b=c.hasClass("no_list");var m=a.height();if(m){var g=a.parent().height();var o=((g-m)/2);a.css("top",o+"px");a.css("left",(o/2)+"px")}else{}function p(w){if(!s||!s.length){return false}var v=false;for(var x=0;x-1){v=true;break}}return v}if(b){c.attr("data-selectedLabel",c.val());var d=c.siblings(".InputfieldPageAutocompleteRemove");d.click(function(){f.val("").change();c.val("").attr("placeholder","").attr("data-selectedLabel","").change().focus();c.trigger("keydown")});c.change(function(){if($(this).val().length==0){d.hide()}else{d.show()}});c.focus(function(){var v=f.val();if(!v.length){return}if(p(v)){return}if($(this).hasClass("added_item")){return}$(this).attr("placeholder",$(this).attr("data-selectedLabel"));$(this).val("")}).blur(function(){setTimeout(function(){},200)})}a.click(function(){c.focus()});a.attr("data-class",a.attr("class"));function u(){var v=$("#_"+r.replace("Inputfield_","")+"_add_items").size()>0;return v}c.autocomplete({minLength:2,source:function(x,v){var w=x.term;if(p(w)){v([]);return}a.attr("class","fa fa-fw fa-spin fa-spinner");if(c.hasClass("and_words")&&w.indexOf(" ")>0){w=w.replace(/\s+/,",")}w=encodeURIComponent(w);var y=e+"&"+q+k+w;$.getJSON(y,function(z){a.attr("class",a.attr("data-class"));n=z.total;if(z.total>0){a.attr("class","fa fa-fw fa-angle-double-down")}else{if(u()){a.attr("class","fa fa-fw fa-plus-circle");j.show()}else{a.attr("class","fa fa-fw fa-frown-o")}}v($.map(z.matches,function(A){return{label:A[i],value:A[i],page_id:A.id}}))})},select:function(v,w){if(!w.item){return}var x=$(this);if(x.hasClass("no_list")){x.val(w.item.label).change();x.attr("data-selectedLabel",w.item.label);x.closest(".InputfieldPageAutocomplete").find(".InputfieldPageAutocompleteData").val(w.item.page_id).change();x.blur();return false}else{InputfieldPageAutocomplete.pageSelected(l,w.item);x.val("").focus();return false}}}).blur(function(){var v=$(this);a.attr("class",a.attr("data-class"));j.hide();if(v.hasClass("no_list")){if(f.val().length||v.val().length){if(v.hasClass("allow_any")||v.hasClass("added_item")){}else{v.val(v.attr("data-selectedLabel")).attr("placeholder","")}}else{v.val("").attr("placeholder","").attr("data-selectedLabel","")}}}).keyup(function(){a.attr("class",a.attr("data-class"))}).keydown(function(w){if(w.keyCode==13){w.preventDefault();if(u()){if($.trim(c.val()).length<1){c.blur();return false}h++;var x={page_id:(-1*h),label:c.val()};if(b){f.val(x.page_id);$("#_"+r.replace("Inputfield_","")+"_add_items").val(x.label);c.addClass("added_item").blur();var v=j.siblings(".InputfieldPageAutocompleteNoteAdd");if(!v.length){var v=$("
");j.after(v)}v.text(j.attr("data-adding")+" "+x.label);v.show()}else{InputfieldPageAutocomplete.pageSelected(l,x);c.val("").blur().focus()}j.hide()}else{$(this).blur()}return false}if(h&&b){var v=j.siblings(".InputfieldPageAutocompleteNoteAdd");var y=$("#_"+r.replace("Inputfield_","")+"_add_items");if(v.length&&y.val()!=$(this).val()){v.remove();f.val("");y.val("");$("#_"+r.replace("Inputfield_","")+"_add_items").val("");h--}}});var t=function(v){v.sortable({axis:"y",update:function(x,w){InputfieldPageAutocomplete.rebuildInput($(this))},start:function(x,w){w.item.addClass("ui-state-highlight")},stop:function(x,w){w.item.removeClass("ui-state-highlight")}});v.addClass("InputfieldPageAutocompleteSortable")};$("#"+l.attr("id")).on("mouseover",">li",function(){$(this).removeClass("ui-state-default").addClass("ui-state-hover");t(l)}).on("mouseout",">li",function(){$(this).removeClass("ui-state-hover").addClass("ui-state-default")})},initFromInputfield:function(a){var b=a.find(".InputfieldPageAutocompleteData");if(!b.length){return}if(b.hasClass("InputfieldPageAutocompleteInit")){return}InputfieldPageAutocomplete.init(b.attr("id"),b.attr("data-url"),b.attr("data-label"),b.attr("data-search"),b.attr("data-operator"));b.addClass("InputfieldPageAutocompleteInit")},pageSelected:function(a,d){var c=false;a.children("li").each(function(){var f=parseInt($(this).children(".itemValue").text());if(f==d.page_id){c=$(this)}});var b=$("#"+a.attr("data-id")+"_input");b.blur();if(c){c.effect("highlight");return}var e=a.children(".itemTemplate").clone();e.removeClass("itemTemplate");e.children(".itemValue").text(d.page_id);e.children(".itemLabel").text(d.label);a.append(e);InputfieldPageAutocomplete.rebuildInput(a)},rebuildInput:function(d){var b=d.attr("data-id");var a=d.attr("data-name");var f=$("#"+b);var h="";var c="";var g=parseInt(f.attr("data-max"));var i=d.children(":not(.itemTemplate)");if(g>0&&i.size()>g){while(i.size()>g){i=i.slice(1)}d.children(":not(.itemTemplate)").replaceWith(i)}i.each(function(){var j=parseInt($(this).children(".itemValue").text());if(j>0){h+=","+j}else{if(j<0){h+=","+j;c+=$(this).children(".itemLabel").text()+"\n"}}});f.val(h);var e=$("#_"+a+"_add_items");if(e.size()>0){e.val(c)}}};$(document).ready(function(){$(".InputfieldPageAutocomplete").each(function(){InputfieldPageAutocomplete.initFromInputfield($(this))});$(document).on("reloaded",".InputfieldPageAutocomplete, .InputfieldPage",function(){InputfieldPageAutocomplete.initFromInputfield($(this))});$(document).on("click",".InputfieldPageAutocomplete ol a.itemRemove",function(){var c=$(this).parent();var a=c.parent();var b=c.children(".itemValue").text();c.remove();InputfieldPageAutocomplete.rebuildInput(a);return false})}); \ No newline at end of file