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