Skip to content
Snippets Groups Projects
Commit 6e9f0116 authored by Reuben Turk's avatar Reuben Turk
Browse files

#315236 by Bartezz, Fabianx, NigelCunningham, jcmarco et al. - gmap views that...

#315236 by Bartezz, Fabianx, NigelCunningham, jcmarco et al. - gmap views that use ajax break when exposed filters are used.
parent d9617334
No related branches found
No related tags found
No related merge requests found
......@@ -1263,3 +1263,36 @@ function gmap_views_plugins() {
),
);
}
/**
* Implementation of hook_views_pre_render().
*/
function gmap_views_pre_render(&$view) {
static $gmap_processed;
// Add js only for gmap style views with ajax and not already processed.
if (($view->plugin_name != 'gmap' && !$view->use_ajax) || $gmap_processed) {
return;
}
// Mark the view as already processed.
$gmap_processed = TRUE;
// Add js with new views callback.
drupal_add_js(drupal_get_path('module', 'gmap') . '/js/gmap_views_ajax.js', 'module');
}
/**
* Implementation of hook_ajax_data_alter().
*/
function gmap_ajax_data_alter(&$object, $views, $view) {
// Add js callback only with gmap style plugins and with ajax.
if ($view->plugin_name != 'gmap' || !$view->use_ajax) {
return;
}
// Save settings.
$js = drupal_add_js(NULL, NULL, 'header');
$object->settings = $js['setting'];
// Register custom callback.
$object->__callbacks = array_merge($object->__callbacks, array('Drupal.gmapAjax.ajaxFixMaps'));
}
// $Id$
/**
* @file
* When using views with ajax enabled, the use of ajaxified
* exposed filters breaks the gmap javascript.
* This file is part of the solution to this problem.
*/
$(document).ready(function() {
Drupal.gmapAjax = Drupal.gmapAjax || {};
/**
* An ajax responder that accepts a packet of JSON data and acts appropriately.
*
* The following fields control behavior.
* - 'display': Display the associated data in the view area.
*/
Drupal.gmapAjax.ajaxFixMaps = function(target, response) {
var $view = $(target);
if (response.settings) {
var i = 0;
var gmap = {};
for (i = 0; i < response.settings.length; i++) {
if (typeof(response.settings[i]['gmap']) == 'object') {
gmap = response.settings[i]['gmap'];
}
}
$view.find('.gmap-map').each(function() {
var id = '#' + $(this).attr("id");
var t = id.split('-');
var mapid = t[1];
Drupal.gmap.unloadMap(mapid);
if (gmap && gmap[mapid]) {
Drupal.settings.gmap[mapid] = gmap[mapid];
}
$(id).empty().each(Drupal.gmap.setup);
});
}
};
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment