Mercurial > kallithea
changeset 1699:623b228cf325 beta
cleaned up JS files in files templates.
- fixed some small issues with editing/adding git files using codemirror
- small css fixes
- separated files/dir browsing into separate template
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 19 Nov 2011 21:00:02 +0200 |
parents | 8fdabc8cce1a |
children | bc16d1d0869a |
files | rhodecode/public/css/style.css rhodecode/public/js/rhodecode.js rhodecode/templates/files/files.html rhodecode/templates/files/files_add.html rhodecode/templates/files/files_browser.html rhodecode/templates/files/files_edit.html rhodecode/templates/files/files_source.html rhodecode/templates/files/files_ypjax.html |
diffstat | 8 files changed, 255 insertions(+), 243 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/public/css/style.css Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/public/css/style.css Sat Nov 19 21:00:02 2011 +0200 @@ -1919,6 +1919,9 @@ border: 1px solid #CCC; padding: 10px; height: 45px; + -webkit-border-radius: 6px 6px 0px 0px; + -moz-border-radius: 6px 6px 0px 0px; + border-radius: 6px 6px 0px 0px; } #graph_content #rev_range_container { @@ -1978,7 +1981,7 @@ } .right .changes .changed_total { - border: 1px solid #DDD; + border: 0px solid #DDD; display: block; float: right; text-align: center; @@ -1986,6 +1989,10 @@ cursor: pointer; background: #FD8; font-weight: bold; + -webkit-border-radius: 0px 0px 0px 6px; + -moz-border-radius: 0px 0px 0px 6px; + border-radius: 0px 0px 0px 6px; + padding: 2px; } .right .changes .added,.changed,.removed {
--- a/rhodecode/public/js/rhodecode.js Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/public/js/rhodecode.js Sat Nov 19 21:00:02 2011 +0200 @@ -7,10 +7,10 @@ } -function str_repeat(i, m) { +var str_repeat = function(i, m) { for (var o = []; m > 0; o[--m] = i); return o.join(''); -} +}; /** * INJECT .format function into String @@ -55,7 +55,7 @@ * * @returns {ColorGenerator} */ -function ColorGenerator(){ +var ColorGenerator = function(){ this.GOLDEN_RATIO = 0.618033988749895; this.CURRENT_RATIO = 0.22717784590367374 // this can be random this.HSV_1 = 0.75;//saturation @@ -129,7 +129,7 @@ /* disable for the mercury iOS browser, or at least older versions of the webkit engine */ || (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent) ) -) +); /** * Partial Ajax Implementation @@ -179,7 +179,7 @@ } },args); -} +}; /** * tooltip activate @@ -206,7 +206,7 @@ hidedelay:5, showdelay:20, }); -} +}; /** * show more @@ -217,7 +217,7 @@ YUD.setStyle(YUD.get(el.id.substring(1)),'display',''); YUD.setStyle(el.parentNode,'display','none'); }); -} +}; /** @@ -284,7 +284,7 @@ } } -} +}; var ajaxPOST = function(url,postData,success) { var sUrl = url; @@ -302,7 +302,7 @@ /** comments **/ var removeInlineForm = function(form) { form.parentNode.removeChild(form); -} +}; var tableTr = function(cls,body){ var form = document.createElement('tr'); @@ -311,7 +311,7 @@ '<td class="lineno-inline old-inline"></td>'+ '<td>{0}</td>'.format(body); return form; -} +}; var createInlineForm = function(parent_tr, f_path, line) { var tmpl = YUD.get('comment-inline-form-template').innerHTML; @@ -327,7 +327,8 @@ YUD.removeClass(parent_tr, 'form-open'); }); return form -} +}; + var getLineNo = function(tr) { var line; var o = tr.children[0].id.split('_'); @@ -340,4 +341,206 @@ } return line -} \ No newline at end of file +}; + + +var fileBrowserListeners = function(current_url, node_list_url, url_base){ + var current_url_branch = +"?branch=__BRANCH__"; + var url = url_base; + var node_url = node_list_url; + + YUE.on('stay_at_branch','click',function(e){ + if(e.target.checked){ + var uri = current_url_branch; + uri = uri.replace('__BRANCH__',e.target.value); + window.location = uri; + } + else{ + window.location = current_url; + } + }) + + var n_filter = YUD.get('node_filter'); + var F = YAHOO.namespace('node_filter'); + + url = url.replace('__REPO__','${c.repo_name}'); + url = url.replace('__REVISION__','${c.changeset.raw_id}'); + url = url.replace('__FPATH__','${c.files_list.path}'); + + node_url = node_url.replace('__REPO__','${c.repo_name}'); + node_url = node_url.replace('__REVISION__','${c.changeset.raw_id}'); + + F.filterTimeout = null; + var nodes = null; + + F.initFilter = function(){ + YUD.setStyle('node_filter_box_loading','display',''); + YUD.setStyle('search_activate_id','display','none'); + YUD.setStyle('add_node_id','display','none'); + YUC.initHeader('X-PARTIAL-XHR',true); + YUC.asyncRequest('GET',url,{ + success:function(o){ + nodes = JSON.parse(o.responseText); + YUD.setStyle('node_filter_box_loading','display','none'); + YUD.setStyle('node_filter_box','display',''); + }, + failure:function(o){ + console.log('failed to load'); + } + },null); + } + + F.updateFilter = function(e) { + + return function(){ + // Reset timeout + F.filterTimeout = null; + var query = e.target.value; + var match = []; + var matches = 0; + var matches_max = 20; + if (query != ""){ + for(var i=0;i<nodes.length;i++){ + var pos = nodes[i].toLowerCase().indexOf(query) + if(query && pos != -1){ + + matches++ + //show only certain amount to not kill browser + if (matches > matches_max){ + break; + } + + var n = nodes[i]; + var n_hl = n.substring(0,pos) + +"<b>{0}</b>".format(n.substring(pos,pos+query.length)) + +n.substring(pos+query.length) + match.push('<tr><td><a class="browser-file" href="{0}">{1}</a></td><td colspan="5"></td></tr>'.format(node_url.replace('__FPATH__',n),n_hl)); + } + if(match.length >= matches_max){ + match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format("${_('search truncated')}")); + } + + } + } + + if(query != ""){ + YUD.setStyle('tbody','display','none'); + YUD.setStyle('tbody_filtered','display',''); + + if (match.length==0){ + match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format("${_('no matching files')}")); + } + + YUD.get('tbody_filtered').innerHTML = match.join(""); + } + else{ + YUD.setStyle('tbody','display',''); + YUD.setStyle('tbody_filtered','display','none'); + } + + } + }; + + YUE.on(YUD.get('filter_activate'),'click',function(){ + F.initFilter(); + }) + YUE.on(n_filter,'click',function(){ + n_filter.value = ''; + }); + YUE.on(n_filter,'keyup',function(e){ + clearTimeout(F.filterTimeout); + F.filterTimeout = setTimeout(F.updateFilter(e),600); + }); +}; + + +var initCodeMirror = function(textAreadId,resetUrl){ + var myCodeMirror = CodeMirror.fromTextArea(YUD.get(textAreadId),{ + mode: "null", + lineNumbers:true + }); + YUE.on('reset','click',function(e){ + window.location=resetUrl + }); + + YUE.on('file_enable','click',function(){ + YUD.setStyle('editor_container','display',''); + YUD.setStyle('upload_file_container','display','none'); + YUD.setStyle('filename_container','display',''); + }); + + YUE.on('upload_file_enable','click',function(){ + YUD.setStyle('editor_container','display','none'); + YUD.setStyle('upload_file_container','display',''); + YUD.setStyle('filename_container','display','none'); + }); +}; + + + +var getIdentNode = function(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); + } +}; + +var getSelectionLink = function(selection_link_label) { + return function(){ + //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; + ranges = [t_int,f_int]; + + } + else{ + //highligth from top + offset = 35; + ranges = [f_int,t_int]; + } + + 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_label; + 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'); + } + } + } +};
--- a/rhodecode/templates/files/files.html Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/templates/files/files.html Sat Nov 19 21:00:02 2011 +0200 @@ -32,24 +32,15 @@ </div> <div class="table"> <div id="files_data"> - %if c.files_list: - <h3 class="files_location"> - ${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.changeset.raw_id,c.files_list.path)} - </h3> - %if c.files_list.is_dir(): - <%include file='files_browser.html'/> - %else: - <%include file='files_source.html'/> - %endif - %else: - <h2> - <a href="#" onClick="javascript:parent.history.back();" target="main">${_('Go back')}</a> - ${_('No files at given path')}: "${c.f_path or "/"}" - </h2> - %endif - + <%include file='files_ypjax.html'/> </div> </div> </div> - -</%def> \ No newline at end of file +<script type="text/javascript"> +var YPJAX_TITLE = "${c.repo_name} ${_('Files')} - ${c.rhodecode_name}"; +var current_url = "${h.url.current()}"; +var node_list_url = '${h.url("files_home",repo_name="__REPO__",revision="__REVISION__",f_path="__FPATH__")}'; +var url_base = '${h.url("files_nodelist_home",repo_name="__REPO__",revision="__REVISION__",f_path="__FPATH__")}'; +fileBrowserListeners(current_url, node_list_url, url_base); +</script> +</%def> \ No newline at end of file
--- a/rhodecode/templates/files/files_add.html Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/templates/files/files_add.html Sat Nov 19 21:00:02 2011 +0200 @@ -83,26 +83,8 @@ </div> ${h.end_form()} <script type="text/javascript"> - var myCodeMirror = CodeMirror.fromTextArea(YUD.get('editor'),{ - mode: "null", - lineNumbers:true - }); - YUE.on('reset','click',function(e){ - window.location="${h.url('files_home',repo_name=c.repo_name,revision=c.cs.revision,f_path=c.f_path)}"; - }); - - YUE.on('file_enable','click',function(){ - YUD.setStyle('editor_container','display',''); - YUD.setStyle('upload_file_container','display','none'); - YUD.setStyle('filename_container','display',''); - }); - - YUE.on('upload_file_enable','click',function(){ - YUD.setStyle('editor_container','display','none'); - YUD.setStyle('upload_file_container','display',''); - YUD.setStyle('filename_container','display','none'); - }); - + var reset_url = "${h.url('files_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.f_path)}"; + initCodeMirror('editor',reset_url); </script> </div> </div>
--- a/rhodecode/templates/files/files_browser.html Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/templates/files/files_browser.html Sat Nov 19 21:00:02 2011 +0200 @@ -35,120 +35,6 @@ <div id="node_filter_box_loading" style="display:none">${_('Loading file list...')}</div> <div id="node_filter_box" style="display:none"> ${h.files_breadcrumbs(c.repo_name,c.changeset.raw_id,c.files_list.path)}/<input type="text" value="type to search..." name="filter" size="25" id="node_filter" autocomplete="off"> - - <script type="text/javascript"> - - YUE.on('stay_at_branch','click',function(e){ - if(e.target.checked){ - var uri = "${h.url.current(branch='__BRANCH__')}" - uri = uri.replace('__BRANCH__',e.target.value); - window.location = uri; - } - else{ - window.location = "${h.url.current()}"; - } - - }) - - var n_filter = YUD.get('node_filter'); - var F = YAHOO.namespace('node_filter'); - - var url = '${h.url("files_nodelist_home",repo_name="__REPO__",revision="__REVISION__",f_path="__FPATH__")}'; - var node_url = '${h.url("files_home",repo_name="__REPO__",revision="__REVISION__",f_path="__FPATH__")}'; - - url = url.replace('__REPO__','${c.repo_name}'); - url = url.replace('__REVISION__','${c.changeset.raw_id}'); - url = url.replace('__FPATH__','${c.files_list.path}'); - - node_url = node_url.replace('__REPO__','${c.repo_name}'); - node_url = node_url.replace('__REVISION__','${c.changeset.raw_id}'); - - - F.filterTimeout = null; - var nodes = null; - - - F.initFilter = function(){ - YUD.setStyle('node_filter_box_loading','display',''); - YUD.setStyle('search_activate_id','display','none'); - YUD.setStyle('add_node_id','display','none'); - YUC.initHeader('X-PARTIAL-XHR',true); - YUC.asyncRequest('GET',url,{ - success:function(o){ - nodes = JSON.parse(o.responseText); - YUD.setStyle('node_filter_box_loading','display','none'); - YUD.setStyle('node_filter_box','display',''); - }, - failure:function(o){ - console.log('failed to load'); - } - },null); - } - - F.updateFilter = function(e) { - - return function(){ - // Reset timeout - F.filterTimeout = null; - var query = e.target.value; - var match = []; - var matches = 0; - var matches_max = 20; - if (query != ""){ - for(var i=0;i<nodes.length;i++){ - var pos = nodes[i].toLowerCase().indexOf(query) - if(query && pos != -1){ - - matches++ - //show only certain amount to not kill browser - if (matches > matches_max){ - break; - } - - var n = nodes[i]; - var n_hl = n.substring(0,pos) - +"<b>{0}</b>".format(n.substring(pos,pos+query.length)) - +n.substring(pos+query.length) - match.push('<tr><td><a class="browser-file" href="{0}">{1}</a></td><td colspan="5"></td></tr>'.format(node_url.replace('__FPATH__',n),n_hl)); - } - if(match.length >= matches_max){ - match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format("${_('search truncated')}")); - } - - } - } - - if(query != ""){ - YUD.setStyle('tbody','display','none'); - YUD.setStyle('tbody_filtered','display',''); - - if (match.length==0){ - match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format("${_('no matching files')}")); - } - - YUD.get('tbody_filtered').innerHTML = match.join(""); - } - else{ - YUD.setStyle('tbody','display',''); - YUD.setStyle('tbody_filtered','display','none'); - } - - } - } - - - YUE.on(YUD.get('filter_activate'),'click',function(){ - F.initFilter(); - }) - YUE.on(n_filter,'click',function(){ - n_filter.value = ''; - }); - YUE.on(n_filter,'keyup',function(e){ - clearTimeout(F.filterTimeout); - F.filterTimeout = setTimeout(F.updateFilter(e),600); - }); - </script> - </div> </div> </div> @@ -171,7 +57,7 @@ %if c.files_list.parent: <tr class="parity0"> <td> - ${h.link_to('..',h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.files_list.parent.path),class_="browser-dir")} + ${h.link_to('..',h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.files_list.parent.path),class_="browser-dir ypjax-link")} </td> <td></td> <td></td> @@ -184,7 +70,7 @@ %for cnt,node in enumerate(c.files_list): <tr class="parity${cnt%2}"> <td> - ${h.link_to(node.name,h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=h.safe_unicode(node.path)),class_=file_class(node))} + ${h.link_to(node.name,h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=h.safe_unicode(node.path)),class_=file_class(node)+" ypjax-link")} </td> <td> %if node.is_file():
--- a/rhodecode/templates/files/files_edit.html Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/templates/files/files_edit.html Sat Nov 19 21:00:02 2011 +0200 @@ -50,13 +50,8 @@ </div> ${h.end_form()} <script type="text/javascript"> - var myCodeMirror = CodeMirror.fromTextArea(YUD.get('editor'),{ - mode: "null", - lineNumbers:true - }); - YUE.on('reset','click',function(){ - window.location="${h.url('files_home',repo_name=c.repo_name,revision=c.cs.revision,f_path=c.file.path)}"; - }) + var reset_url = "${h.url('files_home',repo_name=c.repo_name,revision=c.cs.raw_id,f_path=c.file.path)}"; + initCodeMirror('editor',reset_url); </script> </div> </div>
--- a/rhodecode/templates/files/files_source.html Fri Nov 18 16:31:36 2011 +0200 +++ b/rhodecode/templates/files/files_source.html Sat Nov 19 21:00:02 2011 +0200 @@ -98,77 +98,10 @@ YUE.onDOMReady(function(){ YUE.on('show_rev','click',function(e){ YUE.preventDefault(e); - var cs = YAHOO.util.Dom.get('diff1').value; + var cs = YUD.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; - ranges = [t_int,f_int]; - - } - else{ - //highligth from top - offset = 35; - ranges = [f_int,t_int]; - } - - 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) - + YUE.on('hlcode','mouseup',getSelectionLink("${_('Selection link')}")) }); </script>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rhodecode/templates/files/files_ypjax.html Sat Nov 19 21:00:02 2011 +0200 @@ -0,0 +1,15 @@ +%if c.files_list: + <h3 class="files_location"> + ${_('Location')}: ${h.files_breadcrumbs(c.repo_name,c.changeset.raw_id,c.files_list.path)} + </h3> + %if c.files_list.is_dir(): + <%include file='files_browser.html'/> + %else: + <%include file='files_source.html'/> + %endif +%else: + <h2> + <a href="#" onClick="javascript:parent.history.back();" target="main">${_('Go back')}</a> + ${_('No files at given path')}: "${c.f_path or "/"}" + </h2> +%endif