Had a little time to work this up today. Since KoL already includes jQuery, we can use that, though the version they use is quite old so we have to be careful about which functions we use. The following jQuery is tested working:
PHP:
var loaded = false;
jQuery(function($){
var which = parseInt($("input[name='whichchoice']").val());
if (!loaded && which && which > 0) jQuery.ajax({
url: 'choice.'+which+'.ash',
data: {whichchoice: which, page: $('body').html()},
dataType: 'html',
success: function(newcont) {
if (newcont) $('body').html(newcont);
loaded = true;
},
});
});
I ran across an issue which introduces a limitation to this functionality: some browsers will strip the html and body tags when replacing content (which makes perfect sense, really), so this script only sends/replaces everything in the body tag, not the entire page. However, I can't see this being a major issue. Even if you need to import additional scripts, that can be done in the body tag as well.
Below is what I put together to test it out. The choice number is for The Shore, Inc., since the choice there was free to test. If I were going to properly release this, I'd just write the JavaScript into the page rather than including a separate file, but it was easier to test this way.
EDIT: I guess the next decision is: does this belong in mafia or should it just be released as a script? I'm happy with either and will spin it into a proper release if so desired. The benefit of including it in mafia is that users could still use their own choice.ash override if they like without losing the functionality this provides.
EDIT: Another nifty feature we could add to this is break out the shopkeepers, so you could have things like
choice.The Dinsey Company Store.ash and so forth.
NOTE: choice.ash and choice.js removed because they are merged in the following post.