mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-31 05:44:28 -06:00
Auto download Font Awesome
This commit is contained in:
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>
|
<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
|
And then load SimpleMDE on the first textarea on a page
|
||||||
|
|
||||||
```HTML
|
```HTML
|
||||||
@ -65,6 +59,7 @@ simplemde.value("This text will appear in the editor");
|
|||||||
|
|
||||||
## Configuration
|
## 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`.
|
- **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.*
|
- **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`.
|
- **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.
|
* Interface of SimpleMDE.
|
||||||
*/
|
*/
|
||||||
function SimpleMDE(options) {
|
function SimpleMDE(options) {
|
||||||
|
// Handle options parameter
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
|
||||||
// Used later to refer to it's parent
|
// Used later to refer to it's parent
|
||||||
options.parent = this;
|
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
|
// Find the textarea to use
|
||||||
if(options.element) {
|
if(options.element) {
|
||||||
@ -747,6 +781,7 @@ function SimpleMDE(options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle toolbar and status bar
|
// Handle toolbar and status bar
|
||||||
if(options.toolbar !== false)
|
if(options.toolbar !== false)
|
||||||
options.toolbar = options.toolbar || SimpleMDE.toolbar;
|
options.toolbar = options.toolbar || SimpleMDE.toolbar;
|
||||||
@ -755,6 +790,7 @@ function SimpleMDE(options) {
|
|||||||
options.status = ['autosave', 'lines', 'words', 'cursor'];
|
options.status = ['autosave', 'lines', 'words', 'cursor'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add default preview rendering function
|
// Add default preview rendering function
|
||||||
if(!options.previewRender) {
|
if(!options.previewRender) {
|
||||||
options.previewRender = function(plainText) {
|
options.previewRender = function(plainText) {
|
||||||
@ -763,15 +799,19 @@ function SimpleMDE(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set default options for parsing config
|
// Set default options for parsing config
|
||||||
options.parsingConfig = options.parsingConfig || {};
|
options.parsingConfig = options.parsingConfig || {};
|
||||||
|
|
||||||
|
|
||||||
// Update this options
|
// Update this options
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
|
|
||||||
// Auto render
|
// Auto render
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
|
|
||||||
// The codemirror component is only available after rendering
|
// The codemirror component is only available after rendering
|
||||||
// so, the setter for the initialValue can only run after
|
// so, the setter for the initialValue can only run after
|
||||||
// the element has been rendered
|
// the element has been rendered
|
||||||
|
Loading…
x
Reference in New Issue
Block a user