mirror of
https://github.com/DMOJ/online-judge.git
synced 2024-11-25 16:32:37 +08:00
Completely remove Pagedown
This commit is contained in:
parent
ce1196f74f
commit
2035e606f3
3
.flake8
3
.flake8
@ -18,9 +18,6 @@ per-file-ignores =
|
||||
./judge/management/commands/runmoss.py:F403,F405
|
||||
# E501: line too long, ignore in migrations
|
||||
./judge/migrations/*.py:E501
|
||||
# E303: too many blank lines
|
||||
# PyCharm likes to have double lines between class/def in an if statement.
|
||||
./judge/widgets/pagedown.py:E303
|
||||
exclude =
|
||||
# belongs to the user
|
||||
./dmoj/local_settings.py,
|
||||
|
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,7 +1,3 @@
|
||||
[submodule "resources/pagedown"]
|
||||
path = resources/pagedown
|
||||
url = https://github.com/DMOJ/dmoj-pagedown.git
|
||||
branch = master
|
||||
[submodule "resources/libs"]
|
||||
path = resources/libs
|
||||
url = https://github.com/DMOJ/site-assets.git
|
||||
|
@ -269,7 +269,6 @@ INSTALLED_APPS += (
|
||||
'social_django',
|
||||
'compressor',
|
||||
'django_ace',
|
||||
'pagedown',
|
||||
'sortedm2m',
|
||||
'statici18n',
|
||||
'impersonate',
|
||||
|
@ -1,5 +1,4 @@
|
||||
from judge.widgets.checkbox import CheckboxSelectMultipleWithSelectAll
|
||||
from judge.widgets.martor import *
|
||||
from judge.widgets.mixins import CompressorWidgetMixin
|
||||
from judge.widgets.pagedown import *
|
||||
from judge.widgets.select2 import *
|
||||
|
@ -1,67 +0,0 @@
|
||||
from django.forms.utils import flatatt
|
||||
from django.template.loader import get_template
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.html import conditional_escape
|
||||
|
||||
from judge.widgets.mixins import CompressorWidgetMixin
|
||||
|
||||
__all__ = ['PagedownWidget', 'MathJaxPagedownWidget', 'HeavyPreviewPageDownWidget']
|
||||
|
||||
try:
|
||||
from pagedown.widgets import PagedownWidget as OldPagedownWidget
|
||||
except ImportError:
|
||||
PagedownWidget = None
|
||||
MathJaxPagedownWidget = None
|
||||
HeavyPreviewPageDownWidget = None
|
||||
else:
|
||||
class PagedownWidget(CompressorWidgetMixin, OldPagedownWidget):
|
||||
# The goal here is to compress all the pagedown JS into one file.
|
||||
# We do not want any further compress down the chain, because
|
||||
# 1. we'll create multiple large JS files to download.
|
||||
# 2. this is not a problem here because all the pagedown JS files will be used together.
|
||||
compress_js = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('css', ())
|
||||
super(PagedownWidget, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class MathJaxPagedownWidget(PagedownWidget):
|
||||
class Media:
|
||||
js = [
|
||||
'mathjax_config.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-chtml.min.js',
|
||||
'pagedown_math.js',
|
||||
]
|
||||
|
||||
|
||||
class HeavyPreviewPageDownWidget(PagedownWidget):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('template', 'pagedown.html')
|
||||
self.preview_url = kwargs.pop('preview')
|
||||
self.preview_timeout = kwargs.pop('preview_timeout', None)
|
||||
self.hide_preview_button = kwargs.pop('hide_preview_button', False)
|
||||
super(HeavyPreviewPageDownWidget, self).__init__(*args, **kwargs)
|
||||
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
if value is None:
|
||||
value = ''
|
||||
final_attrs = self.build_attrs(attrs, {'name': name})
|
||||
if 'class' not in final_attrs:
|
||||
final_attrs['class'] = ''
|
||||
final_attrs['class'] += ' wmd-input'
|
||||
return get_template(self.template).render(self.get_template_context(final_attrs, value))
|
||||
|
||||
def get_template_context(self, attrs, value):
|
||||
return {
|
||||
'attrs': flatatt(attrs),
|
||||
'body': conditional_escape(force_str(value)),
|
||||
'id': attrs['id'],
|
||||
'show_preview': self.show_preview,
|
||||
'preview_url': self.preview_url,
|
||||
'preview_timeout': self.preview_timeout,
|
||||
'extra_classes': 'dmmd-no-button' if self.hide_preview_button else None,
|
||||
}
|
||||
|
||||
class Media:
|
||||
js = ['dmmd-preview.js']
|
@ -1,7 +1,6 @@
|
||||
Django>=3.2,<4
|
||||
django_compressor>=3
|
||||
django-mptt>=0.13
|
||||
django-pagedown<2
|
||||
django-registration-redux>=2.10
|
||||
django-reversion>=3.0.5,<4
|
||||
django-social-share
|
||||
|
@ -1,10 +0,0 @@
|
||||
.wmd-wrapper {
|
||||
padding-right: 15px !important;
|
||||
}
|
||||
|
||||
|
||||
.wmd-preview {
|
||||
margin-top: 15px;
|
||||
padding: 15px;
|
||||
word-break: break-word;
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
$(function () {
|
||||
window.register_dmmd_preview = function ($preview) {
|
||||
var $form = $preview.parents('form').first();
|
||||
var $update = $preview.find('.dmmd-preview-update');
|
||||
var $content = $preview.find('.dmmd-preview-content');
|
||||
var preview_url = $preview.attr('data-preview-url');
|
||||
var $textarea = $('#' + $preview.attr('data-textarea-id'));
|
||||
|
||||
// Submit the form if Ctrl+Enter is pressed in pagedown textarea.
|
||||
$textarea.keydown(function (ev) {
|
||||
// Ctrl+Enter pressed (metaKey used to support command key on mac).
|
||||
if ((ev.metaKey || ev.ctrlKey) && ev.which == 13) {
|
||||
$form.submit();
|
||||
}
|
||||
});
|
||||
|
||||
$update.click(function () {
|
||||
var text = $textarea.val();
|
||||
if (text) {
|
||||
$preview.addClass('dmmd-preview-stale');
|
||||
$.post(preview_url, {
|
||||
content: text,
|
||||
csrfmiddlewaretoken: $.cookie('csrftoken')
|
||||
}, function (result) {
|
||||
$content.html(result);
|
||||
$preview.addClass('dmmd-preview-has-content').removeClass('dmmd-preview-stale');
|
||||
|
||||
var $jax = $content.find('.require-mathjax-support');
|
||||
if ($jax.length) {
|
||||
if (!('MathJax' in window)) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: $jax.attr('data-config'),
|
||||
dataType: 'script',
|
||||
cache: true,
|
||||
success: function () {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-chtml.min.js',
|
||||
dataType: 'script',
|
||||
cache: true,
|
||||
success: function () {
|
||||
MathJax.typesetPromise([$content[0]]).then(function () {
|
||||
$content.find('.tex-image').hide();
|
||||
$content.find('.tex-text').show();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MathJax.typesetPromise([$content[0]]).then(function () {
|
||||
$content.find('.tex-image').hide();
|
||||
$content.find('.tex-text').show();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$content.empty();
|
||||
$preview.removeClass('dmmd-preview-has-content').removeClass('dmmd-preview-stale');
|
||||
}
|
||||
}).click();
|
||||
|
||||
var timeout = $preview.attr('data-timeout');
|
||||
var last_event = null;
|
||||
var last_text = $textarea.val();
|
||||
if (timeout) {
|
||||
$textarea.on('keyup paste', function () {
|
||||
var text = $textarea.val();
|
||||
if (last_text == text) return;
|
||||
last_text = text;
|
||||
|
||||
$preview.addClass('dmmd-preview-stale');
|
||||
if (last_event)
|
||||
clearTimeout(last_event);
|
||||
last_event = setTimeout(function () {
|
||||
$update.click();
|
||||
last_event = null;
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$('.dmmd-preview').each(function () {
|
||||
register_dmmd_preview($(this));
|
||||
});
|
||||
|
||||
if ('django' in window && 'jQuery' in window.django)
|
||||
django.jQuery(document).on('formset:added', function(event, $row) {
|
||||
var $preview = $row.find('.dmmd-preview');
|
||||
if ($preview.length) {
|
||||
var id = $row.attr('id');
|
||||
id = id.substr(id.lastIndexOf('-') + 1);
|
||||
$preview.attr('data-textarea-id', $preview.attr('data-textarea-id').replace('__prefix__', id));
|
||||
register_dmmd_preview($preview);
|
||||
}
|
||||
});
|
||||
});
|
@ -1,43 +0,0 @@
|
||||
@import "vars";
|
||||
|
||||
div.dmmd-preview {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div.dmmd-preview-update {
|
||||
background: $color_primary25;
|
||||
color: $color_primary75;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
height: 2em;
|
||||
line-height: 2em;
|
||||
}
|
||||
|
||||
div.dmmd-preview-content {
|
||||
padding: 0 7px;
|
||||
}
|
||||
|
||||
div.dmmd-preview.dmmd-preview-has-content div.dmmd-preview-update {
|
||||
border-radius: 4px 4px 0 0;
|
||||
}
|
||||
|
||||
div.dmmd-preview-has-content div.dmmd-preview-content {
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
|
||||
div.dmmd-no-button div.dmmd-preview-update {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.dmmd-no-button div.dmmd-preview-content {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
div.dmmd-no-button:not(.dmmd-preview-has-content) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.dmmd-preview-stale {
|
||||
background: repeating-linear-gradient(-45deg, $color_primary0, $color_primary0 10px, $color_primary5 10px, $color_primary5 20px);
|
||||
}
|
@ -1 +0,0 @@
|
||||
Subproject commit 6e5eac43883a314d1e0dbc5e70069798859eacbc
|
@ -1,125 +0,0 @@
|
||||
@import "vars";
|
||||
|
||||
.wmd-panel {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.wmd-button-bar {
|
||||
width: 100%;
|
||||
background-color: Silver;
|
||||
}
|
||||
|
||||
.wmd-input {
|
||||
height: 300px;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
background: $color_primary0;
|
||||
border: 1px solid $color_primary50;
|
||||
font-family: Consolas, "Liberation Mono", Monaco, "Courier New", monospace !important;
|
||||
}
|
||||
|
||||
.wmd-preview {
|
||||
background: none;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.wmd-button-row {
|
||||
margin: 5px;
|
||||
padding: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.wmd-spacer {
|
||||
width: 15px;
|
||||
height: 20px;
|
||||
display: inline-block;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.wmd-button {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding-left: 2px;
|
||||
padding-right: 3px;
|
||||
display: inline-block;
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.wmd-button > span {
|
||||
@include vars-img;
|
||||
background: url($path_to_root + '/pagedown/wmd-buttons.png') no-repeat 0 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.wmd-prompt-background {
|
||||
background-color: Black;
|
||||
}
|
||||
|
||||
.wmd-prompt-dialog {
|
||||
border: 1px solid $color_primary25;
|
||||
background-color: $color_primary5;
|
||||
}
|
||||
|
||||
.wmd-prompt-dialog > div {
|
||||
font-size: 0.8em;
|
||||
font-family: arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.wmd-prompt-dialog > form > input[type="text"] {
|
||||
border: 1px solid $color_primary25;
|
||||
color: $color_primary100;
|
||||
}
|
||||
|
||||
.wmd-prompt-dialog > form > input[type="button"] {
|
||||
border: 1px solid $color_primary50;
|
||||
font-family: trebuchet MS, helvetica, sans-serif;
|
||||
font-size: 0.8em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.wmd-wrapper {
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
|
||||
.wmd-preview {
|
||||
margin-top: 15px;
|
||||
padding: 7px;
|
||||
background: $color_primary0;
|
||||
line-height: 1.5em;
|
||||
font-size: 1em;
|
||||
border: 1px solid $color_primary50;
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.wmd-preview:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wmd-preview h1, .wmd-preview h2, .wmd-preview h3, .wmd-preview h4, .wmd-preview h5, .wmd-preview h6 {
|
||||
font-weight: bold !important;
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
.wmd-preview:not(.dmmd-preview) h1 {
|
||||
font-size: 1.6em !important;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.wmd-preview:not(.dmmd-preview) h2 {
|
||||
font-size: 1.4em !important
|
||||
}
|
||||
|
||||
.wmd-preview:not(.dmmd-preview) h3 {
|
||||
font-size: 1em !important
|
||||
}
|
||||
|
||||
.wmd-preview:not(.dmmd-preview) h4, .wmd-preview:not(.dmmd-preview) h5, .wmd-preview:not(.dmmd-preview) h6 {
|
||||
font-size: .9em !important
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
function mathjax_pagedown($) {
|
||||
if ('MathJax' in window) {
|
||||
$.each(window.editors, function (id, editor) {
|
||||
var preview = $('div.wmd-preview#' + id + '_wmd_preview')[0];
|
||||
if (preview) {
|
||||
editor.hooks.chain('onPreviewRefresh', function () {
|
||||
MathJax.typeset([preview]);
|
||||
});
|
||||
MathJax.typeset([preview]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.mathjax_pagedown = mathjax_pagedown;
|
||||
|
||||
$(window).on('load', function () {
|
||||
(mathjax_pagedown)('$' in window ? $ : django.jQuery);
|
||||
});
|
@ -14,8 +14,6 @@
|
||||
@import "widgets";
|
||||
@import "featherlight";
|
||||
@import "comments";
|
||||
@import "pagedown-widget";
|
||||
@import "dmmd-preview";
|
||||
@import "submission";
|
||||
@import "contest";
|
||||
@import "misc";
|
||||
|
@ -6,18 +6,6 @@
|
||||
line-height: unset !important;
|
||||
}
|
||||
|
||||
.wmd-wrapper {
|
||||
padding-top: 2em;
|
||||
}
|
||||
|
||||
.wmd-wrapper ul.wmd-button-row {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.wmd-input {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
#content .content-description h1,
|
||||
#content .content-description h2,
|
||||
#content .content-description h3,
|
||||
@ -65,8 +53,3 @@ select#id_tags.django-select2 {
|
||||
max-width: unset;
|
||||
}
|
||||
}
|
||||
|
||||
.dmmd-preview-update {
|
||||
position: sticky;
|
||||
top: 38px;
|
||||
}
|
||||
|
@ -48,5 +48,4 @@
|
||||
{% if REQUIRE_JAX %}
|
||||
{% include "mathjax-load.html" %}
|
||||
{% endif %}
|
||||
{% include "comments/math.html" %}
|
||||
{% endblock %}
|
||||
|
@ -1,3 +0,0 @@
|
||||
{% compress js, inline %}
|
||||
<script src="{{ static('pagedown_math.js') }}"></script>
|
||||
{% endcompress %}
|
@ -244,8 +244,3 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block description_end %}{% endblock %}
|
||||
|
||||
{% block bodyend %}
|
||||
{{ super() }}
|
||||
{% include "comments/math.html" %}
|
||||
{% endblock %}
|
||||
|
@ -1,14 +0,0 @@
|
||||
<div id="{{ id|safe }}-wmd-wrapper" class="wmd-wrapper">
|
||||
<div class="wmd-panel">
|
||||
<div id="{{ id|safe }}_wmd_button_bar"></div>
|
||||
<textarea{{ attrs|safe }}>{{ body }}</textarea>
|
||||
</div>
|
||||
|
||||
{% if show_preview %}
|
||||
<div id="{{ id|safe }}-preview" data-preview-url="{{ preview_url }}" data-textarea-id="{{ id }}"
|
||||
data-timeout="{{ preview_timeout or '' }}" class="wmd-panel wmd-preview dmmd-preview {{ extra_classes }}">
|
||||
<div class="dmmd-preview-update"><i class="fa fa-refresh"></i> {{ _('Update preview') }}</div>
|
||||
<div class="dmmd-preview-content content-description"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
@ -1,9 +0,0 @@
|
||||
<div class="wmd-wrapper" id="{{ id }}-wmd-wrapper">
|
||||
<div class="wmd-panel">
|
||||
<div id="{{ id|safe }}_wmd_button_bar"></div>
|
||||
<textarea{{ attrs|safe }}>{{ body }}</textarea>
|
||||
</div>
|
||||
{% if show_preview %}
|
||||
<div id="{{ id|safe }}_wmd_preview" class="wmd-panel wmd-preview content-description"></div>
|
||||
{% endif %}
|
||||
</div>
|
@ -46,5 +46,4 @@
|
||||
{% if REQUIRE_JAX %}
|
||||
{% include "mathjax-load.html" %}
|
||||
{% endif %}
|
||||
{% include "comments/math.html" %}
|
||||
{% endblock %}
|
||||
|
@ -346,8 +346,3 @@
|
||||
{% include "comments/list.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block bodyend %}
|
||||
{{ super() }}
|
||||
{% include "comments/math.html" %}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user