Forgot to cvs add these files.
authorEarl Miles
Sat, 29 Mar 2008 00:58:35 +0000 (00:58 +0000)
committerEarl Miles
Sat, 29 Mar 2008 00:58:35 +0000 (00:58 +0000)
js/ajax_view.js [new file with mode: 0644]
theme/views-more.tpl.php [new file with mode: 0644]

diff --git a/js/ajax_view.js b/js/ajax_view.js
new file mode 100644 (file)
index 0000000..609faa2
--- /dev/null
@@ -0,0 +1,142 @@
+// $Id$
+
+/**
+ * @file ajaxView.js
+ *
+ * Handles AJAX fetching of views, including filter submission and response.
+ */
+
+Drupal.Views.Ajax = Drupal.Views.Ajax || {};
+
+/**
+ * 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.Views.Ajax.ajaxViewResponse = function(target, response) {
+
+  if (response.debug) {
+    alert(response.debug);
+  }
+
+  // Check the 'display' for data.
+  if (response.status && response.display) {
+    var view = $(target).replaceWith(response.display).get(0);
+    Drupal.attachBehaviors(view);
+  }
+};
+
+/**
+ * Ajax behavior for views. 
+ */
+Drupal.behaviors.ViewsAjaxView = function() {
+  var ajax_path = Drupal.settings.views.ajax_path;
+  // If there are multiple views this might've ended up showing up multiple times.
+  if (ajax_path.constructor.toString().indexOf("Array") != -1) {
+    ajax_path = ajax_path[0];
+  }
+  if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
+    $.each(Drupal.settings.views.ajaxViews, function(i, settings) {
+      var target;
+      $('.view-id-'+ settings.view_name +'.view-display-id-'+ settings.view_display_id +':not(.views-processed)')
+        .addClass('views-processed')
+        .each(function () {
+          target = $(this).get(0);
+        })
+        // Process exposed filter forms.
+        .find('form#views-exposed-form')
+        .each(function () {
+          var form = this;
+          // ajaxSubmit doesn't accept a data argument, so we have to
+          // pass additional fields this way.
+          $.each(settings, function(key, setting) {
+            $(form).append('<input type="hidden" name="'+ key + '" value="'+ setting +'"/>');
+          });
+        })
+        .submit(function () {
+          $('input[@type=submit]', this).after('<span class="views-throbbing">&nbsp</span>');
+          $(this).ajaxSubmit({
+            url: ajax_path,
+            type: 'GET',
+            success: function(response) {
+              // Call all callbacks.
+              if (response.__callbacks) {
+                $.each(response.__callbacks, function(i, callback) {
+                  eval(callback)(target, response);
+                });
+              }
+            },
+            error: function() { alert("An error occurred"); },
+            dataType: 'json'
+          });
+  
+          return false;
+        })
+        .end()
+        // Process pager links.
+        .find('ul.pager > li > a')
+        .each(function () {
+          var viewData = Drupal.Views.parseQueryString($(this).attr('href'));
+          $.each(settings, function (key, setting) {
+            viewData[key] = setting;
+          });
+
+          $(this)
+            .click(function () {
+              $(this).addClass('views-throbbing');
+              $.ajax({
+                url: ajax_path,
+                type: 'GET',
+                data: viewData,
+                success: function(response) {
+                  $(this).removeClass('views-throbbing');
+                  // Call all callbacks.
+                  if (response.__callbacks) {
+                    $.each(response.__callbacks, function(i, callback) {
+                      eval(callback)(target, response);
+                    });
+                  }
+                },
+                error: function() { $(this).removeClass('views-throbbing'); alert("An error occurred"); },
+                dataType: 'json'
+              });
+
+              return false;
+            });
+        })
+        .end()
+        // Process tablesort links.
+        .find('th.views-field a')
+        .each(function () {
+          var viewData = Drupal.Views.parseQueryString($(this).attr('href'));
+          $.each(settings, function (key, setting) {
+            viewData[key] = setting;
+          });
+
+          $(this)
+            .click(function () {
+              $(this).addClass('views-throbbing');
+              $.ajax({
+                url: ajax_path,
+                type: 'GET',
+                data: viewData,
+                success: function(response) {
+                  $(this).removeClass('views-throbbing');
+                  // Call all callbacks.
+                  if (response.__callbacks) {
+                    $.each(response.__callbacks, function(i, callback) {
+                      eval(callback)(target, response);
+                    });
+                  }
+                },
+                error: function() { $(this).removeClass('views-throbbing'); alert("An error occurred"); },
+                dataType: 'json'
+              });
+
+              return false;
+            });
+        });
+    });
+  }
+};
\ No newline at end of file
diff --git a/theme/views-more.tpl.php b/theme/views-more.tpl.php
new file mode 100644 (file)
index 0000000..18b0a4c
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+// $Id$
+/**
+ * @file views-more.tpl.php
+ * Theme the more link
+ *
+ * - $more_url: the url for the more link
+ *
+ * @ingroup views_templates
+ */
+?>
+
+<a href="<?php print $more_url ?>">View more</a>