Merge pull request #4053 from Snuffleupagus/rename-Settings

Rename 'Settings' to 'ViewHistory'
This commit is contained in:
Brendan Dahl 2014-01-02 10:30:55 -08:00
commit 534939dc5c
3 changed files with 20 additions and 32 deletions

View File

@ -14,39 +14,26 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS, SETTINGS_MEMORY */ /* globals PDFJS, VIEW_HISTORY_MEMORY, isLocalStorageEnabled */
'use strict'; 'use strict';
/** /**
* Settings Manager - This is a utility for saving settings. * View History - This is a utility for saving various view parameters for
* recently opened files.
* *
* The way that settings are stored depends on how PDF.js is built, * The way that the view parameters are stored depends on how PDF.js is built,
* for 'node make <flag>' the following cases exist: * for 'node make <flag>' the following cases exist:
* - FIREFOX or MOZCENTRAL - uses about:config. * - FIREFOX or MOZCENTRAL - uses about:config.
* - B2G - uses asyncStorage. * - B2G - uses asyncStorage.
* - GENERIC or CHROME - uses localStorage, if it is available. * - GENERIC or CHROME - uses localStorage, if it is available.
*/ */
var Settings = (function SettingsClosure() { var ViewHistory = (function ViewHistoryClosure() {
//#if !(FIREFOX || MOZCENTRAL || B2G) function ViewHistory(fingerprint) {
var isLocalStorageEnabled = (function localStorageEnabledTest() {
// Feature test as per http://diveintohtml5.info/storage.html
// The additional localStorage call is to get around a FF quirk, see
// bug #495747 in bugzilla
try {
return ('localStorage' in window && window['localStorage'] !== null &&
localStorage);
} catch (e) {
return false;
}
})();
//#endif
function Settings(fingerprint) {
this.fingerprint = fingerprint; this.fingerprint = fingerprint;
this.initializedPromise = new PDFJS.Promise(); this.initializedPromise = new PDFJS.Promise();
var resolvePromise = (function settingsResolvePromise(db) { var resolvePromise = (function ViewHistoryResolvePromise(db) {
this.initialize(db || '{}'); this.initialize(db || '{}');
this.initializedPromise.resolve(); this.initializedPromise.resolve();
}).bind(this); }).bind(this);
@ -66,13 +53,13 @@ var Settings = (function SettingsClosure() {
//#endif //#endif
} }
Settings.prototype = { ViewHistory.prototype = {
initialize: function settingsInitialize(database) { initialize: function ViewHistory_initialize(database) {
database = JSON.parse(database); database = JSON.parse(database);
if (!('files' in database)) { if (!('files' in database)) {
database.files = []; database.files = [];
} }
if (database.files.length >= SETTINGS_MEMORY) { if (database.files.length >= VIEW_HISTORY_MEMORY) {
database.files.shift(); database.files.shift();
} }
var index; var index;
@ -90,7 +77,7 @@ var Settings = (function SettingsClosure() {
this.database = database; this.database = database;
}, },
set: function settingsSet(name, val) { set: function ViewHistory_set(name, val) {
if (!this.initializedPromise.isResolved) { if (!this.initializedPromise.isResolved) {
return; return;
} }
@ -113,7 +100,7 @@ var Settings = (function SettingsClosure() {
//#endif //#endif
}, },
get: function settingsGet(name, defaultValue) { get: function ViewHistory_get(name, defaultValue) {
if (!this.initializedPromise.isResolved) { if (!this.initializedPromise.isResolved) {
return defaultValue; return defaultValue;
} }
@ -121,5 +108,5 @@ var Settings = (function SettingsClosure() {
} }
}; };
return Settings; return ViewHistory;
})(); })();

View File

@ -65,7 +65,7 @@ limitations under the License.
<script type="text/javascript" src="default_preferences.js"></script> <script type="text/javascript" src="default_preferences.js"></script>
<script type="text/javascript" src="preferences.js"></script> <script type="text/javascript" src="preferences.js"></script>
<script type="text/javascript" src="download_manager.js"></script> <script type="text/javascript" src="download_manager.js"></script>
<script type="text/javascript" src="settings.js"></script> <script type="text/javascript" src="view_history.js"></script>
<script type="text/javascript" src="page_view.js"></script> <script type="text/javascript" src="page_view.js"></script>
<script type="text/javascript" src="thumbnail_view.js"></script> <script type="text/javascript" src="thumbnail_view.js"></script>
<script type="text/javascript" src="text_layer_builder.js"></script> <script type="text/javascript" src="text_layer_builder.js"></script>

View File

@ -17,8 +17,9 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle, /* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager, PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory, getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
Preferences, Settings, PageView, ThumbnailView, noContextMenuHandler, Preferences, ViewHistory, PageView, ThumbnailView,
SecondaryToolbar, PasswordPrompt, PresentationMode, HandTool */ noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
PresentationMode, HandTool */
'use strict'; 'use strict';
@ -33,7 +34,7 @@ var VERTICAL_PADDING = 5;
var MAX_AUTO_SCALE = 1.25; var MAX_AUTO_SCALE = 1.25;
var MIN_SCALE = 0.25; var MIN_SCALE = 0.25;
var MAX_SCALE = 4.0; var MAX_SCALE = 4.0;
var SETTINGS_MEMORY = 20; var VIEW_HISTORY_MEMORY = 20;
var SCALE_SELECT_CONTAINER_PADDING = 8; var SCALE_SELECT_CONTAINER_PADDING = 8;
var SCALE_SELECT_PADDING = 22; var SCALE_SELECT_PADDING = 22;
var THUMBNAIL_SCROLL_MARGIN = -19; var THUMBNAIL_SCROLL_MARGIN = -19;
@ -80,7 +81,7 @@ var mozL10n = document.mozL10n || document.webL10n;
var cache = new Cache(CACHE_SIZE); var cache = new Cache(CACHE_SIZE);
var currentPageNumber = 1; var currentPageNumber = 1;
//#include settings.js //#include view_history.js
//#include pdf_find_bar.js //#include pdf_find_bar.js
//#include pdf_find_controller.js //#include pdf_find_controller.js
//#include pdf_history.js //#include pdf_history.js
@ -832,7 +833,7 @@ var PDFView = {
var prefs = PDFView.prefs = new Preferences(); var prefs = PDFView.prefs = new Preferences();
PDFView.documentFingerprint = id; PDFView.documentFingerprint = id;
var store = PDFView.store = new Settings(id); var store = PDFView.store = new ViewHistory(id);
this.pageRotation = 0; this.pageRotation = 0;