Skip to content

Commit 25ee435

Browse files
author
Dominik Tomasi
committed
compare versions in a separated function
1 parent ba3b656 commit 25ee435

1 file changed

Lines changed: 63 additions & 5 deletions

File tree

system/modules/multicolumnwizard/html/js/multicolumnwizard_be_src.js

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,11 @@ var MultiColumnWizard = new Class(
443443

444444
reinitStylect: function()
445445
{
446-
var build = $('top').get('class').match(/build_\d+/g);
447-
build = build[0];
448-
build = build.replace('build_', '').toInt();
446+
var version = parseContaoVersion();
447+
449448
if(window.Stylect)
450449
{
451-
if (!($('top').hasClass('version_3-2') && build > 3)) {
450+
if (versionCompare('3.2.3',version) >= 0) {
452451
$$('.styled_select').each(function(item, index){
453452
item.dispose();
454453
});
@@ -756,4 +755,63 @@ MultiColumnWizard.addOperationClickCallback('down', MultiColumnWizard.downClick)
756755
}
757756
}, 500);
758757
};
759-
})(window.Backend);
758+
})(window.Backend);
759+
760+
/**
761+
* Simply compares two string version values.
762+
*
763+
* Example:
764+
* versionCompare('1.1', '1.2') => -1
765+
* versionCompare('1.1', '1.1') => 0
766+
* versionCompare('1.2', '1.1') => 1
767+
* versionCompare('2.23.3', '2.22.3') => 1
768+
*
769+
* Returns:
770+
* -1 = left is LOWER than right
771+
* 0 = they are equal
772+
* 1 = left is GREATER = right is LOWER
773+
* And FALSE if one of input versions are not valid
774+
*
775+
* @function
776+
* @param {String} left Version #1
777+
* @param {String} right Version #2
778+
* @return {Integer|Boolean}
779+
* @author Alexey Bass (albass)
780+
* @since 2011-07-14
781+
*/
782+
versionCompare = function(left, right) {
783+
if (typeof left + typeof right != 'stringstring')
784+
return false;
785+
786+
var a = left.split('.')
787+
, b = right.split('.')
788+
, i = 0, len = Math.max(a.length, b.length);
789+
790+
for (; i < len; i++) {
791+
if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) {
792+
return 1;
793+
} else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) {
794+
return -1;
795+
}
796+
}
797+
798+
return 0;
799+
};
800+
801+
/**
802+
* Parse the Version of Contao from Class "top"
803+
* see: MultiColumnWizardHelper::addVersionToClass()
804+
*
805+
* @function
806+
* @return {String}
807+
*/
808+
parseContaoVersion = function() {
809+
810+
// Get Version-Class and convert it to a valid Version-String
811+
var version = $('top').get('class').match(/version_[^\s]*/);
812+
version = version[0];
813+
version = version.replace('version_', '');
814+
version = version.split('-').join('.');
815+
816+
return version
817+
};

0 commit comments

Comments
 (0)