Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cribjs-editor
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
Cédric Le Ninivin
cribjs-editor
Commits
4332c52e
Commit
4332c52e
authored
Sep 18, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add crib enable to CribJS editor for offline support
parent
132335a1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
0 deletions
+121
-0
crib-enable.html
crib-enable.html
+21
-0
crib-enable.js
crib-enable.js
+100
-0
No files found.
crib-enable.html
0 → 100644
View file @
4332c52e
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width"
/>
<title>
Jio Gadget
</title>
<link
rel=
"http://www.renderjs.org/rel/interface"
href=
"interface_jio.html"
>
<!-- renderjs -->
<script
src=
"rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"renderjs.js"
type=
"text/javascript"
></script>
<script
src=
"jiodev.js"
type=
"text/javascript"
></script>
<!-- custom script -->
<script
src=
"crib-enable.js"
type=
"text/javascript"
></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
crib-enable.js
0 → 100644
View file @
4332c52e
/*global window, rJS, jIO, FormData */
/*jslint indent: 2, maxerr: 3 */
(
function
(
window
,
rJS
,
jIO
)
{
"
use strict
"
;
function
waitForServiceWorkerActive
(
registration
)
{
var
serviceWorker
;
if
(
registration
.
installing
)
{
serviceWorker
=
registration
.
installing
;
}
else
if
(
registration
.
waiting
)
{
serviceWorker
=
registration
.
waiting
;
}
else
if
(
registration
.
active
)
{
serviceWorker
=
registration
.
active
;
}
if
(
serviceWorker
.
state
!==
"
activated
"
)
{
return
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
serviceWorker
.
addEventListener
(
'
statechange
'
,
function
(
e
)
{
if
(
e
.
target
.
state
===
"
activated
"
)
{
resolve
();
}
});
RSVP
.
delay
(
500
).
then
(
function
()
{
reject
(
new
Error
(
"
Timeout service worker install
"
));
});
});
}
}
rJS
(
window
)
.
ready
(
function
(
gadget
)
{
// Initialize the gadget local parameters
gadget
.
state_parameter_dict
=
{};
gadget
.
state_parameter_dict
.
default_document
=
window
.
location
.
protocol
+
"
//
"
+
window
.
location
.
host
+
window
.
location
.
pathname
.
substring
(
0
,
window
.
location
.
pathname
.
length
-
"
gadget_jio_crib.html
"
.
length
)
+
"
/
"
;
this
.
state_parameter_dict
.
jio_storage
=
jIO
.
createJIO
({
"
type
"
:
"
indexeddb
"
,
"
database
"
:
"
ojs_source_code
"
});
return
this
.
state_parameter_dict
.
jio_storage
.
put
(
gadget
.
state_parameter_dict
.
default_document
,
{})
})
.
ready
(
function
(
gadget
)
{
if
(
'
serviceWorker
'
in
navigator
)
{
// XXX Hack to not add a new service worker when one is already declared
if
(
!
navigator
.
serviceWorker
.
controller
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
navigator
.
serviceWorker
.
register
(
'
/gadget_cribjs_bootloader_serviceworker.js
'
,
{
scope
:
'
/
'
}
);
})
.
push
(
function
(
registration
)
{
return
waitForServiceWorkerActive
(
registration
);
})
}
}
else
{
throw
"
Service Worker are not available in your browser
"
;
}
})
.
declareMethod
(
'
get
'
,
function
(
url
)
{
var
storage
=
this
.
state_parameter_dict
.
jio_storage
;
return
storage
.
getAttachment
(
this
.
state_parameter_dict
.
default_document
,
url
)
.
push
(
function
(
result
)
{
return
jIO
.
util
.
readBlobAsDataURL
(
result
);
})
.
push
(
function
(
e
)
{
return
e
.
target
.
result
;
});
})
.
declareMethod
(
'
put
'
,
function
(
url
,
data_uri
)
{
var
storage
=
this
.
state_parameter_dict
.
jio_storage
;
data_uri
=
jIO
.
util
.
dataURItoBlob
(
data_uri
);
return
storage
.
putAttachment
(
this
.
state_parameter_dict
.
default_document
,
url
,
data_uri
);
})
.
declareMethod
(
'
allDocs
'
,
function
()
{
var
storage
=
this
.
state_parameter_dict
.
jio_storage
;
return
storage
.
allAttachments
(
this
.
state_parameter_dict
.
default_document
)
.
push
(
function
(
result
)
{
return
result
;
})
})
.
declareMethod
(
'
remove
'
,
function
(
url
)
{
var
storage
=
this
.
state_parameter_dict
.
jio_storage
;
return
storage
.
removeAttachment
(
this
.
state_parameter_dict
.
default_document
,
url
);
});
}(
window
,
rJS
,
jIO
));
\ 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