1/** 2 * Called by picker buttons to insert Text and close the picker again 3 * 4 * @author Andreas Gohr <andi@splitbrain.org> 5 * @author Gabriel Birke <gb@birke-software.de> 6 */ 7function colorPickerInsert(text, edid){ 8 insertTags(edid,'<color '+text+'>', '</color>', ''); 9 pickerClose(); 10} 11 12/** 13 * Creates a picker window for inserting color tags 14 * 15 * The given list can be an associative array with text,icon pairs 16 * or a simple list of text. Style the picker window through the picker 17 * class or the picker buttons with the pickerbutton class. Picker 18 * windows are appended to the body and created invisible. 19 * 20 * @author Andreas Gohr <andi@splitbrain.org> 21 * @author Gabriel Birke <gb@birke-software.de> 22 */ 23function createColorPicker(id,list,icobase,edid){ 24 25 function getInsertHandler(colorCombination) { 26 return function(){ 27 colorPickerInsert(colorCombination, edid); 28 }; 29 } 30 31 var $picker = jQuery('<div class="picker" id="' + id + '"></div>'); 32 $picker.css({position:'absolute', 'marginLeft': '-10000px'}); 33 34 for(var key in list){ 35 if (list.hasOwnProperty(key)) { 36 var $btn = jQuery('<button class="pickerbutton" title="' + key + '"/>'), 37 colorspan = jQuery('<span>' + LANG.plugins.colorpicker.buttontext + '</span>'), 38 fgbg = list[key].split('/'), 39 colorCombination = list[key]; 40 colorspan.css({ 41 color:fgbg[0], 42 backgroundColor: fgbg[1] ? fgbg[1] : '#ffffff' 43 }); 44 45 $btn.append(colorspan); 46 $btn.click(getInsertHandler(list[key])); 47 $picker.append($btn); 48 } 49 } 50 jQuery('body').append($picker); 51 return $picker; 52} 53 54 55/** 56 * Add button action for picker buttons and create picker element 57 * 58 * @param DOMElement btn Button element to add the action to 59 * @param array props Associative array of button properties 60 * @param string edid ID of the editor textarea 61 * @return boolean If button should be appended 62 * @author Gabriel Birke <gb@birke-software.de> 63 */ 64function addBtnActionColorpicker($btn, props, edid) 65{ 66 var pickerid = 'picker'+(pickercounter++); 67 createColorPicker(pickerid, 68 props.list, 69 props.icobase, 70 edid); 71 $btn.click(function(){ 72 pickerToggle(pickerid, $btn); 73 return false; 74 }); 75 76 return true; 77} 78 79 80 81