Skip to content

Instantly share code, notes, and snippets.

@timnovinger
Created March 18, 2010 17:39
Show Gist options
  • Save timnovinger/336618 to your computer and use it in GitHub Desktop.
Save timnovinger/336618 to your computer and use it in GitHub Desktop.
A basic mootools/jquery class template. See http://ryanflorence.com/object-oriented-jquery-with-mootools-pigs-take-flight/ for more information.
// ===========================================================================================================
// NAME
//
// DESCRIPTION GOES HERE
//
// Example
// Mootools style: var *name* = new *NAME*('.tooltip', {'options':'hash', 'syntax':'example'});
// jQuery style: $(element).*name*({'options':'hash', 'syntax':'example'});
//
// Options
// debug: boolean, Turns on/off debugging console.log() messages
//
// More information
// http://ryanflorence.com/object-oriented-jquery-with-mootools-pigs-take-flight/
//
// Requirements
// jQuery
// Mootools (only Native, Class, and Class Extras)
// ===========================================================================================================
*NAME* = new Class({
Implements: [Options, Debugger],
jQuery: '*NAME*',
// Set default options
options: {
debug: false
},
// =========================================================================================================
// Called once class instantiated because it's a "magical" name of "initalize"
// =========================================================================================================
initialize: function (element, options)
{
// Set options defined by defaults or user overwritten values
this.setOptions(options);
// Save the passed in element object for later manipulation
this.element = $(element);
// Turn on debugging if options declare it TRUE
if (this.options.debug === true)
{
this.debugger_initial_run = true;
this.debug('searches for => '+ $(this.element).selector +' (FOUND '+ this.element.length +')');
this.debug();
}
// Return itself, thus allowing chaining
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment