Roo/bootstrap/NavProgressItem.js
[roojs1] / Roo / bootstrap / NavProgressItem.js
1 /*
2  * - LGPL
3  *
4  * Nav Progress Item
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.NavProgressItem
10  * @extends Roo.bootstrap.Component
11  * Bootstrap NavProgressItem class
12  * @cfg {Boolean} active (true|false) Is item active default false
13  * @cfg {Boolean} disabled (true|false) Is item active default false
14  * @cfg {String} html
15  * @cfg {String} position (top|bottom) text position default bottom
16  * @cfg {String} icon show icon instead of number
17  * @cfg {Boolean} forceIcon (true|false) force to show icon..if set to false, Roo.isTouch showing icon, otherwish number
18  * 
19  * @constructor
20  * Create a new NavProgressItem
21  * @param {Object} config The config object
22  */
23 Roo.bootstrap.NavProgressItem = function(config){
24     Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
25     this.addEvents({
26         // raw events
27         /**
28          * @event click
29          * The raw click event for the entire grid.
30          * @param {Roo.bootstrap.NavProgressItem} this
31          * @param {Roo.EventObject} e
32          */
33         "click" : true,
34          /**
35             * @event changed
36             * Fires when the active item active state changes
37             * @param {Roo.bootstrap.NavProgressItem} this
38             * @param {boolean} state the new state
39              
40          */
41         'changed': true
42     });
43    
44 };
45
46 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component,  {
47     
48     active : false,
49     disabled : false,
50     html : '',
51     position : 'bottom',
52     icon : false,
53     
54     getAutoCreate : function()
55     {
56          
57         var cfg = {
58             tag: 'li',
59             cls: 'roo-navigation-bar-item',
60             cn : [
61                 {
62                     tag : 'i',
63                     cls : 'roo-navigation-bar-item-icon ' + (this.icon ? this.icon : '')
64                 },
65                 {
66                     tag : 'span',
67                     cls : 'roo-navigation-bar-item-text ' + this.position,
68                     html : this.html
69                 }
70             ]
71         }
72         
73         if(this.active){
74             cfg.cls += ' active';
75         }
76         if(this.disabled){
77             cfg.cls += ' disabled';
78         }
79         
80         return cfg;
81     },
82     
83     initEvents: function() 
84     {
85         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
86         this.textEl = this.el.select('.roo-navigation-bar-item-text', true).first();
87         
88         if(Roo.isTouch){
89             this.textEl.hide();
90         }
91         
92         this.iconEl.on('click', this.onClick, this);
93         
94     },
95     
96     onClick : function(e)
97     {
98         e.preventDefault();
99         
100         Roo.log(this);
101     }
102     
103     
104 //    
105 //    onClick : function(e)
106 //    {
107 //        if(
108 //                this.preventDefault || 
109 //                this.href == '#' 
110 //        ){
111 //            
112 //            e.preventDefault();
113 //        }
114 //        
115 //        if (this.disabled) {
116 //            return;
117 //        }
118 //        
119 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
120 //        if (tg && tg.transition) {
121 //            Roo.log("waiting for the transitionend");
122 //            return;
123 //        }
124 //        
125 //        
126 //        
127 //        //Roo.log("fire event clicked");
128 //        if(this.fireEvent('click', this, e) === false){
129 //            return;
130 //        };
131 //        
132 //        if(this.tagtype == 'span'){
133 //            return;
134 //        }
135 //        
136 //        //Roo.log(this.href);
137 //        var ael = this.el.select('a',true).first();
138 //        //Roo.log(ael);
139 //        
140 //        if(ael && this.animateRef && this.href.indexOf('#') > -1){
141 //            //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
142 //            if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
143 //                return; // ignore... - it's a 'hash' to another page.
144 //            }
145 //            
146 //            e.preventDefault();
147 //            this.scrollToElement(e);
148 //        }
149 //        
150 //        
151 //        var p =  this.parent();
152 //   
153 //        if (['tabs','pills'].indexOf(p.type)!==-1) {
154 //            if (typeof(p.setActiveItem) !== 'undefined') {
155 //                p.setActiveItem(this);
156 //            }
157 //        }
158 //        
159 //        // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
160 //        if (p.parentType == 'NavHeaderbar' && !this.menu) {
161 //            // remove the collapsed menu expand...
162 //            p.parent().el.select('.navbar-collapse',true).removeClass('in');  
163 //        }
164 //    },
165 //    
166 //    isActive: function () {
167 //        return this.active
168 //    },
169 //    setActive : function(state, fire, is_was_active)
170 //    {
171 //        if (this.active && !state && this.navId) {
172 //            this.was_active = true;
173 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
174 //            if (nv) {
175 //                nv.clearWasActive(this);
176 //            }
177 //            
178 //        }
179 //        this.active = state;
180 //        
181 //        if (!state ) {
182 //            this.el.removeClass('active');
183 //        } else if (!this.el.hasClass('active')) {
184 //            this.el.addClass('active');
185 //        }
186 //        if (fire) {
187 //            this.fireEvent('changed', this, state);
188 //        }
189 //        
190 //        // show a panel if it's registered and related..
191 //        
192 //        if (!this.navId || !this.tabId || !state || is_was_active) {
193 //            return;
194 //        }
195 //        
196 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
197 //        if (!tg) {
198 //            return;
199 //        }
200 //        var pan = tg.getPanelByName(this.tabId);
201 //        if (!pan) {
202 //            return;
203 //        }
204 //        // if we can not flip to new panel - go back to old nav highlight..
205 //        if (false == tg.showPanel(pan)) {
206 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
207 //            if (nv) {
208 //                var onav = nv.getWasActive();
209 //                if (onav) {
210 //                    onav.setActive(true, false, true);
211 //                }
212 //            }
213 //            
214 //        }
215 //        
216 //        
217 //      
218 //    },
219 //     // this should not be here...
220 //    setDisabled : function(state)
221 //    {
222 //        this.disabled = state;
223 //        if (!state ) {
224 //            this.el.removeClass('disabled');
225 //        } else if (!this.el.hasClass('disabled')) {
226 //            this.el.addClass('disabled');
227 //        }
228 //        
229 //    },
230 //    
231 //    /**
232 //     * Fetch the element to display the tooltip on.
233 //     * @return {Roo.Element} defaults to this.el
234 //     */
235 //    tooltipEl : function()
236 //    {
237 //        return this.el.select('' + this.tagtype + '', true).first();
238 //    },
239 //    
240 //    scrollToElement : function(e)
241 //    {
242 //        var c = document.body;
243 //        
244 //        /*
245 //         * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
246 //         */
247 //        if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
248 //            c = document.documentElement;
249 //        }
250 //        
251 //        var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
252 //        
253 //        if(!target){
254 //            return;
255 //        }
256 //
257 //        var o = target.calcOffsetsTo(c);
258 //        
259 //        var options = {
260 //            target : target,
261 //            value : o[1]
262 //        }
263 //        
264 //        this.fireEvent('scrollto', this, options, e);
265 //        
266 //        Roo.get(c).scrollTo('top', options.value, true);
267 //        
268 //        return;
269 //    }
270 });
271  
272
273