slide-editor.js 824 B

1234567891011121314151617181920212223242526272829303132333435
  1. (function() {
  2. $.fn.slide_editor = function() {
  3. return this.each(function() {
  4. var name = this.id;
  5. var this_form = this.form;
  6. $(this).replaceWith($('<div id="' + name + '-slide-editor" class="slide-editor"></div>')
  7. .append($(this).clone())
  8. );
  9. var codeeditor = CodeMirror.fromTextArea($('#' + name)[0], {
  10. mode: 'plain',
  11. lineNumbers: true,
  12. matchBrackets: true,
  13. lineWrapping: true,
  14. styleActiveLine: true,
  15. theme: 'default'
  16. });
  17. if (this_form) {
  18. var changed = false;
  19. codeeditor.on('change', function() {
  20. before_window_unload_message = '您所编辑的内容尚未保存';
  21. changed = true;
  22. });
  23. $(this_form).submit(function() {
  24. if (changed) {
  25. before_window_unload_message = null;
  26. }
  27. changed = false;
  28. });
  29. }
  30. });
  31. };
  32. })()