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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745288344a4620702.html
评论列表(0条)