ACMS.Dispatch.Edit._media=function($item){if(0===$item)return false;var url=ACMS.Library.acmsLink({tpl:"ajax/media-library.html"},false),$target=$($item),type=$target.find("[name='type[]']").val();var $media,$mediaBox,$tagselect,$compiled,$disp,type;$(".js-media_insert",$item).click(function(event){var $self=$(this);do{if(type==="eximage")break;if(type==="media")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){var $mediaBox=$("#js-media_view");var $backdrop=$(".acms-admin-modal-backdrop");if(!$backdrop.length)$backdrop=$($.parseHTML('<div class="acms-admin-modal-backdrop"></div>')).hide().appendTo("body");if(!$mediaBox.length)$mediaBox=$($.parseHTML('<div id="js-media_view" class="acms-admin-modal out">')).appendTo("body");
else{$mediaBox.empty().remove();$mediaBox=$($.parseHTML('<div id="js-media_view" class="acms-admin-modal out">')).appendTo("body")}$raw=$($.parseHTML(data));if($mediaBox.length){$("body").css("overflow","hidden");$mediaBox.append($raw);$mediaBox.show();$backdrop.show();setTimeout(function(){$mediaBox.removeClass("out").addClass("in")},1)}ACMS.Dispatch.Admin($mediaBox);var closeFn=function(){$("body").css("overflow","");$backdrop.fadeOut();$mediaBox.removeClass("in").addClass("out");setTimeout(function(){$mediaBox.hide()},
500);return false};$(".acms-admin-modal-hide").bind("click",closeFn);$mediaBox.click(function(event){var click=event.target;if($(click).hasClass("acms-admin-modal"))closeFn()});$compiled=_.template($("#js-media_list").html());$disp=$(".acms-admin-media-list tbody");getMediaJson(null,1);$("#js-media_insert",$mediaBox).click(function(event){$media=$("[name=media_select]:checked",$mediaBox).closest(".js-media_row");if($media){var $mid_=$("[name='mid']",$media).val(),$src_=$("[name='normalSize']",$media).val(),
$srcL_=$("[name='largeSize']",$media).val(),$x_=$("[name='size']",$media).val().split(" ")[0],$name_=$("[name='name']",$media).val(),$link_=$("[name='permalink']",$media).val(),type_=$("[name='type']",$media).val(),preview='<img src="'+$("img",$media).attr("src")+'"/>';if(type==="eximage"){var $src=$target.find("[name^='eximage_normal']"),$srcL=$target.find("[name^='eximage_large']");$src.val($src_);if($srcL_)$srcL.val($srcL_);else $srcL.val("")}else if(type==="media"){var $label=$target.find("span.label"),
$value=$target.find("[name^='media_id']"),$preview=$target.find(".js-media_preview");if($value.length>1){$label=$self.closest("div").find("span.label");$value=$self.closest("div").find("[name^='media_id']")}$label.text($mid_);$value.val($mid_);$preview.empty();$preview.append(preview)}else if(type==="text"){var $area=$('textarea[name^="text_text_"]',$item);if(0||$tagselect==="none"||$tagselect==="p")if(type_=="image")$area.selection('<img src="'+$src_+'" width="'+$x_+'" alt="" />');else{if(type_==
"file")$area.selection('<a href="'+$link_+'">'+$name_+"</a>")}else if(0||$tagselect==="markdown")if(type_=="image")$area.selection("![]("+$src_+' "")');else if(type_=="file")$area.selection("["+$name_+"]("+$link_+' "")')}closeFn()}return false});var once=true;$(".js-media_reload",$mediaBox).bind("click",function(event){if(once){once=false;return false}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)})});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);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_row",$mediaBox).click(function(event){$("[name=media_select]",this).prop("checked",true)});$(".js-media_more",$mediaBox).click(function(event){$(".js-media_more",$mediaBox).parent().remove();getMediaJson(data,
page)})}};
