plugin.js 859 B

123456789101112131415161718192021222324252627282930
  1. require(["gitbook", "jQuery"], function(gitbook, $) {
  2. gitbook.events.bind('start', function (e, config) {
  3. var conf = config['edit-link'];
  4. var label = conf.label;
  5. var base = conf.base;
  6. var lang = gitbook.state.innerLanguage;
  7. if (lang) {
  8. // label can be a unique string for multi-languages site
  9. if (typeof label === 'object') label = label[lang];
  10. lang = lang + '/';
  11. }
  12. // Add slash at the end if not present
  13. if (base.slice(-1) != "/") {
  14. base = base + "/";
  15. }
  16. gitbook.toolbar.createButton({
  17. icon: 'fa fa-edit',
  18. text: label,
  19. onClick: function() {
  20. var filepath = gitbook.state.filepath;
  21. window.open(base + lang + filepath);
  22. }
  23. });
  24. });
  25. });