none.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. (function($) {
  2. /**
  3. * Attach this editor to a target element.
  4. *
  5. * @param context
  6. * A DOM element, supplied by Drupal.attachBehaviors().
  7. * @param params
  8. * An object containing input format parameters. Default parameters are:
  9. * - editor: The internal editor name.
  10. * - theme: The name/key of the editor theme/profile to use.
  11. * - field: The CSS id of the target element.
  12. * @param settings
  13. * An object containing editor settings for all enabled editor themes.
  14. */
  15. Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
  16. if (params.resizable) {
  17. var $wrapper = $('#' + params.field, context).parents('.form-textarea-wrapper:first');
  18. $wrapper.addClass('resizable');
  19. if (Drupal.behaviors.textarea) {
  20. Drupal.behaviors.textarea.attach(context);
  21. }
  22. }
  23. };
  24. /**
  25. * Detach a single editor instance.
  26. *
  27. * The editor syncs its contents back to the original field before its instance
  28. * is removed.
  29. *
  30. * In here, 'this' is an instance of WysiwygInternalInstance.
  31. * See Drupal.wysiwyg.editor.instance.none for more details.
  32. *
  33. * @param context
  34. * A DOM element, supplied by Drupal.attachBehaviors().
  35. * @param params
  36. * An object containing input format parameters. Only the editor instance in
  37. * params.field should be detached and saved, so its data can be submitted in
  38. * AJAX/AHAH applications.
  39. * @param trigger
  40. * A string describing why the editor is being detached.
  41. * Possible triggers are:
  42. * - unload: (default) Another or no editor is about to take its place.
  43. * - move: Currently expected to produce the same result as unload.
  44. * - serialize: The form is about to be serialized before an AJAX request or
  45. * a normal form submission. If possible, perform a quick detach and leave
  46. * the editor's GUI elements in place to avoid flashes or scrolling issues.
  47. * @see Drupal.detachBehaviors
  48. */
  49. Drupal.wysiwyg.editor.detach.none = function (context, params, trigger) {
  50. if (trigger != 'serialize') {
  51. var $wrapper = $('#' + params.field, context).parents('.form-textarea-wrapper:first');
  52. $wrapper.removeOnce('textarea').removeClass('.resizable-textarea').removeClass('resizable')
  53. .find('.grippie').remove();
  54. }
  55. };
  56. /**
  57. * Instance methods for plain text areas.
  58. */
  59. Drupal.wysiwyg.editor.instance.none = {
  60. insert: function(content) {
  61. var editor = document.getElementById(this.field);
  62. // IE support.
  63. if (document.selection) {
  64. editor.focus();
  65. var sel = document.selection.createRange();
  66. sel.text = content;
  67. }
  68. // Mozilla/Firefox/Netscape 7+ support.
  69. else if (editor.selectionStart || editor.selectionStart == '0') {
  70. var startPos = editor.selectionStart;
  71. var endPos = editor.selectionEnd;
  72. editor.value = editor.value.substring(0, startPos) + content + editor.value.substring(endPos, editor.value.length);
  73. }
  74. // Fallback, just add to the end of the content.
  75. else {
  76. editor.value += content;
  77. }
  78. },
  79. setContent: function (content) {
  80. $('#' + this.field).val(content);
  81. },
  82. getContent: function () {
  83. return $('#' + this.field).val();
  84. }
  85. };
  86. })(jQuery);