From 536519a9a15483e6cc9ef0ab5535528b729743fd Mon Sep 17 00:00:00 2001 From: gigaherz Date: Fri, 23 Mar 2012 16:26:06 +0100 Subject: [PATCH 1/5] Assign the filename to the page title instead of the full URL --- web/viewer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index 67ef67e97..73a65ca05 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -258,7 +258,9 @@ var PDFView = { }, open: function pdfViewOpen(url, scale) { - document.title = this.url = url; + this.url = url; + + document.title = (url.substring(url.lastIndexOf('/')+1)) || url; var self = this; PDFJS.getPdf( From 080a80b7161704d12c8584b00a032a7d7ac60cd4 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Fri, 23 Mar 2012 21:13:04 +0100 Subject: [PATCH 2/5] Better filename cleanup --- web/viewer.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index 73a65ca05..6d3b13cdf 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -15,6 +15,18 @@ var kMaxScale = 4.0; var kImageDirectory = './images/'; var kSettingsMemory = 20; +var Util = { + getFileName: function Util_getFileName(url) { + var anchor = url.indexOf("#"); + var query = url.indexOf("?"); + var s = url.lastIndexOf("/") + 1; + var e = url.length; + if (anchor > 0) e=Math.min(anchor,e); + if (query > 0) e=Math.min(query,e); + return url.substring(url.lastIndexOf("/") + 1, e); + } +}; + var Cache = function cacheCache(size) { var data = []; this.push = function cachePush(view) { @@ -260,7 +272,7 @@ var PDFView = { open: function pdfViewOpen(url, scale) { this.url = url; - document.title = (url.substring(url.lastIndexOf('/')+1)) || url; + document.title = Util.getFileName(url) || url; var self = this; PDFJS.getPdf( From ab46530ff81e09565c129eef1f09970b3584f7d8 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Sat, 24 Mar 2012 15:23:27 +0100 Subject: [PATCH 3/5] Lint fixes. --- web/viewer.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 6d3b13cdf..83fc06544 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -17,13 +17,12 @@ var kSettingsMemory = 20; var Util = { getFileName: function Util_getFileName(url) { - var anchor = url.indexOf("#"); - var query = url.indexOf("?"); - var s = url.lastIndexOf("/") + 1; - var e = url.length; - if (anchor > 0) e=Math.min(anchor,e); - if (query > 0) e=Math.min(query,e); - return url.substring(url.lastIndexOf("/") + 1, e); + var anchor = url.indexOf('#'); + var query = url.indexOf('?'); + var end = url.length; + if (anchor > 0) end = Math.min(anchor, end); + if (query > 0) end = Math.min(query, end); + return url.substring(url.lastIndexOf('/') + 1, end); } }; From 3280a2bececf4cc121aaf25d21cf26cc3ecf7a7c Mon Sep 17 00:00:00 2001 From: gigaherz Date: Tue, 27 Mar 2012 09:27:54 +0200 Subject: [PATCH 4/5] Unwrap getFileName from the object, avoid issues with / in query/anchor strings, simplify the code to calculate 'end'. --- web/viewer.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 83fc06544..389eee6ab 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -15,16 +15,14 @@ var kMaxScale = 4.0; var kImageDirectory = './images/'; var kSettingsMemory = 20; -var Util = { - getFileName: function Util_getFileName(url) { - var anchor = url.indexOf('#'); - var query = url.indexOf('?'); - var end = url.length; - if (anchor > 0) end = Math.min(anchor, end); - if (query > 0) end = Math.min(query, end); - return url.substring(url.lastIndexOf('/') + 1, end); - } -}; +function getFileName(url) { + var anchor = url.indexOf('#'); + var query = url.indexOf('?'); + var end = Math.min( + anchor > 0 ? anchor : url.length, + query > 0 ? query : url.length); + return url.substring(url.lastIndexOf('/', end) + 1, end); +} var Cache = function cacheCache(size) { var data = []; @@ -271,7 +269,7 @@ var PDFView = { open: function pdfViewOpen(url, scale) { this.url = url; - document.title = Util.getFileName(url) || url; + document.title = getFileName(url) || url; var self = this; PDFJS.getPdf( From 2283f0bac1adccf5fccd2a62659e6d968303481f Mon Sep 17 00:00:00 2001 From: gigaherz Date: Sat, 31 Mar 2012 01:23:53 +0200 Subject: [PATCH 5/5] Decode the filename when assigning to title. --- web/viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index d133b09da..8977b53c0 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -311,7 +311,7 @@ var PDFView = { open: function pdfViewOpen(url, scale) { this.url = url; - document.title = getFileName(url) || url; + document.title = decodeURIComponent(getFileName(url)) || url; if (!PDFView.loadingBar) { PDFView.loadingBar = new ProgressBar('#loadingBar', {});