wymeditor.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (function($) {
  2. /**
  3. * Attach this editor to a target element.
  4. */
  5. Drupal.wysiwyg.editor.attach.wymeditor = function (context, params, settings) {
  6. // Prepend basePath to wymPath.
  7. settings.wymPath = settings.basePath + settings.wymPath;
  8. // Update activeId on focus.
  9. settings.postInit = function (instance) {
  10. $(instance._doc).focus(function () {
  11. Drupal.wysiwyg.activeId = params.field;
  12. });
  13. };
  14. // Attach editor.
  15. $('#' + params.field).wymeditor(settings);
  16. };
  17. /**
  18. * Detach a single or all editors.
  19. */
  20. Drupal.wysiwyg.editor.detach.wymeditor = function (context, params, trigger) {
  21. if (typeof params != 'undefined') {
  22. var $field = $('#' + params.field);
  23. var index = $field.data(WYMeditor.WYM_INDEX);
  24. if (typeof index != 'undefined') {
  25. var instance = WYMeditor.INSTANCES[index];
  26. instance.update();
  27. if (trigger != 'serialize') {
  28. $(instance._box).remove();
  29. $(instance._element).show();
  30. delete instance;
  31. }
  32. }
  33. if (trigger != 'serialize') {
  34. $field.show();
  35. }
  36. }
  37. else {
  38. jQuery.each(WYMeditor.INSTANCES, function () {
  39. this.update();
  40. if (trigger != 'serialize') {
  41. $(this._box).remove();
  42. $(this._element).show();
  43. delete this;
  44. }
  45. });
  46. }
  47. };
  48. Drupal.wysiwyg.editor.instance.wymeditor = {
  49. insert: function (content) {
  50. this.getInstance().insert(content);
  51. },
  52. setContent: function (content) {
  53. this.getInstance().html(content);
  54. },
  55. getContent: function () {
  56. return this.getInstance().xhtml();
  57. },
  58. getInstance: function () {
  59. var $field = $('#' + this.field);
  60. var index = $field.data(WYMeditor.WYM_INDEX);
  61. if (typeof index != 'undefined') {
  62. return WYMeditor.INSTANCES[index];
  63. }
  64. return null;
  65. }
  66. };
  67. })(jQuery);