From a2e69e3cce95713c4ddaf5613c30ddf11d9154f5 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 1 Aug 2015 17:06:39 +1000 Subject: [PATCH] Dynamically build markdown editor toolbar, add first button action --- .../assets/js/markdowneditor.js | 154 ++++++++++++++++-- .../partials/_markdowneditor.htm | 53 +----- 2 files changed, 140 insertions(+), 67 deletions(-) diff --git a/modules/backend/formwidgets/markdowneditor/assets/js/markdowneditor.js b/modules/backend/formwidgets/markdowneditor/assets/js/markdowneditor.js index 279dfac3a..3ddb2fbac 100644 --- a/modules/backend/formwidgets/markdowneditor/assets/js/markdowneditor.js +++ b/modules/backend/formwidgets/markdowneditor/assets/js/markdowneditor.js @@ -31,6 +31,120 @@ this.$el.attr('id', 'element-' + Math.random().toString(36).substring(7)) } + + this.createCodeContainer() + this.createToolbar() + + this.$toolbar.on('click', '.btn, .md-dropdown-button', this.proxy(this.onClickButton)) + + $('[data-control="tooltip"]', this.$toolbar).tooltip() + $('[data-toggle="dropdown"]', this.$toolbar).dropdown() + } + + MarkdownEditor.prototype.dispose = function() { + this.$el.off('dispose-control', this.proxy(this.dispose)) + this.$toolbar.off('click', '.btn, .md-dropdown-button', this.proxy(this.onClickButton)) + + this.$el.removeData('oc.markdownEditor') + + this.$el = null + this.$textarea = null + this.$toolbar = null + this.$write = null + this.$preview = null + this.$code = null + this.editor = null + this.$form = null + + this.options = null + + BaseProto.dispose.call(this) + } + + MarkdownEditor.prototype.onClickButton = function(ev) { + var $button = $(ev.target), + action = $button.data('button-action'), + template = $button.data('button-template') + + this[action](template) + } + + MarkdownEditor.prototype.createToolbar = function() { + var self = this, + $button, + $buttons = $('
'), + $fixedButtons = $('
') + + $.each($.oc.markdownEditorButtons, function(code, button) { + $button = $(' - -
- - - - - - - - - - - -
- -
- - -
- +