Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Created January 4, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doublejosh/eca9a9165bbbe6e5e20dac08b0d68322 to your computer and use it in GitHub Desktop.
Save doublejosh/eca9a9165bbbe6e5e20dac08b0d68322 to your computer and use it in GitHub Desktop.
Manage past use of datasources via param
/**
* Discover pane (web parts > 9.0).
*
* @namespace Tabia.DiscoverPane
*/
var Tabia = window.Tabia || {};
(function ($, _, Tabia, groucho, module) {
/**
* Data source connection awareness.
*
* @todo More content updates for data source use.
*/
module.dataSources = function () {
var connections = groucho.userGet('connected') || [];
// Listen for URL changes indicating new connections.
$(window).bind('hashchange', function freshHash () {
var hashVal = window.location.hash.replace('#', ''),
dataSource;
// Confirm this is a datasource hash.
if (hashVal.match(/^connected-(\w|-)+$/g) !== null) {
// Discover datasource and log it.
dataSource = hashVal.replace('connected-', '');
connections.push(dataSource);
groucho.userSet({connected: connections});
Tabia.debug('Datasource connected', {type: 'discoverPane', data: {
dataSource: dataSource, query: window.location.search
}});
module.checkTableauSource();
}
});
// Check once.
module.checkTableauSource();
};
/**
* Data-source-types from past events.
*
* @todo Try slideToggle() for more control.
*/
module.checkTableauSource = function () {
var tableauPrefix = new RegExp(/^tableau-(\w|-)+$/g),
connections = groucho.userGet('connected') || [];
// Confirm if any connections.
if (_.isArray(connections) && connections.length > 0) {
// Find Tableau data source use.
_.some(connections, function checkPrefix (dataSourceName) {
// Check for "tableau-something" datasources to show sharing content.
if (dataSourceName.match(tableauPrefix) !== null) {
// Reveal and normalize style/CSS.
$('.sharing').slideDown().removeClass('hidden').attr('style', '');
}
});
}
};
})(jQuery, _, Tabia, groucho, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment