wymeditor-1.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. settings.postInit = function (instance) {
  9. var $doc = $(instance._doc);
  10. // Inject stylesheet for backwards compatibility.
  11. if (settings.stylesheet) {
  12. $doc.find('head').append('<link rel="stylesheet" type="text/css" media="screen" href="' + settings.stylesheet + '">');
  13. }
  14. // Update activeId on focus.
  15. $doc.find('body').focus(function () {
  16. Drupal.wysiwyg.activeId = params.field;
  17. });
  18. };
  19. // Attach editor.
  20. $('#' + params.field).wymeditor(settings);
  21. };
  22. /**
  23. * Detach a single editor instance.
  24. */
  25. Drupal.wysiwyg.editor.detach.wymeditor = function (context, params, trigger) {
  26. var $field = $('#' + params.field, context);
  27. var index = $field.data(WYMeditor.WYM_INDEX);
  28. if (typeof index == 'undefined' || !WYMeditor.INSTANCES[index]) {
  29. return;
  30. }
  31. var instance = WYMeditor.INSTANCES[index];
  32. instance.update();
  33. if (trigger != 'serialize') {
  34. instance.vanish();
  35. }
  36. };
  37. Drupal.wysiwyg.editor.instance.wymeditor = {
  38. insert: function (content) {
  39. this.getInstance().insert(content);
  40. },
  41. setContent: function (content) {
  42. this.getInstance().html(content);
  43. },
  44. getContent: function () {
  45. return this.getInstance().html();
  46. },
  47. getInstance: function () {
  48. var $field = $('#' + this.field);
  49. var index = $field.data(WYMeditor.WYM_INDEX);
  50. if (typeof index != 'undefined') {
  51. return WYMeditor.INSTANCES[index];
  52. }
  53. return null;
  54. }
  55. };
  56. })(jQuery);