Created
December 30, 2014 21:49
-
-
Save paceaux/c07df26d2950e7ac683a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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