forked from xsmo/Image-Uploader-and-Browser-for-CKEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.js
executable file
·378 lines (318 loc) · 9.53 KB
/
function.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// Copyright (c) 2015, Fujana Solutions - Moritz Maleck. All rights reserved.
// For licensing, see LICENSE.md
// Open image modal
function showImage(imgSrc, imgStyle) {
$("#imageFSimg").attr('src', imgSrc);
$("#imageFSimg").attr('style', 'max-width:' + imgStyle + 'px');
$("#imageFullSreen").show();
$("#background").slideDown(250, "swing");
$("#imgActionUse").attr("onclick","useImage('" + imgSrc + "')");
$("#imgActionDownload").attr("href", imgSrc);
}
// Open editbar
function showEditBar(imgSrc, imgStyle, imgID, imgName) {
var imgSrc = imgSrc;
var imgStyle = imgStyle;
var imgID = imgID;
var imgName = imgName;
$("#editbar").slideUp(100);
$("#editbar").slideDown(100);
$(".fileDiv,.fullWidthFileDiv").removeClass( "selected" );
$("div[data-imgid='" + imgID +"']").addClass( "selected" );
$("#updates").css("visibility", "hidden");
$("#updates").slideUp(150);
$("#editbarDelete").attr("onclick","deleteImg('" + imgName + "', '" + imgID + "');");
$("#editbarUse").attr("onclick","useImage('" + imgSrc + "')");
$("#editbarView").attr("onclick","showImage('" + imgSrc + "','" + imgStyle + "')");
$("#editbarDownload").attr("href", imgSrc);
}
// hide editbar if user clicks outside of element
$(document).mouseup(function (e) {
var container = $(".fileDiv,.fullWidthFileDiv,#editbar");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
hideEditBar();
}
});
// hide editbar function
function hideEditBar() {
$("#editbar").slideUp(100);
$(".fileDiv,.fullWidthFileDiv").removeClass( "selected" );
if (currentpluginver != pluginversion) {
$("#updates").slideDown(150);
$("#updates").css("visibility", "visible");
};
}
// Use image and overgive image src to ckeditor
function useImage(imgSrc) {
function getUrlParam( paramName ) {
var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' ) ;
var match = window.location.search.match(reParam) ;
return ( match && match.length > 1 ) ? match[ 1 ] : null ;
}
var funcNum = getUrlParam( 'CKEditorFuncNum' );
var imgSrc = imgSrc;
var fileUrl = imgSrc;
window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
window.close();
}
// open upload image modal
function uploadImg() {
$("#uploadImgDiv").show();
$("#background2").slideDown(250, "swing");
}
// open settings modal
function pluginSettings() {
$("#settingsDiv").show();
$("#background3").slideDown(250, "swing");
}
// check if new version is available
$( document ).ready(function() {
if (currentpluginver != pluginversion) {
$("#updates").show();
$('#updates').html("A new version of "+ pluginname +" ("+ pluginversion +") is available. <a target=\"_blank\" href=\""+ plugindwonload +"\">Download it now!</a>");
};
});
// call jquery lazy load
$(function() {
$("img.lazy").lazyload();
});
$( document ).ready(function() {
var elem = '#uploadpathEditable';
var text = '.saveUploadPathP';
var btn = '.saveUploadPathA';
var btnCancel = '#pathCancel';
$( elem ).attr('contenteditable','true');
$( elem ).click(function() {
$( this ).addClass("editableActive");
$( btn ).fadeIn();
$( text ).show();
$( '.pathHistory' ).fadeIn();
});
$( btnCancel ).click(function() {
$( elem ).removeClass('editableActive');
$( btn ).hide();
$( text ).hide();
$( '.pathHistory' ).hide();
});
});
function updateImagePath(){
var name = $("#uploadpathEditable").text();
$.ajax({
method: "POST",
url: "pluginconfig.php",
data: { newpath: name, }
}).done(function( msg ) {
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
});
}
function useHistoryPath(path){
var path = path;
$.ajax({
method: "POST",
url: "pluginconfig.php",
data: { newpath: path, }
}).done(function( msg ) {
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
});
}
// open pluginconfig.php to change the extension settings
function extensionSettings(setting){
var setting = setting;
$.ajax({
method: "POST",
url: "pluginconfig.php",
data: {
extension: setting,
}
}).done(function( msg ) {
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
});
}
// check if a file to upload is selected
function checkUpload(){
if( document.getElementById("upload").files.length == 0 ){
alert("Please select a file to upload.");
return false;
}
}
// toggle the edit icons
function toggleQEditIcons(){
$( '.fullWidthlastChild, .qEditIconsDiv' ).toggle();
}
// toggle the edit mode
function toogleQEditMode(){
if($('#qEditBtnOpen').is(':visible')){
Cookies.set('qEditMode', 'yes');
} else {
Cookies.remove('qEditMode');
}
toggleQEditIcons();
$( '#qEditBtnDone, #qEditBtnOpen' ).slideToggle();
}
// check if qEditMode is activated
$( document ).ready(function() {
if(Cookies.get('qEditMode') == "yes"){
toogleQEditMode();
}
});
// drag n' drop
function drop(e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
if(file && file.type.match("image/*")) {
var formdata = new FormData();
formdata.append('upload', file);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'imgupload.php');
xhr.send(formdata);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
hideEditBar();
reloadImages();
setTimeout(function(){
$("#dropzone").slideUp(450, "swing");
}, 50);
}
}
}
}
// toggle dropzone
function toggleDropzone(s) {
var elem = $("#dropzone");
if(s == "show") {
elem.show();
} else {
elem.hide();
}
}
// hide dropzone if user clicks close
$( document ).ready(function() {
$( "#dropzone" ).click(function() {
setTimeout(function(){
toggleDropzone('hide');
}, 500);
});
});
// delete image
function deleteImg(src, imgid) {
$.ajax({
method: "GET",
url: "imgdelete.php",
data: {
img: src,
}
}).done(function() {
var imgDiv = $( "div[data-imgid='" + imgid +"']" );
if(Cookies.get('file_style') == "block"){
imgDiv.addClass("deleteAnimationBlock");
} else {
imgDiv.slideUp(250, "swing");
}
setTimeout(function(){
imgDiv.hide();
hideEditBar();
reloadImages();
}, 320);
});
}
// reload images
function reloadImages() {
$.ajaxSetup({cache:false});
$('#files').load('function.php?f=loadImages', function(response, status, xhr) {
$("img.lazy").lazyload();
});
}
// select language
function selectLang(lang) {
Cookies.set('sy_lang', lang, { expires: 1095 });
$('#setLangDiv').hide();
$('#background4').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
}
// open lang panel
function openLangPanel() {
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
$("#setLangDiv").show();
$("#background4").slideDown(250, "swing");
}, 350);
}
// enable news
function enableNews() {
Cookies.remove('show_news');
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
}
// disable news
function disableNews() {
Cookies.set('show_news', 'no', { expires: 7 });
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 250);
}
function logOut(){
$.ajax({
method: "POST",
url: "logout.php",
}).done(function( msg ) {
$('#settingsDiv').hide();
$('#background3').slideUp(250, 'swing');
setTimeout(function(){
location.reload();
}, 300);
});
}
// keyboard shortcuts
$(document).keyup(function (e){
// left arrow and top arrow
if (e.keyCode == 37 || e.keyCode == 38) {
var imgID = $(".selected").data("imgid");
if(typeof imgID === 'undefined'){
var imgID = 2;
};
var next = --imgID;
$( "div[data-imgid='" + next +"']" ).trigger( "click" );
}
// right arrow and bottom arrow
if (e.keyCode == 39 || e.keyCode == 40) {
var imgID = $(".selected").data("imgid");
if(typeof imgID === 'undefined'){
var imgID = 0;
};
var next = ++imgID;
$( "div[data-imgid='" + next +"']" ).trigger( "click" );
}
// space
if (e.keyCode == 32) {
if($('#imageFullSreen').is(':visible')){
$( "#imageFullSreenClose" ).trigger( "click" );
} else {
var imgID = $(".selected").data("imgid");
if(typeof imgID !== 'undefined'){
$( "#editbarView" ).trigger( "click" );
}
}
}
})