Terribly small javascript library ,up to 5k (gziped)
- Chrome or other supported:( no IE )
- Browser side only,not for node.js
yarn add pida
or
npm install --save pida
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
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);
});
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)
});
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) => {});
pida.$("a[href]").toggle()
pida.$("p").html("same text")
//when you try to getAttributes,return the first
pida.$("input").attr("value")
pida.$("href").attr("link","/index")
pida.$("p").addClass("bigger")
pida.$("p").removeClass("blue-text")
pida.$("a[href]").on("click", (evt) => {
evt.preventDefault();
console.log(evt.target.getAttribute("href"));
});
pida.$("a[href]").on("click",(evt)=>{ console.log(evt);}).addClass("blue").addClass("bigger")
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
在提交get/post等ajax请求时,把xhr作为参数传进去了。
- 一些bug修复. some bugfixs
- 文档更新.document updated;
- 优化代码,以让pida在sonarqube上的等级变为A级。code optimized to pass sonar-scanner.
修复在addClass时的bug
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属性。