This commit is contained in:
a-Sansara 2015-12-16 02:36:06 +01:00
parent 86e4c56268
commit 83236f13e2
2 changed files with 7 additions and 11 deletions

2
src/svan-min.js vendored
View File

@ -1 +1 @@
/* by a-sansara - https://github.com/pluie-org/svan */!function(){var t=function(t,n){return typeof t==n},n=function(n){return t(n,"undefined")},i=function(n){return t(n,"string")},e=function(n){return t(n,"function")},s=function(n){return t(n,"object")},o=function(t,n){return new o.init(t,n)};o.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)}},o.isNone=n,o.isStr=i,o.isObj=s,o.isFunc=e,o.eachObj=function(t,n,i){for(var e in t)t.hasOwnProperty(e)&&n.call(i,e,t[e])},o.ajax=function(t){this.eachObj(t,function(t,n){console.log(t),console.log(n)});var i=new XMLHttpRequest;i.onreadystatechange=function(n){4==this.readyState&&(200==this.status?e(t.done)&&t.done.call(t.context,n,this.responseText,this.statusText):e(t.fail)&&t.fail.call(t.context,n,this.responseText,this.statusText),e(t.always)&&t.always.call(t.context,n,this.responseText,this.statusText))},!n(t.timeout)&&t.async&&(i.timeout=t.timeout),e(t.before)&&t.before.call(i),i.open(t.method,t.url,t.async),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded");var o="";s(t.data)&&this.eachObj(t.data,function(t,n){o+=t+"="+encodeURIComponent(n)}),i.send(o)};var a=o.init=function(t,e){return this.FADE_DURATION=700,this.VERSION=.4,this.context=n(e)?document:e,this.list=i(t)?[].slice.call(this.context.querySelectorAll(t)):s(t)&&!n(t.nodeType)?[t]:[],this.found=this.list.length>0,this};a.prototype=o.prototype,window.Svan=o,n(window.$)&&(window.$=o)}(); /* by a-sansara - 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")};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 a=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)):o(t)&&!i(t.nodeType)?[t]:[],this.found=this.list.length>0,this};a.prototype=n.prototype,window.Svan=n,i(window.$)&&(window.$=n)}();

View File

@ -12,13 +12,13 @@
(function() { (function() {
var is = function(o, intent) { return typeof o == intent; }, var is = function(o, intent) { return typeof o == intent; },
isNone = function(o) { return is(o, 'undefined'); },
isStr = function(o) { return is(o, 'string'); },
isFunc = function(o) { return is(o, 'function'); },
isObj = function(o) { return is(o, 'object'); },
Svan = function (selector, context) { Svan = function (selector, context) {
return new Svan.init(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'); };
Svan.prototype = { Svan.prototype = {
regsan : function (v) { regsan : function (v) {
@ -130,10 +130,6 @@
this.context.addEventListener('DOMContentLoaded', fn); this.context.addEventListener('DOMContentLoaded', fn);
} }
}; };
Svan.isNone = isNone;
Svan.isStr = isStr;
Svan.isObj = isObj;
Svan.isFunc = isFunc;
Svan.eachObj = function(obj, fn, context) { Svan.eachObj = function(obj, fn, context) {
for (var prop in obj) { for (var prop in obj) {
if (obj.hasOwnProperty(prop)) { if (obj.hasOwnProperty(prop)) {
@ -168,7 +164,7 @@
} }
xhr.send(qs); xhr.send(qs);
} }
var init = Svan.init = function(selector, context) { var init = Svan.init = function(selector, context) {
this.FADE_DURATION = 700; this.FADE_DURATION = 700;
this.VERSION = 0.4; this.VERSION = 0.4;