Created
May 29, 2009 21:37
-
-
Save halfninja/120220 to your computer and use it in GitHub Desktop.
Drupal IMCE "Upload/choose file" link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
For Drupal, when using the IMCE file manager. | |
Decorates selected text fields with an "Upload/choose file" link next to them | |
that opens up the IMCE editor. $ids contains the array. | |
If I knew more about Drupal this would probably be a lot neater and require | |
less in-page Javascript. | |
*/ | |
function phptemplate_textfield($el) | |
{ | |
static $code_added = false; | |
$ids = array('edit-field-document-link-0-value'); | |
$id = $el['#id']; | |
if (in_array($id, $ids)) { | |
if (!$code_added) { | |
$code_added = true; | |
$js =<<<EOD | |
function openFileBrowser(id) { | |
window.open('/?q=imce&app=text-box|url@'+id, '', 'width=760,height=560,resizable=1'); | |
} | |
EOD; | |
drupal_add_js($js,'inline'); | |
} | |
$js =<<<EOD | |
$(document).ready(function(){ | |
$('#{$id}').after('<a href="#" class="imceBoxLink" onclick="openFileBrowser(\'{$id}\'); return false;">Upload/choose file</a>\ | |
'); | |
}); | |
EOD; | |
drupal_add_js($js,'inline'); | |
} | |
return theme_textfield($el); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment