Skip to content

Commit

Permalink
Add class to existing block element, instead of inserting a new div e…
Browse files Browse the repository at this point in the history
…lement
  • Loading branch information
davosmith committed Oct 1, 2015
1 parent b18c803 commit 0f82594
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 78 deletions.
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'atto_styles';
$plugin->version = 2015051100;
$plugin->release = '2.9 (Build: 2015081800)';
$plugin->version = 2015092800;
$plugin->release = '2.9 (Build: 2015092800)';
$plugin->requires = 2015051100;
$plugin->maturity = MATURITY_STABLE;
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,19 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
* @private
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle;
var element, node;
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
p.removeAttribute('class');
break;
}
node = this._getParentBlock(element);
if (node) {
node.removeAttribute('class');
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
var displaystyle = pstyle.getPropertyValue('display');
if (displaystyle === 'block') {
eID = p;
break;
}
}
node = this._getParentBlock(element);
if (node) {
node.setAttribute('class', style[1]);
}
eID.setAttribute('class', style[1]);
} else {
var styles = style[1].split(" ");
this.get('host').toggleInlineSelectionClass(styles);
Expand All @@ -134,6 +116,22 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
this.markUpdated();
},

_getParentBlock: function (el) {
var p, node;
for (p = el; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
node = Y.one(p);
if (node.hasClass('editor_atto_content')) {
return null;
}
if (node.getComputedStyle('display') === 'block') {
return node;
}
}
},

hasRangeSelected: function() {
var selection, range;

Expand Down

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

48 changes: 23 additions & 25 deletions yui/build/moodle-atto_styles-button/moodle-atto_styles-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,19 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
* @private
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle;
var element, node;
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
p.removeAttribute('class');
break;
}
node = this._getParentBlock(element);
if (node) {
node.removeAttribute('class');
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
var displaystyle = pstyle.getPropertyValue('display');
if (displaystyle === 'block') {
eID = p;
break;
}
}
node = this._getParentBlock(element);
if (node) {
node.setAttribute('class', style[1]);
}
eID.setAttribute('class', style[1]);
} else {
var styles = style[1].split(" ");
this.get('host').toggleInlineSelectionClass(styles);
Expand All @@ -134,6 +116,22 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
this.markUpdated();
},

_getParentBlock: function (el) {
var p, node;
for (p = el; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
node = Y.one(p);
if (node.hasClass('editor_atto_content')) {
return null;
}
if (node.getComputedStyle('display') === 'block') {
return node;
}
}
},

hasRangeSelected: function() {
var selection, range;

Expand Down
48 changes: 23 additions & 25 deletions yui/src/button/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,19 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
* @private
*/
_changeStyle: function(e, style) {
var eID, element, p, pstyle;
var element, node;
if (style[0] === '<nostyle>') {
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
p.removeAttribute('class');
break;
}
node = this._getParentBlock(element);
if (node) {
node.removeAttribute('class');
}
return;
} else if (style[0] === '<block>') {
document.execCommand('formatBlock', false, '<div>');
element = window.getSelection().focusNode;
for (p = element; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
pstyle = window.getComputedStyle(p, null);
if (pstyle) {
var displaystyle = pstyle.getPropertyValue('display');
if (displaystyle === 'block') {
eID = p;
break;
}
}
node = this._getParentBlock(element);
if (node) {
node.setAttribute('class', style[1]);
}
eID.setAttribute('class', style[1]);
} else {
var styles = style[1].split(" ");
this.get('host').toggleInlineSelectionClass(styles);
Expand All @@ -132,6 +114,22 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed
this.markUpdated();
},

_getParentBlock: function (el) {
var p, node;
for (p = el; p; p = p.parentNode) {
if (p.nodeType !== 1) {
continue;
}
node = Y.one(p);
if (node.hasClass('editor_atto_content')) {
return null;
}
if (node.getComputedStyle('display') === 'block') {
return node;
}
}
},

hasRangeSelected: function() {
var selection, range;

Expand Down

0 comments on commit 0f82594

Please sign in to comment.