Skip to content
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

Make quirk detection optional #9

Closed
gjuggler opened this issue Aug 26, 2013 · 8 comments
Closed

Make quirk detection optional #9

gjuggler opened this issue Aug 26, 2013 · 8 comments
Assignees

Comments

@gjuggler
Copy link

I'm using jquery-simulate-ext in a content-script environment where the DOM is fragile and behavior changes unexpectedly when DIVs are inserted or removed.

I tracked down one of our problems to the DOM manipulation that the key-sequence plugin uses to detect a quirk (i.e., https://github.com/j-ulrich/jquery-simulate-ext/blob/master/src/jquery.simulate.key-sequence.js#L430). I'm removing these lines from my own fork, but if there were a way to optionally disable the quirk detection I would find that useful.

@ghost ghost assigned j-ulrich Aug 28, 2013
@j-ulrich
Copy link
Owner

I agree. However, I'm undecided how to realize this "disable-quirk-detection" switch. The quirk detection is done at the moment the DOM is ready (i.e. before the first call to .simulate()). Therefore, this switch cannot be a simple option of .simulate(). Another solution would be a data attribute on the body element. Something like this:

<body data-jquery-simulate-ext-opts='{"disable-quirk-detection": true}'>
<!-- ... -->
</body>

Would this be a reasonable solution for you, i.e. changing your body element as shown above?

@j-ulrich
Copy link
Owner

Alternatively, I could create a configuration function (disableQuirkDetection() or the like) which must be called after the simulate-ext files have been included but before the DOM is ready. E.g. like this:

<html>
<head>
<!-- ... -->
<script type="text/javascript" src="../libs/jquery.simulate.js"></script>
<script type="text/javascript" src="../src/jquery.simulate.ext.js"></script>
<script type="text/javascript" src="../src/jquery.simulate.drag-n-drop.js"></script>
<script type="text/javascript" src="../src/jquery.simulate.key-sequence.js"></script>
<script type="text/javascript" src="../src/jquery.simulate.key-combo.js"></script>
<script type="text/javascript">
    $.simulate.prototype.disableQuirkDetection();
</script>
<!-- ... -->
<body>
<!-- ... -->
</body>
</html>

The drawback of this solution is that is not possible to disable the quirk detection when the simulate-ext files are included dynamically because the quirk detection would be executed immediately after the scripts are attached to the DOM.

@gjuggler
Copy link
Author

Cool, thanks for thinking seriously about this.

How about detecting a flag on the window object? I'd imagined doing something like this to turn off the detection:

window.JQ_SIM_EXT_DISABLE_QUIRK_DETECTION = true;

It's not the most aesthetic kind of flag, but that would let someone disable the quirk detection at any point before it's run.

By the way, I really enjoyed using the simulate-ext plugin. It was easy to set up and immediately helped us with a tricky keystroke simulation problem we had encountered. Many thanks for that.

@j-ulrich
Copy link
Owner

j-ulrich commented Sep 1, 2013

I don't like to pollute the window or jQuery object but setting a flag seems the best way. Therefore, I think I'll use a variable in the jQuery simulate object. This requires that the flag is set after jQuery simulate is loaded or the flag will be overridden. However, I think that's a reasonable restriction even if the scripts are loaded dynamically (the flag could be set in a callback or the like):

<!-- ... -->
<script type="text/javascript" src="../libs/jquery.simulate.js"></script>
<script type="text/javascript">$.simulate.ext_disableQuirkDetection = true;</script>
<script type="text/javascript" src="../src/jquery.simulate.ext.js"></script>
<!-- ... -->

PS: I'm glad to hear you like the plugin. :-)

@gjuggler
Copy link
Author

gjuggler commented Sep 2, 2013

That looks good. Thanks for being responsive on this. I know it's a small thing, but somehow the quirk detection was making our application implode unless it was turned off, so I'm happy to see the option there.

@j-ulrich
Copy link
Owner

j-ulrich commented Sep 3, 2013

Note that the plugin might not work as expected if the quirk detection is disabled. Therefore, I added the possibility
to manually enable or disable specific quirk fixes by setting the corresponding flag in the jQuery.simulate.prototype.quirks object. For example:

<!-- ... -->
<script type="text/javascript" src="../libs/jquery.simulate.js"></script>
<script type="text/javascript">$.simulate.ext_disableQuirkDetection = true;</script>
<script type="text/javascript" src="../src/jquery.simulate.ext.js"></script>
<script type="text/javascript" src="../src/jquery.simulate.key-sequence.js"></script>
<script type="text/javascript">$.simulate.prototype.quirks.delayedSpacesInNonInputGlitchToEnd = true;</script>
<!-- ... -->

For more information on the quirks and their fixes, see the inline documentation in the source code.

@ghost
Copy link

ghost commented Jul 6, 2016

ctrl+v or control+v doesn't work :(

@j-ulrich
Copy link
Owner

j-ulrich commented Jul 8, 2016

See #30

Repository owner locked and limited conversation to collaborators Jul 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants