Hi guys,
Looking for some ideas from you on how to handle this issue.
A known issue with my Drag'n'Drop Uploads module is that if you disable the WYSIWYG via the 'Disable rich-text' link, the Drag'n'Drop functionality needs to be re-attached when the you 'Enable rich-text'.
The obvious solution would be to trigger an event when the link is clicked, but unfortunately the WYSIWYG module unbinds all click events on the link in question. Not very sporting really, but after playing around with the code in Drupal.wysiwygAttachToggleLink I understand why it does it.
I had a quick scan through the jQuery unbind documentation (http://docs.jquery.com/Events/unbind#examples) and it states that you should be able to simply unbind one particular function from an event, instead of all functions. This would clearly be the way to go, except I just couldn't get it to work.
Curious if you have any thoughts on this? Because at the moment the only solution I can really think to make things work as I need them would be to re-declare Drupal.wysiwygAttachToggleLink in my on javascript, which is not really the best approach.
Cheers,
Deciphered.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | wysiwyg-DRUPAL-6--2.toggle.12.patch | 3.27 KB | sun |
| #8 | wysiwyg-678580-toggler2.patch | 3.28 KB | twod |
| #4 | wysiwyg-678580-toggler.patch | 2.98 KB | twod |
Comments
Comment #1
decipheredAfter a little more digging around I realized that
Drupal.wysiwygAttachToggleLinkis triggering the 'blur' event, so I can simply bind my function to 'blur' instead of 'click'.While this does solve my current problem, it still couldn't hurt to attempt to not hijack the 'click' event if possible, I'm sure there are other modules that would like to bind an event to 'click' on the Disable/Enable rich-text link and still be compatible with the WYSIWYG module.
Cheers,
Deciphered.
Comment #2
twodI'll look into clearing just that function later this evening. Would triggering on something like onMouseUp work instead? Should be more similar to onClick compared to onBlur, I think.
Comment #3
decipheredHi TwoD,
Unfortunately 'MouseUp' wouldn't get triggered if the user used there keyboard to trigger the link, whereas 'Click' would, and as you are manually firing 'Blur', blur is really the only option for the moment.
The only downside to using 'Blur' is that it fires on other than on click, but that doesn't disrupt what I need it to do.
Comment #4
twodThis patch should do the trick.
On a further note, we should take implementing some "onComplete/doneLoading/whatever" events, and relaying them through our API, into consideration for Wysiwyg 3.x. Having to rely on events triggered by this toggler link is not an optimal (and in most cases probably not a useful) solution considering the asynchronous nature of the editors.
Comment #5
decipheredHi TwoD,
I completely agree with that sentiment, a hook that alerted any registered events to let them know what WYSIWYG is being used and any relevant settings would be perfect, and would hopefully simplify the WYSIWYG support in DnDU.
Currently I am using three methods to bind DnDU to the WYSIWYG module:
Not really the way I wanted to do things, but the only way I could make it work.
As for your patch, will give it a workout shortly and see how it goes.
Thanks again,
Deciphered.
Comment #6
decipheredTwoD,
While your code should work, as should the nearly identical version I did myself, where the only difference was I used the
var toggleWysiwygCallback = function() {}style syntax, should also have worked, it doesn't. You can clearly see the the behaviour stacks as the more time you click the button the more flashing/spazing out it begins to do. I'm not clear on why this is happening, but it is unfortunate as it is definitely allowing my bound event to stay bound.Will try to make a bit of time to dig deeper.
Cheers,
Deciphered.
Comment #7
twodI took a look at your code a few hours ago and saw those loops. They seem to work but I'm a bit concerned about the check for
Drupal.wysiwyg.instances[field].editor, that being set to something other than 'none' is no guarantee the editor is done loading and the API is ready for use.If you don't mind, I'll try contacting you once we have the relevant parts of 3.x implemented so you can have a chance to review it and try it out before an official release. As far as I know, only your module interacts with the editors in this way so you have a better idea about the requirements on this module than we have.
EDIT: Your reply got in while I was typing, will respond in a sec. Don't mind the status change.
Comment #8
twodI didn't notice the problems that appeared when toggling multiple times until now. I have no clue why this happens but it might have something to do with the function being redeclared every time during toggling. I don't feel like digging that deep into jQuery to find out where this goes wrong, my head hurts enough already and there's an easier way around this.
I moved the callback outside the function and now it appears to work no matter how many times I toggle it. Tested with multiple editors on the page at the same time just to be sure the closures created by jQuery for our parameters work like they should.
Comment #9
decipheredI had had that thought when I was originally testing, but I never actually tested it... so I apologies for making your head hurt :)/:(
That code works great for me, so I have marked it as RTBC.
Comment #10
sun1) We should namespace those event bindings, i.e. click.wysiwyg
2) Do we need to wrap to keys in quotes?
3) Holy cow. I wasn't aware of that data-passing feature of jQuery :)
4) We want to rename that helper function to .toggleEditor() or similar.
Powered by Dreditor.
Comment #11
twod1) Makes sense.
2) That was for readability,
{params: params, context: context}looked odd (but is technically valid) and I wanted to keep the key names the same as the variables to minimize confusion. I'll remove the quotes if you want.3) Yeah, it's pretty neat. =)
4) I don't mind a name change, but removing the _-prefix (making it 'public') would be a lot easier if it was 'set' instead of 'toggle', if you see what I mean. 3rd party code has little use for a toggle switch if they can't easily read the starting or ending states, nor find out when the operation is done (half the time it will be asynchronous). The function works for our internal use because we keep a reference to the parameters read from the radio buttons (Drupal.settings in D7). Making it public should also mean it's fairly straight forward to use. How
paramsworks is a bit of a wtf if all you want to do is make sure no editor is loaded when, for example; doing AJAX operations on a field. One must first check withDrupal.wysiwyg.instances[field].editorto know the status of the editor, and if it's disabled one also needs to use.getParams(theCorrectElement)to get the correct values, then overrideparams.status. See the last patch I wrote for #527622: WYSIWYG editors disappear after node body rebuild and switching filter does not bring them back for reference.If all this could instead be rewritten to
Drupal.wysiwyg.enableEditor(field)(asynchronous, possibly with callback in 3.x) and Drupal.wysiwyg.disableEditor(field) (synchronous) I'd be happy to do it. It would also simplify the Markup Snippets patch and managing a toggle callback for the Rich edit link would be easier as well. A rewrite like that would probably be easiest to base of the D7 implementation since it has already decoupled the radio buttons with the actual parameters. Maybe time to port that to D6?Yikes, 2am again... Where is all the time going???
Comment #12
sunComment #13
twodWorks nicely and should no longer remove other's handlers. RTBC.
Comment #14
sunThanks for reporting, reviewing, and testing! Committed to all branches.
A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.