plugins: updated query_editor
[myslice.git] / plugins / myplugin / myplugin.js
1 /**
2  * MySlice MyPlugin demonstration plugin
3  * Version: 0.1.0
4  * URL: http://www.myslice.info
5  * Description: Template for writing new plugins and illustrating the different possibilities of the plugin API
6  * Requires: 
7  * Author: The MySlice Team
8  * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités
9  * License: GPLv3
10  */
11
12 /*
13  * It's a best practice to pass jQuery to an IIFE (Immediately Invoked Function
14  * Expression) that maps it to the dollar sign so it can't be overwritten by
15  * another library in the scope of its execution.
16  */
17 (function( $ ){
18
19     var PLUGIN_NAME = 'MyPlugin';
20
21     // Routing calls
22     jQuery.fn.ResourcesSelected = function( method ) {
23         if ( methods[method] ) {
24             return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
25         } else if ( typeof method === 'object' || ! method ) {
26             return methods.init.apply( this, arguments );
27         } else {
28             jQuery.error( 'Method ' +  method + ' does not exist on jQuery' + PLUGIN_NAME );
29         }    
30
31     };
32
33     /***************************************************************************
34      * Public methods
35      ***************************************************************************/
36
37     var methods = {
38
39         /**
40          * @brief Plugin initialization
41          * @param options : an associative array of setting values
42          * @return : a jQuery collection of objects on which the plugin is
43          *     applied, which allows to maintain chainability of calls
44          */
45         init : function( options ) {
46
47             return this.each(function(){
48
49                 var $this = $(this);
50
51                 /* An object that will hold private variables and methods */
52                 var s = new ResourcesSelected(options);
53                 $(this).data('Manifold', s);
54                 
55             }); // this.each
56         }, // init
57
58         /**
59          * @brief Plugin destruction
60          * @return : a jQuery collection of objects on which the plugin is
61          *     applied, which allows to maintain chainability of calls
62          */
63         destroy : function( ) {
64
65             return this.each(function(){
66                 var $this = jQuery(this), data = $this.data('Manifold');
67                 jQuery(window).unbind('Manifold');
68                 data.Manifold.remove();
69                 $this.removeData('Manifold');
70             })
71
72         }, // destroy
73
74     }; // var methods
75
76     /***************************************************************************
77      * ResourcesSelected object
78      ***************************************************************************/
79
80     function MyPlugin(options)
81     {
82         /* member variables */
83
84         this.options = options;
85
86         /* methods */
87
88         /* constructor */
89
90     } // function MyPlugin
91
92 })(jQuery);