チェンジセット 184

差分発生行の前後
無視リスト:
コミット日時:
2007/12/31 04:50:36 (4 年前)
コミッタ:
nitoyon
ログメッセージ:

--

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/aQuery/samples/Test.as

    r182 r184  
    22{ 
    33        import flash.display.*; 
    4         import flash.text.*; 
     4        import flash.text.*; TextField; 
    55        import flash.events.*; 
    66        import flash.utils.*; 
    77        import test.Circle; Circle; 
    88        import test.Circle2; Circle2; 
    9         import com.nitoyon.aquery.$
     9        import com.nitoyon.aquery.*
    1010         
    1111        public class Test extends Sprite 
     
    1313                public function Test() 
    1414                { 
     15                        $(stage); 
     16 
     17                        for(var i:int = 0; i < 25; i++) { 
     18                                $(TextField) 
     19                                        .text(i) 
     20                                        .attr({ 
     21                                                x : (i % 5) * 20,  
     22                                                y : Math.floor(i / 5) * 20, 
     23                                                selectable : false 
     24                                        }) 
     25                                        .appendTo(this); 
     26                        } 
     27 
     28                        $("TextField:odd").hide(); 
     29                        $(this).bind("click", function(event:*):void{ 
     30                                $("TextField:odd").toggle(); 
     31                        }); 
     32 
    1533                        var s1:Sprite = new Sprite(); 
    1634                        addChild(s1); 
     
    3553                        $(s1).attr({alpha : 0.8, x : 30, y : 40}); 
    3654                        $(s2).attr({alpha : 0.5, x : 60, y : 50}); 
    37 /*                    $(s1).prepend(s3); 
     55                      $(s1).prepend(s3); 
    3856                        $(new Circle()).appendTo(s1).attr({x : 20, y : 20}); 
    3957                        $(new Circle()).appendTo(s1).attr({x : 50, y : 50}); 
    40 */ 
     58 
    4159                        $(<test.Circle><test.Circle2/><test.Circle2 x="20" y='20'/></test.Circle>) 
    4260                                .attr({x : 20, y : 20}) 
    4361                                .appendTo(s1); 
    4462 
    45                         $([s1, s2]) 
    46                                 .filter(function(index:int):Boolean{return index == 1}
    47                                         .attr("scaleX", .5); 
     63                        $([s1, s2, s3]) 
     64                                .filter(":nth-child(odd)"
     65                                        .attr("scaleX", 2); 
    4866 
    4967                        var t1:TextField = new TextField(); 
     
    5674                                $(t1).remove(); 
    5775                        }); 
     76 
     77                        $(stage); 
     78                        $("Circle2").hide(); 
    5879                } 
    5980        } 
  • as3/aQuery/src/com/nitoyon/aquery/aQuery.as

    r183 r184  
    5858                } else if( a is XML ) { 
    5959                        a = aQuery.clean( [ a ]); 
     60                // HANDLE: $(Class) 
     61                } else if( a is Class ) { 
     62                        a = new a(); 
    6063                } 
    6164 
     
    158161*/ 
    159162        public function text(e:Object = null):Object { 
    160                 if(e is String) { 
     163                if(e != null) { 
    161164                        return each(function(index:int, val:Object):void{ 
    162165                                if( this.hasOwnProperty("text") ) { 
    163                                         this["text"] = String(e); 
     166                                        this["text"] = e.toString(); 
    164167                                } 
    165168                        }); 
     
    282285                        }) || 
    283286 
    284                         aQuery.multiFilter(t,_array) ); 
    285         } 
    286  
    287 /*      not: function(t) { 
    288                 return this.pushStack( 
    289                         t.constructor == String && 
    290                         aQuery.multiFilter(t, this, true) || 
    291  
    292                         aQuery.grep(this, function(a) { 
    293                                 return ( t.constructor == Array || t.aQuery ) 
    294                                         ? aQuery.inArray( a, t ) < 0 
    295                                         : a != t; 
     287                        aQuery.multiFilter(t.toString(),_array) ); 
     288        } 
     289 
     290        public function not(t:Object):aQuery { 
     291                return pushStack( 
     292                        t is String && 
     293                        aQuery.multiFilter(t as String, _array, true) || 
     294 
     295                        aQuery.grep(this, function(a:Object):Boolean { 
     296                                return ( t is Array ? aQuery.inArray( a, t as Array ) < 0 :  
     297                                         t is aQuery ? aQuery.inArray( a, t._array ) < 0 : a != t); 
    296298                        }) 
    297299                ); 
    298         }, 
    299  
    300         add: function(t)
    301                 return this.pushStack( aQuery.merge( 
    302                         this.get()
    303                         t.constructor == String ? 
    304                                 aQuery(t).get()
    305                                 t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ? 
    306                                        t : [t] ) 
     300        } 
     301 
     302        public function add(t:Object):aQuery
     303                return pushStack( aQuery.merge( 
     304                        get() as Array
     305                        t is String ? 
     306                                aQuery(t).get() as Array
     307                                t is Array ? t as Array :  
     308                                t is aQuery ? t.get() as Array : [t] ) 
    307309                ); 
    308         }, 
    309  
    310         is: function(expr)
    311                 return expr ? aQuery.multiFilter(expr,this).length > 0 : false; 
    312         }, 
    313  
    314         hasClass: function(expr)
    315                 return this.is("." + expr); 
    316         }, 
     310        } 
     311 
     312        public function _is(expr:String):Boolean
     313                return expr ? aQuery.multiFilter(expr, _array).length > 0 : false; 
     314        } 
     315 
     316        public function hasClass(expr:String):Boolean
     317                return _is("." + expr); 
     318        } 
    317319         
    318       val: function( val ) { 
     320/*    val: function( val ) { 
    319321                if ( val == undefined ) { 
    320322                        if ( this.length ) { 
     
    387389                return this.after( val ).remove(); 
    388390        }, 
    389  
    390         slice: function() { 
    391                 return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); 
    392         }, 
    393391*/ 
     392        public function slice(...args):aQuery { 
     393                return pushStack( _array.slice.apply( this, args ) ); 
     394        } 
     395 
    394396        public function map(fn:Function):aQuery { 
    395397                return pushStack(aQuery.map( this, function(elem:Object,i:int):Object{ 
     
    397399                })); 
    398400        } 
    399 /* 
    400         andSelf: function()
    401                 return this.add( this.prevObject ); 
    402         }, 
    403 */ 
     401 
     402        public function andSelf():aQuery
     403                return add( prevObject ); 
     404        } 
     405 
    404406        public function domManip(args:Array, table:Boolean, dir:int, fn:Function):aQuery 
    405407        { 
     
    431433                } 
    432434                return null; 
     435        } 
     436 
     437        public function extend( ...args ):Object { 
     438                // extend jQuery itself if only one argument is passed 
     439                if ( args.length == 1 ) { 
     440                        return aQuery.extend( this, args[0] ); 
     441                } 
     442 
     443                return aQuery.extend.apply( null, args ); 
     444        } 
     445 
     446        public static function extend( ...args ):Object { 
     447                // copy reference to target object 
     448                var target:Object = args[0], a:int = 1, al:int = args.length, deep:Boolean = false; 
     449 
     450                // Handle a deep copy situation 
     451                if ( target is Boolean ) { 
     452                        deep = Boolean(target); 
     453                        target = args[1] || {}; 
     454                } 
     455 
     456                var prop:Object; 
     457 
     458                for ( ; a < al; a++ ) 
     459                        // Only deal with non-null/undefined values 
     460                        if ( (prop = args[a]) != null ) 
     461                                // Extend the base object 
     462                                for ( var i:Object in prop ) { 
     463                                        // Prevent never-ending loop 
     464                                        if ( target == prop[i] ) 
     465                                                continue; 
     466 
     467                                        // Recurse if we're merging object values 
     468                                        if ( deep && prop[i] is Object && target[i] ) 
     469                                                aQuery.extend( target[i], prop[i] ); 
     470 
     471                                        // Don't bring in undefined values 
     472                                        else if ( prop[i] != undefined ) 
     473                                                target[i] = prop[i]; 
     474                                } 
     475 
     476                // Return the modified object 
     477                return target; 
    433478        } 
    434479 
     
    536581        } 
    537582         
    538         static public function prop(elem:Object, value:Object, type:Object, index:int, prop:Object):Object 
    539         { 
     583        static public function prop(elem:Object, value:Object, type:Object, index:int, prop:Object):Object { 
    540584                // Handle executable functions 
    541585                if(aQuery.isFunction(value)) 
     
    795839        } 
    796840 
    797 /*     inArray: function( b, a )
    798                 for ( var i = 0, al = a.length; i < al; i++ ) 
     841       static public function inArray( b:Object, a:Array ):int
     842                for ( var i:int = 0, al:int = a.length; i < al; i++ ) 
    799843                        if ( a[i] == b ) 
    800844                                return i; 
    801845                return -1; 
    802         }, 
    803 */ 
     846        } 
     847 
    804848        static public function merge(first:Array, second:Array):Array { 
    805849                first.push.apply(first, second); 
     
    894938        },*/ 
    895939 
    896         public function remove( a:Object = null ):aQuery { 
    897                 return each( function( a:Object, v:Object = null ):void { 
     940        public function remove( a:String = null ):aQuery { 
     941                return each( function( ...args ):void { 
    898942                        if ( !a || aQuery.filter( a, [this] ).r.length ) { 
    899943                                aQuery.removeData( this ); 
     
    9921036        ]; 
    9931037 
    994         static private function multiFilter( expr:Object, elems:Array, not:Boolean = false ):Array { 
     1038        static private function multiFilter( expr:String, elems:Array, not:Boolean = false ):Array { 
    9951039                var old:Object, cur:Array = []; 
    9961040 
     
    11231167                                                        var tag:String = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2]; 
    11241168 
    1125                                                         // Handle IE7 being really dumb about <object>s 
    1126                                                         if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" ) 
    1127                                                                 tag = "param"; 
    1128  
    11291169                                                        r = aQuery.merge( r, Dom.getElementsByTagName( tag, ret[i] )); 
    11301170                                                } 
     
    11941234        } 
    11951235 
    1196         static private function filter(t:Object,r:Array,not:Boolean = false):Object { 
     1236        static private function filter(t:String,r:Array,not:Boolean = false):Object { 
    11971237                var last:Object; 
    11981238 
     
    12891329                        } else { 
    12901330                                var f:Object = aQuery.expr[m[1]]; 
    1291                                 if ( f is String
     1331                                if ( f is Object
    12921332                                        f = aQuery.expr[m[1]][m[2]]; 
    12931333 
     
    13591399                }); 
    13601400        } 
     1401 
     1402        public function show(speed:Number = 0, callback:Function = null):aQuery { 
     1403                /*return speed ? 
     1404                        animate({ 
     1405                                height: "show", width: "show", opacity: "show" 
     1406                        }, speed, callback) : 
     1407                        */ 
     1408                return filter(":hidden").each(function(...args):void{ 
     1409                                this.visible = true; 
     1410                        }).end(); 
     1411        } 
     1412         
     1413        public function hide(speed:Number = 0, callback:Function = null):aQuery { 
     1414                /*return speed ? 
     1415                        animate({ 
     1416                                height: "hide", width: "hide", opacity: "hide" 
     1417                        }, speed, callback) : 
     1418                        */ 
     1419                return filter(":visible").each(function(...args):void{ 
     1420                                this.visible = false; 
     1421                        }).end(); 
     1422        } 
     1423 
     1424        // Save the old toggle function 
     1425//      _toggle: jQuery.fn.toggle, 
     1426         
     1427        public function toggle():aQuery {// fn, fn2 ){ 
     1428                /*return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ? 
     1429                        this._toggle( fn, fn2 ) : 
     1430                        fn ? 
     1431                                this.animate({ 
     1432                                        height: "toggle", width: "toggle", opacity: "toggle" 
     1433                                }, fn, fn2) :*/ 
     1434                return each(function(...args):void{ 
     1435                        aQuery.create(this)[ aQuery.create(this)._is(":hidden") ? "show" : "hide" ](); 
     1436                }); 
     1437        } 
     1438         
     1439/*      slideDown: function(speed,callback){ 
     1440                return this.animate({height: "show"}, speed, callback); 
     1441        }, 
     1442         
     1443        slideUp: function(speed,callback){ 
     1444                return this.animate({height: "hide"}, speed, callback); 
     1445        }, 
     1446 
     1447        slideToggle: function(speed, callback){ 
     1448                return this.animate({height: "toggle"}, speed, callback); 
     1449        }, 
     1450         
     1451        fadeIn: function(speed, callback){ 
     1452                return this.animate({opacity: "show"}, speed, callback); 
     1453        }, 
     1454         
     1455        fadeOut: function(speed, callback){ 
     1456                return this.animate({opacity: "hide"}, speed, callback); 
     1457        }, 
     1458         
     1459        fadeTo: function(speed,to,callback){ 
     1460                return this.animate({opacity: to}, speed, callback); 
     1461        }, 
     1462 
     1463        public function animate( prop:Object, speed, easing:Number, callback:Function ):aQuery { 
     1464                var opt = aQuery.speed(speed, easing, callback); 
     1465 
     1466                return this[ opt.queue === false ? "each" : "queue" ](function(... args):void { 
     1467                        opt = aQuery.extend({}, opt); 
     1468                        var hidden:Boolean = jQuery(this)._is(":hidden"), self:DisplayObject = this; 
     1469                         
     1470                        for ( var p:String in prop ) { 
     1471                                if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) 
     1472                                        return aQuery.isFunction(opt.complete) && opt.complete.apply(this); 
     1473 
     1474                                if ( p == "height" || p == "width" ) { 
     1475                                        // Store display property 
     1476                                        opt.display = this.visible; 
     1477                                } 
     1478                        } 
     1479 
     1480                        opt.curAnim = aQuery.extend({}, prop); 
     1481                         
     1482                        jQuery.each( prop, function(name:String, val){ 
     1483                                var e = new jQuery.fx( self, opt, name ); 
     1484 
     1485                                if ( /toggle|show|hide/.test(val) ) 
     1486                                        e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop ); 
     1487                                else { 
     1488                                        var parts = val.toString().match(/^([+-]?)([\d.]+)(.*)$/), 
     1489                                                start = e.cur(true) || 0; 
     1490 
     1491                                        if ( parts ) { 
     1492                                                end = parseFloat(parts[2]), 
     1493                                                unit = parts[3] || "px"; 
     1494 
     1495                                                // We need to compute starting value 
     1496                                                if ( unit != "px" ) { 
     1497                                                        self.style[ name ] = end + unit; 
     1498                                                        start = (end / e.cur(true)) * start; 
     1499                                                        self.style[ name ] = start + unit; 
     1500                                                } 
     1501 
     1502                                                // If a +/- token was provided, we're doing a relative animation 
     1503                                                if ( parts[1] ) 
     1504                                                        end = ((parts[1] == "-" ? -1 : 1) * end) + start; 
     1505 
     1506                                                e.custom( start, end, unit ); 
     1507                                        } else 
     1508                                                e.custom( start, val, "" ); 
     1509                                } 
     1510                        }); 
     1511 
     1512                        // For JS strict compliance 
     1513                        return true; 
     1514                }); 
     1515        }, 
     1516*/ 
     1517        public function queue(type:String, fn:Object):aQuery { 
     1518                if ( !fn ) { 
     1519                        fn = type; 
     1520                        type = "fx"; 
     1521                } 
     1522 
     1523                return each(function(... args):void { 
     1524                        if ( fn is Array ) 
     1525                                aQuery.queue(this, type, fn as Array); 
     1526                        else { 
     1527                                aQuery.queue(this, type).push( fn ); 
     1528                         
     1529                                if ( aQuery.queue(this, type).length == 1 ) 
     1530                                        fn.apply(this); 
     1531                        } 
     1532                }); 
     1533        } 
     1534 
     1535/*      stop: function(){ 
     1536                var timers = jQuery.timers; 
     1537 
     1538                return this.each(function(){ 
     1539                        for ( var i = 0; i < timers.length; i++ ) 
     1540                                if ( timers[i].elem == this ) 
     1541                                        timers.splice(i--, 1); 
     1542                }).dequeue(); 
     1543        } 
     1544*/ 
     1545 
     1546        static private function queue( elem:DisplayObject, type:String, array:Array = null ):Array { 
     1547                if ( !elem ) 
     1548                        return []; 
     1549 
     1550                var q:Array = aQuery.data( elem, type + "queue" ) as Array; 
     1551 
     1552                if ( !q || array ) 
     1553                        q = aQuery.data( elem, type + "queue",  
     1554                                array ? aQuery.makeArray(array) : [] ) as Array; 
     1555 
     1556                return q; 
     1557        } 
     1558 
     1559        public function dequeue(type:String = null):aQuery { 
     1560                type = type || "fx"; 
     1561 
     1562                return each(function(... args):void{ 
     1563                        var q:Array = aQuery.queue(this, type); 
     1564 
     1565                        q.shift(); 
     1566 
     1567                        if ( q.length ) 
     1568                                q[0].apply( this ); 
     1569                }); 
     1570        } 
     1571 
     1572        static private function speed(speed:Object, easing:String, fn:Function):Object { 
     1573                var opt:Object = speed && speed is Object ? speed : { 
     1574                        complete: fn || fn != null && easing ||  
     1575                                aQuery.isFunction( speed ) && speed, 
     1576                        duration: speed, 
     1577                        easing: fn && easing || easing && !(easing is Function) && easing 
     1578                }; 
     1579 
     1580                opt.duration = (opt.duration && opt.duration is Number ?  
     1581                        opt.duration :  
     1582                        { slow: 600, fast: 200 }[opt.duration]) || 400; 
     1583         
     1584                // Queueing 
     1585                opt.old = opt.complete; 
     1586                opt.complete = function():void{ 
     1587                        aQuery(this).dequeue(); 
     1588                        if ( aQuery.isFunction( opt.old ) ) 
     1589                                opt.old.apply( this ); 
     1590                }; 
     1591         
     1592                return opt; 
     1593        } 
     1594         
     1595/*      easing: { 
     1596                linear: function( p, n, firstNum, diff ) { 
     1597                        return firstNum + diff * p; 
     1598                }, 
     1599                swing: function( p, n, firstNum, diff ) { 
     1600                        return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum; 
     1601                } 
     1602        }, 
     1603         
     1604        timers: [], 
     1605 
     1606        fx: function( elem, options, prop ){ 
     1607                this.options = options; 
     1608                this.elem = elem; 
     1609                this.prop = prop; 
     1610 
     1611                if ( !options.orig ) 
     1612                        options.orig = {}; 
     1613        }*/ 
     1614 
    13611615} 
    13621616}