Skip to content

Commit

Permalink
issue #8: add function to add span decoration at editor load
Browse files Browse the repository at this point in the history
In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly, I don't know. But, if we call it after setting the HTML, the {mlang} tags flicker with the decoration, and returns to their original state.
  • Loading branch information
Julen Pardo committed Apr 11, 2016
1 parent 8b6cd5e commit e20f235
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 3 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
toolbarItems = [];

if (hascapability) {
this._decorateTagsOnInit();
toolbarItems = this._initializeToolbarItems();

this.addToolbarMenu({
Expand Down Expand Up @@ -241,6 +242,40 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
this.detach();

submitbutton.simulate('click');
},

/**
* Adds the <span> tags to the {mlang} tags when the editor is loaded.
* In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,
* I don't know. But, if we call it after setting the HTML, the {mlang}
* tags flicker with the decoration, and returns to their original state.
*
* @method _decorateTagsOnInit
* @private
*/
_decorateTagsOnInit: function() {
var textarea = Y.one('#id_messageeditable'),
innerHTML = textarea.get('innerHTML'),
regularExpression,
mlangtags,
mlangtag,
index,
decoratedmlangtag;

regularExpression = new RegExp('{mlang.*?}', 'g');
mlangtags = innerHTML.match(regularExpression);

if (mlangtags !== null) {
for (index = 0; index < mlangtags.length; index++) {
mlangtag = mlangtags[index];

decoratedmlangtag = OPENING_SPAN + mlangtag + '</span>';

innerHTML = innerHTML.replace(mlangtag, decoratedmlangtag);
}

textarea.set('innerHTML', innerHTML);
}
}

}, {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
toolbarItems = [];

if (hascapability) {
this._decorateTagsOnInit();
toolbarItems = this._initializeToolbarItems();

this.addToolbarMenu({
Expand Down Expand Up @@ -241,6 +242,40 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
this.detach();

submitbutton.simulate('click');
},

/**
* Adds the <span> tags to the {mlang} tags when the editor is loaded.
* In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,
* I don't know. But, if we call it after setting the HTML, the {mlang}
* tags flicker with the decoration, and returns to their original state.
*
* @method _decorateTagsOnInit
* @private
*/
_decorateTagsOnInit: function() {
var textarea = Y.one('#id_messageeditable'),
innerHTML = textarea.get('innerHTML'),
regularExpression,
mlangtags,
mlangtag,
index,
decoratedmlangtag;

regularExpression = new RegExp('{mlang.*?}', 'g');
mlangtags = innerHTML.match(regularExpression);

if (mlangtags !== null) {
for (index = 0; index < mlangtags.length; index++) {
mlangtag = mlangtags[index];

decoratedmlangtag = OPENING_SPAN + mlangtag + '</span>';

innerHTML = innerHTML.replace(mlangtag, decoratedmlangtag);
}

textarea.set('innerHTML', innerHTML);
}
}

}, {
Expand Down
35 changes: 35 additions & 0 deletions yui/src/button/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
toolbarItems = [];

if (hascapability) {
this._decorateTagsOnInit();
toolbarItems = this._initializeToolbarItems();

this.addToolbarMenu({
Expand Down Expand Up @@ -239,6 +240,40 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
this.detach();

submitbutton.simulate('click');
},

/**
* Adds the <span> tags to the {mlang} tags when the editor is loaded.
* In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,
* I don't know. But, if we call it after setting the HTML, the {mlang}
* tags flicker with the decoration, and returns to their original state.
*
* @method _decorateTagsOnInit
* @private
*/
_decorateTagsOnInit: function() {
var textarea = Y.one('#id_messageeditable'),
innerHTML = textarea.get('innerHTML'),
regularExpression,
mlangtags,
mlangtag,
index,
decoratedmlangtag;

regularExpression = new RegExp('{mlang.*?}', 'g');
mlangtags = innerHTML.match(regularExpression);

if (mlangtags !== null) {
for (index = 0; index < mlangtags.length; index++) {
mlangtag = mlangtags[index];

decoratedmlangtag = OPENING_SPAN + mlangtag + '</span>';

innerHTML = innerHTML.replace(mlangtag, decoratedmlangtag);
}

textarea.set('innerHTML', innerHTML);
}
}

}, {
Expand Down

0 comments on commit e20f235

Please sign in to comment.