From ba4b1d6e1c652886e54afa685affbe466bb71182 Mon Sep 17 00:00:00 2001 From: MinRK Date: Sat, 23 Mar 2013 12:29:51 -0700 Subject: [PATCH 1/4] add anchor and link to heading cells --- IPython/frontend/html/notebook/static/js/textcell.js | 11 ++++++++++- .../frontend/html/notebook/static/less/notebook.less | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 65d96a0a5..90100b2db 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -516,7 +516,16 @@ var IPython = (function (IPython) { HeadingCell.prototype.set_rendered = function (text) { var r = this.element.find("div.text_cell_render"); r.empty(); - r.append($('').html(text)); + r.append( + $('') + .addClass('heading-link') + .attr('href', '#' + text) + .attr('name', text) + .append( + $('') + .html(text) + ) + ); }; diff --git a/IPython/frontend/html/notebook/static/less/notebook.less b/IPython/frontend/html/notebook/static/less/notebook.less index acedafdac..06fd0eef7 100644 --- a/IPython/frontend/html/notebook/static/less/notebook.less +++ b/IPython/frontend/html/notebook/static/less/notebook.less @@ -468,3 +468,8 @@ p { margin-bottom:0; } + +a.heading-link:link { + text-decoration: none; + color: inherit; +} From 7e6b5d98c7d04a5da0d247ef3bc7db01c0bfc772 Mon Sep 17 00:00:00 2001 From: MinRK Date: Sat, 23 Mar 2013 12:46:03 -0700 Subject: [PATCH 2/4] trigger hash on notebook load enables direct links to anchors within notebooks --- IPython/frontend/html/notebook/static/js/notebookmain.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/IPython/frontend/html/notebook/static/js/notebookmain.js b/IPython/frontend/html/notebook/static/js/notebookmain.js index 297822dba..64ffd9508 100644 --- a/IPython/frontend/html/notebook/static/js/notebookmain.js +++ b/IPython/frontend/html/notebook/static/js/notebookmain.js @@ -82,6 +82,11 @@ $(document).ready(function () { IPython.layout_manager.do_resize(); $([IPython.events]).on('notebook_loaded.Notebook', function () { IPython.layout_manager.do_resize(); + var hash = document.location.hash; + if (hash) { + document.location.hash = ''; + document.location.hash = hash; + } }); IPython.notebook.load_notebook($('body').data('notebookId')); From ede5a6619886b61ba08217bdf21f24f28a0b73de Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 24 Mar 2013 12:47:12 -0700 Subject: [PATCH 3/4] put the anchor inside the header tag instead of the other way around. This way, only clicking the text loads the hash link, rather than the whole area. --- IPython/frontend/html/notebook/static/js/textcell.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 90100b2db..ae2b77f5b 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -517,12 +517,12 @@ var IPython = (function (IPython) { var r = this.element.find("div.text_cell_render"); r.empty(); r.append( - $('') - .addClass('heading-link') - .attr('href', '#' + text) - .attr('name', text) + $('') .append( - $('') + $('') + .addClass('heading-link') + .attr('href', '#' + text) + .attr('name', text) .html(text) ) ); From b110a02e7a6898a6034e87f55a4639f670cb902a Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 24 Mar 2013 12:59:41 -0700 Subject: [PATCH 4/4] s/heading-link/heading-anchor/ --- IPython/frontend/html/notebook/static/js/textcell.js | 2 +- IPython/frontend/html/notebook/static/less/notebook.less | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index ae2b77f5b..fee6a4443 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -520,7 +520,7 @@ var IPython = (function (IPython) { $('') .append( $('') - .addClass('heading-link') + .addClass('heading-anchor') .attr('href', '#' + text) .attr('name', text) .html(text) diff --git a/IPython/frontend/html/notebook/static/less/notebook.less b/IPython/frontend/html/notebook/static/less/notebook.less index 06fd0eef7..6c9a0d54f 100644 --- a/IPython/frontend/html/notebook/static/less/notebook.less +++ b/IPython/frontend/html/notebook/static/less/notebook.less @@ -469,7 +469,7 @@ margin-bottom:0; } -a.heading-link:link { +a.heading-anchor:link { text-decoration: none; color: inherit; }