Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the CDN version to the timestamp plugin tutorial #19

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions timestamp-plugin/cdn/final-project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CKEditor 5 Framework – timestamp plugin</title>
<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.css" />
</head>
<body>
<div id="editor">
<h2>Timestamp plugin</h2>
<p>Press the timestamp button to insert the current date and time.</p>
</div>

<script src="https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.umd.js"></script>

<script type="module" src="/main.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions timestamp-plugin/cdn/final-project/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

const {
ClassicEditor,
Bold,
Essentials,
Heading,
Italic,
Paragraph,
List,
Plugin,
ButtonView
} = CKEDITOR;

class Timestamp extends Plugin {
init() {
const editor = this.editor;

editor.ui.componentFactory.add( 'timestamp', () => {
// The button will be an instance of ButtonView.
const button = new ButtonView();

button.set( {
label: 'Timestamp',
withText: true
} );

//Execute a callback function when the button is clicked
button.on( 'execute', () => {
const now = new Date();

//Change the model using the model writer
editor.model.change( writer => {

//Insert the text at the user's current position
editor.model.insertContent( writer.createText( now.toString() ) );
} );
} );

return button;
} );
}
}

ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Essentials, Paragraph, Heading, List, Bold, Italic, Timestamp ],
toolbar: [ 'heading', 'bold', 'italic', 'numberedList', 'bulletedList', 'timestamp' ]
} )
.then( editor => {
console.log( 'Editor was initialized', editor );
} )
.catch( error => {
console.error( error.stack );
} );
14 changes: 14 additions & 0 deletions timestamp-plugin/cdn/final-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "final-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.4.1"
}
}
19 changes: 19 additions & 0 deletions timestamp-plugin/cdn/starter-files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CKEditor 5 Framework – timestamp plugin</title>
<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.css" />
</head>
<body>
<div id="editor">
<h2>Timestamp plugin</h2>
<p>Press the timestamp button to insert the current date and time.</p>
</div>

<script src="https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.umd.js"></script>

<script type="module" src="/main.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions timestamp-plugin/cdn/starter-files/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

const {
ClassicEditor,
Bold,
Essentials,
Heading,
Italic,
Paragraph,
List
} = CKEDITOR;

ClassicEditor
.create( document.querySelector( '#editor' ), {
licenseKey: 'GPL',
plugins: [ Essentials, Paragraph, Heading, List, Bold, Italic ],
toolbar: [ 'heading', 'bold', 'italic', 'numberedList', 'bulletedList' ]
} )
.then( editor => {
console.log( 'Editor was initialized', editor );
} )
.catch( error => {
console.error( error.stack );
} );
14 changes: 14 additions & 0 deletions timestamp-plugin/cdn/starter-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "starter-files",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.4.1"
}
}