PageSourceSearch

https://xn--80akjfhmgn4l.market/scripts/_common/autocompleter/directives/autocompleterDirectives.js

js xn--80akjfhmgn4l.market collected 2026-10-09 21:28:58 UTC 5,271 bytes, 148 lines download raw bytes

1; (function (ng) {
2    'use strict';
3
4    ng.module('autocompleter')
5      .directive('autocompleter', ['$compile', 'autocompleterConfig', function ($compile, autocompleterConfig) {
6          return {
7              restrict: 'A',
8              scope: {
9                  requestUrl: '@',
10                  minLength: '&',
11                  templatePath: '@',
12                  field: '@',
13                  linkAll: '@',
14                  applyFn: '&',
15                  params: '=?',
16                  showEmptyResultMessage: '&',
17                  onInit: '&'
18              },
19              controller: 'AutocompleterCtrl',
20              controllerAs: 'autocompleter',
21              bindToController: true,
22              link: function (scope, element, attrs, ctrl) {
23                  var minLength = ctrl.minLength();
24
25                  ctrl.minLength = minLength != null ? minLength : autocompleterConfig.minLength;
26
27                  ctrl.autocompleterElement = element;
28              }
29          };
30      }]);
31
32    ng.module('autocompleter')
33      .directive('autocompleterInput', ['$compile', '$timeout', function ($compile, $timeout) {
34          return {
35              require: ['autocompleterInput', 'ngModel', '^autocompleter'],
36              restrict: 'A',
37              controller: 'AutocompleterInputCtrl',
38              controllerAs: 'autocompleterInput',
39              bindToController: true,
40              scope: true,
41              link: function (scope, element, attrs, ctrls) {
42
43                  var ctrl = ctrls[0],
44                      ngModel = ctrls[1],
45                      parentCtrl = ctrls[2],
46                      pos;
47
48                  ctrl.listRendered = false;
49
50                  element[0].setAttribute('autocomplete', 'false');
51
52                  element[0].addEventListener('keyup', function (event) {
53                      scope.$apply(function () {
54                          if (ctrl.listRendered === false) {
55
56                              ctrl.listRendered = true;
57
58                              var list = ng.element('<div data-autocompleter-list></div>');
59
60                              parentCtrl.autocompleterElement.append(list);
61
62                              $compile(list)(scope);
63                          }
64
65                          parentCtrl.autocompleteKeyup(event, element[0].value);
66
67                          if (parentCtrl.listPositional == null) {
68                              parentCtrl.setListPosition({ left: element[0].offsetLeft, top: element[0].offsetTop + element[0].offsetHeight });
69                          }
70                      });
71                  });
72
73                  element[0].addEventListener('blur', function (event) {
74                      if (parentCtrl.listCtrl != null && parentCtrl.listCtrl.getStateHover() === false && parentCtrl.isDirty === true) {
75                          parentCtrl.applyFn({ value: ngModel.$modelValue, obj: parentCtrl.activeItem != null ? parentCtrl.activeItem.item : null, event: event });
76                      }
77                  });
78
79                  parentCtrl.model = ngModel;
80              }
81          };
82      }]);
83
84    ng.module('autocompleter')
85      .directive('autocompleterList', ['domService', function (domService) {
86          return {
87              require: ['autocompleterList', '^autocompleter'],
88              restrict: 'A',
89              controller: 'AutocompleterListCtrl',
90              controllerAs: 'autocompleterList',
91              bindToController: true,
92              scope: true,
93              replace: true,
94              templateUrl: '/scripts/_common/autocompleter/templates/_list.html',
95              link: function (scope, element, attrs, ctrls) {
96
97                  var ctrl = ctrls[0],
98                      parentCtrl = ctrls[1];
99
100                  ctrl.parentScope = parentCtrl;
101
102                  parentCtrl.addList(element[0], ctrl);
103
104              }
105          };
106      }]);
107
108    ng.module('autocompleter')
109      .directive('autocompleterItem', [function () {
110          return {
111              require: ['autocompleterItem', '^autocompleter'],
112              controller: 'AutocompleterItemCtrl',
113              controllerAs: 'autocompleterItem',
114              bindToController: true,
115              restrict: 'A',
116              scope: {
117                  item: '=',
118                  itemTemplatePath: '=?',
119                  index: '=?',
120                  groupIndex: '=?'
121              },
122              templateUrl: '/scripts/_common/autocompleter/templates/_item.html',
123              replace: true,
124              link: function (scope, element, attrs, ctrls) {
125
126                  var ctrl = ctrls[0],
127                      parentCtrl = ctrls[1];
128
129                  ctrl.parentScope = parentCtrl;
130
131                  ctrl.itemDOM = element[0];
132
133                  parentCtrl.addItem(ctrl);
134
135                  scope.$on('$destroy', function (destroyEvent) {
136
137                      var currentScope = destroyEvent.currentScope.autocompleterItem;
138
139                      if (currentScope != null) {
140                          currentScope.parentScope.items[currentScope.groupIndex].splice(currentScope.index, 1);
141                      }
142                  });
143              }
144          };
145      }]);
146
147})(window.angular);
148

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.