Index: /CKEditor/branches/features/bbcode/_samples/bbcode.html
===================================================================
--- /CKEditor/branches/features/bbcode/_samples/bbcode.html (revision 6693)
+++ /CKEditor/branches/features/bbcode/_samples/bbcode.html (revision 6694)
@@ -18,5 +18,5 @@
@@ -75,12 +75,24 @@
fillEmptyBlocks : false,
fontSize_sizes : "30/30%;50/50%;100/100%;120/120%;150/150%;200/200%;300/300%",
- colorButton_colors : 'Red/FF0000,Green/00FF00,Blue/0000FF',
toolbar :
[
- ['Source', '-', 'Save','NewPage','Preview','-','Bold', 'Italic','Underline','-', 'TextColor', 'FontSize','-','Link', 'Image'],
+ ['Source', '-', 'Save','NewPage','Preview','-','Undo','Redo'],
+ ['Find','Replace','-','SelectAll','RemoveFormat'],
+ ['Link', 'Image'],
'/',
+ ['FontSize', 'Bold', 'Italic','Underline'],
['NumberedList','BulletedList','-','Blockquote'],
- ['Smiley','SpecialChar'],
- ['Find','Replace','-','SelectAll','RemoveFormat']
+ ['TextColor', '-', 'Smiley','SpecialChar', '-', 'Maximize']
+ ],
+ smiley_images :
+ [
+ 'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif',
+ 'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif',
+ 'cry_smile.gif','kiss.gif'
+ ],
+ smiley_descriptions :
+ [
+ 'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise',
+ 'indecision', 'angel', 'cool', 'crying', 'kiss'
]
});
Index: /CKEditor/branches/features/bbcode/_samples/index.html
===================================================================
--- /CKEditor/branches/features/bbcode/_samples/index.html (revision 6693)
+++ /CKEditor/branches/features/bbcode/_samples/index.html (revision 6694)
@@ -80,4 +80,7 @@
Configuring CKEditor to produce HTML code that can be used with Adobe Flash.
+
BBCodes
+ Configuring CKEditor to produce BBCode tags instead of HTML.
+
Placeholder plugin
Using the Placeholder plugin to create uneditable sections that can only be created and modified with a proper dialog window.
Index: /CKEditor/branches/features/bbcode/_source/plugins/bbcode/plugin.js
===================================================================
--- /CKEditor/branches/features/bbcode/_source/plugins/bbcode/plugin.js (revision 6693)
+++ /CKEditor/branches/features/bbcode/_source/plugins/bbcode/plugin.js (revision 6694)
@@ -6,4 +6,40 @@
(function()
{
+ CKEDITOR.on( 'dialogDefinition', function( ev )
+ {
+ var tab, name = ev.data.name,
+ definition = ev.data.definition;
+
+ if ( name == 'link' )
+ {
+ definition.removeContents( 'target' );
+ definition.removeContents( 'upload' );
+ definition.removeContents( 'advanced' );
+ tab = definition.getContents( 'info' );
+ tab.remove( 'emailSubject' );
+ tab.remove( 'emailBody' );
+ }
+ if ( name == 'image' )
+ {
+ definition.removeContents( 'advanced' );
+ tab = definition.getContents( 'Link' );
+ tab.remove( 'cmbTarget' );
+ tab = definition.getContents( 'info' );
+ tab.remove( 'ratioLock' );
+ tab.remove( 'txtAlt' );
+ tab.remove( 'txtHeight' );
+ tab.remove( 'txtWidth' );
+ tab.remove( 'txtBorder' );
+ tab.remove( 'txtHSpace' );
+ tab.remove( 'txtVSpace' );
+ tab.remove( 'cmbAlign' );
+ }
+ if ( name == 'numberedListStyle' )
+ {
+ tab = definition.getContents( 'info' );
+ tab.remove('start');
+ }
+ });
+
var bbcodeMap = { 'b' : 'strong', 'u': 'u', 'i' : 'em', 'color' : 'span', 'size' : 'span', 'quote' : 'blockquote', 'code' : 'code', 'url' : 'a', 'email' : 'span', 'img' : 'span', '*' : 'li', 'list' : 'ol' },
convertMap = { 'strong' : 'b' , 'b' : 'b', 'u': 'u', 'em' : 'i', 'i': 'i', 'code' : 'code', 'li' : '*' },
@@ -41,4 +77,35 @@
return retval;
}
+
+ function RGBToHex( cssStyle )
+ {
+ return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
+ {
+ red = parseInt( red, 10 ).toString( 16 );
+ green = parseInt( green, 10 ).toString( 16 );
+ blue = parseInt( blue, 10 ).toString( 16 );
+ var color = [red, green, blue] ;
+
+ // Add padding zeros if the hex value is less than 0x10.
+ for ( var i = 0 ; i < color.length ; i++ )
+ color[i] = String( '0' + color[i] ).slice( -2 ) ;
+
+ return '#' + color.join( '' ) ;
+ });
+ }
+
+ // Maintain the map of smiley-to-description.
+ var smileyMap = {"smiley":":)","sad":":(","wink":";)","laugh":":D","cheeky":":P","blush":":*)","surprise":":-o","indecision":":|","angry":">:(","angel":"o:)","cool":"8-)","devil":">:-)","crying":";(","kiss":":-*" },
+ smileyReverseMap = {},
+ smileyRegExp = [];
+
+ // Build regexp for the list of smiley text.
+ for ( var i in smileyMap )
+ {
+ smileyReverseMap[ smileyMap[ i ] ] = i;
+ smileyRegExp.push( smileyMap[ i ].replace( /\(|\)|\:|\/|\*|\-|\|/g, function( match ) { return '\\' + match; } ) );
+ }
+
+ smileyRegExp = new RegExp( smileyRegExp.join( '|' ), 'g' );
var decodeHtml = ( function ()
@@ -203,5 +270,5 @@
}
}
-
+
function checkPendingBrs( tagName, closing )
{
@@ -387,5 +454,18 @@
pendingBrs++;
else if ( piece.length )
- addElement( new CKEDITOR.htmlParser.text( piece ), currentNode );
+ {
+ var lastIndex = 0;
+
+ // Create smiley from text emotion.
+ piece.replace( smileyRegExp, function( match, index )
+ {
+ addElement( new CKEDITOR.htmlParser.text( piece.substr( lastIndex, index ) ), currentNode );
+ addElement( new CKEDITOR.htmlParser.element( 'smiley', { 'desc': smileyReverseMap[ match ] } ), currentNode );
+ lastIndex = index + match.length;
+ });
+
+ if ( lastIndex != piece.length )
+ addElement( new CKEDITOR.htmlParser.text( piece.substr( lastIndex, piece.length ) ), currentNode );
+ }
});
}
@@ -580,4 +660,6 @@
init : function( editor )
{
+ var config = editor.config;
+
function BBCodeToHtml( code )
{
@@ -643,4 +725,20 @@
if ( !element.attributes.href )
element.attributes.href = element.children[ 0 ].value
+ },
+ 'smiley' : function( element )
+ {
+ element.name = 'img';
+
+ var description = element.attributes.desc,
+ image = config.smiley_images[ CKEDITOR.tools.indexOf( config.smiley_descriptions, description ) ],
+ src = CKEDITOR.tools.htmlEncode( config.smiley_path + image );
+
+ element.attributes =
+ {
+ src : src,
+ 'data-cke-saved-src' : src,
+ title : description,
+ alt : description
+ };
}
}
@@ -663,5 +761,8 @@
{
if ( value = style.color )
+ {
tagName = 'color';
+ value = RGBToHex( value );
+ }
else if ( value = style[ 'font-size' ] )
{
@@ -738,5 +839,11 @@
{
element.isEmpty = 0;
- element.children = [ new CKEDITOR.htmlParser.text( attributes.src ) ];
+
+ // Translate smiley (image) to text emotion.
+ var src = attributes[ 'data-cke-saved-src' ];
+ if ( src && src.indexOf( editor.config.smiley_path ) != -1 )
+ return new CKEDITOR.htmlParser.text( smileyMap[ attributes.alt ] );
+ else
+ element.children = [ new CKEDITOR.htmlParser.text( src ) ];
}