X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fskins%2Fkama%2Fskin.js;h=55a97dcda7f516b9a4e17a03a0d7ccde14649a5f;hb=941b0a9ba4e673e292510d80a5a86806994b8ea6;hp=b06443a58807e6fec8313117217891afe61118cc;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/skins/kama/skin.js b/_source/skins/kama/skin.js index b06443a..55a97dc 100644 --- a/_source/skins/kama/skin.js +++ b/_source/skins/kama/skin.js @@ -1,11 +1,12 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.skins.add( 'kama', (function() { - var preload = []; + var preload = [], + uiColorStylesheetId = 'cke_ui_color'; if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 ) { @@ -25,15 +26,9 @@ CKEDITOR.skins.add( 'kama', (function() if ( editor.config.width && !isNaN( editor.config.width ) ) editor.config.width -= 12; - var menuHead; - function menuSetUiColor( color ) - { - if ( !menuHead ) - return null; - - var uiStyle = menuHead.append('style'); - - var cssSrc = "/* UI Color Support */\ + var uiColorMenus = []; + var uiColorRegex = /\$color/g; + var uiColorMenuCss = "/* UI Color Support */\ .cke_skin_kama .cke_menuitem .cke_icon_wrapper\ {\ background-color: $color !important;\ @@ -87,40 +82,58 @@ CKEDITOR.skins.add( 'kama', (function() {\ background-color: $color !important;\ }"; + // We have to split CSS declarations for webkit. + if ( CKEDITOR.env.webkit ) + { + uiColorMenuCss = uiColorMenuCss.split( '}' ).slice( 0, -1 ); + for ( var i = 0 ; i < uiColorMenuCss.length ; i++ ) + uiColorMenuCss[ i ] = uiColorMenuCss[ i ].split( '{' ); + } - uiStyle.setAttribute( "type", "text/css" ); - var regex = /\$color/g; - - // We have to split CSS declarations for webkit. - if ( CKEDITOR.env.webkit ) + function getStylesheet( document ) + { + var node = document.getById( uiColorStylesheetId ); + if( !node ) { - cssSrc = cssSrc.split( '}' ).slice( 0, -1 ); - for ( var i in cssSrc ) - cssSrc[ i ] = cssSrc[ i ].split( '{' ); + node = document.getHead().append( 'style' ); + node.setAttribute( "id", uiColorStylesheetId ); + node.setAttribute( "type", "text/css" ); } + return node; + } - return ( menuSetUiColor = - function( color ) + function updateStylesheets( styleNodes, styleContent, replace ) + { + var r, i, content; + for ( var id = 0 ; id < styleNodes.length ; id++ ) + { + if ( CKEDITOR.env.webkit ) { - if ( CKEDITOR.env.webkit ) - { - for ( var i in cssSrc ) - uiStyle.$.sheet.addRule( - cssSrc[ i ][ 0 ], cssSrc[ i ][ 1 ].replace( regex, color ) - ); - } - else + for ( i = 0 ; i < styleContent.length ; i++ ) { - var css = cssSrc.replace( regex, color ); + content = styleContent[ i ][ 1 ]; + for ( r = 0 ; r < replace.length ; r++ ) + content = content.replace( replace[ r ][ 0 ], replace[ r ][ 1 ] ); - if ( CKEDITOR.env.ie ) - uiStyle.$.styleSheet.cssText = css; - else - uiStyle.setHtml( css ); + styleNodes[ id ].$.sheet.addRule( styleContent[ i ][ 0 ], content ); } - })( color ); + } + else + { + content = styleContent; + for ( r = 0 ; r < replace.length ; r++ ) + content = content.replace( replace[ r ][ 0 ], replace[ r ][ 1 ] ); + + if ( CKEDITOR.env.ie ) + styleNodes[ id ].$.styleSheet.cssText += content; + else + styleNodes[ id ].$.innerHTML += content; + } + } } + var uiColorRegexp = /\$color/g; + CKEDITOR.tools.extend( editor, { uiColor: null, @@ -132,8 +145,9 @@ CKEDITOR.skins.add( 'kama', (function() setUiColor : function( color ) { - var uiStyle = CKEDITOR.document.getHead().append('style'), - cssId = '#cke_' + editor.name.replace('.', '\\.'); + var cssContent, + uiStyle = getStylesheet( CKEDITOR.document ), + cssId = '.cke_editor_' + CKEDITOR.tools.escapeCssSelector( editor.name ); var cssSelectors = [ @@ -144,137 +158,100 @@ CKEDITOR.skins.add( 'kama', (function() ].join( ',' ); var cssProperties = "background-color: $color !important;"; - uiStyle.setAttribute("type", "text/css"); + if ( CKEDITOR.env.webkit ) + cssContent = [ [ cssSelectors, cssProperties ] ]; + else + cssContent = cssSelectors + '{' + cssProperties + '}'; return ( this.setUiColor = function( color ) { - var css = cssProperties.replace( '$color', color ); + var replace = [ [ uiColorRegexp, color ] ]; editor.uiColor = color; - if ( CKEDITOR.env.ie ) - uiStyle.$.styleSheet.cssText = cssSelectors + '{' + css + '}'; - else if ( CKEDITOR.env.webkit ) - uiStyle.$.sheet.addRule( cssSelectors, css ); - else - uiStyle.setHtml( cssSelectors + '{' + css + '}' ); + // Update general style. + updateStylesheets( [ uiStyle ], cssContent, replace ); - menuSetUiColor( color ); + // Update menu styles. + updateStylesheets( uiColorMenus, uiColorMenuCss, replace ); })( color ); } }); - // If the "menu" plugin is loaded, register the listeners. - if ( CKEDITOR.menu ) + editor.on( 'menuShow', function( event ) { - var old = CKEDITOR.menu.prototype.show; + var panel = event.data[ 0 ]; + var iframe = panel.element.getElementsByTag( 'iframe' ).getItem( 0 ).getFrameDocument(); - CKEDITOR.menu.prototype.show = function() + // Add stylesheet if missing. + if ( !iframe.getById( 'cke_ui_color' ) ) { - old.apply( this, arguments ); + var node = getStylesheet( iframe ); + uiColorMenus.push( node ); - if ( !menuHead && editor == this.editor ) - { - // Save reference. - menuHead = this._.element.getDocument().getHead(); - menuSetUiColor( editor.getUiColor() ); - } - }; - } + var color = editor.getUiColor(); + // Set uiColor for new menu. + if ( color ) + updateStylesheets( [ node ], uiColorMenuCss, [ [ uiColorRegexp, color ] ] ); + } + }); // Apply UI color if specified in config. if ( editor.config.uiColor ) editor.setUiColor( editor.config.uiColor ); - - // Fix editor's width. HPadding and 100% width iframe issue. -// if ( CKEDITOR.env.ie && CKEDITOR.env.quirks ) -// { -// editor.on( 'mode', function( event ) -// { -// var container = editor.getResizable(); -// editor.resize( container.$.offsetWidth-10, container.$.offsetHeight ); -// event.removeListener(); -// }); -// } - -// if ( CKEDITOR.env.ie && ( CKEDITOR.env.quirks || CKEDITOR.env.version < 7 ) ) -// { -// editor.on( 'themeLoaded', function( event ) -// { -// var toolbars = editor.container.getChild( [0, 0, 0, 0, 0, 0, 0] ).getChildren(); -// for ( var i = 0 ; i < toolbars.count() ; i++ ) -// { -// var toolbar = toolbars.getItem( i ); - -// var last = toolbar.getLast(); -// if ( !last || !last.getPrevious().hasClass( 'cke_rcombo' ) ) -// continue; -// -// last.addClass( 'cke_toolbar_end_last' ); -// } -// }); -// } } }; })() ); -if ( CKEDITOR.dialog ) +(function() { - CKEDITOR.dialog.on( 'resize', function( evt ) - { - var data = evt.data, - width = data.width, - height = data.height, - dialog = data.dialog, - contents = dialog.parts.contents, - standardsMode = !CKEDITOR.env.quirks; + CKEDITOR.dialog ? dialogSetup() : CKEDITOR.on( 'dialogPluginReady', dialogSetup ); - if ( data.skin != 'kama' ) - return; + function dialogSetup() + { + CKEDITOR.dialog.on( 'resize', function( evt ) + { + var data = evt.data, + width = data.width, + height = data.height, + dialog = data.dialog, + contents = dialog.parts.contents; - contents.setStyles( - ( CKEDITOR.env.ie || ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) ) ? // IE && FF2 + if ( data.skin != 'kama' ) + return; + + contents.setStyles( { width : width + 'px', height : height + 'px' - } - : - { - // To avoid having scrollbars in the dialogs, we're - // (for now) using the "min-xxx" properties, for - // browsers which well support it (#3878). - 'min-width' : width + 'px', - 'min-height' : height + 'px' }); - if ( !CKEDITOR.env.ie ) - return; - - // Fix the size of the elements which have flexible lengths. - setTimeout( function() - { - var body = contents.getParent(), - innerDialog = body.getParent(); - - // tc - var el = innerDialog.getChild( 2 ); - el.setStyle( 'width', ( body.$.offsetWidth ) + 'px' ); - - // bc - el = innerDialog.getChild( 7 ); - el.setStyle( 'width', ( body.$.offsetWidth - 28 ) + 'px' ); - - // ml - el = innerDialog.getChild( 4 ); - el.setStyle( 'height', ( body.$.offsetHeight - 31 - 14 ) + 'px' ); - - // mr - el = innerDialog.getChild( 5 ); - el.setStyle( 'height', ( body.$.offsetHeight - 31 - 14 ) + 'px' ); - }, - 100 ); - }); -} + // Fix the size of the elements which have flexible lengths. + setTimeout( function() + { + var innerDialog = dialog.parts.dialog.getChild( [ 0, 0, 0 ] ), + body = innerDialog.getChild( 0 ); + + // tc + var el = innerDialog.getChild( 2 ); + el.setStyle( 'width', ( body.$.offsetWidth ) + 'px' ); + + // bc + el = innerDialog.getChild( 7 ); + el.setStyle( 'width', ( body.$.offsetWidth - 28 ) + 'px' ); + + // ml + el = innerDialog.getChild( 4 ); + el.setStyle( 'height', ( body.$.offsetHeight - 31 - 14 ) + 'px' ); + + // mr + el = innerDialog.getChild( 5 ); + el.setStyle( 'height', ( body.$.offsetHeight - 31 - 14 ) + 'px' ); + }, + 100 ); + }); + } +})(); /** * The base user interface color to be used by the editor. Not all skins are