plainTextEditor.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, _, Drupal) {
  8. Drupal.quickedit.editors.plain_text = Drupal.quickedit.EditorView.extend({
  9. $textElement: null,
  10. initialize: function initialize(options) {
  11. Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
  12. var editorModel = this.model;
  13. var fieldModel = this.fieldModel;
  14. var $fieldItems = this.$el.find('.quickedit-field');
  15. var $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el;
  16. this.$textElement = $textElement;
  17. editorModel.set('originalValue', $.trim(this.$textElement.text()));
  18. var previousText = editorModel.get('originalValue');
  19. $textElement.on('keyup paste', function (event) {
  20. var currentText = $.trim($textElement.text());
  21. if (previousText !== currentText) {
  22. previousText = currentText;
  23. editorModel.set('currentValue', currentText);
  24. fieldModel.set('state', 'changed');
  25. }
  26. });
  27. },
  28. getEditedElement: function getEditedElement() {
  29. return this.$textElement;
  30. },
  31. stateChange: function stateChange(fieldModel, state, options) {
  32. var from = fieldModel.previous('state');
  33. var to = state;
  34. switch (to) {
  35. case 'inactive':
  36. break;
  37. case 'candidate':
  38. if (from !== 'inactive') {
  39. this.$textElement.removeAttr('contenteditable');
  40. }
  41. if (from === 'invalid') {
  42. this.removeValidationErrors();
  43. }
  44. break;
  45. case 'highlighted':
  46. break;
  47. case 'activating':
  48. _.defer(function () {
  49. fieldModel.set('state', 'active');
  50. });
  51. break;
  52. case 'active':
  53. this.$textElement.attr('contenteditable', 'true');
  54. break;
  55. case 'changed':
  56. break;
  57. case 'saving':
  58. if (from === 'invalid') {
  59. this.removeValidationErrors();
  60. }
  61. this.save(options);
  62. break;
  63. case 'saved':
  64. break;
  65. case 'invalid':
  66. this.showValidationErrors();
  67. break;
  68. }
  69. },
  70. getQuickEditUISettings: function getQuickEditUISettings() {
  71. return { padding: true, unifiedToolbar: false, fullWidthToolbar: false, popup: false };
  72. },
  73. revert: function revert() {
  74. this.$textElement.html(this.model.get('originalValue'));
  75. }
  76. });
  77. })(jQuery, _, Drupal);