1/* global Fluid, CONFIG */ 2 3HTMLElement.prototype.wrap = function(wrapper) { 4 this.parentNode.insertBefore(wrapper, this); 5 this.parentNode.removeChild(this); 6 wrapper.appendChild(this); 7}; 8 9Fluid.plugins = { 10 11 typing: function(text) { 12 if (!('Typed' in window)) { return; } 13 14 var typed = new window.Typed('#subtitle', { 15 strings: [ 16 ' ', 17 text 18 ], 19 cursorChar: CONFIG.typing.cursorChar, 20 typeSpeed : CONFIG.typing.typeSpeed, 21 loop : CONFIG.typing.loop 22 }); 23 typed.stop(); 24 var subtitle = document.getElementById('subtitle'); 25 if (subtitle) { 26 subtitle.innerText = ''; 27 } 28 jQuery(document).ready(function() { 29 typed.start(); 30 }); 31 }, 32 33 fancyBox: function(selector) { 34 if (!CONFIG.image_zoom.enable || !('fancybox' in jQuery)) { return; } 35 36 jQuery(selector || '.markdown-body :not(a) > img, .markdown-body > img').each(function() { 37 var $image = jQuery(this); 38 var imageUrl = $image.attr('data-src') || $image.attr('src') || ''; 39 if (CONFIG.image_zoom.img_url_replace) { 40 var rep = CONFIG.image_zoom.img_url_replace; 41 var r1 = rep[0] || ''; 42 var r2 = rep[1] || ''; 43 if (r1) { 44 if (/^re:/.test(r1)) { 45 r1 = r1.replace(/^re:/, ''); 46 var reg = new RegExp(r1, 'gi'); 47 imageUrl = imageUrl.replace(reg, r2); 48 } else { 49 imageUrl = imageUrl.replace(r1, r2); 50 } 51 } 52 } 53 var $imageWrap = $image.wrap(` 54 <a class="fancybox fancybox.image" href="${imageUrl}" 55 itemscope itemtype="http://schema.org/ImageObject" itemprop="url"></a>` 56 ).parent('a'); 57 if ($imageWrap.length !== 0) { 58 if ($image.is('.group-image-container img')) { 59 $imageWrap.attr('data-fancybox', 'group').attr('rel', 'group'); 60 } else { 61 $imageWrap.attr('data-fancybox', 'default').attr('rel', 'default'); 62 } 63 64 var imageTitle = $image.attr('title') || $image.attr('alt'); 65 if (imageTitle) { 66 $imageWrap.attr('title', imageTitle).attr('data-caption', imageTitle); 67 } 68 } 69 }); 70 71 jQuery.fancybox.defaults.hash = false; 72 jQuery('.fancybox').fancybox({ 73 loop : true, 74 helpers: { 75 overlay: { 76 locked: false 77 } 78 } 79 }); 80 }, 81 82 imageCaption: function(selector) { 83 if (!CONFIG.image_caption.enable) { return; } 84 85 jQuery(selector || `.markdown-body > p > img, .markdown-body > figure > img, 86 .markdown-body > p > a.fancybox, .markdown-body > figure > a.fancybox`).each(function() { 87 var $target = jQuery(this); 88 var $figcaption = $target.next('figcaption'); 89 if ($figcaption.length !== 0) { 90 $figcaption.addClass('image-caption'); 91 } else { 92 var imageTitle = $target.attr('title') || $target.attr('alt'); 93 if (imageTitle) { 94 $target.after(`<figcaption aria-hidden="true" class="image-caption">${imageTitle}</figcaption>`); 95 } 96 } 97 }); 98 }, 99 100 codeWidget() { 101 var enableLang = CONFIG.code_language.enable && CONFIG.code_language.default; 102 var enableCopy = CONFIG.copy_btn && 'ClipboardJS' in window; 103 if (!enableLang && !enableCopy) { 104 return; 105 } 106 107 function getBgClass(ele) { 108 return Fluid.utils.getBackgroundLightness(ele) >= 0 ? 'code-widget-light' : 'code-widget-dark'; 109 } 110 111 var copyTmpl = ''; 112 copyTmpl += '<div class="code-widget">'; 113 copyTmpl += 'LANG'; 114 copyTmpl += '</div>'; 115 jQuery('.markdown-body pre').each(function() { 116 var $pre = jQuery(this); 117 if ($pre.find('code.mermaid').length > 0) { 118 return; 119 } 120 if ($pre.find('span.line').length > 0) { 121 return; 122 } 123 124 var lang = ''; 125 126 if (enableLang) { 127 lang = CONFIG.code_language.default; 128 if ($pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2 && $pre.children().hasClass('hljs')) { 129 lang = $pre[0].children[0].classList[1]; 130 } else if ($pre[0].getAttribute('data-language')) { 131 lang = $pre[0].getAttribute('data-language'); 132 } else if ($pre.parent().hasClass('sourceCode') && $pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2) { 133 lang = $pre[0].children[0].classList[1]; 134 $pre.parent().addClass('code-wrapper'); 135 } else if ($pre.parent().hasClass('markdown-body') && $pre[0].classList.length === 0) { 136 $pre.wrap('<div class="code-wrapper"></div>'); 137 } 138 lang = lang.toUpperCase().replace('NONE', CONFIG.code_language.default); 139 } 140 $pre.append(copyTmpl.replace('LANG', lang).replace('code-widget">', 141 getBgClass($pre[0]) + (enableCopy ? ' code-widget copy-btn" data-clipboard-snippet><i class="iconfont icon-copy"></i>' : ' code-widget">'))); 142 143 if (enableCopy) { 144 var clipboard = new ClipboardJS('.copy-btn', { 145 target: function(trigger) { 146 var nodes = trigger.parentNode.childNodes; 147 for (var i = 0; i < nodes.length; i++) { 148 if (nodes[i].tagName === 'CODE') { 149 return nodes[i]; 150 } 151 } 152 } 153 }); 154 clipboard.on('success', function(e) { 155 e.clearSelection(); 156 e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-copy', 'icon-success'); 157 setTimeout(function() { 158 e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-success', 'icon-copy'); 159 }, 2000); 160 }); 161 } 162 }); 163 } 164};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.