Created
August 11, 2016 13:34
-
-
Save hugofabricio/15883d23da73cd6cc3c8b1bd6eb6b26d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Common | |
window.mod.common = function() { | |
// Scope | |
var that = this; | |
var init = function() { | |
console.log('[brz] begin common.js'); | |
window.mod.navbar = new window.mod['navbar'](); | |
window.mod.mask = new window.mod['mask'](); | |
window.mod.radio = new window.mod['radio'](); | |
window.mod.player = new window.mod['player'](); | |
initInfiniteScroll(); | |
initShare(); | |
initPjax(); | |
}; | |
var initPjax = function() { | |
new window['pjax-api'].Pjax({ | |
areas: [ | |
'.Main' | |
], | |
link: '.pjax-link', | |
form: '.pjax-form', | |
filter: () => true, | |
rewrite: function (document, area, host) { | |
var newBodyClass = $('body', document).attr('class'); | |
$('body').attr('class', newBodyClass); | |
} | |
}); | |
// Add active class | |
$('.Header a').on('click', function() { | |
if ($(this).hasClass('Navbar-link--radio') == false) { | |
$('.Header .active').removeClass('active'); | |
$(this).addClass('active'); | |
} | |
$('.navbar-offcanvas').trigger('offcanvas.close'); | |
}); | |
$(document).on('pjax:unload', function() { | |
$('.InfiniteScroll').infinitescroll('destroy'); | |
}); | |
$(document).on('pjax:ready', function() { | |
// Get new pageview | |
if (window.ga) { | |
window.ga('send', 'pageview', {page: document.location.pathname, title: document.title}); | |
} | |
window.mod.player = new window.mod['player'](); | |
// Infinite scroll | |
initInfiniteScroll(); | |
// Share links | |
initShare(); | |
// Parse facebook | |
FB.XFBML.parse(); | |
}); | |
}; | |
var initShare = function() { | |
$('.Share-link').click(function (e) { | |
e.preventDefault(); | |
var url, | |
el = $(this), | |
shareUrl = encodeURIComponent(el.data('url')), | |
shareTitle = encodeURIComponent(el.data('title')); | |
if (el.hasClass('Share-link--facebook')) { | |
url = 'https://www.facebook.com/sharer/sharer.php?u=' + shareUrl; | |
} else if (el.hasClass('Share-link--linkedin')) { | |
url = 'https://www.linkedin.com/shareArticle?mini=true&url=' + shareUrl + '&title=' + shareTitle; | |
} else if (el.hasClass('Share-link--twitter')) { | |
url = 'https://twitter.com/intent/tweet?url=' + shareUrl + '&text=' + shareTitle + '&wrap_links=true'; | |
} else if (el.hasClass('Share-link--google')) { | |
url = 'https://plus.google.com/share?url=' + shareUrl; | |
} else if (el.hasClass('Share-link--whatsapp')) { | |
url = 'whatsapp://send?text=' + shareTitle + ' ' + shareUrl; | |
} | |
window.open(url); | |
}); | |
}; | |
var initInfiniteScroll = function() { | |
$('.InfiniteScroll').infinitescroll({ | |
navSelector : 'ul.pagination', | |
nextSelector : 'ul.pagination li:last-child a', | |
itemSelector : '.InfiniteScroll-item', | |
loading: { | |
finished: undefined, | |
finishedMsg: 'Nenhum resultado encontrado.', | |
img: '/assets/images/loading.svg', | |
msg: null, | |
msgText: 'Carregando...', | |
selector: '.InfiniteScroll-loading', | |
speed: 'fast', | |
start: undefined | |
} | |
}); | |
}; | |
init(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment