-
Notifications
You must be signed in to change notification settings - Fork 32
/
_indexJS.inc.php
235 lines (202 loc) · 7.01 KB
/
_indexJS.inc.php
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<script>
var fileUrls = [];
var lastEle = null;
var startTime = null;
$(document).ready(function() {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
sequentialUploads: true,
maxFileSize: <?php echo $maxUploadSize; ?>,
<?php echo COUNT($acceptedFileTypes)?('acceptFileTypes: /(\\.|\\/)('.str_replace(".", "", implode("|", $acceptedFileTypes).')$/i,')):''; ?> maxNumberOfFiles: 50
})
.bind('fileuploadadd', function(e, data) {
$('#fileupload #fileListingWrapper').removeClass('hidden');
$('#fileupload #initialUploadSection').addClass('hidden');
$('#fileUploadBadge').addClass('hidden');
// fix for safari
getTotalRows();
// end safari fix
totalRows = getTotalRows()+1;
updateTotalFilesText(totalRows);
})
.bind('fileuploadstart', function(e, data) {
// hide/show sections
$('#addFileRow').addClass('hidden');
$('#processQueueSection').addClass('hidden');
$('#processingQueueSection').removeClass('hidden');
// set all cancel icons to processing
$('.cancel').html('<img class="processingIcon" src="<?php echo SITE_IMAGE_PATH; ?>/processing_small.gif" width="16" height="16"/>');
// set timer
startTime = (new Date()).getTime();
})
.bind('fileuploadstop', function(e, data) {
// finished uploading
updateTitleWithProgress(100);
updateProgessText(100, data.total, data.total);
$('#processQueueSection').addClass('hidden');
$('#processingQueueSection').addClass('hidden');
$('#completedSection').removeClass('hidden');
// set all remainging pending icons to failed
$('.processingIcon').parent().html('<img src="<?php echo SITE_IMAGE_PATH; ?>/red_error_small.png" width="16" height="16"/>');
// setup copy link
setupCopyAllLink();
})
.bind('fileuploadprogressall', function(e, data) {
// update page title with progress
var progress = parseInt(data.loaded / data.total * 100, 10);
updateTitleWithProgress(progress);
updateProgessText(progress, data.loaded, data.total);
})
.bind('fileuploaddone', function(e, data) {
// keep a copy of the urls globally
fileUrls.push(data['result'][0]['url']);
})
.bind('fileuploadfail', function(e, data) {
totalRows = getTotalRows();
if(totalRows > 0)
{
totalRows = totalRows-1;
}
// if no items, show the original uploader
if(totalRows == 0)
{
$('#fileupload #initialUploadSection').removeClass('hidden');
$('#fileupload #fileListingWrapper').addClass('hidden');
$('#fileUploadBadge').removeClass('hidden');
}
else
{
updateTotalFilesText(totalRows);
}
});
// Open download dialogs via iframes,
// to prevent aborting current uploads:
$('#fileupload #files a:not([target^=_blank])').live('click', function (e) {
e.preventDefault();
$('<iframe style="display:none;"></iframe>')
.prop('src', this.href)
.appendTo('body');
});
//$(".ui-dialog-buttonpane").html("<div class='btn_bar_left'><div class='fileupload-progressbar'></div></div>"+$(".ui-dialog-buttonpane").html());
});
function setupCopyAllLink()
{
// setup copy to clipboard
$('#copyAllLink').zclip({
path: "js/ZeroClipboard.swf",
copy: getUrlsAsText()
});
}
function updateProgessText(progress, uploadedBytes, totalBytes)
{
// calculate speed & time left
nowTime = (new Date()).getTime();
loadTime = (nowTime - startTime);
if(loadTime == 0)
{
loadTime = 1;
}
loadTimeInSec = loadTime/1000;
bytesPerSec = uploadedBytes / loadTimeInSec;
textContent = '';
textContent += 'Progress: '+progress+'%';
textContent += ' ';
textContent += '('+bytesToSize(uploadedBytes, 2)+' / '+bytesToSize(totalBytes, 2)+')';
$("#fileupload-progresstextLeft").html(textContent);
rightTextContent = '';
rightTextContent += 'Speed: '+bytesToSize(bytesPerSec, 2)+'ps. ';
rightTextContent += 'Remaining: '+humanReadableTime((totalBytes/bytesPerSec)-(uploadedBytes/bytesPerSec));
$("#fileupload-progresstextRight").html(rightTextContent);
}
function getUrlsAsText()
{
urlStr = '';
for(var i=0; i<fileUrls.length; i++)
{
urlStr += fileUrls[i]+'\n';
}
return urlStr;
}
function updateTitleWithProgress(progress)
{
if(typeof(progress) == "undefined")
{
var progress = 0;
}
if(progress == 0)
{
$(document).attr("title", "<?php echo PAGE_NAME; ?> - <?php echo SITE_CONFIG_SITE_NAME; ?>");
}
else
{
$(document).attr("title", progress+"% Uploaded - <?php echo PAGE_NAME; ?> - <?php echo SITE_CONFIG_SITE_NAME; ?>");
}
}
function getTotalRows()
{
totalRows = $('#files .template-upload').length;
if(typeof(totalRows) == "undefined")
{
return 0;
}
return totalRows;
}
function updateTotalFilesText(total)
{
// removed for now, might be useful in some form in the future
//$('#uploadButton').html('upload '+total+' files');
}
function setRowClasses()
{
// removed for now, might be useful in some form in the future
//$('#files tr').removeClass('even');
//$('#files tr').removeClass('odd');
//$('#files tr:even').addClass('odd');
//$('#files tr:odd').addClass('even');
}
function showAdditionalInformation(ele)
{
// block parent clicks from being processed on additional information
$('.sliderContent table').unbind();
$('.sliderContent table').click(function(e){
e.stopPropagation();
});
// make sure we've clicked on a new element
if(lastEle == ele)
{
// close any open sliders
$('.sliderContent').slideUp('fast');
// remove row highlighting
$('.sliderContent').parent().parent().removeClass('rowSelected');
lastEle = null;
return false;
}
lastEle = ele;
// close any open sliders
$('.sliderContent').slideUp('fast');
// remove row highlighting
$('.sliderContent').parent().parent().removeClass('rowSelected');
// select row and popup content
$(ele).addClass('rowSelected');
// set the position of the sliderContent div
$(ele).find('.sliderContent').css('left', $(ele).offset().left);
$(ele).find('.sliderContent').css('top', $(ele).offset().top+38);
$(ele).find('.sliderContent').slideDown(400, function() {
});
return false;
}
function saveFileToFolder(ele)
{
// get variables
shortUrl = $(ele).closest('.sliderContent').children('.shortUrlHidden').val();
folderId = $(ele).val();
// send ajax request
var request = $.ajax({
url: "<?php echo _CONFIG_SITE_PROTOCOL . '://' . _CONFIG_SITE_FULL_URL; ?>/_updateFolder.ajax.php",
type: "POST",
data: {shortUrl: shortUrl, folderId: folderId},
dataType: "html"
});
}
</script>