Skip to content

Commit 7b3dff2

Browse files
Org: Add requested editor options
Added several new options in editor: - subscipt - alphanumeric lists - blockquote TYPE: Feature
1 parent 4519575 commit 7b3dff2

11 files changed

Lines changed: 204 additions & 23 deletions

File tree

src/onegov/core/html.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'pre',
3333
'strong',
3434
'sup',
35+
'sub',
3536
'span',
3637
'ul',
3738
'h1',
@@ -54,7 +55,8 @@
5455
'abbr': ['title', ],
5556
'acronym': ['title', ],
5657
'img': ['src', 'alt', 'title'],
57-
'p': ['class']
58+
'p': ['class'],
59+
'ol': ['class']
5860
}
5961

6062
# lines without these plaintext characters are excluded in html_to_text

src/onegov/org/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ def get_editor_asset() -> Iterator[str]:
829829
yield 'filemanager.js'
830830
yield 'imagemanager.js'
831831
yield 'table.js'
832+
yield 'alphalist.js'
832833
yield 'redactor.de.js'
833834
yield 'redactor.fr.js'
834835
yield 'redactor.it.js'

src/onegov/org/assets/css/redactor.css

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ body .redactor-box-fullscreen {
160160
display: block;
161161
color: #333;
162162
text-align: center;
163-
padding: 9px 10px;
163+
padding: 9px 9px;
164164
outline: none;
165165
border: none;
166166
text-decoration: none;
@@ -750,8 +750,11 @@ body .redactor-box-fullscreen {
750750
##############################################
751751
*/
752752
.redactor-dropdown .redactor-formatting-blockquote {
753-
color: rgba(0, 0, 0, 0.4);
754-
font-style: italic;
753+
margin: .2rem;
754+
padding: .5rem 1rem;
755+
color: #777;
756+
background-color: #f7f8f8;
757+
border-left: 1px solid #cacaca;
755758
}
756759
.redactor-dropdown .redactor-formatting-pre {
757760
font-family: monospace, sans-serif;
@@ -840,11 +843,10 @@ body .redactor-box-fullscreen {
840843
margin-bottom: 15px;
841844
}
842845
.redactor-editor blockquote {
843-
margin-left: 1.6em !important;
844-
padding: 0;
845-
text-align: left;
846+
padding: .5rem 1rem;
846847
color: #777;
847-
font-style: italic;
848+
background-color: #f7f8f8;
849+
border-left: 1px solid #cacaca;
848850
}
849851
.redactor-editor blockquote:before,
850852
.redactor-editor blockquote:after {
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
(function($) {
2+
$.Redactor.prototype.alphalist = function() {
3+
return {
4+
5+
init: function() {
6+
var self = this;
7+
8+
var button = this.button.addAfter('orderedlist', 'alphalist', this.lang.get('alphalist'));
9+
if (!button || !button.length) {
10+
button = this.button.add('alphalist', this.lang.get('alphalist'));
11+
}
12+
13+
self.$alphalistButton = button;
14+
15+
button.on('click', function(e) {
16+
e.preventDefault();
17+
self.alphalist.toggle.call(self);
18+
});
19+
20+
$(this.$editor).on('keyup mouseup', function() {
21+
self.alphalist.updateButtonState.call(self);
22+
});
23+
},
24+
25+
isAlphaList: function() {
26+
var current = this.selection.getBlock();
27+
if (!current) return false;
28+
var parent = current.parentNode;
29+
return $(parent).is('ol.alpha-list');
30+
},
31+
32+
updateButtonState: function() {
33+
if (this.alphalist.isAlphaList.call(this)) {
34+
this.$alphalistButton.addClass('redactor-act');
35+
} else {
36+
this.$alphalistButton.removeClass('redactor-act');
37+
}
38+
39+
var $olButton = this.button.get('orderedlist');
40+
if ($olButton) {
41+
if (this.alphalist.isAlphaList.call(this)) {
42+
$olButton.removeClass('redactor-act');
43+
}
44+
}
45+
},
46+
47+
focusEnd: function($element) {
48+
var $target = $element.is('ol, ul') ? $element.find('li').last() : $element;
49+
if (!$target.length) return;
50+
var range = document.createRange();
51+
var sel = window.getSelection();
52+
range.selectNodeContents($target[0]);
53+
range.collapse(false);
54+
sel.removeAllRanges();
55+
sel.addRange(range);
56+
this.alphalist.updateButtonState.call(this);
57+
},
58+
59+
toggle: function() {
60+
var current = this.selection.getBlock();
61+
if (!current) return;
62+
63+
var $editor = $(this.$editor);
64+
var selection = this.selection.get();
65+
var selectedBlocks = [];
66+
var parent = current.parentNode;
67+
68+
if ($(parent).hasClass('alpha-list')) {
69+
var $ol = $(parent);
70+
var $items = $ol.find('li');
71+
var blocks = [];
72+
$items.each(function() {
73+
blocks.push($('<p>').html($(this).html()));
74+
});
75+
$ol.replaceWith(blocks);
76+
77+
this.$alphalistButton.removeClass('redactor-act');
78+
79+
this.alphalist.focusEnd.call(this, $(blocks[blocks.length - 1]));
80+
return;
81+
}
82+
83+
if (parent.nodeName === 'UL' || parent.nodeName === 'OL') {
84+
if (!$(parent).hasClass('alpha-list')) {
85+
var $newOl = $('<ol>').addClass('alpha-list').html($(parent).html());
86+
$(parent).replaceWith($newOl);
87+
}
88+
89+
this.alphalist.focusEnd.call(this, $newOl);
90+
this.alphalist.updateButtonState.call(this);
91+
return;
92+
}
93+
94+
if (selection && !selection.isCollapsed) {
95+
var range = selection.getRangeAt(0);
96+
$editor.children().each(function() {
97+
if (range.intersectsNode(this)) {
98+
selectedBlocks.push(this);
99+
}
100+
});
101+
}
102+
103+
if (selectedBlocks.length === 0) {
104+
selectedBlocks.push(current);
105+
}
106+
107+
var $ol = $('<ol>').addClass('alpha-list');
108+
$(selectedBlocks).each(function() {
109+
var content = $(this).html();
110+
$ol.append($('<li>').html(content));
111+
});
112+
113+
$(selectedBlocks[0]).replaceWith($ol);
114+
for (var i = 1; i < selectedBlocks.length; i++) {
115+
$(selectedBlocks[i]).remove();
116+
}
117+
this.alphalist.focusEnd.call(this, $ol);
118+
119+
this.$alphalistButton.addClass('redactor-act');
120+
this.alphalist.updateButtonState.call(this);
121+
}
122+
};
123+
};
124+
})(jQuery);

src/onegov/org/assets/js/editor.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ var translation = $.Redactor.opts.langs[language];
1515
};
1616
})(jQuery);
1717

18+
(function($) {
19+
$.Redactor.prototype.subscript = function() {
20+
return {
21+
init: function() {
22+
var button = this.button.add('subscript', translation.subscript);
23+
this.button.addCallback(button, this.subscript.format);
24+
button.html('x<sub>2</sub>')
25+
},
26+
format: function() {
27+
this.inline.format('sub');
28+
}
29+
};
30+
};
31+
})(jQuery);
32+
1833
$(function() {
1934
_.each($('textarea.editor'), function(el) {
2035
var textarea = $(el);
@@ -24,16 +39,16 @@ $(function() {
2439
textarea.redactor({
2540
buttons: [
2641
'formatting', 'bold', 'italic', 'deleted',
27-
'unorderedlist', 'orderedlist', 'image', 'file', 'link',
28-
'horizontalrule', 'html', 'superscript'
42+
'unorderedlist', 'orderedlist', 'alphalist', 'image', 'file',
43+
'link', 'horizontalrule', 'superscript', 'subscript', 'html'
2944
],
3045
formatting: ['p', 'blockquote', 'pre'],
3146
fileUpload: form.data('file-upload-url'),
3247
fileManagerJson: form.data('file-list-url'),
3348
imageUpload: form.data('image-upload-url'),
3449
imageManagerJson: form.data('image-list-url'),
3550
definedLinks: form.data('sitecollection-url'),
36-
plugins: ['bufferbuttons', 'filemanager', 'imagemanager', 'definedlinks', 'table', 'superscript'],
51+
plugins: ['alphalist', 'bufferbuttons', 'filemanager', 'imagemanager', 'definedlinks', 'table', 'superscript', 'subscript'],
3752
lang: language,
3853
convertVideoLinks: false,
3954
imageResizable: false,
@@ -58,6 +73,10 @@ $(function() {
5873
tag: 'p',
5974
class: 'edit-note',
6075
title: translation.editnote
76+
},
77+
{
78+
tag: 'blockquote',
79+
title: translation.blockquote
6180
}
6281
],
6382
/* defined in input_with_button.js */

src/onegov/org/assets/js/redactor.de.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ $.Redactor.opts.langs['de'] = {
7171
align_justify: 'Blocksatz',
7272
horizontalrule: 'Horizontale Linie',
7373
superscript: 'Hochgestellt',
74+
subscript: 'Tiefgestellt',
7475
fullscreen: 'Vollbild',
7576
deleted: 'Durchgestrichen',
7677
anchor: 'Anker',
@@ -83,6 +84,8 @@ $.Redactor.opts.langs['de'] = {
8384
center: 'Center',
8485
upload_label: 'Datei hier ablegen oder ',
8586
redo: 'Wiederherstellen',
86-
undo: 'Rückgängig'
87+
undo: 'Rückgängig',
88+
alphalist: 'a. Aufzählung',
89+
blockquote: 'Zitat'
8790
};
8891
})( jQuery );

src/onegov/org/assets/js/redactor.fr.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ $.Redactor.opts.langs['fr'] = {
7171
align_justify: 'Justifier',
7272
horizontalrule: 'Ligne horizontale',
7373
superscript: 'Exposant',
74+
subscript: 'Indice',
7475
fullscreen: 'Plein écran',
7576
deleted: 'Supprimer',
7677
anchor: 'Ancre',
@@ -83,6 +84,8 @@ $.Redactor.opts.langs['fr'] = {
8384
center: 'Centrer',
8485
upload_label: 'Déposez le fichier ici ou ',
8586
redo: 'Refaire',
86-
undo: 'Défaire'
87+
undo: 'Défaire',
88+
alphalist: 'a. Liste alphabétique',
89+
blockquote: 'Citation'
8790
};
8891
})( jQuery );

src/onegov/org/assets/js/redactor.it.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ $.Redactor.opts.langs['it'] = {
6868
align_justify: 'Giustifica il testo',
6969
horizontalrule: 'Inserisci regola orizzontale',
7070
superscript: 'Apice',
71+
subscript: 'Pedice',
7172
deleted: 'Eliminato',
7273
anchor: 'Ancora',
7374
link_new_tab: 'Apri il link in una nuova scheda',
@@ -78,6 +79,8 @@ $.Redactor.opts.langs['it'] = {
7879
edit: 'Modifica',
7980
upload_label: 'Trascina il file qui o',
8081
undo: 'Annulla azione',
81-
redo: 'Rifai'
82+
redo: 'Rifai',
83+
alphalist: 'a. Elenco di lettere',
84+
blockquote: 'Citazione'
8285
};
8386
})( jQuery );

src/onegov/town6/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def get_editor_asset() -> Iterator[str]:
304304
yield 'filemanager.js'
305305
yield 'imagemanager.js'
306306
yield 'table.js'
307+
yield 'alphalist.js'
307308
yield 'redactor.de.js'
308309
yield 'redactor.fr.js'
309310
yield 'redactor.it.js'

src/onegov/town6/assets/css/redactor.css

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ body .redactor-box-fullscreen {
160160
display: block;
161161
color: #333;
162162
text-align: center;
163-
padding: 9px 10px;
163+
padding: 9px 9px;
164164
outline: none;
165165
border: none;
166166
text-decoration: none;
@@ -750,8 +750,11 @@ body .redactor-box-fullscreen {
750750
##############################################
751751
*/
752752
.redactor-dropdown .redactor-formatting-blockquote {
753-
color: rgba(0, 0, 0, 0.4);
754-
font-style: italic;
753+
margin: .2rem;
754+
padding: .5rem 1rem;
755+
color: #777;
756+
background-color: #f7f8f8;
757+
border-left: 1px solid #cacaca;
755758
}
756759
.redactor-dropdown .redactor-formatting-pre {
757760
font-family: monospace, sans-serif;
@@ -840,11 +843,10 @@ body .redactor-box-fullscreen {
840843
margin-bottom: 15px;
841844
}
842845
.redactor-editor blockquote {
843-
margin-left: 1.6em !important;
844-
padding: 0;
845-
text-align: left;
846+
padding: .5rem 1rem;
846847
color: #777;
847-
font-style: italic;
848+
background-color: #f7f8f8;
849+
border-left: 1px solid #cacaca;
848850
}
849851
.redactor-editor blockquote:before,
850852
.redactor-editor blockquote:after {

0 commit comments

Comments
 (0)