Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Am planning an upgrade from a ModalFrame Drupal 6 Application to Drupal 7 + CTools.
Managed to get field_groups working with horizontal tabs in a node form all within a CTools Modal dialog.
However, the one really important yet seemingly missing component is the ability for the Modal layer to resize as a function of the active tab's contents.
Wondered if this was a planned feature, or if anyone had a work around here?
Comment | File | Size | Author |
---|---|---|---|
#79 | 1294478-dynamic_modal-79.patch | 20.25 KB | mnico |
#77 | 1294478-dynamic_modal-77.patch | 20.15 KB | sean_e_dietrich |
#75 | ctools-dynamic_modal-1294478-75.patch | 17.7 KB | hctom |
#74 | modal_mobile.jpg | 17.11 KB | m.lebedev |
#74 | interdiff-1294478-70-74.txt | 1.02 KB | m.lebedev |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedRight now the only sizing options the modal has are 'fixed' and 'scale to page'. I never figured out how to do scale to content. If someone would like to contribute this feature I'd be interested, but it's not high on my priority list.
Comment #2
southweb CreditAttribution: southweb commentedThanks for your reply. I'd be happy to have a look. The older ModalFrame dialog has some code to do this that we've tweaked. The important thing I found was to be able to trigger the resize at the right time.
The ctool's dialog code has a .show method, but if there was a way we can access and override this - and also to be able to call a resize method on demand, I can certainly look at the algorithm for resizing?
There is a good discussion here on resizing: http://drupal.org/node/779594.
Just wondering, given my newness to ctools, perhaps there is already some sort of hook in the framework I can use from within JavaScript that will get invoked when the content when a ctool's dialog loads? And some way of overriding the resize method perhaps?
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedThere is a resize method and it is called whenever the modal is shown and whenever the window is resized. It shouldn't be too hard to add a third sizing method to that code.
Comment #4
southweb CreditAttribution: southweb commentedWell I did follow the suggestions on this link, but it required me to actually replace the existing .show method.
http://drupal.org/node/779594.
Is there a way to override rather than replace it? And if I was to add a hook on content changing within the dialog, do you have any ideas on how that could be implemented?
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedWell, I think you would add code to the resize() function and provide a patch.
Comment #6
southweb CreditAttribution: southweb commentedThis would be fine if I knew the resize function was going to get called every time the content changes within the dialog but it doesn't seem to, so ideally ctools could provide the developer with the ability to supply a custom resize method, and provide a set of events for it to respond to - like initial drawing, and content reloading.
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedA call to resize() should be possible there. It might require changing how resize is defined but this shouldn't be too difficult.
Comment #8
southweb CreditAttribution: southweb commentedThis is where I've got to:
I did try to bind the event to 'div.ctools-modal-content' but it didn't like it so, we've add this function. (width *1) is just a hack to make sure "123" gets converted to 123 as I'm sure you're aware.
The corresponding code to update the parent window can then be found here with a function prototype of focus on the horizontalTabs:
http://drupal.org/node/1295352
Let me know if you'd like any changes before I make a patch.
Comment #9
andypostsubscribe
Comment #10
Stalski CreditAttribution: Stalski commentedsubscribe
Comment #11
fourmi4x CreditAttribution: fourmi4x commentedHi, I'm trying to do this for quite some time now ... without success. (I'm on drupal 6.x-1.x-dev)
"There is a resize method and it is called whenever the modal is shown and whenever the window is resized. It shouldn't be too hard to add a third sizing method to that code."
=> I did it like that :
So when I don't put anything, the modal resizes to the modal content's (don't know why...), however the modal is not at the center of the screen : it starts at the middle of the screen. And I can't find how to fix this.
I tried putting in this new "else" :
but it doesn't change anything : it looks like the document size is not available this soon in the process.
I also tried the solution of a "Drupal.CTools.Modal.resize();" function called in "Drupal.CTools.AJAX.commands.modal_display" function : it is called at each reload of the modal, which is great, but the resize to the modal content doesn't work either...
I guess the solution might comme from "Drupal.CTools.Modal.modalContent" function, but I can't find how to get the document size so the modal positions correctly : when and how could I get it?
This feature (auto resizing to content's size) would be really awesome in ctools modal! Thanks for any tip on this.
Comment #12
Dave ReidComment #13
fourmi4x CreditAttribution: fourmi4x commented@bluffit: did you succed in doing it? I'm really stuck on this...
Comment #14
sebas5384 CreditAttribution: sebas5384 commentedThere is any further progress about this issue?
Thanks,
Sebas.
Comment #15
rjbrown99 CreditAttribution: rjbrown99 commentedI'm using 6.x and I had a need to grow the height dynamically based on form content in the modal. In my case it was as simple as modifying the resize function and changing the height CSS to be min-height.
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedDoes that work with width as well? If it does we could make it an actual setting.
Comment #17
rjbrown99 CreditAttribution: rjbrown99 commentedYes, works with width - at least for me it does. I don't have a practical use for dynamic width so I didn't modify that bit. But either way, using a fixed width modal it will start out at the correct width specified when using min-height/min-width, and then grow out from there.
One caveat with this, which matters more for width than height - this solution does not move the modal itself. If the modal pops on the screen at the dead center and your content in the modal starts to extend downward, the modal stays in the same place and just gets 'longer'. That's not an issue for me and is the desired effect, but it would be the same with width where the modal won't move but starts extending to the right with new content. A proper fix for width would likely involve keeping the modal stationary and extending out in either direction so it looks nice for the user. I don't think anyone wants a horizontal scrollbar if they can avoid it.
The other thing I did for resizing a multi-step modal with a form was to add a bit of JS like this, which automatically submits the form when an element is checked and then manually resizes the modal to fit the next step. This works very well for me across all browsers IE7/8/9, Firefox, Chrome, Safari, etc. This effectively resizes my modal to a new size for each distinct step of the multi-step process.
Comment #18
uditmahajan CreditAttribution: uditmahajan commentedI am looking for dynamic resizing of the modal too.
Wouldn't it help to completely migrate the modal to jquery modal? I am just curious, haven't really dug into the entire issue.
Also I was checking out couple of website (not built on drupal) that are offering modal as a solution to do basic task like login, signup etc. In addition to dynamic resizing of the modal the transition is also animated and not sudden.
For example, if I have a form embedded inside a modal. I have to keep the size (particularly height) of the modal keeping in mind the errors too. So there is always a white space left for the error. I would ideally should not be showing that white space. and when the error appear, the modal should automatically resize depending on the height. Not only that, the transition should be animated.
Comment #19
rjbrown99 CreditAttribution: rjbrown99 commentedThere's an issue for that: #1397370: Make modal.js use jQuery dialog.
IMO, there are a few complicating factors involved. Firstly, D6 and its old jQuery library which might require a dependency on jquery_update, and secondly the huge install base of ctools. In the former case it may be that D6 just stays as-is and this is a D7-only choice. In the latter case, it might present problems and bugs for a number of sites. It's more of a code maturity issue and the need for caution when rolling out a large change like that. I'd almost prefer a new ctools 2.x branch for major changes like that, but this is just me and my paranoia in disrupting production sites. I have no meaningful vote anyway :)
I have been able to do most of what you are asking with the existing modal by resizing it upon change in a multi-step process. It's not draggable and I prefer no animations, but it's working quite well across all browsers.
Comment #20
mojzis CreditAttribution: mojzis commented+1 for min-height. do you want a patch for that ?
Comment #21
merlinofchaos CreditAttribution: merlinofchaos commentedThis patch seems to work on Chrome, Firefox and IE9 for me -- and it includes a dynamic modal in the sample.
(Note: There seems to be some brokenness in the sample wizard I'm going to have to fix separately).
Comment #22
Begun CreditAttribution: Begun commentedI just tried out this patch, but ran into issues where the modal dialog is higher than the height of the browser window. In such a case the top of the dialog is not visible, as it is above the top of the browser window. Furthermore the modal will not scroll with the rest of the page when using the browser's vertical scroll bar. Tested in Firefox 14, Chrome 20, IE9
Comment #23
mojzis CreditAttribution: mojzis commented@Begun I think that the negative position is a different issue, i tried to adress it : #1678562: Modal may receive negative top css position
Comment #24
Begun CreditAttribution: Begun commentedFor this dynamic patch to be valid there must be some way of addressing the situation of when the modal is larger than the browser window. Either it needs to degrade gracefully (e.g. set the modal height and width to that of the browser window in the event that the modal is bigger), or be able to handle with the larger modal size. I prefer the latter option. I have already started working on it. Will get back with a patch as soon as I can.
Comment #25
merlinofchaos CreditAttribution: merlinofchaos commentedBut if it's a proble without the patch too I think I agree that it's out of scope for the patch and should be handled independently.
Comment #26
Begun CreditAttribution: Begun commentedI have created a patch which i believe addresses some usability issues with using a dynamic resizing modal introduced in the patch put forward in #21. The current patch overrides the previous behavior of ctools dynamic modals to remain fixed in one position on the screen while the underlying page is scrolled. This default behaviour doesn't work for oversized modals, as the user will not be able to ever scroll to the bottom of the modal. With this current patch, modals whose height is greater than the browser window will be "pinned" to the underlying page at its current position. That way the modal will scroll with the rest of the page.
I have tested it in FF14, IE9, Chrome 20 and Opera11.6.
To use this patch you must first ensure that you have applied the dynamic modal patch in #21. Sorry I am not sure what the standard protocol is for creating a patch based on another patch. In this case I have kept them separate, rather than merging them.
@merlinofchaos From my testing I beleive that the behavior described here occurs as a result of the patch in #21. So I did not create a new issue.
Comment #28
Begun CreditAttribution: Begun commentedHere we go with that patch again from #26 .
Comment #29
Begun CreditAttribution: Begun commentedSorry guys, I have to submit the patch from #26 one more time, as failed to reset the issue status to 'needs review'. I am guessing that the automated testing will not work if the status is not set as such.
Comment #33
Begun CreditAttribution: Begun commentedNever intended to fill this list with failed patch attempts. I am not sure what I am doing wrong. Would be grateful if anyone could help me trouble shoot this in a separate issue (here), so that I don't needlessly take up more space here.
Comment #34
helior CreditAttribution: helior commentedI didn't put any work into this –- I just combined the patch in #21 and #29, manually fixed the merge conflicts, and rerolled against HEAD.
Comment #35
populist CreditAttribution: populist commentedThis is a very cool patch and I did some testing on it today. Some feedback:
1.) There is an issue when content is redrawn inside an existing modal (i.e. in the case of the panels IPE "Add content" wizard) where the size will grows when you change content (one - http://drupal.org/files/Screen Shot 2012-08-29 at 3.39.00 PM.png, two - http://drupal.org/files/Screen Shot 2012-08-29 at 3.38.04 PM.png, three - http://drupal.org/files/Screen Shot 2012-08-29 at 3.38.10 PM.png).
2.) If you scroll the page during the resized it jumps to the left side (http://drupal.org/files/Screen Shot 2012-08-29 at 3.40.38 PM.png)
Comment #36
Begun CreditAttribution: Begun commented@populist:
Could you clarify slightly the first issue. As I understand it, when you adjust content within the modal, the modal size will change. From my understanding this is the correct behavior for a dynamic modal, as it should change to match the content. Could this be an issue with the content itself (e.g. because the internal content is changing size, the modal is adjusting accordingly), in which case you would need to style the content in a way so that it is more fixed dimension wise?
Comment #37
populist CreditAttribution: populist commented@begun:
The issue I was seeing was caused by cases where there was a multi-step form such as the panels "add content" modal. The problem is that when it loads the first time it does the auto adjustment, but on the second + third loads the size of the modal grows (in my example) by ~120px each time even when the content is the same.
To replicate:
1.) Implement the dynamic modal style for the CTools modals
2.) Use the Panels IPE to "add content" to a panel page
3.) Click on various categories in the "Add content" modal and watch the modal size grow
(note - this needs to be done on a screen large enough to show the increase)
Comment #38
merlinofchaos CreditAttribution: merlinofchaos commentedI saw what populist saw too, and I had real trouble figuring out what the heck was causing it.
Comment #39
j0rd CreditAttribution: j0rd commentedI tested patch #34 and seems to work fine for me on the various custom CToolsModals I have.
Comment #40
anouWith patch #34 I've got problems with the ajax-register modal style and the background overlay.
I've attach some screen shots if it can help understand the problems
The only solution I've found for now, is to apply the same style (the one that doesn't change size on scroll) to all my modal calls. I've found nothing for the overlay moving problem...
Comment #41
ckngBackported patch #34 for D6, it works for all my ctools modal. Did not test for multi-steps form though.
Comment #42
thsutton CreditAttribution: thsutton commentedI tried getting the patch in #34 to work with Modal Forms.
It worked perfectly the first time I trigger a dialog but, contrary to merlineofchaos and populist, the second and subsequent times (without a page reload) resulted in a #modal-content element 1766375px wide and 232355px tall. Substantially bigger than the 660x226px of the element within #modal-content. :-)
Comment #43
j0rd CreditAttribution: j0rd commented@thsutton, i've been using this patch on my production website for months now and it works as expected.
with that said, I've customized the CSS pretty heavily so I might have fixed your bug with some custom CSS.
But overall it works pretty well for me for months.
Comment #44
thsutton CreditAttribution: thsutton commented@j0rd I've just tried #34 on a fresh site under Bartik and it seems to work fine. There must be something in my theme CSS that is tripping the logic up.
Cheers
Comment #45
j0rd CreditAttribution: j0rd commentedOne thing I've noticed is (and this may be a wider ctools modal issue, not related to this patch), the modal doesn't work very well in mobile browsers.
Currently this issue is leading to very low conversions with mobile traffic as forms (login, register) which are shown via ctools modals are not accessible on mobile. This is causing a 6% vs. 40% conversion rate on mobile vs. desktop.
While I know my site should be redesigned entirely to not use modals (unfortunately I don't have control over these design decisions), it seems that perhaps some tweaks could improve the usability of ctools modal resize with regards to mobile browsers.
The big issue right now, is for mobile, I have the view port zoomed out all the way to the width of my website. When a user opens a modal it shows up in the center of the screen as expected, but if there's a form in that modal and they attempt to type something into it, the viewport zooms in and the keyboard end up taking up space and that causes ctools modal to fall out of the viewport. Since the user can not see what they're typing, they eventually give up. It's quite surprising that even 6% of people manage to fill out these forms (I would never have the patience required).
For a quick solution I will be removing modals for important forms when user is surfing via mobile....but a better fix would be to make sure that it simply just works.
Colorbox for instance (and unfortunately I enjoy this feature in ctools modal, when browsing on desktop) doesn't attempt to keep the modal in the center of your screen. Perhaps this is another proper solution for mobile browsers vs. desktop. Additionally there's an issue where if the user is at the top or far left or right on the page and they open up a modal, they may never know as it's in the center and may be out of their viewport. This could be fixed by centering the users screen on the modal when it's shown.
Anybody else notice similar issues with ctools modal?
Comment #46
j0rd CreditAttribution: j0rd commentedThe big issue here, is that some mobile browsers call "resize" when you scroll or zoom (i'm looking at you old android browsers, or every mobile safari browser).
In a mobile browser, I suppose you only want to "resize" upon orientation change.
Here's my super hacky patch to make this "semi-work" on mobile devices.
I'm still going to need to disable important modal forms to increase conversions, but at least this allows the user to fill in forms in modal when on mobile, where this previously was nearly impossible.
PS. This patch depends on Modernizr to detect .touch functionality, and thus can never be committed. Patch was provided for proof of concept.
Comment #47
j0rd CreditAttribution: j0rd commentedIn my previous patch, I forgot to add a commit in which I removed the modalContent from following Y scroll. This is important for mobile as you'll scroll & resize when clicking into an input.
Comment #48
lucas.constantino CreditAttribution: lucas.constantino commentedHi there!
I'm using the patch from #34, and I just found a weird issue:
When there is a sticky header (i.e. when there is a long table, the table header stays at the top when scrolling the page down), this element is been positioned outside the modal. Also, this sticky header is appearing based on the scroll offset of the body, not of the modal.
And there goes the image to this issue:
https://dl.dropboxusercontent.com/u/287795/sandbox/Drupal/Screenshot%20f...
Besides that, the patch if working jus fine form me.
Cheers!
p.s.: my first post to drupal.org! Yeih!
Comment #49
rylynchen CreditAttribution: rylynchen commentedThanks for saving my time.
Comment #50
maximpodorov CreditAttribution: maximpodorov commentedThe patch from #34 rerolled for the current dev.
Comment #51
andypostunrelated changes
Comment #52
maximpodorov CreditAttribution: maximpodorov commentedYou are right. This change is removed in the attached patch.
Comment #53
sjeandroz CreditAttribution: sjeandroz commentedHi,
This patch seems to works for me.
But I have modifiy the file modal.js to lightly improve the modal size.
I have added these lines in order to better correspond to my need. Hope it could help someone which have same need that me:
in the function setSize, I have added thses lines, in the end of the "if" bloc Drupal.CTools.Modal.currentSettings.modalSize.type == 'dynamic':
$('div.ctools-modal-content', context).css('max-height', (winHeight / 2) * 1.7 + 'px').css('max-width', (winWidth / 2) * 1.5 + 'px').css("overflow", "auto");
$('div.ctools-modal-content .modal-content', context).css("overflow", "visible");
These lines prevents popup to be bigger than the screen (value 1.7 and 1.5 can be adapted)
Thanks and sorry for my bad english
Comment #54
eshta CreditAttribution: eshta commentedHi there - not any real work done here but I took the recommendations from sjeandroz and combined them with a patch re-roll. Happy to do some more work on this to help get it through if I knew what the blockers were.
Comment #55
aprice42 CreditAttribution: aprice42 commentedPatch in #54 works but when the modal first loads it is positioned off center. When I scroll then it moves into proper centered position.
I took a quick screen cast to illustrate.. https://www.dropbox.com/s/dctyq28c2xt9ujj/modal-position-issue.mov?dl=0
Any thoughts on how to change the position to be correct when the modal first comes up?
Thanks,
Andy
Comment #56
maximpodorov CreditAttribution: maximpodorov commentedThe patch from #54 is modified to trigger "resize" event after attaching behaviors since behavior code can change the visible content of the window. This can fix the problem of _andy.
Comment #57
parisekPatch #56 do not resolve problem reported by _andy, there is still need to scroll to reposition modal window to center of browser (after something in modal changed)
Comment #58
maximpodorov CreditAttribution: maximpodorov commentedIn my project, $(window).trigger('resize').trigger('resize').trigger('resize'); is required after changing the modal content to place the modal in the proper position. Try this solution. :)
Comment #59
herd45 CreditAttribution: herd45 commentedI tested on #56 on Chrome browser on a Droid phone. Here are some issues I found....
The modal is off-center.
The black background does not cover the rest of the screen like it does on a desktop. You can still see most of the rest of the screen.
When registering, clicking on the first password box causes the form to reset and I'm taken back to the top of the form, even though the cursor is active in the password box. The focus should always be on where the cursor is active.
Comment #61
joshf CreditAttribution: joshf commentedThis is ONLY a reroll of #56 so that it applies cleanly to latest dev. I didn't have time to dig in and try to fix the issues reported since then.
Comment #62
maximpodorov CreditAttribution: maximpodorov commentedThe problem with your patch is using unbind() instead of bind(). This breaks existing sites. I fixed this.
Comment #63
a_thakur CreditAttribution: a_thakur at Srijan | A Material+ Company commentedThe patch applies cleanly but issues as mentioned in comment #59
Comment #64
maximpodorov CreditAttribution: maximpodorov commentedCould somebody with the phone try to find the source of this problem?
Comment #65
maximpodorov CreditAttribution: maximpodorov commentedHere's the revised patch which applies to the current dev. Global variables are not created any more in modal.js.
Comment #66
cosolom CreditAttribution: cosolom commentedIt will be good if this patch include in next release.
Comment #67
maximpodorov CreditAttribution: maximpodorov commentedThe patch is re-rolled.
Comment #68
mcannon CreditAttribution: mcannon commentedI just used patch 1294478-67.patch and experienced the same issue when the modal first loads. It loads off center to the right. I dug around and it's being caused by the modal width not being correct when the modalContentResize() initially fires. To get around this I had to use some hacks because of time restraints on my current project, but I want to report my findings and hack here incase someone else has time to resolve the issue in a better fashion.
Outside of the modalContentResize() I added an init variable which I check inside of modalContentResize().
At the end of the modalContentResize() function I trigger the resize once again to get all the correct values.
Then it gets a little hacky since I had to use some setTimeout() function, but I only do this based on the modalContentResizeInit value. So in both Drupal.CTools.Modal.modal_display and Drupal.CTools.Modal.show I wrapped the tigger function like so:
This helped the modal load at the correct size and position without the need to scroll or resize.
Comment #69
dmsmidtThank you all for the work.
Here is a reworked patch, it solves the initial horizontal placement issue mentioned in #55, #59.
The problem was caused by the 'auto' width styling in combination with the positioning of the 'loading' version of the modal. A reset of the position before setting the width fixes it.
It's based on the patch in #61 with some of the changes by maximpodorov manually applied.
I love cleaner code, but a real cleanup should be a separate issue. The patch is already hard to understand due to its size. Therefor this patch is not based on #67.
Furthermore, the new dynamic modal style assumes too much. Fixed, by replacing the following part.
The max values can now be manually overridden in the model style definition. It can be a string, integer or a float. When it is a string, the string will be passed as-is to the css property (allowing for: none/auto). In case of an float smaller than zero we assume scaling in relation to the window size and otherwise (int) a fixed amount in pixels.
More:
- On close the scroll event wasn't removed, fixed.
- Updated the documentation.
- Header with title and close button was not sticky anymore: fixed.
Comment #70
dmsmidtAdditional modal close fix and remove unnecessary change.
Comment #71
anouPatch do not work nicely with the last update (dev). Kind of jump on scroll... and doesn't want to close on click...EDIT: Sorry I had some buggy CSS from previous fight with modal :-)
Comment #72
anouComment #73
anouSorry for the mess with comments, but still got issues with last dev :
-> modal doesn't close (kind of jump off the bottom of the screen)
Comment #74
m.lebedev CreditAttribution: m.lebedev commentedI have a problem in the mobile version. My modal window does not have the right dimensions. I made changes to the code to fix the problem.
Comment #75
hctomPatch from #70 does not apply anymore from Version 7.x-1.13 on. I tried a reroll and finally made it, but unfortunately interdiff is no longer apply to create the corresponding interdiff due to all the changes that happened... And as far as I see there is more broken now after ctools updated several things in modal.js.
But for anyone who wants to work on this, here is my rerolled patch (which applies from 7.x-1.13 on again).
Comment #76
hkirsman CreditAttribution: hkirsman commented+1, also added minimal support to Nodal Forms https://www.drupal.org/project/modal_forms/issues/2997881
Comment #77
sean_e_dietrichPatch #75 didn't work for me. Had to reroll the patch for dev. The newest patch should fix the issue with closing modal, additionally, it makes some assumptions that the close is in the header and that there is a modal header. That has been scaled back to look within the modal content.
Comment #78
sean_e_dietrichComment #79
mnico CreditAttribution: mnico at TIFON commentedHi, I updated the patch from #77 to be compatible with 7.x-1.19.