diff --git a/ChangeLog.md b/ChangeLog.md index 0a73065..d5bea0c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Change Log +## [0.1.4] - 2024-11-21 + +- Image wrapping anchor requires to get its `href` attribute updated when switching color schemes. Add test case. Update docs. + ## [0.1.3] - 2024-11-21 - Fix: Image node URI must be relative to path given in the document instead of path calculated by ``get_image_paths``. diff --git a/dist/js/sphinx-colorschemed-images.esm.js b/dist/js/sphinx-colorschemed-images.esm.js index 8123e5f..ee798ea 100644 --- a/dist/js/sphinx-colorschemed-images.esm.js +++ b/dist/js/sphinx-colorschemed-images.esm.js @@ -57,13 +57,16 @@ var SphinxColorschemeImageHandler = function SphinxColorschemeImageHandler(optio } // Check whether the image is inside a
. - debugger; var figure = img.closest('figure'); if (figure != undefined) { var anchor = figure.querySelector('a'); if (anchor.getAttribute('href') !== new_src) { anchor.href = new_src; } + } else if (img.parentElement.tagName == "A" && img.parentElement.getAttribute("href") !== new_src) { + var parent = img.parentElement; + parent.href = img.getAttribute(data_att); + console.log("the new anchor's href:", parent.href); } }; for (var _iterator = _createForOfIteratorHelperLoose(images), _step; !(_step = _iterator()).done;) { diff --git a/dist/js/sphinx-colorschemed-images.esm.js.map b/dist/js/sphinx-colorschemed-images.esm.js.map index 311ed0e..cd4d7ee 100644 --- a/dist/js/sphinx-colorschemed-images.esm.js.map +++ b/dist/js/sphinx-colorschemed-images.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"sphinx-colorschemed-images.esm.js","sources":["../../js/src/main.js"],"sourcesContent":["export class SphinxColorschemeImageHandler {\n constructor(options={}) {\n this._schemes = [];\n this._mediaqs = [];\n\n // If options are not given or if it is given with a key 'auto'\n // and a boolean value true, then the instance created will add\n // an event listener for changes on prefers-color-scheme to\n // update images accordingly.\n this._auto = options.hasOwnProperty('auto')\n ? options['auto'] === true\n : true;\n\n const meta_prop = document.querySelector('meta[name=\"color-scheme\"]');\n let meta_schemes = (meta_prop == undefined) ? \"\" : meta_prop.content;\n\n if (meta_schemes.length > 0) {\n const schemes = meta_schemes.split(\" \");\n for (const item of schemes) {\n this._schemes.push(item.trim());\n }\n } else {\n this._schemes = ['light', 'dark'];\n }\n\n for (const scheme of this._schemes) {\n const q = globalThis.matchMedia(`(prefers-color-scheme: ${scheme})`);\n if (q.matches) {\n this.activate(scheme);\n }\n if (this._auto === true) {\n q.addEventListener('change', e => {\n if (e.matches) {\n this.activate(scheme);\n }\n });\n this._mediaqs.push(q);\n }\n }\n }\n\n activate = (scheme) => {\n const data_att = `data-alt-src-color-scheme-${scheme}`;\n const images = document.querySelectorAll(`img[${data_att}]`);\n for (const img of images) {\n const new_img = new Image();\n const new_src = img.getAttribute(data_att);\n new_img.src = new_src;\n new_img.addEventListener('load', () => {\n img.src = new_img.src;\n });\n new_img.addEventListener('error', () => {\n console.error(`Could not replace image ${img.src} with ${new_src}.`);\n });\n if (new_img.complete) {\n img.src = new_img.src;\n }\n\n // Check whether the image is inside a
.\n debugger;\n const figure = img.closest('figure');\n if (figure != undefined) {\n const anchor = figure.querySelector('a');\n if (anchor.getAttribute('href') !== new_src) {\n anchor.href = new_src;\n }\n }\n }\n }\n}\n"],"names":["SphinxColorschemeImageHandler","options","_this","activate","scheme","data_att","images","document","querySelectorAll","_loop","img","_step","value","new_img","Image","new_src","getAttribute","src","addEventListener","console","error","complete","figure","closest","undefined","anchor","querySelector","href","_iterator","_createForOfIteratorHelperLoose","done","_schemes","_mediaqs","_auto","hasOwnProperty","meta_prop","meta_schemes","content","length","schemes","split","_iterator2","_step2","item","push","trim","_loop2","_step3","q","globalThis","matchMedia","matches","e","_iterator3"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAaA,6BAA6B,GACxC,SAAAA,6BAAAA,CAAYC,OAAO,EAAK;AAAA,EAAA,IAAAC,KAAA,GAAA,IAAA;AAAA,EAAA,IAAZD,OAAO,KAAA,KAAA,CAAA,EAAA;IAAPA,OAAO,GAAC,EAAE;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C,CAACG,OAAO,EAAE;AACbjD,MAAAA,KAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;AACvB;AACA,IAAA,IAAIF,KAAI,CAAC+B,KAAK,KAAK,IAAI,EAAE;AACvBe,MAAAA,CAAC,CAAC9B,gBAAgB,CAAC,QAAQ,EAAE,UAAAkC,CAAC,EAAI;QAChC,IAAIA,CAAC,CAACD,OAAO,EAAE;AACbjD,UAAAA,KAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;AACvB;AACF,OAAC,CAAC;AACFF,MAAAA,KAAI,CAAC8B,QAAQ,CAACY,IAAI,CAACI,CAAC,CAAC;AACvB;GACD;AAbD,EAAA,KAAA,IAAAK,UAAA,GAAAxB,+BAAA,CAAqB,IAAI,CAACE,QAAQ,CAAAgB,EAAAA,MAAA,EAAAA,CAAAA,CAAAA,MAAA,GAAAM,UAAA,IAAAvB,IAAA,GAAA;IAAAgB,MAAA,EAAA;AAAA;AAcpC;;;;"} \ No newline at end of file +{"version":3,"file":"sphinx-colorschemed-images.esm.js","sources":["../../js/src/main.js"],"sourcesContent":["export class SphinxColorschemeImageHandler {\n constructor(options={}) {\n this._schemes = [];\n this._mediaqs = [];\n\n // If options are not given or if it is given with a key 'auto'\n // and a boolean value true, then the instance created will add\n // an event listener for changes on prefers-color-scheme to\n // update images accordingly.\n this._auto = options.hasOwnProperty('auto')\n ? options['auto'] === true\n : true;\n\n const meta_prop = document.querySelector('meta[name=\"color-scheme\"]');\n let meta_schemes = (meta_prop == undefined) ? \"\" : meta_prop.content;\n\n if (meta_schemes.length > 0) {\n const schemes = meta_schemes.split(\" \");\n for (const item of schemes) {\n this._schemes.push(item.trim());\n }\n } else {\n this._schemes = ['light', 'dark'];\n }\n\n for (const scheme of this._schemes) {\n const q = globalThis.matchMedia(`(prefers-color-scheme: ${scheme})`);\n if (q.matches) {\n this.activate(scheme);\n }\n if (this._auto === true) {\n q.addEventListener('change', e => {\n if (e.matches) {\n this.activate(scheme);\n }\n });\n this._mediaqs.push(q);\n }\n }\n }\n\n activate = (scheme) => {\n const data_att = `data-alt-src-color-scheme-${scheme}`;\n const images = document.querySelectorAll(`img[${data_att}]`);\n for (const img of images) {\n const new_img = new Image();\n const new_src = img.getAttribute(data_att);\n new_img.src = new_src;\n new_img.addEventListener('load', () => {\n img.src = new_img.src;\n });\n new_img.addEventListener('error', () => {\n console.error(`Could not replace image ${img.src} with ${new_src}.`);\n });\n if (new_img.complete) {\n img.src = new_img.src;\n }\n\n // Check whether the image is inside a
.\n const figure = img.closest('figure');\n if (figure != undefined) {\n const anchor = figure.querySelector('a');\n if (anchor.getAttribute('href') !== new_src) {\n anchor.href = new_src;\n }\n } else if (\n (img.parentElement.tagName == \"A\")\n && img.parentElement.getAttribute(\"href\") !== new_src\n ) {\n const parent = img.parentElement;\n parent.href = img.getAttribute(data_att);\n console.log(\"the new anchor's href:\", parent.href);\n }\n }\n }\n}\n"],"names":["SphinxColorschemeImageHandler","options","_this","activate","scheme","data_att","images","document","querySelectorAll","_loop","img","_step","value","new_img","Image","new_src","getAttribute","src","addEventListener","console","error","complete","figure","closest","undefined","anchor","querySelector","href","parentElement","tagName","parent","log","_iterator","_createForOfIteratorHelperLoose","done","_schemes","_mediaqs","_auto","hasOwnProperty","meta_prop","meta_schemes","content","length","schemes","split","_iterator2","_step2","item","push","trim","_loop2","_step3","q","globalThis","matchMedia","matches","e","_iterator3"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAaA,6BAA6B,GACxC,SAAAA,6BAAAA,CAAYC,OAAO,EAAK;AAAA,EAAA,IAAAC,KAAA,GAAA,IAAA;AAAA,EAAA,IAAZD,OAAO,KAAA,KAAA,CAAA,EAAA;IAAPA,OAAO,GAAC,EAAE;AAAA;AAAA,EAAA,IAAA,CAwCtBE,QAAQ,GAAG,UAACC,MAAM,EAAK;IACrB,IAAMC,QAAQ,kCAAgCD,MAAQ;IACtD,IAAME,MAAM,GAAGC,QAAQ,CAACC,gBAAgB,CA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AA,GAEmC;AAAA,IAAA,IAAzB9C,MAAM,GAAA+C,MAAA,CAAAvC,KAAA;IACf,IAAMwC,CAAC,GAAGC,UAAU,CAACC,UAAU,CAA2BlD,yBAAAA,GAAAA,MAAM,MAAG,CAAC;IACpE,IAAIgD,CAAC,CAACG,OAAO,EAAE;AACbrD,MAAAA,KAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;AACvB;AACA,IAAA,IAAIF,KAAI,CAACmC,KAAK,KAAK,IAAI,EAAE;AACvBe,MAAAA,CAAC,CAAClC,gBAAgB,CAAC,QAAQ,EAAE,UAAAsC,CAAC,EAAI;QAChC,IAAIA,CAAC,CAACD,OAAO,EAAE;AACbrD,UAAAA,KAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;AACvB;AACF,OAAC,CAAC;AACFF,MAAAA,KAAI,CAACkC,QAAQ,CAACY,IAAI,CAACI,CAAC,CAAC;AACvB;GACD;AAbD,EAAA,KAAA,IAAAK,UAAA,GAAAxB,+BAAA,CAAqB,IAAI,CAACE,QAAQ,CAAAgB,EAAAA,MAAA,EAAAA,CAAAA,CAAAA,MAAA,GAAAM,UAAA,IAAAvB,IAAA,GAAA;IAAAgB,MAAA,EAAA;AAAA;AAcpC;;;;"} \ No newline at end of file diff --git a/dist/js/sphinx-colorschemed-images.js b/dist/js/sphinx-colorschemed-images.js index 5537790..3c4247b 100644 --- a/dist/js/sphinx-colorschemed-images.js +++ b/dist/js/sphinx-colorschemed-images.js @@ -62,13 +62,16 @@ } // Check whether the image is inside a
. - debugger; var figure = img.closest('figure'); if (figure != undefined) { var anchor = figure.querySelector('a'); if (anchor.getAttribute('href') !== new_src) { anchor.href = new_src; } + } else if (img.parentElement.tagName == "A" && img.parentElement.getAttribute("href") !== new_src) { + var parent = img.parentElement; + parent.href = img.getAttribute(data_att); + console.log("the new anchor's href:", parent.href); } }; for (var _iterator = _createForOfIteratorHelperLoose(images), _step; !(_step = _iterator()).done;) { diff --git a/dist/js/sphinx-colorschemed-images.js.map b/dist/js/sphinx-colorschemed-images.js.map index f19c321..287043b 100644 --- a/dist/js/sphinx-colorschemed-images.js.map +++ b/dist/js/sphinx-colorschemed-images.js.map @@ -1 +1 @@ -{"version":3,"file":"sphinx-colorschemed-images.js","sources":["../../js/src/main.js","../../js/src/script.js"],"sourcesContent":["export class SphinxColorschemeImageHandler {\n constructor(options={}) {\n this._schemes = [];\n this._mediaqs = [];\n\n // If options are not given or if it is given with a key 'auto'\n // and a boolean value true, then the instance created will add\n // an event listener for changes on prefers-color-scheme to\n // update images accordingly.\n this._auto = options.hasOwnProperty('auto')\n ? options['auto'] === true\n : true;\n\n const meta_prop = document.querySelector('meta[name=\"color-scheme\"]');\n let meta_schemes = (meta_prop == undefined) ? \"\" : meta_prop.content;\n\n if (meta_schemes.length > 0) {\n const schemes = meta_schemes.split(\" \");\n for (const item of schemes) {\n this._schemes.push(item.trim());\n }\n } else {\n this._schemes = ['light', 'dark'];\n }\n\n for (const scheme of this._schemes) {\n const q = globalThis.matchMedia(`(prefers-color-scheme: ${scheme})`);\n if (q.matches) {\n this.activate(scheme);\n }\n if (this._auto === true) {\n q.addEventListener('change', e => {\n if (e.matches) {\n this.activate(scheme);\n }\n });\n this._mediaqs.push(q);\n }\n }\n }\n\n activate = (scheme) => {\n const data_att = `data-alt-src-color-scheme-${scheme}`;\n const images = document.querySelectorAll(`img[${data_att}]`);\n for (const img of images) {\n const new_img = new Image();\n const new_src = img.getAttribute(data_att);\n new_img.src = new_src;\n new_img.addEventListener('load', () => {\n img.src = new_img.src;\n });\n new_img.addEventListener('error', () => {\n console.error(`Could not replace image ${img.src} with ${new_src}.`);\n });\n if (new_img.complete) {\n img.src = new_img.src;\n }\n\n // Check whether the image is inside a
.\n debugger;\n const figure = img.closest('figure');\n if (figure != undefined) {\n const anchor = figure.querySelector('a');\n if (anchor.getAttribute('href') !== new_src) {\n anchor.href = new_src;\n }\n }\n }\n }\n}\n","import { SphinxColorschemeImageHandler } from \"./main\";\n\nfunction runWhenDOMContentLoaded(cb) {\n if (document.readyState != 'loading') {\n cb();\n } else if (document.addEventListener) {\n document.addEventListener('DOMContentLoaded', cb);\n } else {\n document.attachEvent('onreadystatechange', function() {\n if (document.readyState == 'complete') cb();\n });\n }\n}\n\nfunction addSphinxColorschemedImageHandler() {\n return new SphinxColorschemeImageHandler();\n}\n\nrunWhenDOMContentLoaded(addSphinxColorschemedImageHandler);\n"],"names":["SphinxColorschemeImageHandler","options","_this","activate","scheme","data_att","images","document","querySelectorAll","_loop","img","_step","value","new_img","Image","new_src","getAttribute","src","addEventListener","console","error","complete","figure","closest","undefined","anchor","querySelector","href","_iterator","_createForOfIteratorHelperLoose","done","_schemes","_mediaqs","_auto","hasOwnProperty","meta_prop","meta_schemes","content","length","schemes","split","_iterator2","_step2","item","push","trim","_loop2","_step3","q","globalThis","matchMedia","matches","e","_iterator3","runWhenDOMContentLoaded","cb","readyState","attachEvent","addSphinxColorschemedImageHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,IAAaA,6BAA6B,GACxC,SAAAA,6BAAAA,CAAYC,OAAO,EAAK;EAAA,EAAA,IAAAC,KAAA,GAAA,IAAA;EAAA,EAAA,IAAZD,OAAO,KAAA,KAAA,CAAA,EAAA;MAAPA,OAAO,GAAC,EAAE;EAAA;EAAA,EAAA,IAAA,CAwCtBE,QAAQ,GAAG,UAACC,MAAM,EAAK;MACrB,IAAMC,QAAQ,kCAAgCD,MAAQ;MACtD,IAAME,MAAM,GAAGC,QAAQ,CAACC,gBAAgB,CAAQH,MAAAA,GAAAA,QAAQ,MAAG,CAAC;MAAC,IAAAI,KAAA,GAAAA,SAAAA,KAAAA,GACnC;EAAA,MAAA,IAAfC,GAAG,GAAAC,KAAA,CAAAC,KAAA;EACZ,MAAA,IAAMC,OAAO,GAAG,IAAIC,KAAK,EAAE;EAC3B,MAAA,IAAMC,OAAO,GAAGL,GAAG,CAACM,YAAY,CAACX,QAAQ,CAAC;QAC1CQ,O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AK,UAAA,GAAAxB,+BAAA,CAAqB,IAAI,CAACE,QAAQ,CAAAgB,EAAAA,MAAA,EAAAA,CAAAA,CAAAA,MAAA,GAAAM,UAAA,IAAAvB,IAAA,GAAA;MAAAgB,MAAA,EAAA;EAAA;EAcpC,CAAC;;ECrCH,SAASQ,uBAAuBA,CAACC,EAAE,EAAE;EACnC,EAAA,IAAIhD,QAAQ,CAACiD,UAAU,IAAI,SAAS,EAAE;EACpCD,IAAAA,EAAE,EAAE;EACN,GAAC,MAAM,IAAIhD,QAAQ,CAACW,gBAAgB,EAAE;EACpCX,IAAAA,QAAQ,CAACW,gBAAgB,CAAC,kBAAkB,EAAEqC,EAAE,CAAC;EACnD,GAAC,MAAM;EACLhD,IAAAA,QAAQ,CAACkD,WAAW,CAAC,oBAAoB,EAAE,YAAW;QACpD,IAAIlD,QAAQ,CAACiD,UAAU,IAAI,UAAU,EAAED,EAAE,EAAE;EAC7C,KAAC,CAAC;EACJ;EACF;EAEA,SAASG,iCAAiCA,GAAG;IAC3C,OAAO,IAAI1D,6BAA6B,EAAE;EAC5C;EAEAsD,uBAAuB,CAACI,iCAAiC,CAAC;;;;;;"} \ No newline at end of file +{"version":3,"file":"sphinx-colorschemed-images.js","sources":["../../js/src/main.js","../../js/src/script.js"],"sourcesContent":["export class SphinxColorschemeImageHandler {\n constructor(options={}) {\n this._schemes = [];\n this._mediaqs = [];\n\n // If options are not given or if it is given with a key 'auto'\n // and a boolean value true, then the instance created will add\n // an event listener for changes on prefers-color-scheme to\n // update images accordingly.\n this._auto = options.hasOwnProperty('auto')\n ? options['auto'] === true\n : true;\n\n const meta_prop = document.querySelector('meta[name=\"color-scheme\"]');\n let meta_schemes = (meta_prop == undefined) ? \"\" : meta_prop.content;\n\n if (meta_schemes.length > 0) {\n const schemes = meta_schemes.split(\" \");\n for (const item of schemes) {\n this._schemes.push(item.trim());\n }\n } else {\n this._schemes = ['light', 'dark'];\n }\n\n for (const scheme of this._schemes) {\n const q = globalThis.matchMedia(`(prefers-color-scheme: ${scheme})`);\n if (q.matches) {\n this.activate(scheme);\n }\n if (this._auto === true) {\n q.addEventListener('change', e => {\n if (e.matches) {\n this.activate(scheme);\n }\n });\n this._mediaqs.push(q);\n }\n }\n }\n\n activate = (scheme) => {\n const data_att = `data-alt-src-color-scheme-${scheme}`;\n const images = document.querySelectorAll(`img[${data_att}]`);\n for (const img of images) {\n const new_img = new Image();\n const new_src = img.getAttribute(data_att);\n new_img.src = new_src;\n new_img.addEventListener('load', () => {\n img.src = new_img.src;\n });\n new_img.addEventListener('error', () => {\n console.error(`Could not replace image ${img.src} with ${new_src}.`);\n });\n if (new_img.complete) {\n img.src = new_img.src;\n }\n\n // Check whether the image is inside a
.\n const figure = img.closest('figure');\n if (figure != undefined) {\n const anchor = figure.querySelector('a');\n if (anchor.getAttribute('href') !== new_src) {\n anchor.href = new_src;\n }\n } else if (\n (img.parentElement.tagName == \"A\")\n && img.parentElement.getAttribute(\"href\") !== new_src\n ) {\n const parent = img.parentElement;\n parent.href = img.getAttribute(data_att);\n console.log(\"the new anchor's href:\", parent.href);\n }\n }\n }\n}\n","import { SphinxColorschemeImageHandler } from \"./main\";\n\nfunction runWhenDOMContentLoaded(cb) {\n if (document.readyState != 'loading') {\n cb();\n } else if (document.addEventListener) {\n document.addEventListener('DOMContentLoaded', cb);\n } else {\n document.attachEvent('onreadystatechange', function() {\n if (document.readyState == 'complete') cb();\n });\n }\n}\n\nfunction addSphinxColorschemedImageHandler() {\n return new SphinxColorschemeImageHandler();\n}\n\nrunWhenDOMContentLoaded(addSphinxColorschemedImageHandler);\n"],"names":["SphinxColorschemeImageHandler","options","_this","activate","scheme","data_att","images","document","querySelectorAll","_loop","img","_step","value","new_img","Image","new_src","getAttribute","src","addEventListener","console","error","complete","figure","closest","undefined","anchor","querySelector","href","parentElement","tagName","parent","log","_iterator","_createForOfIteratorHelperLoose","done","_schemes","_mediaqs","_auto","hasOwnProperty","meta_prop","meta_schemes","content","length","schemes","split","_iterator2","_step2","item","push","trim","_loop2","_step3","q","globalThis","matchMedia","matches","e","_iterator3","runWhenDOMContentLoaded","cb","readyState","attachEvent","addSphinxColorschemedImageHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,IAAaA,6BAA6B,GACxC,SAAAA,6BAAAA,CAAYC,OAAO,EAAK;EAAA,EAAA,IAAAC,KAAA,GAAA,IAAA;EAAA,EAAA,IAAZD,OAAO,KAAA,KAAA,CAAA,EAAA;MAAPA,OAAO,GAAC,EAAE;EAAA;EAAA,EAAA,IAAA,CAwCtBE,QAAQ,GAAG,UAACC,MAAM,EAAK;MACrB,IAAMC,QAAQ,kCAAgCD,MAAQ;MACtD,IAAME,MAAM,GAAGC,QAAQ,CAACC,gBAAgB,CAAQH,MAAAA,GAAAA,QAAQ,MAAG,CAAC;MAAC,IAAAI,KAAA,GAAAA,SAAAA,KAAAA,GACnC;EAAA,MAAA,IAAfC,GAAG,GAAAC,KAAA,CAAAC,KAAA;EACZ,MAAA,IAAMC,OAAO,GAAG,IAAIC,KAAK,EAAE;EAC3B,MAAA,IAAMC,OAAO,GAAGL,GAAG,CAACM,YAAY,CAACX,QAAQ,CAAC;QAC1CQ,OAAO,CAACI,GAAG,GAAGF,OAAO;EACrBF,MAAAA,OAAO,CAACK,gBAAgB,CAAC,MAAM,EAAE,YAAM;EACrCR,QAAAA,GAAG,CAACO,GAAG,GAAGJ,OAAO,CAACI,GAAG;EACvB,OAAC,CAAC;EACFJ,MAAAA,OAAO,CAACK,gBAAgB,CAAC,OAAO,EAAE,YAAM;UACtCC,OAAO,CAACC,KAAK,CAA4BV,0BAAAA,GAAAA,GAAG,CAACO,GAAG,GAAA,QAAA,GAASF,OAAO,GAAA,GAAG,CAAC;EACtE,OAAC,CAAC;QACF,IAAIF,OAAO,CAACQ,QAAQ,EAAE;EACpBX,QAAAA,GAAG,CAACO,GAAG,GAAGJ,OAAO,CAACI,GAAG;EACvB;;EAEA;EACA,MAAA,IAAM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AA;EAcpC,CAAC;;ECrCH,SAASQ,uBAAuBA,CAACC,EAAE,EAAE;EACnC,EAAA,IAAIpD,QAAQ,CAACqD,UAAU,IAAI,SAAS,EAAE;EACpCD,IAAAA,EAAE,EAAE;EACN,GAAC,MAAM,IAAIpD,QAAQ,CAACW,gBAAgB,EAAE;EACpCX,IAAAA,QAAQ,CAACW,gBAAgB,CAAC,kBAAkB,EAAEyC,EAAE,CAAC;EACnD,GAAC,MAAM;EACLpD,IAAAA,QAAQ,CAACsD,WAAW,CAAC,oBAAoB,EAAE,YAAW;QACpD,IAAItD,QAAQ,CAACqD,UAAU,IAAI,UAAU,EAAED,EAAE,EAAE;EAC7C,KAAC,CAAC;EACJ;EACF;EAEA,SAASG,iCAAiCA,GAAG;IAC3C,OAAO,IAAI9D,6BAA6B,EAAE;EAC5C;EAEA0D,uBAAuB,CAACI,iCAAiC,CAAC;;;;;;"} \ No newline at end of file diff --git a/docs/users-guide.rst b/docs/users-guide.rst index 5178c16..8a84d9d 100644 --- a/docs/users-guide.rst +++ b/docs/users-guide.rst @@ -152,11 +152,14 @@ Produces the following ```` tag: .. cs_image:: img/balloon.png :alt: A balloon icon - :align: center + :align: right :width: 200 Switch the color scheme by using the selector at the top right of the header, or change it in your operating system settings. The balloon image will switch automatically between **light** and **dark** color-schemes. +The ``href`` attribute of the anchor that wraps the ```` is also updated, so clicking on it will load the image matching the color scheme. + + The ``cs_figure`` directive *************************** diff --git a/js/src/main.js b/js/src/main.js index 0b16290..097b8d3 100644 --- a/js/src/main.js +++ b/js/src/main.js @@ -57,13 +57,19 @@ export class SphinxColorschemeImageHandler { } // Check whether the image is inside a
. - debugger; const figure = img.closest('figure'); if (figure != undefined) { const anchor = figure.querySelector('a'); if (anchor.getAttribute('href') !== new_src) { anchor.href = new_src; } + } else if ( + (img.parentElement.tagName == "A") + && img.parentElement.getAttribute("href") !== new_src + ) { + const parent = img.parentElement; + parent.href = img.getAttribute(data_att); + console.log("the new anchor's href:", parent.href); } } } diff --git a/js/tests/unit/main.spec.js b/js/tests/unit/main.spec.js index ccedf1c..49b7c38 100644 --- a/js/tests/unit/main.spec.js +++ b/js/tests/unit/main.spec.js @@ -264,6 +264,77 @@ describe('Initialize with options auto=true and auto=false', () => { // -------------------------------------------------------------------- const template_3 = [ + '
', + ' ', + ' Current version with label 3.13', + ' ', + '
', +]; + +describe("Image's src and anchor's href changes in cs_image", () => { + let fixtureEl; + + beforeAll(() => { + fixtureEl = getFixture(); + + // Be sure that prefers-color-scheme matches when is 'dark'. + spyOn(globalThis, 'matchMedia').and.callFake( + (media_query) => { + const matches = media_query.includes('dark') ? true : false; + return { + matches, // prefers-color-scheme: dark + addEventListener: (evt_name, evt_obj) => {}, + }; + } + ); + + // Be sure that the Image loads. + spyOn(globalThis, 'Image').and.callFake( + () => { + return { + src: '', + addEventListener: (evt_name, evt_cb) => { + if (evt_name === 'load') evt_cb(); + } + } + } + ); + }); + + afterEach(() => { + clearFixture(); + }); + + it("Image's src and anchor's href changes in cs_image", () => { + fixtureEl.innerHTML = template_3.join(''); + + // When loading the template the 'src' attribute of + // the image corresponds to the light version of it. + let img = document.querySelector('img'); + expect(img.getAttribute('src')).toEqual('peace.light.png'); + + new SphinxColorschemeImageHandler({auto: false}); + + // After SphinxColorschemeImageHandler is used, + // the image has switch to the dark theme version. + img = document.querySelector('img'); + expect(img.getAttribute('src')).toEqual('peace.dark.png'); + + // Get the enclosing
. + const anchor = document.querySelector('a'); + expect(anchor.getAttribute('href')).toEqual('peace.dark.png'); + }); +}); + + +// -------------------------------------------------------------------- +const template_4 = [ '
', '
', ' ', ]; -describe('Image src changes, and href inside figure too', () => { +describe("Image's src and anchor's href changes in cs_figure", () => { let fixtureEl; beforeAll(() => { fixtureEl = getFixture(); - // Be sure that prefers-color-scheme matches when is 'dark'. // Be sure that prefers-color-scheme matches when is 'dark'. spyOn(globalThis, 'matchMedia').and.callFake( (media_query) => { @@ -311,15 +381,15 @@ describe('Image src changes, and href inside figure too', () => { } } } - ) + ); }); afterEach(() => { clearFixture(); }); - it('Check that the img src changes, and href inside figure too', () => { - fixtureEl.innerHTML = template_3.join(''); + it("Image's src and anchor's href changes in cs_figure", () => { + fixtureEl.innerHTML = template_4.join(''); // When loading the template the 'src' attribute of // the image corresponds to the light version of it. diff --git a/package.json b/package.json index c789d4b..40cbcff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sphinx-colorschemed-images", - "version": "0.1.3", + "version": "0.1.4", "description": "Include color-scheme aware images in Sphinx projects.", "repository": { "type": "git", diff --git a/sphinx_colorschemed_images/__init__.py b/sphinx_colorschemed_images/__init__.py index 7bb02b0..953b9ac 100644 --- a/sphinx_colorschemed_images/__init__.py +++ b/sphinx_colorschemed_images/__init__.py @@ -2,7 +2,7 @@ from .extension import copy_colorschemed_images, extension_builder_inited -__version__ = "0.1.3" +__version__ = "0.1.4" def setup(app) -> dict: