plugin.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require(['gitbook', 'jQuery'], function(gitbook, $) {
  2. var wechatURL;
  3. var alipayURL;
  4. var titleText;
  5. var buttonText;
  6. var wechatText;
  7. var alipayText;
  8. function insertDonateLink() {
  9. if ($('.gitbook-donate').length === 0 && wechatURL !== undefined && (wechatURL !== '' || alipayURL !== '')) {
  10. var html = [
  11. '<div class="gitbook-donate">',
  12. '<div>' + titleText + '</div>',
  13. '<button id="rewardButton" disable="enable" onclick="var qr = document.getElementById(\'QR\'); if (qr.style.display === \'none\') {qr.style.display=\'block\';} else {qr.style.display=\'none\'}">',
  14. '<span>' + buttonText + '</span>',
  15. '</button>',
  16. '<div id="QR" style="display: none;">'
  17. ];
  18. if (wechatURL !== '') {
  19. html = html.concat([
  20. '<div id="wechat" style="display: inline-block">',
  21. '<a href="' + wechatURL + '" class="fancybox" rel="group">',
  22. '<img id="wechat_qr" src="' + wechatURL + '" alt="WeChat Pay"/>',
  23. '</a>',
  24. '<p>' + wechatText + '</p>',
  25. '</div>'
  26. ]);
  27. }
  28. if (alipayURL !== '') {
  29. html = html.concat([
  30. '<div id="alipay" style="display: inline-block">',
  31. '<a href="' + alipayURL+ '" class="fancybox" rel="group">',
  32. '<img id="alipay_qr" src="' + alipayURL + '" alt="Alipay"/>',
  33. '</a>',
  34. '<p>' + alipayText + '</p>', '</div>'
  35. ]);
  36. }
  37. html = html.concat(['</div>', '</div>']);
  38. $('.page-inner section.normal:last').after(html.join(''));
  39. }
  40. }
  41. gitbook.events.bind('start', function(e, config) {
  42. wechatURL = config.donate.wechat || '';
  43. wechatText = config.donate.wechatText || '微信捐赠';
  44. alipayURL = config.donate.alipay || '';
  45. alipayText = config.donate.alipayText || '支付宝捐赠';
  46. titleText = config.donate.title || '';
  47. buttonText = config.donate.button || '赏';
  48. insertDonateLink();
  49. });
  50. gitbook.events.bind('page.change', function() {
  51. insertDonateLink();
  52. });
  53. });