?? moo.fx.js
字號:
}, setHTML: function(html){ this.innerHTML = html; return this; }, getProperty: function(property){ return this.getAttribute(property); }, getTag: function(){ return this.tagName.toLowerCase(); }, getOffset: function(what){ what = what.capitalize(); var el = this; var offset = 0; do { offset += el['offset'+what] || 0; el = el.offsetParent; } while (el); return offset; }, getTop: function(){ return this.getOffset('top'); }, getLeft: function(){ return this.getOffset('left'); }, getValue: function(){ var value = false; switch(this.getTag()){ case 'select': value = this.getElementsByTagName('option')[this.selectedIndex].value; break; case 'input': if ( (this.checked && ['checkbox', 'radio'].test(this.type)) || (['hidden', 'text', 'password'].test(this.type)) ) value = this.value; break; case 'textarea': value = this.value; } return value; }});new Object.Native(Element);Element.extend({ hasClassName: Element.prototype.hasClass, addClassName: Element.prototype.addClass, removeClassName: Element.prototype.removeClass, toggleClassName: Element.prototype.toggleClass});function $Element(el, method, args){ if ($type(args) != 'array') args = [args]; return Element.prototype[method].apply(el, args);};function $(el){ if ($type(el) == 'string') el = document.getElementById(el); if ($type(el) == 'element'){ if (!el.extend){ Unload.elements.push(el); el.extend = Object.extend; el.extend(Element.prototype); } return el; } else return false;};window.addEvent = document.addEvent = Element.prototype.addEvent;window.removeEvent = document.removeEvent = Element.prototype.removeEvent;var Unload = { elements: [], functions: [], vars: [], unload: function(){ Unload.functions.each(function(fn){ fn(); }); window.removeEvent('unload', window.removeFunction); Unload.elements.each(function(el){ for(var p in Element.prototype){ window[p] = null; document[p] = null; el[p] = null; } el.extend = null; }); }};window.removeFunction = Unload.unload;window.addEvent('unload', window.removeFunction);var Fx = fx = {};Fx.Base = new Class({ setOptions: function(options){ this.options = Object.extend({ onStart: Class.empty, onComplete: Class.empty, transition: Fx.Transitions.sineInOut, duration: 500, unit: 'px', wait: true, fps: 50 }, options || {}); }, step: function(){ var time = new Date().getTime(); if (time < this.time + this.options.duration){ this.cTime = time - this.time; this.setNow(); } else { this.options.onComplete.pass(this.element, this).delay(10); this.clearTimer(); this.callChain(); this.now = this.to; } this.increase(); }, set: function(to){ this.now = to; this.increase(); return this; }, setNow: function(){ this.now = this.compute(this.from, this.to); }, compute: function(from, to){ return this.options.transition(this.cTime, from, (to - from), this.options.duration); }, custom: function(from, to){ if (!this.options.wait) this.clearTimer(); if (this.timer) return; this.options.onStart.pass(this.element, this).delay(10); this.from = from; this.to = to; this.time = new Date().getTime(); this.timer = this.step.periodical(Math.round(1000/this.options.fps), this); return this; }, clearTimer: function(){ this.timer = $clear(this.timer); return this; }, setStyle: function(element, property, value){ element.setStyle(property, value + this.options.unit); }});Fx.Base.implement(new Chain);Fx.Style = Fx.Base.extend({ initialize: function(el, property, options){ this.element = $(el); this.setOptions(options); this.property = property.camelCase(); }, hide: function(){ return this.set(0); }, goTo: function(val){ return this.custom(this.now || 0, val); }, increase: function(){ this.setStyle(this.element, this.property, this.now); }});Fx.Styles = Fx.Base.extend({ initialize: function(el, options){ this.element = $(el); this.setOptions(options); this.now = {}; }, setNow: function(){ for (var p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]); }, custom: function(objFromTo){ if (this.timer && this.options.wait) return; var from = {}; var to = {}; for (var p in objFromTo){ from[p] = objFromTo[p][0]; to[p] = objFromTo[p][1]; } return this.parent(from, to); }, increase: function(){ for (var p in this.now) this.setStyle(this.element, p, this.now[p]); }});Element.extend({ effect: function(property, options){ return new Fx.Style(this, property, options); }, effects: function(options){ return new Fx.Styles(this, options); }});Fx.Transitions = { linear: function(t, b, c, d){ return c*t/d + b; }, sineInOut: function(t, b, c, d){ return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }};function $S(){ var els = []; $A(arguments).each(function(sel){ if ($type(sel) == 'string') els.extend(document.getElementsBySelector(sel)); else if ($type(sel) == 'element') els.push($(sel)); }); return $Elements(els);};var $$ = $S;function $E(selector, filter){ return ($(filter) || document).getElement(selector);};function $ES(selector, filter){ return ($(filter) || document).getElementsBySelector(selector);};function $Elements(elements){ return Object.extend(elements, new Elements);};Element.extend({ getElements: function(selector){ var filters = []; selector.clean().split(' ').each(function(sel, i){ var bits = sel.test('^(\\w*|\\*)(?:#(\\w+)|\\.(\\w+))?(?:\\[["\']?(\\w+)["\']?([\\*\\^\\$]?=)["\']?(\\w*)["\']?\\])?$'); if (!bits) return; if (!bits[1]) bits[1] = '*'; var param = bits.remove(bits[0]).associate(['tag', 'id', 'class', 'attribute', 'operator', 'value']); if (i == 0){ if (param['id']){ var el = this.getElementById(param['id']); if (!el || (param['tag'] != '*' && $(el).getTag() != param['tag'])) return false; filters = [el]; } else { filters = $A(this.getElementsByTagName(param['tag'])); } } else { if (param['id']) filters = $Elements(filters).filterById(param['id']); filters = $Elements(filters).filterByTagName(param['tag']); } if (param['class']) filters = $Elements(filters).filterByClassName(param['class']); if (param['attribute']) filters = $Elements(filters).filterByAttribute(param['attribute'], param['value'], param['operator']); }, this); filters.each(function(el){ $(el); }); return $Elements(filters); }, getElement: function(selector){ return this.getElementsBySelector(selector)[0]; }, getElementsBySelector: function(selector){ var els = []; selector.split(',').each(function(sel){ els.extend(this.getElements(sel)); }, this); return $Elements(els); }});document.extend = Object.extend;document.extend({ getElementsByClassName: function(className){ return document.getElements('.'+className); }, getElement: Element.prototype.getElement, getElements: Element.prototype.getElements, getElementsBySelector: Element.prototype.getElementsBySelector});var Elements = new Class({ action: function(actions){ this.each(function(el){ el = $(el); if (actions.initialize) actions.initialize.apply(el); for(var action in actions){ var evt = false; if (action.test('^on[\\w]{1,}')) el[action] = actions[action]; else if (evt = action.test('([\\w-]{1,})event$')) el.addEvent(evt[1], actions[action]); } }); }, //internal methods filterById: function(id){ var found = []; this.each(function(el){ if (el.id == id) found.push(el); }); return found; }, filterByClassName: function(className){ var found = []; this.each(function(el){ if ($Element(el, 'hasClass', className)) found.push(el); }); return found; }, filterByTagName: function(tagName){ var found = []; this.each(function(el){ found.extend($A(el.getElementsByTagName(tagName))); }); return found; }, filterByAttribute: function(name, value, operator){ var found = []; this.each(function(el){ var att = el.getAttribute(name); if(!att) return; if (!operator) return found.push(el); switch(operator){ case '*=': if (att.test(value)) found.push(el); break; case '=': if (att == value) found.push(el); break; case '^=': if (att.test('^'+value)) found.push(el); break; case '$=': if (att.test(value+'$')) found.push(el); } }); return found; }});new Object.Native(Elements);ajax = Class.create();ajax.event = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];function emptyFunction() {}ajax.prototype = { initialize: function(url, options){ this.transport = this.getTransport(); this.options = options; this.postBody = options.postBody || ''; this.method = options.method || 'post'; this.update = $(options.update) || null; this.request(url); }, request: function(url){ this.transport.open(this.method, url, true); this.transport.onreadystatechange = this.onStateChange.bind(this); if (this.method == 'post') { this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=GB2312','text/xml'); if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close'); } this.transport.send(this.postBody); }, onStateChange: function(){ var event = ajax.event[this.transport.readyState]; if (event == 'Complete') { setTimeout(function(){(this.options['on' + this.transport.status] || emptyFunction)(this.transport);}.bind(this), 10); if (this.transport.status == 200 && this.update) setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10); } setTimeout(function(){(this.options['on' + event] || emptyFunction)(this.transport);}.bind(this), 10); if (event == 'Complete') this.transport.onreadystatechange = function(){}; }, getTransport: function() { if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP'); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else return false; }};Object.toQueryString = function(source){ var queryString = []; for (var property in source) queryString.push(encodeURIComponent(property)+'='+encodeURIComponent(source[property])); return queryString.join('&');};Element.extend({ send: function(options){ options = Object.extend(options, {postBody: this.toQueryString(), method: 'post'}); return new Ajax(this.getProperty('action'), options).request(); }, toQueryString: function(){ var queryString = []; $A(this.getElementsByTagName('*')).each(function(el){ var name = $(el).name; var value = el.getValue(); if (value && name) queryString.push(encodeURIComponent(name)+'='+encodeURIComponent(value)); });
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -