您的位置:首页 > Web前端 > JavaScript

新年里 把 自己写的 js基础代码 做个了结..... 死机了吧,悲剧了吧 ... 打不开了吧...编辑器bug出现了吧 ff不能黏贴,复制,换组织就不修正么?

2016-08-25 16:29 489 查看
新年里 把 自己写的 js基础代码 做个了结..... 死机了吧,悲剧了吧 ... 打不开了吧...编辑器bug出现了吧 ff不能黏贴,复制,换组织就不修正么?

 

 

var __doc=document,__undef="undefined",__proto="prototype";function $C(a){return __doc.createElement(a)}function $TagN(a){return __doc.getElementsByTagName(a)}function $N(a){return __doc.getElementsByName(a)}function $ID(a){return __doc.getElementById(a)}function loadscript(b){var a=$C("script");a.type="text/javascript";a.src=b;$TagN("head")[0].appendChild(a)}function loadcss(b){var a=$C("link");a.rel="stylesheet";a.type="text/css";a.href=b;$TagN("head")[0].appendChild(s)}function $clsN(g,h){var b=[];var f=new RegExp("(^| )"+h+"( |$)");var e=g.getElementsByTagName("*");for(var d=0,c=e.length;d<c;d++){if(e[d]&&(e[d].nodeType==1)&&(f.test(e[d].className))){b.push(e[d])}}return b}(function(){if(typeof Moogens==__undef){Moogens={meta:{author:"kenxu",version:"0.01"}}}if(typeof console==__undef){console={log:function(){}}}if(typeof Object.create!=="function"){Object.create=function(c){function b(){}b[__proto]=c;return new b()}}Object.extend=function(b,d){for(var c in d){b[c]=d[c]}return b};Object.extend(String[__proto],{trim:function(){return this.replace(/^\s+|\s+$/g,"")},nocamelize:function(b){return this.replace(/(?=[A-Z])/g,b||"-").toLowerCase()},camelize:function(){return this.replace(/-([a-z])/g,function(c,b){return b.toUpperCase()})}});Function[__proto].bind=function(c){var b=this;return function(){return b.apply(c,arguments)}};Moogens.Class={create:function(){return function(){this.initialize.apply(this,arguments)}}};Moogens.Utilities={arrayMap:function(f,d){var e=[];for(var c=0;c<f.length;c++){var b=d(f[c],c);if(b!==null){e.push(b)}}return e},each:function(d,c){if(d&&d.length){for(var b=0;b<d.length;b++){if(c.call(d[b],b)=="#end#"){break}}}},toArray:function(d){if(typeof d==__undef){return[]}if(Object[__proto].toString.call(d)==="[object Array]"){return d}var c=[];if(typeof d.length!=__undef){for(var b=0;b<d.length;b++){c.push(d[b])}}else{c.push(d)}return c}};Moogens.Browser=new function(){var c={webkit:/(webkit)[ \/]([\w.]+)/,opera:/(opera)(?:.*version)?[ \/]([\w.]+)/,msie:/(msie) ([\w.]+)/,mozilla:/(mozilla)(?:.*? rv:([\w.]+))?/};this.userAgent=navigator.userAgent;this.uaMatch=function(e){e=e.toLowerCase();var d=c.webkit.exec(e)||c.opera.exec(e)||c.msie.exec(e)||e.indexOf("compatible")<0&&c.mozilla.exec(e)||[];return{browser:d[1]||"",version:d[2]||"0"}};var b=this.uaMatch(this.userAgent);this[b.browser]=true;this.version=b.version;if(this.webkit){this.safari=true}c=null};Moogens.Cookie=new function(){this.get=function(c){var b=document.cookie.match(new RegExp("(^| )"+c+"=([^;]*)(;|$)"));if(b!=null){return decodeURIComponent(b[2])}return null};this.set=function(f,i,g,e,j,d){var h=f+"="+encodeURIComponent(i);if(g){var c=new Date();var b=g*3600*1000;c.setTime(c.getTime()+b);h+=";expires="+c.toGMTString()}if(e){h+=";path="+e}if(j){h+=";domain="+j}if(d){h+=";secure"}document.cookie=h};this.clear=function(e,c,b,d){this.set(e,"",0,c,b,d)}};Moogens.Dom={onReady:function(f,b){var e,g;var d=function(h){if(h&&h.type=="DOMContentLoaded"){c()}else{if(h&&h.type=="load"){c()}else{if(__doc.readyState){if((/loaded|complete/).test(__doc.readyState)){c()}else{if(!!__doc.documentElement.doScroll){try{e||__doc.documentElement.doScroll("left")}catch(h){return}c()}}}}}};var c=function(){if(!e){e=true;f.call(b||window);if(__doc.removeEventListener){__doc.removeEventListener("DOMContentLoaded",d,false)}__doc.onreadystatechange=null;window.onload=null;clearInterval(g);g=null}};if(__doc.addEventListener){__doc.addEventListener("DOMContentLoaded",d,false)}__doc.onreadystatechange=d;g=setInterval(d,5);window.onload=d}};var a=(function(){var t=/(?:[\w\-\\.#]+)+(?:\[\w+?=([\'"])?(?:\\\1|.)+?\1\])?|\*|>/ig,n=/^(?:[\w\-_]+)?\.([\w\-_]+)/,o=/^(?:[\w\-_]+)?#([\w\-_]+)/,k=/^([\w\*\-_]+)/,m=[null,null];function q(e,g){g=g||document;var i=/^[\w\-_#]+$/.test(e);if(!i&&g.querySelectorAll){return r(g.querySelectorAll(e))}if(e.indexOf(",")>-1){var z=e.split(/,/g),B=[],C=0,b=z.length;for(;C<b;++C){B=B.concat(q(z[C],g))}return p(B)}var d=e.match(t),f=d.pop(),h=(f.match(o)||m)[1],A=!h&&(f.match(n)||m)[1],y=!h&&(f.match(k)||m)[1],c;if(A&&!y&&g.getElementsByClassName){c=r(g.getElementsByClassName(A))}else{c=!h&&r(g.getElementsByTagName(y||"*"));if(A){c=l(c,"className",RegExp("(^|\\s)"+A+"(\\s|$)"))}if(h){var j=g.getElementById(h);return j?[j]:[]}}return d[0]&&c[0]?u(d,c):c}function r(e){try{return Array[__proto].slice.call(e)}catch(f){var c=[],b=0,d=e.length;for(;b<d;++b){c[b]=e[b]}return c}}function u(j,c,e){var b=j.pop();if(b===">"){return u(j,c,true)}var B=[],h=-1,g=(b.match(o)||m)[1],A=!g&&(b.match(n)||m)[1],y=!g&&(b.match(k)||m)[1],z=-1,f,i,d;y=y&&y.toLowerCase();while((f=c[++z])){i=f.parentNode;do{d=!y||y==="*"||y===i.nodeName.toLowerCase();d=d&&(!g||i.id===g);d=d&&(!A||RegExp("(^|\\s)"+A+"(\\s|$)").test(i.className));if(e||d){break}}while((i=i.parentNode));if(d){B[++h]=f}}return j[0]&&B[0]?u(j,B):B}var p=(function(){var c=+new Date();var b=(function(){var d=1;return function(e){var f=e.k,g=d++;if(!f){e.k=g;return true}return false}})();return function(d){var e=d.length,i=[],f=-1,h=0,g;for(;h<e;++h){g=d[h];if(b(g)){i[++f]=g}}c+=1;return i}})();function l(e,d,f){var b=-1,g,h=-1,c=[];while((g=e[++b])){if(f.test(g[d])){c[++h]=g}}return c}return q})();Moogens.Dom.get=function(b,c){return typeof b=="string"?a(b,c):typeof b=="[object Array]"?b:new Array(b)};Moogens.Dom.Node=function(b){this.setElement=function(c){this.ele=c&&c.nodeType?c:null;return this};this.getElement=function(c){return this.ele};this.getElementTag=function(){return this.ele.nodeName};this.getElementType=function(){return this.ele.nodeType};this.setElement(b||null);this.hasClass=function(c){var d=new RegExp("(^| )"+c+"( |$)");return d.test(this.ele.className)};this.addClass=function(c){return this.toggleClass(c,true)};this.removeClass=function(c){return this.toggleClass(c,false)};this.toggleClass=function(c,e){if(typeof c==__undef){this.ele.className=""}else{var d=new RegExp("(^| )"+c+"( |$)");var f=d.test(this.ele.className);if(typeof e!=__undef){if(e){if(!f){this.ele.className+=" "+c}}else{if(f){this.ele.className=this.ele.className.replace(d," ")}}}else{this.ele.className=f?this.ele.className.replace(d," "):this.ele.className+" "+c}d=f=null}return this};this.css=function(c,d){if(typeof c=="object"){for(var e in c){if(typeof e=="string"){this.ele.style[e.camelize()]=c[e]}}}else{if(typeof c=="string"){if(typeof d==__undef){return this.ele.style[c.camelize()]}this.ele.style[c.camelize()]=(typeof d=="function")?d(this.ele):d}}return this};this.attr=function(c,d){if(typeof c=="object"){for(var g in c){if(typeof g=="string"){try{this.ele[g]=c[g]}catch(f){console.log(this.ele.nodeName+" "+g+" readonly")}}}}else{if(typeof c=="string"){if(typeof d==__undef){return this.ele[c]}if(typeof d=="function"){d=d(this.ele)}try{this.ele[c]=d}catch(f){console.log(this.ele.nodeName+" "+c+" readonly")}}}return this};this.removeAttr=function(c){try{this.ele[c]=null}catch(d){console.log(this.ele.nodeName+" "+c+" readonly")}return this};this.val=function(c){if(typeof c==__undef){return this.ele.value}this.ele.value=c;return this};this.text=function(c){if(typeof c==__undef){if(typeof console._1dct==__undef){console._1dct=function(f){var d="";if(f&&f.nodeType){if(f.nodeType!=8){Moogens.Utilities.each(f.childNodes,function(){d+=this.nodeType==1?console._1dct(this):this.nodeValue})}}return d}}return console._1dct(this.ele)}this.empty().ele.appendChild(__doc.createTextNode(c));return this};this.html=function(c){if(typeof c==__undef){return this.ele.innerHTML}try{this.ele.innerHTML=c.replace(/<script[^>]*>[\S\s]*?<\/script[^>]*>/ig,"")}catch(d){console.log(this.ele.nodeName+" innerHTML readonly")}return this};this.offset=function(){if(this.css("display")=="none"){return{}}var e=this.ele;var d=e.offsetTop;var c=e.offsetLeft;while(e=e.offsetParent){d+=e.offsetTop+(Moogens.Browser.msie?e.clientTop:0);c+=e.offsetLeft+(Moogens.Browser.msie?e.clientLeft:0)}return{left:c,top:d}};this.show=function(){return this.css({display:""})};this.hide=function(){return this.css({display:"none"})};this.toggle=function(){this.ele.style.display=this.ele.style.display==""?"none":"";return this};this.resizeTo=function(c,d){return this.css({width:c+"px",height:d+"px"})};this.remove=function(){this.ele.parentNode.removeChild(this.ele)};this.empty=function(){while(this.ele.firstChild){this.ele.removeChild(this.ele.firstChild)}return this};this.focus=function(){if(this.ele.focus){this.ele.focus()}return this};this.on=function(d,c){if(typeof c=="function"){Moogens.Dom.Event.add(this.ele,d,c)}return this};this.un=function(d,c){if(typeof c=="function"){Moogens.Dom.Event.remove(this.ele,d,c)}return this};this.click=function(c){if(typeof c==__undef){return this.fireEvent("click")}return this.on("click",c)};this.dbclick=function(c){if(typeof c==__undef){return this.fireEvent("dblclick")}return this.on("dblclick",c)};this.fireEvent=function(c){if(typeof c=="string"){c="on"+c;if(typeof this.ele.fireEvent=="function"){this.ele.fireEvent(c)}else{if(typeof this.ele[c]=="function"){this.ele[c]()}}}return this}};Moogens.Dom.NodeList=function(d){var b=new Moogens.Dom.Node();var c=Moogens.Utilities.arrayMap(d,function(e){return e&&e.nodeType?e:null});this.get=function(e){return(typeof e!=__undef)&&c[e]?b.setElement(c[e]):null};this.count=function(){return c.length};this.each=function(f){for(var e=0;e<c.length;e++){f.call(this.get(e),e)}return this}};Moogens.Dom.$=function(b,c){return new Moogens.Dom.NodeList(Moogens.Dom.get(b,c))};Moogens.Dom.Event={add:function(d,c,b){d["e"+c+b]=b;if(d.addEventListener){d.addEventListener(c,b,false)}else{if(d.attachEvent){d[c+b]=function(){d["e"+c+b](window.event)};d.attachEvent("on"+c,d[c+b])}}},remove:function(d,c,b){if(d.removeEventListener){d.removeEventListener(c,d["e"+c+b],false)}else{if(d.detachEvent){d.detachEvent("on"+c,d[c+b])}}d[c+b]=null;d["e"+c+b]=null},preventDefault:function(b){b=b||window.event;if(b.preventDefault){b.preventDefault()}else{b.returnValue=false}},preventBubble:function(b){b=b||window.event;if(b.stopPropagation){b.stopPropagation()}else{b.cancelBubble=true}},keyCode:function(b){b=b||window.event;return b.keyCode||b.charCode||0},addProxy:function(b,d,c,g){var e=d+"_handle";var f=this;b[e]=function(h){h=h||window.event;var i=h.target||h.srcElement;c(i);if(g){f.preventDefault(h)}};this.add(b,d,b[e])},removeProxy:function(b,c){var d=c+"_handle";this.remove(b,c,b[d])}}})();

 

大约10k , 自我感觉良好 ....

 

console.log(Moogens.Dom.get('div > ul'));

 

[
ul
#site_nav
.nav

,
ul
#user_nav
.nav

,
ul

,
ul

]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: