$(function() { 'use strict'; window.getLocale = function () { if (!localStorage) { return 'en'; } if (location.search === '?locale=zh') { localStorage.locale = 'zh'; } return localStorage.locale; }; function main() { $(window).scroll(showGotoTop); $(window).resize(showGotoTop); $('.goto-top').click(function() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; return false; }); initLocale(); initScrollspy(); showGotoTop(); showBaiduShare(); $('#bulletin').bulletin(); } function initLocale() { var $locale = $('#locale'); if (!localStorage) { $locale.hide(); return; } if (getLocale() === 'zh') { $locale.find('.language').text('简体中文').end() .find('[data-locale="en"]').removeClass('active').end() .find('[data-locale="zh"]').addClass('active').end() .find('.dropdown-toggle img').removeClass('flag-en').end() .find('.dropdown-toggle img').addClass('flag-zh').end(); $('[data-zh]').each(function () { $(this).html($(this).data('zh')); }); } $('[data-locale]').click(function () { localStorage.locale = $(this).data('locale'); location.reload(true); }); } function initScrollspy() { var $window = $(window), $body = $(document.body), html = []; $('.page-header').find('h1, h2').each(function (i) { var $this = $(this), parent = $this.is('h1'), link = '' + $.trim($this.text()) + ''; if (parent) { if (i > 0) { html.push(''); } html.push('