PageSourceSearch

https://dowlatow.pro/nassets/3098c47a/file_widget.js?v=1780989909

js dowlatow.pro collected 2026-09-26 07:37:27 UTC 12,668 bytes, 323 lines download raw bytes

1window.fileWidgetQueueNum = 15;
2jQuery.widget( 'gc.fileWidget', {
3    uploader: null,
4    showButtonOnStart: false,
5    options: {
6	    showPreview: true,
7        onComplete: null,
8        fileSizeLimit: '6GB',
9		fileSizeLimitWarning: (typeof Yii != 'undefined') ? Yii.t('common', 'Max size {n} GB', 6) : 'Max size 6 GB'
10    },
11    _create: function () {
12        var self = this;
13        var $block;
14        if (window.isPageRedesigned) {
15            $block = $("<div class='rd-file-widget-wrap'>");
16        } else {
17            $block = $("<div>");
18        }
19        $block.insertAfter( this.element );
20
21        this.stateEl = $("<span style='float: left;'>");
22        this.stateEl.appendTo( $block );
23
24        this.previewEl = $("<div>")
25        this.previewEl.appendTo( $block )
26
27        if ( this.element.val() == "" ) {
28            //this.stateEl.html( "Нет файла" );
29        }
30
31        var labelChange = 'Изменить';
32        var labelDelete = 'Удалить';
33
34        if (typeof Yii != 'undefined') {
35            labelChange = Yii.t( "common", "Change" );
36            labelDelete = Yii.t( "common", "Delete" );
37        }
38
39        var $controlsEl = $("<div>");
40
41        $uploader = $("<a href='javascript:void(0)' class='file-change-link dotted-link'>" + labelChange + "</a>");
42        $uploader.css('marginRight', '5px');
43        $uploader.appendTo( $controlsEl );
44        this.uploader = $uploader;
45
46        this.deleteLink  = $deleteLink = window.isPageRedesigned
47            ? $( "<a class='dotted-link rd-delete-file' href='javascript:void(0)'><i class='gc-icons gc-close f-size-20'></i></a>" )
48            : $( "<a class='dotted-link' style='' href='javascript:void(0)'>" + labelDelete + "</a>" );
49        $deleteLink.click( function() {
50            self.element.val("");
51            self.element.change();
52            self.showPreview();
53            $('.rd-button_upload').show();
54            if (window.isPageRedesigned) {
55                $(this).parent().find('.file-change-link').trigger('click');
56                $(this).parent().find('.uploadifive-button').show();
57                $(this).parent().find('.rd-button_upload').show();
58            }
59        });
60
61        $deleteLink.appendTo( $controlsEl );
62	    if ( this.options.hideDeleteLink ) {
63	    	$deleteLink.hide();
64	    }
65
66        $controlsEl.appendTo( $block );
67        this.showPreview();
68
69        $uploader.click( function() {
70
71            if ( $(this).data('uploadifive-inited' ) ) {
72                return;
73            }
74
75            window.fileWidgetQueueNum++;
76            var queueId = "queue" + window.fileWidgetQueueNum;
77            $el = $("<div id='" + queueId + "'></div>")
78            $el.insertBefore( $(this))
79
80            var labelUpload = 'Загрузить';
81
82            if (typeof Yii != 'undefined') {
83                labelUpload = window.isAccountRedesignEnabled
84                    ? '<div class="rd-button_upload"><div class="rd-button_name">' +
85                            Yii.t( "common", "Добавить файл" ) + '</div><div class="rd-button_desc">' +
86                            Yii.t('common', 'Максимальный размер файла — {n} ГБ', 6) + '</div></div>'
87                    : Yii.t( "common", "Upload" );
88            }
89
90
91            $( this ).uploadifive({
92                auto: true,
93                buttonText: labelUpload,
94                width: 120,
95                id: window.queueNum,
96                queueID:queueId,
97                dnd: false,
98                removeCompleted: self.options.removeUploaded,
99                multi: false,
100                fileSizeLimit: self.options.fileSizeLimit,
101                uploadScript : '/fileservice/widget/upload?deprecated=19'
102                    + '&secure=' + window.isEnabledSecureUpload
103                    + '&host=' + window.fileserviceUploadHost,
104                formData: { fullAnswer: true },
105                onUploadError: function( file, errorCode, errorMsg ) {
106                    alert("ERROR");
107                },
108                onUploadComplete: function( e,res  ) {
109                    res = JSON.parse( res );
110                    self.element.val(res.hash);
111                    self.showPreview();
112                    self.element.change();
113
114                    if(window.isPageRedesigned) {
115                        $(this).parent('.uploadifive-button').hide();
116                        $(this).parent('.uploadifive-button').find('.rd-button_upload').hide();
117                    }
118                },
119				onUpload: function (filesToUpload, settings) {
120                    var secureDirectUploadUri = '/fileservice/widget/secure-direct-upload';
121                    try {
122                        var session = localStorage.getItem('session');
123                        var requestParams = {"fs_ref": window.location.href};
124
125                        if (session !== undefined && session != null){
126                            var objSession = jQuery.parseJSON(session);
127
128                            if (objSession.hasOwnProperty('user_id') && objSession.user_id != null) {
129                                requestParams.fs_u = objSession.user_id;
130                            } else {
131                                requestParams.fs_u = -1;
132                            }
133                        }
134
135                        secureDirectUploadUri += '?' + jQuery.param(requestParams);
136                    } catch (err) {
137                    }
138
139                    delete settings.uploadScript;
140
141					$.ajax({
142						url: '/fileservice/widget/create-secret-link',
143						method: 'GET',
144                        data: {
145                            host: window.fileserviceUploadHost,
146                            uri: secureDirectUploadUri,
147                            expires: 600
148                        },
149						success: function (data, textStatus, jqXHR) {
150                            if (data.link) {
151                                settings.uploadScript = data.link;
152                            } else {
153                                ajaxCall('/fileservice/widget/log-error', {m:  'No link'}, {});
154                            }
155						},
156						error: function (http, message, exc) {
157                            sendCreateLinkError(http, message, exc);
158                        },
159						async: false
160					});
161				}
162            });
163
164            if ( !window.isPageRedesigned && self.options.fileSizeLimit && self.options.fileSizeLimitWarning ) {
165                var warning = $("<p class='text-muted'>" + self.options.fileSizeLimitWarning + "</p>");
166                warning.appendTo( $controlsEl );
167            }
168
169			var accept = jQuery(self.element).data('accept');
170	        accept = accept === undefined ? '' : accept;
171	        if ( self.options.accept ) {
172	        	accept = self.options.accept;
173	        }
174	        if (accept) {
175				var $fileInput = jQuery(self.element).next().find('[type="file"]');
176				$fileInput.attr('accept', accept);
177			}
178
179            $(this).data('uploadifive-inited', true)
180
181        });
182
183        if ( this.options.startWithUploader && ! this.element.val() ) {
184            setTimeout( function() {
185                $uploader.click();
186            }, 100 )
187
188        }
189
190
191    },
192    showUploader: function() {
193        this.uploader.click();
194    },
195    setValue: function( val ) {
196        this.element.val( val )
197        this.showPreview( true )
198    },
199    showPreview: function( showFileWidgetIfNull ) {
200    	if (!this.options.showPreview) {
201    		return;
202	    }
203
204        function getFileName(el) {
205            var currentEl = el ? el[el.length-1] : null;
206            var currentElParent = currentEl ? currentEl.parentElement : null;
207            var filenameNode = currentElParent ? currentElParent.querySelector('.uploadifive-queue-item.complete .filename') : null;
208            if (window.isPageRedesigned) {
209                if (filenameNode) {
210                    var filenameRedesignNode = filenameNode ? currentElParent.querySelectorAll('.uploadifive-queue-item.complete .filename') : null;
211                    return filenameRedesignNode[filenameRedesignNode.length-1].innerText;
212                } else {
213                    return el.val();
214                }
215            }
216            return filenameNode ? filenameNode.innerText : '';
217        }
218
219        function isPdf(hash) {
220            var hashParts = hash.toLowerCase().split(".");
221            if (hashParts.length === 2) {
222                var imgExts = ['pdf'];
223                return imgExts.includes(hashParts[1]);
224            } else {
225                return false;
226            }
227        }
228
229        function isAudio(hash) {
230            var hashParts = hash.toLowerCase().split(".");
231            if (hashParts.length === 2) {
232                var imgExts = ['mp3', 'oga', 'ogg', '3gp', 'aac'];
233                return imgExts.includes(hashParts[1]);
234            } else {
235                return false;
236            }
237        }
238        var currentFilename, filenameEl;
239
240        var value = this.element.val();
241	    if ( value && value != "" ) {
242            var thumbnailUrl = null;
243			if (isImage(value)) {
244				if (this.element.data('thumbnail-url')) {
245					thumbnailUrl = this.element.data('thumbnail-url');
246				} else if (this.options.thumbnailWidth || this.options.thumbnailHeight) {
247					thumbnailUrl = getThumbnailUrl(value, this.options.thumbnailWidth, this.options.thumbnailHeight);
248				} else {
249					thumbnailUrl = getThumbnailUrl(value, 200, 200);
250				}
251                if(window.isPageRedesigned) {
252                    currentFilename = getFileName(this.element);
253
254                    filenameEl = currentFilename ? "<span class='rd-file-name'>" + currentFilename + "</span>" : '';
255                    this.previewEl.html(
256                        "<div class='rd-dropzone__image'>" +
257                        "<img class='rd-file-thumbnail' src='" + thumbnailUrl + "'></div>" + filenameEl
258                    );
259                } else {
260                    this.previewEl.html("<img class='rd-file-thumbnail' src='" + thumbnailUrl + "'>");
261                }
262			} else if (window.isPageRedesigned) {
263                currentFilename = getFileName(this.element);
264                if (!currentFilename) {
265                    currentFilename = value ? value : '';
266                }
267                filenameEl = "<span class='rd-caption-m  rd-file-name'>" + currentFilename + "</span>";
268
269                var fileType;
270                if (isVideo(value)) {
271                    fileType = 'video'
272                } else if (isPdf(value)) {
273                    fileType = 'pdf'
274                } else if (isAudio(value)) {
275                    fileType = 'audio'
276                } else {
277                    fileType = 'file'
278                }
279                thumbnailUrl = '/public/redesign/images/' + fileType + '.svg';
280                this.previewEl.html(
281                    "<div class='rd-dropzone__image icon-thumb'>" +
282                    "<img class='rd-file-thumbnail' src='" + thumbnailUrl + "'></div>" + filenameEl
283                );
284            } else if (isVideo( value ) && this.options.showVideoPreview !== false) {
285				thumbnailUrl = getVideoThumbnailUrl(value, 200, 200);
286                if(window.isPageRedesigned) {
287                    currentFilename = getFileName(this.element);
288                    filenameEl = currentFilename ? "<span class='rd-file-name'>" + currentFilename + "</span>" : '';
289                    this.previewEl.html("<img class='rd-file-thumbnail' src='" + thumbnailUrl + "'>" + filenameEl);
290                } else {
291                    this.previewEl.html("<img class='rd-file-thumbnail' src='/public/img/dummy.png' width='250'>");
292                }
293			}
294			else {
295			    if (value) {
296                    value = value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
297                }
298
299				this.previewEl.html("<a href='" + getDownloadUrl(value) + "'>" + value + "</a>");
300			}
301
302            if (window.isPageRedesigned) {
303                this.previewEl.css('display', 'flex');
304            } else {
305                this.previewEl.show();
306            }
307			this.deleteLink.show();
308
309            if(window.isPageRedesigned) {
310                this.previewEl.addClass('file-preview flex-8 align-center');
311                this.previewEl.parent().find('.file-change-link').hide()
312                this.previewEl.parent().find('.uploadifive-button').hide()
313            }
314        }
315        else {
316            this.previewEl.hide();
317            this.deleteLink.hide();
318            if ( showFileWidgetIfNull ) {
319                this.uploader.click();
320            }
321        }
322    }
323});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.