[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/com_mails/js/ -> admin-email-template-edit-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    /**
   5     * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   6     * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7     */
   8    (function (document, Joomla) {
   9      var EmailTemplateEdit = /*#__PURE__*/function () {
  10        function EmailTemplateEdit(form, options) {
  11          // Set elements
  12          this.form = form;
  13          this.inputSubject = this.form.querySelector('#jform_subject');
  14          this.inputBody = this.form.querySelector('#jform_body');
  15          this.inputHtmlBody = this.form.querySelector('#jform_htmlbody'); // Set options
  16  
  17          this.templateData = options && options.templateData ? options.templateData : {}; // Add back reference
  18  
  19          this.form.EmailTemplateEdit = this;
  20        }
  21  
  22        var _proto = EmailTemplateEdit.prototype;
  23  
  24        _proto.setBodyValue = function setBodyValue(value) {
  25          if (Joomla.editors.instances[this.inputBody.id]) {
  26            Joomla.editors.instances[this.inputBody.id].setValue(value);
  27          } else {
  28            this.inputBody.value = value;
  29          }
  30        };
  31  
  32        _proto.setHtmlBodyValue = function setHtmlBodyValue(value) {
  33          if (Joomla.editors.instances[this.inputHtmlBody.id]) {
  34            Joomla.editors.instances[this.inputHtmlBody.id].setValue(value);
  35          } else {
  36            this.inputHtmlBody.value = value;
  37          }
  38        };
  39  
  40        _proto.insertTag = function insertTag(tag, targetField) {
  41          if (!tag) return false;
  42          var input;
  43  
  44          switch (targetField) {
  45            case 'body':
  46              input = this.inputBody;
  47              break;
  48  
  49            case 'htmlbody':
  50              input = this.inputHtmlBody;
  51              break;
  52  
  53            default:
  54              return false;
  55          }
  56  
  57          if (Joomla.editors.instances[input.id]) {
  58            Joomla.editors.instances[input.id].replaceSelection(tag);
  59          } else {
  60            input.value += " " + tag;
  61          }
  62  
  63          return true;
  64        };
  65  
  66        _proto.bindListeners = function bindListeners() {
  67          var _this = this;
  68  
  69          document.querySelector('#btnResetSubject').addEventListener('click', function (event) {
  70            event.preventDefault();
  71            _this.inputSubject.value = _this.templateData.subject ? _this.templateData.subject : '';
  72          });
  73          var btnResetBody = document.querySelector('#btnResetBody');
  74  
  75          if (btnResetBody) {
  76            btnResetBody.addEventListener('click', function (event) {
  77              event.preventDefault();
  78  
  79              _this.setBodyValue(_this.templateData.body ? _this.templateData.body : '');
  80            });
  81          }
  82  
  83          var btnResetHtmlBody = document.querySelector('#btnResetHtmlBody');
  84  
  85          if (btnResetHtmlBody) {
  86            btnResetHtmlBody.addEventListener('click', function (event) {
  87              event.preventDefault();
  88  
  89              _this.setHtmlBodyValue(_this.templateData.htmlbody ? _this.templateData.htmlbody : '');
  90            });
  91          } // Buttons for inserting a tag
  92  
  93  
  94          this.form.querySelectorAll('.edit-action-add-tag').forEach(function (button) {
  95            button.addEventListener('click', function (event) {
  96              event.preventDefault();
  97              var el = event.target;
  98  
  99              _this.insertTag(el.dataset.tag, el.dataset.target);
 100            });
 101          });
 102        };
 103  
 104        return EmailTemplateEdit;
 105      }();
 106  
 107      document.addEventListener('DOMContentLoaded', function () {
 108        var editor = new EmailTemplateEdit(document.getElementById('item-form'), Joomla.getOptions('com_mails'));
 109        editor.bindListeners();
 110      });
 111    })(document, Joomla);
 112  
 113  })();


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer