2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Backbone, Drupal) {
9 Drupal.quickedit.FieldDecorationView = Backbone.View.extend({
10 _widthAttributeIsEmpty: null,
13 'mouseenter.quickedit': 'onMouseEnter',
14 'mouseleave.quickedit': 'onMouseLeave',
16 'tabIn.quickedit': 'onMouseEnter',
17 'tabOut.quickedit': 'onMouseLeave'
20 initialize: function initialize(options) {
21 this.editorView = options.editorView;
23 this.listenTo(this.model, 'change:state', this.stateChange);
24 this.listenTo(this.model, 'change:isChanged change:inTempStore', this.renderChanged);
26 remove: function remove() {
28 Backbone.View.prototype.remove.call(this);
30 stateChange: function stateChange(model, state) {
31 var from = model.previous('state');
40 if (from !== 'inactive') {
42 if (from !== 'highlighted') {
43 this.model.set('isChanged', false);
51 this.startHighlight();
59 if (from !== 'activating') {
62 if (this.editorView.getQuickEditUISettings().padding) {
68 this.model.set('isChanged', true);
81 renderChanged: function renderChanged() {
82 this.$el.toggleClass('quickedit-changed', this.model.get('isChanged') || this.model.get('inTempStore'));
84 onMouseEnter: function onMouseEnter(event) {
86 that.model.set('state', 'highlighted');
87 event.stopPropagation();
89 onMouseLeave: function onMouseLeave(event) {
91 that.model.set('state', 'candidate', { reason: 'mouseleave' });
92 event.stopPropagation();
94 onClick: function onClick(event) {
95 this.model.set('state', 'activating');
96 event.preventDefault();
97 event.stopPropagation();
99 decorate: function decorate() {
100 this.$el.addClass('quickedit-candidate quickedit-editable');
102 undecorate: function undecorate() {
103 this.$el.removeClass('quickedit-candidate quickedit-editable quickedit-highlighted quickedit-editing');
105 startHighlight: function startHighlight() {
108 that.$el.addClass('quickedit-highlighted');
110 stopHighlight: function stopHighlight() {
111 this.$el.removeClass('quickedit-highlighted');
113 prepareEdit: function prepareEdit() {
114 this.$el.addClass('quickedit-editing');
116 if (this.editorView.getQuickEditUISettings().popup) {
117 this.$el.addClass('quickedit-editor-is-popup');
120 stopEdit: function stopEdit() {
121 this.$el.removeClass('quickedit-highlighted quickedit-editing');
123 if (this.editorView.getQuickEditUISettings().popup) {
124 this.$el.removeClass('quickedit-editor-is-popup');
127 $('.quickedit-candidate').addClass('quickedit-editable');
129 _pad: function _pad() {
130 if (this.$el.data('quickedit-padded')) {
135 if (this.$el[0].style.width === '') {
136 this._widthAttributeIsEmpty = true;
137 this.$el.addClass('quickedit-animate-disable-width').css('width', this.$el.width());
140 var posProp = this._getPositionProperties(this.$el);
141 setTimeout(function () {
142 self.$el.removeClass('quickedit-animate-disable-width');
145 position: 'relative',
146 top: posProp.top - 5 + 'px',
147 left: posProp.left - 5 + 'px',
148 'padding-top': posProp['padding-top'] + 5 + 'px',
149 'padding-left': posProp['padding-left'] + 5 + 'px',
150 'padding-right': posProp['padding-right'] + 5 + 'px',
151 'padding-bottom': posProp['padding-bottom'] + 5 + 'px',
152 'margin-bottom': posProp['margin-bottom'] - 10 + 'px'
153 }).data('quickedit-padded', true);
156 _unpad: function _unpad() {
157 if (!this.$el.data('quickedit-padded')) {
162 if (this._widthAttributeIsEmpty) {
163 this.$el.addClass('quickedit-animate-disable-width').css('width', '');
166 var posProp = this._getPositionProperties(this.$el);
167 setTimeout(function () {
168 self.$el.removeClass('quickedit-animate-disable-width');
171 position: 'relative',
172 top: posProp.top + 5 + 'px',
173 left: posProp.left + 5 + 'px',
174 'padding-top': posProp['padding-top'] - 5 + 'px',
175 'padding-left': posProp['padding-left'] - 5 + 'px',
176 'padding-right': posProp['padding-right'] - 5 + 'px',
177 'padding-bottom': posProp['padding-bottom'] - 5 + 'px',
178 'margin-bottom': posProp['margin-bottom'] + 10 + 'px'
182 this.$el.removeData('quickedit-padded');
184 _getPositionProperties: function _getPositionProperties($e) {
187 var props = ['top', 'left', 'bottom', 'right', 'padding-top', 'padding-left', 'padding-right', 'padding-bottom', 'margin-bottom'];
189 var propCount = props.length;
190 for (var i = 0; i < propCount; i++) {
192 r[p] = parseInt(this._replaceBlankPosition($e.css(p)), 10);
196 _replaceBlankPosition: function _replaceBlankPosition(pos) {
197 if (pos === 'auto' || !pos) {
203 })(jQuery, Backbone, Drupal);