Last active
August 31, 2022 02:38
-
-
Save tmedwards/4199c6b542697f85730138a6ed4c76a8 to your computer and use it in GitHub Desktop.
Saves dialog w/ overwrite buttons
This file contains 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
(function () { | |
// Create a new localization string for overwrite buttons. | |
l10nStrings.savesLabelOverwrite = 'Overwrite'; | |
// Attempt to alter the Saves dialog. | |
$(document).on(':dialogopened', function (ev) { | |
// Cache the jQuery-wrapped dialog body element. | |
var $dialogBody = $(ev.target); | |
// Bail out if this is not the Saves dialog. | |
if (!$dialogBody.hasClass('saves')) { | |
return; | |
} | |
// Add slot overwrite buttons before slot load buttons. | |
$dialogBody.find('button.load').each(function () { | |
// Cache the jQuery-wrapped load button. | |
var $load = $(this); | |
// Get the slot index, which will be the keyword 'auto' for the | |
// autoslave or a numeric (1–maxSlots) for the slot saves. | |
var slot = $load.attr('id').split('-').last(); | |
// Bail out if this is the autosave. | |
if (slot === 'auto') { | |
return; | |
} | |
// Convert the numeric slot into an actual number. | |
slot = Number(slot); | |
// Cache whether saves are currently allowed. | |
var savesAllowed = typeof Config.saves.isAllowed !== 'function' || Config.saves.isAllowed(); | |
// Get the overwrite button text. | |
var text = L10n.get('savesLabelOverwrite'); | |
// Create the new save overwrite button. | |
var $save = $(document.createElement('button')) | |
.attr('id', 'saves-save-' + String(slot)) | |
.addClass('save ui-close') | |
.html(text) | |
.insertBefore($load); | |
if (savesAllowed) { | |
// Attach the save action and label to the button. | |
$save.ariaClick({ | |
label : text + ' ' + L10n.get('savesLabelSlot') + ' ' + String(slot + 1) | |
}, function () { | |
Save.slots.save(slot); | |
}); | |
} | |
else { | |
// Disable the button to indicate that saving is disallowed. | |
$save.ariaDisabled(true); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment