From aadebcd45cd7d16261da00108da332e0ade595fc Mon Sep 17 00:00:00 2001
From: Angus Mak <angus.mak@lullabot.com>
Date: Mon, 3 Jun 2013 16:20:37 +0800
Subject: [PATCH] Issue #2010558 by makagnus: Set JSONP Prefix the callback
 query string parameter is specified

---
 views/theme/views-views-json-style-exhibit.tpl.php | 2 ++
 views/theme/views-views-json-style-simple.tpl.php  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/views/theme/views-views-json-style-exhibit.tpl.php b/views/theme/views-views-json-style-exhibit.tpl.php
index 31f63fa..3c337c7 100644
--- a/views/theme/views-views-json-style-exhibit.tpl.php
+++ b/views/theme/views-views-json-style-exhibit.tpl.php
@@ -12,6 +12,7 @@
  */
 
 $jsonp_prefix = $options['jsonp_prefix'];
+if ($_GET['callback']) $jsonp_prefix = $_GET['callback'];
 
 if ($view->override_path) {
   // We're inside a live preview where the JSON is pretty-printed.
@@ -30,6 +31,7 @@ else {
     // We want to send the JSON as a server response so switch the content
     // type and stop further processing of the page.
     $content_type = ($options['content_type'] == 'default') ? 'application/json' : $options['content_type'];
+    if ($jsonp_prefix) $content_type = 'application/javascript';
     drupal_add_http_header("Content-Type", $content_type. '; charset=utf-8');
     print $json;
     //Don't think this is needed in .tpl.php files: module_invoke_all('exit');
diff --git a/views/theme/views-views-json-style-simple.tpl.php b/views/theme/views-views-json-style-simple.tpl.php
index 2e8fe6a..ec94813 100644
--- a/views/theme/views-views-json-style-simple.tpl.php
+++ b/views/theme/views-views-json-style-simple.tpl.php
@@ -12,6 +12,7 @@
  */
 
 $jsonp_prefix = $options['jsonp_prefix'];
+if ($_GET['callback']) $jsonp_prefix = $_GET['callback'];
 
 if ($view->override_path) {
   // We're inside a live preview where the JSON is pretty-printed.
@@ -34,6 +35,7 @@ else {
     // We want to send the JSON as a server response so switch the content
     // type and stop further processing of the page.
     $content_type = ($options['content_type'] == 'default') ? 'application/json' : $options['content_type'];
+    if ($jsonp_prefix) $content_type = 'application/javascript';
     drupal_add_http_header("Content-Type", "$content_type; charset=utf-8");
     print $json;
     //Don't think this is needed in .tpl.php files: module_invoke_all('exit');
-- 
1.7.12

