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) true to force 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     forceIcon : false,
54     
55     getAutoCreate : function()
56     {
57         var iconCls = 'roo-navigation-bar-item-icon';
58         
59         if((this.forceIcon && this.icon) || !this.forceIcon && Roo.isTouch){
60             iconCls += ' ' + this.icon;
61         }
62         
63         var cfg = {
64             tag: 'li',
65             cls: 'roo-navigation-bar-item',
66             cn : [
67                 {
68                     tag : 'i',
69                     cls : iconCls
70                 },
71                 {
72                     tag : 'span',
73                     cls : 'roo-navigation-bar-item-text ' + this.position,
74                     html : this.html
75                 }
76             ]
77         }
78         
79         if(this.active){
80             cfg.cls += ' active';
81         }
82         if(this.disabled){
83             cfg.cls += ' disabled';
84         }
85         
86         return cfg;
87     },
88     
89     initEvents: function() 
90     {
91         this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
92         this.textEl = this.el.select('.roo-navigation-bar-item-text', true).first();
93         
94         if(Roo.isTouch){
95             this.textEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
96         }
97         
98         this.iconEl.on('click', this.onClick, this);
99         
100     },
101     
102     onClick : function(e)
103     {
104         e.preventDefault();
105         
106         if(this.disabled){
107             return;
108         }
109         
110         this.fireEvent('click', this, e);
111     },
112     
113     
114     
115     
116 //    
117 //    onClick : function(e)
118 //    {
119 //        if(
120 //                this.preventDefault || 
121 //                this.href == '#' 
122 //        ){
123 //            
124 //            e.preventDefault();
125 //        }
126 //        
127 //        if (this.disabled) {
128 //            return;
129 //        }
130 //        
131 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
132 //        if (tg && tg.transition) {
133 //            Roo.log("waiting for the transitionend");
134 //            return;
135 //        }
136 //        
137 //        
138 //        
139 //        //Roo.log("fire event clicked");
140 //        if(this.fireEvent('click', this, e) === false){
141 //            return;
142 //        };
143 //        
144 //        if(this.tagtype == 'span'){
145 //            return;
146 //        }
147 //        
148 //        //Roo.log(this.href);
149 //        var ael = this.el.select('a',true).first();
150 //        //Roo.log(ael);
151 //        
152 //        if(ael && this.animateRef && this.href.indexOf('#') > -1){
153 //            //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
154 //            if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
155 //                return; // ignore... - it's a 'hash' to another page.
156 //            }
157 //            
158 //            e.preventDefault();
159 //            this.scrollToElement(e);
160 //        }
161 //        
162 //        
163 //        var p =  this.parent();
164 //   
165 //        if (['tabs','pills'].indexOf(p.type)!==-1) {
166 //            if (typeof(p.setActiveItem) !== 'undefined') {
167 //                p.setActiveItem(this);
168 //            }
169 //        }
170 //        
171 //        // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
172 //        if (p.parentType == 'NavHeaderbar' && !this.menu) {
173 //            // remove the collapsed menu expand...
174 //            p.parent().el.select('.navbar-collapse',true).removeClass('in');  
175 //        }
176 //    },
177 //    
178 //    isActive: function () {
179 //        return this.active
180 //    },
181 //    setActive : function(state, fire, is_was_active)
182 //    {
183 //        if (this.active && !state && this.navId) {
184 //            this.was_active = true;
185 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
186 //            if (nv) {
187 //                nv.clearWasActive(this);
188 //            }
189 //            
190 //        }
191 //        this.active = state;
192 //        
193 //        if (!state ) {
194 //            this.el.removeClass('active');
195 //        } else if (!this.el.hasClass('active')) {
196 //            this.el.addClass('active');
197 //        }
198 //        if (fire) {
199 //            this.fireEvent('changed', this, state);
200 //        }
201 //        
202 //        // show a panel if it's registered and related..
203 //        
204 //        if (!this.navId || !this.tabId || !state || is_was_active) {
205 //            return;
206 //        }
207 //        
208 //        var tg = Roo.bootstrap.TabGroup.get(this.navId);
209 //        if (!tg) {
210 //            return;
211 //        }
212 //        var pan = tg.getPanelByName(this.tabId);
213 //        if (!pan) {
214 //            return;
215 //        }
216 //        // if we can not flip to new panel - go back to old nav highlight..
217 //        if (false == tg.showPanel(pan)) {
218 //            var nv = Roo.bootstrap.NavGroup.get(this.navId);
219 //            if (nv) {
220 //                var onav = nv.getWasActive();
221 //                if (onav) {
222 //                    onav.setActive(true, false, true);
223 //                }
224 //            }
225 //            
226 //        }
227 //        
228 //        
229 //      
230 //    },
231 //     // this should not be here...
232 //    setDisabled : function(state)
233 //    {
234 //        this.disabled = state;
235 //        if (!state ) {
236 //            this.el.removeClass('disabled');
237 //        } else if (!this.el.hasClass('disabled')) {
238 //            this.el.addClass('disabled');
239 //        }
240 //        
241 //    },
242 //    
243 //    /**
244 //     * Fetch the element to display the tooltip on.
245 //     * @return {Roo.Element} defaults to this.el
246 //     */
247 //    tooltipEl : function()
248 //    {
249 //        return this.el.select('' + this.tagtype + '', true).first();
250 //    },
251 //    
252 //    scrollToElement : function(e)
253 //    {
254 //        var c = document.body;
255 //        
256 //        /*
257 //         * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
258 //         */
259 //        if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
260 //            c = document.documentElement;
261 //        }
262 //        
263 //        var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
264 //        
265 //        if(!target){
266 //            return;
267 //        }
268 //
269 //        var o = target.calcOffsetsTo(c);
270 //        
271 //        var options = {
272 //            target : target,
273 //            value : o[1]
274 //        }
275 //        
276 //        this.fireEvent('scrollto', this, options, e);
277 //        
278 //        Roo.get(c).scrollTo('top', options.value, true);
279 //        
280 //        return;
281 //    }
282 });
283  
284
285