timeline/js/timeline.js
changeset 102 2f1ef2ded30c
parent 101 05c1161fa501
child 103 b9a417017e19
equal deleted inserted replaced
101:05c1161fa501 102:2f1ef2ded30c
   132     timescales : [{
   132     timescales : [{
   133         label : "Semaine",
   133         label : "Semaine",
   134         span : 7 * 86400 * 1000,
   134         span : 7 * 86400 * 1000,
   135         grid_interval : 86400 * 1000,
   135         grid_interval : 86400 * 1000,
   136         grid_date_format : '{{dayOfMonth}} {{monthName}}',
   136         grid_date_format : '{{dayOfMonth}} {{monthName}}',
   137         min_importance : 3
   137         min_importance : 3 //0 //pour les tests, mettre à 0 pour tout afficher
   138     }, {
   138     }, {
   139         label : "3 jours",
   139         label : "3 jours",
   140         span : 3 * 86400 * 1000,
   140         span : 3 * 86400 * 1000,
   141         grid_interval : 6 * 3600 * 1000,
   141         grid_interval : 6 * 3600 * 1000,
   142         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   142         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   143         min_importance : 2
   143         min_importance : 2 //0 //pour les tests, mettre à 0 pour tout afficher
   144     }, {
   144     }, {
   145         label : "Journée",
   145         label : "Journée",
   146         span : 86400 * 1000,
   146         span : 86400 * 1000,
   147         grid_interval : 2 * 3600 * 1000,
   147         grid_interval : 2 * 3600 * 1000,
   148         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   148         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   149         min_importance : 1
   149         min_importance : 1 //0 //pour les tests, mettre à 0 pour tout afficher
   150     }, {
   150     }, {
   151         label : "Demi-Journée",
   151         label : "Demi-Journée",
   152         span : 6 * 3600 * 1000,
   152         span : 6 * 3600 * 1000,
   153         grid_interval : 3600 * 1000,
   153         grid_interval : 3600 * 1000,
   154         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   154         grid_date_format : '{{^isDayStart}}{{0hours}}h{{0minutes}}{{/isDayStart}}{{#isDayStart}}{{dayOfMonth}} {{shortMonthName}}{{/isDayStart}}',
   234     
   234     
   235 Tlns.Templates.Univers = '<div class="Tl-UniversText">{{title}}</div>';
   235 Tlns.Templates.Univers = '<div class="Tl-UniversText">{{title}}</div>';
   236 
   236 
   237 Tlns.Templates.Occurrence =
   237 Tlns.Templates.Occurrence =
   238     '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">'
   238     '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">'
   239     + '{{#image}}<img src="{{image}}" />{{/image}}'
   239     + '{{#image}}<img src="{{image}}" />{{/image}}{{#isFavorite}}<div class="Tl-Occurrence-Favorite"></div>{{/isFavorite}}'
   240     + '</div>{{/occurrences}}';
   240     + '{{#participationCount}}<div class="Tl-Occurrence-Participation">{{participationCount}}</div>{{/participationCount}}</div>{{/occurrences}}';
   241 
   241 
   242 Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3>';
   242 Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3>';
   243 
   243 
   244 Tlns.Templates.OccurrenceDetails = '<div class="Tl-Detail"><div class="Tl-Detail-X"></div><img class="Tl-Detail-Image" src="{{detail_image}}" />'
   244 Tlns.Templates.OccurrenceDetails = 
       
   245     '<div class="Tl-Detail"><div class="Tl-Detail-X"></div><div class="Tl-Detail-Favorite{{#isFavorite}} Tl-Detail-isFavorite{{/isFavorite}}"></div>'
       
   246     + '<div class="Tl-Detail-Image-Wrapper"><img class="Tl-Detail-Image" src="{{detail_image}}" />'
       
   247     + '{{#participationCount}}<div class="Tl-Detail-Participation">{{participationCount}}<span class="Tl-Participation-Icon"></span></div>{{/participationCount}}</div>'
   245     + '<h2 class="Tl-Detail-Title">{{title}}</h2><p class="Tl-Detail-Description">{{detail_description}}</p>'
   248     + '<h2 class="Tl-Detail-Title">{{title}}</h2><p class="Tl-Detail-Description">{{detail_description}}</p>'
   246     + '<div class="Tl-Detail-Bottom"><span class="Tl-Detail-Date">Publié le {{formatted_date}}</span><a class="Tl-Detail-Read" href="{{url}}" target="_blank">Lire la suite</a></div></div>';
   249     + '<div class="Tl-Detail-Bottom"><span class="Tl-Detail-Date">Publié le {{formatted_date}}</span><a class="Tl-Detail-Read" href="{{url}}" target="_blank">Lire la suite</a></div></div>';
   247 
   250 
   248 /* Classes */
   251 /* Classes */
   249 
   252 
   364     this.is_dragging = false;
   367     this.is_dragging = false;
   365     this.start_pos = {
   368     this.start_pos = {
   366         x: _event.pageX,
   369         x: _event.pageX,
   367         y: _event.pageY
   370         y: _event.pageY
   368     };
   371     };
   369     if (typeof this.dragging_type === "undefined") {
   372     this.time_at_start = this.central_time;
   370         this.time_at_start = this.central_time;
       
   371         this.dragging_type = "timeline";
       
   372     }
       
   373 };
   373 };
   374 
   374 
   375 Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) {
   375 Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) {
   376     this.mouse_down = false;
   376     this.mouse_down = false;
   377     this.is_dragging = false;
   377     this.is_dragging = false;
   378     this.dragging_type = undefined;
       
   379 };
   378 };
   380 
   379 
   381 Tlns.Classes.Timeline.prototype.timeFromX = function(_x) {
   380 Tlns.Classes.Timeline.prototype.timeFromX = function(_x) {
   382     return this.start_time + _x / this.current_scale;
   381     return this.start_time + _x / this.current_scale;
   383 };
   382 };
   403             this.is_dragging = true;
   402             this.is_dragging = true;
   404         }
   403         }
   405     }
   404     }
   406     if (this.is_dragging) {
   405     if (this.is_dragging) {
   407         this.hideTooltip();
   406         this.hideTooltip();
   408         switch (this.dragging_type) {
   407         this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale));
   409             case "timeline":
       
   410                 this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale));
       
   411             break;
       
   412         }
       
   413     }
   408     }
   414 };
   409 };
   415 
   410 
   416 Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) {
   411 Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) {
   417     this.univers = [];
   412     this.univers = [];
   563         _occ.visible = (_occ.date >= minT && _occ.date <= _this.end_time && (_occ.importance >= minI));
   558         _occ.visible = (_occ.date >= minT && _occ.date <= _this.end_time && (_occ.importance >= minI));
   564         return _occ.visible;
   559         return _occ.visible;
   565     });
   560     });
   566     
   561     
   567     /* FILTRAGE SI TROP D'OCCURRENCES PAR UNITE DE TEMPS */
   562     /* FILTRAGE SI TROP D'OCCURRENCES PAR UNITE DE TEMPS */
       
   563     /* Commenter la partie ci-dessous pour les tests */
   568     
   564     
   569     var _timescale = this.timescales[this.level],
   565     var _timescale = this.timescales[this.level],
   570         _offset = new Date().getTimezoneOffset() * 60000,
   566         _offset = new Date().getTimezoneOffset() * 60000,
   571         _grid_width = Math.floor(_timescale.grid_interval * this.current_scale),
   567         _grid_width = Math.floor(_timescale.grid_interval * this.current_scale),
   572         _roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset,
   568         _roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset,
   612     var _html = Mustache.to_html(Tlns.Templates.Occurrence, {
   608     var _html = Mustache.to_html(Tlns.Templates.Occurrence, {
   613         occurrences: _visible
   609         occurrences: _visible
   614     });
   610     });
   615     this.$.find('.Tl-Occurrences').html(_html);
   611     this.$.find('.Tl-Occurrences').html(_html);
   616         
   612         
   617     this.$.find('.Tl-Occurrence').mousedown(function() {
   613     this.$.find('.Tl-Occurrence').mousedown(function() { // Clic sur un contenu
   618         var _el = $(this),
   614         var _el = $(this),
   619             _id = _el.attr("occurrence-id");
   615             _id = _el.attr("occurrence-id");
   620         if (typeof _id !== "undefined") {
   616         if (typeof _id !== "undefined") {
   621             _this.editing_occurrence = _this.getOccurrence(_id);
   617             _this.editing_occurrence = _this.getOccurrence(_id);
   622             if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) {
       
   623                 _this.dragging_type = "occurrence";
       
   624             }
       
   625             if (!_this.editing_occurrence.editing) {
   618             if (!_this.editing_occurrence.editing) {
   626                 _(_this.occurrences).each(function(_occ) {
   619                 _(_this.occurrences).each(function(_occ) {
   627                     _occ.editing = false;
   620                     _occ.editing = false;
   628                 });
   621                 });
   629                 _this.editing_occurrence.editing = true;
   622                 _this.editing_occurrence.editing = true;
   630                 _this.$.find(".Tl-Details").html(Mustache.to_html(Tlns.Templates.OccurrenceDetails, _this.editing_occurrence));
   623                 _this.$.find(".Tl-Details").html(Mustache.to_html(Tlns.Templates.OccurrenceDetails, _this.editing_occurrence));
   631             }
   624             }
   632             _this.throttledDrawGrid();
   625             _this.throttledDrawGrid();
   633         }
   626         }
   634     }).mouseover(function(_event) {
   627     }).mouseover(function(_event) { // Hover sur un contenu
   635         var _el = $(this),
   628         var _el = $(this),
   636             _id = _el.attr("occurrence-id");
   629             _id = _el.attr("occurrence-id");
   637         if (typeof _id !== "undefined") {
   630         if (typeof _id !== "undefined") {
   638             var _occurrence = _this.getOccurrence(_id);
   631             var _occurrence = _this.getOccurrence(_id);
   639             if (!_this.is_dragging) {
   632             if (!_this.is_dragging) {
   694 Tlns.Classes.Occurrence = function(_timeline) {
   687 Tlns.Classes.Occurrence = function(_timeline) {
   695     this.timeline = _timeline;
   688     this.timeline = _timeline;
   696 };
   689 };
   697 
   690 
   698 Tlns.Classes.Occurrence.prototype.update = function(_data) {
   691 Tlns.Classes.Occurrence.prototype.update = function(_data) {
       
   692     
       
   693     /* Récupération des propriétés du JSON */
       
   694     
   699     this.original_data = _data;
   695     this.original_data = _data;
   700     this.id = _data.id;
   696     this.id = _data.id;
   701     this.date = new Date(1000 * (_data.dateFirstPublication || _data.dateCreate) || Date.now);
   697     this.date = new Date(1000 * (_data.dateFirstPublication || _data.dateCreate) || Date.now);
   702     this.formatted_date = Tlns.Utils.dateFormat(this.date,this.timeline.tooltip_date_format);
   698     this.formatted_date = Tlns.Utils.dateFormat(this.date,this.timeline.tooltip_date_format);
   703     this.title = _data.title;
   699     this.title = _data.title;
   715     if (typeinfo.picto) {
   711     if (typeinfo.picto) {
   716         this.image = this.timeline.picto_url + typeinfo.picto;
   712         this.image = this.timeline.picto_url + typeinfo.picto;
   717     }
   713     }
   718     this.univers = this.timeline.univers[this.univers_id];
   714     this.univers = this.timeline.univers[this.univers_id];
   719     this.format = typeinfo.label;
   715     this.format = typeinfo.label;
   720 //    this.published = (_data.publication && _data.publication == "En ligne");
   716     
   721 //    this.locked = _data.verrouille || false;
   717     /* Données temporaires aléatoires */
   722 //    this.characters = _data.personnagesSecondaires || [];
   718     this.isFavorite = (Math.random() > 1/2); // A random Boolean ;-)
       
   719     if (this.univers_id >= 2) {
       
   720         this.participationCount = Math.floor(12*Math.random());
       
   721     }
       
   722     /* End Temporary Data */
       
   723     
   723     var _tmp = $('<p>').html(_data.resume || "");
   724     var _tmp = $('<p>').html(_data.resume || "");
   724     var trimmedDesc = _tmp.text().trim().replace(/(\n|\r|\r\n)/mg,' ');
   725     var trimmedDesc = _tmp.text().trim().replace(/(\n|\r|\r\n)/mg,' ');
   725     this.description = trimmedDesc.replace(/(^.{60,80})[\s].+$/m,'$1&hellip;');
   726     this.description = trimmedDesc.replace(/(^.{60,80})[\s].+$/m,'$1&hellip;');
   726     this.detail_description = trimmedDesc.replace(/(^.{360,380})[\s].+$/m,'$1&hellip;');
   727     this.detail_description = trimmedDesc.replace(/(^.{360,380})[\s].+$/m,'$1&hellip;');
   727     this.url = this.timeline.url_base + _data.url;
   728     this.url = this.timeline.url_base + _data.url;