rename method + add README

This commit is contained in:
a-Sansara 2015-12-17 01:33:02 +01:00
parent 5f8da5c3ef
commit 25ecaf8dfc
2 changed files with 73 additions and 9 deletions

64
README.md Normal file
View File

@ -0,0 +1,64 @@
# Svan
Svan is a small vanilla jquery-like lib for web purpose.
small : 7.2 ko in normal version, 3.4 ko in minified version
it intends to produce more usefull jquery api in pur javascript.
var s = $(selector);
### traversing
s.first()
s.last()
s.index(i) // svan specific return node matching selector at given index i
s.each(fn)
s.find(selector)
s.all() // svan specific return nodes matching selector as array
### dom
s.append(htmlStr)
s.html(htmlStr)
s.html()
s.val()
s.val(data)
s.attr(key)
s.attr(key, value)
### css
s.hasClass(cssName)
s.addClass(cssName)
s.removeClass(cssName)
s.toggle(cssName)
### event
$(document).ready
s.on(type, handler, capture)
### effects
s.fadeIn()
s.fadeIn(duration, callback)
s.fadeOut()
s.fadeOut(duration, callback)
### ajax (currently in dev)
s.ajax({
async : ...,
url : ...,
method : ...,
data : ...,
done : ...,
fail : ...,
always : ...,
before : ...,
timeout : ...,
})

View File

@ -42,40 +42,40 @@
find : function(s) {
return this.found ? [].slice.call(this.list[0].querySelectorAll(s)) : [];
},
foreach : function(f) {
each : function(f) {
if (this.found) this.list.forEach(f);
},
// Living Standard cf https://w3c.github.io/DOM-Parsing/#innerhtml
html : function(data) {
if (!data) return this.found ? this.list[0].innerHTML : ''; // assume uniq selector
else this.foreach(function(node) {
else this.each(function(node) {
node.innerHTML = data;
});
},
append : function(data) {
this.foreach(function(node) {
this.each(function(node) {
node.innerHTML += data;
});
},
on : function(type, fn, capture) {
this.foreach(function(node) {
this.each(function(node) {
node.addEventListener(type, fn, capture===true);
});
},
val : function(data) {
if (!data) return this.found ? this.list[0].value : null; // assume uniq selector
else this.foreach(function(node) {
else this.each(function(node) {
node.value = data;
});
},
attr : function(key, value) {
if (arguments.length == 1) return this.found ? this.list[0].getAttribute(key) : null; // assume uniq selector
else this.foreach(function(node) {
else this.each(function(node) {
node.setAttribute(key, value);
});
},
toggle : function(cssName) {
this.foreach(function(node) {
this.each(function(node) {
node.classList.toggle(cssName);
});
},
@ -84,12 +84,12 @@
return this.found ? this.list[0].contains(cssName) : this.found;
},
removeClass : function(cssName) {
this.foreach(function(node) {
this.each(function(node) {
if (node.classList.contains(cssName)) node.classList.toggle(cssName);
});
},
addClass : function(cssName) {
this.foreach(function(node) {
this.each(function(node) {
if (!node.classList.contains(cssName)) node.classList.toggle(cssName);
});
},