/
modaldialog.js
165 lines (148 loc) · 6.3 KB
/
modaldialog.js
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$(function() {
openUploadModalDialog();
});
function openUploadModalDialog(){
$(document).on('click','.upload-edit',function(){
var fieldname=$(this).data('fieldname');
$('#upload_'+fieldname).click();
});
$('.upload').click(function(e) {
e.preventDefault();
var $this = $(this);
var show_title = getQueryVariable('show_title', this.href);
var show_comment = getQueryVariable('show_comment', this.href);
var pos = getQueryVariable('pos', this.href);
var fieldname = getQueryVariable('fieldname', this.href);
var buttonsOpts = {};
buttonsOpts[uploadLang.returnTxt] = function() {
$(this).dialog("close");
};
var windowwidth = $(window).width()-30;
var dialogwidth= Math.min(windowwidth, 940);
$('#uploader').dialog('destroy').remove(); // destroy the old modal dialog
$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
title: uploadLang.title,
autoOpen: true,
width: dialogwidth,
height: 'auto',
open: function( event, ui ) {
setWidthUploader();
},
modal: true,
resizable: false,
autoResize: false,
draggable: true,
closeOnEscape: false,
beforeClose: function() {
var pass;
if(document.getElementById('uploader').contentDocument) {
if(document.getElementById('uploader').contentDocument.defaultView)
{ /*Firefox*/
pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos);
}else{ /*IE8*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
}else{ /*IE6*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
return pass;
},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts,
close: function( ) {
checkconditions();
}
});
});
}
$(window).resize(function() {
setWidthUploader();
if(typeof $("iframe#uploader")[0]!=="undefined" && jQuery.isFunction($("iframe#uploader")[0].contentWindow.fixParentHeigth))
$("iframe#uploader")[0].contentWindow.fixParentHeigth();
});
/* Reset the position of the dialog (recenter) */
function resetUploaderPosition(){
$( "#uploader" ).dialog( "option", "position", $( "#uploader" ).dialog( "option", "position" ) );
}
/* Set the with of upload madal and uploader frame according to windows width */
function setWidthUploader(){
var maxwidth=Math.min($("body").innerWidth()-4, 974);
if(maxwidth!=$( "#uploader" ).dialog( "option", "width" )){
$("#uploader").dialog( "option", "width", maxwidth).width(maxwidth-18) // Leave 20px for overflow
}
resetUploaderPosition();
}
function getQueryVariable(variable, url) {
var vars = url.split("/");
for (var i=0;i<vars.length;i++) {
//var pair = vars[i].split("=");
if (vars[i] == variable) {
return vars[i+1];
}
}
// If not found try with ?
// TODO : replace by a regexp
var vars = url.replace(/\&/g,'&').split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return null;
}
function isValueInArray(arr, val) {
inArray = false;
for (i = 0; i < arr.length; i++) {
if (val.toLowerCase() == arr[i].toLowerCase()) {
inArray = true;
}
}
return inArray;
}
function displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show_comment) {
var jsonobj;
var i;
var display = '';
if (jsonstring == '[]') {
$('#'+fieldname+'_uploadedfiles').html(display);
return;
}
if (jsonstring !== '')
{
jsonobj = eval('(' + jsonstring + ')');
display = '<table width="100%" class="question uploadedfiles"><thead><tr><td width="20%"> </td>';
if (show_title != 0)
display += '<th>'+uploadLang.headTitle+'</th>';
if (show_comment != 0)
display += '<th>'+uploadLang.headComment+'</th>';
display += '<th>'+uploadLang.headFileName+'</th><th class="edit"></th></tr></thead><tbody>';
var image_extensions = new Array('gif', 'jpeg', 'jpg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'jp2', 'iff', 'bmp', 'xbm', 'ico');
for (i = 0; i < filecount; i++)
{
if (isValueInArray(image_extensions, jsonobj[i].ext))
display += '<tr><td class="upload image"><img src="' + uploadurl + '/filegetcontents/'+decodeURIComponent(jsonobj[i].filename)+'" class="uploaded" /></td>';
else
display += '<tr><td class="upload placeholder"><div class="upload-placeholder" /></td>';
if (show_title != 0)
display += '<td class="upload title">'+jsonobj[i].title+'</td>';
if (show_comment != 0)
display += '<td class="upload comment">'+jsonobj[i].comment+'</td>';
display +='<td class="upload edit">'+decodeURIComponent(jsonobj[i].name)+'</td><td>'+'<a class="upload-edit" data-fieldname="'+fieldname+'">'+uploadLang.editFile+'</a></td></tr>';
}
display += '</tbody></table>';
$('#'+fieldname+'_uploadedfiles').html(display);
}
}
function copyJSON(jsonstring, filecount, fieldname, show_title, show_comment, pos) {
$('#'+fieldname).val(jsonstring);
$('#'+fieldname+'_filecount').val(filecount);
displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show_comment, pos);
}
function showBasic() {
$('#basic').show();
}
function hideBasic() {
$('#basic').hide();
}