@@ -2,15 +2,15 @@ import $ from 'jquery';
22import { AJAX } from './ajax.js' ;
33import { Navigation } from './navigation.js' ;
44import { CommonActions , CommonParams } from './common.js' ;
5- import { mysqlDocKeyword , mysqlDocBuiltin } from './doc-links.js' ;
65import { Indexes } from './indexes.js' ;
76import { Config } from './config.js' ;
87import { resizeTopMenu } from './menu-resizer.js' ;
98import tooltip from './tooltip.js' ;
9+ import highlightSql from './sql-highlight.js' ;
1010
1111/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js
1212/* global DatabaseStructure */ // js/database/structure.js
13- /* global firstDayOfCalendar, maxInputVars, mysqlDocTemplate, themeImagePath */ // templates/javascript/variables.twig
13+ /* global firstDayOfCalendar, maxInputVars, themeImagePath */ // templates/javascript/variables.twig
1414
1515/**
1616 * General functions, usually for data manipulation pages.
@@ -1378,108 +1378,6 @@ Functions.catchKeypressesFromSqlInlineEdit = function (event) {
13781378 }
13791379} ;
13801380
1381- /**
1382- * Adds doc link to single highlighted SQL element
1383- *
1384- * @param $elm
1385- * @param params
1386- */
1387- Functions . documentationAdd = function ( $elm , params ) {
1388- if ( typeof mysqlDocTemplate === 'undefined' ) {
1389- return ;
1390- }
1391-
1392- var url = window . sprintf (
1393- decodeURIComponent ( mysqlDocTemplate ) ,
1394- params [ 0 ]
1395- ) ;
1396- if ( params . length > 1 ) {
1397- // The # needs to be escaped to be part of the destination URL
1398- url += encodeURIComponent ( '#' ) + params [ 1 ] ;
1399- }
1400- var content = $elm . text ( ) ;
1401- $elm . text ( '' ) ;
1402- $elm . append ( '<a target="mysql_doc" class="cm-sql-doc" href="' + url + '">' + content + '</a>' ) ;
1403- } ;
1404-
1405- /**
1406- * Generates doc links for keywords inside highlighted SQL
1407- *
1408- * @param idx
1409- * @param elm
1410- */
1411- Functions . documentationKeyword = function ( idx , elm ) {
1412- var $elm = $ ( elm ) ;
1413- /* Skip already processed ones */
1414- if ( $elm . find ( 'a' ) . length > 0 ) {
1415- return ;
1416- }
1417- var keyword = $elm . text ( ) . toUpperCase ( ) ;
1418- var $next = $elm . next ( '.cm-keyword' ) ;
1419- if ( $next ) {
1420- var nextKeyword = $next . text ( ) . toUpperCase ( ) ;
1421- var full = keyword + ' ' + nextKeyword ;
1422-
1423- var $next2 = $next . next ( '.cm-keyword' ) ;
1424- if ( $next2 ) {
1425- var next2Keyword = $next2 . text ( ) . toUpperCase ( ) ;
1426- var full2 = full + ' ' + next2Keyword ;
1427- if ( full2 in mysqlDocKeyword ) {
1428- Functions . documentationAdd ( $elm , mysqlDocKeyword [ full2 ] ) ;
1429- Functions . documentationAdd ( $next , mysqlDocKeyword [ full2 ] ) ;
1430- Functions . documentationAdd ( $next2 , mysqlDocKeyword [ full2 ] ) ;
1431- return ;
1432- }
1433- }
1434- if ( full in mysqlDocKeyword ) {
1435- Functions . documentationAdd ( $elm , mysqlDocKeyword [ full ] ) ;
1436- Functions . documentationAdd ( $next , mysqlDocKeyword [ full ] ) ;
1437- return ;
1438- }
1439- }
1440- if ( keyword in mysqlDocKeyword ) {
1441- Functions . documentationAdd ( $elm , mysqlDocKeyword [ keyword ] ) ;
1442- }
1443- } ;
1444-
1445- /**
1446- * Generates doc links for builtins inside highlighted SQL
1447- *
1448- * @param idx
1449- * @param elm
1450- */
1451- Functions . documentationBuiltin = function ( idx , elm ) {
1452- var $elm = $ ( elm ) ;
1453- var builtin = $elm . text ( ) . toUpperCase ( ) ;
1454- if ( builtin in mysqlDocBuiltin ) {
1455- Functions . documentationAdd ( $elm , mysqlDocBuiltin [ builtin ] ) ;
1456- }
1457- } ;
1458-
1459- /**
1460- * Higlights SQL using CodeMirror.
1461- *
1462- * @param $base
1463- */
1464- Functions . highlightSql = function ( $base ) {
1465- var $elm = $base . find ( 'code.sql' ) ;
1466- $elm . each ( function ( ) {
1467- var $sql = $ ( this ) ;
1468- var $pre = $sql . find ( 'pre' ) ;
1469- /* We only care about visible elements to avoid double processing */
1470- if ( $pre . is ( ':visible' ) ) {
1471- var $highlight = $ ( '<div class="sql-highlight cm-s-default"></div>' ) ;
1472- $sql . append ( $highlight ) ;
1473- if ( typeof window . CodeMirror !== 'undefined' ) {
1474- window . CodeMirror . runMode ( $sql . text ( ) , 'text/x-mysql' , $highlight [ 0 ] ) ;
1475- $pre . hide ( ) ;
1476- $highlight . find ( '.cm-keyword' ) . each ( Functions . documentationKeyword ) ;
1477- $highlight . find ( '.cm-builtin' ) . each ( Functions . documentationBuiltin ) ;
1478- }
1479- }
1480- } ) ;
1481- } ;
1482-
14831381/**
14841382 * Updates an element containing code.
14851383 *
@@ -1655,7 +1553,7 @@ Functions.ajaxShowMessage = function (message = null, timeout = null, type = nul
16551553 if ( msg !== window . Messages . strLoading ) {
16561554 $retval . css ( 'background-image' , 'none' ) ;
16571555 }
1658- Functions . highlightSql ( $retval ) ;
1556+ highlightSql ( $retval ) ;
16591557
16601558 return $retval ;
16611559} ;
@@ -1706,7 +1604,7 @@ Functions.previewSql = function ($form) {
17061604 $ ( '#previewSqlModal' ) . find ( '.modal-body' ) . first ( ) . html ( response . sql_data ) ;
17071605 $ ( '#previewSqlModalLabel' ) . first ( ) . html ( window . Messages . strPreviewSQL ) ;
17081606 $ ( '#previewSqlModal' ) . on ( 'shown.bs.modal' , function ( ) {
1709- Functions . highlightSql ( $ ( '#previewSqlModal' ) ) ;
1607+ highlightSql ( $ ( '#previewSqlModal' ) ) ;
17101608 } ) ;
17111609 } else {
17121610 Functions . ajaxShowMessage ( response . message ) ;
@@ -1738,7 +1636,7 @@ Functions.confirmPreviewSql = function (sqlData, url, callback) {
17381636 $ ( '#previewSqlConfirmModalLabel' ) . first ( ) . html ( window . Messages . strPreviewSQL ) ;
17391637 $ ( '#previewSqlConfirmCode' ) . first ( ) . text ( sqlData ) ;
17401638 $ ( '#previewSqlConfirmModal' ) . on ( 'shown.bs.modal' , function ( ) {
1741- Functions . highlightSql ( $ ( '#previewSqlConfirmModal' ) ) ;
1639+ highlightSql ( $ ( '#previewSqlConfirmModal' ) ) ;
17421640 } ) ;
17431641 $ ( '#previewSQLConfirmOkButton' ) . on ( 'click' , function ( ) {
17441642 callback ( url ) ;
@@ -2341,7 +2239,7 @@ Functions.onloadCreateTableEvents = function () {
23412239 if ( typeof data !== 'undefined' && data . success ) {
23422240 var $pageContent = $ ( '#page_content' ) ;
23432241 $pageContent . html ( data . message ) ;
2344- Functions . highlightSql ( $pageContent ) ;
2242+ highlightSql ( $pageContent ) ;
23452243 Functions . verifyColumnsProperties ( ) ;
23462244 Functions . hideShowConnection ( $ ( '.create_table_form select[name=tbl_storage_engine]' ) ) ;
23472245 Functions . ajaxRemoveMessage ( $msgbox ) ;
@@ -2547,7 +2445,7 @@ Functions.onloadChangePasswordEvents = function () {
25472445
25482446 var $pageContent = $ ( '#page_content' ) ;
25492447 $pageContent . prepend ( data . message ) ;
2550- Functions . highlightSql ( $pageContent ) ;
2448+ highlightSql ( $pageContent ) ;
25512449 $ ( '#change_password_dialog' ) . hide ( ) . remove ( ) ;
25522450 $ ( '#edit_user_dialog' ) . dialog ( 'close' ) . remove ( ) ;
25532451 Functions . ajaxRemoveMessage ( $msgbox ) ;
@@ -3118,7 +3016,7 @@ Functions.indexDialogModal = function (routeUrl, url, title, callbackSuccess, ca
31183016 }
31193017
31203018 modalBody . innerHTML = response . sql_data ;
3121- Functions . highlightSql ( $ ( '#indexDialogPreviewModal' ) ) ;
3019+ highlightSql ( $ ( '#indexDialogPreviewModal' ) ) ;
31223020 } ,
31233021 error : ( ) => {
31243022 modalBody . innerHTML = '<div class="alert alert-danger" role="alert">' + window . Messages . strErrorProcessingRequest + '</div>' ;
@@ -3147,7 +3045,7 @@ Functions.indexDialogModal = function (routeUrl, url, title, callbackSuccess, ca
31473045 }
31483046 if ( typeof data !== 'undefined' && data . success === true ) {
31493047 Functions . ajaxShowMessage ( data . message ) ;
3150- Functions . highlightSql ( $ ( '.result_query' ) ) ;
3048+ highlightSql ( $ ( '.result_query' ) ) ;
31513049 $ ( '.result_query .alert' ) . remove ( ) ;
31523050 /* Reload the field form*/
31533051 $ ( '#table_index' ) . remove ( ) ;
@@ -3523,7 +3421,7 @@ Functions.slidingMessage = function (msg, $object) {
35233421 $obj
35243422 . append ( '<div>' + msg + '</div>' ) ;
35253423 // highlight any sql before taking height;
3526- Functions . highlightSql ( $obj ) ;
3424+ highlightSql ( $obj ) ;
35273425 $obj . find ( 'div' )
35283426 . first ( )
35293427 . hide ( ) ;
@@ -3541,7 +3439,7 @@ Functions.slidingMessage = function (msg, $object) {
35413439 $obj . width ( '100%' )
35423440 . html ( '<div>' + msg + '</div>' ) ;
35433441 // highlight any sql before taking height;
3544- Functions . highlightSql ( $obj ) ;
3442+ highlightSql ( $obj ) ;
35453443 var h = $obj
35463444 . find ( 'div' )
35473445 . first ( )
@@ -3588,7 +3486,7 @@ Functions.onloadCodeMirrorEditor = () => {
35883486 $elm . trigger ( 'focus' ) . on ( 'blur' , Functions . updateQueryParameters ) ;
35893487 }
35903488 }
3591- Functions . highlightSql ( $ ( 'body' ) ) ;
3489+ highlightSql ( $ ( 'body' ) ) ;
35923490} ;
35933491
35943492/**
0 commit comments