Download & Extend

Use drupal_add_js () to add javascript

Project:Views Galleriffic
Version:6.x-6.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I couldn't get this working with drupal_add_js().

I put the necessary javascript into the views-galleriffic-view.tpl.php file which does not seem like a good practice.

I left the drupal_add_js function in views-galleriffic.module so it is still actually loading.

I don't know how to add the additional info at the top of the javascript:

// We only want these styles applied when javascript is enabled
$('div.navigation').css({'width' : '300px', 'float' : 'left'});
$('div.content').css('display', 'block');

// Initially set opacity on thumbs and add
// additional styling for hover effect on thumbs
var onMouseOutOpacity = 0.67;
$('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
.hover(
function () {
$(this).not('.selected').fadeTo('fast', 1.0);
},
function () {
$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
}
);

$(document).ready(function() {
// Initialize Advanced Galleriffic Gallery
var galleryAdv = $('#gallery').galleriffic('#thumbs', {

which is where I think I got hung up.

Comments

#1

What do you mean with additional info? I think you should actually put this code in a seperate file (say views_galleriffic.js) and add it with

<?php
drupal_add_js
(drupal_get_path('module', 'views_galleriffic').'/views_galleriffic.js');
?>

#2

That makes sense. The variables from the views settings then could be added to that file. I will give it a shot.

#3

You might also want to have a look at Drupal.settings to store your settings, because then you can easily set these settings in PHP, e.g. with a value retrieved by variable_get, so you can later on expose it in a settings page.

Also, instead of using

$(document).ready(function() { }

you should use

Drupal.behaviors.viewsGallerifix = function (context) { }

See http://drupal.org/node/205296 for the reason.

#4

Thanks. This is helpful. I'll probably give it a shot in the next couple of days.

#5

Status:active» closed (fixed)

A couple of days turned into a couple of months but this has been fixed.

nobody click here