ckeditor/samples/old/api.html
changeset 0 44d330dccc59
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ckeditor/samples/old/api.html	Thu Dec 15 18:10:20 2016 +0300
     1.3 @@ -0,0 +1,210 @@
     1.4 +<!DOCTYPE html>
     1.5 +<!--
     1.6 +Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
     1.7 +For licensing, see LICENSE.md or http://ckeditor.com/license
     1.8 +-->
     1.9 +<html>
    1.10 +<head>
    1.11 +	<meta charset="utf-8">
    1.12 +	<title>API Usage &mdash; CKEditor Sample</title>
    1.13 +	<script src="../../ckeditor.js"></script>
    1.14 +	<link href="sample.css" rel="stylesheet">
    1.15 +	<script>
    1.16 +
    1.17 +// The instanceReady event is fired, when an instance of CKEditor has finished
    1.18 +// its initialization.
    1.19 +CKEDITOR.on( 'instanceReady', function( ev ) {
    1.20 +	// Show the editor name and description in the browser status bar.
    1.21 +	document.getElementById( 'eMessage' ).innerHTML = 'Instance <code>' + ev.editor.name + '<\/code> loaded.';
    1.22 +
    1.23 +	// Show this sample buttons.
    1.24 +	document.getElementById( 'eButtons' ).style.display = 'block';
    1.25 +});
    1.26 +
    1.27 +function InsertHTML() {
    1.28 +	// Get the editor instance that we want to interact with.
    1.29 +	var editor = CKEDITOR.instances.editor1;
    1.30 +	var value = document.getElementById( 'htmlArea' ).value;
    1.31 +
    1.32 +	// Check the active editing mode.
    1.33 +	if ( editor.mode == 'wysiwyg' )
    1.34 +	{
    1.35 +		// Insert HTML code.
    1.36 +		// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml
    1.37 +		editor.insertHtml( value );
    1.38 +	}
    1.39 +	else
    1.40 +		alert( 'You must be in WYSIWYG mode!' );
    1.41 +}
    1.42 +
    1.43 +function InsertText() {
    1.44 +	// Get the editor instance that we want to interact with.
    1.45 +	var editor = CKEDITOR.instances.editor1;
    1.46 +	var value = document.getElementById( 'txtArea' ).value;
    1.47 +
    1.48 +	// Check the active editing mode.
    1.49 +	if ( editor.mode == 'wysiwyg' )
    1.50 +	{
    1.51 +		// Insert as plain text.
    1.52 +		// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertText
    1.53 +		editor.insertText( value );
    1.54 +	}
    1.55 +	else
    1.56 +		alert( 'You must be in WYSIWYG mode!' );
    1.57 +}
    1.58 +
    1.59 +function SetContents() {
    1.60 +	// Get the editor instance that we want to interact with.
    1.61 +	var editor = CKEDITOR.instances.editor1;
    1.62 +	var value = document.getElementById( 'htmlArea' ).value;
    1.63 +
    1.64 +	// Set editor contents (replace current contents).
    1.65 +	// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setData
    1.66 +	editor.setData( value );
    1.67 +}
    1.68 +
    1.69 +function GetContents() {
    1.70 +	// Get the editor instance that you want to interact with.
    1.71 +	var editor = CKEDITOR.instances.editor1;
    1.72 +
    1.73 +	// Get editor contents
    1.74 +	// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getData
    1.75 +	alert( editor.getData() );
    1.76 +}
    1.77 +
    1.78 +function ExecuteCommand( commandName ) {
    1.79 +	// Get the editor instance that we want to interact with.
    1.80 +	var editor = CKEDITOR.instances.editor1;
    1.81 +
    1.82 +	// Check the active editing mode.
    1.83 +	if ( editor.mode == 'wysiwyg' )
    1.84 +	{
    1.85 +		// Execute the command.
    1.86 +		// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-execCommand
    1.87 +		editor.execCommand( commandName );
    1.88 +	}
    1.89 +	else
    1.90 +		alert( 'You must be in WYSIWYG mode!' );
    1.91 +}
    1.92 +
    1.93 +function CheckDirty() {
    1.94 +	// Get the editor instance that we want to interact with.
    1.95 +	var editor = CKEDITOR.instances.editor1;
    1.96 +	// Checks whether the current editor contents present changes when compared
    1.97 +	// to the contents loaded into the editor at startup
    1.98 +	// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-checkDirty
    1.99 +	alert( editor.checkDirty() );
   1.100 +}
   1.101 +
   1.102 +function ResetDirty() {
   1.103 +	// Get the editor instance that we want to interact with.
   1.104 +	var editor = CKEDITOR.instances.editor1;
   1.105 +	// Resets the "dirty state" of the editor (see CheckDirty())
   1.106 +	// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-resetDirty
   1.107 +	editor.resetDirty();
   1.108 +	alert( 'The "IsDirty" status has been reset' );
   1.109 +}
   1.110 +
   1.111 +function Focus() {
   1.112 +	CKEDITOR.instances.editor1.focus();
   1.113 +}
   1.114 +
   1.115 +function onFocus() {
   1.116 +	document.getElementById( 'eMessage' ).innerHTML = '<b>' + this.name + ' is focused </b>';
   1.117 +}
   1.118 +
   1.119 +function onBlur() {
   1.120 +	document.getElementById( 'eMessage' ).innerHTML = this.name + ' lost focus';
   1.121 +}
   1.122 +
   1.123 +	</script>
   1.124 +
   1.125 +</head>
   1.126 +<body>
   1.127 +	<h1 class="samples">
   1.128 +		<a href="index.html">CKEditor Samples</a> &raquo; Using CKEditor JavaScript API
   1.129 +	</h1>
   1.130 +	<div class="warning deprecated">
   1.131 +		This sample is not maintained anymore. Check out its <a href="http://sdk.ckeditor.com/samples/api.html">brand new version in CKEditor SDK</a>.
   1.132 +	</div>
   1.133 +	<div class="description">
   1.134 +	<p>
   1.135 +		This sample shows how to use the
   1.136 +		<a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.editor">CKEditor JavaScript API</a>
   1.137 +		to interact with the editor at runtime.
   1.138 +	</p>
   1.139 +	<p>
   1.140 +		For details on how to create this setup check the source code of this sample page.
   1.141 +	</p>
   1.142 +	</div>
   1.143 +
   1.144 +	<!-- This <div> holds alert messages to be display in the sample page. -->
   1.145 +	<div id="alerts">
   1.146 +		<noscript>
   1.147 +			<p>
   1.148 +				<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
   1.149 +				support, like yours, you should still see the contents (HTML data) and you should
   1.150 +				be able to edit it normally, without a rich editor interface.
   1.151 +			</p>
   1.152 +		</noscript>
   1.153 +	</div>
   1.154 +	<form action="../../../samples/sample_posteddata.php" method="post">
   1.155 +		<textarea cols="100" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
   1.156 +
   1.157 +		<script>
   1.158 +			// Replace the <textarea id="editor1"> with an CKEditor instance.
   1.159 +			CKEDITOR.replace( 'editor1', {
   1.160 +				on: {
   1.161 +					focus: onFocus,
   1.162 +					blur: onBlur,
   1.163 +
   1.164 +					// Check for availability of corresponding plugins.
   1.165 +					pluginsLoaded: function( evt ) {
   1.166 +						var doc = CKEDITOR.document, ed = evt.editor;
   1.167 +						if ( !ed.getCommand( 'bold' ) )
   1.168 +							doc.getById( 'exec-bold' ).hide();
   1.169 +						if ( !ed.getCommand( 'link' ) )
   1.170 +							doc.getById( 'exec-link' ).hide();
   1.171 +					}
   1.172 +				}
   1.173 +			});
   1.174 +		</script>
   1.175 +
   1.176 +		<p id="eMessage">
   1.177 +		</p>
   1.178 +
   1.179 +		<div id="eButtons" style="display: none">
   1.180 +			<input id="exec-bold" onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command">
   1.181 +			<input id="exec-link" onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command">
   1.182 +			<input onclick="Focus();" type="button" value="Focus">
   1.183 +			<br><br>
   1.184 +			<input onclick="InsertHTML();" type="button" value="Insert HTML">
   1.185 +			<input onclick="SetContents();" type="button" value="Set Editor Contents">
   1.186 +			<input onclick="GetContents();" type="button" value="Get Editor Contents (HTML)">
   1.187 +			<br>
   1.188 +			<textarea cols="100" id="htmlArea" rows="3">&lt;h2&gt;Test&lt;/h2&gt;&lt;p&gt;This is some &lt;a href="/Test1.html"&gt;sample&lt;/a&gt; HTML code.&lt;/p&gt;</textarea>
   1.189 +			<br>
   1.190 +			<br>
   1.191 +			<input onclick="InsertText();" type="button" value="Insert Text">
   1.192 +			<br>
   1.193 +			<textarea cols="100" id="txtArea" rows="3">   First line with some leading whitespaces.
   1.194 +
   1.195 +Second line of text preceded by two line breaks.</textarea>
   1.196 +			<br>
   1.197 +			<br>
   1.198 +			<input onclick="CheckDirty();" type="button" value="checkDirty()">
   1.199 +			<input onclick="ResetDirty();" type="button" value="resetDirty()">
   1.200 +		</div>
   1.201 +	</form>
   1.202 +	<div id="footer">
   1.203 +		<hr>
   1.204 +		<p>
   1.205 +			CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
   1.206 +		</p>
   1.207 +		<p id="copy">
   1.208 +			Copyright &copy; 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
   1.209 +			Knabben. All rights reserved.
   1.210 +		</p>
   1.211 +	</div>
   1.212 +</body>
   1.213 +</html>