wpml-tm-editor-group-view.js
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*global Backbone, jQuery*/
var WPML_TM = WPML_TM || {};
(function () {
"use strict";
WPML_TM.editorGroupView = Backbone.View.extend({
tagName: 'div',
className: 'wpml-form-row wpml-field-group',
events: {
'click .js-button-copy-group': 'onCopy',
'update_button_state .js-button-copy-group': 'setCopyButtonState'
},
render: function (group) {
var self = this;
self.$el.html(WPML_TM['templates/translation-editor/group.html'](group));
},
setup: function () {
this.$el.find('.js-button-copy').css({visibility: 'hidden'});
this.initializeGroupCopyButtons();
this.setCopyButtonState();
},
initializeGroupCopyButtons: function () {
var self = this;
// Poistion the copy button so it's between the original and translation
self.$el.find('.js-button-copy:first').each(function () {
// center the button in group
var groupCopyButton = self.$el.find('.js-button-copy-group');
var firstButton = jQuery(this);
var lastButton = self.$el.find('.js-button-copy:last');
if (lastButton.length) {
var groupHeight = lastButton.position().top + lastButton.height() - firstButton.position().top;
var newTop = groupHeight / 2 - groupCopyButton.height() / 2;
groupCopyButton.css({
'position': 'relative',
'top': newTop
});
}
groupCopyButton.insertAfter(firstButton);
// hide the original copy button
firstButton.hide();
});
},
onCopy: function () {
this.$el.find('.js-button-copy').trigger('click');
},
setCopyButtonState: function () {
this.$el.find('.js-button-copy-group').prop('disabled', this.$el.find('.js-button-copy:disabled').length > 0);
}
});
}());