Completed
Push — master ( 4fbf71...b6fccf )
by Evgenii
03:05
created

yii2-floor12-files.js ➔ initCropper   B

Complexity

Conditions 5

Size

Total Lines 40
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
c 0
b 0
f 0
dl 0
loc 40
rs 8.7413
cc 5
1
console.log('Yii2 files model init.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
2
3
4
var currentCroppingImageId;
5
var currentRenamingFileId;
6
var cropper;
7
var removeFileOnCropCancel;
8
var yii2CropperRoute;
9
10
$(document).on('change', '.yii2-files-upload-field', function () {
11
12
    obj = $(this);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
13
14
    var formData = new FormData();
15
    formData.append('file', obj[0].files[0]);
16
    formData.append('modelClass', obj.data('modelclass'));
17
    formData.append('attribute', obj.data('attribute'));
18
    formData.append('mode', obj.data('mode'));
19
    formData.append('ratio', obj.data('ratio'));
20
    formData.append('_fileFormToken', yii2FileFormToken);
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
21
22
23
    $.ajax({
24
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never declared. If this is a global, consider adding a /** global: yii2UploadRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
        type: 'POST',
26
        data: formData,
27
        processData: false,  // tell jQuery not to process the data
28
        contentType: false,  // tell jQuery not to set contentType
29
        success: function (response) {
30
            id = '#files-widget-block_' + obj.data('block');
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
31
            $(response).appendTo(id).find('div.floor12-files-widget-list');
32
        }
33
    });
34
});
35
36
37
function clipboard(text) {
38
    //based on https://stackoverflow.com/a/12693636
39
    document.oncopy = function (event) {
40
        event.clipboardData.setData("Text", text);
41
        event.preventDefault();
42
    };
43
    document.execCommand("Copy");
44
    document.oncopy = undefined;
45
    f12notification.info(text, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
}
47
48
function updateProgressCircle(val, btnGroup) {
49
    result = 169.646 * (1 - val / 100);
0 ignored issues
show
Bug introduced by
The variable result seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.result.
Loading history...
50
    btnGroup.querySelector('svg #progress-circle').setAttribute('stroke-dashoffset', result);
51
    btnGroup.querySelector('.floor12-file-percents').innerHTML = val + '%';
52
    // setAttribute('stroke-dashoffset', result);
53
}
54
55
var observer = new MutationObserver(function (mutations) {
0 ignored issues
show
Bug introduced by
The variable MutationObserver seems to be never declared. If this is a global, consider adding a /** global: MutationObserver */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
56
    percent = mutations[0].target.style.width.replace('%', '');
0 ignored issues
show
Bug introduced by
The variable percent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.percent.
Loading history...
57
    btnGroup = mutations[0].target.parentElement.parentElement;
0 ignored issues
show
Bug introduced by
The variable btnGroup seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.btnGroup.
Loading history...
58
    updateProgressCircle(percent, btnGroup);
59
});
60
61
function Yii2FilesUploaderSet(id, className, attribute, scenario) {
62
63
    var mode = 'multi';
64
    var blockName = "#" + id;
65
    var block = $(blockName);
66
    var uploadButton = block.find('button.btn-upload')[0];
67
    var filesList = block.find('.floor12-files-widget-list')[0];
68
    var ratio = 0;
69
70
    var csrf = block.parents('form').find('input[name=' + yii2CsrfParam + ']').val();
0 ignored issues
show
Bug introduced by
The variable yii2CsrfParam seems to be never declared. If this is a global, consider adding a /** global: yii2CsrfParam */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
72
    if (block.data('ratio'))
73
        ratio = block.data('ratio');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
74
75
    if (block.hasClass('floor12-files-widget-single-block')) {
76
        mode = 'single';
77
        toggleSingleUploadButton(block);
78
    }
79
80
    var data = {
81
        modelClass: className,
82
        attribute: attribute,
83
        scenario: scenario,
84
        mode: mode,
85
        ratio: ratio,
86
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
87
    }
88
    data[yii2CsrfParam] = csrf
89
90
    var uploader = new ss.SimpleUpload({
0 ignored issues
show
Unused Code introduced by
The variable uploader seems to be never used. Consider removing it.
Loading history...
Bug introduced by
The variable ss seems to be never declared. If this is a global, consider adding a /** global: ss */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
91
        button: uploadButton,
92
        url: yii2UploadRoute,
0 ignored issues
show
Bug introduced by
The variable yii2UploadRoute seems to be never declared. If this is a global, consider adding a /** global: yii2UploadRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
93
        name: 'file',
94
        dropzone: block,
95
        dragClass: 'floor12-files-widget-block-drug-over',
96
        multiple: true,
97
        multipleSelect: true,
98
        data: data,
99
        onSubmit:
100
            function (filename, extension, data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter extension is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
101
                var svg = '\t<svg width="60" height="60" viewBox="0 0 60 60">\n' +
102
                    '\t\t<circle cx="30" cy="30" r="27" fill="none" stroke="#ccc" stroke-width="5" />\n' +
103
                    '\t\t<circle id="progress-circle" cx="30" cy="30" r="27" fill="none" stroke="#666" stroke-width="5" stroke-dasharray="169.646" stroke-dashoffset="169.646" />\n' +
104
                    '\t</svg>';
105
106
                var id = generateId(filename);
107
                var btnGroup = document.createElement('div');
108
                var fileObject = document.createElement('div');
109
                var bar = document.createElement('div');
110
                var percents = document.createElement('div');
111
                btnGroup.setAttribute('id', id);
112
                btnGroup.className = 'btn-group files-btn-group';
113
                fileObject.className = 'floor12-file-object';
114
                percents.className = 'floor12-file-percents';
115
116
                this.setProgressBar(bar);
117
118
                fileObject.innerHTML = svg;
119
120
                observer.observe(bar, {
121
                    attributes: true
122
                });
123
124
                fileObject.appendChild(bar);
125
                fileObject.appendChild(percents);
126
                btnGroup.appendChild(fileObject);
127
128
129
                if (mode == 'single') {
130
                    $(filesList).html('');
131
                }
132
                $(filesList).append(btnGroup);
133
134
135
            },
136
        onComplete: function (filename, response) {
137
            if (!response) {
138
                console.log(filename + 'upload failed');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
139
                return false;
140
            }
141
            f12notification.info(FileUploadedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileUploadedText seems to be never declared. If this is a global, consider adding a /** global: FileUploadedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
142
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
143
            $(idName).replaceWith($(response));
144
145
            if (mode == 'single')
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if mode == "single" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
146
                toggleSingleUploadButton(block);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
147
        },
148
        onError: function (filename, errorType, status, statusText, response, uploadBtn, fileSize) {
0 ignored issues
show
Unused Code introduced by
The parameter fileSize is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter uploadBtn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
149
            data = {
150
                responseText: response,
151
                status: status,
152
                statusText: statusText,
153
            };
154
            processError(data);
155
            idName = "#" + generateId(filename);
0 ignored issues
show
Bug introduced by
The variable idName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.idName.
Loading history...
156
            $(idName).remove();
157
        }
158
159
        //     progressUrl: 'uploadProgress.php', // enables cross-browser progress support (more info below)
160
        //     responseType: 'json',
161
        //    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
162
        //   maxSize: 1024, // kilobytes
163
        //     hoverClass: 'ui-state-hover',
164
        //     focusClass: 'ui-state-focus',
165
        //     disabledClass: 'ui-state-disabled',
166
    });
167
168
}
169
170
function generateId(filename) {
171
    return 'id-' + filename.replace(/[^0-9a-zA-Z]/g, "");
172
}
173
174
function showUploadButton(event) {
175
    obj = $(event.target);
0 ignored issues
show
Bug introduced by
The variable obj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.obj.
Loading history...
176
    console.log(obj);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
177
    obj.parents('div.floor12-files-widget-single-block').find('button').show();
178
}
179
180
function toggleSingleUploadButton(block) {
181
    if (block.find('div.floor12-single-file-object').length > 0)
182
        block.find('button').hide();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
183
    else
184
        block.find('button').show();
185
}
186
187
function sortableFiles() {
188
    $(".floor12-files-widget-list-multi").sortable({
189
        opacity: 0.5,
190
        revert: 1,
191
        items: "div.files-btn-group",
192
    });
193
}
194
195
function removeFile(id) {
196
    id = "#yii2-file-object-" + id;
197
198
    $(id).parents('div.files-btn-group').fadeOut(200, function () {
199
        $(this).remove();
200
        f12notification.info(FileRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileRemovedText seems to be never declared. If this is a global, consider adding a /** global: FileRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
201
    });
202
    return false;
203
}
204
205
function removeAllFiles(event) {
206
    console.log('removeAllFiles');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
207
    $(event.target).parents('div.floor12-files-widget-list').find('div.files-btn-group').fadeOut(200, function () {
208
        $(this).remove();
209
    });
210
    f12notification.info(FilesRemovedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FilesRemovedText seems to be never declared. If this is a global, consider adding a /** global: FilesRemovedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
211
    return false;
212
}
213
214
function initCropperLayout() {
215
    if (yii2CropperRoute.length > 0)
0 ignored issues
show
Bug introduced by
The variable yii2CropperRoute seems to be never initialized.
Loading history...
216
        $.get(yii2CropperRoute, function (response) {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
217
            $('body').append(response);
218
219
            $('#yii2-file-title-editor input').on('keyup', function (e) {
220
                if (e.keyCode == 13) {
221
                    saveFileTitle()
222
                }
223
            });
224
        })
225
}
226
227
function initCropper(id, url, ratio, remove) {
228
    $('#cropperModal').modal({keyboard: false, backdrop: 'static'});
229
230
    currentCroppingImageId = id;
231
232
    removeFileOnCropCancel = false;
233
    if (remove)
234
        removeFileOnCropCancel = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
235
236
    currentCropImage = $('<img>').attr('src', url);
0 ignored issues
show
Bug introduced by
The variable currentCropImage seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.currentCropImage.
Loading history...
237
    $('#cropperArea').html("");
238
    $('#cropperArea').append(currentCropImage);
239
240
    autoCrop = false;
0 ignored issues
show
Bug introduced by
The variable autoCrop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.autoCrop.
Loading history...
241
    aspectRatio = NaN;
0 ignored issues
show
Comprehensibility Best Practice introduced by
You seem to be aliasing the built-in name NaN as aspectRatio. This makes your code very difficult to follow, consider using the built-in name directly.
Loading history...
Bug introduced by
The variable aspectRatio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.aspectRatio.
Loading history...
242
    $('#cropper-btn-cancel').show();
243
244
    console.log(cropperHideCancel);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable cropperHideCancel seems to be never declared. If this is a global, consider adding a /** global: cropperHideCancel */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
245
    if (cropperHideCancel == 'true') {
246
        alert(1);
0 ignored issues
show
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
247
        $('#cropper-btn-cancel').hide();
248
    }
249
250
251
    if (ratio) {
252
        autoCrop = true;
253
        aspectRatio = ratio;
254
        $('.cropper-ratio-btn-group').hide();
255
    }
256
257
    setTimeout(function () {
258
        cropper = currentCropImage.cropper({
259
            viewMode: 1,
260
            background: false,
261
            zoomable: false,
262
            autoCrop: autoCrop,
263
            aspectRatio: aspectRatio,
264
        });
265
    }, 1000)
266
}
267
268
function stopCrop(id) {
0 ignored issues
show
Unused Code introduced by
The parameter id is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
269
    $('#cropperModal').modal('hide');
270
    if (removeFileOnCropCancel)
271
        removeFile(currentCroppingImageId);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
272
}
273
274
function cropImage() {
275
    сropBoxData = cropper.cropper('getCropBoxData');
0 ignored issues
show
Bug introduced by
The variable сropBoxData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.сropBoxData.
Loading history...
276
    imageData = cropper.cropper('getImageData');
0 ignored issues
show
Bug introduced by
The variable imageData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.imageData.
Loading history...
277
    canvasData = cropper.cropper('getCanvasData');
0 ignored issues
show
Bug introduced by
The variable canvasData seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.canvasData.
Loading history...
278
    ratio = imageData.height / imageData.naturalHeight;
0 ignored issues
show
Bug introduced by
The variable ratio seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ratio.
Loading history...
279
    cropLeft = (сropBoxData.left - canvasData.left) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropLeft seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropLeft.
Loading history...
280
    cropTop = (сropBoxData.top - canvasData.top) / ratio;
0 ignored issues
show
Bug introduced by
The variable cropTop seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropTop.
Loading history...
281
    cropWidth = сropBoxData.width / ratio;
0 ignored issues
show
Bug introduced by
The variable cropWidth seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropWidth.
Loading history...
282
    cropHeight = сropBoxData.height / ratio;
0 ignored issues
show
Bug introduced by
The variable cropHeight seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.cropHeight.
Loading history...
283
    rotated = imageData.rotate;
0 ignored issues
show
Bug introduced by
The variable rotated seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.rotated.
Loading history...
284
285
    data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
286
        id: currentCroppingImageId,
287
        width: cropWidth,
288
        height: cropHeight,
289
        top: cropTop,
290
        left: cropLeft,
291
        rotated: rotated,
292
        _fileFormToken: yii2FileFormToken
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
293
    };
294
295
    removeFileOnCropCancel = false;
296
297
    $.ajax({
298
        url: yii2CropRoute,
0 ignored issues
show
Bug introduced by
The variable yii2CropRoute seems to be never declared. If this is a global, consider adding a /** global: yii2CropRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
299
        'method': 'POST',
300
        data: data,
301
        success: function (response) {
302
            id = '#yii2-file-object-' + currentCroppingImageId;
0 ignored issues
show
Bug introduced by
The variable id seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.id.
Loading history...
303
            if ($(id).find('img').length)
304
                $(id).find('img').attr('src', response);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
305
            else {
306
                $(id).css('background-image', 'none');
307
                $(id).css('background-image', 'url(' + response + ')');
308
            }
309
            stopCrop();
310
            f12notification.info(FileSavedText, 1);
0 ignored issues
show
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable FileSavedText seems to be never declared. If this is a global, consider adding a /** global: FileSavedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
311
        },
312
        error: function (response) {
313
            processError(response);
314
        }
315
    })
316
}
317
318
function showRenameFileForm(id, event) {
319
    var blockId = '#yii2-file-object-' + id;
320
    var title = $(blockId).attr('title');
321
    currentRenamingFileId = id;
322
    $('#yii2-file-title-editor').css('top', event.clientY).css('left', event.clientX - 70).fadeIn(100);
323
    $('#yii2-file-title-editor input').val(title).focus();
324
}
325
326
function hideYii2FileTitleEditor() {
327
    $('#yii2-file-title-editor').fadeOut(100);
328
    currentRenamingFileId = null;
329
}
330
331
function saveFileTitle() {
332
    $('#yii2-file-title-editor').fadeOut(100);
333
    val = $('#yii2-file-title-editor input').val();
0 ignored issues
show
Bug introduced by
The variable val seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.val.
Loading history...
334
    blockId = '#yii2-file-object-' + currentRenamingFileId;
0 ignored issues
show
Bug introduced by
The variable blockId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.blockId.
Loading history...
335
    $(blockId).attr('title', val);
336
    $(blockId).attr('data-title', val);
337
338
    $.ajax({
339
            url: yii2RenameRoute,
0 ignored issues
show
Bug introduced by
The variable yii2RenameRoute seems to be never declared. If this is a global, consider adding a /** global: yii2RenameRoute */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
340
            method: 'POST',
341
            data: {id: currentRenamingFileId, title: val, _fileFormToken: yii2FileFormToken},
0 ignored issues
show
Bug introduced by
The variable yii2FileFormToken seems to be never declared. If this is a global, consider adding a /** global: yii2FileFormToken */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
342
            success: function () {
343
                f12notification.info(FileRenamedText, 1);
0 ignored issues
show
Bug introduced by
The variable FileRenamedText seems to be never declared. If this is a global, consider adding a /** global: FileRenamedText */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable f12notification seems to be never declared. If this is a global, consider adding a /** global: f12notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
344
            },
345
            error: function (response) {
346
                processError(response);
347
            }
348
        }
349
    );
350
    currentRenamingFileId = null;
351
}
352
353
$(document).ready(function () {
354
    setInterval(function () {
355
        sortableFiles()
356
    }, 2000);
357
358
    sortableFiles();
359
360
    initCropperLayout();
361
362
});
363
364
365