PageSourceSearch

https://cdnn.1prime.ru//js/libs/ria.get.banners.js

js 1prime.ru collected 2026-09-24 08:27:01 UTC 6,677 bytes, 149 lines download raw bytes

1"use strict";
2
3/**
4 *  Параметы тестирования баненров
5 *  enabled [ true / false ]  - тестирование включено / выключено
6 *  name - имя тестирвоания для выставления нужного варианта через параметр урла
7 *  cookies [ true / false / 'text' ] - записывать вариант в куку и фиксирвоать для пользователя true - имя куки name, 'text' - иное имя куки, false - каждый показ высчитывается новый вариант
8 *  variants : {} - значения выставляются как отношение одного к другому или цифры проценты
9 *      1 / 1 / 1 - значит все варианты равнозначны, эквивалентно 33.33 / 33.33 / 33.33
10 *      1 / 2 / 1 - вариант b больше в 2 раза чем a и b, эквивалентно 25 / 50 / 25
11 *
12* */
13
14$(function() {
15
16    var getBanners = function( element, options ){
17
18        var	defaults = {
19            loadingCounter : 0,
20            loadingCount : 3,
21            loadingTimeout : 2000,
22            loadingUrl: '/services/banners/get/',
23            loadingParams: [ 'type', 'id', 'adfox_name', 'adfox_value', 'adfox_pk' ],           // параметры которые ищутся в opitons
24            sendingParams: [ 'banners_list', 'test-banners', 'show-banners', 'hide-banners' ],  // параметры из урла страницы
25            filter: false
26        };
27
28        this.defOptions = defaults;
29        this.userOptions = options;
30        this.options = $.extend( true, {}, defaults, options );
31
32        this.$element = $( element );
33
34        this.getUrl();
35
36        //console.log( '### getBanners ###   $element = ', this.$element );
37        //console.log( '### getBanners ###   options = ', this.options );
38        //console.log( '### getBanners ###   loadingUrl = ', this.loadingUrl );
39
40        this.getData();
41
42    };
43
44    getBanners.prototype.getUrl = function(){
45        var _this = this,
46            c = 0;
47        _this.loadingUrl = _this.options.loadingUrl;
48
49        // проверка наличия параметров в options и добавление в урл запроса баннеров
50        $.each( _this.options.loadingParams, function( i, v ){
51            if ( _this.options[ v ] ) _this.loadingUrl += ( ( c++ ? '&' : '?' ) + v + '=' + _this.options[ v ] );
52        });
53
54        // проверка параметров в урле страницы и добавление нужных в урл запроса баннеров
55        $.each( window.location.search.replace( '?', '' ).split( '&' ), function( i, v ){
56            // имя параметра урла страницы для проверки
57            let paramName = v.split( '=' )[ 0 ].replace( '[]', '' );
58            // параметры из урла страницы
59            if ( _this.options.sendingParams.indexOf( paramName ) >= 0 ) _this.loadingUrl += ( ( c++ ? '&' : '?' ) + v );
60        })
61
62    };
63
64    getBanners.prototype.getData = function(){
65        var _this = this;
66        $.ajax({
67            url: _this.loadingUrl,
68            dataType: 'html',
69            type: 'GET',
70            success: function ( data ) {
71                _this.$data = $( data );
72                _this.successData();
73            },
74            error: function (){
75                if ( _this.options.loadingCounter < _this.options.loadingCount ){
76                    setTimeout( _this.getData() , _this.options.loadingTimeout );
77                    _this.options.loadingCounter++;
78                } else {
79                    _this.errorData();
80                }
81            }
82        });
83    };
84
85    getBanners.prototype.successData = function(){
86        var _this = this;
87        //console.log( '### getBanners ### SUCCESS GetData - URL = ' + _this.loadingUrl );
88        //console.log( _this.$data );
89        _this.pushBanners();
90    };
91
92    getBanners.prototype.errorData = function(){
93        var _this = this;
94        console.log( '--- getBanners ERROR GetData --- ' + _this.loadingUrl );
95    };
96
97    getBanners.prototype.pushBanners = function(){
98        /* data-hide-banners - помечаются места где загружена заглушка для показа места */
99        /* data-banner-inserted - место в которое уже вставлен баннер */
100        if ( this.$data ) {
101            var _this = this,
102                $banners = $( '.banner[data-position]:not([data-hide-banners]):not([data-banner-inserted])', _this.$element );
103
104            if ( typeof _this.options.filter == 'function' ){
105                $banners = $banners.filter( _this.options.filter );
106            }
107
108                //var allPosition = "";
109                //$banners.each(function(){ allPosition += ' ' + $(this).data('position')});
110                //console.log( '<<< all banners position ', $(_this.$data).data('article-id') || '' , '>>>' );
111                //console.log( allPosition );
112
113            $banners.each( function () {
114                var $bannerPlace = $( this ),
115                    position = $bannerPlace.data('position'),
116                    $bannerContent = $( '.banner__content', $bannerPlace ),
117                    $dynamicBanner = $( 'div[data-position=' + position + ']', _this.$data );
118
119                //console.log( ' <<< ', position ,' >>> ' )
120                //console.log( ' --- place ', $bannerContent[0] )
121                //console.log( ' --- banner ', $dynamicBanner[0] )
122
123                if ( $bannerContent.html() == '' ) {
124                    //console.log( '### getBanners ### ' + position + ' => EMPTY => ADDED BANNER' ); //TODO DELETE AFTER TEST DYNAMIC BANNERS
125                    $bannerContent.append( $dynamicBanner.html() );
126                    $bannerPlace.attr( 'data-banner-inserted', 1 );
127                } else {
128                    //console.log( '### getBanners ### ' + position + ' => FULL' ); //TODO DELETE AFTER TEST DYNAMIC BANNERS
129                }
130            })
131        }
132
133        var event = document.createEvent('Event');
134        event.initEvent('pushbanners', true, true);
135        document.body.dispatchEvent(event);
136    };
137
138    $.fn.getBanners = function( options ) {
139        return this.each( function(){
140            var instance = $.data( this, 'getBanners' );
141            if ( !instance ){
142                instance = new getBanners( this, options );
143                $.data( this, 'getBanners', instance );
144            }
145        });
146    };
147
148
149});

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.