2006-07-22 18:09:48 +02:00
< ? php
2008-03-21 01:27:37 +01:00
/* Copyright ( C ) 2006 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2021-04-23 00:45:07 +02:00
* Copyright ( C ) 2021 Gaëtan MAISON < gm @ ilad . org >
2024-03-12 23:15:16 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2006-07-22 18:09:48 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-07-22 18:09:48 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2006-07-22 18:09:48 +02:00
*/
/**
2011-10-24 09:29:17 +02:00
* \file htdocs / core / class / doleditor . class . php
2010-06-18 21:40:58 +02:00
* \brief Class to manage a WYSIWYG editor
2011-01-31 17:35:55 +01:00
*/
2006-07-22 18:09:48 +02:00
/**
2012-03-12 15:09:46 +01:00
* Class to manage a WYSIWYG editor .
* Usage : $doleditor = new DolEditor ( 'body' , $message , 320 , 'toolbar_mailing' );
* $doleditor -> Create ();
2008-08-07 08:33:35 +02:00
*/
2006-07-22 18:09:48 +02:00
class DolEditor
{
2020-10-31 14:32:18 +01:00
public $tool ; // Store the selected tool
2010-08-27 02:09:58 +02:00
2020-10-31 14:32:18 +01:00
// If using fckeditor
public $editor ;
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
// If not using fckeditor
public $content ;
public $htmlname ;
public $toolbarname ;
public $toolbarstartexpanded ;
public $rows ;
public $cols ;
public $height ;
public $width ;
2023-02-22 21:26:59 +01:00
public $uselocalbrowser ;
2020-10-31 14:32:18 +01:00
public $readonly ;
2022-02-27 14:46:40 +01:00
public $posx ;
public $posy ;
2010-08-27 02:09:58 +02:00
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
/**
* Create an object to build an HTML area to edit a large string content
*
2024-03-24 05:23:06 +01:00
* @ param string $htmlname HTML name of WYSIWIG field
* @ param string $content Content of WYSIWIG field
* @ param int | string $width Width in pixel of edit area ( auto by default )
* @ param int $height Height in pixel of edit area ( 200 px by default )
* @ param string $toolbarname Name of bar set to use ( 'Full' , 'dolibarr_notes[_encoded]' , 'dolibarr_details[_encoded]' = the less featured , 'dolibarr_mailings[_encoded]' , 'dolibarr_readonly' ) .
* @ param string $toolbarlocation Deprecated . Not used
* @ param boolean $toolbarstartexpanded Bar is visible or not at start
* @ param boolean | int $uselocalbrowser Enabled to add links to local object with local browser . If false , only external images can be added in content .
* @ param boolean | string $okforextendededitor True = Allow usage of extended editor tool if qualified ( like ckeditor ) . If 'textarea' , force use of simple textarea . If 'ace' , force use of Ace .
* Warning : If you use 'ace' , don ' t forget to also include ace . js in page header . Also , the button " save " must have class = " buttonforacesave " .
* @ param int $rows Size of rows for textarea tool
* @ param string $cols Size of cols for textarea tool ( textarea number of cols '70' or percent 'x%' )
* @ param int $readonly 0 = Read / Edit , 1 = Read only
* @ param array $poscursor Array for initial cursor position array ( 'x' => x , 'y' => y )
2010-06-24 21:00:21 +02:00
*/
2023-12-21 13:43:19 +01:00
public function __construct ( $htmlname , $content , $width = '' , $height = 200 , $toolbarname = 'Basic' , $toolbarlocation = 'In' , $toolbarstartexpanded = false , $uselocalbrowser = 1 , $okforextendededitor = true , $rows = 0 , $cols = '' , $readonly = 0 , $poscursor = array ())
2020-10-31 14:32:18 +01:00
{
2023-11-24 10:23:21 +01:00
global $conf ;
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
dol_syslog ( get_class ( $this ) . " ::DolEditor htmlname= " . $htmlname . " width= " . $width . " height= " . $height . " toolbarname= " . $toolbarname );
2009-01-31 03:55:32 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $rows ) {
$rows = round ( $height / 20 );
}
if ( ! $cols ) {
2023-12-04 12:04:36 +01:00
$cols = ( $width ? round ( $width / 6 ) : 80 );
2021-02-23 22:03:23 +01:00
}
2019-12-06 09:26:49 +01:00
$shorttoolbarname = preg_replace ( '/_encoded$/' , '' , $toolbarname );
2011-11-05 21:24:55 +01:00
2020-10-31 14:32:18 +01:00
// Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
$defaulteditor = 'ckeditor' ;
2023-11-27 11:24:19 +01:00
$this -> tool = ! getDolGlobalString ( 'FCKEDITOR_EDITORNAME' ) ? $defaulteditor : $conf -> global -> FCKEDITOR_EDITORNAME ;
2020-10-31 14:32:18 +01:00
$this -> uselocalbrowser = $uselocalbrowser ;
$this -> readonly = $readonly ;
2009-01-31 03:55:32 +01:00
2020-10-31 14:32:18 +01:00
// Check if extended editor is ok. If not we force textarea
2023-06-09 13:45:19 +02:00
if (( ! isModEnabled ( 'fckeditor' ) && $okforextendededitor != 'ace' ) || empty ( $okforextendededitor )) {
2021-02-23 22:03:23 +01:00
$this -> tool = 'textarea' ;
}
if ( $okforextendededitor === 'ace' ) {
$this -> tool = 'ace' ;
}
2020-10-31 14:32:18 +01:00
//if ($conf->dol_use_jmobile) $this->tool = 'textarea'; // ckeditor and ace seems ok with mobile
2011-08-15 01:54:09 +02:00
2020-10-31 14:32:18 +01:00
// Define some properties
2021-02-23 22:03:23 +01:00
if ( in_array ( $this -> tool , array ( 'textarea' , 'ckeditor' , 'ace' ))) {
2020-10-31 18:51:30 +01:00
if ( $this -> tool == 'ckeditor' && ! dol_textishtml ( $content )) { // We force content to be into HTML if we are using an advanced editor if content is not HTML.
2020-10-31 14:32:18 +01:00
$this -> content = dol_nl2br ( $content );
2021-02-23 22:03:23 +01:00
} else {
2020-10-31 14:32:18 +01:00
$this -> content = $content ;
}
$this -> htmlname = $htmlname ;
$this -> toolbarname = $shorttoolbarname ;
$this -> toolbarstartexpanded = $toolbarstartexpanded ;
$this -> rows = max ( ROWS_3 , $rows );
$this -> cols = ( preg_match ( '/%/' , $cols ) ? $cols : max ( 40 , $cols )); // If $cols is a percent, we keep it, otherwise, we take max
2022-02-27 14:46:40 +01:00
$this -> height = $height ;
2020-10-31 14:32:18 +01:00
$this -> width = $width ;
2022-02-27 14:46:40 +01:00
$this -> posx = empty ( $poscursor [ 'x' ]) ? 0 : $poscursor [ 'x' ];
$this -> posy = empty ( $poscursor [ 'y' ]) ? 0 : $poscursor [ 'y' ];
2020-10-31 14:32:18 +01:00
}
}
2006-07-22 18:09:48 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output edit area inside the HTML stream .
* Output depends on this -> tool ( fckeditor , ckeditor , textarea , ... )
*
* @ param int $noprint 1 = Return HTML string instead of printing it to output
* @ param string $morejs Add more js . For example : " .on( \ 'saveSnapshot \ ', function(e) { alert( \ 'ee \ '); }); " . Used by CKEditor only .
* @ param boolean $disallowAnyContent Disallow to use any content . true = restrict to a predefined list of allowed elements . Used by CKEditor only .
* @ param string $titlecontent Show title content before editor area . Used by ACE editor only .
* @ param string $option For ACE editor , set the source language ( 'html' , 'php' , 'javascript' , ... )
2022-02-28 21:45:04 +01:00
* @ param string $moreparam Add extra tags to the textarea
* @ param string $morecss Add extra css to the textarea
2020-10-31 14:32:18 +01:00
* @ return void | string
*/
2022-02-16 09:59:18 +01:00
public function Create ( $noprint = 0 , $morejs = '' , $disallowAnyContent = true , $titlecontent = '' , $option = '' , $moreparam = '' , $morecss = '' )
2020-10-31 14:32:18 +01:00
{
// phpcs:enable
global $conf , $langs ;
2011-01-31 20:28:35 +01:00
2020-10-31 14:32:18 +01:00
$fullpage = false ;
2021-02-23 22:03:23 +01:00
if ( isset ( $conf -> global -> FCKEDITOR_ALLOW_ANY_CONTENT )) {
2023-11-27 11:24:19 +01:00
$disallowAnyContent = ! getDolGlobalString ( 'FCKEDITOR_ALLOW_ANY_CONTENT' ); // Only predefined list of html tags are allowed or all
2020-10-31 14:32:18 +01:00
}
2016-09-15 23:23:10 +02:00
2020-10-31 14:32:18 +01:00
$found = 0 ;
2019-12-06 09:26:49 +01:00
$out = '' ;
2010-08-27 02:09:58 +02:00
2021-02-23 22:03:23 +01:00
if ( in_array ( $this -> tool , array ( 'textarea' , 'ckeditor' ))) {
2020-10-31 14:32:18 +01:00
$found = 1 ;
//$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" '.($this->readonly?' disabled':'').' rows="'.$this->rows.'"'.(preg_match('/%/',$this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">';
// TODO We do not put the 'disabled' tag because on a read form, it change style with grey.
//print $this->content;
2022-02-16 09:59:18 +01:00
$out .= '<textarea id="' . $this -> htmlname . '" name="' . $this -> htmlname . '" rows="' . $this -> rows . '"' . ( preg_match ( '/%/' , $this -> cols ) ? ' style="margin-top: 5px; width: ' . $this -> cols . '"' : ' cols="' . $this -> cols . '"' ) . ' ' . ( $moreparam ? $moreparam : '' ) . ' class="flat ' . $morecss . '">' ;
2020-10-31 14:32:18 +01:00
$out .= htmlspecialchars ( $this -> content );
$out .= '</textarea>' ;
2011-01-31 20:28:35 +01:00
2022-08-31 22:02:31 +02:00
if ( $this -> tool == 'ckeditor' && ! empty ( $conf -> use_javascript_ajax ) && isModEnabled ( 'fckeditor' )) {
2021-02-23 22:03:23 +01:00
if ( ! defined ( 'REQUIRE_CKEDITOR' )) {
define ( 'REQUIRE_CKEDITOR' , '1' );
}
2011-02-01 19:49:31 +01:00
2023-01-09 12:30:56 +01:00
$skin = getDolGlobalString ( 'FCKEDITOR_SKIN' , 'moono-lisa' ); // default with ckeditor 4.6 : moono-lisa
2021-12-13 01:19:48 +01:00
2023-08-08 22:03:58 +02:00
$pluginstodisable = 'elementspath,save,flash,div,anchor' ;
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_SPECIALCHAR' )) {
$pluginstodisable .= ',specialchar' ;
2023-08-09 18:33:43 +02:00
}
2021-12-13 01:19:48 +01:00
if ( ! empty ( $conf -> dol_optimize_smallscreen )) {
$pluginstodisable .= ',scayt,wsc,find,undo' ;
}
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_WSC' )) { // spellchecker has end of life december 2021
2021-12-13 01:19:48 +01:00
$pluginstodisable .= ',wsc' ;
}
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'FCKEDITOR_ENABLE_PDF' )) {
2022-05-16 20:28:00 +02:00
$pluginstodisable .= ',exportpdf' ;
}
2023-12-10 16:19:05 +01:00
if ( getDolGlobalInt ( 'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS' ) == 2 ) {
2023-11-14 01:32:42 +01:00
$this -> uselocalbrowser = 0 ; // Can't use browser to navigate into files. Only links with "<img src=data:..." are allowed.
}
2021-12-13 01:19:48 +01:00
$scaytautostartup = '' ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'FCKEDITOR_ENABLE_SCAYT_AUTOSTARTUP' )) {
2021-04-23 00:45:07 +02:00
$scaytautostartup = 'scayt_autoStartup: true,' ;
2021-12-13 01:19:48 +01:00
$scaytautostartup .= 'scayt_sLang: \'' . dol_escape_js ( $langs -> getDefaultLang ()) . '\',' ;
2021-04-23 00:45:07 +02:00
} else {
2021-12-13 01:19:48 +01:00
$pluginstodisable .= ',scayt' ;
2021-04-23 00:45:07 +02:00
}
2013-03-24 19:00:58 +01:00
2020-10-31 14:32:18 +01:00
$htmlencode_force = preg_match ( '/_encoded$/' , $this -> toolbarname ) ? 'true' : 'false' ;
2011-04-09 17:12:20 +02:00
2023-01-03 17:09:08 +01:00
$out .= '<!-- Output ckeditor $disallowAnyContent=' . dol_escape_htmltag ( $disallowAnyContent ) . ' toolbarname=' . dol_escape_htmltag ( $this -> toolbarname ) . ' -->' . " \n " ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . ' " type= " text / javascript " >
2012-03-16 16:56:18 +01:00
$ ( document ) . ready ( function () {
2019-12-04 15:55:22 +01:00
/* console.log("Run ckeditor"); */
2011-07-06 14:44:51 +02:00
/* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
2021-12-13 01:19:48 +01:00
/* should be editor=CKEDITOR.replace but what if there is several editors ? */
2023-01-03 17:09:08 +01:00
tmpeditor = CKEDITOR . replace ( \ '' . dol_escape_js ( $this -> htmlname ) . ' \ ' ,
2011-02-01 19:49:31 +01:00
{
2013-04-13 16:23:05 +02:00
/* property:xxx is same than CKEDITOR.config.property = xxx */
2022-05-16 20:28:00 +02:00
customConfig : ckeditorConfig ,
2023-01-03 17:09:08 +01:00
removePlugins : \ '' . dol_escape_js ( $pluginstodisable ) . ' \ ' ,
2023-12-23 10:43:19 +01:00
versionCheck : false ,
2022-05-16 20:28:00 +02:00
readOnly : '.($this->readonly ? ' true ' : ' false ').' ,
2023-01-03 17:09:08 +01:00
htmlEncodeOutput : '.dol_escape_js($htmlencode_force).' ,
allowedContent : '.($disallowAnyContent ? ' false ' : ' true ').' , /* Advanced Content Filter (ACF) is own when allowedContent is false */
2022-05-16 20:28:00 +02:00
extraAllowedContent : \ ' a [ target ]; div { float , display } \ ' , /* Add the style float and display into div to default other allowed tags */
2024-03-12 23:15:16 +01:00
disallowedContent : \ ' \ ' , /* Tags that are not allowed */
2022-05-16 20:28:00 +02:00
fullPage : '.($fullpage ? ' true ' : ' false ').' , /* if true, the html, header and body tags are kept */
2023-01-03 17:09:08 +01:00
toolbar : \ '' . dol_escape_js ( $this -> toolbarname ) . ' \ ' ,
2011-01-31 23:22:35 +01:00
toolbarStartupExpanded : '.($this->toolbarstartexpanded ? ' true ' : ' false ').' ,
2023-01-03 17:09:08 +01:00
width : '.($this->width ? ' \ '' . dol_escape_js ( $this -> width ) . '\'' : '\'\'' ) . ' ,
height : '.dol_escape_js($this->height).' ,
skin : \ '' . dol_escape_js ( $skin ) . ' \ ' ,
2021-04-23 00:45:07 +02:00
'.$scaytautostartup.'
2023-01-03 17:09:08 +01:00
language : \ '' . dol_escape_js ( $langs -> defaultlang ) . ' \ ' ,
textDirection : \ '' . dol_escape_js ( $langs -> trans ( " DIRECTION " )) . ' \ ' ,
2021-12-13 01:19:48 +01:00
on : {
2024-01-29 13:00:33 +01:00
instanceReady : function ( ev ) {
console . log ( " ckeditor instanceReady " );
2011-04-09 17:12:20 +02:00
// Output paragraphs as <p>Text</p>.
2021-12-13 01:19:48 +01:00
this . dataProcessor . writer . setRules ( \ ' p\ ' , {
indent : false ,
breakBeforeOpen : true ,
breakAfterOpen : false ,
breakBeforeClose : false ,
breakAfterClose : true
});
2024-01-29 13:00:33 +01:00
},
/* This is to remove the tab Link on image popup. Does not work, so commented */
/*
dialogDefinition : function ( event ) {
var dialogName = event . data . name ;
var dialogDefinition = event . data . definition ;
if ( dialogName == \ ' image\ ' ) {
dialogDefinition . removeContents ( \ ' Link\ ' );
}
}
*/
},
2023-11-27 11:24:19 +01:00
disableNativeSpellChecker : '.(!getDolGlobalString(' CKEDITOR_NATIVE_SPELLCHECKER ') ? ' true ' : ' false ' );
2019-12-04 15:49:22 +01:00
2021-02-23 22:03:23 +01:00
if ( $this -> uselocalbrowser ) {
2020-10-31 14:32:18 +01:00
$out .= ',' . " \n " ;
// To use filemanager with old fckeditor (GPL)
2024-01-29 13:00:33 +01:00
// Note: ckeditorFilebrowserBrowseUrl and ckeditorFilebrowserImageBrowseUrl are defined in header by main.inc.php. They include url to browser with url of upload connector in parameter
2020-10-31 14:32:18 +01:00
$out .= ' filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,' ;
$out .= ' filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,' ;
//$out.= ' filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\',';
//$out.= ' filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
$out .= " \n " ;
// To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
2014-03-08 13:17:20 +01:00
/* $out .= ' filebrowserBrowseUrl : \'' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html\ ' ,
2021-02-23 22:03:23 +01:00
filebrowserImageBrowseUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html ? Type = Images\ ' ,
filebrowserFlashBrowseUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / ckfinder . html ? Type = Flash\ ' ,
filebrowserUploadUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / core / connector / php / connector . php ? command = QuickUpload & type = Files\ ' ,
filebrowserImageUploadUrl : \ '' . DOL_URL_ROOT . ' / includes / ckfinder / core / connector / php / connector . php ? command = QuickUpload & type = Images\ ' ,
filebrowserFlashUploadUrl : \ '' . DOL_URL_ROOT . '/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\',' . " \n " ;
2014-03-08 13:17:20 +01:00
*/
2020-10-31 14:32:18 +01:00
$out .= ' filebrowserWindowWidth : \ ' 900 \ ' ,
2011-04-23 00:13:34 +02:00
filebrowserWindowHeight : \ ' 500 \ ' ,
filebrowserImageWindowWidth : \ ' 900 \ ' ,
filebrowserImageWindowHeight : \ '500\'' ;
2020-10-31 14:32:18 +01:00
}
2021-12-13 01:19:48 +01:00
$out .= ' })' . $morejs ; // end CKEditor.replace
// Show the CKEditor javascript object once loaded is ready 'For debug)
//$out .= '; CKEDITOR.on(\'instanceReady\', function(ck) { ck.editor.removeMenuItem(\'maximize\'); ck.editor.removeMenuItem(\'Undo\'); ck.editor.removeMenuItem(\'undo\'); console.log(ck.editor); console.log(ck.editor.toolbar[0]); }); ';
$out .= '});' . " \n " ; // end document.ready
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
}
}
2017-07-18 12:00:18 +02:00
2020-10-31 14:32:18 +01:00
// Output editor ACE
// Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/^ace/' , $this -> tool )) {
2020-10-31 14:32:18 +01:00
$found = 1 ;
2019-12-06 09:26:49 +01:00
$format = $option ;
2017-07-18 03:18:16 +02:00
2020-10-31 14:32:18 +01:00
$out .= " \n " . '<!-- Output Ace editor -->' . " \n " ;
2017-07-18 14:20:37 +02:00
2021-02-23 22:03:23 +01:00
if ( $titlecontent ) {
2020-10-31 14:32:18 +01:00
$out .= '<div class="aceeditorstatusbar" id="statusBar' . $this -> htmlname . '">' . $titlecontent ;
2023-12-21 12:09:54 +01:00
$out .= ' - <span id="morelines" class="right classlink cursorpointer morelines' . $this -> htmlname . '">' . dol_escape_htmltag ( $langs -> trans ( " ShowMoreLines " )) . '</span> ' ;
2020-10-31 14:32:18 +01:00
$out .= '</div>' ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' . " \n " ;
2020-10-31 14:32:18 +01:00
$out .= 'jQuery(document).ready(function() {' . " \n " ;
$out .= ' var aceEditor = window.ace.edit("' . $this -> htmlname . ' aceeditorid " );
2024-03-12 23:15:16 +01:00
aceEditor . moveCursorTo ( '.($this->posy + 1).' , '.$this->posx.' );
aceEditor . gotoLine ( '.($this->posy + 1).' , '.$this->posx.' );
2017-07-19 16:38:00 +02:00
var StatusBar = window . ace . require ( " ace/ext/statusbar " ) . StatusBar ; // Init status bar. Need lib ext-statusbar
var statusBar = new StatusBar ( aceEditor , document . getElementById ( " statusBar'. $this->htmlname .' " )); // Init status bar. Need lib ext-statusbar
2022-02-27 14:46:40 +01:00
var oldNbOfLines = 0 ;
2017-12-10 19:03:18 +01:00
jQuery ( " .morelines'. $this->htmlname .' " ) . click ( function () {
2017-12-10 19:54:04 +01:00
var aceEditorClicked = window . ace . edit ( " '. $this->htmlname .'aceeditorid " );
currentline = aceEditorClicked . getOption ( " maxLines " );
2017-12-10 19:03:18 +01:00
if ( oldNbOfLines == 0 )
{
oldNbOfLines = currentline ;
}
2017-12-10 19:54:04 +01:00
console . log ( " We click on more lines, oldNbOfLines is " + oldNbOfLines + " , we have currently " + currentline );
2017-12-10 19:03:18 +01:00
if ( currentline < 500 )
{
2017-12-10 19:54:04 +01:00
aceEditorClicked . setOptions ({ maxLines : 500 });
2017-12-10 19:03:18 +01:00
}
else
{
2017-12-10 19:54:04 +01:00
aceEditorClicked . setOptions ({ maxLines : oldNbOfLines });
2017-12-10 19:03:18 +01:00
}
2017-07-18 14:20:37 +02:00
});
}) ' ;
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
2017-07-18 14:20:37 +02:00
}
2020-04-20 15:36:08 +02:00
2020-10-31 14:32:18 +01:00
$out .= '<pre id="' . $this -> htmlname . 'aceeditorid" style="' . ( $this -> width ? 'width: ' . $this -> width . 'px; ' : '' );
$out .= ( $this -> height ? ' height: ' . $this -> height . 'px; ' : '' );
//$out.=" min-height: 100px;";
$out .= '">' ;
$out .= htmlspecialchars ( $this -> content );
$out .= '</pre>' ;
2022-02-10 14:34:04 +01:00
$out .= '<input type="hidden" id="' . $this -> htmlname . '_x" name="' . $this -> htmlname . '_x">' ;
$out .= '<input type="hidden" id="' . $this -> htmlname . '_y" name="' . $this -> htmlname . '_y">' ;
2020-10-31 14:32:18 +01:00
$out .= '<textarea id="' . $this -> htmlname . '" name="' . $this -> htmlname . '" style="width:0px; height: 0px; display: none;">' ;
$out .= htmlspecialchars ( $this -> content );
$out .= '</textarea>' ;
2017-07-18 12:00:18 +02:00
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' . " \n " ;
2020-10-31 14:32:18 +01:00
$out .= 'var aceEditor = window.ace.edit("' . $this -> htmlname . ' aceeditorid " );
2017-07-18 12:00:18 +02:00
aceEditor . session . setMode ( " ace/mode/'. $format .' " );
aceEditor . setOptions ({
enableBasicAutocompletion : true , // the editor completes the statement when you hit Ctrl + Space. Need lib ext-language_tools.js
enableLiveAutocompletion : false , // the editor completes the statement while you are typing. Need lib ext-language_tools.js
showPrintMargin : false , // hides the vertical limiting strip
minLines : 10 ,
2019-12-06 09:26:49 +01:00
maxLines : '.(empty($this->height) ? ' 34 ' : (round($this->height / 10))).' ,
2017-07-19 16:38:00 +02:00
fontSize : " 110% " // ensures that the editor fits in the environment
2017-07-18 12:00:18 +02:00
});
// defines the style of the editor
aceEditor . setTheme ( " ace/theme/chrome " );
// hides line numbers (widens the area occupied by error and warning messages)
//aceEditor.renderer.setOption("showLineNumbers", false);
// ensures proper autocomplete, validation and highlighting of JavaScript code
//aceEditor.getSession().setMode("ace/mode/javascript_expression");
' . " \n " ;
2020-10-31 14:32:18 +01:00
$out .= ' jQuery ( document ) . ready ( function () {
2017-09-01 13:09:13 +02:00
jQuery ( " .buttonforacesave " ) . click ( function () {
2022-03-03 00:16:55 +01:00
console . log ( " We click on savefile button for component '.dol_escape_js( $this->htmlname ).' " );
var aceEditor = window . ace . edit ( " '.dol_escape_js( $this->htmlname ).'aceeditorid " );
2022-02-10 14:34:04 +01:00
if ( aceEditor ) {
var cursorPos = aceEditor . getCursorPosition ();
2022-03-02 14:44:14 +01:00
//console.log(cursorPos);
2022-02-10 14:34:04 +01:00
if ( cursorPos ) {
2022-03-03 00:16:55 +01:00
jQuery ( " #'.dol_escape_js( $this->htmlname ).'_x " ) . val ( cursorPos . column );
jQuery ( " #'.dol_escape_js( $this->htmlname ).'_y " ) . val ( cursorPos . row );
2022-02-10 14:34:04 +01:00
}
//console.log(aceEditor.getSession().getValue());
// Inject content of editor into the original HTML field.
2022-03-03 00:16:55 +01:00
jQuery ( " #'.dol_escape_js( $this->htmlname ).' " ) . val ( aceEditor . getSession () . getValue ());
/* if ( jQuery ( " #'.dol_escape_js( $this->htmlname ).' " ) . html () . length > 0 ) return true ;
2022-02-10 14:34:04 +01:00
else return false ; */
2022-03-02 14:44:14 +01:00
return true ;
2022-02-10 14:34:04 +01:00
} else {
console . log ( " Failed to retrieve js object ACE from its name " );
return false ;
}
2017-07-18 03:18:16 +02:00
});
}) ' ;
2020-10-31 14:32:18 +01:00
$out .= '</script>' . " \n " ;
}
2010-08-27 02:09:58 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $found )) {
2020-10-31 14:32:18 +01:00
$out .= 'Error, unknown value for tool ' . $this -> tool . ' in DolEditor Create function.' ;
}
2011-07-06 14:44:51 +02:00
2021-02-23 22:03:23 +01:00
if ( $noprint ) {
return $out ;
} else {
print $out ;
}
2020-10-31 14:32:18 +01:00
}
2006-07-22 18:09:48 +02:00
}