author | veltr |
Wed, 27 Jun 2012 13:15:28 +0200 | |
changeset 71 | fa03eb8a3fe5 |
parent 70 | 43012525c832 |
child 72 | a000f6a29dfa |
permissions | -rw-r--r-- |
65 | 1 |
/* |
2 |
* Main Timeline code |
|
3 |
*/ |
|
4 |
||
5 |
window.Tlns = { |
|
6 |
Utils : {}, |
|
7 |
Defaults : {}, |
|
8 |
Templates : {}, |
|
9 |
Classes : {} |
|
10 |
}; |
|
11 |
||
12 |
/* Utility Functions */ |
|
13 |
||
14 |
Tlns.Utils.SetDefaults = function(_object, _defaults, _options) { |
|
15 |
var _options = _options || {}; |
|
16 |
_(_defaults).each(function(_v, _k) { |
|
17 |
if(/^m(in|ax)_/.test(_k)) { |
|
18 |
var _tab = _k.split('_') |
|
19 |
if( typeof _object[_tab[1]] !== "undefined") { |
|
20 |
var _fn = (_tab[0] === "min" ? Math.max : Math.min); |
|
21 |
_object[_tab[1]] = _fn(_object[_tab[1]], _v); |
|
22 |
} |
|
23 |
} else { |
|
24 |
if( typeof _options[_k] !== "undefined") { |
|
25 |
_object[_k] = _options[_k]; |
|
26 |
} else { |
|
27 |
_object[_k] = _v; |
|
28 |
} |
|
29 |
} |
|
30 |
}); |
|
31 |
} |
|
32 |
||
33 |
Tlns.Utils.dateFormat = function(_date, _template) { |
|
34 |
if (typeof _data !== "object") { |
|
35 |
_date = new Date(_date); |
|
36 |
} |
|
37 |
function zeroPad(_n) { |
|
38 |
return (_n < 10 ? "0" : "") + _n |
|
39 |
} |
|
40 |
var _params = { |
|
41 |
hours: _date.getHours(), |
|
42 |
"0hours": zeroPad(_date.getHours()), |
|
43 |
minutes: _date.getMinutes(), |
|
44 |
"0minutes": zeroPad(_date.getMinutes()), |
|
45 |
seconds: _date.getSeconds(), |
|
46 |
"0seconds": zeroPad(_date.getSeconds()), |
|
47 |
dayOfWeek: ["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"][_date.getDay()], |
|
48 |
shortDayOfWeek: ["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"][_date.getDay()], |
|
49 |
dayOfMonth: _date.getDate(), |
|
50 |
"0dayOfMonth": zeroPad(_date.getDate()), |
|
51 |
monthNumber: 1+_date.getMonth(), |
|
52 |
"0monthNumber": zeroPad(1+_date.getMonth()), |
|
53 |
monthName: ["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"][_date.getMonth()], |
|
54 |
shortMonthName: ["jan","fev","mar","avr","mai","jun","jul","aou","sep","oct","nov","dec"][_date.getMonth()], |
|
55 |
year: _date.getFullYear() |
|
56 |
} |
|
57 |
return Mustache.to_html(_template, _params); |
|
58 |
} |
|
59 |
||
71 | 60 |
Tlns.Utils.guid = function() { |
61 |
return 'xxxx-xxxx-xxxx-xxxx'.replace(/x/g,function() { |
|
62 |
return Math.floor(Math.random()*16).toString(16); |
|
63 |
}); |
|
64 |
} |
|
65 |
||
65 | 66 |
/* Defaults */ |
67 |
||
68 |
Tlns.Defaults.Timeline = { |
|
69 |
container : "timeline", |
|
70 |
width : 950, |
|
71 |
height : 200, |
|
72 |
url_univers : '', |
|
73 |
min_width : 400, |
|
74 |
min_height : 100, |
|
75 |
main_width : 800, |
|
76 |
timescales : [{ |
|
77 |
label : "Mois", |
|
78 |
span : 32 * 86400 * 1000, |
|
79 |
grid_interval : 5 * 86400 * 1000, |
|
80 |
grid_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
81 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
82 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{year}}' |
|
83 |
}, { |
|
84 |
label : "Semaine", |
|
85 |
span : 8 * 86400 * 1000, |
|
86 |
grid_interval : 86400 * 1000, |
|
87 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}}', |
|
88 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
89 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
90 |
}, { |
|
91 |
label : "2 jours", |
|
92 |
span : 2 * 86400 * 1000, |
|
93 |
grid_interval : 8 * 3600 * 1000, |
|
94 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}} {{hours}}h', |
|
95 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
96 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
97 |
}, { |
|
98 |
label : "Demi-Journée", |
|
99 |
span : 12 * 3600 * 1000, |
|
100 |
grid_interval : 2 * 3600 * 1000, |
|
101 |
grid_date_format : '{{hours}}h', |
|
102 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h', |
|
103 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h' |
|
104 |
}, { |
|
105 |
label : "3 Heures", |
|
106 |
span : 3 * 3600 * 1000, |
|
107 |
grid_interval : 30 * 60 * 1000, |
|
108 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
109 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
110 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
111 |
}, { |
|
112 |
label : "1 Heure", |
|
66 | 113 |
span : 60 * 60 * 1000, |
65 | 114 |
grid_interval : 15 * 60 * 1000, |
115 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
116 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
117 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
118 |
}], |
|
119 |
level: 0, |
|
120 |
central_time: 0, |
|
121 |
sync_now: true, |
|
122 |
url_occurrences: '', |
|
66 | 123 |
occurrences: [], |
70 | 124 |
cluster_spacing: 10, |
125 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}' |
|
65 | 126 |
} |
127 |
||
128 |
for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { |
|
129 |
Tlns.Defaults.Timeline.timescales[_i].level = _i; |
|
130 |
} |
|
131 |
||
132 |
/* Templates */ |
|
133 |
||
134 |
Tlns.Templates.Timeline = '<div class="Tl-TopBar"><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-AddButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
135 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-PreviousButton"></div></div><div class="Tl-TopBar-TimeSpan Tl-TopBar-TextBtn Tl-Border-Right">--/--</div>' |
|
136 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-SyncButton"></div></div><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-NextButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
137 |
+ '<div class="Tl-TopBar-Timescales">{{#timescales}}<div class="Tl-TopBar-Button Tl-TopBar-TextBtn Tl-Border-Right" data-level="{{level}}">{{label}}</div>{{/timescales}}</div></div>' |
|
71 | 138 |
+ '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
139 |
+ '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><canvas class="Tl-Layer Tl-Linking-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div>' |
|
140 |
+ '<ul class="Tl-Adding"><li class="Tl-AddingTitle">Ajout d\'une occurrence</li><li><span>Narrative</span><div class="Tl-AddOccurrence Tl-Occnarrative" occurrence-type="narrative" title="Glisser sur la frise chronologique pour ajouter"></div></li>' |
|
141 |
+ '<li><span>De Production</span><div class="Tl-AddOccurrence Tl-Occproduction" occurrence-type="production" title="Glisser sur la frise chronologique pour ajouter"></div></li></ul></div>' |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
142 |
+ '<div class="Tl-Overlay-Container"><div class="Tl-Overlay-Box"><div class="Tl-Overlay"><div class="Tl-Overlay-Tip-Top"></div><div class="Tl-Overlay-Main"></div><div class="Tl-Overlay-Tip-Bottom"></div></div></div></div></div>'; |
65 | 143 |
|
66 | 144 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
145 |
||
70 | 146 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster Tl-Occ{{type}}" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
147 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
148 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-type="{{type}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">' |
|
149 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
|
150 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-type="{{type}}" occurrence-id="{{id}}">' |
|
151 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
|
152 |
|
|
153 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}}</p>' |
|
154 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p><p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
65 | 155 |
|
156 |
/* Classes */ |
|
157 |
||
158 |
Tlns.Classes.Timeline = function(_options) { |
|
159 |
||
160 |
/* Setting Defaults */ |
|
161 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
162 |
||
163 |
/* Setting container CSS */ |
|
164 |
this.$ = $('#' + this.container); |
|
165 |
this.$.addClass('Tl-Main'); |
|
166 |
this.$.css({ |
|
167 |
width : this.width + "px", |
|
168 |
height : this.height + "px" |
|
169 |
}); |
|
170 |
this.$.html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
171 |
|
|
172 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
173 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
174 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
67 | 175 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
70 | 176 |
this.$.find('canvas.Tl-Layer').attr({ |
67 | 177 |
width: this.main_width, |
178 |
height: this.main_height |
|
179 |
}); |
|
65 | 180 |
var _o = this.$.find('.Tl-MainPart').offset(); |
181 |
this.dragging_bounds = { |
|
182 |
left: _o.left, |
|
183 |
top: _o.top, |
|
184 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
185 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
186 |
}; |
|
187 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
188 |
var _this = this; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
189 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
190 |
this.throttledDrawGrid = _.throttle(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
191 |
_this.drawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
192 |
}, 150); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
193 |
|
65 | 194 |
this.setLevel(this.level); |
195 |
|
|
196 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
197 |
_this.setLevel($(this).attr("data-level")); |
|
198 |
}); |
|
199 |
|
|
200 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
201 |
_this.sync_now = !_this.sync_now; |
|
202 |
_this.drawGrid(); |
|
203 |
}) |
|
204 |
|
|
205 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
206 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
207 |
}); |
|
208 |
|
|
209 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
210 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
211 |
}); |
|
212 |
|
|
213 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
214 |
_this.onMouseDown(_event); |
|
215 |
return false; |
|
216 |
}); |
|
217 |
|
|
218 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
219 |
_this.onMouseMove(_event); |
|
220 |
return false; |
|
221 |
}); |
|
222 |
|
|
223 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
224 |
_this.onMouseUp(_event); |
|
225 |
return false; |
|
226 |
}); |
|
227 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
228 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
229 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
230 |
if (_newLevel != _this.level) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
231 |
_this.hideTooltip(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
232 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
233 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
234 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
235 |
_newStart = _tAtMouse - _deltaX / _newScale; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
236 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
237 |
_this.setLevel(_newLevel); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
238 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
239 |
return false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
240 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
241 |
|
66 | 242 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
243 |
$(this).show(); |
|
244 |
}).mouseout(function(_event) { |
|
245 |
$(this).hide(); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
246 |
}); |
65 | 247 |
|
71 | 248 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
249 |
$(this).toggleClass('active'); |
|
250 |
_this.$.find('.Tl-Adding').toggle(); |
|
251 |
}); |
|
252 |
|
|
253 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
254 |
var _el = $(this), |
|
255 |
_type = _el.attr("occurrence-type"), |
|
256 |
_d = _this.timeFromMouse(_event.pageX), |
|
257 |
_u = _this.universFromMouse(_event.pageY), |
|
258 |
_occ = _this.createOrUpdateOccurrence( |
|
259 |
_type, |
|
260 |
{ |
|
261 |
date: _d, |
|
262 |
titre: '<Nouvelle occurrence>', |
|
263 |
univers: _this.univers[_u].id, |
|
264 |
publie: true |
|
265 |
} |
|
266 |
); |
|
267 |
_occ.just_created = true; |
|
268 |
_occ.editing = true; |
|
269 |
_this.editing_occurrence = _occ; |
|
270 |
_this.dragging_type = "occurrence"; |
|
271 |
window.setTimeout(function () { |
|
272 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
273 |
_this.$.find('.Tl-Adding').hide(); |
|
274 |
}, 200); |
|
275 |
_this.throttledDrawGrid(); |
|
276 |
}).mouseup(function(_event) { |
|
277 |
_this.onMouseUp(_event); |
|
278 |
return false; |
|
279 |
}); |
|
280 |
|
|
65 | 281 |
/* Loading Univers */ |
282 |
$.getJSON(this.url_univers, function(_data) { |
|
283 |
_this.onUniversLoaded(_data); |
|
284 |
}); |
|
285 |
} |
|
286 |
||
287 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
288 |
this.mouse_down = true; |
|
289 |
this.is_dragging = false; |
|
290 |
this.start_pos = { |
|
291 |
x: _event.pageX, |
|
292 |
y: _event.pageY |
|
293 |
}; |
|
66 | 294 |
if (typeof this.dragging_type === "undefined") { |
67 | 295 |
this.time_at_start = this.central_time; |
66 | 296 |
this.dragging_type = "timeline"; |
65 | 297 |
} |
298 |
} |
|
299 |
||
300 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
67 | 301 |
if (this.is_dragging) { |
302 |
switch (this.dragging_type) { |
|
303 |
case "occurrence": |
|
304 |
this.editing_occurrence.editing = false; |
|
71 | 305 |
this.editing_occurrence.just_created = false; |
67 | 306 |
this.throttledDrawGrid(); |
307 |
break; |
|
70 | 308 |
case "link": |
309 |
this.editing_occurrence.editing = false; |
|
310 |
this.throttledDrawGrid(); |
|
311 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
312 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
313 |
break; |
|
67 | 314 |
} |
71 | 315 |
} else { |
316 |
if (this.dragging_type == "occurrence" && this.editing_occurrence.just_created) { |
|
317 |
this.deleteOccurrence(this.editing_occurrence.type, this.editing_occurrence.id); |
|
318 |
this.throttledDrawGrid(); |
|
319 |
} |
|
67 | 320 |
} |
65 | 321 |
this.mouse_down = false; |
322 |
this.is_dragging = false; |
|
66 | 323 |
this.dragging_type = undefined; |
65 | 324 |
} |
325 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
326 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
327 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
328 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
329 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
330 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
331 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
332 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
333 |
|
71 | 334 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
335 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
336 |
} |
|
337 |
||
338 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
339 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
340 |
} |
|
341 |
||
65 | 342 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
343 |
if (this.mouse_down) { |
|
344 |
this.is_dragging = true; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
345 |
this.hideTooltip(); |
69 | 346 |
switch (this.dragging_type) { |
347 |
case "occurrence": |
|
348 |
var _d = this.timeFromMouse(_event.pageX); |
|
349 |
this.editing_occurrence.date = _d; |
|
71 | 350 |
var _u = this.universFromMouse(_event.pageY); |
69 | 351 |
this.editing_occurrence.univers = this.univers[_u]; |
352 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
353 |
this.throttledDrawGrid(); |
|
354 |
break; |
|
355 |
case "timeline": |
|
356 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
357 |
break; |
|
70 | 358 |
case "link": |
359 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
360 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
361 |
_ctx.beginPath(); |
|
362 |
_ctx.strokeStyle = '#800080'; |
|
363 |
_ctx.moveTo(this.editing_occurrence.x,this.editing_occurrence.y + Math.floor(this.univers_height / 2)); |
|
364 |
_ctx.lineTo(_event.pageX - this.dragging_bounds.left, _event.pageY - this.dragging_bounds.top); |
|
365 |
_ctx.stroke(); |
|
366 |
break; |
|
65 | 367 |
} |
368 |
} |
|
369 |
} |
|
370 |
||
371 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
372 |
this.univers = []; |
|
373 |
if(_data.length) { |
|
374 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
375 |
} |
|
376 |
for(var _i = 0; _i < _data.length; _i++) { |
|
377 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
378 |
} |
|
66 | 379 |
this.loadOccurrences(); |
65 | 380 |
} |
381 |
||
382 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
383 |
this.setTime(this.central_time + _timeOffset); |
|
384 |
} |
|
385 |
||
386 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
387 |
this.sync_now = false; |
|
388 |
this.central_time = _centralTime; |
|
67 | 389 |
this.throttledDrawGrid(); |
65 | 390 |
} |
391 |
||
392 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
393 |
if (_level >= 0 && _level < this.timescales.length) { |
|
394 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
395 |
var _el = $(this); |
|
396 |
if (_el.attr("data-level") == _level) { |
|
397 |
_el.addClass("active"); |
|
398 |
} else { |
|
399 |
_el.removeClass("active"); |
|
400 |
} |
|
401 |
}); |
|
402 |
this.level = _level; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
403 |
this.throttledDrawGrid(); |
65 | 404 |
} |
405 |
} |
|
406 |
||
407 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
408 |
var _now = new Date().valueOf(); |
|
409 |
if (this.sync_now) { |
|
410 |
this.central_time = _now; |
|
411 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
412 |
} else { |
|
413 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
414 |
} |
|
415 |
var _timescale = this.timescales[this.level], |
|
416 |
_offset = new Date().getTimezoneOffset() * 60000; |
|
66 | 417 |
this.current_scale = this.main_width / (_timescale.span) |
418 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
419 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
420 |
var _grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
421 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
65 | 422 |
_html = ''; |
66 | 423 |
this.$.find('.Tl-TopBar-TimeSpan').html(Tlns.Utils.dateFormat(this.start_time, _timescale.start_date_format) + ' - ' + Tlns.Utils.dateFormat(this.end_time, _timescale.end_date_format)); |
424 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
425 |
var _x = this.current_scale * (_t - this.start_time); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
426 |
if (_x > 0) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
427 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
428 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
429 |
} |
65 | 430 |
} |
431 |
/* |
|
432 |
|
|
433 |
for (var _t = _roundstart; _t < _tmax; _t += _timescale.grid_interval) { |
|
434 |
var _isMajor = !(Math.floor((_t - _offset) / _timescale.grid_interval) % _timescale.major_interval); |
|
67 | 435 |
_html += '<div class="Tl-Grid-Column' + ( _isMajor ? ' Tl-Grid-Major' : '' ) + '" style="width:' + _grid_width + 'px; left: ' + _scale * (_t - this.start_time) + 'px">' |
65 | 436 |
+ ( _isMajor ? '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.date_format) + '</div>' : '' ) + '</div>'; |
437 |
} |
|
438 |
*/ |
|
66 | 439 |
if (this.start_time <= _now && this.end_time >= _now) { |
67 | 440 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
65 | 441 |
} |
442 |
this.$.find('.Tl-Grid').html(_html); |
|
66 | 443 |
this.drawOccurrences(); |
444 |
} |
|
445 |
||
446 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
447 |
var _url = Mustache.to_html(this.url_occurrences, { |
|
448 |
from_time: this.start_time, |
|
449 |
to_time: this.end_time |
|
450 |
}), |
|
451 |
_this = this; |
|
452 |
$.getJSON(_url, function(_data) { |
|
453 |
_this.onOccurrencesLoaded(_data); |
|
454 |
}); |
|
455 |
} |
|
456 |
||
457 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data) { |
|
458 |
if (typeof _data.occurrencesNarratives === "object" && _data.occurrencesNarratives !== null) { |
|
459 |
for (var _i = 0; _i < _data.occurrencesNarratives.length; _i++) { |
|
460 |
this.createOrUpdateOccurrence("narrative", _data.occurrencesNarratives[_i]); |
|
461 |
} |
|
462 |
for (var _i = 0; _i < _data.occurrencesProduction.length; _i++) { |
|
463 |
this.createOrUpdateOccurrence("production", _data.occurrencesProduction[_i]); |
|
464 |
} |
|
465 |
} |
|
466 |
if (!this.mouse_down) { |
|
467 |
this.drawOccurrences(); |
|
468 |
} |
|
469 |
} |
|
470 |
||
71 | 471 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_type, _id) { |
472 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
|
473 |
return (_occ.type == _type && _occ.id == _id); |
|
474 |
}); |
|
475 |
} |
|
476 |
||
66 | 477 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_type, _id) { |
478 |
return _(this.occurrences).find(function(_occ) { |
|
479 |
return (_occ.type == _type && _occ.id == _id); |
|
480 |
}); |
|
481 |
} |
|
482 |
||
483 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
484 |
var _occurrence = this.getOccurrence(_type, _data.id); |
|
485 |
if (typeof _occurrence === "undefined") { |
|
486 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
487 |
this.occurrences.push(_occurrence); |
|
488 |
} |
|
489 |
_occurrence.update(_type, _data); |
|
71 | 490 |
return _occurrence; |
66 | 491 |
} |
492 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
493 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
494 |
this.$.find('.Tl-Overlay-Box') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
495 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
496 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
497 |
.show() |
66 | 498 |
.css({ |
499 |
left: _x + "px", |
|
500 |
top: _y + "px" |
|
501 |
}); |
|
502 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
503 |
} |
|
504 |
||
505 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
506 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
65 | 507 |
} |
508 |
||
509 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
66 | 510 |
var _this = this, |
511 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
512 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.published); |
|
513 |
}); |
|
514 |
_(_visible).each(function(_occ) { |
|
67 | 515 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
516 |
_occ.y = _occ.univers.y; |
66 | 517 |
_occ.in_cluster = false; |
518 |
}); |
|
65 | 519 |
|
66 | 520 |
var _moved = true; |
521 |
while (_moved) { |
|
522 |
_moved = false; |
|
523 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
524 |
for (var _j = 0; _j < _i; _j++) { |
|
525 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
526 |
&& _visible[_j].x != _visible[_i].x |
|
527 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
528 |
) { |
|
529 |
_moved = true; |
|
530 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
531 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
532 |
} |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
536 |
var _clusters = [], |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
537 |
_openCluster = false; |
66 | 538 |
for (var _i = 0; _i < _visible.length; _i++) { |
539 |
for (var _j = 0; _j < _i; _j++) { |
|
540 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
541 |
_visible[_j].in_cluster = true; |
|
542 |
_visible[_i].in_cluster = true; |
|
543 |
var _x = _visible[_j].x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
544 |
_y = _visible[_j].y; |
66 | 545 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
546 |
if (typeof _cluster === "undefined") { |
|
547 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
548 |
_clusters.push(_cluster); |
|
549 |
} |
|
550 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
551 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
552 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
553 |
_cluster.occurrences.push(_visible[_j]); |
66 | 554 |
} |
555 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
556 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
557 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
558 |
_cluster.occurrences.push(_visible[_i]); |
66 | 559 |
} |
560 |
} |
|
561 |
} |
|
562 |
} |
|
563 |
_(_clusters).each(function(_cluster) { |
|
70 | 564 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
565 |
return _o.date; |
|
566 |
}); |
|
66 | 567 |
_cluster.type = _cluster.occurrences[0].type; |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
568 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
569 |
return _o.type + ":" + _o.id; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
570 |
}).join("|"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
571 |
if (_cluster.contents == _this.open_cluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
572 |
_openCluster = _cluster; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
573 |
} |
66 | 574 |
for (var _i = 1; _i < _cluster.occurrences.length; _i++) { |
575 |
if (_cluster.occurrences[_i].type !== _cluster.type) { |
|
576 |
_cluster.type = "both"; |
|
577 |
break; |
|
578 |
} |
|
579 |
} |
|
580 |
}); |
|
581 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
582 |
|
67 | 583 |
var _links = []; |
584 |
|
|
585 |
_(_visible).each(function(_occurrence) { |
|
586 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
587 |
var _parent = _(_visible).find(function(_o) { |
|
588 |
return _o.type == "narrative" && _o.id == _dependance; |
|
589 |
}); |
|
590 |
if (typeof _parent !== "undefined") { |
|
591 |
_links.push({ |
|
592 |
from_x: _occurrence.x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
593 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
67 | 594 |
to_x: _parent.x, |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
595 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
67 | 596 |
}); |
597 |
} |
|
598 |
}); |
|
599 |
}); |
|
600 |
|
|
601 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
602 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
603 |
_(_links).each(function(_link) { |
|
604 |
_ctx.beginPath(); |
|
605 |
_ctx.moveTo(_link.from_x,_link.from_y); |
|
606 |
_ctx.lineTo(_link.to_x,_link.to_y); |
|
607 |
_ctx.stroke(); |
|
70 | 608 |
}); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
609 |
|
66 | 610 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
611 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
612 |
clusters: _clusters, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
613 |
open_cluster: _openCluster |
66 | 614 |
}); |
615 |
this.$.find('.Tl-Occurrences').html(_html); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
616 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
617 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
618 |
if (_openCluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
619 |
var _w = this.$.find('.Tl-Occurrence').width(), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
620 |
_ww = _w * _openCluster.occurrences.length; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
621 |
this.$.find('.Tl-ClusterOverlay').css({ |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
622 |
"margin-left": - Math.floor(_ww/2) + "px", |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
623 |
width: _ww |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
624 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
625 |
_(_openCluster.occurrences).each(function(_o, _i) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
626 |
_o.y = _o.y - 20; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
627 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
628 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
629 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
630 |
|
66 | 631 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
71 | 632 |
var _el = $(this), |
633 |
_type = _el.attr("occurrence-type"), |
|
634 |
_id = _el.attr("occurrence-id"); |
|
635 |
if (typeof _type !== "undefined" && typeof _id !== "undefined") { |
|
636 |
_this.editing_occurrence = _this.getOccurrence(_type,_id); |
|
637 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
|
638 |
_this.dragging_type = "occurrence"; |
|
639 |
_this.editing_occurrence.editing = true; |
|
640 |
} |
|
67 | 641 |
} |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
642 |
}).mouseover(function(_event) { |
66 | 643 |
var _el = $(this), |
71 | 644 |
_type = _el.attr("occurrence-type"), |
645 |
_id = _el.attr("occurrence-id"); |
|
646 |
if (typeof _type !== "undefined" && typeof _id !== "undefined") { |
|
647 |
var _occurrence = _this.getOccurrence(_type, _id); |
|
648 |
if (!_occurrence.locked) { |
|
649 |
_el.find('.Tl-Link').show(); |
|
650 |
} |
|
651 |
_occurrence.formatted_date = Tlns.Utils.dateFormat(_occurrence.date,_this.tooltip_date_format); |
|
652 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
|
653 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
|
70 | 654 |
} |
66 | 655 |
}).mouseout(function() { |
70 | 656 |
var _el = $(this), |
71 | 657 |
_type = _el.attr("occurrence-type"), |
658 |
_id = _el.attr("occurrence-id"); |
|
659 |
if (typeof _type !== "undefined" && typeof _id !== "undefined") { |
|
660 |
var _occurrence = _this.getOccurrence(_type, _id); |
|
661 |
_this.hideTooltip(); |
|
662 |
if (!_occurrence.editing) { |
|
663 |
$(this).find('.Tl-Link').hide(); |
|
664 |
} |
|
70 | 665 |
} |
666 |
}).mouseup(function() { |
|
667 |
var _el = $(this); |
|
668 |
if (_this.dragging_type == "link" && _el.attr("occurrence-type") == "narrative") { |
|
669 |
_this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
|
670 |
} |
|
66 | 671 |
}); |
70 | 672 |
|
673 |
this.$.find('.Tl-Link').mousedown(function() { |
|
674 |
var _el = $(this).parent(); |
|
675 |
_this.editing_occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
|
676 |
if (typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
|
677 |
_this.dragging_type = "link"; |
|
678 |
_this.editing_occurrence.editing = true; |
|
679 |
} |
|
680 |
}) |
|
681 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
682 |
this.$.find('.Tl-Cluster').click(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
683 |
var _el = $(this), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
684 |
_contents = _el.attr("cluster-contents"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
685 |
if (_this.open_cluster == _contents) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
686 |
_this.open_cluster = false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
687 |
} else { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
688 |
_this.open_cluster = _contents; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
689 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
690 |
_this.throttledDrawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
691 |
}) |
65 | 692 |
} |
693 |
||
66 | 694 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
695 |
return _(this.univers).find(function(_univ) { |
|
696 |
return (_univ.id == _id); |
|
697 |
}); |
|
698 |
} |
|
699 |
||
700 |
/* |
|
701 |
* Univers |
|
702 |
*/ |
|
703 |
||
65 | 704 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
705 |
this.id = _data.id; |
|
706 |
this.index = _index; |
|
707 |
this.title = _data.nom; |
|
708 |
this.mainCharacter = _data.personnage; |
|
66 | 709 |
this.y = (_timeline.univers_height * _index); |
65 | 710 |
|
711 |
this.$label = $('<li>').css({ |
|
712 |
height : _timeline.univers_height + "px" |
|
713 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
66 | 714 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
65 | 715 |
|
716 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
717 |
var _txt = _data.nom, |
|
718 |
_span = this.$label.find('span'); |
|
719 |
||
720 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
721 |
_txt = _txt.substr(0, _txt.length - 1); |
|
722 |
_span.html(_txt + '…'); |
|
723 |
} |
|
724 |
} |
|
66 | 725 |
|
726 |
/* |
|
727 |
* Occurrence |
|
728 |
*/ |
|
729 |
||
730 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
731 |
this.timeline = _timeline; |
|
732 |
} |
|
733 |
||
734 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
735 |
this.type = _type; |
|
71 | 736 |
this.id = _data.id || Tlns.Utils.guid(); |
66 | 737 |
this.date = _data.date || _data.datePublication; |
738 |
this.title = _data.titre || "<untitled>"; |
|
739 |
this.univers_id = _data.univers; |
|
740 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
741 |
this.status = _data.statut; |
|
742 |
this.published = _data.publie || false; |
|
743 |
this.locked = _data.verrouille || false; |
|
744 |
this.characters = _data.personnagesSecondaires || []; |
|
745 |
this.dependsOn = _data.dependDe || []; |
|
70 | 746 |
this.description = _data.description || ""; |
747 |
} |
|
748 |
||
749 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
750 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
751 |
this.dependsOn.push(_id); |
|
752 |
} |
|
66 | 753 |
} |
754 |
||
755 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
756 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
757 |
} |