From d503eff2e8e3645b1537ced9e014b836b0741537 Mon Sep 17 00:00:00 2001
From: Justin Ellison <justin.ellison@buckle.com>
Date: Fri, 3 Jun 2011 15:49:01 -0500
Subject: [PATCH] Issue #1177286 by justintime: plupload AJAX callback fails with Clean URL's disabled

---
 js/ng_plupload.js      |    4 ++--
 js/ng_sort_jqueryui.js |    2 +-
 node_gallery.pages.inc |    1 +
 theme/theme.inc        |    6 +++++-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/js/ng_plupload.js b/js/ng_plupload.js
index e3c2768..1af6f64 100644
--- a/js/ng_plupload.js
+++ b/js/ng_plupload.js
@@ -34,13 +34,13 @@ Drupal.behaviors.nodeGalleryPlupload = function (context) {
     }
     self.uploader.bind('FileUploaded', function () {
       if (self.uploader.total.queued == 0) {
-        window.location.href = Drupal.settings.basePath + 'node/' + self.gid + '/edit';
+        window.location.href = Drupal.settings.basePath + Drupal.settings.node_gallery.url_prefix + 'node/' + self.gid + '/edit';
       }
     });
     self.uploader.bind('BeforeUpload', function () {
       if (!self.gid || self.gid < 0) {
         // create the gallery on the fly.
-        var url = Drupal.settings.basePath + 'node-gallery/json/gallery/create/' + self.galleryType;
+        var url = Drupal.settings.basePath + Drupal.settings.node_gallery.url_prefix + 'node-gallery/json/gallery/create/' + self.galleryType;
         // we use a synchronous call here, so plupload waits for us.
         $.ajax({
           url: url,
diff --git a/js/ng_sort_jqueryui.js b/js/ng_sort_jqueryui.js
index 0dcb448..ee991e6 100644
--- a/js/ng_sort_jqueryui.js
+++ b/js/ng_sort_jqueryui.js
@@ -43,7 +43,7 @@ Drupal.behaviors.nodeGalleryInitSorting = function (context) {
 
   var nodeGalleryPresetClickHandler = function () {
     op = this.id.substring(this.id.lastIndexOf('-')+1);
-    url = Drupal.settings.basePath+'node-gallery/json/gallery/'+Drupal.settings.node_gallery.gid+'/sort/'+op;
+    url = Drupal.settings.basePath + Drupal.settings.node_gallery.url_prefix + 'node-gallery/json/gallery/' + Drupal.settings.node_gallery.gid + '/sort/' + op;
     if ($(this).hasClass("node-gallery-sort-active")) {
       url += '/1';
     }
diff --git a/node_gallery.pages.inc b/node_gallery.pages.inc
index 0de2113..b79fb57 100644
--- a/node_gallery.pages.inc
+++ b/node_gallery.pages.inc
@@ -68,6 +68,7 @@ function node_gallery_upload_image_form($gallery) {
         $settings = array(
           'gid' => $gallery->nid,
           'galleryType' => $gallery->type,
+          'url_prefix' => variable_get('clean_url', 0) > 0 ? '' : '?q=',
         );
         drupal_add_js(array('node_gallery' => $settings), 'setting');
         drupal_add_js(drupal_get_path('module', 'node_gallery') .'/js/ng_plupload.js');
diff --git a/theme/theme.inc b/theme/theme.inc
index 8709336..12aeffe 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -148,7 +148,11 @@ function theme_node_gallery_sort_images_form($form) {
   if ($form['jquery_ui_integration']['#value']) {
     jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
     drupal_add_js(drupal_get_path('module', 'node_gallery') .'/js/ng_sort_jqueryui.js');
-    drupal_add_js(array('node_gallery' => array('gid' => $form['gid']['#value'])), 'setting');
+    $settings = array('node_gallery' => array(
+      'gid' => $form['gid']['#value'],
+      'url_prefix' => variable_get('clean_url', 0) > 0 ? '' : '?q=',
+    ));
+    drupal_add_js($settings, 'setting');
     $output .= theme('node_gallery_sort_images_grid', $form['#images']);
   }
   else {
-- 
1.7.1

