setup.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /* eslint-disable strict */
  6. define([
  7. 'jquery',
  8. 'underscore',
  9. 'wysiwygAdapter',
  10. 'module',
  11. 'mage/translate',
  12. 'prototype',
  13. 'mage/adminhtml/events',
  14. 'mage/adminhtml/browser'
  15. ], function (jQuery, _, wysiwygAdapter, module) {
  16. var baseConfig = module.config().config || {},
  17. wysiwygSetup = Class.create({
  18. wysiwygInstance: null
  19. });
  20. wysiwygSetup.prototype = {
  21. /**
  22. * @param {*} htmlId
  23. * @param {Object} config
  24. */
  25. initialize: function (htmlId, config) {
  26. var WysiwygInstancePrototype = new wysiwygAdapter.getAdapterPrototype();
  27. _.bindAll(this, 'openFileBrowser');
  28. config = _.extend({}, baseConfig, config || {});
  29. this.wysiwygInstance = new WysiwygInstancePrototype(htmlId, config);
  30. this.wysiwygInstance.eventBus = this.eventBus = new window.varienEvents();
  31. },
  32. /**
  33. * @param {*} mode
  34. */
  35. setup: function (mode) {
  36. this.wysiwygInstance.setup(mode);
  37. },
  38. /**
  39. * @param {Object} o
  40. */
  41. openFileBrowser: function (o) {
  42. this.wysiwygInstance.openFileBrowser(o);
  43. },
  44. /**
  45. * @return {Boolean}
  46. */
  47. toggle: function () {
  48. return this.wysiwygInstance.toggle();
  49. },
  50. /**
  51. * On form validation.
  52. */
  53. onFormValidation: function () {
  54. this.wysiwygInstance.onFormValidation();
  55. },
  56. /**
  57. * Encodes the content so it can be inserted into the wysiwyg
  58. * @param {String} content - The content to be encoded
  59. *
  60. * @returns {*} - The encoded content
  61. */
  62. updateContent: function (content) {
  63. return this.wysiwygInstance.encodeContent(content);
  64. }
  65. };
  66. window.wysiwygSetup = wysiwygSetup;
  67. return wysiwygSetup;
  68. });