Enable / Disable Events
Track uploader state changes with onEnable and onDisable callbacks.
(function() {
var logEl = document.getElementById('log');
function log(m) { var d = document.createElement('div'); d.className='pkg-log-entry'; d.textContent=m; logEl.appendChild(d); logEl.scrollTop=logEl.scrollHeight; }
var uploader = new MultipleUpload('#demo', {
uploadUrl: '/api/upload',
multiple: true,
onEnable: function() { log('Uploader ENABLED'); },
onDisable: function() { log('Uploader DISABLED'); }
});
document.getElementById('toggle-btn').addEventListener('click', function() {
if (uploader.isEnabled()) uploader.disable();
else uploader.enable();
});
})();Reacting to the control being switched
onEnable and onDisable fire when enable() and disable() are called, and each receives the uploader. They exist so the rest of your interface can stay consistent with the uploader's state.
Keep the reason visible
The pair is most useful for updating whatever explains the state: a message saying the quota is reached, a hint that the form must be saved first. A control that is greyed out with no explanation is indistinguishable from one that is broken, and these callbacks are where that explanation gets kept in sync.