Skip to content

Instantly share code, notes, and snippets.

@benzkji
Last active September 8, 2017 11:15
Show Gist options
  • Save benzkji/7089f01afd9132ef9759d685b6b19a7c to your computer and use it in GitHub Desktop.
Save benzkji/7089f01afd9132ef9759d685b6b19a7c to your computer and use it in GitHub Desktop.
A simple construct for having jquery plugins with state
var WhatEverPlugin = (function ($) {
'use strict';
var $plugins;
// public api
var api = {
reset_all: reset_all,
reset_by_selector: reset_by_selector
};
$.fn.what_ever_plugin = what_ever_plugin;
// may or may be not an auto init plugin - disable at will
$(document).ready( init );
function init() {
$('#content .filer-gui-multiupload-plugin').filer_multiupload_plugin();
};
function what_ever_plugin(custom_options) {
$plugins = this;
var i;
for (i=0; i<$plugins.length; i++) {
init_plugin($plugins[i], custom_options);
}
return this;
};
function init_plugin(plugin, custom_options) {
var $element = $(plugin);
var default_options = {};
var options = $.extend(default_options, custom_options);
var whatever_plugin_state = true;
var $buttons = $element.find(".button");
$buttons.click(on_button_click);
function on_button_click() {
}
function reset() {
}
};
// global methods!
function reset_all() {
// ...
};
function reset_by_selector( selector ) {
var plugin = $plugins.filter( selector );
plugin.reset();
};
return api;
})( jQuery );
@benzkji
Copy link
Author

benzkji commented Sep 8, 2017

first draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment