admin管理员组文章数量:1418380
I'd like to be able to add a button that adds my own custom class. I don't see this in the documentation anywhere but seems like a mon request.
For example.
Highlighting "Some Text" and pressing the button "Custom Class" will add
<p class="wysiwyg-custom-class">Some Text</p
>
I'd like to be able to add a button that adds my own custom class. I don't see this in the documentation anywhere but seems like a mon request.
For example.
Highlighting "Some Text" and pressing the button "Custom Class" will add
<p class="wysiwyg-custom-class">Some Text</p
>
- 1,2 ,3, bonus this is documentation you looked for ? – zb' Commented Dec 13, 2012 at 23:32
- As stated in the title this is for wysihtml5 text editor. I need to be able to highlight the text and add a custom class. It's more plicated than just adding a class though. – dardub Commented Dec 15, 2012 at 1:02
1 Answer
Reset to default 5Define new mand, my example is based on ForeColor:
(function(wysihtml5) {
wysihtml5.mands.setClass = {
exec: function(poser, mand, element_class) {
element_class=element_class.split(/:/);
element=element_class[0];
newclass=element_class[1];
var REG_EXP = new RegExp(newclass,'g');
//register custom class
wysihtml5ParserRules['classes'][newclass]=1;
return wysihtml5.mands.formatInline.exec(poser, mand, element, newclass, REG_EXP);
},
state: function(poser, mand, element_class) {
element_class=element_class.split(/:/);
element=element_class[0];
newclass=element_class[1];
var REG_EXP = new RegExp(newclass,'g');
return wysihtml5.mands.formatInline.state(poser, mand, element, newclass, REG_EXP);
}
};
})(wysihtml5);
usage:
HTML:
<div id="uxToolbar">
<button data-wysihtml5-mand="setClass" data-wysihtml5-mand-value="span:my-wysihtml5-custom-class" type="button" title="View HTML" tabindex="-1" class="btn btn-mini">
My class
</button>
</div>
so as you can see value is from two parts: element:class
DEMO
本文标签: javascriptadd custom class to wysihtml5 text editorStack Overflow
版权声明:本文标题:javascript - add custom class to wysihtml5 text editor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745288344a2651638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论