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

2 lines
12 KiB
JavaScript
Raw 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,n=wp.i18n.sprintf,r={codeEditor:{},instance:null,noticeElements:{},dirty:!1,lintErrors:[],init:function(e,t){r.form=e,t&&i.extend(r,t),r.noticeTemplate=wp.template("wp-file-editor-notice"),r.noticesContainer=r.form.find(".editor-notices"),r.submitButton=r.form.find(":input[name=submit]"),r.spinner=r.form.find(".submit .spinner"),r.form.on("submit",r.submit),r.textarea=r.form.find("#newcontent"),r.textarea.on("change",r.onChange),r.warning=i(".file-editor-warning"),r.docsLookUpButton=r.form.find("#docs-lookup"),r.docsLookUpList=r.form.find("#docs-list"),0<r.warning.length&&r.showWarning(),!1!==r.codeEditor&&_.defer(function(){r.initCodeEditor()}),i(r.initFileBrowser),i(window).on("beforeunload",function(){if(r.dirty)return o("The changes you made will be lost if you navigate away from this page.")}),r.docsLookUpList.on("change",function(){""===i(this).val()?r.docsLookUpButton.prop("disabled",!0):r.docsLookUpButton.prop("disabled",!1)})},showWarning:function(){var e=r.warning.find(".file-editor-warning-message").text();i("#wpwrap").attr("aria-hidden","true"),i(document.body).addClass("modal-open").append(r.warning.detach()),r.warning.removeClass("hidden").find(".file-editor-warning-go-back").trigger("focus"),r.warningTabbables=r.warning.find("a, button"),r.warningTabbables.on("keydown",r.constrainTabbing),r.warning.on("click",".file-editor-warning-dismiss",r.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=r.warningTabbables.first()[0],(i=r.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:r.themeOrPlugin+"_editor_notice"}),r.warning.remove(),i("#wpwrap").removeAttr("aria-hidden"),i("body").removeClass("modal-open")},onChange:function(){r.dirty=!0,r.removeNotice("file_saved")},submit:function(e){var t={};e.preventDefault(),i.each(r.form.serializeArray(),function(){t[this.name]=this.value}),r.instance&&(t.newcontent=r.instance.codemirror.getValue()),r.isSaving||(r.lintErrors.length?r.instance.codemirror.setCursor(r.lintErrors[0].from.line):(r.isSaving=!0,r.textarea.prop("readonly",!0),r.instance&&r.instance.codemirror.setOption("readOnly",!0),r.spinner.addClass("is-active"),e=wp.ajax.post("edit-theme-plugin-file",t),r.lastSaveNoticeCode&&r.removeNotice(r.lastSaveNoticeCode),e.done(function(e){r.lastSaveNoticeCode="file_saved",r.addNotice({code:r.lastSaveNoticeCode,type:"success",message:e.message,dismissible:!0}),r.dirty=!1}),e.fail(function(e){e=i.extend({code:"save_error",message:o("Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.")},e,{type:"error",dismissible:!0});r.lastSaveNoticeCode=e.code,r.addNotice(e)}),e.always(function(){r.spinner.removeClass("is-active"),r.isSaving=!1,r.textarea.prop("readonly",!1),r.instance&&r.instance.codemirror.setOption("readOnly",!1)})))},addNotice:function(e){var t;if(e.code)return r.removeNotice(e.code),(t=i(r.noticeTemplate(e))).hide(),t.find(".notice-dismiss").on("click",function(){r.removeNotice(e.code),e.onDismiss&&e.onDismiss(e)}),wp.a11y.speak(e.message),r.noticesContainer.append(t),t.slideDown("fast"),r.noticeElements[e.code]=t;throw new Error("Missing code.")},removeNotice:function(e){return!!r.noticeElements[e]&&(r.noticeElements[e].slideUp("fast",function(){i(this).remove()}),delete r.noticeElements[e],!0)},initCodeEditor:function(){var e,t=i.extend({},r.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===(r.lintErrors=e).length&&r.submitButton.toggleClass("disabled",!1)},t.onUpdateErrorNotice=fun