เพิ่มการปรับแต่ง ckeditor เวอร์ชั่น 4.4.1 ด้วย jQuery
ในส่วนนี้จะแนะนำเพิ่มเติม กับการปรับแต่ง ckeditor
cke_config.js
- // JavaScript Document
- var toolbar_full=[
- { name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ] },
- { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
- { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
- { name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
- '/',
- { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
- { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] },
- { name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
- { name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
- '/',
- { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
- { name: 'colors', items: [ 'TextColor', 'BGColor' ] },
- { name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
- { name: 'others', items: [ '-' ] },
- { name: 'about', items: [ 'About' ] }
- ];
- var toolbar_basic=[
- [ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ],
- [ 'FontSize', 'TextColor', 'BGColor' ]
- ]
- var toolbar_set=[
- { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] }, // Defines toolbar group with name (used to create voice label) and items in 3 subgroups.
- [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ], // Defines toolbar group without name.
- '/', // Line break - next group will be placed in new line.
- { name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
- ];
- var my_toolbar_group = [
- { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
- { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
- { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
- { name: 'forms' },
- '/',
- { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
- { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
- { name: 'links' },
- { name: 'insert' },
- '/',
- { name: 'styles' },
- { name: 'colors' },
- { name: 'tools' },
- { name: 'others' },
- { name: 'about' }
- ];
- var cke_config={
- language: 'th', //กำหนดภาษา เช่น th en us de
- uiColor: '#A1CFF3',
- toolbar:toolbar_basic
- // toolbarGroups:my_toolbar_group
- }
เมื่อมีการใช้งาน เราจะเรียกใช้ไฟล์นี้ด้วย
- <script src="cke_config.js"></script>
จากนั้นในส่วนของ การใช้งาน ckeditor จะใช้ค่าตัวแปร จากไฟล์ xxx
มากำหนด รูปแบบของ ckeditor อีกที
จะได้เป็น
- <script type="text/javascript">
- $(function(){
- $("#message").ckeditor(cke_config);
- });
- </script>
preview
all code
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title> </title>
- </head>
- <body>
- <div style="margin:auto;width:75%;">
- <form id="form5" name="form5" method="post" action="">
- <textarea name="message" id="message" cols="45" rows="5"></textarea>
- </form>
- <br />
- </div>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script src="ckeditor/ckeditor.js"></script>
- <script src="ckeditor/adapters/jquery.js"></script>
- <script src="cke_config.js"></script>
- <script type="text/javascript">
- $(function(){
- $("#message").ckeditor(cke_config);
- // บรรทัดล่างที่ comment ไว้ลบออกได้
- // var editor = $("#message").ckeditor().editor;
- // $(".emoticon").click(function(){
- // var imgIns=$(this).attr("src");
- // var imgHTML="<img src="+imgIns+" />";
- // editor.insertHtml(imgHTML);
- // });
- });
- </script>
- </body>
- </html>