From 09669d26e23688e3edd452793c0c11af6aa77f16 Mon Sep 17 00:00:00 2001
From: svaj <svaj@1813622.no-reply.drupal.org>
Date: Thu, 20 Mar 2014 11:05:46 -0700
Subject: [PATCH] Fixes https://drupal.org/node/2221437 Supports panes with js.

---
 breakpoint_panels.module | 12 ++++++++----
 js/breakpoint_panels.js  | 19 +++++++------------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/breakpoint_panels.module b/breakpoint_panels.module
index 6ad2ed0..aefae53 100644
--- a/breakpoint_panels.module
+++ b/breakpoint_panels.module
@@ -34,7 +34,7 @@ function breakpoint_panels_menu() {
   $items['breakpoint-panels/get-pane/%'] = array(
     'title' => 'Breakpoint Panels AJAX pane handler',
     'page callback' => 'breakpoint_panels_panels_pane_handler',
-    'page arguments' => array(2),
+    'page arguments' => array(2,3),
     'access callback' => TRUE,
     'type' => MENU_CALLBACK,
   );
@@ -722,7 +722,7 @@ function breakpoint_panels_panels_pane_content_alter($content, $pane, $args, $co
  * If the pane uses context like with panelizer it can be passed as a base64 encoded serialized
  * array.
  */
-function breakpoint_panels_panels_pane_handler($encoded_context = '') {
+function breakpoint_panels_panels_pane_handler($encoded_context = '', $element_id='') {
   // Make sure required ctools functions/methods will be available.
   ctools_include('plugins', 'panels');
   ctools_include('content');
@@ -796,8 +796,12 @@ function breakpoint_panels_panels_pane_handler($encoded_context = '') {
     'pane' => $pane,
     'display' => $display,
   );
-  echo theme('panels_pane', $variables);
-  drupal_exit();
+  $replace = theme('panels_pane', $variables);
+
+  $commands = array();
+  $commands[] = ajax_command_replace('#'.$element_id, $replace);
+  $page = array('#type' => 'ajax', '#commands' => $commands);
+  ajax_deliver($page);
 }
 
 /**
diff --git a/js/breakpoint_panels.js b/js/breakpoint_panels.js
index 0e1a345..fca7877 100644
--- a/js/breakpoint_panels.js
+++ b/js/breakpoint_panels.js
@@ -279,19 +279,14 @@
       /**
        * Does an AJAX request for the pane contents if it has not yet been loaded.
        */
-
       if (!element.hasClass('processed')) {
-        $.ajax({
-          url: url,
-          type: 'GET',
-          dataType: 'html',
-          success: function (response) {
-            // Swap out the contents of the placeholder with the actual pane contents.
-            element.replaceWith(response);
-            // Flag as processed so that it will not load again.
-            element.addClass('processed');
-          }
-        });
+        var element_settings = {};
+        element_settings.progress = {};
+        element_settings.url = url + '/' + element.attr('id');
+        var base = element.attr('id');
+        var ajax = new Drupal.ajax(base, element, element_settings);
+        ajax.eventResponse(element, 'click');
+        element.addClass('processed');
       }
 
     }
-- 
1.8.5.2 (Apple Git-48)

