PATH:
home
/
letacommog
/
letaweb
/
scripts
/
libraries
/
ckeditor_full
/
plugins
/
palettecolorbutton
CKEDITOR.plugins.add( 'palettecolorbutton', { requires: 'panelbutton,floatpanel,fakeobjects', // jscs:disable maximumLineLength 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% // jscs:enable maximumLineLength icons: 'palettebgcolor,palettetextcolor', // %REMOVE_LINE_CORE% hidpi: true, // %REMOVE_LINE_CORE% onLoad:function() { function setPaletteCSS() { if(window.palette == undefined && window.top.palette == undefined ) { return } var colors = (window.palette || window.top.palette).colors; var total = colors.length; for(var i = 0;i < 5;i++) { for(var j = 0;j < 5;j++) { var colorCode = colors[j][i].toHex(); var index = i * 5 + j; var colorClass = 'color-' + index; CKEDITOR.addCss('.' + colorClass+'{'+'color:'+colorCode+';}'); } } } setPaletteCSS(); }, init: function( editor ) { var config = editor.config, lang = editor.lang.palettecolorbutton; if ( !CKEDITOR.env.hc ) { addButton( 'PaletteTextColor', 'fore', lang.textColorTitle, 10 ); addButton( 'PaletteBGColor', 'back', lang.bgColorTitle, 20 ); } function addButton( name, type, title, order ) { var style = new CKEDITOR.style( config[ 'palettecolorButton_' + type + 'Style' ] ), colorBoxId = CKEDITOR.tools.getNextId() + '_colorBox'; editor.ui.add( name, CKEDITOR.UI_PANELBUTTON, { label: title, title: title, modes: { wysiwyg: 1 }, editorFocus: 0, toolbar: 'colors,' + order, allowedContent: style, requiredContent: style, icon:'palette' + (type == 'back' ? 'bg' : 'text') + 'color', panel: { css: CKEDITOR.skin.getPath( 'editor' ), attributes: { role: 'listbox', 'aria-label': lang.panelTitle } }, onBlock: function( panel, block ) { block.autoSize = true; block.element.addClass( 'cke_colorblock' ); block.element.setHtml( renderPalette( panel, type, colorBoxId ) ); // The block should not have scrollbars (#5933, #6056) block.element.getDocument().getBody().setStyle( 'overflow', 'hidden' ); CKEDITOR.ui.fire( 'ready', this ); var keys = block.keys; var rtl = editor.lang.dir == 'rtl'; keys[ rtl ? 37 : 39 ] = 'next'; // ARROW-RIGHT keys[ 40 ] = 'next'; // ARROW-DOWN keys[ 9 ] = 'next'; // TAB keys[ rtl ? 39 : 37 ] = 'prev'; // ARROW-LEFT keys[ 38 ] = 'prev'; // ARROW-UP keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB keys[ 32 ] = 'click'; // SPACE }, refresh: function() { if ( !editor.activeFilter.check( style ) ) this.setState( CKEDITOR.TRISTATE_DISABLED ); }, // The automatic colorbox should represent the real color (#6010) onOpen: function() { var selection = editor.getSelection(), block = selection && selection.getStartElement(), path = editor.elementPath( block ), color; if ( !path ) return; // Find the closest block element. block = path.block || path.blockLimit || editor.document.getBody(); // The background color might be transparent. In that case, look up the color in the DOM tree. do { color = block && block.getComputedStyle( type == 'back' ? 'background-color' : 'color' ) || 'transparent'; } while ( type == 'back' && color == 'transparent' && block && ( block = block.getParent() ) ); // The box should never be transparent. if ( !color || color == 'transparent' ) color = '#ffffff'; // this._.panel._.iframe.getFrameDocument().getById( colorBoxId ).setStyle( 'background-color', color ); return color; } } ); } function renderPalette(panel, type, colorBoxId) { var clickFn = CKEDITOR.tools.addFunction( function( colorClass, type ) { var applyColorStyle = arguments.callee; editor.focus(); panel.hide(); editor.fire( 'saveSnapshot' ); // Clean up any conflicting style within the range. editor.removeStyle( new CKEDITOR.style( config[ 'palettecolorButton_' + type + 'Style' ], { color: 'inherit' } ) ); if(colorClass == null) { CKEDITOR.plugins.palettecolorbutton.commands.removeFormat.exec(editor); } else { var colorStyle = config[ 'palettecolorButton_' + type + 'Style' ]; colorStyle.childRule = type == 'back' ? function( element ) { // It's better to apply background color as the innermost style. (#3599) // Except for "unstylable elements". (#6103) return isUnstylable( element ); } : function( element ) { // Fore color style must be applied inside links instead of around it. (#4772,#6908) return !( element.is( 'a' ) || element.getElementsByTag( 'a' ).count() ) || isUnstylable( element ); }; CKEDITOR.plugins.palettecolorbutton.commands.removeFormat.exec(editor); editor.applyStyle( new CKEDITOR.style( colorStyle, { color: colorClass } ) ); } editor.fire( 'saveSnapshot' ); } ); console.log(window.palette || window.top.palette); if(window.palette == undefined && window.top.palette == undefined ) { return } var colors = (window.palette || window.top.palette).colors; var output = []; output.push( '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' + ' title="', lang.auto, '"' + ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' + ' href="javascript:void(\'', lang.auto, '\')"' + ' role="option" aria-posinset="1" aria-setsize="', total, '">' + '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' + '<tr>' + '<td>' + '<span class="cke_colorbox" id="', colorBoxId, '"></span>' + '</td>' + '<td colspan=7 align=center>', lang.auto, '</td>' + '</tr>' + '</table>' + '</a>'); output.push( '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' ); var total = colors.length; for(var i = 0;i < 5;i++) { output.push( '<tr>' ); for(var j = 0;j < 5;j++) { var colorCode = colors[j][i].toHex(); var index = i * 5 + j; var colorClass = 'color-' + index; var colorLabel = 0; output.push( '<td>' + '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' + ' title="', colorLabel, '"' + ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'', colorClass, '\',\'', type, '\'); return false;"' + ' href="javascript:void(\'', colorLabel, '\')"' + ' role="option" aria-posinset="', ( i + 2 ), '" aria-setsize="', total, '">' + '<span class="cke_colorbox" style="background-color:', colorCode, '"></span>' + '</a>' + '</td>' ); } output.push( '</tr>' ); } output.push( '</table>' ); return output.join( '' ); } function isUnstylable( ele ) { return ( ele.getAttribute( 'contentEditable' ) == 'false' ) || ele.getAttribute( 'data-nostyle' ); } } } ); CKEDITOR.config.palettecolorButton_foreStyle = { element: 'span', attributes: { 'class': '#(color)' }, }; CKEDITOR.config.palettecolorButton_backStyle = { element: 'span', attributes: { 'class': '#(color)' }, }; CKEDITOR.plugins.palettecolorbutton = { commands: { removeFormat: { exec: function( editor ) { var tagsRegex = editor._.removeFormatRegex || ( editor._.removeFormatRegex = new RegExp( '^(?:' + editor.config.removeFormatTags.replace( /,/g, '|' ) + ')$', 'i' ) ); var removeAttributes = editor._.removeAttributes || ( editor._.removeAttributes = editor.config.removeFormatAttributes.split( ',' ) ), filter = CKEDITOR.plugins.palettecolorbutton.filter, ranges = editor.getSelection().getRanges(), iterator = ranges.createIterator(), isElement = function( element ) { return element.type == CKEDITOR.NODE_ELEMENT; }, range; while ( ( range = iterator.getNextRange() ) ) { if ( !range.collapsed ) range.enlarge( CKEDITOR.ENLARGE_ELEMENT ); var bookmark = range.createBookmark(), startNode = bookmark.startNode, endNode = bookmark.endNode, currentNode; var breakParent = function( node ) { // Let's start checking the start boundary. var path = editor.elementPath( node ), pathElements = path.elements; for ( var i = 1, pathElement; pathElement = pathElements[ i ]; i++ ) { if ( pathElement.equals( path.block ) || pathElement.equals( path.blockLimit ) ) break; // If this element can be removed (even partially). if ( tagsRegex.test( pathElement.getName() ) && filter( editor, pathElement ) ) node.breakParent( pathElement ); } }; breakParent( startNode ); if ( endNode ) { breakParent( endNode ); currentNode = startNode.getNextSourceNode( true, CKEDITOR.NODE_ELEMENT ); while ( currentNode ) { // If we have reached the end of the selection, stop looping. if ( currentNode.equals( endNode ) ) break; if ( currentNode.isReadOnly() ) { // In case of non-editable we're skipping to the next sibling *elmenet*. // We need to be aware that endNode can be nested within current non-editable. // This condition tests if currentNode (non-editable) contains endNode. If it does // then we should break the filtering if ( currentNode.getPosition( endNode ) & CKEDITOR.POSITION_CONTAINS ) { break; } currentNode = currentNode.getNext( isElement ); continue; } // Cache the next node to be processed. Do it now, because // currentNode may be removed. var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT ), isFakeElement = currentNode.getName() == 'img' && currentNode.data( 'cke-realelement' ); // This node must not be a fake element, and must not be read-only. if ( !isFakeElement && filter( editor, currentNode ) ) { // Remove elements nodes that match with this style rules. if ( tagsRegex.test( currentNode.getName() ) ) currentNode.remove( 1 ); else { for(var i = 0;i < 5;i++) { output.push( '<tr>' ); for(var j = 0;j < 5;j++) { var index = i * 5 + j; var c= 'color-' + index; if(element.hasClass(c)) currentNode.removeClass( c ); } } } } currentNode = nextNode; } } range.moveToBookmark( bookmark ); } // The selection path may not changed, but we should force a selection // change event to refresh command states, due to the above attribution change. (#9238) editor.forceNextSelectionCheck(); editor.getSelection().selectRanges( ranges ); } } }, // Perform the remove format filters on the passed element. // @param {CKEDITOR.editor} editor // @param {CKEDITOR.dom.element} element filter: function( editor, element ) { var filters = editor._.removeFormatFilters || []; for(var i = 0;i < 5;i++) { for(var j = 0;j < 5;j++) { var index = i * 5 + j; var c= 'color-' + index; if(element.hasClass(c)) return true; } } return false; } };
[+]
..
[+]
lang
[-] plugin.js
[edit]
[+]
icons