126 |
127 |
127 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>' |
128 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>' |
128 + '<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>' |
129 + '<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>' |
129 + '<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>' |
130 + '<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>' |
130 + '<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>' |
131 + '<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>' |
131 + '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul><div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div></div>' |
132 + '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul><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></div>' |
132 + '<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>'; |
133 + '<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>'; |
133 |
134 |
134 Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
135 Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
135 |
136 |
136 Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster Tl-Occ{{type}}" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}"><div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}{{#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;"></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-type="{{type}}" occurrence-id="{{id}}"></div>{{/occurrences}}</div>{{/open_cluster}}'; |
137 Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster Tl-Occ{{type}}" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
|
138 + '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
139 + '{{#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;">' |
|
140 + '{{#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;">' |
|
141 + '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-type="{{type}}" occurrence-id="{{id}}">' |
|
142 + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
|
143 |
|
144 Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}}</p>' |
|
145 + '<p class="Tl-Tooltip-Description">{{description}}</p><p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
137 |
146 |
138 /* Classes */ |
147 /* Classes */ |
139 |
148 |
140 Tlns.Classes.Timeline = function(_options) { |
149 Tlns.Classes.Timeline = function(_options) { |
141 |
150 |
153 |
162 |
154 this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
163 this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
155 this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
164 this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
156 this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
165 this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
157 this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
166 this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
158 this.$.find('.Tl-Canvas').attr({ |
167 this.$.find('canvas.Tl-Layer').attr({ |
159 width: this.main_width, |
168 width: this.main_width, |
160 height: this.main_height |
169 height: this.main_height |
161 }); |
170 }); |
162 var _o = this.$.find('.Tl-MainPart').offset(); |
171 var _o = this.$.find('.Tl-MainPart').offset(); |
163 this.dragging_bounds = { |
172 this.dragging_bounds = { |
250 if (this.is_dragging) { |
259 if (this.is_dragging) { |
251 switch (this.dragging_type) { |
260 switch (this.dragging_type) { |
252 case "occurrence": |
261 case "occurrence": |
253 this.editing_occurrence.editing = false; |
262 this.editing_occurrence.editing = false; |
254 this.throttledDrawGrid(); |
263 this.throttledDrawGrid(); |
|
264 break; |
|
265 case "link": |
|
266 this.editing_occurrence.editing = false; |
|
267 this.throttledDrawGrid(); |
|
268 var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
269 _ctx.clearRect(0,0,this.main_width, this.main_height); |
255 break; |
270 break; |
256 } |
271 } |
257 } |
272 } |
258 this.mouse_down = false; |
273 this.mouse_down = false; |
259 this.is_dragging = false; |
274 this.is_dragging = false; |
281 this.editing_occurrence.univers_id = this.univers[_u].id; |
296 this.editing_occurrence.univers_id = this.univers[_u].id; |
282 this.throttledDrawGrid(); |
297 this.throttledDrawGrid(); |
283 break; |
298 break; |
284 case "timeline": |
299 case "timeline": |
285 this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
300 this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
301 break; |
|
302 case "link": |
|
303 var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
304 _ctx.clearRect(0,0,this.main_width, this.main_height); |
|
305 _ctx.beginPath(); |
|
306 _ctx.strokeStyle = '#800080'; |
|
307 _ctx.moveTo(this.editing_occurrence.x,this.editing_occurrence.y + Math.floor(this.univers_height / 2)); |
|
308 _ctx.lineTo(_event.pageX - this.dragging_bounds.left, _event.pageY - this.dragging_bounds.top); |
|
309 _ctx.stroke(); |
286 break; |
310 break; |
287 } |
311 } |
288 } |
312 } |
289 } |
313 } |
290 |
314 |
513 _(_links).each(function(_link) { |
540 _(_links).each(function(_link) { |
514 _ctx.beginPath(); |
541 _ctx.beginPath(); |
515 _ctx.moveTo(_link.from_x,_link.from_y); |
542 _ctx.moveTo(_link.from_x,_link.from_y); |
516 _ctx.lineTo(_link.to_x,_link.to_y); |
543 _ctx.lineTo(_link.to_x,_link.to_y); |
517 _ctx.stroke(); |
544 _ctx.stroke(); |
518 }) |
545 }); |
519 |
|
520 console.log(_openCluster); |
|
521 |
546 |
522 var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
547 var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
523 occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
548 occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
524 clusters: _clusters, |
549 clusters: _clusters, |
525 open_cluster: _openCluster |
550 open_cluster: _openCluster |
540 }); |
565 }); |
541 } |
566 } |
542 |
567 |
543 this.$.find('.Tl-Occurrence').mousedown(function() { |
568 this.$.find('.Tl-Occurrence').mousedown(function() { |
544 var _el = $(this); |
569 var _el = $(this); |
545 _this.editing_occurrence = _occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
570 _this.editing_occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
546 if (typeof _this.editing_occurrence !== "undefined") { |
571 if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
547 _this.dragging_type = "occurrence"; |
572 _this.dragging_type = "occurrence"; |
548 _this.editing_occurrence.editing = true; |
573 _this.editing_occurrence.editing = true; |
549 } |
574 } |
550 }).mouseover(function(_event) { |
575 }).mouseover(function(_event) { |
551 var _el = $(this), |
576 var _el = $(this), |
552 _occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
577 _occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
553 _this.showTooltip(_occurrence.x, _occurrence.y, _occurrence.title, (_event.pageY - _this.dragging_bounds.top) > (_this.main_height / 2) ); |
578 if (!_occurrence.locked) { |
|
579 _el.find('.Tl-Link').show(); |
|
580 } |
|
581 _occurrence.formatted_date = Tlns.Utils.dateFormat(_occurrence.date,_this.tooltip_date_format); |
|
582 var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
|
583 _this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
554 }).mouseout(function() { |
584 }).mouseout(function() { |
|
585 var _el = $(this), |
|
586 _occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
555 _this.hideTooltip(); |
587 _this.hideTooltip(); |
556 }); |
588 if (!_occurrence.editing) { |
|
589 $(this).find('.Tl-Link').hide(); |
|
590 } |
|
591 }).mouseup(function() { |
|
592 var _el = $(this); |
|
593 if (_this.dragging_type == "link" && _el.attr("occurrence-type") == "narrative") { |
|
594 _this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
|
595 } |
|
596 }); |
|
597 |
|
598 this.$.find('.Tl-Link').mousedown(function() { |
|
599 var _el = $(this).parent(); |
|
600 _this.editing_occurrence = _this.getOccurrence(_el.attr("occurrence-type"),_el.attr("occurrence-id")); |
|
601 if (typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
|
602 _this.dragging_type = "link"; |
|
603 _this.editing_occurrence.editing = true; |
|
604 } |
|
605 }) |
|
606 |
557 this.$.find('.Tl-Cluster').click(function() { |
607 this.$.find('.Tl-Cluster').click(function() { |
558 var _el = $(this), |
608 var _el = $(this), |
559 _contents = _el.attr("cluster-contents"); |
609 _contents = _el.attr("cluster-contents"); |
560 if (_this.open_cluster == _contents) { |
610 if (_this.open_cluster == _contents) { |
561 _this.open_cluster = false; |
611 _this.open_cluster = false; |
562 } else { |
612 } else { |
563 _this.open_cluster = _contents; |
613 _this.open_cluster = _contents; |
564 } |
614 } |
565 console.log(_this.open_cluster); |
|
566 _this.throttledDrawGrid(); |
615 _this.throttledDrawGrid(); |
567 }) |
616 }) |
568 } |
617 } |
569 |
618 |
570 Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
619 Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
617 this.status = _data.statut; |
666 this.status = _data.statut; |
618 this.published = _data.publie || false; |
667 this.published = _data.publie || false; |
619 this.locked = _data.verrouille || false; |
668 this.locked = _data.verrouille || false; |
620 this.characters = _data.personnagesSecondaires || []; |
669 this.characters = _data.personnagesSecondaires || []; |
621 this.dependsOn = _data.dependDe || []; |
670 this.dependsOn = _data.dependDe || []; |
|
671 this.description = _data.description || ""; |
|
672 } |
|
673 |
|
674 Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
675 if (_(this.dependsOn).indexOf(_id) == -1) { |
|
676 this.dependsOn.push(_id); |
|
677 } |
622 } |
678 } |
623 |
679 |
624 Tlns.Classes.Occurrence.prototype.toString = function() { |
680 Tlns.Classes.Occurrence.prototype.toString = function() { |
625 return "Occurrence " + this.type + ': "' + this.title + '"'; |
681 return "Occurrence " + this.type + ': "' + this.title + '"'; |
626 } |
682 } |