Browse Source

cleanup and allowing for multiple timelines closes #53 and closes #18

pull/75/head
Zach Wise 13 years ago
parent
commit
38e0d0f03d
  1. 169
      source/js/VMM.Timeline.js

169
source/js/VMM.Timeline.js

@ -45,24 +45,27 @@
if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
VMM.Timeline = function(w, h, conf) { VMM.Timeline = function(w, h, conf, _timeline_id) {
var version = "0.98";
trace("TIMELINE VERSION " + version);
var $timeline, $feedback, $messege, html_string; var $timeline, $feedback, $messege, slider, timenav, version, timeline_id;
var events = {}, data = {}, _dates = [], config = {};
var has_width = false, has_height = false, ie7 = false;
$timeline = VMM.getElement("#timeline");
html_string = VMM.getElement("#timeline");
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", "#Timeline");
/* PRIVATE VARS if (type.of(_timeline_id) == "string") {
================================================== */ timeline_id = _timeline_id;
var events = {}, data = {}, _dates = []; } else {
timeline_id = "#timeline";
}
version = "0.98.1";
trace("TIMELINE VERSION " + version);
/* CONFIG /* CONFIG
================================================== */ ================================================== */
var config = { config = {
id: timeline_id,
type: "timeline", type: "timeline",
maptype: "toner", maptype: "toner",
interval: 10, interval: 10,
@ -101,47 +104,29 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
language: VMM.Language language: VMM.Language
}; };
VMM.Timeline.Config = config; if ( w != null && w != "") {
VMM.master_config.Timeline = VMM.Timeline.Config;
if (w != null && w != "") {
config.width = w; config.width = w;
VMM.Element.width($timeline, w); has_width = true;
} else {
config.width = VMM.Element.width($timeline);
} }
if (h != null && h != "") { if ( h != null && h != "") {
config.height = h; config.height = h;
VMM.Element.height($timeline, h); has_height = true;
} else {
config.height = VMM.Element.height($timeline);
}
config.nav = {
width: config.width,
height: 200
};
config.feature = {
width: config.width,
height: config.height - config.nav.height
}
if (VMM.Browser.device == "mobile") {
config.feature.height = config.height;
} else {
//config.feature.height = config.height - config.nav.height;
} }
/* APPLY SUPPLIED CONFIG TO TIMELINE CONFIG /* CREATE CONFIG
================================================== */ ================================================== */
var createConfig = function(conf) {
VMM.Timeline.Config = config;
VMM.master_config.Timeline = VMM.Timeline.Config;
// APPLY SUPPLIED CONFIG TO TIMELINE CONFIG
if (typeof timeline_config == 'object') { if (typeof timeline_config == 'object') {
trace("HAS TIMELINE CONFIG"); trace("HAS TIMELINE CONFIG");
var x; var x;
for (x in timeline_config) { for (x in _timeline_config) {
if (Object.prototype.hasOwnProperty.call(timeline_config, x)) { if (Object.prototype.hasOwnProperty.call(_timeline_config, x)) {
config[x] = timeline_config[x]; config[x] = _timeline_config[x];
} }
} }
} else if (typeof conf == 'object') { } else if (typeof conf == 'object') {
@ -153,23 +138,43 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
} }
} }
/* CHECK FOR IE7 config.nav = {width: config.width, height: 200};
================================================== */ config.feature = {width: config.width, height: config.height - config.nav.height};
var ie7 = false;
if (VMM.Browser.browser == "MSIE") { if (VMM.Browser.device == "mobile") {
if ( parseInt(VMM.Browser.version, 10) == 7) { //config.feature.height = config.height;
ie7 = true; } else {
//config.feature.height = config.height - config.nav.height;
} }
} }
/* CREATE COMPONENTS /* CREATE TIMELINE STRUCTURE
================================================== */ ================================================== */
// SLIDER var createStructure = function(w, h) {
//var slider = new VMM.Slider("div.slider", 720, 400, true); $timeline = VMM.getElement(timeline_id);
var slider = new VMM.Slider("div.slider", config);
VMM.Element.addClass(timeline_id, "vmm-timeline");
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", "Timeline");
slider = new VMM.Slider(timeline_id + " div.slider", config);
timenav = new VMM.Timeline.TimeNav(timeline_id + " div.navigation", 720, 400, true);
if (!has_width) {
config.width = VMM.Element.width($timeline);
} else {
VMM.Element.width($timeline, config.width);
}
if (!has_height) {
config.height = VMM.Element.height($timeline);
} else {
VMM.Element.height($timeline, config.height);
}
}
// TIMENAV
var timenav = new VMM.Timeline.TimeNav("div.navigation", 720, 400, true);
/* ON EVENT /* ON EVENT
================================================== */ ================================================== */
@ -227,32 +232,42 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
/* PUBLIC FUNCTIONS /* PUBLIC FUNCTIONS
================================================== */ ================================================== */
this.init = function(d) { this.init = function(_data, _timeline_id, conf) {
if (type.of(_timeline_id) == "string") {
if (_timeline_id.match("#")) {
timeline_id = _timeline_id;
} else {
timeline_id = "#" + _timeline_id;
}
}
createConfig(conf);
createStructure(w,h);
trace('TIMELINE INIT'); trace('TIMELINE INIT');
trace(VMM.Timeline.Config.language);
VMM.Util.date.setLanguage(VMM.Timeline.Config.language); VMM.Util.date.setLanguage(VMM.Timeline.Config.language);
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", VMM.Timeline.Config.language.messages.loading_timeline);
VMM.bindEvent(global, onDataReady, "DATAREADY"); VMM.bindEvent(global, onDataReady, "DATAREADY");
VMM.bindEvent(global, showMessege, "MESSEGE"); VMM.bindEvent(global, showMessege, "MESSEGE");
/* GET DATA /* GET DATA
================================================== */ ================================================== */
if (ie7) {
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", ""); if (VMM.Browser.browser == "MSIE" && parseInt(VMM.Browser.version, 10) == 7) {
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", "Internet Explorer 7 is not supported by #Timeline."); ie7 = true;
VMM.fireEvent(global, "MESSEGE", "Internet Explorer 7 is not supported by #Timeline.");
} else { } else {
if (type.of(d) == "string") { if (type.of(_data) == "string" || type.of(_data) == "object") {
VMM.Timeline.DataObj.getData(d); VMM.Timeline.DataObj.getData(_data);
} else { } else {
VMM.Timeline.DataObj.getData(html_string); VMM.Timeline.DataObj.getData(VMM.getElement(timeline_id));
} }
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", VMM.Timeline.Config.language.messages.loading_timeline);
} }
}; };
this.iframeLoaded = function() { this.iframeLoaded = function() {
@ -272,7 +287,8 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
================================================== */ ================================================== */
var showMessege = function(e, msg) { var showMessege = function(e, msg) {
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", msg); trace("showMessege " + msg);
VMM.attachElement($messege, msg);
}; };
var hideMessege = function() { var hideMessege = function() {
@ -394,6 +410,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
} }
var updateSize = function() { var updateSize = function() {
trace("UPDATE SIZE")
config.width = VMM.Element.width($timeline); config.width = VMM.Element.width($timeline);
config.height = VMM.Element.height($timeline); config.height = VMM.Element.height($timeline);
@ -401,10 +418,11 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
config.feature.width = config.width; config.feature.width = config.width;
if (VMM.Browser.device == "mobile") { if (VMM.Browser.device == "mobile") {
config.feature.height = config.height; //config.feature.height = config.height;
} else { } else {
config.feature.height = config.height - config.nav.height - 3; //config.feature.height = config.height - config.nav.height - 3;
} }
config.feature.height = config.height - config.nav.height - 3;
}; };
var resizeSlides = function() { var resizeSlides = function() {
@ -441,10 +459,10 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
if (data.date[i].type == "tweets") { if (data.date[i].type == "tweets") {
_date.startdate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].startDate); _date.startdate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].startDate);
} else if (data.date[i].type == "google spreadsheet") { } else if (data.date[i].type == "google spreadsheet") {
_date.startdate = new Date(Date.parse(data.date[i].startDate)); //_date.startdate = new Date(Date.parse(data.date[i].startDate));
trace(_date.startdate); _date.startdate = VMM.Util.date.parse(data.date[i].startDate);
} else { } else {
_date.startdate = VMM.Util.parseDate(data.date[i].startDate); _date.startdate = VMM.Util.date.parse(data.date[i].startDate);
} }
_date.uniqueid = (data.date[i].startDate).toString() + "-" + i.toString(); _date.uniqueid = (data.date[i].startDate).toString() + "-" + i.toString();
@ -454,9 +472,10 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
if (data.date[i].type == "tweets") { if (data.date[i].type == "tweets") {
_date.enddate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].endDate); _date.enddate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].endDate);
} else if (data.date[i].type == "google spreadsheet") { } else if (data.date[i].type == "google spreadsheet") {
_date.enddate = new Date(Date.parse(data.date[i].endDate)); //_date.enddate = new Date(Date.parse(data.date[i].endDate));
_date.enddate = VMM.Util.date.parse(data.date[i].endDate);
} else { } else {
_date.enddate = VMM.Util.parseDate(data.date[i].endDate); _date.enddate = VMM.Util.date.parse(data.date[i].endDate);
} }
} else { } else {
_date.enddate = _date.startdate; _date.enddate = _date.startdate;
@ -504,7 +523,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
trace("google spreadsheet startpage date " + data.startDate); trace("google spreadsheet startpage date " + data.startDate);
//_date.startdate = new Date(Date.parse(data.startDate)); //_date.startdate = new Date(Date.parse(data.startDate));
} else { } else {
_date.startdate = VMM.Util.parseDate(data.startDate); _date.startdate = VMM.Util.date.parse(data.startDate);
} }
_date.startdate = new Date(_dates[0].startdate); _date.startdate = new Date(_dates[0].startdate);

Loading…
Cancel
Save