チェンジセット 198
- コミット日時:
- 2008/01/14 01:05:24 (1 年前)
- ファイル:
-
- as3/as3Query/samples/Box25.as (追加)
- as3/as3Query/samples/Box25.swf (追加)
- as3/as3Query/samples/Box25withTweener.as (追加)
- as3/as3Query/samples/Box25withTweener.swf (追加)
- as3/as3Query/samples/CssSelectorDemo.as (更新) (8 diffs)
- as3/as3Query/samples/CssSelectorDemo.swf (更新) (変更前)
- as3/as3Query/samples/test/Base.as (更新) (3 diffs)
- as3/as3Query/samples/test/Circle.as (更新) (1 diff)
- as3/as3Query/samples/test/Polygon.as (更新) (1 diff)
- as3/as3Query/samples/test/Rect.as (更新) (1 diff)
- as3/as3Query/samples/test/RoundRect.as (更新) (1 diff)
- as3/as3Query/samples/test/Square.as (削除)
- as3/as3Query/samples/test/Star.as (更新) (1 diff)
- as3/as3Query/src/com/nitoyon/as3query/Dom.as (更新) (2 diffs)
- as3/as3Query/src/com/nitoyon/as3query/as3Query.as (更新) (11 diffs)
- as3/as3Query/src/com/nitoyon/as3query/as3QueryEvent.as (更新) (1 diff)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/as3Query/samples/CssSelectorDemo.as
r196 r198 1 package 2 { 1 package { 3 2 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; 7 6 import flash.filters.GlowFilter; 8 7 import com.nitoyon.as3query.*; 9 8 9 // import shapes and force them to be linked in the SWF file. 10 10 import test.Circle; Circle; 11 11 import test.Rect; Rect; … … 14 14 import test.Star; Star; 15 15 16 public class CssSelectorDemo extends Sprite 17 { 16 [SWF(width="420", height="430")] 17 public class CssSelectorDemo extends Sprite { 18 // constructor 18 19 public function CssSelectorDemo() { 19 20 $(stage).attr({scaleMode: "noScale", align: "TL"}); … … 24 25 // construct CSS Test List 25 26 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, 31 35 x: 1, 32 36 y: i * 20 + 1, … … 34 38 backgroundColor: 0xaaaaff 35 39 }) 36 .hover( // hover event40 .hover( // hover event (over and out) 37 41 function(event:Event):void { 38 42 this.background = true; … … 42 46 } 43 47 ) 44 .click( // click event48 .click( // click event 45 49 function(event:Event):void { 46 50 $("#q").text(this.text); … … 56 60 } 57 61 62 // TextField change handler 58 63 private function changeHandler(event:Event):void { 59 64 var f:GlowFilter = new GlowFilter(); … … 71 76 ]; 72 77 73 // View XML78 // An XML that markups the positions and properties of shapes and TextField. 74 79 private var xml:XML = 75 80 <test.Rect width="400" height="410" x="10" y="10"> 76 81 <!--input space--> 77 82 <flash.text.TextField 83 text="Type CSS Selector:" 84 x="10" y="10" width="100" height="20" selectable="false"/> 85 86 <flash.text.TextField 78 87 id="q" type="input" 79 88 text="RoundRect" 80 x="1 0" y="10" width="380" height="20" border="true"/>89 x="120" y="10" width="270" height="20" border="true"/> 81 90 82 91 <!--shapes--> … … 121 130 <test.Rect 122 131 id="ex" 123 x="2 80" y="50" width="100" height="340" color="0xeeeeff"/>132 x="270" y="50" width="120" height="340" color="0xeeeeff"/> 124 133 </test.Rect>; 125 134 } as3/as3Query/samples/test/Base.as
r196 r198 5 5 public class Base extends Sprite 6 6 { 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 7 17 private var _color:uint; 8 18 public function get color():uint{return _color;} … … 33 43 _color = 0xffffff; 34 44 _width = _height = 10; 45 _centered = defaultCentered; 35 46 draw(); 36 47 } … … 42 53 graphics.beginFill(color); 43 54 graphics.lineStyle(1, 0x000000); 44 drawShape( );55 drawShape(_centered ? -_width / 2 : 0, _centered ? -_height / 2 : 0); 45 56 graphics.endFill(); 46 57 } 47 58 48 internal function drawShape():void 59 60 internal function drawShape(offsetX:Number, offsetY:Number):void 49 61 { 50 62 } as3/as3Query/samples/test/Circle.as
r196 r198 3 3 public class Circle extends Base 4 4 { 5 internal override function drawShape( ):void5 internal override function drawShape(offsetX:Number, offsetY:Number):void 6 6 { 7 graphics.drawEllipse( 0, 0, width, height);7 graphics.drawEllipse(offsetX, offsetY, width, height); 8 8 } 9 9 } as3/as3Query/samples/test/Polygon.as
r196 r198 11 11 } 12 12 13 internal override function drawShape( ):void13 internal override function drawShape(offsetX:Number, offsetY:Number):void 14 14 { 15 graphics.moveTo( width / 2, 0);15 graphics.moveTo(offsetX + width / 2, offsetY); 16 16 for(var i:int = 1; i < corner; i++) 17 17 { 18 18 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))); 21 21 } 22 22 } as3/as3Query/samples/test/Rect.as
r196 r198 3 3 public class Rect extends Base 4 4 { 5 internal override function drawShape( ):void5 internal override function drawShape(offsetX:Number, offsetY:Number):void 6 6 { 7 graphics.drawRect( 0, 0, width, height);7 graphics.drawRect(offsetX, offsetY, width, height); 8 8 } 9 9 } as3/as3Query/samples/test/RoundRect.as
r196 r198 19 19 } 20 20 21 internal override function drawShape( ):void21 internal override function drawShape(offsetX:Number, offsetY:Number):void 22 22 { 23 graphics.drawRoundRect( 0, 0, width, height, ellipseWidth, ellipseHeight);23 graphics.drawRoundRect(offsetX, offsetY, width, height, ellipseWidth, ellipseHeight); 24 24 } 25 25 } as3/as3Query/samples/test/Star.as
r196 r198 19 19 } 20 20 21 internal override function drawShape( ):void21 internal override function drawShape(offsetX:Number, offsetY:Number):void 22 22 { 23 graphics.moveTo( width / 2, 0);23 graphics.moveTo(offsetX + width / 2, offsetY); 24 24 for(var i:int = 0; i < corner; i++) 25 25 { 26 26 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)); 29 29 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))); 32 32 } 33 33 } as3/as3Query/src/com/nitoyon/as3query/Dom.as
r196 r198 1 1 package com.nitoyon.as3query { 2 3 import flash.display.DisplayObject; 4 import flash.display.DisplayObjectContainer; 2 5 import flash.utils.getQualifiedClassName; 3 6 import flash.utils.Dictionary; 4 import flash.display.DisplayObject;5 import flash.display.DisplayObjectContainer;6 7 7 8 public class Dom { … … 60 61 } 61 62 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; 64 72 } 65 73 as3/as3Query/src/com/nitoyon/as3query/as3Query.as
r196 r198 1 1 package com.nitoyon.as3query { 2 import flash.utils.Proxy; 2 3 import flash.events.Event; 4 import flash.display.DisplayObject; 5 import flash.display.DisplayObjectContainer; 6 import flash.display.Stage; 7 import flash.net.registerClassAlias; 8 import flash.text.StyleSheet; 9 import flash.text.TextField; 10 import flash.utils.Dictionary; 3 11 import flash.utils.flash_proxy; 4 12 import flash.utils.getDefinitionByName; 5 13 import 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; 14 import flash.utils.Proxy; 12 15 13 16 public class as3Query extends Proxy { … … 25 28 } 26 29 27 // AS3 specific implementation: stage30 // stage is an AS3 specific implementation 28 31 private static var _stage:Stage; 29 32 static internal function set stage(value:Stage):void { … … 150 153 } 151 154 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 { 153 156 var obj:Object = key; 154 157 … … 166 169 // Set all the styles 167 170 for ( var prop:String in obj ) 168 as3Query .attr(171 as3Query[type || "attr"]( 169 172 this, 170 173 prop, as3Query.prop(this, obj[prop], type, index, prop) … … 173 176 } 174 177 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 179 182 public function text(e:Object = null):Object { 180 183 if(e != null) { … … 633 636 // Handle executable functions 634 637 if(as3Query.isFunction(value)) 635 value = Function(value).call(elem, [index]);638 value = value.call(elem, [index]); 636 639 637 640 // Handle passing in a number to a CSS property … … 670 673 for ( var i in o ) 671 674 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 } 709 687 } 710 688 711 689 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 801 700 static public function clean(a:Object):Array { 802 701 var r:Array = []; … … 1013 912 } 1014 913 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 } 1027 924 1028 925 //-------------------------------------------------------------------------- … … 1038 935 1039 936 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]}, 1042 939 ":": { 1043 940 // Position Checks … … 1228 1125 // Try to do a global search by ID, where we can 1229 1126 if ( m[1] == "#" ) {//&& elem && elem.getElementById && !as3Query.isXMLDoc(elem) ) { 1230 throw new Error("not implemented");1231 1127 // Optimization for HTML document case 1232 //var oid:DisplayObject = elem.getElementById(m[2]);1128 var oid:DisplayObject = Dom.getElementById(m[2], elem); 1233 1129 1234 1130 // Do a quick check for node name (where applicable) so 1235 1131 // 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] : []; 1237 1133 } else { 1238 1134 // We need to find all descendant elements … … 1513 1409 // A private function for handling mouse 'hovering' 1514 1410 function handleHover(e:Event):Object { 1515 // Check if mouse(over|out) are still within the same parent element1516 //var p = e.relatedTarget;1517 1518 // Traverse up the tree1519 //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 it1522 //if ( p == this ) return false;1523 1524 1411 // 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 1528 1415 // Bind the function to the two event listeners 1529 return this. mouseover(handleHover).mouseout(handleHover);1416 return this.bind("rollOver", handleHover).bind("rollOut", handleHover); 1530 1417 } 1531 1418 as3/as3Query/src/com/nitoyon/as3query/as3QueryEvent.as
r196 r198 1 1 package com.nitoyon.as3query { 2 import flash.utils.Dictionary; 2 3 3 import flash.display.DisplayObject; 4 4 import flash.events.IEventDispatcher; 5 5 import flash.events.Event; 6 import flash.utils.Dictionary; 6 7 7 8 internal class as3QueryEvent {
