Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wiki - add 'write' 'preview' buttons to wiki edit like in issues #7241

Merged
merged 10 commits into from
Nov 17, 2019
2 changes: 2 additions & 0 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ i.icon.centerlock{top:1.5em}
.repository.wiki.new .CodeMirror .CodeMirror-code{font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace}
.repository.wiki.new .CodeMirror .CodeMirror-code .cm-comment{background:inherit}
.repository.wiki.new .editor-preview{background-color:#fff}
.repository.wiki.new .ui.attached.tabular.menu.previewtabs{margin-bottom:15px}
.repository.wiki.new .ui.attached.tabular.menu.previewtabs+.field .editor-toolbar:not(.fullscreen) a.fa-eye{display:none}
.repository.wiki.view .choose.page{margin-top:-5px}
.repository.wiki.view .ui.sub.header{text-transform:none}
.repository.wiki.view>.markdown{padding:15px 30px}
Expand Down
3 changes: 3 additions & 0 deletions public/css/theme-arc-green.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ footer{background:#2e323e;border-top:1px solid #313131}
.ui .text.grey{color:#808084!important}
.ui.attached.table.segment{background:#353945;color:#dbdbdb!important}
.markdown:not(code) h2{border-bottom:1px solid #304251}
.repository.wiki.new .ui.container form .ui.tabular.menu{border-bottom:1px solid rgba(187,187,187,.6)}
.repository.wiki.new .ui.container form .ui.tabular.menu .active.item{border-top:1px solid rgba(187,187,187,.6);border-left:1px solid rgba(187,187,187,.6);border-right:1px solid rgba(187,187,187,.6)}
.repository.wiki.new .ui.container form .ui.tabular.menu .active.item:hover{background:#4b5162}
.hljs,.hljs-keyword,.hljs-selector-tag,.hljs-subst{color:#9daccc}
.markdown:not(code) .highlight pre,.markdown:not(code) pre{background-color:#2a2e3a;border:1px solid #404552}
.markdown:not(code) table tr:nth-child(2n){background-color:#2a2e39}
Expand Down
2 changes: 1 addition & 1 deletion public/js/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions templates/repo/wiki/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<div class="field {{if .Err_Title}}error{{end}}">
<input name="title" value="{{.title}}" autofocus required>
</div>
<div class="ui top attached tabular menu previewtabs">
<a class="active item" data-tab="write">{{.i18n.Tr "write"}}</a>
<a class="item" data-tab="preview">{{.i18n.Tr "preview"}}</a>
</div>
<div class="field">
<textarea class="js-quick-submit" id="edit_area" name="content" data-id="wiki-{{.title}}" data-url="{{.Repository.APIURL}}/markdown" data-context="{{.RepoLink}}/wiki" required>{{if .PageIsWikiEdit}}{{.content}}{{else}}{{.i18n.Tr "repo.wiki.welcome"}}{{end}}</textarea>
</div>
Expand Down
40 changes: 40 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,46 @@ function initWikiForm() {
'clean-block', 'preview', 'fullscreen', 'side-by-side']
});
$(simplemde.codemirror.getInputField()).addClass('js-quick-submit');

setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about to create a wiki.js and move PR related functions to that file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this still be compiled into the same lines?
(as this need to be loaded after simpleMDE is ready)

Copy link
Contributor Author

@Cherrg Cherrg Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 1272 sideBySideChanges = 10; changes variable from line 1137 let sideBySideChanges = 0;

Copy link
Contributor Author

@Cherrg Cherrg Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when all simpeMDE related stuff is in there (line 1146 has FIXME and will be fixed in #7390 or #8891), i will add all wiki related simpleMDE changes to simpleMDE element near line 1304.
May i place the simpleMDE stuff into an extra file?

Copy link
Member

@silverwind silverwind Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could certainly start lazy-loading simpleMDE if it's only used in a few places, ideally using it directly from npm as a dependency.

const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');
const $bPrev = $('.repository.wiki.new .previewtabs a[data-tab="preview"]');
const $toolbar = $('.editor-toolbar');
const $bPreview = $('.editor-toolbar a.fa-eye');
const $bSideBySide = $('.editor-toolbar a.fa-columns');
$bEdit.on('click', () => {
if ($toolbar.hasClass('disabled-for-preview')) {
$bPreview.click();
}
});
$bPrev.on('click', () => {
if (!$toolbar.hasClass('disabled-for-preview')) {
$bPreview.click();
}
});
$bPreview.on('click', () => {
setTimeout(() => {
if ($toolbar.hasClass('disabled-for-preview')) {
if ($bEdit.hasClass('active')) {
$bEdit.removeClass('active');
}
if (!$bPrev.hasClass('active')) {
$bPrev.addClass('active');
}
} else {
if (!$bEdit.hasClass('active')) {
$bEdit.addClass('active');
}
if ($bPrev.hasClass('active')) {
$bPrev.removeClass('active');
}
}
}, 0);
});
$bSideBySide.on('click', () => {
sideBySideChanges = 10;
});
}, 0);
}
}

Expand Down
8 changes: 8 additions & 0 deletions web_src/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,14 @@
.editor-preview {
background-color: white;
}

.ui.attached.tabular.menu.previewtabs {
margin-bottom: 15px;

& + .field .editor-toolbar:not(.fullscreen) a.fa-eye {
display: none;
}
}
}

&.view {
Expand Down
13 changes: 13 additions & 0 deletions web_src/less/themes/arc-green.less
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ a.ui.basic.green.label:hover {
border-bottom: 1px solid #304251;
}

.repository.wiki.new .ui.container form .ui.tabular.menu {
border-bottom: 1px solid rgba(187, 187, 187, 0.6);

.active.item {
border-top: 1px solid rgba(187, 187, 187, 0.6);
border-left: 1px solid rgba(187, 187, 187, 0.6);
border-right: 1px solid rgba(187, 187, 187, 0.6);
&:hover {
background: #4b5162;
}
}
}

.hljs,
.hljs-keyword,
.hljs-selector-tag,
Expand Down