Skip to content

Commit

Permalink
issue #8: create function to remove <span> tags on form submit
Browse files Browse the repository at this point in the history
All the logic to remove the tags is coded inside the 'on' method closure, because seems that is not possible to define a class function that is accessible from closure scope.
  • Loading branch information
Julen Pardo committed Apr 10, 2016
1 parent 6c9de4a commit 20f457e
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 @@ -67,9 +67,44 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
});

this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);
this._cleanTagsOnSubmit();
}
},

/**
* Cleans the <span> tags around the {mlang} tags when the form is submitted.
* All the logic to remove the tags is coded inside the 'on' method closure,
* because seems that is not possible to define a class function that is
* accessible from closure scope.
*/
_cleanTagsOnSubmit: function() {
var submitbutton = Y.one('#id_submitbutton'),
textarea,
innerHTML,
spanedmlangtags,
spanedmlangtag,
index,
cleanmlangtag;

submitbutton.on('click', function(e){
textarea = Y.one('#id_messageeditable');
innerHTML = textarea.get('innerHTML');
e.preventDefault();
spanedmlangtags = innerHTML.match(/<span class=\"filter\-multilang\-tag\">.*?<\/span>/g);

for (index = 0; index < spanedmlangtags.length; index++) {
spanedmlangtag = spanedmlangtags[index];
cleanmlangtag = spanedmlangtag.replace('<span class="filter-multilang-tag">', '');

cleanmlangtag = cleanmlangtag.replace('</span>', '');

innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);
}

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

/**
* Initializes the toolbar items, which will be the installed languages,
* received as parameter.
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 @@ -67,9 +67,44 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
});

this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);
this._cleanTagsOnSubmit();
}
},

/**
* Cleans the <span> tags around the {mlang} tags when the form is submitted.
* All the logic to remove the tags is coded inside the 'on' method closure,
* because seems that is not possible to define a class function that is
* accessible from closure scope.
*/
_cleanTagsOnSubmit: function() {
var submitbutton = Y.one('#id_submitbutton'),
textarea,
innerHTML,
spanedmlangtags,
spanedmlangtag,
index,
cleanmlangtag;

submitbutton.on('click', function(e){
textarea = Y.one('#id_messageeditable');
innerHTML = textarea.get('innerHTML');
e.preventDefault();
spanedmlangtags = innerHTML.match(/<span class=\"filter\-multilang\-tag\">.*?<\/span>/g);

for (index = 0; index < spanedmlangtags.length; index++) {
spanedmlangtag = spanedmlangtags[index];
cleanmlangtag = spanedmlangtag.replace('<span class="filter-multilang-tag">', '');

cleanmlangtag = cleanmlangtag.replace('</span>', '');

innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);
}

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

/**
* Initializes the toolbar items, which will be the installed languages,
* received as parameter.
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 @@ -65,9 +65,44 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att
});

this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);
this._cleanTagsOnSubmit();
}
},

/**
* Cleans the <span> tags around the {mlang} tags when the form is submitted.
* All the logic to remove the tags is coded inside the 'on' method closure,
* because seems that is not possible to define a class function that is
* accessible from closure scope.
*/
_cleanTagsOnSubmit: function() {
var submitbutton = Y.one('#id_submitbutton'),
textarea,
innerHTML,
spanedmlangtags,
spanedmlangtag,
index,
cleanmlangtag;

submitbutton.on('click', function(e){
textarea = Y.one('#id_messageeditable');
innerHTML = textarea.get('innerHTML');
e.preventDefault();
spanedmlangtags = innerHTML.match(/<span class=\"filter\-multilang\-tag\">.*?<\/span>/g);

for (index = 0; index < spanedmlangtags.length; index++) {
spanedmlangtag = spanedmlangtags[index];
cleanmlangtag = spanedmlangtag.replace('<span class="filter-multilang-tag">', '');

cleanmlangtag = cleanmlangtag.replace('</span>', '');

innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);
}

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

/**
* Initializes the toolbar items, which will be the installed languages,
* received as parameter.
Expand Down

0 comments on commit 20f457e

Please sign in to comment.