dialog.js
3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//tinyMCEPopup.requireLangPack();
var YouTubeDialog = {
init : function() {
},
videovalue:function(youtubeID){
// Return video value for replace
// get the current URL
var url = youtubeID;//window.location.toString();
if(url == '') {
tinyMCEPopup.close();
return false;
}else{
//get the parameters
url.match(/\?(.+)$/);
var params = RegExp.$1;
// split up the query string and store in an
// associative array
var params = params.split("&");
var queryStringList = {};
for(var i=0;i<params.length;i++)
{
var tmp = params[i].split("=");
queryStringList[tmp[0]] = unescape(tmp[1]);
}
// print all querystring in key value pairs
for(var i in queryStringList){
return(queryStringList[i]);
}
}
},
insert : function() {
// Insert the contents from the input into the document
var f = document.forms[0], objectCode, videoSize = '', domSize = '', options = '';
//If no code just return.
if(f.youtubeID.value == '') {
tinyMCEPopup.close();
return false;
}
//SELECT AUTOPLY
switch (f.youtubeAutoplay.value){
case '0':
options += 'autoplay=0';
break;
case '1':
options += 'autoplay=1';
break;
}
//SELECT Include related videos
//var relvideo = document.getElementById("youtubeREL");
switch (f.youtubeREL.value) {
case '0':
options += '';
break;
case '1':
options += '&rel=0';
break;
}
//SELECT Watch in HD
//var HD = document.getElementById("youtubeHD");
switch (f.youtubeHD.value){
case '0':
options += '';
break;
case '1':
options += '&hd=1';
break;
}
//SELECT ShowInfo
//var showinfo = document.getElementById("youtubeshowinfo");
switch (f.youtubeshowinfo.value){
case '0':
options += '';
break;
case '1':
options += '&showinfo=0';
break;
}
//SELECT AutoHide
//var autohide = document.getElementById("youtubeautohide");
switch (f.youtubeautohide.value){
case '0':
options += '';
break;
case '1':
options += '&autohide=1';
break;
}
//Config Size Video
if(f.youtubeWidth.value != ''){
domSize += 'width: ' + f.youtubeWidth.value + ';';
videoSize += 'width="' + f.youtubeWidth.value + '"';
}
if(f.youtubeWidth.value != ''){
domSize += 'height: ' + f.youtubeHeight.value + ';';
videoSize += 'height="' + f.youtubeHeight.value + '"';
}
//Replace http://youtu.be/xxxxxxxx for http://www.youtube.com/v/xxxxxxxxxx
if(f.youtubeID.value.match(new RegExp("http://www.youtube.com/","g"))){
//Replace url
var youtubeuri = f.youtubeID.value.replace(f.youtubeID.value,"http://www.youtube.com/v/"+YouTubeDialog.videovalue(f.youtubeID.value));
//Construct URL
var constructUri = youtubeuri+'?'+options;
}else if(f.youtubeID.value.match(new RegExp("http://youtu.be/","g"))){
//Replace url
var youtubeuri = f.youtubeID.value.replace('http://youtu.be/',"http://www.youtube.com/v/");
//Construct URL
var constructUri = youtubeuri+'?'+options;
}
//width="'+document.forms[0].youtubeWidth.value+'" height="'+document.forms[0].youtubeHeight.value+'"
// Insert the contents from the input into the document
var objectCode = '<div class="youtube" style="'+domSize+'">';
objectCode +='<object type="application/x-shockwave-flash" '+videoSize+' data="'+constructUri+'">';
objectCode += '<param name="movie" value="'+constructUri+'" />';
objectCode += '<param name="wmode" value="transparent" />';
objectCode += '</object>';
objectCode += '</div>';
tinyMCEPopup.editor.execCommand('mceInsertContent', false, objectCode);
tinyMCEPopup.close();
}
};
tinyMCEPopup.onInit.add(YouTubeDialog.init, YouTubeDialog);