OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / fckeditor2.6.6 / editor / plugins / YouTube / youtube.js
1 var dialog              = window.parent ;
2 var oEditor             = dialog.InnerDialogLoaded() ;
3 var FCK                 = oEditor.FCK ;
4 var FCKLang             = oEditor.FCKLang ;
5 var FCKConfig   = oEditor.FCKConfig ;
6
7 //security RegExp
8 var REG_SCRIPT = new RegExp("< *script.*>|< *style.*>|< *link.*>|< *body .*>", "i");
9 var REG_PROTOCOL = new RegExp("javascript:|vbscript:|about:", "i");
10 var REG_CALL_SCRIPT = new RegExp("&\{.*\};", "i");
11 var REG_EVENT = new RegExp("onError|onUnload|onBlur|onFocus|onClick|onMouseOver|onMouseOut|onSubmit|onReset|onChange|onSelect|onAbort", "i");
12 // Cookie Basic
13 var REG_AUTH = new RegExp("document\.cookie|Microsoft\.XMLHTTP", "i");
14 // TEXTAREA
15 var REG_NEWLINE = new RegExp("\x0d|\x0a", "i");
16
17 //#### Dialog Tabs
18
19 // Set the dialog tabs.
20 dialog.AddTab( 'Info', oEditor.FCKLang.DlgInfoTab ) ;
21
22 // Get the selected flash embed (if available).
23 var oFakeImage = FCK.Selection.GetSelectedElement() ;
24 var oEmbed ;
25
26 window.onload = function()
27 {
28         // Translate the dialog box texts.
29         oEditor.FCKLanguageManager.TranslatePage(document) ;
30
31         dialog.SetAutoSize( true ) ;
32
33         // Activate the "OK" button.
34         dialog.SetOkButton( true ) ;
35
36         SelectField( 'txtUrl' ) ;
37 }
38
39 //#### The OK button was hit.
40 function Ok()
41 {
42         if ( GetE('txtUrl').value.length == 0 )
43         {
44                 dialog.SetSelectedTab( 'Info' ) ;
45                 GetE('txtUrl').focus() ;
46
47                 alert( oEditor.FCKLang.DlgYouTubeCode ) ;
48
49                 return false ;
50         }
51         
52         // check security
53         if (checkCode(GetE('txtUrl').value) == false) {
54                 alert( oEditor.FCKLang.DlgYouTubeSecurity ) ;
55                 return false;
56         }
57         
58     oEditor.FCKUndo.SaveUndoStep() ;
59     if ( !oEmbed )
60         {
61                 oEmbed          = FCK.EditorDocument.createElement( 'EMBED' ) ;
62                 oFakeImage  = null ;
63         }
64         UpdateEmbed( oEmbed ) ;
65
66         if ( !oFakeImage )
67         {
68                 oFakeImage      = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oEmbed ) ;
69                 oFakeImage.setAttribute( '_fckflash', 'true', 0 ) ;
70                 oFakeImage      = FCK.InsertElement( oFakeImage ) ;
71         }
72
73     oEditor.FCKEmbedAndObjectProcessor.RefreshView( oFakeImage, oEmbed ) ;
74
75         return true ;
76 }
77
78 function UpdateEmbed( e )
79 {
80         var youtubeUrl  = GetE('txtUrl').value;
81         var youtubeId   = youtubeUrl.slice(youtubeUrl.search(/\?v=/i)+3);
82         
83         SetAttribute( e, 'type'                 , 'application/x-shockwave-flash' ) ;
84         SetAttribute( e, 'pluginspage'  , 'http://www.macromedia.com/go/getflashplayer' ) ;
85         
86         if ( GetE('radioHigh').checked ) {
87                 SetAttribute( e, 'src'          , 'http://www.youtube.com/v/'+youtubeId+'%26hl=en%26fs=1%26rel=0%26ap=%2526fmt=18') ;
88         } else {
89                 SetAttribute( e, 'src'          , 'http://www.youtube.com/v/'+youtubeId+'%26hl=en%26fs=1%26rel=0') ;
90         }
91         
92         SetAttribute( e, "width"                , GetE('txtWidth').value == '' ? 425 : GetE('txtWidth').value ) ;
93         SetAttribute( e, "height"               , GetE('txtHeight').value == '' ? 344 : GetE('txtHeight').value ) ;
94 }
95
96 function checkCode(code)
97 {
98         if (code.search(REG_SCRIPT) != -1) {
99                 return false;
100         }
101         
102         if (code.search(REG_PROTOCOL) != -1) {
103                 return false;
104         }
105
106         if (code.search(REG_CALL_SCRIPT) != -1) {
107                 return false;
108         }
109
110         if (code.search(REG_EVENT) != -1) {
111                 return false;
112         }
113
114         if (code.search(REG_AUTH) != -1) {
115                 return false;
116         }
117
118         if (code.search(REG_NEWLINE) != -1) {
119                 return false;
120         }
121 }