amend prepend + add minified version

This commit is contained in:
a-Sansara 2015-12-28 00:00:54 +01:00
parent f4c8bcb014
commit d806e94d6a
2 changed files with 2 additions and 2 deletions

2
src/svan-min.js vendored
View File

@ -1 +1 @@
/* by a-sansara - v 0.4 - https://github.com/pluie-org/svan */!function(){var t=function(t,n){return typeof t==n},n=function(t,i){return new n.init(t,i)},i=n.isNone=function(n){return t(n,"undefined")},e=n.isStr=function(n){return t(n,"string")},s=n.isFunc=function(n){return t(n,"function")},o=n.isObj=function(n){return t(n,"object")},a=n.isNode=function(t){return o(t)&&!i(t.nodeType)},c=n.isWin=function(t){return o(t)&&!i(t.window)&&t.window==t};n.prototype={regsan:function(t){return t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},first:function(){return this.found?this.list[0]:null},last:function(){return this.found?this.list[this.list.length-1]:b},index:function(t){return this.found&&t>0&&t<this.list.length?this.list[t]:b},all:function(){return this.list},find:function(t){return this.found?[].slice.call(this.list[0].querySelectorAll(t)):[]},foreach:function(t){this.found&&this.list.forEach(t)},html:function(t){return t?void this.foreach(function(n){n.innerHTML=t}):this.found?this.list[0].innerHTML:""},append:function(t){this.foreach(function(n){n.innerHTML+=t})},on:function(t,n,i){this.foreach(function(e){e.addEventListener(t,n,i===!0)})},val:function(t){return t?void this.foreach(function(n){n.value=t}):this.found?this.list[0].value:null},attr:function(t,n){return 1==arguments.length?this.found?this.list[0].getAttribute(t):null:void this.foreach(function(i){i.setAttribute(t,n)})},toggle:function(t){this.foreach(function(n){n.classList.toggle(t)})},hasClass:function(t){return this.found?this.list[0].contains(t):this.found},removeClass:function(t){this.foreach(function(n){n.classList.contains(t)&&n.classList.toggle(t)})},addClass:function(t){this.foreach(function(n){n.classList.contains(t)||n.classList.toggle(t)})},fadeIn:function(t,n,i){if(this.found){t||(t=this.FADE_DURATION);var e=parseFloat(1/t*20),s=this.first();s.style.opacity=0,s.style.display=i||"block",function t(){var i=parseFloat(s.style.opacity);(i+=e)<1?(s.style.opacity=i,requestAnimationFrame(t)):"function"==typeof n&&n.call(s)}(t)}},fadeOut:function(t,n){if(this.found){t||(t=this.FADE_DURATION);var i=parseFloat(1/t*20),e=this.first();e.style.opacity=1,function t(){var s=parseFloat(e.style.opacity);(s-=i)<0?(e.style.display="none","function"==typeof n&&n.call(e)):(e.style.opacity=s,requestAnimationFrame(t))}(t)}},ready:function(t){this.context.addEventListener("DOMContentLoaded",t)}},n.eachObj=function(t,n,i){for(var e in t)t.hasOwnProperty(e)&&n.call(i,e,t[e])},n.ajax=function(t){this.eachObj(t,function(t,n){console.log(t),console.log(n)});var n=new XMLHttpRequest;n.onreadystatechange=function(n){4==this.readyState&&(200==this.status?s(t.done)&&t.done.call(t.context,n,this.responseText,this.statusText):s(t.fail)&&t.fail.call(t.context,n,this.responseText,this.statusText),s(t.always)&&t.always.call(t.context,n,this.responseText,this.statusText))},!i(t.timeout)&&t.async&&(n.timeout=t.timeout),s(t.before)&&t.before.call(n),n.open(t.method,t.url,t.async),n.setRequestHeader("Content-Type","application/x-www-form-urlencoded");var e="";o(t.data)&&this.eachObj(t.data,function(t,n){e+=t+"="+encodeURIComponent(n)}),n.send(e)};var u=n.init=function(t,n){return this.FADE_DURATION=700,this.VERSION=.4,this.context=i(n)?document:n,this.list=e(t)?[].slice.call(this.context.querySelectorAll(t)):a(t)||c(t)?[t]:[],this.found=this.list.length>0,this};u.prototype=n.prototype,window.Svan=n,i(window.$)&&(window.$=n)}();
/* by a-sansara - v 0.4 - https://github.com/pluie-org/svan */!function(){var is=function(o,intent){return typeof o==intent},Svan=function(selector,context){return new Svan.init(selector,context)},isNone=Svan.isNone=function(o){return is(o,"undefined")},isStr=Svan.isStr=function(o){return is(o,"string")},isFunc=Svan.isFunc=function(o){return is(o,"function")},isObj=Svan.isObj=function(o){return is(o,"object")},isNode=Svan.isNode=function(o){return isObj(o)&&!isNone(o.nodeType)},isWin=Svan.isWin=function(o){return isObj(o)&&!isNone(o.window)&&o.window==o};Svan.prototype={regsan:function(v){return v.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},first:function(){return this.found?this.list[0]:null},last:function(){return this.found?this.list[this.list.length-1]:b},index:function(i){return this.found&&i>0&&i<this.list.length?this.list[i]:b},all:function(){return this.list},find:function(s){return this.found?new Svan.init(s,this.list[0]):new Svan.init("")},each:function(f){this.found&&this.list.forEach(f)},html:function(data){return data?void this.each(function(node){node.innerHTML=data}):this.found?this.list[0].innerHTML:""},append:function(data){this.each(function(node){node.innerHTML+=data})},prepend:function(data){if(this.found)if(isStr(data)){var div=document.createElement("div");for(div.innerHTML=data;null!=div.lastChild;)this.first().insertBefore(div.lastChild,this.first().firstChild)}else{var div=isStr(data)?document.createElement("div"):data;this.first().insertBefore(data,this.first().firstChild)}},on:function(type,fn,capture){this.each(function(node){node.addEventListener(type,fn,capture===!0)})},val:function(data){return data?void this.each(function(node){node.value=data}):this.found?this.list[0].value:null},attr:function(key,value){return 1==arguments.length?this.found?this.list[0].getAttribute(key):null:void this.each(function(node){node.setAttribute(key,value)})},toggle:function(cssName){this.each(function(node){node.classList.toggle(cssName)})},hasClass:function(cssName){return this.found?this.list[0].classList.contains(cssName):this.found},removeClass:function(cssName){this.each(function(node){node.classList.contains(cssName)&&node.classList.toggle(cssName)})},addClass:function(cssName){this.each(function(node){node.classList.contains(cssName)||node.classList.toggle(cssName)})},fadeIn:function(duration,fn,display){if(this.found){duration||(duration=this.FADE_DURATION);var inc=parseFloat(1/duration*20),n=this.first();n.style.opacity=0,n.style.display=display||"block",function fade(){var val=parseFloat(n.style.opacity);(val+=inc)<1?(n.style.opacity=val,requestAnimationFrame(fade)):"function"==typeof fn&&fn.call(n)}(duration)}},fadeOut:function(duration,fn){if(this.found){duration||(duration=this.FADE_DURATION);var inc=parseFloat(1/duration*20),n=this.first();n.style.opacity=1,function fade(){var val=parseFloat(n.style.opacity);(val-=inc)<0?(n.style.display="none","function"==typeof fn&&fn.call(n)):(n.style.opacity=val,requestAnimationFrame(fade))}(duration)}},ready:function(fn){this.context.addEventListener("DOMContentLoaded",fn)}},Svan.eachObj=function(obj,fn,context){for(var prop in obj)obj.hasOwnProperty(prop)&&fn.call(context,prop,obj[prop])},Svan.ajax=function(def){this.eachObj(def,function(k,v){console.log(k),console.log(v)});var xhr=new XMLHttpRequest;xhr.onreadystatechange=function(){4==this.readyState&&(200==this.status?isFunc(def.done)&&def.done.call(def.context,this.responseText,this.status):isFunc(def.fail)&&def.fail.call(def.context,this.responseText,this.status),isFunc(def.always)&&def.always.call(def.context,this.responseText,this.status))},!isNone(def.timeout)&&def.async&&(xhr.timeout=def.timeout),isFunc(def.before)&&def.before.call(xhr),xhr.open(def.method,def.url,def.async),xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");var qs="";isObj(def.data)&&this.eachObj(def.data,function(k,v){qs+=k+"="+encodeURIComponent(v)}),xhr.send(qs)};var init=Svan.init=function(selector,context){return this.FADE_DURATION=700,this.VERSION=.4,this.context=isNone(context)?document:context,this.list=isStr(selector)?[].slice.call(this.context.querySelectorAll(selector)):isNode(selector)||isWin(selector)?[selector]:[],this.found=this.list.length>0,this};init.prototype=Svan.prototype,window.Svan=Svan,isNone(window.$)&&(window.$=Svan)}();

View File

@ -59,7 +59,7 @@
},
prepend : function(data) {
if (this.found) {
if (isStr(data) {
if (isStr(data)) {
var div = document.createElement('div');
div.innerHTML = data;
while(div.lastChild != null) {