Commit 3743dcf6 authored by Robert Lyon's avatar Robert Lyon

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 aeda6261
......@@ -106,7 +106,7 @@ function delete_success(form, data) {
addElementClass('postdescription_' + data.id, 'hidden');
addElementClass('posttitle_' + data.id, 'hidden');
var results = \$j('#blogpost_pagination div.results').html();
var oldcount = parseInt(results);
var oldcount = parseInt(results, 10);
var newcount = oldcount - 1;
\$j('#blogpost_pagination div.results').html(results.replace(oldcount, newcount));
progressbarUpdate('blogpost', true);
......
......@@ -172,9 +172,9 @@ deconcept.SWFObjectUtil.getPlayerVersion = function(){
return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
this.major = arrVersion[0] != null ? parseInt(arrVersion[0], 10) : 0;
this.minor = arrVersion[1] != null ? parseInt(arrVersion[1], 10) : 0;
this.rev = arrVersion[2] != null ? parseInt(arrVersion[2], 10) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
if(this.major < fv.major) return false;
......
......@@ -1133,7 +1133,7 @@ EOF;
$downloadstr = json_encode(get_string('Download', 'artefact.file'));
return <<<EOF
function formatSize(size) {
size = parseInt(size);
size = parseInt(size, 10);
if (size < 1024) {
return size <= 0 ? '0' : size.toFixed(1).replace(/\.0$/, '') + 'b';
}
......
......@@ -13,4 +13,5 @@ Modifications:
- 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*/)
- 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
\ No newline at end of file
- Set the cookie's "secure" flag if the page is served via HTTPS
- Altered the parseInt() js calls to return number in base 10
\ No newline at end of file
......@@ -228,8 +228,8 @@ var cc =
jqueryOk = true;
for(i = 0; i < parts.length && i < versionRequired.length; i++)
{
currentpart = parseInt(parts[i]);
requiredpart = parseInt(versionRequired[i]);
currentpart = parseInt(parts[i], 10);
requiredpart = parseInt(versionRequired[i], 10);
if(currentpart < requiredpart)
{
/* Unsatisfied - this part of the version string is less than the version we require */
......
......@@ -3,7 +3,7 @@
// Public Methods
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)) {
var newrow = $('#customrow_' + numrows).clone();
var currentncols = $('#customrow_' + numrows).find('#selectnumcolsrow_' + numrows).val();
......@@ -25,13 +25,13 @@
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');
}
};
CustomLayoutManager.customlayout_remove_row = function(row) {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val());
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
$(row).closest('.customrow').remove();
$('#viewlayout_customlayoutnumrows').val(numrows - 1);
var inc = 1;
......@@ -44,14 +44,14 @@
});
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');
}
};
CustomLayoutManager.customlayout_change_numcolumns = function(columnoptions) {
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
$.each($('#selectcollayoutrow_' + currentrow + ' > option').get().reverse(), function() {
if (this.text.split('-').length != numcols) {
......@@ -71,7 +71,7 @@
};
CustomLayoutManager.customlayout_submit_layout = function() {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val());
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
var collayouts = '';
for (i=0; i<numrows; i++) {
collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val();
......@@ -203,7 +203,7 @@
}
function customlayout_change_layout() {
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val());
var numrows = parseInt($('#viewlayout_customlayoutnumrows').val(), 10);
var collayouts = '';
for (i=0; i<numrows; i++) {
collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val();
......
......@@ -16,7 +16,7 @@ function get_string(s) {
if (typeof(str) == 'object') {
var index = 0;
if (args.length > 0 && typeof(plural) == 'function') {
index = plural(parseInt(args[0]));
index = plural(parseInt(args[0], 10));
if (typeof(index) == 'boolean') {
index = index ? 1 : 0;
}
......@@ -721,8 +721,8 @@ function progressbarUpdate(artefacttype, remove) {
// if we have the artefacttype and it needs to be updated
if (typeof artefacttype != 'undefined') {
if ($('progress_counting_' + artefacttype)) {
var counting = parseInt($('progress_counting_' + artefacttype).innerHTML);
var oldcompleted = parseInt($('progress_completed_' + artefacttype).innerHTML);
var counting = parseInt($('progress_counting_' + artefacttype).innerHTML, 10);
var oldcompleted = parseInt($('progress_completed_' + artefacttype).innerHTML, 10);
var completed = oldcompleted + change;
$('progress_completed_' + artefacttype).innerHTML = completed;
var progressitem = $('progress_item_' + artefacttype);
......@@ -737,8 +737,8 @@ function progressbarUpdate(artefacttype, remove) {
}
// now update the totals if we need to
if ((oldcompleted > 0 && oldcompleted <= counting && remove ) || (completed <= counting && !remove)) {
var totalcounting = parseInt($('progress_counting_total').innerHTML);
var totalcompleted = parseInt($('progress_completed_total').innerHTML) + change;
var totalcounting = parseInt($('progress_counting_total').innerHTML, 10);
var totalcompleted = parseInt($('progress_completed_total').innerHTML, 10) + change;
$('progress_completed_total').innerHTML = totalcompleted;
var percentage = roundToFixed((totalcompleted / totalcounting) * 100, 0);
$('progress_bar_percentage').innerHTML = percentage + '%';
......
......@@ -208,7 +208,7 @@ tinymce.PluginManager.add('maharaimage', function(editor) {
function attachmentSelectedCallback(imageList) {
return function(e) {
changingAttachment = true;
var value = parseInt(e.control.value());
var value = parseInt(e.control.value(), 10);
if (value > 0 && imageList[value]) {
var srcCtrl = win.find('#src');
var altCtrl = win.find('#alt');
......
......@@ -236,7 +236,7 @@
// to make sure the 'floating' panel when opened is not longer than
// the 'containing' div
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) {
var windowWidth = windowWide();
if (windowWidth) {
......@@ -518,7 +518,7 @@
$(this).closest('.cellchooser').find('.active').removeClass('active');
$(this).parent().addClass('active');
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')];
element.find('.column-content .blockinstance .blockinstance-header').each(function() {
options.push(get_string('blockorderafter', $(this).find('h2.title').html()));
......
......@@ -14,9 +14,9 @@ $j(function() {
if ($j('#thumbnails{$instanceid}')) {
// adjust height of image + description box to align things up
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) {
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
}).get());
......
......@@ -14,9 +14,9 @@ $j(function() {
if ($j('#thumbnails{$instanceid}')) {
// adjust height of image + description box to align things up
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) {
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
}).get());
......
......@@ -102,12 +102,12 @@
// Update the counters if they are present
if ($('{{$name}}_userlimit')) {
if (from.id == '{{$name}}_potential') {
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML) - list.length);
replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML) - list.length);
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML, 10) - list.length);
replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML, 10) - list.length);
}
else {
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML) + list.length);
replaceChildNodes('{{$name}}_usercount', parseInt($('{{$name}}_usercount').innerHTML) + list.length);
replaceChildNodes('{{$name}}_userlimit', parseInt($('{{$name}}_userlimit').innerHTML, 10) + 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