This tutorial will help you add a button to the SCEditor on your Forumotion forum. The button will allow you to use all Font Awesome icons in your posts with minimal effort !
Attention : you must first install Font Awesome on your forum, otherwise the icons will not display for everyone.
Installation
Firstly we must add some CSS, so our editor popup and button display correctly. Go to Administration Panel > Display > Colors > CSS stylesheet and paste the following style rules.
- Code:
/* Add fontawesome to textarea font-family so the icons are visible */ .sceditor-container textarea { font-family:Verdana, Arial, Helvetica, sans-serif, FontAwesome !important } /* button image */ .sceditor-button-fontawesome div { background:url(http://i19.servimg.com/u/f19/19/06/98/92/fa-f10.png) !important }
/* drop down */ .sceditor-fontawesome { width:220px; height:250px; overflow-y:auto; }
/* icons */ .sceditor-fontawesome i { color:#333; font-size:20px; text-align:center; cursor:pointer; padding:3px 0; width:25%; } .sceditor-fontawesome i:hover { color:#666 }
Next we can go ahead and install the button into the SCEditor. Go to Administration Panel > Modules > JavaScript codes management, make sure JS code management is enabled then create a new script.
Title : SCEditor Font Awesome Icons Placement : In all the pages
- Code:
$(function(){ if (!$.sceditor) return; var defaultSize = 18, // default icon size autoClose = 1, // closes drop down after an icon is clicked, if enabled // icon list fa = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''], A = '', O = A; // if the size is above 0 we'll format a default size for the icons if (defaultSize) { A += '[size=' + defaultSize + ']'; O += '[/size]'; } // create sceditor button and drop down $.sceditor.command.set('fontawesome', { dropDown : function(editor, caller, callback) { var a, b = '', c = document.createElement('DIV'), i = 0, j = fa.length; for (; i<j; i++) b += '<i class="fa">' + fa[i] + '</i>'; c.innerHTML = b; for (a = c.getElementsByTagName('I'), i = 0, j = a.length; i<j; i++) { a[i].onclick = function() { callback(this.innerHTML); autoClose && editor.closeDropDown(true); }; }
editor.createDropDown(caller, 'fontawesome', c); },
// wysiwyg exec : function(c) { var e = this; $.sceditor.command.get('fontawesome').dropDown(e, c, function(icon) { e.insert(' [font=FontAwesome]' + A + icon + O + '[/font] ', '', true, true, true); }); }, // source txtExec : function(c) { var e = this; $.sceditor.command.get('fontawesome').dropDown(e, c, function(icon) { e.insert(' [font=FontAwesome]' + A + icon + O + '[/font] ', ''); }); }, tooltip : 'Font Awesome Icons' }); toolbar = toolbar.replace(/date,/,'fontawesome,date,'); // add the button to the toolbar });
Modifications : Below you will find an explanation of any modifiable settings which can be found at the top of the script.
defaultSize : allows you to set a default size for the icons. It's currently set to 18, if you want the icons to render without size adjusting simply set the value to 0.
autoClose : allows you to choose if you want the drop down to close automatically after choosing an icon. This option is enabled by default, if you want to disable it simply change the 1 to 0.
When you're finished, go ahead and save the script. Then go to the editor and you should now see the Font Awesome flag in the editor toolbar.. Clicking it will open the icon list, and clicking any icon will insert it into the editor ....how awesome is that ?
|