| 1 | /* |
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. |
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 4 | */ |
| 5 | |
| 6 | CKEDITOR.dialog.add( 'uicolor', function( editor ) |
| 7 | { |
| 8 | var dialog, picker, pickerContents, |
| 9 | // Actual UI color value. |
| 10 | uiColor = editor.getUiColor(); |
| 11 | |
| 12 | function setNewPickerColor( color ) |
| 13 | { |
| 14 | // Convert HEX representation to RGB, stripping # char. |
| 15 | if ( /^#/.test( color ) ) |
| 16 | color = YAHOO.util.Color.hex2rgb( color.substr( 1 ) ); |
| 17 | picker.setValue( color, true ); |
| 18 | // Refresh picker UI. |
| 19 | picker.refresh( 'cke_uicolor_picker' ); |
| 20 | }; |
| 21 | |
| 22 | function setNewUiColor( color, force ) |
| 23 | { |
| 24 | if ( force || dialog._.contents.tab1.livePeview.getValue() ) |
| 25 | editor.setUiColor( color ); |
| 26 | // Write new config string into textbox. |
| 27 | dialog._.contents.tab1.configBox.setValue( |
| 28 | 'config.uiColor = "#' + picker.get( "hex" ) + '"' |
| 29 | ); |
| 30 | }; |
| 31 | |
| 32 | pickerContents = |
| 33 | { |
| 34 | id : 'yuiColorPicker', |
| 35 | type : 'html', |
| 36 | html : "<div id='cke_uicolor_picker' style='width: 360px; height: 200px; position: relative;'></div>", |
| 37 | onLoad : function( event ) |
| 38 | { |
| 39 | var url = CKEDITOR.getUrl( |
| 40 | '_source/' + // %REMOVE_LINE% |
| 41 | 'plugins/uicolor/yui/' |
| 42 | ); |
| 43 | |
| 44 | // Create new color picker widget. |
| 45 | picker = new YAHOO.widget.ColorPicker( "cke_uicolor_picker", |
| 46 | { |
| 47 | showhsvcontrols : true, |
| 48 | showhexcontrols : true, |
| 49 | images : |
| 50 | { |
| 51 | PICKER_THUMB : url + "assets/picker_thumb.png", |
| 52 | HUE_THUMB : url + "assets/hue_thumb.png" |
| 53 | } |
| 54 | }); |
| 55 | |
| 56 | // Set actual UI color to the picker. |
| 57 | if ( uiColor ) |
| 58 | setNewPickerColor( uiColor ); |
| 59 | |
| 60 | // Subscribe to the rgbChange event. |
| 61 | picker.on( "rgbChange", function() |
| 62 | { |
| 63 | // Reset predefined box. |
| 64 | dialog._.contents.tab1.predefined.setValue( '' ); |
| 65 | setNewUiColor( '#' + picker.get( 'hex' ) ); |
| 66 | }); |
| 67 | |
| 68 | // Fix input class names. |
| 69 | var inputs = new CKEDITOR.dom.nodeList( picker.getElementsByTagName( 'input' ) ); |
| 70 | for ( var i = 0; i < inputs.count() ; i++ ) |
| 71 | inputs.getItem( i ).addClass( 'cke_dialog_ui_input_text' ); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | return { |
| 76 | title : editor.lang.uicolor.title, |
| 77 | minWidth : 360, |
| 78 | minHeight : 320, |
| 79 | onLoad : function() |
| 80 | { |
| 81 | dialog = this; |
| 82 | this.setupContent(); |
| 83 | }, |
| 84 | contents : [ |
| 85 | { |
| 86 | id : 'tab1', |
| 87 | label : '', |
| 88 | title : '', |
| 89 | expand : true, |
| 90 | padding : 0, |
| 91 | elements : [ |
| 92 | pickerContents, |
| 93 | { |
| 94 | id : 'tab1', |
| 95 | type : 'vbox', |
| 96 | children : |
| 97 | [ |
| 98 | { |
| 99 | id : 'livePeview', |
| 100 | type : 'checkbox', |
| 101 | label : editor.lang.uicolor.preview, |
| 102 | 'default' : 1, |
| 103 | onChange : function() |
| 104 | { |
| 105 | if ( !picker ) |
| 106 | return; |
| 107 | var on = this.getValue(), |
| 108 | color = on ? '#' + picker.get( 'hex' ) : uiColor; |
| 109 | setNewUiColor( color, true ); |
| 110 | } |
| 111 | }, |
| 112 | { |
| 113 | type : 'hbox', |
| 114 | children : |
| 115 | [ |
| 116 | { |
| 117 | id : 'predefined', |
| 118 | type : 'select', |
| 119 | 'default' : '', |
| 120 | label : editor.lang.uicolor.predefined, |
| 121 | items : |
| 122 | [ |
| 123 | [ '' ], |
| 124 | [ 'Light blue', '#9AB8F3' ], |
| 125 | [ 'Sand', '#D2B48C' ], |
| 126 | [ 'Metallic', '#949AAA', ], |
| 127 | [ 'Purple', '#C2A3C7' ], |
| 128 | [ 'Olive', '#A2C980' ], |
| 129 | [ 'Happy green', '#9BD446' ], |
| 130 | [ 'Jezebel Blue', '#14B8C4' ], |
| 131 | [ 'Burn', '#FF893A' ], |
| 132 | [ 'Easy red', '#FF6969' ], |
| 133 | [ 'Pisces 3', '#48B4F2' ], |
| 134 | [ 'Aquarius 5', '#487ED4' ], |
| 135 | [ 'Absinthe', '#A8CF76' ], |
| 136 | [ 'Scrambled Egg', '#C7A622' ], |
| 137 | [ 'Hello monday', '#8E8D80' ], |
| 138 | [ 'Lovely sunshine', '#F1E8B1' ], |
| 139 | [ 'Recycled air', '#B3C593' ], |
| 140 | [ 'Down', '#BCBCA4' ], |
| 141 | [ 'Mark Twain', '#CFE91D' ], |
| 142 | [ 'Specks of dust', '#D1B596' ], |
| 143 | [ 'Lollipop', '#F6CE23' ], |
| 144 | ], |
| 145 | onChange : function() |
| 146 | { |
| 147 | var color = this.getValue(); |
| 148 | if ( color ) |
| 149 | { |
| 150 | setNewPickerColor( color ); |
| 151 | setNewUiColor( color ); |
| 152 | // Refresh predefined preview box. |
| 153 | CKEDITOR.document.getById( 'predefinedPreview' ).setStyle( 'background', color ); |
| 154 | } |
| 155 | else |
| 156 | CKEDITOR.document.getById( 'predefinedPreview' ).setStyle( 'background', '' ); |
| 157 | }, |
| 158 | onShow : function() |
| 159 | { |
| 160 | var color = editor.getUiColor(); |
| 161 | if ( color ) |
| 162 | this.setValue( color ); |
| 163 | } |
| 164 | }, |
| 165 | { |
| 166 | id : 'predefinedPreview', |
| 167 | type : 'html', |
| 168 | html : '<div id="cke_uicolor_preview" style="border: 1px solid black; padding: 3px; width: 30px;">' + |
| 169 | '<div id="predefinedPreview" style="width: 30px; height: 30px;"> </div>' + |
| 170 | '</div>' |
| 171 | } |
| 172 | ] |
| 173 | }, |
| 174 | { |
| 175 | id : 'configBox', |
| 176 | type : 'text', |
| 177 | label : editor.lang.uicolor.config, |
| 178 | onShow : function() |
| 179 | { |
| 180 | var color = editor.getUiColor(); |
| 181 | if ( color ) |
| 182 | this.setValue( |
| 183 | 'config.uiColor = "' + color + '"' |
| 184 | ); |
| 185 | } |
| 186 | } |
| 187 | ] |
| 188 | }, |
| 189 | ] |
| 190 | } |
| 191 | ], |
| 192 | buttons : [ CKEDITOR.dialog.okButton ] |
| 193 | }; |
| 194 | } ); |