Changeset 237


Ignore:
Timestamp:
07/14/09 08:58:44 (4 years ago)
Author:
jeroen
Message:

wrapped up the search plugin

Location:
plugins/search
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/search/com/jeroenwijering/plugins/Search.as

    r236 r237  
    2020 
    2121 
    22         /** Reference to the background color. **/ 
     22        /** Reference to the background clip. **/ 
    2323        private var back:Sprite; 
     24        /** Reference to the border clip. **/ 
     25        private var border:Sprite; 
    2426        /** Reference to the graphics. **/ 
    2527        public var config:Object = { 
    26                 script:'http://gdata.youtube.com/feeds/api/videos?vq=QUERY&format=5', 
    27                 position:'over' 
     28                color:'cc0000', 
     29                label:'YouSearch', 
     30                position:'over', 
     31                script:'http://gdata.youtube.com/feeds/api/videos?vq=QUERY&format=5' 
    2832        }; 
    29         /** Reference to the onscreen graphics.  **/ 
    30         private var screen:Sprite; 
    3133        /** Reference to the textfield that contains the query. **/ 
    32         private var query:TextField; 
     34        private var input:TextField; 
     35        /** Reference to the textfield that labels the submit button. **/ 
     36        private var label:TextField; 
     37        /** Reference to the button graphic.  **/ 
     38        private var submit:Sprite; 
    3339        /** Reference to the View of the player. **/ 
    3440        private var view:AbstractView; 
     
    4955                        back.graphics.drawRect(0,0,400,40); 
    5056                } 
    51                 back.graphics.beginFill(0xFFFFFF,0.1); 
     57                back.graphics.beginFill(0xFFFFFF,0.07); 
    5258                back.graphics.drawRect(0,0,400,20); 
    53                 back.graphics.beginFill(0x000000,0.1); 
     59                back.graphics.beginFill(0x000000,0.07); 
    5460                back.graphics.drawRect(0,20,400,20); 
    5561                addChild(back); 
    56                 screen = new Sprite(); 
    57                 screen.addChild(new Screen()); 
    58                 //screen.scale9Grid = new Rectangle(0,0,100,20); 
    59                 screen.x = screen.y = 10; 
    60                 addChild(screen); 
    61                 query = new TextField(); 
    62                 query.type = TextFieldType.INPUT; 
    63                 query.defaultTextFormat = new TextFormat("_sans",11,0x000000); 
    64                 query.width = 180; 
    65                 query.height = 30; 
    66                 query.x = query.y = 10; 
    67                 query.text = '...'; 
    68                 addChild(query); 
     62                border = new Sprite(); 
     63                border.graphics.beginFill(0x878787); 
     64                border.graphics.drawRect(0,0,200,20); 
     65                border.x = border.y = 10; 
     66                addChild(border); 
     67                input = new TextField(); 
     68                input.background = true; 
     69                input.backgroundColor = 0xFFFFFF; 
     70                input.type = TextFieldType.INPUT; 
     71                input.defaultTextFormat = new TextFormat("_sans",11,0x000000); 
     72                input.height = 18; 
     73                input.x = input.y = 11; 
     74                input.text = '...'; 
     75                addChild(input); 
     76                submit = new Sprite(); 
     77                submit.graphics.beginFill(uint('0x'+config['color'])); 
     78                submit.graphics.drawRect(0,0,118,18); 
     79                submit.graphics.beginFill(0xFFFFFF,0.08); 
     80                submit.graphics.drawRect(0,0,118,9); 
     81                submit.graphics.beginFill(0x000000,0.08); 
     82                submit.graphics.drawRect(0,9,118,9); 
     83                submit.y = 11; 
     84                addChild(submit); 
     85                label = new TextField(); 
     86                var fmt:TextFormat = new TextFormat("_sans",11,0xFFFFFF); 
     87                fmt.align = 'center'; 
     88                label.defaultTextFormat = fmt; 
     89                label.width = 118; 
     90                label.text = config['label']; 
     91                submit.addChild(label); 
    6992        }; 
    7093 
     
    7295        /** Start a search. **/ 
    7396        private function clickHandler(evt:MouseEvent=null):void { 
    74                 var que:String = encodeURI(query.text); 
     97                var que:String = encodeURI(input.text); 
    7598                if(que.length > 3) { 
    7699                        if(view.config['playlist'] == 'none') { 
     
    80103                        view.sendEvent('LOAD',config['script'].replace('QUERY',que)); 
    81104                } 
    82                 query.text = ''; 
     105                input.text = ''; 
    83106        }; 
    84107 
     
    86109        /** Clear the field on focus. **/ 
    87110        private function focusHandler(evt:FocusEvent):void { 
    88                 if(query.text == '...') { 
    89                         query.text = ''; 
     111                if(input.text == '...') { 
     112                        input.text = ''; 
    90113                } 
    91114        }; 
     
    97120                view.addModelListener(ModelEvent.STATE,stateHandler); 
    98121                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler); 
     122                if(view.config['lightcolor'] && !view.config['search.color']) { 
     123                        config['color'] = view.config['lightcolor']; 
     124                } 
    99125                build(); 
    100                 screen.addEventListener(MouseEvent.CLICK,clickHandler); 
    101                 screen.buttonMode = true; 
    102                 screen.mouseChildren = false; 
    103                 query.addEventListener(FocusEvent.FOCUS_IN,focusHandler); 
    104                 query.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler); 
     126                input.addEventListener(FocusEvent.FOCUS_IN,focusHandler); 
     127                input.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler); 
     128                submit.addEventListener(MouseEvent.CLICK,clickHandler); 
     129                submit.buttonMode = true; 
     130                submit.mouseChildren = true; 
    105131                resizeHandler(); 
    106132        }; 
     
    109135        /** Start the search when pressing the enter key. **/ 
    110136        private function keyHandler(evt:KeyboardEvent):void { 
    111                 if(evt.charCode == 13) {  
     137                if(evt.charCode == 13) { 
    112138                        clickHandler(); 
    113139                } 
     
    120146                        x = config['x']; 
    121147                        y = config['y']; 
    122                 }  
     148                } 
    123149                back.width = view.config['width']; 
    124                 screen.x = back.width/2 - screen.width/2; 
     150                border.width = back.width - 20; 
     151                input.width = back.width - 141; 
     152                submit.x = back.width - 129; 
    125153        }; 
    126154 
     
    134162                                break; 
    135163                        default: 
    136                                 stage.focus = query; 
     164                                stage.focus = input; 
    137165                                visible = true; 
    138166                                break; 
  • plugins/search/search.xml

    r236 r237  
    1515        <flashvars> 
    1616                <flashvar> 
     17                        <name>color</name> 
     18                        <default>CC0000</default> 
     19                        <description> 
     20                                Background color of the submit button.  
     21                                If no color is set, but a player "lightcolor" is, that value is used. 
     22                        </description> 
     23                </flashvar> 
     24                <flashvar> 
    1725                        <name>script</name> 
    1826                        <default>http://gdata.youtube.com/feeds/api/videos%3Fvq%3DQUERY%26format%3D5</default> 
     
    2533                </flashvar> 
    2634                <flashvar> 
     35                        <name>label</name> 
     36                        <default>YouSearch</default> 
     37                        <description> 
     38                                Text label of the search button 
     39                        </description> 
     40                </flashvar> 
     41                <flashvar> 
    2742                        <name>position</name> 
    28                         <default>over</default> 
     43                        <default /> 
    2944                        <description> 
    30                                 Position of the search bar. Can be "over", "bottom" or "top". 
    31                                 When set to "over", the bar only shows when the video is paused/stopped. 
     45                                Position of the search bar. Can be "bottom" or "top". 
     46                                Defaults to the "over" position, where the bar only shows when the video is paused/stopped. 
    3247                        </description> 
    3348                </flashvar> 
    3449                <flashvar> 
    3550                        <name>size</name> 
    36                         <default>40</default> 
     51                        <default /> 
    3752                        <description> 
    38                                 Height of the serch bar when placed at the "top" or "bottom" position. 
     53                                Height of the search bar when placed at the "top" or "bottom" position. Set this to "40". 
    3954                        </description> 
    4055                </flashvar> 
Note: See TracChangeset for help on using the changeset viewer.