Skip to content

Instantly share code, notes, and snippets.

@paceaux paceaux/pubUp.js
Created Dec 30, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.