From d829edf2c9dc82a4ce7c57e217c31333c1362b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=BB=B6=E4=B9=89?= Date: Tue, 20 Sep 2022 09:33:12 +0800 Subject: [PATCH] * Code for task #69949. --- module/mr/control.php | 2 + module/mr/css/diff.css | 50 ++ module/mr/js/diff.js | 700 ++++++++++++++++++--------- module/mr/view/diff.html.php | 8 + module/repo/view/diffeditor.html.php | 6 +- 5 files changed, 526 insertions(+), 240 deletions(-) diff --git a/module/mr/control.php b/module/mr/control.php index 310c1990fa..5a246d46ea 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -453,6 +453,8 @@ class mr extends control $this->view->arrange = $arrange; $this->view->sourceBranch = $MR->sourceBranch; $this->view->targetBranch = $MR->targetBranch; + $this->view->newRevision = $MR->targetBranch; + $this->view->oldRevision = $MR->sourceBranch; $this->display(); } diff --git a/module/mr/css/diff.css b/module/mr/css/diff.css index d8bc183fa5..392d2b93b6 100644 --- a/module/mr/css/diff.css +++ b/module/mr/css/diff.css @@ -21,3 +21,53 @@ table.diff {margin-bottom: 0px;} .label-exchange i {padding: 0;} .btn-download {border-right: none;} .body-modal #back {display: none;} + +.repoCode td.code {white-space: inherit;} +.repoCode .content, .repoCode .btn {background-color: #F4F5F7; border: none;} +.repoCode .nav-tabs > li.active > a:before {background: none; height: 0;} + +#fileTabs .tab-pane {display: none;} +#fileTabs .tab-pane.active {display: block;} +#fileTabs .tab-nav-item {max-width: none !important;} +#fileTabs > .tabs-navbar {overflow: hidden; padding-bottom: 10px; position: relative; height: 35px;} +#fileTabs > .tabs-navbar > .nav-tabs {position: absolute; display: flex;} +#filesTree #modules {margin-top: 5px;} +#filesTree {overflow-y: auto;} + +#fileTree li {padding: 0 0 0 8px;} +#fileTree li.has-list {padding-left: 20px;} +#fileTree li > a {display: block; padding: 6px 0; border-radius: 2px; padding-left: 6px; height: 30px; text-decoration: none;} +#fileTree li > a > span {display: inline-block;} +#fileTree li > a > span + span {margin-left: 8px;} +#fileTree li.selected > a {background-color: #E8F3FC;} +#fileTree li.selected > a > span.title {color: #006AF1;} +#fileTree .label-id {border-color: #cbd0db; color: #7d8599} +#fileTree .label.label-type {background: #fff; border: 1px solid #7d8599; color:#7d8599} + +#fileTree li > a > span.title {color: #3C4353; white-space: nowrap; max-width: 60%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;} +#fileTree li > a > span.user {color: #838a9d;} +#fileTree li > a > span.user > .icon-person {font-size: 14px; position: relative; top: -1px; color: #a6aab8} +#fileTree li > a:first-child {padding-left: 18px;} +#fileTree li a.selected {color: #e9f2fb; background-color: #0c64eb;} + +#fileTree li > .list-toggle {transform: rotate(0deg); width: 16px; height: 16px; border: 4px solid #a6aab8; border-radius: 2px; top: 7px;} +#fileTree li > .list-toggle:before {content: ' '; display: block; position: absolute; border: 1px solid #a6aab8; top: 2px; left: -3px; right: -3px; bottom: 2px; min-width: 0; transition: all .2s;} +#fileTree li > .list-toggle:hover:before, #fileTree li > .list-toggle:hover {border-color: #006AF1;} +#fileTree li.open > .list-toggle {width: 12px; height: 12px; top: 9px; background-color: #a6aab8; border-width: 3px; left: 3px;} +#fileTree li.open > .list-toggle:before {border: none; height: 2px; width: 6px; left: 0; top: 2px; background: #fff;} +#fileTree li.open > .list-toggle:hover {background: #006AF1;} + +#fileTree ul > li:after {display: block; position: absolute; content: ' '; border-top: 1px dashed #cbd0db; top: 14px; left: -12px; z-index: 1; width: 10px;} +#fileTree ul > li:before, #fileTree ul > li.has-list:before {background: none; content: ' '; display: block; position: absolute; width: auto; height: auto; border: none; border-left: 1px dashed #cbd0db; top: -13px; bottom: 12px; left: -12px;} +#fileTree ul > li:last-child:before {bottom: auto; height: 29px;} +#fileTree ul > li:first-child:before {top: -9px;} +#fileTree ul > li.has-list:first-child:before {top: -13px;} +#fileTree ul > li.tree-single-item:before {height: 23px;} +#fileTree ul > li.has-list:after {width: 14px;} + +#modules li {padding: 5px 0 0 15px;} +.file-tree #modules .icon {color: #9EA3B0;} +.file-tree #modules .icon-folder {padding-left: 5px;} +li.selected .doc-title .icon, li.selected .doc-title a {color: #438EFF !important;} + +.btn-left, .btn-right {display: none;} diff --git a/module/mr/js/diff.js b/module/mr/js/diff.js index 1935957c8a..7c81433324 100644 --- a/module/mr/js/diff.js +++ b/module/mr/js/diff.js @@ -5,6 +5,48 @@ $(document).ready(function() $(".label-exchange").click(function(){ $('#exchange').submit();}); }); +var distance = 0; + +/** + * Aarrow tabs area. + * + * @param string domID + * @param number shift 1|-1 + * @param bool hideRightBtn + * @access public + * @return void + */ +function arrowTabs(domID, shift, hideRightBtn) +{ + if($('#' + domID).html() == '') return; + + $('.btn-right, .btn-left').show(); + if(hideRightBtn) $('.btn-right').hide(); + + var tabItemWidth = $('#' + domID + ' > .tabs-navbar > .nav-tabs')[0].clientWidth; + var tabsWidth = $('#' + domID + '')[0].clientWidth; + if(tabItemWidth < tabsWidth) + { + $('.btn-right, .btn-left').hide(); + return; + } + + distance += tabsWidth * shift * 0.2; + if(distance > 0) distance = 0; + if(distance == 0) + { + $('.btn-left').hide(); + } + + if((tabItemWidth + distance) < tabsWidth * 0.75) + { + $('.btn-right').hide(); + return arrowTabs(domID, 1, true); + } + + $('#' + domID + ' > .tabs-navbar > .tabs-nav')[0].style.transform = 'translateX('+ distance +'px)'; +} + /** * Change encoding. * @@ -18,298 +60,480 @@ function changeEncoding(encoding) $('#encoding').parents('form').submit(); } +/** + * Html code decode. + * + * @param string str + * @access public + * @return string + */ +function htmlspecialchars_decode(str){ + str = str.replace(/&/g, '&'); + str = str.replace(/</g, '<'); + str = str.replace(/>/g, '>'); + str = str.replace(/"/g, "''"); + str = str.replace(/'/g, "'"); + return str; +} + +/** + * Get diffs by file name. + * + * @param string fileName + * @access public + * @return object + */ +function getDiffs(fileName) +{ + if(fileName.indexOf('./') === 0) fileName = fileName.substring(2); + + var result = { + 'code': {'new': '', 'old': ''}, + 'line': {'new': [], 'old': []} + }; + $.each(diffs, function(i, diff) + { + if(diff.fileName == fileName) + { + if(typeof diff.contents[0].lines != 'object') return result; + + var lines = diff.contents[0].lines; + $.each(lines, function(l, code) + { + if(code.type == 'all' || code.type == 'new') + { + result.code.new += htmlspecialchars_decode(code.line.substring(2)) + "\n"; + result.line.new.push(code.newlc); + } + + if(code.type == 'all' || code.type == 'old') + { + result.code.old += htmlspecialchars_decode(code.line.substring(2)) + "\n"; + result.line.old.push(code.oldlc); + } + }) + return result; + } + }); + + return result; +} + +/** + * Create file tab. + * + * @param string filename + * @param string filepath + * @access public + * @return object + */ +function createTab(filename, filepath) +{ + $('[data-path="' + decodeURIComponent(filepath) + '"]').closest('li').addClass('selected'); + var tabID = Base64.encode(filepath).replaceAll('=', '-'); + return { + title: filename, + id: tabID, + type: 'iframe', + url: createLink('repo', 'ajaxGetDiffEditorContent', urlParams.replace('%s', Base64.encode(encodeURIComponent(filepath)))) + }; +} + +/** + * Load link object page. + * + * @param string $link + * @access public + * @return void + */ +function loadLinkPage(link) +{ + $('#linkObject').attr('href', link); + $('#linkObject').click() +} + $(document).ready(function() { - var $diffCode = $('.diff'); - var $rows = $diffCode.find('tr'); - var rowTip = $('#rowTip').html(); - var lastLine; - $rows.each(function() + if(browser != 'ie') { - var $row = $(this); - if(!$row.hasClass('empty')) + var diffAppose = true; + $('.dropdown #appose').hide(); + + if(!browser || browser == 'ie') { - $row.children('th').first().prepend("
"); - $row.children('td').first().append(rowTip); + $("#inline").click(function(){$('#arrange').val('inline');this.form.submit();}); + $("#appose").click(function(){$('#arrange').val('appose');this.form.submit();}); } + $(".label-exchange").click(function(){ $('#exchange').submit();}); - if(lastLine && !$row.data('line')) + $('.btn-left').click(function() {arrowTabs('fileTabs', 1);}); + $('.btn-right').click(function() {arrowTabs('fileTabs', -2);}); + if(file) $('#fileTabs').tabs({tabs: [createTab(file['basename'], entry)]}); + + /** + * Set pane height. + * + * @access public + * @return void + */ + function setHeight() { - $row.attr('data-line', lastLine); + var paneHeight = $(window).height() - 120; + $('#fileTabs .tab-pane').css('height', paneHeight + 'px') + $('#filesTree').css('height', paneHeight + 45) } - else + setHeight(); + + $(document).on('click', '.repoFileName', function() { - lastLine = $row.data('line'); - } - }).hover(function() - { - var $this = $(this); - if($this.hasClass('empty')) return; - $this.addClass("over"); - }, - function() - { - $(this).removeClass("over"); - }); + var path = $(this).data('path'); + var name = $(this).text(); + var $tabs = $('#fileTabs').data('zui.tabs'); - var isInline = $.cookie('arrange') == 'inline'; - var $reviewFormRow = $('' + (isInline ? '' : '') + ''); - var $reviewForm = $('#reviewForm'); - var $reviewPanel = $('#reviewPanel'); - $reviewFormRow.find('td').append($reviewForm.removeClass('hide')); + $tabs.open(createTab(name, path)); + setHeight(); + arrowTabs('fileTabs', -2); + }); - var highlight = function($e) - { - $('.highlight').removeClass('highlight'); - $e.addClass('highlight'); - }; - - var createReview = function(review, line, show) - { - var $review = $reviewPanel.clone().removeClass('hide').attr('id', review.objectType + '-' + review.id); - $review.find('.realname').text(review.realname); - $review.find('.openedDate').text(review.openedDate); - $review.find('.title').text(review.title); - $review.find('.content').toggle(review.content != '').html(review.content); - $review.find('.code-lines').text(review.lines); - $review.find('input[name="objectID"]').val(review.id); - $review.data(review); - - id = review.objectType == 'bug' ? 'Bug' : 'Task'; - id += '#' + review.id; - if(review.view) id = "" + id + ""; - $review.find('.title').closest('.panel-heading').find('.panel-actions').prepend(id); - if(!review.delete) $review.find('.title').closest('.panel-heading').find('.panel-actions .reviewDelete').hide(); - - $review.toggleClass('show', show > 1); - if(show > 2) highlight($review); - - if(!line && review.line) line = review.line; - if(line) - { - var $row = $rows.filter('[data-line="' + line + '"]').last(); - if(review.entry) $row = $('#diff[data-entry="' + review.entry + '"]').find('tr').filter('[data-line="' + line + '"]'); - if($row.length == 0) return false; - - $commentRow = $row.next('tr'); - if($row.hasClass('commented')) $commentRow = $row.nextAll('tr.comment-row').first(); - if(!$commentRow.hasClass('comment-row')) + /* Remove file path for opened files. */ + $('#fileTabs').on('onClose', function(event, tab) { + var filepath = decodeURIComponent(Base64.decode(tab.id.replaceAll('-', '='))); + var index = openedFiles.indexOf(filepath); + if(index > -1) { - $commentRow = $('' + (isInline ? '
' : '
') + ''); - $row.addClass('commented').after($commentRow); + openedFiles.splice(index, 1) + $('[data-path="' + filepath + '"]').closest('li').removeClass('selected'); } - $commentRow.find('.comment-list').append($review); + if(index == openedFiles.length) arrowTabs('fileTabs', -2); + }); - if(show && $commentRow.hasClass('comment-row')) $commentRow.addClass('show'); - } + /* Append file path into the title. */ + $('#fileTabs').on('onLoad', function(event, tab) { + var filepath = decodeURIComponent(Base64.decode(tab.id.replaceAll('-', '='))); + $('#tab-nav-item-' + tab.id).attr('title', filepath); + document.getElementById('tab-iframe-' + tab.id).contentWindow.updateEditorInline(diffAppose); - return $review; - }; + if(openedFiles.indexOf(filepath) == -1) openedFiles.push(filepath); + }); - var toggleComment = function($row, show) - { - var $commentRow; - if($row.hasClass('comment-row')) + $('#fileTabs').on('onOpen', function(event, tab) { + var filepath = decodeURIComponent(Base64.decode(tab.id.replaceAll('-', '='))); + var index = openedFiles.indexOf(filepath); + if(index > -1) document.getElementById('tab-iframe-' + tab.id).contentWindow.updateEditorInline(diffAppose); + }); + + $('.inline-appose').on('click', function() { - $commentRow = $row; - $row = $commentRow.prev('tr'); - if($row.hasClass('action-row')) + $('.inline-appose').hide(); + diffAppose = !diffAppose; + if(diffAppose) { - $row = $row.prev('tr'); + $('.dropdown #inline').show(); } - } - else - { - $commentRow = $row.next('tr'); - if($commentRow.hasClass('action-row')) + else { - $commentRow = $commentRow.next('tr'); + $('.dropdown #appose').show(); } - } - if(show === undefined) - { - show = !$row.hasClass('open'); - } - if($row.hasClass('commented') && $commentRow.hasClass('comment-row')) - { - $commentRow.toggleClass('show', show); - $row.toggleClass('open', show); - } - }; - - $diffCode.on('click', '.comment-btn', function(e) + var type = $(this).attr('id'); + var tabID = $('.tab-nav-item.active').data('id'); + document.getElementById('tab-iframe-' + tabID).contentWindow.updateEditorInline(diffAppose); + return; + }); + } + else { - $rows.removeClass('selected'); - var $row = $(this).closest('tr'); - if($diffCode.hasClass('with-action-row') && $row.hasClass('with-action-row')) + var $diffCode = $('.diff'); + var $rows = $diffCode.find('tr'); + var rowTip = $('#rowTip').html(); + var lastLine; + $rows.each(function() { - $diffCode.removeClass('with-action-row'); - } - else - { - $diffCode.addClass('with-action-row'); - var line = $row.attr('data-line'); - if(!$row.hasClass('with-action-row')) + var $row = $(this); + if(!$row.hasClass('empty')) { - $rows.removeClass('with-action-row') - $row.addClass('with-action-row'); - - $reviewForm.find('input[name="begin"]').val(line); - $reviewForm.find('input[name="end"]').attr('min', line).val(line); - $reviewForm.find('select#assignedTo').trigger("chosen:updated"); - $reviewForm.find('input#entry').val($row.closest('table#diff').data('entry')); - - $row.after($reviewFormRow); - - KindEditor.remove('#commentText'); - $('#commentText').kindeditor(); + $row.children('th').first().prepend("
"); + $row.children('td').first().append(rowTip); } - highlight($reviewForm); - $reviewForm.find('input[name="title"]').focus(); - $row.addClass('selected'); - } - e.stopPropagation(); - }).on('click', '.reviewDelete', function(e) - { - var $review = $(this).closest('.panel-review'); - if(!$review.length) return; - if(confirm(confirmDelete)) - { - var link = createLink($review.data('objectType'), 'delete', 'id=' + $review.data('id') + '&confirm=yes'); - $.get(link, function(data) + if(lastLine && !$row.data('line')) { - var $commentRow = $review.closest('.comment-row'); - if($commentRow.find('.panel-review').length === 1) + $row.attr('data-line', lastLine); + } + else + { + lastLine = $row.data('line'); + } + }).hover(function() + { + var $this = $(this); + if($this.hasClass('empty')) return; + $this.addClass("over"); + }, + function() + { + $(this).removeClass("over"); + }); + + var isInline = $.cookie('arrange') == 'inline'; + var $reviewFormRow = $('' + (isInline ? '' : '') + ''); + var $reviewForm = $('#reviewForm'); + var $reviewPanel = $('#reviewPanel'); + $reviewFormRow.find('td').append($reviewForm.removeClass('hide')); + + var highlight = function($e) + { + $('.highlight').removeClass('highlight'); + $e.addClass('highlight'); + }; + + var createReview = function(review, line, show) + { + var $review = $reviewPanel.clone().removeClass('hide').attr('id', review.objectType + '-' + review.id); + $review.find('.realname').text(review.realname); + $review.find('.openedDate').text(review.openedDate); + $review.find('.title').text(review.title); + $review.find('.content').toggle(review.content != '').html(review.content); + $review.find('.code-lines').text(review.lines); + $review.find('input[name="objectID"]').val(review.id); + $review.data(review); + + id = review.objectType == 'bug' ? 'Bug' : 'Task'; + id += '#' + review.id; + if(review.view) id = "" + id + ""; + $review.find('.title').closest('.panel-heading').find('.panel-actions').prepend(id); + if(!review.delete) $review.find('.title').closest('.panel-heading').find('.panel-actions .reviewDelete').hide(); + + $review.toggleClass('show', show > 1); + if(show > 2) highlight($review); + + if(!line && review.line) line = review.line; + if(line) + { + var $row = $rows.filter('[data-line="' + line + '"]').last(); + if(review.entry) $row = $('#diff[data-entry="' + review.entry + '"]').find('tr').filter('[data-line="' + line + '"]'); + if($row.length == 0) return false; + + $commentRow = $row.next('tr'); + if($row.hasClass('commented')) $commentRow = $row.nextAll('tr.comment-row').first(); + if(!$commentRow.hasClass('comment-row')) { - $commentRow.removeClass('show').prev('tr').removeClass('commented'); + $commentRow = $('' + (isInline ? '
' : '
') + ''); + $row.addClass('commented').after($commentRow); } - $review.remove(); - }); - } - e.stopPropagation(); - return false; - }).on('click', 'tr.commented', function() - { - toggleComment($(this)); - }).on('click', '.panel-review > .panel-heading', function() - { - $(this).closest('.panel-review').toggleClass('show'); - }); - $reviewForm.submit(function() - { - $(this).ajaxSubmit( + $commentRow.find('.comment-list').append($review); + + if(show && $commentRow.hasClass('comment-row')) $commentRow.addClass('show'); + } + + return $review; + }; + + var toggleComment = function($row, show) { - success:function(json) + var $commentRow; + if($row.hasClass('comment-row')) { - json = $.parseJSON(json); - if(json.result == 'fail') + $commentRow = $row; + $row = $commentRow.prev('tr'); + if($row.hasClass('action-row')) { - var message = ''; - if(typeof(json.message) != 'string') + $row = $row.prev('tr'); + } + } + else + { + $commentRow = $row.next('tr'); + if($commentRow.hasClass('action-row')) + { + $commentRow = $commentRow.next('tr'); + } + } + if(show === undefined) + { + show = !$row.hasClass('open'); + } + if($row.hasClass('commented') && $commentRow.hasClass('comment-row')) + { + $commentRow.toggleClass('show', show); + $row.toggleClass('open', show); + } + }; + + $diffCode.on('click', '.comment-btn', function(e) + { + $rows.removeClass('selected'); + var $row = $(this).closest('tr'); + if($diffCode.hasClass('with-action-row') && $row.hasClass('with-action-row')) + { + $diffCode.removeClass('with-action-row'); + } + else + { + $diffCode.addClass('with-action-row'); + var line = $row.attr('data-line'); + if(!$row.hasClass('with-action-row')) + { + $rows.removeClass('with-action-row') + $row.addClass('with-action-row'); + + $reviewForm.find('input[name="begin"]').val(line); + $reviewForm.find('input[name="end"]').attr('min', line).val(line); + $reviewForm.find('select#assignedTo').trigger("chosen:updated"); + $reviewForm.find('input#entry').val($row.closest('table#diff').data('entry')); + + $row.after($reviewFormRow); + + KindEditor.remove('#commentText'); + $('#commentText').kindeditor(); + } + highlight($reviewForm); + $reviewForm.find('input[name="title"]').focus(); + $row.addClass('selected'); + } + e.stopPropagation(); + }).on('click', '.reviewDelete', function(e) + { + var $review = $(this).closest('.panel-review'); + if(!$review.length) return; + + if(confirm(confirmDelete)) + { + var link = createLink($review.data('objectType'), 'delete', 'id=' + $review.data('id') + '&confirm=yes'); + $.get(link, function(data) + { + var $commentRow = $review.closest('.comment-row'); + if($commentRow.find('.panel-review').length === 1) { - for(i in json.message) + $commentRow.removeClass('show').prev('tr').removeClass('commented'); + } + $review.remove(); + }); + } + e.stopPropagation(); + return false; + }).on('click', 'tr.commented', function() + { + toggleComment($(this)); + }).on('click', '.panel-review > .panel-heading', function() + { + $(this).closest('.panel-review').toggleClass('show'); + }); + + $reviewForm.submit(function() + { + $(this).ajaxSubmit( + { + success:function(json) + { + json = $.parseJSON(json); + if(json.result == 'fail') + { + var message = ''; + if(typeof(json.message) != 'string') { - if(typeof(json.message[i]) == 'string') + for(i in json.message) { - message += json.message[i] + '\n'; - } - else - { - for(j in json.message[i]) + if(typeof(json.message[i]) == 'string') { - message += json.message[i][j] + '\n'; + message += json.message[i] + '\n'; + } + else + { + for(j in json.message[i]) + { + message += json.message[i][j] + '\n'; + } } } } + else + { + message += json.message + '\n'; + } + alert(message); + return false; } - else - { - message += json.message + '\n'; - } - alert(message); - return false; - } - createReview(json, json.line, 3); - $diffCode.removeClass('with-action-row'); - $diffCode.find('tr.with-action-row.selected').removeClass('selected'); - $reviewForm.find('#title').val(''); - KindEditor.html('#commentText', ''); - }, - beforeSubmit:function(formData, jqForm) + createReview(json, json.line, 3); + $diffCode.removeClass('with-action-row'); + $diffCode.find('tr.with-action-row.selected').removeClass('selected'); + $reviewForm.find('#title').val(''); + KindEditor.html('#commentText', ''); + }, + beforeSubmit:function(formData, jqForm) + { + var form = jqForm[0]; + if(!form.product.value) + { + alert(productError); + return false; + } + if(!form.title.value) + { + alert(titleError); + $reviewForm.find('input[name="title"]').focus(); + return false; + } + } + }); + return false; + }).on('change', 'input[name="begin"]', function() + { + var begin = $(this).val(); + var $end = $reviewForm.find('input[name="end"]').attr('min', begin); + if(parseInt($end.val()) < parseInt(begin)) { - var form = jqForm[0]; - if(!form.product.value) - { - alert(productError); - return false; - } - if(!form.title.value) - { - alert(titleError); - $reviewForm.find('input[name="title"]').focus(); - return false; - } + $end.val(begin); } }); - return false; - }).on('change', 'input[name="begin"]', function() - { - var begin = $(this).val(); - var $end = $reviewForm.find('input[name="end"]').attr('min', begin); - if(parseInt($end.val()) < parseInt(begin)) - { - $end.val(begin); - } - }); - if(reviews) - { - var lineReviews; - for(var line in reviews) + if(reviews) { - if(line) + var lineReviews; + for(var line in reviews) { - lineReviews = reviews[line]; - for(var i in lineReviews) createReview(lineReviews[i], line); + if(line) + { + lineReviews = reviews[line]; + for(var i in lineReviews) createReview(lineReviews[i], line); + } } } - } - setTimeout(anchor, 200); + setTimeout(anchor, 200); - $(document).on('click', function() - { - $('.highlight').removeClass('highlight'); - }); - - /** - * Anchor - * - * @access public - * @return void - */ - function anchor() - { - var hash = window.location.hash; - if(!hash) return false; - - var line = hash.substr(1).replace('L', ''); - var $row = $('.diff tr[data-line="' + line +'"]').first(); - if($row.length) return false; - - var anchor = $row.offset().top; - $('body,html').animate({scrollTop:anchor - 50}, 500); - - $row.addClass('highlight'); - if($row.hasClass('commented')) + $(document).on('click', function() { - toggleComment($row, true); - var $commentRow = $row.next('tr'); - if($commentRow.hasClass('comment-row')) $commentRow.addClass('highlight'); + $('.highlight').removeClass('highlight'); + }); + + /** + * Anchor + * + * @access public + * @return void + */ + function anchor() + { + var hash = window.location.hash; + if(!hash) return false; + + var line = hash.substr(1).replace('L', ''); + var $row = $('.diff tr[data-line="' + line +'"]').first(); + if($row.length) return false; + + var anchor = $row.offset().top; + $('body,html').animate({scrollTop:anchor - 50}, 500); + + $row.addClass('highlight'); + if($row.hasClass('commented')) + { + toggleComment($row, true); + var $commentRow = $row.next('tr'); + if($commentRow.hasClass('comment-row')) $commentRow.addClass('highlight'); + } } } }); diff --git a/module/mr/view/diff.html.php b/module/mr/view/diff.html.php index 57716856e0..69d792ac7b 100644 --- a/module/mr/view/diff.html.php +++ b/module/mr/view/diff.html.php @@ -11,6 +11,10 @@ + diff --git a/module/repo/view/diffeditor.html.php b/module/repo/view/diffeditor.html.php index 1d04db8f97..02d4d1401c 100644 --- a/module/repo/view/diffeditor.html.php +++ b/module/repo/view/diffeditor.html.php @@ -1,8 +1,10 @@ fileName : ''; -$file = $entry ? pathinfo($entry) : array(); +$entry = count($diffs) ? $diffs[0]->fileName : ''; +$file = $entry ? pathinfo($entry) : array(); +$showBug = isset($showBug) ? $showBug : true; +$objectID = isset($objectID) ? $objectID : 0; js::set('diffs', $diffs); js::set('file', $file);