Closed (won't fix)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Modal
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
30 Mar 2012 at 12:18 UTC
Updated:
9 Apr 2012 at 03:04 UTC
Jump to comment: Most recent file
Comments
Comment #1
litwol commentedCheers.
Comment #2
tim.plunkettMaybe assign a variable for $('#modal-content')?
Comment #3
litwol commentedCheck it :)
Comment #4
merlinofchaos commentedMarking won't fix on the grounds of http://www.mail-archive.com/development@drupal.org/msg00227.html
Comment #5
igor.ro commented@merlinofchaos, I have read your comments about behaviors problem.
Your ideas are good and I can agree that :not(processed-X) is better then context case.
I have found problem that when we do such way
and we have behaviors like this
This code would not find #modal-content because it search only in context's child. This is the big problem with behaviors.
In other hand we have a lot of contrib and custom modules follow context agreement.
and when I start using ctools modal on my current project I got a lot of bugs with processing the same data twice.
The problem was that ctools modal do not follow drupal behaviors agreement. Even context way is bad.
So currently I have forked ctools module on my project to fix this. I think some of the other 317538 projects used ctools could have the same problem (btw it is not easy to find such bugs out).
This is my minds about.
Thanks
Comment #6
merlinofchaos commentedEven if I sent behaviors the way you suggest, the code you want wouldn't work, because of the way jquery works.
You would be better off avoiding the use of 'context' entirely (PLEASE see the link provided to Matt Butcher's excellent post on the topic) than forking CTools. In fact, forking a module over a philosophical question like this is a really, really, really bad idea and is goint to eventually burn you no matter what, especially when you can fix your code in about 3 minutes and it will work.
Comment #7
merlinofchaos commentedIn fact, if you're willing to fork CTools over this, I think you should probably just write your own modal instead. It doesn't make sense that you'd do this, and I actually find it upsetting. If you do choose to stick with your fork, please do not ask for support.
Comment #8
igor.ro commentedYes, code I have posted in comment #5 would not work.
It was the example of problem when we use context.
That was example to show that you are right about "using context is a bad idea".
Absolutly agree with you that module fork because of philosophical question is a stupid idea.
I'm speaking not about philisophy, I'm speaking about bugs.
A lot of drupal module use behaviors in case that whole document will pass only once.
Current code makes ajax forms that send's twice (or more) if some one open modal window and close it.
Some DOM elements have several same functions on events. And etc...
When we are speaking about your examples, like rows in tables - this is responsibility of behavior.
Behavior should ignore context in it's code if it is necessarily.
If Drupal follow your idea we will solve all problems, discribed in answer to Matt Butcher's excellent post on the topic.
But now this code makes bugs.
This code will works fine.
http://drupal.org/files/ctools-js-behaviours-context-1516062-2.patch
Thank you.
Comment #9
tim.plunkettActually, this seems like a fair point to me. If we accept that using context is broken in a use-case, we just should use it in the selector.
Comment #10
merlinofchaos commentedWhat bugs? Behaviors *must* assume that behaviors on the entire document might run more than once. The modal is *not* the only thing that might run behaviors; there could easily be some other AJAX call that happens on the page that might cause behaviors to run; even if I did fix this 'bug', other things could cause it.
The contract of behaviors requires you to use something like .once() to ensure your behaviors do not run multiple times on your own code. That is not the fault of CTools. This is a bug in your code and trying ot lay the blame on CTools is even worse .
Comment #11
igor.ro commented>> The contract of behaviors requires you to use something like .once() to ensure your behaviors do not run multiple times on your own code.
I did not find any information about this in documentation.
http://drupal.org/node/304258#drupal-behaviors
But I have found
Comment #12
litwol commented@ igor.ro, instead of arguing back and forth, i recommend you take a look at code in core as well as some popular modules and see how they do it. you will discover that all of them use .once() method or equivalent selector behavior in $('somthing:not(.class-name)').addClass('class-name') ... If you dont understand what that does, that is a different issue and we can have discussion about that. but i assure you it is the right way to go about it. so please stop arguing about what is in documentation and what is not.
Good luck.
Comment #13
igor.ro commentedlooks like your point of view is right.
Thanks for discussion.
http://drupal.org/node/114774#javascript-behaviors