Last active
September 8, 2017 11:15
-
-
Save benzkji/7089f01afd9132ef9759d685b6b19a7c to your computer and use it in GitHub Desktop.
A simple construct for having jquery plugins with state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
first draft.