ACMS.Config.Edit={};ACMS.Config.Edit.unitMark=".entryFormColumn";ACMS.Config.Edit.itemMark=".entryFormColumnItem";ACMS.Config.Edit.itemHeadMark=".entryFormColumnHead";ACMS.Config.Edit.itemBodyMark=".entryFormColumnBody";ACMS.Config.Edit.stateSort=false;ACMS.Config.Edit.exFeaturesInited=false;
ACMS.Dispatch.Edit=function(context){var Edit=arguments.callee;var $unit=$(ACMS.Config.Edit.unitMark,context);$unit.$range=$(':input[name="summary_range"]',context);$unit.$more=$unit.find("#more");$unit.$more.show();if($unit.$range.size())if(parseInt($unit.$range.val(),10)){$unit.$more.detach();$unit.find(ACMS.Config.Edit.itemMark).eq($unit.$range.val()-1).after($unit.$more)}else{if(""===$unit.$range.val()){$unit.$more.detach();$unit.append($unit.$more)}}else $unit.$more.remove();$unit.$target=$(".ablogcms--column-add-btn",
context);Edit._refresh($unit);Edit._range($unit);if($("img.column-map",$unit).size()){var region="";if(ACMS.Config.s2dRegion)region="&region="+ACMS.Config.s2dRegion;ACMS.Library.googleLoadProxy("maps","3",{callback:function(){ACMS.Library.yahooLoadProxy({callback:function(){$(ACMS.Config.Edit.itemMark,$unit).each(function(){Edit._item(this,$unit)})},error:function(){$(ACMS.Config.Edit.itemMark,$unit).each(function(){Edit._item(this,$unit)})}})},other_params:"sensor="+ACMS.Config.Gmap.sensor+region})}else $(ACMS.Config.Edit.itemMark,
$unit).each(function(){Edit._item(this,$unit)});Edit._add($unit);$("#tagListTrigger",context).each(function(){Edit.tagassist(this)}).show();$(".js-formUnitGroup",context).each(function(){Edit.formUnitGroup(this)});$(".js-extendTagSelect",context).each(function(){Edit.extendTagSelect(this)});$(':input[name="categoryAdd"]',context).click(function(){Edit._category($('select[name="category_id"]',context));return false}).show();$(ACMS.Config.editInplateTitleMark,context).each(function(){if(ACMS.Config.eid)Edit._editTitle(this)});
$(".js-edit_inplace",context).each(function(){this.inplace=new Edit._inplace(this)});Edit._experimental();if(-1===navigator.userAgent.indexOf("MSIE 6"))Edit._sortable($unit);Edit._indicator(context);try{if(ACMS.Config.admin==="entry-edit"&&ACMS.Config.webStorage==="on"&&typeof localStorage!="undefined")Edit._saveform(context)}catch(e){}var $map=$(".js-map-editable",context);if($map.size()){var region="";if(ACMS.Config.s2dRegion)region="&region="+ACMS.Config.s2dRegion;ACMS.Library.googleLoadProxy("maps",
"3",{callback:function(){$map.each(function(){ACMS.Dispatch.Edit.map(this)})},other_params:"sensor="+ACMS.Config.Gmap.sensor+region})}var $yolp=$(".js-yolp-editable",context);if($yolp.size())ACMS.Library.yahooLoadProxy({callback:function(){$map.each(function(){ACMS.Dispatch.Edit.yolp(this)})}})};
ACMS.Dispatch.Edit._saveform=function(context){var $form=$("#entryForm",context),$time=ACMS.Config.webStorageInterval,$stop=false,$first=false,$bid=ACMS.Config.bid,$cid=ACMS.Config.cid?ACMS.Config.cid:"0",$eid=ACMS.Config.eid?ACMS.Config.eid:"0",$data,$storage;if(ACMS.Config.webStorageType==="session")$storage=sessionStorage;else if(ACMS.Config.webStorageType==="local")$storage=localStorage;var $key="acms_bid:"+$bid+"_cid:"+$cid+"_eid:"+$eid;$data=$storage.getItem($key);if($data!==null){$data=JSON.parse($data);
var $module=$(":submit[name^=ACMS_POST]",$form).attr("name");var $popup=$($.parseHTML("<p>\u7de8\u96c6\u4e2d\u306e\u30c7\u30fc\u30bf\u304c\u3042\u308a\u307e\u3059\u3002\u5fa9\u5143\u3057\u307e\u3059\u304b\uff1f</p>"));$popup.dialog({title:"\u30c7\u30fc\u30bf\u5fa9\u5143",resizable:false,modal:true,autoOpen:false,position:"center",buttons:{"\u5fa9\u5143":function(){$storage.removeItem($key);$stop=true;$storage=null;var form=$("<form/>",{action:"",method:"post",enctype:"multipart/form-data"});var f=
$form.serializeArray();var regExp=new RegExp("DEF","i");$.each($data,function(i,field){if(field.name.match(/:extension$/i)){var fileField=field.name.split(":");form.append($("<input/>",{type:"file",name:fileField[0]}))}form.append($("<input/>",{type:"hidden",name:field.name,value:field.value}))});form.append($("<input/>",{type:"hidden",name:$module,value:"save"}));form.append($("<input/>",{type:"hidden",name:"recover_"+$key,value:""}));form.append($("<input/>",{type:"hidden",name:"field[]",value:"recover_"+
$key}));form.append($("<input/>",{type:"hidden",name:"recover_"+$key+":v#required"}));form.appendTo(document.body);form.submit()},"\u30ad\u30e3\u30f3\u30bb\u30eb":function(){saveWebStorage();$popup.dialog("destroy");$popup.remove()}}});$popup.parent().css({position:"fixed"}).end().dialog("open")}else if($bid)saveWebStorage();function saveWebStorage(){$storage.removeItem($key);$form.bind("keyup change",function(){var $timer=setInterval(function(){if($storage){var $serialize=$form.serializeArray();
$serialize=JSON.stringify($serialize);$storage.setItem($key,$serialize)}if($stop){clearInterval($timer);$timer=null}},$time);$form.unbind("change");$form.unbind("keyup")})}};
ACMS.Dispatch.Edit._indicator=function(context){var $form=$("#entryForm",context),$back=$('[name^="ACMS_POST_2GET"]',context),$body=$("body",context),$img=$($.parseHTML('<div class="js-acms_loader_img js-acms_loader" style="display:none;"></div>'));if(ACMS.Dispatch.Utility.browser().ltIE9)$img=$($.parseHTML('<img class="js-acms_loader_img" src="'+ACMS.Config.root+'themes/system/images/ajax-loader.gif" style="display:none;"/>'));function showProgressLoader(){var $prog=$($.parseHTML('<div id="js-entry_saving_progress"><span></span></div>'));
$prog.css({top:document.body.scrollTop||document.documentElement.scrollTop,left:document.body.scrollLeft||document.documentElement.scrollLeft});$img.appendTo($prog).show();$body.css("overflow","hidden").append($prog);if(!jQuery.support.opacity)$prog.show();else $prog.fadeIn(100);return true}$body.append($img);$form.bind("submit",showProgressLoader);$back.bind("click",function(){$form.unbind("submit",showProgressLoader)})};
ACMS.Dispatch.Edit._editTitle=function(elm){var $self=$(elm);var $inplaceWrapper=$(".js-edit_inplace").parent();if($inplaceWrapper.length&&!ACMS.Config.Edit.stateSort)$self.addClass("js-edit_inplace-title_trigger");$(".js-edit_inplace-title_trigger").click(function(){var $detailBox=$("#js-edit_inplace-detail"),eid=ACMS.Config.eid;var $backdrop=$(".acms-modal-backdrop");if(!$backdrop.length)$backdrop=$($.parseHTML('<div class="acms-modal-backdrop"></div>')).hide().appendTo("body");if(!$detailBox.length)$detailBox=
$($.parseHTML('<div id="js-edit_inplace-detail" class="acms-modal"><div class="acms-modal-dialog"></div></div>')).appendTo("body");else{$detailBox.empty().remove();$detailBox=$($.parseHTML('<div id="js-edit_inplace-detail" class="acms-modal"><div class="acms-modal-dialog"></div></div>')).appendTo("body")}$.ajax({type:"GET",url:ACMS.Library.acmsLink({eid:eid,tpl:"admin/entry/edit.html",admin:"entry-edit",Query:{hash:Math.random().toString()}},true),dataType:"html",success:function(res){var action=
ACMS.Library.acmsLink({eid:eid,admin:"entry-edit",Query:{hash:Math.random().toString()}},true),html=res.replace(/ACMS_POST_Entry_Update/,"ACMS_POST_Entry_Update_Detail"),$raw=$($.parseHTML(html)).attr("action",action);$(".entryFormColumn, .formEntryAction, .js-revision_action",$raw).remove();if($detailBox.length){$("body").css("overflow","hidden");$detailBox.find(".acms-modal-dialog").append($raw).hide().fadeIn();$backdrop.show()}ACMS.Dispatch($detailBox);$(".cancelBtn").attr("onclick","").val("\u9589\u3058\u308b").bind("click",
function(){$("body").css("overflow","");$detailBox.fadeOut();$backdrop.fadeOut();return false})}})})};ACMS.Dispatch.Edit.tagassist=function(elm){$(elm).click(function(){ACMS.Dispatch.Edit._tagassist(this);return false})};
ACMS.Dispatch.Edit._refresh=function($unit){$unit.order=$(':input[name="sort[]"]',$unit).map(function(){this.preValue=$(this).val();return this.preValue});if(1&&$unit.$range.size()&&(0||""!==$unit.$range.val()||$unit.$more.nextAll(ACMS.Config.Edit.itemMark).size()))$unit.$range.val($unit.$more.prevAll(ACMS.Config.Edit.itemMark).size());if($unit.$more.size()){$unit.$more.prevAll(ACMS.Config.Edit.itemMark).each(function(){$(ACMS.Config.Edit.itemBodyMark,this).removeClass("outOfSummaryRange")});$unit.$more.nextAll(ACMS.Config.Edit.itemMark).each(function(){$(ACMS.Config.Edit.itemBodyMark,
this).addClass("outOfSummaryRange")})}};
ACMS.Dispatch.Edit._remove=function(item,$unit){var value=parseInt($(item).find(':input[name="sort[]"]',item).val(),10);$(ACMS.Config.Edit.itemMark,$unit).each(function(){$(this).find(':input[name="sort[]"] option').each(function(){var _value=$(this).attr("value");if(value==_value)$(this).remove();else if(value<_value){$(this).val(_value-1);$(this).text(_value-1)}})});if($unit.$range.size()){var rangeVal=$unit.$range.val();$unit.$range.find("option").each(function(){var _value=$(this).attr("value");
if(value==_value)$(this).remove();else if(value<_value){$(this).val(_value-1);$(this).text(_value-1)}});if(rangeVal>=value&&rangeVal>0)$unit.$range.val(rangeVal-1)}var type=$(':input[name="type[]"]',item).val(),$grave,$casket;if("image"==type||"file"==type){if(!$unit.next("#js-grave").size())$unit.after('<ul id="js-grave" style="display:none;"></ul>');$grave=$unit.next();$casket=$($.parseHTML("<li></li>"));$casket.append($(":input",item));$(':input[name^="'+type+'_edit_"]',$casket).val("delete").attr("checked",
true);$grave.append($casket)}$(item).remove()};
ACMS.Dispatch.Edit._sortable=function($unit){var Edit=this;$unit.sortable({handle:".sorthandle",zIndex:999,opacity:0.6,start:function(event,ui){if("wysiwyg"==$(':input[name^="text_tag_"]',ui.item).val()){var $textarea=$('textarea[name^="text_text_"]',ui.item);$textarea.data("emoditor").destroy();$textarea.removeData()}},stop:function(event,ui){if("wysiwyg"==$(':input[name^="text_tag_"]',ui.item).val())ACMS.Dispatch.emoditor($('textarea[name^="text_text_"]',ui.item));if($(ui.item).is(ACMS.Config.Edit.itemMark))$(':input[name="sort[]"]',
$unit).each(function(i){$(this).val($unit.order.get(i))});Edit._refresh($unit)}})};ACMS.Dispatch.Edit._range=function($unit){$unit.$range.change(function(){var range=$(this).val();if(parseInt(range,10)){var item=null;$unit.find(ACMS.Config.Edit.itemMark).each(function(i){if(range>=i+1)item=this});if(item){$unit.$more.detach();$(item).after($unit.$more)}}else if("0"===range){$unit.$more.detach();$unit.prepend($unit.$more)}else{$unit.$more.detach();$unit.append($unit.$more)}})};
ACMS.Dispatch.Edit.extendTagSelect=function(elm){var $self=$(elm);var $tag=$("[name^=text_tag_]",elm);var $field=$("[name^=text_extend_tag_]",elm);var $extend=$(".acms-extend-field",elm);var $xdata=$tag.children(":selected").data("tag_extend");if($xdata){$extend.text($xdata);$extend.show();$field.show()}$tag.change(function(){$xdata=$tag.children(":selected").data("tag_extend");if($xdata){$extend.text($xdata);$extend.show();$field.show()}else{$extend.text("");$extend.hide();$field.hide()}})};
ACMS.Dispatch.Edit.formUnitGroup=function(elm){var Config=ACMS.Config;var $sortable=$(elm);var $insert=$sortable.find(Config.fieldgroupSortableItemInsertMark);var $anchor=$sortable.find(Config.fieldgroupSortableItemTemplateMark);if($insert.size()&&$anchor.size()){var $template=$anchor.clone();$anchor.find(":input").attr("disabled","disabled");$anchor.hide();$insert.click(insert);var n=0;$sortable.find(Config.fieldgroupSortableItemMark).each(function(){var $block=$(this);n++});if(!n){var $clone=$template.clone();
$clone.removeClass(Config.fieldgroupSortableItemTemplateMark.substr(1));$(':input[name$="]"]',$clone).each(function(){this.name=this.name.replace(/\[\d*\]/,"[0]")});ACMS.Dispatch($clone);$anchor.before($clone)}$sortable.find(Config.fieldgroupSortableItemDeleteMark).click(function(){$(this).parents(Config.fieldgroupSortableItemMark).remove();return false})}$sortable.find(Config.fieldgroupSortableItemHandleMark).css("cursor","pointer");function insert(){var $clone=$template.clone();$clone.removeClass(Config.fieldgroupSortableItemTemplateMark.substr(1));
$clone.show();$clone.find(Config.fieldgroupSortableItemDeleteMark).click(function(){$(this).parents(Config.fieldgroupSortableItemMark).remove();return false});$anchor.before($clone);$clone.find(Config.fieldgroupSortableItemHandleMark).css("cursor","pointer");ACMS.Dispatch($clone);return false}function number($sortable){var $rows=$sortable.find(Config.fieldgroupSortableItemMark).not(Config.fieldgroupSortableItemTemplateMark);var n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){this.name=
n+"-"+this.name});n++});n=0;$rows.each(function(){$(':input[name$="]"]',this).each(function(){this.name=this.name.replace(/\[\d*\]/,"["+n+"]")});n++});n=0;$rows.each(function(){var regex=new RegExp("^"+n+"-");$(':input[name$="]"]',this).each(function(){this.name=this.name.replace(regex,"")});n++})}};
