From: Jordan Augé Date: Fri, 2 Aug 2013 08:43:03 +0000 (+0200) Subject: added the MyPlugin plugin template X-Git-Tag: myslice-0.2-1~83^2~3 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=8518758390ada9d342455308f6dea853196f1c4e added the MyPlugin plugin template --- diff --git a/plugins/myplugin/__init__.py b/plugins/myplugin/__init__.py new file mode 100644 index 00000000..ce8e9392 --- /dev/null +++ b/plugins/myplugin/__init__.py @@ -0,0 +1,23 @@ +from unfold.plugin import Plugin + +class MyPlugin(Plugin): + + def template_file (self): + return "myplugin.html" + + def requirements (self): + reqs = { + 'js_files' : [ + 'js/myplugin.js' + ], + 'css_files': [ + 'css/myplugin.css', + ] + } + return reqs + + def json_settings_list (self): + return ['plugin_uuid', 'domid'] + + def export_json_settings (self): + return True diff --git a/plugins/myplugin/myplugin.css b/plugins/myplugin/myplugin.css new file mode 100644 index 00000000..e69de29b diff --git a/plugins/myplugin/myplugin.html b/plugins/myplugin/myplugin.html new file mode 100644 index 00000000..aa176334 --- /dev/null +++ b/plugins/myplugin/myplugin.html @@ -0,0 +1,3 @@ +
+

MyPlugin

+
diff --git a/plugins/myplugin/myplugin.js b/plugins/myplugin/myplugin.js new file mode 100644 index 00000000..5ea308d6 --- /dev/null +++ b/plugins/myplugin/myplugin.js @@ -0,0 +1,92 @@ +/** + * MySlice MyPlugin demonstration plugin + * Version: 0.1.0 + * URL: http://www.myslice.info + * Description: Template for writing new plugins and illustrating the different possibilities of the plugin API + * Requires: + * Author: The MySlice Team + * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités + * License: GPLv3 + */ + +/* + * It's a best practice to pass jQuery to an IIFE (Immediately Invoked Function + * Expression) that maps it to the dollar sign so it can't be overwritten by + * another library in the scope of its execution. + */ +(function( $ ){ + + var PLUGIN_NAME = 'MyPlugin'; + + // Routing calls + jQuery.fn.ResourcesSelected = function( method ) { + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + jQuery.error( 'Method ' + method + ' does not exist on jQuery' + PLUGIN_NAME ); + } + + }; + + /*************************************************************************** + * Public methods + ***************************************************************************/ + + var methods = { + + /** + * @brief Plugin initialization + * @param options : an associative array of setting values + * @return : a jQuery collection of objects on which the plugin is + * applied, which allows to maintain chainability of calls + */ + init : function( options ) { + + return this.each(function(){ + + var $this = $(this); + + /* An object that will hold private variables and methods */ + var s = new ResourcesSelected(options); + $(this).data('Manifold', s); + + }); // this.each + }, // init + + /** + * @brief Plugin destruction + * @return : a jQuery collection of objects on which the plugin is + * applied, which allows to maintain chainability of calls + */ + destroy : function( ) { + + return this.each(function(){ + var $this = jQuery(this), data = $this.data('Manifold'); + jQuery(window).unbind('Manifold'); + data.Manifold.remove(); + $this.removeData('Manifold'); + }) + + }, // destroy + + }; // var methods + + /*************************************************************************** + * ResourcesSelected object + ***************************************************************************/ + + function MyPlugin(options) + { + /* member variables */ + + this.options = options; + + /* methods */ + + /* constructor */ + + } // function MyPlugin + +})(jQuery);