diff --git a/js/cmb2.js b/js/cmb2.js
index 23cadd2bd..b0ef7c376 100755
--- a/js/cmb2.js
+++ b/js/cmb2.js
@@ -23,6 +23,7 @@ window.CMB2 = (function(window, document, $, undefined){
repeatEls : 'input:not([type="button"]),select,textarea,.cmb2-media-status',
styleBreakPoint : 450,
mediaHandlers : {},
+ neweditor_id : [],
defaults : {
time_picker : l10n.defaults.time_picker,
date_picker : l10n.defaults.date_picker,
@@ -306,13 +307,13 @@ window.CMB2 = (function(window, document, $, undefined){
return false;
};
- $.fn.cleanRow = function( prevNum, group ) {
- var $self = $(this);
- var $inputs = $self.find( 'input:not([type="button"]), select, textarea, label' );
- var $other = $self.find('[id]').not( 'input:not([type="button"]), select, textarea, label' );
+ cmb.cleanRow = function( $row, prevNum, group ) {
+
+ var $inputs = $row.find( 'input:not([type="button"]), select, textarea, label' );
+ var $other = $row.find('[id]').not( 'input:not([type="button"]), select, textarea, label' );
if ( group ) {
// Remove extra ajaxed rows
- $self.find('.cmb-repeat-table .cmb-repeat-row:not(:first-child)').remove();
+ $row.find('.cmb-repeat-table .cmb-repeat-row:not(:first-child)').remove();
// Update all elements w/ an ID
if ( $other.length ) {
@@ -320,7 +321,7 @@ window.CMB2 = (function(window, document, $, undefined){
var $_this = $( this );
var oldID = $_this.attr( 'id' );
var newID = oldID.replace( '_'+ prevNum, '_'+ cmb.idNumber );
- var $buttons = $self.find('[data-selector="'+ oldID +'"]');
+ var $buttons = $row.find('[data-selector="'+ oldID +'"]');
$_this.attr( 'id', newID );
// Replace data-selector vars
@@ -335,8 +336,8 @@ window.CMB2 = (function(window, document, $, undefined){
$inputs.filter(':checked').prop( 'checked', false );
$inputs.filter(':selected').prop( 'selected', false );
- if ( $self.find('h3.cmb-group-title').length ) {
- $self.find( 'h3.cmb-group-title' ).text( $self.data( 'title' ).replace( '{#}', ( cmb.idNumber + 1 ) ) );
+ if ( $row.find('h3.cmb-group-title').length ) {
+ $row.find( 'h3.cmb-group-title' ).text( $row.data( 'title' ).replace( '{#}', ( cmb.idNumber + 1 ) ) );
}
$inputs.each( function(){
@@ -385,11 +386,11 @@ window.CMB2 = (function(window, document, $, undefined){
}
});
- return this;
+ return cmb;
};
- $.fn.newRowHousekeeping = function() {
- var $row = $(this);
+ cmb.newRowHousekeeping = function( $row ) {
+
var $colorPicker = $row.find( '.wp-picker-container' );
var $list = $row.find( '.cmb2-media-status' );
@@ -406,7 +407,7 @@ window.CMB2 = (function(window, document, $, undefined){
$list.empty();
}
- return this;
+ return cmb;
};
cmb.afterRowInsert = function( $row ) {
@@ -488,7 +489,8 @@ window.CMB2 = (function(window, document, $, undefined){
cmb.idNumber = prevNum + 1;
var $row = $oldRow.clone();
- $row.data( 'title', $self.data( 'grouptitle' ) ).newRowHousekeeping().cleanRow( prevNum, true ).find( '.cmb-add-row-button' ).prop( 'disabled', false );
+ cmb.newRowHousekeeping( $row.data( 'title', $self.data( 'grouptitle' ) ) ).cleanRow( $row, prevNum, true );
+ $row.find( '.cmb-add-row-button' ).prop( 'disabled', false );
var $newRow = $( '
'+ $row.html() +'
' );
$oldRow.after( $newRow );
@@ -514,7 +516,7 @@ window.CMB2 = (function(window, document, $, undefined){
cmb.idNumber = prevNum + 1;
var $row = $emptyrow.clone();
- $row.newRowHousekeeping().cleanRow( prevNum );
+ cmb.newRowHousekeeping( $row ).cleanRow( $row, prevNum );
$emptyrow.removeClass('empty-row hidden').addClass('cmb-repeat-row');
$emptyrow.after( $row );
diff --git a/js/cmb2.min.js b/js/cmb2.min.js
index b651424a5..9170bcea6 100644
--- a/js/cmb2.min.js
+++ b/js/cmb2.min.js
@@ -1 +1 @@
-window.CMB2=function(window,document,$){"use strict";var l10n=window.cmb2_l10,setTimeout=window.setTimeout,cmb={formfield:"",idNumber:!1,file_frames:{},repeatEls:'input:not([type="button"]),select,textarea,.cmb2-media-status',styleBreakPoint:450,mediaHandlers:{},defaults:{time_picker:l10n.defaults.time_picker,date_picker:l10n.defaults.date_picker,color_picker:l10n.defaults.color_picker||{}}},$id=function(selector){return $(document.getElementById(selector))};return cmb.metabox=function(){return cmb.$metabox?cmb.$metabox:(cmb.$metabox=$(".cmb2-wrap > .cmb2-metabox"),cmb.$metabox)},cmb.init=function(){cmb.log("CMB2 localized data",l10n);var $metabox=cmb.metabox(),$repeatGroup=$metabox.find(".cmb-repeatable-group");cmb.initPickers($metabox.find('input[type="text"].cmb2-timepicker'),$metabox.find('input[type="text"].cmb2-datepicker'),$metabox.find('input[type="text"].cmb2-colorpicker')),$id("ui-datepicker-div").wrap(''),$(''+l10n.strings.check_toggle+"
").insertBefore(".cmb2-checkbox-list:not(.no-select-all)"),cmb.makeListSortable(),$metabox.on("change",".cmb2_upload_file",function(){cmb.formfield=$(this).attr("id"),$id(cmb.formfield+"_id").val("")}).on("click",".cmb-multicheck-toggle",cmb.toggleCheckBoxes).on("click",".cmb2-upload-button",cmb.handleMedia).on("click",".cmb-attach-list li, .cmb2-media-status .img-status img, .cmb2-media-status .file-status > span",cmb.handleFileClick).on("click",".cmb2-remove-file-button",cmb.handleRemoveMedia).on("click",".cmb-add-group-row",cmb.addGroupRow).on("click",".cmb-add-row-button",cmb.addAjaxRow).on("click",".cmb-remove-group-row",cmb.removeGroupRow).on("click",".cmb-remove-row-button",cmb.removeAjaxRow).on("keyup paste focusout",".cmb2-oembed",cmb.maybeOembed).on("cmb2_remove_row",".cmb-repeatable-group",cmb.resetTitlesAndIterator).on("click",".cmbhandle, .cmbhandle + .cmbhandle-title",cmb.toggleHandle),$repeatGroup.length&&$repeatGroup.filter(".sortable").each(function(){$(this).find(".button.cmb-remove-group-row").before(' ')}).on("click",".cmb-shift-rows",cmb.shiftRows).on("cmb2_add_row",cmb.emptyValue),setTimeout(cmb.resizeoEmbeds,500),$(window).on("resize",cmb.resizeoEmbeds)},cmb.resetTitlesAndIterator=function(){$(".cmb-repeatable-group").each(function(){var $table=$(this);$table.find(".cmb-repeatable-grouping").each(function(rowindex){var $row=$(this);$row.data("iterator",rowindex),$row.find(".cmb-group-title h4").text($table.find(".cmb-add-group-row").data("grouptitle").replace("{#}",rowindex+1))})})},cmb.toggleHandle=function(evt){evt.preventDefault(),$(document).trigger("postbox-toggled",$(this).parent(".postbox").toggleClass("closed"))},cmb.toggleCheckBoxes=function(evt){evt.preventDefault();var $self=$(this),$multicheck=$self.closest(".cmb-td").find("input[type=checkbox]");$self.data("checked")?($multicheck.prop("checked",!1),$self.data("checked",!1)):($multicheck.prop("checked",!0),$self.data("checked",!0))},cmb.handleMedia=function(evt){evt.preventDefault();var $el=$(this);cmb.attach_id=$el.hasClass("cmb2-upload-list")?!1:$el.closest(".cmb-td").find(".cmb2-upload-file-id").val(),cmb.attach_id="0"!==cmb.attach_id?cmb.attach_id:!1,cmb._handleMedia($el.prev("input.cmb2-upload-file").attr("id"),$el.hasClass("cmb2-upload-list"))},cmb.handleFileClick=function(evt){evt.preventDefault();var $el=$(this),$td=$el.closest(".cmb-td"),isList=$td.find(".cmb2-upload-button").hasClass("cmb2-upload-list");cmb.attach_id=isList?$el.find('input[type="hidden"]').data("id"):$td.find(".cmb2-upload-file-id").val(),cmb.attach_id&&cmb._handleMedia($td.find("input.cmb2-upload-file").attr("id"),isList,cmb.attach_id)},cmb._handleMedia=function(formfield,isList){if(wp){var $metabox=cmb.metabox();cmb.formfield=formfield;var $formfield=$id(cmb.formfield),previewSize=$formfield.data("previewsize"),formName=$formfield.attr("name"),uploadStatus=!0,attachment=!0;if(cmb.formfield in cmb.file_frames)return void cmb.file_frames[cmb.formfield].open();cmb.file_frames[cmb.formfield]=wp.media({title:$metabox.find("label[for="+cmb.formfield+"]").text(),button:{text:l10n.strings.upload_file},multiple:isList?!0:!1}),cmb.mediaHandlers.list=function(selection,returnIt){attachment=selection.toJSON(),$formfield.val(attachment.url),$id(cmb.formfield+"_id").val(attachment.id);var fileGroup=[];return $(attachment).each(function(){if(this.type&&"image"===this.type){var width=previewSize[0]?previewSize[0]:50,height=previewSize[1]?previewSize[1]:50;uploadStatus=''+l10n.strings.remove_image+'
'}else uploadStatus=''+l10n.strings.file+" "+this.filename+' ('+l10n.strings.download+' / '+l10n.strings.remove_file+')';fileGroup.push(uploadStatus)}),returnIt?fileGroup:void $(fileGroup).each(function(){$formfield.siblings(".cmb2-media-status").slideDown().append(this)})},cmb.mediaHandlers.single=function(selection){if(attachment=selection.first().toJSON(),$formfield.val(attachment.url),$id(cmb.formfield+"_id").val(attachment.id),attachment.type&&"image"===attachment.type){var width=previewSize[0]?previewSize[0]:350;uploadStatus='"}else uploadStatus='";$formfield.siblings(".cmb2-media-status").slideDown().html(uploadStatus)},cmb.mediaHandlers.selectFile=function(){var selection=cmb.file_frames[cmb.formfield].state().get("selection"),type=isList?"list":"single";return cmb.attach_id&&isList?void $('[data-id="'+cmb.attach_id+'"]').parents("li").replaceWith(cmb.mediaHandlers.list(selection,!0)):void cmb.mediaHandlers[type](selection)},cmb.mediaHandlers.openModal=function(){var selection=cmb.file_frames[cmb.formfield].state().get("selection");if(!cmb.attach_id)return selection.reset();var attach=wp.media.attachment(cmb.attach_id);attach.fetch(),selection.set(attach?[attach]:[])},cmb.file_frames[cmb.formfield].on("select",cmb.mediaHandlers.selectFile).on("open",cmb.mediaHandlers.openModal),cmb.file_frames[cmb.formfield].open()}},cmb.handleRemoveMedia=function(evt){evt.preventDefault();var $self=$(this);return $self.is(".cmb-attach-list .cmb2-remove-file-button")?($self.parents("li").remove(),!1):(cmb.formfield=$self.attr("rel"),cmb.metabox().find("input#"+cmb.formfield).val(""),cmb.metabox().find("input#"+cmb.formfield+"_id").val(""),$self.parents(".cmb2-media-status").html(""),!1)},$.fn.cleanRow=function(prevNum,group){var $self=$(this),$inputs=$self.find('input:not([type="button"]), select, textarea, label'),$other=$self.find("[id]").not('input:not([type="button"]), select, textarea, label');return group&&($self.find(".cmb-repeat-table .cmb-repeat-row:not(:first-child)").remove(),$other.length&&$other.each(function(){var $_this=$(this),oldID=$_this.attr("id"),newID=oldID.replace("_"+prevNum,"_"+cmb.idNumber),$buttons=$self.find('[data-selector="'+oldID+'"]');$_this.attr("id",newID),$buttons.length&&$buttons.attr("data-selector",newID).data("selector",newID)})),cmb.neweditor_id=[],$inputs.filter(":checked").prop("checked",!1),$inputs.filter(":selected").prop("selected",!1),$self.find("h3.cmb-group-title").length&&$self.find("h3.cmb-group-title").text($self.data("title").replace("{#}",cmb.idNumber+1)),$inputs.each(function(){var newID,oldID,$newInput=$(this),isEditor=$newInput.hasClass("wp-editor-area"),oldFor=$newInput.attr("for"),attrs={};if(oldFor)attrs={"for":oldFor.replace("_"+prevNum,"_"+cmb.idNumber)};else{var oldName=$newInput.attr("name"),newName=oldName?oldName.replace("["+prevNum+"]","["+cmb.idNumber+"]"):"";oldID=$newInput.attr("id"),newID=oldID?oldID.replace("_"+prevNum,"_"+cmb.idNumber):"",attrs={id:newID,name:newName,"data-iterator":cmb.idNumber}}if($newInput.removeClass("hasDatepicker").attr(attrs).val(""),isEditor){newID=newID?oldID.replace("zx"+prevNum,"zx"+cmb.idNumber):"",$newInput.html("");var $wysiwyg=$newInput.parents(".cmb-type-wysiwyg");$wysiwyg.find(".mce-tinymce:not(:first-child)").remove();var html=$wysiwyg.html().replace(new RegExp(oldID,"g"),newID);$wysiwyg.html(html),cmb.neweditor_id.push({id:newID,old:oldID})}}),this},$.fn.newRowHousekeeping=function(){var $row=$(this),$colorPicker=$row.find(".wp-picker-container"),$list=$row.find(".cmb2-media-status");return $colorPicker.length&&$colorPicker.each(function(){var $td=$(this).parent();$td.html($td.find('input[type="text"].cmb2-colorpicker').attr("style",""))}),$list.length&&$list.empty(),this},cmb.afterRowInsert=function($row){var _prop;if(cmb.neweditor_id.length){var i;for(i=cmb.neweditor_id.length-1;i>=0;i--){var id=cmb.neweditor_id[i].id,old=cmb.neweditor_id[i].old;if("undefined"==typeof tinyMCEPreInit.mceInit[id]){var newSettings=jQuery.extend({},tinyMCEPreInit.mceInit[old]);for(_prop in newSettings)"string"==typeof newSettings[_prop]&&(newSettings[_prop]=newSettings[_prop].replace(new RegExp(old,"g"),id));tinyMCEPreInit.mceInit[id]=newSettings}if("undefined"==typeof tinyMCEPreInit.qtInit[id]){var newQTS=jQuery.extend({},tinyMCEPreInit.qtInit[old]);for(_prop in newQTS)"string"==typeof newQTS[_prop]&&(newQTS[_prop]=newQTS[_prop].replace(new RegExp(old,"g"),id));tinyMCEPreInit.qtInit[id]=newQTS}tinyMCE.init({id:tinyMCEPreInit.mceInit[id]})}}cmb.initPickers($row.find('input[type="text"].cmb2-timepicker'),$row.find('input[type="text"].cmb2-datepicker'),$row.find('input[type="text"].cmb2-colorpicker'))},cmb.updateNameAttr=function(){var $this=$(this),name=$this.attr("name");if("undefined"==typeof name)return!1;var prevNum=parseInt($this.parents(".cmb-repeatable-grouping").data("iterator")),newNum=prevNum-1,$newName=name.replace("["+prevNum+"]","["+newNum+"]");$this.attr("name",$newName)},cmb.emptyValue=function(evt,row){$('input:not([type="button"]), textarea',row).val("")},cmb.addGroupRow=function(evt){evt.preventDefault();var $self=$(this);$self.trigger("cmb2_add_group_row_start",$self);var $table=$id($self.data("selector")),$oldRow=$table.find(".cmb-repeatable-grouping").last(),prevNum=parseInt($oldRow.data("iterator"));cmb.idNumber=prevNum+1;var $row=$oldRow.clone();$row.data("title",$self.data("grouptitle")).newRowHousekeeping().cleanRow(prevNum,!0).find(".cmb-add-row-button").prop("disabled",!1);var $newRow=$(''+$row.html()+"
");$oldRow.after($newRow),cmb.afterRowInsert($newRow),$table.find(".cmb-repeatable-grouping").length<=1?$table.find(".cmb-remove-group-row").prop("disabled",!0):$table.find(".cmb-remove-group-row").prop("disabled",!1),$table.trigger("cmb2_add_row",$newRow)},cmb.addAjaxRow=function(evt){evt.preventDefault();var $self=$(this),$table=$id($self.data("selector")),$emptyrow=$table.find(".empty-row"),prevNum=parseInt($emptyrow.find("[data-iterator]").data("iterator"));cmb.idNumber=prevNum+1;var $row=$emptyrow.clone();$row.newRowHousekeeping().cleanRow(prevNum),$emptyrow.removeClass("empty-row hidden").addClass("cmb-repeat-row"),$emptyrow.after($row),cmb.afterRowInsert($row),$table.trigger("cmb2_add_row",$row),$table.find(".cmb-remove-row-button").removeClass("button-disabled")},cmb.removeGroupRow=function(evt){evt.preventDefault();var $self=$(this),$table=$id($self.data("selector")),$parent=$self.parents(".cmb-repeatable-grouping"),number=$table.find(".cmb-repeatable-grouping").length;number>1&&($table.trigger("cmb2_remove_group_row_start",$self),$parent.nextAll(".cmb-repeatable-grouping").find(cmb.repeatEls).each(cmb.updateNameAttr),$parent.remove(),2>=number?$table.find(".cmb-remove-group-row").prop("disabled",!0):$table.find(".cmb-remove-group-row").prop("disabled",!1),$table.trigger("cmb2_remove_row"))},cmb.removeAjaxRow=function(evt){evt.preventDefault();var $self=$(this);if(!$self.hasClass("button-disabled")){var $parent=$self.parents(".cmb-row"),$table=$self.parents(".cmb-repeat-table"),number=$table.find(".cmb-row").length;number>2?($parent.hasClass("empty-row")&&$parent.prev().addClass("empty-row").removeClass("cmb-repeat-row"),$self.parents(".cmb-repeat-table .cmb-row").remove(),3===number&&$table.find(".cmb-remove-row-button").addClass("button-disabled"),$table.trigger("cmb2_remove_row")):$self.addClass("button-disabled")}},cmb.shiftRows=function(evt){evt.preventDefault();var $self=$(this);$self.trigger("cmb2_shift_rows_enter",$self);var $parent=$self.parents(".cmb-repeatable-grouping"),$goto=$self.hasClass("move-up")?$parent.prev(".cmb-repeatable-grouping"):$parent.next(".cmb-repeatable-grouping");if($goto.length){$self.trigger("cmb2_shift_rows_start",$self);var inputVals=[];$parent.find(cmb.repeatEls).each(function(){var val,$element=$(this);val=$element.hasClass("cmb2-media-status")?$element.html():"checkbox"===$element.attr("type")||"radio"===$element.attr("type")?$element.is(":checked"):"select"===$element.prop("tagName")?$element.is(":selected"):$element.val(),inputVals.push({val:val,$:$element})}),$goto.find(cmb.repeatEls).each(function(index){var val,$element=$(this);$element.hasClass("cmb2-media-status")?(val=$element.html(),$element.html(inputVals[index].val),inputVals[index].$.html(val)):"checkbox"===$element.attr("type")||"radio"===$element.attr("type")?(inputVals[index].$.prop("checked",$element.is(":checked")),$element.prop("checked",inputVals[index].val)):"select"===$element.prop("tagName")?(inputVals[index].$.prop("selected",$element.is(":selected")),$element.prop("selected",inputVals[index].val)):(inputVals[index].$.val($element.val()),$element.val(inputVals[index].val))}),$self.trigger("cmb2_shift_rows_complete",$self)}},cmb.initPickers=function($timePickers,$datePickers,$colorPickers){cmb.initTimePickers($timePickers),cmb.initDatePickers($datePickers),cmb.initColorPickers($colorPickers)},cmb.initTimePickers=function($selector){$selector.length&&($selector.timepicker("destroy"),$selector.timepicker(cmb.defaults.time_picker))},cmb.initDatePickers=function($selector){$selector.length&&($selector.datepicker("destroy"),$selector.datepicker(cmb.defaults.date_picker))},cmb.initColorPickers=function($selector){$selector.length&&("object"==typeof jQuery.wp&&"function"==typeof jQuery.wp.wpColorPicker?$selector.wpColorPicker(cmb.defaults.color_picker):$selector.each(function(i){$(this).after(''),$id("picker-"+i).hide().farbtastic($(this))}).focus(function(){$(this).next().show()}).blur(function(){$(this).next().hide()}))},cmb.makeListSortable=function(){var $filelist=cmb.metabox().find(".cmb2-media-status.cmb-attach-list");$filelist.length&&$filelist.sortable({cursor:"move"}).disableSelection()},cmb.maybeOembed=function(evt){var $self=$(this),type=evt.type,m={focusout:function(){setTimeout(function(){cmb.spinner(".postbox .cmb2-metabox",!0)},2e3)},keyup:function(){var betw=function(min,max){return evt.which<=max&&evt.which>=min};(betw(48,90)||betw(96,111)||betw(8,9)||187===evt.which||190===evt.which)&&cmb.doAjax($self,evt)},paste:function(){setTimeout(function(){cmb.doAjax($self)},100)}};m[type]()},cmb.resizeoEmbeds=function(){cmb.metabox().each(function(){var $self=$(this),$tableWrap=$self.parents(".inside"),isSide=$self.parents(".inner-sidebar").length||$self.parents("#side-sortables").length,isSmall=isSide,isSmallest=!1;if(!$tableWrap.length)return!0;var tableW=$tableWrap.width();cmb.styleBreakPoint>tableW&&(isSmall=!0,isSmallest=cmb.styleBreakPoint-62>tableW),tableW=isSmall?tableW:Math.round(.82*$tableWrap.width()*.97);var newWidth=tableW-30;if(!isSmall||isSide||isSmallest||(newWidth-=75),newWidth>639)return!0;var $embeds=$self.find(".cmb-type-oembed .embed-status"),$children=$embeds.children().not(".cmb2-remove-wrapper");return $children.length?void $children.each(function(){var $self=$(this),iwidth=$self.width(),iheight=$self.height(),_newWidth=newWidth;$self.parents(".cmb-repeat-row").length&&!isSmall&&(_newWidth=newWidth-91,_newWidth=785>tableW?_newWidth-15:_newWidth);var newHeight=Math.round(_newWidth*iheight/iwidth);$self.width(_newWidth).height(newHeight)}):!0})},cmb.log=function(){l10n.script_debug&&console&&"function"==typeof console.log&&console.log.apply(console,arguments)},cmb.spinner=function($context,hide){hide?$(".cmb-spinner",$context).hide():$(".cmb-spinner",$context).show()},cmb.doAjax=function($obj){var oembed_url=$obj.val();if(!(oembed_url.length<6)){var field_id=$obj.attr("id"),$context=$obj.parents(".cmb-repeat-table .cmb-row .cmb-td");$context=$context.length?$context:$obj.parents(".cmb2-metabox .cmb-row .cmb-td");var embed_container=$(".embed-status",$context),oembed_width=$obj.width(),child_el=$(":first-child",embed_container);cmb.log("oembed_url",oembed_url,field_id),oembed_width=embed_container.length&&child_el.length?child_el.width():$obj.width(),cmb.spinner($context),$(".embed_wrap",$context).html(""),setTimeout(function(){$(".cmb2-oembed:focus").val()===oembed_url&&$.ajax({type:"post",dataType:"json",url:l10n.ajaxurl,data:{action:"cmb2_oembed_handler",oembed_url:oembed_url,oembed_width:oembed_width>300?oembed_width:300,field_id:field_id,object_id:$obj.data("objectid"),object_type:$obj.data("objecttype"),cmb2_ajax_nonce:l10n.ajax_nonce},success:function(response){cmb.log(response),cmb.spinner($context,!0),$(".embed_wrap",$context).html(response.data)}})},500)}},$(document).ready(cmb.init),cmb}(window,document,jQuery);
+window.CMB2=function(window,document,$){"use strict";var l10n=window.cmb2_l10,setTimeout=window.setTimeout,cmb={formfield:"",idNumber:!1,file_frames:{},repeatEls:'input:not([type="button"]),select,textarea,.cmb2-media-status',styleBreakPoint:450,mediaHandlers:{},neweditor_id:[],defaults:{time_picker:l10n.defaults.time_picker,date_picker:l10n.defaults.date_picker,color_picker:l10n.defaults.color_picker||{}}},$id=function(selector){return $(document.getElementById(selector))};return cmb.metabox=function(){return cmb.$metabox?cmb.$metabox:(cmb.$metabox=$(".cmb2-wrap > .cmb2-metabox"),cmb.$metabox)},cmb.init=function(){cmb.log("CMB2 localized data",l10n);var $metabox=cmb.metabox(),$repeatGroup=$metabox.find(".cmb-repeatable-group");cmb.initPickers($metabox.find('input[type="text"].cmb2-timepicker'),$metabox.find('input[type="text"].cmb2-datepicker'),$metabox.find('input[type="text"].cmb2-colorpicker')),$id("ui-datepicker-div").wrap(''),$(''+l10n.strings.check_toggle+"
").insertBefore(".cmb2-checkbox-list:not(.no-select-all)"),cmb.makeListSortable(),$metabox.on("change",".cmb2_upload_file",function(){cmb.formfield=$(this).attr("id"),$id(cmb.formfield+"_id").val("")}).on("click",".cmb-multicheck-toggle",cmb.toggleCheckBoxes).on("click",".cmb2-upload-button",cmb.handleMedia).on("click",".cmb-attach-list li, .cmb2-media-status .img-status img, .cmb2-media-status .file-status > span",cmb.handleFileClick).on("click",".cmb2-remove-file-button",cmb.handleRemoveMedia).on("click",".cmb-add-group-row",cmb.addGroupRow).on("click",".cmb-add-row-button",cmb.addAjaxRow).on("click",".cmb-remove-group-row",cmb.removeGroupRow).on("click",".cmb-remove-row-button",cmb.removeAjaxRow).on("keyup paste focusout",".cmb2-oembed",cmb.maybeOembed).on("cmb2_remove_row",".cmb-repeatable-group",cmb.resetTitlesAndIterator).on("click",".cmbhandle, .cmbhandle + .cmbhandle-title",cmb.toggleHandle),$repeatGroup.length&&$repeatGroup.filter(".sortable").each(function(){$(this).find(".button.cmb-remove-group-row").before(' ')}).on("click",".cmb-shift-rows",cmb.shiftRows).on("cmb2_add_row",cmb.emptyValue),setTimeout(cmb.resizeoEmbeds,500),$(window).on("resize",cmb.resizeoEmbeds)},cmb.resetTitlesAndIterator=function(){$(".cmb-repeatable-group").each(function(){var $table=$(this);$table.find(".cmb-repeatable-grouping").each(function(rowindex){var $row=$(this);$row.data("iterator",rowindex),$row.find(".cmb-group-title h4").text($table.find(".cmb-add-group-row").data("grouptitle").replace("{#}",rowindex+1))})})},cmb.toggleHandle=function(evt){evt.preventDefault(),$(document).trigger("postbox-toggled",$(this).parent(".postbox").toggleClass("closed"))},cmb.toggleCheckBoxes=function(evt){evt.preventDefault();var $self=$(this),$multicheck=$self.closest(".cmb-td").find("input[type=checkbox]");$self.data("checked")?($multicheck.prop("checked",!1),$self.data("checked",!1)):($multicheck.prop("checked",!0),$self.data("checked",!0))},cmb.handleMedia=function(evt){evt.preventDefault();var $el=$(this);cmb.attach_id=$el.hasClass("cmb2-upload-list")?!1:$el.closest(".cmb-td").find(".cmb2-upload-file-id").val(),cmb.attach_id="0"!==cmb.attach_id?cmb.attach_id:!1,cmb._handleMedia($el.prev("input.cmb2-upload-file").attr("id"),$el.hasClass("cmb2-upload-list"))},cmb.handleFileClick=function(evt){evt.preventDefault();var $el=$(this),$td=$el.closest(".cmb-td"),isList=$td.find(".cmb2-upload-button").hasClass("cmb2-upload-list");cmb.attach_id=isList?$el.find('input[type="hidden"]').data("id"):$td.find(".cmb2-upload-file-id").val(),cmb.attach_id&&cmb._handleMedia($td.find("input.cmb2-upload-file").attr("id"),isList,cmb.attach_id)},cmb._handleMedia=function(formfield,isList){if(wp){var $metabox=cmb.metabox();cmb.formfield=formfield;var $formfield=$id(cmb.formfield),previewSize=$formfield.data("previewsize"),formName=$formfield.attr("name"),uploadStatus=!0,attachment=!0;if(cmb.formfield in cmb.file_frames)return void cmb.file_frames[cmb.formfield].open();cmb.file_frames[cmb.formfield]=wp.media({title:$metabox.find("label[for="+cmb.formfield+"]").text(),button:{text:l10n.strings.upload_file},multiple:isList?!0:!1}),cmb.mediaHandlers.list=function(selection,returnIt){attachment=selection.toJSON(),$formfield.val(attachment.url),$id(cmb.formfield+"_id").val(attachment.id);var fileGroup=[];return $(attachment).each(function(){if(this.type&&"image"===this.type){var width=previewSize[0]?previewSize[0]:50,height=previewSize[1]?previewSize[1]:50;uploadStatus=''+l10n.strings.remove_image+'
'}else uploadStatus=''+l10n.strings.file+" "+this.filename+' ('+l10n.strings.download+' / '+l10n.strings.remove_file+')';fileGroup.push(uploadStatus)}),returnIt?fileGroup:void $(fileGroup).each(function(){$formfield.siblings(".cmb2-media-status").slideDown().append(this)})},cmb.mediaHandlers.single=function(selection){if(attachment=selection.first().toJSON(),$formfield.val(attachment.url),$id(cmb.formfield+"_id").val(attachment.id),attachment.type&&"image"===attachment.type){var width=previewSize[0]?previewSize[0]:350;uploadStatus='"}else uploadStatus='";$formfield.siblings(".cmb2-media-status").slideDown().html(uploadStatus)},cmb.mediaHandlers.selectFile=function(){var selection=cmb.file_frames[cmb.formfield].state().get("selection"),type=isList?"list":"single";return cmb.attach_id&&isList?void $('[data-id="'+cmb.attach_id+'"]').parents("li").replaceWith(cmb.mediaHandlers.list(selection,!0)):void cmb.mediaHandlers[type](selection)},cmb.mediaHandlers.openModal=function(){var selection=cmb.file_frames[cmb.formfield].state().get("selection");if(!cmb.attach_id)return selection.reset();var attach=wp.media.attachment(cmb.attach_id);attach.fetch(),selection.set(attach?[attach]:[])},cmb.file_frames[cmb.formfield].on("select",cmb.mediaHandlers.selectFile).on("open",cmb.mediaHandlers.openModal),cmb.file_frames[cmb.formfield].open()}},cmb.handleRemoveMedia=function(evt){evt.preventDefault();var $self=$(this);return $self.is(".cmb-attach-list .cmb2-remove-file-button")?($self.parents("li").remove(),!1):(cmb.formfield=$self.attr("rel"),cmb.metabox().find("input#"+cmb.formfield).val(""),cmb.metabox().find("input#"+cmb.formfield+"_id").val(""),$self.parents(".cmb2-media-status").html(""),!1)},cmb.cleanRow=function($row,prevNum,group){var $inputs=$row.find('input:not([type="button"]), select, textarea, label'),$other=$row.find("[id]").not('input:not([type="button"]), select, textarea, label');return group&&($row.find(".cmb-repeat-table .cmb-repeat-row:not(:first-child)").remove(),$other.length&&$other.each(function(){var $_this=$(this),oldID=$_this.attr("id"),newID=oldID.replace("_"+prevNum,"_"+cmb.idNumber),$buttons=$row.find('[data-selector="'+oldID+'"]');$_this.attr("id",newID),$buttons.length&&$buttons.attr("data-selector",newID).data("selector",newID)})),cmb.neweditor_id=[],$inputs.filter(":checked").prop("checked",!1),$inputs.filter(":selected").prop("selected",!1),$row.find("h3.cmb-group-title").length&&$row.find("h3.cmb-group-title").text($row.data("title").replace("{#}",cmb.idNumber+1)),$inputs.each(function(){var newID,oldID,$newInput=$(this),isEditor=$newInput.hasClass("wp-editor-area"),oldFor=$newInput.attr("for"),attrs={};if(oldFor)attrs={"for":oldFor.replace("_"+prevNum,"_"+cmb.idNumber)};else{var oldName=$newInput.attr("name"),newName=oldName?oldName.replace("["+prevNum+"]","["+cmb.idNumber+"]"):"";oldID=$newInput.attr("id"),newID=oldID?oldID.replace("_"+prevNum,"_"+cmb.idNumber):"",attrs={id:newID,name:newName,"data-iterator":cmb.idNumber}}if($newInput.removeClass("hasDatepicker").attr(attrs).val(""),isEditor){newID=newID?oldID.replace("zx"+prevNum,"zx"+cmb.idNumber):"",$newInput.html("");var $wysiwyg=$newInput.parents(".cmb-type-wysiwyg");$wysiwyg.find(".mce-tinymce:not(:first-child)").remove();var html=$wysiwyg.html().replace(new RegExp(oldID,"g"),newID);$wysiwyg.html(html),cmb.neweditor_id.push({id:newID,old:oldID})}}),cmb},cmb.newRowHousekeeping=function($row){var $colorPicker=$row.find(".wp-picker-container"),$list=$row.find(".cmb2-media-status");return $colorPicker.length&&$colorPicker.each(function(){var $td=$(this).parent();$td.html($td.find('input[type="text"].cmb2-colorpicker').attr("style",""))}),$list.length&&$list.empty(),cmb},cmb.afterRowInsert=function($row){var _prop;if(cmb.neweditor_id.length){var i;for(i=cmb.neweditor_id.length-1;i>=0;i--){var id=cmb.neweditor_id[i].id,old=cmb.neweditor_id[i].old;if("undefined"==typeof tinyMCEPreInit.mceInit[id]){var newSettings=jQuery.extend({},tinyMCEPreInit.mceInit[old]);for(_prop in newSettings)"string"==typeof newSettings[_prop]&&(newSettings[_prop]=newSettings[_prop].replace(new RegExp(old,"g"),id));tinyMCEPreInit.mceInit[id]=newSettings}if("undefined"==typeof tinyMCEPreInit.qtInit[id]){var newQTS=jQuery.extend({},tinyMCEPreInit.qtInit[old]);for(_prop in newQTS)"string"==typeof newQTS[_prop]&&(newQTS[_prop]=newQTS[_prop].replace(new RegExp(old,"g"),id));tinyMCEPreInit.qtInit[id]=newQTS}tinyMCE.init({id:tinyMCEPreInit.mceInit[id]})}}cmb.initPickers($row.find('input[type="text"].cmb2-timepicker'),$row.find('input[type="text"].cmb2-datepicker'),$row.find('input[type="text"].cmb2-colorpicker'))},cmb.updateNameAttr=function(){var $this=$(this),name=$this.attr("name");if("undefined"==typeof name)return!1;var prevNum=parseInt($this.parents(".cmb-repeatable-grouping").data("iterator")),newNum=prevNum-1,$newName=name.replace("["+prevNum+"]","["+newNum+"]");$this.attr("name",$newName)},cmb.emptyValue=function(evt,row){$('input:not([type="button"]), textarea',row).val("")},cmb.addGroupRow=function(evt){evt.preventDefault();var $self=$(this);$self.trigger("cmb2_add_group_row_start",$self);var $table=$id($self.data("selector")),$oldRow=$table.find(".cmb-repeatable-grouping").last(),prevNum=parseInt($oldRow.data("iterator"));cmb.idNumber=prevNum+1;var $row=$oldRow.clone();cmb.newRowHousekeeping($row.data("title",$self.data("grouptitle"))).cleanRow($row,prevNum,!0),$row.find(".cmb-add-row-button").prop("disabled",!1);var $newRow=$(''+$row.html()+"
");$oldRow.after($newRow),cmb.afterRowInsert($newRow),$table.find(".cmb-repeatable-grouping").length<=1?$table.find(".cmb-remove-group-row").prop("disabled",!0):$table.find(".cmb-remove-group-row").prop("disabled",!1),$table.trigger("cmb2_add_row",$newRow)},cmb.addAjaxRow=function(evt){evt.preventDefault();var $self=$(this),$table=$id($self.data("selector")),$emptyrow=$table.find(".empty-row"),prevNum=parseInt($emptyrow.find("[data-iterator]").data("iterator"));cmb.idNumber=prevNum+1;var $row=$emptyrow.clone();cmb.newRowHousekeeping($row).cleanRow($row,prevNum),$emptyrow.removeClass("empty-row hidden").addClass("cmb-repeat-row"),$emptyrow.after($row),cmb.afterRowInsert($row),$table.trigger("cmb2_add_row",$row),$table.find(".cmb-remove-row-button").removeClass("button-disabled")},cmb.removeGroupRow=function(evt){evt.preventDefault();var $self=$(this),$table=$id($self.data("selector")),$parent=$self.parents(".cmb-repeatable-grouping"),number=$table.find(".cmb-repeatable-grouping").length;number>1&&($table.trigger("cmb2_remove_group_row_start",$self),$parent.nextAll(".cmb-repeatable-grouping").find(cmb.repeatEls).each(cmb.updateNameAttr),$parent.remove(),2>=number?$table.find(".cmb-remove-group-row").prop("disabled",!0):$table.find(".cmb-remove-group-row").prop("disabled",!1),$table.trigger("cmb2_remove_row"))},cmb.removeAjaxRow=function(evt){evt.preventDefault();var $self=$(this);if(!$self.hasClass("button-disabled")){var $parent=$self.parents(".cmb-row"),$table=$self.parents(".cmb-repeat-table"),number=$table.find(".cmb-row").length;number>2?($parent.hasClass("empty-row")&&$parent.prev().addClass("empty-row").removeClass("cmb-repeat-row"),$self.parents(".cmb-repeat-table .cmb-row").remove(),3===number&&$table.find(".cmb-remove-row-button").addClass("button-disabled"),$table.trigger("cmb2_remove_row")):$self.addClass("button-disabled")}},cmb.shiftRows=function(evt){evt.preventDefault();var $self=$(this);$self.trigger("cmb2_shift_rows_enter",$self);var $parent=$self.parents(".cmb-repeatable-grouping"),$goto=$self.hasClass("move-up")?$parent.prev(".cmb-repeatable-grouping"):$parent.next(".cmb-repeatable-grouping");if($goto.length){$self.trigger("cmb2_shift_rows_start",$self);var inputVals=[];$parent.find(cmb.repeatEls).each(function(){var val,$element=$(this);val=$element.hasClass("cmb2-media-status")?$element.html():"checkbox"===$element.attr("type")||"radio"===$element.attr("type")?$element.is(":checked"):"select"===$element.prop("tagName")?$element.is(":selected"):$element.val(),inputVals.push({val:val,$:$element})}),$goto.find(cmb.repeatEls).each(function(index){var val,$element=$(this);$element.hasClass("cmb2-media-status")?(val=$element.html(),$element.html(inputVals[index].val),inputVals[index].$.html(val)):"checkbox"===$element.attr("type")||"radio"===$element.attr("type")?(inputVals[index].$.prop("checked",$element.is(":checked")),$element.prop("checked",inputVals[index].val)):"select"===$element.prop("tagName")?(inputVals[index].$.prop("selected",$element.is(":selected")),$element.prop("selected",inputVals[index].val)):(inputVals[index].$.val($element.val()),$element.val(inputVals[index].val))}),$self.trigger("cmb2_shift_rows_complete",$self)}},cmb.initPickers=function($timePickers,$datePickers,$colorPickers){cmb.initTimePickers($timePickers),cmb.initDatePickers($datePickers),cmb.initColorPickers($colorPickers)},cmb.initTimePickers=function($selector){$selector.length&&($selector.timepicker("destroy"),$selector.timepicker(cmb.defaults.time_picker))},cmb.initDatePickers=function($selector){$selector.length&&($selector.datepicker("destroy"),$selector.datepicker(cmb.defaults.date_picker))},cmb.initColorPickers=function($selector){$selector.length&&("object"==typeof jQuery.wp&&"function"==typeof jQuery.wp.wpColorPicker?$selector.wpColorPicker(cmb.defaults.color_picker):$selector.each(function(i){$(this).after(''),$id("picker-"+i).hide().farbtastic($(this))}).focus(function(){$(this).next().show()}).blur(function(){$(this).next().hide()}))},cmb.makeListSortable=function(){var $filelist=cmb.metabox().find(".cmb2-media-status.cmb-attach-list");$filelist.length&&$filelist.sortable({cursor:"move"}).disableSelection()},cmb.maybeOembed=function(evt){var $self=$(this),type=evt.type,m={focusout:function(){setTimeout(function(){cmb.spinner(".postbox .cmb2-metabox",!0)},2e3)},keyup:function(){var betw=function(min,max){return evt.which<=max&&evt.which>=min};(betw(48,90)||betw(96,111)||betw(8,9)||187===evt.which||190===evt.which)&&cmb.doAjax($self,evt)},paste:function(){setTimeout(function(){cmb.doAjax($self)},100)}};m[type]()},cmb.resizeoEmbeds=function(){cmb.metabox().each(function(){var $self=$(this),$tableWrap=$self.parents(".inside"),isSide=$self.parents(".inner-sidebar").length||$self.parents("#side-sortables").length,isSmall=isSide,isSmallest=!1;if(!$tableWrap.length)return!0;var tableW=$tableWrap.width();cmb.styleBreakPoint>tableW&&(isSmall=!0,isSmallest=cmb.styleBreakPoint-62>tableW),tableW=isSmall?tableW:Math.round(.82*$tableWrap.width()*.97);var newWidth=tableW-30;if(!isSmall||isSide||isSmallest||(newWidth-=75),newWidth>639)return!0;var $embeds=$self.find(".cmb-type-oembed .embed-status"),$children=$embeds.children().not(".cmb2-remove-wrapper");return $children.length?void $children.each(function(){var $self=$(this),iwidth=$self.width(),iheight=$self.height(),_newWidth=newWidth;$self.parents(".cmb-repeat-row").length&&!isSmall&&(_newWidth=newWidth-91,_newWidth=785>tableW?_newWidth-15:_newWidth);var newHeight=Math.round(_newWidth*iheight/iwidth);$self.width(_newWidth).height(newHeight)}):!0})},cmb.log=function(){l10n.script_debug&&console&&"function"==typeof console.log&&console.log.apply(console,arguments)},cmb.spinner=function($context,hide){hide?$(".cmb-spinner",$context).hide():$(".cmb-spinner",$context).show()},cmb.doAjax=function($obj){var oembed_url=$obj.val();if(!(oembed_url.length<6)){var field_id=$obj.attr("id"),$context=$obj.parents(".cmb-repeat-table .cmb-row .cmb-td");$context=$context.length?$context:$obj.parents(".cmb2-metabox .cmb-row .cmb-td");var embed_container=$(".embed-status",$context),oembed_width=$obj.width(),child_el=$(":first-child",embed_container);cmb.log("oembed_url",oembed_url,field_id),oembed_width=embed_container.length&&child_el.length?child_el.width():$obj.width(),cmb.spinner($context),$(".embed_wrap",$context).html(""),setTimeout(function(){$(".cmb2-oembed:focus").val()===oembed_url&&$.ajax({type:"post",dataType:"json",url:l10n.ajaxurl,data:{action:"cmb2_oembed_handler",oembed_url:oembed_url,oembed_width:oembed_width>300?oembed_width:300,field_id:field_id,object_id:$obj.data("objectid"),object_type:$obj.data("objecttype"),cmb2_ajax_nonce:l10n.ajax_nonce},success:function(response){cmb.log(response),cmb.spinner($context,!0),$(".embed_wrap",$context).html(response.data)}})},500)}},$(document).ready(cmb.init),cmb}(window,document,jQuery);
\ No newline at end of file