From 9b515fc408e14c5c375f62e5bef5421970f13a19 Mon Sep 17 00:00:00 2001 From: Tran Quang Tri Date: Fri, 30 Oct 2015 18:00:30 +0000 Subject: [PATCH 1/3] [FIX + ADD] fix markdown update condition on form view, add markdown support on list view --- .../static/src/js/web_widget_text_markdown.js | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) 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 index 7fbfa4c0..493730d3 100644 --- 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 @@ -39,16 +39,17 @@ openerp.web_widget_text_markdown = function (oe) { store_dom_value: function () { if (!this.get('effective_readonly') && - this._get_raw_value() !== '' && this.is_syntax_valid()) { - // We use internal_set_value because we were called by - // ``.commit_value()`` which is called by a ``.set_value()`` - // itself called because of a ``onchange`` event - this.internal_set_value( - this.parse_value( - this._get_raw_value())); - } - }, + // We use internal_set_value because we were called by + // ``.commit_value()`` which is called by a ``.set_value()`` + // itself called because of a ``onchange`` event + this.internal_set_value( + this.parse_value( + this._get_raw_value() + ) + ); + } + }, commit_value: function () { this.store_dom_value(); @@ -58,7 +59,7 @@ openerp.web_widget_text_markdown = function (oe) { _get_raw_value: function() { if (this.$txt === false) return ''; - return this.$txt.val(); + return this.$txt.val(); }, render_value: function () { @@ -86,4 +87,35 @@ openerp.web_widget_text_markdown = function (oe) { } } ); + + /** + * bootstrap_markdown support on list view + **/ + oe.web_widget_text_markdown.FieldTextMarkDownList = oe.web.list.Char.extend({ + + init: function(){ + this._super.apply(this, arguments); + hljs.initHighlightingOnLoad(); + marked.setOptions({ + sanitize: true, + highlight: function (code) { + return hljs.highlightAuto(code).value; + } + }); + }, + + _format: function(row_data, options){ + options = options || {}; + var markdown_text = marked( + oe.web.format_value( + row_data[this.id].value, this, options.value_if_empty + ) + ); + return markdown_text; + } + }); + + oe.web.list.columns.add( + "field.bootstrap_markdown", "oe.web_widget_text_markdown.FieldTextMarkDownList" + ); }; From c79ea227450185ea5aabbd980514c3d0d3b831bc Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Mon, 23 Nov 2015 23:43:23 -0500 Subject: [PATCH 2/3] OCA Transbot updated translations from Transifex --- web_widget_text_markdown/i18n/ar.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/de.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/es.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/fi.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/fr.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/pt_BR.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/sl.po | 26 ++++++++++++++++++++++++++ web_widget_text_markdown/i18n/tr.po | 26 ++++++++++++++++++++++++++ 8 files changed, 208 insertions(+) create mode 100644 web_widget_text_markdown/i18n/ar.po create mode 100644 web_widget_text_markdown/i18n/de.po create mode 100644 web_widget_text_markdown/i18n/es.po create mode 100644 web_widget_text_markdown/i18n/fi.po create mode 100644 web_widget_text_markdown/i18n/fr.po create mode 100644 web_widget_text_markdown/i18n/pt_BR.po create mode 100644 web_widget_text_markdown/i18n/sl.po create mode 100644 web_widget_text_markdown/i18n/tr.po diff --git a/web_widget_text_markdown/i18n/ar.po b/web_widget_text_markdown/i18n/ar.po new file mode 100644 index 00000000..f94ad717 --- /dev/null +++ b/web_widget_text_markdown/i18n/ar.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# SaFi J. , 2015 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-12-16 07:41+0000\n" +"PO-Revision-Date: 2015-12-16 17:24+0000\n" +"Last-Translator: SaFi J. \n" +"Language-Team: Arabic (http://www.transifex.com/oca/OCA-web-8-0/language/ar/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: ar\n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "مارك داون" diff --git a/web_widget_text_markdown/i18n/de.po b/web_widget_text_markdown/i18n/de.po new file mode 100644 index 00000000..4281e587 --- /dev/null +++ b/web_widget_text_markdown/i18n/de.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Rudolf Schnapka , 2016 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-10 07:31+0000\n" +"PO-Revision-Date: 2016-01-18 20:15+0000\n" +"Last-Translator: Rudolf Schnapka \n" +"Language-Team: German (http://www.transifex.com/oca/OCA-web-8-0/language/de/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "Abschlag" diff --git a/web_widget_text_markdown/i18n/es.po b/web_widget_text_markdown/i18n/es.po new file mode 100644 index 00000000..5e1a0254 --- /dev/null +++ b/web_widget_text_markdown/i18n/es.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Pedro M. Baeza , 2015 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-23 13:46+0000\n" +"PO-Revision-Date: 2015-11-07 11:29+0000\n" +"Last-Translator: Pedro M. Baeza \n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-web-8-0/language/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "MarkDown" diff --git a/web_widget_text_markdown/i18n/fi.po b/web_widget_text_markdown/i18n/fi.po new file mode 100644 index 00000000..dde9456f --- /dev/null +++ b/web_widget_text_markdown/i18n/fi.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Jarmo Kortetjärvi , 2016 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-10 07:31+0000\n" +"PO-Revision-Date: 2016-02-01 09:42+0000\n" +"Last-Translator: Jarmo Kortetjärvi \n" +"Language-Team: Finnish (http://www.transifex.com/oca/OCA-web-8-0/language/fi/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fi\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "Markdown" diff --git a/web_widget_text_markdown/i18n/fr.po b/web_widget_text_markdown/i18n/fr.po new file mode 100644 index 00000000..f318e132 --- /dev/null +++ b/web_widget_text_markdown/i18n/fr.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Christophe CHAUVET , 2016 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-05-06 15:50+0000\n" +"PO-Revision-Date: 2016-05-06 08:22+0000\n" +"Last-Translator: Christophe CHAUVET \n" +"Language-Team: French (http://www.transifex.com/oca/OCA-web-8-0/language/fr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "MarkDown" diff --git a/web_widget_text_markdown/i18n/pt_BR.po b/web_widget_text_markdown/i18n/pt_BR.po new file mode 100644 index 00000000..8d929c06 --- /dev/null +++ b/web_widget_text_markdown/i18n/pt_BR.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# danimaribeiro , 2016 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-11 02:18+0000\n" +"PO-Revision-Date: 2016-03-05 16:20+0000\n" +"Last-Translator: danimaribeiro \n" +"Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/OCA-web-8-0/language/pt_BR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_BR\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "MarkDown" diff --git a/web_widget_text_markdown/i18n/sl.po b/web_widget_text_markdown/i18n/sl.po new file mode 100644 index 00000000..6c15a1f3 --- /dev/null +++ b/web_widget_text_markdown/i18n/sl.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Matjaž Mozetič , 2015 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-23 13:46+0000\n" +"PO-Revision-Date: 2015-11-08 05:48+0000\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-web-8-0/language/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "MarkDown" diff --git a/web_widget_text_markdown/i18n/tr.po b/web_widget_text_markdown/i18n/tr.po new file mode 100644 index 00000000..8b929686 --- /dev/null +++ b/web_widget_text_markdown/i18n/tr.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_text_markdown +# +# Translators: +# Ahmet Altınışık , 2016 +msgid "" +msgstr "" +"Project-Id-Version: web (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-10 07:31+0000\n" +"PO-Revision-Date: 2016-01-31 11:44+0000\n" +"Last-Translator: Ahmet Altınışık \n" +"Language-Team: Turkish (http://www.transifex.com/oca/OCA-web-8-0/language/tr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: tr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: web_widget_text_markdown +#. openerp-web +#: code:addons/web_widget_text_markdown/static/src/js/web_widget_text_markdown.js:12 +#, python-format +msgid "MarkDown" +msgstr "MarkDown" From d937f31f394e5b10a84be6fb6ebbd02dceabc0b3 Mon Sep 17 00:00:00 2001 From: "phuc.nt" Date: Tue, 27 Feb 2018 09:31:21 +0700 Subject: [PATCH 3/3] [10.0][MIG] web_widget_text_markdown Adjustment to make it work version 10.0 --- web_widget_text_markdown/README.rst | 15 +- web_widget_text_markdown/__manifest__.py | 31 +- .../demo/bootstrap_markdown.xml | 12 + .../bootstrap-markdown/bootstrap-markdown.js | 1641 ++++++++++------- .../static/src/css/main.css | 4 +- .../static/src/js/web_widget_text_markdown.js | 51 +- .../static/src/xml/bootstrap_markdown.xml | 10 +- web_widget_text_markdown/views/main.xml | 13 +- 8 files changed, 1018 insertions(+), 759 deletions(-) create mode 100644 web_widget_text_markdown/demo/bootstrap_markdown.xml diff --git a/web_widget_text_markdown/README.rst b/web_widget_text_markdown/README.rst index 4ce76627..72c4306a 100644 --- a/web_widget_text_markdown/README.rst +++ b/web_widget_text_markdown/README.rst @@ -8,11 +8,6 @@ This module adds a new widget for text field in form view on Odoo: [1]: http://www.codingdrama.com/bootstrap-markdown/ "bootstrap-markdown" -Installation -============ - -It was tested on openerp trunk, 8.0 branch. - Usage ===== @@ -48,6 +43,16 @@ Contributors ------------ * Nicolas Jeudy +* Nguyen Tan Phuc + +Do not contact contributors directly about support or help with technical issues. + +Funders +------- + +The development of this module has been financially supported by: + +* Komit https://komit-consulting.com Maintainer ---------- diff --git a/web_widget_text_markdown/__manifest__.py b/web_widget_text_markdown/__manifest__.py index f3678db2..e281a0e6 100644 --- a/web_widget_text_markdown/__manifest__.py +++ b/web_widget_text_markdown/__manifest__.py @@ -2,6 +2,7 @@ ############################################################################## # # Copyright (C) 2014 Sudokeys () +# Copyright (C) 2017 Komit () # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published @@ -20,18 +21,26 @@ { 'name': 'web_widget_text_markdown', - 'version': '8.0.1.0.0', - 'author': "Sudokeys,Odoo Community Association (OCA)", - 'maintainer': 'Sudokeys', - 'category': '', + 'version': '10.0.1.0.0', + "author": "Komit, " + "Sudokeys, " + "Odoo Community Association (OCA)", + 'category': 'Web', 'license': 'AGPL-3', - 'depends': ['base', 'web'], - 'website': 'http://www.sudokey.com', - 'data': ['views/main.xml', ], - "qweb": ["static/src/xml/bootstrap_markdown.xml", - ], - 'demo': [], - 'installable': False, + 'website': 'https://github.com/OCA/web', + 'depends': [ + 'base', 'web' + ], + 'demo': [ + "demo/bootstrap_markdown.xml", + ], + 'data': [ + 'views/main.xml', + ], + "qweb": [ + "static/src/xml/bootstrap_markdown.xml", + ], + 'installable': True, 'auto_install': False, 'application': False } 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 00000000..0442662e --- /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/static/lib/bootstrap-markdown/bootstrap-markdown.js b/web_widget_text_markdown/static/lib/bootstrap-markdown/bootstrap-markdown.js index 66ad62f1..fffdbcf1 100644 --- a/web_widget_text_markdown/static/lib/bootstrap-markdown/bootstrap-markdown.js +++ b/web_widget_text_markdown/static/lib/bootstrap-markdown/bootstrap-markdown.js @@ -1,8 +1,8 @@ /* =================================================== - * bootstrap-markdown.js v2.7.0 + * bootstrap-markdown.js v2.10.0 * http://github.com/toopay/bootstrap-markdown * =================================================== - * Copyright 2013-2014 Taufan Aditya + * 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. @@ -16,97 +16,125 @@ * See the License for the specific language governing permissions and * limitations under the License. * ========================================================== */ - -!function ($) { - - "use strict"; // jshint ;_; - +(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"; /* MARKDOWN CLASS DEFINITION * ========================== */ - var Markdown = function (element, options) { + 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(), 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() - } + 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 + constructor: Markdown, + __alterButtons: function(name, alter) { + var handler = this.$handler, + isAll = (name == 'all'), + that = this; - , __alterButtons: function(name,alter) { - var handler = this.$handler, isAll = (name == 'all'),that = this - - $.each(handler,function(k,v) { - var halt = true + $.each(handler, function(k, v) { + var halt = true; if (isAll) { - halt = false + halt = false; } else { - halt = v.indexOf(name) < 0 + halt = v.indexOf(name) < 0; } - if (halt == false) { - alter(that.$editor.find('button[data-handler="'+v+'"]')) + if (halt === false) { + alter(that.$editor.find('button[data-handler="' + v + '"]')); } - }) - } - - , __buildButtons: function(buttonsArray, container) { + }); + }, + __buildButtons: function(buttonsArray, container) { var i, - ns = this.$ns, - handler = this.$handler, - callback = this.$callback + ns = this.$ns, + handler = this.$handler, + callback = this.$callback; - for (i=0;i', { - 'class': 'btn-group' - }) + buttons = btnGroups[y].data, + btnGroupContainer = $('
', { + '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'); + 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 + 'type': 'button', + 'title': this.__localize(button.title) + hotkeyCaption, + 'tabindex': tabIndex, + 'data-provider': ns, + 'data-handler': buttonHandler, + 'data-hotkey': hotkey }); - if (button.toggle == true){ + if (button.toggle === true) { buttonContainer.attr('data-toggle', 'button'); } buttonIconContainer = $(''); @@ -121,50 +149,55 @@ callback.push(button.callback); } - // Attach the button group into container dom + // Attach the button group into container DOM container.append(btnGroupContainer); } } return container; - } - , __setListener: function() { + }, + __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 + 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) + this.$textarea.attr('rows', rowsVal); if (this.$options.resize) { - this.$textarea.css('resize',this.$options.resize) + this.$textarea.css('resize', this.$options.resize); } - this.$textarea - .on('focus', $.proxy(this.focus, this)) - .on('keypress', $.proxy(this.keypress, this)) - .on('keyup', $.proxy(this.keyup, this)) - .on('change', $.proxy(this.change, this)) + // Re-attach markdown data + this.$textarea.data('markdown', this); + }, + __setEventListeners: function() { + 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)) + this.$textarea.on('keydown', $.proxy(this.keydown, this)); } - // Re-attach markdown data - this.$textarea.data('markdown',this) - } - - , __handle: function(e) { + if (this.eventSupported('keypress')) { + this.$textarea.on('keypress', $.proxy(this.keypress, 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] + handler = this.$handler, + callback = this.$callback, + handlerName = target.attr('data-handler'), + callbackIndex = handler.indexOf(handlerName), + callbackHandler = callback[callbackIndex]; // Trigger the focusin - $(e.currentTarget).focus() + $(e.currentTarget).focus(); - callbackHandler(this) + callbackHandler(this); // Trigger onChange for each button handle this.change(this); @@ -172,15 +205,14 @@ // Unless it was the save handler, // focusin the textarea if (handlerName.indexOf('cmdSave') < 0) { - this.$textarea.focus() + this.$textarea.focus(); } - e.preventDefault() - } - - , __localize: function(string) { + e.preventDefault(); + }, + __localize: function(string) { var messages = $.fn.markdown.messages, - language = this.$options.language + language = this.$options.language; if ( typeof messages !== 'undefined' && typeof messages[language] !== 'undefined' && @@ -189,185 +221,209 @@ 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') - } + }, + __getIcon: function(src) { + if(typeof src == 'object'){ + var customIcon = this.$options.customIcons[src.name]; + return typeof customIcon == 'undefined' ? src.icon[this.$options.iconlibrary] : customIcon; + } else { + return 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'); + this.$options.onFullscreenExit(this); - this.$isFullscreen = mode; - $textarea.focus() - } + if (this.$isPreview === true) + this.hidePreview().showPreview(); + } - , showEditor: function() { + 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() - } - }) + 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) { + if (this.$editor === null) { // Create the panel var editorHeader = $('
', { - 'class': 'md-header btn-toolbar' - }) + '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) allBtnGroups = allBtnGroups.concat(options.additionalButtons[0]) + 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 additional group matches an existing group + var matchingGroups = $.grep(allBtnGroups, function(allButtonGroup, allIdx) { + return allButtonGroup.name === buttonGroup.name; + }); + + // if it matches add the additional 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 - }) + .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) + editorHeader = this.__buildButtons([allBtnGroups], editorHeader); } if (options.fullscreen.enable) { - editorHeader.append('
').on('click', '.md-control-fullscreen', function(e) { - e.preventDefault(); - instance.setFullscreen(true) - }) + editorHeader.append('
').on('click', '.md-control-fullscreen', function(e) { + e.preventDefault(); + instance.setFullscreen(true); + }); } - editor.append(editorHeader) + editor.append(editorHeader); // Wrap the textarea if (container.is('textarea')) { - container.before(editor) - textarea = container - textarea.addClass('md-input') - editor.append(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) + currentContent = $.trim(rawContent); // This is some arbitrary content that could be edited textarea = $(' - +
diff --git a/web_widget_text_markdown/views/main.xml b/web_widget_text_markdown/views/main.xml index e8a8ab26..73ab4309 100644 --- a/web_widget_text_markdown/views/main.xml +++ b/web_widget_text_markdown/views/main.xml @@ -1,6 +1,7 @@ - +