EventX-css-event
- Allow programmer to listen for css style change event.
- JQuery css style event.
Table of content
Install
Browser
NPM
npm install eventx-css-event
Events
Name | Description | Example |
---|---|---|
stylechange |
Listen to inline and media screen style change | Click |
stylechange:<...> |
Listen to inline and media screen style change (Only style <...>) | Click |
inlinestylechange |
Listen to inline style change | Click |
inlinestylechange:<...> |
Listen to inline style change (Only style <...>) | Click |
mediastylechange |
Listen to media style change | |
mediastylechange:<...> |
Listen to media style change (Only style <...>) |
Why we need this library ???
Problem statement
I want to alert "Style ... changed from ... to ..." when some css style of #ex is changed, alert "Style ... added with value ..." when some css style of #ex is added and alert "Style ... removed with old value ..." when some css style of #ex is removed (only consider inline style).
Before using this library
const target = ; const ob = { for var mutation of mutationsList if mutationtarget == target0 var curr = mutationtargetstyle; var currattr = mutationtarget; var old = mutationoldValue ? mutationoldValue : ; var styleName = null; var oldStyleValue = null; var newStyleValue = null; if oldlength > 0 && oldoldlength - 1 == "" old; if currattrlength > 0 && currattrcurrattrlength - 1 == "" currattr; if oldlength == currattrlength // style change for var _style of old var style = _style; style0 = style0; style1 = style1; if currstyle0 != style1 styleName = style0; oldStyleValue = style1; newStyleValue = currstyle0; break; else if oldlength < currattrlength // add var _old = {}; for var _style of old var style = _style; style0 = style0; style1 = style1; _oldstyle0 = style1; for var _style of currattr var style = _style; style0 = style0; style1 = style1; if !_oldstyle0 styleName = style0; oldStyleValue = ""; newStyleValue = currstyle0; break; else // remove var _curr = {}; for var _style of currattr var style = _style; style0 = style0; style1 = style1; _currstyle0 = style1; for var _style of old var style = _style; style0 = style0; style1 = style1; if !_currstyle0 styleName = style0; oldStyleValue = style1; newStyleValue = ""; break;
if styleName if oldStyleValue && newStyleValue ; else if !oldStyleValue && newStyleValue ; else if oldStyleValue && !newStyleValue ;
} }}); var config = attributes: true attributeOldValue: true attributeFilter: "style";ob;
Note: Above example require JQuery
After using this library
if eoldStyleValue && enewStyleValue ; else if !eoldStyleValue && enewStyleValue ; else if eoldStyleValue && !enewStyleValue ;
});
Note: Above example require JQuery
Difference
- First and final block obviously shorter.
- Closer to english language.
- Remember easier.
Without JQuery
evx
if eoldStyleValue && enewStyleValue ; else if !eoldStyleValue && enewStyleValue ; else if eoldStyleValue && !enewStyleValue ;
});
Yeah, still simple and easy.
Examples
Features
You can find list of event name here
On
;
evx;
- View all JQuery coding style at http://api.jquery.com/on/
- e is a Edited MutationRecord object
- this = target element (Warning: not working if you use arrow function)
- For more information about Edited MutationRecord run console.log(e) in event handler or read here
Off
;
evx
- View all JQuery coding style at http://api.jquery.com/off/
Rename Event (Solve event name conflict)
evx
Create new event type
Remove event type
Edited MutationRecord
Property Name | Type | Description |
---|---|---|
target | HTMLElement | Target element which style has been changed |
styleName | String | Name of style that has been changed |
oldStyleValue | String | Value of that style before changed |
newStyleValue | String | Value of that style after changed |
changetype | String | "inline" if inline change or "media" if media change |
License
Released under the MIT License Copyright © 2018 Chomtana