plugin.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // LICENSE : MIT
  2. "use strict";
  3. require(['gitbook'], function (gitbook) {
  4. function addBeforeHeader(element) {
  5. jQuery('.book-header > h1').before(element);
  6. }
  7. function createButton(_ref) {
  8. var user = _ref.user;
  9. var repo = _ref.repo;
  10. var type = _ref.type;
  11. var size = _ref.size;
  12. var width = _ref.width;
  13. var height = _ref.height;
  14. var count = _ref.count;
  15. var extraParam = type === "watch" ? "&v=2" : "";
  16. return '<a class="btn pull-right hidden-mobile" aria-label="github">\n <iframe\n style="display:inline-block;vertical-align:middle;"\n src="https://ghbtns.com/github-btn.html?user=' + user + '&repo=' + repo + '&type=' + type + '&count=' + count + '&size=' + size + extraParam + '"\n frameborder="0"\n scrolling="0"\n width="' + width + 'px"\n height="' + height + 'px"\n ></iframe>\n </a>';
  17. }
  18. function createUserButton(_ref2) {
  19. var user = _ref2.user;
  20. var size = _ref2.size;
  21. var width = _ref2.width;
  22. var height = _ref2.height;
  23. var count = _ref2.count;
  24. return '<a class="btn pull-right hidden-mobile" aria-label="github">\n <iframe\n style="display:inline-block;vertical-align:middle;"\n src="https://ghbtns.com/github-btn.html?user=' + user + '&type=follow&count=' + count + '&size=' + size + '"\n frameborder="0"\n scrolling="0"\n width="' + width + 'px"\n height="' + height + 'px"\n ></iframe>\n </a>';
  25. }
  26. function insertGitHubLink(button) {
  27. var user = button.user;
  28. var repo = button.repo;
  29. var type = button.type;
  30. var size = button.size;
  31. var width = button.width;
  32. var height = button.height;
  33. var count = button.count;
  34. var size = size || "large";
  35. var width = width || (size === "large" ? "150" : "100");
  36. var height = height || (size === "large" ? "30" : "20");
  37. var count = typeof count === "boolean" ? count : false;
  38. if (type === 'follow') {
  39. var elementString = createUserButton({
  40. user: user,
  41. size: size,
  42. width: width,
  43. height: height,
  44. count: count
  45. });
  46. } else {
  47. var elementString = createButton({
  48. user: user,
  49. repo: repo,
  50. type: type,
  51. size: size,
  52. width: width,
  53. height: height,
  54. count: count
  55. });
  56. }
  57. addBeforeHeader(elementString);
  58. }
  59. function init(config) {
  60. config.buttons.forEach(insertGitHubLink);
  61. }
  62. // injected by html hook
  63. function getPluginConfig() {
  64. return window["gitbook-plugin-github-buttons"];
  65. }
  66. // make sure configuration gets injected
  67. gitbook.events.bind('start', function (e, config) {
  68. window["gitbook-plugin-github-buttons"] = config["github-buttons"];
  69. });
  70. gitbook.events.bind('page.change', function () {
  71. init(getPluginConfig());
  72. });
  73. });
  74. //# sourceMappingURL=plugin.js.map