MDL-46500 filepicker: prevent error when element does not exist

This commit is contained in:
Ben Kelada 2014-10-14 17:25:01 +11:00 committed by David Monllao
parent 32a69a7d7a
commit 848e04183f
2 changed files with 15 additions and 4 deletions

View File

@ -88,6 +88,9 @@ M.form_filemanager.init = function(Y, options) {
}
// prepare filemanager for drag-and-drop upload
this.filemanager = Y.one('#filemanager-'+options.client_id);
if (!this.filemanager) {
return;
}
if (this.filemanager.hasClass('filemanager-container') || !this.filemanager.one('.filemanager-container')) {
this.dndcontainer = this.filemanager;
} else {
@ -434,6 +437,9 @@ M.form_filemanager.init = function(Y, options) {
print_path: function() {
var p = this.options.path;
if (!this.pathbar) {
return;
}
this.pathbar.setContent('').addClass('empty');
if (p && p.length!=0 && this.viewmode != 2) {
for(var i = 0; i < p.length; i++) {
@ -1053,6 +1059,9 @@ M.form_filemanager.init = function(Y, options) {
// finally init everything needed
// hide loading picture, display filemanager interface
var filemanager = Y.one('#filemanager-'+options.client_id);
if (!filemanager) {
return;
}
filemanager.removeClass('fm-loading').addClass('fm-loaded');
var manager = new FileManagerHelper(options);

View File

@ -298,10 +298,12 @@ if ($data->addtemplate){
///then we generate strings to replace
foreach ($possiblefields as $eachfield){
$field = data_get_field($eachfield, $data);
$patterns[]="[[".$field->field->name."]]";
$replacements[] = $field->display_add_field($rid);
$patterns[]="[[".$field->field->name."#id]]";
$replacements[] = 'field_'.$field->field->id;
if (strpos($data->addtemplate, "[[".$field->field->name."]]") !== false) {
$patterns[] = "[[".$field->field->name."]]";
$replacements[] = $field->display_add_field($rid);
$patterns[] = "[[".$field->field->name."#id]]";
$replacements[] = 'field_'.$field->field->id;
}
}
$newtext = str_ireplace($patterns, $replacements, $data->{$mode});