some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-01-31 22:48:17 +04:00
parent 8bbba6506b
commit 4ed4617ffb

View File

@ -834,6 +834,30 @@ function resetStorageState(){
} }
// generic state managers...
function loadState(){
var n = loadURLState()
var state = loadStorageState()
if(n != null){
setCurrentPage(n)
} else {
setCurrentPage(state.current_page)
}
loadBookmarks(state.bookmarks)
}
function saveState(){
saveURLState()
saveStorageState()
}
function resetState(){
resetStorageState()
loadState()
}
/********************************************** JSON serialization ***/
// JSON format state managers... // JSON format state managers...
// format: // format:
// { // {
@ -848,14 +872,16 @@ function resetStorageState(){
// // root <page>... // // root <page>...
// { // {
// type: 'page' | 'cover', // type: 'page' | 'cover',
// classes: [...] // // classes set on the page element...
// class: [...]
// content: <page-content> // content: <page-content>
// }, // },
// //
// // article... // // article...
// { // {
// type: 'article', // type: 'article',
// classes: [...] // // classes set on the article element...
// class: [...]
// pages: [ // pages: [
// <page>, // <page>,
// ... // ...
@ -865,8 +891,10 @@ function resetStorageState(){
// ] // ]
// } // }
// //
// XXX do we need to store page classes? ...can the user edit them? // NOTE: content classes are stored in the content...
function buildJSONState(export_bookmarks, export_position){ // NOTE: at this point all page classes will be stored, but .current
// will be ignored on restore...
function buildJSON(export_bookmarks, export_position){
function _getContent(_, elem){ function _getContent(_, elem){
elem = $(elem) elem = $(elem)
if(elem.hasClass('page')){ if(elem.hasClass('page')){
@ -894,7 +922,8 @@ function buildJSONState(export_bookmarks, export_position){
} }
return res return res
} }
function loadJSONState(data, ignore_chrome){
function loadJSON(data, ignore_chrome){
function _build(block, elem){ function _build(block, elem){
if(elem.type == 'page'){ if(elem.type == 'page'){
createPage(elem.content) createPage(elem.content)
@ -932,28 +961,6 @@ function loadJSONState(data, ignore_chrome){
} }
// generic state managers...
function loadState(){
var n = loadURLState()
var state = loadStorageState()
if(n != null){
setCurrentPage(n)
} else {
setCurrentPage(state.current_page)
}
loadBookmarks(state.bookmarks)
}
function saveState(){
saveURLState()
saveStorageState()
}
function resetState(){
resetStorageState()
loadState()
}
/***************************************************** constructor ***/ /***************************************************** constructor ***/
// These function will construct detached magazine building blocks... // These function will construct detached magazine building blocks...