-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui_utils.js
1183 lines (909 loc) · 33 KB
/
ui_utils.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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function($) {
'use strict';
if (window.JSVEE === undefined) {
return;
}
JSVEE.utils.ui = {};
/**
* Creates an empty stack frame element. If the PC is given, that will be
* assigned to the stack frame.
*
* @memberOf JSVEE.utils.ui
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createFrame = function(pc, small) {
var frame = $('<div></div>').addClass('jsvee-stack-frame');
var label = $('<div></div>').text(JSVEE.messages.stackFrame());
var emptyVar = JSVEE.utils.ui.createEmptyVar();
var evArea = JSVEE.utils.ui.createEvaluationArea();
frame.attr('title', JSVEE.messages.stackFrameTitle());
frame.attr('data-pc', pc);
if (small) {
frame.addClass('jsvee-small');
} else {
label.addClass('jsvee-area-label jsvee-area-label2');
label.appendTo(frame);
}
emptyVar.appendTo(frame);
evArea.appendTo(frame);
return frame;
};
/**
* Creates an empty variable which is usually a placeholder for new variables
* inside a stack frame.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createEmptyVar = function() {
var emptyVar = $('<div></div>');
emptyVar.addClass('jsvee-variable-empty');
return emptyVar;
};
/**
* Creates a new evaluation area.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createEvaluationArea = function() {
var area = $('<div></div>').addClass('jsvee-evaluation-area');
area.attr('title', JSVEE.messages.evaluationAreaTitle());
area.attr('data-title', JSVEE.messages.evaluationArea());
return area;
};
/**
* Resizes the filler element inside the stack so that all the stack frames
* are in the bottom of the stack.
*/
JSVEE.utils.ui.resizeStack = function(area) {
var stack = area.find('.jsvee-stack');
var frameHeightSum = 0;
var stackFiller = stack.find('.jsvee-stack-filler');
var codeArea = area.find('.jsvee-code-area'),
stackHeight = 0;
var rightPanels = area.find('.jsvee-right-panels');
stack.find('.jsvee-stack-frame').each(function() {
frameHeightSum += $(this).outerHeight(true);
});
/*
* if (stack.attr('data-height') && frameHeightSum ===
* +stack.attr('data-height')) { return; }
*/
stackFiller.css('height', '0px');
stackHeight = stack.height();
if (stackHeight - frameHeightSum > 0) {
stackFiller.css('height', (stackHeight - frameHeightSum) + 'px');
}
if (rightPanels.outerHeight(true) > stackHeight) {
var current = parseInt(stackFiller.css('height'), 10);
stackFiller.css('height', (current + (rightPanels.outerHeight(true) - stack.outerHeight(true))) + 'px');
}
if (codeArea.hasClass('jsvee-code-left') && codeArea.outerHeight(true) > area.find('.jsvee-memory-area').outerHeight(true)) {
var extra = codeArea.outerHeight(true) - area.find('.jsvee-memory-area').outerHeight(true);
var current = parseInt(stackFiller.css('height'), 10);
stackFiller.css('height', (current + extra) + 'px');
}
stack.attr('data-height', frameHeightSum);
};
/**
* Creates a new element for the given value.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createValue = function(value, id, type) {
var val = $('<div></div>').addClass('jsvee-value');
val.attr('data-type', type).attr('data-value', value);
val.attr('data-id', id);
if (type) {
val.attr('title', JSVEE.messages.valueTitleWithType(type, value));
} else {
val.attr('title', JSVEE.messages.valueTitle(value));
}
val.text(value);
return val;
};
/**
* Finds the requested value from the heap. The type is optional.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findValue = function(area, value, type) {
var heap = area.find('.jsvee-heap');
if (type) {
return heap.children('.jsvee-value[data-value="' + value + '"][data-type="' + type + '"]').first();
}
return heap.children('.jsvee-value[data-value="' + value + '"]').first();
};
/**
* Finds the requested value from the heap by the id value. If the id value is
* negative, the value with highest id will be returned.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findValueById = function(area, id) {
if (+id >= 0) {
var result = area.find('.jsvee-instance[data-id="' + id + '"]');
if (result.length > 0)
return result.first();
return area.find('.jsvee-heap .jsvee-value[data-id="' + id + '"]').first();
}
var lastId = +area.find('.jsvee-heap').attr('data-id-counter');
return area.find('.jsvee-instance[data-id="' + (lastId - 1) + '"]').first();
};
/**
* Tries to find the requested value from the heap. If the value does not
* exist, it will be created.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findOrCreateValue = function(area, value, type) {
var result = JSVEE.utils.ui.findValue(area, value, type);
// If the value was not found, create a new
if (result.length === 0) {
// Increase the global id counter
var id = +area.find('.jsvee-heap').attr('data-id-counter');
area.find('.jsvee-heap').attr('data-id-counter', id + 1);
var newVal = value;
if (type === "Double" && value.toString().split(".").length > 1 && value.toString().split(".")[1].length > 3) {
newVal = value.toFixed(3);
}
var newValue = JSVEE.utils.ui.createValue(newVal, id, type);
var heap = area.find('.jsvee-heap');
newValue.appendTo(heap);
return newValue;
}
return result.first();
};
/**
* Creates a new element for a class instance.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createInstance = function(area, className) {
// Increase the global id counter
var id = +area.find('.jsvee-heap').attr('data-id-counter');
area.find('.jsvee-heap').attr('data-id-counter', id + 1);
var instance = $('<div></div>').addClass('jsvee-instance');
var name = $('<div></div>').addClass('jsvee-name');
var name2 = $('<div></div>').addClass('jsvee-name2');
instance.attr('data-type', className);
instance.attr('data-id', id);
instance.attr('title', JSVEE.messages.instanceTitle(className, id));
name.text(id);
name.appendTo(instance);
name2.text(className);
name2.appendTo(name);
return instance;
};
/**
* Creates a new element for a reference.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createReference = function(area, id) {
var ref = $('<div></div>').addClass('jsvee-value jsvee-ref');
var type = area.find('.jsvee-instance[data-id="' + id + '"]').first().attr('data-type');
ref.attr('data-id', id);
ref.attr('data-type', type);
ref.text(id);
ref.attr('title', JSVEE.messages.referenceTitle(id));
return ref;
};
/**
* Finds the most recent class instance in the heap.
*/
JSVEE.utils.ui.findLastInstance = function(area) {
return area.find('.jsvee-heap .jsvee-instance').last();
};
/**
* Finds and creates a new reference. If the id is not defined or it is
* negative, a reference to the most recent object will be returned.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findReference = function(area, id) {
var ref = null;
if (id === undefined || +id < 0) {
ref = JSVEE.utils.ui.findLastInstance(area);
} else {
ref = JSVEE.utils.ui.findValueById(area, id);
}
return JSVEE.utils.ui.createReference(area, ref.attr('data-id'));
};
/**
* Creates a new operator element.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createOperator = function(operator, type, className, params) {
var op = $('<div></div>').addClass('jsvee-operator');
op.attr('title', JSVEE.messages.operatorTitle(operator));
op.attr('data-name', operator);
op.attr('data-class', (className && className.trim().length > 0) ? className : null);
op.attr('data-type', type);
op.attr('data-params', params);
op.text(operator);
return op;
};
/**
* Creates a new function element.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createFunction = function(name, text, paramCount, pc, className, isStatic) {
var f = $('<div></div>').addClass('jsvee-function');
f.attr('data-name', name);
f.attr('data-params', paramCount);
f.attr('data-pc', pc);
f.attr('data-class', className);
f.attr('data-static', isStatic);
f.text(text);
if (className) {
f.attr('title', JSVEE.messages.methodTitle(name));
} else {
f.attr('title', JSVEE.messages.functionTitle(name));
}
if (+pc <= 0) {
f.addClass('jsvee-function-builtin');
}
return f;
};
/**
* Creates a new class element.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createClass = function(name) {
var c = $('<div></div>').addClass('jsvee-class').attr('data-name', name);
c.attr('title', JSVEE.messages.classTitle(name));
var n = $('<div></div>').addClass('jsvee-name');
n.text(name);
n.appendTo(c);
return c;
};
/**
* Calls an function which creates an element, hides it, fades it in and then
* removes the element. This is useful if the animation just fades in the
* element.
*/
JSVEE.utils.ui.fadeInAndRemove = function(ready, func, args) {
var that = this,
args2 = [];
// The given function will call this function and gives
// the created element as parameter
args2.push(function(element) {
// The function may have created multiple elements
if (!$.isArray(element)) {
element.hide().fadeIn(that.animationLength, function() {
element.remove();
ready(); // notifies that the animation is completed
});
} else {
$.each(element, function(i) {
var that = this;
this.hide().fadeIn(that.animationLength, function() {
that.remove();
if (i === element.length - 1) {
ready(); // call the callback after the last element
}
});
});
}
});
args2.push.apply(args2, args);
func.apply(this, args2); // call the actual function
};
/**
* Highlights the current code line and optionally only a portion of it.
*/
JSVEE.utils.ui.highlightCurrentLine = function(area, line, position) {
var codeTable = area.find('.jsvee-code-table');
codeTable.find('.jsvee-arrow-right').remove();
codeTable.find('.jsvee-gutter.jsvee-current').removeClass('jsvee-current');
var arrow = $('<div></div>').addClass('jsvee-arrow-right');
codeTable.find('.jsvee-gutter').eq(line - 1).addClass('jsvee-current').prepend(arrow);
var parent = area.find('.jsvee-current-code-line').parent();
// If only a part of the line is currently highlighted,
// convert the line back to a single span
// data-text in parent contains the original line
if (parent.children().length > 1) {
parent.find('span').remove();
$('<span></span>').text(parent.attr('data-text')).appendTo(parent);
}
codeTable.find('.jsvee-current-code-line').removeClass('jsvee-current-code-line');
var newLine = codeTable.find('.jsvee-code-line').eq(line - 1);
newLine.children().remove();
if (position) {
// Position should be in format "a:b" where
// a is the starting index (starting from 0) and
// b is the position of the last character to be highlighted
var parts = position.split(':');
parts[1] = parseInt(parts[1], 10);
$('<span></span>').text(newLine.attr('data-text').substring(0, parts[0])).appendTo(newLine);
var x = $('<span></span>').text(newLine.attr('data-text').substring(parts[0], parts[1] + 1));
x.addClass('jsvee-current-code-line').appendTo(newLine);
$('<span></span>').text(newLine.attr('data-text').substring(parts[1] + 1)).appendTo(newLine);
} else {
$('<span></span>').text(newLine.attr('data-text')).addClass('jsvee-current-code-line').appendTo(newLine);
}
};
/**
* Shows the given text in the info area.
*/
JSVEE.utils.ui.showInfoText = function(area, text, asHTML) {
if (!asHTML) {
area.find('.jsvee-info-area').text(text).show();
} else {
area.find('.jsvee-info-area').html(text).show();
}
};
/**
* Clears the current info text and hides the info area.
*/
JSVEE.utils.ui.hideInfo = function(area) {
area.find('.jsvee-info-area').hide().text('').children().remove();
};
/**
* Sets the status text to the status area.
*/
JSVEE.utils.ui.setStatusText = function(area, text) {
area.find('.jsvee-status-area').text(text);
};
/**
* Appends the given text to the status area.
*/
JSVEE.utils.ui.appendToStatus = function(area, text) {
var statusArea = area.find('.jsvee-status-area');
statusArea.text(statusArea.text() + text);
};
/**
* Creates a new variable element.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createVariable = function(name) {
var parts = name.split('.');
var n = parts[parts.length - 1];
var variable = $('<div></div>').addClass('jsvee-variable');
variable.attr('data-name', n);
variable.attr('title', JSVEE.messages.variable(n));
$('<div></div>').text(n).addClass('jsvee-name').appendTo(variable);
return variable;
};
/**
* Creates an empty variable element which has only borders.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.createEmptyVariable = function() {
return $('<div></div>').addClass('jsvee-variable-empty-hover');
};
/**
* Places the given variable element to the correct parent element.
*/
JSVEE.utils.ui.placeVariable = function(area, name, variable, ref) {
var parts = name.split('.');
if (parts.length === 1 && !ref) {
// normal local variable
area.find('.jsvee-stack-frame').first().find('.jsvee-variable-empty').before(variable);
} else if (ref) {
// an instance variable
var refVar = JSVEE.utils.ui.findVariable(area, ref.substring(1));
var id = refVar.find('.jsvee-value').attr('data-id');
var instance = JSVEE.utils.ui.findValueById(area, id);
instance.append(variable);
} else {
// a class variable
var classV = area.find('.jsvee-class[data-name="' + parts[0] + '"]').last();
// Find the correct place for the variable:
// a) last of the existing variables
// b) before methods
if (classV.find('.jsvee-variable-empty').length > 0) {
classV.find('.jsvee-variable-empty').before(variable);
} else if (classV.find('.jsvee-function').length > 0) {
classV.find('.jsvee-function').first().before(variable);
} else {
classV.append(variable);
}
// Make sure that the empty container for variables exists
if (classV.find('.jsvee-variable-empty').length === 0) {
var emptyVar = $('<div></div>').addClass('jsvee-variable-empty');
classV.find('.jsvee-variable, .jsvee-variable-empty-hover').last().after(emptyVar);
}
}
};
/**
* Finds the correct evaluation area in the topmost stack frame.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findEvaluationArea = function(area, position) {
var target = area.find('.jsvee-evaluation-area').first();
var i = 0;
if (position) {
var parts = position.split('/');
for (i = 0; i < parts.length - 1; i++) {
if (i % 2 === 0) {
target = target.children().eq(parts[i]);
} else {
target = target.find('.jsvee-evaluation-area-param').eq(parts[i]);
}
}
}
return target;
};
/**
* Animates the movement of the element to the given evaluation area.
*/
JSVEE.utils.ui.animateMoveToTarget = function(area, element, target, original, ready, before, over) {
var clone = element.clone();
clone.css('top', '');
clone.css('left', '');
var point = null;
if (over) { // use the given element as the end position
point = [over.position().left, over.position().top];
} else {
if (!before) {
clone.appendTo(target); // add the element in to the target
} else {
target.before(clone); // add the element before the target
}
point = [clone.position().left, clone.position().top];
}
clone.remove();
JSVEE.utils.ui.animateMove.call(this, area, element, point, original, function() {
ready();
});
};
/**
* Animates the movement of the element to the given coordinates. When this
* function is called, 'this' should point to a JSVEE instance.
*/
JSVEE.utils.ui.animateMove = function(area, element, endPoint, moveOriginal, ready) {
var animLength = this.animationLength;
var move = element;
var clone = null;
var placeholder = null;
if (!moveOriginal) {
clone = element.clone().css('position', 'absolute');
clone.appendTo(area);
clone.offset(element.offset());
// Use the literal area as starting point for values
// if the values in the heap are invisible
if (!element.is(':visible') && element.is('.jsvee-value')) {
clone.offset(area.find('.jsvee-literals').offset());
}
clone.css('z-index', '999');
move = clone;
} else {
element.css('z-index', '999');
if (element.css('position') !== 'absolute') {
element.css('position', 'absolute');
element.offset(element.offset());
}
if (!element.parent().is('.jsvee-animation-area')) {
placeholder = $('<div></div>').css('height', element.outerHeight(true) + 'px').css('width',
element.outerWidth(true) + 'px');
element.before(placeholder);
}
}
move.animate({ top: endPoint[1] + 'px', left: endPoint[0] + 'px' }, animLength, function() {
if (clone !== null) {
clone.remove();
} else {
element.css('z-index', '');
element.css('position', '');
element.css('top', '');
element.css('left', '');
}
if (placeholder !== null) {
placeholder.remove();
}
ready();
});
};
/**
* Finds the requested variable. Returns null, if the variable was not found.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findVariable = function(area, name, id) {
var variable = null;
var parts = name.split('.');
// Local, instance or class variable?
if (parts.length === 1 && !id) {
variable = area.find('.jsvee-stack-frame').first().find('.jsvee-variable[data-name="' + name + '"]');
} else if (id) {
var instance = JSVEE.utils.ui.findValueById(area, id);
variable = instance.find('.jsvee-variable[data-name="' + name + '"]');
} else {
var x = area.find('.jsvee-class[data-name="' + parts[0] + '"]').last();
variable = x.find('.jsvee-variable[data-name="' + parts[1] + '"]');
}
if (variable.length === 0) {
return null;
}
return variable.last();
};
/**
* Finds the first value in the topmost stack frame and returns it.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findFirstValue = function(area) {
var evArea = area.find('.jsvee-stack-frame').first().find('.jsvee-evaluation-area').first();
return evArea.find('.jsvee-value, .jsvee-function').first();
};
/**
* Finds the element in the topmost stack frame in the given position.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findElement = function(area, position, previous) {
if (!position) {
return null;
}
var target = area.find('.jsvee-evaluation-area').first();
var parts = position.split('/');
var i = 0;
var j = null;
for (i = 0; i < parts.length; i++) {
if (target.length === 0) {
return null;
}
j = parts[i];
if (i === parts.length - 1 && previous) {
target = target.children().eq(j - 1);
} else if (target.hasClass('jsvee-function') || target.hasClass('jsvee-operator')) {
target = target.find('.jsvee-evaluation-area-param').eq(j);
} else {
target = target.children().eq(j);
}
}
return target;
};
/**
* Finds the correct operator element.
*
* @param {jQueryObject} area
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findOperator = function(area, operator, position) {
var previous = null;
if (!position) {
previous = area.find('.jsvee-evaluation-area').first().children().last();
} else {
previous = JSVEE.utils.ui.findElement(area, position, true);
}
// Try to find the operator from the correct class
var dataType = previous.attr('data-type');
var op = area.find('.jsvee-class[data-name="' + dataType + '"] .jsvee-operator[data-name="' + operator + '"]');
// If not found, use a generic operator
if (op.length === 0) {
op = area.find('.jsvee-operators .jsvee-operator[data-name="' + operator + '"]');
}
return op.first();
};
/**
* Finds the operands of the given operator.
*
* @returns {Array}
*/
JSVEE.utils.ui.findOperands = function(op) {
var prev = op.prev();
var next = op.next();
var operands = [];
if (op.attr('data-type') === 'lr') {
operands = [prev, next];
} else if (op.attr('data-type') === 'l') {
operands = [prev];
} else if (op.attr('data-type') === 'r') {
operands = [next];
}
return operands;
};
/**
* Flashes the element at the given position. When this function is called,
* 'this' should point to a JSAV instance.
*/
JSVEE.utils.ui.flashElement = function(ready, position) {
var that = this;
var target = JSVEE.utils.ui.findElement(this.area, position);
target.addClass('jsvee-highlight');
target.animate({ delay: 1 }, that.animationLength / 2, function() {
target.removeClass('jsvee-highlight');
target.animate({ delay: 1 }, that.animationLength / 2, function() {
ready();
});
});
};
/**
* Finds the requested function (or method) element.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findFunction = function(area, name, params, className, position) {
if (!className) {
var func = area.find('.jsvee-functions .jsvee-function[data-name="' + name + '"][data-params="' + params + '"]')
.first();
if (func.length == 0) {
func = area.find('.jsvee-functions .jsvee-function[data-name="' + name + '"]').first();
if (+func.attr('data-params') < 0)
return func;
} else {
return func;
}
return null;
}
var realName = className;
// Get the correct type by looking the reference which should already be
// in the evaluation area
if (className === '?') {
var element = JSVEE.utils.ui.findElement(area, position, true);
realName = element.attr('data-type');
}
if (+params > 0) {
var s1 = '.jsvee-classes .jsvee-class[data-name="' + realName + '"]';
var s2 = ' .jsvee-function[data-name="' + name + '"][data-params="' + params + '"]';
var s3 = ' .jsvee-function[data-name="' + name + '"][data-params="-1"]';
return area.find(s1 + s2 + ", " + s1 + s3).first();
}
var s = '.jsvee-classes .jsvee-class[data-name="' + realName + '"] .jsvee-function[data-name="' + name + '"]';
return area.find(s).first();
};
/**
* Converts a function element to contain the evaluation areas for the
* parameters. This is called after a function is added to the evaluation
* area.
*/
JSVEE.utils.ui.convertFunctionToCallable = function(element) {
element.attr('title', '');
element.addClass('jsvee-function');
if (!element.children().first().hasClass('jsvee-ref')) {
element.text('');
var nameLabel = $('<div></div>').addClass('jsvee-function-name');
nameLabel.css('display', 'inline-block');
nameLabel.text(element.attr('data-name'));
nameLabel.appendTo(element);
}
var params = +element.attr('data-params');
var i = 0;
for (i = 0; i < params; i++) {
if (i > 0) {
element.append($('<div style="display: inline-block; vertical-align: bottom;"> , </div>'));
}
$('<div></div>').addClass('jsvee-evaluation-area-param').appendTo(element);
}
// Place the method's self reference inside the function
if (element.attr('data-class') && !element.attr('data-static')) {
var selfParam = $('<div></div>');
selfParam.addClass('jsvee-evaluation-area-param jsvee-self-param').prependTo(element);
var self = element.prev();
self.remove();
self.appendTo(selfParam);
nameLabel.text(' . ' + nameLabel.text());
}
};
/**
* Creates a new element for collection initializer.
*/
JSVEE.utils.ui.createCollectionInitializer = function(area, id, paramCount) {
var element = $('<div></div>').addClass("jsvee-operator");
var selfParam = $('<div></div>');
selfParam.addClass('jsvee-evaluation-area-param jsvee-self-param').appendTo(element);
var collection = JSVEE.utils.ui.findValueById(area, id);
var self = JSVEE.utils.ui.createReference(area, collection.attr('data-id'));
self.appendTo(selfParam);
var arrow = $('<span></span>').html(' ← ');
arrow.appendTo(element);
var i = 0;
for (i = 0; i < paramCount; i++) {
if (i > 0) {
element.append($('<div style="display: inline-block; vertical-align: bottom;"> , </div>'));
}
$('<div></div>').addClass('jsvee-evaluation-area-param').appendTo(element);
}
return element;
};
/**
* Adds the evaluation areas inside the given operator element.
*/
JSVEE.utils.ui.createOperatorParameters = function(element) {
var parts = element.attr('data-params').split('#');
element.text('');
if (element.attr('data-type') === 'pr') {
var selfParam = $('<div></div>');
selfParam.addClass('jsvee-evaluation-area-param jsvee-self-param').prependTo(element);
element.prev().appendTo(element);
}
$.each(parts, function(i, val) {
var span = $('<span></span>').text(val);
element.append(span);
if (i < parts.length - 1) {
var evArea = $('<div></div>').addClass('jsvee-evaluation-area-param');
evArea.appendTo(element);
}
});
};
/**
* Returns if the given function element represents a built-in function, ie.
* the PC value of the function is negative.
*
* @returns {Boolean}
*/
JSVEE.utils.ui.isFunctionBuiltin = function(element) {
var pc = element.attr('data-pc');
return !(pc.toString()[0] === '@' || +pc >= 0);
};
/**
* Finds the topmost active function call which is located in the stack frame
* below the topmost stack frame.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findActiveCall = function(area) {
var frame = area.find('.jsvee-stack-frame').eq(1);
var call = frame.find('.jsvee-function.jsvee-active');
return call;
};
/**
* Finds the requested parameter value in the topmost active function call.
*
* @returns {jQueryObject}
*/
JSVEE.utils.ui.findParameterValue = function(area, index) {
var evArea = JSVEE.utils.ui.findActiveCall(area).find('.jsvee-evaluation-area-param').eq(index);
var value = evArea.find('.jsvee-value, .jsvee-function').first();
return value;
};
/**
* Finds the value which is located in the given collection at the specified
* index.
*
* @returns {jQueryObject}