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

shrink code

parent d55d473e
......@@ -2,37 +2,6 @@
"use strict";
(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 i, val, params = searchString.split("&");
......@@ -106,22 +75,13 @@
$(this).text(errorThrown);
},
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!
browserAPI = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({
_links: {
self: {href: value._links.scope.href},
self: {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}'}
}}));
......@@ -130,27 +90,18 @@
_links: {
self: {href:''},
scope: {href: value._links.scope.href},
display: {href: ''},
call: {href:'browser://call/{method}/{scope}/{interaction}'}
}}));
$("body").html(
'<iframe src="' +
// XXX Hardcoded gadget to load
'filebrowser.html?file=' + browserAPI +
'" id="' + generateUuid() +
'">' +
'<p>Your browser does not support iframes.</p>' +
'</iframe">');
$("body").addGadget({
"src": 'filebrowser.html?file=' + browserAPI,
"iframe": "true"
});
$("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">');
$("body").addGadget({
"src": value._links.target.href + '?file=' + previewAPI,
"iframe": "true"
});
}
});
} else {
......
......@@ -9,12 +9,12 @@
sessionStorage.setItem("schnick", "schnack");
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," +
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: ''}
......
......@@ -817,8 +817,7 @@
),
"sandbox" : priv.getAttribute(gadget, 'sandbox') || false,
"iframe" : priv.getAttribute(gadget, 'iframe') || false,
"wrapper": gadget,
"directory": spec
"wrapper": gadget
};
// add gadget
......@@ -904,7 +903,7 @@
options.parent.replaceWith(newHTML);
} else {
newParentElement = options.parent;
$(newHTML).prependTo(options.parent);
$(newHTML).appendTo(options.parent);
}
if (callback) {
callback();
......@@ -931,7 +930,7 @@
options.parent.replaceWith(newHTML);
} else {
newParentElement = options.parent;
$(newHTML).prependTo(options.parent);
$(newHTML).appendTo(options.parent);
}
// select iframe
......@@ -1025,12 +1024,11 @@
window.top.postMessage(options, window.location.href);
};
// => load gadget
// => add a gadget
that.addGadget = $.fn.addGadget = function (options) {
var addressArray = window.location.href.split("?"),
element = this[0];
var element = this[0];
// set parent
// check if we can remove the parent
if (element === document || element === window || element === document.body) {
options.parent = document.body;
options.replaceParent = false;
......@@ -1038,43 +1036,31 @@
options.parent = this;
options.replaceParent = true;
}
// set uuid
if (options.id === undefined) {
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 cors
// LOADING
// module
// ======================== LOADING ========================
// module/requireJs
if (options.module && require !== undefined) {
require([priv.extractModuleName(options.src)], function (response) {
priv.appendGadget(response, options);
});
// iFrame
} else if (options.iframe) {
priv.appendGadget(undefined, options);
// via Ajax (default)
// straight ajax (default)
} else {
$.ajax({
url: options.src,
// not sure this is helpful or not
cache: true,
method: options.method || "GET",
success: function (data) {
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