今回解説するeffects.
Web開発によく使われるライブラリとして,
今回の解説の見どころは,
effects.
それではコードを見ていきましょう。
0001:// script.aculo.us effects.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
0002:
0003:// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
0004:// Contributors:
0005:// Justin Palmer (http://encytemedia.com/)
0006:// Mark Pilgrim (http://diveintomark.org/)
0007:// Martin Bialasinki
0008://
0009:// script.aculo.us is freely distributable under the terms of an MIT-style license.
0010:// For details, see the script.aculo.us web site: http://script.aculo.us/
0011:
1~11行目は,
0012:// converts rgb() and #xxx to #xxxxxx format,
0013:// returns self (or first argument) if not convertable
0014:String.prototype.parseColor = function() {
0015: var color = '#';
0016: if (this.slice(0,4) == 'rgb(') {
0017: var cols = this.slice(4,this.length-1).split(',');
0018: var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
0019: } else {
0020: if (this.slice(0,1) == '#') {
0021: if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
0022: if (this.length==7) color = this.toLowerCase();
0023: }
0024: }
0025: return (color.length==7 ? color : (arguments[0] || this));
0026:};
0027:
0028:/*--------------------------------------------------------------------------*/
0029:
12~28行目のparseColorは,
16行目で,
17行目で,
18行目で,
20行目で,
21行目で,
22行目で,
25行目で,
0030:Element.collectTextNodes = function(element) {
0031: return $A($(element).childNodes).collect( function(node) {
0032: return (node.nodeType==3 ? node.nodeValue :
0033: (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
0034: }).flatten().join('');
0035:};
0036:
30~36行目のcollectTextNodesは,
31行目で,
32行目で,
33行目で,
34行目で,
0037:Element.collectTextNodesIgnoreClass = function(element, className) {
0038: return $A($(element).childNodes).collect( function(node) {
0039: return (node.nodeType==3 ? node.nodeValue :
0040: ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
0041: Element.collectTextNodesIgnoreClass(node, className) : ''));
0042: }).flatten().join('');
0043:};
0044:
37~44行目のcollectTextNodesIgnoreClassは,
0045:Element.setContentZoom = function(element, percent) {
0046: element = $(element);
0047: element.setStyle({fontSize: (percent/100) + 'em'});
0048: if (Prototype.Browser.WebKit) window.scrollBy(0,0);
0049: return element;
0050:};
0051:
45~51行目のsetContentZoomは,
47行目で,
48行目で,
0052:Element.getInlineOpacity = function(element){
0053: return $(element).style.opacity || '';
0054:};
0055:
52~55行目のgetInlineOpacityは,
53行目で,
0056:Element.forceRerendering = function(element) {
0057: try {
0058: element = $(element);
0059: var n = document.createTextNode(' ');
0060: element.appendChild(n);
0061: element.removeChild(n);
0062: } catch(e) { }
0063:};
0064:
0065:/*--------------------------------------------------------------------------*/
0066:
56~66行目のforceRerenderingは,