From 38a89c451b9d687d5690f3d9f9c1356fcc8f3614 Mon Sep 17 00:00:00 2001 From: thatcher Date: Tue, 6 Dec 2011 07:41:43 -0500 Subject: [PATCH] removed OpenSeadragon.format because it was only called once in the entire codebase, and didnt actually format a string. Instead just be direct and return string. corrected treatment of prefixUrl at that location since it was ignored otherwise. --- openseadragon.js | 82 ++------------------------------------------ src/navcontrol.js | 3 +- src/openseadragon.js | 77 ----------------------------------------- 3 files changed, 5 insertions(+), 157 deletions(-) diff --git a/openseadragon.js b/openseadragon.js index 495a7221..5983eaba 100644 --- a/openseadragon.js +++ b/openseadragon.js @@ -40,7 +40,7 @@ * **/ -OpenSeadragon = window.OpenSeadragon || function(){}; +OpenSeadragon = window.OpenSeadragon || function(){}; (function( $ ){ @@ -54,83 +54,6 @@ OpenSeadragon = window.OpenSeadragon || function(){}; }; }; - $.format = function(){ - - var args = arguments, - useLocale = false, - result = '', - format = args[0], - open, - close, - brace, - colonIndex, - argNumber, - argFormat, - arg, - i; - - for ( i = 0; ; ) { - open = format.indexOf('{', i); - close = format.indexOf('}', i); - if ((open < 0) && (close < 0)) { - result += format.slice(i); - break; - } - if ((close > 0) && ((close < open) || (open < 0))) { - if (format.charAt(close + 1) !== '}') { - throw Error('SeadragonError: Formatted String Brace Mismatch. \n' + format ); - } - result += format.slice(i, close + 1); - i = close + 2; - continue; - } - - result += format.slice(i, open); - i = open + 1; - - if (format.charAt(i) === '{') { - result += '{'; - i++; - continue; - } - - if (close < 0) { - throw Error('SeadragonError: Formatted String Brace Mismatch. \n' + format ); - } - - - brace = format.substring(i, close); - colonIndex = brace.indexOf(':'); - argNumber = parseInt((colonIndex < 0) ? brace : brace.substring(0, colonIndex), 10) + 1; - - if( isNaN( argNumber ) ){ - throw Error('SeadragonError: Invalid Format String\n' + format ); - } - argFormat = (colonIndex < 0) ? '' : brace.substring(colonIndex + 1); - - arg = args[argNumber]; - if (typeof (arg) === "undefined" || arg === null) { - arg = ''; - } - - if (arg.toFormattedString) { - result += arg.toFormattedString(argFormat); - } - else if (useLocale && arg.localeFormat) { - result += arg.localeFormat(argFormat); - } - else if ( arg.format ) { - result += arg.format(argFormat); - } - else - result += arg.toString(); - - i = close + 1; - } - - return result; - }; - }( OpenSeadragon )); (function($){ @@ -1261,7 +1184,8 @@ $.NavControl.prototype = { this._events = value; }, _resolveUrl: function(url) { - return $.format("{1}", this._viewer.get_prefixUrl(), url); + var prefix = this._viewer.get_prefixUrl(); + return prefix ? prefix + url : url; }, _beginZoomingIn: function() { this._lastZoomTime = new Date().getTime(); diff --git a/src/navcontrol.js b/src/navcontrol.js index 36d6b160..e5f9b63c 100644 --- a/src/navcontrol.js +++ b/src/navcontrol.js @@ -90,7 +90,8 @@ $.NavControl.prototype = { this._events = value; }, _resolveUrl: function(url) { - return $.format("{1}", this._viewer.get_prefixUrl(), url); + var prefix = this._viewer.get_prefixUrl(); + return prefix ? prefix + url : url; }, _beginZoomingIn: function() { this._lastZoomTime = new Date().getTime(); diff --git a/src/openseadragon.js b/src/openseadragon.js index 46403d48..b8649910 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -54,81 +54,4 @@ OpenSeadragon = window.OpenSeadragon || function(){}; }; }; - $.format = function(){ - - var args = arguments, - useLocale = false, - result = '', - format = args[0], - open, - close, - brace, - colonIndex, - argNumber, - argFormat, - arg, - i; - - for ( i = 0; ; ) { - open = format.indexOf('{', i); - close = format.indexOf('}', i); - if ((open < 0) && (close < 0)) { - result += format.slice(i); - break; - } - if ((close > 0) && ((close < open) || (open < 0))) { - if (format.charAt(close + 1) !== '}') { - throw Error('SeadragonError: Formatted String Brace Mismatch. \n' + format ); - } - result += format.slice(i, close + 1); - i = close + 2; - continue; - } - - result += format.slice(i, open); - i = open + 1; - - if (format.charAt(i) === '{') { - result += '{'; - i++; - continue; - } - - if (close < 0) { - throw Error('SeadragonError: Formatted String Brace Mismatch. \n' + format ); - } - - - brace = format.substring(i, close); - colonIndex = brace.indexOf(':'); - argNumber = parseInt((colonIndex < 0) ? brace : brace.substring(0, colonIndex), 10) + 1; - - if( isNaN( argNumber ) ){ - throw Error('SeadragonError: Invalid Format String\n' + format ); - } - argFormat = (colonIndex < 0) ? '' : brace.substring(colonIndex + 1); - - arg = args[argNumber]; - if (typeof (arg) === "undefined" || arg === null) { - arg = ''; - } - - if (arg.toFormattedString) { - result += arg.toFormattedString(argFormat); - } - else if (useLocale && arg.localeFormat) { - result += arg.localeFormat(argFormat); - } - else if ( arg.format ) { - result += arg.format(argFormat); - } - else - result += arg.toString(); - - i = close + 1; - } - - return result; - }; - }( OpenSeadragon ));