WordPress/wp-admin/js/code-editor.min.js

1 line
3.0 KiB
JavaScript

void 0===window.wp&&(window.wp={}),void 0===window.wp.codeEditor&&(window.wp.codeEditor={}),function(l,d){"use strict";d.codeEditor.defaultSettings={codemirror:{},csslint:{},htmlhint:{},jshint:{},onTabNext:function(){},onTabPrevious:function(){},onChangeLintingErrors:function(){},onUpdateErrorNotice:function(){}},d.codeEditor.initialize=function(t,n){var e,a,o,i;return e=l("string"==typeof t?"#"+t:t),(o=l.extend({},d.codeEditor.defaultSettings,n)).codemirror=l.extend({},o.codemirror),function(r,s){var a=[],d=[];function c(){s.onUpdateErrorNotice&&!_.isEqual(a,d)&&(s.onUpdateErrorNotice(a,r),d=a)}function u(){var i,t=r.getOption("lint");return!!t&&(!0===t?t={}:_.isObject(t)&&(t=l.extend({},t)),t.options||(t.options={}),"javascript"===s.codemirror.mode&&s.jshint&&l.extend(t.options,s.jshint),"css"===s.codemirror.mode&&s.csslint&&l.extend(t.options,s.csslint),"htmlmixed"===s.codemirror.mode&&s.htmlhint&&(t.options.rules=l.extend({},s.htmlhint),s.jshint&&(t.options.rules.jshint=s.jshint),s.csslint&&(t.options.rules.csslint=s.csslint)),t.onUpdateLinting=(i=t.onUpdateLinting,function(t,n,e){var o=_.filter(t,function(t){return"error"===t.severity});i&&i.apply(t,n,e),_.isEqual(o,a)||(a=o,s.onChangeLintingErrors&&s.onChangeLintingErrors(o,t,n,e),(!r.state.focused||0===a.length||0<d.length)&&c())}),t)}r.setOption("lint",u()),r.on("optionChange",function(t,n){var e,o,i="CodeMirror-lint-markers";"lint"===n&&(o=r.getOption("gutters")||[],!0===(e=r.getOption("lint"))?(_.contains(o,i)||r.setOption("gutters",[i].concat(o)),r.setOption("lint",u())):e||r.setOption("gutters",_.without(o,i)),r.getOption("lint")?r.performLint():(a=[],c()))}),r.on("blur",c),r.on("startCompletion",function(){r.off("blur",c)}),r.on("endCompletion",function(){r.on("blur",c),_.delay(function(){r.state.focused||c()},500)}),l(document.body).on("mousedown",function(t){!r.state.focused||l.contains(r.display.wrapper,t.target)||l(t.target).hasClass("CodeMirror-hint")||c()})}(a=d.CodeMirror.fromTextArea(e[0],o.codemirror),o),i={settings:o,codemirror:a},a.showHint&&a.on("keyup",function(t,n){var e,o,i,r,s=/^[a-zA-Z]$/.test(n.key);a.state.completionActive&&s||"string"!==(r=a.getTokenAt(a.getCursor())).type&&"comment"!==r.type&&(i=d.CodeMirror.innerMode(a.getMode(),r.state).mode.name,o=a.doc.getLine(a.doc.getCursor().line).substr(0,a.doc.getCursor().ch),"html"===i||"xml"===i?e="<"===n.key||"/"===n.key&&"tag"===r.type||s&&"tag"===r.type||s&&"attribute"===r.type||"="===r.string&&r.state.htmlState&&r.state.htmlState.tagName:"css"===i?e=s||":"===n.key||" "===n.key&&/:\s+$/.test(o):"javascript"===i?e=s||"."===n.key:"clike"===i&&"php"===a.options.mode&&(e="keyword"===r.type||"variable"===r.type),e&&a.showHint({completeSingle:!1}))}),function(e,o){var i=l(e.getTextArea());e.on("blur",function(){i.data("next-tab-blurs",!1)}),e.on("keydown",function(t,n){27!==n.keyCode?9===n.keyCode&&i.data("next-tab-blurs")&&(n.shiftKey?o.onTabPrevious(e,n):o.onTabNext(e,n),i.data("next-tab-blurs",!1),n.preventDefault()):i.data("next-tab-blurs",!0)})}(a,n),i}}(window.jQuery,window.wp);