-
Notifications
You must be signed in to change notification settings - Fork 0
/
pega_yui_editor.js
8829 lines (8441 loc) · 370 KB
/
pega_yui_editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.5.2
*/
/*
Change #1: In the cmd_list updated the logic to fix the bullet/numbering extra line issue. copied this piece of code from 2.6.0
Change #2: Updated _buttonClick() to mark editor as dirty when any toolbar icon is clicked
Change #3: Updated cleanHTML() to decode all '&' back to '&'.
Change #4: Updated filter_invalid_lists() to correct regular expression by putting '?' to make \n optional
Change #5: Added purgeElement in pega.widget.toolbar destroy
Change #6: Added purgeElement in pega.widget.toolbar addButton
Change #7: Updated _cleanIncomingHTML() to remove extra empty lines and to prevent inserting empty lines.
Change #8: Updated cmd_forecolor to support in FireFox
Change #9: Updated cmd_backcolor to support in FireFox
Change #10: Updated this.setAttributeConfig('html') to pass LINKS
Change #11: Updated _getSelectedElement() to fix the formatting issue in ordered/unordered list
Change #12: Updated cmd_list to create formatted list in IE
Change #13: Created _findStyle(), _cleanSpans() to improve the text selection and clean the unncessary spans.
Change #14: Modified _handleAfterNodeChange to improve load time /check in check out time for large content in RTE
Change #15: Modified _createColorPicker api to register with proper function name for load instead of anonymous function and created appendColorPicker api
Change #16: Modified cmd_fontsize - _cleanSpans() is called to remove unnecessary <span> tags
Change #17: Modified cleanHTML because - browsers sometimes add <p>..</p> tags around content from the design mode. These tags are undesirable as they cause empty spaces in the templates. Make the behavior consistent by removing these tags
Change #18: Modified cleanHTML to clean up markup generated by spellchecker before further processing(raidv)
*/
(function() {
/**
* @private
**/
var Dom = pega.util.Dom,
Event = pega.util.Event,
Lang = pega.lang;
/**
* @description <p>Creates a rich custom Toolbar Button. Primarily used with the Rich Text Editor's Toolbar</p>
* @class ToolbarButtonAdvanced
* @namespace pega.widget
* @requires yahoo, dom, element, event, container_core, menu, button
* @beta
*
* Provides a toolbar button based on the button and menu widgets.
* @constructor
* @param {String/HTMLElement} el The element to turn into a button.
* @param {Object} attrs Object liternal containing configuration parameters.
*/
if (pega.widget.Button) {
pega.widget.ToolbarButtonAdvanced = pega.widget.Button;
/**
* @property buttonType
* @private<body
* @description Tells if the Button is a Rich Button or a Simple Button
*/
pega.widget.ToolbarButtonAdvanced.prototype.buttonType = 'rich';
/**
* @method checkValue
* @param {String} value The value of the option that we want to mark as selected
* @description Select an option by value
*/
pega.widget.ToolbarButtonAdvanced.prototype.checkValue = function(value) {
var _menuItems = this.getMenu().getItems();
if (_menuItems.length === 0) {
this.getMenu()._onBeforeShow();
_menuItems = this.getMenu().getItems();
}
for (var i = 0; i < _menuItems.length; i++) {
_menuItems[i].cfg.setProperty('checked', false);
if (_menuItems[i].value == value) {
_menuItems[i].cfg.setProperty('checked', true);
}
}
};
} else {
pega.widget.ToolbarButtonAdvanced = function() {};
}
/**
* @description <p>Creates a basic custom Toolbar Button. Primarily used with the Rich Text Editor's Toolbar</p>
* @class ToolbarButton
* @namespace pega.widget
* @requires yahoo, dom, element, event
* @Extends pega.util.Element
* @beta
*
* Provides a toolbar button based on the button and menu widgets, <select> elements are used in place of menu's.
* @constructor
* @param {String/HTMLElement} el The element to turn into a button.
* @param {Object} attrs Object liternal containing configuration parameters.
*/
pega.widget.ToolbarButton = function(el, attrs) {
if (Lang.isObject(arguments[0]) && !Dom.get(el).nodeType) {
attrs = el;
}
var local_attrs = (attrs || {});
var oConfig = {
element: null,
attributes: local_attrs
};
if (!oConfig.attributes.type) {
oConfig.attributes.type = 'push';
}
oConfig.element = document.createElement('span');
oConfig.element.setAttribute('unselectable', 'on');
oConfig.element.className = 'yui-button yui-' + oConfig.attributes.type + '-button';
oConfig.element.innerHTML = '<span class="first-child"><a href="#">LABEL</a></span>';
oConfig.element.firstChild.firstChild.tabIndex = '-1';
oConfig.attributes.id = Dom.generateId();
pega.widget.ToolbarButton.superclass.constructor.call(this, oConfig.element, oConfig.attributes);
};
pega.extend(pega.widget.ToolbarButton, pega.util.Element, {
/**
* @property buttonType
* @private
* @description Tells if the Button is a Rich Button or a Simple Button
*/
buttonType: 'normal',
/**
* @method _handleMouseOver
* @private
* @description Adds classes to the button elements on mouseover (hover)
*/
_handleMouseOver: function() {
if (!this.get('disabled')) {
this.addClass('yui-button-hover');
this.addClass('yui-' + this.get('type') + '-button-hover');
}
},
/**
* @method _handleMouseOut
* @private
* @description Removes classes from the button elements on mouseout (hover)
*/
_handleMouseOut: function() {
this.removeClass('yui-button-hover');
this.removeClass('yui-' + this.get('type') + '-button-hover');
},
/**
* @method checkValue
* @param {String} value The value of the option that we want to mark as selected
* @description Select an option by value
*/
checkValue: function(value) {
if (this.get('type') == 'menu') {
var opts = this._button.options;
for (var i = 0; i < opts.length; i++) {
if (opts[i].value == value) {
opts.selectedIndex = i;
}
}
}
},
/**
* @method init
* @description The ToolbarButton class's initialization method
*/
init: function(p_oElement, p_oAttributes) {
pega.widget.ToolbarButton.superclass.init.call(this, p_oElement, p_oAttributes);
this.on('mouseover', this._handleMouseOver, this, true);
this.on('mouseout', this._handleMouseOut, this, true);
},
/**
* @method initAttributes
* @description Initializes all of the configuration attributes used to create
* the toolbar.
* @param {Object} attr Object literal specifying a set of
* configuration attributes used to create the toolbar.
*/
initAttributes: function(attr) {
pega.widget.ToolbarButton.superclass.initAttributes.call(this, attr);
/**
* @attribute value
* @description The value of the button
* @type String
*/
this.setAttributeConfig('value', {
value: attr.value
});
/**
* @attribute menu
* @description The menu attribute, see pega.widget.Button
* @type Object
*/
this.setAttributeConfig('menu', {
value: attr.menu || false
});
/**
* @attribute type
* @description The type of button to create: push, menu, color, select, spin
* @type String
*/
this.setAttributeConfig('type', {
value: attr.type,
writeOnce: true,
method: function(type) {
var el, opt;
if (!this._button) {
this._button = this.get('element').getElementsByTagName('a')[0];
}
switch (type) {
case 'select':
case 'menu':
el = document.createElement('select');
var menu = this.get('menu');
for (var i = 0; i < menu.length; i++) {
opt = document.createElement('option');
opt.innerHTML = menu[i].text;
opt.value = menu[i].value;
if (menu[i].checked) {
opt.selected = true;
}
el.appendChild(opt);
}
this._button.parentNode.replaceChild(el, this._button);
Event.on(el, 'change', this._handleSelect, this, true);
this._button = el;
break;
}
}
});
/**
* @attribute disabled
* @description Set the button into a disabled state
* @type String
*/
this.setAttributeConfig('disabled', {
value: attr.disabled || false,
method: function(disabled) {
if (disabled) {
this.addClass('yui-button-disabled');
this.addClass('yui-' + this.get('type') + '-button-disabled');
if (this.get('type') == 'color') {
this.get('menu').hide();
}
} else {
this.removeClass('yui-button-disabled');
this.removeClass('yui-' + this.get('type') + '-button-disabled');
}
if (this.get('type') == 'menu') {
this._button.disabled = disabled;
}
}
});
/**
* @attribute label
* @description The text label for the button
* @type String
*/
this.setAttributeConfig('label', {
value: attr.label,
method: function(label) {
if (!this._button) {
this._button = this.get('element').getElementsByTagName('a')[0];
}
if (this.get('type') == 'push') {
this._button.innerHTML = label;
}
}
});
/**
* @attribute title
* @description The title of the button
* @type String
*/
this.setAttributeConfig('title', {
value: attr.title
});
/**
* @config container
* @description The container that the button is rendered to, handled by Toolbar
* @type String
*/
this.setAttributeConfig('container', {
value: null,
writeOnce: true,
method: function(cont) {
this.appendTo(cont);
}
});
},
/**
* @private
* @method _handleSelect
* @description The event fired when a change event gets fired on a select element
* @param {Event} ev The change event.
*/
_handleSelect: function(ev) {
var tar = Event.getTarget(ev);
var value = tar.options[tar.selectedIndex].value;
this.fireEvent('change', {type: 'change', value: value });
},
/**
* @method getMenu
* @description A stub function to mimic pega.widget.Button's getMenu method
*/
getMenu: function() {
return this.get('menu');
},
/**
* @method destroy
* @description Destroy the button
*/
destroy: function() {
Event.purgeElement(this.get('element'), true);
if(this.get('element') && this.get('element').parentNode)
this.get('element').parentNode.removeChild(this.get('element'));
//Brutal Object Destroy
for (var i in this) {
if (Lang.hasOwnProperty(this, i)) {
this[i] = null;
}
}
},
/**
* @method fireEvent
* @description Overridden fireEvent method to prevent DOM events from firing if the button is disabled.
*/
fireEvent: function (p_sType , p_aArgs) {
// Disabled buttons should not respond to DOM events
if (this.DOM_EVENTS[p_sType] && this.get('disabled')) {
return;
}
pega.widget.ToolbarButton.superclass.fireEvent.call(this, p_sType, p_aArgs);
},
/**
* @method toString
* @description Returns a string representing the toolbar.
* @return {String}
*/
toString: function() {
return 'ToolbarButton (' + this.get('id') + ')';
}
});
})();
/**
* @description <p>Creates a rich Toolbar widget based on Button. Primarily used with the Rich Text Editor</p>
* @namespace pega.widget
* @requires yahoo, dom, element, event, toolbarbutton
* @optional container_core, dragdrop
* @beta
*/
(function() {
/**
* @private
**/
var Dom = pega.util.Dom,
Event = pega.util.Event,
Lang = pega.lang;
var getButton = function(id) {
var button = id;
if (Lang.isString(id)) {
button = this.getButtonById(id);
}
if (Lang.isNumber(id)) {
button = this.getButtonByIndex(id);
}
if ((!(button instanceof pega.widget.ToolbarButton)) && (!(button instanceof pega.widget.ToolbarButtonAdvanced))) {
button = this.getButtonByValue(id);
}
if ((button instanceof pega.widget.ToolbarButton) || (button instanceof pega.widget.ToolbarButtonAdvanced)) {
return button;
}
return false;
};
/**
* Provides a rich toolbar widget based on the button and menu widgets
* @constructor
* @class Toolbar
* @extends pega.util.Element
* @param {String/HTMLElement} el The element to turn into a toolbar.
* @param {Object} attrs Object liternal containing configuration parameters.
*/
pega.widget.Toolbar = function(el, attrs) {
if (Lang.isObject(arguments[0]) && !Dom.get(el).nodeType) {
attrs = el;
}
this.rteElts = false;
if(attrs && attrs.rteElts) {
this.rteElts = attrs.rteElts;
delete attrs["rteElts"];
}
var local_attrs = (attrs || {});
var oConfig = {
element: null,
attributes: local_attrs
};
if (Lang.isString(el) && Dom.get(el)) {
oConfig.element = Dom.get(el);
} else if (Lang.isObject(el) && Dom.get(el) && Dom.get(el).nodeType) {
oConfig.element = Dom.get(el);
}
if (!oConfig.element) {
oConfig.element = document.createElement('DIV');
oConfig.element.id = Dom.generateId();
if (local_attrs.container && Dom.get(local_attrs.container)) {
Dom.get(local_attrs.container).appendChild(oConfig.element);
}
}
if (!oConfig.element.id) {
oConfig.element.id = ((Lang.isString(el)) ? el : Dom.generateId());
}
if(!this.rteElts) {
var fs = document.createElement('fieldset');
var lg = document.createElement('legend');
lg.innerHTML = 'Toolbar';
fs.appendChild(lg);
var cont = document.createElement('DIV');
oConfig.attributes.cont = cont;
Dom.addClass(cont, 'yui-toolbar-subcont');
fs.appendChild(cont);
oConfig.element.appendChild(fs);
oConfig.element.tabIndex = -1;
}
else {
oConfig.attributes.cont = oConfig.element.getElementsByTagName("FIELDSET")[0].getElementsByTagName("DIV")[0];
}
oConfig.attributes.element = oConfig.element;
oConfig.attributes.id = oConfig.element.id;
pega.widget.Toolbar.superclass.constructor.call(this, oConfig.element, oConfig.attributes);
};
/**
* @method _addMenuClasses
* @private
* @description This method is called from Menu's renderEvent to add a few more classes to the menu items
* @param {String} ev The event that fired.
* @param {Array} na Array of event information.
* @param {Object} o Button config object.
*/
function _addMenuClasses(ev, na, o) {
Dom.addClass(this.element, 'yui-toolbar-' + o.get('value') + '-menu');
if (Dom.hasClass(o._button.parentNode.parentNode, 'yui-toolbar-select')) {
Dom.addClass(this.element, 'yui-toolbar-select-menu');
}
var items = this.getItems();
for (var i = 0; i < items.length; i++) {
Dom.addClass(items[i].element, 'yui-toolbar-' + o.get('value') + '-' + ((items[i].value) ? items[i].value.replace(/ /g, '-').toLowerCase() : items[i]._oText.nodeValue.replace(/ /g, '-').toLowerCase()));
Dom.addClass(items[i].element, 'yui-toolbar-' + o.get('value') + '-' + ((items[i].value) ? items[i].value.replace(/ /g, '-') : items[i]._oText.nodeValue.replace(/ /g, '-')));
}
}
pega.extend(pega.widget.Toolbar, pega.util.Element, {
/**
* @property buttonType
* @description The default button to use
* @type Object
*/
buttonType: pega.widget.ToolbarButton,
/**
* @property dd
* @description The DragDrop instance associated with the Toolbar
* @type Object
*/
dd: null,
/**
* @property _colorData
* @description Object reference containing colors hex and text values.
* @type Object
*/
_colorData: {
/* {{{ _colorData */
'#111111': 'Obsidian',
'#2D2D2D': 'Dark Gray',
'#434343': 'Shale',
'#5B5B5B': 'Flint',
'#737373': 'Gray',
'#8B8B8B': 'Concrete',
'#A2A2A2': 'Gray',
'#B9B9B9': 'Titanium',
'#000000': 'Black',
'#D0D0D0': 'Light Gray',
'#E6E6E6': 'Silver',
'#FFFFFF': 'White',
'#BFBF00': 'Pumpkin',
'#FFFF00': 'Yellow',
'#FFFF40': 'Banana',
'#FFFF80': 'Pale Yellow',
'#FFFFBF': 'Butter',
'#525330': 'Raw Siena',
'#898A49': 'Mildew',
'#AEA945': 'Olive',
'#7F7F00': 'Paprika',
'#C3BE71': 'Earth',
'#E0DCAA': 'Khaki',
'#FCFAE1': 'Cream',
'#60BF00': 'Cactus',
'#80FF00': 'Chartreuse',
'#A0FF40': 'Green',
'#C0FF80': 'Pale Lime',
'#DFFFBF': 'Light Mint',
'#3B5738': 'Green',
'#668F5A': 'Lime Gray',
'#7F9757': 'Yellow',
'#407F00': 'Clover',
'#8A9B55': 'Pistachio',
'#B7C296': 'Light Jade',
'#E6EBD5': 'Breakwater',
'#00BF00': 'Spring Frost',
'#00FF80': 'Pastel Green',
'#40FFA0': 'Light Emerald',
'#80FFC0': 'Sea Foam',
'#BFFFDF': 'Sea Mist',
'#033D21': 'Dark Forrest',
'#438059': 'Moss',
'#7FA37C': 'Medium Green',
'#007F40': 'Pine',
'#8DAE94': 'Yellow Gray Green',
'#ACC6B5': 'Aqua Lung',
'#DDEBE2': 'Sea Vapor',
'#00BFBF': 'Fog',
'#00FFFF': 'Cyan',
'#40FFFF': 'Turquoise Blue',
'#80FFFF': 'Light Aqua',
'#BFFFFF': 'Pale Cyan',
'#033D3D': 'Dark Teal',
'#347D7E': 'Gray Turquoise',
'#609A9F': 'Green Blue',
'#007F7F': 'Seaweed',
'#96BDC4': 'Green Gray',
'#B5D1D7': 'Soapstone',
'#E2F1F4': 'Light Turquoise',
'#0060BF': 'Summer Sky',
'#0080FF': 'Sky Blue',
'#40A0FF': 'Electric Blue',
'#80C0FF': 'Light Azure',
'#BFDFFF': 'Ice Blue',
'#1B2C48': 'Navy',
'#385376': 'Biscay',
'#57708F': 'Dusty Blue',
'#00407F': 'Sea Blue',
'#7792AC': 'Sky Blue Gray',
'#A8BED1': 'Morning Sky',
'#DEEBF6': 'Vapor',
'#0000BF': 'Deep Blue',
'#0000FF': 'Blue',
'#4040FF': 'Cerulean Blue',
'#8080FF': 'Evening Blue',
'#BFBFFF': 'Light Blue',
'#212143': 'Deep Indigo',
'#373E68': 'Sea Blue',
'#444F75': 'Night Blue',
'#00007F': 'Indigo Blue',
'#585E82': 'Dockside',
'#8687A4': 'Blue Gray',
'#D2D1E1': 'Light Blue Gray',
'#6000BF': 'Neon Violet',
'#8000FF': 'Blue Violet',
'#A040FF': 'Violet Purple',
'#C080FF': 'Violet Dusk',
'#DFBFFF': 'Pale Lavender',
'#302449': 'Cool Shale',
'#54466F': 'Dark Indigo',
'#655A7F': 'Dark Violet',
'#40007F': 'Violet',
'#726284': 'Smoky Violet',
'#9E8FA9': 'Slate Gray',
'#DCD1DF': 'Violet White',
'#BF00BF': 'Royal Violet',
'#FF00FF': 'Fuchsia',
'#FF40FF': 'Magenta',
'#FF80FF': 'Orchid',
'#FFBFFF': 'Pale Magenta',
'#4A234A': 'Dark Purple',
'#794A72': 'Medium Purple',
'#936386': 'Cool Granite',
'#7F007F': 'Purple',
'#9D7292': 'Purple Moon',
'#C0A0B6': 'Pale Purple',
'#ECDAE5': 'Pink Cloud',
'#BF005F': 'Hot Pink',
'#FF007F': 'Deep Pink',
'#FF409F': 'Grape',
'#FF80BF': 'Electric Pink',
'#FFBFDF': 'Pink',
'#451528': 'Purple Red',
'#823857': 'Purple Dino',
'#A94A76': 'Purple Gray',
'#7F003F': 'Rose',
'#BC6F95': 'Antique Mauve',
'#D8A5BB': 'Cool Marble',
'#F7DDE9': 'Pink Granite',
'#C00000': 'Apple',
'#FF0000': 'Fire Truck',
'#FF4040': 'Pale Red',
'#FF8080': 'Salmon',
'#FFC0C0': 'Warm Pink',
'#441415': 'Sepia',
'#82393C': 'Rust',
'#AA4D4E': 'Brick',
'#800000': 'Brick Red',
'#BC6E6E': 'Mauve',
'#D8A3A4': 'Shrimp Pink',
'#F8DDDD': 'Shell Pink',
'#BF5F00': 'Dark Orange',
'#FF7F00': 'Orange',
'#FF9F40': 'Grapefruit',
'#FFBF80': 'Canteloupe',
'#FFDFBF': 'Wax',
'#482C1B': 'Dark Brick',
'#855A40': 'Dirt',
'#B27C51': 'Tan',
'#7F3F00': 'Nutmeg',
'#C49B71': 'Mustard',
'#E1C4A8': 'Pale Tan',
'#FDEEE0': 'Marble'
/* }}} */
},
/**
* @property _colorPicker
* @description The HTML Element containing the colorPicker
* @type HTMLElement
*/
_colorPicker: null,
/**
* @property STR_COLLAPSE
* @description String for Toolbar Collapse Button
* @type String
*/
STR_COLLAPSE: 'Collapse Toolbar',
/**
* @property STR_SPIN_LABEL
* @description String for spinbutton dynamic label. Note the {VALUE} will be replaced with pega.lang.substitute
* @type String
*/
STR_SPIN_LABEL: 'Spin Button with value {VALUE}. Use Control Shift Up Arrow and Control Shift Down arrow keys to increase or decrease the value.',
/**
* @property STR_SPIN_UP
* @description String for spinbutton up
* @type String
*/
STR_SPIN_UP: 'Click to increase the value of this input',
/**
* @property STR_SPIN_DOWN
* @description String for spinbutton down
* @type String
*/
STR_SPIN_DOWN: 'Click to decrease the value of this input',
/**
* @property _titlebar
* @description Object reference to the titlebar
* @type HTMLElement
*/
_titlebar: null,
/**
* @property browser
* @description Standard browser detection
* @type Object
*/
browser: pega.env.ua,
/**
* @protected
* @property _buttonList
* @description Internal property list of current buttons in the toolbar
* @type Array
*/
_buttonList: null,
/**
* @protected
* @property _buttonGroupList
* @description Internal property list of current button groups in the toolbar
* @type Array
*/
_buttonGroupList: null,
/**
* @protected
* @property _sep
* @description Internal reference to the separator HTML Element for cloning
* @type HTMLElement
*/
_sep: null,
/**
* @protected
* @property _sepCount
* @description Internal refernce for counting separators, so we can give them a useful class name for styling
* @type Number
*/
_sepCount: null,
/**
* @protected
* @property draghandle
* @type HTMLElement
*/
_dragHandle: null,
/**
* @protected
* @property _toolbarConfigs
* @type Object
*/
_toolbarConfigs: {
renderer: true
},
/**
* @protected
* @property CLASS_CONTAINER
* @description Default CSS class to apply to the toolbar container element
* @type String
*/
CLASS_CONTAINER: 'yui-toolbar-container',
/**
* @protected
* @property CLASS_DRAGHANDLE
* @description Default CSS class to apply to the toolbar's drag handle element
* @type String
*/
CLASS_DRAGHANDLE: 'yui-toolbar-draghandle',
/**
* @protected
* @property CLASS_SEPARATOR
* @description Default CSS class to apply to all separators in the toolbar
* @type String
*/
CLASS_SEPARATOR: 'yui-toolbar-separator',
/**
* @protected
* @property CLASS_DISABLED
* @description Default CSS class to apply when the toolbar is disabled
* @type String
*/
CLASS_DISABLED: 'yui-toolbar-disabled',
/**
* @protected
* @property CLASS_PREFIX
* @description Default prefix for dynamically created class names
* @type String
*/
CLASS_PREFIX: 'yui-toolbar',
/**
* @method init
* @description The Toolbar class's initialization method
*/
init: function(p_oElement, p_oAttributes) {
pega.widget.Toolbar.superclass.init.call(this, p_oElement, p_oAttributes);
},
/**
* @method initAttributes
* @description Initializes all of the configuration attributes used to create
* the toolbar.
* @param {Object} attr Object literal specifying a set of
* configuration attributes used to create the toolbar.
*/
initAttributes: function(attr) {
pega.widget.Toolbar.superclass.initAttributes.call(this, attr);
this.addClass(this.CLASS_CONTAINER);
/**
* @attribute buttonType
* @description The buttonType to use (advanced or basic)
* @type String
*/
this.setAttributeConfig('buttonType', {
value: attr.buttonType || 'basic',
writeOnce: true,
validator: function(type) {
switch (type) {
case 'advanced':
case 'basic':
return true;
}
return false;
},
method: function(type) {
if (type == 'advanced') {
if (pega.widget.Button) {
this.buttonType = pega.widget.ToolbarButtonAdvanced;
} else {
this.buttonType = pega.widget.ToolbarButton;
}
} else {
this.buttonType = pega.widget.ToolbarButton;
}
}
});
/**
* @attribute buttons
* @description Object specifying the buttons to include in the toolbar
* Example:
* <code><pre>
* {
* { id: 'b3', type: 'button', label: 'Underline', value: 'underline' },
* { type: 'separator' },
* { id: 'b4', type: 'menu', label: 'Align', value: 'align',
* menu: [
* { text: "Left", value: 'alignleft' },
* { text: "Center", value: 'aligncenter' },
* { text: "Right", value: 'alignright' }
* ]
* }
* }
* </pre></code>
* @type Array
*/
this.setAttributeConfig('buttons', {
value: [],
writeOnce: true,
method: function(data) {
for (var i in data) {
if (Lang.hasOwnProperty(data, i)) {
if (data[i].type == 'separator') {
this.addSeparator();
} else if (data[i].group !== undefined) {
this.addButtonGroup(data[i]);
} else {
this.addButton(data[i]);
}
}
}
}
});
/**
* @attribute disabled
* @description Boolean indicating if the toolbar should be disabled. It will also disable the draggable attribute if it is on.
* @default false
* @type Boolean
*/
this.setAttributeConfig('disabled', {
value: false,
method: function(disabled) {
if (this.get('disabled') === disabled) {
return false;
}
if (disabled) {
this.addClass(this.CLASS_DISABLED);
this.set('draggable', false);
this.disableAllButtons();
} else {
this.removeClass(this.CLASS_DISABLED);
if (this._configs.draggable._initialConfig.value) {
//Draggable by default, set it back
this.set('draggable', true);
}
this.resetAllButtons();
}
}
});
/**
* @config cont
* @description The container for the toolbar.
* @type HTMLElement
*/
this.setAttributeConfig('cont', {
value: attr.cont,
readOnly: true
});
/**
* @attribute grouplabels
* @description Boolean indicating if the toolbar should show the group label's text string.
* @default true
* @type Boolean
*/
this.setAttributeConfig('grouplabels', {
value: ((attr.grouplabels === false) ? false : true),
method: function(grouplabels) {
if (grouplabels) {
Dom.removeClass(this.get('cont'), (this.CLASS_PREFIX + '-nogrouplabels'));
} else {
Dom.addClass(this.get('cont'), (this.CLASS_PREFIX + '-nogrouplabels'));
}
}
});
/**
* @attribute titlebar
* @description Boolean indicating if the toolbar should have a titlebar. If
* passed a string, it will use that as the titlebar text
* @default false
* @type Boolean or String
*/
this.setAttributeConfig('titlebar', {
value: false,
method: function(titlebar) {
if (titlebar) {
if (this._titlebar && this._titlebar.parentNode) {
this._titlebar.parentNode.removeChild(this._titlebar);
}
this._titlebar = document.createElement('DIV');
this._titlebar.tabIndex = '-1';
Event.on(this._titlebar, 'focus', function() {
this._handleFocus();
}, this, true);
Dom.addClass(this._titlebar, this.CLASS_PREFIX + '-titlebar');
if (Lang.isString(titlebar)) {
var h2 = document.createElement('h2');
h2.tabIndex = '-1';
h2.innerHTML = '<a href="#" tabIndex="0">' + titlebar + '</a>';
this._titlebar.appendChild(h2);
Event.on(h2.firstChild, 'click', function(ev) {
Event.stopEvent(ev);
});
Event.on([h2, h2.firstChild], 'focus', function() {
this._handleFocus();
}, this, true);
}
if (this.get('firstChild')) {
this.insertBefore(this._titlebar, this.get('firstChild'));
} else {
this.appendChild(this._titlebar);
}
if (this.get('collapse')) {
this.set('collapse', true);
}
} else if (this._titlebar) {
if (this._titlebar && this._titlebar.parentNode) {
this._titlebar.parentNode.removeChild(this._titlebar);
}
}
}
});
/**
* @attribute collapse
* @description Boolean indicating if the the titlebar should have a collapse button.
* The collapse button will not remove the toolbar, it will minimize it to the titlebar
* @default false
* @type Boolean
*/
this.setAttributeConfig('collapse', {
value: false,
method: function(collapse) {
if (this._titlebar) {
var collapseEl = null;
var el = Dom.getElementsByClassName('collapse', 'span', this._titlebar);
if (collapse) {
if (el.length > 0) {
//There is already a collapse button
return true;
}
collapseEl = document.createElement('SPAN');
collapseEl.innerHTML = 'X';
var label = this.STR_COLLAPSE;
if(pega.u.d.fieldValuesList.get('STR_COLLAPSE')) label = pega.u.d.fieldValuesList.get('STR_COLLAPSE').replace("/","");
collapseEl.title = label;
Dom.addClass(collapseEl, 'collapse');
this._titlebar.appendChild(collapseEl);
Event.addListener(collapseEl, 'click', function() {
if (Dom.hasClass(this.get('cont').parentNode, 'yui-toolbar-container-collapsed')) {
this.collapse(false); //Expand Toolbar
} else {
this.collapse(); //Collapse Toolbar
}
}, this, true);
} else {
collapseEl = Dom.getElementsByClassName('collapse', 'span', this._titlebar);
if (collapseEl[0]) {
if (Dom.hasClass(this.get('cont').parentNode, 'yui-toolbar-container-collapsed')) {
//We are closed, reopen the titlebar..
this.collapse(false); //Expand Toolbar
}
collapseEl[0].parentNode.removeChild(collapseEl[0]);
}
}
}
}
});
/**
* @attribute draggable
* @description Boolean indicating if the toolbar should be draggable.
* @default false