mirror of
https://github.com/flynx/PortableMag.git
synced 2025-11-01 04:20:20 +00:00
tweeking JSON builder/loader...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b2cda96410
commit
aef1000227
19
magazine.js
19
magazine.js
@ -853,12 +853,14 @@ function resetStorageState(){
|
|||||||
// // root <page>...
|
// // root <page>...
|
||||||
// {
|
// {
|
||||||
// type: 'page' | 'cover',
|
// type: 'page' | 'cover',
|
||||||
|
// classes: [...]
|
||||||
// content: <page-content>
|
// content: <page-content>
|
||||||
// },
|
// },
|
||||||
//
|
//
|
||||||
// // article...
|
// // article...
|
||||||
// {
|
// {
|
||||||
// type: 'article',
|
// type: 'article',
|
||||||
|
// classes: [...]
|
||||||
// pages: [
|
// pages: [
|
||||||
// <page>,
|
// <page>,
|
||||||
// ...
|
// ...
|
||||||
@ -868,18 +870,20 @@ function resetStorageState(){
|
|||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// XXX store cover state...
|
// XXX do we need to store page classes? ...can the user edit them?
|
||||||
function buildJSONState(export_bookmarks, export_position){
|
function buildJSONState(export_bookmarks, export_position){
|
||||||
function _getContent(_, elem){
|
function _getContent(_, elem){
|
||||||
elem = $(elem)
|
elem = $(elem)
|
||||||
if(elem.hasClass('page')){
|
if(elem.hasClass('page')){
|
||||||
return {
|
return {
|
||||||
type: elem.hasClass('cover') ? 'cover' : 'page',
|
type: elem.hasClass('cover') ? 'cover' : 'page',
|
||||||
|
'class': elem.attr('class'),
|
||||||
content: elem.children('.content')[0].outerHTML
|
content: elem.children('.content')[0].outerHTML
|
||||||
}
|
}
|
||||||
} else if(elem.hasClass('article')){
|
} else if(elem.hasClass('article')){
|
||||||
return {
|
return {
|
||||||
type: 'article',
|
type: 'article',
|
||||||
|
'class': elem.attr('class'),
|
||||||
pages: elem.children('.page').map(_getContent).toArray()
|
pages: elem.children('.page').map(_getContent).toArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -898,14 +902,19 @@ function buildJSONState(export_bookmarks, export_position){
|
|||||||
function loadJSONState(data){
|
function loadJSONState(data){
|
||||||
function _build(block, elem){
|
function _build(block, elem){
|
||||||
if(elem.type == 'page'){
|
if(elem.type == 'page'){
|
||||||
block.append(_createPage(elem.content))
|
_createPage(elem.content)
|
||||||
|
.addClass(elem['class'])
|
||||||
|
.appendTo(block)
|
||||||
|
|
||||||
} else if(elem.type == 'cover'){
|
} else if(elem.type == 'cover'){
|
||||||
block.append(_createCoverPage(elem.content))
|
_createCoverPage(elem.content)
|
||||||
|
.addClass(elem['class'])
|
||||||
|
.appendTo(block)
|
||||||
|
|
||||||
} else if(elem.type == 'article') {
|
} else if(elem.type == 'article') {
|
||||||
// buiold an article...
|
// buiold an article...
|
||||||
var article = _createEmptyArticle()
|
var article = _createEmptyArticle()
|
||||||
|
.addClass(elem['class'])
|
||||||
.appendTo(block)
|
.appendTo(block)
|
||||||
// populate article with pages...
|
// populate article with pages...
|
||||||
$(elem.pages).each(function(_, e){
|
$(elem.pages).each(function(_, e){
|
||||||
@ -917,7 +926,11 @@ function loadJSONState(data){
|
|||||||
$(data.pages).each(function(_, e){
|
$(data.pages).each(function(_, e){
|
||||||
_build(mag, e)
|
_build(mag, e)
|
||||||
})
|
})
|
||||||
|
// remove service classes...
|
||||||
|
// XXX should we do this here, on build or in both places...
|
||||||
|
mag.children('.current.page').removeClass('current')
|
||||||
loadMagazine(mag)
|
loadMagazine(mag)
|
||||||
|
setupNavigator()
|
||||||
loadBookmarks(data.bookmarks)
|
loadBookmarks(data.bookmarks)
|
||||||
setCurrentPage(data.position)
|
setCurrentPage(data.position)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user