From 7ac78e725935731855abbe7ee7cdbbaf91148d1d Mon Sep 17 00:00:00 2001 From: ppatrik Date: Sun, 30 Oct 2016 12:24:58 +0100 Subject: [PATCH 1/3] fixed positioning to be relative (reason: semantic-ui uses relative positioning and suggestions had bad position) --- massautocomplete.js | 8 +++----- massautocomplete.min.js | 2 +- massautocomplete.theme.css | 5 ++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/massautocomplete.js b/massautocomplete.js index dac72c6..57d93f5 100644 --- a/massautocomplete.js +++ b/massautocomplete.js @@ -34,12 +34,10 @@ angular.module('MassAutoComplete', []) // Position ac container given a target element config.position_autocomplete = function(container, target) { - var rect = target[0].getBoundingClientRect(), - scrollTop = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset, - scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset; + var rect = target[0].getBoundingClientRect(); - container[0].style.top = rect.top + rect.height + scrollTop + 'px'; - container[0].style.left = rect.left + scrollLeft + 'px'; + container[0].style.top = rect.height + 'px'; + container[0].style.left = 0; container[0].style.width = rect.width + 'px'; }; diff --git a/massautocomplete.min.js b/massautocomplete.min.js index 213732f..cda2694 100644 --- a/massautocomplete.min.js +++ b/massautocomplete.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("MassAutoComplete",[]).provider("massAutocompleteConfig",function(){var e=this;e.KEYS={TAB:9,ESC:27,ENTER:13,UP:38,DOWN:40},e.EVENTS={KEYDOWN:"keydown",RESIZE:"resize",BLUR:"blur"},e.DEBOUNCE={position:150,attach:300,suggest:200,blur:150},e.generate_random_id=function(e){return e+"_"+Math.random().toString().substring(2)},e.position_autocomplete=function(e,t){var n=t[0].getBoundingClientRect(),o=document.body.scrollTop||document.documentElement.scrollTop||window.pageYOffset,i=document.body.scrollLeft||document.documentElement.scrollLeft||window.pageXOffset;e[0].style.top=n.top+n.height+o+"px",e[0].style.left=n.left+i+"px",e[0].style.width=n.width+"px"},this.$get=function(){return e}}).directive("massAutocomplete",["massAutocompleteConfig","$timeout","$window","$document","$q",function(e,t,n,o,i){return{restrict:"A",scope:{options:"&massAutocomplete"},transclude:!0,template:'
',link:function(e,t){e.container=angular.element(t[0].getElementsByClassName("ac-container")[0])},controller:["$scope",function(a){function c(){a.show_autocomplete=!0}function l(){a.show_autocomplete=!1,f()}function s(e,n,o){var i;return function(){var a=this,c=arguments,l=function(){i=null,o||e.apply(a,c)},s=o&&!i;t.cancel(i),i=t(l,n),s&&e.apply(a,c)}}function u(t){return(!t.id||""===t.id)&&(t.id=e.generate_random_id("ac_element"),!0)}function r(){e.position_autocomplete(a.container,b)}function d(t,n){a.selected_index=0,a.waiting_for_suggestion=!0,"string"==typeof t&&t.length>0?i.when(N.suggest(t),function(o){b&&b===n&&(o&&o.length>0?(o.forEach(function(t){t.id||(t.id=e.generate_random_id("ac_item"))}),a.results=[{value:t,label:"",id:""}].concat(o),c(),N.auto_select_first&&m(1)):(a.results=[],l()))},function(e){l(),N.on_error&&N.on_error(e)})["finally"](function(){a.waiting_for_suggestion=!1}):(a.waiting_for_suggestion=!1,l(),a.$apply())}function E(e,t,n){b!==t&&(b&&g.detach(),t[0]===o[0].activeElement&&(n.on_attach&&n.on_attach(),b=t,v=e,N=n,w=e.$viewValue,T=u(t),a.container[0].setAttribute("aria-labelledby",b.id),a.results=[],a.selected_index=-1,_(),S=a.$watch(function(){return e.$modelValue},function(e){e!==y&&(r(),A(e,b))})))}function p(e){v.$modelValue!==e&&(v.$setViewValue(e),v.$render())}function f(){a.selected_index=-1,a.container[0].removeAttribute("aria-activedescendant")}function m(e){var t=a.results[e];return b.val(t.value),a.selected_index=e,a.container[0].setAttribute("aria-activedescendant",t.id),t}function _(){angular.element(n).bind(e.EVENTS.RESIZE,x),h[e.EVENTS.BLUR]=function(){t(function(){b&&b[0]===o[0].activeElement||g.detach()},V.debounce_blur)},b.bind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),h[e.EVENTS.KEYDOWN]=function(t){if(!t.shiftKey)switch(t.keyCode){case e.KEYS.ESC:a.show_autocomplete?(l(),a.$apply()):b.val(w);break;case e.KEYS.ENTER:a.show_autocomplete&&a.selected_index>0&&!a.waiting_for_suggestion&&(a.apply_selection(a.selected_index),t.stopPropagation(),t.preventDefault()),l(),a.$apply();break;case e.KEYS.TAB:if(!a.show_autocomplete)break;t.preventDefault();case e.KEYS.DOWN:a.results.length>0&&(a.show_autocomplete?m(a.selected_index+1>a.results.length-1?0:a.selected_index+1):(c(),m(0)),a.$apply());break;case e.KEYS.UP:a.show_autocomplete&&(t.preventDefault(),m(a.selected_index-1>=0?a.selected_index-1:a.results.length-1),a.$apply())}},b.bind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN])}var g=this,h={};h[e.EVENTS.BLUR]=null,h[e.EVENTS.KEYDOWN]=null,h[e.EVENTS.RESIZE]=null;var b,v,N,w,S,y,T,$=a.options()||{},V={debounce_position:$.debounce_position||e.DEBOUNCE.position,debounce_attach:$.debounce_attach||e.DEBOUNCE.attach,debounce_suggest:$.debounce_suggest||e.DEBOUNCE.suggest,debounce_blur:$.debounce_blur||e.DEBOUNCE.blur};a.show_autocomplete=!1;var x=s(r,V.debounce_position),A=s(d,V.debounce_suggest);g.attach=s(E,V.debounce_attach),g.detach=function(){if(b){var t=b.val();p(t),N.on_detach&&N.on_detach(t),b.unbind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN]),b.unbind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),T&&b[0].removeAttribute("id")}l(),a.container[0].removeAttribute("aria-labelledby"),angular.element(n).unbind(e.EVENTS.RESIZE,h[e.EVENTS.RESIZE]),S&&S(),a.selected_index=a.results=void 0,v=b=w=void 0},a.apply_selection=function(e){if(b[0].focus(),!(!a.show_autocomplete||e>a.results.length||e<0)){var t=m(e);y=t.value,p(t.value),l(),N.on_select&&N.on_select(t)}},a.$on("$destroy",function(){g.detach(),a.container.remove()})}]}}]).directive("massAutocompleteItem",function(){return{restrict:"A",require:["^massAutocomplete","ngModel"],scope:{massAutocompleteItem:"&"},link:function(e,t,n,o){n.$set("autocomplete","off");var i=o[0],a=o[1];t.bind("focus",function(){var n=e.massAutocompleteItem();if(!n)throw new Error("Invalid options");i.attach(a,t,n)})}}})}(); \ No newline at end of file +!function(){"use strict";angular.module("MassAutoComplete",[]).provider("massAutocompleteConfig",function(){var e=this;e.KEYS={TAB:9,ESC:27,ENTER:13,UP:38,DOWN:40},e.EVENTS={KEYDOWN:"keydown",RESIZE:"resize",BLUR:"blur"},e.DEBOUNCE={position:150,attach:300,suggest:200,blur:150},e.generate_random_id=function(e){return e+"_"+Math.random().toString().substring(2)},e.position_autocomplete=function(e,t){var n=t[0].getBoundingClientRect();e[0].style.top=n.height+"px",e[0].style.left=0,e[0].style.width=n.width+"px"},this.$get=function(){return e}}).directive("massAutocomplete",["massAutocompleteConfig","$timeout","$window","$document","$q",function(e,t,n,o,i){return{restrict:"A",scope:{options:"&massAutocomplete"},transclude:!0,template:'
',link:function(e,t){e.container=angular.element(t[0].getElementsByClassName("ac-container")[0])},controller:["$scope",function(a){function c(){a.show_autocomplete=!0}function s(){a.show_autocomplete=!1,_()}function l(e,n,o){var i;return function(){var a=this,c=arguments,s=function(){i=null,o||e.apply(a,c)},l=o&&!i;t.cancel(i),i=t(s,n),l&&e.apply(a,c)}}function u(t){return(!t.id||""===t.id)&&(t.id=e.generate_random_id("ac_element"),!0)}function r(){e.position_autocomplete(a.container,b)}function d(t,n){a.selected_index=0,a.waiting_for_suggestion=!0,"string"==typeof t&&t.length>0?i.when(N.suggest(t),function(o){b&&b===n&&(o&&o.length>0?(o.forEach(function(t){t.id||(t.id=e.generate_random_id("ac_item"))}),a.results=[{value:t,label:"",id:""}].concat(o),c(),N.auto_select_first&&f(1)):(a.results=[],s()))},function(e){s(),N.on_error&&N.on_error(e)}).finally(function(){a.waiting_for_suggestion=!1}):(a.waiting_for_suggestion=!1,s(),a.$apply())}function E(e,t,n){b!==t&&(b&&g.detach(),t[0]===o[0].activeElement&&(n.on_attach&&n.on_attach(),b=t,v=e,N=n,S=e.$viewValue,$=u(t),a.container[0].setAttribute("aria-labelledby",b.id),a.results=[],a.selected_index=-1,m(),w=a.$watch(function(){return e.$modelValue},function(e){e!==y&&(r(),A(e,b))})))}function p(e){v.$modelValue!==e&&(v.$setViewValue(e),v.$render())}function _(){a.selected_index=-1,a.container[0].removeAttribute("aria-activedescendant")}function f(e){var t=a.results[e];return b.val(t.value),a.selected_index=e,a.container[0].setAttribute("aria-activedescendant",t.id),t}function m(){angular.element(n).bind(e.EVENTS.RESIZE,x),h[e.EVENTS.BLUR]=function(){t(function(){b&&b[0]===o[0].activeElement||g.detach()},T.debounce_blur)},b.bind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),h[e.EVENTS.KEYDOWN]=function(t){if(!t.shiftKey)switch(t.keyCode){case e.KEYS.ESC:a.show_autocomplete?(s(),a.$apply()):b.val(S);break;case e.KEYS.ENTER:a.show_autocomplete&&a.selected_index>0&&!a.waiting_for_suggestion&&(a.apply_selection(a.selected_index),t.stopPropagation(),t.preventDefault()),s(),a.$apply();break;case e.KEYS.TAB:if(!a.show_autocomplete)break;t.preventDefault();case e.KEYS.DOWN:a.results.length>0&&(a.show_autocomplete?f(a.selected_index+1>a.results.length-1?0:a.selected_index+1):(c(),f(0)),a.$apply());break;case e.KEYS.UP:a.show_autocomplete&&(t.preventDefault(),f(a.selected_index-1>=0?a.selected_index-1:a.results.length-1),a.$apply())}},b.bind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN])}var g=this,h={};h[e.EVENTS.BLUR]=null,h[e.EVENTS.KEYDOWN]=null,h[e.EVENTS.RESIZE]=null;var b,v,N,S,w,y,$,V=a.options()||{},T={debounce_position:V.debounce_position||e.DEBOUNCE.position,debounce_attach:V.debounce_attach||e.DEBOUNCE.attach,debounce_suggest:V.debounce_suggest||e.DEBOUNCE.suggest,debounce_blur:V.debounce_blur||e.DEBOUNCE.blur};a.show_autocomplete=!1;var x=l(r,T.debounce_position),A=l(d,T.debounce_suggest);g.attach=l(E,T.debounce_attach),g.detach=function(){if(b){var t=b.val();p(t),N.on_detach&&N.on_detach(t),b.unbind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN]),b.unbind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),$&&b[0].removeAttribute("id")}s(),a.container[0].removeAttribute("aria-labelledby"),angular.element(n).unbind(e.EVENTS.RESIZE,h[e.EVENTS.RESIZE]),w&&w(),a.selected_index=a.results=void 0,v=b=S=void 0},a.apply_selection=function(e){if(b[0].focus(),!(!a.show_autocomplete||e>a.results.length||e<0)){var t=f(e);y=t.value,p(t.value),s(),N.on_select&&N.on_select(t)}},a.$on("$destroy",function(){g.detach(),a.container.remove()})}]}}]).directive("massAutocompleteItem",function(){return{restrict:"A",require:["^massAutocomplete","ngModel"],scope:{massAutocompleteItem:"&"},link:function(e,t,n,o){n.$set("autocomplete","off");var i=o[0],a=o[1];t.bind("focus",function(){var n=e.massAutocompleteItem();if(!n)throw new Error("Invalid options");i.attach(a,t,n)})}}})}(); \ No newline at end of file diff --git a/massautocomplete.theme.css b/massautocomplete.theme.css index bf24b8d..d47a6a9 100644 --- a/massautocomplete.theme.css +++ b/massautocomplete.theme.css @@ -1,3 +1,6 @@ +[mass-autocomplete] { + position: relative; +} .ac-container { -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; @@ -39,4 +42,4 @@ .ac-container .ac-menu .ac-state-focus { outline: none; background-color: #e0eaff; -} +} \ No newline at end of file From aefe9681b3d8c3dfbd0d614159ca9ad538493bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Pekar=C4=8D=C3=ADk?= Date: Sat, 3 Nov 2018 16:02:10 +0100 Subject: [PATCH 2/3] Pridanie neglobalnej zavislosti na angular. --- massautocomplete.js | 4 ++-- massautocomplete.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/massautocomplete.js b/massautocomplete.js index 57d93f5..996caa8 100644 --- a/massautocomplete.js +++ b/massautocomplete.js @@ -1,5 +1,5 @@ /* global angular */ -(function() { +(function(angular) { 'use strict'; angular.module('MassAutoComplete', []) @@ -456,4 +456,4 @@ angular.module('MassAutoComplete', []) } }; }); -})(); +})(angular); diff --git a/massautocomplete.min.js b/massautocomplete.min.js index cda2694..f0b9ec2 100644 --- a/massautocomplete.min.js +++ b/massautocomplete.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("MassAutoComplete",[]).provider("massAutocompleteConfig",function(){var e=this;e.KEYS={TAB:9,ESC:27,ENTER:13,UP:38,DOWN:40},e.EVENTS={KEYDOWN:"keydown",RESIZE:"resize",BLUR:"blur"},e.DEBOUNCE={position:150,attach:300,suggest:200,blur:150},e.generate_random_id=function(e){return e+"_"+Math.random().toString().substring(2)},e.position_autocomplete=function(e,t){var n=t[0].getBoundingClientRect();e[0].style.top=n.height+"px",e[0].style.left=0,e[0].style.width=n.width+"px"},this.$get=function(){return e}}).directive("massAutocomplete",["massAutocompleteConfig","$timeout","$window","$document","$q",function(e,t,n,o,i){return{restrict:"A",scope:{options:"&massAutocomplete"},transclude:!0,template:'
',link:function(e,t){e.container=angular.element(t[0].getElementsByClassName("ac-container")[0])},controller:["$scope",function(a){function c(){a.show_autocomplete=!0}function s(){a.show_autocomplete=!1,_()}function l(e,n,o){var i;return function(){var a=this,c=arguments,s=function(){i=null,o||e.apply(a,c)},l=o&&!i;t.cancel(i),i=t(s,n),l&&e.apply(a,c)}}function u(t){return(!t.id||""===t.id)&&(t.id=e.generate_random_id("ac_element"),!0)}function r(){e.position_autocomplete(a.container,b)}function d(t,n){a.selected_index=0,a.waiting_for_suggestion=!0,"string"==typeof t&&t.length>0?i.when(N.suggest(t),function(o){b&&b===n&&(o&&o.length>0?(o.forEach(function(t){t.id||(t.id=e.generate_random_id("ac_item"))}),a.results=[{value:t,label:"",id:""}].concat(o),c(),N.auto_select_first&&f(1)):(a.results=[],s()))},function(e){s(),N.on_error&&N.on_error(e)}).finally(function(){a.waiting_for_suggestion=!1}):(a.waiting_for_suggestion=!1,s(),a.$apply())}function E(e,t,n){b!==t&&(b&&g.detach(),t[0]===o[0].activeElement&&(n.on_attach&&n.on_attach(),b=t,v=e,N=n,S=e.$viewValue,$=u(t),a.container[0].setAttribute("aria-labelledby",b.id),a.results=[],a.selected_index=-1,m(),w=a.$watch(function(){return e.$modelValue},function(e){e!==y&&(r(),A(e,b))})))}function p(e){v.$modelValue!==e&&(v.$setViewValue(e),v.$render())}function _(){a.selected_index=-1,a.container[0].removeAttribute("aria-activedescendant")}function f(e){var t=a.results[e];return b.val(t.value),a.selected_index=e,a.container[0].setAttribute("aria-activedescendant",t.id),t}function m(){angular.element(n).bind(e.EVENTS.RESIZE,x),h[e.EVENTS.BLUR]=function(){t(function(){b&&b[0]===o[0].activeElement||g.detach()},T.debounce_blur)},b.bind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),h[e.EVENTS.KEYDOWN]=function(t){if(!t.shiftKey)switch(t.keyCode){case e.KEYS.ESC:a.show_autocomplete?(s(),a.$apply()):b.val(S);break;case e.KEYS.ENTER:a.show_autocomplete&&a.selected_index>0&&!a.waiting_for_suggestion&&(a.apply_selection(a.selected_index),t.stopPropagation(),t.preventDefault()),s(),a.$apply();break;case e.KEYS.TAB:if(!a.show_autocomplete)break;t.preventDefault();case e.KEYS.DOWN:a.results.length>0&&(a.show_autocomplete?f(a.selected_index+1>a.results.length-1?0:a.selected_index+1):(c(),f(0)),a.$apply());break;case e.KEYS.UP:a.show_autocomplete&&(t.preventDefault(),f(a.selected_index-1>=0?a.selected_index-1:a.results.length-1),a.$apply())}},b.bind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN])}var g=this,h={};h[e.EVENTS.BLUR]=null,h[e.EVENTS.KEYDOWN]=null,h[e.EVENTS.RESIZE]=null;var b,v,N,S,w,y,$,V=a.options()||{},T={debounce_position:V.debounce_position||e.DEBOUNCE.position,debounce_attach:V.debounce_attach||e.DEBOUNCE.attach,debounce_suggest:V.debounce_suggest||e.DEBOUNCE.suggest,debounce_blur:V.debounce_blur||e.DEBOUNCE.blur};a.show_autocomplete=!1;var x=l(r,T.debounce_position),A=l(d,T.debounce_suggest);g.attach=l(E,T.debounce_attach),g.detach=function(){if(b){var t=b.val();p(t),N.on_detach&&N.on_detach(t),b.unbind(e.EVENTS.KEYDOWN,h[e.EVENTS.KEYDOWN]),b.unbind(e.EVENTS.BLUR,h[e.EVENTS.BLUR]),$&&b[0].removeAttribute("id")}s(),a.container[0].removeAttribute("aria-labelledby"),angular.element(n).unbind(e.EVENTS.RESIZE,h[e.EVENTS.RESIZE]),w&&w(),a.selected_index=a.results=void 0,v=b=S=void 0},a.apply_selection=function(e){if(b[0].focus(),!(!a.show_autocomplete||e>a.results.length||e<0)){var t=f(e);y=t.value,p(t.value),s(),N.on_select&&N.on_select(t)}},a.$on("$destroy",function(){g.detach(),a.container.remove()})}]}}]).directive("massAutocompleteItem",function(){return{restrict:"A",require:["^massAutocomplete","ngModel"],scope:{massAutocompleteItem:"&"},link:function(e,t,n,o){n.$set("autocomplete","off");var i=o[0],a=o[1];t.bind("focus",function(){var n=e.massAutocompleteItem();if(!n)throw new Error("Invalid options");i.attach(a,t,n)})}}})}(); \ No newline at end of file +!function(e){"use strict";e.module("MassAutoComplete",[]).provider("massAutocompleteConfig",function(){var e=this;e.KEYS={TAB:9,ESC:27,ENTER:13,UP:38,DOWN:40},e.EVENTS={KEYDOWN:"keydown",RESIZE:"resize",BLUR:"blur"},e.DEBOUNCE={position:150,attach:300,suggest:200,blur:150},e.generate_random_id=function(e){return e+"_"+Math.random().toString().substring(2)},e.position_autocomplete=function(e,t){var n=t[0].getBoundingClientRect();e[0].style.top=n.height+"px",e[0].style.left=0,e[0].style.width=n.width+"px"},this.$get=function(){return e}}).directive("massAutocomplete",["massAutocompleteConfig","$timeout","$window","$document","$q",function(t,n,o,i,a){return{restrict:"A",scope:{options:"&massAutocomplete"},transclude:!0,template:'
',link:function(t,n){t.container=e.element(n[0].getElementsByClassName("ac-container")[0])},controller:["$scope",function(c){function s(){c.show_autocomplete=!0}function l(){c.show_autocomplete=!1,f()}function u(e,t,o){var i;return function(){var a=this,c=arguments,s=function(){i=null,o||e.apply(a,c)},l=o&&!i;n.cancel(i),i=n(s,t),l&&e.apply(a,c)}}function r(e){return(!e.id||""===e.id)&&(e.id=t.generate_random_id("ac_element"),!0)}function d(){t.position_autocomplete(c.container,v)}function E(e,n){c.selected_index=0,c.waiting_for_suggestion=!0,"string"==typeof e&&e.length>0?a.when(S.suggest(e),function(o){v&&v===n&&(o&&o.length>0?(o.forEach(function(e){e.id||(e.id=t.generate_random_id("ac_item"))}),c.results=[{value:e,label:"",id:""}].concat(o),s(),S.auto_select_first&&m(1)):(c.results=[],l()))},function(e){l(),S.on_error&&S.on_error(e)})["finally"](function(){c.waiting_for_suggestion=!1}):(c.waiting_for_suggestion=!1,l(),c.$apply())}function p(e,t,n){v!==t&&(v&&h.detach(),t[0]===i[0].activeElement&&(n.on_attach&&n.on_attach(),v=t,N=e,S=n,w=e.$viewValue,V=r(t),c.container[0].setAttribute("aria-labelledby",v.id),c.results=[],c.selected_index=-1,g(),y=c.$watch(function(){return e.$modelValue},function(e){e!==$&&(d(),D(e,v))})))}function _(e){N.$modelValue!==e&&(N.$setViewValue(e),N.$render())}function f(){c.selected_index=-1,c.container[0].removeAttribute("aria-activedescendant")}function m(e){var t=c.results[e];return v.val(t.value),c.selected_index=e,c.container[0].setAttribute("aria-activedescendant",t.id),t}function g(){e.element(o).bind(t.EVENTS.RESIZE,A),b[t.EVENTS.BLUR]=function(){n(function(){v&&v[0]===i[0].activeElement||h.detach()},x.debounce_blur)},v.bind(t.EVENTS.BLUR,b[t.EVENTS.BLUR]),b[t.EVENTS.KEYDOWN]=function(e){if(!e.shiftKey)switch(e.keyCode){case t.KEYS.ESC:c.show_autocomplete?(l(),c.$apply()):v.val(w);break;case t.KEYS.ENTER:c.show_autocomplete&&c.selected_index>0&&!c.waiting_for_suggestion&&(c.apply_selection(c.selected_index),e.stopPropagation(),e.preventDefault()),l(),c.$apply();break;case t.KEYS.TAB:if(!c.show_autocomplete)break;e.preventDefault();case t.KEYS.DOWN:c.results.length>0&&(c.show_autocomplete?m(c.selected_index+1>c.results.length-1?0:c.selected_index+1):(s(),m(0)),c.$apply());break;case t.KEYS.UP:c.show_autocomplete&&(e.preventDefault(),m(c.selected_index-1>=0?c.selected_index-1:c.results.length-1),c.$apply())}},v.bind(t.EVENTS.KEYDOWN,b[t.EVENTS.KEYDOWN])}var h=this,b={};b[t.EVENTS.BLUR]=null,b[t.EVENTS.KEYDOWN]=null,b[t.EVENTS.RESIZE]=null;var v,N,S,w,y,$,V,T=c.options()||{},x={debounce_position:T.debounce_position||t.DEBOUNCE.position,debounce_attach:T.debounce_attach||t.DEBOUNCE.attach,debounce_suggest:T.debounce_suggest||t.DEBOUNCE.suggest,debounce_blur:T.debounce_blur||t.DEBOUNCE.blur};c.show_autocomplete=!1;var A=u(d,x.debounce_position),D=u(E,x.debounce_suggest);h.attach=u(p,x.debounce_attach),h.detach=function(){if(v){var n=v.val();_(n),S.on_detach&&S.on_detach(n),v.unbind(t.EVENTS.KEYDOWN,b[t.EVENTS.KEYDOWN]),v.unbind(t.EVENTS.BLUR,b[t.EVENTS.BLUR]),V&&v[0].removeAttribute("id")}l(),c.container[0].removeAttribute("aria-labelledby"),e.element(o).unbind(t.EVENTS.RESIZE,b[t.EVENTS.RESIZE]),y&&y(),c.selected_index=c.results=void 0,N=v=w=void 0},c.apply_selection=function(e){if(v[0].focus(),!(!c.show_autocomplete||e>c.results.length||e<0)){var t=m(e);$=t.value,_(t.value),l(),S.on_select&&S.on_select(t)}},c.$on("$destroy",function(){h.detach(),c.container.remove()})}]}}]).directive("massAutocompleteItem",function(){return{restrict:"A",require:["^massAutocomplete","ngModel"],scope:{massAutocompleteItem:"&"},link:function(e,t,n,o){n.$set("autocomplete","off");var i=o[0],a=o[1];t.bind("focus",function(){var n=e.massAutocompleteItem();if(!n)throw new Error("Invalid options");i.attach(a,t,n)})}}})}(angular); \ No newline at end of file From 21698de430ca390489765107b458dca8207fb96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Pekar=C4=8D=C3=ADk?= Date: Sat, 3 Nov 2018 16:25:58 +0100 Subject: [PATCH 3/3] pridanie modulu s exportovanim --- index.js | 2 ++ massautocomplete.js | 5 ++--- package.json | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..485dfeb --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +require('./massautocomplete'); +module.exports = 'MassAutoComplete'; diff --git a/massautocomplete.js b/massautocomplete.js index 996caa8..6dd0240 100644 --- a/massautocomplete.js +++ b/massautocomplete.js @@ -1,6 +1,5 @@ /* global angular */ -(function(angular) { -'use strict'; +(function(angular) {'use strict'; angular.module('MassAutoComplete', []) @@ -456,4 +455,4 @@ angular.module('MassAutoComplete', []) } }; }); -})(angular); +})(window.angular); diff --git a/package.json b/package.json index 624284e..39affee 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "angular-mass-autocomplete", - "version": "0.5.0", + "version": "0.5.4", "description": "Autocomplete for Angular.js applications with a lot to complete", - "main": "massautocomplete.js", + "main": "index.js", "repository": { "type": "git", "url": "https://github.com/hakib/MassAutocomplete" @@ -18,8 +18,8 @@ "bugs": { "url": "https://github.com/hakib/MassAutocomplete/issues" }, - "peerDependencies": { - "angular": "1" + "dependencies": { + "angular": "*" }, "devDependencies": { "eslint": "^3.1.1",