Skip to content

Instantly share code, notes, and snippets.

@cbourdage
Created March 17, 2014 22:06
Show Gist options
  • Select an option

  • Save cbourdage/9609359 to your computer and use it in GitHub Desktop.

Select an option

Save cbourdage/9609359 to your computer and use it in GitHub Desktop.
General Gorilla Plugin Syntax
;
/**
* Gorilla manufacturers.js
* Copyright 2013 Gorilla Group.
*
* Standard Tab plugin. Works with the following
* conventions on the tabs themselves:
* - current tab index (within tabs array)
* - data-target
* - href (matching #id)
*/
if (typeof Gorilla === 'undefined') {
var Gorilla = {};
}
(function($) {
'use strict';
var _namespace = 'PluginName';
/**
* Constructor method
*/
var PluginName = this.PluginName = function(el, options) {
this.$el = $(el);
this.options = options;
this.contents = $('#' + this.$el.data('filterContent'));
this._bindEvents();
this.contents.find('.item').addClass('out');
this.transIn(this.$el.find('.active'));
};
PluginName.defaults = {
};
PluginName.prototype = {
/**
* Binds events to elements
*/
_bindEvents : function() {
},
/**
* Resets tabs back to initial state
*/
reset : function() {
this.unset();
this._bindEvents();
},
/**
* Unset all filters
*/
unset : function() {
this.$el.off('.' + _namespace);
},
/**
* Unset tab stuffs for responsive
*/
respond : function(options) {
}
};
// Plugin declaration/assignment
$.fn[_namespace] = function(options) {
var args = arguments;
options || (options = {});
return this.each(function() {
var $this = $(this),
data = $this.data(_namespace);
if (!data && typeof options === 'string') {
$this.data(_namespace, (data = new PluginName(this, $.extend({}, PluginName.defaults, Array.prototype.slice.call(args, 1)))));
} else if (!data) {
$this.data(_namespace, (data = new PluginName(this, $.extend({}, PluginName.defaults, options))));
}
if (typeof options === 'string') {
if (PluginName.prototype[options]) {
data[options].apply(data, Array.prototype.slice.call(args, 1));
} else {
console.error('Method ' + options + ' does not exist in ' + _namespace);
}
}
});
};
}).call(Gorilla, window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment