Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Make alert message dynamic, remove tour parse, add message for unsupported tours

ZachTRicebc57d6463e0d
diff --git a/web/js/alert/ui.js b/web/js/alert/ui.js
index cbcfebff5..46fef14c5 100644
--- a/web/js/alert/ui.js
+++ b/web/js/alert/ui.js
@@ -15,7 +15,8 @@ export function alertUi(ui) {
var getInitialAlertProps = function() {
return {
visible: false,
- showTourAlert: self.showTourAlert
+ showTourAlert: self.showTourAlert,
+ message: null
};
};
@@ -24,7 +25,21 @@ export function alertUi(ui) {
if (!hideTour) return;
self.reactComponent.setState({
- visible: true
+ visible: true,
+ message: 'To view these tours again. Click the \'Start Tour\' link in the "i" button menu above.'
+ });
+
+ setTimeout(() => {
+ self.reactComponent.setState({
+ visible: false
+ });
+ }, 10000);
+ };
+
+ self.noTourAvailable = function(e) {
+ self.reactComponent.setState({
+ visible: true,
+ message: 'Sorry, this tour is no longer supported.'
});
setTimeout(() => {
diff --git a/web/js/app.js b/web/js/app.js
index 0a5ab3c70..8782f83a4 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -95,7 +95,6 @@ import { compareModel } from './compare/model';
import { compareUi } from './compare/ui';
// Tour
-import { parse as tourParser } from './tour/tour';
import { tourModel } from './tour/model';
import { tourUi } from './tour/ui';
@@ -338,8 +337,7 @@ class App extends React.Component {
layerParser,
dateParser,
mapParser,
- palettes.parse,
- tourParser
+ palettes.parse
];
if (config.features.dataDownload) {
parsers.push(dataParser);
@@ -395,14 +393,12 @@ class App extends React.Component {
models.compare = compareModel(models, config);
models.link.register(models.compare);
}
- models.tour = tourModel(config);
models.link
.register(models.proj)
.register(models.layers)
.register(models.date)
.register(models.palettes)
- .register(models.map)
- .register(models.tour);
+ .register(models.map);
models.link.load(state);
if (config.features.googleTagManager) {
googleTagManager.init(config.features.googleTagManager.id); // Insert google tag manager
@@ -432,6 +428,10 @@ class App extends React.Component {
models.naturalEvents = naturalEventsModel(models, config, ui);
models.link.register(models.naturalEvents);
}
+ if (config.features.tour) {
+ models.tour = tourModel(config, ui);
+ models.link.register(models.tour);
+ }
// HACK: Map needs permalink state loaded before starting. But
// data download now needs it too.
models.link.load(state); // needs to be loaded twice
diff --git a/web/js/components/alert/alert-tour.js b/web/js/components/alert/alert-tour.js
index 4846a9410..41c793234 100644
--- a/web/js/components/alert/alert-tour.js
+++ b/web/js/components/alert/alert-tour.js
@@ -7,7 +7,8 @@ class TourAlert extends React.Component {
super(props);
this.state = {
- visible: props.visible
+ visible: props.visible,
+ message: props.message
};
this.onDismiss = this.onDismiss.bind(this);
@@ -21,7 +22,7 @@ class TourAlert extends React.Component {
return (
<div>
<Alert className="wv-alert" isOpen={this.state.visible} toggle={this.onDismiss}>
- <p>To view these tours again. Click the 'Start Tour' link in the "i" button menu above.</p>
+ <p>{this.state.message}</p>
</Alert>
</div>
);
@@ -29,7 +30,8 @@ class TourAlert extends React.Component {
}
TourAlert.propTypes = {
- visible: PropTypes.bool.isRequired
+ visible: PropTypes.bool.isRequired,
+ message: PropTypes.string
};
export default TourAlert;
diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.js
index 4892fd438..8989e044c 100644
--- a/web/js/components/tour/modal-tour-in-progress.js
+++ b/web/js/components/tour/modal-tour-in-progress.js
@@ -38,7 +38,7 @@ class ModalInProgress extends React.Component {
}
// Scroll content div to the top when step updates
- this.refs.stepContent.parentNode.scrollTop = 0;
+ if (this.refs.stepContent) this.refs.stepContent.parentNode.scrollTop = 0;
// Fetch meta and load link
if (modalStarted && !this.props.metaLoaded) {
diff --git a/web/js/tour/model.js b/web/js/tour/model.js
index 082ea75bd..b8ee91e52 100644
--- a/web/js/tour/model.js
+++ b/web/js/tour/model.js
@@ -8,7 +8,7 @@ export function tourModel(config) {
self.select = function (storyId) {
var story = config.stories[storyId];
if (!story) {
- throw new Error('Invalid tour: ' + storyId);
+ console.warn('Unsupported tour: ' + storyId);
}
var updated = false;
if (!self.selected || self.selected.id !== storyId) {
diff --git a/web/js/tour/old-ui.js b/web/js/tour/old-ui.js
deleted file mode 100644
index b4f3691b2..000000000
--- a/web/js/tour/old-ui.js
+++ /dev/null
@@ -1,241 +0,0 @@
-import $ from 'jquery';
-import 'jquery-ui-bundle/jquery-ui';
-import 'jquery.joyride';
-import util from '../util/util';
-import wvui from '../ui/ui';
-import googleAnalytics from '../components/util/google-analytics';
-import feedbackModal from '../feedback';
-
-export default function(models, ui, config) {
- var self = {};
- self.resetting = false;
- self.events = util.events();
- var init = function() {
- $('#wv-tour').click(function() {
- self.start();
- });
- self.introduction();
- };
-
- self.introduction = function() {
- if (!config.features.tour) {
- return;
- }
-
- // Don't start tour if coming in via a permalink
- if (window.location.search && !config.parameters.tour) {
- return;
- }
-
- // Tour does not work on IE 9 or below
- if (util.browser.ie && util.browser.version <= 9) {
- return;
- }
-
- // Don't annoy with the tour if they cannot opt out in the future
- if (!util.browser.localStorage) {
- return;
- }
-
- // Don't show tour if the user has opted out
- if (localStorage.getItem('hideSplash')) {
- return;
- }
-
- // Don't show tour on small screens
- if (!validScreenSize()) {
- return;
- }
-
- self.start(true);
- };
-
- /**
- * Create the splash screen and tour panels and control iteration over them.
- */
- self.start = function(introduction) {
- if (util.browser.ie && util.browser.version <= 9) {
- wvui.unsupported('tour');
- return;
- }
-
- if (!validScreenSize()) {
- wvui.notify(
- 'Unfortunately the @NAME@ tour can only be viewed in larger web browser windows.'
- );
- return;
- }
-
- var $content = $('#wv-tour-content');
- if ($content.children().length === 0) {
- $content.load('pages/tour.html', function() {
- onLoad(introduction);
- });
- } else {
- onLoad(introduction);
- }
- };
-
- var onLoad = function(introduction) {
- wvui.close();
- var $startDialog = $('#wv-tour-intro');
- $startDialog.dialog({
- title: 'Welcome to @NAME@!',
- dialogClass: 'tour',
- modal: true,
- width: 700,
- height: 'auto',
- draggable: false,
- resizable: false,
- closeText: ''
- });
-
- if (introduction) {
- $('#wv-tour-skip').show();
- } else {
- $('#wv-tour-skip').hide();
- }
-
- var mapAnchor = document.getElementById('mapPanelTourAnchor');
- if (!mapAnchor) {
- var owner = document.getElementById('wv-map');
- mapAnchor = document.createElement('div');
- mapAnchor.setAttribute('id', 'mapPanelTourAnchor');
- mapAnchor.setAttribute(
- 'style',
- 'float:right; height:68px; right:14px; top:90px; width:36px; position:relative; z-index:-1'
- );
- owner.appendChild(mapAnchor);
- }
-
- var endTour = function() {
- wvui.close();
- var $dialog = $('#wv-tour-end');
- $dialog.dialog({
- title: 'Finished!',
- dialogClass: 'tour',
- modal: true,
- width: 600,
- height: 'auto',
- draggable: false,
- resizable: false,
- closeText: ''
- });
- feedbackModal.decorate($dialog.find('.feedback'));
- $('#repeat').click(repeatTour);
- $('#done').click(handleDone);
- };
-
- /*
- * Restart the tour at the beginning.
- */
- var repeatTour = function(e) {
- e.stopPropagation();
- $('.ui-dialog-content').dialog('close');
- $('#joyRideTipContent').joyride({
- scroll: false,
- autoStart: true,
- includepage: true,
- template: {
- link: '<a href="#" class="joyride-close-tip">X</a>'
- },
- postStepCallback: function(index, tip) {
- if (index === 5) {
- endTour();
- }
- }
- });
- };
-
- /*
- * Hide the tour.
- */
- var handleDone = function(e) {
- e.stopPropagation();
- $('.ui-dialog-content').dialog('close');
- };
-
- /*
- * Close the splash and go straight to worldview.
- */
- var handleSkipTour = function() {
- $('.ui-dialog-content').dialog('close');
- };
-
- var onStop = function(index, tip, button) {
- setTourState();
- googleAnalytics.event('Tour', 'Click', 'Post Tour View', index + 1);
- if (index === 5 && button === false) {
- endTour();
- }
- };
-
- /*
- * Close the splash and start the tour.
- */
- var handleTakeTour = function(e) {
- e.stopPropagation();
- $('.ui-dialog-content').dialog('close');
- initTourState();
- googleAnalytics.event('Tour', 'Click', 'Take Tour');
- $('#joyRideTipContent').joyride({
- scroll: false,
- autoStart: true,
- includepage: true,
- template: {
- link: '<a href="#" class="joyride-close-tip">X</a>'
- },
- postStepCallback: onStop
- });
- };
-
- /*
- * Toggle the value of the "hideSplash" flag.
- */
- var setDoNotShow = function() {
- if (!util.browser.localStorage) return;
- var hideSplash = localStorage.getItem('hideSplash');
- localStorage.setItem('hideSplash', !hideSplash);
- };
-
- // assign events and start
- $('#takeTour').click(handleTakeTour);
- $('#skipTour').click(handleSkipTour);
- $('#dontShowAgain').click(setDoNotShow);
- };
-
- var initTourState = function() {
- var leading;
- var map = ui.map.selected;
-
- self.resetting = true;
- if (models.compare && models.compare.active) {
- models.compare.toggle();
- }
- models.proj.selectDefault();
- models.layers.reset(models.layers.activeLayers);
- models.date.select(util.today());
-
- leading = models.map.getLeadingExtent();
- map.getView().fit(leading, map.getSize());
- self.resetting = false;
- self.events.trigger('reset');
- setTourState();
- };
-
- var setTourState = function() {
- models.proj.selectDefault();
- ui.sidebar.expandNow();
- ui.sidebar.selectTab('layers');
- ui.timeline.expandNow();
- };
-
- var validScreenSize = function() {
- var viewWidth = $(window).width();
- var viewHeight = $(window).height();
- return viewWidth > 800 && viewHeight > 680;
- };
-
- init();
- return self;
-}
diff --git a/web/js/tour/tour.js b/web/js/tour/tour.js
deleted file mode 100644
index 1c9ace287..000000000
--- a/web/js/tour/tour.js
+++ /dev/null
@@ -1,11 +0,0 @@
-export function parse(state, errors, config) {
- var storyId = state.tr;
- if (storyId) {
- if (!config.stories[storyId]) {
- delete state.tr;
- errors.push({
- message: 'Unsupported tour: ' + storyId
- });
- }
- }
-};
diff --git a/web/js/tour/ui.js b/web/js/tour/ui.js
index 8f175a7e5..fe3750e21 100644
--- a/web/js/tour/ui.js
+++ b/web/js/tour/ui.js
@@ -24,6 +24,8 @@ export function tourUi(models, ui, config) {
if (story && storyLoaded === false) {
self.selectTour(null, story, 1, story.id);
storyLoaded = true;
+ } else if (typeof story === 'undefined') {
+ ui.alert.noTourAvailable();
}
});
};