diff --git a/setup/web_widget_text_markdown/odoo/addons/web_widget_text_markdown b/setup/web_widget_text_markdown/odoo/addons/web_widget_text_markdown new file mode 120000 index 000000000..872e5f4ad --- /dev/null +++ b/setup/web_widget_text_markdown/odoo/addons/web_widget_text_markdown @@ -0,0 +1 @@ +../../../../web_widget_text_markdown \ No newline at end of file diff --git a/setup/web_widget_text_markdown/setup.py b/setup/web_widget_text_markdown/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_widget_text_markdown/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_text_markdown/README.rst b/web_widget_text_markdown/README.rst new file mode 100644 index 000000000..2c8d6e9d7 --- /dev/null +++ b/web_widget_text_markdown/README.rst @@ -0,0 +1,114 @@ +======================== +Web Widget Text Markdown +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8e4fa31404e335de7a1e78b7aa8c1530de1e895d5c6d2afe70269e663589c8c3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/15.0/web_widget_text_markdown + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_text_markdown + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a new widget for text field in form view on Odoo: + +- In readonly mode, it uses text contents to parse and render them to html markdown syntax. +- In write mode, use [bootstrap-markdown][1] + +[1]: `bootstrap-markdown `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Your XML form view definition should contain:: + + ... + + ... + +Known issues / Roadmap +====================== + +* Can't create attachments on virtual records + +* Improve user experience with Odoo specific syntax +* Improve user experience with Github specific syntax + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Alexandre Díaz +* Komit +* Sudokeys +* Sunflower IT + +Contributors +~~~~~~~~~~~~ + +* Nicolas Jeudy +* Nguyen Tan Phuc +* Alexandre Díaz +* Tom Blauwendraat +* Kevin Kamau +* Helly kapatel +* [APSL-Nagarro](): + * Bernat Obrador + * Patryk Pyczko + +Other credits +~~~~~~~~~~~~~ + +* Komit https://komit-consulting.com + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_text_markdown/__init__.py b/web_widget_text_markdown/__init__.py new file mode 100644 index 000000000..ef5ae3587 --- /dev/null +++ b/web_widget_text_markdown/__init__.py @@ -0,0 +1 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). diff --git a/web_widget_text_markdown/__manifest__.py b/web_widget_text_markdown/__manifest__.py new file mode 100644 index 000000000..bfe751cc9 --- /dev/null +++ b/web_widget_text_markdown/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright (C) 2014 Sudokeys () +# Copyright (C) 2017 Komit () +# +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Web Widget Text Markdown", + "version": "15.0.1.0.0", + "author": "Alexandre Díaz, " + "Komit, " + "Sudokeys, " + "Sunflower IT, " + "Odoo Community Association (OCA)", + "category": "Web", + "license": "AGPL-3", + "website": "https://github.com/OCA/web", + "summary": "Widget to text fields that adds markdown support", + "depends": ["web"], + "demo": ["demo/bootstrap_markdown.xml"], + "data": [], + "installable": True, + "auto_install": False, + "application": False, + "assets": { + "web.assets_backend": [ + "/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js", + ], + "web.qunit_suite": [ + "/web_widget_text_markdown/static/tests/js/web_widget_text_markdown.js", + ], + }, +} diff --git a/web_widget_text_markdown/demo/bootstrap_markdown.xml b/web_widget_text_markdown/demo/bootstrap_markdown.xml new file mode 100644 index 000000000..be6bc22c2 --- /dev/null +++ b/web_widget_text_markdown/demo/bootstrap_markdown.xml @@ -0,0 +1,12 @@ + + + + res.groups + + + + bootstrap_markdown + + + + diff --git a/web_widget_text_markdown/i18n/web_widget_text_markdown.pot b/web_widget_text_markdown/i18n/web_widget_text_markdown.pot new file mode 100644 index 000000000..b698d2e2d --- /dev/null +++ b/web_widget_text_markdown/i18n/web_widget_text_markdown.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:0 +#, python-format +msgid "Translate" +msgstr "" diff --git a/web_widget_text_markdown/readme/CONTRIBUTORS.rst b/web_widget_text_markdown/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..34430bff8 --- /dev/null +++ b/web_widget_text_markdown/readme/CONTRIBUTORS.rst @@ -0,0 +1,9 @@ +* Nicolas Jeudy +* Nguyen Tan Phuc +* Alexandre Díaz +* Tom Blauwendraat +* Kevin Kamau +* Helly kapatel +* [APSL-Nagarro](): + * Bernat Obrador + * Patryk Pyczko diff --git a/web_widget_text_markdown/readme/CREDITS.rst b/web_widget_text_markdown/readme/CREDITS.rst new file mode 100644 index 000000000..ca0b19940 --- /dev/null +++ b/web_widget_text_markdown/readme/CREDITS.rst @@ -0,0 +1 @@ +* Komit https://komit-consulting.com diff --git a/web_widget_text_markdown/readme/DESCRIPTION.rst b/web_widget_text_markdown/readme/DESCRIPTION.rst new file mode 100644 index 000000000..45bf1ff0e --- /dev/null +++ b/web_widget_text_markdown/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module adds a new widget for text field in form view on Odoo: + +- In readonly mode, it uses text contents to parse and render them to html markdown syntax. +- In write mode, use [bootstrap-markdown][1] + +[1]: `bootstrap-markdown `_ diff --git a/web_widget_text_markdown/readme/ROADMAP.rst b/web_widget_text_markdown/readme/ROADMAP.rst new file mode 100644 index 000000000..8d1b2e80a --- /dev/null +++ b/web_widget_text_markdown/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +* Can't create attachments on virtual records + +* Improve user experience with Odoo specific syntax +* Improve user experience with Github specific syntax diff --git a/web_widget_text_markdown/readme/USAGE.rst b/web_widget_text_markdown/readme/USAGE.rst new file mode 100644 index 000000000..c4551498a --- /dev/null +++ b/web_widget_text_markdown/readme/USAGE.rst @@ -0,0 +1,5 @@ +Your XML form view definition should contain:: + + ... + + ... diff --git a/web_widget_text_markdown/static/description/icon.png b/web_widget_text_markdown/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_widget_text_markdown/static/description/icon.png differ diff --git a/web_widget_text_markdown/static/description/index.html b/web_widget_text_markdown/static/description/index.html new file mode 100644 index 000000000..570566518 --- /dev/null +++ b/web_widget_text_markdown/static/description/index.html @@ -0,0 +1,466 @@ + + + + + + +Web Widget Text Markdown + + + +
+

