WordPress/wp-admin/js/theme-plugin-editor.min.js

2 lines
11 KiB
JavaScript
Raw Permalink Normal View History

/*! This file is auto-generated */
window.wp||(window.wp={}),wp.themePluginEditor=function(i){"use strict";var t,o=wp.i18n.__,s=wp.i18n._n,r=wp.i18n.sprintf,n={codeEditor:{},instance:null,noticeElements:{},dirty:!1,lintErrors:[],init:function(e,t){n.form=e,t&&i.extend(n,t),n.noticeTemplate=wp.template("wp-file-editor-notice"),n.noticesContainer=n.form.find(".editor-notices"),n.submitButton=n.form.find(":input[name=submit]"),n.spinner=n.form.find(".submit .spinner"),n.form.on("submit",n.submit),n.textarea=n.form.find("#newcontent"),n.textarea.on("change",n.onChange),n.warning=i(".file-editor-warning"),n.docsLookUpButton=n.form.find("#docs-lookup"),n.docsLookUpList=n.form.find("#docs-list"),0<n.warning.length&&n.showWarning(),!1!==n.codeEditor&&_.defer(function(){n.initCodeEditor()}),i(n.initFileBrowser),i(window).on("beforeunload",function(){if(n.dirty)return o("The changes you made will be lost if you navigate away from this page.")}),n.docsLookUpList.on("change",function(){""===i(this).val()?n.docsLookUpButton.prop("disabled",!0):n.docsLookUpButton.prop("disabled",!1)})},showWarning:function(){var e=n.warning.find(".file-editor-warning-message").text();i("#wpwrap").attr("aria-hidden","true"),i(document.body).addClass("modal-open").append(n.warning.detach()),n.warning.removeClass("hidden").find(".file-editor-warning-go-back").trigger("focus"),n.warningTabbables=n.warning.find("a, button"),n.warningTabbables.on("keydown",n.constrainTabbing),n.warning.on("click",".file-editor-warning-dismiss",n.dismissWarning),setTimeout(function(){wp.a11y.speak(wp.sanitize.stripTags(e.replace(/\s+/g," ")),"assertive")},1e3)},constrainTabbing:function(e){var t,i;9===e.which&&(t=n.warningTabbables.first()[0],(i=n.warningTabbables.last()[0])!==e.target||e.shiftKey?t===e.target&&e.shiftKey&&(i.focus(),e.preventDefault()):(t.focus(),e.preventDefault()))},dismissWarning:function(){wp.ajax.post("dismiss-wp-pointer",{pointer:n.themeOrPlugin+"_editor_notice"}),n.warning.remove(),i("#wpwrap").removeAttr("aria-hidden"),i("body").removeClass("modal-open")},onChange:function(){n.dirty=!0,n.removeNotice("file_saved")},submit:function(e){var t={};e.preventDefault(),i.each(n.form.serializeArray(),function(){t[this.name]=this.value}),n.instance&&(t.newcontent=n.instance.codemirror.getValue()),n.isSaving||(n.lintErrors.length?n.instance.codemirror.setCursor(n.lintErrors[0].from.line):(n.isSaving=!0,n.textarea.prop("readonly",!0),n.instance&&n.instance.codemirror.setOption("readOnly",!0),n.spinner.addClass("is-active"),e=wp.ajax.post("edit-theme-plugin-file",t),n.lastSaveNoticeCode&&n.removeNotice(n.lastSaveNoticeCode),e.done(function(e){n.lastSaveNoticeCode="file_saved",n.addNotice({code:n.lastSaveNoticeCode,type:"success",message:e.message,dismissible:!0}),n.dirty=!1}),e.fail(function(e){e=i.extend({code:"save_error",message:o("An error occurred while saving your changes. Please try again. If the problem persists, you may need to manually update the file via FTP.")},e,{type:"error",dismissible:!0});n.lastSaveNoticeCode=e.code,n.addNotice(e)}),e.always(function(){n.spinner.removeClass("is-active"),n.isSaving=!1,n.textarea.prop("readonly",!1),n.instance&&n.instance.codemirror.setOption("readOnly",!1)})))},addNotice:function(e){var t;if(e.code)return n.removeNotice(e.code),(t=i(n.noticeTemplate(e))).hide(),t.find(".notice-dismiss").on("click",function(){n.removeNotice(e.code),e.onDismiss&&e.onDismiss(e)}),wp.a11y.speak(e.message),n.noticesContainer.append(t),t.slideDown("fast"),n.noticeElements[e.code]=t;throw new Error("Missing code.")},removeNotice:function(e){return!!n.noticeElements[e]&&(n.noticeElements[e].slideUp("fast",function(){i(this).remove()}),delete n.noticeElements[e],!0)},initCodeEditor:function(){var e,t=i.extend({},n.codeEditor);t.onTabPrevious=function(){i("#templateside").find(":tabbable").last().trigger("focus")},t.onTabNext=function(){i("#template").find(":tabbable:not(.CodeMirror-code)").first().trigger("focus")},t.onChangeLintingErrors=function(e){0===(n.lintErrors=e).length&&n.submitButton.toggleClass("disabled",!1)},t.onUpdateErrorNotice=function(e){n.submitButton.to