属性「current」が「current」に設定されていないiframeをページで検索しようとしています。
(現在の属性はiframeの使用時に設定され、読み込まれるとリセットされます)。
現在に設定されていないiframeが1つ以上ある場合は、そのうちの1つELSEを使用し、新しいiframeを作成し、他の処理を行って新しいiframeを使用するようにコーディングしようとしています。
しかし、このコードは完全には機能していません。「アラート」をトリップすることはありません。そのため、「現在の」属性が設定されていないiframeがないことがわかっていても、ELSEの部分に入ることがありません。
var $fi = $visible.find(".file-info");
thisPreview = {};
var iframes = $('iframe').filter(function (index) {
return index == 0 || $('iframe').attr("current") == "no";
})
if(iframes.length >0){ //if one of the iframes hasnt got current set as current, use it
var theSuffix = iframes.attr('id').split('_').pop();
thisPreview[theSuffix] = $fi.prev(".image-preview");
$(this).closest(".file-upload-form").children(".variable-hidden").attr('value',theSuffix);
iframes.attr('current','current');
$(this).closest('.file-upload-form').attr('target','upload_target_'+theSuffix);
}
else{//else, create a new iframe, quick!
var count = $('[id^="upload_target_"]').length();
alert(count);
var countPlus1 = count+1;
iframe = $('<frame>').attr({'id':'upload_target_'+countPlus1,'name':'upload_target_'+countPlus1,'current':'current'}).addClass('upload-target');
iframe.appendTo($('#container'));
thisPreview[countPlus1] = $fi.prev(".image-preview");
$(this).closest(".file-upload-form").children(".variable-hidden").attr('value',countPlus1);
$(this).closest('.file-upload-form').attr('target','upload_target_'+countPlus1);
}