This patch add this new features in the line of the popups module:

- optionally adds the automodal js/css, this way hook_init avoid loading the automodal css and js on every page.
- the automodal can be activated (if no auto scan active) calling from any custom module the function automodal_add_automodal();
- This automodal_add_automoda() can be called defining a new selector and defining new default settings for the modalframe.
This way in a custom module you can change a link with a hook_link_alter adding the automodal with a specific configuration and over a new-defined or existing selector
format: automodal_add_automodal('.new_selector', array('with settings'));

-The javascript takes the modalframe settings and selector from the module and it's applied just once

Comments

jcmarco’s picture

StatusFileSize
new3.55 KB
jcmarco’s picture

StatusFileSize
new3.63 KB

Added extra check for js in the hook_init

jcmarco’s picture

Forget patch in #2, it has problems using Pressflow and memcache.

jcmarco’s picture

StatusFileSize
new4.33 KB

Now you can add different selectors with different settings each
Just use automodal_add_automodal($arraywithsettings, '.automodal_2');

troyl’s picture

this patch is not working and no modalframes are called anymore...so reverting back to the last dev one

jcmarco’s picture

Have you tested #4? I have it in a local devel server and it works fine.
I have created two different classes with different settings, and it launches the different modalframes with the links.

I was using popups before and I am trying to get the 'same' behavior but with modalframe.
If it has problems so I will forget this patches and I will run it in a custom module, maybe nobody is interested in
trying to 'migrate' popups behavior to modalframe, this module could easily be a 'transparent' migration to
modalframe.

troyl’s picture

I am interested in ModalFrame and your module gives a nice bridge for people without coding knowledge to work with ModalFrame, however, I will test the #4 Patch again and I would let you know.

danny englander’s picture

I tried the patch in #4 and got this message:

patching file automodal.js
Hunk #1 FAILED at 1.
1 out of 2 hunks FAILED -- saving rejects to file automodal.js.rej
patching file automodal.module

I can post the .rej file's code if anyone is interested

keva’s picture

same problem as #8.
contents of automodal.js.rej:

***************
*** 1,18 ****
  (function ($) {
-   Drupal.behaviors.automodal = function () {
-     var selector = Drupal.settings.automodal.selector || '.automodal';
-     
-     var settings = {
-       autoResize: true,
-       autoFit: true,
-       width: 600,
-       height: 400,
-       //onSubmit: function (a, b) {} 
-     }
-     
-     $(selector).click(function () {
        settings.url = $(this).attr('href') || '#';
-       
        if (settings.url.indexOf('?') >= 0) {
          settings.url += '&'
        }
--- 1,13 ----
+ // $Id$
+ 
  (function ($) {
+ 
+ Drupal.behaviors.automodal = function (context) {
+ 
+   $.each(Drupal.settings.automodal, function(selector, settings) {
+     $(selector +':not(.automodal-processed)', context).addClass('automodal-processed').each(function () {
        settings.url = $(this).attr('href') || '#';
+ 
        if (settings.url.indexOf('?') >= 0) {
          settings.url += '&'
        }
Vector-’s picture

For the people who are having trouble applying this patch...
Have you applied the fix at #769426: IE 7 script error ?

That fix would cause this patch to not apply cleanly, and it's the only thing I see in the issue queue that might cause this?
To fix the patch locally, one should only have to apply the same change to the patch itself as applied to automodal.module (remove the trailing comma in settings)

Vector-’s picture

StatusFileSize
new1.67 KB

Note: All of the following patches I've posted depend on patch in #4
http://drupal.org/node/767128#comment-2833562

Along the lines of porting features from Popups UI, I've put this together...

This patch adds a hook_automodal() that functions almost identically to hook_popups()
(I copied most of the implementation from Popups UI directly, with a few changes to suit automodal)

If you're considering using these features, you might also want to check #685364: close modal on form submit

The combination of these two patches (and possibly the one below, still not sure if that's going to be applicable for most people) should allow very easy porting of existing Popups UI reliant modules.

Vector-’s picture

StatusFileSize
new509 bytes

EDIT: Using a RegExp in JavaScript just feels dirty... all the rest of the rambling below applies, but don't use this patch!

And I ran into a problem with '/'s in selectors - they weren't getting escaped properly...

I'd be very interested in knowing if other people get errors related to this when trying to add a selector containing a '/' (ex a[href*=path/to])
(FireFox was reporting something along the lines of "Expected selector to end with ] found /")

I would be particularly interested in knowing if anyone else has this problem, however - because I'm very suspicious that this could be a local bug related to jQuery 1.8
(which, of course, is not AT ALL supported in D6... so if it's a local problem only, I'll probably think on other ways to fix this)

Vector-’s picture

StatusFileSize
new595 bytes

Another attempt to fix the selector encoding, this one feels a bit less dirty

Still not sure if this is a jQuery 1.8 related problem or not...

Vector-’s picture

StatusFileSize
new491 bytes

And another patch, this one adds the ability to parse functions from strings in settings.onSubmit

This patch depends on http://drupal.org/node/685364#comment-3129642 - but wouldn't be difficult to reroll...

Vector-’s picture

StatusFileSize
new533 bytes

patch in #14 needs a sanity check - other modules (Autoload, I think) might have already done the work for us.

Try that again:

mfer’s picture

subscribe. Will look into this soon.

mfer’s picture

@Vector for the new function piece why aren't you adding the function via js and calling it?

mfer’s picture

@Vector The more I look at it the more I see to problems with what you posted.

  1. Implementing a hook_automodal isn't really needed if there is automodal_add. If someone wants it on every page they can just use hook_init and automodal_add.
  2. JavaScript functions shouldn't be written in PHP and passed through the settings. This is just a bad bad bad idea.

The one place I could see a hook is hook_automodal_alter that passes in a selector and settings. Giving other modules an option to alter the settings for the selector. But, that would need to be another issue all together.

mfer’s picture

Status: Needs review » Fixed

Code based on #4 has now landed. http://drupal.org/cvs?commit=408872

For details see the API.txt file and the new function automodal_add().

Also, the default for the autoscan is on. This will preserve backwards compatibility for a number of sites.

There is, also, a hook_automodal_alter.

I would love testers of this.

keva’s picture

This seems like a stupid question, but I'm used to testing patches: Is the new code to test to be found in 6.x-1.x-dev (Aug 17 2010)? Or do we pull it from the CVS link in #19?

Iagoo’s picture

please somthing about that??

http://drupal.org/node/872352

thanks

mfer’s picture

@keva This is now in 6.x-1.x-dev. When I'm working on modules I do not tend to use patches as they slow down the process. I only work with patches on other peoples modules and core.

keva’s picture

Thanks mfer - I'll test in the next couple of days.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Vote_Sizing_Steve’s picture

Where do I find the value for this 'selector'? Here's the php code I use to invoke an automodal link on my page:

function Modal_Popup( $URL = '', $Text = '', $Modal_Attributes = null, $Link_Attributes = '' ){
#	Test values:
	$Link_Attributes = 'id="my_selector"';
	$Modal_Attributes = array(
		 'width' => 200,
		 'height' => 580 );
#	End test values.
	if( is_array( $Modal_Attributes )){
		automodal_add( '.my_selector', $Modal_Attributes ); }
	return(
		Wrap_HTML(
			'a',
			'href="'.$URL.'" class="automodal" '.$Link_Attributes,
			$Text )); }

... but the module 'reverts' to the default values. (The Wrap_HTML function just puts < a../a > tags around the values passed to it.)