/**
* Provides a DropzoneJS atop of the file element.
*
- * Configuration options are:
- * - #title
+ * Required options are:
+ * - #title (string)
* The main field title.
- * - #description
+ * - #description (string)
* Description under the field.
- * - #dropzone_description
+ * - #dropzone_description (string)
* Will be visible inside the upload area.
- * - #max_filesize
+ * - #max_filesize (string)
* Used by dropzonejs and expressed in number + unit (i.e. 1.1M) This will be
* converted to a form that DropzoneJs understands. See:
* http://www.dropzonejs.com/#config-maxFilesize
- * - #extensions
+ * - #extensions (string)
* A string of valid extensions separated by a space.
- * - #max_files
+ * - #max_files (integer)
* Number of files that can be uploaded.
* If < 1, there is no limit.
+ * - #clientside_resize (bool)
+ * Whether or not to use DropzoneJS clientside resizing. It requires v4.4.0+
+ * version of the library.
+ *
+ * Optional options are:
+ * - #resize_width (integer)
+ * (optional) The maximum with in px. If omitted defaults to NULL.
+ * - #resize_height (integer)
+ * (optional) The maximum height in px. If omitted defaults to NULL.
+ * - #resize_quality (float)
+ * (optional) The quality of the resize. Accepts values from 0 - 1. Ie: 0.8.
+ * Defautls to 1.
+ * - #resize_method (string)
+ * (optional) Accepts 'contain', which scales the image, or 'crop' which crops
+ * the image. Defaults to 'contain'.
+ * - #thumbnail_method (string).
+ * (optional) Accepts 'contain', which scales the image, or 'crop' which crops
+ * the image. Defaults to 'contain'.
+ *
+ * @todo Not sure about the version for clientside.
*
* When submitted the element returns an array of temporary file locations. It's
* the duty of the environment that implements this element to handle the
],
];
+ if (!empty($element['#clientside_resize'])) {
+ $element['#attached']['drupalSettings']['dropzonejs']['instances'][$element['#id']] += [
+ 'resizeWidth' => !empty($element['#resize_width']) ? $element['#resize_width'] : NULL,
+ 'resizeHeight' => !empty($element['#resize_height']) ? $element['#resize_height'] : NULL,
+ 'resizeQuality' => !empty($element['#resize_quality']) ? $element['#resize_quality'] : 1,
+ 'resizeMethod' => !empty($element['#resize_method']) ? $element['#resize_method'] : 'contain',
+ 'thumbnailMethod' => !empty($element['#thumbnail_method']) ? $element['#thumbnail_method'] : 'contain',
+ ];
+ array_unshift($element['#attached']['library'], 'dropzonejs/exif-js');
+ }
+
static::setAttributes($element, ['dropzone-enable']);
return $element;
}