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 | |
---|
8 | var 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 : "tab_class"; |
---|
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 | this.divContainer.addClass( this.className ); |
---|
24 | if( this.title ) |
---|
25 | this.divContainer.attr( {id:this.id, title:this.title, name:this.numTab} ); |
---|
26 | else |
---|
27 | this.divContainer.attr( {id:this.id, name:this.numTab} ); |
---|
28 | |
---|
29 | this.divContainer.html( this.value ); |
---|
30 | |
---|
31 | if( this.parent ) |
---|
32 | this.parent.append( this.divContainer ); |
---|
33 | |
---|
34 | // Define button events |
---|
35 | if( this.contextToSave ) |
---|
36 | this.divContainer.bind( 'click', [this, this.contextToSave], this.onClickEvent ); |
---|
37 | else |
---|
38 | this.divContainer.bind( 'click', this, this.onClickEvent ); |
---|
39 | |
---|
40 | |
---|
41 | }, |
---|
42 | |
---|
43 | // Getter / Setter ******************************************************** |
---|
44 | getContainer: function() |
---|
45 | { |
---|
46 | return this.divContainer; |
---|
47 | }, |
---|
48 | |
---|
49 | setValue : function( value ) |
---|
50 | { |
---|
51 | this.value = value; |
---|
52 | this.divText.html( this.value ); |
---|
53 | }, |
---|
54 | |
---|
55 | setCallbackOnClick : function( value ) |
---|
56 | { |
---|
57 | this.callbackOnClick = value; |
---|
58 | }, |
---|
59 | |
---|
60 | // Actions ******************************************************** |
---|
61 | active : function() |
---|
62 | { |
---|
63 | this.divContainer.addClass( "activated" ); |
---|
64 | }, |
---|
65 | |
---|
66 | inactive : function() |
---|
67 | { |
---|
68 | this.divContainer.removeClass( "activated" ); |
---|
69 | }, |
---|
70 | |
---|
71 | remove : function() |
---|
72 | { |
---|
73 | this.divContainer.remove(); |
---|
74 | |
---|
75 | }, |
---|
76 | |
---|
77 | // Events ******************************************************** |
---|
78 | onClickEvent : function( event ) |
---|
79 | { |
---|
80 | var clickedTab = event.data; |
---|
81 | |
---|
82 | //tabs |
---|
83 | $( "." + this.className ).removeClass( "activated" ); |
---|
84 | clickedTab.divContainer.addClass( "activated" ); |
---|
85 | |
---|
86 | if( (undefined == event.detail || 1 == event.detail) && clickedTab.callbackOnClick ) |
---|
87 | clickedTab.callbackOnClick( event ); |
---|
88 | } |
---|
89 | |
---|
90 | } ); |
---|