2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.ux.TaskBar
\r
11 * @extends Ext.util.Observable
\r
13 Ext.ux.TaskBar = function(app){
\r
18 Ext.extend(Ext.ux.TaskBar, Ext.util.Observable, {
\r
20 this.startMenu = new Ext.ux.StartMenu(Ext.apply({
\r
24 title: 'Jack Slocum',
\r
26 }, this.app.startConfig));
\r
28 this.startBtn = new Ext.Button({
\r
30 id: 'ux-startbutton',
\r
32 menu: this.startMenu,
\r
34 renderTo: 'ux-taskbar-start',
\r
35 clickEvent:'mousedown',
\r
36 template: new Ext.Template(
\r
37 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
\r
38 '<td class="ux-startbutton-left"><i> </i></td><td class="ux-startbutton-center"><em unselectable="on"><button class="x-btn-text" type="{1}" style="height:30px;">{0}</button></em></td><td class="ux-startbutton-right"><i> </i></td>',
\r
39 "</tr></tbody></table>")
\r
42 var width = Ext.get('ux-startbutton').getWidth()+10;
\r
44 var sbBox = new Ext.BoxComponent({
\r
45 el: 'ux-taskbar-start',
\r
53 this.tbPanel = new Ext.ux.TaskButtonsPanel({
\r
54 el: 'ux-taskbuttons-panel',
\r
55 id: 'TaskBarButtons',
\r
59 var container = new Ext.ux.TaskBarContainer({
\r
62 items: [sbBox,this.tbPanel]
\r
68 addTaskButton : function(win){
\r
69 return this.tbPanel.addButton(win, 'ux-taskbuttons-panel');
\r
72 removeTaskButton : function(btn){
\r
73 this.tbPanel.removeButton(btn);
\r
76 setActiveButton : function(btn){
\r
77 this.tbPanel.setActiveButton(btn);
\r
84 * @class Ext.ux.TaskBarContainer
\r
85 * @extends Ext.Container
\r
87 Ext.ux.TaskBarContainer = Ext.extend(Ext.Container, {
\r
88 initComponent : function() {
\r
89 Ext.ux.TaskBarContainer.superclass.initComponent.call(this);
\r
91 this.el = Ext.get(this.el) || Ext.getBody();
\r
92 this.el.setHeight = Ext.emptyFn;
\r
93 this.el.setWidth = Ext.emptyFn;
\r
94 this.el.setSize = Ext.emptyFn;
\r
100 this.el.dom.scroll = 'no';
\r
101 this.allowDomMove = false;
\r
102 this.autoWidth = true;
\r
103 this.autoHeight = true;
\r
104 Ext.EventManager.onWindowResize(this.fireResize, this);
\r
105 this.renderTo = this.el;
\r
108 fireResize : function(w, h){
\r
109 this.fireEvent('resize', this, w, h, w, h);
\r
116 * @class Ext.ux.TaskButtonsPanel
\r
117 * @extends Ext.BoxComponent
\r
119 Ext.ux.TaskButtonsPanel = Ext.extend(Ext.BoxComponent, {
\r
120 activeButton: null,
\r
121 enableScroll: true,
\r
122 scrollIncrement: 0,
\r
123 scrollRepeatInterval: 400,
\r
124 scrollDuration: .35,
\r
126 resizeButtons: true,
\r
128 minButtonWidth: 118,
\r
130 buttonWidthSet: false,
\r
132 initComponent : function() {
\r
133 Ext.ux.TaskButtonsPanel.superclass.initComponent.call(this);
\r
134 this.on('resize', this.delegateUpdates);
\r
137 this.stripWrap = Ext.get(this.el).createChild({
\r
138 cls: 'ux-taskbuttons-strip-wrap',
\r
140 tag:'ul', cls:'ux-taskbuttons-strip'
\r
143 this.stripSpacer = Ext.get(this.el).createChild({
\r
144 cls:'ux-taskbuttons-strip-spacer'
\r
146 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
\r
148 this.edge = this.strip.createChild({
\r
150 cls:'ux-taskbuttons-edge'
\r
152 this.strip.createChild({
\r
157 addButton : function(win){
\r
158 var li = this.strip.createChild({tag:'li'}, this.edge); // insert before the edge
\r
159 var btn = new Ext.ux.TaskBar.TaskButton(win, li);
\r
161 this.items.push(btn);
\r
163 if(!this.buttonWidthSet){
\r
164 this.lastButtonWidth = btn.container.getWidth();
\r
167 this.setActiveButton(btn);
\r
171 removeButton : function(btn){
\r
172 var li = document.getElementById(btn.container.id);
\r
174 li.parentNode.removeChild(li);
\r
177 for(var i = 0, len = this.items.length; i < len; i++) {
\r
178 if(this.items[i] != btn){
\r
179 s.push(this.items[i]);
\r
184 this.delegateUpdates();
\r
187 setActiveButton : function(btn){
\r
188 this.activeButton = btn;
\r
189 this.delegateUpdates();
\r
192 delegateUpdates : function(){
\r
193 /*if(this.suspendUpdates){
\r
196 if(this.resizeButtons && this.rendered){
\r
199 if(this.enableScroll && this.rendered){
\r
204 autoSize : function(){
\r
205 var count = this.items.length;
\r
206 var ow = this.el.dom.offsetWidth;
\r
207 var aw = this.el.dom.clientWidth;
\r
209 if(!this.resizeButtons || count < 1 || !aw){ // !aw for display:none
\r
213 var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.buttonMargin, this.buttonWidth), this.minButtonWidth); // -4 for float errors in IE
\r
214 var btns = this.stripWrap.dom.getElementsByTagName('button');
\r
216 this.lastButtonWidth = Ext.get(btns[0].id).findParent('li').offsetWidth;
\r
218 for(var i = 0, len = btns.length; i < len; i++) {
\r
221 var tw = Ext.get(btns[i].id).findParent('li').offsetWidth;
\r
222 var iw = btn.offsetWidth;
\r
224 btn.style.width = (each - (tw-iw)) + 'px';
\r
228 autoScroll : function(){
\r
229 var count = this.items.length;
\r
230 var ow = this.el.dom.offsetWidth;
\r
231 var tw = this.el.dom.clientWidth;
\r
233 var wrap = this.stripWrap;
\r
234 var cw = wrap.dom.offsetWidth;
\r
235 var pos = this.getScrollPos();
\r
236 var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
\r
238 if(!this.enableScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues
\r
242 wrap.setWidth(tw); // moved to here because of problem in Safari
\r
245 wrap.dom.scrollLeft = 0;
\r
246 //wrap.setWidth(tw); moved from here because of problem in Safari
\r
247 if(this.scrolling){
\r
248 this.scrolling = false;
\r
249 this.el.removeClass('x-taskbuttons-scrolling');
\r
250 this.scrollLeft.hide();
\r
251 this.scrollRight.hide();
\r
254 if(!this.scrolling){
\r
255 this.el.addClass('x-taskbuttons-scrolling');
\r
257 tw -= wrap.getMargins('lr');
\r
258 wrap.setWidth(tw > 20 ? tw : 20);
\r
259 if(!this.scrolling){
\r
260 if(!this.scrollLeft){
\r
261 this.createScrollers();
\r
263 this.scrollLeft.show();
\r
264 this.scrollRight.show();
\r
267 this.scrolling = true;
\r
268 if(pos > (l-tw)){ // ensure it stays within bounds
\r
269 wrap.dom.scrollLeft = l-tw;
\r
270 }else{ // otherwise, make sure the active button is still visible
\r
271 this.scrollToButton(this.activeButton, true); // true to animate
\r
273 this.updateScrollButtons();
\r
277 createScrollers : function(){
\r
278 var h = this.el.dom.offsetHeight; //var h = this.stripWrap.dom.offsetHeight;
\r
281 var sl = this.el.insertFirst({
\r
282 cls:'ux-taskbuttons-scroller-left'
\r
285 sl.addClassOnOver('ux-taskbuttons-scroller-left-over');
\r
286 this.leftRepeater = new Ext.util.ClickRepeater(sl, {
\r
287 interval : this.scrollRepeatInterval,
\r
288 handler: this.onScrollLeft,
\r
291 this.scrollLeft = sl;
\r
294 var sr = this.el.insertFirst({
\r
295 cls:'ux-taskbuttons-scroller-right'
\r
298 sr.addClassOnOver('ux-taskbuttons-scroller-right-over');
\r
299 this.rightRepeater = new Ext.util.ClickRepeater(sr, {
\r
300 interval : this.scrollRepeatInterval,
\r
301 handler: this.onScrollRight,
\r
304 this.scrollRight = sr;
\r
307 getScrollWidth : function(){
\r
308 return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
\r
311 getScrollPos : function(){
\r
312 return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
\r
315 getScrollArea : function(){
\r
316 return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
\r
319 getScrollAnim : function(){
\r
321 duration: this.scrollDuration,
\r
322 callback: this.updateScrollButtons,
\r
327 getScrollIncrement : function(){
\r
328 return (this.scrollIncrement || this.lastButtonWidth+2);
\r
331 /* getBtnEl : function(item){
\r
332 return document.getElementById(item.id);
\r
335 scrollToButton : function(item, animate){
\r
336 item = item.el.dom.parentNode; // li
\r
337 if(!item){ return; }
\r
338 var el = item; //this.getBtnEl(item);
\r
339 var pos = this.getScrollPos(), area = this.getScrollArea();
\r
340 var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;
\r
341 var right = left + el.offsetWidth;
\r
343 this.scrollTo(left, animate);
\r
344 }else if(right > (pos + area)){
\r
345 this.scrollTo(right - area, animate);
\r
349 scrollTo : function(pos, animate){
\r
350 this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
\r
352 this.updateScrollButtons();
\r
356 onScrollRight : function(){
\r
357 var sw = this.getScrollWidth()-this.getScrollArea();
\r
358 var pos = this.getScrollPos();
\r
359 var s = Math.min(sw, pos + this.getScrollIncrement());
\r
361 this.scrollTo(s, this.animScroll);
\r
365 onScrollLeft : function(){
\r
366 var pos = this.getScrollPos();
\r
367 var s = Math.max(0, pos - this.getScrollIncrement());
\r
369 this.scrollTo(s, this.animScroll);
\r
373 updateScrollButtons : function(){
\r
374 var pos = this.getScrollPos();
\r
375 this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-left-disabled');
\r
376 this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-right-disabled');
\r
383 * @class Ext.ux.TaskBar.TaskButton
\r
384 * @extends Ext.Button
\r
386 Ext.ux.TaskBar.TaskButton = function(win, el){
\r
388 Ext.ux.TaskBar.TaskButton.superclass.constructor.call(this, {
\r
389 iconCls: win.iconCls,
\r
390 text: Ext.util.Format.ellipsis(win.title, 12),
\r
392 handler : function(){
\r
393 if(win.minimized || win.hidden){
\r
395 }else if(win == win.manager.getActive()){
\r
401 clickEvent:'mousedown',
\r
402 template: new Ext.Template(
\r
403 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
\r
404 '<td class="ux-taskbutton-left"><i> </i></td><td class="ux-taskbutton-center"><em unselectable="on"><button class="x-btn-text" type="{1}" style="height:28px;">{0}</button></em></td><td class="ux-taskbutton-right"><i> </i></td>',
\r
405 "</tr></tbody></table>")
\r
409 Ext.extend(Ext.ux.TaskBar.TaskButton, Ext.Button, {
\r
410 onRender : function(){
\r
411 Ext.ux.TaskBar.TaskButton.superclass.onRender.apply(this, arguments);
\r
413 this.cmenu = new Ext.menu.Menu({
\r
416 handler: function(){
\r
417 if(!this.win.isVisible()){
\r
420 this.win.restore();
\r
426 handler: this.win.minimize,
\r
430 handler: this.win.maximize,
\r
434 handler: this.closeWin.createDelegate(this, this.win, true),
\r
439 this.cmenu.on('beforeshow', function(){
\r
440 var items = this.cmenu.items.items;
\r
442 items[0].setDisabled(w.maximized !== true && w.hidden !== true);
\r
443 items[1].setDisabled(w.minimized === true);
\r
444 items[2].setDisabled(w.maximized === true || w.hidden === true);
\r
447 this.el.on('contextmenu', function(e){
\r
449 if(!this.cmenu.el){
\r
450 this.cmenu.render();
\r
452 var xy = e.getXY();
\r
453 xy[1] -= this.cmenu.el.getHeight();
\r
454 this.cmenu.showAt(xy);
\r
458 closeWin : function(cMenu, e, win){
\r
459 if(!win.isVisible()){
\r