diff --git a/paragraphs.collapsible.css b/paragraphs.collapsible.css index 07672d4..f2e0c95 100644 --- a/paragraphs.collapsible.css +++ b/paragraphs.collapsible.css @@ -33,6 +33,11 @@ td.paragraph-bundle-content-open.paragraph-bundle-content-collapsible.collapsed display: none; } +td.paragraph-bundle-content-open.paragraph-bundle-content-collapsible.removed > .form-actions .paragraphs-action-link, +td.paragraph-bundle-content-open.paragraph-bundle-content-collapsible.removed > .ajax-new-content > .form-actions .paragraphs-action-link { + display: none; +} + td.paragraph-bundle-content-open.paragraph-bundle-content-collapsible.expanded > .paragraph-bundle-preview, td.paragraph-bundle-content-open.paragraph-bundle-content-collapsible.expanded > .ajax-new-content > .paragraph-bundle-preview { display: none; diff --git a/paragraphs.collapsible.js b/paragraphs.collapsible.js index 048a6d7..9ddb175 100644 --- a/paragraphs.collapsible.js +++ b/paragraphs.collapsible.js @@ -754,20 +754,20 @@ * The count of paragraphs toggled. */ controller.toggleAll = function(triggerElement, options, action_name) { + var self = this; var $t = $(triggerElement); var settings = options || {}; settings.updateAllTrigger = false; // Determine action. - var requested_action = (action_name && action_name in controller.actions) ? controller.actions[action_name] : this.getToggleAction($t); - var requested_action_name = requested_action.name; + var requested_action = (action_name && action_name in self.actions) ? self.actions[action_name] : self.getToggleAction($t); // Toggle paragraphs. - var toggledCount = this.toggleItems(triggerElement, requested_action_name, settings); + var toggledCount = this.toggleItems(triggerElement, requested_action.name, settings); // Update trigger class and label. if (toggledCount > 0) { - this.updateAllTrigger(triggerElement); + this.updateAllTrigger(triggerElement, requested_action.name); } return toggledCount; @@ -778,35 +778,37 @@ * * @param object triggerElement * The trigger element. + * @param string update_action_name + * The trigger will be set to this action - 'collapse', 'expand'. + * If not defined, it will be derive from the current class name. */ - controller.updateAllTrigger = function(triggerElement, action_name) { + controller.updateAllTrigger = function(triggerElement, update_action_name) { var self = this; var $t = $(triggerElement); - var trigger_current_action = self.getToggleAction($t); + var update_action = (update_action_name && update_action_name in self.actions) ? self.actions[update_action_name] : null; // Determine trigger action based on items. - var trigger_action; - var item_action; - var $items = self.findTriggerItems($t); - if ($items && $items.length > 0) { - $.each($items, function(itemIndex, $item) { - item_action = self.getCurrentAction($item); - // If any are open, then set all action as item. - if (item_action && item_action.isOpen) { - trigger_action = item_action; - return false; - } - }); - } + if (update_action === null) { + var items_action, item_action; + var $items = self.findTriggerItems($t); + if ($items && $items.length > 0) { + $.each($items, function(itemIndex, $item) { + item_action = self.getCurrentAction($item); + // If any are open, then set all action as item. + if (item_action && item_action.isOpen) { + items_action = item_action; + return false; + } + }); + } - // If none are open, then all are collapsed. - if (!trigger_action) { - trigger_action = self.actions.collapse; + // If none are open, then all are collapsed. + update_action = items_action ? items_action : self.actions.collapse; } // If the trigger needs updated ... - if (trigger_current_action.opposite != trigger_action.name) { - var other_action = self.actions[trigger_action.opposite]; + if (update_action) { + var other_action = self.actions[update_action.opposite]; // Build triggers. var $triggers = [$t]; @@ -828,8 +830,8 @@ if ($trigger.length > 0) { $trigger .removeClass(other_action.classname) - .addClass(trigger_action.classname) - .text(trigger_action.allOnText); + .addClass(update_action.classname) + .text(update_action.allOnText); } }); } diff --git a/paragraphs.field_widget.inc b/paragraphs.field_widget.inc index 8c6d338..129cad9 100644 --- a/paragraphs.field_widget.inc +++ b/paragraphs.field_widget.inc @@ -682,6 +682,7 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta $fake_button_link_attributes = array( 'class' => array( drupal_html_class($fake_button_link_name), + 'paragraphs-action-link', 'paragraphs-' . $fake_button_action . '-link', ), ); diff --git a/paragraphs.module b/paragraphs.module index 2385bd5..7460544 100644 --- a/paragraphs.module +++ b/paragraphs.module @@ -1219,13 +1219,19 @@ function theme_paragraphs_field_multiple_value_form($variables) { $item_classes = $item_base_classes; $is_ajax_new = isset($item['#prefix']) && strpos($item['#prefix'], 'class="ajax-new-content"') !== FALSE; + // The item has been removed if the confirm delete button is present. + $is_being_edited = !empty($item['actions']['collapse_button']); + + // The item has been removed if the confirm delete button is present. + $is_removed = !empty($item['actions']['confirm_delete_button']); + if ($collapsible) { $expanded = $default_edit_open; $collapsible_restore = TRUE; if ($default_edit_mode === 'open') { // Non-AJAX collapsing. $collapsible_restore = $default_edit_open; - if (!$expanded && !$is_ajax_new && empty($item['#entity']->removed)) { + if (!$expanded && !$is_ajax_new && !$is_removed) { // Collapse if set to initially collapse and the paragraph is not // new content or deleted. The being_edited flag is set for all // new open form items so it cannot be used to determine the state. @@ -1235,11 +1241,8 @@ function theme_paragraphs_field_multiple_value_form($variables) { else { // AJAX collapsing. $collapsible_restore = FALSE; - if (isset($item['#entity']->removed)) { - $expanded = !empty($item['#entity']->removed); - } - elseif (isset($item['#entity']->being_edited)) { - $expanded = !empty($item['#entity']->being_edited); + if ($is_removed || $is_being_edited) { + $expanded = TRUE; } } @@ -1252,6 +1255,14 @@ function theme_paragraphs_field_multiple_value_form($variables) { $collapsed_row_count++; } + // Add current mode classes. + if ($is_being_edited) { + $item_classes[] = 'editing'; + } + if ($is_removed) { + $item_classes[] = 'removed'; + } + // Block collapsible state restore for this item. if (!$collapsible_restore) { $item_classes[] = 'no-collapsible-state-restore';