Warmcat homepage andy@warmcat.com
libwebsockets
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1745907655, "reponame":"cgit", "desc":"CGI gitweb", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://warmcat.com/repo/cgit", "f":3, "items": [ {"schema":"libjg2-1", "cid":"a61f2fdde43da672157f14e51c4d18f6", "commit": {"type":"commit", "time": 1530589970, "time_ofs": 480, "oid_tree": { "oid": "52385c60bcbf6d5164abb74d901543ae5a8c47a1", "alias": []}, "oid":{ "oid": "dcc6eeac1155d4257e8e2cc5503db8e5a0d0c159", "alias": []}, "msg": "cgit.js: line range highlight: make responsive to url changes", "sig_commit": { "git_time": { "time": 1530589970, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1529705265, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "cgit.js: line range highlight: make responsive to url changes\n\nBrowser default interpretation of the # part of the URL is\nto try to match it to an element ID one time at page load.\n\nSubsequent modifications in the URL bar are ignored, even if\nyou hit enter there.\n\nThis patch makes the line range highlight able to clean up\nafter itself and be reapplied, and has the highlight function\nlisten for hashchange events and re-interpret the # part\nwhen they occur.\n\nNow if you edit the URL and press enter, any existing highlight\nis removed, the # part reinterpreted and the new highlight\napplied automatically.\n\nThis is particularly useful if you edit the # link with the\nintention to show a range before copying the URL.\n\nClicking on the line number, which changes the URL bar to\nhave a corresponding #n part, also triggers hashchange and\nmakes the clicked line be highlit immediately.\n\nSigned-off-by: Andy Green \u003candy@warmcat.com\u003e" , "diff": "diff --git a/cgit.js b/cgit.js\nindex 7c034e3..6cc27c1 100644\n--- a/cgit.js\n+++ b/cgit.js\n@@ -33,6 +33,18 @@ function line_range_highlight()\n {\n \tvar h \u003d window.location.hash, l1 \u003d 0, l2 \u003d 0, e, t;\n \n+\te \u003d document.getElementById(\u0022cgit-line-range\u0022);\n+\tif (e) {\n+\t\tl1 \u003d e.l1;\n+\t\twhile (l1 \u003c\u003d e.l2) {\n+\t\t\tvar e1;\n+\t\t\te1 \u003d document.getElementById('n' + l1++);\n+\t\t\te1.style.backgroundColor \u003d null;\n+\t\t}\n+\n+\t\te.remove();\n+\t}\n+\n \tl1 \u003d parseInt(h.substring(2));\n \tif (!l1)\n \t\treturn;\n@@ -56,6 +68,7 @@ function line_range_highlight()\n \tde.className \u003d \u0022selected-lines\u0022;\n \tde.style.bottom \u003d e.style.bottom;\n \tde.style.top \u003d collect_offsetTop(e) + 'px';\n+\tde.id \u003d \u0022cgit-line-range\u0022;\n \tde.l1 \u003d l1;\n \tde.l2 \u003d l2;\n \n@@ -89,4 +102,8 @@ window.addEventListener(\u0022load\u0022, function() {\n \tline_range_highlight();\n }, false);\n \n+window.addEventListener(\u0022hashchange\u0022, function() {\n+\tline_range_highlight();\n+}, false);\n+\n })();\n","s":{"c":1745907655,"u": 483}} ],"g": 1396,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}