Feature can be added to Tom Select without modifying via the microplugin interface. This helps protect against code bloat, allows for leaner builds and allows for addons to be sanely isolated The plugin system is lean, makes very few assumptions, and gives the developer complete control.
Plugin Usage Without Optionsnew TomSelect('#select',{
plugins: ['plugin_a', 'plugin_b']
});
With Options
new TomSelect('#select',{
plugins: {
'plugin_a': { },
'plugin_b': { }
}
});
For a more detailed description of plugin option formats and how the plugin system works, check out the microplugin documentation.
Including PluginsPlugins can be included in your projects in four different ways:
tom-select.complete.jsUsing tom-select.complete.js
in your projects will give you immediate access to all plugins
Save some bandwidth with a bundle that's about 4kb smaller. tom-select.popular.js
includes dropdown_input, remove_button, no_backspace_delete, and restore_on_backspace plugins.
If you don't need any plugins, or want to load plugins individually, use tom-select.base.js
.
Add plugins to your project by including their js files and calling TomSelect.define
.
import TomSelect from 'tom-select/base';
import TomSelect_remove_button from 'tom-select/plugins/remove_button.js';
import TomSelect_dropdown_header from 'tom-select/dropdown_header.js';
TomSelect.define('remove_button', TomSelect_remove_button);
TomSelect.define('dropdown_header', TomSelect_dropdown_header);
Alternatively you can require
plugins directly if your build tool supports it.
import TomSelect from 'tom-select/base';
TomSelect.define('remove_button', require('tom-select/plugins/remove_button.js'));
TomSelect.define('dropdown_header', require('tom-select/plugins/dropdown_header.js'));
tom-select.custom.js
Use NPM to hand-pick plugins and create /dist/js/tom-select.custom.js
git clone https://github.com/orchidjs/tom-select.git
cd tom-select
npm install
npm run build -- --plugins=remove_button,restore_on_backspace
Creating Plugins
A few notes:
/[a-z_]+$
TomSelect.define
directly, this is done when importing the plugin.setup()
method (see "DOM Events").
export default function(plugin_options) {
};
Adding Dependencies
export default function(plugin_options) {
this.require('another_plugin');
};
Method Hooks
Execute plugin code 'before' or 'after' existing methods
export default function(plugin_options) {
this.hook('after', 'setup', function() {
});
};
Overriding Methods
Use the 'instead' hook to override existing methods.
Note: If the method you're overriding returns a value, make sure the overridden function returns a value as well.
export default function(plugin_options) {
var original_setup = this.setup;
this.hook('instead', 'setup', function() {
return original_setup.apply(this, arguments);
});
};
DOM Events
If you want to add event listeners to dom elements, add them after the setup()
method.
export default function(plugin_options) {
this.hook('after', 'setup', function() {
this.control.addEventListener('click',function(evt){
alert('the control was clicked');
});
});
};
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4