mirror of
https://github.com/Hopiu/wagtail-modeltranslation.git
synced 2026-03-16 22:10:30 +00:00
Rewrote JavaScript to be compatible with EcmaScript < 6. Clarified js docs in version_compare.js
This commit is contained in:
parent
57d0a348bf
commit
765ac7a19d
2 changed files with 17 additions and 15 deletions
|
|
@ -17,27 +17,27 @@ $(document).ready(function(){
|
|||
// Wagtail < 2.6
|
||||
header = $(currentStreamField).children('h2')[0];
|
||||
//Search for the input field so that we can get is id to know the field's name.
|
||||
let streamFieldDiv = $(currentStreamField).find('div.sequence-container.sequence-type-stream')[0];
|
||||
let fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
let lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
var streamFieldDiv = $(currentStreamField).find('div.sequence-container.sequence-type-stream')[0];
|
||||
var fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
var lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
fieldName = fieldInfos.substring(0, lastUnderscore);
|
||||
fieldLang = fieldInfos.substring(lastUnderscore + 1, fieldInfos.length);
|
||||
} else if(versionCompare(WAGTAIL_VERSION,'2.7.0', {zeroExtend: true})===-1){
|
||||
// Wagtail < 2.7
|
||||
header = $(currentStreamField).children('.title-wrapper')[0];
|
||||
//Search for the input field so that we can get is id to know the field's name.
|
||||
let streamFieldDiv = $(currentStreamField).find('div.sequence-container.sequence-type-stream')[0];
|
||||
let fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
let lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
var streamFieldDiv = $(currentStreamField).find('div.sequence-container.sequence-type-stream')[0];
|
||||
var fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
var lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
fieldName = fieldInfos.substring(0, lastUnderscore);
|
||||
fieldLang = fieldInfos.substring(lastUnderscore + 1, fieldInfos.length);
|
||||
} else {
|
||||
// Wagtail >= 2.7
|
||||
header = $(currentStreamField).children('.title-wrapper')[0];
|
||||
//Search for the input field so that we can get is id to know the field's name.
|
||||
let streamFieldDiv = $(currentStreamField).find('.field-content')[0];
|
||||
let fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
let lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
var streamFieldDiv = $(currentStreamField).find('.field-content')[0];
|
||||
var fieldInfos = $(streamFieldDiv).find('input')[0].id.split('-')[0];
|
||||
var lastUnderscore = fieldInfos.lastIndexOf("_");
|
||||
fieldName = fieldInfos.substring(0, lastUnderscore);
|
||||
fieldLang = fieldInfos.substring(lastUnderscore + 1, fieldInfos.length);
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ $(document).ready(function(){
|
|||
if (fieldLang != langs[j]) {
|
||||
var currentFieldID = fieldName + '_' + fieldLang;
|
||||
var targetFieldID = fieldName + '_' + langs [j];
|
||||
$(header).children('.translation-field-copy-wrapper')[0].innerHTML += `<button class="button translation-field-copy" current-lang-code="${currentFieldID}" data-lang-code="${targetFieldID}">${langs[j]}</button>`;
|
||||
$(header).children('.translation-field-copy-wrapper')[0].innerHTML += '<button class="button translation-field-copy" current-lang-code="' + currentFieldID + '" data-lang-code="' + targetFieldID + '">' + langs[j] + '</button>';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -80,11 +80,11 @@ function requestCopyField(originID, targetID) {
|
|||
})
|
||||
.done(function(data) {
|
||||
/* Put the html data in the targetID field */
|
||||
var wrapperDiv = $(`#${targetID}-count`).parents('.input')[0];
|
||||
var wrapperDiv = $('#' + targetID + '-count').parents('.input')[0];
|
||||
$(wrapperDiv).html(data);
|
||||
})
|
||||
.fail(function(error) {
|
||||
console.log(`wagtail-modeltranslation error: ${error.responseText}`);
|
||||
console.log('wagtail-modeltranslation error: ' + error.responseText);
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@
|
|||
*
|
||||
* @param {string} v1 The first version to be compared.
|
||||
* @param {string} v2 The second version to be compared.
|
||||
* @param {object} [options] Optional flags that affect comparison behavior:
|
||||
* @param {object} [options] Optional flags that affect comparison behavior.
|
||||
* @param {boolean} [options.lexicographical = false] Switch to compare version strings lexicographically instead of naturally.
|
||||
* @param {boolean} [options.zeroExtend = false] Switch to pad version with "zero" parts instead to be considered smaller.
|
||||
* <ul>
|
||||
* <li>
|
||||
* <tt>lexicographical: false</tt> compares each part of the version strings lexicographically instead of
|
||||
* <tt>lexicographical: true</tt> compares each part of the version strings lexicographically instead of
|
||||
* naturally; this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than
|
||||
* "1.2".
|
||||
* </li>
|
||||
* <li>
|
||||
* <tt>zeroExtend: false</tt> changes the result if one version string has less parts than the other. In
|
||||
* <tt>zeroExtend: true</tt> changes the result if one version string has less parts than the other. In
|
||||
* this case the shorter string will be padded with "zero" parts instead of being considered smaller.
|
||||
* </li>
|
||||
* </ul>
|
||||
|
|
|
|||
Loading…
Reference in a new issue