5

I am a developer Magento themes but I'm still learning how to work with the theme rwd.

I am getting a javascript error (below) when I see our store smaller screens resolution.

TypeError: this.toggleElements.toggleSingle is not a function
this.toggleElements.toggleSingle();

I don't understand the function below. I have copied the rdw package files to make the package from our store and have not changed any html tag in any of these files, just added my classes for CSS usage.

enquire.register('(max-width: ' + bp.medium + 'px)', {
    setup: function () {
        this.toggleElements = $j(
            // This selects the menu on the My Account and CMS pages
            '.col-left-first .block:not(.block-layered-nav) .block-title, ' +
                '.col-left-first .block-layered-nav .block-subtitle--filter, ' +
                '.sidebar:not(.col-left-first) .block .block-title'
        );
    },
    match: function () {
        this.toggleElements.toggleSingle();
    },
    unmatch: function () {
        this.toggleElements.toggleSingle({destruct: true});
    }
});

What can be causing this error?

10

I have had the same problem. Fixed it by checking the length of the element which needs to be toggled. The best thing you could do is rewrite this javascript file in your custom Magento theme that you use and add this code.

    match: function () {
        if(this.toggleElements.length > 0){
            this.toggleElements.toggleSingle();
        }
    },
    unmatch: function () {
        if(this.toggleElements.length > 0){
            this.toggleElements.toggleSingle({destruct: true});
        }
    }
  • I had not thought of that. So simple that go unnoticed. Thank you very much. – Rone Clay Brasil Jun 9 '15 at 9:20
  • @jelle-siderius, thank you Jelle. Very helpful. – Andhi Irawan Jul 21 '16 at 9:39
8

the answer of jelle siderius doesn't work on my magento installation. I've fixed it, in changing this line

jQuery.fn.toggleSingle = function (options) {

in

$j.fn.toggleSingle = function (options) {

protected by Community Sep 22 '15 at 10:52

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.