Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/h-gh/yii-js-event-handler

Using this Library you can add `custom events` to elements. Your `custom events` will run whenever you define.
https://github.com/h-gh/yii-js-event-handler

event javscript jquery php yii2 yii2-asset yii2-assets yii2-widget yii2-widgets

Last synced: about 1 month ago
JSON representation

Using this Library you can add `custom events` to elements. Your `custom events` will run whenever you define.

Awesome Lists containing this project

README

        




# Yii JavaScript event handler
Using this Library you can trigger your `custom events` on some another elements trigger.
![MIT License](https://img.shields.io/github/license/H-Gh/yii-js-event-handler.svg?style=flat-square)
![Code Size](https://img.shields.io/github/languages/code-size/H-Gh/yii-js-event-handler.svg?style=flat-square)
## Instalation
```
composer require hgh/yii-js-event-handler
```

## Usage
### Register Yii2 Asset
```php
YiiJsEventHandlerAsset::register($this);
```

### Instantiate jQuery Plugin
There are two way of instantiate this `jQuery` plugin.
#### Use default attributes
To use default options you have to add two predefined attribute to your `html` element. You put your custom `JS` events into `data-events-to-run`. Separate your `custom events` using `space`. Then using `data-on` specify when these `custom events` should be trigger. The values that you can put in `data-on` follows `jQuery` events. Visit [Form events](https://api.jquery.com/category/events/form-events/), [Mouse events](https://api.jquery.com/category/events/mouse-events/) and [keyboard events](https://api.jquery.com/category/events/keyboard-events/) .
```html


```

#### Define your custom attributes
In other hand, You can define your custom attributes. For this you have to `instantiate` `eventHandler` plugin.
```javascript
$(document).ready(function () {
$("[data-my-custom-on-attribute]").eventHandler({
onEventAttribute: "data-my-custom-on-attribute",
toRunEventsAttribute: "data-my-custom-to-run-events-attribute"
});
});
```
Now, you can use these attributes like this:
```html


```

## Sample
##### html
```html

Click Me to Run Custom Event

```

##### jquery
```javascript
$(document).ready(function () {
$(document).on("customEvent", function () {
alert("Custom event triggered");
});
$(document).on("anotherCustomEvent", function () {
alert("Another custom event triggered");
});});
```