Skip to content

Commit 3bc5e91

Browse files
committed
README.md changes
1 parent 16a1c5f commit 3bc5e91

File tree

2 files changed

+95
-7
lines changed

2 files changed

+95
-7
lines changed

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# UseLessJs
2+
UseLessJs is a library with some special HTML Elements to make common operations easy. The elements will help to reduce JavaScript code.
3+
4+
## How to implement
5+
To implement UseLessJs to you project you need to link your script tag as module type. An example bellow :
6+
```html
7+
<!DOCTYPE html>
8+
<html lang="en">
9+
<head>
10+
<meta charset="UTF-8">
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12+
<title>How to implement</title>
13+
</head>
14+
<body>
15+
<!-- Other tags -->
16+
<script src="/lib/useless.js" type="module"></script>
17+
</body>
18+
</html>
19+
```
20+
21+
22+
23+
## Currently this library has 6 special elements.
24+
25+
### <form-submit></form-submit>
26+
This element helps you to submit form data to backend without refresh and JavaScript. This only support GET & POST Requests. Here an example below :
27+
28+
```html
29+
<!-- You need to wrap your form with the element -->
30+
<form-submit url="http://localhost:9000/test-submit" method="get" response="myfunc">
31+
<form>
32+
<input type="email" name="email"/>
33+
<input type="password" name="password"/>
34+
<button>Submit</button>
35+
</form>
36+
</form-submit>
37+
<script>
38+
function myfunc(response){
39+
console.log(response); // You can get response from server with callback function.
40+
}
41+
</script>
42+
```
43+
44+
### <fetch-data><fetch-data>
45+
This element helps you to fetch data like posts from backend server without any JavaScript.
46+
47+
```html
48+
<!-- You need to wrap your item with the element -->
49+
<fetch-data src="https://api.thecatapi.com/v1/images/search?limit=4&breed_ids=beng&api_key=REPLACE_ME">
50+
<div class="post">
51+
<img src="{url}" width="100" height="100">
52+
<h3>{id}</h3>
53+
</div>
54+
</fetch-data>
55+
<!-- use {property_name} literal to show the JSON object property -->
56+
```
57+
58+
### <send-data></send-data>
59+
If you need to send data on button click this element will help you to do it without JavaScript. An example below:
60+
61+
```html
62+
<!-- You need to wrap your button with the element -->
63+
<send-data url="http://localhost:9000/test-submit" method="post" data-user="1" response="myfunc">
64+
<button>Send Data</button>
65+
</send-data>
66+
```
67+
68+
### <count-num></count-num>
69+
You can create counter without any JavaScript. An Example :
70+
71+
```html
72+
<count-num initial="0">
73+
<div>{value}</div>
74+
<button data-action="+" data-by="1">Increament ({value})</button>
75+
<button data-action="-" data-by="1">Decreament ({value})</button>
76+
</count-num>
77+
```
78+
79+
### <input-validate></input-validate>
80+
To validate your input data you can use the this element. You can validate input value with Regular Expressions. An Example below :
81+
82+
```html
83+
<!-- Wrap your input tag with the element, the valid/invalid attribute use to add class by valid/invalid data. -->
84+
<input-validate valid="valid" invalid="invalid" regex="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$">
85+
<input type="text" placeholder="Enter something...."/>
86+
</input-validate>
87+
```
88+
89+
### <load-script></load-script>
90+
To load script file after page load this element helps you. It's possible to set a delay to load the script on document.
91+
92+
```html
93+
<!-- Simply set your src to load js. And set after attribute to specify delay -->
94+
<load-script after="5000" src="/path/to/script.js"></load-script>
95+
```

examples/input-validate.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
<input-validate valid="valid" invalid="invalid" regex="^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$">
2323
<input type="text" placeholder="Enter something...."/>
2424
</input-validate>
25-
<script>
26-
27-
function myfunc(response){
28-
console.log(response)
29-
}
30-
31-
</script>
3225

3326
<script src="/lib/useless.js" type="module"></script>
3427

0 commit comments

Comments
 (0)