1(function($){ 2 3 var PKSFMethods = { 4 5 $allSyncSanfonas : false, 6 7 configure : function configure( data ){ 8 9 // Open first 10 if( data.$.data( 'open-first' ) === 'false' ){ 11 data.openFirst = false; 12 } 13 // Se tudo já foi inicializado 14 data.initialized = false; 15 // Actual style 16 data.actualStyle = false; 17 // Timeout 18 data.timeout = false; 19 // Se está ativado 20 data.enabled = false; 21 // Headers 22 data.$headers = []; 23 // Contents 24 data.$contents = []; 25 // Navigation 26 data.navigation = false; 27 // Speed 28 data.speed = data.$.data( 'speed' ) === undefined ? '400' : data.$.data( 'speed' ); 29 // Sincronize otheres 30 data.syncOthers = data.$.data( 'sync-others' ) === undefined ? false : data.$.data( 'sync-others' ); 31 32 // Ãtems da sanfona 33 data.$items = data.$.find( data.items ); 34 if( !data.$items ){ 35 console.info( 'Sanfona: Não foi encontrado nenhum Ãtem:' + data.items ); 36 return; 37 } 38 // Headers 39 data.$headers = data.$items.find( data.headers ); 40 if( !data.$headers.length ){ 41 console.info( 'Sanfona: Não foi encontrado nenhum header: ' + data.headers ); 42 return; 43 } 44 // Contents 45 data.$contents = data.$items.find( data.contents ); 46 if( !data.$contents.length ){ 47 console.info( 'Sanfona: Não foi encontrado nenhum conteudo: ' + data.contents ); 48 return; 49 } 50 51 // Triggers on mobile 52 data.triggers = data.$.data( 'triggers' ); 53 54 // Associando os headers aos conteúdos 55 data.$items.each(function(i){ 56 57 this.$ = this.$ || $( this ); 58 59 // Header 60 this.header = data.$headers.eq( i ); 61 this.header.get( 0 ).target = data.$items.eq( i ); 62 63 // Content 64 this.content = data.$contents.eq( i ); 65 this.content.get( 0 ).target = data.$items.eq( i ); 66 67 if( data.triggers ){ 68 var _this = this; 69 this.$.on( 'click', '.trigger', function(e){ 70 _this.header.trigger( 'click' ); 71 }); 72 } 73 74 }); 75 76 // Se existem links nos headers 77 data.$headers.on( 'click', 'a', function(event){ 78 79 event.preventDefault(); 80 81 this.$ = this.$ || $( this ); 82 83 // Hash 84 var hash = this.$.attr( 'href' ); 85 if( hash !== undefined && hash !== '' ){ 86 87 if( hash.indexOf( 'http' === 0 ) ){ 88 hash = '#' + hash.split( '#' ).pop(); 89 } 90 91 var $item = $( hash ).attr( 'id', '' ); 92 window.location.hash = hash; 93 $item.attr( 'id', hash ); 94 95 var _referrer = Cookie.get( 'originReferrer' ); 96 97 } 98 99 }); 100 101 // Responsive 102 if( data.breakpoint !== false ){ 103 $( window ).bind( 'resize', function(){ 104 PKSFMethods.resizeBind( data ); 105 }).resize(); 106 } 107 // Static size 108 else { 109 PKSFMethods.enable( data, data.style ); 110 } 111 112 // Abrindo pela URL 113 var $item_to_open = []; 114 if( window.backhash ){ 115 $item_to_open = data.$items.filter( window.backhash ); 116 } 117 else { 118 var _hash = window.location.hash === '' || window.location.hash === '#' || window.location.hash.indexOf( '=' ) > -1 ? false : window.location.hash; 119 if( _hash ){ 120 $item_to_open = data.$items.filter( window.location.hash ); 121 } 122 } 123 if( $item_to_open.length ){ 124 PKSFMethods.toggleItem( data, $item_to_open, true, false ); 125 } 126 127 data.initialized = true; 128 129 }, 130 resize : function resize( data ){ 131 // Viewport 132 var viewport = piki_get_viewport(); 133 // Estilo para aplicar 134 var styleToApply = data.style; 135 // Breakpoint 136 if( viewport.width <= data.breakpoint.width ){ 137 styleToApply = data.breakpoint.style; 138 } 139 // Aplica o estilo, se necessário 140 if( styleToApply !== data.actualStyle ){ 141 if( data.enabled !== true ){ 142 PKSFMethods.enable( data, styleToApply ); 143 } 144 else { 145 PKSFMethods.applyStyle( data, styleToApply ); 146 } 147 } 148 }, 149 enable : function enable( data, style ){ 150 // Main classes 151 data.$.addClass( 'piki-sanfona ' + ( style === undefined ? data.style : style ) ); 152 // Items 153 data.$items.addClass( 'sanfona-item' ); 154 // Headers 155 data.$headers.addClass( 'sanfona-header' ); 156 data.$.on( 'click.pikiSanfona', '.sanfona-header', function( event ){ 157 event.preventDefault(); 158 PKSFMethods.doClick( data, this ); 159 }); 160 // Contents 161 data.$contents.addClass( 'sanfona-content' ); 162 // Status 163 data.enabled = true; 164 // Estilo selecionado 165 PKSFMethods.applyStyle( data, style ); 166 }, 167 disable : function disable( data ){
168 // Main classes 169 data.$.removeClass( 'piki-sanfona ' + data.style ); 170 // Items 171 data.$items.removeClass( 'sanfona-item' ); 172 // Headers 173 $data.$.off( '.pikiSanfona', '.sanfona-header' ); 174 data.$headers.removeClass( 'sanfona-header' ); 175 // Contents 176 data.$contents.show(); 177 data.$contents.removeClass( 'sanfona-content' ); 178 // Status 179 data.enabled = false; 180 }, 181 applyStyle : function applyStyle( data, style ){ 182 183 // Restando a classe 184 data.$.removeClass( 'sanfona abas' ).addClass( style ); 185 186 // Ãtem aberto 187 var $opened = data.$items.filter( '.opened' ); 188 189 // Se o estilo será mudado 190 var styleChanged = false; 191 192 // Abs 193 if( style === 'abas' && data.actualStyle !== 'abas' ){ 194 195 // Fecha todos 196 data.$contents.hide(); 197 198 data.navigation = $( '<ul class="sanfona-controls clear"></ul>' ).prependTo( data.$ ); 199 data.$headers.each(function(x){ 200 var newTab = $( '<li class="x-'+ (x+1) +'"></li>' ).appendTo( data.navigation ); 201 $( this ).appendTo( newTab ); 202 }); 203 204 // Triggers 205 if( data.triggers ){ 206 var $triggers = data.$items.children( '.trigger' ); 207 if( $triggers.length ) $triggers.remove(); 208 } 209 210 data.$.addClass( 'abas' ) 211 data.actualStyle = 'abas'; 212 styleChanged = true; 213 214 } 215 216 // Sanfona 217 else if( style === 'sanfona' && data.actualStyle !== 'sanfona' ){ 218 219 // Esconde os conteúdos 220 data.$contents.hide(); 221 222 // Headers 223 data.$headers.each(function(){ 224 $( this ).prependTo( this.target ); 225 }); 226 227 // Navigation 228 if( data.navigation.length ){ 229 data.navigation.remove(); 230 } 231 232 // Triggers 233 if( data.triggers ){ 234 data.$items.each(function(){ 235 data.trigger = $( '<button class="trigger">'+ data.triggers +'</button>' ).appendTo( this.$ ); 236 }); 237 } 238 239 data.$.addClass( 'sanfona' ); 240 data.actualStyle = 'sanfona'; 241 styleChanged = true; 242 243 } 244 // Se o estilo foi mudado 245 if( styleChanged ){ 246 PKSFMethods.clearClasses( data ); 247 if( $opened.length ){ 248 PKSFMethods.toggleItem( data, $opened, true ); 249 } 250 else if( data.openFirst === true ){ 251 PKSFMethods.toggleItem( data, data.$items.first(), true ); 252 } 253 } 254 // Callback after change style 255 if( data.breakpoint !== undefined && data.breakpoint.callback !== undefined ){ 256 data.breakpoint.callback.call( data._ ); 257 } 258 }, 259 resizeBind : function resizeBind( data ){ 260 clearTimeout( data.timeout ); 261 data.timeout = setTimeout(function(){ 262 data.$.pikiSanfona( 'resize' ); 263 }, 500 ); 264 }, 265 doClick : function doClick( data, clicked ){ 266 var $item = clicked.target; 267 PKSFMethods.toggleItem( data, $item, false, true ); 268 }, 269 toggleItem : function toggleItem( data, $item, stopAnimate, scrollTo ){ 270 271 if( stopAnimate === undefined ){ stopAnimate = false; } 272 if( scrollTo === undefined ){ scrollTo = false; } 273 274 var clicked = $item.get( 0 ); 275 276 var isOpened = $item.is( '.opened' ); 277 278 // Aba já aberta 279 if( data.actualStyle == 'abas' && isOpened === true ) return; 280 281 // Limpa todas as classes 282 PKSFMethods.clearClasses( data ); 283 284 clicked.header.addClass( 'opened' ); 285 clicked.content.addClass( 'opened' ); 286 clicked.header.parent( 'li' ).addClass( 'opened' ); 287 288 if( !isOpened ){ 289 290 $item.addClass( 'opened' ); 291 292 if( stopAnimate === true ){ 293 294 clicked.content.show(); 295 296 if( scrollTo === true ){ 297 var offset = data.actualStyle === 'abas' ? 60 : 0; 298 PKSFMethods.scrollTo( $item, offset ); 299 } 300 301 } 302 else { 303 304 clicked.content.stop( true, true ).show(); 305 PKSFMethods.refreshSlicks( data, $item ); 306 clicked.content.hide(); 307 308 // Animation options 309 var animeOptions = { opacity: 'show', height: 'show', paddingBottom: 'show', paddingTop: 'show' }; 310 311 // Doing 312 clicked.content.stop( true, true ).animate( animeOptions, data.speed, function(){ 313 if( scrollTo === true ){ 314 var offset = data.actualStyle === 'abas' ? 60 : 0; 315 PKSFMethods.scrollTo( $item, offset ); 316 } 317 });
318 319 } 320 321 if( data.triggers ){ 322 $item.children( '.trigger' ).html( 'Fechar' ); 323 } 324 325 } 326 else { 327 328 $item.removeClass( 'opened' ); 329 $item.get(0).header.removeClass( 'opened' ); 330 $item.get(0).content.removeClass( 'opened' ); 331 332 } 333 334 // Fecha os outros 335 PKSFMethods.closeItems( data, data.$items.not( '.opened' ) ); 336 337 // Sync with others sanfonas 338 if( data.syncOthers ){ 339 340 if( PKSFMethods.$allSyncSanfonas === false ){ 341 PKSFMethods.$allSyncSanfonas = $( '.piki-sanfona[data-sync-others="true"]' ); 342 } 343 344 if( PKSFMethods.$allSyncSanfonas.length > 1 ){ 345 346 const $others = PKSFMethods.$allSyncSanfonas.not( data.$ ); 347 $others.each(function(){ 348 349 this.$ = this.$ || $( this ); 350 351 const dataOther = this.$.data( 'pikiSanfona' ); 352 if( dataOther !== undefined ){ 353 354 // Limpa todas as classes 355 PKSFMethods.clearClasses( dataOther ); 356 357 // Fecha os outros 358 PKSFMethods.closeItems( dataOther, dataOther.$items ); 359 360 } 361 362 }); 363 364 } 365 366 } 367 368 }, 369 370 closeItems : function( data, $items ){ 371 372 if( !$items || !$items.length ) return true; 373 374 // Fecha os outros 375 $items.each(function(){ 376 377 this.$ = this.$ || $( this ); 378 379 // Animation options 380 var animeOptions = { opacity: 'hide', height: 'hide', paddingBottom: 'hide', paddingTop: 'hide' }; 381 382 // Doing 383 this.content.stop( true, true ).animate( animeOptions, data.speed ); 384 385 }); 386 387 388 }, 389 390 scrollTo : function scrollTo( $target, offset ){ 391 392 // Offset 393 offset = parseInt( offset ); 394 395 // Espaço 396 const vw = Math.max( document.documentElement.clientWidth || 0, window.innerWidth || 0 ); 397 offset += 16 + ( vw >= 992 ? 92 : 60 ); 398 const postTop = $target.offset().top - offset; 399 400 $( 'html, body' ).css( 'scroll-behavior', 'smooth' ); 401 window.scrollTo( 0, postTop ); 402 403 }, 404 refreshSlicks : function refreshSlicks( data, $parent ){ 405 var $slicks = $( '.slick-slider', $parent ); 406 if( $slicks.length ){ 407 for( var s = 0; s < $slicks.length; s++ ){ 408 var $s = $slicks.eq( s ); 409 if( $s.is( '.slick-initialized' ) ){ 410 $s.slick( 'refresh' ); 411 } 412 } 413 } 414 }, 415 clearClasses : function clearClasses( data ){ 416 data.$items.removeClass( 'opened' ); 417 data.$contents.removeClass( 'opened' ); 418 data.$headers.removeClass( 'opened' ); 419 data.$headers.parent( 'li' ).removeClass( 'opened' ); 420 if( data.triggers ){ 421 data.$items.children( '.trigger' ).html( data.triggers ); 422 } 423 } 424 425 }; 426 427 // Sanfona 428 $.fn.pikiSanfona = function( arg1 ){ 429 430 return this.each(function(){ 431 432 // Jquery object 433 if( this.$ === undefined ){ 434 this.$ = $( this ); 435 } 436 437 // Keeping this 438 var data = this.$.data( 'pikiSanfona' ); 439 440 // Configurando o plugin quando necessário 441 if( arg1 === undefined || typeof arg1 === 'object' ){ 442 443 // Se ainda não foi configurado 444 if( data === undefined ){ 445 446 // Opções padrão 447 var defaults = { 448 items: '.item', 449 headers: '.trigger', 450 contents: '.content', 451 breakpoint : false, 452 effect : 'slide', 453 style : 'sanfona', 454 openFirst : true, 455 columns: 1 456 }; 457 458 if( typeof arg1 === 'object' ){ 459 data = $.extend({}, defaults, arg1 ); 460 } 461 else { 462 data = defaults; 463 } 464 465 data.$ = this.$; 466 data._ = this; 467 data.$.data( 'pikiSanfona', data ); 468 469 PKSFMethods.configure.apply( this, [ data ] ); 470 471 } 472 473 } 474 else if ( PKSFMethods[ arg1 ] ) { 475 476 var otherArgs = Array.prototype.slice.call( arguments, 1 ); 477 Array.prototype.unshift.call( otherArgs, data ); 478 return PKSFMethods[ arg1 ].apply( this, otherArgs ); 479 480 } 481 482 }); 483 484 }; 485 486})(jQuery);
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.