Mercurial > kallithea
changeset 1320:09c3fb460fcb beta
Fixed problem with anchor link positioning when passed in ranges.
Added anchor link tooltip for code selection
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 08 May 2011 19:58:42 +0200 |
parents | 57185e93061e |
children | 560206522815 |
files | rhodecode/lib/helpers.py rhodecode/templates/files/files_annotate.html rhodecode/templates/files/files_source.html |
diffstat | 3 files changed, 136 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py Sat May 07 16:21:53 2011 +0200 +++ b/rhodecode/lib/helpers.py Sun May 08 19:58:42 2011 +0200 @@ -217,11 +217,11 @@ '<tr><td><div class="linenodiv" ' 'style="background-color: #f0f0f0; padding-right: 10px">' '<pre style="line-height: 125%">' + - ls + '</pre></div></td><td class="code">') + ls + '</pre></div></td><td id="hlcode" class="code">') else: yield 0, ('<table class="%stable">' % self.cssclass + '<tr><td class="linenos"><div class="linenodiv"><pre>' + - ls + '</pre></div></td><td class="code">') + ls + '</pre></div></td><td id="hlcode" class="code">') yield 0, dummyoutfile.getvalue() yield 0, '</td></tr></table>' @@ -252,7 +252,7 @@ golden_ratio = 0.618033988749895 h = 0.22717784590367374 - for c in xrange(n): + for _ in xrange(n): h += golden_ratio h %= 1 HSV_tuple = [h, 0.95, 0.95]
--- a/rhodecode/templates/files/files_annotate.html Sat May 07 16:21:53 2011 +0200 +++ b/rhodecode/templates/files/files_annotate.html Sun May 08 19:58:42 2011 +0200 @@ -73,24 +73,63 @@ ${_('Binary file (%s)') % c.file.mimetype} %else: % if c.file.size < c.cut_off_limit: - ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='S',cssclass="code-highlight")} + ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")} %else: ${_('File is to big to display')} ${h.link_to(_('show as raw'), h.url('files_raw_home',repo_name=c.repo_name,revision=c.cs.revision,f_path=c.f_path))} %endif - <script type="text/javascript"> - YAHOO.util.Event.onDOMReady(function(){ - YAHOO.util.Event.addListener('show_rev','click',function(e){ - YAHOO.util.Event.preventDefault(e); - var cs = YAHOO.util.Dom.get('diff1').value; - var url = "${h.url('files_annotate_home',repo_name=c.repo_name,revision='__CS__',f_path=c.f_path)}".replace('__CS__',cs); - window.location = url; - }); - }); - </script> + <script type="text/javascript"> + function highlight_lines(lines){ + for(pos in lines){ + YUD.setStyle('L'+lines[pos],'background-color','#FFFFBE'); + } + } + page_highlights = location.href.substring(location.href.indexOf('#')+1).split('L'); + if (page_highlights.length == 2){ + highlight_ranges = page_highlights[1].split(","); + + var h_lines = []; + for (pos in highlight_ranges){ + var _range = highlight_ranges[pos].split('-'); + if(_range.length == 2){ + var start = parseInt(_range[0]); + var end = parseInt(_range[1]); + if (start < end){ + for(var i=start;i<=end;i++){ + h_lines.push(i); + } + } + } + else{ + h_lines.push(parseInt(highlight_ranges[pos])); + } + } + highlight_lines(h_lines); + + //remember original location + var old_hash = location.href.substring(location.href.indexOf('#')); + + // this makes a jump to anchor moved by 3 posstions for padding + window.location.hash = '#L'+Math.max(parseInt(h_lines[0])-3,1); + + //sets old anchor + window.location.hash = old_hash; + + } + </script> %endif </div> </div> + <script type="text/javascript"> + YAHOO.util.Event.onDOMReady(function(){ + YUE.on('show_rev','click',function(e){ + YAHOO.util.Event.preventDefault(e); + var cs = YAHOO.util.Dom.get('diff1').value; + var url = "${h.url('files_annotate_home',repo_name=c.repo_name,revision='__CS__',f_path=c.f_path)}".replace('__CS__',cs); + window.location = url; + }); + }); + </script> </div> </div> </div>
--- a/rhodecode/templates/files/files_source.html Sat May 07 16:21:53 2011 +0200 +++ b/rhodecode/templates/files/files_source.html Sun May 08 19:58:42 2011 +0200 @@ -51,12 +51,11 @@ ${_('File is to big to display')} ${h.link_to(_('show as raw'), h.url('files_raw_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.f_path))} %endif - <script type="text/javascript"> function highlight_lines(lines){ for(pos in lines){ YUD.setStyle('L'+lines[pos],'background-color','#FFFFBE'); - } + } } page_highlights = location.href.substring(location.href.indexOf('#')+1).split('L'); if (page_highlights.length == 2){ @@ -78,7 +77,17 @@ h_lines.push(parseInt(highlight_ranges[pos])); } } - highlight_lines(h_lines); + highlight_lines(h_lines); + + //remember original location + var old_hash = location.href.substring(location.href.indexOf('#')); + + // this makes a jump to anchor moved by 3 posstions for padding + window.location.hash = '#L'+Math.max(parseInt(h_lines[0])-3,1); + + //sets old anchor + window.location.hash = old_hash; + } </script> %endif @@ -86,12 +95,79 @@ </div> <script type="text/javascript"> -YAHOO.util.Event.onDOMReady(function(){ - YAHOO.util.Event.addListener('show_rev','click',function(e){ - YAHOO.util.Event.preventDefault(e); +YUE.onDOMReady(function(){ + YUE.on('show_rev','click',function(e){ + YUE.preventDefault(e); var cs = YAHOO.util.Dom.get('diff1').value; var url = "${h.url('files_home',repo_name=c.repo_name,revision='__CS__',f_path=c.f_path)}".replace('__CS__',cs); window.location = url; - }); + }); + + function getIdentNode(n){ + //iterate thru nodes untill matched interesting node ! + + if (typeof n == 'undefined'){ + return -1 + } + + if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){ + return n + } + else{ + return getIdentNode(n.parentNode); + } + } + + function getSelectionLink() { + //get selection from start/to nodes + if (typeof window.getSelection != "undefined") { + s = window.getSelection(); + + from = getIdentNode(s.anchorNode); + till = getIdentNode(s.focusNode); + + f_int = parseInt(from.id.replace('L','')); + t_int = parseInt(till.id.replace('L','')); + + if (f_int > t_int){ + //highlight from bottom + offset = -35; + } + else{ + //highligth from top + offset = 35; + } + + ranges = [f_int,t_int].sort(); + + if (ranges[0] != ranges[1]){ + if(YUD.get('linktt') == null){ + hl_div = document.createElement('div'); + hl_div.id = 'linktt'; + } + anchor = '#L'+ranges[0]+'-'+ranges[1]; + hl_div.innerHTML = ''; + l = document.createElement('a'); + l.href = location.href.substring(0,location.href.indexOf('#'))+anchor; + l.innerHTML = "${_('Selection link')}" + hl_div.appendChild(l); + + YUD.get('body').appendChild(hl_div); + + xy = YUD.getXY(till.id); + + YUD.addClass('linktt','yui-tt'); + YUD.setStyle('linktt','top',xy[1]+offset+'px'); + YUD.setStyle('linktt','left',xy[0]+'px'); + YUD.setStyle('linktt','visibility','visible'); + } + else{ + YUD.setStyle('linktt','visibility','hidden'); + } + } + } + + YUE.on('hlcode','mouseup',getSelectionLink) + }); </script> \ No newline at end of file