function media_browser_testbed in D7 Media 7
Same name and namespace in other branches
- 7.4 includes/media.browser.inc \media_browser_testbed()
- 7.2 includes/media.browser.inc \media_browser_testbed()
- 7.3 includes/media.browser.inc \media_browser_testbed()
Menu callback for testing the media browser
1 string reference to 'media_browser_testbed'
- media_menu in ./
media.module - Implement of hook_menu().
File
- includes/
media.browser.inc, line 304 - Media Browser page callback
Code
function media_browser_testbed($form) {
media_attach_browser_js($form);
$form['test_element'] = array(
'#type' => 'media',
'#media_options' => array(
'global' => array(
'types' => array(
'video',
'audio',
),
),
),
);
$launcher = '<a href="#" id="launcher"> Launch Media Browser</a>';
$form['options'] = array(
'#type' => 'textarea',
'#title' => 'Options (JSON)',
'#rows' => 10,
);
$form['launcher'] = array(
'#markup' => $launcher,
);
$form['result'] = array(
'#type' => 'textarea',
'#title' => 'Result',
);
$js = <<<EOF
Drupal.behaviors.mediaTest = {
attach: function(context, settings) {
var delim = "---";
var recentOptions = [];
var recentOptionsCookie = jQuery.cookie("recentOptions");
if (recentOptionsCookie) {
recentOptions = recentOptionsCookie.split("---");
}
var recentSelectBox = jQuery('<select id="recent_options" style="width:100%"></select>').change(function() { jQuery('#edit-options').val(jQuery(this).val())});
jQuery('.form-item-options').append('<label for="recent_options">Recent</a>');
jQuery('.form-item-options').append(recentSelectBox);
jQuery('.form-item-options').append(jQuery('<a href="#">Reset</a>').click(function() {alert('reset'); jQuery.cookie("recentOptions", null); window.location.reload(); }));
jQuery.each(recentOptions, function (idx, val) {
recentSelectBox.append(jQuery('<option></option>').val(val).html(val));
});
jQuery('#launcher').click(function () {
jQuery('#edit-result').val('');
var options = {};
var optionsTxt = jQuery('#edit-options').val();
if (optionsTxt) {
// Store it in the recent box
recentOptionsCookie += "---" + optionsTxt
jQuery.cookie("recentOptions", recentOptionsCookie, { expires: 7 });
recentSelectBox.append(jQuery('<option></option>').val(optionsTxt).html(optionsTxt));
options = eval('(' + optionsTxt + ')');
}
Drupal.media.popups.mediaBrowser(Drupal.behaviors.mediaTest.mediaSelected, options);
return false;
});
},
mediaSelected: function(selectedMedia) {
var result = JSON.stringify(selectedMedia);
jQuery('#edit-result').val(result);
}
}
EOF;
drupal_add_js($js, array(
'type' => 'inline',
));
return $form;
}