pida
v1.0.16
Published
tiny library like jQuery without any dependencies 一个很小的jquery类似的库,用了jquery类似的查询语法,没有依赖
Downloads
7
Maintainers
Readme
Pida
Terribly small javascript library ,up to 5k (gziped)
- Chrome or other supported:( no IE )
- Browser side only,not for node.js
Installation:
yarn add pida
or
npm install --save pida
Example of document query
import pida from 'pida'
pida.onDomReady(()=>{
console.dir(pida.$("a").length)
pida.addListener(pida.$("a"),"click",(evt)=>{
console.log(evt.target);
})
pida.each(pida.$("a"),(item)=>{
console.log(item);
})
console.dir(pida)
})
vite demo project:https://github.com/gotapi/pida-demo
ajax get request
pida.get("https://ip4.dev/myip?format=json",{
"on":{
"load":(progress)=>{
console.log("onload")
},
"loaded":(progress)=>{
console.log("onloaded")
}
}
}).then((data)=>{
console.log(data);
}).catch((err)=>{
console.log("got error")
console.log(err);
});
ajax post request
let data = new FormData()
data.append("title","hello")
pida.post("https://example.org/",{
headers:{
"secret":"this is secret"
}
},
data
).then((resp)=>{
console.log("got resp:")
console.log(resp)
}).catch((err)=>{
console.log("got error")
console.log(err)
});
example for post x-www-form-urlencoded data:
let formSend = "type=json&url=" + encodeURIComponent(location.href) + "&content=" + encodeURIComponent("Hellobaby");
pida.post("https://gotapi.net/v3/api/text2pic", {
"timeout": 15000,
"headers": {
"secret": secret,
"Content-Type": "application/x-www-form-urlencoded"
}
},
formSend).then((data) => {});
hide/show/toggle
pida.$("a[href]").toggle()
html/val/text
pida.$("p").html("same text")
attr
//when you try to getAttributes,return the first
pida.$("input").attr("value")
pida.$("href").attr("link","/index")
addClass/removeClass
pida.$("p").addClass("bigger")
pida.$("p").removeClass("blue-text")
usage of event binding
pida.$("a[href]").on("click", (evt) => {
evt.preventDefault();
console.log(evt.target.getAttribute("href"));
});
chainable
pida.$("a[href]").on("click",(evt)=>{ console.log(evt);}).addClass("blue").addClass("bigger")
other helpers
pida.each(iter,(element)=>{
})
pida.isArray()
pida.isObject()
pida.isString()
console.log(pida.os) //Windows or iOS or Android etc.
console.log(pida.browser) //Chrome or Opera or Microsoft Edge or Firefox etc
change log
1.0.16
在提交get/post等ajax请求时,把xhr作为参数传进去了。
1.0.15
- 一些bug修复. some bugfixs
- 文档更新.document updated;
- 优化代码,以让pida在sonarqube上的等级变为A级。code optimized to pass sonar-scanner.
1.0.14
修复在addClass时的bug
1.0.13
The behavior of html/val/attr/text is unified. When there are multiple hit objects, only the first html/val/attr/text attribute is returned. 统一了html/val/attr/text的行为,当命中对象有多个时,只返回第一个的html/val/attr/text属性。