From 56816cedba42db02d319b3b1d64dec075b5d8b2f Mon Sep 17 00:00:00 2001 From: lcb931023 Date: Fri, 9 Jan 2015 12:17:42 +0800 Subject: [PATCH] add hash string routing ability with slideName. --- source/js/Core/Slider/VMM.Slider.Slide.js | 1 + source/js/Core/Slider/VMM.Slider.js | 16 ++++++++++++---- source/js/VMM.Timeline.DataObj.js | 3 ++- source/js/VMM.Timeline.js | 10 +++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/source/js/Core/Slider/VMM.Slider.Slide.js b/source/js/Core/Slider/VMM.Slider.Slide.js index ff1f9c2..ea53701 100644 --- a/source/js/Core/Slider/VMM.Slider.Slide.js +++ b/source/js/Core/Slider/VMM.Slider.Slide.js @@ -22,6 +22,7 @@ if (typeof VMM.Slider != 'undefined') { _id = _id + data.uniqueid; this.enqueue = _enqueue; this.id = _id; + this.slideName = data.slideName; element = VMM.appendAndGetElement(_parent, "
", "slider-item"); diff --git a/source/js/Core/Slider/VMM.Slider.js b/source/js/Core/Slider/VMM.Slider.js index fe149c8..6b9c988 100644 --- a/source/js/Core/Slider/VMM.Slider.js +++ b/source/js/Core/Slider/VMM.Slider.js @@ -113,6 +113,18 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { } } + // Get index using Slide Name for hash routing + this.findSlideIndexByName = function(n) { + for (var i = 0; i < slides.length; i++) + { + if (slides[i].slideName == n) { + return i; + } + } + return -1; + }; + + /* GETTERS AND SETTERS ================================================== */ this.setData = function(d) { @@ -799,7 +811,3 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { }; } - - - - diff --git a/source/js/VMM.Timeline.DataObj.js b/source/js/VMM.Timeline.DataObj.js index a0f238b..283ed67 100644 --- a/source/js/VMM.Timeline.DataObj.js +++ b/source/js/VMM.Timeline.DataObj.js @@ -282,6 +282,7 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef } else { var date = { type: "google spreadsheet", + slideName: getGVar(dd.gsx$slidename), startDate: getGVar(dd.gsx$startdate), endDate: getGVar(dd.gsx$enddate), headline: getGVar(dd.gsx$headline), @@ -794,4 +795,4 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef }; -} \ No newline at end of file +} diff --git a/source/js/VMM.Timeline.js b/source/js/VMM.Timeline.js index f75b4d0..0fd7b17 100755 --- a/source/js/VMM.Timeline.js +++ b/source/js/VMM.Timeline.js @@ -155,11 +155,18 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { } } + // Routes number AND Slide Name window.onhashchange = function () { var hash = window.location.hash.substring(1); if (config.hash_bookmark) { if (is_moving) { - goToEvent(parseInt(hash)); + if ( isNaN(parseInt(hash)) ) { + // if string, find the index and route to it + var slideI = slider.findSlideIndexByName(hash); + if ( slideI != -1 ) goToEvent(slideI); + } else { + goToEvent(parseInt(hash)); + } } else { is_moving = false; } @@ -580,6 +587,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { } } + _date.slideName = data.date[i].slideName; _date.title = data.date[i].headline; _date.headline = data.date[i].headline; _date.type = data.date[i].type;