Commit ab89e765 authored by Robert Lyon's avatar Robert Lyon
Browse files

Always specify what base type we want returned from parseInt()



Bug 1394330

In most places in mahara we specify that we want base 10 number
returned (or base 16 in case of a hexidecimal css colour)

But there are a few places where we don't specify the radix at all

It's best practice to always include the radix because for older
browsers it interprets leading 0 as octal by default.

Also makes it clearer to developers what type of number is expected to
be retrieved from the string.

Change-Id: Iaecc85cbed875f85b313188c4e96cc1b77c77b31
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent dc706458
...@@ -87,7 +87,7 @@ function delete_success(form, data) { ...@@ -87,7 +87,7 @@ function delete_success(form, data) {
addElementClass('postdescription_' + data.id, 'hidden'); addElementClass('postdescription_' + data.id, 'hidden');
addElementClass('posttitle_' + data.id, 'hidden'); addElementClass('posttitle_' + data.id, 'hidden');
var results = \$j('#blogpost_pagination div.results').html(); var results = \$j('#blogpost_pagination div.results').html();
var oldcount = parseInt(results); var oldcount = parseInt(results, 10);
var newcount = oldcount - 1; var newcount = oldcount - 1;
\$j('#blogpost_pagination div.results').html(results.replace(oldcount, newcount)); \$j('#blogpost_pagination div.results').html(results.replace(oldcount, newcount));
progressbarUpdate('blogpost', true); progressbarUpdate('blogpost', true);
......
...@@ -14,9 +14,9 @@ $j(function() { ...@@ -14,9 +14,9 @@ $j(function() {
if ($j('#thumbnails{$instanceid}')) { if ($j('#thumbnails{$instanceid}')) {
// adjust height of image + description box to align things up // adjust height of image + description box to align things up
var maxHeight = Math.max.apply(null, $j('#thumbnails{$instanceid} .thumb').map(function() { var maxHeight = Math.max.apply(null, $j('#thumbnails{$instanceid} .thumb').map(function() {
var height = parseInt($j(this).find('img').attr('height')); var height = parseInt($j(this).find('img').attr('height'), 10);
if ($j(this).find('.caption').length > 0) { if ($j(this).find('.caption').length > 0) {
height += parseInt($j(this).find('.caption').height()); height += parseInt($j(this).find('.caption').height(), 10);
} }
return (height + 3); // we will give it a little more heigth to avoid a vertical scrollbar sometimes appearing return (height + 3); // we will give it a little more heigth to avoid a vertical scrollbar sometimes appearing
}).get()); }).get());
......
...@@ -14,9 +14,9 @@ $j(function() { ...@@ -14,9 +14,9 @@ $j(function() {
if ($j('#thumbnails{$instanceid}')) { if ($j('#thumbnails{$instanceid}')) {
// adjust height of image + description box to align things up // adjust height of image + description box to align things up
var maxHeight = Math.max.apply(null, $j('#thumbnails{$instanceid} .thumb').map(function() { var maxHeight = Math.max.apply(null, $j('#thumbnails{$instanceid} .thumb').map(function() {
var height = parseInt($j(this).find('img').attr('height')); var height = parseInt($j(this).find('img').attr('height'), 10);
if ($j(this).find('.caption').length > 0) { if ($j(this).find('.caption').length > 0) {
height += parseInt($j(this).find('.caption').height()); height += parseInt($j(this).find('.caption').height(), 10);
} }
return (height + 3); // we will give it a little more heigth to avoid a vertical scrollbar sometimes appearing return (height + 3); // we will give it a little more heigth to avoid a vertical scrollbar sometimes appearing
}).get()); }).get());
......
...@@ -172,9 +172,9 @@ deconcept.SWFObjectUtil.getPlayerVersion = function(){ ...@@ -172,9 +172,9 @@ deconcept.SWFObjectUtil.getPlayerVersion = function(){
return PlayerVersion; return PlayerVersion;
} }
deconcept.PlayerVersion = function(arrVersion){ deconcept.PlayerVersion = function(arrVersion){
this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0; this.major = arrVersion[0] != null ? parseInt(arrVersion[0], 10) : 0;
this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0; this.minor = arrVersion[1] != null ? parseInt(arrVersion[1], 10) : 0;
this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0; this.rev = arrVersion[2] != null ? parseInt(arrVersion[2], 10) : 0;
} }
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){ deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
if(this.major < fv.major) return false; if(this.major < fv.major) return false;
......
...@@ -1133,7 +1133,7 @@ EOF; ...@@ -1133,7 +1133,7 @@ EOF;
$downloadstr = json_encode(get_string('Download', 'artefact.file')); $downloadstr = json_encode(get_string('Download', 'artefact.file'));
return <<<EOF return <<<EOF
function formatSize(size) { function formatSize(size) {
size = parseInt(size); size = parseInt(size, 10);
if (size < 1024) { if (size < 1024) {
return size <= 0 ? '0' : size.toFixed(1).replace(/\.0$/, '') + 'b'; return size <= 0 ? '0' : size.toFixed(1).replace(/\.0$/, '') + 'b';
} }
......
...@@ -13,4 +13,5 @@ Modifications: ...@@ -13,4 +13,5 @@ Modifications:
- renamed 'style.css' to 'cookieconsent.css' and copied/moved it to htdocs/raw/static/style - renamed 'style.css' to 'cookieconsent.css' and copied/moved it to htdocs/raw/static/style
- decrease all font-size properties in 'cookieconsent.css' for smaller text (all changes marked with: /*changed*/) - decrease all font-size properties in 'cookieconsent.css' for smaller text (all changes marked with: /*changed*/)
- changed some height and max-height properties in 'cookieconsent.css' (all changes marked with: /*changed*/) - changed some height and max-height properties in 'cookieconsent.css' (all changes marked with: /*changed*/)
- Set the cookie's "secure" flag if the page is served via HTTPS - Set the cookie's "secure" flag if the page is served via HTTPS
\ No newline at end of file - Altered the parseInt() js calls to return number in base 10
\ No newline at end of file
...@@ -228,8 +228,8 @@ var cc = ...@@ -228,8 +228,8 @@ var cc =
jqueryOk = true; jqueryOk = true;
for(i = 0; i < parts.length && i < versionRequired.length; i++) for(i = 0; i < parts.length && i < versionRequired.length; i++)
{ {
currentpart = parseInt(parts[i]); currentpart = parseInt(parts[i], 10);
requiredpart = parseInt(versionRequired[i]); requiredpart = parseInt(versionRequired[i], 10);
if(currentpart < requiredpart) if(currentpart < requiredpart)
{ {
/* Unsatisfied - this part of the version string is less than the version we require */ /* Unsatisfied - this part of the version string is less than the version we require */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// Public Methods // Public Methods
CustomLayoutManager.customlayout_add_row = function() { CustomLayoutManager.customlayout_add_row = function() {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val()); var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
if ((numrows < get_max_custom_rows()) && (numrows >= 1)) { if ((numrows < get_max_custom_rows()) && (numrows >= 1)) {
var newrow = $('#customrow_' + numrows).clone(); var newrow = $('#customrow_' + numrows).clone();
var currentncols = $('#customrow_' + numrows).find('#selectnumcolsrow_' + numrows).val(); var currentncols = $('#customrow_' + numrows).find('#selectnumcolsrow_' + numrows).val();
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
customlayout_change_layout(); customlayout_change_layout();
} }
if (parseInt($('#viewlayout_customlayoutnumrows').val()) >= get_max_custom_rows()) { if (parseInt($('#viewlayout_customlayoutnumrows').val(), 10) >= get_max_custom_rows()) {
$('#addrow').attr('disabled', 'disabled'); $('#addrow').attr('disabled', 'disabled');
} }
}; };
CustomLayoutManager.customlayout_remove_row = function(row) { CustomLayoutManager.customlayout_remove_row = function(row) {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val()); var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
$(row).closest('.customrow').remove(); $(row).closest('.customrow').remove();
$('#viewlayout_customlayoutnumrows').val(numrows - 1); $('#viewlayout_customlayoutnumrows').val(numrows - 1);
var inc = 1; var inc = 1;
...@@ -44,14 +44,14 @@ ...@@ -44,14 +44,14 @@
}); });
customlayout_change_layout(); customlayout_change_layout();
if (parseInt($('#viewlayout_customlayoutnumrows').val()) < get_max_custom_rows()) { if (parseInt($('#viewlayout_customlayoutnumrows').val(), 10) < get_max_custom_rows()) {
$('#addrow').removeAttr('disabled'); $('#addrow').removeAttr('disabled');
} }
}; };
CustomLayoutManager.customlayout_change_numcolumns = function(columnoptions) { CustomLayoutManager.customlayout_change_numcolumns = function(columnoptions) {
var currentrow = $(columnoptions).attr('id').substr($(columnoptions).attr('id').lastIndexOf('_') + 1); var currentrow = $(columnoptions).attr('id').substr($(columnoptions).attr('id').lastIndexOf('_') + 1);
var numcols = parseInt(columnoptions.options[columnoptions.selectedIndex].value); var numcols = parseInt(columnoptions.options[columnoptions.selectedIndex].value, 10);
// reverse in order to select the first option // reverse in order to select the first option
$.each($('#selectcollayoutrow_' + currentrow + ' > option').get().reverse(), function() { $.each($('#selectcollayoutrow_' + currentrow + ' > option').get().reverse(), function() {
if (this.text.split('-').length != numcols) { if (this.text.split('-').length != numcols) {
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
}; };
CustomLayoutManager.customlayout_submit_layout = function() { CustomLayoutManager.customlayout_submit_layout = function() {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val()); var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
var collayouts = ''; var collayouts = '';
for (i=0; i<numrows; i++) { for (i=0; i<numrows; i++) {
collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val(); collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val();
...@@ -203,7 +203,7 @@ ...@@ -203,7 +203,7 @@
} }
function customlayout_change_layout() { function customlayout_change_layout() {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val()); var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
var collayouts = ''; var collayouts = '';
for (i=0; i<numrows; i++) { for (i=0; i<numrows; i++) {
collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val(); collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val();
......
...@@ -16,7 +16,7 @@ function get_string(s) { ...@@ -16,7 +16,7 @@ function get_string(s) {
if (typeof(str) == 'object') { if (typeof(str) == 'object') {
var index = 0; var index = 0;
if (args.length > 0 && typeof(plural) == 'function') { if (args.length > 0 && typeof(plural) == 'function') {
index = plural(parseInt(args[0])); index = plural(parseInt(args[0], 10));
if (typeof(index) == 'boolean') { if (typeof(index) == 'boolean') {
index = index ? 1 : 0; index = index ? 1 : 0;
} }
...@@ -721,8 +721,8 @@ function progressbarUpdate(artefacttype, remove) { ...@@ -721,8 +721,8 @@ function progressbarUpdate(artefacttype, remove) {
// if we have the artefacttype and it needs to be updated // if we have the artefacttype and it needs to be updated
if (typeof artefacttype != 'undefined') { if (typeof artefacttype != 'undefined') {
if ($('progress_counting_' + artefacttype)) { if ($('progress_counting_' + artefacttype)) {
var counting = parseInt($('progress_counting_' + artefacttype).innerHTML); var counting = parseInt($('progress_counting_' + artefacttype).innerHTML, 10);
var oldcompleted = parseInt($('progress_completed_' + artefacttype).innerHTML); var oldcompleted = parseInt($('progress_completed_' + artefacttype).innerHTML, 10);
var completed = oldcompleted + change; var completed = oldcompleted + change;
$('progress_completed_' + artefacttype).innerHTML = completed; $('progress_completed_' + artefacttype).innerHTML = completed;
var progressitem = $('progress_item_' + artefacttype); var progressitem = $('progress_item_' + artefacttype);
...@@ -737,8 +737,8 @@ function progressbarUpdate(artefacttype, remove) { ...@@ -737,8 +737,8 @@ function progressbarUpdate(artefacttype, remove) {
} }
// now update the totals if we need to // now update the totals if we need to
if ((oldcompleted > 0 && oldcompleted <= counting && remove ) || (completed <= counting && !remove)) { if ((oldcompleted > 0 && oldcompleted <= counting && remove ) || (completed <= counting && !remove)) {
var totalcounting = parseInt($('progress_counting_total').innerHTML); var totalcounting = parseInt($('progress_counting_total').innerHTML, 10);
var totalcompleted = parseInt($('progress_completed_total').innerHTML) + change; var totalcompleted = parseInt($('progress_completed_total').innerHTML, 10) + change;
$('progress_completed_total').innerHTML = totalcompleted; $('progress_completed_total').innerHTML = totalcompleted;
var percentage = roundToFixed((totalcompleted / totalcounting) * 100, 0); var percentage = roundToFixed((totalcompleted / totalcounting) * 100, 0);
$('progress_bar_percentage').innerHTML = percentage + '%'; $('progress_bar_percentage').innerHTML = percentage + '%';
......
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
// to make sure the 'floating' panel when opened is not longer than // to make sure the 'floating' panel when opened is not longer than
// the 'containing' div // the 'containing' div
var editwrapper = $('#editcontent-sidebar-wrapper'); var editwrapper = $('#editcontent-sidebar-wrapper');
var editwrapperheight = (parseInt(editwrapper.css('height')) + parseInt(editwrapper.css('padding-top')) + parseInt(editwrapper.css('padding-bottom'))); var editwrapperheight = (parseInt(editwrapper.css('height'), 10) + parseInt(editwrapper.css('padding-top'), 10) + parseInt(editwrapper.css('padding-bottom'), 10));
if ($('#main-column').height() < editwrapperheight) { if ($('#main-column').height() < editwrapperheight) {
var windowWidth = windowWide(); var windowWidth = windowWide();
if (windowWidth) { if (windowWidth) {
...@@ -522,7 +522,7 @@ ...@@ -522,7 +522,7 @@
$(this).closest('.cellchooser').find('.active').removeClass('active'); $(this).closest('.cellchooser').find('.active').removeClass('active');
$(this).parent().addClass('active'); $(this).parent().addClass('active');
var position = $(this).val().split('-'); var position = $(this).val().split('-');
var element = $('#column-container > .row').eq(parseInt(position[0]) - 1).find('.column').eq(parseInt(position[1]) - 1); var element = $('#column-container > .row').eq(parseInt(position[0], 10) - 1).find('.column').eq(parseInt(position[1], 10) - 1);
var options = [get_string('blockordertop')]; var options = [get_string('blockordertop')];
element.find('.column-content .blockinstance .blockinstance-header').each(function() { element.find('.column-content .blockinstance .blockinstance-header').each(function() {
options.push(get_string('blockorderafter', $(this).find('h2.title').text())); options.push(get_string('blockorderafter', $(this).find('h2.title').text()));
......
...@@ -113,12 +113,12 @@ ...@@ -113,12 +113,12 @@
// Update the counters if they are present // Update the counters if they are present
if ($('{{$name}}_userlimit')) { if ($('{{$name}}_userlimit')) {
if (from.id == '{{$name}}_potential') { if (from.id == '{{$name}}_potential') {
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML) - list.length); replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML, 10) - list.length);
replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML) - list.length); replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML, 10) - list.length);
} }
else { else {
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML) + list.length); replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML, 10) + list.length);
replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML) + list.length); replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML, 10) + list.length);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment