diff --git a/core/modules/editor/js/editor.js b/core/modules/editor/js/editor.js index d22957d..db61de8 100644 --- a/core/modules/editor/js/editor.js +++ b/core/modules/editor/js/editor.js @@ -29,7 +29,7 @@ Drupal.behaviors.editor = { var activeFormatID = $this.val(); var field = behavior.findFieldForFormatSelector($this); - // Directly attach this editor, if the text format is enabled. + // Directly attach this editor if the text format is enabled. if (settings.editor.formats[activeFormatID]) { Drupal.editorAttach(field, settings.editor.formats[activeFormatID]); } @@ -56,7 +56,8 @@ Drupal.behaviors.editor = { } // Detach any editor when the containing form is submitted. $this.parents('form').submit(function (event) { - // Do not detach if the event was canceled. + // If the event is already canceled, the form won't be submitted and + // we don't need to detach the editors. if (event.isDefaultPrevented()) { return; } @@ -94,12 +95,49 @@ Drupal.behaviors.editor = { } }; +/** + * Attaches a text editor based on the associated field's text format. + * + * Modules that provide text editors need to implement an attach method in + * Drupal.editors.foo.attach, where "foo" is the name of the editor. This method + * typically loads the editor library if necessary and replaces the text field + * with a rich text editor. + * + * @param field + * DOM element containing the text field to which the editor should be + * attached. + * @param format + * Object containing information about the associated text format and the + * editor settings. + */ Drupal.editorAttach = function (field, format) { if (format.editor) { Drupal.editors[format.editor].attach(field, format); } }; +/** + * Detaches a text editor from a field. + * + * This method is called when the text format is changed and the previous format + * had an associated text editor. Modules that provide text editors need to + * implement a detach method in Drupal.editors.foo.detach, where "foo" is the + * name of the editor. This method typically removes any rich text interface + * from the DOM and updates the value of the associated text area with the + * editor contents. + * + * @param field + * DOM element containing the text field from which the editor should be + * removed. + * @param format + * Object containing information about the associated text format and the + * editor settings. + * @param trigger + * String containing an explanation of why the editor is being detached. This + * value is passed through directly from Drupal.detachBehaviors(). + * + * @see Drupal.detachBehaviors() + */ Drupal.editorDetach = function (field, format, trigger) { if (format.editor) { Drupal.editors[format.editor].detach(field, format, trigger);