Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: fck editor.

fck editor: Difference between revisions

From MoodleDocs
(FCK editor implementation)
 
No edit summary
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The print_textarea function to replace the one currently in weblib.php to implement fck editor.
The print_textarea function to replace the one currently in weblib.php to implement fck editor.


Make sure fck editor is unzipped to "Moodle/lib/editor" in a folder "fck"
Make sure fck editor is unzipped to "Moodle/lib/editor" in a folder "fckeditor"
 
 
 


Steps to installation


# In moodle/lib/weblib.php replace the print_textarea function with the one provided.
# Download fck editor to moodle/lib/editor (be sure to name the folder with the editor as "fckeditor"
# Adjust the config file for fck editor to options you want to test
# Make sure in the print_textarea function that the path to fckeditor.js is correct If there is a change in your file structure






<pre>


/* test FCKeditor implementation*/
/* test FCKeditor implementation*/
Line 103: Line 106:


}
}
</pre>
For Moodle 1.8.2:
This FCKEditor integration only semi-works.  It has the only-loading-in-first-textarea bug.
see [http://moodle.org/mod/forum/discuss.php?d=78305] for background and
[http://moodle.org/mod/forum/discuss.php?d=76912] for more on the whole editor issue at large.
--[[User:Andrew Grothe|Andrew Grothe]] 12:38, 9 October 2007 (CDT)
The code above has a glitch, it renders the editor on header and not in it's real location, the code below resembles a modified function for correct rendering of the fckeditor
Also comment use_html_editor() function contents in same weblib.php for avoiding Javascript errors about missing object
<pre>
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0, $return=false) {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
global $CFG, $course;
static $scriptcount; // For loading the htmlarea script only once.
if (empty($courseid)) {
if (!empty($course->id)) { // search for it in global context
$courseid = $course->id;
}
}
if (empty($scriptcount)) {
$scriptcount = 0;
}
if ($usehtmleditor) {
if (!empty($courseid) and isteacher($courseid)) {
$strFck = ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>' . "\n" : '';
} else {
$strFck = ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>'."\n" : '';
}
$scriptcount++;
if ($height) { // Usually with legacy calls
if ($rows < $minrows) {
$rows = $minrows;
}
}
if ($width) { // Usually with legacy calls
if ($cols < $mincols) {
$cols = $mincols;
}
}
}
$strFck .= '<textarea id= "' . $name .'_' . $scriptcount .'"  name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
$strFck .= $value;
$strFck .= '</textarea>'."\n";
$strFck .= '<script type="text/javascript" defer="defer">
var oFCKeditor_' . $scriptcount .' = new FCKeditor("' . $name . '_' . $scriptcount .'") ;
oFCKeditor_' . $scriptcount .'.BasePath = "'. $CFG->wwwroot .'/lib/editor/fckeditor/" ;
oFCKeditor_' . $scriptcount .'.Height = 400 ;
oFCKeditor_' . $scriptcount .'.Width = 700 ;
oFCKeditor_' . $scriptcount .'.ReplaceTextarea() ;
</script>';
if ($return) {
        return $strFck;
    }
    echo $strFck;
}
</pre>
--[[User:Frederic Yesid Peña Sánchez|Frederic Yesid Peña Sánchez]] 14:15, 13 March 2008 (GMT-5)

Latest revision as of 20:12, 11 July 2008

The print_textarea function to replace the one currently in weblib.php to implement fck editor.

Make sure fck editor is unzipped to "Moodle/lib/editor" in a folder "fckeditor"

Steps to installation

  1. In moodle/lib/weblib.php replace the print_textarea function with the one provided.
  2. Download fck editor to moodle/lib/editor (be sure to name the folder with the editor as "fckeditor"
  3. Adjust the config file for fck editor to options you want to test
  4. Make sure in the print_textarea function that the path to fckeditor.js is correct If there is a change in your file structure



/* test FCKeditor implementation*/
 
 
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
 global $CFG, $course;
 static $scriptcount; // For loading the htmlarea script only once.

 if (empty($courseid)) {

 if (!empty($course->id)) { // search for it in global context

 $courseid = $course->id;

 }

 }

 if (empty($scriptcount)) {

 $scriptcount = 0;

 }


 if ($usehtmleditor) {

 if (!empty($courseid) and isteacher($courseid)) {

 echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>' . "\n" : '';

 } else {

 echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>'."\n" : '';

 }


 echo '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>

  
    
  <script type="text/javascript">
      window.onload = function()
      {
        var oFCKeditor = new FCKeditor("MyTextarea") ;
        oFCKeditor.BasePath = "'. $CFG->wwwroot .'/lib/editor/fckeditor/" ;
        oFCKeditor.Height	= 400 ;
        oFCKeditor.Width	= 700 ;
        oFCKeditor.ReplaceTextarea() ;
      }
    </script>';

 

 $scriptcount++;





 if ($height) { // Usually with legacy calls

 if ($rows < $minrows) {

 $rows = $minrows;

 }

 }

 if ($width) { // Usually with legacy calls

 if ($cols < $mincols) {

 $cols = $mincols;

 }

 } 
 

 }

 echo '<textarea id= "MyTextarea"  name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';

 p($value);

 echo '</textarea>'."\n";

}


For Moodle 1.8.2: This FCKEditor integration only semi-works. It has the only-loading-in-first-textarea bug. see [1] for background and [2] for more on the whole editor issue at large. --Andrew Grothe 12:38, 9 October 2007 (CDT)

The code above has a glitch, it renders the editor on header and not in it's real location, the code below resembles a modified function for correct rendering of the fckeditor

Also comment use_html_editor() function contents in same weblib.php for avoiding Javascript errors about missing object

function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0, $return=false) {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
	global $CFG, $course;
	static $scriptcount; // For loading the htmlarea script only once.
	if (empty($courseid)) {
		if (!empty($course->id)) { // search for it in global context
			$courseid = $course->id;
		}
	}

	if (empty($scriptcount)) {
		$scriptcount = 0;
	}

	if ($usehtmleditor) {
		if (!empty($courseid) and isteacher($courseid)) {
			$strFck = ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>' . "\n" : '';
		} else {
			$strFck = ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/fckeditor/fckeditor.js"></script>'."\n" : '';
		}
		$scriptcount++;
		if ($height) { // Usually with legacy calls
			if ($rows < $minrows) {
				$rows = $minrows;
			}
		}
		
		if ($width) { // Usually with legacy calls
			if ($cols < $mincols) {
				$cols = $mincols;
			}
		} 
	}
	
	$strFck .= '<textarea id= "' . $name .'_' . $scriptcount .'"  name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
	$strFck .= $value;
	$strFck .= '</textarea>'."\n";
	$strFck .= '<script type="text/javascript" defer="defer">
		var oFCKeditor_' . $scriptcount .' = new FCKeditor("' . $name . '_' . $scriptcount .'") ;
			oFCKeditor_' . $scriptcount .'.BasePath = "'. $CFG->wwwroot .'/lib/editor/fckeditor/" ;
			oFCKeditor_' . $scriptcount .'.Height	= 400 ;
			oFCKeditor_' . $scriptcount .'.Width	= 700 ;
			oFCKeditor_' . $scriptcount .'.ReplaceTextarea() ;
		</script>';
		
	
	
	if ($return) {
        return $strFck;
    }
    echo $strFck;
}

--Frederic Yesid Peña Sánchez 14:15, 13 March 2008 (GMT-5)