Skip to content

Commit

Permalink
Merge branch 't/9990' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 15, 2013
2 parents 85dfc91 + 05c1c01 commit c7cf983
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 34 deletions.
9 changes: 9 additions & 0 deletions plugins/dialog/dialogDefinition.js
Expand Up @@ -195,6 +195,15 @@
* @property {String} title
*/

/**
* The content that needs to be allowed to enable this UI element.
* All formats accepted by {@link CKEDITOR.filter#check} may be used.
*
* When all UI elements in a tab are disabled, this tab will be disabled automatically.
*
* @property {String/Object/CKEDITOR.style} requiredContent
*/

/**
* CSS class names to append to the UI element.
*
Expand Down
51 changes: 41 additions & 10 deletions plugins/dialog/plugin.js
Expand Up @@ -1024,6 +1024,9 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
* @param {Object} contents Content definition.
*/
addPage: function( contents ) {
if ( contents.requiredContent && !this._.editor.filter.check( contents.requiredContent ) )
return;

var pageHtml = [],
titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
elements = contents.elements,
Expand All @@ -1036,6 +1039,25 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
style: contents.style || 'width: 100%;'
}, pageHtml );

var contentMap = this._.contents[ contents.id ] = {},
cursor,
children = vbox.getChild(),
enabledFields = 0;

while ( ( cursor = children.shift() ) ) {
// Count all allowed fields.
if ( !cursor.notAllowed && cursor.type != 'hbox' && cursor.type != 'vbox' )
enabledFields++;

contentMap[ cursor.id ] = cursor;
if ( typeof( cursor.getChild ) == 'function' )
children.push.apply( children, cursor.getChild() );
}

// If all fields are disabled (because they are not allowed) hide this tab.
if ( !enabledFields )
contents.hidden = true;

// Create the HTML for the tab and the content block.
var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
page.setAttribute( 'role', 'tabpanel' );
Expand Down Expand Up @@ -1065,16 +1087,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
this._.lastTab = tab;
this.updateStyle();

var contentMap = this._.contents[ contents.id ] = {},
cursor,
children = vbox.getChild();

while ( ( cursor = children.shift() ) ) {
contentMap[ cursor.id ] = cursor;
if ( typeof( cursor.getChild ) == 'function' )
children.push.apply( children, cursor.getChild() );
}

// Attach the DOM nodes.

page.setAttribute( 'name', contents.id );
Expand Down Expand Up @@ -1422,6 +1434,20 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
return CKEDITOR.dialog._.currentTop;
},

/**
* Check whether tab wasn't removed by {@link CKEDITOR.config#removeDialogTabs}.
*
* @param {CKEDITOR.editor} editor
* @param {String} dialogName
* @param {String} tabName
* @returns {Boolean}
*/
isTabEnabled: function( editor, dialogName, tabName ) {
var cfg = editor.config.removeDialogTabs;

return !( cfg && cfg.match( new RegExp( '(?:^|;)' + dialogName + ':' + tabName + '(?:$|;)', 'i' ) ) );
},

