Rewrote JavaScript to be compatible with EcmaScript < 6. Clarified js docs in version_compare.js

This commit is contained in:
Benedikt Willi 2019-11-11 10:41:14 +01:00
parent 57d0a348bf
commit 765ac7a19d
2 changed files with 17 additions and 15 deletions

View file

@ -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);
})
}

View file

@ -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>