bye bye resources_selected, welcome queryupdater
[myslice.git] / to-be-integrated / plugins / debug_platform / static / js / debug_platform.js
1 /**
2  * Description: DebugPlatform plugin
3  * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA
4  * License: GPLv3
5  */
6
7 /*
8  * It's a best practice to pass jQuery to an IIFE (Immediately Invoked Function
9  * Expression) that maps it to the dollar sign so it can't be overwritten by
10  * another library in the scope of its execution.
11  */
12
13 (function($){
14
15     
16     // routing calls
17     jQuery.fn.DebugPlatform = function( method ) {
18                 if ( methods[method] ) {
19                         return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
20                 } else if ( typeof method === 'object' || ! method ) {
21                         return methods.init.apply( this, arguments );
22                 } else {
23                         jQuery.error( 'Method ' +  method + ' does not exist on jQuery.DebugPlatform' );
24                 }    
25     };
26
27     /***************************************************************************
28      * Public methods
29      ***************************************************************************/
30
31     var methods = {
32
33         /**
34          * @brief Plugin initialization
35          * @param options : an associative array of setting values
36          * @return : a jQuery collection of objects on which the plugin is
37          *     applied, which allows to maintain chainability of calls
38          */
39         init : function ( options ) {
40
41             var default_code_mirror_options = {
42               gutters: ["note-gutter", "CodeMirror-linenumbers"],
43               tabSize: 4,
44               indentUnit: 4,
45               matchBrackets: true,
46               lineNumbers: true,
47               lineWrapping: true,
48               tabMode: 'spaces' // or 'shift'
49             };
50
51             /* Default settings */
52             var options = $.extend( {
53                 useCodeMirror: true,
54                 codeMirrorOptions: default_code_mirror_options,
55                 syntaxHighlighting: []
56             }, options);
57
58             return this.each(function() {
59
60                 var $this = $(this);
61
62                 /* An object that will hold private variables and methods */
63                 var plugin = new DebugPlatform(options);
64                 $this.data('Manifold', plugin);
65
66                 /* Events */
67                 $this.on('show.DebugPlatform', methods.show);
68
69                 // This is the new plugin API meant to replace the weird publish_subscribe mechanism
70             }); // this.each
71         }, // init
72
73         /**
74          * @brief Plugin destruction
75          * @return : a jQuery collection of objects on which the plugin is
76          *     applied, which allows to maintain chainability of calls
77          */
78         destroy : function( ) {
79
80             return this.each(function() {
81                 var $this = $(this);
82                 var querytable = $this.data('Manifold');
83
84                 // Unbind all events using namespacing
85                 $(window).unbind('Manifold');
86
87                 // Remove associated data
88                 querytable.remove();
89                 $this.removeData('Manifold');
90             });
91         }, // destroy
92
93     }; // var methods;
94
95     /***************************************************************************
96      * Plugin object
97      ***************************************************************************/
98
99     function DebugPlatform(options)
100     {
101         /* member variables */
102         this.options = options;
103
104         var object = this;
105
106     } // function DebugPlatform
107
108 })( jQuery );
109