From 0ba8e46c1e7888b6033acb90a1f35234f5216d06 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 21 Mar 2013 16:55:42 +0100 Subject: [PATCH] add former tophat-core.js as manifold-core.js -- remove extra spin --- manifold/js/manifold-core.js | 119 +++++++++++++++++++++++++++++++++++ plugins/hazelnut/hazelnut.js | 2 +- 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 manifold/js/manifold-core.js diff --git a/manifold/js/manifold-core.js b/manifold/js/manifold-core.js new file mode 100644 index 00000000..ae9067f5 --- /dev/null +++ b/manifold/js/manifold-core.js @@ -0,0 +1,119 @@ +/* + * This file is included in tophat_render.php + */ + +/* getting random error messages with this... -- jordan + wait until query code is fixed +jQuery(document).ready(function() { + // ajax default settings + jQuery.ajaxSetup({ + timeout: 3000, + error:function(x,e){ + if('parsererror'==e) { + alert('Sorry, we ran into a technical problem (parse error). Please try again...'); + } else if('timeout'==e) { + alert('Request timed out. Please try again...'); + } + else if ( "status" in x ) { + if(0 == x.status){ + alert('You are offline! Please check your network.'); + }else if (404 == x.status){ + alert('Sorry, we ran into a technical problem (404). Please try again...'); + }else if(500 == x.status){ + alert('Sorry, we ran into a technical problem (500). Please try again...'); + } + } + else { + alert('Sorry, we ran into a technical problem (unknown error). Please try again...'); + } + } + }); +}); +*/ + +function get_value(value) { + //if(typeof(jQuery(value).attr('value'))!="undefined"){ + if (/.*<\/span>/i.test(value)) { + return jQuery(value).attr('value'); + } else { + return value; + } +} + +/* +From: http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object + I want to note that the .clone() method in jQuery only clones DOM elements. In order to clone JavaScript objects, you would do: + + // Shallow copy + var newObject = jQuery.extend({}, oldObject); + + // Deep copy + var newObject = jQuery.extend(true, {}, oldObject); + + More information can be found in the jQuery documentation +*/ +function clone_object(obj) { + return jQuery.extend(true, {}, obj); +} + +/* https://gist.github.com/661855 */ +(function(jQuery) { + + var o = jQuery({}); + + jQuery.subscribe = function( types, selector, data, fn) { + /* borrowed from jQuery */ + if ( data == null && fn == null ) { + // ( types, fn ) + fn = selector; + data = selector = undefined; + } else if ( fn == null ) { + if ( typeof selector === "string" ) { + // ( types, selector, fn ) + fn = data; + data = undefined; + } else { + // ( types, data, fn ) + fn = data; + data = selector; + selector = undefined; + } + } + /* */ + + /* We use an indirection function that will clone the object passed in + * parameter to the subscribe callback + * + * FIXME currently we only clone query objects which are the only ones + * supported and editable, we might have the same issue with results but + * the page load time will be severely affected... + */ + o.on.apply(o, [types, selector, data, function() { + for(i = 1; i < arguments.length; i++) { + if ( arguments[i].constructor.name == 'Query' ) + arguments[i] = arguments[i].clone(); + } + fn.apply(o, arguments); + }]); + }; + + jQuery.unsubscribe = function() { + o.off.apply(o, arguments); + }; + + jQuery.publish = function() { + o.trigger.apply(o, arguments); + }; + +}(jQuery)); + + +function executeFunctionByName(functionName, context /*, args */) { + var args = Array.prototype.slice.call(arguments).splice(2); + var namespaces = functionName.split("."); + var func = namespaces.pop(); + for(var i = 0; i < namespaces.length; i++) { + context = context[namespaces[i]]; + } + return context[func].apply(this, args); +} diff --git a/plugins/hazelnut/hazelnut.js b/plugins/hazelnut/hazelnut.js index 90dc75c7..76009760 100644 --- a/plugins/hazelnut/hazelnut.js +++ b/plugins/hazelnut/hazelnut.js @@ -147,7 +147,7 @@ oSelectAll.click(selectAll); /* Spinner (could be done when the query is received = a query is in progress, also for update) */ - $('#' + options.plugin_uuid).spin() +// $('#' + options.plugin_uuid).spin() /* Add a filtering function to the current table * Note: we use closure to get access to the 'options' -- 2.45.2