CKEditor Adding a Calendar control

Source: Internet
Author: User

the Calendar control here is open source.My97datepicker, first look at the following:

1, click on the left-hand custom
Calendar Controlbutton to pop up the Calendar Control dialog box.



2. Click OK to add the Calendar control to the form designer while preserving the calendar's control style


3. Click the CKEditor preview control to see if you can make a calendar selection.



Here's the implementation, for how to add a custom control to CKEditor, refer to the
ckeditor_4.4.5 Customizing Toolbars"article.

First add the My97datepicker js file to the plugin directory:



the code for Plugin.js is as follows:

  1. CKEDITOR.plugins.add (' DatePicker ',
  2. {
  3. Requires: [' Dialog '],
  4. Init: function (editor)
  5. {
  6. var pluginname = ' DatePicker ';
  7. //Loading a custom window
  8. CKEDITOR.dialog.add (' DatePicker ',This.path + "Dialogs/datepicker.js");
  9. //Register a call command for a custom plugin
  10. Editor.addcommand (Pluginname, new Ckeditor.dialogcommand ( ' DatePicker '));
  11. //Register a button to invoke the custom plugin
  12. Editor.ui.addButton (' DatePicker ',
  13. {
  14. //editor.lang.mine is a Chinese item defined in the Zh-cn.js,
  15. //You can write English characters directly here, but to display Chinese you have to modify Zh-cn.js
  16. Label:editor.lang.mine,
  17. Command:pluginname
  18. });
  19. }
  20. }
  21. );


The This.path in the Nineth line of code above can get the path where the current file is located.

The Datepicker.js code under dialogs is as follows:


  1. CKEDITOR.dialog.add ( ' datepicker ', function (editor)
  2. {
  3. return {
  4. Title: ' Calendar control ',
  5. MINWIDTH:300,
  6. minheight:150,
  7. Contents: [
  8. {
  9. ID: ' tab1 ',
  10. Label: ",
  11. Title: ",
  12. Elements:
  13. [
  14. {
  15. Type: ' html ',
  16. HTML:' Select Date: <style type= ' text/css ' >
  17. . Wdate{border: #999 1px solid;height:20px;
  18. Background: #fff URL (' +ckeditor.plugins.get ("DatePicker"). path+'/images/datepicker.gif)
  19. No-repeat right;}
  20. </style>
  21. <input type= "text" id= "d241" onfocus= "Wdatepicker ({datefmt:\ ' Yyyy-mm-dd hh:mm:ss\ '})"
  22. class= "Wdate" style= "width:150px"/> '
  23. }
  24. ]
  25. }
  26. ],
  27. OnOk: function () {
  28. editor.inserthtml ('
  29. <style type= "Text/css" >
  30. . Wdate{border: #999 1px solid;height:20px;
  31. Background: #fff URL (' +ckeditor.plugins.get ("DatePicker"). path+'/images/datepicker.gif)
  32. No-repeat right;}
  33. </style>
  34. <input type= "text" id= "d241" onfocus= "Wdatepicker ({datefmt:\ ' Yyyy-mm-dd hh:mm:ss\ '})"
  35. class= "Wdate" style= "width:150px"/> ");
  36. },
  37. };
  38. } );



The style of the calendar control needs to be added to the above JS file, otherwise it is easy to refer to a bug where the reference path does not cause the style to be lost.

Transferred from: http://itxxz.com/a/gaoji/2014/1127/ckeditor_my97DatePicker.html

CKEditor Adding a Calendar control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.