Debian Codegraph @

debian/patches/replace-minified-js-with-original

raw
1 Description: Replace minified JS with its original source
2 The minified JS mentions « copied from develop.kde.org ».
3 This patch replaces the minified JS with the original source found in the
4 upstream website repo.
5 Origin: https://inven.kde.org/documentation/develop-kde-org/-/tree/4b2787c0e4bd8769dabb434a2f95cec8edf5c005/assets/js
6 ---
7 --- a/kapidox/data/htmlresource/js/main.js
8 +++ b/kapidox/data/htmlresource/js/main.js
9 @@ -1,50 +1,395 @@
10 -/** copied from develop.kde.org */
11 -(function($){'use strict';$(function(){$('[data-toggle="tooltip"]').tooltip();$('[data-toggle="popover"]').popover();$('.popover-dismiss').popover({trigger:'focus'})});function bottomPos(element){return element.offset().top+element.outerHeight();}
12 -$(function(){var promo=$(".js-td-cover");if(!promo.length){return}
13 -var promoOffset=bottomPos(promo);var navbarOffset=$('.js-navbar-scroll').offset().top;var threshold=Math.ceil($('.js-navbar-scroll').outerHeight());if((promoOffset-navbarOffset)<threshold){$('.js-navbar-scroll').addClass('navbar-bg-onscroll');}
14 -$(window).on('scroll',function(){var navtop=$('.js-navbar-scroll').offset().top-$(window).scrollTop();var promoOffset=bottomPos($('.js-td-cover'));var navbarOffset=$('.js-navbar-scroll').offset().top;if((promoOffset-navbarOffset)<threshold){$('.js-navbar-scroll').addClass('navbar-bg-onscroll');}else{$('.js-navbar-scroll').removeClass('navbar-bg-onscroll');$('.js-navbar-scroll').addClass('navbar-bg-onscroll--fade');}});});}(jQuery));function getOffsetSum(elem){var top=0,left=0
15 -while(elem){top=top+parseInt(elem.offsetTop)
16 -left=left+parseInt(elem.offsetLeft)
17 -elem=elem.offsetParent}
18 -return{top:top,left:left}}
19 -function setActiveMenuItem(li){var isMenuItem=li.matches('#TableOfContents > ul > li')
20 -var isSubMenuItem=li.matches('#TableOfContents > ul > li > ul > li')
21 -var wasActive=li.classList.contains('active')
22 -if(isMenuItem||!wasActive){var menuItem=document.querySelector('#TableOfContents > ul > li.active')
23 -if(menuItem){menuItem.classList.remove('active')}
24 -var menuItem=document.querySelector('#TableOfContents > ul > li > ul > li.active')
25 -if(menuItem){menuItem.classList.remove('active')}}
26 -li.classList.add('active')
27 -if(isMenuItem){var firstSubMenuItem=li.querySelector('ul > li')
28 -if(firstSubMenuItem){firstSubMenuItem.classList.add('active')}}else if(isSubMenuItem){var menuItem=li.parentNode.parentNode
29 -menuItem.classList.add('active')}}
30 -function getMenuItemElement(li){var id=li.querySelector('a').href.split('#',2)[1]
31 -return document.getElementById(id)}
32 -function updateTOC(){var viewTop=window.scrollY
33 -var tocList=document.querySelectorAll('#TableOfContents li')
34 -for(var i=0;i<tocList.length;i++){var curMenuItem=tocList[i]
35 -var curElement=getMenuItemElement(curMenuItem)
36 -var offset=getOffsetSum(curElement)
37 -var offsetDiff=viewTop-offset.top
38 -if(offsetDiff<0){if(i<=1){setActiveMenuItem(curMenuItem)}else{var prevMenuItem=tocList[i-1]
39 -var prevElement=getMenuItemElement(prevMenuItem)
40 -var prevOffset=getOffsetSum(prevElement)
41 -var prevOffsetDiff=viewTop-prevOffset.top
42 -var sectionReadRatio=(prevOffsetDiff)/prevMenuItem.offsetHeight
43 -if(sectionReadRatio>=0.7){setActiveMenuItem(curMenuItem)}else{setActiveMenuItem(prevMenuItem)}}
44 -break}else if(i==tocList.length-1){setActiveMenuItem(curMenuItem)}}}
45 -var updating=false
46 -function queueUpdateTOC(){if(!updating){updating=true
47 -requestAnimationFrame(function(){updateTOC()
48 -updating=false})}}
49 +// Imported from https://invent.kde.org/documentation/develop-kde-org/-/blob/cafdb9dfe7b37b8060e6a4fcc0709bcc80a42d15/assets/js/base.js
50 +/*
51 + * Copyright 2018 Google LLC
52 +
53 +Licensed under the Apache License, Version 2.0 (the "License");
54 +you may not use this file except in compliance with the License.
55 +You may obtain a copy of the License at
56 +
57 + https://www.apache.org/licenses/LICENSE-2.0
58 +
59 +Unless required by applicable law or agreed to in writing, software
60 +distributed under the License is distributed on an "AS IS" BASIS,
61 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62 +See the License for the specific language governing permissions and
63 +limitations under the License.
64 +*/
65 +
66 +(function($) {
67 +
68 + 'use strict';
69 +
70 + $(function() {
71 + $('[data-toggle="tooltip"]').tooltip();
72 + $('[data-toggle="popover"]').popover();
73 +
74 + $('.popover-dismiss').popover({
75 + trigger: 'focus'
76 + })
77 + });
78 +
79 +
80 + function bottomPos(element) {
81 + return element.offset().top + element.outerHeight();
82 + }
83 +
84 + // Bootstrap Fixed Header
85 + $(function() {
86 + var promo = $(".js-td-cover");
87 + if (!promo.length) {
88 + return
89 + }
90 +
91 + var promoOffset = bottomPos(promo);
92 + var navbarOffset = $('.js-navbar-scroll').offset().top;
93 +
94 + var threshold = Math.ceil($('.js-navbar-scroll').outerHeight());
95 + if ((promoOffset - navbarOffset) < threshold) {
96 + $('.js-navbar-scroll').addClass('navbar-bg-onscroll');
97 + }
98 +
99 +
100 + $(window).on('scroll', function() {
101 + var navtop = $('.js-navbar-scroll').offset().top - $(window).scrollTop();
102 + var promoOffset = bottomPos($('.js-td-cover'));
103 + var navbarOffset = $('.js-navbar-scroll').offset().top;
104 + if ((promoOffset - navbarOffset) < threshold) {
105 + $('.js-navbar-scroll').addClass('navbar-bg-onscroll');
106 + } else {
107 + $('.js-navbar-scroll').removeClass('navbar-bg-onscroll');
108 + $('.js-navbar-scroll').addClass('navbar-bg-onscroll--fade');
109 + }
110 + });
111 + });
112 +
113 +
114 +}(jQuery));
115 +
116 +function getOffsetSum(elem) {
117 + var top=0, left=0
118 + while (elem) {
119 + top = top + parseInt(elem.offsetTop)
120 + left = left + parseInt(elem.offsetLeft)
121 + elem = elem.offsetParent
122 + }
123 + return { top: top, left: left }
124 +}
125 +
126 +function setActiveMenuItem(li) {
127 + var isMenuItem = li.matches('#TableOfContents > ul > li')
128 + var isSubMenuItem = li.matches('#TableOfContents > ul > li > ul > li')
129 + var wasActive = li.classList.contains('active')
130 +
131 + if (isMenuItem || !wasActive) {
132 + // Unset current active item
133 + var menuItem = document.querySelector('#TableOfContents > ul > li.active')
134 + if (menuItem) {
135 + menuItem.classList.remove('active')
136 + }
137 + var menuItem = document.querySelector('#TableOfContents > ul > li > ul > li.active')
138 + if (menuItem) {
139 + menuItem.classList.remove('active')
140 + }
141 + }
142 + li.classList.add('active')
143 +
144 + if (isMenuItem) {
145 + var firstSubMenuItem = li.querySelector('ul > li')
146 + if (firstSubMenuItem) {
147 + firstSubMenuItem.classList.add('active')
148 + }
149 + } else if (isSubMenuItem) {
150 + var menuItem = li.parentNode.parentNode // TODO: parentUntil('li')
151 + menuItem.classList.add('active')
152 + }
153 +
154 + // Scroll to item
155 + // li.scrollIntoView()
156 +}
157 +function getMenuItemElement(li) {
158 + var id = li.querySelector('a').href.split('#', 2)[1]
159 + return document.getElementById(id)
160 +}
161 +function updateTOC() {
162 + var viewTop = window.scrollY
163 + var tocList = document.querySelectorAll('#TableOfContents li')
164 + // Binary Search maybe (since elements are in order)?
165 + for (var i = 0; i < tocList.length; i++) {
166 + var curMenuItem = tocList[i]
167 + var curElement = getMenuItemElement(curMenuItem)
168 + var offset = getOffsetSum(curElement)
169 + var offsetDiff = viewTop - offset.top
170 + if (offsetDiff < 0) {
171 + if (i <= 1) {
172 + // At top, select the first item
173 + setActiveMenuItem(curMenuItem)
174 + } else {
175 + var prevMenuItem = tocList[i - 1]
176 + var prevElement = getMenuItemElement(prevMenuItem)
177 + var prevOffset = getOffsetSum(prevElement)
178 + var prevOffsetDiff = viewTop - prevOffset.top
179 + var sectionReadRatio = (prevOffsetDiff)/prevMenuItem.offsetHeight
180 + if (sectionReadRatio >= 0.7) {
181 + // Current item is being read
182 + setActiveMenuItem(curMenuItem)
183 + } else {
184 + // Previous item is still being read
185 + setActiveMenuItem(prevMenuItem)
186 + }
187 + }
188 + break
189 + } else if (i == tocList.length - 1) {
190 + // At bottom, select last item
191 + setActiveMenuItem(curMenuItem)
192 + }
193 + }
194 +}
195 +
196 +var updating = false
197 +function queueUpdateTOC() {
198 + if (!updating) {
199 + updating = true
200 + requestAnimationFrame(function() {
201 + updateTOC()
202 + updating = false
203 + })
204 + }
205 +}
206 +
207 queueUpdateTOC()
208 -window.addEventListener('scroll',queueUpdateTOC);(function($){'use strict';$(function(){var article=document.getElementsByTagName('main')[0];if(!article){return;}
209 -var headings=article.querySelectorAll('h1, h2, h3, h4, h5, h6');headings.forEach(function(heading){if(heading.id){var a=document.createElement('a');a.style.visibility='hidden';a.setAttribute('aria-hidden','true');a.innerHTML=' <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>';a.href='#'+heading.id;heading.insertAdjacentElement('beforeend',a);heading.addEventListener('mouseenter',function(){a.style.visibility='initial';});heading.addEventListener('mouseleave',function(){a.style.visibility='hidden';});}});});}(jQuery));;(function($){'use strict';$(document).ready(function(){const $searchInput=$('.td-search-input');$searchInput.data('html',true);$searchInput.data('placement','bottom');$searchInput.data('template','<div class="popover offline-search-result" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>');$searchInput.on('change',(event)=>{render($(event.target));$searchInput.blur();});$searchInput.closest('form').on('submit',()=>{return false;});let idx=null;const resultDetails=new Map();$.ajax($searchInput.data('offline-search-index-json-src')).then((data)=>{idx=lunr(function(){this.ref('ref');this.field('title',{boost:2});this.field('body');data.forEach((doc)=>{this.add(doc);resultDetails.set(doc.ref,{title:doc.title,excerpt:doc.excerpt,});});});$searchInput.trigger('change');});const render=($targetSearchInput)=>{$targetSearchInput.popover('dispose');if(idx===null){return;}
210 -const searchQuery=$targetSearchInput.val();if(searchQuery===''){return;}
211 -const results=idx.query((q)=>{const tokens=lunr.tokenizer(searchQuery.toLowerCase());tokens.forEach((token)=>{const queryString=token.toString();q.term(queryString,{boost:100,});q.term(queryString,{wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING,boost:10,});q.term(queryString,{editDistance:2,});});}).slice(0,10);const $html=$('<div>');$html.append($('<div>').css({display:'flex',justifyContent:'space-between',marginBottom:'1em',}).append($('<span>').text('Search results').css({fontWeight:'bold'})).append($('<i>').addClass('fas fa-times search-result-close-button').css({cursor:'pointer',})));const $searchResultBody=$('<div>').css({maxHeight:`calc(100vh - ${
212 -$targetSearchInput.offset().top-
213 -$(window).scrollTop()+
214 -180
215 -}px)`,overflowY:'auto',});$html.append($searchResultBody);if(results.length===0){$searchResultBody.append($('<p>').text(`No results found for query "${searchQuery}"`));}else{results.forEach((r)=>{const $cardHeader=$('<div>').addClass('card-header');const doc=resultDetails.get(r.ref);const href=$searchInput.data('offline-search-base-href')+
216 -r.ref.replace(/^\//,'');$cardHeader.append($('<a>').attr('href',href).text(doc.title));const $cardBody=$('<div>').addClass('card-body');$cardBody.append($('<p>').addClass('card-text text-muted').text(doc.excerpt));const $card=$('<div>').addClass('card');$card.append($cardHeader).append($cardBody);$searchResultBody.append($card);});}
217 -$targetSearchInput.on('shown.bs.popover',()=>{$('.search-result-close-button').on('click',()=>{$targetSearchInput.val('');$targetSearchInput.trigger('change');});});$targetSearchInput.data('content',$html[0].outerHTML).popover('show');};});})(jQuery);
218 +window.addEventListener('scroll', queueUpdateTOC)
219 +
220 +// Imported from https://invent.kde.org/documentation/develop-kde-org/-/blob/cafdb9dfe7b37b8060e6a4fcc0709bcc80a42d15/assets/js/anchor.js
221 +/*
222 + * Copyright 2018 Google LLC
223 +
224 +Licensed under the Apache License, Version 2.0 (the "License");
225 +you may not use this file except in compliance with the License.
226 +You may obtain a copy of the License at
227 +
228 + https://www.apache.org/licenses/LICENSE-2.0
229 +
230 +Unless required by applicable law or agreed to in writing, software
231 +distributed under the License is distributed on an "AS IS" BASIS,
232 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
233 +See the License for the specific language governing permissions and
234 +limitations under the License.
235 +*/
236 +
237 +(function ($) {
238 + 'use strict';
239 +
240 + // Headers' anchor link that shows on hover
241 + $(function () {
242 + // append anchor links to headings in markdown.
243 + var article = document.getElementsByTagName('main')[0];
244 + if (!article) {
245 + return;
246 + }
247 + var headings = article.querySelectorAll('h1, h2, h3, h4, h5, h6');
248 + headings.forEach(function (heading) {
249 + if (heading.id) {
250 + var a = document.createElement('a');
251 + // set visibility: hidden, not display: none to avoid layout change
252 + a.style.visibility = 'hidden';
253 + // [a11y] hide this from screen readers, etc..
254 + a.setAttribute('aria-hidden', 'true');
255 + // material insert_link icon in svg format
256 + a.innerHTML = ' <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>';
257 + a.href = '#' + heading.id;
258 + heading.insertAdjacentElement('beforeend', a);
259 + heading.addEventListener('mouseenter', function () {
260 + a.style.visibility = 'initial';
261 + });
262 + heading.addEventListener('mouseleave', function () {
263 + a.style.visibility = 'hidden';
264 + });
265 + }
266 + });
267 + });
268 +
269 +}(jQuery));
270 +
271 +// Imported from https://invent.kde.org/documentation/develop-kde-org/-/blob/cafdb9dfe7b37b8060e6a4fcc0709bcc80a42d15/assets/js/offline-search.js
272 +// Adapted from code by Matt Walters https://www.mattwalters.net/posts/hugo-and-lunr/
273 +
274 +(function ($) {
275 + 'use strict';
276 +
277 + $(document).ready(function () {
278 + const $searchInput = $('.td-search-input');
279 +
280 + //
281 + // Options for popover
282 + //
283 +
284 + $searchInput.data('html', true);
285 + $searchInput.data('placement', 'bottom');
286 + $searchInput.data(
287 + 'template',
288 + '<div class="popover offline-search-result" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
289 + );
290 +
291 + //
292 + // Register handler
293 + //
294 +
295 + $searchInput.on('change', (event) => {
296 + render($(event.target));
297 +
298 + // Hide keyboard on mobile browser
299 + $searchInput.blur();
300 + });
301 +
302 + // Prevent reloading page by enter key on sidebar search.
303 + $searchInput.closest('form').on('submit', () => {
304 + return false;
305 + });
306 +
307 + //
308 + // Lunr
309 + //
310 +
311 + let idx = null; // Lunr index
312 + const resultDetails = new Map(); // Will hold the data for the search results (titles and summaries)
313 +
314 + // Set up for an Ajax call to request the JSON data file that is created by Hugo's build process
315 + $.ajax($searchInput.data('offline-search-index-json-src')).then(
316 + (data) => {
317 + idx = lunr(function () {
318 + this.ref('ref');
319 + this.field('title', { boost: 2 });
320 + this.field('body');
321 +
322 + data.forEach((doc) => {
323 + this.add(doc);
324 +
325 + resultDetails.set(doc.ref, {
326 + title: doc.title,
327 + excerpt: doc.excerpt,
328 + });
329 + });
330 + });
331 +
332 + $searchInput.trigger('change');
333 + }
334 + );
335 +
336 + const render = ($targetSearchInput) => {
337 + // Dispose the previous result
338 + $targetSearchInput.popover('dispose');
339 +
340 + //
341 + // Search
342 + //
343 +
344 + if (idx === null) {
345 + return;
346 + }
347 +
348 + const searchQuery = $targetSearchInput.val();
349 + if (searchQuery === '') {
350 + return;
351 + }
352 +
353 + const results = idx
354 + .query((q) => {
355 + const tokens = lunr.tokenizer(searchQuery.toLowerCase());
356 + tokens.forEach((token) => {
357 + const queryString = token.toString();
358 + q.term(queryString, {
359 + boost: 100,
360 + });
361 + q.term(queryString, {
362 + wildcard:
363 + lunr.Query.wildcard.LEADING |
364 + lunr.Query.wildcard.TRAILING,
365 + boost: 10,
366 + });
367 + q.term(queryString, {
368 + editDistance: 2,
369 + });
370 + });
371 + })
372 + .slice(0, 10);
373 +
374 + //
375 + // Make result html
376 + //
377 +
378 + const $html = $('<div>');
379 +
380 + $html.append(
381 + $('<div>')
382 + .css({
383 + display: 'flex',
384 + justifyContent: 'space-between',
385 + marginBottom: '1em',
386 + })
387 + .append(
388 + $('<span>')
389 + .text('Search results')
390 + .css({ fontWeight: 'bold' })
391 + )
392 + .append(
393 + $('<i>')
394 + .addClass('fas fa-times search-result-close-button')
395 + .css({
396 + cursor: 'pointer',
397 + })
398 + )
399 + );
400 +
401 + const $searchResultBody = $('<div>').css({
402 + maxHeight: `calc(100vh - ${
403 + $targetSearchInput.offset().top -
404 + $(window).scrollTop() +
405 + 180
406 + }px)`,
407 + overflowY: 'auto',
408 + });
409 + $html.append($searchResultBody);
410 +
411 + if (results.length === 0) {
412 + $searchResultBody.append(
413 + $('<p>').text(`No results found for query "${searchQuery}"`)
414 + );
415 + } else {
416 + results.forEach((r) => {
417 + const $cardHeader = $('<div>').addClass('card-header');
418 + const doc = resultDetails.get(r.ref);
419 + const href =
420 + $searchInput.data('offline-search-base-href') +
421 + r.ref.replace(/^\//, '');
422 +
423 + $cardHeader.append(
424 + $('<a>').attr('href', href).text(doc.title)
425 + );
426 +
427 + const $cardBody = $('<div>').addClass('card-body');
428 + $cardBody.append(
429 + $('<p>')
430 + .addClass('card-text text-muted')
431 + .text(doc.excerpt)
432 + );
433 +
434 + const $card = $('<div>').addClass('card');
435 + $card.append($cardHeader).append($cardBody);
436 +
437 + $searchResultBody.append($card);
438 + });
439 + }
440 +
441 + $targetSearchInput.on('shown.bs.popover', () => {
442 + $('.search-result-close-button').on('click', () => {
443 + $targetSearchInput.val('');
444 + $targetSearchInput.trigger('change');
445 + });
446 + });
447 +
448 + $targetSearchInput
449 + .data('content', $html[0].outerHTML)
450 + .popover('show');
451 + };
452 + });
453 +})(jQuery);