2

I'm using OSClass. when goto http://localhost/osclass/index.php?page=item&id=2 page, that gives following ERROR.

Uncaught ReferenceError: jQuery is not defined 
(anonymous function) 

Uncaught TypeError: Object [object Object] has no method 'fancybox' 
(anonymous function)
o 
p.fireWith 
e.extend.ready 
c.addEventListener.B 

Uncaught TypeError: Cannot call method 'create' of undefined
(anonymous function)

in that file my js are,

osc_register_script('fancybox', osc_current_web_theme_js_url('fancybox/jquery.fancybox.js'));

osc_enqueue_script('fancybox');
osc_enqueue_script('jquery-validate');

osc_enqueue_style('fancybox', osc_current_web_theme_js_url('fancybox/jquery.fancybox.css'));

and

    <script type="text/javascript">
        $(document).ready(function(){
            $("a[rel=image_group]").fancybox({
                openEffect : 'none',
                closeEffect : 'none',
                nextEffect : 'fade',
                prevEffect : 'fade',
                loop : false,
                helpers : {
                        title : {
                                type : 'inside'
                        }
                }
            });
        });
    </script>

Where is my problem?

leppie
  • 115,091
  • 17
  • 196
  • 297
KarSho
  • 5,699
  • 13
  • 45
  • 78

2 Answers2

1

jQuery is not loaded when the script that is throwing the error tries to use it. The errors that follow the first all stem from jQuery not being defined.

jQuery needs to be loaded before anything else that may depend on it.

Since you are using those functions to load things you need to place, prior to any other javascript that may conceivably need jQuery:

osc_register_script('jquery', osc_assets_url('path/to/jquery.js'));
osc_enqueue_script('jquery');

From looking at some other code related to what you are using you might also be able to use the following instead (this depends on the rest of your code... I'm just throwing this out as you don't really show us much... the enqueue function is likely a better choice):

<script type="text/javascript" src="<?php echo osc_current_web_theme_js_url('jquery.js') ; ?>"></script>
rg88
  • 20,742
  • 18
  • 76
  • 110
1

I fixed it this morning, here's the commit : https://github.com/osclass/Osclass/commit/cd9f75080f42d681be2e6bce709269073c0bcec2

The problem was that fancybox's dependencies weren't set

CONEJO
  • 388
  • 1
  • 11
  • 1
    This is a less detailed version of the answer below which was given 4 hours before yours. Not sure how it got accepted, no offense. – AlienWebguy Mar 04 '13 at 19:19
  • Because JQuery was already being registered/enqueue (in oc-load.php file), the problem was that fancybox has not set the dependencies, and it was being loaded before jquery. The correct fix was to set the dependencies (so fancybox will be loaded AFTER jQuery). – CONEJO Mar 05 '13 at 10:51