Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
8a1e595d
Commit
8a1e595d
authored
Jun 07, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reworked 2nd instance in example to only using ajax links
parent
77fdb96b
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
695 additions
and
319 deletions
+695
-319
gadget/filebrowser.js
gadget/filebrowser.js
+95
-64
gadget/filebrowser_and_preview.js
gadget/filebrowser_and_preview.js
+119
-46
gadget/filecontent.js
gadget/filecontent.js
+53
-101
gadget/preview.html
gadget/preview.html
+18
-0
gadget/preview.js
gadget/preview.js
+88
-0
gadget/preview_by_hash_change.js
gadget/preview_by_hash_change.js
+4
-0
gadget/preview_by_postmessage.js
gadget/preview_by_postmessage.js
+65
-45
renderjs.js
renderjs.js
+253
-63
No files found.
gadget/filebrowser.js
View file @
8a1e595d
/*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"
use strict
"
;
(
function
(
document
,
$
)
{
"
use strict
"
;
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
...
@@ -15,76 +14,108 @@
return
null
;
};
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
;
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
scope
,
register
,
service
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
if
(
fileToDisplay
)
{
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
$
.
ajax
({
method
:
'
GET
'
,
// XXX Hardcoded
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
$
.
ajax
({
method
:
'
GET
'
,
// XXX Hardcoded
url
:
value
.
_links
.
storage
.
href
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value2
,
textStatus
,
jqXHR
)
{
var
content_type
=
jqXHR
.
getResponseHeader
(
"
Content-Type
"
)
||
""
;
// XXX Hardcoded mime type
if
(
content_type
.
split
(
'
;
'
)[
0
]
===
"
application/hal+json
"
)
{
// XXX Will fail if response does not send expected links...
$
(
this
).
html
(
"
<ul>
"
);
for
(
var
i
in
value2
.
_links
.
contents
){
$
(
this
).
append
(
"
<li><button id='
"
+
i
+
"
'>
"
+
value2
.
_links
.
contents
[
i
].
href
+
"
</button></li>
"
);
$
(
this
).
find
(
"
#
"
+
i
.
toString
()).
on
(
'
click
'
,
function
(
e
,
target
)
{
$
.
ajax
({
// XXX Hardcoded post and url
// Why using postMessage?
method
:
"
POST
"
,
url
:
value
.
_links
.
display
.
href
,
context
:
$
(
this
),
data
:
$
(
this
).
text
(),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
Plumbing failed:
"
+
errorThrown
);
},
// success: function (value, textStatus, jqXHR) {
// console.log(value);
// },
});
});
}
$
(
this
).
append
(
"
</ul>
"
);
}
else
{
$
(
this
).
text
(
"
Unsupported content type
"
+
content_type
);
};
},
});
},
});
scope
=
value
.
_links
.
scope
.
href
.
slice
(
0
,
-
1
).
split
(
/
[/]
+/
).
pop
();
register
=
value
.
_links
.
call
.
href
.
replace
(
"
{method}
"
,
"
register
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
""
);
service
=
{
"
type
"
:
"
service/test
"
,
"
src
"
:
encodeURIComponent
(
window
.
location
.
href
),
"
rel
"
:
"
browse
"
,
"
self
"
:
window
.
frameElement
.
id
};
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
$
.
ajax
({
method
:
'
POST
'
,
url
:
register
,
context
:
$
(
this
),
data
:
JSON
.
stringify
(
service
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
registration failed:
"
+
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
// console.log("registration successful");
}
});
// HACK: this is hacking the functionality provided by the
// filebrowser!
// 'browser://call/browse/' should be called by the interactor
// instead of hardcoding it here
$
.
ajax
({
method
:
'
GET
'
,
url
:
value
.
_links
.
scope
.
href
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value2
,
textStatus
,
jqXHR
)
{
var
content_type
=
jqXHR
.
getResponseHeader
(
"
Content-Type
"
)
||
""
,
request
=
value
.
_links
.
call
.
href
.
replace
(
"
{method}
"
,
"
service
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
"
preview
"
);
// XXX Hardcoded mime type
if
(
content_type
.
split
(
'
;
'
)[
0
]
===
"
application/hal+json
"
)
{
// XXX Will fail if response does not send expected links...
$
(
this
).
html
(
"
<ul>
"
);
for
(
var
i
in
value2
.
_links
.
contents
){
$
(
this
).
append
(
"
<li><button id='
"
+
i
+
"
'>
"
+
value2
.
_links
.
contents
[
i
].
href
+
"
</button></li>
"
);
$
(
this
).
find
(
"
#
"
+
i
.
toString
()).
on
(
'
click
'
,
function
(
e
,
target
)
{
$
.
ajax
({
method
:
"
POST
"
,
url
:
request
,
context
:
$
(
this
),
data
:
$
(
this
).
text
(),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
request failed:
"
+
errorThrown
);
},
// success: function (value, textStatus, jqXHR) {
// console.log("request sent");
// }
});
});
}
$
(
this
).
append
(
"
</ul>
"
);
}
else
{
$
(
this
).
text
(
"
Unsupported content type
"
+
content_type
);
};
}
});
},
});
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
(2)
"
);
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
};
$
(
document
).
ready
(
function
()
{
mapUrl
(
window
.
location
);
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
});
}(
document
,
jQuery
));
gadget/filebrowser_and_preview.js
View file @
8a1e595d
/*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"
use strict
"
;
(
function
(
document
,
$
)
{
...
...
@@ -20,6 +19,20 @@
return
-
1
;
};
var
generateUuid
=
function
()
{
var
S4
=
function
()
{
/* 65536 */
var
i
,
string
=
Math
.
floor
(
Math
.
random
()
*
0x10000
).
toString
(
16
);
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
string
=
"
0
"
+
string
;
}
return
string
;
};
return
S4
()
+
S4
();
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
...
@@ -32,29 +45,69 @@
return
null
;
};
// this is our "interactor", it only knows one other iFrame
// so we post to this one!
var
handler
=
function
(
event
)
{
var
frames
=
document
.
getElementsByTagName
(
"
iframe
"
),
frame
,
i
;
for
(
i
=
0
;
i
<
frames
.
length
;
i
+=
1
)
{
frame
=
frames
[
i
];
if
(
myIndexOf
(
event
.
source
.
location
.
pathname
,
frame
.
getAttribute
(
"
src
"
).
split
(
"
?
"
)[
0
]
)
<
0
)
{
frame
.
contentWindow
.
postMessage
(
event
.
data
,
"
*
"
);
// frame.contentWindow.postMessage(event.data, window.location.href);
}
// prevent registrations to renderJs from triggering here
var
type
=
event
.
data
.
type
,
service
,
scope
,
request
;
if
(
type
===
undefined
)
{
$
.
ajax
({
method
:
"
GET
"
,
url
:
event
.
data
,
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
request failed:
"
+
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
// we now have the URL to handle and the method
// to request. We need to POST this, because
// we can't access renderJS.gadgetService from here...
// when optimizing all the secondary ajax calls should be removed
// question also is, whether we need POST at all, if we could
// pass everything through the URL?
scope
=
value
.
_links
.
self
.
href
.
split
(
"
/
"
).
slice
(
0
,
-
1
).
pop
();
service
=
{
"
service
"
:
value
.
_links
.
self
.
href
.
split
(
/
[/]
+/
).
pop
(),
"
parameters
"
:
[
value
.
_links
.
request
.
href
],
"
scope
"
:
scope
}
request
=
'
browser://request/
'
+
scope
+
'
/
'
;
$
.
ajax
({
method
:
"
POST
"
,
url
:
request
,
context
:
$
(
this
),
data
:
JSON
.
stringify
(
service
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
request for service failed
"
);
},
// success: function () {
// console.log("service requested from renderJS");
// }
});
}
});
// var frames = document.getElementsByTagName("iframe"), frame, i;
// for (i = 0; i < frames.length; i += 1) {
// frame = frames[i];
// if (myIndexOf(
// event.source.location.pathname,
// frame.getAttribute("src").split("?")[0]
// ) < 0) {
// frame.contentWindow.postMessage(event.data, "*");
// }
// }
}
};
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
,
fileToDisplayData
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
browserAPI
,
previewAPI
;
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
// XXX Hardcoded
...
...
@@ -64,45 +117,65 @@
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
fileToDisplayData
=
"
data://application/hal+json;base64,
"
+
var
access
;
// detour to request, while working on the 2nd preview window
if
(
value
.
_links
.
target
.
href
===
"
preview_by_postmessage.html
"
)
{
access
=
"
request
"
;
}
else
{
access
=
"
plumb
"
;
}
// merge again once working!
browserAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
value
.
_links
.
storage
.
href
},
storage
:
{
href
:
value
.
_links
.
storage
.
href
},
display
:
{
href
:
'
browser://plumb/parentwindow/
'
},
self
:
{
href
:
value
.
_links
.
scope
.
href
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
display
:
{
href
:
'
browser://
'
+
access
+
'
/parentwindow/
'
},
// pass API-url so child can call parent
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
if
(
fileToDisplay
)
{
$
(
"
body
"
).
html
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser.html?file=
'
+
fileToDisplayData
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
previewAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
display
:
{
href
:
''
},
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
value
.
_links
.
preview
.
href
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
$
(
"
body
"
).
html
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser.html?file=
'
+
browserAPI
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
},
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
value
.
_links
.
target
.
href
+
'
?file=
'
+
previewAPI
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
}
});
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
(2)
"
);
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
};
$
(
document
).
ready
(
function
()
{
mapUrl
(
window
.
location
);
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
if
(
window
.
addEventListener
){
window
.
addEventListener
(
"
message
"
,
handler
,
false
)
...
...
gadget/filecontent.js
View file @
8a1e595d
/*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
// filebrowser_and_preview.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"
use strict
"
;
(
function
(
document
,
$
)
{
// sample contents
localStorage
.
setItem
(
"
foo
"
,
"
bar
"
);
localStorage
.
setItem
(
"
baz
"
,
"
bam
"
);
sessionStorage
.
setItem
(
"
cous
"
,
"
cous
"
);
sessionStorage
.
setItem
(
"
schnick
"
,
"
schnack
"
);
// contents
localStorage
.
setItem
(
"
foo
"
,
"
bar
"
);
localStorage
.
setItem
(
"
baz
"
,
"
bam
"
);
sessionStorage
.
setItem
(
"
cous
"
,
"
cous
"
);
sessionStorage
.
setItem
(
"
schnick
"
,
"
schnack
"
);
// var myIndexOf = function (path, contains) {
// var len = path.length;
// var wordLen = contains.length;
// for(var i = 0; i < len; i++) {
// var j = 0;
// for(j = 0; j < wordLen; j++) {
// if(path[i+j] != contains[j]) {
// break;
// }
// }
// if(j == wordLen) {
// return i;
// }
// }
// return -1;
// };
//
// var getParameter = function(searchString, paramName) {
// var i, val, params = searchString.split("&");
//
// for (i=0;i<params.length;i++) {
// val = params[i].split("=");
// if (val[0] == paramName) {
// return decodeURIComponent(val[1]);
// }
// }
// return null;
// };
//
// // this is our "interactor", it only knows one other iFrame
// // so we post to this one!
// var handler = function (event) {
// var frames = document.getElementsByTagName("iframe"), frame, i;
// for (i = 0; i < frames.length; i += 1) {
// frame = frames[i];
// if (myIndexOf(
// event.source.location.pathname,
// frame.getAttribute("src").split("?")[0]
// ) < 0) {
// frame.contentWindow.postMessage(event.data, "*");
// }
// }
// };
//
var
mapUrl
=
function
(
url
)
{
// var searchString = url.href.split("?")[1],
// fileToDisplay;
//
// if (searchString) {
// fileToDisplay = getParameter(searchString, "file");
//
// if (fileToDisplay) {
var
param1
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
""
},
storage
:
{
href
:
'
browser://browse/ls/
'
},
preview
:
{
href
:
'
preview_by_hash_change.html
'
},
}}));
var
generateUuid
=
function
()
{
var
S4
=
function
()
{
var
i
,
string
=
Math
.
floor
(
Math
.
random
()
*
0x10000
).
toString
(
16
);
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
string
=
"
0
"
+
string
;
}
return
string
;
};
return
S4
()
+
S4
();
};
var
param2
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
""
},
storage
:
{
href
:
'
browser://browse/ss/
'
},
preview
:
{
href
:
'
preview_by_postmessage.html
'
},
}}));
var
setup
=
function
()
{
// this will have to run automatically should renderJs have an easy API
var
instance1
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
// not sure if scope should be passed as a link or JSON parameter
scope
:
{
href
:
'
browser://browse/ls/
'
},
target
:
{
href
:
'
preview_by_hash_change.html
'
},
call
:
{
href
:
''
}
}}));
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser_and_preview.html
'
+
"
?file=
"
+
param1
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
var
instance2
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
'
browser://browse/ss/
'
},
target
:
{
href
:
'
preview_by_postmessage.html
'
},
call
:
{
href
:
''
}
}}));
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser_and_preview.html
'
+
"
?file=
"
+
param2
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser_and_preview.html
'
+
"
?file=
"
+
instance1
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
// } else {
// $("body").text("No parameter found in url");
// }
// } else {
// $("body").text("No parameter found in url (2)");
// }
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser_and_preview.html
'
+
"
?file=
"
+
instance2
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
};
$
(
document
).
ready
(
function
()
{
mapUrl
(
window
.
location
);
// if (window.addEventListener){
// window.addEventListener("message", handler, false)
// } else {
// window.attachEvent("onmessage", handler)
// }
setup
();
});
}(
document
,
jQuery
));
gadget/preview.html
0 → 100644
View file @
8a1e595d
<!DOCTYPE html>
<html>
<head>
<title>
Preview
</title>
<meta
name=
"viewport"
content=
"width=device-width, height=device-height, initial-scale=1"
/>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
<script
type=
"text/javascript"
src=
"http://code.jquery.com/jquery-1.9.1.min.js"
></script>
<script
type=
"text/javascript"
src=
"../hyperbrowser.js"
></script>
<script
type=
"text/javascript"
src=
"../renderjs.js"
></script>
<script
type=
"text/javascript"
src=
"preview.js"
></script>
</head>
<body>
<noscript>
Please enable Javascript
</noscript>
</body>
</html>
\ No newline at end of file
gadget/preview.js
0 → 100644
View file @
8a1e595d
// > grab URL with parameters of file to open
// > call addGadget with those parameters?
// > display a file from some storage (local/session)
// > storage type will also be a parameter in the url?
// return "browser://localstorage/foo"
// file=browser%3A%2F%2Flocalstorage%2Ffoo
/*global document, jQuery */
"
use strict
"
;
(
function
(
document
,
$
)
{
var
ajaxGet
=
function
(
src
,
cb
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
src
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
cb
(
value
,
textStatus
,
jqXHR
);
}
});
};
var
handler
=
function
(
event
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
}
else
{
window
.
document
.
body
.
innerHTML
=
value
;
}
});
});
}
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
if
(
value
===
""
)
{
$
(
this
).
text
(
"
file not found
"
);
}
else
{
$
(
this
).
text
(
value
);
}
},
});
}
}
else
{
$
(
this
).
text
(
"
no file to display
"
);
}
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
val
=
params
[
i
].
split
(
"
=
"
);
if
(
val
[
0
]
==
paramName
)
{
return
decodeURIComponent
(
val
[
1
]);
}
}
return
null
;
};
$
(
document
).
ready
(
function
()
{
// mapUrl(window.location);
if
(
window
.
addEventListener
){
window
.
addEventListener
(
"
message
"
,
handler
,
false
)
}
else
{
window
.
attachEvent
(
"
onmessage
"
,
handler
)
}
});
}(
document
,
jQuery
));
\ No newline at end of file
gadget/preview_by_hash_change.js
View file @
8a1e595d
...
...
@@ -83,6 +83,10 @@
}
else
{
window
.
attachEvent
(
"
onmessage
"
,
handler
)
}
// $(window).on('hashchange', function() {
// console.log("LE HASH CHANGED");
// });
// $(window).trigger("hashchange");
});
}(
document
,
jQuery
));
\ No newline at end of file
gadget/preview_by_postmessage.js
View file @
8a1e595d
// > grab URL with parameters of file to open
// > call addGadget with those parameters?
// > display a file from some storage (local/session)
// > storage type will also be a parameter in the url?
// return "browser://localstorage/foo"
// file=browser%3A%2F%2Flocalstorage%2Ffoo
/*global document, jQuery */
"
use strict
"
;
(
function
(
document
,
$
)
{
...
...
@@ -24,44 +17,21 @@
};
var
handler
=
function
(
event
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
}
else
{
window
.
document
.
body
.
innerHTML
=
value
;
}
});
});
}
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
if
(
value
===
""
)
{
$
(
this
).
text
(
"
file not found
"
);
}
else
{
$
(
this
).
text
(
value
);
}
},
var
type
=
event
.
data
.
type
,
method
=
type
?
type
.
split
(
"
/
"
)[
0
]
:
undefined
;
// prevent both renderJs and page events triggering on "run"
if
(
type
===
undefined
||
method
!==
"
run
"
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
}
else
{
window
.
document
.
body
.
innerHTML
=
value
;
}
});
}
}
else
{
$
(
this
).
text
(
"
no file to display
"
);
});
}
}
;
}
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
...
@@ -75,8 +45,58 @@
return
null
;
};
$
(
document
).
ready
(
function
()
{
// mapUrl(window.location);
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
scope
,
register
,
service
;
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
scope
=
value
.
_links
.
scope
.
href
.
slice
(
0
,
-
1
).
split
(
/
[/]
+/
).
pop
();
register
=
value
.
_links
.
call
.
href
.
replace
(
"
{method}
"
,
"
register
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
""
);
service
=
{
"
type
"
:
"
service/test
"
,
"
src
"
:
encodeURIComponent
(
window
.
location
.
href
),
"
rel
"
:
"
preview
"
,
"
self
"
:
window
.
frameElement
.
id
};
$
.
ajax
({
method
:
'
POST
'
,
url
:
register
,
context
:
$
(
this
),
data
:
JSON
.
stringify
(
service
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
registration failed:
"
+
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
// console.log("registration successful");
}
});
}
});
}
}
$
(
document
).
ready
(
function
()
{
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
if
(
window
.
addEventListener
){
window
.
addEventListener
(
"
message
"
,
handler
,
false
)
...
...
renderjs.js
View file @
8a1e595d
This diff is collapsed.
Click to expand it.
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