index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * 便签笔记入口程序
  3. * @author zhaoxianlie
  4. */
  5. let StickyNotes = (() => {
  6. // 添加事件监听
  7. let addListener = () => {
  8. // 正在编辑中
  9. let editing = false;
  10. window.onbeforeunload = function (e) {
  11. if (editing) {
  12. (e || window.event).returnValue = '当前还有未保存的笔记,确定要离开么?';
  13. }
  14. };
  15. // add note
  16. $('#addnote').click(function () {
  17. editing = true;
  18. html5sticky.addNote();
  19. return false;
  20. });
  21. // delete all notes
  22. $('#remove').click(function () {
  23. html5sticky.deleteAllNotes();
  24. return false;
  25. });
  26. $(document.body).delegate('.delete_stickynote', 'click', function (e) {
  27. // delete note
  28. html5sticky.deleteNote($(this));
  29. return false;
  30. }).delegate('.close_stickynote', 'click', function (e) {
  31. editing = false;
  32. // close enlarged note
  33. html5sticky.closeNote($(this));
  34. return false;
  35. }).delegate('.save_stickynote', 'click', function (e) {
  36. editing = false;
  37. // save the note
  38. html5sticky.saveNote($(this));
  39. return false;
  40. }).delegate('.note_common', 'click', function (e) {
  41. // enlarge the note
  42. $(this).find('.btn-close').hide();
  43. html5sticky.enlargeNote($(this));
  44. return false;
  45. }).delegate('.note_common', 'mouseover', function (e) {
  46. // 显示关闭按钮
  47. $(this).find('.btn-close').show();
  48. }).delegate('.note_common', 'mouseout', function (e) {
  49. // 隐藏关闭按钮
  50. $(this).find('.btn-close').hide();
  51. });
  52. // collapse the notes
  53. $('#collapse').click(function (event) {
  54. html5sticky.collapse();
  55. return false;
  56. });
  57. // expand the notes
  58. $('#expand').click(function (event) {
  59. html5sticky.expand();
  60. return false;
  61. });
  62. // allow escape to close big note
  63. $(document).keyup(function (e) {
  64. if (e.keyCode === 27) {
  65. $('#overlay').remove();
  66. $('.bignore').remove();
  67. }
  68. });
  69. // 下载
  70. $('#export').click(function (e) {
  71. html5sticky.export();
  72. return false;
  73. });
  74. // 导入笔记
  75. $('#import').click(function (event) {
  76. if (confirm('仅支持再次导入【之前用本工具导出的*.zip包】,请确认zip包已准备好?')) {
  77. html5sticky.importNotes();
  78. }
  79. return false;
  80. });
  81. // 文件夹选中
  82. $('#folders').delegate('li', 'click', function (e) {
  83. $(this).addClass('x-selected').siblings('li').removeClass('x-selected');
  84. let txt = $(this).text();
  85. let id = $(this).attr('id').replace(/^f_/, '');
  86. html5sticky.setCurrentFolder(txt, id);
  87. html5sticky.loadNotes(id);
  88. });
  89. // 创建文件夹
  90. $('#createFolder').click(function (e) {
  91. let el = html5sticky.createFolder();
  92. if (el) {
  93. el.trigger('click');
  94. }
  95. return false;
  96. });
  97. };
  98. // 初始化
  99. let init = () => {
  100. $(function () {
  101. html5sticky.buildFoldersAndInitNotes();
  102. addListener();
  103. });
  104. };
  105. return {
  106. init: init
  107. };
  108. })();
  109. StickyNotes.init();