      1 (function ($, rf) {
      2
      3     rf.ui = rf.ui || {};
      4
      5     rf.ui.PopupPanel.Border = function(id, modalPanel, cursor, sizer) {
      6
      7         $super.constructor.call(this, id);
      8
      9         this.element = $(rf.getDomElement(id));
     10         this.element.css('cursor', cursor);
     11         var border = this;
     12         this.element.bind('mousedown', {border:border}, this.startDrag);
     13
     14         this.modalPanel = modalPanel;
     15         this.sizer = sizer;
     16     };
     17
     18     var $super = rf.BaseComponent.extend(rf.ui.PopupPanel.Border);
     19     var $super = rf.ui.PopupPanel.Border.$super;
     20
     21     $.extend(rf.ui.PopupPanel.Border.prototype, (function (options) {
     22
     23         return {
     24
     25             name: "RichFaces.ui.PopupPanel.Border",
     26
     27             destroy: function() {
     28                 if (this.doingDrag) {
     29                     $(document).unbind('mousemove', this.doDrag);
     30                     $(document).unbind('mouseup', this.endDrag);
     31                 }
     32
     33                 this.element.unbind('mousedown', this.startDrag);
     34                 this.element = null;
     35                 this.modalPanel = null;
     36             },
     37
     38             show: function() {
     39                 this.element.show();
     40             },
     41
     42             hide: function() {
     43                 this.element.hide();
     44             },
     45
     46             startDrag: function(event) {
     47                 var border = event.data.border;
     48                 border.doingDrag = true;
     49
     50                 border.dragX = event.clientX;
     51                 border.dragY = event.clientY;
     52                 $(document).bind('mousemove', {border:border}, border.doDrag);
     53                 $(document).bind('mouseup', {border:border}, border.endDrag);
     54
     55                 border.modalPanel.startDrag(border);
     56
     57                 border.onselectStartHandler = document.onselectstart;
     58                 document.onselectstart = function() {
     59                     return false;
     60                 }
     61             },
     62
     63             getWindowSize : function() {
     64                 var myWidth = 0, myHeight = 0;
     65                 if (typeof( window.innerWidth ) == 'number') {
     66                     myWidth = window.innerWidth;
     67                     myHeight = window.innerHeight;
     68                 } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
     69                     myWidth = document.documentElement.clientWidth;
     70                     myHeight = document.documentElement.clientHeight;
     71                 } else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) {
     72                     myWidth = document.body.clientWidth;
     73                     myHeight = document.body.clientHeight;
     74                 }
     75                 return {"width":myWidth,"height":myHeight};
     76             },
     77
     78             doDrag: function(event) {
     79                 var border = event.data.border;
     80                 if (!border.doingDrag) {
     81                     return;
     82                 }
     83
     84                 var evtX = event.clientX;
     85                 var evtY = event.clientY;
     86
     87                 var winSize = border.getWindowSize();
     88
     89                 if (evtX < 0) {
     90                     evtX = 0;
     91                 } else if (evtX >= winSize.width) {
     92                     evtX = winSize.width - 1;
     93                 }
     94
     95                 if (evtY < 0) {
     96                     evtY = 0;
     97                 } else if (evtY >= winSize.height) {
     98                     evtY = winSize.height - 1;
     99                 }
    100
    101                 var dx = evtX - border.dragX;
    102                 var dy = evtY - border.dragY;
    103
    104                 if (dx != 0 || dy != 0) {
    105
    106                     var id = border.id;
    107
    108                     var diff = border.sizer.prototype.doDiff(dx, dy);//TODO
    109                     var doResize;
    110
    111                     var element = border.modalPanel.cdiv;
    112
    113                     if (diff.deltaWidth || diff.deltaHeight) {
    114                         doResize = border.modalPanel.invokeEvent("resize", event, null, element);
    115                     } else if (diff.deltaX || diff.deltaY) {
    116                         doResize = border.modalPanel.invokeEvent("move", event, null, element);
    117                     }
    118
    119                     var vetoes;
    120
    121                     if (doResize) {
    122                         vetoes = border.modalPanel.doResizeOrMove(diff);
    123                     }
    124
    125                     if (vetoes) {
    126                         if (!vetoes.x) {
    127                             border.dragX = evtX;
    128                         } else {
    129                             if (!diff.deltaX) {
    130                                 border.dragX -= vetoes.vx || 0;
    131                             } else {
    132                                 border.dragX += vetoes.vx || 0;
    133                             }
    134                         }
    135
    136                         if (!vetoes.y) {
    137                             border.dragY = evtY;
    138                         } else {
    139                             if (!diff.deltaY) {
    140                                 border.dragY -= vetoes.vy || 0;
    141                             } else {
    142                                 border.dragY += vetoes.vy || 0;
    143                             }
    144                         }
    145                     }
    146                 }
    147             },
    148
    149             endDrag: function(event) {
    150                 var border = event.data.border;
    151                 border.doingDrag = undefined;
    152
    153                 $(document).unbind('mousemove', border.doDrag);
    154                 $(document).unbind('mouseup', border.endDrag);
    155
    156                 border.modalPanel.endDrag(border);
    157
    158                 document.onselectstart = border.onselectStartHandler;
    159                 border.onselectStartHandler = null;
    160             },
    161
    162             doPosition: function() {
    163                 this.sizer.prototype.doPosition(this.modalPanel, this.element);	//TODO remove prototype
    164             }
    165         }
    166
    167     })());
    168
    169 })(RichFaces.jQuery, window.RichFaces);