plugin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. /**
  6. * @fileOverview The Save plugin.
  7. */
  8. ( function() {
  9. var saveCmd = {
  10. readOnly: 1,
  11. exec: function( editor ) {
  12. if ( editor.fire( 'save' ) ) {
  13. var $form = editor.element.$.form;
  14. if ( $form ) {
  15. try {
  16. $form.submit();
  17. } catch ( e ) {
  18. // If there's a button named "submit" then the form.submit
  19. // function is masked and can't be called in IE/FF, so we
  20. // call the click() method of that button.
  21. if ( $form.submit.click )
  22. $form.submit.click();
  23. }
  24. }
  25. }
  26. }
  27. };
  28. var pluginName = 'save';
  29. // Register a plugin named "save".
  30. CKEDITOR.plugins.add( pluginName, {
  31. // jscs:disable maximumLineLength
  32. lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
  33. // jscs:enable maximumLineLength
  34. icons: 'save', // %REMOVE_LINE_CORE%
  35. hidpi: true, // %REMOVE_LINE_CORE%
  36. init: function( editor ) {
  37. // Save plugin is for replace mode only.
  38. if ( editor.elementMode != CKEDITOR.ELEMENT_MODE_REPLACE )
  39. return;
  40. var command = editor.addCommand( pluginName, saveCmd );
  41. command.modes = { wysiwyg: !!( editor.element.$.form ) };
  42. editor.ui.addButton && editor.ui.addButton( 'Save', {
  43. label: editor.lang.save.toolbar,
  44. command: pluginName,
  45. toolbar: 'document,10'
  46. } );
  47. }
  48. } );
  49. } )();
  50. /**
  51. * Fired when the user clicks the Save button on the editor toolbar.
  52. * This event allows to overwrite the default Save button behavior.
  53. *
  54. * @since 4.2
  55. * @event save
  56. * @member CKEDITOR.editor
  57. * @param {CKEDITOR.editor} editor This editor instance.
  58. */