Notebook.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/App/Notebook", ["exports", "Site"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(exports, require("Site"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(mod.exports, global.Site);
  11. global.AppNotebook = mod.exports;
  12. }
  13. })(this, function (_exports, _Site2) {
  14. "use strict";
  15. Object.defineProperty(_exports, "__esModule", {
  16. value: true
  17. });
  18. _exports.run = run;
  19. _exports.getInstance = getInstance;
  20. _exports.default = _exports.AppNotebook = void 0;
  21. _Site2 = babelHelpers.interopRequireDefault(_Site2);
  22. var AppNotebook =
  23. /*#__PURE__*/
  24. function (_Site) {
  25. babelHelpers.inherits(AppNotebook, _Site);
  26. function AppNotebook() {
  27. babelHelpers.classCallCheck(this, AppNotebook);
  28. return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(AppNotebook).apply(this, arguments));
  29. }
  30. babelHelpers.createClass(AppNotebook, [{
  31. key: "initialize",
  32. value: function initialize() {
  33. babelHelpers.get(babelHelpers.getPrototypeOf(AppNotebook.prototype), "initialize", this).call(this);
  34. this.$listItem = $('.list-group-item');
  35. this.$actionBtn = $('.site-action');
  36. this.$toggle = this.$actionBtn.find('.site-action-toggle');
  37. this.$newNote = $('#addNewNote');
  38. this.$mdEdit = $('#mdEdit');
  39. this.window = $(window); // states
  40. this.states = {
  41. listItemActive: false
  42. };
  43. }
  44. }, {
  45. key: "process",
  46. value: function process() {
  47. babelHelpers.get(babelHelpers.getPrototypeOf(AppNotebook.prototype), "process", this).call(this);
  48. this.handleResize();
  49. this.steupListItem();
  50. this.steupActionBtn();
  51. }
  52. }, {
  53. key: "initEditer",
  54. value: function initEditer() {
  55. this.$mdEdit.markdown({
  56. autofocus: false,
  57. savable: false
  58. });
  59. }
  60. }, {
  61. key: "listItemActive",
  62. value: function listItemActive(active) {
  63. var api = this.$actionBtn.data('actionBtn');
  64. if (active) {
  65. api.show();
  66. } else {
  67. this.$listItem.removeClass('active');
  68. }
  69. this.states.listItemActive = active;
  70. }
  71. }, {
  72. key: "steupListItem",
  73. value: function steupListItem() {
  74. var self = this;
  75. this.$listItem.on('click', function () {
  76. $(this).siblings().removeClass('active');
  77. $(this).addClass('active');
  78. self.listItemActive(true);
  79. });
  80. }
  81. }, {
  82. key: "steupActionBtn",
  83. value: function steupActionBtn() {
  84. var _this = this;
  85. this.$toggle.on('click', function (e) {
  86. if (_this.states.listItemActive) {
  87. _this.listItemActive(false);
  88. } else {
  89. _this.$newNote.modal('show');
  90. e.stopPropagation();
  91. }
  92. });
  93. }
  94. }, {
  95. key: "handleResize",
  96. value: function handleResize() {
  97. this.window.on('resize', this.initEditer());
  98. }
  99. }]);
  100. return AppNotebook;
  101. }(_Site2.default);
  102. _exports.AppNotebook = AppNotebook;
  103. var instance = null;
  104. function getInstance() {
  105. if (!instance) {
  106. instance = new AppNotebook();
  107. }
  108. return instance;
  109. }
  110. function run() {
  111. var app = getInstance();
  112. app.run();
  113. }
  114. var _default = AppNotebook;
  115. _exports.default = _default;
  116. });