FieldToolbarView.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 ($, _, Backbone, Drupal) {
  8. Drupal.quickedit.FieldToolbarView = Backbone.View.extend({
  9. $editedElement: null,
  10. editorView: null,
  11. _id: null,
  12. initialize: function initialize(options) {
  13. this.$editedElement = options.$editedElement;
  14. this.editorView = options.editorView;
  15. this.$root = this.$el;
  16. this._id = 'quickedit-toolbar-for-' + this.model.id.replace(/[/[\]]/g, '_');
  17. this.listenTo(this.model, 'change:state', this.stateChange);
  18. },
  19. render: function render() {
  20. this.setElement($(Drupal.theme('quickeditFieldToolbar', {
  21. id: this._id
  22. })));
  23. this.$el.prependTo(this.$root);
  24. return this;
  25. },
  26. stateChange: function stateChange(model, state) {
  27. var from = model.previous('state');
  28. var to = state;
  29. switch (to) {
  30. case 'inactive':
  31. break;
  32. case 'candidate':
  33. if (from !== 'inactive' && from !== 'highlighted') {
  34. this.$el.remove();
  35. this.setElement();
  36. }
  37. break;
  38. case 'highlighted':
  39. break;
  40. case 'activating':
  41. this.render();
  42. if (this.editorView.getQuickEditUISettings().fullWidthToolbar) {
  43. this.$el.addClass('quickedit-toolbar-fullwidth');
  44. }
  45. if (this.editorView.getQuickEditUISettings().unifiedToolbar) {
  46. this.insertWYSIWYGToolGroups();
  47. }
  48. break;
  49. case 'active':
  50. break;
  51. case 'changed':
  52. break;
  53. case 'saving':
  54. break;
  55. case 'saved':
  56. break;
  57. case 'invalid':
  58. break;
  59. }
  60. },
  61. insertWYSIWYGToolGroups: function insertWYSIWYGToolGroups() {
  62. this.$el.append(Drupal.theme('quickeditToolgroup', {
  63. id: this.getFloatedWysiwygToolgroupId(),
  64. classes: ['wysiwyg-floated', 'quickedit-animate-slow', 'quickedit-animate-invisible', 'quickedit-animate-delay-veryfast'],
  65. buttons: []
  66. })).append(Drupal.theme('quickeditToolgroup', {
  67. id: this.getMainWysiwygToolgroupId(),
  68. classes: ['wysiwyg-main', 'quickedit-animate-slow', 'quickedit-animate-invisible', 'quickedit-animate-delay-veryfast'],
  69. buttons: []
  70. }));
  71. this.show('wysiwyg-floated');
  72. this.show('wysiwyg-main');
  73. },
  74. getId: function getId() {
  75. return 'quickedit-toolbar-for-' + this._id;
  76. },
  77. getFloatedWysiwygToolgroupId: function getFloatedWysiwygToolgroupId() {
  78. return 'quickedit-wysiwyg-floated-toolgroup-for-' + this._id;
  79. },
  80. getMainWysiwygToolgroupId: function getMainWysiwygToolgroupId() {
  81. return 'quickedit-wysiwyg-main-toolgroup-for-' + this._id;
  82. },
  83. _find: function _find(toolgroup) {
  84. return this.$el.find('.quickedit-toolgroup.' + toolgroup);
  85. },
  86. show: function show(toolgroup) {
  87. var $group = this._find(toolgroup);
  88. $group.on(Drupal.quickedit.util.constants.transitionEnd, function (event) {
  89. $group.off(Drupal.quickedit.util.constants.transitionEnd);
  90. });
  91. window.setTimeout(function () {
  92. $group.removeClass('quickedit-animate-invisible');
  93. }, 0);
  94. }
  95. });
  96. })(jQuery, _, Backbone, Drupal);