summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReuben Turk2010-11-04 11:50:31 (GMT)
committer Reuben Turk2010-11-04 11:50:31 (GMT)
commit6e9f01166173c095b00eadb39f0d6fe24f2bc7da (patch)
tree36c9878176069d584179566cb62fa9903117bb69
parentd9617334cb5284c52571ba7ecdede78e47201779 (diff)
#315236 by Bartezz, Fabianx, NigelCunningham, jcmarco et al. - gmap views that use ajax break when exposed filters are used.
-rw-r--r--gmap.module33
-rw-r--r--js/gmap_views_ajax.js45
2 files changed, 78 insertions, 0 deletions
diff --git a/gmap.module b/gmap.module
index 61dbe69..169d03f 100644
--- a/gmap.module
+++ b/gmap.module
@@ -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'));
+}
+
diff --git a/js/gmap_views_ajax.js b/js/gmap_views_ajax.js
new file mode 100644
index 0000000..1353dc0
--- /dev/null
+++ b/js/gmap_views_ajax.js
@@ -0,0 +1,45 @@
+// $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);
+ });
+ }
+ };
+});
+