PageSourceSearch

https://akademia-excel.ru/nassets/3e6171b4/js/folder-pixabay.js?v=1765633899

js akademia-excel.ru collected 2026-09-30 11:25:37 UTC 10,248 bytes, 293 lines download raw bytes

1jQuery.widget( 'gc.gcFilePixabayFolder', {
2    options: {
3        owner: null,
4        folder: null
5    },
6
7    _create: function() {
8        var self = this;
9        this.element.addClass("pixabay-folder")
10
11        this.panel = this.createPanel();
12        this.panel.appendTo( this.element )
13
14		var searchLabel = 'Поиск по фотобанку Pixabay';
15		var licenseLabel = 'Все изображения опубликованы под лицензией Creative Commons CC0 (бесплатно доступны к использованию)';
16		if (typeof Yii != 'undefined') {
17			searchLabel = Yii.t("common", searchLabel);
18			licenseLabel = Yii.t("common", licenseLabel);
19		}
20
21		this.pixabayEl = $('<div class="clearfix pixabay-info-label"><a target="_blank" href="http://pixabay.com"><img  src="https://pixabay.com/static/img/public/leaderboard_b.png"></a> ' + searchLabel + ' <br/>' + licenseLabel + ' </div>')
22                this.pixabayEl.appendTo( this.element )
23
24        this.filesEl = $('<div class="files-list"></div>')
25        this.filesEl.appendTo( this.element )
26
27
28    },
29    checkNeedToRefresh: function() {
30        var self = this;
31        //this.panel = this.createPanel();
32    },
33    createPanel: function() {
34
35        var self = this;
36
37		var searchSimpleLabel = 'Поиск';
38		var allImagesLabel = 'все изображения';
39		var photoLabel = 'фото';
40		var ilustrationLabel = 'иллюстрации';
41		var vectorLabel = 'векторные';
42		var allOrintationLabel = 'любая ориентация';
43		var horizontalLabel = 'горизонтальные';
44		var verticalLabel = 'вертикальные';
45		var findLabel = 'Найти';
46		var wordLabel = 'прибой';
47
48		if (typeof Yii != 'undefined') {
49			searchSimpleLabel = Yii.t("common", searchSimpleLabel);
50			allImagesLabel = Yii.t("common", allImagesLabel);
51			photoLabel = Yii.t("common", photoLabel);
52			ilustrationLabel = Yii.t("common", ilustrationLabel);
53			vectorLabel = Yii.t("common", vectorLabel);
54			allOrintationLabel = Yii.t("common", allOrintationLabel);
55			horizontalLabel = Yii.t("common", horizontalLabel);
56			verticalLabel = Yii.t("common", verticalLabel);
57			findLabel = Yii.t("common", findLabel);
58			wordLabel = Yii.t("common", wordLabel);
59		}
60
61        var $panel = $(
62           "<form class='search-panel'>"
63           + "<div class='results-nav'> <span class='results-count text-muted' style='padding-right: 10px'></span> <span class='btn-prev-page fa fa-chevron-left'></span> <span class='page-num'></span> / <span class='page-count'></span> <span class='btn-next-page fa fa-chevron-right'></span> </div>"
64           + "<div class='filter'>"+searchSimpleLabel+" <input class='search-input' type=text size=50 > <select class='type-select'><option value='all'>"+allImagesLabel+"</option><option selected value='photo'>"+photoLabel+"</option><option value='illustration'>"+ilustrationLabel+"</option><option value='vector'>"+vectorLabel+"</option></select> <select class='orientation-select'><option value='all'>"+allOrintationLabel+"</option><option value='horizontal'>"+horizontalLabel+"</option><option value='vertical'>"+verticalLabel+"</option></select>  <button type='submit' class='btn btn-primary btn-xs'>"+findLabel+"</button></div>"
65           + "</form>"
66        )
67
68        this.searchInput = $panel.find('.search-input')
69        this.searchInput.val(wordLabel)
70        this.typeSelect = $panel.find('.type-select')
71        this.orientationSelect = $panel.find('.orientation-select')
72
73        this.pageNumEl = $panel.find('.page-num')
74        this.pageCountEl = $panel.find('.page-count')
75        this.resultsCountEl = $panel.find('.results-count')
76        this.nextPageBtn = $panel.find('.btn-next-page')
77        this.prevPageBtn = $panel.find('.btn-prev-page')
78
79        this.nextPageBtn.hide();
80        this.prevPageBtn.hide();
81
82        this.nextPageBtn.click( function() {
83            self.loadFiles( self.pageNum + 1)
84        })
85
86        this.prevPageBtn.click( function() {
87            self.loadFiles( self.pageNum - 1)
88        })
89
90        $panel.submit( function() {
91            self.loadFiles();
92            return false;
93        })
94
95        return $panel;
96    },
97
98    createFileEl: function( hit ) {
99        var $el = $('<div class="file-item pixabay-file-item"></div>')
100        var self = this;
101
102        $el.data('webformat-url', hit.webformatURL)
103        $el.data('hit', hit)
104
105        $imgWrapper = $('<div class="img-wrapper"></div>')
106        $imgWrapper.appendTo( $el );
107        //$imgWrapper = $imgWrapper.find('span')
108
109        var $img = $('<img>')
110        $img.attr( "src", hit.previewURL )
111        $img.appendTo( $imgWrapper )
112
113        //$selectBtn = $('<button class="btn btn-select btn-primary">Выбрать</button>')
114        //$selectBtn.appendTo( $el )
115
116        $favBtn = $('<button class="btn btn-link btn-favorites"><span class="to-favorites glyphicon glyphicon-folder-close"></span><span class="from-favorites glyphicon glyphicon-folder-open"></span></button>')
117        //$favBtn.appendTo( $el )
118        self.favBtn = $favBtn
119
120
121        var $previewDiv = $('<div class="preview-div"></div>')
122        $previewDiv.appendTo( $el )
123        $previewDiv.hide();
124
125        $el.mouseover( function() {
126            $previewEl = $(this).find('.preview-div');
127            var webformatURL = $(this).data('webformat-url')
128            if ( ! $previewEl.data('loaded')) {
129                var $img = $("<div><img src='" + webformatURL + "'/></div>")
130				var inCommonLabel = 'в общие';
131				if (typeof Yii != 'undefined') {
132					inCommonLabel = Yii.t("common", inCommonLabel);
133				}
134				var $buttons = $('<div class="buttons"> <a class="to-fav" href="javascript:void(0)"> <span class="glyphicon glyphicon-folder-close"></span> ' + inCommonLabel + '</a></div>')
135
136                var $toFavBtn = $buttons.find( '.to-fav' )
137
138                $toFavBtn.click( function(e ) {
139                    self.toFavorites( $el )
140                    e.stopPropagation();
141                    e.preventDefault();
142                })
143
144                $previewEl.click( function() {
145                    self.selectFile( $el );
146                } );
147
148                $img.appendTo( $previewEl )
149                $buttons.appendTo( $previewEl )
150
151                $previewEl.data('loaded', true)
152            }
153            if ( ! $el.hasClass('loading')) {
154                $previewEl.show();
155            }
156        } );
157
158        $el.mouseout( function() {
159            $(this).find('.preview-div').hide();
160        } );
161
162
163
164        return $el;
165    },
166    startLoading: function( $el ) {
167        $el.find('.preview-div').hide();
168        $el.addClass('loading')
169
170        $loader = $("<div class='loader' style='position: absolute; top: 10px; left: 10px; '></div>")
171        setElLoading( $loader )
172        $loader.appendTo( $el )
173    },
174    stopLoading: function( $el ) {
175        $el.find('.loader').remove();
176        $el.removeClass('loading')
177    },
178    toFavorites: function( $el ) {
179        var self = this;
180        var hit = $el.data('hit')
181        if ( hit.webformatURL ) {
182
183
184            self.startLoading( $el );
185
186            self.getFileFromPixabay( hit, function( hash ) {
187                self.markFile( hash, "favorites", true, function() {
188                    self.stopLoading( $el );
189                    $('.folder-picker-favorites').effect('highlight', { duration: 1000})
190                })
191            })
192
193        }
194    },
195
196    selectFile: function( $el ) {
197
198        var self = this;
199        var hit = $el.data('hit')
200        if ( hit.largeImageURL ) {
201            self.startLoading( $el );
202
203            self.getFileFromPixabay( hit, function( hash ) {
204                self.stopLoading( $el );
205                self.options.owner.fileSelected( hash )
206            })
207        }
208
209    },
210
211
212    getFileFromPixabay: function( hit, callback ) {
213        var data = { link:hit.largeImageURL }
214        ajaxCall( "/pl/fileservice/widget/load-link", data, {}, function( response ) {
215            if ( callback ) {
216                callback( response.data.hash )
217            }
218        } )
219    },
220
221    markFile: function( hash, mark, positive, callback ) {
222        var data = {
223            hash: hash,
224            mark: mark,
225            positive: positive ? 1 : 0
226        }
227
228        ajaxCall( "/pl/fileservice/widget/mark", data, {}, function() {
229            if ( callback ) {
230                callback( positive );
231            }
232        } )
233    },
234    loadFiles: function( pageNum ) {
235        var self = this;
236
237        $toElement = this.filesEl;
238
239        $toElement.empty();
240
241        if ( ! pageNum ) {
242            pageNum = 1;
243        }
244
245        var perPage = 40;
246        var searchParamsStr = "";
247        searchParamsStr += "q=" + encodeURIComponent( this.searchInput.val() )
248        searchParamsStr += "&image_type=" + this.typeSelect.val()
249        searchParamsStr += "&orientation=" + this.orientationSelect.val()
250        searchParamsStr += "&page=" + pageNum;
251        searchParamsStr += "&per_page=" + perPage;
252
253        $.get( "https://pixabay.com/api/?key=2495655-17a65303269e60a85dbeaffe8&" + searchParamsStr, {}, function( response ) {
254            for( key in response.hits) {
255                var hit = response.hits[key];
256                var $el = self.createFileEl( hit )
257                $el.appendTo( $toElement )
258            }
259
260            var pagesCount = Math.ceil( response.totalHits / perPage );
261
262            self.pageNum = pageNum;
263
264            self.pageNumEl.html( pageNum )
265            self.pageCountEl.html( pagesCount )
266            if ( pageNum < pagesCount ) {
267                self.nextPageBtn.show();
268            }
269            else {
270                self.nextPageBtn.hide();
271            }
272            if ( pageNum > 1 ) {
273                self.prevPageBtn.show();
274            } else {
275                self.prevPageBtn.hide();
276            }
277
278			var isoLabel = 'изображений';
279
280			if (typeof Yii != 'undefined') {
281				isoLabel = Yii.t("common", isoLabel);
282			}
283
284			self.resultsCountEl.html(isoLabel + ": " + response.totalHits);
285        })
286    },
287    /*selectFile: function( hash ) {
288        this.options.owner.fileSelected( hash )
289    },*/
290    init: function() {
291        this.loadFiles()
292    }
293} );

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.