/**
* The default OK button for dialogs. Fires the `ok` event and closes the dialog if the event succeeds.
*
Expand Down Expand Up @@ -2191,6 +2217,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
id = this.id = elementDefinition.id,
i;

if ( elementDefinition.requiredContent && !dialog.getParentEditor().filter.check( elementDefinition.requiredContent ) ) {
styles.display = 'none';
this.notAllowed = true;
}

// Set the id, a unique id is required for getElement() to work.
attributes.id = domId;

Expand Down
6 changes: 5 additions & 1 deletion plugins/dialogadvtab/plugin.js
Expand Up @@ -68,7 +68,7 @@

// @param tabConfig
// id, dir, classes, styles
createAdvancedTab: function( editor, tabConfig ) {
createAdvancedTab: function( editor, tabConfig, element ) {
if ( !tabConfig )
tabConfig = defaultTabConfig;

Expand All @@ -95,6 +95,7 @@
id: 'advId',
att: 'id',
type: 'text',
requiredContent: element ? element + '[id]' : null,
label: lang.id,
setup: setupAdvParams,
commit: commitAdvParams
Expand All @@ -106,6 +107,7 @@
id: 'advLangDir',
att: 'dir',
type: 'select',
requiredContent: element ? element + '[dir]' : null,
label: lang.langDir,
'default': '',
style: 'width:100%',
Expand Down Expand Up @@ -134,6 +136,7 @@
id: 'advStyles',
att: 'style',
type: 'text',
requiredContent: element ? element + '{cke-xyz}' : null,
label: lang.styles,
'default': '',

Expand Down Expand Up @@ -172,6 +175,7 @@
id: 'advCSSClasses',
att: 'class',
type: 'text',
requiredContent: element ? element + '(cke-xyz)' : null,
label: lang.cssClasses,
'default': '',
setup: setupAdvParams,
Expand Down
18 changes: 13 additions & 5 deletions plugins/div/dialogs/div.js
Expand Up @@ -275,6 +275,7 @@
{
id: 'class',
type: 'text',
requiredContent: 'div(cke-xyz)', // Random text like 'xyz' will check if all are allowed.
label: editor.lang.common.cssClass,
'default': ''
}
Expand All @@ -298,12 +299,14 @@
{
type: 'text',
id: 'id',
requiredContent: 'div[id]',
label: editor.lang.common.id,
'default': ''
},
{
type: 'text',
id: 'lang',
requiredContent: 'div[lang]',
label: editor.lang.common.langCode,
'default': ''
}
Expand All @@ -315,6 +318,7 @@
{
type: 'text',
id: 'style',
requiredContent: 'div{cke-xyz}', // Random text like 'xyz' will check if all are allowed.
style: 'width: 100%;',
label: editor.lang.common.cssStyle,
'default': '',
Expand All @@ -330,6 +334,7 @@
{
type: 'text',
id: 'title',
requiredContent: 'div[title]',
style: 'width: 100%;',
label: editor.lang.common.advisoryTitle,
'default': ''
Expand All @@ -339,6 +344,7 @@
{
type: 'select',
id: 'dir',
requiredContent: 'div[dir]',
style: 'width: 100%;',
label: editor.lang.common.langDir,
'default': '',
Expand Down Expand Up @@ -368,19 +374,21 @@

// Reuse the 'stylescombo' plugin's styles definition.
editor.getStylesSet( function( stylesDefinitions ) {
var styleName;
var styleName, style;

if ( stylesDefinitions ) {
// Digg only those styles that apply to 'div'.
for ( var i = 0; i < stylesDefinitions.length; i++ ) {
var styleDefinition = stylesDefinitions[ i ];
if ( styleDefinition.element && styleDefinition.element == 'div' ) {
styleName = styleDefinition.name;
styles[ styleName ] = new CKEDITOR.style( styleDefinition );
styles[ styleName ] = style = new CKEDITOR.style( styleDefinition );

// Populate the styles field options with style name.
stylesField.items.push( [ styleName, styleName ] );
stylesField.add( styleName, styleName );
if ( editor.filter.check( style ) ) {
// Populate the styles field options with style name.
stylesField.items.push( [ styleName, styleName ] );
stylesField.add( styleName, styleName );
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/div/plugin.js
Expand Up @@ -17,10 +17,14 @@
if ( editor.blockless )
return;

var lang = editor.lang.div;
var lang = editor.lang.div,
allowed = 'div(*)';

if ( CKEDITOR.dialog.isTabEnabled( editor, 'editdiv', 'advanced' ) )
allowed += ';div[dir,id,lang,title]{*}';

editor.addCommand( 'creatediv', new CKEDITOR.dialogCommand( 'creatediv', {
allowedContent: 'div(*)[dir,id,lang,title]{*}',
allowedContent: allowed,
requiredContent: 'div',
contextSensitive: true,
refresh: function( editor, path ) {
Expand Down
13 changes: 13 additions & 0 deletions plugins/flash/dialogs/flash.js
Expand Up @@ -373,6 +373,7 @@
{
type: 'text',
id: 'width',
requiredContent: 'embed[width]',
style: 'width:95px',
label: editor.lang.common.width,
validate: CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.width ) ),
Expand All @@ -382,6 +383,7 @@
{
type: 'text',
id: 'height',
requiredContent: 'embed[height]',
style: 'width:95px',
label: editor.lang.common.height,
validate: CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.height ) ),
Expand All @@ -391,6 +393,7 @@
{
type: 'text',
id: 'hSpace',
requiredContent: 'embed[hspace]',
style: 'width:95px',
label: editor.lang.flash.hSpace,
validate: CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ),
Expand All @@ -400,6 +403,7 @@
{
type: 'text',
id: 'vSpace',
requiredContent: 'embed[vspace]',
style: 'width:95px',
label: editor.lang.flash.vSpace,
validate: CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ),
Expand Down Expand Up @@ -454,6 +458,7 @@
{
id: 'scale',
type: 'select',
requiredContent: 'embed[scale]',
label: editor.lang.flash.scale,
'default': '',
style: 'width : 100%;',
Expand All @@ -469,6 +474,7 @@
{
id: 'allowScriptAccess',
type: 'select',
requiredContent: 'embed[allowscriptaccess]',
label: editor.lang.flash.access,
'default': '',
style: 'width : 100%;',
Expand All @@ -490,6 +496,7 @@
{
id: 'wmode',
type: 'select',
requiredContent: 'embed[wmode]',
label: editor.lang.flash.windowMode,
'default': '',
style: 'width : 100%;',
Expand All @@ -505,6 +512,7 @@
{
id: 'quality',
type: 'select',
requiredContent: 'embed[quality]',
label: editor.lang.flash.quality,
'default': 'high',
style: 'width : 100%;',
Expand All @@ -529,6 +537,7 @@
{
id: 'align',
type: 'select',
requiredContent: 'object[align]',
label: editor.lang.common.align,
'default': '',
style: 'width : 100%;',
Expand Down Expand Up @@ -613,6 +622,7 @@
{
type: 'text',
id: 'id',
requiredContent: 'object[id]',
label: editor.lang.common.id,
setup: loadValue,
commit: commitValue
Expand All @@ -626,13 +636,15 @@
{
type: 'text',
id: 'bgcolor',
requiredContent: 'embed[bgcolor]',
label: editor.lang.flash.bgcolor,
setup: loadValue,
commit: commitValue
},
{
type: 'text',
id: 'class',
requiredContent: 'embed(cke-xyz)', // Random text like 'xyz' will check if all are allowed.
label: editor.lang.common.cssClass,
setup: loadValue,
commit: commitValue
Expand All @@ -642,6 +654,7 @@
{
type: 'text',
id: 'style',
requiredContent: 'embed{cke-xyz}', // Random text like 'xyz' will check if all are allowed.
validate: CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
label: editor.lang.common.cssStyle,
setup: loadValue,
Expand Down
13 changes: 10 additions & 3 deletions plugins/flash/plugin.js
Expand Up @@ -34,10 +34,17 @@

},
init: function( editor ) {
var allowed = 'object[classid,codebase,height,hspace,vspace,width];' +
'param[name,value];' +
'embed[height,hspace,pluginspage,src,type,vspace,width]';

if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'properties' ) )
allowed += ';object[align]; embed[allowscriptaccess,quality,scale,wmode]';
if ( CKEDITOR.dialog.isTabEnabled( editor, 'flash', 'advanced' ) )
allowed += ';object[id]{*}; embed[bgcolor]{*}(*)';

editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash', {
allowedContent: 'object[align,classid,codebase,height,hspace,vspace,width]{*}(*);' +
'param[name,value];' +
'embed[allowscriptaccess,bgcolor,height,hspace,pluginspage,quality,scale,src,type,vspace,width,wmode]{*}(*)',
allowedContent: allowed,
requiredContent: 'embed'
} ) );
editor.ui.addButton && editor.ui.addButton( 'Flash', {
Expand Down

0 comments on commit c7cf983

Please sign in to comment.