You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by bu...@apache.org on 2017/05/17 15:33:04 UTC
svn commit: r1012387 [7/29] - in /websites/staging/ooo-site/trunk: cgi-bin/
content/ content/scripts/api.simile-widgets.org/
content/scripts/api.simile-widgets.org/ajax/
content/scripts/api.simile-widgets.org/ajax/2.2.1.fake/
content/scripts/api.simile...
Added: websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/window-manager.js
==============================================================================
--- websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/window-manager.js (added)
+++ websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/window-manager.js Wed May 17 15:33:02 2017
@@ -0,0 +1,414 @@
+/**
+ * @fileOverview UI layers and window-wide dragging
+ * @name SimileAjax.WindowManager
+ */
+
+/**
+ * This is a singleton that keeps track of UI layers (modal and
+ * modeless) and enables/disables UI elements based on which layers
+ * they belong to. It also provides window-wide dragging
+ * implementation.
+ */
+SimileAjax.WindowManager = {
+ _initialized: false,
+ _listeners: [],
+
+ _draggedElement: null,
+ _draggedElementCallback: null,
+ _dropTargetHighlightElement: null,
+ _lastCoords: null,
+ _ghostCoords: null,
+ _draggingMode: "",
+ _dragging: false,
+
+ _layers: []
+};
+
+SimileAjax.WindowManager.initialize = function() {
+ if (SimileAjax.WindowManager._initialized) {
+ return;
+ }
+
+ SimileAjax.DOM.registerEvent(document.body, "mousedown", SimileAjax.WindowManager._onBodyMouseDown);
+ SimileAjax.DOM.registerEvent(document.body, "mousemove", SimileAjax.WindowManager._onBodyMouseMove);
+ SimileAjax.DOM.registerEvent(document.body, "mouseup", SimileAjax.WindowManager._onBodyMouseUp);
+ SimileAjax.DOM.registerEvent(document, "keydown", SimileAjax.WindowManager._onBodyKeyDown);
+ SimileAjax.DOM.registerEvent(document, "keyup", SimileAjax.WindowManager._onBodyKeyUp);
+
+ SimileAjax.WindowManager._layers.push({index: 0});
+
+ SimileAjax.WindowManager._historyListener = {
+ onBeforeUndoSeveral: function() {},
+ onAfterUndoSeveral: function() {},
+ onBeforeUndo: function() {},
+ onAfterUndo: function() {},
+
+ onBeforeRedoSeveral: function() {},
+ onAfterRedoSeveral: function() {},
+ onBeforeRedo: function() {},
+ onAfterRedo: function() {}
+ };
+ SimileAjax.History.addListener(SimileAjax.WindowManager._historyListener);
+
+ SimileAjax.WindowManager._initialized = true;
+};
+
+SimileAjax.WindowManager.getBaseLayer = function() {
+ SimileAjax.WindowManager.initialize();
+ return SimileAjax.WindowManager._layers[0];
+};
+
+SimileAjax.WindowManager.getHighestLayer = function() {
+ SimileAjax.WindowManager.initialize();
+ return SimileAjax.WindowManager._layers[SimileAjax.WindowManager._layers.length - 1];
+};
+
+SimileAjax.WindowManager.registerEventWithObject = function(elmt, eventName, obj, handlerName, layer) {
+ SimileAjax.WindowManager.registerEvent(
+ elmt,
+ eventName,
+ function(elmt2, evt, target) {
+ return obj[handlerName].call(obj, elmt2, evt, target);
+ },
+ layer
+ );
+};
+
+SimileAjax.WindowManager.registerEvent = function(elmt, eventName, handler, layer) {
+ if (layer == null) {
+ layer = SimileAjax.WindowManager.getHighestLayer();
+ }
+
+ var handler2 = function(elmt, evt, target) {
+ if (SimileAjax.WindowManager._canProcessEventAtLayer(layer)) {
+ SimileAjax.WindowManager._popToLayer(layer.index);
+ try {
+ handler(elmt, evt, target);
+ } catch (e) {
+ SimileAjax.Debug.exception(e);
+ }
+ }
+ SimileAjax.DOM.cancelEvent(evt);
+ return false;
+ }
+
+ SimileAjax.DOM.registerEvent(elmt, eventName, handler2);
+};
+
+SimileAjax.WindowManager.pushLayer = function(f, ephemeral, elmt) {
+ var layer = { onPop: f, index: SimileAjax.WindowManager._layers.length, ephemeral: (ephemeral), elmt: elmt };
+ SimileAjax.WindowManager._layers.push(layer);
+
+ return layer;
+};
+
+SimileAjax.WindowManager.popLayer = function(layer) {
+ for (var i = 1; i < SimileAjax.WindowManager._layers.length; i++) {
+ if (SimileAjax.WindowManager._layers[i] == layer) {
+ SimileAjax.WindowManager._popToLayer(i - 1);
+ break;
+ }
+ }
+};
+
+SimileAjax.WindowManager.popAllLayers = function() {
+ SimileAjax.WindowManager._popToLayer(0);
+};
+
+SimileAjax.WindowManager.registerForDragging = function(elmt, callback, layer) {
+ SimileAjax.WindowManager.registerEvent(
+ elmt,
+ "mousedown",
+ function(elmt, evt, target) {
+ SimileAjax.WindowManager._handleMouseDown(elmt, evt, callback);
+ },
+ layer
+ );
+};
+
+SimileAjax.WindowManager._popToLayer = function(level) {
+ while (level+1 < SimileAjax.WindowManager._layers.length) {
+ try {
+ var layer = SimileAjax.WindowManager._layers.pop();
+ if (layer.onPop != null) {
+ layer.onPop();
+ }
+ } catch (e) {
+ }
+ }
+};
+
+SimileAjax.WindowManager._canProcessEventAtLayer = function(layer) {
+ if (layer.index == (SimileAjax.WindowManager._layers.length - 1)) {
+ return true;
+ }
+ for (var i = layer.index + 1; i < SimileAjax.WindowManager._layers.length; i++) {
+ if (!SimileAjax.WindowManager._layers[i].ephemeral) {
+ return false;
+ }
+ }
+ return true;
+};
+
+SimileAjax.WindowManager.cancelPopups = function(evt) {
+ var evtCoords = (evt) ? SimileAjax.DOM.getEventPageCoordinates(evt) : { x: -1, y: -1 };
+
+ var i = SimileAjax.WindowManager._layers.length - 1;
+ while (i > 0 && SimileAjax.WindowManager._layers[i].ephemeral) {
+ var layer = SimileAjax.WindowManager._layers[i];
+ if (layer.elmt != null) { // if event falls within main element of layer then don't cancel
+ var elmt = layer.elmt;
+ var elmtCoords = SimileAjax.DOM.getPageCoordinates(elmt);
+ if (evtCoords.x >= elmtCoords.left && evtCoords.x < (elmtCoords.left + elmt.offsetWidth) &&
+ evtCoords.y >= elmtCoords.top && evtCoords.y < (elmtCoords.top + elmt.offsetHeight)) {
+ break;
+ }
+ }
+ i--;
+ }
+ SimileAjax.WindowManager._popToLayer(i);
+};
+
+SimileAjax.WindowManager._onBodyMouseDown = function(elmt, evt, target) {
+ if (!("eventPhase" in evt) || evt.eventPhase == evt.BUBBLING_PHASE) {
+ SimileAjax.WindowManager.cancelPopups(evt);
+ }
+};
+
+SimileAjax.WindowManager._handleMouseDown = function(elmt, evt, callback) {
+ SimileAjax.WindowManager._draggedElement = elmt;
+ SimileAjax.WindowManager._draggedElementCallback = callback;
+ SimileAjax.WindowManager._lastCoords = { x: evt.clientX, y: evt.clientY };
+
+ SimileAjax.DOM.cancelEvent(evt);
+ return false;
+};
+
+SimileAjax.WindowManager._onBodyKeyDown = function(elmt, evt, target) {
+ if (SimileAjax.WindowManager._dragging) {
+ if (evt.keyCode == 27) { // esc
+ SimileAjax.WindowManager._cancelDragging();
+ } else if ((evt.keyCode == 17 || evt.keyCode == 16) && SimileAjax.WindowManager._draggingMode != "copy") {
+ SimileAjax.WindowManager._draggingMode = "copy";
+
+ var img = SimileAjax.Graphics.createTranslucentImage(SimileAjax.urlPrefix + "images/copy.png");
+ img.style.position = "absolute";
+ img.style.left = (SimileAjax.WindowManager._ghostCoords.left - 16) + "px";
+ img.style.top = (SimileAjax.WindowManager._ghostCoords.top) + "px";
+ document.body.appendChild(img);
+
+ SimileAjax.WindowManager._draggingModeIndicatorElmt = img;
+ }
+ }
+};
+
+SimileAjax.WindowManager._onBodyKeyUp = function(elmt, evt, target) {
+ if (SimileAjax.WindowManager._dragging) {
+ if (evt.keyCode == 17 || evt.keyCode == 16) {
+ SimileAjax.WindowManager._draggingMode = "";
+ if (SimileAjax.WindowManager._draggingModeIndicatorElmt != null) {
+ document.body.removeChild(SimileAjax.WindowManager._draggingModeIndicatorElmt);
+ SimileAjax.WindowManager._draggingModeIndicatorElmt = null;
+ }
+ }
+ }
+};
+
+SimileAjax.WindowManager._onBodyMouseMove = function(elmt, evt, target) {
+ if (SimileAjax.WindowManager._draggedElement != null) {
+ var callback = SimileAjax.WindowManager._draggedElementCallback;
+
+ var lastCoords = SimileAjax.WindowManager._lastCoords;
+ var diffX = evt.clientX - lastCoords.x;
+ var diffY = evt.clientY - lastCoords.y;
+
+ if (!SimileAjax.WindowManager._dragging) {
+ if (Math.abs(diffX) > 5 || Math.abs(diffY) > 5) {
+ try {
+ if ("onDragStart" in callback) {
+ callback.onDragStart();
+ }
+
+ if ("ghost" in callback && callback.ghost) {
+ var draggedElmt = SimileAjax.WindowManager._draggedElement;
+
+ SimileAjax.WindowManager._ghostCoords = SimileAjax.DOM.getPageCoordinates(draggedElmt);
+ SimileAjax.WindowManager._ghostCoords.left += diffX;
+ SimileAjax.WindowManager._ghostCoords.top += diffY;
+
+ var ghostElmt = draggedElmt.cloneNode(true);
+ ghostElmt.style.position = "absolute";
+ ghostElmt.style.left = SimileAjax.WindowManager._ghostCoords.left + "px";
+ ghostElmt.style.top = SimileAjax.WindowManager._ghostCoords.top + "px";
+ ghostElmt.style.zIndex = 1000;
+ SimileAjax.Graphics.setOpacity(ghostElmt, 50);
+
+ document.body.appendChild(ghostElmt);
+ callback._ghostElmt = ghostElmt;
+ }
+
+ SimileAjax.WindowManager._dragging = true;
+ SimileAjax.WindowManager._lastCoords = { x: evt.clientX, y: evt.clientY };
+
+ document.body.focus();
+ } catch (e) {
+ SimileAjax.Debug.exception("WindowManager: Error handling mouse down", e);
+ SimileAjax.WindowManager._cancelDragging();
+ }
+ }
+ } else {
+ try {
+ SimileAjax.WindowManager._lastCoords = { x: evt.clientX, y: evt.clientY };
+
+ if ("onDragBy" in callback) {
+ callback.onDragBy(diffX, diffY);
+ }
+
+ if ("_ghostElmt" in callback) {
+ var ghostElmt = callback._ghostElmt;
+
+ SimileAjax.WindowManager._ghostCoords.left += diffX;
+ SimileAjax.WindowManager._ghostCoords.top += diffY;
+
+ ghostElmt.style.left = SimileAjax.WindowManager._ghostCoords.left + "px";
+ ghostElmt.style.top = SimileAjax.WindowManager._ghostCoords.top + "px";
+ if (SimileAjax.WindowManager._draggingModeIndicatorElmt != null) {
+ var indicatorElmt = SimileAjax.WindowManager._draggingModeIndicatorElmt;
+
+ indicatorElmt.style.left = (SimileAjax.WindowManager._ghostCoords.left - 16) + "px";
+ indicatorElmt.style.top = SimileAjax.WindowManager._ghostCoords.top + "px";
+ }
+
+ if ("droppable" in callback && callback.droppable) {
+ var coords = SimileAjax.DOM.getEventPageCoordinates(evt);
+ var target = SimileAjax.DOM.hittest(
+ coords.x, coords.y,
+ [ SimileAjax.WindowManager._ghostElmt,
+ SimileAjax.WindowManager._dropTargetHighlightElement
+ ]
+ );
+ target = SimileAjax.WindowManager._findDropTarget(target);
+
+ if (target != SimileAjax.WindowManager._potentialDropTarget) {
+ if (SimileAjax.WindowManager._dropTargetHighlightElement != null) {
+ document.body.removeChild(SimileAjax.WindowManager._dropTargetHighlightElement);
+
+ SimileAjax.WindowManager._dropTargetHighlightElement = null;
+ SimileAjax.WindowManager._potentialDropTarget = null;
+ }
+
+ var droppable = false;
+ if (target != null) {
+ if ((!("canDropOn" in callback) || callback.canDropOn(target)) &&
+ (!("canDrop" in target) || target.canDrop(SimileAjax.WindowManager._draggedElement))) {
+
+ droppable = true;
+ }
+ }
+
+ if (droppable) {
+ var border = 4;
+ var targetCoords = SimileAjax.DOM.getPageCoordinates(target);
+ var highlight = document.createElement("div");
+ highlight.style.border = border + "px solid yellow";
+ highlight.style.backgroundColor = "yellow";
+ highlight.style.position = "absolute";
+ highlight.style.left = targetCoords.left + "px";
+ highlight.style.top = targetCoords.top + "px";
+ highlight.style.width = (target.offsetWidth - border * 2) + "px";
+ highlight.style.height = (target.offsetHeight - border * 2) + "px";
+ SimileAjax.Graphics.setOpacity(highlight, 30);
+ document.body.appendChild(highlight);
+
+ SimileAjax.WindowManager._potentialDropTarget = target;
+ SimileAjax.WindowManager._dropTargetHighlightElement = highlight;
+ }
+ }
+ }
+ }
+ } catch (e) {
+ SimileAjax.Debug.exception("WindowManager: Error handling mouse move", e);
+ SimileAjax.WindowManager._cancelDragging();
+ }
+ }
+
+ SimileAjax.DOM.cancelEvent(evt);
+ return false;
+ }
+};
+
+SimileAjax.WindowManager._onBodyMouseUp = function(elmt, evt, target) {
+ if (SimileAjax.WindowManager._draggedElement != null) {
+ try {
+ if (SimileAjax.WindowManager._dragging) {
+ var callback = SimileAjax.WindowManager._draggedElementCallback;
+ if ("onDragEnd" in callback) {
+ callback.onDragEnd();
+ }
+ if ("droppable" in callback && callback.droppable) {
+ var dropped = false;
+
+ var target = SimileAjax.WindowManager._potentialDropTarget;
+ if (target != null) {
+ if ((!("canDropOn" in callback) || callback.canDropOn(target)) &&
+ (!("canDrop" in target) || target.canDrop(SimileAjax.WindowManager._draggedElement))) {
+
+ if ("onDropOn" in callback) {
+ callback.onDropOn(target);
+ }
+ target.ondrop(SimileAjax.WindowManager._draggedElement, SimileAjax.WindowManager._draggingMode);
+
+ dropped = true;
+ }
+ }
+
+ if (!dropped) {
+ // TODO: do holywood explosion here
+ }
+ }
+ }
+ } finally {
+ SimileAjax.WindowManager._cancelDragging();
+ }
+
+ SimileAjax.DOM.cancelEvent(evt);
+ return false;
+ }
+};
+
+SimileAjax.WindowManager._cancelDragging = function() {
+ var callback = SimileAjax.WindowManager._draggedElementCallback;
+ if ("_ghostElmt" in callback) {
+ var ghostElmt = callback._ghostElmt;
+ document.body.removeChild(ghostElmt);
+
+ delete callback._ghostElmt;
+ }
+ if (SimileAjax.WindowManager._dropTargetHighlightElement != null) {
+ document.body.removeChild(SimileAjax.WindowManager._dropTargetHighlightElement);
+ SimileAjax.WindowManager._dropTargetHighlightElement = null;
+ }
+ if (SimileAjax.WindowManager._draggingModeIndicatorElmt != null) {
+ document.body.removeChild(SimileAjax.WindowManager._draggingModeIndicatorElmt);
+ SimileAjax.WindowManager._draggingModeIndicatorElmt = null;
+ }
+
+ SimileAjax.WindowManager._draggedElement = null;
+ SimileAjax.WindowManager._draggedElementCallback = null;
+ SimileAjax.WindowManager._potentialDropTarget = null;
+ SimileAjax.WindowManager._dropTargetHighlightElement = null;
+ SimileAjax.WindowManager._lastCoords = null;
+ SimileAjax.WindowManager._ghostCoords = null;
+ SimileAjax.WindowManager._draggingMode = "";
+ SimileAjax.WindowManager._dragging = false;
+};
+
+SimileAjax.WindowManager._findDropTarget = function(elmt) {
+ while (elmt != null) {
+ if ("ondrop" in elmt && (typeof elmt.ondrop) == "function") {
+ break;
+ }
+ elmt = elmt.parentNode;
+ }
+ return elmt;
+};
Added: websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/xmlhttp.js
==============================================================================
--- websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/xmlhttp.js (added)
+++ websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/scripts/xmlhttp.js Wed May 17 15:33:02 2017
@@ -0,0 +1,137 @@
+/**
+ * @fileOverview XmlHttp utility functions
+ * @name SimileAjax.XmlHttp
+ */
+
+SimileAjax.XmlHttp = new Object();
+
+/**
+ * Callback for XMLHttp onRequestStateChange.
+ */
+SimileAjax.XmlHttp._onReadyStateChange = function(xmlhttp, fError, fDone) {
+ switch (xmlhttp.readyState) {
+ // 1: Request not yet made
+ // 2: Contact established with server but nothing downloaded yet
+ // 3: Called multiple while downloading in progress
+
+ // Download complete
+ case 4:
+ try {
+ if (xmlhttp.status == 0 // file:// urls, works on Firefox
+ || xmlhttp.status == 200 // http:// urls
+ ) {
+ if (fDone) {
+ fDone(xmlhttp);
+ }
+ } else {
+ if (fError) {
+ fError(
+ xmlhttp.statusText,
+ xmlhttp.status,
+ xmlhttp
+ );
+ }
+ }
+ } catch (e) {
+ SimileAjax.Debug.exception("XmlHttp: Error handling onReadyStateChange", e);
+ }
+ break;
+ }
+};
+
+/**
+ * Creates an XMLHttpRequest object. On the first run, this
+ * function creates a platform-specific function for
+ * instantiating an XMLHttpRequest object and then replaces
+ * itself with that function.
+ */
+SimileAjax.XmlHttp._createRequest = function() {
+ if (SimileAjax.Platform.browser.isIE) {
+ var programIDs = [
+ "Msxml2.XMLHTTP",
+ "Microsoft.XMLHTTP",
+ "Msxml2.XMLHTTP.4.0"
+ ];
+ for (var i = 0; i < programIDs.length; i++) {
+ try {
+ var programID = programIDs[i];
+ var f = function() {
+ return new ActiveXObject(programID);
+ };
+ var o = f();
+
+ // We are replacing the SimileAjax._createXmlHttpRequest
+ // function with this inner function as we've
+ // found out that it works. This is so that we
+ // don't have to do all the testing over again
+ // on subsequent calls.
+ SimileAjax.XmlHttp._createRequest = f;
+
+ return o;
+ } catch (e) {
+ // silent
+ }
+ }
+ // fall through to try new XMLHttpRequest();
+ }
+
+ try {
+ var f = function() {
+ return new XMLHttpRequest();
+ };
+ var o = f();
+
+ // We are replacing the SimileAjax._createXmlHttpRequest
+ // function with this inner function as we've
+ // found out that it works. This is so that we
+ // don't have to do all the testing over again
+ // on subsequent calls.
+ SimileAjax.XmlHttp._createRequest = f;
+
+ return o;
+ } catch (e) {
+ throw new Error("Failed to create an XMLHttpRequest object");
+ }
+};
+
+/**
+ * Performs an asynchronous HTTP GET.
+ *
+ * @param {Function} fError a function of the form
+ function(statusText, statusCode, xmlhttp)
+ * @param {Function} fDone a function of the form function(xmlhttp)
+ */
+SimileAjax.XmlHttp.get = function(url, fError, fDone) {
+ var xmlhttp = SimileAjax.XmlHttp._createRequest();
+
+ xmlhttp.open("GET", url, true);
+ xmlhttp.onreadystatechange = function() {
+ SimileAjax.XmlHttp._onReadyStateChange(xmlhttp, fError, fDone);
+ };
+ xmlhttp.send(null);
+};
+
+/**
+ * Performs an asynchronous HTTP POST.
+ *
+ * @param {Function} fError a function of the form
+ function(statusText, statusCode, xmlhttp)
+ * @param {Function} fDone a function of the form function(xmlhttp)
+ */
+SimileAjax.XmlHttp.post = function(url, body, fError, fDone) {
+ var xmlhttp = SimileAjax.XmlHttp._createRequest();
+
+ xmlhttp.open("POST", url, true);
+ xmlhttp.onreadystatechange = function() {
+ SimileAjax.XmlHttp._onReadyStateChange(xmlhttp, fError, fDone);
+ };
+ xmlhttp.send(body);
+};
+
+SimileAjax.XmlHttp._forceXML = function(xmlhttp) {
+ try {
+ xmlhttp.overrideMimeType("text/xml");
+ } catch (e) {
+ xmlhttp.setrequestheader("Content-Type", "text/xml");
+ }
+};
\ No newline at end of file
Added: websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/simile-ajax-api.js
==============================================================================
--- websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/simile-ajax-api.js (added)
+++ websites/staging/ooo-site/trunk/content/scripts/api.simile-widgets.org/ajax/2.2.1/simile-ajax-api.js Wed May 17 15:33:02 2017
@@ -0,0 +1,214 @@
+/*==================================================
+ * Simile Ajax API
+ *
+ * Include this file in your HTML file as follows:
+ *
+ * <script src="http://simile.mit.edu/ajax/api/simile-ajax-api.js" type="text/javascript"></script>
+ *
+ *==================================================
+ */
+
+if (typeof SimileAjax == "undefined") {
+ var SimileAjax = {
+ loaded: false,
+ loadingScriptsCount: 0,
+ error: null,
+ params: { bundle:"true" }
+ };
+
+ SimileAjax.Platform = new Object();
+ /*
+ HACK: We need these 2 things here because we cannot simply append
+ a <script> element containing code that accesses SimileAjax.Platform
+ to initialize it because IE executes that <script> code first
+ before it loads ajax.js and platform.js.
+ */
+
+ var getHead = function(doc) {
+ return doc.getElementsByTagName("head")[0];
+ };
+
+ SimileAjax.findScript = function(doc, substring) {
+ var heads = doc.documentElement.getElementsByTagName("head");
+ for (var h = 0; h < heads.length; h++) {
+ var node = heads[h].firstChild;
+ while (node != null) {
+ if (node.nodeType == 1 && node.tagName.toLowerCase() == "script") {
+ var url = node.src;
+ var i = url.indexOf(substring);
+ if (i >= 0) {
+ return url;
+ }
+ }
+ node = node.nextSibling;
+ }
+ }
+ return null;
+ };
+ SimileAjax.includeJavascriptFile = function(doc, url, onerror, charset) {
+ onerror = onerror || "";
+ if (doc.body == null) {
+ try {
+ var q = "'" + onerror.replace( /'/g, '&apos' ) + "'"; // "
+ doc.write("<script src='" + url + "' onerror="+ q +
+ (charset ? " charset='"+ charset +"'" : "") +
+ " type='text/javascript'>"+ onerror + "</script>");
+ return;
+ } catch (e) {
+ // fall through
+ }
+ }
+
+ var script = doc.createElement("script");
+ if (onerror) {
+ try { script.innerHTML = onerror; } catch(e) {}
+ script.setAttribute("onerror", onerror);
+ }
+ if (charset) {
+ script.setAttribute("charset", charset);
+ }
+ script.type = "text/javascript";
+ script.language = "JavaScript";
+ script.src = url;
+ return getHead(doc).appendChild(script);
+ };
+ SimileAjax.includeJavascriptFiles = function(doc, urlPrefix, filenames) {
+ for (var i = 0; i < filenames.length; i++) {
+ SimileAjax.includeJavascriptFile(doc, urlPrefix + filenames[i]);
+ }
+ SimileAjax.loadingScriptsCount += filenames.length;
+ SimileAjax.includeJavascriptFile(doc, SimileAjax.urlPrefix + "scripts/signal.js?" + filenames.length);
+ };
+ SimileAjax.includeCssFile = function(doc, url) {
+ if (doc.body == null) {
+ try {
+ doc.write("<link rel='stylesheet' href='" + url + "' type='text/css'/>");
+ return;
+ } catch (e) {
+ // fall through
+ }
+ }
+
+ var link = doc.createElement("link");
+ link.setAttribute("rel", "stylesheet");
+ link.setAttribute("type", "text/css");
+ link.setAttribute("href", url);
+ getHead(doc).appendChild(link);
+ };
+ SimileAjax.includeCssFiles = function(doc, urlPrefix, filenames) {
+ for (var i = 0; i < filenames.length; i++) {
+ SimileAjax.includeCssFile(doc, urlPrefix + filenames[i]);
+ }
+ };
+
+ /**
+ * Append into urls each string in suffixes after prefixing it with urlPrefix.
+ * @param {Array} urls
+ * @param {String} urlPrefix
+ * @param {Array} suffixes
+ */
+ SimileAjax.prefixURLs = function(urls, urlPrefix, suffixes) {
+ for (var i = 0; i < suffixes.length; i++) {
+ urls.push(urlPrefix + suffixes[i]);
+ }
+ };
+
+ /**
+ * Parse out the query parameters from a URL
+ * @param {String} url the url to parse, or location.href if undefined
+ * @param {Object} to optional object to extend with the parameters
+ * @param {Object} types optional object mapping keys to value types
+ * (String, Number, Boolean or Array, String by default)
+ * @return a key/value Object whose keys are the query parameter names
+ * @type Object
+ */
+ SimileAjax.parseURLParameters = function(url, to, types) {
+ to = to || {};
+ types = types || {};
+
+ if (typeof url == "undefined") {
+ url = location.href;
+ }
+ var q = url.indexOf("?");
+ if (q < 0) {
+ return to;
+ }
+ url = (url+"#").slice(q+1, url.indexOf("#")); // toss the URL fragment
+
+ var params = url.split("&"), param, parsed = {};
+ var decode = window.decodeURIComponent || unescape;
+ for (var i = 0; param = params[i]; i++) {
+ var eq = param.indexOf("=");
+ var name = decode(param.slice(0,eq));
+ var old = parsed[name];
+ if (typeof old == "undefined") {
+ old = [];
+ } else if (!(old instanceof Array)) {
+ old = [old];
+ }
+ parsed[name] = old.concat(decode(param.slice(eq+1)));
+ }
+ for (var i in parsed) {
+ if (!parsed.hasOwnProperty(i)) continue;
+ var type = types[i] || String;
+ var data = parsed[i];
+ if (!(data instanceof Array)) {
+ data = [data];
+ }
+ if (type === Boolean && data[0] == "false") {
+ to[i] = false; // because Boolean("false") === true
+ } else {
+ to[i] = type.apply(this, data);
+ }
+ }
+ return to;
+ };
+
+ (function() {
+ var javascriptFiles = [
+ "platform.js",
+ "debug.js",
+ "xmlhttp.js",
+ "json.js",
+ "dom.js",
+ "graphics.js",
+ "date-time.js",
+ "string.js",
+ "html.js",
+ "data-structure.js",
+ "units.js",
+
+ "ajax.js",
+ "history.js",
+ "window-manager.js"
+ ];
+ var cssFiles = [
+ "graphics.css"
+ ];
+ if (!("jQuery" in window) && !("$" in window)) {
+ javascriptFiles.unshift("jquery-1.3.2.min.js");
+ }
+
+ if (typeof SimileAjax_urlPrefix == "string") {
+ SimileAjax.urlPrefix = SimileAjax_urlPrefix;
+ } else {
+ var url = SimileAjax.findScript(document, "simile-ajax-api.js");
+ if (url == null) {
+ SimileAjax.error = new Error("Failed to derive URL prefix for Simile Ajax API code files");
+ return;
+ }
+
+ SimileAjax.urlPrefix = url.substr(0, url.indexOf("simile-ajax-api.js"));
+ }
+
+ SimileAjax.parseURLParameters(url, SimileAjax.params, {bundle:Boolean});
+ if (SimileAjax.params.bundle) {
+ SimileAjax.includeJavascriptFiles(document, SimileAjax.urlPrefix, [ "simile-ajax-bundle.js" ]);
+ } else {
+ SimileAjax.includeJavascriptFiles(document, SimileAjax.urlPrefix + "scripts/", javascriptFiles);
+ }
+ SimileAjax.includeCssFiles(document, SimileAjax.urlPrefix + "styles/", cssFiles);
+
+ SimileAjax.loaded = true;
+ })();
+}