]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blobdiff - sources/plugins/colorbutton/plugin.js
Add audio, color and fonts
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / plugins / colorbutton / plugin.js
diff --git a/sources/plugins/colorbutton/plugin.js b/sources/plugins/colorbutton/plugin.js
new file mode 100644 (file)
index 0000000..5382333
--- /dev/null
@@ -0,0 +1,411 @@
+/**\r
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.\r
+ * For licensing, see LICENSE.md or http://ckeditor.com/license\r
+ */\r
+\r
+/**\r
+ * @fileOverview The "colorbutton" plugin that makes it possible to assign\r
+ *               text and background colors to editor contents.\r
+ *\r
+ */\r
+CKEDITOR.plugins.add( 'colorbutton', {\r
+       requires: 'panelbutton,floatpanel',\r
+       // jscs:disable maximumLineLength\r
+       lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,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,oc,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%\r
+       // jscs:enable maximumLineLength\r
+       icons: 'bgcolor,textcolor', // %REMOVE_LINE_CORE%\r
+       hidpi: true, // %REMOVE_LINE_CORE%\r
+       init: function( editor ) {\r
+               var config = editor.config,\r
+                       lang = editor.lang.colorbutton;\r
+\r
+               if ( !CKEDITOR.env.hc ) {\r
+                       addButton( 'TextColor', 'fore', lang.textColorTitle, 10, {\r
+                               contentTransformations: [\r
+                                       [\r
+                                               {\r
+                                                       element: 'font',\r
+                                                       check: 'span{color}',\r
+                                                       left: function( element ) {\r
+                                                               return !!element.attributes.color;\r
+                                                       },\r
+                                                       right: function( element ) {\r
+                                                               element.name = 'span';\r
+\r
+                                                               element.attributes.color && ( element.styles.color = element.attributes.color );\r
+                                                               delete element.attributes.color;\r
+                                                       }\r
+                                               }\r
+                                       ]\r
+                               ]\r
+                       } );\r
+\r
+                       var  bgOptions = {},\r
+                               normalizeBackground = editor.config.colorButton_normalizeBackground;\r
+\r
+                       if ( normalizeBackground === undefined || normalizeBackground ) {\r
+                               // If background contains only color, then we want to convert it into background-color so that it's\r
+                               // correctly picked by colorbutton plugin.\r
+                               bgOptions.contentTransformations = [\r
+                                       [\r
+                                               {\r
+                                                       // Transform span that specify background with color only to background-color.\r
+                                                       element: 'span',\r
+                                                       left: function( element ) {\r
+                                                               var tools = CKEDITOR.tools;\r
+                                                               if ( element.name != 'span' || !element.styles || !element.styles.background ) {\r
+                                                                       return false;\r
+                                                               }\r
+\r
+                                                               var background = tools.style.parse.background( element.styles.background );\r
+\r
+                                                               // We return true only if background specifies **only** color property, and there's only one background directive.\r
+                                                               return background.color && tools.objectKeys( background ).length === 1;\r
+                                                       },\r
+                                                       right: function( element ) {\r
+                                                               var style = new CKEDITOR.style( editor.config.colorButton_backStyle, {\r
+                                                                               color: element.styles.background\r
+                                                                       } ),\r
+                                                                       definition = style.getDefinition();\r
+\r
+                                                               // Align the output object with the template used in config.\r
+                                                               element.name = definition.element;\r
+                                                               element.styles = definition.styles;\r
+                                                               element.attributes = definition.attributes || {};\r
+\r
+                                                               return element;\r
+                                                       }\r
+                                               }\r
+                                       ]\r
+                               ];\r
+                       }\r
+\r
+                       addButton( 'BGColor', 'back', lang.bgColorTitle, 20, bgOptions );\r
+               }\r
+\r
+               function addButton( name, type, title, order, options ) {\r
+                       var style = new CKEDITOR.style( config[ 'colorButton_' + type + 'Style' ] ),\r
+                               colorBoxId = CKEDITOR.tools.getNextId() + '_colorBox';\r
+\r
+                       options = options || {};\r
+\r
+                       editor.ui.add( name, CKEDITOR.UI_PANELBUTTON, {\r
+                               label: title,\r
+                               title: title,\r
+                               modes: { wysiwyg: 1 },\r
+                               editorFocus: 0,\r
+                               toolbar: 'colors,' + order,\r
+                               allowedContent: style,\r
+                               requiredContent: style,\r
+                               contentTransformations: options.contentTransformations,\r
+\r
+                               panel: {\r
+                                       css: CKEDITOR.skin.getPath( 'editor' ),\r
+                                       attributes: { role: 'listbox', 'aria-label': lang.panelTitle }\r
+                               },\r
+\r
+                               onBlock: function( panel, block ) {\r
+                                       block.autoSize = true;\r
+                                       block.element.addClass( 'cke_colorblock' );\r
+                                       block.element.setHtml( renderColors( panel, type, colorBoxId ) );\r
+                                       // The block should not have scrollbars (#5933, #6056)\r
+                                       block.element.getDocument().getBody().setStyle( 'overflow', 'hidden' );\r
+\r
+                                       CKEDITOR.ui.fire( 'ready', this );\r
+\r
+                                       var keys = block.keys;\r
+                                       var rtl = editor.lang.dir == 'rtl';\r
+                                       keys[ rtl ? 37 : 39 ] = 'next'; // ARROW-RIGHT\r
+                                       keys[ 40 ] = 'next'; // ARROW-DOWN\r
+                                       keys[ 9 ] = 'next'; // TAB\r
+                                       keys[ rtl ? 39 : 37 ] = 'prev'; // ARROW-LEFT\r
+                                       keys[ 38 ] = 'prev'; // ARROW-UP\r
+                                       keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB\r
+                                       keys[ 32 ] = 'click'; // SPACE\r
+                               },\r
+\r
+                               refresh: function() {\r
+                                       if ( !editor.activeFilter.check( style ) )\r
+                                               this.setState( CKEDITOR.TRISTATE_DISABLED );\r
+                               },\r
+\r
+                               // The automatic colorbox should represent the real color (#6010)\r
+                               onOpen: function() {\r
+\r
+                                       var selection = editor.getSelection(),\r
+                                               block = selection && selection.getStartElement(),\r
+                                               path = editor.elementPath( block ),\r
+                                               color;\r
+\r
+                                       if ( !path )\r
+                                               return;\r
+\r
+                                       // Find the closest block element.\r
+                                       block = path.block || path.blockLimit || editor.document.getBody();\r
+\r
+                                       // The background color might be transparent. In that case, look up the color in the DOM tree.\r
+                                       do {\r
+                                               color = block && block.getComputedStyle( type == 'back' ? 'background-color' : 'color' ) || 'transparent';\r
+                                       }\r
+                                       while ( type == 'back' && color == 'transparent' && block && ( block = block.getParent() ) );\r
+\r
+                                       // The box should never be transparent.\r
+                                       if ( !color || color == 'transparent' )\r
+                                               color = '#ffffff';\r
+\r
+                                       if ( config.colorButton_enableAutomatic !== false ) {\r
+                                               this._.panel._.iframe.getFrameDocument().getById( colorBoxId ).setStyle( 'background-color', color );\r
+                                       }\r
+\r
+                                       return color;\r
+                               }\r
+                       } );\r
+               }\r
+\r
+               function renderColors( panel, type, colorBoxId ) {\r
+                       var output = [],\r
+                               colors = config.colorButton_colors.split( ',' ),\r
+                               colorsPerRow = config.colorButton_colorsPerRow || 6,\r
+                               // Tells if we should include "More Colors..." button.\r
+                               moreColorsEnabled = editor.plugins.colordialog && config.colorButton_enableMore !== false,\r
+                               // aria-setsize and aria-posinset attributes are used to indicate size of options, because\r
+                               // screen readers doesn't play nice with table, based layouts (#12097).\r
+                               total = colors.length + ( moreColorsEnabled ? 2 : 1 );\r
+\r
+                       var clickFn = CKEDITOR.tools.addFunction( function( color, type ) {\r
+                               var applyColorStyle = arguments.callee;\r
+                               function onColorDialogClose( evt ) {\r
+                                       this.removeListener( 'ok', onColorDialogClose );\r
+                                       this.removeListener( 'cancel', onColorDialogClose );\r
+\r
+                                       evt.name == 'ok' && applyColorStyle( this.getContentElement( 'picker', 'selectedColor' ).getValue(), type );\r
+                               }\r
+\r
+                               if ( color == '?' ) {\r
+                                       editor.openDialog( 'colordialog', function() {\r
+                                               this.on( 'ok', onColorDialogClose );\r
+                                               this.on( 'cancel', onColorDialogClose );\r
+                                       } );\r
+\r
+                                       return;\r
+                               }\r
+\r
+                               editor.focus();\r
+\r
+                               panel.hide();\r
+\r
+                               editor.fire( 'saveSnapshot' );\r
+\r
+                               // Clean up any conflicting style within the range.\r
+                               editor.removeStyle( new CKEDITOR.style( config[ 'colorButton_' + type + 'Style' ], { color: 'inherit' } ) );\r
+\r
+                               if ( color ) {\r
+                                       var colorStyle = config[ 'colorButton_' + type + 'Style' ];\r
+\r
+                                       colorStyle.childRule = type == 'back' ?\r
+                                       function( element ) {\r
+                                               // It's better to apply background color as the innermost style. (#3599)\r
+                                               // Except for "unstylable elements". (#6103)\r
+                                               return isUnstylable( element );\r
+                                       } : function( element ) {\r
+                                               // Fore color style must be applied inside links instead of around it. (#4772,#6908)\r
+                                               return !( element.is( 'a' ) || element.getElementsByTag( 'a' ).count() ) || isUnstylable( element );\r
+                                       };\r
+\r
+                                       editor.applyStyle( new CKEDITOR.style( colorStyle, { color: color } ) );\r
+                               }\r
+\r
+                               editor.fire( 'saveSnapshot' );\r
+                       } );\r
+\r
+                       if ( config.colorButton_enableAutomatic !== false ) {\r
+                               // Render the "Automatic" button.\r
+                               output.push( '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +\r
+                                       ' title="', lang.auto, '"' +\r
+                                       ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +\r
+                                       ' href="javascript:void(\'', lang.auto, '\')"' +\r
+                                       ' role="option" aria-posinset="1" aria-setsize="', total, '">' +\r
+                                               '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' +\r
+                                                       '<tr>' +\r
+                                                               '<td colspan="' + colorsPerRow + '" align="center"><span class="cke_colorbox" id="', colorBoxId, '"></span>', lang.auto, '</td>' +\r
+                                                       '</tr>' +\r
+                                               '</table>' +\r
+                                       '</a>' );\r
+                       }\r
+                       output.push( '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' );\r
+\r
+                       // Render the color boxes.\r
+                       for ( var i = 0; i < colors.length; i++ ) {\r
+                               if ( ( i % colorsPerRow ) === 0 )\r
+                                       output.push( '</tr><tr>' );\r
+\r
+                               var parts = colors[ i ].split( '/' ),\r
+                                       colorName = parts[ 0 ],\r
+                                       colorCode = parts[ 1 ] || colorName;\r
+\r
+                               // The data can be only a color code (without #) or colorName + color code\r
+                               // If only a color code is provided, then the colorName is the color with the hash\r
+                               // Convert the color from RGB to RRGGBB for better compatibility with IE and <font>. See #5676\r
+                               if ( !parts[ 1 ] )\r
+                                       colorName = '#' + colorName.replace( /^(.)(.)(.)$/, '$1$1$2$2$3$3' );\r
+\r
+                               var colorLabel = editor.lang.colorbutton.colors[ colorCode ] || colorCode;\r
+                               output.push( '<td>' +\r
+                                       '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' +\r
+                                               ' title="', colorLabel, '"' +\r
+                                               ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'', colorName, '\',\'', type, '\'); return false;"' +\r
+                                               ' href="javascript:void(\'', colorLabel, '\')"' +\r
+                                               ' role="option" aria-posinset="', ( i + 2 ), '" aria-setsize="', total, '">' +\r
+                                               '<span class="cke_colorbox" style="background-color:#', colorCode, '"></span>' +\r
+                                       '</a>' +\r
+                                       '</td>' );\r
+                       }\r
+\r
+                       // Render the "More Colors" button.\r
+                       if ( moreColorsEnabled ) {\r
+                               output.push( '</tr>' +\r
+                                       '<tr>' +\r
+                                               '<td colspan="' + colorsPerRow + '" align="center">' +\r
+                                                       '<a class="cke_colormore" _cke_focus=1 hidefocus=true' +\r
+                                                               ' title="', lang.more, '"' +\r
+                                                               ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'?\',\'', type, '\');return false;"' +\r
+                                                               ' href="javascript:void(\'', lang.more, '\')"', ' role="option" aria-posinset="', total, '" aria-setsize="', total, '">', lang.more, '</a>' +\r
+                                               '</td>' ); // tr is later in the code.\r
+                       }\r
+\r
+                       output.push( '</tr></table>' );\r
+\r
+                       return output.join( '' );\r
+               }\r
+\r
+               function isUnstylable( ele ) {\r
+                       return ( ele.getAttribute( 'contentEditable' ) == 'false' ) || ele.getAttribute( 'data-nostyle' );\r
+               }\r
+       }\r
+} );\r
+\r
+/**\r
+ * Whether to enable the **More Colors** button in the color selectors.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             config.colorButton_enableMore = false;\r
+ *\r
+ * @cfg {Boolean} [colorButton_enableMore=true]\r
+ * @member CKEDITOR.config\r
+ */\r
+\r
+/**\r
+ * Defines the colors to be displayed in the color selectors. This is a string\r
+ * containing hexadecimal notation for HTML colors, without the `'#'` prefix.\r
+ *\r
+ * **Since 3.3:** A color name may optionally be defined by prefixing the entries with\r
+ * a name and the slash character. For example, `'FontColor1/FF9900'` will be\r
+ * displayed as the color `#FF9900` in the selector, but will be output as `'FontColor1'`.\r
+ *\r
+ * **Since 4.6.2:** The default color palette has changed. It contains fewer colors in more\r
+ * pastel shades than the previous one.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             // Brazil colors only.\r
+ *             config.colorButton_colors = '00923E,F8C100,28166F';\r
+ *\r
+ *             config.colorButton_colors = 'FontColor1/FF9900,FontColor2/0066CC,FontColor3/F00';\r
+ *\r
+ *             // CKEditor color palette available before version 4.6.2.\r
+ *             config.colorButton_colors =\r
+ *                     '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +\r
+ *                     'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +\r
+ *                     'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +\r
+ *                     'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +\r
+ *                     'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';\r
+ *\r
+ * @cfg {String} [colorButton_colors=see source]\r
+ * @member CKEDITOR.config\r
+ */\r
+CKEDITOR.config.colorButton_colors = '1ABC9C,2ECC71,3498DB,9B59B6,4E5F70,F1C40F,' +\r
+       '16A085,27AE60,2980B9,8E44AD,2C3E50,F39C12,' +\r
+       'E67E22,E74C3C,ECF0F1,95A5A6,DDD,FFF,' +\r
+       'D35400,C0392B,BDC3C7,7F8C8D,999,000';\r
+\r
+/**\r
+ * Stores the style definition that applies the text foreground color.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             // This is actually the default value.\r
+ *             config.colorButton_foreStyle = {\r
+ *                     element: 'span',\r
+ *                     styles: { color: '#(color)' }\r
+ *             };\r
+ *\r
+ * @cfg [colorButton_foreStyle=see source]\r
+ * @member CKEDITOR.config\r
+ */\r
+CKEDITOR.config.colorButton_foreStyle = {\r
+       element: 'span',\r
+       styles: { 'color': '#(color)' },\r
+       overrides: [ {\r
+               element: 'font', attributes: { 'color': null }\r
+       } ]\r
+};\r
+\r
+/**\r
+ * Stores the style definition that applies the text background color.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             // This is actually the default value.\r
+ *             config.colorButton_backStyle = {\r
+ *                     element: 'span',\r
+ *                     styles: { 'background-color': '#(color)' }\r
+ *             };\r
+ *\r
+ * @cfg [colorButton_backStyle=see source]\r
+ * @member CKEDITOR.config\r
+ */\r
+CKEDITOR.config.colorButton_backStyle = {\r
+       element: 'span',\r
+       styles: { 'background-color': '#(color)' }\r
+};\r
+\r
+/**\r
+ * Whether to enable the **Automatic** button in the color selectors.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             config.colorButton_enableAutomatic = false;\r
+ *\r
+ * @cfg {Boolean} [colorButton_enableAutomatic=true]\r
+ * @member CKEDITOR.config\r
+ */\r
+\r
+/**\r
+ * Defines how many colors will be shown per row in the color selectors.\r
+ *\r
+ * Read more in the [documentation](#!/guide/dev_colorbutton)\r
+ * and see the [SDK sample](http://sdk.ckeditor.com/samples/colorbutton.html).\r
+ *\r
+ *             config.colorButton_colorsPerRow = 8;\r
+ *\r
+ * @since 4.6.2\r
+ * @cfg {Number} [colorButton_colorsPerRow=6]\r
+ * @member CKEDITOR.config\r
+ */\r
+\r
+/**\r
+ * Whether the plugin should convert `background` CSS properties with color only, to a `background-color` property,\r
+ * allowing the [Color Button](http://ckeditor.com/addon/colorbutton) plugin to edit these styles.\r
+ *\r
+ *             config.colorButton_normalizeBackground = false;\r
+ *\r
+ * @since 4.6.1\r
+ * @cfg {Boolean} [colorButton_normalizeBackground=true]\r
+ * @member CKEDITOR.config\r
+ */\r