Hi there,

I posted an issue about collapsible fieldsets and Gmaps stuck inside them, and someone posted a patch to try and fix it. I'm unfortunately not able to port that patch to the 4.7.x version of the module because the javascript is completely different (it's independent of jQuery for instance...blah).

Anyway my form is here, click on Upload Images.

http://www.unitorganizer.com/drupal476/taxonomygallery/upload

If you view source of the page, you can see way down near the bottom that I've attempted to add in some code to deal with this issue, and I'm currently debugging it because there is some error in my code I'm not seeing.

If anyone could help me, because I need this feature to work for both the 5.0 version and the 4.7 version.

Dave

Comments

dwees’s picture

Oops, btw this seems to already work fine in Internet Explorer 6 and 7, it's just the standards based browsers that have issues. For some reason they only show half of the Google map.

Dave

dwees’s picture

So I've worked out a solution to the collapsible fieldsets for the Gmaps. It isn't a patch to the module, just an example of how to implement a solution.

I have multiple collapsible fieldsets on the same page, so with each fieldset I need to associate an onclick event (without overriding the default onclick event) which does a map.panTo for the Gmap inside that fieldset.

I created a $form element of the type Mark-up like so:


    $form['image'.$num]['location'.$num]['gmap_js'.$num] = array(
      '#type' => 'markup',
      '#value' => '<script type="text/javascript">
          addEvent($("imagefield'.$num.'").firstChild, "onclick", function () { onclickCheckResize('.$mapnum.', "'.$mapnum.'");});
          addEvent($("imagefield'.$num.'").firstChild, "onclick", function () { onclickPanto('.$mapnum.', "'.$mapnum.'")});  
      </script>'
    );

obviously the form of this needs to be adjusted but the concept is sound.

Now the addEvent and onclick functions are defined in Javascript like so:

/*
 *  Adds event listeners when necessary designed by Aaron Moore
 */
function addEvent(element, listener, handler)
{
  //if the system is not set up, set it up, and
  // store any outside script's event registration in the first handler slot
  if(typeof element[listener] != 'function' || 
  typeof element[listener + '_num'] == 'undefined'){
    element[listener + '_num'] = 0;
    if(typeof element[listener] == 'function'){
      element[listener + 0] = element[listener];
      element[listener + '_num']++;
    }
    element[listener] = function(e){
      var r = true;
      e = (e) ? e : window.event;
      for(var i = 0; i < element[listener + '_num']; i++)
        if(element[listener + i](e) === false) r = false;
      return r;
    }
  }
  //if handler is not already stored, assign it
  for(var i = 0; i < element[listener + '_num']; i++)
    if(element[listener + i] == handler) return;
  element[listener + element[listener + '_num']] = handler;
  element[listener + '_num']++;
}

/*
 *  Removes event listeners when necessary designed by Aaron Moore
 */
function removeEvent(element, listener, handler)
{
  //if the system is not set up, or there are no handlers to remove, exit
  if(typeof element[listener] != 'function' || 
  typeof element[listener + '_num'] == 'undefined' ||
  element[listener + '_num'] == 0) return;
  //loop through handlers,
  //  if target handler is reached, begin overwriting each
  //  handler with the handler in front of it until one before the last
  var found = false;
  for(var i = 0; i < element[listener + '_num']; i++){
    if(!found)
      found = element[listener + i] == handler;
    if(found && (i+1) < element[listener + '_num'])
      element[listener + i] = element[listener + (i+1)];
  }
  //if handler was found, decrement the handler count
  if(found)
    element[listener + '_num']--;
}

function onclickCheckResize(mapid) {
  mapid.checkResize();
}

function onclickPanto(mapid, mapname) {
  taxonomy_gallery_textchange(mapid, mapname);
}

where taxonomy_gallery_textchange is a slight modification of the gmap_textchange function (because I have a form with 5 identical fields, and I want all 5 to be controllable by the behaviour of the first form).

Hope this makes sense? I'm sure something similar can be applied to the overall behaviour of the module?

Dave

bdragon’s picture

Status: Active » Closed (won't fix)

4.7.x is dead and buried...

dwees’s picture

That makes sense.