Cloned DMOJ

This commit is contained in:
thanhluong 2020-01-21 15:35:58 +09:00
parent f623974b58
commit 49dc9ff10c
513 changed files with 132349 additions and 39 deletions

5
django_ace/__init__.py Normal file
View file

@ -0,0 +1,5 @@
"""
Django-ace originally from https://github.com/bradleyayers/django-ace.
"""
from .widgets import AceWidget

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

View file

@ -0,0 +1,58 @@
.django-ace-widget {
display: inline-block;
position: relative;
}
.django-ace-widget > div {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.django-ace-widget.loading {
display: none;
}
.django-ace-toolbar {
font-size: 12px;
text-align: left;
color: #555;
text-shadow: 0 1px 0 #fff;
border-bottom: 1px solid #d8d8d8;
background-color: #eaeaea;
background-image: -moz-linear-gradient(#fafafa, #eaeaea);
background-image: -webkit-linear-gradient(#fafafa, #eaeaea);
background-image: linear-gradient(#fafafa, #eaeaea);
background-repeat: repeat-x;
clear: both;
overflow: hidden;
}
.django-ace-max_min {
float: right;
padding: 5px;
background: url(img/expand.png) no-repeat 5px 5px;
display: block;
height: 16px;
width: 16px;
}
.django-ace-editor {
position: relative;
}
.django-ace-editor-fullscreen {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1000;
}
.django-ace-editor-fullscreen .django-ace-max_min {
background-image: url(img/contract.png);
}

View file

@ -0,0 +1,182 @@
(function () {
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
function getDocWidth() {
var D = document;
return Math.max(
Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
Math.max(D.body.clientWidth, D.documentElement.clientWidth)
);
}
function next(elem) {
// Credit to John Resig for this function
// taken from Pro JavaScript techniques
do {
elem = elem.nextSibling;
} while (elem && elem.nodeType != 1);
return elem;
}
function prev(elem) {
// Credit to John Resig for this function
// taken from Pro JavaScript techniques
do {
elem = elem.previousSibling;
} while (elem && elem.nodeType != 1);
return elem;
}
function redraw(element) {
element = $(element);
var n = document.createTextNode(' ');
element.appendChild(n);
(function () {
n.parentNode.removeChild(n)
}).defer();
return element;
}
function minimizeMaximize(widget, main_block, editor) {
if (window.fullscreen == true) {
main_block.className = 'django-ace-editor';
widget.style.width = window.ace_widget.width + 'px';
widget.style.height = window.ace_widget.height + 'px';
window.fullscreen = false;
}
else {
window.ace_widget = {
'width': widget.offsetWidth,
'height': widget.offsetHeight
};
main_block.className = 'django-ace-editor-fullscreen';
widget.style.height = getDocHeight() + 'px';
widget.style.width = getDocWidth() + 'px';
window.scrollTo(0, 0);
window.fullscreen = true;
}
editor.resize();
}
function apply_widget(widget) {
var div = widget.firstChild,
textarea = next(widget),
editor = ace.edit(div),
mode = widget.getAttribute('data-mode'),
theme = widget.getAttribute('data-theme'),
wordwrap = widget.getAttribute('data-wordwrap'),
toolbar = prev(widget),
main_block = toolbar.parentNode;
// Toolbar maximize/minimize button
var min_max = toolbar.getElementsByClassName('django-ace-max_min');
min_max[0].onclick = function () {
minimizeMaximize(widget, main_block, editor);
return false;
};
editor.getSession().setValue(textarea.value);
// the editor is initially absolute positioned
textarea.style.display = "none";
// options
if (mode) {
editor.getSession().setMode('ace/mode/' + mode);
}
if (theme) {
editor.setTheme("ace/theme/" + theme);
}
if (wordwrap == "true") {
editor.getSession().setUseWrapMode(true);
}
editor.getSession().on('change', function () {
textarea.value = editor.getSession().getValue();
});
editor.commands.addCommands([
{
name: 'Full screen',
bindKey: {win: 'Ctrl-F11', mac: 'Command-F11'},
exec: function (editor) {
minimizeMaximize(widget, main_block, editor);
},
readOnly: true // false if this command should not apply in readOnly mode
},
{
name: 'submit',
bindKey: "Ctrl+Enter",
exec: function (editor) {
$('form#problem_submit').submit();
},
readOnly: true
},
{
name: "showKeyboardShortcuts",
bindKey: {win: "Ctrl-Shift-/", mac: "Command-Shift-/"},
exec: function (editor) {
ace.config.loadModule("ace/ext/keybinding_menu", function (module) {
module.init(editor);
editor.showKeyboardShortcuts();
});
}
},
{
name: "increaseFontSize",
bindKey: "Ctrl-+",
exec: function (editor) {
var size = parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(size + 1);
}
},
{
name: "decreaseFontSize",
bindKey: "Ctrl+-",
exec: function (editor) {
var size = parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(Math.max(size - 1 || 1));
}
},
{
name: "resetFontSize",
bindKey: "Ctrl+0",
exec: function (editor) {
editor.setFontSize(12);
}
}
]);
window[widget.id] = editor;
$(widget).trigger('ace_load', [editor]);
}
function init() {
var widgets = document.getElementsByClassName('django-ace-widget');
for (var i = 0; i < widgets.length; i++) {
var widget = widgets[i];
widget.className = "django-ace-widget"; // remove `loading` class
apply_widget(widget);
}
}
if (window.addEventListener) { // W3C
window.addEventListener('load', init);
} else if (window.attachEvent) { // Microsoft
window.attachEvent('onload', init);
}
})();

57
django_ace/widgets.py Normal file
View file

@ -0,0 +1,57 @@
"""
Django-ace originally from https://github.com/bradleyayers/django-ace.
"""
from urllib.parse import urljoin
from django import forms
from django.conf import settings
from django.forms.utils import flatatt
from django.utils.safestring import mark_safe
class AceWidget(forms.Textarea):
def __init__(self, mode=None, theme=None, wordwrap=False, width='100%', height='300px',
no_ace_media=False, *args, **kwargs):
self.mode = mode
self.theme = theme
self.wordwrap = wordwrap
self.width = width
self.height = height
self.ace_media = not no_ace_media
super(AceWidget, self).__init__(*args, **kwargs)
@property
def media(self):
js = [urljoin(settings.ACE_URL, 'ace.js')] if self.ace_media else []
js.append('django_ace/widget.js')
css = {
'screen': ['django_ace/widget.css'],
}
return forms.Media(js=js, css=css)
def render(self, name, value, attrs=None, renderer=None):
attrs = attrs or {}
ace_attrs = {
'class': 'django-ace-widget loading',
'style': 'width:%s; height:%s' % (self.width, self.height),
'id': 'ace_%s' % name,
}
if self.mode:
ace_attrs['data-mode'] = self.mode
if self.theme:
ace_attrs['data-theme'] = self.theme
if self.wordwrap:
ace_attrs['data-wordwrap'] = 'true'
attrs.update(style='width: 100%; min-width: 100%; max-width: 100%; resize: none')
textarea = super(AceWidget, self).render(name, value, attrs)
html = '<div%s><div></div></div>%s' % (flatatt(ace_attrs), textarea)
# add toolbar
html = ('<div class="django-ace-editor"><div style="width: 100%%" class="django-ace-toolbar">'
'<a href="./" class="django-ace-max_min"></a></div>%s</div>') % html
return mark_safe(html)