diff --git a/static/index.html b/static/index.html index 91d49c0..1ce6517 100644 --- a/static/index.html +++ b/static/index.html @@ -22,7 +22,7 @@ html, body { diff --git a/static/sdk.js b/static/sdk.js index e99723b..6ecf765 100644 --- a/static/sdk.js +++ b/static/sdk.js @@ -1,8 +1,10 @@ ;"use strict"; -var contented = (function($) { +var contented = (function($, currentScriptPath) { "use strict"; + var baseURL = currentScriptPath.replace('sdk.js', ''); + /** * contented_SupportsDrop returns whether drag-and-drop is supported by this * browser. @@ -17,19 +19,23 @@ var contented = (function($) { * contented_EnableDrop enables drag-and-drop upload on a DOM element. * The class "is-dragover" will be toggled on the target element. * - * @param DOMElement element Drop target - * @param string baseURL Base URL of the contented server + * @param any element Drop target (string selector / DOMElement / jQuery) * @param Function onUploaded Called with a property object for every uploaded file * @param Function onClose Called when the widget should be destroyed */ - var contented_EnableDrop = function(element, baseURL, onUploaded, onClose) { + var contented_EnableDrop = function(elementSelector, onUploaded, onClose) { onUploaded = onUploaded || function(){}; onClose = onClose || function(){}; + if ($(elementSelector).length != 1) { + return; // should only find one element + } + var element = $(elementSelector)[0]; + // // Create a new div for ourselves on top of the existing area - $.get(baseURL + "/about", function(ret) { + $.get(baseURL + "about", function(ret) { $("title").text( ret.AppTitle ); var extraText = ""; @@ -37,7 +43,7 @@ var contented = (function($) { extraText = " (max " + Math.floor(ret.MaxUploadBytes / (1024*1024)) + " MiB)"; } - $.get(baseURL + "/widget.html", function(widgetHtml) { + $.get(baseURL + "widget.html", function(widgetHtml) { var $f = $("
").html(widgetHtml); $f.find(".contented-extratext").text(extraText); @@ -147,7 +153,20 @@ var contented = (function($) { return { 'supportsDrop': contented_SupportsDrop, - 'enableDrop': contented_EnableDrop + 'init': contented_EnableDrop }; -})(jQuery); +})( + jQuery, + (function() { + + // Determine current script path + // @ref https://stackoverflow.com/a/26023176 + var scripts = document.querySelectorAll( 'script[src]' ); + var currentScript = scripts[ scripts.length - 1 ].src; + var currentScriptChunks = currentScript.split( '/' ); + var currentScriptFile = currentScriptChunks[ currentScriptChunks.length - 1 ]; + + return currentScript.replace( currentScriptFile, '' ); + })() +);