| 1 | package string {
|
|---|
| 2 |
|
|---|
| 3 | public class Css {
|
|---|
| 4 | public var text_align:String;
|
|---|
| 5 | public var font_size:Number;
|
|---|
| 6 | private var text_decoration:String;
|
|---|
| 7 | private var margin:String;
|
|---|
| 8 | public var margin_top:Number;
|
|---|
| 9 | public var margin_bottom:Number;
|
|---|
| 10 | public var margin_left:Number;
|
|---|
| 11 | public var margin_right:Number;
|
|---|
| 12 |
|
|---|
| 13 | private var padding:String;
|
|---|
| 14 | public var padding_top:Number=0;
|
|---|
| 15 | public var padding_bottom:Number=0;
|
|---|
| 16 | public var padding_left:Number=0;
|
|---|
| 17 | public var padding_right:Number=0;
|
|---|
| 18 |
|
|---|
| 19 | public var font_weight:String;
|
|---|
| 20 | public var font_style:String;
|
|---|
| 21 | public var font_family:String;
|
|---|
| 22 | public var color:Number;
|
|---|
| 23 | private var stop_process:Number; // Flag for disable checking
|
|---|
| 24 | public var background_colour:Number;
|
|---|
| 25 | public var background_colour_set:Boolean;
|
|---|
| 26 |
|
|---|
| 27 | private var display:String;
|
|---|
| 28 |
|
|---|
| 29 | public function Css( txt:String ) {
|
|---|
| 30 | // To lower case
|
|---|
| 31 | txt.toLowerCase();
|
|---|
| 32 |
|
|---|
| 33 | // monk.e.boy: remove the { and }
|
|---|
| 34 | txt = txt.replace( '{', '' );
|
|---|
| 35 | txt = txt.replace( '}', '' );
|
|---|
| 36 |
|
|---|
| 37 | // monk.e.boy: setup some default values.
|
|---|
| 38 | // does this confilct with 'clear()'?
|
|---|
| 39 | this.margin_top = 0;
|
|---|
| 40 | this.margin_bottom = 0;
|
|---|
| 41 | this.margin_left = 0;
|
|---|
| 42 | this.margin_right = 0;
|
|---|
| 43 |
|
|---|
| 44 | this.padding_top = 0;
|
|---|
| 45 | this.padding_bottom = 0;
|
|---|
| 46 | this.padding_left = 0;
|
|---|
| 47 | this.padding_right = 0;
|
|---|
| 48 |
|
|---|
| 49 | this.color = 0;
|
|---|
| 50 | this.background_colour_set = false;
|
|---|
| 51 | this.font_size = 9;
|
|---|
| 52 |
|
|---|
| 53 | // Splitting by the ;
|
|---|
| 54 | var arr:Array = txt.split(";");
|
|---|
| 55 |
|
|---|
| 56 | // Checking all the types of css params we accept and writing to internal variables of the object class
|
|---|
| 57 | for( var i:Number = 0; i < arr.length; i++)
|
|---|
| 58 | {
|
|---|
| 59 | getAttribute(arr[i]);
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | private function trim( txt:String ):String {
|
|---|
| 64 | var l:Number = 0;
|
|---|
| 65 | var r:Number = txt.length - 1;
|
|---|
| 66 | while(txt.charAt(l) == ' ' || txt.charAt(l) == "\t" ) l++;
|
|---|
| 67 | while(txt.charAt(r) == ' ' || txt.charAt(r) == "\t" ) r--;
|
|---|
| 68 | return txt.substring( l, r+1 );
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | private function removeDoubleSpaces( txt:String ):String {
|
|---|
| 72 | var aux:String;
|
|---|
| 73 | var auxPrev:String;
|
|---|
| 74 | aux = txt;
|
|---|
| 75 | do {
|
|---|
| 76 | auxPrev = aux;
|
|---|
| 77 | aux.replace(' ',' ');
|
|---|
| 78 | } while ( auxPrev.length != aux.length );
|
|---|
| 79 | return aux;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | private function ToNumber(cad:String):Number {
|
|---|
| 83 |
|
|---|
| 84 | cad = cad.replace( 'px', '' );
|
|---|
| 85 |
|
|---|
| 86 | if ( isNaN( Number(cad) ) ) {
|
|---|
| 87 | return 0;
|
|---|
| 88 | } else {
|
|---|
| 89 | return Number(cad);
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | private function getAttribute( txt:String ):void {
|
|---|
| 94 | var arr:Array = txt.split(":");
|
|---|
| 95 | if( arr.length==2 )
|
|---|
| 96 | {
|
|---|
| 97 | this.stop_process = 1;
|
|---|
| 98 | this.set( arr[0], trim(arr[1]) );
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | /*
|
|---|
| 102 | public function get( cad:String ):Number {
|
|---|
| 103 | switch (cad) {
|
|---|
| 104 | case "text-align" : return this.text_align;
|
|---|
| 105 | case "font-size" : return ToNumber(this.font_size);
|
|---|
| 106 | case "text-decoration" : return this.text_decoration;
|
|---|
| 107 | case "margin-top" : return this.margin_top;
|
|---|
| 108 | case "margin-bottom" : return this.margin_bottom;
|
|---|
| 109 | case "margin-left" : return this.margin_left;
|
|---|
| 110 | case "margin-right" : return this.margin_right;
|
|---|
| 111 | case "padding-top" : return this.padding_top;
|
|---|
| 112 | case "padding-bottom" : return this.padding_bottom;
|
|---|
| 113 | case "padding-left" : return this.padding_left;
|
|---|
| 114 | case "padding-right" : return this.padding_right;
|
|---|
| 115 | case "font-weight" : return ToNumber(this.font_weight);
|
|---|
| 116 | case "font-style" : return this.font_style;
|
|---|
| 117 | case "font-family" : return this.font_family;
|
|---|
| 118 | case "color" : return this.color;
|
|---|
| 119 | case "background-color" : return this.bg_colour;
|
|---|
| 120 | case "display" : return this.display;
|
|---|
| 121 | default : return 0;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | */
|
|---|
| 125 | // FUCKING!! Flash without By reference String parameters on functions
|
|---|
| 126 | public function set( cad:String, val:String ):void {
|
|---|
| 127 | cad = trim( cad );
|
|---|
| 128 |
|
|---|
| 129 | switch( cad )
|
|---|
| 130 | {
|
|---|
| 131 | case "text-align" : this.text_align = val; break;
|
|---|
| 132 | case "font-size" : this.set_font_size(val); break;
|
|---|
| 133 | case "text-decoration" : this.text_decoration = val; break;
|
|---|
| 134 |
|
|---|
| 135 | case "margin" : this.setMargin(val); break;
|
|---|
| 136 | case "margin-top" : this.margin_top = ToNumber(val); break;
|
|---|
| 137 | case "margin-bottom" : this.margin_bottom = ToNumber(val); break;
|
|---|
| 138 | case "margin-left" : this.margin_left = ToNumber(val); break;
|
|---|
| 139 | case "margin-right" : this.margin_right = ToNumber(val); break;
|
|---|
| 140 |
|
|---|
| 141 | case 'padding' : this.setPadding(val); break;
|
|---|
| 142 | case "padding-top" : this.padding_top = ToNumber(val); break;
|
|---|
| 143 | case "padding-bottom" : this.padding_bottom = ToNumber(val); break;
|
|---|
| 144 | case "padding-left" : this.padding_left = ToNumber(val); break;
|
|---|
| 145 | case "padding-right" : this.padding_right = ToNumber(val); break;
|
|---|
| 146 |
|
|---|
| 147 | case "font-weight" : this.font_weight = val; break;
|
|---|
| 148 | case "font-style" : this.font_style = val; break;
|
|---|
| 149 | case "font-family" : this.font_family = val; break;
|
|---|
| 150 | case "color" : this.set_color(val); break;
|
|---|
| 151 | case "background-color":
|
|---|
| 152 | this.background_colour = Utils.get_colour(val);
|
|---|
| 153 | this.background_colour_set = true;
|
|---|
| 154 | break;
|
|---|
| 155 | case "display" : this.display = val; break;
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | public function set_color( val:String ):void {
|
|---|
| 160 | this.color = Utils.get_colour( val );
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | public function set_font_size( val:String ):void {
|
|---|
| 164 | this.font_size = ToNumber(val);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | private function setPadding( val:String ):void {
|
|---|
| 169 |
|
|---|
| 170 | val = trim( val );
|
|---|
| 171 | var arr:Array = val.split(' ');
|
|---|
| 172 |
|
|---|
| 173 | switch( arr.length )
|
|---|
| 174 | {
|
|---|
| 175 |
|
|---|
| 176 | // margin: 30px;
|
|---|
| 177 | case 1:
|
|---|
| 178 | this.padding_top = ToNumber(arr[0]);
|
|---|
| 179 | this.padding_right = ToNumber(arr[0]);
|
|---|
| 180 | this.padding_bottom = ToNumber(arr[0]);
|
|---|
| 181 | this.padding_left = ToNumber(arr[0]);
|
|---|
| 182 | break;
|
|---|
| 183 |
|
|---|
| 184 | // margin: 15px 5px;
|
|---|
| 185 | case 2:
|
|---|
| 186 | this.padding_top = ToNumber(arr[0]);
|
|---|
| 187 | this.padding_right = ToNumber(arr[1]);
|
|---|
| 188 | this.padding_bottom = ToNumber(arr[0]);
|
|---|
| 189 | this.padding_left = ToNumber(arr[1]);
|
|---|
| 190 | break;
|
|---|
| 191 |
|
|---|
| 192 | // margin: 15px 5px 10px;
|
|---|
| 193 | case 3:
|
|---|
| 194 | this.padding_top = ToNumber(arr[0]);
|
|---|
| 195 | this.padding_right = ToNumber(arr[1]);
|
|---|
| 196 | this.padding_bottom = ToNumber(arr[2]);
|
|---|
| 197 | this.padding_left = ToNumber(arr[1]);
|
|---|
| 198 | break;
|
|---|
| 199 |
|
|---|
| 200 | // margin: 1px 2px 3px 4px;
|
|---|
| 201 | default:
|
|---|
| 202 | this.padding_top = ToNumber(arr[0]);
|
|---|
| 203 | this.padding_right = ToNumber(arr[1]);
|
|---|
| 204 | this.padding_bottom = ToNumber(arr[2]);
|
|---|
| 205 | this.padding_left = ToNumber(arr[3]);
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | private function setMargin( val:String ):void {
|
|---|
| 210 |
|
|---|
| 211 | val = trim( val );
|
|---|
| 212 | var arr:Array = val.split(' ');
|
|---|
| 213 |
|
|---|
| 214 | switch( arr.length )
|
|---|
| 215 | {
|
|---|
| 216 |
|
|---|
| 217 | // margin: 30px;
|
|---|
| 218 | case 1:
|
|---|
| 219 | this.margin_top = ToNumber(arr[0]);
|
|---|
| 220 | this.margin_right = ToNumber(arr[0]);
|
|---|
| 221 | this.margin_bottom = ToNumber(arr[0]);
|
|---|
| 222 | this.margin_left = ToNumber(arr[0]);
|
|---|
| 223 | break;
|
|---|
| 224 |
|
|---|
| 225 | // margin: 15px 5px;
|
|---|
| 226 | case 2:
|
|---|
| 227 | this.margin_top = ToNumber(arr[0]);
|
|---|
| 228 | this.margin_right = ToNumber(arr[1]);
|
|---|
| 229 | this.margin_bottom = ToNumber(arr[0]);
|
|---|
| 230 | this.margin_left = ToNumber(arr[1]);
|
|---|
| 231 | break;
|
|---|
| 232 |
|
|---|
| 233 | // margin: 15px 5px 10px;
|
|---|
| 234 | case 3:
|
|---|
| 235 | this.margin_top = ToNumber(arr[0]);
|
|---|
| 236 | this.margin_right = ToNumber(arr[1]);
|
|---|
| 237 | this.margin_bottom = ToNumber(arr[2]);
|
|---|
| 238 | this.margin_left = ToNumber(arr[1]);
|
|---|
| 239 | break;
|
|---|
| 240 |
|
|---|
| 241 | // margin: 1px 2px 3px 4px;
|
|---|
| 242 | default:
|
|---|
| 243 | this.margin_top = ToNumber(arr[0]);
|
|---|
| 244 | this.margin_right = ToNumber(arr[1]);
|
|---|
| 245 | this.margin_bottom = ToNumber(arr[2]);
|
|---|
| 246 | this.margin_left = ToNumber(arr[3]);
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | public function clear():void {
|
|---|
| 251 | this.text_align = undefined;
|
|---|
| 252 | this.font_size = undefined;
|
|---|
| 253 | this.text_decoration = undefined;
|
|---|
| 254 | this.margin_top = undefined;
|
|---|
| 255 | this.margin_bottom = undefined;
|
|---|
| 256 | this.margin_left = undefined;
|
|---|
| 257 | this.margin_right = undefined;
|
|---|
| 258 | this.font_weight = undefined;
|
|---|
| 259 | this.font_style = undefined;
|
|---|
| 260 | this.font_family = undefined;
|
|---|
| 261 | this.color = undefined;
|
|---|
| 262 | this.display = undefined;
|
|---|
| 263 | }
|
|---|
| 264 | }
|
|---|
| 265 | }
|
|---|