I have encountered a minor yet annoying bug in ctools modal.
When the modal window is visible browser keyboard shortcuts only work if an input element inside the modal window is in focus.
The reason is that keypress/keydown events gets targeted at the body element when no other element is in focus, but the modal event handler filters out any event that doesn't have a target inside the modal content div.
I have attached a patch as an attempt to solve this. In the patch i have tried to check if the target is body or the modal content div itself, and allow those events.
If the target is neither body, modal content div or inside the modal content div, the focus is moved to the modal content div. (using jquery's .focus() which seems to work better).
I'm hoping some of you, who are more experienced with ctools modal and the javascript event system will take a look at this, see if it's useful, or if more work is needed.
Comment | File | Size | Author |
---|
Comments
Comment #1
prinds CreditAttribution: prinds commentedmaybe a change of status will create some response..
Comment #3
prinds CreditAttribution: prinds commentedha.. wonderful, an automated response.. looks like i need to learn a thing or two about patches..
Comment #4
prinds CreditAttribution: prinds commentedtrying again..
Comment #5
jerrylow CreditAttribution: jerrylow commentedSeems like the new updates to Chrome made this a none issue but even with the new Safari the issue still persists. I've updated the patch in terms of the lines where it applies.
Comment #6
joelpittetThanks for pointing me at this patch and fixing it so I can use cmd+f to find things in modal windows (panels add content specifically)!
$.size() is deprecated as of jquery 1.8 so might as well change that to length() here maybe?
@see http://api.jquery.com/size/
And there is some minor but odd coding standards spacing before and after the opening if parenthesis and need a space between
#modalContent,body
I think these lines helped fix the problem thanks:)
Comment #7
jerrylow CreditAttribution: jerrylow commented@joelpittet - Good catches. There're more .size and a few more deprecated functions in there. I'll do some testing with some of the functions with 1.5 and 1.7+ and do another update/issue.
Comment #8
joelpittetYeah those other size() calls should be another issue separate from this, just thought in context this should be fixed so thanks for that. It could be a follow-up issue to this one.
Thanks @jerrylow, attached is some very minor whitespace and coding standards changes to #7
Comment #9
japerryThanks Joel, looks good. Committed.
Comment #12
jlafu CreditAttribution: jlafu commentedHi, I'm re-opening this issue after finding an error when updating my site to ctools 7.x-1.6 (debugging that error led to this issue).
I have:
When I add/edit a translation of this content type, and from within that translation I add a translation of the Image field, I can't type anymore in the input fields of this content type.
Ok, I'm trying to explain it step by step:
I've realized that this is solved by doing this:
Which is going back to the previous version of that line, as in ctools 7.x-1.5. Since I don't understand that change, I'm posting here my problem and how I've solved it in my project to ask you experts if you think this is an issue and how it should be treated. If it is, I'd be glad to solve it.
The core/modules versions I'm using are:
Drupal 7.34
ctools 7.x-1.6
File entity 7.x-2.0-beta1
Media7.x-2.0-alpha4
Entity Translation 7.x-1.0-beta4
Thank you very much for your help.
Comment #13
joelpittet@jlafu that may be a good catch:
if ( $('#modalContent')) $('#modalContent').get(0).focus();
Should really be:
For coding standards and all.
Here's a patch, try this out and let me know.
We may need to open a new issue for this as this one is closed. (up to the maintainers)
Comment #14
jlafu CreditAttribution: jlafu commentedThanks a lot @joelpittet
I have tried your patch, but it does not work for my case. The only thing that works for me is (better coded now):
(I don't post it as a patch since I don't understand how I am altering the original code).
The funny thing is that I have tested that any of the two changes in your patch (the check on $('#modalContent').length and the use of $('#modalContent').focus() instead of $('#modalContent').get(0).focus() ) break my configuration.
I am assuming that it is caused by the ctools modal opening another ctools modal and then coming back directly to the edit node page sequence. But I have no Idea of what is getting lost in the path...
Thank you very much for your help and tell me if I can provide some more information about this.
Comment #15
joelpittetSo that sounds like it may be a bigger problem then... get(0) is getting the DOM element of the first instance of that, and calling it's focus() method.
The problems with that, it assumes there is more than one, but there can only be one ID in valid HTML. #modalContent
The jQuery.focus and DOM focus method should trigger the same. Except for invisible elements which jQuery makes notes to in their docs. @see http://api.jquery.com/focus/
I have some help on how to contribute to core: http://pittet.ca/drupal/sprint/patch
But more useful is having a look at How to create a patch with Git: https://www.drupal.org/node/707484
I think you are right here. Which may be why the .get(0) is working for you because it's setting focus on the first one it finds in the DOM. Where as the other one sets focus on all of the IDs it finds(even though there should only be one ... highlander).
The assumption that there is only one ctools modal on the page made by the #ID causes this craziness.
Maybe we can document this line as well and revert as a way forward?
Comment #16
jlafu CreditAttribution: jlafu commentedHi, if documenting and reverting sounds ok to you, I think it can be the way to go, since we are'nt breaking anything or unrolling funcionality, we are just undoing some coding standards to avoid a bigger problem.
I think that if we document it and open a related issue with all the information of the "big problem" we are good.
Do you agree?
Comment #17
joelpittetI agree, think that may be the best approach, undoing that part of the code change does not effect this issue with the keyboard shortcuts disabled.
Comment #18
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 4 year old patch in #13 to modal.js does not apply to the latest ctools 7.x-1.x-dev and if still applicable needs to be re-rolled.