|
|
|
@ -28,57 +28,49 @@ var Cache = function cacheCache(size) {
@@ -28,57 +28,49 @@ var Cache = function cacheCache(size) {
|
|
|
|
|
// Settings Manager - This is a utility for saving settings
|
|
|
|
|
// First we see if localStorage is available, which isn't pt. in FF due to bug #495747
|
|
|
|
|
// If not, we use FUEL in FF and fallback to Cookies for other browsers.
|
|
|
|
|
(function(parent) { |
|
|
|
|
var COOKIE_WORKS = (function() { |
|
|
|
|
document.cookie = 'they=work'; |
|
|
|
|
return document.cookie.length > 0; |
|
|
|
|
})(); |
|
|
|
|
var Settings = (function settingsClosure() { |
|
|
|
|
var isCookiesEnabled = (function() { |
|
|
|
|
document.cookie = 'they=work'; |
|
|
|
|
return document.cookie.length > 0; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var LOCALSTORAGE_WORKS = (function() { |
|
|
|
|
try { |
|
|
|
|
if(typeof localStorage != 'undefined') { |
|
|
|
|
return true; |
|
|
|
|
var isLocalStorageEnabled = (function localStorageEnabledTest() { |
|
|
|
|
try { |
|
|
|
|
localStorage; |
|
|
|
|
} catch(e) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} catch(e) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var extPrefix = 'extensions.uriloader@pdf.js'; |
|
|
|
|
|
|
|
|
|
var Settings = { |
|
|
|
|
set: function(name, val) { |
|
|
|
|
if(location.protocol == 'chrome:' && !LOCALSTORAGE_WORKS) { |
|
|
|
|
Application.prefs.setValue(extPrefix + '.' + name, val); |
|
|
|
|
} else if(LOCALSTORAGE_WORKS) { |
|
|
|
|
localStorage.setItem(name, val); |
|
|
|
|
} else if(COOKIE_WORKS) { |
|
|
|
|
var cookieString = name + '=' + escape(val); |
|
|
|
|
var expire = (new Date((new Date().getTime())+1000*60*60*24*365)).toGMTString(); |
|
|
|
|
cookieString += '; expires='+expire; |
|
|
|
|
document.cookie = cookieString; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
get: function(name, defaultValue) { |
|
|
|
|
if(location.protocol == 'chrome:' && !LOCALSTORAGE_WORKS) { |
|
|
|
|
return Application.prefs.getValue(extPrefix + '.' + name, defaultValue); |
|
|
|
|
} else if(LOCALSTORAGE_WORKS) { |
|
|
|
|
return localStorage.getItem(name) || defaultValue; |
|
|
|
|
} else if(COOKIE_WORKS) { |
|
|
|
|
var res = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' ); |
|
|
|
|
if (res) { |
|
|
|
|
return unescape(res[2]); |
|
|
|
|
} else { |
|
|
|
|
return fallback; |
|
|
|
|
return true; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var extPrefix = 'extensions.uriloader@pdf.js'; |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
set: function settingsSet(name, val) { |
|
|
|
|
if(location.protocol == 'chrome:' && !isLocalStorageEnabled) { |
|
|
|
|
Application.prefs.setValue(extPrefix + '.' + name, val); |
|
|
|
|
} else if(isLocalStorageEnabled) { |
|
|
|
|
localStorage.setItem(name, val); |
|
|
|
|
} else if(isCookiesEnabled) { |
|
|
|
|
var cookieString = name + '=' + escape(val); |
|
|
|
|
var expire = (new Date((new Date().getTime())+1000*60*60*24*365)).toGMTString(); |
|
|
|
|
cookieString += '; expires='+expire; |
|
|
|
|
document.cookie = cookieString; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
get: function settingsGet(name, defaultValue) { |
|
|
|
|
if(location.protocol == 'chrome:' && !isLocalStorageEnabled) { |
|
|
|
|
return Application.prefs.getValue(extPrefix + '.' + name, defaultValue); |
|
|
|
|
} else if(isLocalStorageEnabled) { |
|
|
|
|
return localStorage.getItem(name) || defaultValue; |
|
|
|
|
} else if(isCookiesEnabled) { |
|
|
|
|
var res = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' ); |
|
|
|
|
return res ? unescape(res[2]) : defaultValue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
parent.Settings = Settings; |
|
|
|
|
})(this); |
|
|
|
|
}; |
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
var cache = new Cache(kCacheSize); |
|
|
|
|
var currentPageNumber = 1; |
|
|
|
@ -347,15 +339,6 @@ var PDFView = {
@@ -347,15 +339,6 @@ var PDFView = {
|
|
|
|
|
pagesRefMap[pageRef.num + ' ' + pageRef.gen + ' R'] = i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var id = pdf.fingerprint; |
|
|
|
|
if (id) { |
|
|
|
|
var scroll = Settings.get(id + '.scroll', -1); |
|
|
|
|
if (scroll != -1) { |
|
|
|
|
setTimeout(function scrollWindow() { |
|
|
|
|
window.scrollTo(0, scroll); |
|
|
|
|
}, 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.pagesRefMap = pagesRefMap; |
|
|
|
|
this.destinations = pdf.catalog.destinations; |
|
|
|
|
this.setScale(scale || kDefaultScale, true); |
|
|
|
@ -371,8 +354,15 @@ var PDFView = {
@@ -371,8 +354,15 @@ var PDFView = {
|
|
|
|
|
this.setHash(this.initialBookmark); |
|
|
|
|
this.initialBookmark = null; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
this.page = 1; |
|
|
|
|
else { |
|
|
|
|
var scroll = Settings.get(pdf.fingerprint + '.scroll', -1); |
|
|
|
|
if (scroll != -1) { |
|
|
|
|
setTimeout(function scrollWindow() { |
|
|
|
|
window.scrollTo(0, scroll); |
|
|
|
|
}, 0); |
|
|
|
|
} else |
|
|
|
|
this.page = 1; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
setHash: function pdfViewSetHash(hash) { |
|
|
|
|