plugin.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. ( function() {
  6. CKEDITOR.plugins.add( 'templates', {
  7. requires: 'dialog',
  8. // jscs:disable maximumLineLength
  9. 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%
  10. // jscs:enable maximumLineLength
  11. icons: 'templates,templates-rtl', // %REMOVE_LINE_CORE%
  12. hidpi: true, // %REMOVE_LINE_CORE%
  13. init: function( editor ) {
  14. CKEDITOR.dialog.add( 'templates', CKEDITOR.getUrl( this.path + 'dialogs/templates.js' ) );
  15. editor.addCommand( 'templates', new CKEDITOR.dialogCommand( 'templates' ) );
  16. editor.ui.addButton && editor.ui.addButton( 'Templates', {
  17. label: 'Макеты страницы',
  18. command: 'templates',
  19. toolbar: 'styles,1'
  20. } );
  21. }
  22. } );
  23. var templates = {},
  24. loadedTemplatesFiles = {};
  25. CKEDITOR.addTemplates = function( name, definition ) {
  26. templates[ name ] = definition;
  27. };
  28. CKEDITOR.getTemplates = function( name ) {
  29. return templates[ name ];
  30. };
  31. CKEDITOR.loadTemplates = function( templateFiles, callback ) {
  32. // Holds the templates files to be loaded.
  33. var toLoad = [];
  34. // Look for pending template files to get loaded.
  35. for ( var i = 0, count = templateFiles.length; i < count; i++ ) {
  36. if ( !loadedTemplatesFiles[ templateFiles[ i ] ] ) {
  37. toLoad.push( templateFiles[ i ] );
  38. loadedTemplatesFiles[ templateFiles[ i ] ] = 1;
  39. }
  40. }
  41. if ( toLoad.length )
  42. CKEDITOR.scriptLoader.load( toLoad, callback );
  43. else
  44. setTimeout( callback, 0 );
  45. };
  46. } )();
  47. /**
  48. * The templates definition set to use. It accepts a list of names separated by
  49. * comma. It must match definitions loaded with the {@link #templates_files} setting.
  50. *
  51. * config.templates = 'my_templates';
  52. *
  53. * @cfg {String} [templates='default']
  54. * @member CKEDITOR.config
  55. */
  56. /**
  57. * The list of templates definition files to load.
  58. *
  59. * config.templates_files = [
  60. * '/editor_templates/site_default.js',
  61. * 'http://www.example.com/user_templates.js
  62. * ];
  63. *
  64. * @cfg
  65. * @member CKEDITOR.config
  66. */
  67. CKEDITOR.config.templates_files = [
  68. CKEDITOR.getUrl( 'plugins/templates/templates/default.js' )
  69. ];
  70. /**
  71. * Whether the "Replace actual contents" checkbox is checked by default in the
  72. * Templates dialog.
  73. *
  74. * config.templates_replaceContent = false;
  75. *
  76. * @cfg
  77. * @member CKEDITOR.config
  78. */
  79. CKEDITOR.config.templates_replaceContent = true;