From cb35891df17c87d5fffa99d10dff21649ce78fd1 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 6 Sep 2022 11:26:15 +0800 Subject: [PATCH] * Modify diff page style. --- module/repo/js/common.js | 48 -------- module/repo/js/diff.js | 90 +++++++++++++-- module/repo/js/monaco.js | 42 +++---- .../repo/view/ajaxgeteditorcontent.html.php | 108 ++++++++++-------- module/repo/view/diffeditor.html.php | 6 +- 5 files changed, 164 insertions(+), 130 deletions(-) diff --git a/module/repo/js/common.js b/module/repo/js/common.js index 737427acdf..645f1ea834 100644 --- a/module/repo/js/common.js +++ b/module/repo/js/common.js @@ -124,51 +124,3 @@ $(function() }); } }) - -/** - * Set pane height. - * - * @access public - * @return void - */ -function setHeight() -{ - var paneHeight = $(window).height() - 120; - $('#fileTabs .tab-pane').css('height', paneHeight + 'px') - - paneHeight += 45; - if($('.label-exchange').html()) paneHeight -= 50; - $('#filesTree').css('height', paneHeight + 'px') -} -setHeight(); - -$(document).on('click', '.repoFileName', function() -{ - var path = encodeURIComponent($(this).data('path')); - var name = $(this).text(); - var $tabs = $('#fileTabs').data('zui.tabs'); - if(openedFiles.indexOf(path) == -1) openedFiles.push(path); - - $tabs.open(createTab(name, path)); - setHeight(); - arrowTabs('fileTabs', -2); -}); - -/* 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) - { - openedFiles.splice(index, 1) - $('[data-path="' + filepath + '"]').closest('li').removeClass('selected'); - } - - if(index == openedFiles.length) arrowTabs('fileTabs', -2); -}); - -/* Append file path into the title. */ -$('#fileTabs').on('onLoad', function(event, tab) { - var filepath = Base64.decode(tab.id.replaceAll('-', '=')); - $('#tab-nav-item-' + tab.id).attr('title', decodeURIComponent(filepath)); -}); diff --git a/module/repo/js/diff.js b/module/repo/js/diff.js index 054dd01302..722609a9bb 100644 --- a/module/repo/js/diff.js +++ b/module/repo/js/diff.js @@ -1,12 +1,45 @@ +/** + * Change code encoding. + * + * @param string encoding + * @access public + * @return void + */ function changeEncoding(encoding) { $('#encoding').val(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) { - var result = {'new': '', 'old': ''}; + var result = { + 'code': {'new': '', 'old': ''}, + 'line': {'new': [], 'old': []} + }; $.each(diffs, function(i, diff) { if(diff.fileName == fileName) @@ -16,13 +49,16 @@ function getDiffs(fileName) var lines = diff.contents[0].lines; $.each(lines, function(l, code) { - if(code.type == 'new') + if(code.type == 'all' || code.type == 'new') { - result.new += code.line.substring(2) + "\n"; + result.code.new += htmlspecialchars_decode(code.line.substring(2)) + "\n"; + result.line.new.push(code.newlc); } - else + + if(code.type == 'all' || code.type == 'old') { - result.old += code.line.substring(2) + "\n"; + result.code.old += htmlspecialchars_decode(code.line.substring(2)) + "\n"; + result.line.old.push(code.oldlc); } }) return result; @@ -54,8 +90,14 @@ function createTab(filename, filepath) $(document).ready(function() { - $("#inline").click(function(){$('#arrange').val('inline');this.form.submit();}); - $("#appose").click(function(){$('#arrange').val('appose');this.form.submit();}); + var diffAppose = true; + $('#appose').hide(); + + if(browser == 'ie') + { + $("#inline").click(function(){$('#arrange').val('inline');this.form.submit();}); + $("#appose").click(function(){$('#arrange').val('appose');this.form.submit();}); + } $(".label-exchange").click(function(){ $('#exchange').submit();}); $('.btn-left').click(function() {arrowTabs('fileTabs', 1);}); @@ -78,10 +120,9 @@ $(document).ready(function() $(document).on('click', '.repoFileName', function() { - var path = encodeURIComponent($(this).data('path')); + var path = $(this).data('path'); var name = $(this).text(); var $tabs = $('#fileTabs').data('zui.tabs'); - if(openedFiles.indexOf(path) == -1) openedFiles.push(path); $tabs.open(createTab(name, path)); setHeight(); @@ -103,8 +144,35 @@ $(document).ready(function() /* Append file path into the title. */ $('#fileTabs').on('onLoad', function(event, tab) { - var filepath = Base64.decode(tab.id.replaceAll('-', '=')); - $('#tab-nav-item-' + tab.id).attr('title', decodeURIComponent(filepath)); + 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); + + if(openedFiles.indexOf(filepath) == -1) openedFiles.push(filepath); + }); + + $('#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() + { + $('.inline-appose').hide(); + diffAppose = !diffAppose; + if(diffAppose) + { + $('#inline').show(); + } + else + { + $('#appose').show(); + } + var type = $(this).attr('id'); + var tabID = $('.tab-nav-item.active').data('id'); + document.getElementById('tab-iframe-' + tabID).contentWindow.updateEditorInline(diffAppose); + return; }); }); diff --git a/module/repo/js/monaco.js b/module/repo/js/monaco.js index 227a815f81..5e49ba4c37 100644 --- a/module/repo/js/monaco.js +++ b/module/repo/js/monaco.js @@ -1,27 +1,27 @@ +/** + * 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', 'ajaxGetEditorContent', urlParams.replace('%s', Base64.encode(encodeURIComponent(filepath)))) + }; +} + $(function() { $('.btn-left').click(function() {arrowTabs('fileTabs', 1);}); $('.btn-right').click(function() {arrowTabs('fileTabs', -2);}); - - /** - * 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', 'ajaxGetEditorContent', urlParams.replace('%s', Base64.encode(encodeURIComponent(filepath)))) - }; - } $('#fileTabs').tabs({tabs: [createTab(file['basename'], entry)]}); /** @@ -40,7 +40,7 @@ $(function() $(document).on('click', '.repoFileName', function() { - var path = encodeURIComponent($(this).data('path')); + var path = $(this).data('path'); var name = $(this).text(); var $tabs = $('#fileTabs').data('zui.tabs'); if(openedFiles.indexOf(path) == -1) openedFiles.push(path); diff --git a/module/repo/view/ajaxgeteditorcontent.html.php b/module/repo/view/ajaxgeteditorcontent.html.php index 976f168328..a5f8f4bbc6 100644 --- a/module/repo/view/ajaxgeteditorcontent.html.php +++ b/module/repo/view/ajaxgeteditorcontent.html.php @@ -80,6 +80,7 @@ js::import($jsRoot . 'monaco-editor/min/vs/loader.js');