X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=to-be-integrated%2Fplugins%2Fdebug_platform%2Fstatic%2Fjs%2Fdebug_platform.js;fp=to-be-integrated%2Fplugins%2Fdebug_platform%2Fstatic%2Fjs%2Fdebug_platform.js;h=dda946c33c16256a12375350d8354319413bc5c8;hb=5afb541f209f479b009e8305dd2626780cadcff9;hp=0000000000000000000000000000000000000000;hpb=0c12a2033bcb737c05c472cb069a288f44b3872a;p=unfold.git diff --git a/to-be-integrated/plugins/debug_platform/static/js/debug_platform.js b/to-be-integrated/plugins/debug_platform/static/js/debug_platform.js new file mode 100644 index 00000000..dda946c3 --- /dev/null +++ b/to-be-integrated/plugins/debug_platform/static/js/debug_platform.js @@ -0,0 +1,109 @@ +/** + * Description: DebugPlatform plugin + * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA + * 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($){ + + + // routing calls + jQuery.fn.DebugPlatform = 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.DebugPlatform' ); + } + }; + + /*************************************************************************** + * 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 ) { + + var default_code_mirror_options = { + gutters: ["note-gutter", "CodeMirror-linenumbers"], + tabSize: 4, + indentUnit: 4, + matchBrackets: true, + lineNumbers: true, + lineWrapping: true, + tabMode: 'spaces' // or 'shift' + }; + + /* Default settings */ + var options = $.extend( { + useCodeMirror: true, + codeMirrorOptions: default_code_mirror_options, + syntaxHighlighting: [] + }, options); + + return this.each(function() { + + var $this = $(this); + + /* An object that will hold private variables and methods */ + var plugin = new DebugPlatform(options); + $this.data('Manifold', plugin); + + /* Events */ + $this.on('show.DebugPlatform', methods.show); + + // This is the new plugin API meant to replace the weird publish_subscribe mechanism + }); // 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 = $(this); + var querytable = $this.data('Manifold'); + + // Unbind all events using namespacing + $(window).unbind('Manifold'); + + // Remove associated data + querytable.remove(); + $this.removeData('Manifold'); + }); + }, // destroy + + }; // var methods; + + /*************************************************************************** + * Plugin object + ***************************************************************************/ + + function DebugPlatform(options) + { + /* member variables */ + this.options = options; + + var object = this; + + } // function DebugPlatform + +})( jQuery ); +