Skip to content

Commit

Permalink
Update markdown interface (#1411)
Browse files Browse the repository at this point in the history
* Cleanup markdown interface

Including refreshed UI which shows preview simultaniously with editor

* Fix path in UIManager
  • Loading branch information
rijkvanzanten authored and wellingguzman committed Apr 24, 2017
1 parent 7c156ee commit e575809
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 103 deletions.
2 changes: 1 addition & 1 deletion app/core/UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ define(function(require, exports, module) {
require('core/interfaces/user'),
require('core/interfaces/directus_file_title'),
require('core/interfaces/map'),
require('core/interfaces/markdown'),
require('core/interfaces/markdown/component'),
require('core/interfaces/multiple_files'),
require('core/interfaces/multiple_files/csv/component'),
require('core/interfaces/translation'),
Expand Down
102 changes: 0 additions & 102 deletions app/core/interfaces/markdown.js

This file was deleted.

39 changes: 39 additions & 0 deletions app/core/interfaces/markdown/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Markdown UI component
// Directus 6.0

// (c) RANGER
// Directus may be freely distributed under the GNU license.
// For all details and documentation:
// http://www.getdirectus.com

define([
'core/interfaces/markdown/interface',
'core/UIComponent',
'marked'
],function(Input, UIComponent, marked) {

'use strict';

return UIComponent.extend({
id: 'markdown',
dataTypes: ['TEXT', 'VARCHAR'],
variables: [
{id: 'rows', type: 'Number', default_value: 14, ui: 'numeric', char_length: 3},
{id: 'github_flavored_markdown', type: 'Boolean', default_value: false, ui: 'checkbox'},
{id: 'tables', type: 'Boolean', default_value: false, ui: 'checkbox'},
{id: 'breaks', type: 'Boolean', default_value: false, ui: 'checkbox'},
{id: 'sanitize', type: 'Boolean', default_value: false, ui: 'checkbox'}
],
Input: Input,
validate: function(value, options) {
if (options.schema.isRequired() && _.isEmpty(value)) {
return 'This field is required';
}
},
list: function(options) {
var raw_val = marked(options.value);

return _.isString(raw_val) ? raw_val.replace(/<(?:.|\n)*?>/gm, '').substr(0,100) : '<span class="silver">--</span>';
}
});
});
63 changes: 63 additions & 0 deletions app/core/interfaces/markdown/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<style>
.md-interface {
position: relative;
display: flex;
}

.md-interface > * {
max-height: 80vh;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}

.md-interface textarea {
font-family: monospace;
transition-property: box-shadow;
height: auto;
}

.md-interface > div {
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
display: none;
width: 100%;
background-color: white;
border: 1px solid #cccccc;
padding: 1rem;
}

.md-interface > div h2 {
max-width: none;
}

.md-interface > div ul {
list-style-position: inside;
}

.md-controls {
margin-bottom: 1em;
}

@media screen and (min-width: 70em) {
.md-interface {
width: auto;
}

.md-controls {
display: none;
}

.md-interface > div {
display: block;
}
}
</style>
<div class="md-controls">
<button class="toggle-pane" type="button" data-action="md-edit">Editor</button>
<button class="toggle-pane" type="button" data-action="md-preview">Preview</button>
</div>
<div class="md-interface">
<textarea rows="{{rows}}" class="md-editor" name="{{name}}" id="{{name}}" {{#if readonly}}readonly{{/if}}>{{rawValue}}</textarea>
<div class="md-editor-preview">{{{value}}}</div>
</div>
63 changes: 63 additions & 0 deletions app/core/interfaces/markdown/interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Markdown UI component
// Directus 6.0

// (c) RANGER
// Directus may be freely distributed under the GNU license.
// For all details and documentation:
// http://www.getdirectus.com

define([
'core/UIView',
'marked'
],function(UIView, marked) {

'use strict';

return UIView.extend({
template: 'markdown/input',

events: {
'keyup': 'renderMarkdown',
'change textarea.md-editor': 'renderMarkdown',
'click button[data-action="md-preview"]': function (e) {
this.$('.md-editor').hide();
this.$('.md-editor-preview').show();
this.$('.btn').removeClass('active');
e.currentTarget.className += ' active';
},
'click button[data-action="md-edit"]': function (e) {
this.$('.md-editor-preview').hide();
this.$('.md-editor').show();
this.$('.btn').removeClass('active');
e.currentTarget.className += ' active';
}
},

renderMarkdown: function() {
var value = this.$('.md-editor').val();
if (value) {
this.$('.md-editor-preview').html(marked(value));
}
},

initialize: function() {
marked.setOptions({
gfm: this.options.settings.get('github_flavored_markdown'),
tables: this.options.settings.get('tables'),
breaks: this.options.settings.get('breaks'),
sanitize: this.options.settings.get('sanitize')
});
},

serialize: function() {
return {
rawValue: this.options.value,
value: (this.options.value) ? marked(this.options.value):'',
name: this.options.name,
rows: this.options.settings.get('rows'),
comment: this.options.schema.get('comment'),
readonly: !this.options.canWrite
};
}
});
});

0 comments on commit e575809

Please sign in to comment.