mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-27 19:47:42 +01:00
49007e52bc
Patches occasionally come in on generated files. We should be kind to new contributors and give them a hint that these files are auto-generated. This is a follow-up to [41271], which added the banner to minified CSS files. Fixes #48424. See #30666. Built from https://develop.svn.wordpress.org/trunk@46589 git-svn-id: http://core.svn.wordpress.org/trunk@46386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
/*! This file is auto-generated */
|
|
window.wp||(window.wp={}),wp.themePluginEditor=function(s){"use strict";var o,t;o={l10n:{lintError:{singular:"",plural:""},saveAlert:"",saveError:""},codeEditor:{},instance:null,noticeElements:{},dirty:!1,lintErrors:[],init:function(e,t){o.form=e,t&&s.extend(o,t),o.noticeTemplate=wp.template("wp-file-editor-notice"),o.noticesContainer=o.form.find(".editor-notices"),o.submitButton=o.form.find(":input[name=submit]"),o.spinner=o.form.find(".submit .spinner"),o.form.on("submit",o.submit),o.textarea=o.form.find("#newcontent"),o.textarea.on("change",o.onChange),o.warning=s(".file-editor-warning"),o.docsLookUpButton=o.form.find("#docs-lookup"),o.docsLookUpList=o.form.find("#docs-list"),0<o.warning.length&&o.showWarning(),!1!==o.codeEditor&&_.defer(function(){o.initCodeEditor()}),s(o.initFileBrowser),s(window).on("beforeunload",function(){if(o.dirty)return o.l10n.saveAlert}),o.docsLookUpList.on("change",function(){""===s(this).val()?o.docsLookUpButton.prop("disabled",!0):o.docsLookUpButton.prop("disabled",!1)})},showWarning:function(){var e=o.warning.find(".file-editor-warning-message").text();s("#wpwrap").attr("aria-hidden","true"),s(document.body).addClass("modal-open").append(o.warning.detach()),o.warning.removeClass("hidden").find(".file-editor-warning-go-back").focus(),o.warningTabbables=o.warning.find("a, button"),o.warningTabbables.on("keydown",o.constrainTabbing),o.warning.on("click",".file-editor-warning-dismiss",o.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=o.warningTabbables.first()[0],(i=o.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:o.themeOrPlugin+"_editor_notice"}),o.warning.remove(),s("#wpwrap").removeAttr("aria-hidden"),s("body").removeClass("modal-open")},onChange:function(){o.dirty=!0,o.removeNotice("file_saved")},submit:function(e){var t,i={};e.preventDefault(),s.each(o.form.serializeArray(),function(){i[this.name]=this.value}),o.instance&&(i.newcontent=o.instance.codemirror.getValue()),o.isSaving||(o.lintErrors.length?o.instance.codemirror.setCursor(o.lintErrors[0].from.line):(o.isSaving=!0,o.textarea.prop("readonly",!0),o.instance&&o.instance.codemirror.setOption("readOnly",!0),o.spinner.addClass("is-active"),t=wp.ajax.post("edit-theme-plugin-file",i),o.lastSaveNoticeCode&&o.removeNotice(o.lastSaveNoticeCode),t.done(function(e){o.lastSaveNoticeCode="file_saved",o.addNotice({code:o.lastSaveNoticeCode,type:"success",message:e.message,dismissible:!0}),o.dirty=!1}),t.fail(function(e){var t=s.extend({code:"save_error",message:o.l10n.saveError},e,{type:"error",dismissible:!0});o.lastSaveNoticeCode=t.code,o.addNotice(t)}),t.always(function(){o.spinner.removeClass("is-active"),o.isSaving=!1,o.textarea.prop("readonly",!1),o.instance&&o.instance.codemirror.setOption("readOnly",!1)})))},addNotice:function(e){var t;if(!e.code)throw new Error("Missing code.");return o.removeNotice(e.code),(t=s(o.noticeTemplate(e))).hide(),t.find(".notice-dismiss").on("click",function(){o.removeNotice(e.code),e.onDismiss&&e.onDismiss(e)}),wp.a11y.speak(e.message),o.noticesContainer.append(t),t.slideDown("fast"),o.noticeElements[e.code]=t},removeNotice:function(e){return!!o.noticeElements[e]&&(o.noticeElements[e].slideUp("fast",function(){s(this).remove()}),delete o.noticeElements[e],!0)},initCodeEditor:function(){var i,e;(i=s.extend({},o.codeEditor)).onTabPrevious=function(){s("#templateside").find(":tabbable").last().focus()},i.onTabNext=function(){s("#template").find(":tabbable:not(.CodeMirror-code)").first().focus()},i.onChangeLintingErrors=function(e){0===(o.lintErrors=e).length&&o.submitButton.toggleClass("disabled",!1)},i.onUpdateErrorNotice=function(e){var t;o.submitButton.toggleClass("disabled",0<e.length),0!==e.length?(t=1===e.length?o.l10n.lintError.singular.replace("%d","1"):o.l10n.lintError.plural.replace("%d",String(e.length)),o.addNotice({code:"lint_errors",type:"error",message:t,dismissible:!1}).find("input[type=checkbox]").on("click",function(){i.onChangeLintingErrors([]),o.removeNotice("lint_errors")})):o.removeNotice("lint_errors")},(e=wp.codeEditor.initialize(s("#newcontent"),i)).codemirror.on("change",o.onChange),s(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"}),s("#theme-plugin-editor-label").on("click",function(){e.codemirror.focus()}),o.instance=e},initFileBrowser:function(){var e=s("#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 n=(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 s(e){return 1===e.length&&e.match(/\S/)}function o(e){"*"==i?(e.tree.expandAllSiblingItems(e),t=!0):s(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):s(i)&&o(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:s(i)&&o(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 s=e.firstElementChild;s;){if("ul"==s.tagName.toLowerCase()){s.setAttribute("role","group"),this.isExpandable=!0;break}s=s.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 i(e){"object"==typeof e&&(this.domNode=e,this.treeitems=[],this.firstChars=[],this.firstTreeitem=null,this.lastTreeitem=null)}return i.prototype.init=function(){this.domNode.getAttribute("role")||this.domNode.setAttribute("role","tree"),function e(t,i,s){for(var o=t.firstElementChild,r=s;o;)("li"===o.tagName.toLowerCase()&&"span"===o.firstElementChild.tagName.toLowerCase()||"a"===o.tagName.toLowerCase())&&((r=new n(o,i,s)).init(),i.treeitems.push(r),i.firstChars.push(r.label.substring(0,1).toLowerCase())),o.firstElementChild&&e(o,i,r),o=o.nextElementSibling}(this.domNode,this,!1),this.updateVisibleTreeitems(),this.firstTreeitem.domNode.tabIndex=0},i.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}},i.prototype.setFocusToNextItem=function(e){for(var t=!1,i=this.treeitems.length-1;0<=i;i--){var s=this.treeitems[i];if(s===e)break;s.isVisible&&(t=s)}t&&this.setFocusToItem(t)},i.prototype.setFocusToPreviousItem=function(e){for(var t=!1,i=0;i<this.treeitems.length;i++){var s=this.treeitems[i];if(s===e)break;s.isVisible&&(t=s)}t&&this.setFocusToItem(t)},i.prototype.setFocusToParentItem=function(e){e.groupTreeitem&&this.setFocusToItem(e.groupTreeitem)},i.prototype.setFocusToFirstItem=function(){this.setFocusToItem(this.firstTreeitem)},i.prototype.setFocusToLastItem=function(){this.setFocusToItem(this.lastTreeitem)},i.prototype.expandTreeitem=function(e){e.isExpandable&&(e.domNode.setAttribute("aria-expanded",!0),this.updateVisibleTreeitems())},i.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)}},i.prototype.collapseTreeitem=function(e){var t=!1;(t=e.isExpanded()?e:e.groupTreeitem)&&(t.domNode.setAttribute("aria-expanded",!1),this.updateVisibleTreeitems(),this.setFocusToItem(t))},i.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)}},i.prototype.setFocusByFirstCharacter=function(e,t){var i,s;t=t.toLowerCase(),(i=this.treeitems.indexOf(e)+1)===this.treeitems.length&&(i=0),-1===(s=this.getIndexFirstChars(i,t))&&(s=this.getIndexFirstChars(0,t)),-1<s&&this.setFocusToItem(this.treeitems[s])},i.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=i,o}(jQuery); |