wymeditor.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 editor instance.
  19. */
  20. Drupal.wysiwyg.editor.detach.wymeditor = function (context, params, trigger) {
  21. var $field = $('#' + params.field, context);
  22. var index = $field.data(WYMeditor.WYM_INDEX);
  23. if (typeof index == 'undefined' || !WYMeditor.INSTANCES[index]) {
  24. return;
  25. }
  26. var instance = WYMeditor.INSTANCES[index];
  27. instance.update();
  28. if (trigger != 'serialize') {
  29. $(instance._box).remove();
  30. $(instance._element).show();
  31. delete WYMeditor.INSTANCES[index];
  32. $field.show();
  33. }
  34. };
  35. Drupal.wysiwyg.editor.instance.wymeditor = {
  36. insert: function (content) {
  37. this.getInstance().insert(content);
  38. },
  39. setContent: function (content) {
  40. this.getInstance().html(content);
  41. },
  42. getContent: function () {
  43. return this.getInstance().xhtml();
  44. },
  45. getInstance: function () {
  46. var $field = $('#' + this.field);
  47. var index = $field.data(WYMeditor.WYM_INDEX);
  48. if (typeof index != 'undefined') {
  49. return WYMeditor.INSTANCES[index];
  50. }
  51. return null;
  52. }
  53. };
  54. })(jQuery);