X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fstatic%2Fjs%2Fplugin.js;h=24d41129aea7c105c03874aba02950a591c85ce4;hb=91dec1137db6f3b461ab40542f06b5fa93a2efa5;hp=f39296170d98b7b362fd7c01d2a2a7ce8ce0280b;hpb=9a62ec0dc3ee3e859f3563da29d9c838a658b140;p=myslice.git diff --git a/manifold/static/js/plugin.js b/manifold/static/js/plugin.js index f3929617..24d41129 100644 --- a/manifold/static/js/plugin.js +++ b/manifold/static/js/plugin.js @@ -20,6 +20,13 @@ $.plugin = function(name, object) { }; }; +// set to either +// * false or undefined or none : no debug +// * true : trace all event calls +// * [ 'in_progress', 'query_done' ] : would only trace to these events +var plugin_debug=false; +plugin_debug = [ 'in_progress', 'query_done' ]; + var Plugin = Class.extend({ init: function(options, element) { @@ -30,6 +37,9 @@ var Plugin = Class.extend({ // reference and a normal reference this.element = element; this.$element = $(element); + // programmatically add specific class for publishing events + // used in manifold.js for triggering API events + if ( ! this.$element.hasClass('pubsub')) this.$element.addClass('pubsub'); // return this so we can chain/use the bridge with less code. return this; @@ -39,35 +49,52 @@ var Plugin = Class.extend({ return (typeof this.on_filter_added === 'function'); }, + // do we need to log API calls ? + _is_in : function (obj, arr) { + for(var i=0; i + // and then $("#some-id-that-comes-from-the-db") + // however the syntax for that selector prevents from using some characters in id + // and so for some of our ids this won't work + // instead of 'flattening' we now do this instead + // + // and to retrieve it + // $("[some_id='then!we:can+use.what$we!want']") + // which thanks to the quotes, works; and you can use this with id as well in fact + // of course if now we have quotes in the id it's going to squeak, but well.. + + // escape (read: backslashes) some meta-chars in input + escape_id: function(id) { + if( id !== undefined){ + return id.replace( /(:|\.|\[|\])/g, "\\$1" ); + }else{ + return "undefined-id"; + } }, id_from_record: function(method, record) { @@ -226,14 +282,28 @@ var Plugin = Class.extend({ return array[arguments.length + 1]; }, - /* SPIN */ + // TOGGLE + // plugin-helper.js is about managing toggled state + // it would be beneficial to merge it in here + toggle_on: function () { return this.toggle("true"); }, + toggle_off: function () { return this.toggle("false"); }, + toggle: function (status) { + plugin_helper.set_toggle_status (this.options.plugin_uuid,status); + }, - spin: function() { - manifold.spin(this.element); + /* SPIN */ + // use spin() to get our default spin settings (called presets) + // use spin(true) to get spin's builtin defaults + // you can also call spin_presets() yourself and tweak what you need to, like topmenuvalidation does + spin: function (presets) { + var presets = ( presets === undefined ) ? spin_presets() : presets; + try { this.$element.spin(presets); } + catch (err) { messages.debug("Cannot turn on spin " + err); } }, unspin: function() { - manifold.spin(this.element, false); + try { this.$element.spin(false); } + catch (err) { messages.debug("Cannot turn off spin " + err); } }, /* TEMPLATE */