Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

plugin-sharing.js 3.7KB

il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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?s=100&p[url]="+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/home?status="+encodeURIComponent(document.title+" "+location.href));
  27. }
  28. },
  29. 'google': {
  30. 'label': 'Google+',
  31. 'icon': 'fa fa-google-plus',
  32. 'onClick': function(e) {
  33. e.preventDefault();
  34. window.open("https://plus.google.com/share?url="+encodeURIComponent(location.href));
  35. }
  36. },
  37. 'linkedin': {
  38. 'label': 'LinkedIn',
  39. 'icon': 'fa fa-linkedin',
  40. 'onClick': function(e) {
  41. e.preventDefault();
  42. window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
  43. }
  44. },
  45. 'weibo': {
  46. 'label': 'Weibo',
  47. 'icon': 'fa fa-weibo',
  48. 'onClick': function(e) {
  49. e.preventDefault();
  50. window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
  51. }
  52. },
  53. 'instapaper': {
  54. 'label': 'Instapaper',
  55. 'icon': 'fa fa-instapaper',
  56. 'onClick': function(e) {
  57. e.preventDefault();
  58. window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
  59. }
  60. },
  61. 'vk': {
  62. 'label': 'VK',
  63. 'icon': 'fa fa-vk',
  64. 'onClick': function(e) {
  65. e.preventDefault();
  66. window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
  67. }
  68. }
  69. };
  70. gitbook.events.bind("start", function(e, config) {
  71. var opts = config.sharing;
  72. if (!opts) return;
  73. // Create dropdown menu
  74. var menu = _.chain(opts.all)
  75. .map(function(id) {
  76. var site = SITES[id];
  77. return {
  78. text: site.label,
  79. onClick: site.onClick
  80. };
  81. })
  82. .compact()
  83. .value();
  84. // Create main button with dropdown
  85. if (menu.length > 0) {
  86. gitbook.toolbar.createButton({
  87. icon: 'fa fa-share-alt',
  88. label: 'Share',
  89. position: 'right',
  90. dropdown: [menu]
  91. });
  92. }
  93. // Direct actions to share
  94. _.each(SITES, function(site, sideId) {
  95. if (!opts[sideId]) return;
  96. gitbook.toolbar.createButton({
  97. icon: site.icon,
  98. label: site.label,
  99. title: site.label,
  100. position: 'right',
  101. onClick: site.onClick
  102. });
  103. });
  104. });
  105. });