I am trying to set the value keyboard=true for all modals within a page. Is there a way to configure that to be set as default or do I need to go to each modal and set it?
I know the case is closed and you've rendered your verdict, but I wanna testify:
The accepted answer sets the keyboard option for all the modals that currently exist by going through them one by one<sup>†</sup>. You can extend objects that have not yet been created, and do so while taking less of a performance hit by just setting the default option:
<!-- language: lang-js -->$.fn.modal.Constructor.DEFAULTS.keyboard = true;
Demo in Fiddle
<sup>†</sup> - Here is a direct quote from the documentation:
<!-- language: lang-js -->$('#myModal').modal({ keyboard: false }) // initialized with no keyboard
This code initializes each modal in the selector $('#myModal')
and also sets one of the options when doing so.
Here's a demo with two modals - they both will be initialized immediately! It goes through each one, initializes it, and applies the setting. The question was not asking for a way to initialize the modals that use a setting. It was asking for a way to default the settings so future initializations wouldn't have to specify it. In terms of performance, just doing the the lookup in the DOM for $('.modal')
costs extra that overriding the default does not.