cba8f7bbca6b772b34ec9b0f23d01bfb0dce601c
[yaffs-website] / web / core / modules / image / js / theme.js
1 /**
2  * @file
3  * Provides theme functions for image Quick Edit's client-side HTML.
4  */
5
6 (function (Drupal) {
7
8   'use strict';
9
10   /**
11    * Theme function for validation errors of the Image in-place editor.
12    *
13    * @param {object} settings
14    *   Settings object used to construct the markup.
15    * @param {string} settings.errors
16    *   Already escaped HTML representing error messages.
17    *
18    * @return {string}
19    *   The corresponding HTML.
20    */
21   Drupal.theme.quickeditImageErrors = function (settings) {
22     return '<div class="quickedit-image-errors">' + settings.errors + '</div>';
23   };
24
25   /**
26    * Theme function for the dropzone element of the Image module's in-place
27    * editor.
28    *
29    * @param {object} settings
30    *   Settings object used to construct the markup.
31    * @param {string} settings.state
32    *   State of the upload.
33    * @param {string} settings.text
34    *   Text to display inline with the dropzone element.
35    *
36    * @return {string}
37    *   The corresponding HTML.
38    */
39   Drupal.theme.quickeditImageDropzone = function (settings) {
40     return '<div class="quickedit-image-dropzone ' + settings.state + '">' +
41       '  <i class="quickedit-image-icon"></i>' +
42       '  <span class="quickedit-image-text">' + settings.text + '</span>' +
43       '</div>';
44   };
45
46   /**
47    * Theme function for the toolbar of the Image module's in-place editor.
48    *
49    * @param {object} settings
50    *   Settings object used to construct the markup.
51    * @param {bool} settings.alt_field
52    *   Whether or not the "Alt" field is enabled for this field.
53    * @param {bool} settings.alt_field_required
54    *   Whether or not the "Alt" field is required for this field.
55    * @param {string} settings.alt
56    *   The current value for the "Alt" field.
57    * @param {bool} settings.title_field
58    *   Whether or not the "Title" field is enabled for this field.
59    * @param {bool} settings.title_field_required
60    *   Whether or not the "Title" field is required for this field.
61    * @param {string} settings.title
62    *   The current value for the "Title" field.
63    *
64    * @return {string}
65    *   The corresponding HTML.
66    */
67   Drupal.theme.quickeditImageToolbar = function (settings) {
68     var html = '<form class="quickedit-image-field-info">';
69     if (settings.alt_field) {
70       html += '  <div>' +
71         '    <label for="alt" class="' + (settings.alt_field_required ? 'required' : '') + '">' + Drupal.t('Alternative text') + '</label>' +
72         '    <input type="text" placeholder="' + settings.alt + '" value="' + settings.alt + '" name="alt" ' + (settings.alt_field_required ? 'required' : '') + '/>' +
73         '  </div>';
74     }
75     if (settings.title_field) {
76       html += '  <div>' +
77         '    <label for="title" class="' + (settings.title_field_required ? 'form-required' : '') + '">' + Drupal.t('Title') + '</label>' +
78         '    <input type="text" placeholder="' + settings.title + '" value="' + settings.title + '" name="title" ' + (settings.title_field_required ? 'required' : '') + '/>' +
79         '  </div>';
80     }
81     html += '</form>';
82
83     return html;
84   };
85
86 })(Drupal);