openwysiwyg.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Backup $ and reset it to jQuery.
  2. Drupal.wysiwyg._openwysiwyg = $;
  3. $ = jQuery;
  4. // Wrap openWYSIWYG's methods to temporarily use its version of $.
  5. jQuery.each(WYSIWYG, function (key, value) {
  6. if (jQuery.isFunction(value)) {
  7. WYSIWYG[key] = function () {
  8. var old$ = $;
  9. $ = Drupal.wysiwyg._openwysiwyg;
  10. var result = value.apply(this, arguments);
  11. $ = old$;
  12. return result;
  13. };
  14. }
  15. });
  16. // Override editor functions.
  17. WYSIWYG.getEditor = function (n) {
  18. return Drupal.wysiwyg._openwysiwyg("wysiwyg" + n);
  19. };
  20. (function($) {
  21. /**
  22. * Attach this editor to a target element.
  23. */
  24. Drupal.wysiwyg.editor.attach.openwysiwyg = function(context, params, settings) {
  25. // Initialize settings.
  26. settings.ImagesDir = settings.path + 'images/';
  27. settings.PopupsDir = settings.path + 'popups/';
  28. settings.CSSFile = settings.path + 'styles/wysiwyg.css';
  29. //settings.DropDowns = [];
  30. var config = new WYSIWYG.Settings();
  31. for (var setting in settings) {
  32. config[setting] = settings[setting];
  33. }
  34. // Attach editor.
  35. WYSIWYG.setSettings(params.field, config);
  36. WYSIWYG_Core.includeCSS(WYSIWYG.config[params.field].CSSFile);
  37. WYSIWYG._generate(params.field, config);
  38. };
  39. /**
  40. * Detach a single or all editors.
  41. */
  42. Drupal.wysiwyg.editor.detach.openwysiwyg = function(context, params) {
  43. if (typeof params != 'undefined') {
  44. var instance = WYSIWYG.config[params.field];
  45. if (typeof instance != 'undefined') {
  46. WYSIWYG.updateTextArea(params.field);
  47. jQuery('#wysiwyg_div_' + params.field).remove();
  48. delete instance;
  49. }
  50. jQuery('#' + params.field).show();
  51. }
  52. else {
  53. jQuery.each(WYSIWYG.config, function(field) {
  54. WYSIWYG.updateTextArea(field);
  55. jQuery('#wysiwyg_div_' + field).remove();
  56. delete this;
  57. jQuery('#' + field).show();
  58. });
  59. }
  60. };
  61. })(jQuery);