From 2dbb61c103c7fc42503cce99f9dd382bb8af5b27 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 25 May 2012 12:19:04 +0200 Subject: [PATCH] rename vars; in Ox.formatDimensions, use multiplication sign; more efficient version of Ox.parseDuration --- source/Ox/js/Format.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 22703e72..e9326848 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -464,11 +464,11 @@ Ox.formatDegrees Formats degrees as D°MM'SS" > Ox.formatDegrees(-111.11, 'lng') "111\u00B006'36\"W" @*/ -Ox.formatDegrees = function(deg, mode) { +Ox.formatDegrees = function(degrees, mode) { var days = 0, - sec = Math.round(Math.abs(deg) * 3600), - sign = deg < 0 ? '-' : '', - split = Ox.formatDuration(sec).split(':'); + seconds = Math.round(Math.abs(degrees) * 3600), + sign = degrees < 0 ? '-' : '', + split = Ox.formatDuration(seconds).split(':'); if (split.length == 4) { days = parseInt(split.shift(), 10); } @@ -476,8 +476,8 @@ Ox.formatDegrees = function(deg, mode) { return (!mode ? sign : '') + split[0] + '\u00B0' + split[1] + "'" + split[2] + '"' + ( - mode == 'lat' ? (deg < 0 ? 'S' : 'N') - : mode == 'lng' ? (deg < 0 ? 'W' : 'E') + mode == 'lat' ? (degrees < 0 ? 'S' : 'N') + : mode == 'lng' ? (degrees < 0 ? 'W' : 'E') : '' ); }; @@ -485,10 +485,10 @@ Ox.formatDegrees = function(deg, mode) { /*@ Ox.formatDimensions Formats valus as dimension > Ox.formatDimensions([1920, 1080], 'px') - "1920 x 1080 px" + "1920 × 1080 px" @*/ -Ox.formatDimensions = Ox.formatResolution = function(arr, str) { - return arr.join(' x ') + (str ? ' ' + str : ''); +Ox.formatDimensions = Ox.formatResolution = function(array, string) { + return array.join(' × ') + (string ? ' ' + string : ''); }; /*@ @@ -629,7 +629,6 @@ Ox.formatPercent = function(num, total, dec) { return Ox.formatNumber(num / total * 100, dec) + '%' }; - /*@ Ox.formatString Basic string formatting > Ox.formatString('{0}{1}', ['foo', 'bar']) @@ -690,12 +689,8 @@ Ox.parseDuration Takes a formatted duration, returns seconds > Ox.parseDuration('1::') 3600 @*/ -Ox.parseDuration = function(str) { - var split = str.split(':').reverse(); - while (split.length > 3) { - split.pop(); - } - return split.reduce(function(prev, curr, i) { - return prev + (parseFloat(curr) || 0) * Math.pow(60, i); +Ox.parseDuration = function(string) { + return string.split(':').reverse().slice(0, 3).reduce(function(p, c, i) { + return p + (parseFloat(c) || 0) * Math.pow(60, i); }, 0); -} +};