From 90048f41debb04ad6d1c64f99cd42eed39bb6690 Mon Sep 17 00:00:00 2001
From: "Kolier.Li" <kolier.li@gmail.com>
Date: Sun, 24 Jun 2012 08:21:17 +0800
Subject: [PATCH] Compatible with mathjax_trigger.

---
 mathjax.js     |   64 +++++++++++++++++++++++++++++---------------------------
 mathjax.module |    5 ++++-
 2 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/mathjax.js b/mathjax.js
index 8dd4d7d..535e05a 100644
--- a/mathjax.js
+++ b/mathjax.js
@@ -3,38 +3,40 @@
 /**
  * Add MathJax support to HTML using settings variables defined in the module
  */
-(function ($) {
+(function($) {
   Drupal.behaviors.mathjax = {
-    attach: function(context, settings) { // include mathjax only after setting variables are defined
-      var mathjax = Drupal.settings.mathjax;
-    
-      // from http://www.mathjax.org/resources/docs/?dynamic.html
-      var script = document.createElement("script");
-      script.type = "text/javascript";
-
-  if (mathjax.path=='cdn') {
-    script.src  = "https://d3eoax9i5htok0.cloudfront.net/mathjax/1.1-latest/MathJax.js";
-    // script.src  = "http://cdn.mathjax.org/mathjax/latest/MathJax.js"; // unsafe clear connection
-  }
-  else {
-      script.src = mathjax.path;
-  }
-    
-      var config = 'MathJax.Hub.Config({' +
-                     'extensions: ["tex2jax.js"],' +
-                     'jax: ["input/TeX","output/HTML-CSS"],' +
-                     'tex2jax: {' +
-                       'inlineMath: [ [\'$\',\'$\'], [\'\\\\(\',\'\\\\)\'] ],' +  // look for $...$ and \(...\) as delimiters for inline math
-                       'displayMath: [ [\'$$\',\'$$\'], [\'\\\\[\',\'\\\\]\'] ],' + // look for $$...$$ and \[...\] as delimiters for display math
-                       'processEscapes: true' +
-                     '}' +
-                   '});' +
-                   'MathJax.Hub.Startup.onload();';
-    
-      if (window.opera) {script.innerHTML = config}
-                   else {script.text = config}
-    
-      document.getElementsByTagName("head")[0].appendChild(script);
+    attach : function(context, settings) { // include mathjax only after setting variables are defined
+      if (Drupal.settings.hasOwnProperty('mathjax')) {
+        var mathjax = Drupal.settings.mathjax;
+  
+        // from http://www.mathjax.org/resources/docs/?dynamic.html
+        var script = document.createElement("script");
+        script.type = "text/javascript";
+  
+        if (mathjax.path == 'cdn') {
+          script.src = "https://d3eoax9i5htok0.cloudfront.net/mathjax/1.1-latest/MathJax.js";
+          // script.src  = "http://cdn.mathjax.org/mathjax/latest/MathJax.js"; // unsafe clear connection
+        }
+        else {
+          script.src = mathjax.path;
+        }
+  
+        var config = 'MathJax.Hub.Config({' + 'extensions: ["tex2jax.js"],'
+            + 'jax: ["input/TeX","output/HTML-CSS"],' + 'tex2jax: {'
+            + 'inlineMath: [ [\'$\',\'$\'], [\'\\\\(\',\'\\\\)\'] ],' + // look for $...$ and \(...\) as delimiters for inline math
+            'displayMath: [ [\'$$\',\'$$\'], [\'\\\\[\',\'\\\\]\'] ],' + // look for $$...$$ and \[...\] as delimiters for display math
+            'processEscapes: true' + '}' + '});'
+            + 'MathJax.Hub.Startup.onload();';
+  
+        if (window.opera) {
+          script.innerHTML = config
+        }
+        else {
+          script.text = config
+        }
+  
+        document.getElementsByTagName("head")[0].appendChild(script);
+      }
     }
   };
 })(jQuery);
diff --git a/mathjax.module b/mathjax.module
index e55b357..c145332 100644
--- a/mathjax.module
+++ b/mathjax.module
@@ -20,9 +20,12 @@ function mathjax_help($path, $arg) {
  */
 function mathjax_init() {
   global $base_path;
+  
+  $active = mathjax_active() && variable_get('mathjax_enabled', TRUE);
+  drupal_alter('mathjax_active', $active);
 
   // Load Mathjax only on specified nodes
-  if (mathjax_active() && variable_get('mathjax_enabled', TRUE)) {
+  if ($active) {
     drupal_add_js(drupal_get_path('module', 'mathjax') . '/mathjax.js', 'file');
   
     // Pass variables to mathjax.js
-- 
1.7.10.msysgit.1

