Desktop.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:3k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.0.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.Desktop = function(app){
  2. this.taskbar = new Ext.ux.TaskBar(app);
  3. var taskbar = this.taskbar;
  4. var desktopEl = Ext.get('x-desktop');
  5.     var taskbarEl = Ext.get('ux-taskbar');
  6.     var shortcuts = Ext.get('x-shortcuts');
  7.     var windows = new Ext.WindowGroup();
  8.     var activeWindow;
  9.     function minimizeWin(win){
  10.         win.minimized = true;
  11.         win.hide();
  12.     }
  13.     function markActive(win){
  14.         if(activeWindow && activeWindow != win){
  15.             markInactive(activeWindow);
  16.         }
  17.         taskbar.setActiveButton(win.taskButton);
  18.         activeWindow = win;
  19.         Ext.fly(win.taskButton.el).addClass('active-win');
  20.         win.minimized = false;
  21.     }
  22.     function markInactive(win){
  23.         if(win == activeWindow){
  24.             activeWindow = null;
  25.             Ext.fly(win.taskButton.el).removeClass('active-win');
  26.         }
  27.     }
  28.     function removeWin(win){
  29.      taskbar.removeTaskButton(win.taskButton);
  30.         layout();
  31.     }
  32.     function layout(){
  33.         desktopEl.setHeight(Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight());
  34.     }
  35.     Ext.EventManager.onWindowResize(layout);
  36.     this.layout = layout;
  37.     this.createWindow = function(config, cls){
  38.      var win = new (cls||Ext.Window)(
  39.             Ext.applyIf(config||{}, {
  40.                 manager: windows,
  41.                 minimizable: true,
  42.                 maximizable: true
  43.             })
  44.         );
  45.         win.render(desktopEl);
  46.         win.taskButton = taskbar.addTaskButton(win);
  47.         win.cmenu = new Ext.menu.Menu({
  48.             items: [
  49.             ]
  50.         });
  51.         win.animateTarget = win.taskButton.el;
  52.         
  53.         win.on({
  54.          'activate': {
  55.          fn: markActive
  56.          },
  57.          'beforeshow': {
  58.          fn: markActive
  59.          },
  60.          'deactivate': {
  61.          fn: markInactive
  62.          },
  63.          'minimize': {
  64.          fn: minimizeWin
  65.          },
  66.          'close': {
  67.          fn: removeWin
  68.          }
  69.         });
  70.         
  71.         layout();
  72.         return win;
  73.     };
  74.     this.getManager = function(){
  75.         return windows;
  76.     };
  77.     this.getWindow = function(id){
  78.         return windows.get(id);
  79.     }
  80.     
  81.     this.getWinWidth = function(){
  82. var width = Ext.lib.Dom.getViewWidth();
  83. return width < 200 ? 200 : width;
  84. }
  85. this.getWinHeight = function(){
  86. var height = (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight());
  87. return height < 100 ? 100 : height;
  88. }
  89. this.getWinX = function(width){
  90. return (Ext.lib.Dom.getViewWidth() - width) / 2
  91. }
  92. this.getWinY = function(height){
  93. return (Ext.lib.Dom.getViewHeight()-taskbarEl.getHeight() - height) / 2;
  94. }
  95.     layout();
  96.     if(shortcuts){
  97.         shortcuts.on('click', function(e, t){
  98.             if(t = e.getTarget('dt', shortcuts)){
  99.                 e.stopEvent();
  100.                 var module = app.getModule(t.id.replace('-shortcut', ''));
  101.                 if(module){
  102.                     module.createWindow();
  103.                 }
  104.             }
  105.         });
  106.     }
  107. };