mirror of
https://github.com/flynx/PortableMag.git
synced 2025-11-01 04:20:20 +00:00
added JSON builder/loader...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f302bb56c1
commit
b2cda96410
1
TODO.otl
1
TODO.otl
@ -6,6 +6,7 @@
|
|||||||
[_] BUG: no drag threshold on excludedElements (TouchSwipe)
|
[_] BUG: no drag threshold on excludedElements (TouchSwipe)
|
||||||
| stalled...
|
| stalled...
|
||||||
[_] 11% general todo
|
[_] 11% general todo
|
||||||
|
[_] decide wether to make the editor toolbar oriented or floating bars around context...
|
||||||
[_] make the editor switchable...
|
[_] make the editor switchable...
|
||||||
| if it is imported it should be able to switch on and off on demand...
|
| if it is imported it should be able to switch on and off on demand...
|
||||||
[_] add min-width to magazine and article...
|
[_] add min-width to magazine and article...
|
||||||
|
|||||||
91
magazine.js
91
magazine.js
@ -840,14 +840,86 @@ function resetStorageState(){
|
|||||||
|
|
||||||
|
|
||||||
// JSON format state managers...
|
// JSON format state managers...
|
||||||
|
// format:
|
||||||
|
// {
|
||||||
|
// title: <magazine-title>,
|
||||||
|
// bookmarks: [
|
||||||
|
// <page-numer>,
|
||||||
|
// ...
|
||||||
|
// ],
|
||||||
|
// // this is optional...
|
||||||
|
// position: <page-number>
|
||||||
|
// pages: [
|
||||||
|
// // root <page>...
|
||||||
|
// {
|
||||||
|
// type: 'page' | 'cover',
|
||||||
|
// content: <page-content>
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// // article...
|
||||||
|
// {
|
||||||
|
// type: 'article',
|
||||||
|
// pages: [
|
||||||
|
// <page>,
|
||||||
|
// ...
|
||||||
|
// ]
|
||||||
|
// ]
|
||||||
|
// ...
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// XXX store cover state...
|
||||||
|
function buildJSONState(export_bookmarks, export_position){
|
||||||
|
function _getContent(_, elem){
|
||||||
|
elem = $(elem)
|
||||||
|
if(elem.hasClass('page')){
|
||||||
|
return {
|
||||||
|
type: elem.hasClass('cover') ? 'cover' : 'page',
|
||||||
|
content: elem.children('.content')[0].outerHTML
|
||||||
|
}
|
||||||
|
} else if(elem.hasClass('article')){
|
||||||
|
return {
|
||||||
|
type: 'article',
|
||||||
|
pages: elem.children('.page').map(_getContent).toArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var res = {
|
||||||
|
title: $('.magazine').attr('title'),
|
||||||
|
// this can contain pages or arrays...
|
||||||
|
pages: $('.magazine > .page, .magazine > .article').map(_getContent).toArray(),
|
||||||
|
bookmarks: export_bookmarks ? buildBookmarkList() : [],
|
||||||
|
}
|
||||||
|
if(export_position){
|
||||||
|
res.position = getPageNumber()
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
function loadJSONState(data){
|
function loadJSONState(data){
|
||||||
// XXX
|
function _build(block, elem){
|
||||||
|
if(elem.type == 'page'){
|
||||||
|
block.append(_createPage(elem.content))
|
||||||
|
|
||||||
|
} else if(elem.type == 'cover'){
|
||||||
|
block.append(_createCoverPage(elem.content))
|
||||||
|
|
||||||
|
} else if(elem.type == 'article') {
|
||||||
|
// buiold an article...
|
||||||
|
var article = _createEmptyArticle()
|
||||||
|
.appendTo(block)
|
||||||
|
// populate article with pages...
|
||||||
|
$(elem.pages).each(function(_, e){
|
||||||
|
_build(article, e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
function buildJSONState(){
|
|
||||||
// XXX
|
|
||||||
}
|
}
|
||||||
function dumpJSONState(){
|
var mag = _createEmptyMagazine(data.title)
|
||||||
// XXX
|
$(data.pages).each(function(_, e){
|
||||||
|
_build(mag, e)
|
||||||
|
})
|
||||||
|
loadMagazine(mag)
|
||||||
|
loadBookmarks(data.bookmarks)
|
||||||
|
setCurrentPage(data.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -910,7 +982,7 @@ function _createPage(template){
|
|||||||
.addClass('page')
|
.addClass('page')
|
||||||
.append($('<div/>')
|
.append($('<div/>')
|
||||||
.addClass('content')
|
.addClass('content')
|
||||||
.text(template))
|
.html(template))
|
||||||
}
|
}
|
||||||
function _createCoverPage(template){
|
function _createCoverPage(template){
|
||||||
return _createPage(template).addClass('cover')
|
return _createPage(template).addClass('cover')
|
||||||
@ -922,9 +994,14 @@ function _createCoverPage(template){
|
|||||||
// - cover
|
// - cover
|
||||||
// - article
|
// - article
|
||||||
// - cover
|
// - cover
|
||||||
|
function loadMagazine(mag){
|
||||||
|
clearMagazine()
|
||||||
|
return mag.appendTo($('.aligner'))
|
||||||
|
}
|
||||||
|
|
||||||
function createMagazine(title, cover, article){
|
function createMagazine(title, cover, article){
|
||||||
clearMagazine()
|
clearMagazine()
|
||||||
var mag = _createMagazine(title, cover, article).appendTo($('.aligner'))
|
var mag = loadMagazine(_createMagazine(title, cover, article))
|
||||||
setCurrentPage()
|
setCurrentPage()
|
||||||
setupNavigator()
|
setupNavigator()
|
||||||
return mag
|
return mag
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user