I'm getting the wrong js output on my page.

<script type="text/javascript" src="/gallery2/modules/search/SearchBlock.js"></script>

<script type="text/javascript" src="/&lt;script type=&quot;text/javascript&quot; src=&quot;/gallery2/themes/PGlightbox/theme.js&quot;&gt;
&lt;/script&gt;"></script>
<script type="text/javascript" src="/gallery2/themes/PGlightbox/images/lb/js/prototype.js"></script>
<script type="text/javascript" src="/gallery2/themes/PGlightbox/images/lb/js/scriptaculous.js"></script>
<script type="text/javascript" src="/gallery2/themes/PGlightbox/images/lb/js/lightbox.js"></script>
<script type="text/javascript" src="/gallery2/themes/PGlightbox/images/lb/js/slide.js"></script>
<script type="text/javascript" src="/sites/all/modules/jquery_update/collapse-fix.js"></script>

I tried to debug it, but i'm stumped now. As you can see the 2nd line, the script src is malformed. I'm trying to find where the theme.js is being called into drupal_add_js function. I looked at the gallery_set_javascript function in the gallery_base.inc file trying to printout the javascript files, but i got all the js except for the theme.js. If you could possibly help me out. thanks alot.

Comments

profix898’s picture

If theme.js is not passed through gallery_set_javascript() then its likely to be included in the G2 theme template directly. I suggest that you start searching there.

jmai’s picture

Thanks.

thumb’s picture

I'm seeing a similar error with CSS with a few sites I'm attempting to upgrade:

<link type="text/css" rel="stylesheet" media="all" href="<style type="text/css">
.g2content { width: auto; }
.gallery-thumb { width: 170px; height: 170px; }
.gallery-album { height: 190px; }
</style>">

jmai, if you've learned anything since posting, I'd sure appreciate it if you'd share, I'll do the same :) Seems that the problem may only occur in non-standard or custom G2 themes. My issue is happening in two different hacks of Siriux.

profix898’s picture

FYI: There are two functions where the JS/CSS includes are processed:

  1. Function GalleryEmbed::parseHead() in G2 returns arrays containing the css/js/meta elements of the page (called from gallery_set_head() in Drupal)
  2. The arrays above are 'post-processed' converting the paths to Drupal-compatible format in gallery_set_javascript() or gallery_set_css()

What means, if gallery_set_* doesnt receive all elements, its likely that parseHead() failed to detect them. Can you please verify that parseHead() works correctly or post the head content of a page/theme that fails!?

thumb’s picture

In Siriux, links to external style sheets are processed properly, including the following:

{* Include this theme's style sheet *}
<link rel="stylesheet" type="text/css" href="{g->theme url="theme.css"}"/>

What isn't working are internal stylesheets, like the following:

<style type="text/css">
.content {ldelim} width: {$theme.params.contentWidth}px; {rdelim}
{if !empty($theme.params.thumbnailSize)}
{assign var="thumbCellSize" value=$theme.params.thumbnailSize+30}
.gallery-thumb {ldelim} width: {$thumbCellSize}px; height: {$thumbCellSize}px; {rdelim}
.gallery-album {ldelim} height: {$thumbCellSize+30}px; {rdelim}
 {/if}
 </style>

I think the contents between the style tags are stuffed into the href value of link tag. Shouldn't be hard to reproduce.

jmai’s picture

I'm using the PGlightbox theme.

I mod the code in the function gallery_set_head in the gallery_base.inc to the following:

    print t('HTML: ') . $html;
    list($title, $css, $javascript) = GalleryEmbed::parseHead($html);
    print t('Title: ');
    print_r($title);
    print t('JS: ');
    print_r ($javascript);
    print t('CSS: ');
    print_r ($css);

My output that I get is the following:

HTML: Title: www.badfreaks.com - Gallery JS: Array ( [0] =>  [1] =>  [2] =>  [3] =>  [4] =>  [5] =>  [6] =>  [7] => ) CSS: Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => ) HTML: Title: JS: Array ( ) CSS: Array ( [0] => )
jmai’s picture

OK I think I found my problem. The parsing of the javascript files in the gallery_set_javascript of gallery_base.inc had failed because the ending

tag was on another line.

My original html javascript include was:

<script type="text/javascript" src="/gallery2/themes/PGlightbox/theme.js">
</script>

I did a printout of the parsing and got this:

Files: Array
(
    [0] => /gallery2/modules/search/SearchBlock.js
    [1] => <script type="text/javascript" src="/gallery2/themes/PGlightbox/theme.js">
</script>
    [2] => /gallery2/themes/PGlightbox/images/lb/js/prototype.js
    [3] => /gallery2/themes/PGlightbox/images/lb/js/scriptaculous.js
    [4] => /gallery2/themes/PGlightbox/images/lb/js/lightbox.js
    [5] => /gallery2/themes/PGlightbox/images/lb/js/slide.js
)

As you can see, the index 1 doesn't get parsed correct.
The code line I need to fix is:

$files = preg_replace('/<script(.*?)src="([^"]*)"([^>]*)>(.*?)<\/script>/i', '${2}', $files);

But I think I should look at the root of the problem in Gallery2 where the themes include all the necessary files. From reading how to create a theme, the fix was in theme.tpl. Thanks for your helpful hint profix898

thumb’s picture

Thanks for sharing jmai. In my experience, calls to external JS files, like yours, keep the opening and closing script on one line. Seems like a simple fix for you, just remove the line break.

For internal stylesheets, it's a generally accepted practice by many to separate style declarations with line breaks as Siriux does. I may try to remove all line breaks to fix my problem, but I agree, it would be good to investigate further.

alexandreracine’s picture

Status: Active » Closed (fixed)

It's fine now? Good.

DEV version not supported anymore.

------------
Feel free to reopen but please look at the latest version first! It's probably fixed.

http://drupal.org/project/gallery

Closing (cleanup)