Web Widget Text Markdown

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This module adds a new widget for text field in form view on Odoo:

+
    +
  • In readonly mode, it uses text contents to parse and render them to html markdown syntax.
  • +
  • In write mode, use [bootstrap-markdown][1]
  • +
+

[1]: bootstrap-markdown

+

Table of contents

+ +
+

Usage

+

Your XML form view definition should contain:

+
+...
+<field name="field_name" widget="bootstrap_markdown"/>
+...
+
+
+
+

Known issues / Roadmap

+
    +
  • Can’t create attachments on virtual records
  • +
  • Improve user experience with Odoo specific syntax
  • +
  • Improve user experience with Github specific syntax
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Alexandre Díaz
  • +
  • Komit
  • +
  • Sudokeys
  • +
  • Sunflower IT
  • +
+
+
+

Contributors

+ +
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_widget_text_markdown/static/src/css/web_widget_text_markdown.css b/web_widget_text_markdown/static/src/css/web_widget_text_markdown.css new file mode 100644 index 000000000..8d76bd396 --- /dev/null +++ b/web_widget_text_markdown/static/src/css/web_widget_text_markdown.css @@ -0,0 +1,7 @@ +.o_field_text_markdown blockquote { + background: #f9f9f9; + border-left: 10px solid #ccc; + margin: 1.5em 10px; + padding: 1em 10px 0.1em 10px; + quotes: "\201C""\201D""\2018""\2019"; +} diff --git a/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js b/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js new file mode 100644 index 000000000..c80388073 --- /dev/null +++ b/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js @@ -0,0 +1,148 @@ +/* global showdown */ +/* Copyright 2014 Sudokeys + * Copyright 2017 Komit - + * Copyright 2019 Alexandre Díaz - + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +odoo.define("web_widget_text_markdown.FieldTextMarkDown", function (require) { + "use strict"; + + var basic_fields = require("web.basic_fields"); + var field_registry = require("web.field_registry"); + var core = require("web.core"); + + var _t = core._t; + var LIBS_PATH = "/web_widget_text_markdown/static/src/lib/"; + var CUST_LIBS_PATH = "/web_widget_text_markdown/static/src/css/"; + + var FieldTextMarkDown = basic_fields.FieldText.extend({ + className: [ + basic_fields.FieldText.prototype.className, + "o_field_text_markdown", + ].join(" "), + jsLibs: [ + LIBS_PATH + "bootstrap-markdown.js", + LIBS_PATH + "showdown.js", + LIBS_PATH + "showdown-footnotes.js", + LIBS_PATH + "showdown-table.js", + LIBS_PATH + "showdown-toc.js", + ], + cssLibs: [ + LIBS_PATH + "bootstrap-markdown.min.css", + CUST_LIBS_PATH + "web_widget_text_markdown.css", + ], + + _getValue: function () { + var $widget = this.attrs.widget; + var $type = this.field.type; + if ($type === "html" && $widget && $widget === "bootstrap_markdown") { + return this._getHtmlValue(this.$input.val()); + } + return this.$markdown.getContent(); + }, + + start: function () { + this._super(); + this.shw_render_html = new showdown.Converter({ + extensions: ["table", "footnotes", "toc"], + emoji: true, + underline: true, + tablesHeaderId: true, + omitExtraWLInCodeBlocks: true, + noHeaderId: true, + prefixHeaderId: true, + rawPrefixHeaderId: true, + ghCompatibleHeaderId: true, + rawHeaderId: true, + headerLevelStart: false, + parseImgDimensions: true, + simplifiedAutoLink: true, + literalMidWordUnderscores: false, + literalMidWordAsterisks: true, + strikethrough: true, + tables: true, + ghCodeBlocks: true, + tasklists: true, + smoothLivePreview: true, + smartIndentationFix: true, + disableForced4SpacesIndentedSublists: true, + simpleLineBreaks: true, + requireSpaceBeforeHeadingText: true, + ghMentions: true, + ghMentionsLink: "https://github.com/{u}", + encodeEmails: true, + openLinksInNewWindow: true, + backslashEscapesHTMLTags: true, + completeHTMLDocument: true, + metadata: true, + splitAdjacentBlockquotes: true, + }); + }, + + _prepareInput: function () { + var $input = this._super.apply(this, arguments); + _.defer( + function ($elm) { + $input.removeClass(this.className); + $input.wrap( + _.str.sprintf("
", this.className) + ); + $elm.markdown(this._getMarkdownOptions()); + this.$markdown = $elm.data("markdown"); + this.$markdown.setContent(this.value || ""); + }.bind(this), + $input + ); + return $input; + }, + _getHtmlValue: function (value) { + return this.shw_render_html.makeHtml(this._formatValue(value)); + }, + + _renderReadonly: function () { + this.$el.html(this._getHtmlValue(this.value)); + }, + + _getMarkdownOptions: function () { + var self = this; + var markdownOpts = { + iconlibrary: "fa", + autofocus: false, + width: "o_field_text_markdown", + savable: false, + language: this.getSession().user_context.lang, + onPreview: function (e) { + var render_val = self._getHtmlValue(e.getContent()); + return render_val; + }, + }; + + if (_t.database.multi_lang && this.field.translate) { + markdownOpts.additionalButtons = [ + [ + { + name: "oTranslate", + data: [ + { + name: "cmdTranslate", + title: _t("Translate"), + icon: {fa: "fa fa-flag"}, + // eslint-disable-next-line max-len + callback: this._markdownTranslate.bind(self), + }, + ], + }, + ], + ]; + } + return markdownOpts; + }, + + _markdownTranslate: function () { + // Event is the click event from callback + this._onTranslate(event); + }, + }); + + field_registry.add("bootstrap_markdown", FieldTextMarkDown); + return FieldTextMarkDown; +}); diff --git a/web_widget_text_markdown/static/src/lib/bootstrap-markdown.js b/web_widget_text_markdown/static/src/lib/bootstrap-markdown.js new file mode 100644 index 000000000..7e20ad632 --- /dev/null +++ b/web_widget_text_markdown/static/src/lib/bootstrap-markdown.js @@ -0,0 +1,1390 @@ +/* =================================================== + * bootstrap-markdown.js v2.10.0 + * http://github.com/toopay/bootstrap-markdown + * =================================================== + * Copyright 2013-2016 Taufan Aditya + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + +(function(factory){ + if (typeof define === "function" && define.amd) { + //RequireJS + define(["jquery"], factory); + } else if (typeof exports === 'object') { + //Backbone.js + factory(require('jquery')); + } else { + //Jquery plugin + factory(jQuery); + } +}(function($){ + "use strict"; // jshint ;_; + + /* MARKDOWN CLASS DEFINITION + * ========================== */ + + var Markdown = function (element, options) { + // @TODO : remove this BC on next major release + // @see : https://github.com/toopay/bootstrap-markdown/issues/109 + var opts = ['autofocus', 'savable', 'hideable', 'width', + 'height', 'resize', 'iconlibrary', 'language', + 'footer', 'fullscreen', 'hiddenButtons', 'disabledButtons']; + $.each(opts,function(_, opt){ + if (typeof $(element).data(opt) !== 'undefined') { + options = typeof options == 'object' ? options : {} + options[opt] = $(element).data(opt) + } + }); + // End BC + + // Class Properties + this.$ns = 'bootstrap-markdown'; + this.$element = $(element); + this.$editable = {el:null, type:null,attrKeys:[], attrValues:[], content:null}; + this.$options = $.extend(true, {}, $.fn.markdown.defaults, options, this.$element.data('options')); + this.$oldContent = null; + this.$isPreview = false; + this.$isFullscreen = false; + this.$editor = null; + this.$textarea = null; + this.$handler = []; + this.$callback = []; + this.$nextTab = []; + + this.showEditor(); + }; + + Markdown.prototype = { + + constructor: Markdown + + , __alterButtons: function(name,alter) { + var handler = this.$handler, isAll = (name == 'all'),that = this; + + $.each(handler,function(k,v) { + var halt = true; + if (isAll) { + halt = false; + } else { + halt = v.indexOf(name) < 0; + } + + if (halt === false) { + alter(that.$editor.find('button[data-handler="'+v+'"]')); + } + }); + } + + , __buildButtons: function(buttonsArray, container) { + var i, + ns = this.$ns, + handler = this.$handler, + callback = this.$callback; + + for (i=0;i', { + 'class': 'btn-group' + }); + + for (z=0;z'); + buttonContainer.text(' ' + this.__localize(btnText)).addClass('btn-default btn-sm').addClass(btnClass); + if(btnClass.match(/btn\-(primary|success|info|warning|danger|link)/)){ + buttonContainer.removeClass('btn-default'); + } + buttonContainer.attr({ + 'type': 'button', + 'title': this.__localize(button.title) + hotkeyCaption, + 'tabindex': tabIndex, + 'data-provider': ns, + 'data-handler': buttonHandler, + 'data-hotkey': hotkey + }); + if (button.toggle === true){ + buttonContainer.attr('data-toggle', 'button'); + } + buttonIconContainer = $(''); + buttonIconContainer.addClass(buttonIcon); + buttonIconContainer.prependTo(buttonContainer); + + // Attach the button object + btnGroupContainer.append(buttonContainer); + + // Register handler and callback + handler.push(buttonHandler); + callback.push(button.callback); + } + + // Attach the button group into container dom + container.append(btnGroupContainer); + } + } + + return container; + } + , __setListener: function() { + // Set size and resizable Properties + var hasRows = typeof this.$textarea.attr('rows') !== 'undefined', + maxRows = this.$textarea.val().split("\n").length > 5 ? this.$textarea.val().split("\n").length : '5', + rowsVal = hasRows ? this.$textarea.attr('rows') : maxRows; + + this.$textarea.attr('rows',rowsVal); + if (this.$options.resize) { + this.$textarea.css('resize',this.$options.resize); + } + + this.$textarea.on({ + 'focus' : $.proxy(this.focus, this), + 'keyup' : $.proxy(this.keyup, this), + 'change' : $.proxy(this.change, this), + 'select' : $.proxy(this.select, this) + }); + + if (this.eventSupported('keydown')) { + this.$textarea.on('keydown', $.proxy(this.keydown, this)); + } + + if (this.eventSupported('keypress')) { + this.$textarea.on('keypress', $.proxy(this.keypress, this)) + } + + // Re-attach markdown data + this.$textarea.data('markdown',this); + } + + , __handle: function(e) { + var target = $(e.currentTarget), + handler = this.$handler, + callback = this.$callback, + handlerName = target.attr('data-handler'), + callbackIndex = handler.indexOf(handlerName), + callbackHandler = callback[callbackIndex]; + + // Trigger the focusin + $(e.currentTarget).focus(); + + callbackHandler(this); + + // Trigger onChange for each button handle + this.change(this); + + // Unless it was the save handler, + // focusin the textarea + if (handlerName.indexOf('cmdSave') < 0) { + this.$textarea.focus(); + } + + e.preventDefault(); + } + + , __localize: function(string) { + var messages = $.fn.markdown.messages, + language = this.$options.language; + if ( + typeof messages !== 'undefined' && + typeof messages[language] !== 'undefined' && + typeof messages[language][string] !== 'undefined' + ) { + return messages[language][string]; + } + return string; + } + + , __getIcon: function(src) { + return typeof src == 'object' ? src[this.$options.iconlibrary] : src; + } + + , setFullscreen: function(mode) { + var $editor = this.$editor, + $textarea = this.$textarea; + + if (mode === true) { + $editor.addClass('md-fullscreen-mode'); + $('body').addClass('md-nooverflow'); + this.$options.onFullscreen(this); + } else { + $editor.removeClass('md-fullscreen-mode'); + $('body').removeClass('md-nooverflow'); + + if (this.$isPreview == true) this.hidePreview().showPreview() + } + + this.$isFullscreen = mode; + $textarea.focus(); + } + + , showEditor: function() { + var instance = this, + textarea, + ns = this.$ns, + container = this.$element, + originalHeigth = container.css('height'), + originalWidth = container.css('width'), + editable = this.$editable, + handler = this.$handler, + callback = this.$callback, + options = this.$options, + editor = $( '
', { + 'class': 'md-editor', + click: function() { + instance.focus(); + } + }); + + // Prepare the editor + if (this.$editor === null) { + // Create the panel + var editorHeader = $('
', { + 'class': 'md-header btn-toolbar' + }); + + // Merge the main & additional button groups together + var allBtnGroups = []; + if (options.buttons.length > 0) allBtnGroups = allBtnGroups.concat(options.buttons[0]); + if (options.additionalButtons.length > 0) { + // iterate the additional button groups + $.each(options.additionalButtons[0], function(idx, buttonGroup){ + + // see if the group name of the addional group matches an existing group + var matchingGroups = $.grep(allBtnGroups, function(allButtonGroup, allIdx){ + return allButtonGroup.name === buttonGroup.name; + }); + + // if it matches add the addional buttons to that group, if not just add it to the all buttons group + if(matchingGroups.length > 0) { + matchingGroups[0].data = matchingGroups[0].data.concat(buttonGroup.data); + } else { + allBtnGroups.push(options.additionalButtons[0][idx]); + } + + }); + } + + // Reduce and/or reorder the button groups + if (options.reorderButtonGroups.length > 0) { + allBtnGroups = allBtnGroups + .filter(function(btnGroup) { + return options.reorderButtonGroups.indexOf(btnGroup.name) > -1; + }) + .sort(function(a, b) { + if (options.reorderButtonGroups.indexOf(a.name) < options.reorderButtonGroups.indexOf(b.name)) return -1; + if (options.reorderButtonGroups.indexOf(a.name) > options.reorderButtonGroups.indexOf(b.name)) return 1; + return 0; + }); + } + + // Build the buttons + if (allBtnGroups.length > 0) { + editorHeader = this.__buildButtons([allBtnGroups], editorHeader); + } + + if (options.fullscreen.enable) { + editorHeader.append('
').on('click', '.md-control-fullscreen', function(e) { + e.preventDefault(); + instance.setFullscreen(true); + }); + } + + editor.append(editorHeader); + + // Wrap the textarea + if (container.is('textarea')) { + container.before(editor); + textarea = container; + textarea.addClass('md-input'); + editor.append(textarea); + } else { + var rawContent = (typeof toMarkdown == 'function') ? toMarkdown(container.html()) : container.html(), + currentContent = $.trim(rawContent); + + // This is some arbitrary content that could be edited + textarea = $('