0

You find much infos to trailing commas here: Are trailing commas in arrays and objects part of the spec?

It's about the comma at "right there".

[
        { title: "..", display: function() { return ".."; } },
        { title: "..", display: function() { return ".."; } },
        { title: "..", display: function() { return ".."; } }, // <--right there
    ]

My problem is now, that a 3rd party tool generates this list with a trailing comma and I am not able to access the sourcecode of this tool. I

<body>
my stuff
<!-- the folloging div with the javascript comes from the 3rd party -->
<div class="item"><script type="text/javascript">
$(document).ready(function() {


    $.supersized({

        // Functionality
        slide_interval          :   8000,       // Length between transitions
        transition              :   1,          // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
        transition_speed        :   400,        // Speed of transition
        fit_always              :   0,          //Prevents the image from being cropped by locking it at 100% width.
        min_width               :   600,        //min-width of images
        random                  :   0,      //random img
        vertical_center         :   1,          //vertical alignment

        // Components                           
        slide_links             :   'false',    // Individual links for each slide (Options: false, 'number', 'name', 'blank')
        slides                  :   [           // Slideshow Images

    {image : 'image1.jpg', otherstuff: 'blah', moreotherstuff: 'lorem'},

    {image : 'image2.jpg', otherstuff: 'blub', moreotherstuff: 'ipsum'},


                                    ]
    });
});
</script></div>

And now I am asking me is there any way to get this working in IE7/IE8.

The only way I see right now (as i can't edit the 3rd party and can't access it on the server) is: - give a special output without that div - request the normal side via ajax - parse everything, get this div, delete last comma and execute the javascript

that's realy not the way I want do it. Is there another way I could solve this?

2 Answers 2

3

IE7/IE8 will report 1 element bigger array length, unless you trim those arrays.

If you know all JS methods which accepts data from 3rd party you can write wrapper for them. For example:

var removeEmpty = function(array){
    var i, result = [];

    for (i = 0; i < array.length; ++i){
        if ( typeof array[i] != 'undefined' ){
            result.push(array[i]);
        }
    }

    return result;
};

$.supersized = (function() {
    var origMethod = $.supersized;

    return function(config) {
        config.slides = removeEmpty(config.slides); // get rid of undefined data in array
        return origMethod.call(this, config); // call original method
    };
}());
1
  • I did it your way. Thanks alot
    – nbar
    Oct 23, 2013 at 13:54
1

No, there is no way to get those trailing commas working in IE. It simply can't be done; it's a fundamental part of the browser's javascript parser.

This is an extremely well-known issue, which means that your third party tool is very obviously faulty and clearly hasn't been tested properly. I don't know where you got it from, but if you paid for it, I'd be complaining loudly if I were you.

If you really can't deal with the problem at source, then your only option remaining is to fix the generated code before it gets into IE. That much is easier said than done. Depending on the complexity of the generated code, you might be able to write a regex for it if it's simple and predictable, but if the code it generates is complex or of varying complexity, I suspect you may be in trouble with that idea.

Your Answer

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

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