ACMS.Dispatch.Edit._media=function($item){if(0===$item)return false;var Edit=this;var $url=ACMS.Library.acmsLink({tpl:"ajax/media-library.html"},false);var $target=$($item);var $type=$target.find("[name='type[]']").val();var $media,$mediaBox,$tagselect,$compiled,$disp;$(".js-media_insert",$item).click(function(event){do{if($type==="eximage")break;if($type==="text"){$tagselect=$target.find("[name^='text_tag_']").val();if(0||$tagselect==="markdown"||$tagselect==="none"||$tagselect==="p")break}alert("\u3053\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u306f\u30e1\u30c7\u30a3\u30a2\u3092\u633f\u5165\u3067\u304d\u307e\u305b\u3093\u3002");
return false}while(false);$.get($url,function(data){$mediaBox=$("#js-media_insert_view");if(!$mediaBox.length)$mediaBox=$('<div id="js-media_view"></div>').appendTo("body");else $mediaBox.empty().hide();$mediaBox.append(data);$mediaBox.fadeIn("fast").position({of:window,my:"center center"});$compiled=_.template($("#js-media_list").html());$disp=$(".acms-media-list > ul");getMediaJson(null,1);$("#js-media_insert",$mediaBox).click(function(event){if($media){var $src_=$("[name='normalSize']",$media).val();
var $srcL_=$("[name='largeSize']",$media).val();var $x_=$("[name='size']",$media).val().split(" ")[0];var $name_=$("[name='name']",$media).val();if($type==="eximage"){var $src=$target.find("[name^='eximage_normal']");var $srcL=$target.find("[name^='eximage_large']");$src.val($src_);if($srcL_)$srcL.val($srcL_);else $srcL.val("")}else if($type==="text"){var $area=$('textarea[name^="text_text_"]',$item);if(0||$tagselect==="none"||$tagselect==="p")$area.selection('<img src="'+$src_+'" width="'+$x_+'" alt="" />');
else if(0||$tagselect==="markdown")$area.selection("![]("+$src_+' "")')}$mediaBox.remove()}});$("#js-media_reload",$mediaBox).click(function(event){var $data=new FormData;$data.append("axis",$("[name='axis']",$mediaBox).val());$data.append("_bid",$("[name='_bid']",$mediaBox).val());$data.append("tag",$("[name='label']",$mediaBox).val());$data.append("order",$("[name='order']",$mediaBox).val());$data.append("query[]","axis");$data.append("query[]","_bid");$data.append("tpl","ajax/media_list.json");
$data.append("ACMS_POST_2GET",true);getMediaJson($data,1)});$(".js-media_close").click(function(event){$mediaBox.remove();return false})});return false});function getMediaJson(data,page){var $url=ACMS.Library.acmsLink({tpl:"ajax/media_list.json",page:String(page)},false);if(page<2)$disp.empty();if(data){data.append("page",page);$.ajax({type:"POST",data:data,processData:false,contentType:false,success:function(json){var mediaHtml=$compiled({data:json});$disp.append(mediaHtml);console.log(json.NextPage);
setAction(data,json.NextPage)}})}else $.getJSON($url,data,function(json){var mediaHtml=$compiled({data:json});$disp.append(mediaHtml);setAction(data,json.NextPage)})}function setAction(data,page){$(".js-media_thumbnail",$mediaBox).click(function(event){if($media)$("img",$media).removeClass("media_selected");$media=$(this);$("img",$media).addClass("media_selected")});$(".js-media_more",$mediaBox).click(function(event){$(".js-media_more",$mediaBox).parent().remove();getMediaJson(data,page)})}};
