チェンジセット 198: as3/as3Query/src
- コミット日時:
- 2008/01/14 01:05:24 (4 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
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 {

