Skip to content

Rewritten modal without jquery#23955

Merged
Johann-S merged 2 commits intotwbs:v4-without-jqueryfrom
alekitto:v4-without-jquery
Sep 15, 2017
Merged

Rewritten modal without jquery#23955
Johann-S merged 2 commits intotwbs:v4-without-jqueryfrom
alekitto:v4-without-jquery

Conversation

@alekitto
Copy link
Copy Markdown
Contributor

To make it work correctly the following changes were required:

  • Trigger events in jQuery if available
  • Add util functions for manipulating data attributes and jQuery data object
  • Util.extend now supports multiple objects

Comment thread js/src/dom/eventHandler.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add a new regex here ? off method already work

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const does not work in IE10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use babel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The off implementation was not complete and i think i've messed up some things. Now working on a cleaner and more jQuery-like solution.

Comment thread js/src/dom/eventHandler.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you check for jQuery !== undefined it should be better with $ which come from your Util.jQuery getter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Fixed.

Comment thread js/src/dom/eventHandler.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you call stopImmediatePropagation here ? evt isn't dispatched

Comment thread js/src/util.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setDataAttribute and removeDataAttribute should be in our DOM Manipulator here : https://github.com/twbs/bootstrap/blob/v4-without-jquery/js/src/dom/manipulator.js

Comment thread js/src/modal.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a change here, our Modal continue to depend on jQuery

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've missed it. I've just changed it.

@Johann-S
Copy link
Copy Markdown
Member

You made a very good work here @alekitto but they are few changes here before I can merge your PR 👍

Comment thread js/src/util.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan here because EventHandler.getBrowserTransitionEnd() will be called each time Util.supportsTransitionEnd() is called

@Johann-S
Copy link
Copy Markdown
Member

I updated the base branch with v4-dev, so that's why they are other commits

@alekitto
Copy link
Copy Markdown
Contributor Author

Ok, i've rebased my branch with upstream. Now working on your comments..

Comment thread js/src/util.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you add a check if transition is set or not, you should revert this change it was better before that, because they aren't any check done each time we call this method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cyclic import (util -> eventHandler -> util) was causing me troubles yesterday, but now seems working correctly. Probably it was another error.

Comment thread js/tests/unit/modal.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want you can use EventHandler here

@Johann-S Johann-S mentioned this pull request Sep 15, 2017
45 tasks
@Johann-S
Copy link
Copy Markdown
Member

Oups last thing I forgot, can you update our visual modal test ? please

@alekitto alekitto force-pushed the v4-without-jquery branch 2 times, most recently from a9e2521 to 6c5846d Compare September 15, 2017 13:33
@alekitto
Copy link
Copy Markdown
Contributor Author

alekitto commented Sep 15, 2017

Ok, EventHandler off method has been rewritten to support namespaced events (click.namespace), native events without namespace (click removes click.namespace) and namespace only (.namespace removes click.namespace and keydown.namespace).

Visual modal test has been updated

@Johann-S
Copy link
Copy Markdown
Member

Johann-S commented Sep 15, 2017

I don't understand why you made that change on off because off already support namespaced events 🤔
What's the difference between what you've done and what we had ? and why you did that change ?

EDIT :
So if we want to call off on a namespaced event like that : click.bs.alert, is it working ?

Comment thread js/tests/unit/dom/eventHandler.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not our button plugin 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops

@alekitto
Copy link
Copy Markdown
Contributor Author

The off method did not remove events if event type like click.dismiss.bs.modal was passed. This would lead to events not removed in the hide method, especially from document and window nodes. Additionally, non namespaced events was removed only if an handler function was specified as third argument

@Johann-S
Copy link
Copy Markdown
Member

Ok thank you for the explanation 👍 and yep the second point wasn't implemented thank you

@alekitto
Copy link
Copy Markdown
Contributor Author

Yes, now EventHandler.off(element, 'click.bs.alert') is working as expected

Johann-S pushed a commit that referenced this pull request Nov 14, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 18, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 20, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 20, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 21, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 22, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Nov 25, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Nov 27, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Nov 28, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Nov 29, 2018
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Jan 4, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Jan 6, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Jan 7, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Jan 17, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Jan 17, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 7, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 7, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 8, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Johann-S pushed a commit that referenced this pull request Feb 11, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 12, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 13, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 15, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 19, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
XhmikosR pushed a commit that referenced this pull request Feb 20, 2019
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
@arcanedev-maroc
Copy link
Copy Markdown

arcanedev-maroc commented Jul 6, 2020

About Modal events, can i suggest a feature request ?

How about adding a public method to listen a modal event:

class Modal {
    //...

    on(event, callback) {
        this._element.addEventListener(`${event}${EVENT_KEY}`, callback);    
    }

    //...
}

So instead of:

let myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal._element.addEventListener('hidden.bs.modal', function (e) {
    // do something...
})

We can do something like this:

var myModal = new bootstrap.Modal(document.getElementById('myModal'));
myModal.on('hidden', function (e) {
    // do something...
});

I don't know if it's going to have a conflict with jquery but we can change the method name on into something else like listen('hidden', ...).

I can create a PR for this feature if it's OK 👍

@alekitto
Copy link
Copy Markdown
Contributor Author

alekitto commented Jul 8, 2020

My 2 cents: This could be an interesting feature, but I think that should be implemented for all the components.
For example:

const myCollapse = new bootstrap.Collapse(document.getElementById('test-collapse'));
myCollapse.on('shown', e => { ... });

could be equally good and useful.

@arcanedev-maroc probably you should open a new issue proposing a these changes to the event system of the components to better discuss pros and cons of this new design.

@arcanedev-maroc
Copy link
Copy Markdown

arcanedev-maroc commented Jul 9, 2020

@alekitto DONE 👍

Issue: #31266

mike-odom pushed a commit to mike-odom/bootstrap that referenced this pull request Dec 26, 2025
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
mike-odom pushed a commit to mike-odom/bootstrap that referenced this pull request Dec 26, 2025
* Trigger jquery events if available in event handler

* Rewritten modal without jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants