wymeditor.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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) {
  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. $(instance._box).remove();
  28. $(instance._element).show();
  29. delete instance;
  30. }
  31. $field.show();
  32. }
  33. else {
  34. jQuery.each(WYMeditor.INSTANCES, function () {
  35. this.update();
  36. $(this._box).remove();
  37. $(this._element).show();
  38. delete this;
  39. });
  40. }
  41. };
  42. Drupal.wysiwyg.editor.instance.wymeditor = {
  43. insert: function (content) {
  44. var $field = $('#' + this.field);
  45. var index = $field.data(WYMeditor.WYM_INDEX);
  46. if (typeof index != 'undefined') {
  47. var instance = WYMeditor.INSTANCES[index];
  48. instance.insert(content);
  49. }
  50. }
  51. };
  52. })(jQuery);