(function(b,a,c,d){b.CMB={formfield:"",iterator:0,file_frames:{},init:function(){CMB.log(b.cmb_l10);if(b.cmb_l10.new_admin_style){c(".cmb-spinner img").hide(); }c(".cmb_timepicker").each(function(){c("#"+jQuery(this).attr("id")).timePicker({startTime:"07:00",endTime:"22:00",show24Hours:false,separator:":",step:30}); });c(".cmb_datepicker").each(function(){c("#"+jQuery(this).attr("id")).datepicker();});c("#ui-datepicker-div").wrap('
');if(typeof jQuery.wp==="object"&&typeof jQuery.wp.wpColorPicker==="function"){c("input:text.cmb_colorpicker").wpColorPicker(); }else{c("input:text.cmb_colorpicker").each(function(e){c(this).after('
'); c("#picker-"+e).hide().farbtastic(c(this));}).focus(function(){c(this).next().show();}).blur(function(){c(this).next().hide();});}c(".cmb_metabox").on("change",".cmb_upload_file",function(){CMB.formfield=c(this).attr("name"); c("#"+CMB.formfield+"_id").val("");}).on("click",".cmb_upload_button",function(f){f.preventDefault();var j=c(this);CMB.formfield=j.prev("input").attr("name"); var i=c("#"+CMB.formfield);var e=true;var h=true;var g=j.hasClass("cmb_upload_list");if(CMB.formfield in CMB.file_frames){CMB.file_frames[CMB.formfield].open(); return;}CMB.file_frames[CMB.formfield]=wp.media.frames.file_frame=wp.media({title:c("label[for="+CMB.formfield+"]").text(),button:{text:b.cmb_l10.upload_file},multiple:g?true:false}); CMB.file_frames[CMB.formfield].on("select",function(){if(g){h=CMB.file_frames[CMB.formfield].state().get("selection").toJSON();i.val(h.url);c("#"+CMB.formfield+"_id").val(h.id); var k=[];c(h).each(function(){if(this.type&&this.type==="image"){e='
  • '+this.filename+'

    '+cmb_l10.remove_image+'

  • '; }else{e="
  • "+cmb_l10.file+" "+this.filename+'    ('+cmb_l10.download+' / '+cmb_l10.remove_file+')
  • '; }k.push(e);});c(k).each(function(){i.siblings(".cmb_media_status").slideDown().append(this);});}else{h=CMB.file_frames[CMB.formfield].state().get("selection").first().toJSON(); i.val(h.url);c("#"+CMB.formfield+"_id").val(h.id);if(h.type&&h.type==="image"){e='
    '+h.filename+'

    '+cmb_l10.remove_image+"

    "; }else{e=cmb_l10.file+" "+h.filename+'    ('+cmb_l10.download+' / '+cmb_l10.remove_file+")"; }i.siblings(".cmb_media_status").slideDown().html(e);}});CMB.file_frames[CMB.formfield].open();}).on("click",".cmb_remove_file_button",function(e){var g=c(this); if(g.is(".attach_list .cmb_remove_file_button")){g.parents("li").remove();return false;}CMB.formfield=g.attr("rel");var f=g.parents(".img_status");c("input#"+CMB.formfield).val(""); c("input#"+CMB.formfield+"_id").val("");if(!f.length){g.parents(".cmb_media_status").html("");}else{f.html("");}return false;}).on("click",".add-row-button",function(i){i.preventDefault(); var k=c(this);var h="#"+k.data("selector");var g=c(h);var j=c(".empty-row",g).clone(true);j.removeClass("empty-row").addClass("repeat-row");j.insertBefore(h+" tbody>tr:last"); var f=c("input.cmb_datepicker",j);var l=f.attr("id");f.attr("id",l+CMB.iterator);CMB.iterator++;}).on("click",".remove-row-button",function(g){g.preventDefault(); var h=c(this);var f=h.parents(".cmb-repeat-table");CMB.log("number of tbodys",f.length);CMB.log("number of trs",c("tr",f).length);if(c("tr",f).length>2){h.parents(".cmb-repeat-table tr").remove(); }}).on("keyup",".cmb_oembed",function(e){CMB.doAjax(c(this),e);});c(".cmb_oembed").bind("paste",function(g){var f=c(this);setTimeout(function(){CMB.doAjax(f,"paste"); },100);}).blur(function(){setTimeout(function(){CMB.spinner(".postbox table.cmb_metabox",true);},2000);});setTimeout(CMB.resizeoEmbeds,500);c(b).on("resize",CMB.resizeoEmbeds); },log:function(){if(b.cmb_l10.script_debug&&console&&typeof console.log==="function"){console.log.apply(console,arguments);}},spinner:function(f,e){if(e){c(".cmb-spinner",f).hide(); }else{c(".cmb-spinner",f).show();}},doAjax:function(m,l){var h=m.val();if(h.length<6){return;}if(l==="paste"||l.which<=90&&l.which>=48||l.which>=96&&l.which<=111||l.which==8||l.which==9||l.which==187||l.which==190){var j=m.attr("id"); var g=m.parents(".cmb_metabox tr td");var k=c(".embed_status",g);var f=m.width();var i=c(":first-child",k);f=(k.length&&i.length)?i.width():m.width();CMB.spinner(g); c(".embed_wrap",g).html("");setTimeout(function(){if(c(".cmb_oembed:focus").val()!=h){return;}c.ajax({type:"post",dataType:"json",url:b.cmb_l10.ajaxurl,data:{action:"cmb_oembed_handler",oembed_url:h,oembed_width:f>300?f:300,field_id:j,object_id:m.data("objectid"),object_type:m.data("objecttype"),cmb_ajax_nonce:b.cmb_l10.ajax_nonce},success:function(e){CMB.log(e); if(typeof e.id==="undefined"){return;}CMB.spinner(g,true);c(".embed_wrap",g).html(e.result);}});},500);}},resizeoEmbeds:function(){c("table.cmb_metabox").each(function(j){var m=c(this); var l=m.parents(".inside");if(!l.length){return true;}var i=l.width();var h=Math.round((i*0.82)*0.97)-30;if(h>639){return true;}var f=c(".cmb-type-oembed .embed_status",m).children().first(); var g=f.width();var k=f.height();var e=Math.round((h*k)/g);f.width(h).height(e);});}};c(a).ready(CMB.init);})(window,document,jQuery);