1"use strict"; 2 3var ria_layout_manager = { 4 init: function(){ 5 var _this = this; 6 7 console.log('ria_layout_manager >>> inited'); 8 9 _this.minHeightViewWidgets = 100; // минималÑÐ½Ð°Ñ Ð²ÑÑоÑа виджеÑов, еÑли менÑÑе Ñо ÑкÑÑваÑÑÑÑ 10 _this.headerToSmall = 300; // ÑÐ°Ð·Ð¼ÐµÑ Ð¿ÑокÑÑÑки до маленÑкого Ñ ÐµÐ´ÐµÑа 11 _this.widgetsSize = false; // вÑÑоÑа облаÑÑи виджеÑов 12 13 // Ñлаг ÑÑо на ÑÑаниÑе вклÑÑен пÑилипаÑÑий Ñ ÐµÐ´ÐµÑ 14 _this.stickedOn = ( $("#body").data('header-sticked-on') && $('#header').length > 0 ) ? true : false; 15 16 _this.isMobile = ( ria && ria.mobileBrowser ) ? ria.mobileBrowser() : false; // Ñлаг ÑÑо мобилÑнÑй бÑаÑÐ·ÐµÑ 17 _this.notPullToReload = 'page-nopulltoreload'; // клаÑÑ Ð½Ð° <html/> Ð´Ð»Ñ Ð·Ð°Ð¿ÑеÑа Push to reload 18 /** акÑивноÑÑÑ ÑоÑÑоÑний */ 19 _this._state = { 20 lenta : false, 21 chat : false, 22 live : false, 23 notPull : false 24 }; 25 /** модиÑикаÑоÑÑ Ð²ÐµÑаÑÑÑÑ Ð½Ð° body */ 26 _this.mod = { 27 hSticked :'m-header-sticked', 28 hSmall : 'm-header-small', 29 hBrand : 'm-header-brand', 30 lenta : 'm-widget-lenta', 31 chat : 'm-widget-chat', 32 live : 'm-widget-live' 33 }; 34 /** клаÑÑÑ Ð´Ð»Ñ Ð¸Ð´ÐµÐ½ÑиÑикаÑии кнопок ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð²Ð¸Ð´Ð¶ÐµÑами */ 35 _this.button = { 36 lenta : 'js__toggle-lenta', 37 chat : 'js__toggle-chat', 38 live : 'js__toggle-live', 39 all: 'js__widgets-close' 40 }; 41 42 /** подклÑÑение history Ð±Ð»Ñ Ð¾Ð±ÑабоÑки оÑкÑÑÑÐ¸Ñ ÐенÑÑ */ 43 if ( !!( window.history && history.pushState && history.replaceState ) ) { 44 _this.historyHandlers(); 45 } 46 47 $( window ).on( 'scroll resize', function () { 48 if ( _this.stickedOn ) _this.headerStatesSwitching(); 49 _this.setWidgetsSize(); 50 }); 51 52 _this.widgetsManager(); 53 54 $( window ).scroll(); 55 56 if ( ( '#header' ).length > 0 ) $( "#body" ).addClass( "m-header-ready" ); 57 58 }, 59 60 historyHandlers : function(){ 61 var _this = this; 62 _this.fromHistory = false; 63 _this.disablePopstate = false; 64 65 /** ÐодпиÑка на ÑÑÐ¸Ð³ÐµÑ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ¸Ñ ÑоÑÑоÑÐ½Ð¸Ñ Ð²Ð¸Ð´Ð¶ÐµÑов */ 66 $( 'body' ).bind( 'widget', function( e, n, s ){ 67 if ('scrollRestoration' in history) { 68 history.scrollRestoration = 'manual'; 69 } 70 71 if ( n == 'lenta' && !_this.fromHistory ){ 72 if ( s == true ){ 73 history.pushState( { 'lenta' : true }, null, location.href ) 74 } else { 75 _this.disablePopstate = true; 76 history.back() 77 } 78 } 79 80 if ( n == 'chat' && !_this.fromHistory ){ 81 if ( s == true ){ 82 history.pushState( { 'chat' : true }, null, location.href ) 83 } else { 84 _this.disablePopstate = true; 85 86 history.back() 87 } 88 } 89 _this.fromHistory = false; 90 91 if ('scrollRestoration' in history) { 92 history.scrollRestoration = 'auto'; 93 } 94 } ); 95 window.addEventListener( "popstate", function( e ) { 96 if ( !_this.disablePopstate ){ 97 _this.fromHistory = true; 98 if ( e.state && e.state.lenta && e.state.lenta === true ) { 99 _this.changeState( 'lenta', true ); 100 } else { 101 _this.changeState( 'lenta', false ); 102 dataLayer.push({ 'block' : 'lenta_widget', 'event' : 'lenta_close_back' }); 103 } 104 105 if ( e.state && e.state.chat && e.state.chat === true ) { 106 _this.changeState( 'chat', true ); 107 } else { 108 _this.changeState( 'chat', false ); 109 dataLayer.push({ 'block' : 'chat_widget', 'event' : 'chat_close_back' }); 110 } 111 } 112 _this.disablePopstate = false;
113 }, false ); 114 }, 115 116 /** ÑпÑавление пÑилипанием Ñ ÐµÐ´ÐµÑа и ÑазмеÑом */ 117 headerStatesSwitching : function(){ 118 var _this = this, 119 $b = $( '#body' ), 120 limit = $( '#header' ).offset().top + ( $b.hasClass( _this.mod.hBrand ) ? $( '#headerHeight' ).outerHeight() : 0 ) ; 121 this.headerStatesCheck( limit, $b.hasClass( _this.mod.hSticked ), _this.mod.hSticked); 122 this.headerStatesCheck( limit + _this.headerToSmall, $b.hasClass( _this.mod.hSmall ), _this.mod.hSmall); 123 }, 124 125 headerStatesCheck : function( limit, flag, cl ){ 126 var st = $( window ).scrollTop(); 127 if ( st > limit && !flag ) { 128 $( '#body' ).addClass( cl ); 129 } else if ( st == 0 || ( st <= limit && flag ) ){ 130 $( '#body' ).removeClass( cl ); 131 } 132 }, 133 134 /** вÑÑÑавление вÑÑоÑÑ Ð·Ð¾Ð½Ñ Ñ Ð²Ð¸Ð´Ð¶ÐµÑами */ 135 setWidgetsSize: function(){ 136 var _this = this, 137 widgetsHeight = '100%', 138 $headerHeight = $( '#headerHeight' ); 139 140 141 //console.log( this.getClientWidth() , ' ', $( window ).scrollTop(), " ", $headerHeight.offset().top) 142 143 if ( this.getClientWidth() > 767 && $( window ).scrollTop() < $headerHeight.offset().top ) { 144 widgetsHeight = _this.getViewHeight() - $headerHeight[ 0 ].getBoundingClientRect().top; 145 } 146 147 //console.log('_this.widgetsSize = '+_this.widgetsSize+' $headerHeight = '+ $headerHeight[ 0 ].getBoundingClientRect().top + ' widgetsHeight = '+widgetsHeight); 148 149 if ( _this.widgetsSize != widgetsHeight ) { 150 if ( widgetsHeight < _this.minHeightViewWidgets ) widgetsHeight = 0; 151 $( '#widgetsSize' ).height( widgetsHeight ); 152 _this.widgetsSize = widgetsHeight; 153 } 154 }, 155 156 widgetsManager: function(){ 157 var _this = this, 158 $body = $( 'body' ), 159 _s = _this._state; 160 161 $( window ).on( 'resize', function () { 162 var clientWidth = _this.getClientWidth(); 163 /** закÑÑваем виджеÑÑ ÑаÑа или лайв ÑÑанÑлÑÑии, еÑли оÑкÑÑÑа ленÑа */ 164 if ( _s.lenta && clientWidth < 768 && ( _s.chat || _s.live ) ) { 165 _this.changeState({ 166 'chat': false, 167 'live': false 168 }); 169 } 170 if ( ( _s.lenta || _s.live || _s.chat ) && !$('#modalLayer').hasClass('m-open') ) { 171 ria.disablePageScroll( clientWidth >= 768 ? false : true ); 172 } 173 }); 174 175 /** click по body закÑÑÐ²Ð°ÐµÑ Ð»ÐµÐ½ÑÑ Ð¿Ñи ÑазÑеÑении более 768 */ 176 $body.on( 'click', function(){ 177 if ( _this.getClientWidth() >= 768 && _this._state.lenta ) { 178 _this.changeState( 'lenta', false ); 179 } 180 }); 181 182 $( '#widgetBottom' ).on( 'click', function( e ){ 183 if ( _this._state.lenta ) { 184 e.stopPropagation(); 185 }; 186 }); 187 188 $( '.'+_this.button.live ).on( 'click', function(e){ 189 e.stopPropagation(); 190 e.preventDefault(); 191 if ( _this._state.live ) { 192 _this._state.lenta ? _this.changeState( 'lenta', false ) : _this.changeState( 'live', false ); 193 } else { 194 _this.changeState({ 195 'lenta': false, 196 'chat': false, 197 'live': true 198 }); 199 } 200 }); 201 202 $( '.'+_this.button.chat ).on( 'click', function( e ){ 203 e.stopPropagation(); 204 e.preventDefault(); 205 if ( _this._state.chat ) { 206 _this._state.lenta ? _this.changeState( 'lenta', false ) : _this.changeState( 'chat', false ); 207 } else { 208 _this.changeState({ 209 'lenta': false, 210 'chat': true, 211 'live': false 212 }); 213 } 214 }); 215 216 $( '.'+_this.button.lenta ).on( 'click', function( e ){ 217 e.stopPropagation(); 218 e.preventDefault(); 219 _this._state.lenta ? _this.changeState( 'lenta', false ) : _this.changeState( 'lenta', true ); 220 }); 221 222 $( '.'+_this.button.all ).on( 'click', function( e ){ 223 e.stopPropagation(); 224 e.preventDefault(); 225 _this.changeState({ 226 'lenta': false, 227 'chat': false, 228 'live': false 229 }); 230 }); 231 232 }, 233 234 /** ÐÑклÑÑение pull to reload поÑÑедÑÑвом html { overflow:hidden } пÑи оÑкÑÑÑии ÑаÑа 235 * #RIA2018-755 236 * ÑÑало не нÑжнÑм вÑвÑзи Ñ Ð¾Ð±Ð½Ð¾Ð²Ð¾Ð¹ Ð¥Ñома - оÑÑавили пÑÐ¾Ð·Ð°Ð¿Ð°Ñ */ 237 disablePullToReload: function( allow ){ 238 if ( this.isMobile && ( allow === true || this._state.lenta || this._state.chat || this._state.live ) && this.getClientWidth() < 768 ){ 239 $( 'html' ).addClass( this.notPullToReload ); 240 this._state.notPull = true; 241 } else if ( allow === false || ( !this._state.lenta || !this._state.chat || !this._state.live ) ){ 242 $( 'html' ).removeClass( this.notPullToReload ); 243 this._state.notPull = false;
244 } 245 }, 246 247 changeState: function( n, s ) { 248 var _this = this; 249 if ( $.isPlainObject( n ) || ( typeof n == "string" && typeof s == "boolean" ) ) { 250 var is_state = false, 251 obj = {}; 252 if ( $.isPlainObject( n ) ) { 253 obj = n; 254 } else { 255 obj[n] = s; 256 } 257 $.each( obj , function( k, v ){ 258 if ( _this._state[ k ] != v ) _this.setState( k, v ); 259 if ( v ) is_state = true; 260 }); 261 262 if ( _this.getClientWidth() < 768 ) ria.disablePageScroll( is_state ); 263 } else { 264 return false 265 } 266 /*TODO test */ //console.log(_this._state); 267 }, 268 269 setState: function( n, s ){ 270 var _this = this; 271 if ( typeof n == "string" && typeof s == "boolean") { 272 if ( s ) { 273 _this._state[ n ] = true; 274 $( 'body' ).addClass( _this.mod[ n ] ); 275 } else { 276 _this._state[ n ] = false; 277 $( 'body' ).removeClass( _this.mod[ n ] ); 278 } 279 $( 'body' ).trigger( 'widget', [ n, s ] ); 280 } else { 281 return false; 282 } 283 }, 284 285 /** 286 * полÑÑение ÑиÑÐ¸Ð½Ñ ÐºÐ¾Ð½ÑенÑной облаÑÑи клиенÑа 287 * @returns {Number} size 288 */ 289 getViewWidth: function(){ 290 var $viewSize = $('#jsViewSize'); 291 return $viewSize.length > 0 ? parseInt($viewSize.width()) : this.getClientWidth(); 292 }, 293 /** 294 * полÑÑение вÑÑоÑÑ ÐºÐ¾Ð½ÑенÑной облаÑÑи клиенÑа 295 * @returns {Number} size 296 */ 297 getViewHeight: function(){ 298 var $viewSize = $('#jsViewSize'); 299 return $viewSize.length > 0 ? parseInt($viewSize.height()) : this.getClientHeigth(); 300 }, 301 /** 302 * полÑÑение ÑиÑÐ¸Ð½Ñ Ð¾ÐºÐ½Ð° клиенÑа 303 * @returns {Number} size 304 */ 305 getClientWidth: function(){ 306 return Math.max(window.innerWidth || 0, (document.getElementsByTagName('html')[0] || {}).clientWidth || 0) 307 }, 308 /** 309 * полÑÑение вÑÑоÑÑ Ð¾ÐºÐ½Ð° клиенÑа 310 * @returns {Number} size 311 */ 312 getClientHeigth: function(){ 313 return Math.max(window.innerHeight || 0, (document.getElementsByTagName('html')[0] || {}).clientHeight || 0) 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
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.