From: Jordan Augé Date: Thu, 8 Aug 2013 13:14:16 +0000 (+0200) Subject: manifold: imprved plugin class with helpers for naming HTML tags in plugins X-Git-Tag: myslice-0.2-1~70 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=f7419e1b9bedd90e390fa27bf7d7868db617caee manifold: imprved plugin class with helpers for naming HTML tags in plugins plugins: improved active_filters, attempt for using templates in JS third-party: added mustache.js for js templating --- diff --git a/Makefile b/Makefile index 73f0bf95..235336b7 100644 --- a/Makefile +++ b/Makefile @@ -93,6 +93,9 @@ THIRD-PARTY-RESOURCES += $(shell ls third-party/jquery-notify/ui.notify.css) THIRD-PARTY-RESOURCES += $(shell ls third-party/codemirror-3.15/lib/codemirror.js) THIRD-PARTY-RESOURCES += $(shell ls third-party/codemirror-3.15/lib/codemirror.css) THIRD-PARTY-RESOURCES += $(shell ls third-party/codemirror-3.15/mode/sql/sql.js) +# Mustache.js +THIRD-PARTY-RESOURCES += $(shell ls third-party/mustache/mustache.js) + thirdparty-js: @find $(THIRD-PARTY-RESOURCES) -name '*.js' diff --git a/manifold/css/manifold.css b/manifold/css/manifold.css new file mode 100644 index 00000000..42c034d3 --- /dev/null +++ b/manifold/css/manifold.css @@ -0,0 +1,4 @@ +.template { + visibility: hidden; + position: absolute; +} diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 01c55310..667ad34b 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -128,6 +128,8 @@ var manifold = { * Helper functions **************************************************************************/ + separator: '__', + spin_presets: {}, spin: function(locator, active /*= true */) { diff --git a/manifold/js/plugin.js b/manifold/js/plugin.js index 11aefad5..5d3df742 100644 --- a/manifold/js/plugin.js +++ b/manifold/js/plugin.js @@ -83,13 +83,50 @@ var Plugin = Class.extend({ default_options: {}, - speak: function(msg){ - // You have direct access to the associated and cached jQuery element - this.$element.append('

'+msg+'

'); + id: function() + { + var ret = this.options.plugin_uuid; + for (var i = 0; i < arguments.length; i++) { + ret = ret + manifold.separator + arguments[i]; + } + return ret; + }, + + el: function() + { + if (arguments.length == 0) { + return $('#' + this.id()); + } else { + // We make sure to search _inside_ the dom tag of the plugin + return $('#' + this.id.apply(this, arguments), this.el()); + } + }, + + els: function(cls) + { + return $('.' + cls, this.el()); + }, + + id_from_filter: function(filter, use_value) + { + use_value = typeof use_value !== 'undefined' ? use_value : true; + + var key = filter[0]; + var op = filter[1]; + var value = filter[2]; + var op_str = this.getOperatorLabel(op); + var s = manifold.separator; + + if (use_value) { + return 'filter' + s + key + s + op_str + s + value; + } else { + return 'filter' + s + key + s + op_str; + } }, - register: function() { - // Registers the plugin to jQuery + str_from_filter: function(filter) + { + return filter[0] + ' ' + filter[1] + ' ' + filter[2]; }, }); diff --git a/plugins/active_filters/active_filters.html b/plugins/active_filters/active_filters.html index 21e361ef..a722d4a2 100644 --- a/plugins/active_filters/active_filters.html +++ b/plugins/active_filters/active_filters.html @@ -1,15 +1,24 @@ -
-