mirror of
https://github.com/flynx/PortableMag.git
synced 2025-10-29 19:20:09 +00:00
added saving magazine data to local storage + abstracted out the magazine title...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d8744a5e63
commit
f630a3b16f
11
TODO.otl
11
TODO.otl
@ -14,8 +14,6 @@
|
|||||||
| text areas, inputs, ...
|
| text areas, inputs, ...
|
||||||
[_] EXPERIMENT: Try using scroll instead of left of .magazine....
|
[_] EXPERIMENT: Try using scroll instead of left of .magazine....
|
||||||
| this might improve speed...
|
| this might improve speed...
|
||||||
[_] BUG: as on android, on loading from json view does not reach cur page...
|
|
||||||
| likely due to animation/transition stopping for some reason....
|
|
||||||
[_] 0% add two main page themes (global/local applicable):
|
[_] 0% add two main page themes (global/local applicable):
|
||||||
[_] light
|
[_] light
|
||||||
[_] dark
|
[_] dark
|
||||||
@ -66,6 +64,15 @@
|
|||||||
| e.g. setting "shown"/"hidden" classes in HTML and adding
|
| e.g. setting "shown"/"hidden" classes in HTML and adding
|
||||||
| something like a page reset that will restore the default state,
|
| something like a page reset that will restore the default state,
|
||||||
| rather than the current "hideLayers"
|
| rather than the current "hideLayers"
|
||||||
|
[_] BUG: as on android, on loading from json view does not reach cur page...
|
||||||
|
| likely due to animation/transition stopping for some reason....
|
||||||
|
[_] BUG: togglePageView results in jumpy animation if USE_REAL_PAGE_SIZES is set
|
||||||
|
| this does not happen if USE_REAL_PAGE_SIZES is set and FIT_PAGE_TO_VIEW
|
||||||
|
| is unset...
|
||||||
|
|
|
||||||
|
| the most likely cause is that there is some time passing between some
|
||||||
|
| edits to element parameters. these writes must be done in an as compact
|
||||||
|
| a burst as possible,
|
||||||
[_] BUG: when #URL updates are off layer toggling breaks...
|
[_] BUG: when #URL updates are off layer toggling breaks...
|
||||||
| will show but not hide layers...
|
| will show but not hide layers...
|
||||||
[_] BUG: href to existing anchors will mess up layout...
|
[_] BUG: href to existing anchors will mess up layout...
|
||||||
|
|||||||
99
magazine.js
99
magazine.js
@ -35,6 +35,9 @@ var DRAG_FULL_PAGE = true
|
|||||||
// we get to the right from the no-resize element...
|
// we get to the right from the no-resize element...
|
||||||
// ...think the reason is .no-resize page centering...
|
// ...think the reason is .no-resize page centering...
|
||||||
// XXX still buggy on togglePageView to TN after funny sized pages...
|
// XXX still buggy on togglePageView to TN after funny sized pages...
|
||||||
|
// ...the most probable reason is that we waste too much time between
|
||||||
|
// setting different values to elements...
|
||||||
|
// need to keep wrights as tight as possible...
|
||||||
//var USE_REAL_PAGE_SIZES = true
|
//var USE_REAL_PAGE_SIZES = true
|
||||||
var USE_REAL_PAGE_SIZES = false
|
var USE_REAL_PAGE_SIZES = false
|
||||||
|
|
||||||
@ -107,6 +110,13 @@ function getPageAlign(page){
|
|||||||
: FULL_PAGE_ALIGN)
|
: FULL_PAGE_ALIGN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX need a way to get the title without a magazine loaded...
|
||||||
|
// ...something like a current magazine option...
|
||||||
|
function getMagazineTitle(){
|
||||||
|
return ($('.magazine').attr('title')
|
||||||
|
|| $('.magazine').attr('name'))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getPageScale(){
|
function getPageScale(){
|
||||||
return getElementScale($('.scaler'))
|
return getElementScale($('.scaler'))
|
||||||
@ -811,9 +821,10 @@ function saveURLState(){
|
|||||||
|
|
||||||
|
|
||||||
// local storage state managers...
|
// local storage state managers...
|
||||||
function loadStorageState(){
|
function loadStorageState(title){
|
||||||
var title = ($('.magazine').attr('title')
|
if(title == null){
|
||||||
|| $('.magazine').attr('name'))
|
title = getMagazineTitle()
|
||||||
|
}
|
||||||
var data = $.jStorage.get(title, {})
|
var data = $.jStorage.get(title, {})
|
||||||
// set the defaults...
|
// set the defaults...
|
||||||
if(data.current_page == null){
|
if(data.current_page == null){
|
||||||
@ -824,31 +835,82 @@ function loadStorageState(){
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
function saveStorageState(){
|
function saveStorageState(title){
|
||||||
var title = ($('.magazine').attr('title')
|
if(title == null){
|
||||||
|| $('.magazine').attr('name'))
|
title = getMagazineTitle()
|
||||||
$.jStorage.set(title, {
|
}
|
||||||
|
var data = $.jStorage.get(title, {})
|
||||||
|
$.extend(data, {
|
||||||
current_page: getPageNumber(),
|
current_page: getPageNumber(),
|
||||||
bookmarks: buildBookmarkList()
|
bookmarks: buildBookmarkList()
|
||||||
})
|
})
|
||||||
|
$.jStorage.set(title, data)
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
function resetStorageState(){
|
function resetStorageState(title){
|
||||||
var title = ($('.magazine').attr('title')
|
if(title == null){
|
||||||
|| $('.magazine').attr('name'))
|
title = getMagazineTitle()
|
||||||
|
}
|
||||||
$.jStorage.deleteKey(title)
|
$.jStorage.deleteKey(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// JSON state on local storage...
|
||||||
|
// NOTE: these will only load the data, bookmarks and position are
|
||||||
|
// ignored...
|
||||||
|
function saveJSONStorage(title){
|
||||||
|
if(title == null){
|
||||||
|
title = getMagazineTitle()
|
||||||
|
}
|
||||||
|
var data = $.jStorage.get(title, {})
|
||||||
|
$.extend(data, {
|
||||||
|
// XXX do we need to stringify this??
|
||||||
|
'magazine-data': buildJSON()
|
||||||
|
})
|
||||||
|
$.jStorage.set(title, data)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
// load JSON magazine data from storage...
|
||||||
|
// XXX we're losing the bookmarks at some point...
|
||||||
|
function loadJSONStorage(title){
|
||||||
|
if(title == null){
|
||||||
|
title = getMagazineTitle()
|
||||||
|
}
|
||||||
|
var data = $.jStorage.get(title, {})
|
||||||
|
// NOTE: we are caching the data here because the actual structure
|
||||||
|
// is persistent and may get overwritten by loadJSON(...)
|
||||||
|
var bookmarks = data.bookmarks
|
||||||
|
var current_page = data.current_page
|
||||||
|
var json = data['magazine-data']
|
||||||
|
if(json != null){
|
||||||
|
loadJSON(json)
|
||||||
|
loadMagazineUserData(current_page, bookmarks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove JSON magazine data from storage...
|
||||||
|
// NOTE: this will resave curent values but will remove the JSON data...
|
||||||
|
function clearJSONStorage(title){
|
||||||
|
if(title == null){
|
||||||
|
title = getMagazineTitle()
|
||||||
|
}
|
||||||
|
var data = $.jStorage.get(title, {})
|
||||||
|
var json = data['magazine-data']
|
||||||
|
if(json != null){
|
||||||
|
delete data['magazine-data']
|
||||||
|
$.jStorage.set(title, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// generic state managers...
|
// generic state managers...
|
||||||
function loadState(){
|
function loadState(){
|
||||||
var n = loadURLState()
|
var n = loadURLState()
|
||||||
var state = loadStorageState()
|
var state = loadStorageState()
|
||||||
if(n != null){
|
if(n == null){
|
||||||
setCurrentPage(n)
|
n = state.current_page
|
||||||
} else {
|
|
||||||
setCurrentPage(state.current_page)
|
|
||||||
}
|
}
|
||||||
loadBookmarks(state.bookmarks)
|
loadMagazineUserData(n, state.bookmarks)
|
||||||
}
|
}
|
||||||
function saveState(){
|
function saveState(){
|
||||||
saveURLState()
|
saveURLState()
|
||||||
@ -961,11 +1023,11 @@ function writeMetadata(elem, res, metadata){
|
|||||||
metadata = JSONMetadata
|
metadata = JSONMetadata
|
||||||
}
|
}
|
||||||
for(var a in metadata){
|
for(var a in metadata){
|
||||||
if(elem[a]){
|
if(res[a] != null){
|
||||||
if(metadata[a] == 'as-is'){
|
if(metadata[a] == 'as-is'){
|
||||||
res.attr(a, elem[a])
|
elem.attr(a, res[a])
|
||||||
} else {
|
} else {
|
||||||
res.attr(a, metadata[e].writer(elem[a]))
|
elem.attr(a, metadata[e].writer(res[a]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1070,6 +1132,7 @@ function loadJSON(data, load_user_data){
|
|||||||
|
|
||||||
// create an empty magazine...
|
// create an empty magazine...
|
||||||
var mag = createEmptyMagazine(data.title)
|
var mag = createEmptyMagazine(data.title)
|
||||||
|
// XXX for some reason this does not restore name/title...
|
||||||
writeMetadata(mag, data)
|
writeMetadata(mag, data)
|
||||||
// build the actual strcture...
|
// build the actual strcture...
|
||||||
$(data.pages).each(function(_, e){
|
$(data.pages).each(function(_, e){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user