From 4ed4617ffbaa9b1738fc5b4b3904c8756f9ee593 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 31 Jan 2013 22:48:17 +0400 Subject: [PATCH] some refactoring... Signed-off-by: Alex A. Naanou --- magazine.js | 61 +++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/magazine.js b/magazine.js index 41bea11..799f3ac 100755 --- a/magazine.js +++ b/magazine.js @@ -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... // format: // { @@ -848,14 +872,16 @@ function resetStorageState(){ // // root ... // { // type: 'page' | 'cover', -// classes: [...] +// // classes set on the page element... +// class: [...] // content: // }, // // // article... // { // type: 'article', -// classes: [...] +// // classes set on the article element... +// class: [...] // pages: [ // , // ... @@ -865,8 +891,10 @@ function resetStorageState(){ // ] // } // -// XXX do we need to store page classes? ...can the user edit them? -function buildJSONState(export_bookmarks, export_position){ +// NOTE: content classes are stored in the content... +// 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){ elem = $(elem) if(elem.hasClass('page')){ @@ -894,7 +922,8 @@ function buildJSONState(export_bookmarks, export_position){ } return res } -function loadJSONState(data, ignore_chrome){ + +function loadJSON(data, ignore_chrome){ function _build(block, elem){ if(elem.type == 'page'){ 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 ***/ // These function will construct detached magazine building blocks...