plainTextEditor.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 {
  72. padding: true,
  73. unifiedToolbar: false,
  74. fullWidthToolbar: false,
  75. popup: false
  76. };
  77. },
  78. revert: function revert() {
  79. this.$textElement.html(this.model.get('originalValue'));
  80. }
  81. });
  82. })(jQuery, _, Drupal);