User:MateyY/Module.js

/* A module constructor plugin * Relies on jQuery * Version 1.1.1 * By MateyY * Please import */ (function($) { //Safe way to use $	$.fn.railModule = function(settings) {		var $rail = $("#WikiaRail"); //Select the wikia rail		if (!settings) settings = {}; //Evade errors		if (!settings.position) settings.position = 0;		else if (settings.position < 0) settings.position = $rail.find(".module").length + 1 + settings.position; //Negative values		var $module = $rail.find(".module:eq(" + settings.position + ")"),			$new = this.addClass("module"); //Add class that all modules have		$rail.find(".module").length <= settings.position ? $new.insertAfter($rail.find(".module:last")) : $new.insertBefore($module);		//Return an object with all jQuery methods		//As well as some rail-exclusive methods		var self = this,			moduleObject = $.extend(true,this,{ //Return first heading heading: function { var header = self.find(":header:first"); return header.length ? header : null; },				//Return plain jQuery object tojQuery: function { return $(self); }			});		return moduleObject;	}; })(jQuery);