Skip to content

Instantly share code, notes, and snippets.

@paceaux
Created December 30, 2014 21:49
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 paceaux/c07df26d2950e7ac683a to your computer and use it in GitHub Desktop.
Save paceaux/c07df26d2950e7ac683a to your computer and use it in GitHub Desktop.
String.prototype.replaceAt = function () {
var rlen = arguments[2] == null ? 1 : arguments[2];
return this.substring(0, arguments[0]) + arguments[1] + this.substring(arguments[0] + rlen);
};
var currentItem = SDL.Client.UI.ApplicationHost.ViewModels.Navigation.currentNavigationItem();
var navHappy = {
init: function () {
this.newSrc = this.getNewSrc();
},
getCurrentItem: function () {
return SDL.Client.UI.ApplicationHost.ViewModels.Navigation.currentNavigationItem();
},
getCurrentSrc: function () {
var currentItem = this.getCurrentItem();
return currentItem.targetDisplay.src;
},
getCurrentTCM: function () {
var currentSrc = this.getCurrentSrc();
return currentSrc.slice(currentSrc.indexOf("tcm:")+4, currentSrc.length);
},
getCurrentPublicationNumber: function () {
var currentTCM = this.getCurrentTCM();
return currentTCM.slice(0, currentTCM.indexOf("-"));
},
getNewPublicationNumber: function () {
return parseInt(this.getCurrentPublicationNumber(), 10) -1;
},
getNewTCM: function () {
var currentTCM = this.getCurrentTCM();
return currentTCM.replaceAt(0, this.getNewPublicationNumber());
},
getNewSrc: function () {
var currentSrc = this.getCurrentSrc(),
currentTCM = this.getCurrentTCM(),
newTCM = this.getNewTCM();
return currentSrc.replace(currentTCM, newTCM );
},
goToNewPublication: function () {
window.location = this.getNewSrc();
}
};
navHappy.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment