skin.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. skin.js
  7. =========
  8. In this file we interact with the CKEditor JavaScript API to register the skin
  9. and enable additional skin related features.
  10. The level of complexity of this file depends on the features available in the
  11. skin. There is only one mandatory line of code to be included here, which is
  12. setting CKEDITOR.skin.name. All the rest is optional, but recommended to be
  13. implemented as they make higher quality skins.
  14. For this skin, the following tasks are achieved in this file:
  15. 1. Register the skin.
  16. 2. Register browser specific skin files.
  17. 3. Define the "Chameleon" feature.
  18. 4. Register the skin icons, to have them used on the development version of
  19. the skin.
  20. */
  21. // 1. Register the skin
  22. // ----------------------
  23. // The CKEDITOR.skin.name property must be set to the skin name. This is a
  24. // lower-cased name, which must match the skin folder name as well as the value
  25. // used on config.skin to tell the editor to use the skin.
  26. //
  27. // This is the only mandatory property to be defined in this file.
  28. CKEDITOR.skin.name = 'moono';
  29. // 2. Register browser specific skin files
  30. // -----------------------------------------
  31. // (http://docs.cksource.com/CKEditor_4.x/Skin_SDK/Browser_Hacks)
  32. //
  33. // To help implementing browser specific "hacks" to the skin files and have it
  34. // easy to maintain, it is possible to have dedicated files for such browsers,
  35. // for both the main skin CSS files: editor.css and dialog.css.
  36. //
  37. // The browser files must be named after the main file names, appended by an
  38. // underscore and the browser name (e.g. editor_ie.css, dialog_ie8.css).
  39. //
  40. // The accepted browser names must match the CKEDITOR.env properties. The most
  41. // common names are: ie, webkit and gecko. Check the documentation for the complete
  42. // list:
  43. // http://docs.ckeditor.com/#!/api/CKEDITOR.env
  44. //
  45. // Internet explorer is an expection and the browser version is also accepted
  46. // (ie7, ie8, ie9, ie10), as well as a special name for IE in Quirks mode (iequirks).
  47. //
  48. // The available browser specific files must be set separately for editor.css
  49. // and dialog.css.
  50. CKEDITOR.skin.ua_editor = 'ie,iequirks,ie7,ie8,gecko';
  51. CKEDITOR.skin.ua_dialog = 'ie,iequirks,ie7,ie8';
  52. // 3. Define the "Chameleon" feature
  53. // -----------------------------------
  54. // (http://docs.cksource.com/CKEditor_4.x/Skin_SDK/Chameleon)
  55. //
  56. // "Chameleon" is a unique feature available in CKEditor. It makes it possible
  57. // to end users to specify which color to use as the basis for the editor UI.
  58. // It is enough to set config.uiColor to any color value and voila, the UI is
  59. // colored.
  60. //
  61. // The only detail here is that the skin itself must be compatible with the
  62. // Chameleon feature. That's because the skin CSS files are the responsible to
  63. // apply colors in the UI and each skin do that in different way and on
  64. // different places.
  65. //
  66. // Implementing the Chameleon feature requires a bit of JavaScript programming.
  67. // The CKEDITOR.skin.chameleon function must be defined. It must return the CSS
  68. // "template" to be used to change the color of a specific CKEditor instance
  69. // available in the page. When a color change is required, this template is
  70. // appended to the page holding the editor, overriding styles defined in the
  71. // skin files.
  72. //
  73. // The "$color" placeholder can be used in the returned string. It'll be
  74. // replaced with the desired color.
  75. CKEDITOR.skin.chameleon = ( function() {
  76. // This method can be used to adjust colour brightness of various element.
  77. // Colours are accepted in 7-byte hex format, for example: #00ff00.
  78. // Brightness ratio must be a float number within [-1, 1],
  79. // where -1 is black, 1 is white and 0 is the original colour.
  80. var colorBrightness = ( function() {
  81. function channelBrightness( channel, ratio ) {
  82. var brighten = ratio < 0 ? (
  83. 0 | channel * ( 1 + ratio )
  84. ) : (
  85. 0 | channel + ( 255 - channel ) * ratio
  86. );
  87. return ( '0' + brighten.toString( 16 ) ).slice( -2 );
  88. }
  89. return function( hexColor, ratio ) {
  90. var channels = hexColor.match( /[^#]./g );
  91. for ( var i = 0 ; i < 3 ; i++ )
  92. channels[ i ] = channelBrightness( parseInt( channels[ i ], 16 ), ratio );
  93. return '#' + channels.join( '' );
  94. };
  95. } )(),
  96. // Use this function just to avoid having to repeat all these rules on
  97. // several places of our template.
  98. verticalGradient = ( function() {
  99. var template = new CKEDITOR.template( 'background:#{to};' +
  100. 'background-image:linear-gradient(to bottom,{from},{to});' +
  101. 'filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr=\'{from}\',endColorstr=\'{to}\');' );
  102. return function( from, to ) {
  103. return template.output( { from: from, to: to } );
  104. };
  105. } )(),
  106. // Style templates for various user interface parts:
  107. // * Default editor template.
  108. // * Default panel template.
  109. templates = {
  110. editor: new CKEDITOR.template(
  111. '{id}.cke_chrome [border-color:{defaultBorder};] ' +
  112. '{id} .cke_top [ ' +
  113. '{defaultGradient}' +
  114. 'border-bottom-color:{defaultBorder};' +
  115. '] ' +
  116. '{id} .cke_bottom [' +
  117. '{defaultGradient}' +
  118. 'border-top-color:{defaultBorder};' +
  119. '] ' +
  120. '{id} .cke_resizer [border-right-color:{ckeResizer}] ' +
  121. // Dialogs.
  122. '{id} .cke_dialog_title [' +
  123. '{defaultGradient}' +
  124. 'border-bottom-color:{defaultBorder};' +
  125. '] ' +
  126. '{id} .cke_dialog_footer [' +
  127. '{defaultGradient}' +
  128. 'outline-color:{defaultBorder};' +
  129. 'border-top-color:{defaultBorder};' + // IE7 doesn't use outline.
  130. '] ' +
  131. '{id} .cke_dialog_tab [' +
  132. '{lightGradient}' +
  133. 'border-color:{defaultBorder};' +
  134. '] ' +
  135. '{id} .cke_dialog_tab:hover [' +
  136. '{mediumGradient}' +
  137. '] ' +
  138. '{id} .cke_dialog_contents [' +
  139. 'border-top-color:{defaultBorder};' +
  140. '] ' +
  141. '{id} .cke_dialog_tab_selected, {id} .cke_dialog_tab_selected:hover [' +
  142. 'background:{dialogTabSelected};' +
  143. 'border-bottom-color:{dialogTabSelectedBorder};' +
  144. '] ' +
  145. '{id} .cke_dialog_body [' +
  146. 'background:{dialogBody};' +
  147. 'border-color:{defaultBorder};' +
  148. '] ' +
  149. // Toolbars, buttons.
  150. '{id} .cke_toolgroup [' +
  151. '{lightGradient}' +
  152. 'border-color:{defaultBorder};' +
  153. '] ' +
  154. '{id} a.cke_button_off:hover, {id} a.cke_button_off:focus, {id} a.cke_button_off:active [' +
  155. '{mediumGradient}' +
  156. '] ' +
  157. '{id} .cke_button_on [' +
  158. '{ckeButtonOn}' +
  159. '] ' +
  160. '{id} .cke_toolbar_separator [' +
  161. 'background-color: {ckeToolbarSeparator};' +
  162. '] ' +
  163. // Combo buttons.
  164. '{id} .cke_combo_button [' +
  165. 'border-color:{defaultBorder};' +
  166. '{lightGradient}' +
  167. '] ' +
  168. '{id} a.cke_combo_button:hover, {id} a.cke_combo_button:focus, {id} .cke_combo_on a.cke_combo_button [' +
  169. 'border-color:{defaultBorder};' +
  170. '{mediumGradient}' +
  171. '] ' +
  172. // Elementspath.
  173. '{id} .cke_path_item [' +
  174. 'color:{elementsPathColor};' +
  175. '] ' +
  176. '{id} a.cke_path_item:hover, {id} a.cke_path_item:focus, {id} a.cke_path_item:active [' +
  177. 'background-color:{elementsPathBg};' +
  178. '] ' +
  179. '{id}.cke_panel [' +
  180. 'border-color:{defaultBorder};' +
  181. '] '
  182. ),
  183. panel: new CKEDITOR.template(
  184. // Panel drop-downs.
  185. '.cke_panel_grouptitle [' +
  186. '{lightGradient}' +
  187. 'border-color:{defaultBorder};' +
  188. '] ' +
  189. // Context menus.
  190. '.cke_menubutton_icon [' +
  191. 'background-color:{menubuttonIcon};' +
  192. '] ' +
  193. '.cke_menubutton:hover .cke_menubutton_icon, .cke_menubutton:focus .cke_menubutton_icon, .cke_menubutton:active .cke_menubutton_icon [' +
  194. 'background-color:{menubuttonIconHover};' +
  195. '] ' +
  196. '.cke_menuseparator [' +
  197. 'background-color:{menubuttonIcon};' +
  198. '] ' +
  199. // Color boxes.
  200. 'a:hover.cke_colorbox, a:focus.cke_colorbox, a:active.cke_colorbox [' +
  201. 'border-color:{defaultBorder};' +
  202. '] ' +
  203. 'a:hover.cke_colorauto, a:hover.cke_colormore, a:focus.cke_colorauto, a:focus.cke_colormore, a:active.cke_colorauto, a:active.cke_colormore [' +
  204. 'background-color:{ckeColorauto};' +
  205. 'border-color:{defaultBorder};' +
  206. '] '
  207. )
  208. };
  209. return function( editor, part ) {
  210. var uiColor = editor.uiColor,
  211. // The following are CSS styles used in templates.
  212. // Styles are generated according to current editor.uiColor.
  213. templateStyles = {
  214. // CKEditor instances have a unique ID, which is used as class name into
  215. // the outer container of the editor UI (e.g. ".cke_1").
  216. //
  217. // The Chameleon feature is available for each CKEditor instance,
  218. // independently. Because of this, we need to prefix all CSS selectors with
  219. // the unique class name of the instance.
  220. id: '.' + editor.id,
  221. // These styles are used by various UI elements.
  222. defaultBorder: colorBrightness( uiColor, -0.1 ),
  223. defaultGradient: verticalGradient( colorBrightness( uiColor, 0.9 ), uiColor ),
  224. lightGradient: verticalGradient( colorBrightness( uiColor, 1 ), colorBrightness( uiColor, 0.7 ) ),
  225. mediumGradient: verticalGradient( colorBrightness( uiColor, 0.8 ), colorBrightness( uiColor, 0.5 ) ),
  226. // These are for specific UI elements.
  227. ckeButtonOn: verticalGradient( colorBrightness( uiColor, 0.6 ), colorBrightness( uiColor, 0.7 ) ),
  228. ckeResizer: colorBrightness( uiColor, -0.4 ),
  229. ckeToolbarSeparator: colorBrightness( uiColor, 0.5 ),
  230. ckeColorauto: colorBrightness( uiColor, 0.8 ),
  231. dialogBody: colorBrightness( uiColor, 0.7 ),
  232. // Use gradient instead of simple hex to avoid further filter resetting in IE.
  233. dialogTabSelected: verticalGradient( '#FFFFFF', '#FFFFFF' ),
  234. dialogTabSelectedBorder: '#FFF',
  235. elementsPathColor: colorBrightness( uiColor, -0.6 ),
  236. elementsPathBg: uiColor,
  237. menubuttonIcon: colorBrightness( uiColor, 0.5 ),
  238. menubuttonIconHover: colorBrightness( uiColor, 0.3 )
  239. };
  240. return templates[ part ]
  241. .output( templateStyles )
  242. .replace( /\[/g, '{' ) // Replace brackets with braces.
  243. .replace( /\]/g, '}' );
  244. };
  245. } )();
  246. // %REMOVE_START%
  247. // 4. Register the skin icons for development purposes only
  248. // ----------------------------------------------------------
  249. // (http://docs.cksource.com/CKEditor_4.x/Skin_SDK/Icons)
  250. //
  251. // Note: As "moono" is the default CKEditor skin, it provides no custom icons,
  252. // thus this code is commented out.
  253. //
  254. // This code is here just to make the skin work fully when using its "source"
  255. // version. Without this, the skin will still work, but its icons will not be
  256. // used (again, on source version only).
  257. //
  258. // This block of code is not necessary on the release version of the skin.
  259. // Because of this it is very important to include it inside the REMOVE_START
  260. // and REMOVE_END comment markers, so the skin builder will properly clean
  261. // things up.
  262. //
  263. // If a required icon is not available here, the plugin defined icon will be
  264. // used instead. This means that a skin is not required to provide all icons.
  265. // Actually, it is not required to provide icons at all.
  266. //
  267. // (function() {
  268. // // The available icons. This list must match the file names (without
  269. // // extension) available inside the "icons" folder.
  270. // var icons = ( 'about,anchor-rtl,anchor,bgcolor,bidiltr,bidirtl,blockquote,' +
  271. // 'bold,bulletedlist-rtl,bulletedlist,button,checkbox,copy-rtl,copy,' +
  272. // 'creatediv,cut-rtl,cut,docprops-rtl,docprops,find-rtl,find,flash,form,' +
  273. // 'hiddenfield,horizontalrule,icons,iframe,image,imagebutton,indent-rtl,' +
  274. // 'indent,italic,justifyblock,justifycenter,justifyleft,justifyright,' +
  275. // 'link,maximize,newpage-rtl,newpage,numberedlist-rtl,numberedlist,' +
  276. // 'outdent-rtl,outdent,pagebreak-rtl,pagebreak,paste-rtl,paste,' +
  277. // 'pastefromword-rtl,pastefromword,pastetext-rtl,pastetext,preview-rtl,' +
  278. // 'preview,print,radio,redo-rtl,redo,removeformat,replace,save,scayt,' +
  279. // 'select-rtl,select,selectall,showblocks-rtl,showblocks,smiley,' +
  280. // 'source-rtl,source,specialchar,spellchecker,strike,subscript,' +
  281. // 'superscript,table,templates-rtl,templates,textarea-rtl,textarea,' +
  282. // 'textcolor,textfield-rtl,textfield,uicolor,underline,undo-rtl,undo,unlink' ).split( ',' );
  283. //
  284. // var iconsFolder = CKEDITOR.getUrl( CKEDITOR.skin.path() + 'icons/' + ( CKEDITOR.env.hidpi ? 'hidpi/' : '' ) );
  285. //
  286. // for ( var i = 0; i < icons.length; i++ ) {
  287. // CKEDITOR.skin.addIcon( icons[ i ], iconsFolder + icons[ i ] + '.png' );
  288. // }
  289. // })();
  290. // %REMOVE_END%