Commit 8ab4b629 authored by Sven Franck's avatar Sven Franck

shrink code

parent d55d473e
...@@ -2,37 +2,6 @@ ...@@ -2,37 +2,6 @@
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
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 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 getParameter = function(searchString, paramName) {
var i, val, params = searchString.split("&"); var i, val, params = searchString.split("&");
...@@ -106,22 +75,13 @@ ...@@ -106,22 +75,13 @@
$(this).text(errorThrown); $(this).text(errorThrown);
}, },
success: function (value, textStatus, jqXHR) { success: function (value, textStatus, jqXHR) {
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! // merge again once working!
browserAPI = "data://application/hal+json;base64," + browserAPI = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({ window.btoa(JSON.stringify({
_links: { _links: {
self: {href: value._links.scope.href}, self: {href:''},
scope: {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}'} call: {href:'browser://call/{method}/{scope}/{interaction}'}
}})); }}));
...@@ -130,27 +90,18 @@ ...@@ -130,27 +90,18 @@
_links: { _links: {
self: {href:''}, self: {href:''},
scope: {href: value._links.scope.href}, scope: {href: value._links.scope.href},
display: {href: ''},
call: {href:'browser://call/{method}/{scope}/{interaction}'} call: {href:'browser://call/{method}/{scope}/{interaction}'}
}})); }}));
$("body").html( $("body").addGadget({
'<iframe src="' + "src": 'filebrowser.html?file=' + browserAPI,
// XXX Hardcoded gadget to load "iframe": "true"
'filebrowser.html?file=' + browserAPI + });
'" id="' + generateUuid() +
'">' +
'<p>Your browser does not support iframes.</p>' +
'</iframe">');
$("body").append( $("body").addGadget({
'<iframe src="' + "src": value._links.target.href + '?file=' + previewAPI,
// XXX Hardcoded gadget to load "iframe": "true"
value._links.target.href + '?file=' + previewAPI + });
'" id="' + generateUuid() +
'">' +
'<p>Your browser does not support iframes.</p>' +
'</iframe">');
} }
}); });
} else { } else {
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
sessionStorage.setItem("schnick", "schnack"); sessionStorage.setItem("schnick", "schnack");
var setup = function () { var setup = function () {
// this will have to run automatically should renderJs have an easy API // not an easy API...
// can this be done automatically?
var instance1 = "data://application/hal+json;base64," + var instance1 = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({ window.btoa(JSON.stringify({
_links: { _links: {
self: {href: ''}, self: {href: ''},
// not sure if scope should be passed as a link or JSON parameter
scope: {href: 'browser://browse/ls/'}, scope: {href: 'browser://browse/ls/'},
target: {href: 'preview_by_hash_change.html'}, target: {href: 'preview_by_hash_change.html'},
call: {href: ''} call: {href: ''}
......
...@@ -817,8 +817,7 @@ ...@@ -817,8 +817,7 @@
), ),
"sandbox" : priv.getAttribute(gadget, 'sandbox') || false, "sandbox" : priv.getAttribute(gadget, 'sandbox') || false,
"iframe" : priv.getAttribute(gadget, 'iframe') || false, "iframe" : priv.getAttribute(gadget, 'iframe') || false,
"wrapper": gadget, "wrapper": gadget
"directory": spec
}; };
// add gadget // add gadget
...@@ -904,7 +903,7 @@ ...@@ -904,7 +903,7 @@
options.parent.replaceWith(newHTML); options.parent.replaceWith(newHTML);
} else { } else {
newParentElement = options.parent; newParentElement = options.parent;
$(newHTML).prependTo(options.parent); $(newHTML).appendTo(options.parent);
} }
if (callback) { if (callback) {
callback(); callback();
...@@ -931,7 +930,7 @@ ...@@ -931,7 +930,7 @@
options.parent.replaceWith(newHTML); options.parent.replaceWith(newHTML);
} else { } else {
newParentElement = options.parent; newParentElement = options.parent;
$(newHTML).prependTo(options.parent); $(newHTML).appendTo(options.parent);
} }
// select iframe // select iframe
...@@ -1025,12 +1024,11 @@ ...@@ -1025,12 +1024,11 @@
window.top.postMessage(options, window.location.href); window.top.postMessage(options, window.location.href);
}; };
// => load gadget // => add a gadget
that.addGadget = $.fn.addGadget = function (options) { that.addGadget = $.fn.addGadget = function (options) {
var addressArray = window.location.href.split("?"), var element = this[0];
element = this[0];
// set parent // check if we can remove the parent
if (element === document || element === window || element === document.body) { if (element === document || element === window || element === document.body) {
options.parent = document.body; options.parent = document.body;
options.replaceParent = false; options.replaceParent = false;
...@@ -1038,43 +1036,31 @@ ...@@ -1038,43 +1036,31 @@
options.parent = this; options.parent = this;
options.replaceParent = true; options.replaceParent = true;
} }
// set uuid // set uuid
if (options.id === undefined) { if (options.id === undefined) {
options.id = priv.generateUuid(); options.id = priv.generateUuid();
} }
// set directory (root)
// if no ?-param is available, we can only set to href
if (options.directory === undefined) {
if (addressArray.length > 1) {
options.directory = {
"root": priv.decodeURI(addressArray[1].split("=")[1])
};
} else {
options.directory = {
"root": that.gadgetService ?
that.gadgetService.root :
window.location.href
};
}
}
// set offline // set offline
// set cors // set cors
// LOADING // ======================== LOADING ========================
// module // module/requireJs
if (options.module && require !== undefined) { if (options.module && require !== undefined) {
require([priv.extractModuleName(options.src)], function (response) { require([priv.extractModuleName(options.src)], function (response) {
priv.appendGadget(response, options); priv.appendGadget(response, options);
}); });
// iFrame // iFrame
} else if (options.iframe) { } else if (options.iframe) {
priv.appendGadget(undefined, options); priv.appendGadget(undefined, options);
// via Ajax (default)
// straight ajax (default)
} else { } else {
$.ajax({ $.ajax({
url: options.src, url: options.src,
// not sure this is helpful or not
cache: true,
method: options.method || "GET", method: options.method || "GET",
success: function (data) { success: function (data) {
priv.appendGadget(data, options); priv.appendGadget(data, options);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment