none.js 3.0 KB

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