question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fire onshow event on all modals

See original GitHub issue

Hello!

I have 30 modals on a page (each one is completelly different) however when I initiallize each modal using $("#modal_id").modal(( "setting", { closable:false;...})) on page load, the “mouse hangs” for as long as 500 to 1000ms. Also, using Google PageSpeed Insights, when I remove the initiallization of modals on pageload it gets saved 12 points on the final score, so clearly initiallizing that much modals impacts user experience.

So I ask you: is it possible to attach some kind of event to ONLY initiate the modals when the .modal("show") is called for the first time on each modal?

Cause I have hundreds of .modal("show") calls all over the place on my pages. Wheter a user clicks on a button, on a link, hover a image, scrolls past at certain point on a page… Those .modal("show") calls are all over the place and it would too tedious/labour intensive to change every single .modal("show") to something like

if (typeof initiated_modal_23 === "undefined") {
    
    initiated_modal_23  = true;
    $("#modal_id").modal(( "setting", { closable:false;...}));

}

$("#modal_id").modal("show");

For some reasom initializing modals with many content inside affects heavily page load. So it would be nice to know if there is some way to solve this problem.

OBS: I could defer the initialization of modals after 3 seconds (for example) from page load but if any .modal("show") gets executed before the initialization problems will happen, as you expect.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lubber-decommented, Feb 1, 2019

@batata004 You could change the global settings after showing the first modal. Ugly, but works

http://jsfiddle.net/hnx3r4wu/

1reaction
ColinFrickcommented, Feb 1, 2019

@batata004 this works for me: https://jsfiddle.net/5ewq4tdy/ What’s important is that you have to set the onShow before any modal is initialized.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bootstrap jquery show.bs.modal event won't fire - Stack Overflow
i'm using the modal example from the bootstrap 3 docs. the modal works. however i need to access the show.bs.modal event when it...
Read more >
Bootstrap show.bs.modal Event - Tutorialspoint
The show.bs.modal event in Bootstrap fires when the modal is about to be displayed. Here the alert is set using the same event...
Read more >
trigger a bootstrap modal show event - jQuery Forum
show.bs.modal is an event that the Bootstrap modal code itself triggers when the show function is called.
Read more >
Ability to add listeners directly to objects like Modals/Collapse ...
How about a public method to add listener(s) to an object, something like: class Modal { //... on(event, callback) { this._element.
Read more >
JavaScript · Bootstrap
All modal events are fired at the modal itself (i.e. at the <div class="modal"> ). Event Type, Description. show.bs.modal, This event fires immediately...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found