-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresentor.js
More file actions
102 lines (88 loc) · 2.78 KB
/
Copy pathpresentor.js
File metadata and controls
102 lines (88 loc) · 2.78 KB
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
function Presentor(line) {
this.line = line;
this.wrapper = jQuery("<div>",{id: "wrapper_" + line, class: "wrapper"}).appendTo("#demo");
this.queue = new Array();
}
Presentor.prototype = {
EMPTY_SIGN: "--",
run: function() {
var cmd;
var _this = this;
if(this.queue.length > 0) {
cmd = this.queue.shift();
cmd.call(this);
setTimeout(function(){_this.run()}, 100);
}
},
clear: function() {
this.queue = new Array();
return(this);
},
set: function(index, value) {
this.queue.push(function() {
var id = "_" + this.line + "_" + index;
var elem = $("#" + id);
if (value === null) value = this.EMPTY_SIGN; // Null is no displayed
if(elem.length > 0) { // Element with the given id found - update it's text
elem.css({'height': value});
$("span", $(elem)).text(value);
//elem.text(value);
} else { // Create the element
jQuery('<span/>', {
text: value
}).appendTo(
jQuery('<div/>', {
id: id,
height: value,
//text: value
}).addClass("element").appendTo(this.wrapper));
}
});
},
fetched: function(index, value) {
this.queue.push(function() {
var position = $("#_" + this.line + "_" + index).position();
jQuery("<div/>", {
id: "_fetched",
text: value + ""
}).addClass("element fetched")
.css({top: position.top, left: position.left})
.animate({top: '-=70'})
//.css({top: position.top - 70, left: position.left})
.appendTo('body');
});
},
unfetched: function(to_index) {
this.queue.push(function() {
$("#_fetched").remove();
});
},
before_compare: function (index_a, index_b) {
this.queue.push(function() {
var element_a = this.Util.element(this.line, index_a);
var element_b = this.Util.element(this.line, index_b);
element_a.add(element_b).addClass("compared");
});
},
compared: function(index_of_larger) {
this.queue.push(function() {
$(".compared").removeClass("compared");
});
},
moved: function(from, to, from_value, to_value) {
this.queue.push(function() {
var from_elem = this.Util.element(this.line, from);
var to_elem = this.Util.element(this.line, to);
from_value = (from_value == null ? this.EMPTY_SIGN : from_value);
to_value = (to_value == null ? this.EMPTY_SIGN : to_value);
from_elem.text(from_value);
to_elem.text(to_value);
});
},
// Utility
Util: {
element: function(line, index) {
return(index < 0 ? $("#_fetched") : $("#_" + line + "_" + index));
}
}
}