From 4951c1b04bf66f81cf648b76af3795245d56381a Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 11 Feb 2013 05:48:20 +0000 Subject: Improvements to the app management UI. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1444660 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/js/htdocs/ui.js | 110 +++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 14 deletions(-) (limited to 'sca-cpp/trunk/modules/js/htdocs/ui.js') diff --git a/sca-cpp/trunk/modules/js/htdocs/ui.js b/sca-cpp/trunk/modules/js/htdocs/ui.js index 3aa9e1052a..2bd21f6ed4 100644 --- a/sca-cpp/trunk/modules/js/htdocs/ui.js +++ b/sca-cpp/trunk/modules/js/htdocs/ui.js @@ -29,6 +29,8 @@ var ui = {}; ui.elementByID = function(node, id) { if (node.skipNode == true) return null; + if (node == document) + return document.getElementById(id); for (var i in node.childNodes) { var child = node.childNodes[i]; if (isNull(child)) @@ -42,6 +44,21 @@ ui.elementByID = function(node, id) { return null; }; +/** + * Remove ids in a tree of elements. + */ +ui.removeElementIDs = function(node) { + if (!isNull(node.id)) + node.id = null; + for (var i in node.childNodes) { + var child = node.childNodes[i]; + if (isNull(child)) + continue; + ui.removeElementIDs(child); + } + return true; +}; + /** * Return the current document, or a child element with the given id. */ @@ -228,6 +245,20 @@ ui.webkitVersion = function() { return Number(navigator.userAgent.replace(/.*AppleWebKit\/(\d+\.\d+).*/, '$1')); }; +/** + * Return the Safari version. + */ +ui.browserVersion = function() { + return Number(navigator.userAgent.replace(/.*Version\/(\d+\.\d+).*/, '$1')); +}; + +/** + * Return true if the client is Android based. + */ +ui.isAndroid = function() { + return navigator.userAgent.match(/Android/i); +}; + /** * Return true if the client is Firefox. */ @@ -273,16 +304,11 @@ ui.msieVersion = function() { /** * Run a UI rendering function asynchronously. */ -ui.asyncFrame = null; -ui.async = function(f) { - if (isNull(ui.asyncFrame)) - // Use requestAnimationFrame when available, fallback to setTimeout - ui.asyncFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || - function(f) { - return window.setTimeout(f, 16); - }; - return ui.asyncFrame.call(window, f); +ui.async = function(f, t) { + window.setTimeout(function() { + return f(); + }, isNull(t)? 0 : t); + return true; }; /** @@ -290,10 +316,10 @@ ui.async = function(f) { */ ui.delayed = {} ui.delay = function(f, t) { - var id = window.setTimeout(function() { + var id = window.setTimeout(function() { delete ui.delayed[id]; return f(); - }, isNull(t)? 16 : t); + }, isNull(t)? 0 : t); ui.delayed[id] = id; return id; }; @@ -443,6 +469,9 @@ ui.navigate = function(url, win) { window.ontouchmove = null; } + // Cancel any cancelable HTTP requests + HTTPBindingClient.cancelRequests(); + // Cleanup memoized element lookups ui.unmemo$(); @@ -459,13 +488,66 @@ ui.navigate = function(url, win) { return false; } +/** + * Bind a click handler to a widget. + */ +ui.ontouchstart = function(widget, e) { + //debug('ontouchstart'); + widget.down = true; + widget.moved = false; + var t = e.touches[0]; + widget.moveX = t.clientX; + widget.moveY = t.clientY; +}; + +ui.ontouchmove = function(widget, e) { + //debug('ontouchmove'); + var t = e.touches[0]; + if (t.clientX != widget.moveX) { + widget.moveX = t.clientX; + widget.moved = true; + } + if (t.clientY != widget.moveY) { + widget.moveY = t.clientY; + widget.moved = true; + } +}; + +ui.ontouchend = function(widget, e) { + //debug('ontouchend'); + widget.down = false; + if (!widget.moved) { + e.preventDefault(); + return widget.onclick(e); + } +}; + +ui.onclick = function(widget, handler) { + if (ui.isMobile()) { + widget.ontouchstart = function(e) { + return ui.ontouchstart(widget, e); + }; + widget.ontouchmove = function(e) { + return ui.ontouchmove(widget, e); + }; + widget.ontouchend = function(e) { + return ui.ontouchend(widget, e); + }; + } + widget.onclick = function(e) { + //debug('onclick'); + return handler(e); + }; + return widget; +}; + /** * Build a portable tag. */ ui.href = function(id, loc, target, html) { if (target == '_blank') return '' + html + ''; - return '' + html + ''; + return '' + html + ''; }; /** @@ -489,7 +571,7 @@ ui.menufunc = function(id, name, fun, hilight) { function Menu() { this.content = function() { function href(id, fun, html) { - return '' + html + ''; + return '' + html + ''; } if (hilight == true) -- cgit v1.2.3