source: ether_iasi/trunk/web/resources/js/classesForJQuery/Tab.js @ 710

Last change on this file since 710 was 710, checked in by vmipsl, 12 years ago
File size: 3.1 KB
Line 
1// dom parent: in which dom element to draw the button
2// int id: id of the dom element
3// func onclick: callback function when button clicked
4// str className : className of the general button
5// str classNameText : className for the button's text
6//********************************************************
7
8var Tab = Class.create( {
9            initialize: function( param )
10            {
11                // Init
12                this.numTab = param.numTab ? param.numTab : 1;
13                this.id = param.id ? param.id : "";
14                this.parent = param.parent ? param.parent : false;
15                this.value = param.value ? param.value : "";
16                this.title = param.title ? param.title : false;
17                this.className = param.className ? param.className : false;
18                this.callbackOnClick = param.onClick ? param.onClick : false;
19                this.contextToSave = param.contextToSave ? param.contextToSave : false;
20
21                // Create tab elements
22                this.divContainer = $( document.createElement( "div" ) );
23                if( this.className )
24                    this.divContainer.addClass( this.className );
25                if( this.title )
26                    this.divContainer.attr( {id:this.id, title:this.title, name:this.numTab} );
27                else
28                    this.divContainer.attr( {id:this.id, name:this.numTab} );
29
30                this.divContainer.html( this.value );
31
32                if( this.parent )
33                    this.parent.append( this.divContainer );
34
35                // Define button events
36                if( this.contextToSave )
37                    this.divContainer.bind( 'click', [this, this.contextToSave], this.onClickEvent );
38                else
39                    this.divContainer.bind( 'click', this, this.onClickEvent );
40
41
42            },
43
44            // Getter / Setter ********************************************************
45            getContainer: function()
46            {
47                return this.divContainer;
48            },
49
50            setValue : function( value )
51            {
52                this.value = value;
53                this.divText.html( this.value );
54            },
55
56            setCallbackOnClick : function( value )
57            {
58                this.callbackOnClick = value;
59            },
60
61            // Actions ********************************************************
62            active : function()
63            {
64                this.divContainer.addClass( "activated" );
65            },
66
67            inactive : function()
68            {
69                this.divContainer.removeClass( "activated" );
70            },
71
72            remove : function()
73            {
74                this.divContainer.remove();
75
76            },
77
78            // Events ********************************************************
79            onClickEvent : function( event )
80            {
81                var clickedTab = event.data;
82                if( (undefined == event.detail || 1 == event.detail) && clickedTab.callbackOnClick )
83                    clickedTab.callbackOnClick( event );
84            }
85
86        } );
Note: See TracBrowser for help on using the repository browser.