Auto download Font Awesome

pull/114/head
Wes Cossick 9 years ago
parent c6e3a4bf55
commit bfda8350ae

@ -21,12 +21,6 @@ SimpleMDE is also available on [jsDelivr](http://www.jsdelivr.com/#!simplemde).
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
```
SimpleMDE depends on Font Awesome (load via MaxCDN for best performance).
```HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
```
And then load SimpleMDE on the first textarea on a page
```HTML
@ -65,6 +59,7 @@ simplemde.value("This text will appear in the editor");
## Configuration
- **autoDownloadFontAwesome**: If set to `true`, force downloads Font Awesome (used for icons). If set to false, prevents downloading. Defaults to `undefined`, which will intelligently check whether Font Awesome has already been included, then download accordingly.
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
- **autosave**: *Saves the text that's being written. It will forget the text when the form is submitted.*
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.

@ -733,10 +733,44 @@ var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ord
* Interface of SimpleMDE.
*/
function SimpleMDE(options) {
// Handle options parameter
options = options || {};
// Used later to refer to it's parent
options.parent = this;
// Check if Font Awesome needs to be auto downloaded
var autoDownloadFA = true;
if(options.autoDownloadFontAwesome === false){
autoDownloadFA = false;
}
if(options.autoDownloadFontAwesome !== true){
var styleSheets = document.styleSheets;
for(var i = 0; i < styleSheets.length; i++) {
if(!styleSheets[i].href)
continue;
if(styleSheets[i].href.indexOf("//maxcdn.bootstrapcdn.com/font-awesome/") > -1){
autoDownloadFA = false;
}
}
}
if(autoDownloadFA){
console.log("autodownloading");
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css";
document.getElementsByTagName("head")[0].appendChild(link);
}else{
console.log("not autodownloading");
}
// Find the textarea to use
if(options.element) {
@ -747,6 +781,7 @@ function SimpleMDE(options) {
return;
}
// Handle toolbar and status bar
if(options.toolbar !== false)
options.toolbar = options.toolbar || SimpleMDE.toolbar;
@ -755,6 +790,7 @@ function SimpleMDE(options) {
options.status = ['autosave', 'lines', 'words', 'cursor'];
}
// Add default preview rendering function
if(!options.previewRender) {
options.previewRender = function(plainText) {
@ -763,15 +799,19 @@ function SimpleMDE(options) {
}
}
// Set default options for parsing config
options.parsingConfig = options.parsingConfig || {};
// Update this options
this.options = options;
// Auto render
this.render();
// The codemirror component is only available after rendering
// so, the setter for the initialValue can only run after
// the element has been rendered

Loading…
Cancel
Save