Ignore:
Timestamp:
07/04/11 07:28:59 (23 months ago)
Author:
jeroen
Message:

wrapped the sharing plugin for HTML5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sharing/src/as/Sharing.as

    r1879 r1880  
    11package { 
    22 
    3     import com.longtailvideo.jwplayer.events.PlaylistEvent; 
    4     import com.longtailvideo.jwplayer.player.IPlayer; 
    5     import com.longtailvideo.jwplayer.plugins.IPlugin; 
    6     import com.longtailvideo.jwplayer.plugins.PluginConfig; 
    7     import com.longtailvideo.jwplayer.view.components.DockButton; 
    8     import com.longtailvideo.jwplayer.utils.Logger; 
     3    import com.longtailvideo.jwplayer.events.*; 
     4    import com.longtailvideo.jwplayer.player.*; 
     5    import com.longtailvideo.jwplayer.plugins.*; 
    96 
    107    import flash.display.DisplayObject; 
    11     import flash.display.LoaderInfo; 
    128    import flash.display.Sprite; 
    139    import flash.events.MouseEvent; 
    1410    import flash.external.ExternalInterface; 
     11    import flash.filters.DropShadowFilter; 
    1512    import flash.net.URLRequest; 
    1613    import flash.net.navigateToURL; 
     
    1815    import flash.text.TextField; 
    1916    import flash.text.TextFormat; 
    20     import flash.utils.setTimeout; 
    2117 
    2218 
     
    4642 
    4743        /** Reference to the background sheet. **/ 
    48         private var _backSheet:DisplayObject; 
     44        private var _back:Sprite; 
     45        /** The current embed code. **/ 
     46        private var _code:String; 
     47        /** Reference to the code field background. **/ 
     48        private var _codeBack:DisplayObject; 
    4949        /** Reference to the code copy button. **/ 
    50         private var _codeButton:DisplayObject; 
     50        private var _codeButton:Sprite; 
    5151        /** Reference to the code text field. **/ 
    5252        private var _codeField:TextField; 
     53        /** The form with all code elements. **/ 
     54        private var _codeForm:Sprite; 
    5355        /** Reference to the code label. **/ 
    5456        private var _codeLabel:TextField; 
    5557        /** The plugin configuration options.**/ 
    5658        private var _config:Object; 
    57         /** Reference to the container with options. **/ 
    58         private var _container:Sprite; 
     59        /** The form with all buttons. **/ 
     60        private var _form:Sprite; 
    5961        /** The current video link. **/ 
    6062        private var _link:String; 
     63        /** Reference to the link field background. **/ 
     64        private var _linkBack:DisplayObject; 
    6165        /** Reference to the link copy button. **/ 
    62         private var _linkButton:DisplayObject; 
     66        private var _linkButton:Sprite; 
    6367        /** Reference to the link text field. **/ 
    6468        private var _linkField:TextField; 
     69        /** Reference to the link form. **/ 
     70        private var _linkForm:Sprite; 
    6571        /** Reference to the link label. **/ 
    6672        private var _linkLabel:TextField; 
     
    6874        private var _player:IPlayer; 
    6975        /** Reference to the facebook button. **/ 
    70         private var _facebookButton:DisplayObject; 
     76        private var _facebookButton:Sprite; 
    7177        /** Reference to the twitter button. **/ 
    72         private var _twitterButton:DisplayObject; 
     78        private var _twitterButton:Sprite; 
    7379 
    7480 
    7581        /** The background screen was clicked. **/ 
    7682        private function _backHandler(evt:MouseEvent):void { 
    77             visible = false; 
     83            _back.visible = false; 
     84            _form.visible = false; 
     85            // Only 5.7+... 
     86            try { _player.controls.display.show(); } catch (error:Error) {} 
    7887        }; 
    7988 
     
    8392            stage.focus = _codeField; 
    8493            _codeField.setSelection(0,999999); 
    85             System.setClipboard(_codeField.text); 
     94            System.setClipboard(_code); 
    8695        }; 
    8796 
     
    95104        /** The dock icon was clicked. **/ 
    96105        private function _dockHandler(evt:MouseEvent):void { 
    97             visible = true; 
     106            _back.visible = true; 
     107            _form.visible = true; 
     108            // Only 5.7+... 
     109            try { _player.controls.display.hide(); } catch (error:Error) {} 
    98110        }; 
    99111 
     
    122134            _config = config; 
    123135            _player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, _itemHandler); 
    124             _player.controls.dock.addButton(new DockIcon(), "share", _dockHandler) as DockButton; 
    125             this.visible = false; 
    126             // Add the backsheet 
    127             _backSheet = new BackSheet(); 
    128             _backSheet.addEventListener(MouseEvent.CLICK,_backHandler); 
    129             //addChild(_backSheet); 
    130             // Add the container. 
    131             _container = new Sprite(); 
    132             addChild(_container); 
    133             // Add the fields 
     136            _player.controls.dock.addButton(new DockIcon(), "share", _dockHandler); 
     137            // Add the background and form. 
     138            _back = new Sprite(); 
     139            _back.visible = false; 
     140            _back.buttonMode = true; 
     141            _back.addChild(new BackSheet()); 
     142            _back.addEventListener(MouseEvent.CLICK,_backHandler); 
     143            addChild(_back); 
     144            _form = new Sprite(); 
     145            _form.visible = false; 
     146            addChild(_form); 
     147 
     148            // Add the embed code fields 
     149            _codeForm = new Sprite(); 
     150            _form.addChild(_codeForm); 
     151            _codeLabel = new TextField(); 
     152            _codeLabel.defaultTextFormat = new TextFormat('Arial', 13, 0xFFFFFF, true); 
     153            _codeLabel.text = "Embed code"; 
     154            _codeLabel.x = -5; 
     155            _codeLabel.y = 3; 
     156            _codeLabel.filters = new Array(new DropShadowFilter(1,45,0,1,0,0,1)); 
     157            _codeForm.addChild(_codeLabel); 
     158            _codeBack = new InputBackground(); 
     159            _codeForm.addChild(_codeBack); 
     160            _codeBack.x = 80; 
    134161            _codeField = new TextField(); 
     162            _codeField.defaultTextFormat = new TextFormat('Arial',11,0x000000); 
     163            _codeForm.addChild(_codeField); 
     164            _codeField.x = 84; 
     165            _codeField.y = 5; 
     166            _codeField.width = 178; 
     167            _codeField.height = 20; 
     168            _codeButton = new Sprite(); 
     169            _codeForm.addChild(_codeButton); 
     170            _codeButton.buttonMode = true; 
     171            _codeButton.addChild(new CopyButton()); 
     172            _codeButton.addEventListener(MouseEvent.CLICK,_codeHandler); 
     173            _codeButton.x = 260; 
     174 
     175            // Add the video link fields 
     176            _linkForm = new Sprite(); 
     177            _form.addChild(_linkForm); 
     178            _linkForm.y = 40; 
     179            _linkLabel = new TextField(); 
     180            _linkLabel.defaultTextFormat = new TextFormat('Arial', 13, 0xFFFFFF, true); 
     181            _linkLabel.text = "Video link"; 
     182            _linkLabel.x = 10; 
     183            _linkLabel.y = 3; 
     184            _linkLabel.filters = new Array(new DropShadowFilter(1,45,0,1,0,0,1)); 
     185            _linkForm.addChild(_linkLabel); 
     186            _linkBack = new InputBackground(); 
     187            _linkForm.addChild(_linkBack); 
     188            _linkBack.x = 80; 
    135189            _linkField = new TextField(); 
     190            _linkField.defaultTextFormat = new TextFormat('Arial',11,0x000000); 
     191            _linkForm.addChild(_linkField); 
     192            _linkField.x = 84; 
     193            _linkField.y = 5; 
     194            _linkField.width = 178; 
     195            _linkField.height = 20; 
     196            _linkButton = new Sprite(); 
     197            _linkForm.addChild(_linkButton); 
     198            _linkButton.buttonMode = true; 
     199            _linkButton.addChild(new CopyButton()); 
     200            _linkButton.addEventListener(MouseEvent.CLICK,_linkHandler); 
     201            _linkButton.x = 260; 
     202 
     203            // Add facebook and twitter buttons. 
     204            _facebookButton = new Sprite(); 
     205            _facebookButton.addChild(new FacebookButton()); 
     206            _facebookButton.buttonMode = true; 
     207            _facebookButton.addEventListener(MouseEvent.CLICK,_facebookHandler); 
     208            _facebookButton.x = 80; 
     209            _facebookButton.y = 40; 
     210            _linkForm.addChild(_facebookButton); 
     211            _twitterButton = new Sprite(); 
     212            _twitterButton.addChild(new TwitterButton()); 
     213            _twitterButton.buttonMode = true; 
     214            _twitterButton.addEventListener(MouseEvent.CLICK,_twitterHandler); 
     215            _twitterButton.x = 190; 
     216            _twitterButton.y = 40; 
     217            _linkForm.addChild(_twitterButton); 
    136218        }; 
    137219 
     
    139221        /** Change the embed code when an item changes.  */ 
    140222        public function _itemHandler(evt:PlaylistEvent):void { 
    141             /** 
    142             if(_player.playlist.currentItem['sharing.code'] &&  
    143                 _player.playlist.currentItem['sharing.code'] != _config['code']) { 
    144                 _embedField.text = _player.playlist.currentItem['sharing.code']; 
    145             } else if (_config['code'] == true) { 
    146                 _embedField.text = _embedCode; 
    147             } else if (_config['code'].length == 8) { 
    148                 _embedField.text = getBotrEmbed(); 
    149             } else {  
    150                 _embedField.text = _config['code']; 
    151             } 
    152             if(_player.playlist.currentItem['sharing.link'] &&  
    153                 _player.playlist.currentItem['sharing.link'] != _config['link']) { 
    154                 _shareField.text = _player.playlist.currentItem['sharing.link']; 
    155             } else if(_player.playlist.currentItem['link'] &&  
    156                 _player.playlist.currentItem['link'] != _player.config['link'] &&  
    157                 _config['link'] == true) { 
    158                 _shareField.text = _player.playlist.currentItem['link']; 
    159             } else if (_config['link'] == true) { 
    160                 _shareField.text = _pageURL; 
    161             } else {  
    162                 _shareField.text = _config['link']; 
    163             } 
    164             **/ 
     223            // Set the embed code. 
     224            var item:Object = _player.playlist.currentItem; 
     225            _code = ''; 
     226            if(item['sharing.code']) { 
     227                _code = item['sharing.code']; 
     228            } else if(_config.code) { 
     229                _code = _config.code; 
     230            } 
     231            if(_code.substr(0,3) == '%3C') {  
     232                _code = decodeURIComponent(_code);  
     233            } 
     234            _codeField.text = _code; 
     235            if(_code == '') { 
     236                _codeForm.visible = false; 
     237                _linkForm.y = 20; 
     238            } else { 
     239                _codeForm.visible = true; 
     240                _linkForm.y = 40; 
     241            } 
     242            // Set the video link. 
     243            _link = _getPageURL(); 
     244            if(item['sharing.link']) { 
     245                _link = item['sharing.link']; 
     246            } else if(_config.link) { 
     247                _link = _config.link; 
     248            } 
     249            _linkField.text = _link; 
    165250        }; 
    166251 
     
    170255            stage.focus = _linkField; 
    171256            _linkField.setSelection(0,999999); 
    172             System.setClipboard(_linkField.text); 
     257            System.setClipboard(_link); 
    173258        }; 
    174259 
     
    176261        /** Reposition the screens when the player resizes itself **/ 
    177262        public function resize(wid:Number, hei:Number):void { 
    178             _backSheet.width = wid; 
    179             _backSheet.height = hei; 
    180             _container.x = Math.round(wid/2 - 160); 
    181             _container.y = Math.round(hei/2 - 70); 
     263            _back.width = wid; 
     264            _back.height = hei; 
     265            _form.x = Math.round(wid/2 - 160); 
     266            _form.y = Math.round(hei/2 - 54); 
    182267        }; 
    183268 
Note: See TracChangeset for help on using the changeset viewer.