jquery.pageEditor.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Generic pageEditor plugin. Allows an editor DOM object to trigger
  3. * init, start, and end events. Implementors can check whether the
  4. * editor is currently editing and bind handlers for the events triggered
  5. * by the editor.
  6. */
  7. (function($) {
  8. $.fn.pageEditor = function(method, data) {
  9. this.each(function() {
  10. switch (method) {
  11. case 'isEditing':
  12. return this.editing;
  13. case 'start':
  14. if (!this.inited) {
  15. this.inited = true;
  16. $(this).trigger('init.pageEditor', data);
  17. }
  18. this.editing = true;
  19. $(this).trigger('start.pageEditor', data);
  20. break;
  21. case 'end':
  22. if (!this.inited) {
  23. this.inited = true;
  24. $(this).trigger('init.pageEditor', data);
  25. }
  26. this.editing = false;
  27. $(this).trigger('end.pageEditor', data);
  28. break;
  29. default:
  30. this.inited = false;
  31. this.editing = false;
  32. break;
  33. }
  34. });
  35. return this;
  36. };
  37. })(jQuery);