summaryrefslogtreecommitdiff
path: root/modules/file
diff options
context:
space:
mode:
Diffstat (limited to 'modules/file')
-rw-r--r--modules/file/file.js13
-rw-r--r--modules/file/file.module5
-rw-r--r--modules/file/tests/file.test4
-rw-r--r--modules/file/tests/file_module_test.module1
4 files changed, 14 insertions, 9 deletions
diff --git a/modules/file/file.js b/modules/file/file.js
index 1071384f8..1a9f87e4f 100644
--- a/modules/file/file.js
+++ b/modules/file/file.js
@@ -1,4 +1,3 @@
-
/**
* @file
* Provides JavaScript additions to the managed file field type.
@@ -77,7 +76,7 @@ Drupal.file = Drupal.file || {
'%filename': this.value,
'%extensions': extensionPattern.replace(/\|/g, ', ')
});
- $(this).parents('div.form-managed-file').prepend('<div class="messages error file-upload-js-error">' + error + '</div>');
+ $(this).closest('div.form-managed-file').prepend('<div class="messages error file-upload-js-error">' + error + '</div>');
this.value = '';
return false;
}
@@ -96,8 +95,8 @@ Drupal.file = Drupal.file || {
// Check if we're working with an "Upload" button.
var $enabledFields = [];
- if ($(this).parents('div.form-managed-file').size() > 0) {
- $enabledFields = $(this).parents('div.form-managed-file').find('input.form-file');
+ if ($(this).closest('div.form-managed-file').length > 0) {
+ $enabledFields = $(this).closest('div.form-managed-file').find('input.form-file');
}
// Temporarily disable upload fields other than the one we're currently
@@ -119,8 +118,8 @@ Drupal.file = Drupal.file || {
*/
progressBar: function (event) {
var clickedButton = this;
- var $progressId = $(clickedButton).parents('div.form-managed-file').find('input.file-progress');
- if ($progressId.size()) {
+ var $progressId = $(clickedButton).closest('div.form-managed-file').find('input.file-progress');
+ if ($progressId.length) {
var originalName = $progressId.attr('name');
// Replace the name with the required identifier.
@@ -133,7 +132,7 @@ Drupal.file = Drupal.file || {
}
// Show the progress bar if the upload takes longer than half a second.
setTimeout(function () {
- $(clickedButton).parents('div.form-managed-file').find('div.ajax-progress-bar').slideDown();
+ $(clickedButton).closest('div.form-managed-file').find('div.ajax-progress-bar').slideDown();
}, 500);
},
/**
diff --git a/modules/file/file.module b/modules/file/file.module
index 506b0e91d..3d351fa2c 100644
--- a/modules/file/file.module
+++ b/modules/file/file.module
@@ -16,7 +16,7 @@ function file_help($path, $arg) {
case 'admin/help#file':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The File module defines a <em>File</em> field type for the Field module, which lets you manage and validate uploaded files attached to content on your site (see the <a href="@field-help">Field module help page</a> for more information about fields). For more information, see the online handbook entry for <a href="@file">File module</a>.', array('@field-help' => url('admin/help/field'), '@file' => 'http://drupal.org/handbook/modules/file')) . '</p>';
+ $output .= '<p>' . t('The File module defines a <em>File</em> field type for the Field module, which lets you manage and validate uploaded files attached to content on your site (see the <a href="@field-help">Field module help page</a> for more information about fields). For more information, see the online handbook entry for <a href="@file">File module</a>.', array('@field-help' => url('admin/help/field'), '@file' => 'http://drupal.org/documentation/modules/file')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Attaching files to content') . '</dt>';
@@ -72,6 +72,7 @@ function file_element_info() {
'#progress_message' => NULL,
'#upload_validators' => array(),
'#upload_location' => NULL,
+ '#size' => 22,
'#extended' => FALSE,
'#attached' => array(
'css' => array($file_path . '/file.css'),
@@ -442,7 +443,7 @@ function file_managed_file_process($element, &$form_state, $form) {
'#type' => 'file',
'#title' => t('Choose a file'),
'#title_display' => 'invisible',
- '#size' => 22,
+ '#size' => $element['#size'],
'#theme_wrappers' => array(),
'#weight' => -10,
);
diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test
index 1b5fdf5cd..7fa6d6f01 100644
--- a/modules/file/tests/file.test
+++ b/modules/file/tests/file.test
@@ -239,6 +239,10 @@ class FileManagedFileElementTestCase extends FileFieldTestCase {
* Tests the managed_file element type.
*/
function testManagedFile() {
+ // Check that $element['#size'] is passed to the child upload element.
+ $this->drupalGet('file/test');
+ $this->assertFieldByXpath('//input[@name="files[nested_file]" and @size="13"]', NULL, 'The custom #size attribute is passed to the child upload element.');
+
// Perform the tests with all permutations of $form['#tree'] and
// $element['#extended'].
foreach (array(0, 1) as $tree) {
diff --git a/modules/file/tests/file_module_test.module b/modules/file/tests/file_module_test.module
index 358c8b011..f66c749dd 100644
--- a/modules/file/tests/file_module_test.module
+++ b/modules/file/tests/file_module_test.module
@@ -36,6 +36,7 @@ function file_module_test_form($form, &$form_state, $tree = TRUE, $extended = FA
'#upload_location' => 'public://test',
'#progress_message' => t('Please wait...'),
'#extended' => (bool) $extended,
+ '#size' => 13,
);
if ($default_fid) {
$form['nested']['file']['#default_value'] = $extended ? array('fid' => $default_fid) : $default_fid;