added the MyPlugin plugin template
authorJordan Augé <jordan.auge@lip6.fr>
Fri, 2 Aug 2013 08:43:03 +0000 (10:43 +0200)
committerJordan Augé <jordan.auge@lip6.fr>
Fri, 2 Aug 2013 08:43:03 +0000 (10:43 +0200)
plugins/myplugin/__init__.py [new file with mode: 0644]
plugins/myplugin/myplugin.css [new file with mode: 0644]
plugins/myplugin/myplugin.html [new file with mode: 0644]
plugins/myplugin/myplugin.js [new file with mode: 0644]

diff --git a/plugins/myplugin/__init__.py b/plugins/myplugin/__init__.py
new file mode 100644 (file)
index 0000000..ce8e939
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/plugins/myplugin/myplugin.html b/plugins/myplugin/myplugin.html
new file mode 100644 (file)
index 0000000..aa17633
--- /dev/null
@@ -0,0 +1,3 @@
+<div id={{ domid }}>
+<p>MyPlugin</p>
+</div>
diff --git a/plugins/myplugin/myplugin.js b/plugins/myplugin/myplugin.js
new file mode 100644 (file)
index 0000000..5ea308d
--- /dev/null
@@ -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);