none.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.attach) {
  20. Drupal.behaviors.textarea.attach();
  21. }
  22. }
  23. };
  24. /**
  25. * Detach a single or all editors.
  26. *
  27. * @param context
  28. * A DOM element, supplied by Drupal.attachBehaviors().
  29. * @param params
  30. * (optional) An object containing input format parameters. If defined,
  31. * only the editor instance in params.field should be detached. Otherwise,
  32. * all editors should be detached and saved, so they can be submitted in
  33. * AJAX/AHAH applications.
  34. */
  35. Drupal.wysiwyg.editor.detach.none = function(context, params) {
  36. if (typeof params != 'undefined') {
  37. var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
  38. $wrapper.removeOnce('textarea').removeClass('.resizable-textarea')
  39. .find('.grippie').remove();
  40. }
  41. };
  42. /**
  43. * Instance methods for plain text areas.
  44. */
  45. Drupal.wysiwyg.editor.instance.none = {
  46. insert: function(content) {
  47. var editor = document.getElementById(this.field);
  48. // IE support.
  49. if (document.selection) {
  50. editor.focus();
  51. var sel = document.selection.createRange();
  52. sel.text = content;
  53. }
  54. // Mozilla/Firefox/Netscape 7+ support.
  55. else if (editor.selectionStart || editor.selectionStart == '0') {
  56. var startPos = editor.selectionStart;
  57. var endPos = editor.selectionEnd;
  58. editor.value = editor.value.substring(0, startPos) + content + editor.value.substring(endPos, editor.value.length);
  59. }
  60. // Fallback, just add to the end of the content.
  61. else {
  62. editor.value += content;
  63. }
  64. }
  65. };
  66. })(jQuery);