-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdebug_DAL.txt
390 lines (281 loc) · 9.03 KB
/
debug_DAL.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
DEBUGGING DAL:
Here is where Select 2 opens. The .open) is what draws the drop down.
Select2.prototype.toggleDropdown = function () {
if (this.isDisabled()) {
return;
}
if (this.isOpen()) {
this.close();
} else {
this.open();
}
};
It fires this:
Select2.prototype.open = function () {
if (this.isOpen()) {
return;
}
if (this.isDisabled()) {
return;
}
this.trigger('query', {});
};
Which lands here:
Select2.prototype.trigger = function (name, args) {
var actualTrigger = Select2.__super__.trigger;
var preTriggerMap = {
'open': 'opening',
'close': 'closing',
'select': 'selecting',
'unselect': 'unselecting',
'clear': 'clearing'
};
if (args === undefined) {
args = {};
}
if (name in preTriggerMap) {
var preTriggerName = preTriggerMap[name];
var preTriggerArgs = {
prevented: false,
name: name,
args: args
};
actualTrigger.call(this, preTriggerName, preTriggerArgs);
if (preTriggerArgs.prevented) {
args.prevented = true;
return;
}
}
actualTrigger.call(this, name, args);
};
Which lands here:
actualTrigger.call(this, name, args);
Observable.prototype.trigger = function (event) {
var slice = Array.prototype.slice;
var params = slice.call(arguments, 1);
this.listeners = this.listeners || {};
// Params should always come in as an array
if (params == null) {
params = [];
}
// If there are no arguments to the event, use a temporary object
if (params.length === 0) {
params.push({});
}
// Set the `_type` of the first object to the event
params[0]._type = event;
if (event in this.listeners) {
this.invoke(this.listeners[event], slice.call(arguments, 1));
}
if ('*' in this.listeners) {
this.invoke(this.listeners['*'], arguments);
}
};
Which hits this:
this.invoke(this.listeners[event], slice.call(arguments, 1));
three times it seems, thre listeners on the query event.
Can't see names for them, just locations:
query: Array(3)
0: ƒ (params)
arguments: null
caller: null
length: 1
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: select2.full.js:1114
[[Scopes]]: Scopes[6]
1: ƒ (params)
arguments: null
caller: null
length: 1
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: select2.full.js:4261
[[Scopes]]: Scopes[6]
2: ƒ (params)
arguments: null
caller: null
length: 1
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: select2.full.js:5664
[[Scopes]]: Scopes[6]
length: 3
__proto__: Array(0)
The first one is:
container.on('query', function (params) {
self.hideMessages();
self.showLoading(params);
});
The second one is:
container.on('query', function (params) {
self.lastParams = params;
self.loading = true;
});
The third one is:
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open', {});
}
this.dataAdapter.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
And it is self.trigger('open', {}); that opens the drop down.
That ends up back in Select2.prototype.trigger and then Observable.prototype.trigger but this time round there's only one listener and we land in:
container.on('*', function (name, params) {
// Ignore events that should not be relayed
if ($.inArray(name, relayEvents) === -1) {
return;
}
// The parameters should always be an object
params = params || {};
// Generate the jQuery event for the Select2 event
var evt = $.Event('select2:' + name, {
params: params
});
self.$element.trigger(evt);
// Only handle preventable events if it was one
if ($.inArray(name, preventableEvents) === -1) {
return;
}
But this doesn't display the drop down yet and we cycle back to Observable.prototype.trigger with hte open event and ther are 5 listeners to that:
The first:
container.on('open', function () {
// When the dropdown is open, aria-expanded="true"
self.$selection.attr('aria-expanded', 'true');
self.$selection.attr('aria-owns', resultsId);
self._attachCloseHandler(container);
});
The second:
container.on('open', function () {
self.$search.attr('tabindex', 0);
self.$search.attr('aria-controls', resultsId);
self.$search.trigger('focus');
window.setTimeout(function () {
self.$search.trigger('focus');
}, 0);
});
The third:
container.on('open', function () {
self._showDropdown();
self._attachPositioningHandler(container);
// Must bind after the results handlers to ensure correct sizing
self._bindContainerResultHandlers(container);
});
The fourth:
container.on('open', function () {
// When the dropdown is open, aria-expended="true"
self.$results.attr('aria-expanded', 'true');
self.$results.attr('aria-hidden', 'false');
self.setClasses();
self.ensureHighlightVisible();
});
And the 5th:
this.on('open', function () {
self.$container.addClass('select2-container--open');
});
It is the 3rd that looks interesting, especially:
self._showDropdown();
self._attachPositioningHandler(container);
And indeed:
self._showDropdown();
displays the dropdown. Drilling into it we find:
AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown();
this._resizeDropdown();
};
does the work. The first line draws the dropdown.
this.$dropdownContainer seems already built here, and has:
style="position: absolute; top: 350.469px; left: 172.628px;"
Which positions it, wrongly now below the host.
On the multi select below it it is preapred as:
style="position: absolute; top: 391.903px; left: 172.628px;"
But this time with the edit box over the original. So higher one row.
Which is line 4574 in https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.full.js
This be where it (this.$dropdownContainer) is set:
AttachBody.prototype.render = function (decorated) {
var $container = $('<span></span>');
var $dropdown = decorated.call(this);
$container.append($dropdown);
this.$dropdownContainer = $container;
return $container;
};
and this be where the CSS is set:
AttachBody.prototype._positionDropdown = function () {
var $window = $(window);
var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
var newDirection = null;
var offset = this.$container.offset();
offset.bottom = offset.top + this.$container.outerHeight(false);
var container = {
height: this.$container.outerHeight(false)
};
container.top = offset.top;
container.bottom = offset.top + container.height;
var dropdown = {
height: this.$dropdown.outerHeight(false)
};
var viewport = {
top: $window.scrollTop(),
bottom: $window.scrollTop() + $window.height()
};
var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
var css = {
left: offset.left,
top: container.bottom
};
// Determine what the parent element is to use for calculating the offset
var $offsetParent = this.$dropdownParent;
// For statically positioned elements, we need to get the element
// that is determining the offset
if ($offsetParent.css('position') === 'static') {
$offsetParent = $offsetParent.offsetParent();
}
var parentOffset = {
top: 0,
left: 0
};
if (
$.contains(document.body, $offsetParent[0]) ||
$offsetParent[0].isConnected
) {
parentOffset = $offsetParent.offset();
}
css.top -= parentOffset.top;
css.left -= parentOffset.left;
if (!isCurrentlyAbove && !isCurrentlyBelow) {
newDirection = 'below';
}
if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
newDirection = 'above';
} else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
newDirection = 'below';
}
if (newDirection == 'above' ||
(isCurrentlyAbove && newDirection !== 'below')) {
css.top = container.top - parentOffset.top - dropdown.height;
}
if (newDirection != null) {
this.$dropdown
.removeClass('select2-dropdown--below select2-dropdown--above')
.addClass('select2-dropdown--' + newDirection);
this.$container
.removeClass('select2-container--below select2-container--above')
.addClass('select2-container--' + newDirection);
}
this.$dropdownContainer.css(css);
};
This last spot is where it's positioned. css contains:
{left: 172.62783813476562, top: 341.5483169433594}
AttachBody.prototype.render is called on page load and
AttachBody.prototype._positionDropdown is called on click (when the drop down is required)