Skip to content

Commit

Permalink
add id attribute to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafaznv committed Aug 30, 2021
1 parent 5cecad0 commit 6ec1b91
Show file tree
Hide file tree
Showing 14 changed files with 512 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/nova-ckeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
'bold',
'italic',
'alignment',
'elementIdAttributes',
'horizontalLine',
'subscript',
'superscript',
Expand Down
2 changes: 1 addition & 1 deletion dist/css/field.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions resources/js/ckeditor/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ import VideoBrowser from './plugins/VideoBrowser'
import SnippetBrowser from './plugins/SnippetBrowser'

// Video
import Video from "./plugins/video/video";
import Video from "./plugins/video/video"


// Other
import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting';
import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting'
import ElementAddAttributes from './plugins/element-attribute/src/add-attribute-to-element'

// Extend the Base Class
export default class CkEditor extends ClassicEditorBase {
Expand Down Expand Up @@ -114,7 +115,8 @@ export default class CkEditor extends ClassicEditorBase {
HtmlEmbed,
SourceEditing,
Indent,
IndentBlock
IndentBlock,
ElementAddAttributes
]
}
}
2 changes: 1 addition & 1 deletion resources/js/ckeditor/config/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
types: ['gif', 'png', 'jpg', 'jpeg', 'webp']
},
toolbar: [
'mediaBrowser',
'imageBrowser',
'imageStyle:full',
'imageStyle:alignLeft',
'imageStyle:alignCenter',
Expand Down
91 changes: 91 additions & 0 deletions resources/js/ckeditor/plugins/element-attribute/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.sass-cache
connect.lock
typings

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Lerna
lerna-debug.log

# System Files
.DS_Store
Thumbs.db
21 changes: 21 additions & 0 deletions resources/js/ckeditor/plugins/element-attribute/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Rhys Stubbs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Command from '@ckeditor/ckeditor5-core/src/command'

class ElementAddAttributesCommand extends Command {
refresh() {
const element = this.editor.model.document.selection.anchor.parent

this.isEnabled = true

if (!!element && element.hasAttribute('id')) {
this.value = element.getAttribute('id')
}
else {
this.value = false
}
}

execute(options) {
const model = this.editor.model
const element = this.editor.model.document.selection.anchor.parent

model.change(writer => {
writer.setAttribute('id', options.newValue, element)
})
}
}

export default ElementAddAttributesCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ElementAddAttributesCommand from './add-attribute-to-element-command';
import {viewToModelStyleAttribute, modelToViewStyleAttribute} from './converters';

class ElementAddAttributesEditing extends Plugin {
static get pluginName() {
return 'ElementAddAttributesEditing';
}

init() {
const editor = this.editor;
const data = editor.data;
const editing = editor.editing;

// Converters for imageStyle attribute from model to view.
editing.downcastDispatcher.on('attribute:id', modelToViewStyleAttribute());
data.downcastDispatcher.on('attribute:id', modelToViewStyleAttribute());

// Converter for figure element from view to model.
data.upcastDispatcher.on('element', viewToModelStyleAttribute(), {priority: 'low'});

this.editor.commands.add('elementIdAttributes', new ElementAddAttributesCommand(this.editor));
}
}

export default ElementAddAttributesEditing;
Loading

0 comments on commit 6ec1b91

Please sign in to comment.