To implement a file chooser, we need to open DAM in a new window and listen from messages sent back.
Use the following example and replace [URLTODAM] with the url of DAM and [URLTODEFAULTIMAGE] with the url to a default image that is used if no image is chosen in the DAM.
$(document).ready(function(){//Note that this function is called from the DAM windowwindow.receiveMessageV6=function(event){//Close DAMwindow.currentMediaBank.close();//parse the datavardata=$.parseJSON(event.data);//set the valuesvarfileIdField=window.currentfileChooser.find("input.fileChooserFileId");if(fileIdField){fileIdField.val(data.key.fileId);}varfileNameField=window.currentfileChooser.find("input.fileChooserFileName");if(fileNameField){fileNameField.val(data.metadata.fileName);}varcroppingIdField=window.currentfileChooser.find("input.fileChooserCroppingId");if(croppingIdField){croppingIdField.val(data.key.croppingId);}varcroppingNameField=window.currentfileChooser.find("input.fileChooserCroppingName");if(croppingNameField){croppingNameField.val(data.metadata.croppingName);}varfullNameField=window.currentfileChooser.find(".fileChooserFullName");if(fullNameField){if(data.metadata.fileName){varfullname=data.metadata.fileName;if(data.metadata.croppingName){fullname+=" ("+data.metadata.croppingName+")";}fullNameField.html(fullname);}}varfileChooserThumbnail=window.currentfileChooser.find("img.fileChooserThumbnail");if(fileChooserThumbnail){fileChooserThumbnail.attr("src",data.metadata.thumbnailUrl);}}$(".fileChooser6 .choosefile").click(function(){window.currentfileChooser=$(this).closest(".fileChooser6");if(window.addEventListener){addEventListener("message",window.receiveMessageV6,false);}else{attachEvent("onmessage",window.receiveMessageV6);}window.currentMediaBank=window.open([URLTODAM]);});$(".fileChooser6 .removefile").click(function(){window.currentfileChooser=$(this).closest(".fileChooser6");varfileIdField=window.currentfileChooser.find("input.fileChooserFileId");if(fileIdField){fileIdField.val(null);}varfileNameField=window.currentfileChooser.find("input.fileChooserFileName");if(fileNameField){fileNameField.val(null);}varcroppingIdField=window.currentfileChooser.find("input.fileChooserCroppingId");if(croppingIdField){croppingIdField.val(null);}varcroppingNameField=window.currentfileChooser.find("input.fileChooserCroppingName");if(croppingNameField){croppingNameField.val(null);}varfullNameField=window.currentfileChooser.find(".fileChooserFullName");if(fullNameField){fullNameField.html("No file selected");}varfileChooserThumbnail=window.currentfileChooser.find("img.fileChooserThumbnail");if(fileChooserThumbnail){fileChooserThumbnail.attr("src","[URLTODEFAULTIMAGE]");}});});
When a file chooser is needed use the following html. Replace [URLTODEFAULTIMAGE] with the url to a default image that is used if no image is chosen in DAM.