Skip to content

Commit c77a8bc

Browse files
author
pmelab
committed
Added automatic enhancements.
1 parent 37dcc3c commit c77a8bc

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

formawesome.module

+17-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function formawesome_form_system_theme_settings_alter(&$form, &$form_state) {
4141
'title' => t('Enhance selectables'),
4242
'description' => t('Wrap checkboxes and radio buttons to be easier styleable.'),
4343
),
44+
'enhance_selectboxes' => array(
45+
'title' => t('Enhance select boxes'),
46+
'description' => t('Use jQuery Select2 for all select boxes.'),
47+
),
48+
'enhance_filefields' => array(
49+
'title' => t('Enhance file fields'),
50+
'description' => t('CSS styleable file fields.'),
51+
),
4452
);
4553

4654
$form['formawesome'] = array(
@@ -50,6 +58,7 @@ function formawesome_form_system_theme_settings_alter(&$form, &$form_state) {
5058
'#title' => 'Formawesome',
5159
'#description' => t('Toggle form enhancements for this theme.'),
5260
);
61+
5362
foreach ($features as $key => $feature) {
5463
$setting = 'formawesome_' . $key;
5564
$form['formawesome'][$setting] = array(
@@ -84,6 +93,7 @@ function formawesome_field_widget_form_alter(&$element, &$form_state, $context)
8493
if (in_array($widget_type, $formawesome_autocomplete_multiple)) {
8594
$element['#attributes']['data-max-values'] = $context['field']['cardinality'];
8695
}
96+
8797
if (in_array($context['instance']['widget']['type'], $formawesome_autocomplete_unknown)) {
8898
$element['#attributes']['data-allow-unknown'] = 'true';
8999
}
@@ -132,6 +142,9 @@ function formawesome_library() {
132142
$select2 . '/select2.js' => array(),
133143
$module . '/js/formawesome.select2.js' => array(),
134144
),
145+
'css' => array(
146+
$select2 . '/select2.css',
147+
),
135148
'dependencies' => array(
136149
array('formawesome', 'formawesome.base'),
137150
),
@@ -213,14 +226,16 @@ function formawesome_form_element_process(&$element, &$form_state, &$complete_fo
213226
$element['#enhance'] = FALSE;
214227
}
215228

216-
if ($element['#type'] == 'select' && $element['#enhance']) {
229+
if ($element['#type'] == 'select' && ($element['#enhance'] || formawesome_feature_enabled('enhance_selectboxes'))) {
217230
$element['#attached']['library'][] = array('formawesome', 'formawesome.select2');
218231
$element['#attached']['library'][] = array('formawesome', 'formawesome.base');
232+
$element['#attributes']['class'][] = 'formawesome-enhanced';
219233
}
220234

221-
if ($element['#type'] == 'file' && $element['#enhance']) {
235+
if ($element['#type'] == 'file' && ($element['#enhance'] || formawesome_feature_enabled('enhance_filefields'))) {
222236
$element['#attached']['js'][] = drupal_get_path('module', 'formawesome') . '/js/formawesome.file.js';
223237
$element['#attached']['library'][] = array('formawesome', 'formawesome.base');
238+
$element['#attributes']['class'][] = 'formawesome-enhanced';
224239
}
225240

226241
return $element;

js/formawesome.file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
Drupal.behaviors.formawesomeFile = {
77
attach: function($context, settings) {
8-
$('input[type="file"]', $context).once(function(){
8+
$('input[type="file"].formawesome-enhanced', $context).once(function(){
99
var $wrapper = $('<div class="image-preview formawesome-upload"></div>');
1010
var $status = $('<span class="formawesome-upload-status"></span>');
1111
var $button = $('<span class="formawesome-upload-choose">' + Drupal.t('Choose file') + '</span>');

js/formawesome.select2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
*/
1515
Drupal.behaviors.formawesome_select2 = {
1616
attach: function (context, settings) {
17-
$('select.enhanced', context).once(function() {
17+
$('select.formawesome-enhanced', context).once(function() {
1818
var $label = $(this).parent().find('label');
1919
$label.css('display', 'none');
2020
var options = {
2121
placeholder: $label.text(),
2222
adaptContainerCssClass: function (c) { return null; },
2323
adaptDropdownCssClass: function (c) { return null; },
24-
minimumResultsForSearch: -1,
24+
minimumResultsForSearch: 8,
2525
selectOnBlur: true
2626
};
2727
if ($(this).data('theme') && Drupal.formawesome.theme[$(this).data('theme')]) {

0 commit comments

Comments
 (0)