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