チェンジセット 198

差分発生行の前後
無視リスト:
コミット日時:
2008/01/14 01:05:24 (1 年前)
コミッタ:
nitoyon
ログメッセージ:

--

ファイル:

凡例:

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

    r196 r198  
    1 package 
    2 
     1package { 
    32        import flash.display.*; 
    4         import flash.text.*; TextField; 
    5         import flash.events.*
    6         import flash.utils.*
     3        import flash.text.TextField; 
     4        import flash.text.StyleSheet
     5        import flash.events.Event
    76        import flash.filters.GlowFilter; 
    87        import com.nitoyon.as3query.*; 
    98 
     9        // import shapes and force them to be linked in the SWF file. 
    1010        import test.Circle; Circle; 
    1111        import test.Rect; Rect; 
     
    1414        import test.Star; Star; 
    1515 
    16         public class CssSelectorDemo extends Sprite 
    17         { 
     16        [SWF(width="420", height="430")] 
     17        public class CssSelectorDemo extends Sprite { 
     18                // constructor 
    1819                public function CssSelectorDemo() { 
    1920                        $(stage).attr({scaleMode: "noScale", align: "TL"}); 
     
    2425                        // construct CSS Test List 
    2526                        as3Query.each(cssTest, function(i:int, css:String):void { 
    26                                 $(TextField)   // $(ClassName) == $(new ClassName()) 
    27                                         .attr({    // set attributes by Object 
    28                                                 text: css, 
    29                                                 width: Number($("#ex").attr("width")) - 1,  
    30                                                 height: 20, 
     27                                $(TextField)     // $(ClassName) equals $(new ClassName()) 
     28                                        .css("p", {  // set CSS 
     29                                                fontFamily: "sans-serif" 
     30                                        }) 
     31                                        .attr({      // set the attributes 
     32                                                text: "<p>" + css + "</p>", 
     33                                                width: Number($("#ex").attr("width")) - 2,  
     34                                                height: 19, 
    3135                                                x: 1, 
    3236                                                y: i * 20 + 1, 
     
    3438                                                backgroundColor: 0xaaaaff 
    3539                                        }) 
    36                                         .hover(    // hover event 
     40                                        .hover(      // hover event (over and out) 
    3741                                                function(event:Event):void { 
    3842                                                        this.background = true; 
     
    4246                                                } 
    4347                                        ) 
    44                                         .click(    // click event 
     48                                        .click(      // click event 
    4549                                                function(event:Event):void { 
    4650                                                        $("#q").text(this.text); 
     
    5660                } 
    5761 
     62                // TextField change handler 
    5863                private function changeHandler(event:Event):void { 
    5964                        var f:GlowFilter = new GlowFilter(); 
     
    7176                ]; 
    7277 
    73                 // View XML 
     78                // An XML that markups the positions and properties of shapes and TextField. 
    7479                private var xml:XML =  
    7580                        <test.Rect width="400" height="410" x="10" y="10"> 
    7681                                <!--input space--> 
    7782                                <flash.text.TextField  
     83                                        text="Type CSS Selector:" 
     84                                        x="10" y="10" width="100" height="20" selectable="false"/> 
     85 
     86                                <flash.text.TextField  
    7887                                        id="q" type="input" 
    7988                                        text="RoundRect" 
    80                                         x="10" y="10" width="380" height="20" border="true"/> 
     89                                        x="120" y="10" width="270" height="20" border="true"/> 
    8190 
    8291                                <!--shapes--> 
     
    121130                                <test.Rect 
    122131                                        id="ex" 
    123                                         x="280" y="50" width="100" height="340" color="0xeeeeff"/> 
     132                                        x="270" y="50" width="120" height="340" color="0xeeeeff"/> 
    124133                        </test.Rect>; 
    125134        } 
  • as3/as3Query/samples/test/Base.as

    r196 r198  
    55        public class Base extends Sprite 
    66        { 
     7                private var _centered:Boolean; 
     8                public function get centered():Boolean{return _centered;} 
     9                public function set centered(value:Boolean):void 
     10                { 
     11                        _centered = value; 
     12                        draw(); 
     13                } 
     14 
     15                public var defaultCentered:Boolean = false; 
     16 
    717                private var _color:uint; 
    818                public function get color():uint{return _color;} 
     
    3343                        _color = 0xffffff; 
    3444                        _width = _height = 10; 
     45                        _centered = defaultCentered; 
    3546                        draw(); 
    3647                } 
     
    4253                        graphics.beginFill(color); 
    4354                        graphics.lineStyle(1, 0x000000); 
    44                         drawShape(); 
     55                        drawShape(_centered ? -_width / 2 : 0, _centered ? -_height / 2 : 0); 
    4556                        graphics.endFill(); 
    4657                } 
    4758 
    48                 internal function drawShape():void 
     59 
     60                internal function drawShape(offsetX:Number, offsetY:Number):void 
    4961                { 
    5062                } 
  • as3/as3Query/samples/test/Circle.as

    r196 r198  
    33        public class Circle extends Base 
    44        { 
    5                 internal override function drawShape():void 
     5                internal override function drawShape(offsetX:Number, offsetY:Number):void 
    66                { 
    7                         graphics.drawEllipse(0, 0, width, height); 
     7                        graphics.drawEllipse(offsetX, offsetY, width, height); 
    88                } 
    99        } 
  • as3/as3Query/samples/test/Polygon.as

    r196 r198  
    1111                } 
    1212 
    13                 internal override function drawShape():void 
     13                internal override function drawShape(offsetX:Number, offsetY:Number):void 
    1414                { 
    15                         graphics.moveTo(width / 2, 0); 
     15                        graphics.moveTo(offsetX + width / 2, offsetY); 
    1616                        for(var i:int = 1; i < corner; i++) 
    1717                        { 
    1818                                var rad:Number = 2 * Math.PI / corner * i; 
    19                                 graphics.lineTo(width  / 2 * (1 + Math.sin(rad)),  
    20                                                 height / 2 * (1 - Math.cos(rad))); 
     19                                graphics.lineTo(offsetX + width  / 2 * (1 + Math.sin(rad)),  
     20                                                offsetY + height / 2 * (1 - Math.cos(rad))); 
    2121                        } 
    2222                } 
  • as3/as3Query/samples/test/Rect.as

    r196 r198  
    33        public class Rect extends Base 
    44        { 
    5                 internal override function drawShape():void 
     5                internal override function drawShape(offsetX:Number, offsetY:Number):void 
    66                { 
    7                         graphics.drawRect(0, 0, width, height); 
     7                        graphics.drawRect(offsetX, offsetY, width, height); 
    88                } 
    99        } 
  • as3/as3Query/samples/test/RoundRect.as

    r196 r198  
    1919                } 
    2020 
    21                 internal override function drawShape():void 
     21                internal override function drawShape(offsetX:Number, offsetY:Number):void 
    2222                { 
    23                         graphics.drawRoundRect(0, 0, width, height, ellipseWidth, ellipseHeight); 
     23                        graphics.drawRoundRect(offsetX, offsetY, width, height, ellipseWidth, ellipseHeight); 
    2424                } 
    2525        } 
  • as3/as3Query/samples/test/Star.as

    r196 r198  
    1919                } 
    2020 
    21                 internal override function drawShape():void 
     21                internal override function drawShape(offsetX:Number, offsetY:Number):void 
    2222                { 
    23                         graphics.moveTo(width / 2, 0); 
     23                        graphics.moveTo(offsetX + width / 2, offsetY); 
    2424                        for(var i:int = 0; i < corner; i++) 
    2525                        { 
    2626                                var rad:Number = Math.PI / corner * (2 * i + 1); 
    27                                 graphics.lineTo(width  / 2 * (1 + Math.sin(rad) * ratio),  
    28                                                 height / 2 * (1 - Math.cos(rad) * ratio)); 
     27                                graphics.lineTo(offsetX + width  / 2 * (1 + Math.sin(rad) * ratio),  
     28                                                offsetY + height / 2 * (1 - Math.cos(rad) * ratio)); 
    2929                                rad = Math.PI / corner * (2 * i + 2); 
    30                                 graphics.lineTo(width  / 2 * (1 + Math.sin(rad)),  
    31                                                 height / 2 * (1 - Math.cos(rad))); 
     30                                graphics.lineTo(offsetX + width  / 2 * (1 + Math.sin(rad)),  
     31                                                offsetY + height / 2 * (1 - Math.cos(rad))); 
    3232                        } 
    3333                } 
  • as3/as3Query/src/com/nitoyon/as3query/Dom.as

    r196 r198  
    11package com.nitoyon.as3query { 
     2 
     3import flash.display.DisplayObject; 
     4import flash.display.DisplayObjectContainer; 
    25import flash.utils.getQualifiedClassName; 
    36import flash.utils.Dictionary; 
    4 import flash.display.DisplayObject; 
    5 import flash.display.DisplayObjectContainer; 
    67 
    78public class Dom { 
     
    6061        } 
    6162 
    62         static public function getElementById( id:String ):DisplayObject { 
    63                 return idList[ id ]; 
     63        static public function getElementById( id:String, elem:DisplayObject = null ):DisplayObject { 
     64                var ret:DisplayObject = idList[ id ]; 
     65                if ( !elem )  
     66                        return ret; 
     67                else if( elem is DisplayObjectContainer  
     68                        && DisplayObjectContainer(elem).contains(ret) ) 
     69                                return ret; 
     70                else 
     71                        return null; 
    6472        } 
    6573 
  • as3/as3Query/src/com/nitoyon/as3query/as3Query.as

    r196 r198  
    11package com.nitoyon.as3query { 
    2 import flash.utils.Proxy; 
     2 
     3import flash.events.Event; 
     4import flash.display.DisplayObject; 
     5import flash.display.DisplayObjectContainer; 
     6import flash.display.Stage; 
     7import flash.net.registerClassAlias; 
     8import flash.text.StyleSheet; 
     9import flash.text.TextField; 
     10import flash.utils.Dictionary; 
    311import flash.utils.flash_proxy; 
    412import flash.utils.getDefinitionByName; 
    513import flash.utils.getQualifiedClassName; 
    6 import flash.utils.Dictionary; 
    7 import flash.events.Event; 
    8 import flash.net.registerClassAlias; 
    9 import flash.display.DisplayObject; 
    10 import flash.display.DisplayObjectContainer; 
    11 import flash.display.Stage; 
     14import flash.utils.Proxy; 
    1215 
    1316public class as3Query extends Proxy { 
     
    2528        } 
    2629 
    27         // AS3 specific implementation: stage 
     30        // stage is an AS3 specific implementation 
    2831        private static var _stage:Stage; 
    2932        static internal function set stage(value:Stage):void { 
     
    150153        } 
    151154 
    152         public function attr(key:Object, value:Object = null, type:String = ""):Object { 
     155        public function attr(key:Object, value:Object = null, type:String = null):Object { 
    153156                var obj:Object = key; 
    154157 
     
    166169                        // Set all the styles 
    167170                        for ( var prop:String in obj ) 
    168                                 as3Query.attr
     171                                as3Query[type || "attr"]
    169172                                        this, 
    170173                                        prop, as3Query.prop(this, obj[prop], type, index, prop) 
     
    173176        } 
    174177 
    175 /*     css: function( key, value )
    176                 return this.attr( key, value, "curCSS" ); 
    177         }, 
    178 */ 
     178       public function css( key:String, value:Object = null ):Object
     179                return attr( key, value, "css" ); 
     180        } 
     181 
    179182        public function text(e:Object = null):Object { 
    180183                if(e != null) { 
     
    633636                // Handle executable functions 
    634637                if(as3Query.isFunction(value)) 
    635                         value = Function(value).call(elem, [index]); 
     638                        value = value.call(elem, [index]); 
    636639 
    637640                // Handle passing in a number to a CSS property 
     
    670673                for ( var i in o ) 
    671674                        e.style[i] = e.style["old"+i]; 
    672         }, 
    673  
    674         css: function(e,p) { 
    675                 if ( p == "height" || p == "width" ) { 
    676                         var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; 
    677  
    678                         as3Query.each( d, function(){ 
    679                                 old["padding" + this] = 0; 
    680                                 old["border" + this + "Width"] = 0; 
    681                         }); 
    682  
    683                         as3Query.swap( e, old, function() { 
    684                                 if ( as3Query(e).is(':visible') ) { 
    685                                         oHeight = e.offsetHeight; 
    686                                         oWidth = e.offsetWidth; 
    687                                 } else { 
    688                                         e = as3Query(e.cloneNode(true)) 
    689                                                 .find(":radio").removeAttr("checked").end() 
    690                                                 .css({ 
    691                                                         visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" 
    692                                                 }).appendTo(e.parentNode)[0]; 
    693  
    694                                         var parPos = as3Query.css(e.parentNode,"position") || "static"; 
    695                                         if ( parPos == "static" ) 
    696                                                 e.parentNode.style.position = "relative"; 
    697  
    698                                         oHeight = e.clientHeight; 
    699                                         oWidth = e.clientWidth; 
    700  
    701                                         if ( parPos == "static" ) 
    702                                                 e.parentNode.style.position = "static"; 
    703  
    704                                         e.parentNode.removeChild(e); 
    705                                 } 
    706                         }); 
    707  
    708                         return p == "height" ? oHeight : oWidth; 
     675        },*/ 
     676 
     677        static public function css(e:DisplayObject, p:String, value:Object = null):Object { 
     678                if ( value != null ) { 
     679                        if ( e is TextField ) { 
     680                                var tf:TextField = TextField(e); 
     681                                tf.styleSheet = tf.styleSheet || new StyleSheet(); 
     682                                if(value is String) 
     683                                        tf.styleSheet.parseCSS(value.toString()); 
     684                                else 
     685                                        tf.styleSheet.setStyle( p, as3Query.extend(as3Query.curCSS( e, p) || {}, value) ); 
     686                        } 
    709687                } 
    710688 
    711689                return as3Query.curCSS( e, p ); 
    712         }, 
    713  
    714         curCSS: function(elem, prop, force) { 
    715                 var ret, stack = [], swap = []; 
    716  
    717                 // A helper method for determining if an element's values are broken 
    718                 function color(a){ 
    719                         if ( !as3Query.browser.safari ) 
    720                                 return false; 
    721  
    722                         var ret = document.defaultView.getComputedStyle(a,null); 
    723                         return !ret || ret.getPropertyValue("color") == ""; 
    724                 } 
    725  
    726                 if (prop == "opacity" && as3Query.browser.msie) { 
    727                         ret = as3Query.attr(elem.style, "opacity"); 
    728                         return ret == "" ? "1" : ret; 
    729                 } 
    730                  
    731                 if (prop.match(/float/i)) 
    732                         prop = styleFloat; 
    733  
    734                 if (!force && elem.style[prop]) 
    735                         ret = elem.style[prop]; 
    736  
    737                 else if (document.defaultView && document.defaultView.getComputedStyle) { 
    738  
    739                         if (prop.match(/float/i)) 
    740                                 prop = "float"; 
    741  
    742                         prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); 
    743                         var cur = document.defaultView.getComputedStyle(elem, null); 
    744  
    745                         if ( cur && !color(elem) ) 
    746                                 ret = cur.getPropertyValue(prop); 
    747  
    748                         // If the element isn't reporting its values properly in Safari 
    749                         // then some display: none elements are involved 
    750                         else { 
    751                                 // Locate all of the parent display: none elements 
    752                                 for ( var a = elem; a && color(a); a = a.parentNode ) 
    753                                         stack.unshift(a); 
    754  
    755                                 // Go through and make them visible, but in reverse 
    756                                 // (It would be better if we knew the exact display type that they had) 
    757                                 for ( a = 0; a < stack.length; a++ ) 
    758                                         if ( color(stack[a]) ) { 
    759                                                 swap[a] = stack[a].style.display; 
    760                                                 stack[a].style.display = "block"; 
    761                                         } 
    762  
    763                                 // Since we flip the display style, we have to handle that 
    764                                 // one special, otherwise get the value 
    765                                 ret = prop == "display" && swap[stack.length-1] != null ? 
    766                                         "none" : 
    767                                         document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || ""; 
    768  
    769                                 // Finally, revert the display styles back 
    770                                 for ( a = 0; a < swap.length; a++ ) 
    771                                         if ( swap[a] != null ) 
    772                                                 stack[a].style.display = swap[a]; 
    773                         } 
    774  
    775                         if ( prop == "opacity" && ret == "" ) 
    776                                 ret = "1"; 
    777  
    778                 } else if (elem.currentStyle) { 
    779                         var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); 
    780                         ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; 
    781  
    782                         // From the awesome hack by Dean Edwards 
    783                         // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 
    784  
    785                         // If we're not dealing with a regular pixel number 
    786                         // but a number that has a weird ending, we need to convert it to pixels 
    787                         if ( !/^\d+(px)?$/i.test(ret) && /^\d/.test(ret) ) { 
    788                                 var style = elem.style.left; 
    789                                 var runtimeStyle = elem.runtimeStyle.left; 
    790                                 elem.runtimeStyle.left = elem.currentStyle.left; 
    791                                 elem.style.left = ret || 0; 
    792                                 ret = elem.style.pixelLeft + "px"; 
    793                                 elem.style.left = style; 
    794                                 elem.runtimeStyle.left = runtimeStyle; 
    795                         } 
    796                 } 
    797  
    798                 return ret; 
    799         }, 
    800 */ 
     690        } 
     691 
     692        static private function curCSS(elem:DisplayObject, prop:String, force:Boolean = false):Object { 
     693                if (elem is TextField) { 
     694                        var tf:TextField = TextField(elem); 
     695                        return tf.styleSheet ? tf.styleSheet.getStyle(prop) : null; 
     696                } 
     697                return null; 
     698        } 
     699 
    801700        static public function clean(a:Object):Array { 
    802701                var r:Array = []; 
     
    1013912        } 
    1014913 
    1015 /*      empty: function() { 
    1016                 // Clean up the cache 
    1017                 jQuery("*", this).each(function(){ jQuery.removeData(this); }); 
    1018  
    1019                 while ( this.firstChild ) 
    1020                         this.removeChild( this.firstChild ); 
    1021         } 
    1022 }, function(i,n){ 
    1023         jQuery.fn[ i ] = function() { 
    1024                 return this.each( n, arguments ); 
    1025         }; 
    1026 });*/ 
     914        public function empty():as3Query { 
     915                return each( function( ...args ):void { 
     916                        // Clean up the cache 
     917                        as3Query.create("*", this).each(function(...args):void{ as3Query.removeData(this); }); 
     918 
     919                        var c:DisplayObjectContainer = this as DisplayObjectContainer; 
     920                        while ( c && c.numChildren ) 
     921                                c.removeChildAt(0); 
     922                }); 
     923        } 
    1027924 
    1028925        //-------------------------------------------------------------------------- 
     
    1038935 
    1039936        static private const expr:Object = { 
    1040                 "": function(a:DisplayObject,i:int, m:Array, r:Array):Boolean{return m[2]=='*'||Dom.nodeNameCmp(a,m[2])}, 
    1041 //             "#": function(a:DisplayObject,i:int){return a.getAttribute('id')==m[2]}, 
     937                "": function(a:DisplayObject,i:int, m:Array, r:Array):Boolean{return m[2]=='*'||Dom.nodeNameCmp(a,m[2])}, 
     938               "#": function(a:DisplayObject,i:int, m:Array, r:Array):Boolean{return as3Query.data(a, "id")==m[2]}, 
    1042939                ":": { 
    1043940                        // Position Checks 
     
    12281125                                        // Try to do a global search by ID, where we can 
    12291126                                        if ( m[1] == "#" ) {//&& elem && elem.getElementById && !as3Query.isXMLDoc(elem) ) { 
    1230                                                 throw new Error("not implemented"); 
    12311127                                                // Optimization for HTML document case 
    1232                                                 //var oid:DisplayObject = elem.getElementById(m[2]); 
     1128                                                var oid:DisplayObject = Dom.getElementById(m[2], elem); 
    12331129                                                 
    12341130                                                // Do a quick check for node name (where applicable) so 
    12351131                                                // that div#foo searches will be really fast 
    1236                                                 //ret = r = oid && (!m[3] || as3Query.nodeName(oid, m[3])) ? [oid] : []; 
     1132                                                ret = r = oid && (!m[3] || Dom.nodeNameCmp(oid, m[3])) ? [oid] : []; 
    12371133                                        } else { 
    12381134                                                // We need to find all descendant elements 
     
    15131409                // A private function for handling mouse 'hovering' 
    15141410                function handleHover(e:Event):Object { 
    1515                         // Check if mouse(over|out) are still within the same parent element 
    1516                         //var p = e.relatedTarget; 
    1517          
    1518                         // Traverse up the tree 
    1519                         //while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; }; 
    1520                          
    1521                         // If we actually just moused on to a sub-element, ignore it 
    1522                         //if ( p == this ) return false; 
    1523                          
    15241411                        // Execute the right function 
    1525                         return (e.type == "mouseOver" ? f : g).apply(this, [e]); 
    1526                 } 
    1527                  
     1412                        return (e.type == "rollOver" ? f : g).apply(this, [e]); 
     1413                } 
     1414 
    15281415                // Bind the function to the two event listeners 
    1529                 return this.mouseover(handleHover).mouseout(handleHover); 
     1416                return this.bind("rollOver", handleHover).bind("rollOut", handleHover); 
    15301417        } 
    15311418 
  • as3/as3Query/src/com/nitoyon/as3query/as3QueryEvent.as

    r196 r198  
    11package com.nitoyon.as3query { 
    2 import flash.utils.Dictionary; 
     2 
    33import flash.display.DisplayObject; 
    44import flash.events.IEventDispatcher; 
    55import flash.events.Event; 
     6import flash.utils.Dictionary; 
    67 
    78internal class as3QueryEvent {