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