X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fembed%2Fjs%2Fembed.js;fp=web%2Fmodules%2Fcontrib%2Fembed%2Fjs%2Fembed.js;h=683b8a244ef3823427b122c57be5faf2e04438af;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/embed/js/embed.js b/web/modules/contrib/embed/js/embed.js new file mode 100644 index 000000000..683b8a244 --- /dev/null +++ b/web/modules/contrib/embed/js/embed.js @@ -0,0 +1,72 @@ +/** + * @file + * Drupal Embed module. + */ + +(function ($, Drupal) { + + 'use strict'; + + /** + * Attaches or detaches behaviors, except the ones we do not want. + * + * @param {string} action + * Either 'attach' or 'detach'. + * @param {HTMLDocument|HTMLElement} context + * The context argument for Drupal.attachBehaviors()/detachBehaviors(). + * @param {object} settings + * The settings argument for Drupal.attachBehaviors()/detachBehaviors(). + */ + Drupal.runEmbedBehaviors = function (action, context, settings) { + // Do not run the excluded behaviors. + var stashed = {}; + $.each(Drupal.embed.excludedBehaviors, function (i, behavior) { + stashed[behavior] = Drupal.behaviors[behavior]; + delete Drupal.behaviors[behavior]; + }); + // Run the remaining behaviors. + (action === 'attach' ? Drupal.attachBehaviors : Drupal.detachBehaviors)(context, settings); + // Put the stashed behaviors back in. + $.extend(Drupal.behaviors, stashed); + }; + + /** + * Ajax 'embed_insert' command: insert the rendered embedded item. + * + * The regular Drupal.ajax.commands.insert() command cannot target elements + * within iframes. This is a skimmed down equivalent that works no matter + * whether the CKEditor is in iframe or div area mode. + * + * @param {Drupal.Ajax} ajax + * An Ajax object. + * @param {object} response + * The Ajax response. + * @param {string} response.data + * The Ajax response's content. + * @param {number} [status] + * The HTTP status code. + */ + Drupal.AjaxCommands.prototype.embed_insert = function (ajax, response, status) { + var $target = $(ajax.element); + // No need to detach behaviors here, the widget is created fresh each time. + $target.html(response.data); + Drupal.runEmbedBehaviors('attach', $target.get(0), response.settings || ajax.settings); + }; + + /** + * Stores settings specific to Embed module. + */ + Drupal.embed = { + + /** + * A list of behaviors which are to be excluded while attaching/detaching. + * + * - Drupal.behaviors.editor, to avoid editor inception. + * - Drupal.behaviors.contextual, to keep contextual links hidden. + */ + excludedBehaviors: ['editor', 'contextual'] + + }; + + +})(jQuery, Drupal);