X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fimage_widget_crop%2Fjs%2Fiwc.behaviors.js;fp=web%2Fmodules%2Fcontrib%2Fimage_widget_crop%2Fjs%2Fiwc.behaviors.js;h=2714adc6df81903db6c62eaf8e636950de8f0844;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hp=0000000000000000000000000000000000000000;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/modules/contrib/image_widget_crop/js/iwc.behaviors.js b/web/modules/contrib/image_widget_crop/js/iwc.behaviors.js new file mode 100644 index 000000000..2714adc6d --- /dev/null +++ b/web/modules/contrib/image_widget_crop/js/iwc.behaviors.js @@ -0,0 +1,62 @@ +/** + * @file + * Defines the Drupal behaviors needed for the Image Widget Crop module. + */ + +(function ($, Drupal) { + 'use strict'; + + /** + * Drupal behavior for the Image Widget Crop module. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches the behavior and creates Cropper instances. + * @prop {Drupal~behaviorAttach} detach + * Detaches the behavior and destroys Cropper instances. + */ + Drupal.behaviors.imageWidgetCrop = { + attach: function (context) { + this.createInstances(context); + }, + detach: function (context) { + this.destroyInstances(context); + }, + + /** + * Creates necessary instances of Drupal.ImageWidgetCrop. + * + * @param {HTMLElement|jQuery} [context=document] + * The context which to find elements in. + */ + createInstances: function (context) { + var $context = $(context || document); + $context.find(Drupal.ImageWidgetCrop.prototype.selectors.wrapper).each(function () { + var $element = $(this); + if (!$element.data('ImageWidgetCrop')) { + $element.data('ImageWidgetCrop', new Drupal.ImageWidgetCrop($element)); + } + }); + }, + + /** + * Destroys any instances of Drupal.ImageWidgetCrop. + * + * @param {HTMLElement|jQuery} [context=document] + * The context which to find elements in. + */ + destroyInstances: function (context) { + var $context = $(context || document); + $context.find(Drupal.ImageWidgetCrop.prototype.selectors.wrapper).each(function () { + var $element = $(this); + var instance = $element.data('ImageWidgetCrop'); + if (instance) { + instance.destroy(); + $element.removeData('ImageWidgetCrop'); + } + }); + } + }; + +}(jQuery, Drupal));