mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Squashed commit of the following:
commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89991ce42
Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9faad7ea88
Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912cf85e9e
Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b7521c7dcdd
Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
This commit is contained in:
@@ -255,6 +255,9 @@ code.wrap {
|
||||
.ui.status.buttons .octicon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.ui.menu .item .octicon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.ui.inline.delete-button {
|
||||
padding: 8px 15px;
|
||||
font-weight: normal;
|
||||
@@ -1266,57 +1269,57 @@ footer .ui.language .menu {
|
||||
.repository.file.list #file-content .view-raw img {
|
||||
padding: 5px 5px 0 5px;
|
||||
}
|
||||
.repository.file.list #file-content .code-view * {
|
||||
#file-content .code-view * {
|
||||
font-size: 12px;
|
||||
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
line-height: 20px;
|
||||
}
|
||||
.repository.file.list #file-content .code-view table {
|
||||
#file-content .code-view table {
|
||||
width: 100%;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num {
|
||||
#file-content .code-view .lines-num {
|
||||
vertical-align: top;
|
||||
text-align: right;
|
||||
color: #999;
|
||||
background: #f5f5f5;
|
||||
width: 1%;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num span {
|
||||
#file-content .code-view .lines-num span {
|
||||
line-height: 20px;
|
||||
padding: 0 10px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num,
|
||||
.repository.file.list #file-content .code-view .lines-code {
|
||||
#file-content .code-view .lines-num,
|
||||
#file-content .code-view .lines-code {
|
||||
padding: 0;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num pre,
|
||||
.repository.file.list #file-content .code-view .lines-code pre,
|
||||
.repository.file.list #file-content .code-view .lines-num ol,
|
||||
.repository.file.list #file-content .code-view .lines-code ol,
|
||||
.repository.file.list #file-content .code-view .lines-num .hljs,
|
||||
.repository.file.list #file-content .code-view .lines-code .hljs {
|
||||
#file-content .code-view .lines-num pre,
|
||||
#file-content .code-view .lines-code pre,
|
||||
#file-content .code-view .lines-num ol,
|
||||
#file-content .code-view .lines-code ol,
|
||||
#file-content .code-view .lines-num .hljs,
|
||||
#file-content .code-view .lines-code .hljs {
|
||||
background-color: white;
|
||||
margin: 0;
|
||||
padding: 0 !important;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num pre li,
|
||||
.repository.file.list #file-content .code-view .lines-code pre li,
|
||||
.repository.file.list #file-content .code-view .lines-num ol li,
|
||||
.repository.file.list #file-content .code-view .lines-code ol li,
|
||||
.repository.file.list #file-content .code-view .lines-num .hljs li,
|
||||
.repository.file.list #file-content .code-view .lines-code .hljs li {
|
||||
#file-content .code-view .lines-num pre li,
|
||||
#file-content .code-view .lines-code pre li,
|
||||
#file-content .code-view .lines-num ol li,
|
||||
#file-content .code-view .lines-code ol li,
|
||||
#file-content .code-view .lines-num .hljs li,
|
||||
#file-content .code-view .lines-code .hljs li {
|
||||
padding-left: 5px;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
.repository.file.list #file-content .code-view .lines-num pre li.active,
|
||||
.repository.file.list #file-content .code-view .lines-code pre li.active,
|
||||
.repository.file.list #file-content .code-view .lines-num ol li.active,
|
||||
.repository.file.list #file-content .code-view .lines-code ol li.active,
|
||||
.repository.file.list #file-content .code-view .lines-num .hljs li.active,
|
||||
.repository.file.list #file-content .code-view .lines-code .hljs li.active {
|
||||
#file-content .code-view .lines-num pre li.active,
|
||||
#file-content .code-view .lines-code pre li.active,
|
||||
#file-content .code-view .lines-num ol li.active,
|
||||
#file-content .code-view .lines-code ol li.active,
|
||||
#file-content .code-view .lines-num .hljs li.active,
|
||||
#file-content .code-view .lines-code .hljs li.active {
|
||||
background: #ffffdd;
|
||||
}
|
||||
.repository.file.list .sidebar {
|
||||
@@ -1895,7 +1898,7 @@ footer .ui.language .menu {
|
||||
max-width: 100%;
|
||||
padding: 5px 5px 0 5px;
|
||||
}
|
||||
.repository .code-view {
|
||||
#file-content .code-view {
|
||||
overflow: auto;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
@@ -2157,13 +2160,13 @@ footer .ui.language .menu {
|
||||
.page.buttons {
|
||||
padding-top: 15px;
|
||||
}
|
||||
.ui.comments .dropzone {
|
||||
.ui.comments .dropzone, .ui.upload .dropzone {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
border: 2px dashed #0087F7;
|
||||
box-shadow: none!important;
|
||||
}
|
||||
.ui.comments .dropzone .dz-error-message {
|
||||
.ui.comments .dropzone .dz-error-message, .ui.upload .dropzone .dz-error-message {
|
||||
top: 140px;
|
||||
}
|
||||
.settings .content {
|
||||
@@ -2797,3 +2800,197 @@ footer .ui.language .menu {
|
||||
.ui.user.list .item .description a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.btn-octicon {
|
||||
display: inline-block;
|
||||
padding: 5px;
|
||||
margin-left: 5px;
|
||||
line-height: 1;
|
||||
color: #767676;
|
||||
vertical-align: middle;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
outline: none;
|
||||
}
|
||||
.btn-octicon:hover {
|
||||
color: #4078c0;
|
||||
}
|
||||
.btn-octicon-danger:hover {
|
||||
color: #bd2c00;
|
||||
}
|
||||
.btn-octicon.disabled {
|
||||
color: #bbb;
|
||||
cursor: default;
|
||||
}
|
||||
.inline-form {
|
||||
display: inline-block;
|
||||
}
|
||||
.ui.form .breadcrumb input {
|
||||
min-height: 34px;
|
||||
padding: 7px 8px;
|
||||
color: #333;
|
||||
vertical-align: middle;
|
||||
background-color: #fff;
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 8px center;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
outline: none;
|
||||
box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
|
||||
width: inherit;
|
||||
}
|
||||
#file-actions {
|
||||
padding-left: 20px;
|
||||
}
|
||||
.CodeMirror.cm-s-default {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
height: 600px;
|
||||
padding: 0 !important;
|
||||
}
|
||||
.commit-form-wrapper {
|
||||
padding-left: 64px;
|
||||
}
|
||||
.commit-form {
|
||||
position: relative;
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.commit-form-wrapper .commit-form-avatar {
|
||||
float: left;
|
||||
margin-left: -64px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.commit-form::before {
|
||||
border-width: 8px;
|
||||
border-color: transparent;
|
||||
border-right-color: #ddd;
|
||||
position: absolute;
|
||||
top: 11px;
|
||||
right: 100%;
|
||||
left: -16px;
|
||||
display: block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
pointer-events: none;
|
||||
content: " ";
|
||||
border-style: solid solid outset;
|
||||
}
|
||||
.form-checkbox input[type=checkbox], .form-checkbox input[type=radio] {
|
||||
float: left;
|
||||
margin: 2px 0 0 -20px;
|
||||
vertical-align: middle;
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
}
|
||||
.branch-name {
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
color: rgba(0,0,0,0.5);
|
||||
background-color: rgba(209,227,237,0.5);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.form-control, .form-select {
|
||||
min-height: 34px;
|
||||
padding: 7px 8px;
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
vertical-align: middle;
|
||||
background-color: #fff;
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 8px center;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
outline: none;
|
||||
box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
|
||||
}
|
||||
.form-control.input-contrast {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
.form-control.mr-2 {
|
||||
margin-right: 6px !important;
|
||||
}
|
||||
.quick-pull-choice .new-branch-name-input input {
|
||||
width: 240px !important;
|
||||
padding-left: 26px !important;
|
||||
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
}
|
||||
.quick-pull-choice .new-branch-name-input .quick-pull-new-branch-icon {
|
||||
position: absolute;
|
||||
top: 9px;
|
||||
left: 10px;
|
||||
color: #b0c4ce;
|
||||
}
|
||||
.text-muted, .text-gray {
|
||||
color: #767676 !important;
|
||||
}
|
||||
.quick-pull-choice .new-branch-name-input {
|
||||
position: relative;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.quick-pull-choice .quick-pull-branch-name {
|
||||
display: none;
|
||||
padding-left: 48px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.quick-pull-choice.will-create-branch .quick-pull-branch-name {
|
||||
display: inline-block;
|
||||
}
|
||||
.nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
#file-buttons {
|
||||
padding-right: 15px;
|
||||
}
|
||||
.repository .ui.container .ui.breadcrumb {
|
||||
font-size: 1.5em;
|
||||
color: #767676;
|
||||
max-width: 600px;
|
||||
}
|
||||
.repository .ui.container .item:first-child .ui.breadcrumb {
|
||||
max-width: none;
|
||||
}
|
||||
.repository .ui.container .ui.breadcrumb.field {
|
||||
margin-bottom: 10px !important;
|
||||
}
|
||||
.repo-edit-file-cancel {
|
||||
padding-left: 10px;
|
||||
}
|
||||
#new-branch-item {
|
||||
display:none;
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
padding: .71428571em 1.14285714em!important;
|
||||
background: 0 0!important;
|
||||
color: rgba(0,0,0,.87)!important;
|
||||
text-transform: none!important;
|
||||
box-shadow: none!important;
|
||||
-webkit-transition: none!important;
|
||||
transition: none!important;
|
||||
border-top: none;
|
||||
padding-right: calc(1.14285714rem + 17px)!important;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
line-height: 1.1;
|
||||
}
|
||||
#new-branch-item:hover {
|
||||
background: rgba(0,0,0,.05)!important;
|
||||
color: rgba(0,0,0,.95)!important;
|
||||
}
|
||||
#new-branch-item .icon {
|
||||
float: left;
|
||||
margin-left: -15px;
|
||||
}
|
||||
#new-branch-item .description {
|
||||
margin-top: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.repository .ui.container .ui.breadcrumb {
|
||||
font-size: 1.5em;
|
||||
color: #767676;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
@@ -28,6 +28,61 @@ function initCommentPreviewTab($form) {
|
||||
buttonsClickOnEnter();
|
||||
}
|
||||
|
||||
var previewTab;
|
||||
var previewTabApis;
|
||||
|
||||
function initEditPreviewTab($form) {
|
||||
var $tab_menu = $form.find('.tabular.menu');
|
||||
$tab_menu.find('.item').tab();
|
||||
previewTab = $tab_menu.find('.item[data-tab="' + $tab_menu.data('preview') + '"]');
|
||||
|
||||
if (previewTab.length) {
|
||||
previewTabApis = previewTab.data('preview-apis').split(',');
|
||||
previewTab.click(function () {
|
||||
var $this = $(this);
|
||||
$.post($this.data('url'), {
|
||||
"_csrf": csrf,
|
||||
"mode": "gfm",
|
||||
"context": $this.data('context'),
|
||||
"text": $form.find('.tab.segment[data-tab="' + $tab_menu.data('write') + '"] textarea').val()
|
||||
},
|
||||
function (data) {
|
||||
var $preview_tab = $form.find('.tab.segment[data-tab="' + $tab_menu.data('preview') + '"]');
|
||||
$preview_tab.html(data);
|
||||
emojify.run($preview_tab[0]);
|
||||
$('pre code', $preview_tab[0]).each(function (i, block) {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
buttonsClickOnEnter();
|
||||
}
|
||||
|
||||
function initEditDiffTab($form) {
|
||||
var $tab_menu = $form.find('.tabular.menu');
|
||||
$tab_menu.find('.item').tab();
|
||||
$tab_menu.find('.item[data-tab="' + $tab_menu.data('diff') + '"]').click(function () {
|
||||
var $this = $(this);
|
||||
$.post($this.data('url'), {
|
||||
"_csrf": csrf,
|
||||
"context": $this.data('context'),
|
||||
"content": $form.find('.tab.segment[data-tab="' + $tab_menu.data('write') + '"] textarea').val()
|
||||
},
|
||||
function (data) {
|
||||
var $diff_tab = $form.find('.tab.segment[data-tab="' + $tab_menu.data('diff') + '"]');
|
||||
$diff_tab.html(data);
|
||||
emojify.run($diff_tab[0]);
|
||||
initCodeView()
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
buttonsClickOnEnter();
|
||||
}
|
||||
|
||||
function initCommentForm() {
|
||||
if ($('.comment.form').length == 0) {
|
||||
return
|
||||
@@ -145,6 +200,11 @@ function initCommentForm() {
|
||||
selectItem('.select-assignee', '#assignee_id');
|
||||
}
|
||||
|
||||
function initEditForm() {
|
||||
initEditPreviewTab($('.edit.form'));
|
||||
initEditDiffTab($('.edit.form'));
|
||||
}
|
||||
|
||||
function initInstall() {
|
||||
if ($('.install').length == 0) {
|
||||
return;
|
||||
@@ -450,7 +510,7 @@ function initRepository() {
|
||||
|
||||
// Change status
|
||||
var $status_btn = $('#status-button');
|
||||
$('#content').keyup(function () {
|
||||
$('#edit_area').keyup(function () {
|
||||
if ($(this).val().length == 0) {
|
||||
$status_btn.text($status_btn.data('status'))
|
||||
} else {
|
||||
@@ -516,15 +576,10 @@ function initRepositoryCollaboration() {
|
||||
});
|
||||
}
|
||||
|
||||
function initWiki() {
|
||||
if ($('.repository.wiki').length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ($('.repository.wiki.new').length > 0) {
|
||||
var $edit_area = $('#edit-area');
|
||||
var simplemde = new SimpleMDE({
|
||||
function initWikiForm() {
|
||||
var $edit_area = $('.repository.wiki textarea#edit_area');
|
||||
if ($edit_area.length > 0) {
|
||||
new SimpleMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
element: $edit_area[0],
|
||||
forceSync: true,
|
||||
@@ -549,18 +604,284 @@ function initWiki() {
|
||||
renderingConfig: {
|
||||
singleLineBreaks: false
|
||||
},
|
||||
spellChecker: false,
|
||||
indentWithTabs: false,
|
||||
tabSize: 4,
|
||||
spellChecker: false,
|
||||
toolbar: ["bold", "italic", "strikethrough", "|",
|
||||
"heading", "heading-1", "heading-2", "heading-3", "|",
|
||||
"heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
|
||||
"code", "quote", "|",
|
||||
"unordered-list", "ordered-list", "|",
|
||||
"link", "image", "horizontal-rule", "|",
|
||||
"preview", "fullscreen"]
|
||||
"link", "image", "table", "horizontal-rule", "|",
|
||||
"clean-block", "preview", "fullscreen", "side-by-side"]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function initIssueForm() {
|
||||
var $edit_area = $('.repository.issue textarea.edit_area');
|
||||
if ($edit_area.length > 0) {
|
||||
$edit_area.each(function (i, edit_area) {
|
||||
new SimpleMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
element: edit_area[0],
|
||||
forceSync: true,
|
||||
previewRender: function (plainText, preview) { // Async method
|
||||
setTimeout(function () {
|
||||
// FIXME: still send render request when return back to edit mode
|
||||
$.post($edit_area.data('url'), {
|
||||
"_csrf": csrf,
|
||||
"mode": "gfm",
|
||||
"context": $edit_area.data('context'),
|
||||
"text": plainText
|
||||
},
|
||||
function (data) {
|
||||
preview.innerHTML = '<div class="markdown">' + data + '</div>';
|
||||
emojify.run($('.editor-preview')[0]);
|
||||
}
|
||||
);
|
||||
}, 0);
|
||||
|
||||
return "Loading...";
|
||||
},
|
||||
renderingConfig: {
|
||||
singleLineBreaks: false
|
||||
},
|
||||
indentWithTabs: false,
|
||||
tabSize: 4,
|
||||
spellChecker: false,
|
||||
toolbar: ["bold", "italic", "strikethrough", "|",
|
||||
"code", "quote", "|",
|
||||
"unordered-list", "ordered-list", "|",
|
||||
"link", "image", "table"]
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var editArea;
|
||||
var editFilename;
|
||||
var smdEditor;
|
||||
var cmEditor;
|
||||
var mdFileExtensions;
|
||||
var lineWrapExtensions;
|
||||
|
||||
// For IE
|
||||
String.prototype.endsWith = function (pattern) {
|
||||
var d = this.length - pattern.length;
|
||||
return d >= 0 && this.lastIndexOf(pattern) === d;
|
||||
};
|
||||
|
||||
// Adding function to get the cursor position in a text field to jquery objects
|
||||
(function ($, undefined) {
|
||||
$.fn.getCursorPosition = function () {
|
||||
var el = $(this).get(0);
|
||||
var pos = 0;
|
||||
if ('selectionStart' in el) {
|
||||
pos = el.selectionStart;
|
||||
} else if ('selection' in document) {
|
||||
el.focus();
|
||||
var Sel = document.selection.createRange();
|
||||
var SelLength = document.selection.createRange().text.length;
|
||||
Sel.moveStart('character', -el.value.length);
|
||||
pos = Sel.text.length - SelLength;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
function initEditor() {
|
||||
editFilename = $("#file-name");
|
||||
editFilename.keyup(function (e) {
|
||||
var sections = $('.breadcrumb span.section');
|
||||
var dividers = $('.breadcrumb div.divider');
|
||||
if (e.keyCode == 8) {
|
||||
if ($(this).getCursorPosition() == 0) {
|
||||
if (sections.length > 0) {
|
||||
var value = sections.last().find('a').text();
|
||||
$(this).val(value + $(this).val());
|
||||
$(this)[0].setSelectionRange(value.length, value.length);
|
||||
sections.last().remove();
|
||||
dividers.last().remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.keyCode == 191) {
|
||||
var parts = $(this).val().split('/');
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
var value = parts[i];
|
||||
if (i < parts.length - 1) {
|
||||
if (value.length) {
|
||||
$('<span class="section"><a href="#">' + value + '</a></span>').insertBefore($(this));
|
||||
$('<div class="divider"> / </div>').insertBefore($(this));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(this).val(value);
|
||||
}
|
||||
$(this)[0].setSelectionRange(0, 0);
|
||||
}
|
||||
}
|
||||
var parts = [];
|
||||
$('.breadcrumb span.section').each(function (i, element) {
|
||||
element = $(element);
|
||||
if (element.find('a').length) {
|
||||
parts.push(element.find('a').text());
|
||||
} else {
|
||||
parts.push(element.text());
|
||||
}
|
||||
});
|
||||
if ($(this).val())
|
||||
parts.push($(this).val());
|
||||
$('#tree-name').val(parts.join('/'));
|
||||
}).trigger('keyup');
|
||||
|
||||
editArea = $('.repository.edit textarea#edit_area');
|
||||
|
||||
if (!editArea.length)
|
||||
return;
|
||||
|
||||
mdFileExtensions = editArea.data("md-file-extensions").split(",");
|
||||
lineWrapExtensions = editArea.data("line-wrap-extensions").split(",");
|
||||
|
||||
editFilename.on("keyup", function (e) {
|
||||
var val = editFilename.val(), m, mode, spec, extension, extWithDot, previewLink, dataUrl, apiCall;
|
||||
extension = extWithDot = "";
|
||||
if (m = /.+\.([^.]+)$/.exec(val)) {
|
||||
extension = m[1];
|
||||
extWithDot = "." + extension;
|
||||
}
|
||||
|
||||
var info = CodeMirror.findModeByExtension(extension);
|
||||
previewLink = $('a[data-tab=preview]');
|
||||
if (info) {
|
||||
mode = info.mode;
|
||||
spec = info.mime;
|
||||
apiCall = mode;
|
||||
}
|
||||
else {
|
||||
apiCall = extension
|
||||
}
|
||||
|
||||
if (previewLink.length && apiCall && previewTabApis && previewTabApis.length && previewTabApis.indexOf(apiCall) >= 0) {
|
||||
dataUrl = previewLink.data('url');
|
||||
previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode));
|
||||
previewLink.show();
|
||||
}
|
||||
else {
|
||||
previewLink.hide();
|
||||
}
|
||||
|
||||
// If this file is a Markdown extensions, we will load that editor and return
|
||||
if (mdFileExtensions.indexOf(extWithDot) >= 0) {
|
||||
if (setSimpleMDE()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Else we are going to use CodeMirror
|
||||
if (!cmEditor) {
|
||||
if (!setCodeMirror())
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode) {
|
||||
cmEditor.setOption("mode", spec);
|
||||
CodeMirror.autoLoadMode(cmEditor, mode);
|
||||
}
|
||||
|
||||
if (lineWrapExtensions.indexOf(extWithDot) >= 0) {
|
||||
cmEditor.setOption("lineWrapping", true);
|
||||
}
|
||||
else {
|
||||
cmEditor.setOption("lineWrapping", false);
|
||||
}
|
||||
}).trigger('keyup');
|
||||
}
|
||||
|
||||
function setSimpleMDE() {
|
||||
if (cmEditor) {
|
||||
cmEditor.toTextArea();
|
||||
cmEditor = null;
|
||||
}
|
||||
|
||||
if (smdEditor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
smdEditor = new SimpleMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
element: editArea[0],
|
||||
forceSync: true,
|
||||
renderingConfig: {
|
||||
singleLineBreaks: false
|
||||
},
|
||||
indentWithTabs: false,
|
||||
tabSize: 4,
|
||||
spellChecker: false,
|
||||
previewRender: function (plainText, preview) { // Async method
|
||||
setTimeout(function () {
|
||||
// FIXME: still send render request when return back to edit mode
|
||||
$.post(editArea.data('url'), {
|
||||
"_csrf": csrf,
|
||||
"mode": "gfm",
|
||||
"context": editArea.data('context'),
|
||||
"text": plainText
|
||||
},
|
||||
function (data) {
|
||||
preview.innerHTML = '<div class="markdown">' + data + '</div>';
|
||||
emojify.run($('.editor-preview')[0]);
|
||||
}
|
||||
);
|
||||
}, 0);
|
||||
|
||||
return "Loading...";
|
||||
},
|
||||
toolbar: ["bold", "italic", "strikethrough", "|",
|
||||
"heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
|
||||
"code", "quote", "|",
|
||||
"unordered-list", "ordered-list", "|",
|
||||
"link", "image", "table", "horizontal-rule", "|",
|
||||
"clean-block", "preview", "fullscreen", "side-by-side"]
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function setCodeMirror() {
|
||||
if (smdEditor) {
|
||||
smdEditor.toTextArea();
|
||||
smdEditor = null;
|
||||
}
|
||||
|
||||
if (cmEditor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cmEditor = CodeMirror.fromTextArea(editArea[0], {
|
||||
lineNumbers: true
|
||||
});
|
||||
cmEditor.on("change", function (cm, change) {
|
||||
editArea.val(cm.getValue());
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function initQuickPull() {
|
||||
$('.js-quick-pull-choice-option').change(function () {
|
||||
quickPullChoiceChange();
|
||||
});
|
||||
quickPullChoiceChange();
|
||||
}
|
||||
|
||||
function quickPullChoiceChange() {
|
||||
var radio = $('.js-quick-pull-choice-option:checked');
|
||||
if (radio.val() == 'commit-to-new-branch')
|
||||
$('.quick-pull-branch-name').show();
|
||||
else
|
||||
$('.quick-pull-branch-name').hide();
|
||||
}
|
||||
|
||||
function initOrganization() {
|
||||
if ($('.organization').length == 0) {
|
||||
return;
|
||||
@@ -867,6 +1188,37 @@ function searchRepositories() {
|
||||
hideWhenLostFocus('#search-repo-box .results', '#search-repo-box');
|
||||
}
|
||||
|
||||
function initCodeView() {
|
||||
if ($('.code-view .linenums').length > 0) {
|
||||
$(document).on('click', '.lines-num span', function (e) {
|
||||
var $select = $(this);
|
||||
var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
|
||||
selectRange($list, $list.filter('[rel=' + $select.attr('id') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
|
||||
deSelect();
|
||||
});
|
||||
|
||||
$(window).on('hashchange', function (e) {
|
||||
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
||||
var $list = $('.code-view ol.linenums > li');
|
||||
var $first;
|
||||
if (m) {
|
||||
$first = $list.filter('.' + m[1]);
|
||||
selectRange($list, $first, $list.filter('.' + m[2]));
|
||||
$("html, body").scrollTop($first.offset().top - 200);
|
||||
return;
|
||||
}
|
||||
m = window.location.hash.match(/^#(L\d+)$/);
|
||||
if (m) {
|
||||
$first = $list.filter('.' + m[1]);
|
||||
selectRange($list, $first);
|
||||
$("html, body").scrollTop($first.offset().top - 200);
|
||||
}
|
||||
}).trigger('hashchange');
|
||||
}
|
||||
}
|
||||
|
||||
var $dropz;
|
||||
|
||||
$(document).ready(function () {
|
||||
csrf = $('meta[name=_csrf]').attr("content");
|
||||
suburl = $('meta[name=_suburl]').attr("content");
|
||||
@@ -916,12 +1268,12 @@ $(document).ready(function () {
|
||||
}
|
||||
|
||||
// Dropzone
|
||||
if ($('#dropzone').length > 0) {
|
||||
var $dropz = $('#dropzone');
|
||||
if ($dropz.length > 0) {
|
||||
// Disable auto discover for all elements:
|
||||
Dropzone.autoDiscover = false;
|
||||
|
||||
var filenameDict = {};
|
||||
var $dropz = $('#dropzone');
|
||||
$dropz.dropzone({
|
||||
url: $dropz.data('upload-url'),
|
||||
headers: {"X-Csrf-Token": csrf},
|
||||
@@ -936,12 +1288,16 @@ $(document).ready(function () {
|
||||
init: function () {
|
||||
this.on("success", function (file, data) {
|
||||
filenameDict[file.name] = data.uuid;
|
||||
$('.attachments').append('<input id="' + data.uuid + '" name="attachments" type="hidden" value="' + data.uuid + '">');
|
||||
var input = $('<input id="' + data.uuid + '" name="files" type="hidden">').val(data.uuid);
|
||||
$('.files').append(input);
|
||||
});
|
||||
this.on("removedfile", function (file) {
|
||||
if (file.name in filenameDict) {
|
||||
$('#' + filenameDict[file.name]).remove();
|
||||
}
|
||||
if ($dropz.data('remove-url') && $dropz.data('csrf')) {
|
||||
$.post($dropz.data('remove-url'), {file: filenameDict[file.name], _csrf: $dropz.data('csrf')});
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -975,6 +1331,15 @@ $(document).ready(function () {
|
||||
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
|
||||
});
|
||||
|
||||
// Clipboard for copying filename on edit page
|
||||
if ($('.clipboard-tree-name').length) {
|
||||
new Clipboard(document.querySelector('.clipboard-tree-name'), {
|
||||
text: function () {
|
||||
return $('#tree-name').val();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helpers.
|
||||
$('.delete-button').click(function () {
|
||||
var $this = $(this);
|
||||
@@ -1038,10 +1403,14 @@ $(document).ready(function () {
|
||||
initCommentForm();
|
||||
initInstall();
|
||||
initRepository();
|
||||
initWiki();
|
||||
initWikiForm();
|
||||
initIssueForm();
|
||||
initEditForm();
|
||||
initEditor();
|
||||
initOrganization();
|
||||
initWebhook();
|
||||
initAdmin();
|
||||
initQuickPull();
|
||||
|
||||
var routes = {
|
||||
'div.user.settings': initUserSettings,
|
||||
@@ -1057,76 +1426,50 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
function changeHash(hash) {
|
||||
if (history.pushState) {
|
||||
history.pushState(null, null, hash);
|
||||
}
|
||||
else {
|
||||
location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
||||
function deSelect() {
|
||||
if (window.getSelection) {
|
||||
window.getSelection().removeAllRanges();
|
||||
} else {
|
||||
document.selection.empty();
|
||||
}
|
||||
}
|
||||
|
||||
function selectRange($list, $select, $from) {
|
||||
$list.removeClass('active');
|
||||
if ($from) {
|
||||
var a = parseInt($select.attr('rel').substr(1));
|
||||
var b = parseInt($from.attr('rel').substr(1));
|
||||
var c;
|
||||
if (a != b) {
|
||||
if (a > b) {
|
||||
c = a;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
var classes = [];
|
||||
for (var i = a; i <= b; i++) {
|
||||
classes.push('.L' + i);
|
||||
}
|
||||
$list.filter(classes.join(',')).addClass('active');
|
||||
changeHash('#L' + a + '-' + 'L' + b);
|
||||
return
|
||||
}
|
||||
}
|
||||
$select.addClass('active');
|
||||
changeHash('#' + $select.attr('rel'));
|
||||
}
|
||||
|
||||
$(window).load(function () {
|
||||
function changeHash(hash) {
|
||||
if (history.pushState) {
|
||||
history.pushState(null, null, hash);
|
||||
}
|
||||
else {
|
||||
location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
||||
function deSelect() {
|
||||
if (window.getSelection) {
|
||||
window.getSelection().removeAllRanges();
|
||||
} else {
|
||||
document.selection.empty();
|
||||
}
|
||||
}
|
||||
|
||||
function selectRange($list, $select, $from) {
|
||||
$list.removeClass('active');
|
||||
if ($from) {
|
||||
var a = parseInt($select.attr('rel').substr(1));
|
||||
var b = parseInt($from.attr('rel').substr(1));
|
||||
var c;
|
||||
if (a != b) {
|
||||
if (a > b) {
|
||||
c = a;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
var classes = [];
|
||||
for (var i = a; i <= b; i++) {
|
||||
classes.push('.L' + i);
|
||||
}
|
||||
$list.filter(classes.join(',')).addClass('active');
|
||||
changeHash('#L' + a + '-' + 'L' + b);
|
||||
return
|
||||
}
|
||||
}
|
||||
$select.addClass('active');
|
||||
changeHash('#' + $select.attr('rel'));
|
||||
}
|
||||
|
||||
// Code view.
|
||||
if ($('.code-view .linenums').length > 0) {
|
||||
$(document).on('click', '.lines-num span', function (e) {
|
||||
var $select = $(this);
|
||||
var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
|
||||
selectRange($list, $list.filter('[rel=' + $select.attr('id') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
|
||||
deSelect();
|
||||
});
|
||||
|
||||
$(window).on('hashchange', function (e) {
|
||||
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
||||
var $list = $('.code-view ol.linenums > li');
|
||||
var $first;
|
||||
if (m) {
|
||||
$first = $list.filter('.' + m[1]);
|
||||
selectRange($list, $first, $list.filter('.' + m[2]));
|
||||
$("html, body").scrollTop($first.offset().top - 200);
|
||||
return;
|
||||
}
|
||||
m = window.location.hash.match(/^#(L\d+)$/);
|
||||
if (m) {
|
||||
$first = $list.filter('.' + m[1]);
|
||||
selectRange($list, $first);
|
||||
$("html, body").scrollTop($first.offset().top - 200);
|
||||
}
|
||||
}).trigger('hashchange');
|
||||
}
|
||||
initCodeView();
|
||||
|
||||
// Repo clone url.
|
||||
if ($('#repo-clone-url').length > 0) {
|
||||
@@ -1135,7 +1478,6 @@ $(window).load(function () {
|
||||
if ($('#repo-clone-ssh').click().length === 0) {
|
||||
$('#repo-clone-https').click();
|
||||
}
|
||||
;
|
||||
break;
|
||||
default:
|
||||
$('#repo-clone-https').click();
|
||||
|
Reference in New Issue
Block a user