File modules/editor/trumbowyg/plugins/colors/trumbowyg.colors.js
Last commit: Tue Aug 28 00:33:27 2018 +0200 Jan Dankert Editoren für Markdown (SimpleMDE) und HTML (Trumbowyg) installiert.
1 /* =========================================================== 2 * trumbowyg.colors.js v1.2 3 * Colors picker plugin for Trumbowyg 4 * http://alex-d.github.com/Trumbowyg 5 * =========================================================== 6 * Author : Alexandre Demode (Alex-D) 7 * Twitter : @AlexandreDemode 8 * Website : alex-d.fr 9 */ 10 11 (function ($) { 12 'use strict'; 13 14 $.extend(true, $.trumbowyg, { 15 langs: { 16 // jshint camelcase:false 17 cs: { 18 foreColor: 'Barva textu', 19 backColor: 'Barva pozadí' 20 }, 21 en: { 22 foreColor: 'Text color', 23 backColor: 'Background color' 24 }, 25 fr: { 26 foreColor: 'Couleur du texte', 27 backColor: 'Couleur de fond' 28 }, 29 nl: { 30 foreColor: 'Tekstkleur', 31 backColor: 'Achtergrondkleur' 32 }, 33 sk: { 34 foreColor: 'Farba textu', 35 backColor: 'Farba pozadia' 36 }, 37 zh_cn: { 38 foreColor: '文字颜色', 39 backColor: '背景颜色' 40 }, 41 ru: { 42 foreColor: 'Цвет текста', 43 backColor: 'Цвет выделения текста' 44 }, 45 ja: { 46 foreColor: '文字色', 47 backColor: '背景色' 48 }, 49 tr: { 50 foreColor: 'Yazı rengi', 51 backColor: 'Arkaplan rengi' 52 } 53 } 54 }); 55 56 // jshint camelcase:true 57 58 59 function hex(x) { 60 return ('0' + parseInt(x).toString(16)).slice(-2); 61 } 62 63 function colorToHex(rgb) { 64 if (rgb.search('rgb') === -1) { 65 return rgb.replace('#', ''); 66 } else if (rgb === 'rgba(0, 0, 0, 0)') { 67 return 'transparent'; 68 } else { 69 rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/); 70 return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); 71 } 72 } 73 74 function colorTagHandler(element, trumbowyg) { 75 var tags = []; 76 77 if (!element.style) { 78 return tags; 79 } 80 81 // background color 82 if (element.style.backgroundColor !== '') { 83 var backColor = colorToHex(element.style.backgroundColor); 84 if (trumbowyg.o.plugins.colors.colorList.indexOf(backColor) >= 0) { 85 tags.push('backColor' + backColor); 86 } else { 87 tags.push('backColorFree'); 88 } 89 } 90 91 // text color 92 var foreColor; 93 if (element.style.color !== '') { 94 foreColor = colorToHex(element.style.color); 95 } else if (element.hasAttribute('color')) { 96 foreColor = colorToHex(element.getAttribute('color')); 97 } 98 if (foreColor) { 99 if (trumbowyg.o.plugins.colors.colorList.indexOf(foreColor) >= 0) { 100 tags.push('foreColor' + foreColor); 101 } else { 102 tags.push('foreColorFree'); 103 } 104 } 105 106 return tags; 107 } 108 109 var defaultOptions = { 110 colorList: ['ffffff', '000000', 'eeece1', '1f497d', '4f81bd', 'c0504d', '9bbb59', '8064a2', '4bacc6', 'f79646', 'ffff00', 'f2f2f2', '7f7f7f', 'ddd9c3', 'c6d9f0', 'dbe5f1', 'f2dcdb', 'ebf1dd', 'e5e0ec', 'dbeef3', 'fdeada', 'fff2ca', 'd8d8d8', '595959', 'c4bd97', '8db3e2', 'b8cce4', 'e5b9b7', 'd7e3bc', 'ccc1d9', 'b7dde8', 'fbd5b5', 'ffe694', 'bfbfbf', '3f3f3f', '938953', '548dd4', '95b3d7', 'd99694', 'c3d69b', 'b2a2c7', 'b7dde8', 'fac08f', 'f2c314', 'a5a5a5', '262626', '494429', '17365d', '366092', '953734', '76923c', '5f497a', '92cddc', 'e36c09', 'c09100', '7f7f7f', '0c0c0c', '1d1b10', '0f243e', '244061', '632423', '4f6128', '3f3151', '31859b', '974806', '7f6000'] 111 }; 112 113 // Add all colors in two dropdowns 114 $.extend(true, $.trumbowyg, { 115 plugins: { 116 color: { 117 init: function (trumbowyg) { 118 trumbowyg.o.plugins.colors = trumbowyg.o.plugins.colors || defaultOptions; 119 var foreColorBtnDef = { 120 dropdown: buildDropdown('foreColor', trumbowyg) 121 }, 122 backColorBtnDef = { 123 dropdown: buildDropdown('backColor', trumbowyg) 124 }; 125 126 trumbowyg.addBtnDef('foreColor', foreColorBtnDef); 127 trumbowyg.addBtnDef('backColor', backColorBtnDef); 128 }, 129 tagHandler: colorTagHandler 130 } 131 } 132 }); 133 134 function buildDropdown(fn, trumbowyg) { 135 var dropdown = []; 136 137 $.each(trumbowyg.o.plugins.colors.colorList, function (i, color) { 138 var btn = fn + color, 139 btnDef = { 140 fn: fn, 141 forceCss: true, 142 param: '#' + color, 143 style: 'background-color: #' + color + ';' 144 }; 145 trumbowyg.addBtnDef(btn, btnDef); 146 dropdown.push(btn); 147 }); 148 149 var removeColorButtonName = fn + 'Remove', 150 removeColorBtnDef = { 151 fn: 'removeFormat', 152 param: fn, 153 style: 'background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAG0lEQVQIW2NkQAAfEJMRmwBYhoGBYQtMBYoAADziAp0jtJTgAAAAAElFTkSuQmCC);' 154 }; 155 trumbowyg.addBtnDef(removeColorButtonName, removeColorBtnDef); 156 dropdown.push(removeColorButtonName); 157 158 // add free color btn 159 var freeColorButtonName = fn + 'Free', 160 freeColorBtnDef = { 161 fn: function () { 162 trumbowyg.openModalInsert(trumbowyg.lang[fn], 163 { 164 color: { 165 label: fn, 166 value: '#FFFFFF' 167 } 168 }, 169 // callback 170 function (values) { 171 trumbowyg.execCmd(fn, values.color); 172 return true; 173 } 174 ); 175 }, 176 text: '#', 177 // style adjust for displaying the text 178 style: 'text-indent: 0;line-height: 20px;padding: 0 5px;' 179 }; 180 trumbowyg.addBtnDef(freeColorButtonName, freeColorBtnDef); 181 dropdown.push(freeColorButtonName); 182 183 return dropdown; 184 } 185 })(jQuery);
Downloadmodules/editor/trumbowyg/plugins/colors/trumbowyg.colors.js
History Tue, 28 Aug 2018 00:33:27 +0200 Jan Dankert Editoren für Markdown (SimpleMDE) und HTML (Trumbowyg) installiert.