wp/wp-admin/js/code-editor.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
       
     1 /**
       
     2  * @output wp-admin/js/code-editor.js
       
     3  */
       
     4 
     1 if ( 'undefined' === typeof window.wp ) {
     5 if ( 'undefined' === typeof window.wp ) {
       
     6 	/**
       
     7 	 * @namespace wp
       
     8 	 */
     2 	window.wp = {};
     9 	window.wp = {};
     3 }
    10 }
     4 if ( 'undefined' === typeof window.wp.codeEditor ) {
    11 if ( 'undefined' === typeof window.wp.codeEditor ) {
       
    12 	/**
       
    13 	 * @namespace wp.codeEditor
       
    14 	 */
     5 	window.wp.codeEditor = {};
    15 	window.wp.codeEditor = {};
     6 }
    16 }
     7 
    17 
     8 ( function( $, wp ) {
    18 ( function( $, wp ) {
     9 	'use strict';
    19 	'use strict';
    31 	 * @param {CodeMirror} editor - Editor.
    41 	 * @param {CodeMirror} editor - Editor.
    32 	 * @param {object}     settings - Code editor settings.
    42 	 * @param {object}     settings - Code editor settings.
    33 	 * @param {object}     settings.codeMirror - Settings for CodeMirror.
    43 	 * @param {object}     settings.codeMirror - Settings for CodeMirror.
    34 	 * @param {Function}   settings.onChangeLintingErrors - Callback for when there are changes to linting errors.
    44 	 * @param {Function}   settings.onChangeLintingErrors - Callback for when there are changes to linting errors.
    35 	 * @param {Function}   settings.onUpdateErrorNotice - Callback to update error notice.
    45 	 * @param {Function}   settings.onUpdateErrorNotice - Callback to update error notice.
       
    46 	 *
    36 	 * @returns {void}
    47 	 * @returns {void}
    37 	 */
    48 	 */
    38 	function configureLinting( editor, settings ) { // eslint-disable-line complexity
    49 	function configureLinting( editor, settings ) { // eslint-disable-line complexity
    39 		var currentErrorAnnotations = [], previouslyShownErrorAnnotations = [];
    50 		var currentErrorAnnotations = [], previouslyShownErrorAnnotations = [];
    40 
    51 
   200 	 * @param {CodeMirror} codemirror - Editor.
   211 	 * @param {CodeMirror} codemirror - Editor.
   201 	 * @param {object}     settings - Code editor settings.
   212 	 * @param {object}     settings - Code editor settings.
   202 	 * @param {object}     settings.codeMirror - Settings for CodeMirror.
   213 	 * @param {object}     settings.codeMirror - Settings for CodeMirror.
   203 	 * @param {Function}   settings.onTabNext - Callback to handle tabbing to the next tabbable element.
   214 	 * @param {Function}   settings.onTabNext - Callback to handle tabbing to the next tabbable element.
   204 	 * @param {Function}   settings.onTabPrevious - Callback to handle tabbing to the previous tabbable element.
   215 	 * @param {Function}   settings.onTabPrevious - Callback to handle tabbing to the previous tabbable element.
       
   216 	 *
   205 	 * @returns {void}
   217 	 * @returns {void}
   206 	 */
   218 	 */
   207 	function configureTabbing( codemirror, settings ) {
   219 	function configureTabbing( codemirror, settings ) {
   208 		var $textarea = $( codemirror.getTextArea() );
   220 		var $textarea = $( codemirror.getTextArea() );
   209 
   221 
   238 			event.preventDefault();
   250 			event.preventDefault();
   239 		});
   251 		});
   240 	}
   252 	}
   241 
   253 
   242 	/**
   254 	/**
   243 	 * @typedef {object} CodeEditorInstance
   255 	 * @typedef {object} wp.codeEditor~CodeEditorInstance
   244 	 * @property {object} settings - The code editor settings.
   256 	 * @property {object} settings - The code editor settings.
   245 	 * @property {CodeMirror} codemirror - The CodeMirror instance.
   257 	 * @property {CodeMirror} codemirror - The CodeMirror instance.
   246 	 */
   258 	 */
   247 
   259 
   248 	/**
   260 	/**
   258 	 * @param {Function}              [settings.onTabNext] - Callback to handle tabbing to the next tabbable element.
   270 	 * @param {Function}              [settings.onTabNext] - Callback to handle tabbing to the next tabbable element.
   259 	 * @param {object}                [settings.codemirror] - Options for CodeMirror.
   271 	 * @param {object}                [settings.codemirror] - Options for CodeMirror.
   260 	 * @param {object}                [settings.csslint] - Rules for CSSLint.
   272 	 * @param {object}                [settings.csslint] - Rules for CSSLint.
   261 	 * @param {object}                [settings.htmlhint] - Rules for HTMLHint.
   273 	 * @param {object}                [settings.htmlhint] - Rules for HTMLHint.
   262 	 * @param {object}                [settings.jshint] - Rules for JSHint.
   274 	 * @param {object}                [settings.jshint] - Rules for JSHint.
       
   275 	 *
   263 	 * @returns {CodeEditorInstance} Instance.
   276 	 * @returns {CodeEditorInstance} Instance.
   264 	 */
   277 	 */
   265 	wp.codeEditor.initialize = function initialize( textarea, settings ) {
   278 	wp.codeEditor.initialize = function initialize( textarea, settings ) {
   266 		var $textarea, codemirror, instanceSettings, instance;
   279 		var $textarea, codemirror, instanceSettings, instance;
   267 		if ( 'string' === typeof textarea ) {
   280 		if ( 'string' === typeof textarea ) {