-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
percentage-fontsize plugin implementation #688
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* SCEditor Inline-Code Plugin for BBCode format | ||
* http://www.sceditor.com/ | ||
* | ||
* Copyright (C) 2011-2013, Sam Clarke (samclarke.com) | ||
* | ||
* SCEditor is licensed under the MIT license: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* @fileoverview SCEditor percentage fontsize plugin for BBCode format | ||
* This plugin allow usage of the percent indication in font size bbcode tag | ||
* in a format used in phpBB system: | ||
* [size=50]text[/font] | ||
* means the text will be shown with font 50% of the current size | ||
* [size=200]text[/font] | ||
* means the text will be shown with font 200% of the current size | ||
* @author Alex Betis | ||
*/ | ||
|
||
(function (sceditor) { | ||
'use strict'; | ||
|
||
var dom = sceditor.dom; | ||
|
||
sceditor.plugins['percentage-fontsize'] = function () { | ||
var base = this; | ||
|
||
/** | ||
* Default sizes | ||
* @type {Object} | ||
* @private | ||
*/ | ||
var sizes = [50, 75, 100, 150, 200]; | ||
|
||
/** | ||
* Private functions | ||
* @private | ||
*/ | ||
var commandHandler; | ||
|
||
base.init = function () { | ||
var opts = this.opts; | ||
var pOpts = opts.percentageFontsize; | ||
|
||
// Enable for BBCode only | ||
if (opts.format && opts.format !== 'bbcode') { | ||
return; | ||
} | ||
|
||
if (pOpts) { | ||
if (pOpts.sizes) { | ||
sizes = pOpts.sizes; | ||
} | ||
} | ||
|
||
// The plugin will override current fontsize implementation | ||
sceditor.command.set('size', { | ||
exec: commandHandler, | ||
txtExec: commandHandler, | ||
tooltip: 'Font Size' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please explain what do you mean here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a function named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I don't understand what function do you mean that have to be with underscore or translatable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, OK. The code sends tooltips through the translation function when displaying: |
||
}); | ||
|
||
sceditor.formats.bbcode.set('size', { | ||
tags: { | ||
font: { | ||
size: null | ||
} | ||
}, | ||
styles: { | ||
'font-size': null | ||
}, | ||
format: function (element, content) { | ||
var fontSize = dom.attr(element, 'size'); | ||
var size; | ||
|
||
if (!fontSize) { | ||
fontSize = element.style.fontSize; | ||
} | ||
|
||
// remove "%" from the option | ||
size = fontSize.replace('%', ''); | ||
|
||
return '[size=' + size + ']' + content + '[/size]'; | ||
}, | ||
html: '<font style="font-size:{defaultattr}%">{!0}</font>' | ||
}); | ||
}; | ||
|
||
/** | ||
* Function for the txtExec and exec properties | ||
* | ||
* @param {node} caller | ||
* @private | ||
*/ | ||
commandHandler = function (caller) { | ||
var editor = this; | ||
var content = document.createElement('div'); | ||
|
||
sceditor.utils.each(sizes, function (index, size) { | ||
var link = document.createElement('a'); | ||
var font = document.createElement('font'); | ||
link.className = 'sceditor-fontsize-option'; | ||
link.setAttribute('data-size', size); | ||
font.textContent = size + '%'; | ||
font.style.fontSize = size + '%'; | ||
link.appendChild(font); | ||
link.addEventListener('click', function (e) { | ||
var size = dom.attr(this, 'data-size'); | ||
|
||
editor.closeDropDown(true); | ||
|
||
if (editor.sourceMode()) { | ||
editor.insert('[size=' + size + ']', '[/size]'); | ||
} else { | ||
editor.wysiwygEditorInsertHtml( | ||
'<font style="font-size: ' + size + '%;">', | ||
'</font>'); | ||
} | ||
|
||
e.preventDefault(); | ||
}); | ||
|
||
content.appendChild(link); | ||
}); | ||
|
||
editor.createDropDown(caller, 'fontsize-picker', content); | ||
}; | ||
}; | ||
})(sceditor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this behave like a constant? If so, turn the variable name into CAPS
Personally, I'd have a default value but allow setting options to change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a documentation for plugin configuration fomat?
Couldn't find any documentation for format.js configuration for example...