magicButtons v.1.0.0 - jQuery plugin
Version: 1.0.0.
Author: [email protected]
License: MIT
Try demo here ! Demo
Dependencies
The following plugin is based on jquery. The default icons are those of FontAwesome 5 (solid).
Get start
Inclusion
Inclusion via js
<script src="/magicBtn.js"></script>
Inclusion via compiled css
<link rel="stylesheet" href="/magicBtn.css">
Inclusion via .scss
@import "magicBtn";
New instance of plugin
/** * @param string selector - Target * @param obj options - Options to customize plugins */ $.magicBtn(selector,options);
- The first parameter represents the container on which the plugin will take effect. By default the scope is global (on all the document).
- The second parameter is an object, which contains the initialization options.
You can initialize the plugin with the following options:
options = { buttonType: 'type', // 'material','outline' rounded: false, // (bool) - add class '.round', border-radius: 5px fill: false // Just for 'outline', fill effect on button:hover }
Methods applicable to any button
1. Start loading
var options = { loadginText: 'Your loading text', loadingIcon: bool(true), icon: '<i></i>' } $('#selector').startLoading(options);
Options of this method
- The initial text is saved as an attribute:
<button data-initial-text="$text">$text</button>
. - Append text.
- If the 'icon' option is true then the html string is hung.
2. Result status
var options = { initialText: data-initial-text status: '',//One of success, warning, error. Empty for default. } $('#selector').resultLoading(options);
There may be four types of results:
- success:
- statusText: 'Result text'
- statusIcon: '
'
- disalbed: bool(false)
- warning
- statusText: 'Result text'
- statusIcon: '
'
- disalbed: bool(false)
- error
- statusText: 'Result text'
- statusIcon: ''
- disalbed: bool(false)
- Default: The initial text saved by attribute with the method is returned
startLoading();
3. Remove loading
var options = { text: 'Your custom text for the button' } $('#selector').removeLoading(options);
Actions of this mehod
- text: data-initial-text
- remove class: 'success','warning' or 'error'
4. Disabled status
var options = {} $('#selector').disabled(options);
Actions of this mehod
- Add class 'disabled'
- Add attribute 'disabled'
Helper classes and functions
Button block
The button has 100% width.
<button class="block"></button>
Icon rotating
If the loading icons are static, just add the rotating class.
$(selector).startLoading({ 'icon': '<i class="fas fa-cog rotating"></i>' })
Errors
Elect errors that are returned by the plugin:
- resultLoading(); If multiple states are initialized as true, returns an error can be just one (success, warning, error).