Current time: 28-03-2024, 09:17 PM
Hello There, Guest!
Login 
  • Search
  • jQuery Generate Syndication URL on the fly


    MyBB Group Developer
    #1
    jQuery 
    For those lazy heads: let's save a click!

    To generate a new syndication URL you need to click on the "Generate Syndication URL" button after choosing your desired forums, syndication version and limit. This will generate the URL on the fly in front of your eyes as you change your preference. Lets do it.

    Open the template misc_syndication and find the variable {$feedurl}. Add the following script before that:
    Note: You need to add the script before the var, not after, else jQuery will be confused to identify the element holding URL.
    <script>$(function(){var i=parseInt($("input[name=limit]").val(),10),t=[];$("input[type=submit]").hide(),$(":contains(syndication.php):last").attr("id","feedurl"),$("select[name='forums[]'], input[name='version'], input[name=limit]").on("change keyup",function(){t.fid=$("select[name='forums[]']").val(),t.fid=0===t.fid.length||0===$.inArray("all",t.fid)?"":"fid="+t.fid.join(","),t.ver=$("input[name='version']:checked").val(),t.ver=""===t.ver||"rss2.0"===t.ver?"":"type="+t.ver,t.lmt=$("input[name=limit]").val(),t.lmt="limit="+(isNaN(t.lmt)||t.lmt<1?i:t.lmt),t=[t.fid,t.ver,t.lmt].filter(function(i){return""!==i}),$("#feedurl").text(rootpath+"/syndication.php?"+t.join("&"))})});</script>
    

    Thats all.

    This will hide the "Generate Syndication URL" button, but don't worry, wee don't need that anymore.

    Now save the template. Done.

    Result:
    [Image: screen.gif]

    tl;dr:
    For the readability of the curious minds, this is the expanded version of the script (which you can also use in place of the above):
    <script type="text/javascript">
    $(function(){
        var rootLimit = parseInt($("input[name=limit]").val(), 10), param = [];
        $("input[type=submit]").hide();
        $(":contains(syndication.php):last").attr('id', 'feedurl');
        $("select[name='forums[]'], input[name='version'], input[name='limit']").on('change keyup', function(){
            param.fid = $("select[name='forums[]']").val();
            param.fid = (param.fid.length === 0 || $.inArray("all", param.fid) === 0) ? "" : "fid="+param.fid.join(",");
            param.ver = $("input[name='version']:checked").val();
            param.ver = (param.ver === "" || param.ver === "rss2.0") ? "" : "type="+param.ver;
            param.lmt = $("input[name=limit]").val();
            param.lmt = "limit=" + ((isNaN(param.lmt) || param.lmt < 1) ? rootLimit : param.lmt);
            param = [param.fid,param.ver,param.lmt].filter(function(v){return v!==''});
            $("#feedurl").text(rootpath + "/syndication.php?" + param.join("&"));
        });
    });
    </script>
    
    Like Reply