Javascript blueprint class for WordPress w. jQuery

The class

var $ = jQuery.noConflict();
 
// remap jQuery to $
(function($){
})(window.jQuery);
 
 
// remap jQuery to $ AND wait till doc loaded
jQuery(document).ready(function($){
});
 
 
function My_Class() {
    // private properties
    var privateProp = 'private property';
 
    this.post_id = 0;
    this.post_type = '';
    this.baseUrl = '/';
 
    // public properties
    this.publicProp = 'public property';
 
    // privileged methods
    this.privilegedFunc = function(){ alert('privileged method'); }
 
    // private methods
    function privateFunc(){ alert('private method'); }
 
    this.showPost = function() {
    };
};
 
// public prototype properties
My_Class.prototype.prototypeProp = 'prototype property';
 
// static properties
My_Class.staticProp = 'static property'; 
 
// public method
My_Class.prototype.publicFunc = function() {
    alert('public method');
}
 
My_Class.prototype.init = function() {
	if(this.post_id > 0) 
	{
		this.showPost();
	}
}

Init in WordPress footer

	var obj;
	jQuery(document).ready(function($) {
		obj = new My_Class();
		obj.baseUrl = '<?php echo get_stylesheet_directory_uri(); ?>/';
		<?php if( (is_single() || is_singular()) && !is_front_page() ) : ?>
		obj.post_id = <?php echo $post->ID; ?>;
		obj.post_type = '<?php echo $post->post_type; ?>';
		<?php endif; ?>
		obj.init();
	});

comments

No comments yet.

Sorry, the comment form is closed at this time.