-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paragraphs Actions JS for closing the toggle.
- Loading branch information
Showing
4 changed files
with
49 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @file | ||
* Paragraphs actions JS code for paragraphs actions button. | ||
*/ | ||
|
||
(function ($, Backdrop) { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Process paragraph_actions elements. | ||
* | ||
* @type {Backdrop~behavior} | ||
* | ||
* @prop {Backdrop~behaviorAttach} attach | ||
* Attaches paragraphsActions behaviors. | ||
*/ | ||
Backdrop.behaviors.paragraphsActions = { | ||
attach: function (context, settings) { | ||
var $actionsElement = $('.paragraphs-actions-more').once('paragraphs-actions-more', context); | ||
// Attach event handlers to toggle button. | ||
$actionsElement.each(function () { | ||
var $this = $(this); | ||
|
||
$this.on('focusout', function (e) { | ||
setTimeout(function () { | ||
if ($this.has(document.activeElement).length == 0) { | ||
// The focus left the action button group, hide actions. | ||
$this.removeAttr('open'); | ||
} | ||
}, 1); | ||
}); | ||
}); | ||
$(document).on('keydown.paragraphsActions', function (event) { | ||
if (event.key === 'Escape') { | ||
$('.paragraphs-actions-more').removeAttr('open'); | ||
} | ||
}); | ||
|
||
}, | ||
detach: function (context) { | ||
$(document).off('keydown.paragraphsActions'); | ||
} | ||
}; | ||
|
||
})(jQuery, Backdrop); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,9 +156,9 @@ function paragraphs_field_multiple_value_form($field, $instance, $langcode, $ite | |
if (module_exists('file')) { | ||
// file.js triggers uploads when the main Submit button is clicked. | ||
$field_elements['#attached']['js'][] = backdrop_get_path('module', 'file') . '/js/file.js'; | ||
$field_elements['#attached']['js'][] = backdrop_get_path('module', 'paragraphs') . '/paragraphs.js'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
laryn
Author
Member
|
||
$form_state['has_file_element'] = TRUE; | ||
} | ||
$field_elements['#attached']['js'][] = backdrop_get_path('module', 'paragraphs') . '/paragraphs.js'; | ||
|
||
return $field_elements; | ||
} | ||
|
@@ -336,6 +336,7 @@ function _paragraphs_add_more_buttons($instance, $langcode, $form_state, $field_ | |
); | ||
} | ||
} | ||
$field_elements['#attached']['js'][] = backdrop_get_path('module', 'paragraphs') . '/js/paragraphs_actions.js'; | ||
This comment has been minimized.
Sorry, something went wrong.
herbdool
Contributor
|
||
} | ||
else { | ||
$field_elements['add_more']['add_more'] = array( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@laryn we could probably move this file to the js folder as well and rename it
paragraphs-file.js
or something like that.