Address yury's comments, and remove unnecessary hash settings
This commit is contained in:
parent
0de0e92bc4
commit
ac8f0e2c87
@ -28,17 +28,15 @@ var Cache = function cacheCache(size) {
|
|||||||
// Settings Manager - This is a utility for saving settings
|
// 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
|
// 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.
|
// If not, we use FUEL in FF and fallback to Cookies for other browsers.
|
||||||
(function(parent) {
|
var Settings = (function settingsClosure() {
|
||||||
var COOKIE_WORKS = (function() {
|
var isCookiesEnabled = (function() {
|
||||||
document.cookie = 'they=work';
|
document.cookie = 'they=work';
|
||||||
return document.cookie.length > 0;
|
return document.cookie.length > 0;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var LOCALSTORAGE_WORKS = (function() {
|
var isLocalStorageEnabled = (function localStorageEnabledTest() {
|
||||||
try {
|
try {
|
||||||
if(typeof localStorage != 'undefined') {
|
localStorage;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -47,13 +45,13 @@ var LOCALSTORAGE_WORKS = (function() {
|
|||||||
|
|
||||||
var extPrefix = 'extensions.uriloader@pdf.js';
|
var extPrefix = 'extensions.uriloader@pdf.js';
|
||||||
|
|
||||||
var Settings = {
|
return {
|
||||||
set: function(name, val) {
|
set: function settingsSet(name, val) {
|
||||||
if(location.protocol == 'chrome:' && !LOCALSTORAGE_WORKS) {
|
if(location.protocol == 'chrome:' && !isLocalStorageEnabled) {
|
||||||
Application.prefs.setValue(extPrefix + '.' + name, val);
|
Application.prefs.setValue(extPrefix + '.' + name, val);
|
||||||
} else if(LOCALSTORAGE_WORKS) {
|
} else if(isLocalStorageEnabled) {
|
||||||
localStorage.setItem(name, val);
|
localStorage.setItem(name, val);
|
||||||
} else if(COOKIE_WORKS) {
|
} else if(isCookiesEnabled) {
|
||||||
var cookieString = name + '=' + escape(val);
|
var cookieString = name + '=' + escape(val);
|
||||||
var expire = (new Date((new Date().getTime())+1000*60*60*24*365)).toGMTString();
|
var expire = (new Date((new Date().getTime())+1000*60*60*24*365)).toGMTString();
|
||||||
cookieString += '; expires='+expire;
|
cookieString += '; expires='+expire;
|
||||||
@ -61,24 +59,18 @@ var Settings = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get: function(name, defaultValue) {
|
get: function settingsGet(name, defaultValue) {
|
||||||
if(location.protocol == 'chrome:' && !LOCALSTORAGE_WORKS) {
|
if(location.protocol == 'chrome:' && !isLocalStorageEnabled) {
|
||||||
return Application.prefs.getValue(extPrefix + '.' + name, defaultValue);
|
return Application.prefs.getValue(extPrefix + '.' + name, defaultValue);
|
||||||
} else if(LOCALSTORAGE_WORKS) {
|
} else if(isLocalStorageEnabled) {
|
||||||
return localStorage.getItem(name) || defaultValue;
|
return localStorage.getItem(name) || defaultValue;
|
||||||
} else if(COOKIE_WORKS) {
|
} else if(isCookiesEnabled) {
|
||||||
var res = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );
|
var res = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );
|
||||||
if (res) {
|
return res ? unescape(res[2]) : defaultValue;
|
||||||
return unescape(res[2]);
|
|
||||||
} else {
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
})();
|
||||||
parent.Settings = Settings;
|
|
||||||
})(this);
|
|
||||||
|
|
||||||
var cache = new Cache(kCacheSize);
|
var cache = new Cache(kCacheSize);
|
||||||
var currentPageNumber = 1;
|
var currentPageNumber = 1;
|
||||||
@ -347,15 +339,6 @@ var PDFView = {
|
|||||||
pagesRefMap[pageRef.num + ' ' + pageRef.gen + ' R'] = i;
|
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.pagesRefMap = pagesRefMap;
|
||||||
this.destinations = pdf.catalog.destinations;
|
this.destinations = pdf.catalog.destinations;
|
||||||
this.setScale(scale || kDefaultScale, true);
|
this.setScale(scale || kDefaultScale, true);
|
||||||
@ -371,8 +354,15 @@ var PDFView = {
|
|||||||
this.setHash(this.initialBookmark);
|
this.setHash(this.initialBookmark);
|
||||||
this.initialBookmark = null;
|
this.initialBookmark = null;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
var scroll = Settings.get(pdf.fingerprint + '.scroll', -1);
|
||||||
|
if (scroll != -1) {
|
||||||
|
setTimeout(function scrollWindow() {
|
||||||
|
window.scrollTo(0, scroll);
|
||||||
|
}, 0);
|
||||||
|
} else
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setHash: function pdfViewSetHash(hash) {
|
setHash: function pdfViewSetHash(hash) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user