Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard
erp5
Commits
d6563ef6
Commit
d6563ef6
authored
Sep 04, 2018
by
Richard
Committed by
Richard
Sep 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_notebook]: different localStorages for different notebooks
parent
0d7a728a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
4 deletions
+90
-4
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_notebook.html.html
...Item/portal_skins/erp5_notebook/gadget_notebook.html.html
+1
-1
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
...al_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
+89
-3
No files found.
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_notebook.html.html
View file @
d6563ef6
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
</head>
</head>
<body>
<body>
<div
id=
'page'
></div>
<script
id=
"jsmd"
type=
"text/jsmd"
></script>
<script
id=
"jsmd"
type=
"text/jsmd"
></script>
<div
id=
'page'
></div>
</body>
</body>
</html>
</html>
\ No newline at end of file
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_officejs_jio_notebook.js.js
View file @
d6563ef6
...
@@ -3,6 +3,65 @@
...
@@ -3,6 +3,65 @@
(
function
(
window
,
rJS
,
RSVP
)
{
(
function
(
window
,
rJS
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
function
parseJsmdChunk
(
str
)
{
var
chunkType
,
content
,
firstLine
,
settings
=
{},
firstLineBreak
=
str
.
indexOf
(
'
\n
'
);
if
(
firstLineBreak
===
-
1
)
{
// a cell with only 1 line, and hence no content
firstLine
=
str
;
content
=
''
;
}
else
{
firstLine
=
str
.
substring
(
0
,
firstLineBreak
).
trim
();
content
=
str
.
substring
(
firstLineBreak
+
1
).
trim
();
}
// let firstLine = str.substring(0,firstLineBreak).trim()
var
firstLineFirstSpace
=
firstLine
.
indexOf
(
'
'
);
if
(
firstLineFirstSpace
===
-
1
)
{
// if there is NO space on the first line (after trimming), there are no cell settings
chunkType
=
firstLine
.
toLowerCase
();
}
else
{
// if there is a space on the first line (after trimming), there must be cell settings
chunkType
=
firstLine
.
substring
(
0
,
firstLineFirstSpace
).
toLowerCase
();
// make sure the cell settings parse as JSON
}
if
(
chunkType
===
'
meta
'
)
{
return
{
chunkType
:
'
meta
'
,
iodideSettings
:
JSON
.
parse
(
content
)
};
}
return
null
;
}
function
getiodideSettingsFromJsmd
(
jsmdString
)
{
// returns iodideSettings of last found chunk and exits
var
chunkObjects
=
jsmdString
.
split
(
'
\n
%%
'
)
.
map
(
function
(
str
,
chunkNum
)
{
// if this is the first chunk, and it starts with "%%", drop those chars
var
sstr
;
if
(
chunkNum
===
0
&&
str
.
substring
(
0
,
2
)
===
'
%%
'
)
{
sstr
=
str
.
substring
(
2
);
}
else
{
sstr
=
str
;
}
return
sstr
;
})
.
map
(
function
(
str
)
{
return
str
.
trim
();
})
.
filter
(
function
(
str
)
{
return
str
!==
''
;
});
for
(
var
i
=
(
chunkObjects
.
length
-
1
);
i
>=
0
;
i
--
)
{
var
chunk
=
parseJsmdChunk
(
chunkObjects
[
i
]);
if
(
chunk
&&
chunk
.
iodideSettings
)
{
return
chunk
.
iodideSettings
;
}
}
return
''
;
}
rJS
(
window
)
rJS
(
window
)
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Acquired methods
// Acquired methods
...
@@ -22,11 +81,31 @@
...
@@ -22,11 +81,31 @@
return
this
.
changeState
({
return
this
.
changeState
({
key
:
options
.
key
,
key
:
options
.
key
,
value
:
options
.
value
,
value
:
options
.
value
,
first_render
:
true
first_render
:
true
,
timestamp
:
options
.
render_timestamp
});
});
})
})
.
onStateChange
(
function
(
modified_dict
)
{
.
onStateChange
(
function
(
modified_dict
)
{
if
(
!
this
.
state
.
value
.
includes
(
'
%%
'
))
{
this
.
state
.
value
=
''
;
}
var
iodideSettings
=
getiodideSettingsFromJsmd
(
this
.
state
.
value
);
if
(
iodideSettings
&&
!
iodideSettings
.
title
)
{
iodideSettings
.
title
=
'
notebook-
'
+
modified_dict
.
timestamp
;
var
regex
=
/%% meta
\r\n([\S\s]
*
?)\n
%%/m
;
var
capturedGroup
=
this
.
state
.
value
.
match
(
regex
)[
1
];
this
.
state
.
value
=
this
.
state
.
value
.
replace
(
capturedGroup
,
JSON
.
stringify
(
iodideSettings
));
}
if
(
!
iodideSettings
)
{
var
jsmdTitleTemplate
=
'
%% meta
\n
{
\n
"title": ""
\n
}
\n
'
,
notebookTitle
=
'
notebook-
'
+
modified_dict
.
timestamp
,
positionToInsertTitle
=
20
,
jsmdNotebookTitle
=
[
jsmdTitleTemplate
.
slice
(
0
,
positionToInsertTitle
),
notebookTitle
,
jsmdTitleTemplate
.
slice
(
positionToInsertTitle
)].
join
(
''
);
this
.
state
.
value
=
jsmdNotebookTitle
+
this
.
state
.
value
;
}
this
.
element
.
querySelector
(
'
script
'
).
textContent
=
this
.
state
.
value
;
this
.
element
.
querySelector
(
'
script
'
).
textContent
=
this
.
state
.
value
;
if
(
!
modified_dict
.
hasOwnProperty
(
'
first_render
'
))
{
if
(
!
modified_dict
.
hasOwnProperty
(
'
first_render
'
))
{
throw
new
Error
(
'
Sorry, it is not possible to dynamically change the iodide content
'
);
throw
new
Error
(
'
Sorry, it is not possible to dynamically change the iodide content
'
);
}
}
...
@@ -36,8 +115,15 @@
...
@@ -36,8 +115,15 @@
})
})
.
declareMethod
(
"
getContent
"
,
function
()
{
.
declareMethod
(
"
getContent
"
,
function
()
{
var
dict
=
{};
//prefer content since last save, fallback on autosave if it does not exist
dict
[
this
.
state
.
key
]
=
localStorage
.
getItem
(
'
AUTOSAVE: untitled
'
);
var
dict
=
{},
notebookTitle
=
getiodideSettingsFromJsmd
(
this
.
state
.
value
).
title
,
localStorageJsmd
=
localStorage
.
getItem
(
notebookTitle
);
if
(
!
localStorageJsmd
)
{
var
autosaveString
=
'
AUTOSAVE:
'
+
notebookTitle
;
localStorageJsmd
=
localStorage
.
getItem
(
autosaveString
);
}
dict
[
this
.
state
.
key
]
=
localStorageJsmd
;
return
dict
;
return
dict
;
});
});
}(
window
,
rJS
,
RSVP
));
}(
window
,
rJS
,
RSVP
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment