diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 75f85bb..b1b4cc8 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -6,14 +6,20 @@ /** * A jQuery object. * + * HTMLElement or collection of HTMLElement held by a jQuery object. + * * @typedef {object} jQuery * * @prop {number} length=0 + * Number of HTMLElement contained in the jQuery object. */ /** * Variable generated by Drupal with all the configuration created from PHP. * + * This variable is used to pass data from the backend to the frontend. Data + * contained in `drupalSettings` is used during behavior initialization. + * * @global * * @var {object} drupalSettings @@ -22,6 +28,9 @@ /** * Variable generated by Drupal that holds all translated strings from PHP. * + * Content of this variable is automatically created by Drupal when using locale + * module. It holds the translation of strings used on the page. + * * @global * * @var {object} drupalTranslations @@ -30,6 +39,8 @@ /** * Global Drupal object. * + * All Drupal JS API is contained in this namespace. + * * @global * * @namespace @@ -51,8 +62,7 @@ if (window.jQuery) { "use strict"; /** - * Custom error type thrown after attach/detach if one or more behaviors - * failed. + * Custom error thrown after attach/detach if one or more behaviors failed. * * @memberof Drupal * @@ -70,21 +80,21 @@ if (window.jQuery) { function DrupalBehaviorError(list, event) { /** - * Setting name helps debuggers. + * Setting the name property helps debuggers display a user-friendly type. * * @type {string} */ this.name = 'DrupalBehaviorError'; /** - * Execution phase errors were triggered. + * Execution phase during which behavior errors were triggered. * * @type {string} */ this.event = event || 'attach'; /** - * All thrown errors. + * Complete list of all thrown errors. * * @type {Array.} */ @@ -98,7 +108,7 @@ if (window.jQuery) { } /** - * Final message to send to debuggers. + * Final message that will be displayed in browser's console/debugger. * * @type {string} */ @@ -112,8 +122,10 @@ if (window.jQuery) { * * @callback Drupal~behaviorAttach * - * @param {HTMLElement} context + * @param {HTMLDocument|HTMLElement} context + * An element to attach behaviors to. * @param {object} settings + * An object containing settings for the current context. * * @see Drupal.attachBehaviors */ @@ -123,10 +135,12 @@ if (window.jQuery) { * * @callback Drupal~behaviorDetach * - * @param {HTMLElement} context - * @param {object} settings + * @param {HTMLDocument|HTMLElement} context + * An element to detach behaviors from. + * @param {?object} settings + * An object containing settings for the current context. It is rarely used. * @param {string} trigger - * One of 'unload', 'serialize' or 'move'. + * One of `unload`, `move` or `serialize`. * * @see Drupal.detachBehaviors */ @@ -135,7 +149,7 @@ if (window.jQuery) { * @typedef {object} Drupal~behavior * * @prop {Drupal~behaviorAttach} attach - * Function run on page load and after an AJAX call. + * Function run on page load and after an Ajax call. * @prop {Drupal~behaviorDetach} detach * Function run when content is serialized or removed from the page. */ @@ -154,7 +168,7 @@ if (window.jQuery) { * Behaviors are event-triggered actions that attach to page elements, * enhancing default non-JavaScript UIs. Behaviors are registered in the * {@link Drupal.behaviors} object using the method 'attach' and optionally - * also 'detach' as follows: + * also 'detach'. * * {@link Drupal.attachBehaviors} is added below to the jQuery.ready event and * therefore runs on initial page load. Developers implementing Ajax in their @@ -172,19 +186,18 @@ if (window.jQuery) { * @example * Drupal.behaviors.behaviorName = { * attach: function (context, settings) { - * ... + * // ... * }, * detach: function (context, settings, trigger) { - * ... + * // ... * } * }; * - * @param {Element} context - * An element to attach behaviors to. If none is given, the document - * element is used. - * @param {object} settings + * @param {HTMLDocument|HTMLElement} [context=document] + * An element to attach behaviors to. + * @param {object} [settings=drupalSettings] * An object containing settings for the current context. If none is given, - * the global drupalSettings object is used. + * the global {@link drupalSettings} object is used. * * @see Drupal~behaviorAttach * @see Drupal.detachBehaviors @@ -230,17 +243,16 @@ if (window.jQuery) { * implementation, i.e. .removeOnce('behaviorName'), to ensure the behavior * is detached only from previously processed elements. * - * @param {Element} context - * An element to detach behaviors from. If none is given, the document - * element is used. - * @param {object} settings + * @param {HTMLDocument|HTMLElement} [context=document] + * An element to detach behaviors from. + * @param {object} [settings=drupalSettings] * An object containing settings for the current context. If none given, - * the global drupalSettings object is used. - * @param {string} trigger + * the global {@link drupalSettings} object is used. + * @param {string} [trigger=unload] * A string containing what's causing the behaviors to be detached. The * possible triggers are: - * - unload: (default) The context element is being removed from the DOM. - * - move: The element is about to be moved within the DOM (for example, + * - `unload`: The context element is being removed from the DOM. + * - `move`: The element is about to be moved within the DOM (for example, * during a tabledrag row swap). After the move is completed, * {@link Drupal.attachBehaviors} is called, so that the behavior can undo * whatever it did in response to the move. Many behaviors won't need to @@ -248,7 +260,7 @@ if (window.jQuery) { * IFRAME elements reload their "src" when being moved within the DOM, * behaviors bound to IFRAME elements (like WYSIWYG editors) may need to * take some action. - * - serialize: When an Ajax form is submitted, this is called with the + * - `serialize`: When an Ajax form is submitted, this is called with the * form as the context. This provides every behavior within the form an * opportunity to ensure that the field elements have correct content * in them before the form is serialized. The canonical use-case is so @@ -288,8 +300,11 @@ if (window.jQuery) { * Helper to test document width for mobile configurations. * * @param {number} [width=640] + * Value of the width to check for. * * @return {bool} + * Returns true if the document's `clientWidth` is bigger than `width`, + * returns false otherwise. * * @deprecated Temporary solution for the mobile initiative. */ @@ -327,13 +342,14 @@ if (window.jQuery) { * An object of replacements pairs to make. Incidences of any key in this * array are replaced with the corresponding value. Based on the first * character of the key, the value is escaped and/or themed: - * - !variable: inserted as is - * - @variable: escape plain text to HTML ({@link Drupal.checkPlain}) - * - %variable: escape text and theme as a placeholder for user-submitted + * - `!variable`: inserted as is + * - `@variable`: escape plain text to HTML ({@link Drupal.checkPlain}) + * - `%variable`: escape text and theme as a placeholder for user-submitted * content ({@link Drupal.checkPlain} + * {@link Drupal.theme}('placeholder')) * * @return {string} + * Returns the formatted string. * * @see Drupal.t */ @@ -429,11 +445,12 @@ if (window.jQuery) { * of any key in this array are replaced with the corresponding value. * See {@link Drupal.formatString}. * @param {object} [options] + * Additional options for translation. * @param {string} [options.context=''] * The context the source string belongs to. * * @return {string} - * The translated string. + * Returns the translated string. */ Drupal.t = function (str, args, options) { options = options || {}; @@ -457,6 +474,7 @@ if (window.jQuery) { * Drupal path to transform to URL. * * @return {string} + * Returns the full Drupal URL. */ Drupal.url = function (path) { return drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + path; @@ -523,6 +541,7 @@ if (window.jQuery) { * Unencoded path. * * @return {string} + * Returns the encoded path. */ Drupal.encodePath = function (item) { return window.encodeURIComponent(item).replace(/%2F/g, '/');