1 line
29 KiB
JavaScript
1 line
29 KiB
JavaScript
|
window.CMB2=window.CMB2||{},function(window,document,$,cmb,undefined){"use strict";var $document,l10n=window.cmb2_l10,setTimeout=window.setTimeout,$id=function(selector){return $(document.getElementById(selector))},defaults={idNumber:!1,repeatEls:'input:not([type="button"],[id^=filelist]),select,textarea,.cmb2-media-status',noEmpty:'input:not([type="button"]):not([type="radio"]):not([type="checkbox"]),textarea',repeatUpdate:'input:not([type="button"]),select,textarea,label',styleBreakPoint:450,mediaHandlers:{},defaults:{time_picker:l10n.defaults.time_picker,date_picker:l10n.defaults.date_picker,color_picker:l10n.defaults.color_picker||{},code_editor:l10n.defaults.code_editor},media:{frames:{}}};cmb.init=function(){$document=$(document),$.extend(cmb,defaults),cmb.trigger("cmb_pre_init");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')),cmb.initCodeEditors($metabox.find(".cmb2-textarea-code:not(.disable-codemirror)")),$('<p><span class="button-secondary cmb-multicheck-toggle">'+l10n.strings.check_toggle+"</span></p>").insertBefore(".cmb2-checkbox-list:not(.no-select-all)"),cmb.makeListSortable(),cmb.makeRepeatableSortable(),$metabox.on("change",".cmb2_upload_file",function(){cmb.media.field=$(this).attr("id"),$id(cmb.media.field+"_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.on("cmb2_add_row",cmb.emptyValue).on("cmb2_add_row",cmb.setDefaults).filter(".sortable").each(function(){$(this).find(".cmb-remove-group-row-button").before('<a class="button-secondary cmb-shift-rows move-up alignleft" href="#"><span class="'+l10n.up_arrow_class+'"></span></a> <a class="button-secondary cmb-shift-rows move-down alignleft" href="#"><span class="'+l10n.down_arrow_class+'"></span></a>')}).on("click",".cmb-shift-rows",cmb.shiftRows),setTimeout(cmb.resizeoEmbeds,500),$(window).on("resize",cmb.resizeoEmbeds),$id("addtag").length&&cmb.listenTagAdd(),$(document).on("cmb_init",cmb.mceEnsureSave),cmb.trigger("cmb_init")},cmb.mceEnsureSave=function(){wp.data&&wp.data.hasOwnProperty("subscribe")&&cmb.canTinyMCE()&&wp.data.subscribe(function(){var editor=wp.data.hasOwnProperty("select")?wp.data.select("core/editor"):null;if(editor&&editor.isSavingPost&&editor.isSavingPost()&&window.tinyMCE.editors.length)for(var i=0;i<window.tinyMCE.editors.length;i++)window.tinyMCE.activeEditor!==window.tinyMCE.editors[i]&&window.tinyMCE.editors[i].save()})},cmb.canTinyMCE=function(){return l10n.user_can_richedit&&window.tinyMCE},cmb.listenTagAdd=function(){$document.ajaxSuccess(function(evt,xhr,settings){settings.data&&settings.data.length&&-1!==settings.data.indexOf("action=add-tag")&&cmb.resetBoxes($id("addtag").find(".cmb2-wrap > .cmb2-metabox"))})},cmb.resetBoxes=function($boxes){$.each($boxes,function(){cmb.resetBox($(this))})},cmb.resetBox=function($box){$box.find(".wp-picker-clear").trigger("click"),$box.find(".cmb2-remove-file-button").trigger("click"),$box.find(".cmb-row.cmb-repeatable-grouping:not(:first-of-type) .cmb-remove-group-row").click(),$box.find(".cmb-repeat-row:not(:first-child)").remove(),$box.find('input:not([type="button"]),select,textarea').each(function(){var $element=$(this),tagName=$element.prop("tagName");if("INPUT"===tagName){var elT
|