Skip to content

Commit

Permalink
semantic blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchi committed Mar 22, 2024
1 parent 70165b0 commit e8f6065
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions tests/behat/atto_styles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Feature: Atto styles
"title": "Warning text",
"type": "inline",
"classes": "label label-warning"
},{
"title": "Heading 3",
"type": "h3",
"classes": ""
}]
"""
And the config value "toolbar" of "editor_atto" is set as admin to multiline
Expand Down Expand Up @@ -120,3 +124,4 @@ Feature: Atto styles
| text | style | html |
| "i'm a hero" | "Hero unit box" | "<div class=\"hero-unit\">i'm a hero</div>" |
| "help" | "Muted Well" | "<div class=\"well text-muted\">help</div>" |
| "I'm a h3" | "Heading 3" | "<h3 class=\"\">I'm a h3" |
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
styles = JSON.parse(styles);
var items = [];
var icon, span, spanpreview, inlinehint;
var blocklevel = ['block', 'h3', 'h4', 'h5', 'blockquote'];
Y.Array.each(styles, function(style) {
icon = '<i></i>';
span = '<span>';
Expand All @@ -52,9 +53,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
if (style.type === 'nostyle') {
icon = '<i class="fa fa-fw fa-times"></i>';
span = '<span class="nostyle">';
} else if (style.type === 'block') {
} else if (blocklevel.indexOf(style.type) != -1) {
icon = '<i class="fa fa-fw fa-tint"></i>';
span = '<span class="blockstyle">';
span = '<span class="blockstyle ' + style.type + '">';
} else if (style.type == 'inline') {
icon = '<i class="fa fa-fw fa-i-cursor"></i>';
span = '<span class="inlinestyle">';
Expand Down Expand Up @@ -110,6 +111,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle, styles, host, i;
var semanticblocks = ['<block>', '<h3>', '<h4>', '<h5>', '<blockquote>'];
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
Expand All @@ -126,8 +128,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
}
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
} else if (semanticblocks.indexOf(style[0]) != -1) {
var formatblock = (style[0] == '<block>') ? '<div>' : style[0];
document.execCommand('formatBlock', false, formatblock);
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
return;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions yui/build/moodle-atto_styles-button/moodle-atto_styles-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
styles = JSON.parse(styles);
var items = [];
var icon, span, spanpreview, inlinehint;
var blocklevel = ['block', 'h3', 'h4', 'h5', 'blockquote'];
Y.Array.each(styles, function(style) {
icon = '<i></i>';
span = '<span>';
Expand All @@ -52,9 +53,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
if (style.type === 'nostyle') {
icon = '<i class="fa fa-fw fa-times"></i>';
span = '<span class="nostyle">';
} else if (style.type === 'block') {
} else if (blocklevel.indexOf(style.type) != -1) {
icon = '<i class="fa fa-fw fa-tint"></i>';
span = '<span class="blockstyle">';
span = '<span class="blockstyle ' + style.type + '">';
} else if (style.type == 'inline') {
icon = '<i class="fa fa-fw fa-i-cursor"></i>';
span = '<span class="inlinestyle">';
Expand Down Expand Up @@ -110,6 +111,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle, styles, host, i;
var semanticblocks = ['<block>', '<h3>', '<h4>', '<h5>', '<blockquote>'];
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
Expand All @@ -126,8 +128,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
}
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
} else if (semanticblocks.indexOf(style[0]) != -1) {
var formatblock = (style[0] == '<block>') ? '<div>' : style[0];
document.execCommand('formatBlock', false, formatblock);
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
return;
Expand Down
11 changes: 7 additions & 4 deletions yui/src/button/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
styles = JSON.parse(styles);
var items = [];
var icon, span, spanpreview, inlinehint;
var blocklevel = ['block', 'h3', 'h4', 'h5', 'blockquote'];
Y.Array.each(styles, function(style) {
icon = '<i></i>';
span = '<span>';
Expand All @@ -50,9 +51,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
if (style.type === 'nostyle') {
icon = '<i class="fa fa-fw fa-times"></i>';
span = '<span class="nostyle">';
} else if (style.type === 'block') {
} else if (blocklevel.indexOf(style.type) != -1) {
icon = '<i class="fa fa-fw fa-tint"></i>';
span = '<span class="blockstyle">';
span = '<span class="blockstyle ' + style.type + '">';
} else if (style.type == 'inline') {
icon = '<i class="fa fa-fw fa-i-cursor"></i>';
span = '<span class="inlinestyle">';
Expand Down Expand Up @@ -108,6 +109,7 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle, styles, host, i;
var semanticblocks = ['<block>', '<h3>', '<h4>', '<h5>', '<blockquote>'];
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
Expand All @@ -124,8 +126,9 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
}
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
} else if (semanticblocks.indexOf(style[0]) != -1) {
var formatblock = (style[0] == '<block>') ? '<div>' : style[0];
document.execCommand('formatBlock', false, formatblock);
element = window.getSelection().focusNode;
if (!this.editor.contains(element)) {
return;
Expand Down

0 comments on commit e8f6065

Please sign in to comment.