Search code examples
javascriptobjectobject-literal

Cant figure out how to setup object literal JS Organization


I just read this tutorial: http://rmurphey.com/blog/2009/10/15/using-objects-to-organize-your-code/

Im trying to setup a function in object literal format (to be common and reusable). But I cant seem to get it working? Anyone see issues with my code?

    // Generic Email Signup via Bronto
var emailSignup = {
    'config' : {
        // Configurable Options
        'container' : $('#email-signup'),
        'emailButton' : $('#email-submit'),
        'emailErrorContainer' : $('#email-error'),
        'emailInput' : $('#mail-signup-input'),
        'brontoDirectAddURL' : 'http://app.bronto.com/public/?q=direct_add&fn=Public_DirectAddForm&id=cczmcguxestyqabxqmbvwznavplrbom&email=',
        'brontoListID' : '0bbc03ec000000000000000000000003287b',

        // configurable function for getting
        // a URL for loading item content

    },
    'init' : function(config) {
        // stays the same
        // provide for custom configuration via init()
        if (config && typeof(config) == 'object') {
            $.extend(emailSignup.config, config);
        }

        // create and/or cache some DOM elements
        // we'll want to use throughout the code
        emailSignup.$container = emailSignup.config.container;
        emailSignup.$errorContainer = emailSignup.config.emailErrorContainer;
        emailSignup.$button = emailSignup.config.emailButton;
        emailSignup.$input = emailSignup.config.emailInput;


        // Add email track to drop image pixel into for submission
        emailSignup.$errorContainer.append('<div class="track"></div>');

        // Call getEmail
        emailSignup.getEmail(emailSignup.$button);

        // make a note that the initialization
        // is complete; we don't strictly need this
        // for this iteration, but it can come in handy
        emailSignup.initialized = true;

    },
    'getEmail' : function($button) { 

        // click event
        emailSignup.$button.click(function(){
            console.log('test click');
        });   

    },
    'validateEmail' : function() { 

        var $emailRegEx = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var $emailVal = emailSignup.$input.val();

    },
    'submitEmail' : function($emailVal) {
            $(".track").html('<img src="http://app.bronto.com/public/?q=direct_add&fn=Public_DirectAddForm&id=cczmcguxestyqabxqmbvwznavplrbom&email=' +  email + '&list1=0bbc03ec000000000000000000000003287b" width="0" height="0" border="0" alt=""/>');
     },
};

$(document).ready(function() {
    emailSignup.init({ 'emailInput' : '#email-input' });
});

Solution

  • Nevermind, it seems to be working fine.