Skip to content

Instantly share code, notes, and snippets.

@kijtra
Created November 14, 2012 04:53
Show Gist options
  • Save kijtra/4070324 to your computer and use it in GitHub Desktop.
Save kijtra/4070324 to your computer and use it in GitHub Desktop.
if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};
RedactorPlugins.fontsize = {
init: function(){
var doc = document;
if ( !doc.getElementById( 'redactor-fontsize-style' ) ) {
var head = doc.getElementsByTagName( 'head' )[0];
var imgsrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAASCAMAAACZ8IWSAAAAA3NCSVQICAjb4U/gAAAAgVBMVEX///////9VVVX///96enpVVVVVVVVVVVX///9VVVX////Hx8erq6tVVVXo6OhVVVVVVVX////e3t5aWlpVVVX////e3t5VVVX////U1NRVVVV6enpaWlpVVVWrq6uVlZVubm5aWlpVVVVycnJubm5mZmZaWlpVVVWrq6tmZmZVVVU4bmHEAAAAK3RSTlMAEREiIiIzRFVVZmZmZnd3iJmZmZmqqqq7u7vMzMzd3d3d3e7u7u7u////6dkbcAAAAAlwSFlzAAALEgAACxIB0t1+/AAAAB90RVh0U29mdHdhcmUATWFjcm9tZWRpYSBGaXJld29ya3MgOLVo0ngAAACGSURBVBiVrc7JFoIwDAXQIA5YpyKiQalgHSjv/z+QwrKpx41vkUVuk5ToD0Gsac0oLGEFnDFGyOmDe8JgFlP2hlcW27bWlV9HJOWyVQ80ibw/69raoFdSdgXnR6CSct345zWaNISlyf0JjX4fwKHDc0HaAu95QBmzH1Ilcxn53s84577SVAdK6gqHkfp1SQAAAABJRU5ErkJggg==';
var styleText = '.redactor_btn_fontsize{background-image:url(' + imgsrc + ') !important;}';
var style = doc.createElement( 'style' );
style.type = 'text/css';
style.id = 'redactor-fontsize-style';
if ( style.styleSheet ) {//IE
style.styleSheet.cssText = styleText;
} else {
style.appendChild( document.createTextNode( styleText ) );
}
head.appendChild( style );
}
var dropdown = {
nofontsize: {
title: '指定なし',
callback: this.fontSize
},
fontsize1: {
title: '<font size="1">1 (8pt)</font>',
callback: this.fontSize
},
fontsize2: {
title: '<font size="2">2 (10pt)</font>',
callback: this.fontSize
},
fontsize3: {
title: '<font size="3">3 (12pt)</font>',
callback: this.fontSize
},
fontsize4: {
title: '<font size="4">4 (14pt)</font>',
callback: this.fontSize
},
fontsize5: {
title: '<font size="5">5 (18pt)</font>',
callback: this.fontSize
},
fontsize6: {
title: '<font size="6">6 (24pt)</font>',
callback: this.fontSize
},
fontsize7: {
title: '<font size="7">7 (36pt)</font>',
callback: this.fontSize
}
};
this.addBtnAfter('backcolor','fontsize','文字サイズ',function(){},dropdown);
},
fontSize: function( obj, event, key ) {
if ( key.match( /^fontsize(\d+)$/ ) ) {
obj.execCommand( 'fontSize', RegExp.$1 );
} else if ( key == 'nofontsize' ) {
obj.execCommand( 'removeFormat', key );
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment