text: angular.module("angular-media-preview",[]).directive("mediaPreview",function($log,$document){function _link(scope,elem,attrs,ngModel){function addToContainer(element){return element.addClass(previewClass),container.append(element)}function onChange(e){var files=elem[0].files;attrs.multiple?ngModel.$setViewValue(files):ngModel.$setViewValue(files[0]),container.empty(),files&&files.length&&angular.forEach(files,function(data,index){var result,$mediaElement,$reader=new FileReader;$reader.onloaderror=function(e){result=fallbackImage},$reader.onload=function(e){result=e.target.result},$reader.onloadend=function(e){return result.indexOf("data:audio")>-1?($mediaElement=angular.element(document.createElement("audio")),$mediaElement.attr("controls","true")):result.indexOf("data:video")>-1?($mediaElement=angular.element(document.createElement("video")),$mediaElement.attr("controls","true")):$mediaElement=angular.element(document.createElement("img")),$mediaElement.attr("src",result),addToContainer($mediaElement)},$reader.readAsDataURL(data)})}if("input"!==elem[0].nodeName.toLowerCase())return void $log.warn("mediaPreview:","The directive will work only for input element, actual element is a",elem[0].nodeName.toLowerCase());if("file"!=attrs.type)return void $log.warn("mediaPreview:","Expected input type file, received instead:",attrs.type,"on element:",elem);elem.attr("accept")||elem.attr("accept","image/*,video/*,audio/*");var container,fallbackImage="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAA00lEQVR4Ae2XwQqDQAxEveinFD9e2MUfq6Cep7GnrPAg1JVCu5OTvEwe9FLtWlpqR6OyVn2aXbNGdX6KB4OLrmbRyIKsGsksWKsINhbUShM0wVcEk43CnAVY722mMEfBhPWD9mGOAlvBepSDwK1gPc5LASp8fbCJ81KACl9PNkOYo8CfKOtHUpijwJ841y1xToJy5VxXnLPgvUL1OAeBW4F6kKPAnYB6jKPAnYA68PZ/8EOCJtjvfvmdqwjSvR8gTz1YcCiytgs/TvLnvaDi/J2gCV63ZgZdEb12DwAAAABJRU5ErkJggg==",previewClass=attrs.previewClass||"media-preview",containerClass=attrs.containerClass||"media-container";attrs.previewContainer&&(document.getElementById(attrs.previewContainer)||angular.isElement(attrs.previewContainer))?container=angular.isElement(attrs.previewContainer)?attrs.previewContainer:angular.element(document.getElementById(attrs.previewContainer)):(container=angular.element(document.createElement("div")),elem.parent()[0].insertBefore(container[0],elem[0])),container.addClass(containerClass),elem.on("change",onChange),scope.$on("$destroy",function(){elem.off("change",onChange)})}var directive={restrict:"A",require:"ngModel",link:_link};return directive});