6 (function ($, Drupal) {
11 * Attaches or detaches behaviors, except the ones we do not want.
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().
20 Drupal.runEmbedBehaviors = function (action, context, settings) {
21 // Do not run the excluded behaviors.
23 $.each(Drupal.embed.excludedBehaviors, function (i, behavior) {
24 stashed[behavior] = Drupal.behaviors[behavior];
25 delete Drupal.behaviors[behavior];
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);
34 * Ajax 'embed_insert' command: insert the rendered embedded item.
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.
40 * @param {Drupal.Ajax} ajax
42 * @param {object} response
44 * @param {string} response.data
45 * The Ajax response's content.
46 * @param {number} [status]
47 * The HTTP status code.
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);
57 * Stores settings specific to Embed module.
62 * A list of behaviors which are to be excluded while attaching/detaching.
64 * - Drupal.behaviors.editor, to avoid editor inception.
65 * - Drupal.behaviors.contextual, to keep contextual links hidden.
67 excludedBehaviors: ['editor', 'contextual']