3 * Defines the Drupal behaviors needed for the Image Widget Crop module.
6 (function ($, Drupal) {
10 * Drupal behavior for the Image Widget Crop module.
12 * @type {Drupal~behavior}
14 * @prop {Drupal~behaviorAttach} attach
15 * Attaches the behavior and creates Cropper instances.
16 * @prop {Drupal~behaviorAttach} detach
17 * Detaches the behavior and destroys Cropper instances.
19 Drupal.behaviors.imageWidgetCrop = {
20 attach: function (context) {
21 this.createInstances(context);
23 detach: function (context) {
24 this.destroyInstances(context);
28 * Creates necessary instances of Drupal.ImageWidgetCrop.
30 * @param {HTMLElement|jQuery} [context=document]
31 * The context which to find elements in.
33 createInstances: function (context) {
34 var $context = $(context || document);
35 $context.find(Drupal.ImageWidgetCrop.prototype.selectors.wrapper).each(function () {
36 var $element = $(this);
37 if (!$element.data('ImageWidgetCrop')) {
38 $element.data('ImageWidgetCrop', new Drupal.ImageWidgetCrop($element));
44 * Destroys any instances of Drupal.ImageWidgetCrop.
46 * @param {HTMLElement|jQuery} [context=document]
47 * The context which to find elements in.
49 destroyInstances: function (context) {
50 var $context = $(context || document);
51 $context.find(Drupal.ImageWidgetCrop.prototype.selectors.wrapper).each(function () {
52 var $element = $(this);
53 var instance = $element.data('ImageWidgetCrop');
56 $element.removeData('ImageWidgetCrop');