File modules/editor/trumbowyg/plugins/lineheight/trumbowyg.lineheight.js

Last commit: Tue Aug 28 00:33:27 2018 +0200	Jan Dankert	Editoren für Markdown (SimpleMDE) und HTML (Trumbowyg) installiert.
1 (function ($) { 2 'use strict'; 3 4 $.extend(true, $.trumbowyg, { 5 langs: { 6 // jshint camelcase:false 7 en: { 8 lineheight: 'Line height', 9 lineheights: { 10 '0.9': 'Small', 11 'normal': 'Regular', 12 '1.5': 'Large', 13 '2.0': 'Extra large' 14 } 15 }, 16 fr: { 17 lineheight: 'Hauteur de ligne', 18 lineheights: { 19 '0.9': 'Petit', 20 'normal': 'Regular', 21 '1.5': 'Grand', 22 '2.0': 'Très grand' 23 } 24 }, 25 nl: { 26 lineheight: 'Regelhoogte', 27 lineheights: { 28 '0.9': 'Klein', 29 'normal': 'Normaal', 30 '1.5': 'Groot', 31 '2.0': 'Extra groot' 32 } 33 }, 34 tr: { 35 lineheight: 'Satır yüksekliği', 36 lineheights: { 37 '0.9': 'Küçük', 38 'normal': 'Normal', 39 '1.5': 'Büyük', 40 '2.0': 'Çok Büyük' 41 } 42 } 43 } 44 }); 45 // jshint camelcase:true 46 47 // Add dropdown with font sizes 48 $.extend(true, $.trumbowyg, { 49 plugins: { 50 lineheight: { 51 init: function (trumbowyg) { 52 trumbowyg.addBtnDef('lineheight', { 53 dropdown: buildDropdown(trumbowyg) 54 }); 55 } 56 } 57 } 58 }); 59 60 // Build the dropdown 61 function buildDropdown(trumbowyg) { 62 var dropdown = []; 63 var sizes = ['0.9', 'normal', '1.5', '2.0']; 64 65 $.each(sizes, function(index, size) { 66 trumbowyg.addBtnDef('lineheight_' + size, { 67 text: '<span style="line-height: ' + size + ';">' + trumbowyg.lang.lineheights[size] + '</span>', 68 hasIcon: false, 69 fn: function(){ 70 trumbowyg.saveRange(); 71 var text = trumbowyg.getRangeText(); 72 if (text.replace(/\s/g, '') !== '') { 73 try { 74 var parent = getSelectionParentElement(); 75 $(parent).css('lineHeight', size); 76 } catch (e) { 77 } 78 } 79 } 80 }); 81 dropdown.push('lineheight_' + size); 82 }); 83 84 return dropdown; 85 } 86 87 // Get the selection's parent 88 function getSelectionParentElement() { 89 var parentEl = null, 90 selection; 91 if (window.getSelection) { 92 selection = window.getSelection(); 93 if (selection.rangeCount) { 94 parentEl = selection.getRangeAt(0).commonAncestorContainer; 95 if (parentEl.nodeType !== 1) { 96 parentEl = parentEl.parentNode; 97 } 98 } 99 } else if ((selection = document.selection) && selection.type !== 'Control') { 100 parentEl = selection.createRange().parentElement(); 101 } 102 return parentEl; 103 } 104 })(jQuery);
Download modules/editor/trumbowyg/plugins/lineheight/trumbowyg.lineheight.js
History Tue, 28 Aug 2018 00:33:27 +0200 Jan Dankert Editoren für Markdown (SimpleMDE) und HTML (Trumbowyg) installiert.