Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Updated animation directory to 2 spaces

ZachTRice817ddb3fee1a
diff --git a/web/js/animation/wv.anim.gif.js b/web/js/animation/wv.anim.gif.js
index 0a7f654d7..b2115ab78 100644
--- a/web/js/animation/wv.anim.gif.js
+++ b/web/js/animation/wv.anim.gif.js
@@ -16,847 +16,917 @@ var wv = wv || {};
wv.anim = wv.anim || {};
wv.anim.gif = wv.anim.gif || function(models, config, ui) {
- var self = {};
- var $cropee = $("#wv-map");
- var jcropAPI = null;
- var coords = null;
- var animCoords = null;
- var previousCoords = null;
- var animModel = models.anim;
- var $progress;// progress bar
- var loader;
- var showDates = true;// show date stamp
- var progressing = false; //if progress bar has started
- var GRATICLE_WARNING =
- "The graticule layer cannot be used to take a snapshot. Would you " +
- "like to hide this layer?";
- var PALETTE_WARNING =
- "One or more layers on the map have been modified (changed palette, " +
- "thresholds, etc.). These modifications cannot be used to take a " +
- "snapshot. Would you like to temporarily revert to the original " +
- "layer(s)?";
- var ROTATE_WARNING = "Image may not be downloaded when rotated. Would you like to reset rotation?";
-
- /*
- * sets listeners
- *
- *
- * @method init
- * @static
- *
- * @returns {void}
- *
- */
- self.init = function() {
- models.anim.events.on('gif-click', setImageCoords);
+ var self = {};
+ var $cropee = $("#wv-map");
+ var jcropAPI = null;
+ var coords = null;
+ var animCoords = null;
+ var previousCoords = null;
+ var animModel = models.anim;
+ var $progress; // progress bar
+ var loader;
+ var showDates = true; // show date stamp
+ var progressing = false; //if progress bar has started
+ var GRATICLE_WARNING =
+ "The graticule layer cannot be used to take a snapshot. Would you " +
+ "like to hide this layer?";
+ var PALETTE_WARNING =
+ "One or more layers on the map have been modified (changed palette, " +
+ "thresholds, etc.). These modifications cannot be used to take a " +
+ "snapshot. Would you like to temporarily revert to the original " +
+ "layer(s)?";
+ var ROTATE_WARNING = "Image may not be downloaded when rotated. Would you like to reset rotation?";
+
+ /*
+ * sets listeners
+ *
+ *
+ * @method init
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.init = function() {
+ models.anim.events.on('gif-click', setImageCoords);
+ };
+
+ /*
+ * Uses, frameUrl array and gifShot
+ * Library to create GIF
+ *
+ *
+ * @method createGIF
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.createGIF = function() {
+ var stateObj = animModel.rangeState;
+ var interval = stateObj.speed;
+ var startDate = stateObj.startDate;
+ var endDate = stateObj.endDate;
+ var shootGIFafterImageLoad;
+ var imageArra;
+ var stamp;
+ var build;
+
+ loader = wv.ui.indicator.loading();
+ build = function(stamp) {
+ var buildProgressBar = function() {
+ $progress = $("<progress />") //display progress for GIF creation
+ .attr("class", "wv-gif-progress");
+ wv.ui.getDialog()
+ .append($progress)
+ .dialog({ //dialog for progress
+ title: "Collecting Images...",
+ width: 300,
+ height: 100
+ });
+ $progress.attr("value", 0);
+ };
+ var onGifProgress = function(captureProgress) {
+ if (!progressing) {
+ buildProgressBar();
+ progressing = true;
+ wv.ui.indicator.hide(loader);
+ }
+ $progress.parent()
+ .dialog("option", "title", "Creating GIF..."); //set dialog title
+ $progress.attr("value", captureProgress); //before value set, it is in indeterminate state
+ };
+
+ imageArra = getImageArray(startDate, endDate, $progress);
+ if (!imageArra) { // won't be true if there are too mant frames
+ return;
+ }
+
+ gifshot.createGIF({
+ 'gifWidth': animCoords.w,
+ 'gifHeight': animCoords.h,
+ 'images': imageArra,
+ 'stamp': stamp,
+ 'textAlign': 'right',
+ 'textBaseline': 'top',
+ 'fontColor': '#fff',
+ 'fontWeight': 'lighter',
+ 'fontFamily': 'Helvetica Neue',
+ 'fontSize': '16px',
+ 'interval': 1 / interval,
+ 'progressCallback': onGifProgress,
+ 'stroke': {
+ 'color': '#000',
+ 'pixels': 1.7
+ },
+ 'pause': 1
+ }, onGifComplete);
};
-
- /*
- * Uses, frameUrl array and gifShot
- * Library to create GIF
- *
- *
- * @method createGIF
- * @static
- *
- * @returns {void}
- *
- */
- self.createGIF = function() {
- var stateObj = animModel.rangeState;
- var interval = stateObj.speed;
- var startDate = stateObj.startDate;
- var endDate = stateObj.endDate;
- var shootGIFafterImageLoad;
- var imageArra;
- var stamp;
- var build;
-
- loader = wv.ui.indicator.loading();
- build = function(stamp) {
- var buildProgressBar = function() {
- $progress = $("<progress />") //display progress for GIF creation
- .attr("class", "wv-gif-progress");
- wv.ui.getDialog().append($progress).dialog({ //dialog for progress
- title: "Collecting Images...",
- width: 300,
- height: 100
- });
- $progress.attr("value", 0);
- };
- var onGifProgress = function(captureProgress) {
- if(!progressing) {
- buildProgressBar();
- progressing = true;
- wv.ui.indicator.hide(loader);
- }
- $progress.parent().dialog("option", "title", "Creating GIF..."); //set dialog title
- $progress.attr("value", captureProgress); //before value set, it is in indeterminate state
- };
-
- imageArra = getImageArray(startDate, endDate, $progress);
- if(!imageArra) {// won't be true if there are too mant frames
- return;
- }
-
- gifshot.createGIF({
- 'gifWidth': animCoords.w,
- 'gifHeight': animCoords.h,
- 'images': imageArra,
- 'stamp': stamp,
- 'textAlign': 'right',
- 'textBaseline': 'top',
- 'fontColor' : '#fff',
- 'fontWeight': 'lighter',
- 'fontFamily': 'Helvetica Neue',
- 'fontSize': '16px',
- 'interval': 1 / interval,
- 'progressCallback': onGifProgress,
- 'stroke': {
- 'color': '#000',
- 'pixels': 1.7
- },
- 'pause' : 1
- }, onGifComplete);
- };
- stamp = new Image();
- stamp.onload = function() {build(stamp);};
- stamp.onerror = function() {build(null);};
- stamp.src = 'brand/images/wv-icon-w-shadow.png';
+ stamp = new Image();
+ stamp.onload = function() {
+ build(stamp);
};
-
- /*
- * Calculates resolution of frame based
- * on zoom and projection
- *
- *
- * @func calcRes
- * @private
- *
- * @returns {void}
- *
- */
- var calcRes = function(mode) { //return either multiplier or string resolution
- //geographic has 10 zoom levels from 0 to 9, polar projections have 8 from 0 to 7
- var isGeographic = models.proj.selected.id === "geographic";
-
- //Map the zoom level from 0-9 / 0-7 to an index from 0-4
- var zoom_res = [40, 20, 4, 2, 1], str, res;
- if(isGeographic)
- res = zoom_res[Math.floor(ui.map.selected.getView().getZoom() / 2)];
-
- else
- res = zoom_res[Math.floor(((ui.map.selected.getView().getZoom() + 2) / 2))];
-
- if(mode === 0)
- return res;
- else {
- switch(res){
- case 1:
- str = "250m";
- break;
- case 2:
- str = "500m";
- break;
- case 4:
- str = "1km";
- break;
- case 20:
- str = "5km";
- break;
- default:
- str = "10km";
- }
-
- return str;
- }
+ stamp.onerror = function() {
+ build(null);
};
-
- /*
- * checks if rotation, changed palettes, or graticules
- * are active and ask to reset if any are active
- *
- * @method getGif
- * @static
- *
- * @returns {void}
- *
- */
- self.getGif = function() {
- var layers;
- //check for rotation, changed palettes, and graticule layers and ask for reset if so
-
- //ui.anim.stop(); Add this
- layers = models.layers.get({renderable: true});
- if (models.palettes.inUse()) {
- wv.ui.ask({
- header: "Notice",
- message: PALETTE_WARNING,
- onOk: function() {
- previousPalettes = models.palettes.active;
- models.palettes.clear();
- self.getGif();
- }
- });
- return;
+ stamp.src = 'brand/images/wv-icon-w-shadow.png';
+ };
+
+ /*
+ * Calculates resolution of frame based
+ * on zoom and projection
+ *
+ *
+ * @func calcRes
+ * @private
+ *
+ * @returns {void}
+ *
+ */
+ var calcRes = function(mode) { //return either multiplier or string resolution
+ //geographic has 10 zoom levels from 0 to 9, polar projections have 8 from 0 to 7
+ var isGeographic = models.proj.selected.id === "geographic";
+
+ //Map the zoom level from 0-9 / 0-7 to an index from 0-4
+ var zoom_res = [40, 20, 4, 2, 1],
+ str, res;
+ if (isGeographic)
+ res = zoom_res[Math.floor(ui.map.selected.getView()
+ .getZoom() / 2)];
+
+ else
+ res = zoom_res[Math.floor(((ui.map.selected.getView()
+ .getZoom() + 2) / 2))];
+
+ if (mode === 0)
+ return res;
+ else {
+ switch (res) {
+ case 1:
+ str = "250m";
+ break;
+ case 2:
+ str = "500m";
+ break;
+ case 4:
+ str = "1km";
+ break;
+ case 20:
+ str = "5km";
+ break;
+ default:
+ str = "10km";
+ }
+
+ return str;
+ }
+ };
+
+ /*
+ * checks if rotation, changed palettes, or graticules
+ * are active and ask to reset if any are active
+ *
+ * @method getGif
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.getGif = function() {
+ var layers;
+ //check for rotation, changed palettes, and graticule layers and ask for reset if so
+
+ //ui.anim.stop(); Add this
+ layers = models.layers.get({
+ renderable: true
+ });
+ if (models.palettes.inUse()) {
+ wv.ui.ask({
+ header: "Notice",
+ message: PALETTE_WARNING,
+ onOk: function() {
+ previousPalettes = models.palettes.active;
+ models.palettes.clear();
+ self.getGif();
}
- if ( _.find(layers, {id: "Graticule"}) && models.proj.selected.id === "geographic" ) {
- wv.ui.ask({
- header: "Notice",
- message: GRATICULE_WARNING,
- onOk: function() {
- models.layers.setVisibility("Graticule", false);
- self.getGif(startDate, endDate, delta, interval);
- }
- });
- return;
+ });
+ return;
+ }
+ if (_.find(layers, {
+ id: "Graticule"
+ }) && models.proj.selected.id === "geographic") {
+ wv.ui.ask({
+ header: "Notice",
+ message: GRATICULE_WARNING,
+ onOk: function() {
+ models.layers.setVisibility("Graticule", false);
+ self.getGif(startDate, endDate, delta, interval);
}
- if(ui.map.selected.getView().getRotation() !== 0.0) {
- wv.ui.ask({
- header: "Reset rotation?",
- message: ROTATE_WARNING,
- onOk: function() {
- resetRotation();
- //Let rotation finish before reselecting can occur
- setImageCoords();
- }
- });
- return;
+ });
+ return;
+ }
+ if (ui.map.selected.getView()
+ .getRotation() !== 0.0) {
+ wv.ui.ask({
+ header: "Reset rotation?",
+ message: ROTATE_WARNING,
+ onOk: function() {
+ resetRotation();
+ //Let rotation finish before reselecting can occur
+ setImageCoords();
}
- WVC.GA.event('Animation', 'Click', 'Create GIF');
- self.createGIF();
- };
-
- /*
- * Retieves avtive layers by day
- *
- * @method getLayersForDay
- * @private
- *
- * @param {array} array of layers
- *
- * @returns {array} array of layer ids
- *
- */
- var getLayers = function(products, proj) {
- var layers = [];
- _.each(products, function(layer) {
- if ( layer.projections[proj].layer ) {
- layers.push(layer.projections[proj].layer);
- } else {
- layers.push(layer.id);
- }
- });
- return layers;
- };
- /*
- * retrieves renderable layers
- *
- * @method getProducts
- * @private
- *
- * @returns {array} array of layer objects
- *
- */
- var getProducts = function(date) {
- var layers = [];
- var products = models.layers.get({reverse: true, renderable: true });
- _.each(products, function(layer) {
- if(layer.endDate) {
- if(date > new Date(layer.endDate)) return;
- }
- if(layer.visible && new Date(layer.startDate) < date) {
- layers.push(layer);
- } else if(!layer.startDate) {
- layers.push(layer);
- }
- });
- return layers;
- };
-
- /*
- * Retieves opacities from palettes
- *
- * @method getOpacities
- * @private
- *
- * @param {array} array of layers
- *
- * @returns {array} array of opacities
- *
- */
- var getOpacities = function(products) {
- var opacities = [];
- _.each(products, function(product) {
- opacities.push( ( _.isUndefined(product.opacity) ) ? 1: product.opacity );
- });
- return opacities;
- };
-
- /*
- * Retieves coordinates from pixel
- *
- * @method getCoords
- * @private
- *
- * @returns {array} array of coords
- *
- */
- var getCoords = function() {
- return [ui.map.selected.getCoordinateFromPixel([Math.floor(animCoords.x), Math.floor(animCoords.y2)]),
+ });
+ return;
+ }
+ WVC.GA.event('Animation', 'Click', 'Create GIF');
+ self.createGIF();
+ };
+
+ /*
+ * Retieves avtive layers by day
+ *
+ * @method getLayersForDay
+ * @private
+ *
+ * @param {array} array of layers
+ *
+ * @returns {array} array of layer ids
+ *
+ */
+ var getLayers = function(products, proj) {
+ var layers = [];
+ _.each(products, function(layer) {
+ if (layer.projections[proj].layer) {
+ layers.push(layer.projections[proj].layer);
+ } else {
+ layers.push(layer.id);
+ }
+ });
+ return layers;
+ };
+ /*
+ * retrieves renderable layers
+ *
+ * @method getProducts
+ * @private
+ *
+ * @returns {array} array of layer objects
+ *
+ */
+ var getProducts = function(date) {
+ var layers = [];
+ var products = models.layers.get({
+ reverse: true,
+ renderable: true
+ });
+ _.each(products, function(layer) {
+ if (layer.endDate) {
+ if (date > new Date(layer.endDate)) return;
+ }
+ if (layer.visible && new Date(layer.startDate) < date) {
+ layers.push(layer);
+ } else if (!layer.startDate) {
+ layers.push(layer);
+ }
+ });
+ return layers;
+ };
+
+ /*
+ * Retieves opacities from palettes
+ *
+ * @method getOpacities
+ * @private
+ *
+ * @param {array} array of layers
+ *
+ * @returns {array} array of opacities
+ *
+ */
+ var getOpacities = function(products) {
+ var opacities = [];
+ _.each(products, function(product) {
+ opacities.push((_.isUndefined(product.opacity)) ? 1 : product.opacity);
+ });
+ return opacities;
+ };
+
+ /*
+ * Retieves coordinates from pixel
+ *
+ * @method getCoords
+ * @private
+ *
+ * @returns {array} array of coords
+ *
+ */
+ var getCoords = function() {
+ return [ui.map.selected.getCoordinateFromPixel([Math.floor(animCoords.x), Math.floor(animCoords.y2)]),
ui.map.selected.getCoordinateFromPixel([Math.floor(animCoords.x2), Math.floor(animCoords.y)])];
- };
- /*
- * Dimenions from zoom & projection
- *
- * @method getDimensions
- * @private
- *
- * @returns {array} array with dimensions
- *
- */
- var getDimensions = function(lonlat, proj) {
-
- var conversionFactor = proj === "geographic" ? 0.002197 : 256;
- var res = calcRes(0);
- return [
- Math.round((Math.abs(lonlat[1][0] - lonlat[0][0]) / conversionFactor) / Number(res)),// width
- Math.round((Math.abs(lonlat[1][1] - lonlat[0][1]) / conversionFactor) / Number(res))// height
+ };
+ /*
+ * Dimenions from zoom & projection
+ *
+ * @method getDimensions
+ * @private
+ *
+ * @returns {array} array with dimensions
+ *
+ */
+ var getDimensions = function(lonlat, proj) {
+
+ var conversionFactor = proj === "geographic" ? 0.002197 : 256;
+ var res = calcRes(0);
+ return [
+ Math.round((Math.abs(lonlat[1][0] - lonlat[0][0]) / conversionFactor) / Number(res)), // width
+ Math.round((Math.abs(lonlat[1][1] - lonlat[0][1]) / conversionFactor) / Number(res)) // height
];
- };
- /*
- * loops through dates and created image
- * download urls and pushs them to an
- * array
- *
- * @method getImageArray
- * @private
- *
- * @returns {array} array of jpg urls
- *
- */
- var getImageArray = function (startDate, endDate) {
- var url;
- var a = [];
- var fromDate = new Date(startDate);
- var toDate = new Date(endDate);
- var current = fromDate;
- var host;
- var path;
- var j = 0;
- var src;
- var strDate;
- var lonlat = getCoords();
- var proj = models.proj.selected.id;
- var dimensions = getDimensions(lonlat, proj);
- var opacities;
- var epsg = ( models.proj.change ) ? models.proj.change.epsg : models.proj.selected.epsg;
- var products = getProducts();
-
-
- if ( config.features.imageDownload ) {
- host = config.features.imageDownload.host;
- path = config.parameters.imagegen || config.features.imageDownload.path;
- } else {
- host = 'https://gibs.earthdata.nasa.gov';
- path = 'image-download';
- }
-
- while(current <= toDate) {
- j++;
- strDate = wv.util.toISOStringDate(current);
- products = getProducts(current);
-
- layers = getLayers(products, proj);
- opacities = getOpacities(products);
- url = wv.util.format(host + '/' + path + "?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}", "TIME={1}", lonlat[0][0]+","+lonlat[0][1]+","+lonlat[1][0]+","+lonlat[1][1], epsg, layers.join(","), opacities.join(","), dimensions[0], dimensions[1]);
- src = wv.util.format(url, strDate);
- if(showDates) {
- a.push({src: src, text: strDate});
- } else {
- a.push(src);
- }
- current = wv.util.dateAdd(current, ui.anim.ui.getInterval(), 1);
- if(j > 40) { // too many frames
- showUnavailableReason();
- wv.ui.indicator.hide(loader);
-
- return false;
- }
-
- }
- return a;
- };
-
- /*
- * Thows an alert notifies the user
- * that too many frames were selected
- *
- * @method showUnavailableReason
- * @private
- *
- * @returns {void}
- *
- */
- var showUnavailableReason = function() {
- var headerMsg = "<h3 class='wv-data-unavailable-header'>GIF Not Available</h3>";
- var bodyMsg = 'Too many frames were selected. Please request less than 40 frames if you would like to generate a GIF';
- callback = function() {
- $('#timeline-footer').toggleClass('wv-anim-active');
- };
- wv.ui.notify(headerMsg + bodyMsg, "Notice", 600, callback);
- };
-
- /*
- * resets map rotation to
- * zero degrees
- *
- * @method resetRotation
- * @private
- *
- * @returns {void}
- *
- */
- var resetRotation = function() {
- ui.map.selected.getView().animate({
- duration: 400,
- rotation: 0
+ };
+ /*
+ * loops through dates and created image
+ * download urls and pushs them to an
+ * array
+ *
+ * @method getImageArray
+ * @private
+ *
+ * @returns {array} array of jpg urls
+ *
+ */
+ var getImageArray = function(startDate, endDate) {
+ var url;
+ var a = [];
+ var fromDate = new Date(startDate);
+ var toDate = new Date(endDate);
+ var current = fromDate;
+ var host;
+ var path;
+ var j = 0;
+ var src;
+ var strDate;
+ var lonlat = getCoords();
+ var proj = models.proj.selected.id;
+ var dimensions = getDimensions(lonlat, proj);
+ var opacities;
+ var epsg = (models.proj.change) ? models.proj.change.epsg : models.proj.selected.epsg;
+ var products = getProducts();
+
+
+ if (config.features.imageDownload) {
+ host = config.features.imageDownload.host;
+ path = config.parameters.imagegen || config.features.imageDownload.path;
+ } else {
+ host = 'https://gibs.earthdata.nasa.gov';
+ path = 'image-download';
+ }
+
+ while (current <= toDate) {
+ j++;
+ strDate = wv.util.toISOStringDate(current);
+ products = getProducts(current);
+
+ layers = getLayers(products, proj);
+ opacities = getOpacities(products);
+ url = wv.util.format(host + '/' + path + "?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}", "TIME={1}", lonlat[0][0] + "," + lonlat[0][1] + "," + lonlat[1][0] + "," + lonlat[1][1], epsg, layers.join(","), opacities.join(","), dimensions[0], dimensions[1]);
+ src = wv.util.format(url, strDate);
+ if (showDates) {
+ a.push({
+ src: src,
+ text: strDate
});
+ } else {
+ a.push(src);
+ }
+ current = wv.util.dateAdd(current, ui.anim.ui.getInterval(), 1);
+ if (j > 40) { // too many frames
+ showUnavailableReason();
+ wv.ui.indicator.hide(loader);
+
+ return false;
+ }
+
+ }
+ return a;
+ };
+
+ /*
+ * Thows an alert notifies the user
+ * that too many frames were selected
+ *
+ * @method showUnavailableReason
+ * @private
+ *
+ * @returns {void}
+ *
+ */
+ var showUnavailableReason = function() {
+ var headerMsg = "<h3 class='wv-data-unavailable-header'>GIF Not Available</h3>";
+ var bodyMsg = 'Too many frames were selected. Please request less than 40 frames if you would like to generate a GIF';
+ callback = function() {
+ $('#timeline-footer')
+ .toggleClass('wv-anim-active');
};
-
- /*
- * Handles GIF generater conpletion
- *
- * @method onGifComplete
- * @callback
- *
- * @param obj {object} gifShot GIF-complete
- * object
- *
- * @returns {void}
- *
- */
- var onGifComplete = function (obj) { //callback function for when image is finished
- if (obj.error === false) {
- $progress.remove();
- progressing = false;
- var animatedImage = document.createElement('img');
-
- //Create a blob out of the image's base64 encoding because Chrome can't handle large data URIs, taken from:
- //http://stackoverflow.com/questions/16761927/aw-snap-when-data-uri-is-too-large
- var byteCharacters = atob(obj.image.substring(22)), byteArrays = []; //remove "data:image/gif;base64,"
- for (var offset = 0; offset < byteCharacters.length; offset += 512) {
- var slice = byteCharacters.slice(offset, offset + 512);
-
- var byteNumbers = new Array(slice.length);
- for (var i = 0; i < slice.length; i++)
- byteNumbers[i] = slice.charCodeAt(i);
-
- var byteArray = new Uint8Array(byteNumbers);
- byteArrays.push(byteArray);
- }
-
- var blob = new Blob(byteArrays, {type: "image/gif"});
- var blobURL = URL.createObjectURL(blob); //supported in Chrome and FF
- animatedImage.src = blobURL;
- var dlURL = wv.util.format("nasa-worldview-{1}-to-{2}.gif", animModel.rangeState.startDate, animModel.rangeState.endDate);
- var downloadSize = (blob.size / 1024).toFixed();
-
- //Create download link and apply button CSS
- var $download = $("<a><span class=ui-button-text>Download</span></a>")
- .attr("type", "button")
- .attr("role", "button")
- .attr("download", dlURL)
- .attr("href", blobURL)
- .attr("class", "ui-button ui-widget ui-state-default ui-button-text-only")
- .hover(function() {$(this).addClass("ui-state-hover");}, function() {$(this).removeClass("ui-state-hover");})
- .click(function() {
- WVC.GA.event('Animation', 'Download', 'GIF', downloadSize);
- });
-
- var $catalog =
- "<div class='gif-results-dialog' style='height: " + animCoords.h + "px; min-height: 210px;' >" +
- "<div>" +
- "<div><b>" +
- "Size: " +
- "</b></div>" +
- "<div>" +
- downloadSize + " KB" +
- "</div>" +
- "</div>" +
- "<div>" +
- "<div><b>" +
- "Speed: " +
- "</b></div>" +
- "<div>" +
- animModel.rangeState.speed + " fps" +
- "</div>" +
-
- "</div>" +
- "<div>" +
- "<div><b>" +
- "Date Range: " +
- "</b></div>" +
- "<div>" +
- animModel.rangeState.startDate +
- "</div>" +
- "<div>" +
- " - " +
- "</div>" +
- "<div>" +
- animModel.rangeState.endDate +
- "</div>" +
- "</div>" +
- "<div>" +
- "<div><b>" +
- "Increments: " +
- "</b></div>" +
- "<div>" +
- ui.anim.widget.getIncrements() +
- "</div>" +
-
- "</div>" +
- "</div>";
- var $dialogBodyCase = $("<div></div>");
- $dialogBodyCase.addClass('gif-results-dialog-case');
- $dialogBodyCase.css('padding', '10px 0');
- $dialogBodyCase.append(animatedImage);
- $dialogBodyCase.append($catalog);
- //calculate the offset of the dialog position based on image size to display it properly
- //only height needs to be adjusted to center the dialog
- var pos_width = animCoords.w * 1 / window.innerWidth, pos_height = animCoords.h * 50 / window.innerHeight;
- var at_string = "center-" + pos_width.toFixed() + "% center-" + pos_height.toFixed() + "%";
-
- //Create a dialog over the view and place the image there
- var $imgDialog = wv.ui.getDialog().append($dialogBodyCase).append($download);
- $imgDialog.dialog({
- dialogClass: "wv-panel wv-gif-results",
- title: "Your GIF",
- width: animCoords.w + 198,
- resizable: false,
- close: function() {
- animCoords = null;
- $imgDialog.find("img").remove();
- $('#timeline-footer').toggleClass('wv-anim-active');
- },
- position: { //based on image size
- my: "center center",
- at: at_string,
- of: window
- }
- });
- } else {
- var headerMsg = "<h3 class='wv-data-unavailable-header'>GIF Not Available</h3>";
- var bodyMsg = 'One or more of the frames requested was unable to be processed';
- wv.ui.indicator.hide(loader);
- callback = function() {
- $('#timeline-footer').toggleClass('wv-anim-active');
- };
- wv.ui.notify(headerMsg + bodyMsg, "Notice", 600, callback);
- }
- };
-
- /*
- * uses resolution and dimension to
- * calculates size of selected area
- *
- * @method calcSize
- * @private
- *
- * @param c {object} dimension object
- *
- * @returns {number} Size of frame
- *
- */
- var calcSize = function(c) {
- var lonlat1 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x), Math.floor(c.y2)]),
- lonlat2 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x2), Math.floor(c.y)]);
-
- var conversionFactor = models.proj.selected.id === "geographic" ? 0.002197 : 256, res = calcRes(0);
-
- var imgWidth = Math.round((Math.abs(lonlat2[0] - lonlat1[0]) / conversionFactor) / Number(res)),
- imgHeight = Math.round((Math.abs(lonlat2[1] - lonlat1[1]) / conversionFactor) / Number(res));
-
- return ((imgWidth * imgHeight * 24) / 8388608).toFixed(2);
- };
-
- /*
- * removes jquery JCrop
- *
- * @method removeCrop
- * @private
- *
- * @param c {object} dimension object
- *
- * @returns {void}
- *
- */
- var removeCrop = function() {
- $("#wv-map").insertAfter('#productsHolder'); //retain map element before disabling jcrop
- animCoords = undefined;
- jcropAPI.destroy();
- if(models.proj.selected.id === "geographic")
- ui.map.events.trigger('selectiondone');
- };
-
- /*
- * Builds selector dialog
- *
- * @method getSelectorDialog
- * @private
- *
- * @param width {number}
- *
- * @returns {JQuery} Selector diaglog element
- *
- */
- self.getSelectorDialog = function(width) {
- var $dialogBox;
- var $createButton;
- var $footer;
- var $dialog =$("<div class='gif-dialog'></div>");
- var $checkBox;
- var dialog =
- "<div class='content'>" +
- "Create an animation from " +
- "<b>" +
- animModel.rangeState.startDate +
- "</b>" +
- " to " +
- "<b>" +
- animModel.rangeState.endDate +
- "</b>" +
- " at a rate of " +
- animModel.rangeState.speed +
- " frames per second" +
- "</div>";
- $createButton = $("<a><span class=ui-button-text>Create GIF</span></a>")
- .attr("type", "button")
- .attr("role", "button")
- .attr("class", "ui-button ui-widget ui-state-default ui-button-text-only")
- .hover(function() {$(this).addClass("ui-state-hover");}, function() {$(this).removeClass("ui-state-hover");});
- $checkBox = $("<div class='wv-checkbox-date'><label for='checkbox-date'><input type='checkbox' title='Check box to remove dates from Animating GIF' name='checkbox-date' class='checkbox-date-input' id='checkbox-date-input'>Include Date Stamps</label></div>");
- $footer = $('<div></div>');
- $footer.append($createButton).append($checkBox);
- $dialog.html(dialog).append($footer);
- // init Checkbox state and listeners
- initCheckBox($checkBox);
-
- $createButton.on('click', self.getGif);
- $dialogBox = wv.ui.getDialog();
- $dialogBox.html($dialog);
- $dialogBox.css({paddingBottom: '10px'});
- $dialogBox.dialog({
- dialogClass: "wv-panel wv-image",
- title: "Generate GIF",
- height: 'auto',
- width: width,
- minHeight: 40,
- minWidth: 287,
- resizable: false,
- show: { effect: "slide", direction: "down" },
- position: {
- my: "left top",
- at: "left bottom+10",
- of: $(".jcrop-tracker")
- },
-
- close: function(event) {
- destoryCheckboxListeners($checkBox);
- $("#wv-map").insertAfter('#productsHolder'); //retain map element before disabling jcrop
- jcropAPI.destroy();
- if(models.proj.selected.id === "geographic")
- ui.map.events.trigger('selectiondone');
- }
- });
- return $dialogBox;
- };
-
- /*
- * Inits iCheck default
- * to enable Gif-date-stamp
- * toggling
- *
- * @method initCheckBox
- * @private
- *
- * @param $checkBox {Jquery} checkbox
- *
- * @returns {void}
- *
- */
- var initCheckBox = function($checkBox) {
- $checkBox.iCheck({
- checkboxClass: 'icheckbox_square-red'
+ wv.ui.notify(headerMsg + bodyMsg, "Notice", 600, callback);
+ };
+
+ /*
+ * resets map rotation to
+ * zero degrees
+ *
+ * @method resetRotation
+ * @private
+ *
+ * @returns {void}
+ *
+ */
+ var resetRotation = function() {
+ ui.map.selected.getView()
+ .animate({
+ duration: 400,
+ rotation: 0
+ });
+ };
+
+ /*
+ * Handles GIF generater conpletion
+ *
+ * @method onGifComplete
+ * @callback
+ *
+ * @param obj {object} gifShot GIF-complete
+ * object
+ *
+ * @returns {void}
+ *
+ */
+ var onGifComplete = function(obj) { //callback function for when image is finished
+ if (obj.error === false) {
+ $progress.remove();
+ progressing = false;
+ var animatedImage = document.createElement('img');
+
+ //Create a blob out of the image's base64 encoding because Chrome can't handle large data URIs, taken from:
+ //http://stackoverflow.com/questions/16761927/aw-snap-when-data-uri-is-too-large
+ var byteCharacters = atob(obj.image.substring(22)),
+ byteArrays = []; //remove "data:image/gif;base64,"
+ for (var offset = 0; offset < byteCharacters.length; offset += 512) {
+ var slice = byteCharacters.slice(offset, offset + 512);
+
+ var byteNumbers = new Array(slice.length);
+ for (var i = 0; i < slice.length; i++)
+ byteNumbers[i] = slice.charCodeAt(i);
+
+ var byteArray = new Uint8Array(byteNumbers);
+ byteArrays.push(byteArray);
+ }
+
+ var blob = new Blob(byteArrays, {
+ type: "image/gif"
+ });
+ var blobURL = URL.createObjectURL(blob); //supported in Chrome and FF
+ animatedImage.src = blobURL;
+ var dlURL = wv.util.format("nasa-worldview-{1}-to-{2}.gif", animModel.rangeState.startDate, animModel.rangeState.endDate);
+ var downloadSize = (blob.size / 1024)
+ .toFixed();
+
+ //Create download link and apply button CSS
+ var $download = $("<a><span class=ui-button-text>Download</span></a>")
+ .attr("type", "button")
+ .attr("role", "button")
+ .attr("download", dlURL)
+ .attr("href", blobURL)
+ .attr("class", "ui-button ui-widget ui-state-default ui-button-text-only")
+ .hover(function() {
+ $(this)
+ .addClass("ui-state-hover");
+ }, function() {
+ $(this)
+ .removeClass("ui-state-hover");
+ })
+ .click(function() {
+ WVC.GA.event('Animation', 'Download', 'GIF', downloadSize);
});
- $checkBox.iCheck('check');
- showDates = true;
- $checkBox.on('ifChecked', onchecked);
- $checkBox.on('ifUnchecked', onchecked);
- };
- /*
- * checkBox event handler
- *
- * @method onchecked
- * @private
- *
- * @param e {Jquery} event object
- *
- * @returns {void}
- *
- */
- var onchecked = function(e) {
- if(e.type === 'ifUnchecked' ) {
- showDates = false;
- } else {
- showDates = true;
- }
- };
- /*
- * checkBox event listener destroyer
- *
- * @method destoryCheckboxListeners
- * @private
- *
- * @param $checkBox {Jquery} checkbox
- *
- * @returns {void}
- *
- */
- var destoryCheckboxListeners = function($checkBox) {
- $checkBox.off('ifChecked', onchecked);
- $checkBox.off('ifUnchecked', onchecked);
- };
- /*
- * Sets diaglog width && location
- *
- * @method setDialogWidth
- * @private
- *
- * @param $dialog {Jquery} dialog
- * @param width {number} JCrop selector width
- *
- * @returns {void}
- *
- */
- var setDialogWidth = function($dialog, width) {
- var $parent;
- if(width < 287) {
- width = 287;
+ var $catalog =
+ "<div class='gif-results-dialog' style='height: " + animCoords.h + "px; min-height: 210px;' >" +
+ "<div>" +
+ "<div><b>" +
+ "Size: " +
+ "</b></div>" +
+ "<div>" +
+ downloadSize + " KB" +
+ "</div>" +
+ "</div>" +
+ "<div>" +
+ "<div><b>" +
+ "Speed: " +
+ "</b></div>" +
+ "<div>" +
+ animModel.rangeState.speed + " fps" +
+ "</div>" +
+
+ "</div>" +
+ "<div>" +
+ "<div><b>" +
+ "Date Range: " +
+ "</b></div>" +
+ "<div>" +
+ animModel.rangeState.startDate +
+ "</div>" +
+ "<div>" +
+ " - " +
+ "</div>" +
+ "<div>" +
+ animModel.rangeState.endDate +
+ "</div>" +
+ "</div>" +
+ "<div>" +
+ "<div><b>" +
+ "Increments: " +
+ "</b></div>" +
+ "<div>" +
+ ui.anim.widget.getIncrements() +
+ "</div>" +
+
+ "</div>" +
+ "</div>";
+ var $dialogBodyCase = $("<div></div>");
+ $dialogBodyCase.addClass('gif-results-dialog-case');
+ $dialogBodyCase.css('padding', '10px 0');
+ $dialogBodyCase.append(animatedImage);
+ $dialogBodyCase.append($catalog);
+ //calculate the offset of the dialog position based on image size to display it properly
+ //only height needs to be adjusted to center the dialog
+ var pos_width = animCoords.w * 1 / window.innerWidth,
+ pos_height = animCoords.h * 50 / window.innerHeight;
+ var at_string = "center-" + pos_width.toFixed() + "% center-" + pos_height.toFixed() + "%";
+
+ //Create a dialog over the view and place the image there
+ var $imgDialog = wv.ui.getDialog()
+ .append($dialogBodyCase)
+ .append($download);
+ $imgDialog.dialog({
+ dialogClass: "wv-panel wv-gif-results",
+ title: "Your GIF",
+ width: animCoords.w + 198,
+ resizable: false,
+ close: function() {
+ animCoords = null;
+ $imgDialog.find("img")
+ .remove();
+ $('#timeline-footer')
+ .toggleClass('wv-anim-active');
+ },
+ position: { //based on image size
+ my: "center center",
+ at: at_string,
+ of: window
}
- if($dialog) {
- $parent = $dialog.parent();
- $parent.width(width);
- $parent.position({
- my: "left top",
- at: "left bottom+10",
- of: $(".jcrop-tracker")
- });
- }
- };
-
- /*
- * Adjusts download icon size
- *
- * @method setIconFontSize
- * @private
- *
- * @param $el {Jquery} icon element
- * @param width {number} JCrop selector width
- *
- * @returns {void}
- *
- */
- var setIconFontSize = function($el, width) {
- var fs = Math.abs(width / 4);
- if(!$el)
- return;
- if(fs <= 30) {
- fs = 30;
+ });
+ } else {
+ var headerMsg = "<h3 class='wv-data-unavailable-header'>GIF Not Available</h3>";
+ var bodyMsg = 'One or more of the frames requested was unable to be processed';
+ wv.ui.indicator.hide(loader);
+ callback = function() {
+ $('#timeline-footer')
+ .toggleClass('wv-anim-active');
+ };
+ wv.ui.notify(headerMsg + bodyMsg, "Notice", 600, callback);
+ }
+ };
+
+ /*
+ * uses resolution and dimension to
+ * calculates size of selected area
+ *
+ * @method calcSize
+ * @private
+ *
+ * @param c {object} dimension object
+ *
+ * @returns {number} Size of frame
+ *
+ */
+ var calcSize = function(c) {
+ var lonlat1 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x), Math.floor(c.y2)]),
+ lonlat2 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x2), Math.floor(c.y)]);
+
+ var conversionFactor = models.proj.selected.id === "geographic" ? 0.002197 : 256,
+ res = calcRes(0);
+
+ var imgWidth = Math.round((Math.abs(lonlat2[0] - lonlat1[0]) / conversionFactor) / Number(res)),
+ imgHeight = Math.round((Math.abs(lonlat2[1] - lonlat1[1]) / conversionFactor) / Number(res));
+
+ return ((imgWidth * imgHeight * 24) / 8388608)
+ .toFixed(2);
+ };
+
+ /*
+ * removes jquery JCrop
+ *
+ * @method removeCrop
+ * @private
+ *
+ * @param c {object} dimension object
+ *
+ * @returns {void}
+ *
+ */
+ var removeCrop = function() {
+ $("#wv-map")
+ .insertAfter('#productsHolder'); //retain map element before disabling jcrop
+ animCoords = undefined;
+ jcropAPI.destroy();
+ if (models.proj.selected.id === "geographic")
+ ui.map.events.trigger('selectiondone');
+ };
+
+ /*
+ * Builds selector dialog
+ *
+ * @method getSelectorDialog
+ * @private
+ *
+ * @param width {number}
+ *
+ * @returns {JQuery} Selector diaglog element
+ *
+ */
+ self.getSelectorDialog = function(width) {
+ var $dialogBox;
+ var $createButton;
+ var $footer;
+ var $dialog = $("<div class='gif-dialog'></div>");
+ var $checkBox;
+ var dialog =
+ "<div class='content'>" +
+ "Create an animation from " +
+ "<b>" +
+ animModel.rangeState.startDate +
+ "</b>" +
+ " to " +
+ "<b>" +
+ animModel.rangeState.endDate +
+ "</b>" +
+ " at a rate of " +
+ animModel.rangeState.speed +
+ " frames per second" +
+ "</div>";
+ $createButton = $("<a><span class=ui-button-text>Create GIF</span></a>")
+ .attr("type", "button")
+ .attr("role", "button")
+ .attr("class", "ui-button ui-widget ui-state-default ui-button-text-only")
+ .hover(function() {
+ $(this)
+ .addClass("ui-state-hover");
+ }, function() {
+ $(this)
+ .removeClass("ui-state-hover");
+ });
+ $checkBox = $("<div class='wv-checkbox-date'><label for='checkbox-date'><input type='checkbox' title='Check box to remove dates from Animating GIF' name='checkbox-date' class='checkbox-date-input' id='checkbox-date-input'>Include Date Stamps</label></div>");
+ $footer = $('<div></div>');
+ $footer.append($createButton)
+ .append($checkBox);
+ $dialog.html(dialog)
+ .append($footer);
+ // init Checkbox state and listeners
+ initCheckBox($checkBox);
+
+ $createButton.on('click', self.getGif);
+ $dialogBox = wv.ui.getDialog();
+ $dialogBox.html($dialog);
+ $dialogBox.css({
+ paddingBottom: '10px'
+ });
+ $dialogBox.dialog({
+ dialogClass: "wv-panel wv-image",
+ title: "Generate GIF",
+ height: 'auto',
+ width: width,
+ minHeight: 40,
+ minWidth: 287,
+ resizable: false,
+ show: {
+ effect: "slide",
+ direction: "down"
+ },
+ position: {
+ my: "left top",
+ at: "left bottom+10",
+ of: $(".jcrop-tracker")
+ },
+
+ close: function(event) {
+ destoryCheckboxListeners($checkBox);
+ $("#wv-map")
+ .insertAfter('#productsHolder'); //retain map element before disabling jcrop
+ jcropAPI.destroy();
+ if (models.proj.selected.id === "geographic")
+ ui.map.events.trigger('selectiondone');
+ }
+ });
+ return $dialogBox;
+ };
+
+ /*
+ * Inits iCheck default
+ * to enable Gif-date-stamp
+ * toggling
+ *
+ * @method initCheckBox
+ * @private
+ *
+ * @param $checkBox {Jquery} checkbox
+ *
+ * @returns {void}
+ *
+ */
+ var initCheckBox = function($checkBox) {
+ $checkBox.iCheck({
+ checkboxClass: 'icheckbox_square-red'
+ });
+ $checkBox.iCheck('check');
+ showDates = true;
+ $checkBox.on('ifChecked', onchecked);
+ $checkBox.on('ifUnchecked', onchecked);
+ };
+ /*
+ * checkBox event handler
+ *
+ * @method onchecked
+ * @private
+ *
+ * @param e {Jquery} event object
+ *
+ * @returns {void}
+ *
+ */
+ var onchecked = function(e) {
+ if (e.type === 'ifUnchecked') {
+ showDates = false;
+ } else {
+ showDates = true;
+ }
+ };
+ /*
+ * checkBox event listener destroyer
+ *
+ * @method destoryCheckboxListeners
+ * @private
+ *
+ * @param $checkBox {Jquery} checkbox
+ *
+ * @returns {void}
+ *
+ */
+ var destoryCheckboxListeners = function($checkBox) {
+ $checkBox.off('ifChecked', onchecked);
+ $checkBox.off('ifUnchecked', onchecked);
+ };
+
+ /*
+ * Sets diaglog width && location
+ *
+ * @method setDialogWidth
+ * @private
+ *
+ * @param $dialog {Jquery} dialog
+ * @param width {number} JCrop selector width
+ *
+ * @returns {void}
+ *
+ */
+ var setDialogWidth = function($dialog, width) {
+ var $parent;
+ if (width < 287) {
+ width = 287;
+ }
+ if ($dialog) {
+ $parent = $dialog.parent();
+ $parent.width(width);
+ $parent.position({
+ my: "left top",
+ at: "left bottom+10",
+ of: $(".jcrop-tracker")
+ });
+ }
+ };
+
+ /*
+ * Adjusts download icon size
+ *
+ * @method setIconFontSize
+ * @private
+ *
+ * @param $el {Jquery} icon element
+ * @param width {number} JCrop selector width
+ *
+ * @returns {void}
+ *
+ */
+ var setIconFontSize = function($el, width) {
+ var fs = Math.abs(width / 4);
+ if (!$el)
+ return;
+ if (fs <= 30) {
+ fs = 30;
+ }
+ $el.css('font-size', fs);
+ };
+
+ /*
+ * Initializes and sets callbacks for
+ * Jcrop selector
+ *
+ * @method setImageCoords
+ * @private
+ *
+ * @returns {void}
+ *
+ */
+ var setImageCoords = function() {
+ var starterWidth;
+ var $dlButton;
+ var $dialog;
+ //Set JCrop selection
+ if (previousCoords === null || previousCoords === undefined)
+ previousCoords = [($(window)
+ .width() / 2) - 100, ($(window)
+ .height() / 2) - 100, ($(window)
+ .width() / 2) + 100, ($(window)
+ .height() / 2) + 100];
+ else
+ previousCoords = [previousCoords.x, previousCoords.y, previousCoords.x2, previousCoords.y2];
+
+ if (models.proj.selected.id === "geographic")
+ ui.map.events.trigger('selecting');
+ starterWidth = previousCoords[0] - previousCoords[2];
+ //Start the image cropping. Show the dialog
+ $("#wv-map")
+ .Jcrop({
+ bgColor: 'black',
+ bgOpacity: 0.3,
+ fullScreen: true,
+ setSelect: previousCoords,
+ onSelect: function(c) {
+ animCoords = c;
+ $("#wv-gif-width")
+ .html((c.w));
+ $("#wv-gif-height")
+ .html((c.h));
+ },
+ onChange: function(c) { //Update gif size and image size in MB
+ var modalLeftMargin;
+ animCoords = c;
+
+ if (c.h !== 0 && c.w !== 0) //don't save coordinates if empty selection
+ previousCoords = c;
+ var dataSize = calcSize(c);
+ //Update the gif selection dialog
+ $("#wv-gif-width")
+ .html((c.w));
+ $("#wv-gif-height")
+ .html((c.h));
+ $("#wv-gif-size")
+ .html(dataSize + " MB");
+
+ if (dataSize > 250) { //disable GIF generation if GIF would be too large
+ $("#wv-gif-button")
+ .button("disable");
+ } else {
+ $("#wv-gif-button")
+ .button("enable");
+ }
+ setDialogWidth($dialog, c.w);
+ setIconFontSize($dlButton, c.w);
+ },
+ onRelease: function(c) {
+ removeCrop();
+ $('#timeline-footer')
+ .toggleClass('wv-anim-active');
+ if ($dialog) {
+ wv.ui.close();
+ }
}
- $el.css('font-size', fs);
- };
-
- /*
- * Initializes and sets callbacks for
- * Jcrop selector
- *
- * @method setImageCoords
- * @private
- *
- * @returns {void}
- *
- */
- var setImageCoords = function() {
- var starterWidth;
- var $dlButton;
- var $dialog;
- //Set JCrop selection
- if(previousCoords === null || previousCoords === undefined)
- previousCoords = [($(window).width()/2)-100,($(window).height()/2)-100,($(window).width()/2)+100,($(window).height()/2)+100];
- else
- previousCoords = [previousCoords.x, previousCoords.y, previousCoords.x2, previousCoords.y2];
-
- if(models.proj.selected.id === "geographic")
- ui.map.events.trigger('selecting');
- starterWidth = previousCoords[0] - previousCoords[2];
- //Start the image cropping. Show the dialog
- $("#wv-map").Jcrop({
- bgColor: 'black',
- bgOpacity: 0.3,
- fullScreen: true,
- setSelect: previousCoords,
- onSelect: function(c) {
- animCoords = c;
- $("#wv-gif-width").html((c.w));
- $("#wv-gif-height").html((c.h));
- },
- onChange: function(c) { //Update gif size and image size in MB
- var modalLeftMargin;
- animCoords = c;
-
- if(c.h !== 0 && c.w !== 0) //don't save coordinates if empty selection
- previousCoords = c;
- var dataSize = calcSize(c);
- //Update the gif selection dialog
- $("#wv-gif-width").html((c.w));
- $("#wv-gif-height").html((c.h));
- $("#wv-gif-size").html(dataSize + " MB");
-
- if(dataSize > 250) {//disable GIF generation if GIF would be too large
- $("#wv-gif-button").button("disable");
- } else {
- $("#wv-gif-button").button("enable");
- }
- setDialogWidth($dialog, c.w);
- setIconFontSize($dlButton, c.w);
- },
- onRelease: function(c) {
- removeCrop();
- $('#timeline-footer').toggleClass('wv-anim-active');
- if($dialog) {
- wv.ui.close();
- }
- }
- }, function() {
- var $tracker;
- $dlButton =
- "<div class='wv-dl-gif-bt-case'>" +
- "<i class='fa fa-download'>" +
- "</div>";
- jcropAPI = this;
- $('#timeline-footer').toggleClass('wv-anim-active');
- $dialog = self.getSelectorDialog();
- $tracker = this.ui.selection.find('.jcrop-tracker');
- $tracker.append($dlButton);
- $dlButton = $('.wv-dl-gif-bt-case i');
- setIconFontSize($dlButton, starterWidth);
- $dlButton.on('click', self.getGif);
-
-
- });
- };
- self.init();
- return self;
+ }, function() {
+ var $tracker;
+ $dlButton =
+ "<div class='wv-dl-gif-bt-case'>" +
+ "<i class='fa fa-download'>" +
+ "</div>";
+ jcropAPI = this;
+ $('#timeline-footer')
+ .toggleClass('wv-anim-active');
+ $dialog = self.getSelectorDialog();
+ $tracker = this.ui.selection.find('.jcrop-tracker');
+ $tracker.append($dlButton);
+ $dlButton = $('.wv-dl-gif-bt-case i');
+ setIconFontSize($dlButton, starterWidth);
+ $dlButton.on('click', self.getGif);
+
+
+ });
+ };
+ self.init();
+ return self;
};
diff --git a/web/js/animation/wv.anim.js b/web/js/animation/wv.anim.js
index 8bb8f776a..d65b00afe 100644
--- a/web/js/animation/wv.anim.js
+++ b/web/js/animation/wv.anim.js
@@ -11,31 +11,37 @@
* Licensed under the NASA Open Source Agreement, Version 1.3
* http://opensource.gsfc.nasa.gov/nosa.php
*/
- var wv = wv || {};
+var wv = wv || {};
- wv.anim = (function(self) {
+wv.anim = (function(self) {
- //Given the raw string, parse state.a into an object
- self.parse = function(state, errors) {
- if(state.a) {
- var str = state.a, astate = {attributes: []};
+ //Given the raw string, parse state.a into an object
+ self.parse = function(state, errors) {
+ if (state.a) {
+ var str = state.a,
+ astate = {
+ attributes: []
+ };
- //Get text before (
- var on = str.match(/[^\(,]+/)[0];
- if (on !== 'on') { //don't do anything if wrong format
- state.a = undefined;
- return;
- }
+ //Get text before (
+ var on = str.match(/[^\(,]+/)[0];
+ if (on !== 'on') { //don't do anything if wrong format
+ state.a = undefined;
+ return;
+ }
- //remove (, get key value pairs
- str = str.match(/\(.*\)/)[0].replace(/[\(\)]/g, "");
- var kvps = str.split(",");
- _.each(kvps, function (kvp) {
- var parts = kvp.split("=");
- astate.attributes.push({id: parts[0], value: parts[1]});
- });
- state.a = astate;
- }
- };
- return self;
- })(wv.anim || {});
+ //remove (, get key value pairs
+ str = str.match(/\(.*\)/)[0].replace(/[\(\)]/g, "");
+ var kvps = str.split(",");
+ _.each(kvps, function(kvp) {
+ var parts = kvp.split("=");
+ astate.attributes.push({
+ id: parts[0],
+ value: parts[1]
+ });
+ });
+ state.a = astate;
+ }
+ };
+ return self;
+})(wv.anim || {});
diff --git a/web/js/animation/wv.anim.model.js b/web/js/animation/wv.anim.model.js
index 58dfeefe3..643036a8b 100644
--- a/web/js/animation/wv.anim.model.js
+++ b/web/js/animation/wv.anim.model.js
@@ -13,141 +13,141 @@
*/
var wv = wv || {};
wv.anim = wv.anim || {};
-wv.anim.model = wv.anim.model || function(models, config) {
- //state.a is now an object, check input and set values
- var self = {};
- self.delay = 500;
- self.events = wv.util.events();
+wv.anim.model = wv.anim.model || function(models, config) {
+ //state.a is now an object, check input and set values
+ var self = {};
+ self.delay = 500;
+ self.events = wv.util.events();
- self.animationState = {
- active: false,
- speed: 10,
- loop: false,
- reverse: false
- };
+ self.animationState = {
+ active: false,
+ speed: 10,
+ loop: false,
+ reverse: false
+ };
- /*
- * Pulls state.a from permalink
- * on page load
- *
- * @method load
- * @static
- *
- * @param state {object} state object
- * @param errors {object} error object
- * @returns {void}
- *
- */
- self.load = function(state, errors) {
- self.rangeState = self.rangeState || {};
- // self.rangeState.playing = false;
- // if(state.a) {
- // self.rangeState.state = 'on';
- // attributes = state.a.attributes;
- // attributes.forEach(function(attr) {
- // self.rangeState[attr.id] = attr.value;
- // });
- // }
+ /*
+ * Pulls state.a from permalink
+ * on page load
+ *
+ * @method load
+ * @static
+ *
+ * @param state {object} state object
+ * @param errors {object} error object
+ * @returns {void}
+ *
+ */
+ self.load = function(state, errors) {
+ self.rangeState = self.rangeState || {};
+ // self.rangeState.playing = false;
+ // if(state.a) {
+ // self.rangeState.state = 'on';
+ // attributes = state.a.attributes;
+ // attributes.forEach(function(attr) {
+ // self.rangeState[attr.id] = attr.value;
+ // });
+ // }
- if(state.ab) {
- self.rangeState.state = state.ab;
- }
- if(state.as && state.ae) {
+ if (state.ab) {
+ self.rangeState.state = state.ab;
+ }
+ if (state.as && state.ae) {
- if(state.ae.length == 10 && state.as.length == 10) {
- self.rangeState.startDate = state.as;
- self.rangeState.endDate = state.ae;
- }
- }
- if(state.av) {
- self.rangeState.speed = Number(state.av);
- }
- if(state.al) {
- self.rangeState.loop = Boolean(state.al);
- }
- };
+ if (state.ae.length == 10 && state.as.length == 10) {
+ self.rangeState.startDate = state.as;
+ self.rangeState.endDate = state.ae;
+ }
+ }
+ if (state.av) {
+ self.rangeState.speed = Number(state.av);
+ }
+ if (state.al) {
+ self.rangeState.loop = Boolean(state.al);
+ }
+ };
- /*
- * Toggles state object between
- * on and off
- *
- * @method toggleActive
- * @static
- *
- * @returns {void}
- *
- */
- self.toggleActive = function() {
- if(self.rangeState.state === 'off') {
- self.rangeState.state = 'on';
- } else {
- self.rangeState.state = 'off';
- }
- };
+ /*
+ * Toggles state object between
+ * on and off
+ *
+ * @method toggleActive
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.toggleActive = function() {
+ if (self.rangeState.state === 'off') {
+ self.rangeState.state = 'on';
+ } else {
+ self.rangeState.state = 'off';
+ }
+ };
- /*
- * saves animation state to permalink
- *
- * @method save
- * @static
- *
- * @returns {void}
- *
- */
+ /*
+ * saves animation state to permalink
+ *
+ * @method save
+ * @static
+ *
+ * @returns {void}
+ *
+ */
- self.add = function(arra) {
- // var updatedState = _.clone(self.state);
- // arra.forEach(function(prop) {
- // updatedState[prop.id] = prop.value;
- // });
- // self.animationState = updatedState;
- };
+ self.add = function(arra) {
+ // var updatedState = _.clone(self.state);
+ // arra.forEach(function(prop) {
+ // updatedState[prop.id] = prop.value;
+ // });
+ // self.animationState = updatedState;
+ };
- /*
- * saves animation state to permalink
- *
- * @method save
- * @static
- *
- * @returns {void}
- *
- */
- self.save = function(state) {
- var activeState;
- var playStates;
- var options;
- var newState;
+ /*
+ * saves animation state to permalink
+ *
+ * @method save
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.save = function(state) {
+ var activeState;
+ var playStates;
+ var options;
+ var newState;
- rangeState = self.rangeState;
- // state.a = state.a || [];
- // newState = {id: rangeState.state};
- // newState.attributes = [];
- if(rangeState.state) {
- state.ab = rangeState.state;
- state.as = rangeState.startDate;
- state.ae = rangeState.endDate;
- state.av = String(rangeState.speed);
- state.al = String(rangeState.loop);
- }
- // newState.attributes.push(
- // {
- // id:'startDate',
- // value: rangeState.startDate
- // },
- // {
- // id:'endDate',
- // value: rangeState.endDate
- // },
- // {
- // id:'speed',
- // value: rangeState.speed
- // },
- // {
- // id:'loop',
- // value: rangeState.loop
- // }
- // );
- // state.a.push(newState);
- };
- return self;
-};
\ No newline at end of file
+ rangeState = self.rangeState;
+ // state.a = state.a || [];
+ // newState = {id: rangeState.state};
+ // newState.attributes = [];
+ if (rangeState.state) {
+ state.ab = rangeState.state;
+ state.as = rangeState.startDate;
+ state.ae = rangeState.endDate;
+ state.av = String(rangeState.speed);
+ state.al = String(rangeState.loop);
+ }
+ // newState.attributes.push(
+ // {
+ // id:'startDate',
+ // value: rangeState.startDate
+ // },
+ // {
+ // id:'endDate',
+ // value: rangeState.endDate
+ // },
+ // {
+ // id:'speed',
+ // value: rangeState.speed
+ // },
+ // {
+ // id:'loop',
+ // value: rangeState.loop
+ // }
+ // );
+ // state.a.push(newState);
+ };
+ return self;
+};
diff --git a/web/js/animation/wv.anim.rangeselect.js b/web/js/animation/wv.anim.rangeselect.js
index 62d02d22d..02baf3c92 100644
--- a/web/js/animation/wv.anim.rangeselect.js
+++ b/web/js/animation/wv.anim.rangeselect.js
@@ -16,230 +16,236 @@ var wv = wv || {};
wv.anim = wv.anim || {};
wv.anim.rangeselect = wv.anim.rangeselect || function(models, config, ui) {
- var self = {};
- var model;
- var timeline = ui.timeline;
- var widgetOptions = ui.anim.options;
- var rangeSelectionFactory = React.createFactory(WVC.RangeSelector);
- var $mountLocation = $('#wv-rangeselector-case')[0];
- var reactGlobal = {};
- var $footer = $('#timeline-footer');
- var $header = $('#timeline-header');
- var $timeline = $('#timeline');
-
- ui.anim.rangeOptions = ui.anim.rangeOptions || {};
+ var self = {};
+ var model;
+ var timeline = ui.timeline;
+ var widgetOptions = ui.anim.options;
+ var rangeSelectionFactory = React.createFactory(WVC.RangeSelector);
+ var $mountLocation = $('#wv-rangeselector-case')[0];
+ var reactGlobal = {};
+ var $footer = $('#timeline-footer');
+ var $header = $('#timeline-header');
+ var $timeline = $('#timeline');
+
+ ui.anim.rangeOptions = ui.anim.rangeOptions || {};
+ /*
+ * set listeners and initiates
+ * widget
+ *
+ * @method init
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.init = function() {
+ var $animateButton = $('#animate-button');
+ var options;
+
+ self.setDefaults();
+ self.render();
+ models.date.events.on('timeline-change', self.update);
+ model.events.on('change', self.update);
+ };
+
+ /*
+ * Sets default state for animation
+ * feature
+ *
+ * @method setDefaults
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.setDefaults = function() {
/*
- * set listeners and initiates
- * widget
- *
- * @method init
- * @static
- *
- * @returns {void}
- *
+ * Set some defaults
*/
- self.init = function() {
- var $animateButton = $('#animate-button');
- var options;
-
- self.setDefaults();
- self.render();
- models.date.events.on('timeline-change', self.update);
- model.events.on('change', self.update);
+ var rangeState;
+
+ model = models.anim || {};
+ model.rangeState = model.rangeState || {};
+ rangeState = model.rangeState;
+ rangeState.state = rangeState.state || null;
+ rangeState.loop = rangeState.loop || false;
+ rangeState.speed = rangeState.speed || 3;
+ };
+ /*
+ * renders react rangeselector component
+ *
+ * @method render
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.render = function() {
+ var options;
+ var startLocation;
+ var EndLocation;
+ var pick = d3.select('#guitarpick');
+ var pickWidth = pick.node()
+ .getBoundingClientRect()
+ .width;
+ var ticHeight = $('.end-tick')
+ .height();
+ var animEndLocation = (d3.transform(pick.attr("transform"))
+ .translate[0] - (pickWidth / 2)); // getting guitar pick location
+
+ if (model.rangeState.startDate) {
+ startLocation = self.getLocationFromStringDate(model.rangeState.startDate);
+ endLocation = self.getLocationFromStringDate(model.rangeState.endDate);
+ } else {
+ startLocation = animEndLocation - 100;
+ endLocation = animEndLocation;
+ self.updateRange(startLocation, endLocation);
+ }
+
+ options = {
+ startLocation: startLocation, // or zero
+ endLocation: endLocation,
+ max: self.getMaxWidth(),
+ startColor: '#40a9db',
+ endColor: '#295f92',
+ startTriangleColor: '#fff',
+ endTriangleColor: '#4b7aab',
+ rangeColor: '#45bdff',
+ rangeOpacity: 0.3,
+ pinWidth: 5,
+ height: 45,
+ onDrag: self.updateRange,
+ onRangeClick: self.onRangeClick
};
-
- /*
- * Sets default state for animation
- * feature
- *
- * @method setDefaults
- * @static
- *
- * @returns {void}
- *
- */
- self.setDefaults = function() {
- /*
- * Set some defaults
- */
- var rangeState;
-
- model = models.anim || {};
- model.rangeState = model.rangeState || {};
- rangeState = model.rangeState;
- rangeState.state = rangeState.state || null;
- rangeState.loop = rangeState.loop || false;
- rangeState.speed = rangeState.speed || 3;
- };
- /*
- * renders react rangeselector component
- *
- * @method render
- * @static
- *
- * @returns {void}
- *
- */
- self.render = function() {
- var options;
- var startLocation;
- var EndLocation;
- var pick = d3.select('#guitarpick');
- var pickWidth = pick.node().getBoundingClientRect().width;
- var ticHeight = $('.end-tick').height();
- var animEndLocation = (d3.transform(pick.attr("transform")).translate[0] - (pickWidth / 2)); // getting guitar pick location
-
- if(model.rangeState.startDate) {
- startLocation = self.getLocationFromStringDate(model.rangeState.startDate);
- endLocation = self.getLocationFromStringDate(model.rangeState.endDate);
- } else {
- startLocation = animEndLocation - 100;
- endLocation = animEndLocation;
- self.updateRange(startLocation, endLocation);
- }
-
- options = {
- startLocation: startLocation, // or zero
- endLocation: endLocation,
- max: self.getMaxWidth(),
- startColor: '#40a9db',
- endColor: '#295f92',
- startTriangleColor: '#fff',
- endTriangleColor: '#4b7aab',
- rangeColor: '#45bdff',
- rangeOpacity: 0.3,
- pinWidth: 5,
- height: 45,
- onDrag: self.updateRange,
- onRangeClick: self.onRangeClick
- };
- self.reactComponent = ReactDOM.render(rangeSelectionFactory(options), $mountLocation);
- };
-
- /*
- * calculates offset of timeline
- *
- * @method getHeaderOffset
- * @static
- *
- * @returns {number} OffsetX
- *
- */
- self.getHeaderOffset = function() {
- return $header.width() + Number($timeline.css('left').replace("px", "")) + Number($footer.css('margin-left').replace("px", ""));
- };
-
- /*
- * calculates offset of date
- * on timeline
- *
- * @method getLocationFromStringDate
- * @static
- *
- * @param date {string} date string
- * @returns {number} OffsetX
- *
- */
- self.getLocationFromStringDate = function(date) {
- return timeline.x(new Date(date));
- };
-
- /*
- * updates react component state
- *
- * @method update
- * @static
- *
- * @param date {string} date string
- * @returns {void}
- *
- */
- self.update = function() { // being called from timeline.config.js
- var props = self.updateOptions();
- self.reactComponent.setState(props);
- };
-
- /*
- * returns max width of timeline
- *
- * @method getMaxWidth
- * @static
- *
- * @returns {number} max width
- *
- */
- self.getMaxWidth = function() {
- var $elWidth = $footer.width();
- var $dataWidth = timeline.x(timeline.data.end());
- if($elWidth > $dataWidth) {
- return $dataWidth;
- }
- return $elWidth;
- };
-
- /*
- * Gets prop updates
- *
- * @method updateOptions
- * @static
- *
- * @returns {object} props
- *
- */
- self.updateOptions = function() {
- var max;
- var state = model.rangeState;
- var props = {};
- props.startLocation = self.getLocationFromStringDate(state.startDate);
- props.endLocation = self.getLocationFromStringDate(state.endDate);
- props.max = self.getMaxWidth();
-
- return props;
- };
-
- /*
- * Handles click on widget:
- * switches current date to
- * date clicked
- *
- * @method onRangeClick
- * @static
- *
- * @param e {object} native event object
- *
- * @returns {object} props
- *
- */
- self.onRangeClick = function(e) {
- var headerOffset = self.getHeaderOffset();
- var offsetX = (e.pageX - headerOffset);
- var date = timeline.x.invert(offsetX);
- models.date.select(date);
- };
-
- /*
- * Updates start and end dates and triggers
- * change events
- *
- * @method updateRange
- * @static
- *
- * @param startLocation {number} offsetX
- * @param EndLocation {number} offsetX
- *
- * @returns {object} props
- *
- */
- self.updateRange = function(startLocation, EndLocation) {
- var startDate = timeline.x.invert(startLocation);
- var endDate = timeline.x.invert(EndLocation);
- var state = model.rangeState;
- state.startDate = wv.util.toISOStringDate(startDate) || 0;
- state.endDate = wv.util.toISOStringDate(endDate);
- model.rangeState.playing = false;
- model.events.trigger('change');
- model.events.trigger('datechange');
- };
- self.init();
- return self;
-};
\ No newline at end of file
+ self.reactComponent = ReactDOM.render(rangeSelectionFactory(options), $mountLocation);
+ };
+
+ /*
+ * calculates offset of timeline
+ *
+ * @method getHeaderOffset
+ * @static
+ *
+ * @returns {number} OffsetX
+ *
+ */
+ self.getHeaderOffset = function() {
+ return $header.width() + Number($timeline.css('left')
+ .replace("px", "")) + Number($footer.css('margin-left')
+ .replace("px", ""));
+ };
+
+ /*
+ * calculates offset of date
+ * on timeline
+ *
+ * @method getLocationFromStringDate
+ * @static
+ *
+ * @param date {string} date string
+ * @returns {number} OffsetX
+ *
+ */
+ self.getLocationFromStringDate = function(date) {
+ return timeline.x(new Date(date));
+ };
+
+ /*
+ * updates react component state
+ *
+ * @method update
+ * @static
+ *
+ * @param date {string} date string
+ * @returns {void}
+ *
+ */
+ self.update = function() { // being called from timeline.config.js
+ var props = self.updateOptions();
+ self.reactComponent.setState(props);
+ };
+
+ /*
+ * returns max width of timeline
+ *
+ * @method getMaxWidth
+ * @static
+ *
+ * @returns {number} max width
+ *
+ */
+ self.getMaxWidth = function() {
+ var $elWidth = $footer.width();
+ var $dataWidth = timeline.x(timeline.data.end());
+ if ($elWidth > $dataWidth) {
+ return $dataWidth;
+ }
+ return $elWidth;
+ };
+
+ /*
+ * Gets prop updates
+ *
+ * @method updateOptions
+ * @static
+ *
+ * @returns {object} props
+ *
+ */
+ self.updateOptions = function() {
+ var max;
+ var state = model.rangeState;
+ var props = {};
+ props.startLocation = self.getLocationFromStringDate(state.startDate);
+ props.endLocation = self.getLocationFromStringDate(state.endDate);
+ props.max = self.getMaxWidth();
+
+ return props;
+ };
+
+ /*
+ * Handles click on widget:
+ * switches current date to
+ * date clicked
+ *
+ * @method onRangeClick
+ * @static
+ *
+ * @param e {object} native event object
+ *
+ * @returns {object} props
+ *
+ */
+ self.onRangeClick = function(e) {
+ var headerOffset = self.getHeaderOffset();
+ var offsetX = (e.pageX - headerOffset);
+ var date = timeline.x.invert(offsetX);
+ models.date.select(date);
+ };
+
+ /*
+ * Updates start and end dates and triggers
+ * change events
+ *
+ * @method updateRange
+ * @static
+ *
+ * @param startLocation {number} offsetX
+ * @param EndLocation {number} offsetX
+ *
+ * @returns {object} props
+ *
+ */
+ self.updateRange = function(startLocation, EndLocation) {
+ var startDate = timeline.x.invert(startLocation);
+ var endDate = timeline.x.invert(EndLocation);
+ var state = model.rangeState;
+ state.startDate = wv.util.toISOStringDate(startDate) || 0;
+ state.endDate = wv.util.toISOStringDate(endDate);
+ model.rangeState.playing = false;
+ model.events.trigger('change');
+ model.events.trigger('datechange');
+ };
+ self.init();
+ return self;
+};
diff --git a/web/js/animation/wv.anim.ui.js b/web/js/animation/wv.anim.ui.js
index 68a641d0b..7db885d4b 100644
--- a/web/js/animation/wv.anim.ui.js
+++ b/web/js/animation/wv.anim.ui.js
@@ -1,698 +1,700 @@
/*
- * Copyright (C) 2013 - 2014 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- *
- * Licensed under the NASA Open Source Agreement, Version 1.3
- * http://opensource.gsfc.nasa.gov/nosa.php
- */
-var wv = wv || {};
-wv.anim = wv.anim || {};
-wv.anim.ui = wv.anim.ui || function(models, ui) {
- var self = {};
- self.events = wv.util.events();
- var dateModel = models.date;
- var animModel = models.anim;
- var queueLength;
- var animateArray;
- var map = ui.map.selected;
- var zooms = ['year', 'month', 'day'];
- var queue = new Queue(5, Infinity);
- var preload = {};
- var preloadArray;
- var inQueue;
- var pastDates;
- var loader;
-
- /*
- * sets listeners
- *
- *
- * @method init
- * @static
- *
- * @returns {void}
- *
- */
- self.init = function() {
- self.refreshState();
- animModel.events.on('play', self.onPushedPlay);
- animModel.events.on('gif-click', self.refreshState);
- animModel.events.on('datechange', self.refreshState);
- animModel.events.on('toggle-widget', self.refreshState);
- if(models.proj) {
- models.proj.events.on("select", self.refreshState);
- }
- if(models.palettes) {
- models.palettes.events.on('update', self.refreshState);
- }
- if(models.data) {
- models.data.events.on('activate', self.refreshState);
- models.date.events.on('zoom-change', self.refreshState);
- models.date.events.on("select", self.dateChange);
- }
- if(ui.map) {
- ui.map.events.on('added-layer', self.refreshState);
- }
- //map.on('moveend', self.refreshState);
- };
-
- /*
- * If there is a change of date
- * and the animiation is not playing
- * the amin.ui states will be refreshed
- *
- * @method dateChange
- * @static
- *
- * @returns {void}
- *
- */
- self.dateChange = function() {
- if(!self.state.playing) {
- self.refreshState();
- }
- };
-
- /*
- * Resets amin.ui object
- * and variable states
- *
- * @method refreshState
- * @static
- *
- * @returns {void}
- *
- */
-
- self.refreshState = function() {
- preloadArray = [];
- preload = {};
- pastDates = {};
- inQueue = {};
- queueLength = 10;
- self.state = {
- playing: false,
- playIndex: self.getStartDate(),
- supportingCustomLayers: self.hasCustomLayers()
- };
- animModel.rangeState.playing = false;
- animModel.events.trigger('change');
- wv.ui.indicator.hide(loader);
- wv.ui.indicator._hide(loader);
- };
- /*
- * Determines whether to start at
- * current date or to start at the
- * selected start date
- *
- * @method getStartDate
- * @static
- *
- * @returns {string} ISO string Date
- *
- */
-
- self.getStartDate = function() {
- var state;
- var endDate;
- var startDate;
- var currentDate;
- state = animModel.rangeState;
- endDate = wv.util.parseDateUTC(state.endDate);
- startDate = wv.util.parseDateUTC(state.startDate);
- currentDate = dateModel.selected;
- if(currentDate > startDate && self.nextDate(currentDate) < endDate) {
- return wv.util.toISOStringDate(self.nextDate(currentDate));
- }
- return wv.util.toISOStringDate(startDate);
-
- };
-
- /*
- * Handles a play click event
- *
- * @method onPushedPlay
- * @static
- *
- * @returns {void}
- *
- */
- self.onPushedPlay = function() {
- self.checkQueue(queueLength, self.state.playIndex);
- self.checkShouldPlay();
- };
-
- /*
- * retrieves the current timeline zoom
- *
- * @method getInterval
- * @static
- *
- * @returns {string} Zoom increment
- *
- */
- self.getInterval = function() {
- return zooms[ui.timeline.config.currentZoom - 1];
- };
-
- /*
- * Gets next date based on current
- * increments
- *
- * @method nextDate
- * @static
- *
- * @param date {object} JS date obj
- *
- * @returns {object} JS Date
- *
- */
- self.nextDate = function(date) {
- return wv.util.dateAdd(date, self.getInterval(), 1);
- };
-
- /*
- * Gets next date based on current
- * increments
- *
- * @method nextDate
- * @static
- *
- * @param date {object} JS date obj
- *
- * @returns {object} JS Date
- *
- */
- self.addDate = function(date) {
- self.addToInQueue(date);
- queue.add(function () {
- return ui.map.promiseDay(date);
- })
- .then(function(date) {
- self.addDateToCache(date);
- self.shiftCache();
- self.checkQueue(queueLength, self.state.playIndex);
- self.checkShouldPlay();
- });
- };
-
- /*
- * Add date to loading Queue
- * obj
- *
- * @method addToInQueue
- * @static
- *
- * @param date {object} JS date obj
- *
- * @returns {void}
- *
- */
- self.addToInQueue = function(date) {
- var strDate = wv.util.toISOStringDate(date);
- inQueue[strDate] = date;
- preloadArray.push(strDate);
- };
-
- /*
- * removes date from inQueue obj
- * and adds it to the preloaded
- * obj
- *
- * @method addDateToCache
- * @static
- *
- * @param date {object} JS date obj
- *
- * @returns {void}
- *
- */
- self.addDateToCache = function(date) {
- var strDate = wv.util.toISOStringDate(date);
- preload[strDate] = date;
- delete inQueue[strDate];
- };
-
- /*
- * removes item from cache after it has
- * been played and quelimit reached
- *
- *
- * @method shiftCache
- * @static
- *
- * @returns {void}
- *
- */
- self.shiftCache = function() {
- var key;
- if(preload[preloadArray[0]] &&
- wv.util.objectLength(preload) > queueLength + (queueLength / 2) + 1 &&
- pastDates[preloadArray[0]] &&
- !self.isInToPlayGroup(preloadArray[0])) {
- key = preloadArray.shift();
- delete preload[key];
- delete pastDates[key];
- }
- };
-
- /*
- * checks if this date is in array of
- * dates that need to play in future
- * within buffer length
- *
- *
- * @method isInToPlayGroup
- * @static
- *
- * @param testDate {string} JS date string
- *
- * @returns {boolean}
- *
- */
- self.isInToPlayGroup = function(testDate) {
- var loop = animModel.rangeState.loop;
- var i = 0;
- var day = new Date(self.state.playIndex);
- var startDate = new Date(animModel.rangeState.startDate);
- var endDate = new Date(animModel.rangeState.endDate);
- var jsTestDate = new Date(testDate);
- while(i < queueLength) {
- if(self.nextDate(day) > endDate) {
- if(!loop) {
- return false;
- }
- day = self.setNewDate(day, startDate);
- } else {
- day = self.nextDate(day);
- }
- if(day.valueOf() == jsTestDate.valueOf()) {
- return true;
- }
- i++;
- }
- return false;
- };
-
- /*
- * Clears precache
- *
- * @method clearCache
- * @static
- *
- *
- * @returns {void}
- *
- */
- self.clearCache = function() {
- preload = {};
- preloadArray = [];
- };
-
- /*
- * Determines what dates should
- * be queued
- *
- * @method checkQueue
- * @static
- *
- * @param bufferLength {number} JS date string
- * @param index {string} Date string
- * @returns {void}
- *
- */
- self.checkQueue = function(bufferLength, index) {
- var date;
- var currentDate;
- var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);
- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
- var loop = animModel.rangeState.loop;
- var lastToQueue;
- var nextDate;
- if(!animModel.rangeState.playing) {
- return self.refreshState();
- }
- currentDate = wv.util.parseDateUTC(index);
- lastToQueue = self.getLastBufferDateStr(currentDate, startDate, endDate);
-
- if(!preloadArray[0] && !inQueue[index]) {
- self.initialPreload(currentDate, startDate, endDate, lastToQueue);
- } else if (!preload[lastToQueue] && !inQueue[lastToQueue] && !self.state.supportingCustomLayers) {// if last preload date doesn't exist
- self.addItemToQueue(currentDate, startDate, endDate);
- } else if(self.state.supportingCustomLayers && preloadArray[0]) {
- self.customQueuer(currentDate, startDate, endDate);
- }
- };
-
- /*
- * Checks to see if custom layers are
- * active
- *
- * @method hasCustomLayers
- * @static
- *
- * @returns {boolean}
- *
- */
- self.hasCustomLayers = function() {
- var layer;
- var layers = models.layers.get();
-
- for(var i = 0, len = layers; i < layers.length; i++) {
- layer = layers[i];
- if(!_.isEmpty(models.palettes.isActive(layer.id)) && layer.visible) {
- return true;
- }
- }
- return false;
- };
-
- /*
- * Custom date queuer created for
- * custom colormaps
- *
- * @method customQueuer
- * @static
- *
- * @param currentDate {object} JS date
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- *
- * @returns {void}
- *
- */
- self.customQueuer = function(currentDate, startDate, endDate) {
- var nextDateStr;
- var nextDate = self.nextDate(currentDate);
- if(nextDate > endDate) {
- nextDate = self.setNewDate(nextDate, startDate);
- }
-
- nextDateStr = wv.util.toISOStringDate(nextDate);
-
- if(!preload[nextDateStr] && !inQueue[nextDateStr] && !self.state.playing) {
- self.clearCache();
- self.checkQueue(queueLength, self.state.playIndex);
- }
- };
-
- /*
- * adds dates to precache queuer
- *
- * @method initialPreload
- * @static
- *
- * @param currentDate {object} JS date
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- * @param lastToQueue {string} date String
- *
- * @returns {void}
- *
- */
- self.initialPreload = function(currentDate, startDate, endDate, lastToQueue) {
- var day = currentDate;
- queueLength = self.getQueueLength(startDate, endDate);
- if(queueLength <= 1) { // if only one frame will play just move to that date
- dateModel.select(startDate);
- animModel.rangeState.playing = false;
- setTimeout(function() {self.refreshState();}, 100);
- return;
- }
- for(var i = 0; i < queueLength; i++) {
- self.addDate(day);
- day = self.getNextBufferDate(day, startDate, endDate);
- if(wv.util.toISOStringDate(day) === lastToQueue) {
- self.addDate(day);
- loader = wv.ui.indicator.loading();
- return;
- } else if(wv.util.toISOStringDate(day) === wv.util.toISOStringDate(currentDate)) {
- queueLength = i;
- loader = wv.ui.indicator.loading();
- return;
- }
- }
- loader = wv.ui.indicator.loading();
- };
-
- /*
- * calculates buffer length if
- * date array length is less than
- * default queueLength
- *
- * @method getQueueLength
- * @static
- *
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- *
- * @returns {number} new buffer length
- *
- */
- self.getQueueLength= function(startDate, endDate) {
- var day = startDate;
- var i = 0;
- while(i < queueLength) {
- i++;
- day = self.nextDate(day);
- if(day > endDate){
- return i;
- }
- }
- return i;
- };
-
- /*
- * Verifies that date is
- * valid and adds it to queuer
- *
- * @method addItemToQueue
- * @static
- *
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- *
- * @returns {void}
- *
- */
- self.addItemToQueue = function(currentDate, startDate, endDate) {
- var nextDate = self.getNextBufferDate(currentDate, startDate, endDate);
- var nextDateStr = wv.util.toISOStringDate(nextDate);
-
- if(!inQueue[nextDateStr] &&
- !preload[nextDateStr] &&
- nextDate <= endDate &&
- nextDate >= startDate) {
- self.addDate(nextDate);
- self.checkQueue(queueLength, self.state.playIndex);
- }
- };
-
- /*
- * gets next date to add to
- * queue
- *
- * @method addItemToQueue
- * @static
- *
- * @param currentDate {object} JS date
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- *
- * @returns {object} JS Date
- *
- */
- self.getNextBufferDate = function(currentDate, startDate, endDate) {
- var lastInBuffer = wv.util.parseDateUTC(preloadArray[preloadArray.length - 1]);
- var nextDate = self.nextDate(lastInBuffer);
- if(lastInBuffer >= endDate || self.nextDate(lastInBuffer) > endDate) {
- return self.setNewDate(nextDate, startDate);
- }
- return self.nextDate(lastInBuffer);
- };
-
- /*
- * Gets the last date that should be added
- * to the queuer
- *
- * @method getLastBufferDateStr
- * @static
- *
- * @param currentDate {object} JS date
- * @param startDate {object} JS date
- * @param endDate {object} JS date
- *
- * @returns {string} Date string
- *
- */
- self.getLastBufferDateStr = function(currentDate, startDate, endDate) {
- var day = currentDate;
- var loop = animModel.rangeState.loop;
- var i = 1;
-
- while(i < queueLength) {
- if(self.nextDate(day) > endDate) {
- if(!loop) {
- return wv.util.toISOStringDate(day);
- }
- day = self.setNewDate(day, startDate);
-
- } else {
- day = self.nextDate(day);
- }
- i++;
- }
- return wv.util.toISOStringDate(day);
- };
-
- /*
- * Gets the last date that should be added
- * to the queuer
- *
- * @method checkShouldLoop
- * @static
- *
- * @param playIndexJSDate {object} JS date
- * that is currently being shown
- *
- * @returns {void}
- *
- */
- self.checkShouldLoop = function(playIndexJSDate) {
- if(animModel.rangeState.loop) {
- self.shiftCache();
- self.state.playIndex = wv.util.toISOStringDate(self.setNewDate(playIndexJSDate, new Date(animModel.rangeState.startDate)));
- setTimeout( function() {
- self.checkShouldPlay();
- self.checkQueue(queueLength,self.state.playIndex);
- }, 1000);
- } else {
- self.refreshState();
- }
- };
-
- /*
- * Gets the last date that should be added
- * to the queuer
- *
- * @method checkShouldLoop
- * @static
- *
- * @param playIndexJSDate {object} JS date
- * that is currently being shown
- *
- * @returns {void}
- *
- */
- self.checkShouldPlay = function() {
- var currentDate = wv.util.parseDateUTC(self.state.playIndex);
- var fps = 1000 / animModel.rangeState.speed;
- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
- var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);
- if(self.state.playing || !animModel.rangeState.playing) {
- return false;
- }
-
- if(preload[self.getLastBufferDateStr(currentDate, startDate, endDate)]) {
- self.play(self.state.playIndex);
- return;
- }
- if(self.state.supportingCustomLayers &&
- preload[self.state.playIndex] &&
- _.isEmpty(inQueue)) {
- self.play(self.state.playIndex);
- return;
- }
- self.shiftCache();
- };
-
- /*
- * removes loader and starts the
- * animation
- *
- * @method play
- * @static
- *
- * @param index {string} date string
- *
- * @returns {void}
- *
- */
- self.play = function(index) {
- self.state.playing = true;
- wv.ui.indicator.hide(loader);
- wv.ui.indicator._hide(loader);
- self.animate(index);
- return;
- };
-
- /*
- * Gets date to start on when animation
- * is being looped
- *
- * @method setNewDate
- * @static
- *
- * @param date {number} JS Date
- * @param newDate {number} JS Date
- *
- * @returns {void}
- *
- */
- self.setNewDate = function(date, newDate) {
- return newDate;
- };
-
- /*
- * function that loops through frames
- * at a specified time interval
- *
- * @method animate
- * @static
- *
- * @param index {string} Date string
- * @returns {void}
- *
- */
- self.animate = function(index) {
- var interval;
- var playIndex = index;
- var playIndexJSDate;
- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
- var player = function() {
- self.shiftCache();
- self.checkQueue(queueLength, playIndex);
-
- dateModel.select(wv.util.parseDateUTC(playIndex));
- pastDates[playIndex] = wv.util.parseDateUTC(playIndex); // played record
- self.state.playIndex = playIndex;
- playIndex = wv.util.toISOStringDate(self.nextDate(new Date(playIndex)));
- playIndexJSDate = new Date(playIndex);
- if(playIndexJSDate > endDate) {
- clearInterval(interval);
- self.state.playing = false;
- self.checkShouldLoop(playIndexJSDate);
- return;
- }
- if(!animModel.rangeState.playing || !preload[playIndex]) {
- clearInterval(interval);
- self.state.playing = false;
- if(!preload[playIndex] && animModel.rangeState.playing) {// Still playing, add loader
- loader = wv.ui.indicator.loading();
- self.shiftCache();
- self.checkQueue(queueLength, self.state.playIndex);
- } else {
- self.refreshState();
- }
- return;
- }
-
- self.checkQueue(queueLength, self.state.playIndex);
- interval = setTimeout(player, 1000 / animModel.rangeState.speed);
- };
- interval = setTimeout(player, animModel.rangeState.speed);
- };
- self.init();
- return self;
-};
\ No newline at end of file
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ *
+ * Licensed under the NASA Open Source Agreement, Version 1.3
+ * http://opensource.gsfc.nasa.gov/nosa.php
+ */
+ var wv = wv || {};
+ wv.anim = wv.anim || {};
+ wv.anim.ui = wv.anim.ui || function(models, ui) {
+ var self = {};
+ self.events = wv.util.events();
+ var dateModel = models.date;
+ var animModel = models.anim;
+ var queueLength;
+ var animateArray;
+ var map = ui.map.selected;
+ var zooms = ['year', 'month', 'day'];
+ var queue = new Queue(5, Infinity);
+ var preload = {};
+ var preloadArray;
+ var inQueue;
+ var pastDates;
+ var loader;
+
+ /*
+ * sets listeners
+ *
+ *
+ * @method init
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.init = function() {
+ self.refreshState();
+ animModel.events.on('play', self.onPushedPlay);
+ animModel.events.on('gif-click', self.refreshState);
+ animModel.events.on('datechange', self.refreshState);
+ animModel.events.on('toggle-widget', self.refreshState);
+ if (models.proj) {
+ models.proj.events.on("select", self.refreshState);
+ }
+ if (models.palettes) {
+ models.palettes.events.on('update', self.refreshState);
+ }
+ if (models.data) {
+ models.data.events.on('activate', self.refreshState);
+ models.date.events.on('zoom-change', self.refreshState);
+ models.date.events.on("select", self.dateChange);
+ }
+ if (ui.map) {
+ ui.map.events.on('added-layer', self.refreshState);
+ }
+ //map.on('moveend', self.refreshState);
+ };
+
+ /*
+ * If there is a change of date
+ * and the animiation is not playing
+ * the amin.ui states will be refreshed
+ *
+ * @method dateChange
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.dateChange = function() {
+ if (!self.state.playing) {
+ self.refreshState();
+ }
+ };
+
+ /*
+ * Resets amin.ui object
+ * and variable states
+ *
+ * @method refreshState
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+
+ self.refreshState = function() {
+ preloadArray = [];
+ preload = {};
+ pastDates = {};
+ inQueue = {};
+ queueLength = 10;
+ self.state = {
+ playing: false,
+ playIndex: self.getStartDate(),
+ supportingCustomLayers: self.hasCustomLayers()
+ };
+ animModel.rangeState.playing = false;
+ animModel.events.trigger('change');
+ wv.ui.indicator.hide(loader);
+ wv.ui.indicator._hide(loader);
+ };
+ /*
+ * Determines whether to start at
+ * current date or to start at the
+ * selected start date
+ *
+ * @method getStartDate
+ * @static
+ *
+ * @returns {string} ISO string Date
+ *
+ */
+
+ self.getStartDate = function() {
+ var state;
+ var endDate;
+ var startDate;
+ var currentDate;
+ state = animModel.rangeState;
+ endDate = wv.util.parseDateUTC(state.endDate);
+ startDate = wv.util.parseDateUTC(state.startDate);
+ currentDate = dateModel.selected;
+ if (currentDate > startDate && self.nextDate(currentDate) < endDate) {
+ return wv.util.toISOStringDate(self.nextDate(currentDate));
+ }
+ return wv.util.toISOStringDate(startDate);
+
+ };
+
+ /*
+ * Handles a play click event
+ *
+ * @method onPushedPlay
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onPushedPlay = function() {
+ self.checkQueue(queueLength, self.state.playIndex);
+ self.checkShouldPlay();
+ };
+
+ /*
+ * retrieves the current timeline zoom
+ *
+ * @method getInterval
+ * @static
+ *
+ * @returns {string} Zoom increment
+ *
+ */
+ self.getInterval = function() {
+ return zooms[ui.timeline.config.currentZoom - 1];
+ };
+
+ /*
+ * Gets next date based on current
+ * increments
+ *
+ * @method nextDate
+ * @static
+ *
+ * @param date {object} JS date obj
+ *
+ * @returns {object} JS Date
+ *
+ */
+ self.nextDate = function(date) {
+ return wv.util.dateAdd(date, self.getInterval(), 1);
+ };
+
+ /*
+ * Gets next date based on current
+ * increments
+ *
+ * @method nextDate
+ * @static
+ *
+ * @param date {object} JS date obj
+ *
+ * @returns {object} JS Date
+ *
+ */
+ self.addDate = function(date) {
+ self.addToInQueue(date);
+ queue.add(function() {
+ return ui.map.promiseDay(date);
+ })
+ .then(function(date) {
+ self.addDateToCache(date);
+ self.shiftCache();
+ self.checkQueue(queueLength, self.state.playIndex);
+ self.checkShouldPlay();
+ });
+ };
+
+ /*
+ * Add date to loading Queue
+ * obj
+ *
+ * @method addToInQueue
+ * @static
+ *
+ * @param date {object} JS date obj
+ *
+ * @returns {void}
+ *
+ */
+ self.addToInQueue = function(date) {
+ var strDate = wv.util.toISOStringDate(date);
+ inQueue[strDate] = date;
+ preloadArray.push(strDate);
+ };
+
+ /*
+ * removes date from inQueue obj
+ * and adds it to the preloaded
+ * obj
+ *
+ * @method addDateToCache
+ * @static
+ *
+ * @param date {object} JS date obj
+ *
+ * @returns {void}
+ *
+ */
+ self.addDateToCache = function(date) {
+ var strDate = wv.util.toISOStringDate(date);
+ preload[strDate] = date;
+ delete inQueue[strDate];
+ };
+
+ /*
+ * removes item from cache after it has
+ * been played and quelimit reached
+ *
+ *
+ * @method shiftCache
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.shiftCache = function() {
+ var key;
+ if (preload[preloadArray[0]] &&
+ wv.util.objectLength(preload) > queueLength + (queueLength / 2) + 1 &&
+ pastDates[preloadArray[0]] &&
+ !self.isInToPlayGroup(preloadArray[0])) {
+ key = preloadArray.shift();
+ delete preload[key];
+ delete pastDates[key];
+ }
+ };
+
+ /*
+ * checks if this date is in array of
+ * dates that need to play in future
+ * within buffer length
+ *
+ *
+ * @method isInToPlayGroup
+ * @static
+ *
+ * @param testDate {string} JS date string
+ *
+ * @returns {boolean}
+ *
+ */
+ self.isInToPlayGroup = function(testDate) {
+ var loop = animModel.rangeState.loop;
+ var i = 0;
+ var day = new Date(self.state.playIndex);
+ var startDate = new Date(animModel.rangeState.startDate);
+ var endDate = new Date(animModel.rangeState.endDate);
+ var jsTestDate = new Date(testDate);
+ while (i < queueLength) {
+ if (self.nextDate(day) > endDate) {
+ if (!loop) {
+ return false;
+ }
+ day = self.setNewDate(day, startDate);
+ } else {
+ day = self.nextDate(day);
+ }
+ if (day.valueOf() == jsTestDate.valueOf()) {
+ return true;
+ }
+ i++;
+ }
+ return false;
+ };
+
+ /*
+ * Clears precache
+ *
+ * @method clearCache
+ * @static
+ *
+ *
+ * @returns {void}
+ *
+ */
+ self.clearCache = function() {
+ preload = {};
+ preloadArray = [];
+ };
+
+ /*
+ * Determines what dates should
+ * be queued
+ *
+ * @method checkQueue
+ * @static
+ *
+ * @param bufferLength {number} JS date string
+ * @param index {string} Date string
+ * @returns {void}
+ *
+ */
+ self.checkQueue = function(bufferLength, index) {
+ var date;
+ var currentDate;
+ var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);
+ var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
+ var loop = animModel.rangeState.loop;
+ var lastToQueue;
+ var nextDate;
+ if (!animModel.rangeState.playing) {
+ return self.refreshState();
+ }
+ currentDate = wv.util.parseDateUTC(index);
+ lastToQueue = self.getLastBufferDateStr(currentDate, startDate, endDate);
+
+ if (!preloadArray[0] && !inQueue[index]) {
+ self.initialPreload(currentDate, startDate, endDate, lastToQueue);
+ } else if (!preload[lastToQueue] && !inQueue[lastToQueue] && !self.state.supportingCustomLayers) { // if last preload date doesn't exist
+ self.addItemToQueue(currentDate, startDate, endDate);
+ } else if (self.state.supportingCustomLayers && preloadArray[0]) {
+ self.customQueuer(currentDate, startDate, endDate);
+ }
+ };
+
+ /*
+ * Checks to see if custom layers are
+ * active
+ *
+ * @method hasCustomLayers
+ * @static
+ *
+ * @returns {boolean}
+ *
+ */
+ self.hasCustomLayers = function() {
+ var layer;
+ var layers = models.layers.get();
+
+ for (var i = 0, len = layers; i < layers.length; i++) {
+ layer = layers[i];
+ if (!_.isEmpty(models.palettes.isActive(layer.id)) && layer.visible) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ /*
+ * Custom date queuer created for
+ * custom colormaps
+ *
+ * @method customQueuer
+ * @static
+ *
+ * @param currentDate {object} JS date
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ *
+ * @returns {void}
+ *
+ */
+ self.customQueuer = function(currentDate, startDate, endDate) {
+ var nextDateStr;
+ var nextDate = self.nextDate(currentDate);
+ if (nextDate > endDate) {
+ nextDate = self.setNewDate(nextDate, startDate);
+ }
+
+ nextDateStr = wv.util.toISOStringDate(nextDate);
+
+ if (!preload[nextDateStr] && !inQueue[nextDateStr] && !self.state.playing) {
+ self.clearCache();
+ self.checkQueue(queueLength, self.state.playIndex);
+ }
+ };
+
+ /*
+ * adds dates to precache queuer
+ *
+ * @method initialPreload
+ * @static
+ *
+ * @param currentDate {object} JS date
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ * @param lastToQueue {string} date String
+ *
+ * @returns {void}
+ *
+ */
+ self.initialPreload = function(currentDate, startDate, endDate, lastToQueue) {
+ var day = currentDate;
+ queueLength = self.getQueueLength(startDate, endDate);
+ if (queueLength <= 1) { // if only one frame will play just move to that date
+ dateModel.select(startDate);
+ animModel.rangeState.playing = false;
+ setTimeout(function() {
+ self.refreshState();
+ }, 100);
+ return;
+ }
+ for (var i = 0; i < queueLength; i++) {
+ self.addDate(day);
+ day = self.getNextBufferDate(day, startDate, endDate);
+ if (wv.util.toISOStringDate(day) === lastToQueue) {
+ self.addDate(day);
+ loader = wv.ui.indicator.loading();
+ return;
+ } else if (wv.util.toISOStringDate(day) === wv.util.toISOStringDate(currentDate)) {
+ queueLength = i;
+ loader = wv.ui.indicator.loading();
+ return;
+ }
+ }
+ loader = wv.ui.indicator.loading();
+ };
+
+ /*
+ * calculates buffer length if
+ * date array length is less than
+ * default queueLength
+ *
+ * @method getQueueLength
+ * @static
+ *
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ *
+ * @returns {number} new buffer length
+ *
+ */
+ self.getQueueLength = function(startDate, endDate) {
+ var day = startDate;
+ var i = 0;
+ while (i < queueLength) {
+ i++;
+ day = self.nextDate(day);
+ if (day > endDate) {
+ return i;
+ }
+ }
+ return i;
+ };
+
+ /*
+ * Verifies that date is
+ * valid and adds it to queuer
+ *
+ * @method addItemToQueue
+ * @static
+ *
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ *
+ * @returns {void}
+ *
+ */
+ self.addItemToQueue = function(currentDate, startDate, endDate) {
+ var nextDate = self.getNextBufferDate(currentDate, startDate, endDate);
+ var nextDateStr = wv.util.toISOStringDate(nextDate);
+
+ if (!inQueue[nextDateStr] &&
+ !preload[nextDateStr] &&
+ nextDate <= endDate &&
+ nextDate >= startDate) {
+ self.addDate(nextDate);
+ self.checkQueue(queueLength, self.state.playIndex);
+ }
+ };
+
+ /*
+ * gets next date to add to
+ * queue
+ *
+ * @method addItemToQueue
+ * @static
+ *
+ * @param currentDate {object} JS date
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ *
+ * @returns {object} JS Date
+ *
+ */
+ self.getNextBufferDate = function(currentDate, startDate, endDate) {
+ var lastInBuffer = wv.util.parseDateUTC(preloadArray[preloadArray.length - 1]);
+ var nextDate = self.nextDate(lastInBuffer);
+ if (lastInBuffer >= endDate || self.nextDate(lastInBuffer) > endDate) {
+ return self.setNewDate(nextDate, startDate);
+ }
+ return self.nextDate(lastInBuffer);
+ };
+
+ /*
+ * Gets the last date that should be added
+ * to the queuer
+ *
+ * @method getLastBufferDateStr
+ * @static
+ *
+ * @param currentDate {object} JS date
+ * @param startDate {object} JS date
+ * @param endDate {object} JS date
+ *
+ * @returns {string} Date string
+ *
+ */
+ self.getLastBufferDateStr = function(currentDate, startDate, endDate) {
+ var day = currentDate;
+ var loop = animModel.rangeState.loop;
+ var i = 1;
+
+ while (i < queueLength) {
+ if (self.nextDate(day) > endDate) {
+ if (!loop) {
+ return wv.util.toISOStringDate(day);
+ }
+ day = self.setNewDate(day, startDate);
+
+ } else {
+ day = self.nextDate(day);
+ }
+ i++;
+ }
+ return wv.util.toISOStringDate(day);
+ };
+
+ /*
+ * Gets the last date that should be added
+ * to the queuer
+ *
+ * @method checkShouldLoop
+ * @static
+ *
+ * @param playIndexJSDate {object} JS date
+ * that is currently being shown
+ *
+ * @returns {void}
+ *
+ */
+ self.checkShouldLoop = function(playIndexJSDate) {
+ if (animModel.rangeState.loop) {
+ self.shiftCache();
+ self.state.playIndex = wv.util.toISOStringDate(self.setNewDate(playIndexJSDate, new Date(animModel.rangeState.startDate)));
+ setTimeout(function() {
+ self.checkShouldPlay();
+ self.checkQueue(queueLength, self.state.playIndex);
+ }, 1000);
+ } else {
+ self.refreshState();
+ }
+ };
+
+ /*
+ * Gets the last date that should be added
+ * to the queuer
+ *
+ * @method checkShouldLoop
+ * @static
+ *
+ * @param playIndexJSDate {object} JS date
+ * that is currently being shown
+ *
+ * @returns {void}
+ *
+ */
+ self.checkShouldPlay = function() {
+ var currentDate = wv.util.parseDateUTC(self.state.playIndex);
+ var fps = 1000 / animModel.rangeState.speed;
+ var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
+ var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);
+ if (self.state.playing || !animModel.rangeState.playing) {
+ return false;
+ }
+
+ if (preload[self.getLastBufferDateStr(currentDate, startDate, endDate)]) {
+ self.play(self.state.playIndex);
+ return;
+ }
+ if (self.state.supportingCustomLayers &&
+ preload[self.state.playIndex] &&
+ _.isEmpty(inQueue)) {
+ self.play(self.state.playIndex);
+ return;
+ }
+ self.shiftCache();
+ };
+
+ /*
+ * removes loader and starts the
+ * animation
+ *
+ * @method play
+ * @static
+ *
+ * @param index {string} date string
+ *
+ * @returns {void}
+ *
+ */
+ self.play = function(index) {
+ self.state.playing = true;
+ wv.ui.indicator.hide(loader);
+ wv.ui.indicator._hide(loader);
+ self.animate(index);
+ return;
+ };
+
+ /*
+ * Gets date to start on when animation
+ * is being looped
+ *
+ * @method setNewDate
+ * @static
+ *
+ * @param date {number} JS Date
+ * @param newDate {number} JS Date
+ *
+ * @returns {void}
+ *
+ */
+ self.setNewDate = function(date, newDate) {
+ return newDate;
+ };
+
+ /*
+ * function that loops through frames
+ * at a specified time interval
+ *
+ * @method animate
+ * @static
+ *
+ * @param index {string} Date string
+ * @returns {void}
+ *
+ */
+ self.animate = function(index) {
+ var interval;
+ var playIndex = index;
+ var playIndexJSDate;
+ var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);
+ var player = function() {
+ self.shiftCache();
+ self.checkQueue(queueLength, playIndex);
+
+ dateModel.select(wv.util.parseDateUTC(playIndex));
+ pastDates[playIndex] = wv.util.parseDateUTC(playIndex); // played record
+ self.state.playIndex = playIndex;
+ playIndex = wv.util.toISOStringDate(self.nextDate(new Date(playIndex)));
+ playIndexJSDate = new Date(playIndex);
+ if (playIndexJSDate > endDate) {
+ clearInterval(interval);
+ self.state.playing = false;
+ self.checkShouldLoop(playIndexJSDate);
+ return;
+ }
+ if (!animModel.rangeState.playing || !preload[playIndex]) {
+ clearInterval(interval);
+ self.state.playing = false;
+ if (!preload[playIndex] && animModel.rangeState.playing) { // Still playing, add loader
+ loader = wv.ui.indicator.loading();
+ self.shiftCache();
+ self.checkQueue(queueLength, self.state.playIndex);
+ } else {
+ self.refreshState();
+ }
+ return;
+ }
+
+ self.checkQueue(queueLength, self.state.playIndex);
+ interval = setTimeout(player, 1000 / animModel.rangeState.speed);
+ };
+ interval = setTimeout(player, animModel.rangeState.speed);
+ };
+ self.init();
+ return self;
+ };
diff --git a/web/js/animation/wv.anim.widget.js b/web/js/animation/wv.anim.widget.js
index 8c9514cf5..62cfbb84f 100644
--- a/web/js/animation/wv.anim.widget.js
+++ b/web/js/animation/wv.anim.widget.js
@@ -16,374 +16,378 @@ var wv = wv || {};
wv.anim = wv.anim || {};
wv.anim.widget = wv.anim.widget || function(models, config, ui) {
- var zooms = ['yearly', 'monthly', 'daily'];
- var self = {};
- var timeline = ui.timeline;
- var model = models.anim;
- var widgetFactory = React.createFactory(WVC.AnimationWidget);
- var $timelineFooter;
- var $animateButton;
- var dataModel;
- /*
- * set listeners and initiate
- * widget
- *
- * @method init
- * @static
- *
- * @returns {void}
- *
- */
- self.init = function() {
- var speed;
- var Widget;
+ var zooms = ['yearly', 'monthly', 'daily'];
+ var self = {};
+ var timeline = ui.timeline;
+ var model = models.anim;
+ var widgetFactory = React.createFactory(WVC.AnimationWidget);
+ var $timelineFooter;
+ var $animateButton;
+ var dataModel;
+ /*
+ * set listeners and initiate
+ * widget
+ *
+ * @method init
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.init = function() {
+ var speed;
+ var Widget;
- Widget = self.initWidget();
- //mount react component
- $animateButton = $('#animate-button');
- self.reactComponent = ReactDOM.render(Widget, $('#wv-animation-widet-case')[0]);
+ Widget = self.initWidget();
+ //mount react component
+ $animateButton = $('#animate-button');
+ self.reactComponent = ReactDOM.render(Widget, $('#wv-animation-widet-case')[0]);
- $timelineFooter = $('#timeline-footer');
- $animateButton.on('click', function() {
- WVC.GA.event('Animation', 'Click', 'Animation Icon');
- self.toggleAnimationWidget();
- });
- if(model.rangeState.state === 'on') { // show animation widget if active in permalink
- $timelineFooter.toggleClass('wv-anim-active');
+ $timelineFooter = $('#timeline-footer');
+ $animateButton.on('click', function() {
+ WVC.GA.event('Animation', 'Click', 'Animation Icon');
+ self.toggleAnimationWidget();
+ });
+ if (model.rangeState.state === 'on') { // show animation widget if active in permalink
+ $timelineFooter.toggleClass('wv-anim-active');
+ }
+ $('.wv-date-selector-widget input')
+ .on('keydown', function(e) {
+ // A bit of a hack
+ e.stopPropagation(); // needed to correct event bubbling between react and Document
+ });
+ model.events.trigger('change');
+ model.events.on('change', self.update);
+ models.date.events.on('timeline-change', self.update);
+ if (models.data) {
+ dataModel = models.data;
+ dataModel.events.on('activate', function() {
+ self.toggleAnimationWidget();
+ self.onDataActivate();
+ });
+ dataModel.events.on('deactivate', function() {
+ self.onDataDeactivate();
+ });
+ } else {
+ dataModel = {};
+ dataModel.active = false;
+ }
+
+ //hack for react bug https://github.com/facebook/react/issues/1920
+ $('.wv-date-selector-widget input')
+ .keydown(function(e) {
+ if (e.keyCode == 13 || e.keyCode == 9) {
+ e.preventDefault();
}
- $('.wv-date-selector-widget input').on('keydown', function(e){
- // A bit of a hack
- e.stopPropagation(); // needed to correct event bubbling between react and Document
- });
- model.events.trigger('change');
- model.events.on('change', self.update);
- models.date.events.on('timeline-change', self.update);
- if(models.data) {
- dataModel = models.data;
- dataModel.events.on('activate', function() {
- self.toggleAnimationWidget();
- self.onDataActivate();
- });
- dataModel.events.on('deactivate', function() {
- self.onDataDeactivate();
- });
- } else {
- dataModel = {};
- dataModel.active = false;
+ });
+ // Space bar event listener
+ $(window)
+ .keypress(function(e) {
+ if ((e.keyCode == 32 ||
+ e.charCode == 32) && // space click
+ !$("#layer-modal")
+ .dialog("isOpen")) { //layer selector is not open
+ e.preventDefault();
+ self.onSpaceBar();
}
+ });
+ };
- //hack for react bug https://github.com/facebook/react/issues/1920
- $('.wv-date-selector-widget input').keydown(function(e) {
- if(e.keyCode == 13 || e.keyCode == 9) {
- e.preventDefault();
- }
- });
- // Space bar event listener
- $(window).keypress(function(e) {
- if ((e.keyCode == 32 ||
- e.charCode == 32 ) && // space click
- !$( "#layer-modal" ).dialog( "isOpen" )) {//layer selector is not open
- e.preventDefault();
- self.onSpaceBar();
- }
- });
- };
-
- /*
- * Widget initializer
- * passes initial props
- *
- * @method initWidget
- * @static
- *
- * @returns {void}
- *
- */
- self.initWidget = function() {
- var rangeState = model.rangeState;
- return widgetFactory({
- onPushPlay: self.onPressPlay,
- onPushLoop: self.onPressLoop,
- onPushPause: self.onPressPause,
- onPushGIF: self.onPressGIF,
- looping: model.rangeState.loop,
- increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3
- incrementArray: _.without(zooms, self.getIncrements()), // array of zooms without current zoom
- onDateChange: self.dateUpdate,
- sliderLabel: 'Frames Per Second',
- sliderSpeed: rangeState.speed,
- onZoomSelect: self.onZoomSelect,
- onSlide: self.onRateChange,
- startDate: new Date(rangeState.startDate),
- endDate: new Date(rangeState.endDate),
- minDate: models.date.minDate(),
- maxDate: models.date.maxDate(),
- onClose: self.toggleAnimationWidget
- });
- };
- /*
- * Determines whether to play
- * animation or pause animation
- *
- * @method onSpaceBar
- * @static
- *
- * @returns {void}
- *
- */
- self.onSpaceBar = function() {
- if(model.rangeState.state === 'on') {
- if(model.rangeState.playing) {
- self.onPressPause();
- return;
- }
- self.onPressPlay();
- self.update();
- return;
- }
- };
+ /*
+ * Widget initializer
+ * passes initial props
+ *
+ * @method initWidget
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.initWidget = function() {
+ var rangeState = model.rangeState;
+ return widgetFactory({
+ onPushPlay: self.onPressPlay,
+ onPushLoop: self.onPressLoop,
+ onPushPause: self.onPressPause,
+ onPushGIF: self.onPressGIF,
+ looping: model.rangeState.loop,
+ increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3
+ incrementArray: _.without(zooms, self.getIncrements()), // array of zooms without current zoom
+ onDateChange: self.dateUpdate,
+ sliderLabel: 'Frames Per Second',
+ sliderSpeed: rangeState.speed,
+ onZoomSelect: self.onZoomSelect,
+ onSlide: self.onRateChange,
+ startDate: new Date(rangeState.startDate),
+ endDate: new Date(rangeState.endDate),
+ minDate: models.date.minDate(),
+ maxDate: models.date.maxDate(),
+ onClose: self.toggleAnimationWidget
+ });
+ };
+ /*
+ * Determines whether to play
+ * animation or pause animation
+ *
+ * @method onSpaceBar
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onSpaceBar = function() {
+ if (model.rangeState.state === 'on') {
+ if (model.rangeState.playing) {
+ self.onPressPause();
+ return;
+ }
+ self.onPressPlay();
+ self.update();
+ return;
+ }
+ };
- /*
- * Updates the state of the
- * widget react component
- *
- * @method update
- * @static
- *
- * @returns {void}
- *
- */
- self.update = function() {
- var state = model.rangeState;
- self.reactComponent.setState({
- startDate: new Date(state.startDate),
- endDate: new Date(state.endDate),
- playing: state.playing,
- increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3
- incrementArray: _.without(zooms, self.getIncrements()) // array of zooms without current zoom
- });
- };
+ /*
+ * Updates the state of the
+ * widget react component
+ *
+ * @method update
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.update = function() {
+ var state = model.rangeState;
+ self.reactComponent.setState({
+ startDate: new Date(state.startDate),
+ endDate: new Date(state.endDate),
+ playing: state.playing,
+ increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3
+ incrementArray: _.without(zooms, self.getIncrements()) // array of zooms without current zoom
+ });
+ };
- /*
- * Gets zoom increment
- *
- * @method getIncrements
- * @static
- *
- * @returns {string} timeline interval
- *
- */
- self.getIncrements = function() {
- return zooms[timeline.config.currentZoom - 1];
- };
+ /*
+ * Gets zoom increment
+ *
+ * @method getIncrements
+ * @static
+ *
+ * @returns {string} timeline interval
+ *
+ */
+ self.getIncrements = function() {
+ return zooms[timeline.config.currentZoom - 1];
+ };
- /*
- * A handler that responds to
- * a zoom change and triggers
- * the proper change
- *
- * @method onZoomSelect
- * @static
- *
- * @param increment {number} Timeline zoom
- * level number
- *
- * @returns {string} timeline interval
- *
- */
- self.onZoomSelect = function(increment) {
- var zoomLevel = _.indexOf(zooms, increment);
- return timeline.config.zoom(zoomLevel + 1);
- };
+ /*
+ * A handler that responds to
+ * a zoom change and triggers
+ * the proper change
+ *
+ * @method onZoomSelect
+ * @static
+ *
+ * @param increment {number} Timeline zoom
+ * level number
+ *
+ * @returns {string} timeline interval
+ *
+ */
+ self.onZoomSelect = function(increment) {
+ var zoomLevel = _.indexOf(zooms, increment);
+ return timeline.config.zoom(zoomLevel + 1);
+ };
- /*
- * Updates the state and triggers
- * change events.
- *
- * @method dateUpdate
- * @static
- *
- * @param startDate {obj} Start Date
- *
- * @param endDate {obj} End Date
- *
- * @returns {void}
- *
- */
- self.dateUpdate = function(startDate, endDate) {
- model.rangeState.startDate = wv.util.toISOStringDate(startDate) || 0;
- model.rangeState.endDate = wv.util.toISOStringDate(endDate);
- model.rangeState.playing = false;
- model.events.trigger('change');
- model.events.trigger('datechange');
- };
+ /*
+ * Updates the state and triggers
+ * change events.
+ *
+ * @method dateUpdate
+ * @static
+ *
+ * @param startDate {obj} Start Date
+ *
+ * @param endDate {obj} End Date
+ *
+ * @returns {void}
+ *
+ */
+ self.dateUpdate = function(startDate, endDate) {
+ model.rangeState.startDate = wv.util.toISOStringDate(startDate) || 0;
+ model.rangeState.endDate = wv.util.toISOStringDate(endDate);
+ model.rangeState.playing = false;
+ model.events.trigger('change');
+ model.events.trigger('datechange');
+ };
- /*
- * Toggles the visibility of the
- * widget
- *
- * @method toggleAnimationWidget
- * @static
- *
- * @returns {void}
- *
- */
- self.toggleAnimationWidget = function() {
- // If timeline is hidden, pressing
- // the anim icon will open the
- // timeline and the anim widget
- if(model.rangeState.state === null) { // widget hasn't been clicked before
- model.rangeState.state = 'off';
- self.makeDateGuess();
- }
- if($timelineFooter.is(":hidden") && !dataModel.active) {
- ui.timeline.toggle(); //toggle
- if(model.rangeState.state === 'on') { // activate anim if not already
- return;
- }
- setTimeout(function() {
- model.events.trigger('change');
- model.events.trigger('toggle-widget');
- }, 500);
- }
- if(model.rangeState.state === 'off' && dataModel.active) {
- return; // Keep animation off when data-download is active.
- }
- model.toggleActive(); // sets anim state to on or off
+ /*
+ * Toggles the visibility of the
+ * widget
+ *
+ * @method toggleAnimationWidget
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.toggleAnimationWidget = function() {
+ // If timeline is hidden, pressing
+ // the anim icon will open the
+ // timeline and the anim widget
+ if (model.rangeState.state === null) { // widget hasn't been clicked before
+ model.rangeState.state = 'off';
+ self.makeDateGuess();
+ }
+ if ($timelineFooter.is(":hidden") && !dataModel.active) {
+ ui.timeline.toggle(); //toggle
+ if (model.rangeState.state === 'on') { // activate anim if not already
+ return;
+ }
+ setTimeout(function() {
model.events.trigger('change');
model.events.trigger('toggle-widget');
+ }, 500);
+ }
+ if (model.rangeState.state === 'off' && dataModel.active) {
+ return; // Keep animation off when data-download is active.
+ }
+ model.toggleActive(); // sets anim state to on or off
+ model.events.trigger('change');
+ model.events.trigger('toggle-widget');
- return $timelineFooter.toggleClass('wv-anim-active');
- };
+ return $timelineFooter.toggleClass('wv-anim-active');
+ };
- self.makeDateGuess = function() {
- var start;
- var end;
- var currentDate = new Date(models.date.selected);
- var interval = ui.anim.ui.getInterval();
- var day = wv.util.dateAdd(currentDate, interval, 7);
- var today = new Date();
+ self.makeDateGuess = function() {
+ var start;
+ var end;
+ var currentDate = new Date(models.date.selected);
+ var interval = ui.anim.ui.getInterval();
+ var day = wv.util.dateAdd(currentDate, interval, 7);
+ var today = new Date();
- if(day > today) {
- model.rangeState.endDate = wv.util.toISOStringDate(currentDate);
- model.rangeState.startDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, -7));
- } else {
- model.rangeState.startDate = wv.util.toISOStringDate(currentDate);
- model.rangeState.endDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, 7));
- }
- };
- /*
- * Press play button event handler
- *
- * @method onPressPlay
- * @static
- *
- * @returns {void}
- *
- */
- self.onPressPlay = function() {
- model.rangeState.playing = true;
- model.events.trigger('play');
- };
+ if (day > today) {
+ model.rangeState.endDate = wv.util.toISOStringDate(currentDate);
+ model.rangeState.startDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, -7));
+ } else {
+ model.rangeState.startDate = wv.util.toISOStringDate(currentDate);
+ model.rangeState.endDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, 7));
+ }
+ };
+ /*
+ * Press play button event handler
+ *
+ * @method onPressPlay
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onPressPlay = function() {
+ model.rangeState.playing = true;
+ model.events.trigger('play');
+ };
- /*
- * Play button event handler
- *
- * @method onPressPlay
- *
- * @param speed {number} speed in frames
- * per second
- *
- * @static
- *
- * @returns {void}
- *
- */
- self.onRateChange = function(speed) {
- model.rangeState.speed = speed;
- model.events.trigger('change');
- };
+ /*
+ * Play button event handler
+ *
+ * @method onPressPlay
+ *
+ * @param speed {number} speed in frames
+ * per second
+ *
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onRateChange = function(speed) {
+ model.rangeState.speed = speed;
+ model.events.trigger('change');
+ };
- /*
- * Pause button event handler
- *
- * @method onPressPause
- *
- * @static
- *
- * @returns {void}
- *
- */
- self.onPressPause = function() {
- var state = model.rangeState;
- state.playing = false;
- model.events.trigger('change');
- };
+ /*
+ * Pause button event handler
+ *
+ * @method onPressPause
+ *
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onPressPause = function() {
+ var state = model.rangeState;
+ state.playing = false;
+ model.events.trigger('change');
+ };
- /*
- * Deactivate widget when data download
- * is active
- *
- * @method onDataActivate
- *
- * @static
- *
- * @returns {void}
- *
- */
- self.onDataActivate = function() {
- $animateButton.addClass('wv-disabled-button');
- $animateButton.prop('title', 'Animation feature is deactivated when data download feature is active');
- };
+ /*
+ * Deactivate widget when data download
+ * is active
+ *
+ * @method onDataActivate
+ *
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onDataActivate = function() {
+ $animateButton.addClass('wv-disabled-button');
+ $animateButton.prop('title', 'Animation feature is deactivated when data download feature is active');
+ };
- /*
- * reActivate widget when data download
- * is deactivated
- *
- * @method onDataDeactivate
- *
- * @static
- *
- * @returns {void}
- *
- */
- self.onDataDeactivate = function() {
- $animateButton.removeClass('wv-disabled-button');
- $animateButton.prop('title', 'Setup animation');
- };
+ /*
+ * reActivate widget when data download
+ * is deactivated
+ *
+ * @method onDataDeactivate
+ *
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onDataDeactivate = function() {
+ $animateButton.removeClass('wv-disabled-button');
+ $animateButton.prop('title', 'Setup animation');
+ };
- /*
- * Adjusts state when loop is triggered
- *
- * @method onPressLoop
- *
- * @static
- *
- * @param loop {boolean}
- *
- * @returns {void}
- *
- */
- self.onPressLoop = function(loop) {
- var state = model.rangeState;
- state.loop = loop;
- model.events.trigger('change');
- };
+ /*
+ * Adjusts state when loop is triggered
+ *
+ * @method onPressLoop
+ *
+ * @static
+ *
+ * @param loop {boolean}
+ *
+ * @returns {void}
+ *
+ */
+ self.onPressLoop = function(loop) {
+ var state = model.rangeState;
+ state.loop = loop;
+ model.events.trigger('change');
+ };
- /*
- * Gif icon event handler: Triggers
- * gif area selection
- *
- * @method onPressGIF
- *
- * @static
- *
- * @returns {void}
- *
- */
- self.onPressGIF = function() {
- model.events.trigger('gif-click');
- };
- self.init();
- return self;
-};
\ No newline at end of file
+ /*
+ * Gif icon event handler: Triggers
+ * gif area selection
+ *
+ * @method onPressGIF
+ *
+ * @static
+ *
+ * @returns {void}
+ *
+ */
+ self.onPressGIF = function() {
+ model.events.trigger('gif-click');
+ };
+ self.init();
+ return self;
+};