whizzywig-60.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var buttonPath = null;
  2. (function($) {
  3. /**
  4. * Attach this editor to a target element.
  5. */
  6. Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
  7. // Previous versions used per-button images found in this location,
  8. // now it is only used for custom buttons.
  9. if (settings.buttonPath) {
  10. window.buttonPath = settings.buttonPath;
  11. }
  12. // Assign the toolbar image path used for native buttons, if available.
  13. if (settings.toolbarImagePath) {
  14. btn._f = settings.toolbarImagePath;
  15. }
  16. // Fall back to text labels for all buttons.
  17. else {
  18. window.buttonPath = 'textbuttons';
  19. }
  20. // Whizzywig needs to have the width set 'inline'.
  21. $field = $('#' + params.field);
  22. var originalValues = Drupal.wysiwyg.instances[params.field];
  23. originalValues.originalStyle = $field.attr('style');
  24. $field.css('width', $field.width() + 'px');
  25. // Attach editor.
  26. makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
  27. // Whizzywig fails to detect and set initial textarea contents.
  28. var instance = $('#whizzy' + params.field).get(0);
  29. if (instance) {
  30. instance.contentWindow.document.body.innerHTML = tidyD($field.val());
  31. }
  32. };
  33. /**
  34. * Detach a single or all editors.
  35. */
  36. Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) {
  37. var detach = function (index) {
  38. var id = whizzies[index];
  39. var instance = $('#whizzy' + id).get(0);
  40. if (!instance) {
  41. return;
  42. }
  43. var editingArea = instance.contentWindow.document;
  44. var $field = $('#' + id);
  45. // Whizzywig shows the original textarea in source mode.
  46. if ($field.css('display') == 'block') {
  47. editingArea.body.innerHTML = $field.val();
  48. }
  49. // Save contents of editor back into textarea.
  50. $field.val(tidyH(editingArea));
  51. // Move original textarea back to its previous location.
  52. $container = $('#CONTAINER' + id);
  53. $field.insertBefore($container);
  54. // Remove editor instance.
  55. $container.remove();
  56. whizzies.splice(index, 1);
  57. // Restore original textarea styling.
  58. var originalValues = Drupal.wysiwyg.instances[id];
  59. $field.removeAttr('style');
  60. $field.attr('style', originalValues.originalStyle);
  61. }
  62. if (typeof params != 'undefined') {
  63. for (var i = 0; i < whizzies.length; i++) {
  64. if (whizzies[i] == params.field) {
  65. detach(i);
  66. break;
  67. }
  68. }
  69. }
  70. else {
  71. while (whizzies.length > 0) {
  72. detach(0);
  73. }
  74. }
  75. };
  76. })(jQuery);