1

I am developing mvc web application. I have added following scripts in bundle

 bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
                    "~/Scripts/jquery.js",
                    "~/Scripts/bootstrap.js",
                    "~/Scripts/jquery.dcjqaccordion.2.7.js",
                    "~/Scripts/jquery.scrollTo.min.js",
                    "~/Scripts/jquery.nicescroll.js",
                    "~/Scripts/jquery.sparkline.js",
                    "~/Scripts/assets/jquery-easy-pie-chart/jquery.easy-pie-chart.js",
                    "~/Scripts/owl.carousel.js",
                    "~/Scripts/jquery.customSelect.js",
                    "~/Scripts/respond.js",
                    "~/Scripts/slidebars.js",
                    "~/Scripts/common-scripts.js",
                    "~/Scripts/sparkline-chart.js",
                    "~/Scripts/easy-pie-chart.js",
                    "~/Scripts/count.js",
                    "~/Scripts/Main.js"));

When I run the site it is giving me this error

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'cookie'

Instead of adding these scripts in bundle if I add it on my _LayOut.cshtml then all works fine. I have added BundleTable.EnableOptimizations = true; in my Bundle.config. I am not getting where is the issue. Can someone help me to solve this? I searched that cookie keyword entire from my solution and I didn't find anything. Please see following screenshot

enter image description here

I have upgraded my scripts by using nugget command line package manager. But still my problem isn't solved. I found the script which cause an issue.

EDIT

~/Scripts/common-scripts.js this script giving me error.

Here is script code

/*---LEFT BAR ACCORDION----*/
$(function () {
    $('#nav-accordion').dcAccordion({
        eventType: 'click',
        autoClose: true,
        saveState: true,
        disableLink: true,
        speed: 'slow',
        showCount: false,
        autoExpand: true,
        //        cookie: 'dcjq-accordion-1',
        classExpand: 'dcjq-current-parent'
    });
});

// right slidebar
$(function () {
    $.slidebars();
});

var Script = function () {

    //    sidebar dropdown menu auto scrolling
    jQuery('#sidebar .sub-menu > a').click(function () {
        var o = ($(this).offset());
        diff = 250 - o.top;
        if (diff > 0)
            $("#sidebar").scrollTo("-=" + Math.abs(diff), 500);
        else
            $("#sidebar").scrollTo("+=" + Math.abs(diff), 500);
    });

    //    sidebar toggle
    $(function () {
        function responsiveView() {
            var wSize = $(window).width();
            if (wSize <= 768) {
                $('#container').addClass('sidebar-close');
                $('#sidebar > ul').hide();
            }

            if (wSize > 768) {
                $('#container').removeClass('sidebar-close');
                $('#sidebar > ul').show();
            }
        }
        $(window).on('load', responsiveView);
        $(window).on('resize', responsiveView);
    });

    $('.fa-bars').click(function () {
        if ($('#sidebar > ul').is(":visible") === true) {
            $('#main-content').css({
                'margin-left': '0px'
            });
            $('#sidebar').css({
                'margin-left': '-210px'
            });
            $('#sidebar > ul').hide();
            $("#container").addClass("sidebar-closed");
        } else {
            $('#main-content').css({
                'margin-left': '210px'
            });
            $('#sidebar > ul').show();
            $('#sidebar').css({
                'margin-left': '0'
            });
            $("#container").removeClass("sidebar-closed");
        }
    });

    // custom scrollbar
    $("#sidebar").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '' });

    $("html").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '6', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '', zindex: '1000' });

    // widget tools
    jQuery('.panel .tools .fa-chevron-down').click(function () {
        var el = jQuery(this).parents(".panel").children(".panel-body");
        if (jQuery(this).hasClass("fa-chevron-down")) {
            jQuery(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
            el.slideUp(200);
        } else {
            jQuery(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
            el.slideDown(200);
        }
    });

    // by default collapse widget
    //    $('.panel .tools .fa').click(function () {
    //        var el = $(this).parents(".panel").children(".panel-body");
    //        if ($(this).hasClass("fa-chevron-down")) {
    //            $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up");
    //            el.slideUp(200);
    //        } else {
    //            $(this).removeClass("fa-chevron-up").addClass("fa-chevron-down");
    //            el.slideDown(200); }
    //    });

    jQuery('.panel .tools .fa-times').click(function () {
        jQuery(this).parents(".panel").parent().remove();
    });

    //    tool tips
    $('.tooltips').tooltip();

    //    popovers
    $('.popovers').popover();

    // custom bar chart
    if ($(".custom-bar-chart")) {
        $(".bar").each(function () {
            var i = $(this).find(".value").html();
            $(this).find(".value").html("");
            $(this).find(".value").animate({
                height: i
            }, 2000)
        })
    }
}();
12
  • My guess is that the scripts are getting minified during the bundling process and minified variables are overwriting each other. Commented Mar 21, 2015 at 5:26
  • @MikeLoffland Thank you for reply. Burt I removed .min from scripts. Commented Mar 21, 2015 at 5:30
  • @MikeLoffland I searched that cookie keyword entire from my solution and I didn't find anything. Commented Mar 21, 2015 at 5:32
  • If you set BundleTable.EnableOptimizations = false and you don't get the error... It proves that minification is the cause. Commented Mar 21, 2015 at 5:48
  • Scripts/jquery.scrollTo.min.js Commented Mar 21, 2015 at 5:51

1 Answer 1

1

Looking at the source of that dcjqAccordian, it tries to call $.cookie to save it's state. You'll need to add jQuery.Cookie as a script for that to work: https://github.com/carhartl/jquery-cookie or https://www.nuget.org/packages/jquery.cookie/

So, your bundle will look something like:

bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
                    "~/Scripts/jquery.js",
                    "~/Scripts/jquery.cookie.*",
                    "~/Scripts/bootstrap.js",
                    "~/Scripts/jquery.dcjqaccordion.2.7.js",
                    ... etc.

As an aside, I would avoid using a plain "jquery.js" reference; assuming you're using the NuGet package, you would normally use:

bundles.Add(new ScriptBundle("~/bundles/adminscripts").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery.cookie.*",
                    "~/Scripts/bootstrap.js",
                    "~/Scripts/jquery.dcjqaccordion.2.7.js",
                    ... etc.
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for reply. I have added this script to my solution. Right now it is giving me error in slidebars.
It's working now. My mistake. I entered wrong path to slidebars.js file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.