Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

106 lines
3.5KB

  1. gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
  2. var SITES = {
  3. 'github': {
  4. 'label': 'Github',
  5. 'icon': 'fa fa-github',
  6. 'onClick': function(e) {
  7. e.preventDefault();
  8. var repo = $('meta[name="github-repo"]').attr('content');
  9. if (typeof repo === 'undefined') throw("Github repo not defined");
  10. window.open("https://github.com/"+repo);
  11. }
  12. },
  13. 'facebook': {
  14. 'label': 'Facebook',
  15. 'icon': 'fa fa-facebook',
  16. 'onClick': function(e) {
  17. e.preventDefault();
  18. window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(location.href));
  19. }
  20. },
  21. 'twitter': {
  22. 'label': 'Twitter',
  23. 'icon': 'fa fa-twitter',
  24. 'onClick': function(e) {
  25. e.preventDefault();
  26. window.open("http://twitter.com/intent/tweet?text="+document.title+"&url="+encodeURIComponent(location.href)+"&hashtags=rmarkdown,bookdown");
  27. }
  28. },
  29. 'linkedin': {
  30. 'label': 'LinkedIn',
  31. 'icon': 'fa fa-linkedin',
  32. 'onClick': function(e) {
  33. e.preventDefault();
  34. window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
  35. }
  36. },
  37. 'weibo': {
  38. 'label': 'Weibo',
  39. 'icon': 'fa fa-weibo',
  40. 'onClick': function(e) {
  41. e.preventDefault();
  42. window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
  43. }
  44. },
  45. 'instapaper': {
  46. 'label': 'Instapaper',
  47. 'icon': 'fa fa-italic',
  48. 'onClick': function(e) {
  49. e.preventDefault();
  50. window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
  51. }
  52. },
  53. 'vk': {
  54. 'label': 'VK',
  55. 'icon': 'fa fa-vk',
  56. 'onClick': function(e) {
  57. e.preventDefault();
  58. window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
  59. }
  60. }
  61. };
  62. gitbook.events.bind("start", function(e, config) {
  63. var opts = config.sharing;
  64. if (!opts) return;
  65. // Create dropdown menu
  66. var menu = _.chain(opts.all)
  67. .map(function(id) {
  68. var site = SITES[id];
  69. return {
  70. text: site.label,
  71. onClick: site.onClick
  72. };
  73. })
  74. .compact()
  75. .value();
  76. // Create main button with dropdown
  77. if (menu.length > 0) {
  78. gitbook.toolbar.createButton({
  79. icon: 'fa fa-share-alt',
  80. label: 'Share',
  81. position: 'right',
  82. dropdown: [menu]
  83. });
  84. }
  85. // Direct actions to share
  86. _.each(SITES, function(site, sideId) {
  87. if (!opts[sideId]) return;
  88. gitbook.toolbar.createButton({
  89. icon: site.icon,
  90. label: site.label,
  91. title: site.label,
  92. position: 'right',
  93. onClick: site.onClick
  94. });
  95. });
  96. });
  97. });