Library that make document manipulation a lot easier
npm install eyjseye or e, manipulate DOM elements with ease while keeping your code organized and well readable.yeap that's me! @yousef_neji
Check changelog for more informations
check
``JavaScript
// commonjs
var e = require('eyjs');
// ESM
import e from "eyjs";
`
Selecting an element
`JavaScript`
// div id="bar"
let bar = e("div#bar");
// all spans with class="list-item"
let listItem = e("span.list-item");
// all elements with class ".fools"
let fools = e(".fools");
// using ! only return the first occurence
let firstButton = e(".btns!");
Creating elements Extra functionalities baron baron.attr("contentEditable","true"); // manipulating atributes baron.on("click",cb); // events handling baron.child(0); // getting child number 0 baron.client("width") // get client specific informations "width" "height" "left" or "top" You can modify the way you use customInp.redefine("text",(action, value, elm)=>{ Serializing is transcoding form inputs data into an appropriate string format that you can send over the network to the server. let opts = { let data = form.serialize(opts); - description: models used to create elements similar to react components except easier to manager, you can create basic blueprint using where // do ajax stuff // try to avoid using this attribute unless
`JavaScript
let baron = e("",{
text: "leave",
parent: bar,
class: "btn button_dark", // also accepts array for multiple class setting at once or string concatenation of them with spaces between
data: { // setting dataset values
index: 12,
manMap: "off"
}
},{
backgroundColor: "red",
color: "white"
})
``JavaScriptfalse
// the most amazing functionalities is that u can chain calls
baron
.hide() // display: none
.show(customStyle); // display: inline-block or custom style
.data("name","yousef neji"), // more powerfull than dataset, using WeakMaps!
.data("name"); // deleting a key
baron.attr("style",false); // will remove the attribute style`
baron.rAttr("style"); // or you could simply use rAttr
baron.attr("data-index"); // setting or getting dataset values
baron.delegate("click",".body", cb); // events delegation
baron.click(cb); // triggering or handling events
baron.childlen // getting children length.textRedefine set/get features of .text and .val
and .val using .redefine`JavaScript`
let customInp = e('div',{ class: "custom-inp", parent: form });
if(action == "set"){
return value.join(" || ");
} else if(action === "get") {
return value.split(" || ");
}
}).serializeSerializing form elements fn
( param : opts )opts.inputs
The function will select all sub inputs, select, textarea elements and return their values, in order to narrow the selection you can pre-define the inputs you want to select in , which also offers custom-input & custom-getter as follow:custom-inputs
- : When your form contains custom inputs(div with special input features for example), you define them in the opts.inputs by a selector like .special-input, #specialinp... etc.custom-getters
- : the naming convention is only for explainatory purpose, this feature basically nameless, It's the ability to provide a custom way to subtract the data of certain input/custom, by defining a function with the name of that input/custom, here's how u do it:opts.[fieldname]
- : (inp) => inp.child(0).val();`
html``javascriptv
let form = e('form.createUser');
// optionally identify the inputs to serialize adding custom inputs
inputs: ['input','select','.custom-input'],
hobby: (inp)=>{
let v = [];
// this will select the custom-input .list>span spans
// get their values and push it into array.`
e(inp.find(".list>span")).each(span => v.push(span.textContext));
// then return the value as string by joining it using ','
return v.join(',');
}
}
// send data over network using jcall/fetch/axios ...~Models~e("model:youModelName", blueprint), later on, you use the returned constructor over and over when ever the need calls!blueprint
- how it works:
- include the "model:\_model_name\_".
- define your :blueprint
- a is an object containing nested objects that defines each component of your model,blueprint
- a element is formed by tagname
[.classname1.classname2: _index - default_value], _index(must contain the _) represent a datacell to display data later, and default_value will be set if no data passed.`
- Usuage:
javascriptdefault
let failMessage = e("model:FailMessage", {
"div.head": {
"div.title: _title - Big Fancy Title": {},
"div.close": {}
},
"div.body": {
"p.message: _message - no message": {},
"div.details: _details - no details": {},
"div.actions": {
"button.ok: _ok - OK": {},
"button.cancel: _cancel - Cancel": {}
}
}
})
fetch()
.then()
.catch((e)=>{
// create a new instance
let error = failMessage({
parent: document.body // append using parent attribute
_title: "Backend error - " + e.name,
_message: e.message,
// you want to mess up with your model
// text: "some text",
// html: "some html",
});
// or append later
error.appendTo(document.body);
// you may pre-create the error in earlier stage! before the fetch()
// and refresh it content using .refresh function
error.refresh({
_title: "Backend error - " + e.name,
_message: e.message
})
// refresh also accepts an attribute (set true by default)_message
// which adjut whether to update all datacells of the model
// or only update the one passed through the function
// EXAMPLE:
error.refresh({
_title: "Other Error - " + e.name
})
// this will update _title to the new value and also update
// the other datacells like _details ..._message
// but since they're not passed they will display the default values
// from the constructor up at the top!
// => no message_details
// => no details``
// ...
// unless you passed (default: false)
error.refresh({
_title: "Other error - " + e.name,
default: true
})
// in this case only _title will be changed!
})
Copyrights
Reserved under MIT license