Search code examples
javascriptrating-system

Implement unlimited frequency in rating-widget.com


The rating-widget documentation writes about unlimited user rating frequency of their star rating system. But I'm not sure how to add it to the main function code.

Where can I add the line frequency=unlimited. Should be easy. But I'm a JS rookie.

(function(d, t, e, m){
    window.RW_Async_Init = function(){
        RW.init({
            huid: "336233",
            uid: "2e7de74f3aeb426c10a2087ead09259c",
            source: "website",
            options: {
                "size": "medium",
                "style": "oxygen",
                "isDummy": false
            } 
        });
        RW.render();
    };
    // Append Rating-Widget JavaScript library.
    var rw, s = d.getElementsByTagName(e)[0], id = "rw-js",
        l = d.location, 
        ck = "Y" + t.getFullYear() + "M" + t.getMonth() + "D" + t.getDate(),
        p = l.protocol,
        f = ((l.search.indexOf("DBG=") > -1) ? "" : ".min"),
        a = ("https:" == p ? "secure." + m + "js/" : "js." + m);
    if (d.getElementById(id)) return;              
    rw = d.createElement(e);
    rw.id = id; rw.async = true;
    rw.type = "text/javascript";
    rw.src = p + "//" + a + "external" + f + ".js?ck=" + ck;
    s.parentNode.insertBefore(rw, s);
}(document, new Date(), "script", "rating-widget.com/"));

Solution

  • In the options object section it describes which options you can specify, which includes frequency, so you could specify this key/value:

    frequency: RW.FREQUENCY.UNLIMITED
    

    You would specify that in the init call, in the options object, like this:

    RW.init({
        huid: "336233",
        uid: "2e7de74f3aeb426c10a2087ead09259c",
        source: "website",
        options: {
            frequency: RW.FREQUENCY.UNLIMITED, // <-- added
            "size": "medium",
            "style": "oxygen",
            "isDummy": false
        } 
    });
    

    NB: The documentation is not really complete, as the above syntax is not covered in the RW methods section, where the init call is said to need the uid as the first argument. This evidently is only one of the ways to call init, as the page you used to grab your code passes a nested object as the first (and only) argument.

    Also, it seems more inline with the main documentation to use the predefined enumerations for setting the options. So you would set the size with RW.SIZE.SMALL instead of "small".