Skip to content

Instantly share code, notes, and snippets.

@samclarke
Last active December 10, 2015 00:59
Show Gist options
  • Save samclarke/4355569 to your computer and use it in GitHub Desktop.
Save samclarke/4355569 to your computer and use it in GitHub Desktop.
Update SCEditor [size] tag to work with percentages.
$.sceditorBBCodePlugin.bbcode.set('size', {
format: function($elm, content) {
var size = $elm.data('scefontsize');
if(!size)
{
size = $elm.css('fontSize').replace("px", "") - 0;
if(!this.baseFontSizePx)
this.baseFontSizePx = $elm.parents('body').css('fontSize').replace("px", "") - 0;
size = Math.round((size / this.baseFontSizePx) * 100);
}
return '[size=' + size + ']' + content + '[/size]';
},
html: function(token, attrs, content) {
return '<span data-scefontsize="' + (~~attrs.defaultattr) + '" style="font-size:' + (~~attrs.defaultattr) + '%">' + content + '</span>';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment