For Drupal 7, a jQuery will not load for "anonymous" users on any template pages. But when I log in as an administrator it loads. It's similar to this issue: http://drupal.org/node/802432, but nothing I tried has worked. The only way I could get the jQuery to load was by giving the user access to the administration menu, which I do not want to do.
I have the following code in the preprocess_node
function of the template.php file.
if ($variables['view_mode'] == 'full') {
$node =& $variables['node'];
if ($node->type == 'page') {
$path = drupal_get_path('theme', 'responsive');
drupal_add_js($path . '/js/jquery.snap.js', array('type' => 'file', 'scope'
=> 'header'));
drupal_add_js($path . '/js/jquery.snap2.js', array('type' => 'file', 'scope'
=>'header'));
}
}
Here is the original JS code
<script type="text/javascript">
document.write(unescape("%3Cscript src='"
+((document.location.protocol=="https:")?"https://snapabug.appspot.com":
"http: //www.snapengage.com") + "/snapabug.js' type='text/javascript
'%3E%3C /script%3E"));
</script>
<script type="text/javascript">
SnapABug.addButton("77777-7777","0","50%", true);
</script>
I put the code in two separate JS files (couldn't get it to work in a single file)
jquery.snap.js
(function($) {
document.write(unescape("%3Cscript src='"
+ ((document.location.protocol=="https:")?"https://snapabug.appspot.com":
"http: //www.snapengage.com") + "/snapabug.js' type='text/javascript
'%3E%3C /script%3E"));
})(jQuery);
jquery.snap2.js
(function($) {
SnapABug.addButton("77777-7777","0","50%", true);
})(jQuery);
When I look at the HTML source I see an error for jquery.snap2.js: "Uncaught Reference Error: SnapBug is not defined." The result is the snapabug.js is not loading. This error does not occur on the administrative side and the snapabug.js does load.