?? moo.fx.js
字號:
//MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006 Valerio Proietti, <http://mad4milk.net>, MIT Style License.var Position = { cumulativeOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; } while (element); return [valueL, valueT]; }};function $c(array){ var nArray = []; for (var i=0;i<array.length;i++) nArray.push(array[i]); return nArray;}var Class = function(properties){ var klass = function(){ for (var p in this){ } if (arguments[0] != 'noinit' && this.initialize) return this.initialize.apply(this, arguments); }; klass.extend = this.extend; klass.implement = this.implement; klass.prototype = properties; return klass;};Class.empty = function(){};Class.create = function(properties){ return new Class(properties);};Class.prototype = { extend: function(properties){ var pr0t0typ3 = new this('noinit'); for (var property in properties){ var previous = pr0t0typ3[property]; var current = properties[property]; if (previous && previous != current) current = previous.parentize(current) || current; pr0t0typ3[property] = current; } return new Class(pr0t0typ3); }, implement: function(properties){ for (var property in properties) this.prototype[property] = properties[property]; }};Object.extend = function(){ var args = arguments; if (args[1]) args = [args[0], args[1]]; else args = [this, args[0]]; for (var property in args[1]) args[0][property] = args[1][property]; return args[0];};Object.Native = function(){ for (var i = 0; i < arguments.length; i++) arguments[i].extend = Class.prototype.implement;};new Object.Native(Function, Array, String, Number);Function.extend({ parentize: function(current){ var previous = this; return function(){ this.parent = previous; return current.apply(this, arguments); }; }});Function.extend({ pass: function(args, bind){ var fn = this; if ($type(args) != 'array') args = [args]; return function(){ return fn.apply(bind || fn._proto_ || fn, args); }; }, bind: function(bind){ var fn = this; return function(){ return fn.apply(bind, arguments); }; }, bindAsEventListener: function(bind){ var fn = this; return function(event){ fn.call(bind, event || window.event); return false; }; }, delay: function(ms, bind){ return setTimeout(this.bind(bind || this._proto_ || this), ms); }, periodical: function(ms, bind){ return setInterval(this.bind(bind || this._proto_ || this), ms); }});function $clear(timer){ clearTimeout(timer); clearInterval(timer); return null;};function $type(obj){ if (!obj) return false; var type = false; if (obj instanceof Function) type = 'function'; else if (obj.nodeName){ if (obj.nodeType == 3 && !/\S/.test(obj.nodeValue)) type = 'textnode'; else if (obj.nodeType == 1) type = 'element'; } else if (obj instanceof Array) type = 'array'; else if (typeof obj == 'object') type = 'object'; else if (typeof obj == 'string') type = 'string'; else if (typeof obj == 'number' && isFinite(obj)) type = 'number'; return type;};var Chain = new Class({ chain: function(fn){ this.chains = this.chains || []; this.chains.push(fn); return this; }, callChain: function(){ if (this.chains && this.chains.length) this.chains.splice(0, 1)[0].delay(10, this); }, clearChain: function(){ this.chains = []; }});if (!Array.prototype.forEach){ Array.prototype.forEach = function(fn, bind){ for(var i = 0; i < this.length ; i++) fn.call(bind, this[i], i); };}Array.extend({ each: Array.prototype.forEach, copy: function(){ var newArray = []; for (var i = 0; i < this.length; i++) newArray.push(this[i]); return newArray; }, remove: function(item){ for (var i = 0; i < this.length; i++){ if (this[i] == item) this.splice(i, 1); } return this; }, test: function(item){ for (var i = 0; i < this.length; i++){ if (this[i] == item) return true; }; return false; }, extend: function(newArray){ for (var i = 0; i < newArray.length; i++) this.push(newArray[i]); return this; }, associate: function(keys){ var newArray = []; for (var i =0; i < this.length; i++) newArray[keys[i]] = this[i]; return newArray; }});function $A(array){ return Array.prototype.copy.call(array);};String.extend({ test: function(regex, params){ return this.match(new RegExp(regex, params)); }, toInt: function(){ return parseInt(this); }, camelCase: function(){ return this.replace(/-\D/gi, function(match){ return match.charAt(match.length - 1).toUpperCase(); }); }, capitalize: function(){ return this.toLowerCase().replace(/\b[a-z]/g, function(match){ return match.toUpperCase(); }); }, trim: function(){ return this.replace(/^\s*|\s*$/g, ''); }, clean: function(){ return this.replace(/\s\s/g, ' ').trim(); }, rgbToHex: function(array){ var rgb = this.test('([\\d]{1,3})', 'g'); if (rgb[3] == 0) return 'transparent'; var hex = []; for (var i = 0; i < 3; i++){ var bit = (rgb[i]-0).toString(16); hex.push(bit.length == 1 ? '0'+bit : bit); } var hexText = '#'+hex.join(''); if (array) return hex; else return hexText; }, hexToRgb: function(array){ var hex = this.test('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$'); var rgb = []; for (var i = 1; i < hex.length; i++){ if (hex[i].length == 1) hex[i] += hex[i]; rgb.push(parseInt(hex[i], 16)); } var rgbText = 'rgb('+rgb.join(',')+')'; if (array) return rgb; else return rgbText; }});Number.extend({ toInt: function(){ return this; }});var Element = new Class({ initialize: function(el){ if ($type(el) == 'string') el = document.createElement(el); return $(el); }, inject: function(el, where){ el = $(el) || new Element(el); switch(where){ case "before": $(el.parentNode).insertBefore(this, el); break; case "after": { if (!el.getNext()) $(el.parentNode).appendChild(this); else $(el.parentNode).insertBefore(this, el.getNext()); } break; case "inside": el.appendChild(this); break; } return this; }, injectBefore: function(el){ return this.inject(el, 'before'); }, injectAfter: function(el){ return this.inject(el, 'after'); }, injectInside: function(el){ return this.inject(el, 'inside'); }, adopt: function(el){ this.appendChild($(el) || new Element(el)); return this; }, remove: function(){ this.parentNode.removeChild(this); }, clone: function(contents){ return $(this.cloneNode(contents || true)); }, replaceWith: function(el){ var el = $(el) || new Element(el); this.parentNode.replaceChild(el, this); return el; }, appendText: function(text){ if (this.getTag() == 'style' && window.ActiveXObject) this.styleSheet.cssText = text; else this.appendChild(document.createTextNode(text)); return this; }, hasClass: function(className){ return !!this.className.test("\\b"+className+"\\b"); }, addClass: function(className){ if (!this.hasClass(className)) this.className = (this.className+' '+className.trim()).clean(); return this; }, removeClass: function(className){ if (this.hasClass(className)) this.className = this.className.replace(className.trim(), '').clean(); return this; }, toggleClass: function(className){ if (this.hasClass(className)) return this.removeClass(className); else return this.addClass(className); }, setStyle: function(property, value){ if (property == 'opacity') this.setOpacity(parseFloat(value)); else this.style[property.camelCase()] = value; return this; }, setStyles: function(source){ if ($type(source) == 'object') { for (var property in source) this.setStyle(property, source[property]); } else if ($type(source) == 'string') { if (window.ActiveXObject) this.cssText = source; else this.setAttribute('style', source); } return this; }, setOpacity: function(opacity){ if (opacity == 0){ if(this.style.visibility != "hidden") this.style.visibility = "hidden"; } else { if(this.style.visibility != "visible") this.style.visibility = "visible"; } if (window.ActiveXObject) this.style.filter = "alpha(opacity=" + opacity*100 + ")"; this.style.opacity = opacity; return this; }, getStyle: function(property){ var proPerty = property.camelCase(); var style = this.style[proPerty] || false; if (!style) { if (document.defaultView) style = document.defaultView.getComputedStyle(this,null).getPropertyValue(property); else if (this.currentStyle) style = this.currentStyle[proPerty]; } if (style && ['color', 'backgroundColor', 'borderColor'].test(proPerty) && style.test('rgb')) style = style.rgbToHex(); return style; }, addEvent: function(action, fn){ this[action+fn] = fn.bind(this); if (this.addEventListener) this.addEventListener(action, fn, false); else this.attachEvent('on'+action, this[action+fn]); var el = this; if (this != window) Unload.functions.push(function(){ el.removeEvent(action, fn); el[action+fn] = null; }); return this; }, removeEvent: function(action, fn){ if (this.removeEventListener) this.removeEventListener(action, fn, false); else this.detachEvent('on'+action, this[action+fn]); return this; }, getBrother: function(what){ var el = this[what+'Sibling']; while ($type(el) == 'textnode') el = el[what+'Sibling']; return $(el); }, getPrevious: function(){ return this.getBrother('previous'); }, getNext: function(){ return this.getBrother('next'); }, getFirst: function(){ var el = this.firstChild; while ($type(el) == 'textnode') el = el.nextSibling; return $(el); }, getLast: function(){ var el = this.lastChild; while ($type(el) == 'textnode') el = el.previousSibling; return $(el); }, setProperty: function(property, value){ var el = false; switch(property){ case 'class': this.className = value; break; case 'style': this.setStyles(value); break; case 'name': if (window.ActiveXObject && this.getTag() == 'input'){ el = $(document.createElement('<input name="'+value+'" />')); $A(this.attributes).each(function(attribute){ if (attribute.name != 'name') el.setProperty(attribute.name, attribute.value); }); if (this.parentNode) this.replaceWith(el); }; default: this.setAttribute(property, value); } return el || this; }, setProperties: function(source){ for (var property in source) this.setProperty(property, source[property]); return this;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -