3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.ux.TaskBar"></div>/**
\r
9 * @class Ext.ux.TaskBar
\r
10 * @extends Ext.util.Observable
\r
12 Ext.ux.TaskBar = function(app){
\r
17 Ext.extend(Ext.ux.TaskBar, Ext.util.Observable, {
\r
19 this.startMenu = new Ext.ux.StartMenu(Ext.apply({
\r
23 title: 'Jack Slocum',
\r
25 }, this.app.startConfig));
\r
27 this.startBtn = new Ext.Button({
\r
29 id: 'ux-startbutton',
\r
31 menu: this.startMenu,
\r
33 renderTo: 'ux-taskbar-start',
\r
34 clickEvent: 'mousedown',
\r
35 template: new Ext.Template(
\r
36 '<table cellspacing="0" class="x-btn {3}"><tbody><tr>',
\r
37 '<td class="ux-startbutton-left"><i> </i></td>',
\r
38 '<td class="ux-startbutton-center"><em class="{5} unselectable="on">',
\r
39 '<button class="x-btn-text {2}" type="{1}" style="height:30px;">{0}</button>',
\r
41 '<td class="ux-startbutton-right"><i> </i></td>',
\r
42 "</tr></tbody></table>")
\r
45 var width = this.startBtn.getEl().getWidth()+10;
\r
47 var sbBox = new Ext.BoxComponent({
\r
48 el: 'ux-taskbar-start',
\r
56 this.tbPanel = new Ext.ux.TaskButtonsPanel({
\r
57 el: 'ux-taskbuttons-panel',
\r
58 id: 'TaskBarButtons',
\r
62 var container = new Ext.ux.TaskBarContainer({
\r
65 items: [sbBox,this.tbPanel]
\r
71 addTaskButton : function(win){
\r
72 return this.tbPanel.addButton(win, 'ux-taskbuttons-panel');
\r
75 removeTaskButton : function(btn){
\r
76 this.tbPanel.removeButton(btn);
\r
79 setActiveButton : function(btn){
\r
80 this.tbPanel.setActiveButton(btn);
\r
86 <div id="cls-Ext.ux.TaskBarContainer"></div>/**
\r
87 * @class Ext.ux.TaskBarContainer
\r
88 * @extends Ext.Container
\r
90 Ext.ux.TaskBarContainer = Ext.extend(Ext.Container, {
\r
91 initComponent : function() {
\r
92 Ext.ux.TaskBarContainer.superclass.initComponent.call(this);
\r
94 this.el = Ext.get(this.el) || Ext.getBody();
\r
95 this.el.setHeight = Ext.emptyFn;
\r
96 this.el.setWidth = Ext.emptyFn;
\r
97 this.el.setSize = Ext.emptyFn;
\r
103 this.el.dom.scroll = 'no';
\r
104 this.allowDomMove = false;
\r
105 this.autoWidth = true;
\r
106 this.autoHeight = true;
\r
107 Ext.EventManager.onWindowResize(this.fireResize, this);
\r
108 this.renderTo = this.el;
\r
111 fireResize : function(w, h){
\r
112 this.fireEvent('resize', this, w, h, w, h);
\r
118 <div id="cls-Ext.ux.TaskButtonsPanel"></div>/**
\r
119 * @class Ext.ux.TaskButtonsPanel
\r
120 * @extends Ext.BoxComponent
\r
122 Ext.ux.TaskButtonsPanel = Ext.extend(Ext.BoxComponent, {
\r
123 activeButton: null,
\r
124 enableScroll: true,
\r
125 scrollIncrement: 0,
\r
126 scrollRepeatInterval: 400,
\r
127 scrollDuration: .35,
\r
129 resizeButtons: true,
\r
131 minButtonWidth: 118,
\r
133 buttonWidthSet: false,
\r
135 initComponent : function() {
\r
136 Ext.ux.TaskButtonsPanel.superclass.initComponent.call(this);
\r
137 this.on('resize', this.delegateUpdates);
\r
140 this.stripWrap = Ext.get(this.el).createChild({
\r
141 cls: 'ux-taskbuttons-strip-wrap',
\r
143 tag:'ul', cls:'ux-taskbuttons-strip'
\r
146 this.stripSpacer = Ext.get(this.el).createChild({
\r
147 cls:'ux-taskbuttons-strip-spacer'
\r
149 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
\r
151 this.edge = this.strip.createChild({
\r
153 cls:'ux-taskbuttons-edge'
\r
155 this.strip.createChild({
\r
160 addButton : function(win){
\r
161 var li = this.strip.createChild({tag:'li'}, this.edge); // insert before the edge
\r
162 var btn = new Ext.ux.TaskBar.TaskButton(win, li);
\r
164 this.items.push(btn);
\r
166 if(!this.buttonWidthSet){
\r
167 this.lastButtonWidth = btn.container.getWidth();
\r
170 this.setActiveButton(btn);
\r
174 removeButton : function(btn){
\r
175 var li = document.getElementById(btn.container.id);
\r
177 li.parentNode.removeChild(li);
\r
180 for(var i = 0, len = this.items.length; i < len; i++) {
\r
181 if(this.items[i] != btn){
\r
182 s.push(this.items[i]);
\r
187 this.delegateUpdates();
\r
190 setActiveButton : function(btn){
\r
191 this.activeButton = btn;
\r
192 this.delegateUpdates();
\r
195 delegateUpdates : function(){
\r
196 /*if(this.suspendUpdates){
\r
199 if(this.resizeButtons && this.rendered){
\r
202 if(this.enableScroll && this.rendered){
\r
207 autoSize : function(){
\r
208 var count = this.items.length;
\r
209 var ow = this.el.dom.offsetWidth;
\r
210 var aw = this.el.dom.clientWidth;
\r
212 if(!this.resizeButtons || count < 1 || !aw){ // !aw for display:none
\r
216 var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.buttonMargin, this.buttonWidth), this.minButtonWidth); // -4 for float errors in IE
\r
217 var btns = this.stripWrap.dom.getElementsByTagName('button');
\r
219 this.lastButtonWidth = Ext.get(btns[0].id).findParent('li').offsetWidth;
\r
221 for(var i = 0, len = btns.length; i < len; i++) {
\r
224 var tw = Ext.get(btns[i].id).findParent('li').offsetWidth;
\r
225 var iw = btn.offsetWidth;
\r
227 btn.style.width = (each - (tw-iw)) + 'px';
\r
231 autoScroll : function(){
\r
232 var count = this.items.length;
\r
233 var ow = this.el.dom.offsetWidth;
\r
234 var tw = this.el.dom.clientWidth;
\r
236 var wrap = this.stripWrap;
\r
237 var cw = wrap.dom.offsetWidth;
\r
238 var pos = this.getScrollPos();
\r
239 var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
\r
241 if(!this.enableScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues
\r
245 wrap.setWidth(tw); // moved to here because of problem in Safari
\r
248 wrap.dom.scrollLeft = 0;
\r
249 //wrap.setWidth(tw); moved from here because of problem in Safari
\r
250 if(this.scrolling){
\r
251 this.scrolling = false;
\r
252 this.el.removeClass('x-taskbuttons-scrolling');
\r
253 this.scrollLeft.hide();
\r
254 this.scrollRight.hide();
\r
257 if(!this.scrolling){
\r
258 this.el.addClass('x-taskbuttons-scrolling');
\r
260 tw -= wrap.getMargins('lr');
\r
261 wrap.setWidth(tw > 20 ? tw : 20);
\r
262 if(!this.scrolling){
\r
263 if(!this.scrollLeft){
\r
264 this.createScrollers();
\r
266 this.scrollLeft.show();
\r
267 this.scrollRight.show();
\r
270 this.scrolling = true;
\r
271 if(pos > (l-tw)){ // ensure it stays within bounds
\r
272 wrap.dom.scrollLeft = l-tw;
\r
273 }else{ // otherwise, make sure the active button is still visible
\r
274 this.scrollToButton(this.activeButton, true); // true to animate
\r
276 this.updateScrollButtons();
\r
280 createScrollers : function(){
\r
281 var h = this.el.dom.offsetHeight; //var h = this.stripWrap.dom.offsetHeight;
\r
284 var sl = this.el.insertFirst({
\r
285 cls:'ux-taskbuttons-scroller-left'
\r
288 sl.addClassOnOver('ux-taskbuttons-scroller-left-over');
\r
289 this.leftRepeater = new Ext.util.ClickRepeater(sl, {
\r
290 interval : this.scrollRepeatInterval,
\r
291 handler: this.onScrollLeft,
\r
294 this.scrollLeft = sl;
\r
297 var sr = this.el.insertFirst({
\r
298 cls:'ux-taskbuttons-scroller-right'
\r
301 sr.addClassOnOver('ux-taskbuttons-scroller-right-over');
\r
302 this.rightRepeater = new Ext.util.ClickRepeater(sr, {
\r
303 interval : this.scrollRepeatInterval,
\r
304 handler: this.onScrollRight,
\r
307 this.scrollRight = sr;
\r
310 getScrollWidth : function(){
\r
311 return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
\r
314 getScrollPos : function(){
\r
315 return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
\r
318 getScrollArea : function(){
\r
319 return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
\r
322 getScrollAnim : function(){
\r
324 duration: this.scrollDuration,
\r
325 callback: this.updateScrollButtons,
\r
330 getScrollIncrement : function(){
\r
331 return (this.scrollIncrement || this.lastButtonWidth+2);
\r
334 /* getBtnEl : function(item){
\r
335 return document.getElementById(item.id);
\r
338 scrollToButton : function(item, animate){
\r
339 item = item.el.dom.parentNode; // li
\r
340 if(!item){ return; }
\r
341 var el = item; //this.getBtnEl(item);
\r
342 var pos = this.getScrollPos(), area = this.getScrollArea();
\r
343 var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;
\r
344 var right = left + el.offsetWidth;
\r
346 this.scrollTo(left, animate);
\r
347 }else if(right > (pos + area)){
\r
348 this.scrollTo(right - area, animate);
\r
352 scrollTo : function(pos, animate){
\r
353 this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
\r
355 this.updateScrollButtons();
\r
359 onScrollRight : function(){
\r
360 var sw = this.getScrollWidth()-this.getScrollArea();
\r
361 var pos = this.getScrollPos();
\r
362 var s = Math.min(sw, pos + this.getScrollIncrement());
\r
364 this.scrollTo(s, this.animScroll);
\r
368 onScrollLeft : function(){
\r
369 var pos = this.getScrollPos();
\r
370 var s = Math.max(0, pos - this.getScrollIncrement());
\r
372 this.scrollTo(s, this.animScroll);
\r
376 updateScrollButtons : function(){
\r
377 var pos = this.getScrollPos();
\r
378 this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-left-disabled');
\r
379 this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-right-disabled');
\r
385 <div id="cls-Ext.ux.TaskBar.TaskButton"></div>/**
\r
386 * @class Ext.ux.TaskBar.TaskButton
\r
387 * @extends Ext.Button
\r
389 Ext.ux.TaskBar.TaskButton = function(win, el){
\r
391 Ext.ux.TaskBar.TaskButton.superclass.constructor.call(this, {
\r
392 iconCls: win.iconCls,
\r
393 text: Ext.util.Format.ellipsis(win.title, 12),
\r
395 handler : function(){
\r
396 if(win.minimized || win.hidden){
\r
398 }else if(win == win.manager.getActive()){
\r
404 clickEvent:'mousedown',
\r
405 template: new Ext.Template(
\r
406 '<table cellspacing="0" class="x-btn {3}"><tbody><tr>',
\r
407 '<td class="ux-taskbutton-left"><i> </i></td>',
\r
408 '<td class="ux-taskbutton-center"><em class="{5} unselectable="on">',
\r
409 '<button class="x-btn-text {2}" type="{1}" style="height:28px;">{0}</button>',
\r
411 '<td class="ux-taskbutton-right"><i> </i></td>',
\r
412 "</tr></tbody></table>")
\r
416 Ext.extend(Ext.ux.TaskBar.TaskButton, Ext.Button, {
\r
417 onRender : function(){
\r
418 Ext.ux.TaskBar.TaskButton.superclass.onRender.apply(this, arguments);
\r
420 this.cmenu = new Ext.menu.Menu({
\r
423 handler: function(){
\r
424 if(!this.win.isVisible()){
\r
427 this.win.restore();
\r
433 handler: this.win.minimize,
\r
437 handler: this.win.maximize,
\r
441 handler: this.closeWin.createDelegate(this, this.win, true),
\r
446 this.cmenu.on('beforeshow', function(){
\r
447 var items = this.cmenu.items.items;
\r
449 items[0].setDisabled(w.maximized !== true && w.hidden !== true);
\r
450 items[1].setDisabled(w.minimized === true);
\r
451 items[2].setDisabled(w.maximized === true || w.hidden === true);
\r
454 this.el.on('contextmenu', function(e){
\r
456 if(!this.cmenu.el){
\r
457 this.cmenu.render();
\r
459 var xy = e.getXY();
\r
460 xy[1] -= this.cmenu.el.getHeight();
\r
461 this.cmenu.showAt(xy);
\r
465 closeWin : function(cMenu, e, win){
\r
466 if(!win.isVisible()){
\r