1 2//Using an object literal for a jQuery feature 3var multipage = { 4 init: function( settings ) { 5 multipage.config = { 6 url : null, 7 relUrl : null, 8 lang : 'pl/', 9 curUrl : '', 10 lock : 0, 11 menu : 1, 12 snap : 0, 13 offset : 120, 14 ready : 0, 15 menuSelector : "#nav-multipage a, .navbar a", 16 navSelector : '#nav-multipage' 17 }; 18 //allow overriding the default config 19 $.extend( multipage.config, settings ); 20 21 multipage.setup(); 22 23 $( window ).resize( multipage.resize ); 24 $( window ).scroll( multipage.scroll ); 25 26 if( !multipage.config.snap ) 27 setInterval( function() { multipage.scroll( 'timer' ) } , 1000 ); 28 }, 29 setup: function() { 30 multipage.initMultipage(); 31 }, 32 resize: function() { 33 multipage.scroll( 'timer' ); 34 }, 35 scroll: function( opt ) { 36 37 if( multipage.config.lock || multipage.config.snap ) return; 38 39 var loadOffset = multipage.config.offset+10; 40 var pageOffset = 100; 41 var limitTop = $(document).scrollTop(); 42 var limitBottom = $(document).scrollTop() + $( window ).height(); 43 var position, height, value; 44 45 $( 'section' ).each( function( id, el ) { 46 47 if( !multipage.config.menu ){ 48 position = $(el).position(); 49 height = $(el).height(); 50 value = $(el).data('url'); 51 posTop = position.top; 52 posBottom = position.top + height; 53 54 if( posTop - pageOffset <= limitTop && posBottom - pageOffset >= limitTop ){ 55 multipage.changeAddress( value ); 56 } 57 } 58 59 if( !$(el).hasClass('loaded') ){ 60 61 if( multipage.config.menu ){ 62 position = $(el).position(); 63 height = $(el).height(); 64 value = $(el).data('url'); 65 posTop = position.top; 66 posBottom = position.top + height; 67 } 68 69 //scroll up 70 if( posTop - loadOffset <= limitTop && posBottom - loadOffset >= limitTop ){ 71 if( opt=='timer' ) multipage.showPage( value, 0 );//scrollOnce 72 else multipage.showPage( value, 'scrollOnce' );//scrollOnce 73 } 74 75 //scroll down 76 else if( posBottom + loadOffset >= limitBottom && posTop + loadOffset <= limitBottom ){ 77 multipage.showPage( value, 0 ); 78 } 79 80 //scroll inside 81 else if( posTop >= limitTop && posBottom <= limitBottom ){ 82 multipage.showPage( value, 0 ); 83 } 84 85 } 86 }); 87 }, 88 89 validateLink: function( el ) { 90 91 var href = jQuery( el ).attr( 'href' ).replace( '#', '' ); 92 if( !href || jQuery( el ).attr( 'href' ).length < 1 ) 93 return 0; 94 95 if( href.indexOf('captcha') > 0 ) 96 return 0; 97 98 if( href.indexOf('ajax') > 0 ) 99 return 0; 100 101 if( href.indexOf('ajax') > 0 ) 102 return 0; 103 104 if( href.indexOf('.jpg') > 0 ) 105 return 0; 106 107 if( href.indexOf('.png') > 0 ) 108 return 0; 109 110 if( href.indexOf('.gif') > 0 ) 111 return 0; 112 113 return 1; 114 }, 115 116 prepareSectionName: function( name ) { 117 118 if( !name || name=='' ) return name; 119 120 name = name.replace( multipage.config.url, '').replace( multipage.config.lang, '' ).replace( document.location.hash, '' ).replace( '#', '' ).replace( /[^A-Za-z0-9\-]+/g, "" ); 121 122 return name; 123 }, 124 125 initMultipage: function() { 126 127 $('body').addClass('enable_multipage'); 128 //handle history 129 if ( !$('html').hasClass('no-history') ) { 130 $.address.state( multipage.config.url ).init(function(event) {}) 131 } 132 else{ 133 $.address.state( multipage.config.relUrl ).init(function(event) {}) 134 } 135 $.address.externalChange( multipage.onChangeAddress ); 136 137 $('[data-spy="scroll"]').each(function () { 138 var $spy = $(this); 139 $spy.scrollspy($spy.data()) 140 }); 141 142 multipage.initClicks(); 143 144 multipage.initNavigation(); 145 146 multipage.initDocument(); 147 148 if( multipage.config.snap ){ 149 multipage.initSnap();
150 } 151 }, 152 153 154 initDocument: function() { 155 156 hashView = multipage.prepareSectionName( document.location.hash ); 157 158 if( hashView && jQuery( 'section[name=' + hashView + ']' ).length ){ 159 //initialView = multipage.prepareSectionName( document.location.hash ); 160 document.location.href = multipage.config.url + multipage.config.lang + hashView; 161 } 162 else{ 163 var initialView = document.location.href.replace( multipage.config.url, '' ); 164 if( initialView.indexOf( '?' ) > -1 ) 165 initialView = initialView.substr( 0, initialView.indexOf( '?' ) ); 166 if( initialView.indexOf( '/p/' ) > -1 ) 167 initialView = initialView.substr( 0, initialView.indexOf( '/p/' ) ); 168 if( initialView.indexOf( '/id/' ) > -1 ) 169 initialView = initialView.substr( 0, initialView.indexOf( '/id/' ) ); 170 if( initialView.indexOf( '/sort/' ) > -1 ) 171 initialView = initialView.substr( 0, initialView.indexOf( '/sort/' ) ); 172 if( initialView.indexOf( '/date/' ) > -1 ) 173 initialView = initialView.substr( 0, initialView.indexOf( '/date/' ) ); 174 if( initialView.indexOf( '/type/' ) > -1 ) 175 initialView = initialView.substr( 0, initialView.indexOf( '/type/' ) ); 176 if( initialView.indexOf( '/desc/' ) > -1 ) 177 initialView = initialView.substr( 0, initialView.indexOf( '/desc/' ) ); 178 if( initialView.indexOf( '/asc/' ) > -1 ) 179 initialView = initialView.substr( 0, initialView.indexOf( '/asc/' ) ); 180 if( initialView.indexOf( '/lang/' ) > -1 ) 181 initialView = initialView.substr( 0, initialView.indexOf( '/lang/' ) ); 182 183 initialView = multipage.prepareSectionName( initialView ); 184 } 185 186 187 188 if(!initialView.length){ 189 initialView = 'no-initial-section'; 190 } 191 192 if( !jQuery( 'section[name=' + initialView + ']' ).length){ 193 initialView = jQuery( 'section' ).eq(0).data('url'); 194 multipage.showPage( initialView, 'stay' ); 195 } 196 else{ 197 multipage.showPage( initialView, 'move' ); 198 } 199 200 setTimeout( function() { 201 multipage.config.ready = 1; 202 }, 100); 203 }, 204 205 206 initClicks: function() { 207 208 //prevent default click - nav 209 jQuery(multipage.config.menuSelector).click( function( e ) { 210 211 if( !multipage.validateLink( this ) ) 212 return; 213 214 var value = multipage.prepareSectionName( jQuery( this ).data( 'url' ) ); 215 216 if( jQuery( 'section[name=' + value + ']' ).length ){ 217 e.preventDefault(); 218 multipage.config.lock = 0; 219 multipage.showPage( value, 'scroll' ); 220 221 if( !multipage.config.menu ) multipage.changeAddress( value ); 222 } 223 }); 224 225 //prevent default click - sections 226 jQuery( 'section a' ).live("click", function(e){ 227 228 if( !multipage.validateLink( this ) ) 229 return; 230 231 var value = multipage.prepareSectionName( jQuery( this ).attr( 'href' ) ); 232 233 if( jQuery( 'section[name=' + value + ']' ).length ){ 234 e.preventDefault(); 235 multipage.config.lock = 0; 236 multipage.showPage( value, 'scroll' ); 237 238 if( !multipage.config.menu ) multipage.changeAddress( value ); 239 } 240 241 }); 242 }, 243 244 initNavigation: function() { 245 246 247 //handle nav activation - scrollspy 248 $(window).on('activate.bs.scrollspy', function( e, el ) { 249 250 var relatedTarget = $(multipage.config.navSelector); 251 252 if( $(relatedTarget).find('a.active') && $(relatedTarget).find('a.active').data('url') ) { 253 url = $(relatedTarget).find('a').data('url'); 254 } 255 if( $(relatedTarget).find('a.active') && $(relatedTarget).find('a.active').data('url') ) { 256 url = $(relatedTarget).find('a.active').eq(-1).data('url'); 257 } 258 url = multipage.prepareSectionName( url ); 259 260 if( multipage.config.menu ){ 261 multipage.changeAddress( url ); 262 } 263 }); 264 }, 265 266 changeAddress: function( url ) { 267 268 pageUrl = multipage.config.lang+url; 269 if( !url || pageUrl == multipage.config.curUrl ) return; 270 271 multipage.config.curUrl = pageUrl; 272 if( $.address.value().indexOf( pageUrl ) < 0 && !$("section[data-url="+url+"]").hasClass('one-page-content') && !$("section[data-url="+url+"]").hasClass('no-loading')){ 273 274 $.address.value( pageUrl ); 275 // $.address.title( $("section[data-url="+url+"]").data('name') ); 276 } 277 }, 278 279 onChangeAddress: function( data ) { 280 281 url = data.pathNames[data.pathNames.length-1]; 282 multipage.scrollTo( url ); 283 }, 284 285 showPage: function( pageUrl, mod ) { 286 287 pageUrl = multipage.prepareSectionName( pageUrl ); 288 var elemSelector = "section[data-url="+pageUrl+"]"; 289 290 if( multipage.config.lock || typeof(pageUrl)=='undefined' ) return; 291 292 multipage.config.lock = 1; 293 setTimeout( function() { multipage.config.lock = 0 }, 750); 294 295 if( mod=='scroll' ) { 296 multipage.scrollTo( pageUrl ); 297 } 298 if( mod=='move' ){ 299 multipage.moveTo( pageUrl ); 300 return; 301 } 302 if( mod=='stay' ){ 303 multipage.config.lock = 0; 304 } 305 306 if( !$(elemSelector).hasClass('loaded') && !$(elemSelector).hasClass('waiting') ){ 307 308 $(elemSelector).addClass('waiting'); 309 var heightPrev = $(elemSelector).height(); 310 var scrollPrev = $(document).scrollTop(); 311 312 $.ajaxSetup({'cache':true}); 313 $.ajax({
314 url: multipage.config.url+'ajax/'+multipage.config.lang+pageUrl 315 }) 316 .done( function ( data ) { 317 318 $(elemSelector).addClass('loaded'); 319 $(elemSelector).removeClass('waiting'); 320 $(elemSelector).removeClass('loading'); 321 $(elemSelector).html( '<div class="loader"></div>'+data); 322 //$(elemSelector).find('.loader').css('height', $(window).height() ); 323 324 multipage.initScrollSpy(); 325 setTimeout( function() { multipage.initScrollSpy(); }, 500); 326 multipage.initFitImage( elemSelector + " .image-fit" ); 327 //website.initLazyLoad( elemSelector+" img.lazy" ); 328 //$( elemSelector+" img.lazy" ).filter(":in-viewport").trigger('scroll'); 329 website.setup( elemSelector ); 330 setTimeout( function() { 331 website.initLazyLoad( elemSelector+" img.lazy" ); 332 $( elemSelector+" img.lazy" ).filter(":in-viewport").trigger('scroll'); 333 }, 500); 334 335 $(elemSelector+' .loader').fadeOut(750); 336 337 if( mod=='scrollOnce' ) { 338 $(document).scrollTop( $(document).scrollTop() + $(elemSelector).height() - heightPrev - 50 ); 339 } 340 341 if( typeof ga === "function" && typeof ga.getAll === "function" ){ 342 tracker = ga.getAll()[0]; 343 tracker.send('pageview', { 344 'page': multipage.config.lang+pageUrl, 345 'title': $(elemSelector).data('name') 346 }); 347 } 348 else if( typeof ga === 'function' ){ 349 ga('send', 'pageview', { 350 'page': multipage.config.lang+pageUrl, 351 'title': $(elemSelector).data('name') 352 }); 353 } 354 }) 355 .fail( function( jqXHR, textStatus, errorThrown ) { 356 $(elemSelector).removeClass('loaded'); 357 $(elemSelector).removeClass('waiting'); 358 $(elemSelector).addClass('loading'); 359 }) 360 ; 361 } 362 363 }, 364 365 scrollTo: function( obj ) { 366 367 if( !multipage.config.ready ) 368 return; 369 370 obj = multipage.prepareSectionName( obj ); 371 372 if( jQuery( 'section[name=' + obj + ']' ).length ) { 373 if( multipage.config.snap ){ 374 var index = $('section').index( $('section[name=' + obj + ']') ); 375 $.fn.fullpage.moveTo( index+1 ); 376 } else { 377 var offset = 0; 378 if( jQuery( 'section[name=' + obj + ']' ).data('url') != jQuery( 'section:first-of-type' ).data('url') ) 379 offset = jQuery( 'section[name=' + obj + ']' ).offset().top - multipage.config.offset; //- 80 380 381 if(offset && multipage.config.mobile) 382 offset -= $('.menu-holder').height(); 383 384 jQuery( 'html, body' ) 385 .stop(true,false) 386 .animate( { scrollTop : offset }, 500, 'easeInOutExpo', function() { 387 388 setTimeout( function() { 389 multipage.config.lock = 0; 390 }, 100); 391 } ); 392 } 393 } 394 }, 395 396 moveTo: function( obj ) { 397 398 obj = multipage.prepareSectionName( obj ); 399 400 if( jQuery( 'section[name=' + obj + ']' ).length ) { 401 if(multipage.config.snap) { 402 var index = $('section').index( $('section[name=' + obj + ']') ); 403 if(!!($.fn.fullpage.silentMoveTo && $.fn.fullpage.silentMoveTo.constructor && $.fn.fullpage.silentMoveTo.call && $.fn.fullpage.silentMoveTo.apply)) 404 $.fn.fullpage.silentMoveTo( index+1 ); 405 } else { 406 var offset = 0; 407 if( jQuery( 'section[name=' + obj + ']').data('url') != jQuery( 'section:first-of-type' ).data('url') ) 408 offset = jQuery( 'section[name=' + obj + ']' ).offset().top - multipage.config.offset; 409 410 if(offset && multipage.config.mobile) 411 offset -= $('.menu-holder').height(); 412 413 jQuery( 'html, body' )
414 .stop(true,false) 415 .animate( { scrollTop : offset }, 0, 'easeInOutExpo', function() { 416 setTimeout( function() { 417 multipage.config.lock = 0; 418 }, 500); 419 } ); 420 } 421 422 } 423 }, 424 425 //Init all lazy images based on .lazy class 426 initScrollSpy: function() { 427 428 if( $('[data-spy="scroll"]')!=null && $('[data-spy="scroll"]').length > 0 ){ 429 $('[data-spy="scroll"]').each(function () { 430 var $spy = $(this).scrollspy('refresh'); 431 }); 432 } 433 }, 434 435 //Init all fancy box galleries based on rel=lightbox-gallery 436 initFitImage: function( obj ) { 437 $(obj).each(function( id, el ) { 438 website.fitImage( $(el), $(el).find('img') ); 439 }); 440 }, 441 442 initSnap: function( ) { 443 //$.fn.fullpage.destroy(); 444 $('#multipage').fullpage({ 445 scrollingSpeed: 500, 446 sectionSelector: 'section', 447 scrollBar: true, 448 //autoScrolling: false, 449 //fitToSectionDelay: 1000, 450 onLeave: function(index, nextIndex, direction){ 451 452 var url = $('section').eq(nextIndex-1).data('url'); 453 454 if( url ){ 455 multipage.changeAddress( url ); 456 multipage.showPage( url, 'stay' ); 457 } 458 459 multipage.initFlip(index, nextIndex, direction); 460 } 461 }); 462 463 464 setTimeout( function() { 465 var url = $('section').filter('.loaded').data('url'); 466 multipage.moveTo( url ); 467 }, 100); 468 }, 469 470 initFlip: function( index, nextIndex, direction ) { 471 472 473 if ( direction == 'down' ) { 474 $('.s'+index).find('.flipbox').addClass('active'); 475 } 476 if ( direction == 'up' ) { 477 $('.s'+nextIndex).find('.flipbox').removeClass('active'); 478 } 479 } 480 481};
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.