Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load once example pattern #1

Open
frank-dspeed opened this issue Nov 16, 2017 · 0 comments
Open

Only load once example pattern #1

frank-dspeed opened this issue Nov 16, 2017 · 0 comments

Comments

@frank-dspeed
Copy link
Member

blog = {};
blog.comments = blog.comments || {};
blog.comments.debugMode = false;

blog.isFirstLoad = function(namesp, jsFile) {
    var isFirst = namesp.firstLoad === undefined;
    namesp.firstLoad = false;
    
    if (!isFirst) {
        console.log(
            "Warning: Javascript file is included twice: " + 
                jsFile);
    }

    return isFirst;
};


$(document).ready(function () {
    if (!blog.isFirstLoad(blog.comments, "comments.js")) {
        return;
    }

    // normal event handling stuff.
    $("#nameIt").click(function(e) {
        var name= $("input[type=text]").val();    
        $("#nameOut")
            .append("<div>Hi there " + name + "</div>");
    });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant