Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / embed / js / embed.js
1 /**
2  * @file
3  * Drupal Embed module.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Attaches or detaches behaviors, except the ones we do not want.
12    *
13    * @param {string} action
14    *   Either 'attach' or 'detach'.
15    * @param {HTMLDocument|HTMLElement} context
16    *   The context argument for Drupal.attachBehaviors()/detachBehaviors().
17    * @param {object} settings
18    *   The settings argument for Drupal.attachBehaviors()/detachBehaviors().
19    */
20   Drupal.runEmbedBehaviors = function (action, context, settings) {
21     // Do not run the excluded behaviors.
22     var stashed = {};
23     $.each(Drupal.embed.excludedBehaviors, function (i, behavior) {
24       stashed[behavior] = Drupal.behaviors[behavior];
25       delete Drupal.behaviors[behavior];
26     });
27     // Run the remaining behaviors.
28     (action === 'attach' ? Drupal.attachBehaviors : Drupal.detachBehaviors)(context, settings);
29     // Put the stashed behaviors back in.
30     $.extend(Drupal.behaviors, stashed);
31   };
32
33   /**
34    * Ajax 'embed_insert' command: insert the rendered embedded item.
35    *
36    * The regular Drupal.ajax.commands.insert() command cannot target elements
37    * within iframes. This is a skimmed down equivalent that works no matter
38    * whether the CKEditor is in iframe or div area mode.
39    *
40    * @param {Drupal.Ajax} ajax
41    *   An Ajax object.
42    * @param {object} response
43    *   The Ajax response.
44    * @param {string} response.data
45    *    The Ajax response's content.
46    * @param {number} [status]
47    *   The HTTP status code.
48    */
49   Drupal.AjaxCommands.prototype.embed_insert = function (ajax, response, status) {
50     var $target = $(ajax.element);
51     // No need to detach behaviors here, the widget is created fresh each time.
52     $target.html(response.data);
53     Drupal.runEmbedBehaviors('attach', $target.get(0), response.settings || ajax.settings);
54   };
55
56   /**
57    * Stores settings specific to Embed module.
58    */
59   Drupal.embed = {
60
61     /**
62      * A list of behaviors which are to be excluded while attaching/detaching.
63      *
64      * - Drupal.behaviors.editor, to avoid editor inception.
65      * - Drupal.behaviors.contextual, to keep contextual links hidden.
66      */
67     excludedBehaviors: ['editor', 'contextual']
68
69   };
70
71
72 })(jQuery, Drupal);