Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5-bin
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
erp5-bin
Commits
6a2e4922
Commit
6a2e4922
authored
Feb 01, 2021
by
Roque
Browse files
Options
Browse Files
Download
Plain Diff
erp5_notebook: JSMD viewer refactoring
See merge request
!8
parents
c510cfd6
ff372f17
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
109 deletions
+49
-109
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
...tem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
+2
-0
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
...ateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
+29
-29
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_viewer.html.html
...m/portal_skins/erp5_notebook/gadget_jsmd_viewer.html.html
+4
-1
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_viewer.js.js
...eItem/portal_skins/erp5_notebook/gadget_jsmd_viewer.js.js
+14
-79
No files found.
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.html.html
View file @
6a2e4922
...
...
@@ -11,8 +11,10 @@
<link
rel=
"stylesheet"
type=
"text/css"
href=
"gadget_jsmd_eval.css"
/>
<script
src=
"rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"renderjs.js"
type=
"text/javascript"
></script>
<script
src=
"marked.js"
type=
"text/javascript"
></script>
<script
src=
"iodide_utils.js"
type=
"text/javascript"
></script>
<script
src=
"gadget_global.js"
type=
"text/javascript"
></script>
<script
src=
"gadget_jsmd_eval.js"
type=
"text/javascript"
></script>
</head>
...
...
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
View file @
6a2e4922
/*global window,
console, RSVP, document, URL, eval, XMLHttpRequest, marked, WebAssembly, loadSharedlib
*/
/*global window,
document, rJS, RSVP, XMLHttpRequest, WebAssembly, loadSharedlib, marked, console
*/
/*jslint nomen: true, indent: 2, maxerr: 3 */
(
function
(
window
)
{
(
function
(
window
,
document
,
rJS
,
RSVP
,
XMLHttpRequest
,
WebAssembly
,
loadSharedlib
,
marked
,
console
)
{
"
use strict
"
;
var
IODide
=
function
createIODide
()
{
...
...
@@ -532,31 +532,31 @@
};
}
rJS
(
window
)
.
declareMethod
(
"
render
"
,
function
(
options
)
{
return
this
.
changeState
(
options
);
})
.
onStateChange
(
function
(
options
)
{
var
gadget
=
this
,
jsmd
=
options
.
jsmd_code
,
cell_list
=
parseJSMDCellList
(
jsmd
),
len
=
cell_list
.
length
,
i
,
queue
=
new
RSVP
.
Queue
();
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
queue
.
push
(
deferCellExecution
(
cell_list
[
i
]));
}
return
queue
.
push
(
function
()
{
console
.
info
(
'
JSMD executed.
'
);
},
function
(
error
)
{
console
.
error
(
error
);
var
pre
=
document
.
createElement
(
'
pre
'
);
pre
.
textContent
=
error
;
document
.
body
.
appendChild
(
pre
);
});
});
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
var
jsmd
=
document
.
querySelector
(
'
[type="text/x-jsmd"]
'
).
textContent
,
cell_list
=
parseJSMDCellList
(
jsmd
),
len
=
cell_list
.
length
,
i
,
queue
=
new
RSVP
.
Queue
();
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
queue
.
push
(
deferCellExecution
(
cell_list
[
i
]));
}
return
queue
.
push
(
function
()
{
console
.
info
(
'
JSMD executed.
'
);
},
function
(
error
)
{
console
.
error
(
error
);
var
pre
=
document
.
createElement
(
'
pre
'
);
pre
.
textContent
=
error
;
document
.
body
.
appendChild
(
pre
);
})
.
push
(
function
()
{
window
.
parent
.
postMessage
(
"
jsmd_eval_done
"
,
window
.
origin
);
});
},
false
);
}(
window
));
\ No newline at end of file
}(
window
,
document
,
rJS
,
RSVP
,
XMLHttpRequest
,
WebAssembly
,
loadSharedlib
,
marked
,
console
));
\ No newline at end of file
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_viewer.html.html
View file @
6a2e4922
...
...
@@ -15,6 +15,9 @@
</head>
<body>
<div></div>
<div
data-gadget-url=
"gadget_jsmd_eval.html"
data-gadget-scope=
"jsmd_eval"
data-gadget-sandbox=
"iframe"
>
</div>
</body>
</html>
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_viewer.js.js
View file @
6a2e4922
/*global window, rJS, console, RSVP, jIO, DOMParser, Blob, document,
URL, loopEventListener */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(
function
(
window
,
rJS
,
RSVP
,
jIO
,
DOMParser
,
document
,
URL
,
loopEventListener
)
{
/*global window, rJS, RSVP, document, loopEventListener, console */
/*jslint nomen: true, indent: 2, maxerr: 30 */
(
function
(
window
,
rJS
,
RSVP
,
document
,
loopEventListener
,
console
)
{
"
use strict
"
;
function
fetchHTML
(
url
,
base_url
)
{
url
=
new
URL
(
url
,
base_url
).
href
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
url
:
url
});
})
.
push
(
function
(
evt
)
{
// Insert a "base" element, in order to resolve all relative links
// which could get broken with a data url
var
doc
=
(
new
DOMParser
()).
parseFromString
(
evt
.
target
.
responseText
,
'
text/html
'
),
base
=
doc
.
createElement
(
'
base
'
);
base
.
href
=
url
;
doc
.
head
.
insertBefore
(
base
,
doc
.
head
.
firstChild
);
return
doc
;
});
}
rJS
(
window
)
.
ready
(
function
(
gadget
)
{
gadget
.
property_dict
=
{};
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.
declareMethod
(
"
render
"
,
function
(
options
)
{
return
this
.
changeState
(
options
);
})
.
onStateChange
(
function
()
{
// Reset everything if something change
var
gadget
=
this
,
base_url
=
document
.
location
.
toString
(),
doc
;
var
gadget
=
this
;
gadget
.
property_dict
.
deferred
=
RSVP
.
defer
();
return
fetchHTML
(
"
gadget_jsmd_eval.html
"
,
base_url
)
.
push
(
function
(
result
)
{
doc
=
result
;
// Insert text
doc
.
body
.
textContent
=
''
;
// Insert the JSMD value inside the HTML
var
script
=
document
.
createElement
(
'
script
'
),
iframe
=
document
.
createElement
(
"
iframe
"
),
loading_spinner
=
document
.
createElement
(
"
div
"
);
script
.
setAttribute
(
'
type
'
,
'
text/x-jsmd
'
);
script
.
setAttribute
(
'
id
'
,
'
jsmd-source
'
);
script
.
textContent
=
gadget
.
state
.
value
;
doc
.
head
.
appendChild
(
script
);
return
gadget
.
getDeclaredGadget
(
'
jsmd_eval
'
)
.
push
(
function
(
eval_gadget
)
{
var
loading_spinner
=
document
.
createElement
(
"
div
"
);
loading_spinner
.
setAttribute
(
'
id
'
,
'
js-spinner
'
);
loading_spinner
.
classList
.
add
(
"
nb-ui-icon-spinner
"
);
loading_spinner
.
classList
.
add
(
"
nb-ui-btn-icon-notext
"
);
loading_spinner
.
classList
.
add
(
"
nb-loader
"
);
loading_spinner
.
innerHTML
=
"
Loading notebook...
"
;
/*
blob = new Blob([doc.documentElement.outerHTML],
{type: "text/html;charset=UTF-8"});
return jIO.util.readBlobAsDataURL(blob);
})
.push(function (evt) {
*/
// XXX Insecure
iframe
.
setAttribute
(
"
sandbox
"
,
"
allow-scripts allow-same-origin
"
);
// iframe.setAttribute("csp", "default-src *; script-src * 'unsafe-inline';");
// iframe.setAttribute("src", evt.target.result);
iframe
.
setAttribute
(
'
id
'
,
'
jsmd_eval_notebook
'
);
iframe
.
setAttribute
(
'
name
'
,
'
jsmd_eval_notebook
'
);
iframe
.
setAttribute
(
"
srcdoc
"
,
doc
.
documentElement
.
outerHTML
);
gadget
.
element
.
innerHTML
=
iframe
.
outerHTML
;
gadget
.
element
.
prepend
(
loading_spinner
);
return
eval_gadget
.
render
({
'
jsmd_code
'
:
gadget
.
state
.
value
});
})
.
push
(
function
()
{
gadget
.
listenResize
();
gadget
.
listenMessage
();
console
.
log
(
"
JSMD Eval Done.
"
);
document
.
querySelector
(
'
[id="js-spinner"]
'
).
remove
();
return
gadget
.
property_dict
.
deferred
.
resolve
();
});
})
...
...
@@ -102,20 +51,6 @@
});
})
.
declareJob
(
'
listenMessage
'
,
function
()
{
var
gadget
=
this
,
dict
=
gadget
.
property_dict
;
return
loopEventListener
(
window
,
'
message
'
,
false
,
function
(
event
)
{
//only handle jsmd eval child messages
if
((
event
.
origin
!==
window
.
origin
)
||
(
event
.
data
!==
"
jsmd_eval_done
"
))
return
;
console
.
log
(
"
JSMD Eval Done.
"
);
document
.
querySelector
(
'
[id="js-spinner"]
'
).
remove
();
return
dict
.
deferred
.
resolve
();
}
);
})
.
declareJob
(
'
listenResize
'
,
function
()
{
var
gadget
=
this
;
function
resize
()
{
...
...
@@ -127,4 +62,4 @@
return
loopEventListener
(
window
,
'
resize
'
,
false
,
resize
);
});
}(
window
,
rJS
,
RSVP
,
jIO
,
DOMParser
,
document
,
URL
,
loopEventListener
));
\ No newline at end of file
}(
window
,
rJS
,
RSVP
,
document
,
loopEventListener
,
console
));
\ 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