Commit 7a2b3e65 authored by fangel's avatar fangel Committed by Paris Liakos

Issue #1848506 Media Browser parameters reset after AJAX pagination

parent fa663c31
......@@ -12,22 +12,7 @@ function media_browser($selected = NULL) {
$output = array();
$output['#attached']['library'][] = array('media', 'media_browser_page');
// Build out browser settings. Permissions- and security-related behaviors
// should not rely on these parameters, since they come from the HTTP query.
// @TODO make sure we treat parameters as user input.
$params = drupal_get_query_parameters() + array(
'types' => array(),
'multiselect' => FALSE,
);
// Transform text 'true' and 'false' to actual booleans.
foreach ($params as $k => $v) {
if ($v === 'true') { $params[$k] = TRUE; }
elseif ($v === 'false') { $params[$k] = FALSE; }
}
array_walk_recursive($params, 'media_recursive_check_plain');
$params = media_set_browser_params($params);
$params = media_set_browser_params();
// If one or more files have been selected, the browser interaction is now
// complete. Return empty page content to the dialog which now needs to close,
......@@ -170,22 +155,35 @@ function media_browser($selected = NULL) {
*
* It also offers a chance for some meddler to meddle with them.
*
* @param array $params
* An array of parameters provided when a media_browser is launched.
*
* @see media_browser()
*/
function media_set_browser_params(array $params = NULL) {
$stored_params = &drupal_static(__FUNCTION__, array());
function media_set_browser_params() {
$params = &drupal_static(__FUNCTION__, array());
if (isset($params)) {
$stored_params = $params;
// Allow modules to alter the parameters.
drupal_alter('media_browser_params', $stored_params);
}
if (empty($params)) {
// Build out browser settings. Permissions- and security-related behaviors
// should not rely on these parameters, since they come from the HTTP query.
// @TODO make sure we treat parameters as user input.
$params = drupal_get_query_parameters() + array(
'types' => array(),
'multiselect' => FALSE,
);
// Transform text 'true' and 'false' to actual booleans.
foreach ($params as $k => $v) {
if ($v === 'true') { $params[$k] = TRUE; }
elseif ($v === 'false') { $params[$k] = FALSE; }
}
array_walk_recursive($params, 'media_recursive_check_plain');
// Allow modules to alter the parameters.
drupal_alter('media_browser_params', $params);
}
return $params;
}
return $stored_params;
}
/**
* For sanity in grammar.
......
......@@ -65,6 +65,14 @@ Drupal.media.browser.views.select = function(view) {
* Sets up event-handlers for selecting items in the view.
*/
Drupal.media.browser.views.setup = function(view) {
// Ensure we only setup each view once..
if ($(view).hasClass('media-browser-views-processed')) {
return;
}
// Reset the list of selected files
Drupal.media.browser.selectMedia([]);
// Catch the click on a media item
$('.view-content .media-item', view).bind('click', function () {
var fid = $(this).closest('a[data-fid]').data('fid'),
......@@ -120,6 +128,9 @@ Drupal.media.browser.views.setup = function(view) {
}
Drupal.media.browser.selectMedia(selectedFiles);
});
// Add the processed class, so we dont accidentally process the same element twice..
$(view).addClass('media-browser-views-processed');
}
}(jQuery));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment