skylark-utils
Version:
An Elegant HTML5 JavaScript Library.
10 lines (9 loc) • 8.32 kB
JavaScript
/**
* skylark-utils - An Elegant HTML5 JavaScript Library.
* @author Hudaokeji Co.,Ltd
* @version v0.9.3
* @link www.skylarkjs.org
* @license MIT
*/
define(["./skylark","./langx","./browser","./noder"],function(e,r,n,t,i){function s(e,n,t){for(var i=t&&r.isString(t);e=e.parentNode;){if(v(e,n))return e;if(t)if(i){if(v(e,t))break}else if(e==t)break}return null}function u(e,n,t){for(var i=[],s=t&&r.isString(t);e=e.parentNode;)if(v(e,n)&&i.push(e),t)if(s){if(v(e,t))break}else if(e==t)break;return i}function a(e,r){return r=r||t.doc(),r.getElementById(e)}function o(e,r){for(var n=e.childNodes,t=[],i=0;i<n.length;i++){var e=n[i];1==e.nodeType&&(r&&!v(e,r)||t.push(e))}return t}function c(e,r){for(;e&&!v(e,r);)e=e.parentNode;return e}function f(e,r){try{return E.call(e.querySelectorAll(r))}catch(n){}return w.query(e,r)}function l(e,r){try{return e.querySelector(r)}catch(n){}var t=w.query(e,r);return t.length>0?t[0]:null}function p(e){return l(document.body,e)}function d(e){return f(document.body,e)}function h(e,r,n){for(var t=e.childNodes,i=t[0];i;){if(1==i.nodeType){if(!r||v(i,r))return i;if(n)break}i=i.nextSibling}return null}function b(e,r,n){for(var t=e.childNodes,i=t[t.length-1];i;){if(1==i.nodeType){if(!r||v(i,r))return i;if(n)break}i=i.previousSibling}return null}function v(e,n){if(!n||!e||1!==e.nodeType)return!1;if(r.isString(n)){try{return N.call(e,n.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g,'[$1="$2"]'))}catch(t){}return w.match(e,n)}return r.isArrayLike(n)?r.inArray(e,n):r.isPlainObject(n)?w.check(e,n):e===n}function g(e,r,n){for(var t=e.nextSibling;t;){if(1==t.nodeType){if(!r||v(t,r))return t;if(n)break}t=t.nextSibling}return null}function k(e,r){for(var n=e.nextSibling,t=[];n;)1==n.nodeType&&(r&&!v(n,r)||t.push(n)),n=n.nextSibling;return t}function y(e,r){var n=e.parentNode;return!n||r&&!v(n,r)?null:n}function S(e,r,n){for(var t=e.previousSibling;t;){if(1==t.nodeType){if(!r||v(t,r))return t;if(n)break}t=t.previousSibling}return null}function x(e,r){for(var n=e.previousSibling,t=[];n;)1==n.nodeType&&(r&&!v(n,r)||t.push(n)),n=n.previousSibling;return t}function m(e,r){for(var n=e.parentNode.firstChild,t=[];n;)1==n.nodeType&&n!==e&&(r&&!v(n,r)||t.push(n)),n=n.nextSibling;return t}var w={},A=Array.prototype.filter,E=Array.prototype.slice,N=n.matchesSelector;(function(){function e(e,s,u,o,f,p,d,h,b,v,g,k,y,S,x,m){if((s||n===-1)&&(r.expressions[++n]=[],t=-1,s))return"";if(u||o||t===-1){u=u||" ";var w=r.expressions[n];i&&w[t]&&(w[t].reverseCombinator=c(u)),w[++t]={combinator:u,tag:"*"}}var $=r.expressions[n][t];if(f)$.tag=f.replace(a,"");else if(p)$.id=p.replace(a,"");else if(d)d=d.replace(a,""),$.classList||($.classList=[]),$.classes||($.classes=[]),$.classList.push(d),$.classes.push({value:d,regexp:new RegExp("(^|\\s)"+l(d)+"(\\s|$)")});else if(y)m=m||x,m=m?m.replace(a,""):null,$.pseudos||($.pseudos=[]),$.pseudos.push({key:y.replace(a,""),value:m,type:1==k.length?"class":"element"});else if(h){h=h.replace(a,""),g=(g||"").replace(a,"");var A,E;switch(b){case"^=":E=new RegExp("^"+l(g));break;case"$=":E=new RegExp(l(g)+"$");break;case"~=":E=new RegExp("(^|\\s)"+l(g)+"(\\s|$)");break;case"|=":E=new RegExp("^"+l(g)+"(-|$)");break;case"=":A=function(e){return g==e};break;case"*=":A=function(e){return e&&e.indexOf(g)>-1};break;case"!=":A=function(e){return g!=e};break;default:A=function(e){return!!e}}""==g&&/^[*$^]=$/.test(b)&&(A=function(){return!1}),A||(A=function(e){return e&&E.test(e)}),$.attributes||($.attributes=[]),$.attributes.push({key:h,operator:b,value:g,test:A})}return""}var r,n,t,i,s={},u={},a=/\\/g,o=function(t,a){if(null==t)return null;if(t.Slick===!0)return t;t=(""+t).replace(/^\s+|\s+$/g,""),i=!!a;var c=i?u:s;if(c[t])return c[t];for(r={Slick:!0,expressions:[],raw:t,reverse:function(){return o(this.raw,!0)}},n=-1;t!=(t=t.replace(p,e)););return r.length=r.expressions.length,c[r.raw]=i?f(r):r},c=function(e){return"!"===e?" ":" "===e?"!":/^!/.test(e)?e.replace(/^!/,""):"!"+e},f=function(e){for(var r=e.expressions,n=0;n<r.length;n++){for(var t=r[n],i={parts:[],tag:"*",combinator:c(t[0].combinator)},s=0;s<t.length;s++){var u=t[s];u.reverseCombinator||(u.reverseCombinator=" "),u.combinator=u.reverseCombinator,delete u.reverseCombinator}t.reverse().push(i)}return e},l=function(){var e=/(?=[\-\[\]{}()*+?.\\\^$|,#\s])/g,r="\\";return function(n){return n.replace(e,r)}}(),p=new RegExp("^(?:\\s*(,)\\s*|\\s*(<combinator>+)\\s*|(\\s+)|(<unicode>+|\\*)|\\#(<unicode>+)|\\.(<unicode>+)|\\[\\s*(<unicode1>+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(<unicode>+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)".replace(/<combinator>/,"["+l(">+~`!@$%^&={}\\;</")+"]").replace(/<unicode>/g,"(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])").replace(/<unicode1>/g,"(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])")),d=this.Slick||{};d.parse=function(e){return o(e)},d.escapeRegExp=l,this.Slick||(this.Slick=d)}).apply(w);var E=Array.prototype.slice;w.parseSelector=w.Slick.parse,w.pseudos={checked:function(e){return!!e.checked},contains:function(e,r,n,t){if($(this).text().indexOf(t)>-1)return this},disabled:function(e){return!!e.disabled},enabled:function(e){return!e.disabled},eq:function(e,r,n,t){return r==t},focus:function(e){return document.activeElement===e&&(e.href||e.type||e.tabindex)},first:function(e,r){return 0===r},gt:function(e,r,n,t){return r>t},has:function(e,r,n,t){return w.querySelector(e,t).length>0},hidden:function(e){return!w.pseudos.visible(e)},last:function(e,r,n){return r===n.length-1},lt:function(e,r,n,t){return r<t},not:function(e,r,n,t){return w.match(e,t)},parent:function(e){return!!e.parentNode},selected:function(e){return!!e.selected},visible:function(e){return e.offsetWidth&&e.offsetWidth}},w.divide=function(e){var r,n,t,i,s,u="",a=[];if((n=e.id)&&(u+="#"+n),t=e.classes)for(var o=t.length;o--;)u+="."+t[o].value;if(i=e.attributes)for(var o=0;o<i.length;o++)u+=i[o].operator?"["+i[o].key+i[o].operator+JSON.stringify(i[o].value)+"]":"["+i[o].key+"]";if(s=e.pseudos)for(o=s.length;o--;)part=s[o],this.pseudos[part.key]?a.push(part):void 0!==part.value&&(u+=":"+part.key+"("+JSON.stringify(part));return(r=e.tag)&&(u=r.toUpperCase()+u),u||(u="*"),{nativeSelector:u,customPseudos:a}},w.check=function(e,r,n,t){var i,s,u,a,o;if(i=r.tag){var c=e.nodeName.toUpperCase();if("*"==i){if(c<"@")return!1}else if(c!=(i||"").toUpperCase())return!1}if((s=r.id)&&e.getAttribute("id")!=s)return!1;var f,l,p,d;if(u=r.classes)for(f=u.length;f--;)if(p=e.getAttribute("class"),!p||!u[f].regexp.test(p))return!1;if(a)for(f=a.length;f--;)if(l=a[f],l.operator?!l.test(e.getAttribute(l.key)):!e.hasAttribute(l.key))return!1;if(o=r.pseudos)for(f=o.length;f--;)if(l=o[f],d=this.pseudos[l.key]){if(!d(e,n,t,l.value))return!1}else if(!N.call(e,l.key))return!1;return!0},w.match=function(e,r){var n=w.Slick.parse(r);if(!n)return!0;var t,i=n.expressions,s=0;for(t=0;currentExpression=i[t];t++)if(1==currentExpression.length){var u=currentExpression[0];if(this.check(e,u))return!0;s++}if(s==n.length)return!1;var a,o=this.query(document,n);for(t=0;a=o[t++];)if(a===e)return!0;return!1},w.combine=function(e,r){var n,t=r.combinator,i=r,s=[];switch(t){case">":s=o(e,i);break;case"+":n=g(e,i,!0),n&&s.push(n);break;case"^":n=h(e,i,!0),n&&s.push(n);break;case"~":s=k(e,i);break;case"++":var a=S(e,i,!0),c=g(e,i,!0);a&&s.push(a),c&&s.push(c);break;case"~~":s=m(e,i);break;case"!":s=u(e,i);break;case"!>":n=y(e,i),n&&s.push(n);break;case"!+":s=S(e,i,!0);break;case"!^":n=b(e,i,!0),n&&s.push(n);break;case"!~":s=x(e,i);break;default:var f=this.divide(r);if(s=E.call(e.querySelectorAll(f.nativeSelector)),f.customPseudos)for(var l=f.customPseudos.length-1;l>=0;l--)s=A.call(s,function(e,r){return w.check(e,{pseudos:[f.customPseudos[l]]},r,s)})}return s},w.query=function(e,n,t){for(var i,s,u=this.Slick.parse(n),a=[],o=u.expressions,c=0;i=o[c];c++){for(var f,l=[e],p=0;s=i[p];p++)f=r.map(l,function(e,r){return w.combine(e,s)}),f&&(l=f);f&&(a=a.concat(f))}return a};var C=function(){return C};return r.mixin(C,{ancestor:s,ancestors:u,byId:a,children:o,closest:c,descendant:l,descendants:f,find:p,findAll:d,firstChild:h,lastChild:b,matches:v,nextSibling:g,nextSiblings:k,parent:y,previousSibling:S,previousSiblings:x,pseudos:w.pseudos,siblings:m}),e.finder=C});
//# sourceMappingURL=sourcemaps/finder.js.map