?
avatar ivsero
ivsero
27 Mar 2016

Steps to reproduce the issue

https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/html/behavior.php contain the following code:

// Attach caption to document
JFactory::getDocument()->addScriptDeclaration(
    "jQuery(window).on('load',  function() {
    new JCaption('" . $selector . "');
    });"
);

but in https://github.com/joomla/joomla-cms/blob/staging/media/system/js/caption.js JCaption - now is function:

var JCaption = function(c) {
    var e, b, a = function(f) {
            e = jQuery.noConflict();
            b = f;
            e(b).each(function(g, h) {
                d(h)
            })
        },
        d = function(i) {
            var h = e(i),
                f = h.attr("title"),
                j = h.attr("width") || i.width,
                l = h.attr("align") || h.css("float") || i.style.styleFloat || "none",
                g = e("<p/>", {
                    text: f,
                    "class": b.replace(".", "_")
                }),
                k = e("<div/>", {
                    "class": b.replace(".", "_") + " " + l,
                    css: {
                        "float": l,
                        width: j
                    }
                });
            h.before(k);
            k.append(h);
            if (f !== "") {
                k.append(g)
            }
        };
    a(c)
};

Expected result

I expect to see class in caption.js or function call in behavior.php

Actual result

As a result some functions doesn't work correctly. We have the following code:

<script language="javascript" type="text/javascript"> 
$(document).ready(function () { 

$('a.menu_class3').click(function () { 
$('ul.the_menu3').slideToggle('medium'); 

}); 
}); 
</script>

Now object $('ul.the_menu3') is null and we see error-message in browser developer console:

TypeError: $(...) is null.

When we replace older version of caption.js from Joomla 3.1.5 (where JCaption() - is class) all works correctly.

avatar ivsero ivsero - open - 27 Mar 2016
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of JCaption() but in it's function in caption js
behavior.php initializate instanse of class JCaption() but in it's function in caption js
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of JCaption() but in it's function in caption js
behavior.php initializate instanse of class JCaption() but in it's function in caption js
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of class JCaption() but in it's function in caption js
behavior.php initializate instanse of class JCaption() but it's function in caption js
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of class JCaption() but in it's function in caption js
behavior.php initializate instanse of class JCaption() but it's function in caption js
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of class JCaption() but it's function in caption js
behavior.php initializate instanse of class JCaption() but it's function in caption.js
avatar ivsero ivsero - change - 27 Mar 2016
Title
behavior.php initializate instanse of class JCaption() but it's function in caption js
behavior.php initializate instanse of class JCaption() but it's function in caption.js
avatar ivsero ivsero - change - 27 Mar 2016
The description was changed
avatar ivsero ivsero - change - 27 Mar 2016
The description was changed
avatar Fedik
Fedik - comment - 27 Mar 2016

JCaption - now is function ...
I expect to see class in caption.js or function call in behavior.php

oh man, I just leave it here
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function

avatar Fedik
Fedik - comment - 27 Mar 2016

And you should not use $ globally.
The issue is invalid, from my point of view.

avatar ivsero
ivsero - comment - 27 Mar 2016

@Fedik Thank you for links, but I know about "new" operator usage for Function objects in JavaScript.
I'll try to replace code

<script language="javascript" type="text/javascript">
$(document).ready(function () {

$('a.menu_class3').click(function () {
$('ul.the_menu3').slideToggle('medium');

});
});
</script> 

on

<script language="javascript" type="text/javascript">
jQuery(document).ready(function () {

jQuery('a.menu_class3').click(function () {
jQuery('ul.the_menu3').slideToggle('medium');

});
});
</script> 

and situation changed. It seems to help solve my problem.

avatar Fedik
Fedik - comment - 27 Mar 2016

then please close the issue, because it not Joomla! issue

avatar ivsero ivsero - change - 27 Mar 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-03-27 13:55:33
Closed_By ivsero
avatar ivsero ivsero - close - 27 Mar 2016

Add a Comment

Login with GitHub to post a comment