-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bye bye simulate #2704
Bye bye simulate #2704
Conversation
e200c19
to
93f8cd8
Compare
👍 Looks good, will review in the morning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I'm really pro the removal of the extra event dependency, so that's great, thanks! Just see my notes below.
Chosen.trigger(@form_field, 'input') | ||
Chosen.trigger(@form_field, 'change') | ||
|
||
@trigger: (element, eventType) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having trigger
as public method shouldn't be necessary. But this probably has been done so the method is available in the tests as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Should I call it _trigger
instead?
Chosen.trigger(@form_field, 'change') | ||
|
||
@trigger: (element, eventType) -> | ||
if (document.createEventObject) # Old IE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
statements should be written without parens (I know, there are some conditions that do use parens, but they just slipped through the cracks I guess)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem
expect(container.hasClassName("chosen-container-active")).toBe true | ||
|
||
#select an item | ||
container.select(".active-result").last().simulate("mouseup") | ||
Chosen.trigger(container.select(".active-result").last(), 'mouseup'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicky, but inconsistent quote usage. On multiple locations, but marking them all feels too extreme.
And yes I know it's hypocritical, because we use single and double quotes randomly around the library, but I still strive for some consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 should not have switched them
@@ -27,11 +27,11 @@ describe "Basic setup", -> | |||
expect($F(select)).toBe "" | |||
|
|||
container = div.down(".chosen-container") | |||
container.simulate("mousedown") # open the drop | |||
Chosen.trigger(container, "mousedown") # open the drop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a good idea, because Chosen.trigger
is not a full-fledged implementation of triggering builtin events (it always relies on the Event class, while many DOM events are using subclasses with extra properties)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what is a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, as Chosen does not need a full-fledged event triggering system (as it does not need to trigger mouse events), the simpler would probably be to keep using an external library for that in the testsuite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I arrived at the same conclusion 😄
@trigger: (element, eventType) -> | ||
if (document.createEventObject) # Old IE: | ||
element.fireEvent("on#{eventType}", document.createEventObject()); | ||
else # Modern way: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should detect support for the modern way instead (detecting dispatchEvent
), to use the modern way when multiple ways are available. fireEvent
should be a fallback only.
Btw, you should also write the code using createEvent()
and initEvent
when dispatchEvent
is available but not the Event constructor (i.e. the intermediate API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
a308b1c
to
1f300d5
Compare
Tweaked as per comments, and reorganized the commits to make more sense. |
a6b7f46
to
51bf72b
Compare
Ok, hopefully third time's the charm. No more |
51bf72b
to
45d6883
Compare
evt.initEvent(eventType, true, true); | ||
element.dispatchEvent(evt) | ||
else | ||
document.createEventObject # Old IE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Fixed
@@ -229,7 +229,7 @@ | |||
<td>change</td> | |||
<td> | |||
<p>Chosen triggers the standard DOM event whenever a selection is made (it also sends a <code class="language-javascript">selected</code> or <code class="language-javascript">deselected</code> parameter that tells you which option was changed).</p> | |||
<p><strong>Note:</strong> in order to use change in the Prototype version, you have to include the <a href="https://github.com/kangax/protolicious/blob/5b56fdafcd7d7662c9d648534225039b2e78e371/event.simulate.js">Event.simulate</a> class. The selected and deselected parameters are not available for Prototype.</p> | |||
<p>The selected and deselected parameters are not available for Prototype.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<strong>Note:</strong>
should be kept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
45d6883
to
80a5d63
Compare
@stof anything else? |
Thanks again, @marcandre 💯 |
👍 I'm pretty impressed by the committer team! |
Is it possible to make a release with this? |
I'm collecting as much small bugfixes as possible for a new release, but I expect to release 1.7.0 somewhere next week. |
I would still very much appreciate a release... |
@marcandre I understand, and it has been more than a week now, but there are still quite some PR's that I'd like to see merged for the 1.7.0 release. |
@marcandre took some time, but as there was no progress since a few months I decided to put out a release. So 1.7.0 is now available. |
Thanks @koenpunt |
This PR removes the dependency on
simulate
, which is old, unmaintained and incomplete.Replacing costs about 5 lines of code...
It also adds the
input
event to the prototype version.Builds on #2697