Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Created March 12, 2016 12:31
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 islaytitans/21a9c2e1bb9e5a2958af to your computer and use it in GitHub Desktop.
Save islaytitans/21a9c2e1bb9e5a2958af to your computer and use it in GitHub Desktop.
Script to move between the subtabs of a Sitecore Item Layout
define(["sitecore", "/-/speak/v1/experienceprofile/CintelUtl.js"], function (sc, cintelUtil) {
var selectedTabProperty = "selectedTab";
var textProperty = "text";
var app = sc.Definitions.App.extend({
initialized: function () {
this.processTabs();
},
loadPanel: function () {
var panelId = $("[data-sc-id='InteractionsTabControl'] > .tab-content > .active .sc-load-on-demand-panel").data("sc-id");
var panel = this[panelId];
if (panel && !panel.get("isLoaded")) {
panel.on("change:isLoaded", function () {
panel.set("isBusy", false);
});
panel.set("isBusy", true);
panel.load();
}
},
showDefaultTab: function () {
var firstTabId = this.InteractionsTabControl.get(selectedTabProperty);
var urlTabId = this.getTabIdFromUrl();
if (urlTabId && urlTabId != firstTabId) {
this.InteractionsTabControl.set(selectedTabProperty, urlTabId);
} else {
this.loadPanel();
}
},
processTabs: function () {
this.InteractionsTabControl.on("change:" + selectedTabProperty, function (tabControl, selectedTab) {
this.loadPanel();
}, this);
this.showDefaultTab();
},
getTabIdFromUrl: function () {
var tabName = cintelUtil.getQueryParam("subtab");
if (!tabName) return null;
var tabIdControlId = tabName[0].toUpperCase() + tabName.toLowerCase().substring(1) + "TabId";
var tabIdControl = this[tabIdControlId];
if (!tabIdControl) return null;
return tabIdControl.get(textProperty);
}
});
return app;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment