-
Notifications
You must be signed in to change notification settings - Fork 80
/
CMSMain.Translatable.js
executable file
·64 lines (58 loc) · 1.51 KB
/
CMSMain.Translatable.js
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
63
64
/**
* File: CMSMain.Translatable.js
*/
(function($) {
$.entwine('ss', function($){
/**
* Class: .CMSMain #Form_LangForm
*
* Dropdown with languages above CMS tree, causing a redirect upon translation
*/
$('.CMSMain #Form_LangForm').entwine({
/**
* Constructor: onmatch
*/
onmatch: function() {
var self = this;
// monitor form loading for any locale changes
$('#Form_EditForm').bind('loadnewpage', function(e) {
var newLocale = $(this).find(':input[name=Locale]').val();
if(newLocale) self.val(newLocale);
});
this._super();
}
});
/**
* whenever a new value is selected, reload the whole CMS in the new locale
*/
$('.CMSMain #Form_LangForm :input[name=Locale]').entwine({
onchange: function(e) {
var url = $.path.addSearchParams(
document.location.href.replace(/locale=[^&]*/, ''),
{locale: $(e.target).val()}
);
$('.cms-container').loadPanel(url);
return false;
}
});
/**
* Class: .CMSMain .createTranslation
*
* Loads /admin/createtranslation, which will create the new record,
* and redirect to an edit form.
*
* Dropdown in "Translation" tab in CMS forms, with button to
* trigger translating the currently loaded record.
*
* Requires:
* jquery.metadata
*/
$('.LeftAndMain :input[name=action_createtranslation]').entwine({
onclick: function(e) {
this.parents('form').trigger('submit', [this]);
e.preventDefault();
return false;
}
});
});
}(jQuery));