Fossil SCM
pixchr layout changes requested at [https://pikchr.org/home/forumpost/504f54f61b]. See the comments about alt/ctrl/meta keys.
Commit
cd22f0f07d452bcc542bc949eb5f28f1f65ec4caf690758b7e570672ac6ca5e0
Parent
82a0b517a78e44c…
2 files changed
+16
-11
+4
-1
+16
-11
| --- src/fossil.pikchr.js | ||
| +++ src/fossil.pikchr.js | ||
| @@ -36,26 +36,29 @@ | ||
| 36 | 36 | already dealt with. |
| 37 | 37 | |
| 38 | 38 | This code expects the following structure around the SVGs, and |
| 39 | 39 | will not process any which don't match this: |
| 40 | 40 | |
| 41 | - <DIV><SVG.pikchr></SVG><PRE.pikchr-src></PRE></DIV> | |
| 41 | + <DIV> | |
| 42 | + <DIV><SVG.pikchr></SVG></DIV> | |
| 43 | + <PRE.pikchr-src></PRE> | |
| 44 | + </DIV> | |
| 42 | 45 | */ |
| 43 | 46 | P.addSrcView = function f(svg){ |
| 44 | 47 | if(!f.hasOwnProperty('parentClick')){ |
| 45 | 48 | f.parentClick = function(ev){ |
| 46 | - if(ev.ctrlKey || this.classList.contains('toggle')){ | |
| 49 | + if(ev.altKey || ev.metaKey || ev.ctrlKey | |
| 50 | + /* Every combination of special key (alt, shift, ctrl, | |
| 51 | + meta) is handled differently everywhere. Shift is used | |
| 52 | + by the browser, Ctrl doesn't work on an iMac, and Alt is | |
| 53 | + intercepted by most Linux window managers to control | |
| 54 | + window movement! So... we just listen for *any* of them | |
| 55 | + (except Shift) and the user will need to find one which | |
| 56 | + works on on their environment. */ | |
| 57 | + || this.classList.contains('toggle')){ | |
| 47 | 58 | this._childs.forEach((e)=>e.classList.toggle('hidden')); |
| 48 | 59 | } |
| 49 | - /* For the sake of small pics, we have to eliminate the | |
| 50 | - parent element's max-width... */ | |
| 51 | - const src = this._childs[1]; | |
| 52 | - if(src.classList.contains('hidden')){ | |
| 53 | - this.style.maxWidth = this.dataset.origMaxWidth; | |
| 54 | - }else{ | |
| 55 | - this.style.maxWidth = "unset"; | |
| 56 | - } | |
| 57 | 60 | }; |
| 58 | 61 | }; |
| 59 | 62 | if(!svg) svg = 'svg.pikchr'; |
| 60 | 63 | if('string' === typeof svg){ |
| 61 | 64 | document.querySelectorAll(svg).forEach((e)=>f.call(this, e)); |
| @@ -67,21 +70,23 @@ | ||
| 67 | 70 | if(svg.dataset.pikchrProcessed){ |
| 68 | 71 | return this; |
| 69 | 72 | } |
| 70 | 73 | svg.dataset.pikchrProcessed = 1; |
| 71 | 74 | const parent = svg.parentNode; |
| 72 | - const srcView = svg.nextElementSibling; | |
| 75 | + const srcView = parent.nextElementSibling; | |
| 73 | 76 | if(!srcView || !srcView.classList.contains('pikchr-src')){ |
| 74 | 77 | /* Without this element, there's nothing for us to do here. */ |
| 75 | 78 | return this; |
| 76 | 79 | } |
| 77 | 80 | parent.dataset.origMaxWidth = parent.style.maxWidth; |
| 78 | 81 | parent._childs = [svg, srcView]; |
| 79 | 82 | D.addClass(srcView, 'hidden'); |
| 80 | 83 | D.removeClass(svg, 'hidden'); |
| 81 | 84 | parent.addEventListener('click', f.parentClick, false); |
| 85 | + /* When the parent is hidden, it has 0 height so cannot be clicked, so... */ | |
| 86 | + srcView.addEventListener('click', (ev)=>f.parentClick.call(parent, ev), false); | |
| 82 | 87 | if(parent.classList.contains('source')){ |
| 83 | 88 | /* Start off in source-view mode via a very fake click event */ |
| 84 | 89 | f.parentClick.call(parent, {ctrlKey:true}); |
| 85 | 90 | } |
| 86 | 91 | }; |
| 87 | 92 | })(window.fossil); |
| 88 | 93 |
| --- src/fossil.pikchr.js | |
| +++ src/fossil.pikchr.js | |
| @@ -36,26 +36,29 @@ | |
| 36 | already dealt with. |
| 37 | |
| 38 | This code expects the following structure around the SVGs, and |
| 39 | will not process any which don't match this: |
| 40 | |
| 41 | <DIV><SVG.pikchr></SVG><PRE.pikchr-src></PRE></DIV> |
| 42 | */ |
| 43 | P.addSrcView = function f(svg){ |
| 44 | if(!f.hasOwnProperty('parentClick')){ |
| 45 | f.parentClick = function(ev){ |
| 46 | if(ev.ctrlKey || this.classList.contains('toggle')){ |
| 47 | this._childs.forEach((e)=>e.classList.toggle('hidden')); |
| 48 | } |
| 49 | /* For the sake of small pics, we have to eliminate the |
| 50 | parent element's max-width... */ |
| 51 | const src = this._childs[1]; |
| 52 | if(src.classList.contains('hidden')){ |
| 53 | this.style.maxWidth = this.dataset.origMaxWidth; |
| 54 | }else{ |
| 55 | this.style.maxWidth = "unset"; |
| 56 | } |
| 57 | }; |
| 58 | }; |
| 59 | if(!svg) svg = 'svg.pikchr'; |
| 60 | if('string' === typeof svg){ |
| 61 | document.querySelectorAll(svg).forEach((e)=>f.call(this, e)); |
| @@ -67,21 +70,23 @@ | |
| 67 | if(svg.dataset.pikchrProcessed){ |
| 68 | return this; |
| 69 | } |
| 70 | svg.dataset.pikchrProcessed = 1; |
| 71 | const parent = svg.parentNode; |
| 72 | const srcView = svg.nextElementSibling; |
| 73 | if(!srcView || !srcView.classList.contains('pikchr-src')){ |
| 74 | /* Without this element, there's nothing for us to do here. */ |
| 75 | return this; |
| 76 | } |
| 77 | parent.dataset.origMaxWidth = parent.style.maxWidth; |
| 78 | parent._childs = [svg, srcView]; |
| 79 | D.addClass(srcView, 'hidden'); |
| 80 | D.removeClass(svg, 'hidden'); |
| 81 | parent.addEventListener('click', f.parentClick, false); |
| 82 | if(parent.classList.contains('source')){ |
| 83 | /* Start off in source-view mode via a very fake click event */ |
| 84 | f.parentClick.call(parent, {ctrlKey:true}); |
| 85 | } |
| 86 | }; |
| 87 | })(window.fossil); |
| 88 |
| --- src/fossil.pikchr.js | |
| +++ src/fossil.pikchr.js | |
| @@ -36,26 +36,29 @@ | |
| 36 | already dealt with. |
| 37 | |
| 38 | This code expects the following structure around the SVGs, and |
| 39 | will not process any which don't match this: |
| 40 | |
| 41 | <DIV> |
| 42 | <DIV><SVG.pikchr></SVG></DIV> |
| 43 | <PRE.pikchr-src></PRE> |
| 44 | </DIV> |
| 45 | */ |
| 46 | P.addSrcView = function f(svg){ |
| 47 | if(!f.hasOwnProperty('parentClick')){ |
| 48 | f.parentClick = function(ev){ |
| 49 | if(ev.altKey || ev.metaKey || ev.ctrlKey |
| 50 | /* Every combination of special key (alt, shift, ctrl, |
| 51 | meta) is handled differently everywhere. Shift is used |
| 52 | by the browser, Ctrl doesn't work on an iMac, and Alt is |
| 53 | intercepted by most Linux window managers to control |
| 54 | window movement! So... we just listen for *any* of them |
| 55 | (except Shift) and the user will need to find one which |
| 56 | works on on their environment. */ |
| 57 | || this.classList.contains('toggle')){ |
| 58 | this._childs.forEach((e)=>e.classList.toggle('hidden')); |
| 59 | } |
| 60 | }; |
| 61 | }; |
| 62 | if(!svg) svg = 'svg.pikchr'; |
| 63 | if('string' === typeof svg){ |
| 64 | document.querySelectorAll(svg).forEach((e)=>f.call(this, e)); |
| @@ -67,21 +70,23 @@ | |
| 70 | if(svg.dataset.pikchrProcessed){ |
| 71 | return this; |
| 72 | } |
| 73 | svg.dataset.pikchrProcessed = 1; |
| 74 | const parent = svg.parentNode; |
| 75 | const srcView = parent.nextElementSibling; |
| 76 | if(!srcView || !srcView.classList.contains('pikchr-src')){ |
| 77 | /* Without this element, there's nothing for us to do here. */ |
| 78 | return this; |
| 79 | } |
| 80 | parent.dataset.origMaxWidth = parent.style.maxWidth; |
| 81 | parent._childs = [svg, srcView]; |
| 82 | D.addClass(srcView, 'hidden'); |
| 83 | D.removeClass(svg, 'hidden'); |
| 84 | parent.addEventListener('click', f.parentClick, false); |
| 85 | /* When the parent is hidden, it has 0 height so cannot be clicked, so... */ |
| 86 | srcView.addEventListener('click', (ev)=>f.parentClick.call(parent, ev), false); |
| 87 | if(parent.classList.contains('source')){ |
| 88 | /* Start off in source-view mode via a very fake click event */ |
| 89 | f.parentClick.call(parent, {ctrlKey:true}); |
| 90 | } |
| 91 | }; |
| 92 | })(window.fossil); |
| 93 |
+4
-1
| --- src/pikchrshow.c | ||
| +++ src/pikchrshow.c | ||
| @@ -178,17 +178,20 @@ | ||
| 178 | 178 | zClassToggle = " toggle"; |
| 179 | 179 | } |
| 180 | 180 | if(PIKCHR_PROCESS_DIV_SOURCE & pikFlags){ |
| 181 | 181 | zClassSource = " source"; |
| 182 | 182 | } |
| 183 | - blob_appendf(pOut,"<div class=\"pikchr-svg%s%s\" " | |
| 183 | + blob_appendf(pOut,"<div><div class=\"pikchr-svg%s%s\" " | |
| 184 | 184 | "style=\"%b\">\n", |
| 185 | 185 | zClassToggle/*safe-for-%s*/, |
| 186 | 186 | zClassSource/*safe-for-%s*/, &css); |
| 187 | 187 | blob_reset(&css); |
| 188 | 188 | } |
| 189 | 189 | blob_append(pOut, zOut, -1); |
| 190 | + if(PIKCHR_PROCESS_DIV & pikFlags){ | |
| 191 | + blob_append(pOut, "</div>\n", 7); | |
| 192 | + } | |
| 190 | 193 | if((PIKCHR_PROCESS_SRC & pikFlags) |
| 191 | 194 | || (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags)){ |
| 192 | 195 | blob_appendf(pOut, "<pre class='pikchr-src%s'>" |
| 193 | 196 | "%h</pre>\n", |
| 194 | 197 | (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags) |
| 195 | 198 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -178,17 +178,20 @@ | |
| 178 | zClassToggle = " toggle"; |
| 179 | } |
| 180 | if(PIKCHR_PROCESS_DIV_SOURCE & pikFlags){ |
| 181 | zClassSource = " source"; |
| 182 | } |
| 183 | blob_appendf(pOut,"<div class=\"pikchr-svg%s%s\" " |
| 184 | "style=\"%b\">\n", |
| 185 | zClassToggle/*safe-for-%s*/, |
| 186 | zClassSource/*safe-for-%s*/, &css); |
| 187 | blob_reset(&css); |
| 188 | } |
| 189 | blob_append(pOut, zOut, -1); |
| 190 | if((PIKCHR_PROCESS_SRC & pikFlags) |
| 191 | || (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags)){ |
| 192 | blob_appendf(pOut, "<pre class='pikchr-src%s'>" |
| 193 | "%h</pre>\n", |
| 194 | (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags) |
| 195 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -178,17 +178,20 @@ | |
| 178 | zClassToggle = " toggle"; |
| 179 | } |
| 180 | if(PIKCHR_PROCESS_DIV_SOURCE & pikFlags){ |
| 181 | zClassSource = " source"; |
| 182 | } |
| 183 | blob_appendf(pOut,"<div><div class=\"pikchr-svg%s%s\" " |
| 184 | "style=\"%b\">\n", |
| 185 | zClassToggle/*safe-for-%s*/, |
| 186 | zClassSource/*safe-for-%s*/, &css); |
| 187 | blob_reset(&css); |
| 188 | } |
| 189 | blob_append(pOut, zOut, -1); |
| 190 | if(PIKCHR_PROCESS_DIV & pikFlags){ |
| 191 | blob_append(pOut, "</div>\n", 7); |
| 192 | } |
| 193 | if((PIKCHR_PROCESS_SRC & pikFlags) |
| 194 | || (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags)){ |
| 195 | blob_appendf(pOut, "<pre class='pikchr-src%s'>" |
| 196 | "%h</pre>\n", |
| 197 | (PIKCHR_PROCESS_SRC_HIDDEN & pikFlags) |
| 198 |