Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
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
Klaus Wölfel
renderjs
Commits
1ec0842a
Commit
1ec0842a
authored
Jun 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switched to renderJs.mapUrl, cleaned up code
parent
a0a78541
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
314 deletions
+165
-314
gadget/filebrowser.js
gadget/filebrowser.js
+64
-97
gadget/filebrowser_and_preview.js
gadget/filebrowser_and_preview.js
+20
-63
gadget/filecontent.js
gadget/filecontent.js
+23
-26
gadget/preview_by_hash_change.js
gadget/preview_by_hash_change.js
+29
-61
gadget/preview_by_postmessage.js
gadget/preview_by_postmessage.js
+29
-67
No files found.
gadget/filebrowser.js
View file @
1ec0842a
...
...
@@ -2,120 +2,87 @@
(
function
(
document
,
$
)
{
"
use strict
"
;
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
var
setup
=
function
(
)
{
renderJs
.
mapUrl
(
window
.
location
.
search
,
function
(
value
,
textStatus
,
jqXHR
)
{
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
val
=
params
[
i
].
split
(
"
=
"
);
if
(
val
[
0
]
==
paramName
)
{
return
decodeURIComponent
(
val
[
1
]);
}
}
return
null
;
};
var
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
"
:
"
register/any
"
,
"
src
"
:
encodeURIComponent
(
window
.
location
.
href
),
"
rel
"
:
"
browse
"
,
"
self
"
:
window
.
frameElement
.
id
};
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
scope
,
register
,
service
;
$
.
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");
}
});
if
(
fileToDisplay
)
{
// 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
:
fileToDisplay
,
url
:
value
.
_links
.
scope
.
href
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
success
:
function
(
value2
,
textStatus
,
jqXHR
)
{
var
content_type
=
jqXHR
.
getResponseHeader
(
"
Content-Type
"
)
||
""
,
request
=
value
.
_links
.
call
.
href
.
replace
(
"
{method}
"
,
"
request
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
"
preview
"
);
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
"
:
"
register/any
"
,
"
src
"
:
encodeURIComponent
(
window
.
location
.
href
),
"
rel
"
:
"
browse
"
,
"
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");
}
});
// 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>
"
);
// 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}
"
,
"
request
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
"
preview
"
);
$
(
this
).
find
(
"
#
"
+
i
.
toString
()).
on
(
'
click
'
,
function
(
e
,
target
)
{
// 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
);
};
$
.
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
"
);
}
});
};
$
(
document
).
ready
(
function
()
{
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
setup
();
});
}(
document
,
jQuery
));
gadget/filebrowser_and_preview.js
View file @
1ec0842a
...
...
@@ -2,74 +2,31 @@
(
function
(
document
,
$
)
{
"
use strict
"
;
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
;
};
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
browserAPI
,
previewAPI
;
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
// XXX Hardcoded
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
// merge again once working!
browserAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
previewAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
$
(
"
body
"
).
addGadget
({
"
src
"
:
'
filebrowser.html?file=
'
+
browserAPI
,
"
iframe
"
:
"
true
"
});
var
setup
=
function
()
{
renderJs
.
mapUrl
(
window
.
location
.
search
,
function
(
value
,
textStatus
,
jqXHR
)
{
var
sendAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
$
(
"
body
"
).
addGadget
({
"
src
"
:
'
filebrowser.html?file=
'
+
sendAPI
,
"
iframe
"
:
"
true
"
});
$
(
"
body
"
).
addGadget
({
"
src
"
:
value
.
_links
.
target
.
href
+
'
?file=
'
+
previewAPI
,
"
iframe
"
:
"
true
"
});
}
$
(
"
body
"
).
addGadget
({
"
src
"
:
value
.
_links
.
target
.
href
+
'
?file=
'
+
sendAPI
,
"
iframe
"
:
"
true
"
});
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
});
};
$
(
document
).
ready
(
function
()
{
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
setup
();
});
}(
document
,
jQuery
));
gadget/filecontent.js
View file @
1ec0842a
...
...
@@ -9,37 +9,34 @@
sessionStorage
.
setItem
(
"
schnick
"
,
"
schnack
"
);
var
setup
=
function
()
{
// TODO: I don't like scope/target for passing too specific information
// like scope = which storage to use and target = which file to load in
// the next target
// TODO: Should be in window.location.href, not declared here
// TODO: how to pass multiple instances of _links? allow at all?
var
instance1
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
'
browser://browse/ls/
'
},
target
:
{
href
:
'
preview_by_hash_change.html
'
}
// instance1 and 2 should be passed through the URl, mapped here!
renderJs
.
mapUrl
(
window
.
location
.
search
,
function
(
value
,
textStatus
,
jqXHR
)
{
var
instance1
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
'
browser://browse/ls/
'
},
target
:
{
href
:
'
preview_by_hash_change.html
'
}
}}));
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
'
}
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
'
}
}}));
$
(
"
body
"
).
addGadget
({
"
src
"
:
"
filebrowser_and_preview.html?file=
"
+
instance1
,
"
iframe
"
:
"
true
"
});
$
(
"
body
"
).
addGadget
({
"
src
"
:
"
filebrowser_and_preview.html?file=
"
+
instance1
,
"
iframe
"
:
"
true
"
});
$
(
"
body
"
).
addGadget
({
"
src
"
:
"
filebrowser_and_preview.html?file=
"
+
instance2
,
"
iframe
"
:
"
true
"
$
(
"
body
"
).
addGadget
({
"
src
"
:
"
filebrowser_and_preview.html?file=
"
+
instance2
,
"
iframe
"
:
"
true
"
});
});
};
...
...
gadget/preview_by_hash_change.js
View file @
1ec0842a
...
...
@@ -2,70 +2,38 @@
"
use strict
"
;
(
function
(
document
,
$
)
{
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
;
var
setup
=
function
()
{
renderJs
.
mapUrl
(
window
.
location
.
search
,
function
(
value
,
textStatus
,
jqXHR
)
{
var
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
"
:
"
register/any
"
,
"
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");
}
});
});
};
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
"
:
"
register/any
"
,
"
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
"
);
}
setup
();
});
}(
document
,
jQuery
));
\ No newline at end of file
gadget/preview_by_postmessage.js
View file @
1ec0842a
...
...
@@ -2,76 +2,38 @@
"
use strict
"
;
(
function
(
document
,
$
)
{
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
;
var
setup
=
function
()
{
renderJs
.
mapUrl
(
window
.
location
.
search
,
function
(
value
,
textStatus
,
jqXHR
)
{
var
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
"
:
"
register/any
"
,
"
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");
}
});
});
};
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
"
:
"
register/any
"
,
"
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");
}
});
// renderJs.addService(service, function (response, error) {
// console.log("registration happened");
// console.log(error);
// console.log(response);
// });
}
});
}
}
$
(
document
).
ready
(
function
()
{
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
setup
();
});
}(
document
,
jQuery
));
\ 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