-
Notifications
You must be signed in to change notification settings - Fork 28
/
editing.js
786 lines (718 loc) · 20.3 KB
/
editing.js
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
// Adminer specific functions
/** Load syntax highlighting
* @param string first three characters of database system version
* @param [boolean]
*/
function bodyLoad(version, maria) {
if (window.jush) {
jush.create_links = ' target="_blank" rel="noreferrer noopener"';
if (version) {
for (var key in jush.urls) {
var obj = jush.urls;
if (typeof obj[key] != 'string') {
obj = obj[key];
key = 0;
if (maria) {
for (var i = 1; i < obj.length; i++) {
obj[i] = obj[i]
.replace(/\.html/, '/')
.replace(/-type-syntax/, '-data-types')
.replace(/numeric-(data-types)/, '$1-$&')
.replace(/#statvar_.*/, '#$$1')
;
}
}
}
obj[key] = (maria ? obj[key].replace(/dev\.mysql\.com\/doc\/mysql\/en\//, 'mariadb.com/kb/en/library/') : obj[key]) // MariaDB
.replace(/\/doc\/mysql/, '/doc/refman/' + version) // MySQL
.replace(/\/docs\/current/, '/docs/' + version) // PostgreSQL
;
}
}
if (window.jushLinks) {
jush.custom_links = jushLinks;
}
jush.highlight_tag('code', 0);
var tags = qsa('textarea');
for (var i = 0; i < tags.length; i++) {
if (/(^|\s)jush-/.test(tags[i].className)) {
var pre = jush.textarea(tags[i]);
if (pre) {
setupSubmitHighlightInput(pre);
}
}
}
}
}
/** Get value of dynamically created form field
* @param HTMLFormElement
* @param string
* @return HTMLElement
*/
function formField(form, name) {
// required in IE < 8, form.elements[name] doesn't work
for (var i=0; i < form.length; i++) {
if (form[i].name == name) {
return form[i];
}
}
}
/** Try to change input type to password or to text
* @param HTMLInputElement
* @param boolean
*/
function typePassword(el, disable) {
try {
el.type = (disable ? 'text' : 'password');
} catch (e) {
}
}
/** Install toggle handler
* @param [HTMLElement]
*/
function messagesPrint(el) {
var els = qsa('.toggle', el);
for (var i = 0; i < els.length; i++) {
els[i].onclick = partial(toggle, els[i].getAttribute('href').substr(1));
}
}
/** Hide or show some login rows for selected driver
* @param HTMLSelectElement
*/
function loginDriver(driver) {
var trs = parentTag(driver, 'table').rows;
var disabled = /sqlite/.test(selectValue(driver));
alterClass(trs[1], 'hidden', disabled); // 1 - row with server
trs[1].getElementsByTagName('input')[0].disabled = disabled;
}
var dbCtrl;
var dbPrevious = {};
/** Check if database should be opened to a new window
* @param MouseEvent
* @this HTMLSelectElement
*/
function dbMouseDown(event) {
dbCtrl = isCtrl(event);
if (dbPrevious[this.name] == undefined) {
dbPrevious[this.name] = this.value;
}
}
/** Load database after selecting it
* @this HTMLSelectElement
*/
function dbChange() {
if (dbCtrl) {
this.form.target = '_blank';
}
this.form.submit();
this.form.target = '';
if (dbCtrl && dbPrevious[this.name] != undefined) {
this.value = dbPrevious[this.name];
dbPrevious[this.name] = undefined;
}
}
/** Check whether the query will be executed with index
* @this HTMLElement
*/
function selectFieldChange() {
var form = this.form;
var ok = (function () {
var inputs = qsa('input', form);
for (var i=0; i < inputs.length; i++) {
if (inputs[i].value && /^fulltext/.test(inputs[i].name)) {
return true;
}
}
var ok = form.limit.value;
var selects = qsa('select', form);
var group = false;
var columns = {};
for (var i=0; i < selects.length; i++) {
var select = selects[i];
var col = selectValue(select);
var match = /^(where.+)col\]/.exec(select.name);
if (match) {
var op = selectValue(form[match[1] + 'op]']);
var val = form[match[1] + 'val]'].value;
if (col in indexColumns && (!/LIKE|REGEXP/.test(op) || (op == 'LIKE' && val.charAt(0) != '%'))) {
return true;
} else if (col || val) {
ok = false;
}
}
if ((match = /^(columns.+)fun\]/.exec(select.name))) {
if (/^(avg|count|count distinct|group_concat|max|min|sum)$/.test(col)) {
group = true;
}
var val = selectValue(form[match[1] + 'col]']);
if (val) {
columns[col && col != 'count' ? '' : val] = 1;
}
}
if (col && /^order/.test(select.name)) {
if (!(col in indexColumns)) {
ok = false;
}
break;
}
}
if (group) {
for (var col in columns) {
if (!(col in indexColumns)) {
ok = false;
}
}
}
return ok;
})();
setHtml('noindex', (ok ? '' : '!'));
}
var added = '.', rowCount;
/** Check if val is equal to a-delimiter-b where delimiter is '_', '' or big letter
* @param string
* @param string
* @param string
* @return boolean
*/
function delimiterEqual(val, a, b) {
return (val == a + '_' + b || val == a + b || val == a + b.charAt(0).toUpperCase() + b.substr(1));
}
/** Escape string to use as identifier
* @param string
* @return string
*/
function idfEscape(s) {
return s.replace(/`/, '``');
}
/** Set up event handlers for edit_fields().
*/
function editFields() {
var els = qsa('[name$="[field]"]');
for (var i = 0; i < els.length; i++) {
els[i].oninput = function () {
editingNameChange.call(this);
if (!this.defaultValue) {
editingAddRow.call(this);
}
}
}
els = qsa('[name$="[length]"]');
for (var i = 0; i < els.length; i++) {
mixin(els[i], {onfocus: editingLengthFocus, oninput: editingLengthChange});
}
els = qsa('[name$="[type]"]');
for (var i = 0; i < els.length; i++) {
mixin(els[i], {
onfocus: function () { lastType = selectValue(this); },
onchange: editingTypeChange,
onmouseover: function (event) { helpMouseover.call(this, event, getTarget(event).value, 1) },
onmouseout: helpMouseout
});
}
}
/** Handle clicks on fields editing
* @param MouseEvent
* @return boolean false to cancel action
*/
function editingClick(event) {
var el = getTarget(event);
if (!isTag(el, 'input')) {
el = parentTag(el, 'label');
el = el && qs('input', el);
}
if (el) {
var name = el.name;
if (/^add\[/.test(name)) {
editingAddRow.call(el, 1);
} else if (/^up\[/.test(name)) {
editingMoveRow.call(el, 1);
} else if (/^down\[/.test(name)) {
editingMoveRow.call(el);
} else if (/^drop_col\[/.test(name)) {
editingRemoveRow.call(el, 'fields\$1[field]');
} else {
if (name == 'auto_increment_col') {
var field = el.form['fields[' + el.value + '][field]'];
if (!field.value) {
field.value = 'id';
field.oninput();
}
}
return;
}
return false;
}
}
/** Handle input on fields editing
* @param InputEvent
*/
function editingInput(event) {
var el = getTarget(event);
if (/\[default\]$/.test(el.name)) {
el.previousSibling.checked = true;
}
}
/** Detect foreign key
* @this HTMLInputElement
*/
function editingNameChange() {
var name = this.name.substr(0, this.name.length - 7);
var type = formField(this.form, name + '[type]');
var opts = type.options;
var candidate; // don't select anything with ambiguous match (like column `id`)
var val = this.value;
for (var i = opts.length; i--; ) {
var match = /(.+)`(.+)/.exec(opts[i].value);
if (!match) { // common type
if (candidate && i == opts.length - 2 && val == opts[candidate].value.replace(/.+`/, '') && name == 'fields[1]') { // single target table, link to column, first field - probably `id`
return;
}
break;
}
var table = match[1];
var column = match[2];
var tables = [ table, table.replace(/s$/, ''), table.replace(/es$/, '') ];
for (var j=0; j < tables.length; j++) {
table = tables[j];
if (val == column || val == table || delimiterEqual(val, table, column) || delimiterEqual(val, column, table)) {
if (candidate) {
return;
}
candidate = i;
break;
}
}
}
if (candidate) {
type.selectedIndex = candidate;
type.onchange();
}
}
/** Add table row for next field
* @param [boolean]
* @return boolean false
* @this HTMLInputElement
*/
function editingAddRow(focus) {
var match = /(\d+)(\.\d+)?/.exec(this.name);
var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
var row = parentTag(this, 'tr');
var row2 = cloneNode(row);
var tags = qsa('select', row);
var tags2 = qsa('select', row2);
for (var i=0; i < tags.length; i++) {
tags2[i].name = tags[i].name.replace(/[0-9.]+/, x);
tags2[i].selectedIndex = tags[i].selectedIndex;
}
tags = qsa('input', row);
tags2 = qsa('input', row2);
var input = tags2[0]; // IE loose tags2 after insertBefore()
for (var i=0; i < tags.length; i++) {
if (tags[i].name == 'auto_increment_col') {
tags2[i].value = x;
tags2[i].checked = false;
}
tags2[i].name = tags[i].name.replace(/([0-9.]+)/, x);
if (/\[(orig|field|comment|default)/.test(tags[i].name)) {
tags2[i].value = '';
}
if (/\[(has_default)/.test(tags[i].name)) {
tags2[i].checked = false;
}
}
tags[0].oninput = editingNameChange;
row.parentNode.insertBefore(row2, row.nextSibling);
if (focus) {
input.oninput = editingNameChange;
input.focus();
}
added += '0';
rowCount++;
return false;
}
/** Remove table row for field
* @param string regular expression replacement
* @return boolean false
* @this HTMLInputElement
*/
function editingRemoveRow(name) {
var field = formField(this.form, this.name.replace(/[^\[]+(.+)/, name));
field.parentNode.removeChild(field);
parentTag(this, 'tr').style.display = 'none';
return false;
}
/** Move table row for field
* @param [boolean]
* @return boolean false for success
* @this HTMLInputElement
*/
function editingMoveRow(up){
var row = parentTag(this, 'tr');
if (!('nextElementSibling' in row)) {
return true;
}
row.parentNode.insertBefore(row, up
? row.previousElementSibling
: row.nextElementSibling ? row.nextElementSibling.nextElementSibling : row.parentNode.firstChild);
return false;
}
var lastType = '';
/** Clear length and hide collation or unsigned
* @this HTMLSelectElement
*/
function editingTypeChange() {
var type = this;
var name = type.name.substr(0, type.name.length - 6);
var text = selectValue(type);
for (var i=0; i < type.form.elements.length; i++) {
var el = type.form.elements[i];
if (el.name == name + '[length]') {
if (!(
(/(char|binary)$/.test(lastType) && /(char|binary)$/.test(text))
|| (/(enum|set)$/.test(lastType) && /(enum|set)$/.test(text))
)) {
el.value = '';
}
el.oninput.apply(el);
}
if (lastType == 'timestamp' && el.name == name + '[has_default]' && /timestamp/i.test(formField(type.form, name + '[default]').value)) {
el.checked = false;
}
if (el.name == name + '[collation]') {
alterClass(el, 'hidden', !/(char|text|enum|set)$/.test(text));
}
if (el.name == name + '[unsigned]') {
alterClass(el, 'hidden', !/(^|[^o])int(?!er)|numeric|real|float|double|decimal|money/.test(text));
}
if (el.name == name + '[on_update]') {
alterClass(el, 'hidden', !/timestamp|datetime/.test(text)); // MySQL supports datetime since 5.6.5
}
if (el.name == name + '[on_delete]') {
alterClass(el, 'hidden', !/`/.test(text));
}
}
helpClose();
}
/** Mark length as required
* @this HTMLInputElement
*/
function editingLengthChange() {
alterClass(this, 'required', !this.value.length && /var(char|binary)$/.test(selectValue(this.parentNode.previousSibling.firstChild)));
}
/** Edit enum or set
* @this HTMLInputElement
*/
function editingLengthFocus() {
var td = this.parentNode;
if (/(enum|set)$/.test(selectValue(td.previousSibling.firstChild))) {
var edit = qs('#enum-edit');
edit.value = enumValues(this.value);
td.appendChild(edit);
this.style.display = 'none';
edit.style.display = 'inline';
edit.focus();
}
}
/** Get enum values
* @param string
* @return string values separated by newlines
*/
function enumValues(s) {
var re = /(^|,)\s*'(([^\\']|\\.|'')*)'\s*/g;
var result = [];
var offset = 0;
var match;
while (match = re.exec(s)) {
if (offset != match.index) {
break;
}
result.push(match[2].replace(/'(')|\\(.)/g, '$1$2'));
offset += match[0].length;
}
return (offset == s.length ? result.join('\n') : s);
}
/** Finish editing of enum or set
* @this HTMLTextAreaElement
*/
function editingLengthBlur() {
var field = this.parentNode.firstChild;
var val = this.value;
field.value = (/^'[^\n]+'$/.test(val) ? val : val && "'" + val.replace(/\n+$/, '').replace(/'/g, "''").replace(/\\/g, '\\\\').replace(/\n/g, "','") + "'");
field.style.display = 'inline';
this.style.display = 'none';
}
/** Show or hide selected table column
* @param boolean
* @param number
*/
function columnShow(checked, column) {
var trs = qsa('tr', qs('#edit-fields'));
for (var i=0; i < trs.length; i++) {
alterClass(qsa('td', trs[i])[column], 'hidden', !checked);
}
}
/** Display partition options
* @this HTMLSelectElement
*/
function partitionByChange() {
var partitionTable = /RANGE|LIST/.test(selectValue(this));
alterClass(this.form['partitions'], 'hidden', partitionTable || !this.selectedIndex);
alterClass(qs('#partition-table'), 'hidden', !partitionTable);
helpClose();
}
/** Add next partition row
* @this HTMLInputElement
*/
function partitionNameChange() {
var row = cloneNode(parentTag(this, 'tr'));
row.firstChild.firstChild.value = '';
parentTag(this, 'table').appendChild(row);
this.oninput = function () {};
}
/** Show or hide comment fields
* @param HTMLInputElement
* @param [boolean] whether to focus Comment if checked
*/
function editingCommentsClick(el, focus) {
var comment = el.form['Comment'];
columnShow(el.checked, 6);
alterClass(comment, 'hidden', !el.checked);
if (focus && el.checked) {
comment.focus();
}
}
/** Uncheck 'all' checkbox
* @param MouseEvent
* @this HTMLTableElement
*/
function dumpClick(event) {
var el = parentTag(getTarget(event), 'label');
if (el) {
el = qs('input', el);
var match = /(.+)\[\]$/.exec(el.name);
if (match) {
checkboxClick.call(el, event);
formUncheck('check-' + match[1]);
}
}
}
/** Add row for foreign key
* @this HTMLSelectElement
*/
function foreignAddRow() {
var row = cloneNode(parentTag(this, 'tr'));
this.onchange = function () { };
var selects = qsa('select', row);
for (var i=0; i < selects.length; i++) {
selects[i].name = selects[i].name.replace(/\]/, '1$&');
selects[i].selectedIndex = 0;
}
parentTag(this, 'table').appendChild(row);
}
/** Add row for indexes
* @this HTMLSelectElement
*/
function indexesAddRow() {
var row = cloneNode(parentTag(this, 'tr'));
this.onchange = function () { };
var selects = qsa('select', row);
for (var i=0; i < selects.length; i++) {
selects[i].name = selects[i].name.replace(/indexes\[\d+/, '$&1');
selects[i].selectedIndex = 0;
}
var inputs = qsa('input', row);
for (var i=0; i < inputs.length; i++) {
inputs[i].name = inputs[i].name.replace(/indexes\[\d+/, '$&1');
inputs[i].value = '';
}
parentTag(this, 'table').appendChild(row);
}
/** Change column in index
* @param string name prefix
* @this HTMLSelectElement
*/
function indexesChangeColumn(prefix) {
var names = [];
for (var tag in { 'select': 1, 'input': 1 }) {
var columns = qsa(tag, parentTag(this, 'td'));
for (var i=0; i < columns.length; i++) {
if (/\[columns\]/.test(columns[i].name)) {
var value = selectValue(columns[i]);
if (value) {
names.push(value);
}
}
}
}
this.form[this.name.replace(/\].*/, '][name]')].value = prefix + names.join('_');
}
/** Add column for index
* @param string name prefix
* @this HTMLSelectElement
*/
function indexesAddColumn(prefix) {
var field = this;
var select = field.form[field.name.replace(/\].*/, '][type]')];
if (!select.selectedIndex) {
while (selectValue(select) != "INDEX" && select.selectedIndex < select.options.length) {
select.selectedIndex++;
}
select.onchange();
}
var column = cloneNode(field.parentNode);
var selects = qsa('select', column);
for (var i = 0; i < selects.length; i++) {
select = selects[i];
select.name = select.name.replace(/\]\[\d+/, '$&1');
select.selectedIndex = 0;
}
field.onchange = partial(indexesChangeColumn, prefix);
var inputs = qsa('input', column);
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
input.name = input.name.replace(/\]\[\d+/, '$&1');
if (input.type != 'checkbox') {
input.value = '';
}
}
parentTag(field, 'td').appendChild(column);
field.onchange();
}
/** Updates the form action
* @param HTMLFormElement
* @param string
*/
function sqlSubmit(form, root) {
if (encodeURIComponent(form['query'].value).length < 2e3) {
form.action = root
+ '&sql=' + encodeURIComponent(form['query'].value)
+ (form['limit'].value ? '&limit=' + +form['limit'].value : '')
+ (form['error_stops'].checked ? '&error_stops=1' : '')
+ (form['only_errors'].checked ? '&only_errors=1' : '')
;
}
}
/** Handle changing trigger time or event
* @param RegExp
* @param string
* @param HTMLFormElement
*/
function triggerChange(tableRe, table, form) {
var formEvent = selectValue(form['Event']);
if (tableRe.test(form['Trigger'].value)) {
form['Trigger'].value = table + '_' + (selectValue(form['Timing']).charAt(0) + formEvent.charAt(0)).toLowerCase();
}
alterClass(form['Of'], 'hidden', !/ OF/.test(formEvent));
}
var that, x, y; // em and tablePos defined in schema.inc.php
/** Get mouse position
* @param MouseEvent
* @this HTMLElement
*/
function schemaMousedown(event) {
if ((event.which ? event.which : event.button) == 1) {
that = this;
x = event.clientX - this.offsetLeft;
y = event.clientY - this.offsetTop;
}
}
/** Move object
* @param MouseEvent
*/
function schemaMousemove(event) {
if (that !== undefined) {
var left = (event.clientX - x) / em;
var top = (event.clientY - y) / em;
var divs = qsa('div', that);
var lineSet = { };
for (var i=0; i < divs.length; i++) {
if (divs[i].className == 'references') {
var div2 = qs('[id="' + (/^refs/.test(divs[i].id) ? 'refd' : 'refs') + divs[i].id.substr(4) + '"]');
var ref = (tablePos[divs[i].title] ? tablePos[divs[i].title] : [ div2.parentNode.offsetTop / em, 0 ]);
var left1 = -1;
var id = divs[i].id.replace(/^ref.(.+)-.+/, '$1');
if (divs[i].parentNode != div2.parentNode) {
left1 = Math.min(0, ref[1] - left) - 1;
divs[i].style.left = left1 + 'em';
divs[i].querySelector('div').style.width = -left1 + 'em';
var left2 = Math.min(0, left - ref[1]) - 1;
div2.style.left = left2 + 'em';
div2.querySelector('div').style.width = -left2 + 'em';
}
if (!lineSet[id]) {
var line = qs('[id="' + divs[i].id.replace(/^....(.+)-.+$/, 'refl$1') + '"]');
var top1 = top + divs[i].offsetTop / em;
var top2 = top + div2.offsetTop / em;
if (divs[i].parentNode != div2.parentNode) {
top2 += ref[0] - top;
line.querySelector('div').style.height = Math.abs(top1 - top2) + 'em';
}
line.style.left = (left + left1) + 'em';
line.style.top = Math.min(top1, top2) + 'em';
lineSet[id] = true;
}
}
}
that.style.left = left + 'em';
that.style.top = top + 'em';
}
}
/** Finish move
* @param MouseEvent
* @param string
*/
function schemaMouseup(event, db) {
if (that !== undefined) {
tablePos[that.firstChild.firstChild.firstChild.data] = [ (event.clientY - y) / em, (event.clientX - x) / em ];
that = undefined;
var s = '';
for (var key in tablePos) {
s += '_' + key + ':' + Math.round(tablePos[key][0] * 10000) / 10000 + 'x' + Math.round(tablePos[key][1] * 10000) / 10000;
}
s = encodeURIComponent(s.substr(1));
var link = qs('#schema-link');
link.href = link.href.replace(/[^=]+$/, '') + s;
cookie('adminer_schema-' + db + '=' + s, 30); //! special chars in db
}
}
var helpOpen, helpIgnore; // when mouse outs <option> then it mouse overs border of <select> - ignore it
/** Display help
* @param MouseEvent
* @param string
* @param bool display on left side (otherwise on top)
* @this HTMLElement
*/
function helpMouseover(event, text, side) {
var target = getTarget(event);
if (!text) {
helpClose();
} else if (window.jush && (!helpIgnore || this != target)) {
helpOpen = 1;
var help = qs('#help');
help.innerHTML = text;
jush.highlight_tag([ help ]);
alterClass(help, 'hidden');
var rect = target.getBoundingClientRect();
var body = document.documentElement;
help.style.top = (body.scrollTop + rect.top - (side ? (help.offsetHeight - target.offsetHeight) / 2 : help.offsetHeight)) + 'px';
help.style.left = (body.scrollLeft + rect.left - (side ? help.offsetWidth : (help.offsetWidth - target.offsetWidth) / 2)) + 'px';
}
}
/** Close help after timeout
* @param MouseEvent
* @this HTMLElement
*/
function helpMouseout(event) {
helpOpen = 0;
helpIgnore = (this != getTarget(event));
setTimeout(function () {
if (!helpOpen) {
helpClose();
}
}, 200);
}
/** Close help
*/
function helpClose() {
alterClass(qs('#help'), 'hidden', true);
}