$delta_to_focus = 0;
foreach ($field_state['items'
] as $delta =>
$item_fields) { $delta_to_focus =
$delta;
if ($item_fields['weight'
] >
$removed_item_weight) { // Stop directly when we find an item with a bigger weight. We also
// have to subtract 1 from the delta in this case, since the delta's
// are renumbered when rebuilding the form.
$delta_to_focus--;
break;
} } $response->
addCommand(new InvokeCommand("#
$wrapper_id [data-media-library-item-delta=
$delta_to_focus]", 'focus'
));
} // Shift focus to the open button if the user removed the last selected
// item, or when the user has added items to the selection and is allowed to
// select more items. When the user is not allowed to add more items, the
// button needs to be disabled. Since we can't shift the focus to disabled
// elements, the focus is set via JavaScript by adding the
// 'data-disabled-focus' attribute and we also don't want to set the focus
// here.
// @see Drupal.behaviors.MediaLibraryWidgetDisableButton
elseif ($removed_last || (!
$is_remove_button && !
isset($element['open_button'
]['#attributes'
]['data-disabled-focus'
]))) { $response->
addCommand(new InvokeCommand("#
$wrapper_id .js-media-library-open-button", 'focus'
));
}