Jump to content

User:Kagundu/js-utils/ClientTemplate.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {

    function ClientTemplate(basePath) {
        this.basePath = basePath;
    }

    ClientTemplate.prototype.getTemplatePath = function(name, extension) {
        if(typeof extension === "undefined") {
            extension = "html";
        }
        return '//wiki.riteme.site/w/index.php?title=' + this.basePath + '/' + name +'.template.' + extension + '&action=raw&smaxage=21600&maxage=86400&ctype=text/x-wiki';
    }

    ClientTemplate.prototype.getTemplate = function(name) {
        var url = this.getTemplatePath(name);
        var d = $.Deferred();
        $.get(url).done(function(data) {
            d.resolve(_.template(data));
        });
        return d;
    }

    window.ClientTemplate = ClientTemplate;
})();