bd49c1cf9708d7d7613a30db730b53b76b65e29c
[myslice.git] / plugins / pres_view / static / js / pres_view.js
1 /**
2  * Description: PresView plugin
3  * Copyright (c) 2012 UPMC Sorbonne Universite
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     var PLUGIN_NAME = 'PresView';
16
17     // routing calls
18     jQuery.fn.PresView = function( method ) {
19                 if ( methods[method] ) {
20                         return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
21                 } else if ( typeof method === 'object' || ! method ) {
22                         return methods.init.apply( this, arguments );
23                 } else {
24                         jQuery.error( 'Method ' +  method + ' does not exist on jQuery.' + PLUGIN_NAME );
25                 }    
26     };
27
28     /***************************************************************************
29      * Public methods
30      ***************************************************************************/
31
32     var methods = {
33
34         /**
35          * @brief Plugin initialization
36          * @param options : an associative array of setting values
37          * @return : a jQuery collection of objects on which the plugin is
38          *     applied, which allows to maintain chainability of calls
39          */
40         init : function ( options ) {
41
42             return this.each(function() {
43
44                 var $this = $(this);
45
46                 /* An object that will hold private variables and methods */
47                 var plugin = new PresView(options);
48                 $this.data('Manifold', plugin);
49
50                 /* Events */
51                 $this.on('show.' + PLUGIN_NAME, methods.show);
52
53             }); // this.each
54         }, // init
55
56         /**
57          * @brief Plugin destruction
58          * @return : a jQuery collection of objects on which the plugin is
59          *     applied, which allows to maintain chainability of calls
60          */
61         destroy : function( ) {
62
63             return this.each(function() {
64                 var $this = $(this);
65                 var plugin = $this.data('Manifold');
66
67                 // Unbind all events using namespacing
68                 $(window).unbind(PLUGIN_NAME);
69
70                 // Remove associated data
71                 plugin.remove();
72                 $this.removeData('Manifold');
73             });
74         }, // destroy
75
76         show : function( ) {
77             google.maps.event.trigger(map, 'resize');
78         } // show
79
80     }; // var methods;
81
82     /***************************************************************************
83      * Plugin object
84      ***************************************************************************/
85
86     function PresView(options)
87     {
88
89         /* member variables */
90         this.options = options;
91
92         var object = this;
93       
94         /**
95          *
96          */
97         this.initialize = function() {
98                         //APE + no conflit
99             j = jQuery.noConflict();
100                     ape_initialize();
101                     j.getScript('/all-static/js/config.js');
102
103                         // jquery:datepicker
104                         j(".datepicker").datepicker({
105                                 showOtherMonths: true,
106                                 selectOtherMonths: true,
107                                 showAnim: 'slideDown',
108                                 //regional: 'fr',
109                                 dateFormat: 'dd/mm/yy',
110                                 setDate: -14
111                         });
112
113                         // jquery:accordion
114                         j("#accordion").accordion({ 
115                                 animated: 'easeslide',
116                                 autoHeight: false,
117                                 //fillSpace: true
118                         });
119                         
120                         // jquery:slider
121                         j("#interval_animation").slider({
122                                 min: 0.5,
123                                 max: 10,
124                                 step: 0.5,
125                                 value: 4
126                         });
127
128                         // jquery:tooltip
129                         // http://www.alessioatzeni.com/blog/simple-tooltip-with-jquery-only-text/
130                         // Tooltip only Text
131                         j('.masterTooltip').hover(function(){
132                                         // Hover over code
133                                         var title = j('#interval_animation').attr('title');
134                                         j('#interval_animation').data('tipText', title).removeAttr('title');
135                                         j('<p class="tooltip"></p>')
136                                         .text(title)
137                                         .appendTo('body')
138                                         .fadeIn('slow');
139                         }, function() {
140                                         // Hover out code
141                                         j('#interval_animation').attr('title', j('#interval_animation').data('tipText'));
142                                         j('.tooltip').remove();
143                         }).mousemove(function(e) {
144                                         var mousex = e.pageX + 20; //Get X coordinates
145                                         var mousey = e.pageY + 10; //Get Y coordinates
146                                         j('.tooltip')
147                                         .css({ top: mousey, left: mousex })
148                         });
149         },
150       
151
152         /* Constructor */
153
154         this.initialize();
155
156     } // function PresView
157
158 })( jQuery );
159
160