mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-14 22:56:19 +01:00
fdad915022
The recommended approach for any plugins using these globals or properties is to switch to the newer `wp.i18n` functions. In the meantime, this ensures that accessing any of these globals does not break the rest of the code on the page, and an appropriate warning message is logged to the JavaScript console. Follow-up to: https://core.trac.wordpress.org/query?summary=~wp.i18n&milestone=5.5 Props omarreiss, peterwilsoncc, kbjohnson90, johnbillion, TimothyBlynJacobs, joostdevalk, ocean90, desrosj, SergeyBiryukov. Merges [48923] to the 5.5 branch. Fixes #51123. Built from https://develop.svn.wordpress.org/branches/5.5@48925 git-svn-id: http://core.svn.wordpress.org/branches/5.5@48687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
/*! This file is auto-generated */
|
|
window.wp||(window.wp={}),wp.themePluginEditor=function(o){"use strict";var s,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)return n("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(){var e=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){var t,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){var t,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){var t=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){var t;if(!e.code)throw new Error("Missing code.");return s.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()}),delete s.noticeElements[e],!0)},initCodeEditor:function(){var t,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.submitButton.toggleClass("disabled",0<e.length),0!==e.length?s.addNotice({code:"lint_errors",type:"error",message:r(i("There is %s error which must be fixed before you can update this file.","There are %s errors which must be fixed before you can update this file.",e.length),String(e.length)),dismissible:!1}).find("input[type=checkbox]").on("click",function(){t.onChangeLintingErrors([]),s.removeNotice("lint_errors")}):s.removeNotice("lint_errors")},(e=wp.codeEditor.initialize(o("#newcontent"),t)).codemirror.on("change",s.onChange),o(e.codemirror.display.lineDiv).attr({role:"textbox","aria-multiline":"true","aria-labelledby":"theme-plugin-editor-label","aria-describedby":"editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"}),o("#theme-plugin-editor-label").on("click",function(){e.codemirror.focus()}),s.instance=e},initFileBrowser:function(){var e=o("#templateside");e.find('[role="group"]').parent().attr("aria-expanded",!1),e.find(".notice").parents("[aria-expanded]").attr("aria-expanded",!0),e.find('[role="tree"]').each(function(){new t(this).init()}),e.find(".current-file:first").each(function(){this.scrollIntoViewIfNeeded?this.scrollIntoViewIfNeeded():this.scrollIntoView(!1)})}};var a=(e.prototype.init=function(){this.domNode.tabIndex=-1,this.domNode.getAttribute("role")||this.domNode.setAttribute("role","treeitem"),this.domNode.addEventListener("keydown",this.handleKeydown.bind(this)),this.domNode.addEventListener("click",this.handleClick.bind(this)),this.domNode.addEventListener("focus",this.handleFocus.bind(this)),this.domNode.addEventListener("blur",this.handleBlur.bind(this)),this.isExpandable?(this.domNode.firstElementChild.addEventListener("mouseover",this.handleMouseOver.bind(this)),this.domNode.firstElementChild.addEventListener("mouseout",this.handleMouseOut.bind(this))):(this.domNode.addEventListener("mouseover",this.handleMouseOver.bind(this)),this.domNode.addEventListener("mouseout",this.handleMouseOut.bind(this)))},e.prototype.isExpanded=function(){return!!this.isExpandable&&"true"===this.domNode.getAttribute("aria-expanded")},e.prototype.handleKeydown=function(e){e.currentTarget;var t=!1,i=e.key;function o(e){return 1===e.length&&e.match(/\S/)}function s(e){"*"==i?(e.tree.expandAllSiblingItems(e),t=!0):o(i)&&(e.tree.setFocusByFirstCharacter(e,i),t=!0)}if(this.stopDefaultClick=!1,!(e.altKey||e.ctrlKey||e.metaKey)){if(e.shift)e.keyCode==this.keyCode.SPACE||e.keyCode==this.keyCode.RETURN?(e.stopPropagation(),this.stopDefaultClick=!0):o(i)&&s(this);else switch(e.keyCode){case this.keyCode.SPACE:case this.keyCode.RETURN:this.isExpandable?(this.isExpanded()?this.tree.collapseTreeitem(this):this.tree.expandTreeitem(this),t=!0):(e.stopPropagation(),this.stopDefaultClick=!0);break;case this.keyCode.UP:this.tree.setFocusToPreviousItem(this),t=!0;break;case this.keyCode.DOWN:this.tree.setFocusToNextItem(this),t=!0;break;case this.keyCode.RIGHT:this.isExpandable&&(this.isExpanded()?this.tree.setFocusToNextItem(this):this.tree.expandTreeitem(this)),t=!0;break;case this.keyCode.LEFT:this.isExpandable&&this.isExpanded()?(this.tree.collapseTreeitem(this),t=!0):this.inGroup&&(this.tree.setFocusToParentItem(this),t=!0);break;case this.keyCode.HOME:this.tree.setFocusToFirstItem(),t=!0;break;case this.keyCode.END:this.tree.setFocusToLastItem(),t=!0;break;default:o(i)&&s(this)}t&&(e.stopPropagation(),e.preventDefault())}},e.prototype.handleClick=function(e){e.target!==this.domNode&&e.target!==this.domNode.firstElementChild||this.isExpandable&&(this.isExpanded()?this.tree.collapseTreeitem(this):this.tree.expandTreeitem(this),e.stopPropagation())},e.prototype.handleFocus=function(e){var t=this.domNode;this.isExpandable&&(t=t.firstElementChild),t.classList.add("focus")},e.prototype.handleBlur=function(e){var t=this.domNode;this.isExpandable&&(t=t.firstElementChild),t.classList.remove("focus")},e.prototype.handleMouseOver=function(e){e.currentTarget.classList.add("hover")},e.prototype.handleMouseOut=function(e){e.currentTarget.classList.remove("hover")},e);function e(e,t,i){if("object"==typeof e){e.tabIndex=-1,this.tree=t,this.groupTreeitem=i,this.domNode=e,this.label=e.textContent.trim(),this.stopDefaultClick=!1,e.getAttribute("aria-label")&&(this.label=e.getAttribute("aria-label").trim()),this.isExpandable=!1,this.isVisible=!1,this.inGroup=!1,i&&(this.inGroup=!0);for(var o=e.firstElementChild;o;){if("ul"==o.tagName.toLowerCase()){o.setAttribute("role","group"),this.isExpandable=!0;break}o=o.nextElementSibling}this.keyCode=Object.freeze({RETURN:13,SPACE:32,PAGEUP:33,PAGEDOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40})}}function d(e){"object"==typeof e&&(this.domNode=e,this.treeitems=[],this.firstChars=[],this.firstTreeitem=null,this.lastTreeitem=null)}return d.prototype.init=function(){this.domNode.getAttribute("role")||this.domNode.setAttribute("role","tree"),function e(t,i,o){for(var s=t.firstElementChild,n=o;s;)("li"===s.tagName.toLowerCase()&&"span"===s.firstElementChild.tagName.toLowerCase()||"a"===s.tagName.toLowerCase())&&((n=new a(s,i,o)).init(),i.treeitems.push(n),i.firstChars.push(n.label.substring(0,1).toLowerCase())),s.firstElementChild&&e(s,i,n),s=s.nextElementSibling}(this.domNode,this,!1),this.updateVisibleTreeitems(),this.firstTreeitem.domNode.tabIndex=0},d.prototype.setFocusToItem=function(e){for(var t=0;t<this.treeitems.length;t++){var i=this.treeitems[t];i===e?(i.domNode.tabIndex=0,i.domNode.focus()):i.domNode.tabIndex=-1}},d.prototype.setFocusToNextItem=function(e){for(var t=!1,i=this.treeitems.length-1;0<=i;i--){var o=this.treeitems[i];if(o===e)break;o.isVisible&&(t=o)}t&&this.setFocusToItem(t)},d.prototype.setFocusToPreviousItem=function(e){for(var t=!1,i=0;i<this.treeitems.length;i++){var o=this.treeitems[i];if(o===e)break;o.isVisible&&(t=o)}t&&this.setFocusToItem(t)},d.prototype.setFocusToParentItem=function(e){e.groupTreeitem&&this.setFocusToItem(e.groupTreeitem)},d.prototype.setFocusToFirstItem=function(){this.setFocusToItem(this.firstTreeitem)},d.prototype.setFocusToLastItem=function(){this.setFocusToItem(this.lastTreeitem)},d.prototype.expandTreeitem=function(e){e.isExpandable&&(e.domNode.setAttribute("aria-expanded",!0),this.updateVisibleTreeitems())},d.prototype.expandAllSiblingItems=function(e){for(var t=0;t<this.treeitems.length;t++){var i=this.treeitems[t];i.groupTreeitem===e.groupTreeitem&&i.isExpandable&&this.expandTreeitem(i)}},d.prototype.collapseTreeitem=function(e){var t=!1;(t=e.isExpanded()?e:e.groupTreeitem)&&(t.domNode.setAttribute("aria-expanded",!1),this.updateVisibleTreeitems(),this.setFocusToItem(t))},d.prototype.updateVisibleTreeitems=function(){this.firstTreeitem=this.treeitems[0];for(var e=0;e<this.treeitems.length;e++){var t=this.treeitems[e],i=t.domNode.parentNode;for(t.isVisible=!0;i&&i!==this.domNode;)"false"==i.getAttribute("aria-expanded")&&(t.isVisible=!1),i=i.parentNode;t.isVisible&&(this.lastTreeitem=t)}},d.prototype.setFocusByFirstCharacter=function(e,t){var i,o;t=t.toLowerCase(),(i=this.treeitems.indexOf(e)+1)===this.treeitems.length&&(i=0),-1===(o=this.getIndexFirstChars(i,t))&&(o=this.getIndexFirstChars(0,t)),-1<o&&this.setFocusToItem(this.treeitems[o])},d.prototype.getIndexFirstChars=function(e,t){for(var i=e;i<this.firstChars.length;i++)if(this.treeitems[i].isVisible&&t===this.firstChars[i])return i;return-1},t=d,s}(jQuery),wp.themePluginEditor.l10n=wp.themePluginEditor.l10n||{saveAlert:"",saveError:"",lintError:{alternative:"wp.i18n",func:function(){return{singular:"",plural:""}}}},wp.themePluginEditor.l10n=window.wp.deprecateL10nObject("wp.themePluginEditor.l10n",wp.themePluginEditor.l10n); |