      1 (function ($, rf) {
      2
      3     rf.ui = rf.ui || {};
      4     var selectionEventHandler = function(event) {
      5         event.stopPropagation();
      6         event.preventDefault();
      7     };
      8
      9     var disableSelection = function (element) {
     10         if (typeof element.onselectstart != "undefined") //IE
     11         {
     12             $(rf.getDomElement(element)).bind('selectstart', selectionEventHandler);
     13         }
     14         else //All other (ie: Opera)
     15         {
     16             $(rf.getDomElement(element)).bind('mousedown', selectionEventHandler);
     17         }
     18     };
     19
     20     var enableSelection = function (element) {
     21         if (typeof element.onselectstart != "undefined") //IE
     22         {
     23             $(rf.getDomElement(element)).unbind('selectstart', selectionEventHandler);
     24         }
     25         else //All other (ie: Opera)
     26         {
     27             $(rf.getDomElement(element)).unbind('mousedown', selectionEventHandler);
     28         }
     29     };
     30
     31     var defaultOptions = {
     32         width:-1,
     33         height:-1,
     34         minWidth:-1,
     35         minHeight:-1,
     36         modal:true,
     37         moveable:true,
     38         resizeable: false,
     39         autosized: false,
     40         left: "auto",
     41         top : "auto",
     42         zindex:100,
     43         shadowDepth : 5,
     44         shadowOpacity: 0.1,
     45         attachToBody:true
     46     };
     47
     48
     49     rf.ui.PopupPanel = function(id, options) {
     50
     51         $super.constructor.call(this, id);
     52         this.markerId = id;
     53         this.attachToDom(this.markerId);
     54         this.options = $.extend(this.options, defaultOptions, options || {});
     55
     56         this.minWidth = this.getMinimumSize(this.options.minWidth);
     57         this.minHeight = this.getMinimumSize(this.options.minHeight);
     58         this.maxWidth = this.options.maxWidth;
     59         this.maxHeight = this.options.maxHeight;
     60
     61         this.baseZIndex = this.options.zindex;
     62
     63         this.div = $(rf.getDomElement(id));
     64         this.cdiv = $(rf.getDomElement(id + "_container"));
     65         this.contentDiv = $(rf.getDomElement(id + "_content"));
     66         this.shadowDiv = $(rf.getDomElement(id + "_shadow"));
     67         this.shadeDiv = $(rf.getDomElement(id + "_shade"));
     68         this.scrollerDiv = $(rf.getDomElement(id + "_content_scroller"));
     69
     70         $(this.shadowDiv).css("opacity", this.options.shadowOpacity);
     71         this.shadowDepth = parseInt(this.options.shadowDepth);
     72
     73         this.borders = new Array();
     74         this.firstHref = $(rf.getDomElement(id + "FirstHref"));
     75         if (this.options.resizeable) {
     76             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerN", this, "N-resize", rf.ui.PopupPanel.Sizer.N));
     77             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerE", this, "E-resize", rf.ui.PopupPanel.Sizer.E));
     78             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerS", this, "S-resize", rf.ui.PopupPanel.Sizer.S));
     79             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerW", this, "W-resize", rf.ui.PopupPanel.Sizer.W));
     80
     81             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerNW", this, "NW-resize", rf.ui.PopupPanel.Sizer.NW));
     82             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerNE", this, "NE-resize", rf.ui.PopupPanel.Sizer.NE));
     83             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerSE", this, "SE-resize", rf.ui.PopupPanel.Sizer.SE));
     84             this.borders.push(new rf.ui.PopupPanel.Border(id + "ResizerSW", this, "SW-resize", rf.ui.PopupPanel.Sizer.SW));
     85         }
     86
     87         if (this.options.moveable && rf.getDomElement(id + "_header")) {
     88             this.header = new rf.ui.PopupPanel.Border(id + "_header", this, "move", rf.ui.PopupPanel.Sizer.Header);
     89         } else {
     90             $(rf.getDomElement(id + "_header")).css('cursor', 'default');
     91         }
     92
     93         this.cdiv.resize($.proxy(this.resizeListener, this));
     94     };
     95
     96     rf.BaseComponent.extend(rf.ui.PopupPanel);
     97     var $super = rf.ui.PopupPanel.$super;
     98     $.extend(rf.ui.PopupPanel.prototype, (function (options) {
     99
    100         return {
    101
    102             name: "PopupPanel",
    103             saveInputValues: function(element) {
    104                 /* Fix for RF-3856 - Checkboxes in modal panel does not hold their states after modal was closed and opened again */
    105                 if (rf.browser.msie /* reproducible for checkbox/radio in IE6, radio in IE 7/8 beta 2 */) {
    106                     $('input[type=checkbox], input[type=radio]', element).each(function(index) {
    107                         $(this).defaultChecked = $(this).checked;
    108                     });
    109                 }
    110             },
    111
    112             width: function() {
    113                 return this.getContentElement()[0].clientWidth;//TODO
    114             },
    115
    116             height: function() {
    117                 return this.getContentElement()[0].clientHeight;//TODO
    118             },
    119
    120             getLeft : function () {
    121                 return this.cdiv.css('left');
    122             },
    123
    124             getTop : function () {
    125                 return this.cdiv.css('top');
    126             },
    127
    128             getInitialSize : function() {
    129                 if (this.options.autosized) {
    130                     return 15;
    131                 } else {
    132                     return $(rf.getDomElement(this.markerId + "_header_content")).height();
    133                 }
    134             },
    135
    136             getContentElement: function() {
    137                 if (!this._contentElement) {
    138                     this._contentElement = this.cdiv;
    139                 }
    140
    141                 return this._contentElement;
    142             },
    143             getSizeElement : function() {
    144                 return document.body;
    145             },
    146
    147             getMinimumSize : function(size) {
    148                 return Math.max(size, 2 * this.getInitialSize() + 2);
    149             },
    150
    151             __getParsedOption: function(options, name) {
    152                 var value = parseInt(options[name], 10);
    153
    154                 if (value < 0 || isNaN(value)) {
    155                     value = this[name];
    156                 }
    157
    158                 return value;
    159             },
    160
    161             destroy: function() {
    162
    163                 this._contentElement = null;
    164                 this.firstOutside = null;
    165                 this.lastOutside = null;
    166                 this.firstHref = null;
    167                 this.parent = null;
    168                 if (this.header) {
    169                     this.header.destroy();
    170                     this.header = null;
    171                 }
    172
    173                 for (var k = 0; k < this.borders.length; k++) {
    174                     this.borders[k].destroy();
    175                 }
    176                 this.borders = null;
    177
    178                 if (this.domReattached) {
    179                     this.div.remove();
    180                 }
    181
    182                 this.markerId = null;
    183                 this.options = null;
    184
    185                 this.div = null;
    186                 this.cdiv = null;
    187                 this.contentDiv = null;
    188                 this.shadowDiv = null;
    189                 this.scrollerDiv = null;
    190                 this.userOptions = null;
    191                 this.eIframe = null;
    192
    193                 $super.destroy.call(this);
    194
    195             },
    196
    197             initIframe : function() {
    198                 if (this.contentWindow) {
    199                     $(this.contentWindow.document.body).css("margin", "0px 0px 0px 0px");
    200                 } else {
    201                     //TODO opera etc.
    202
    203                 }
    204
    205                 if ("transparent" == $(document.body).css("background-color")) {
    206                     $(this).css('filter', "alpha(opacity=0)");
    207                     $(this).css('opacity', "0");
    208                 }
    209             },
    210
    211             setLeft: function(pos) {
    212                 if (!isNaN(pos)) {
    213                     this.cdiv.css('left', pos + "px");
    214                 }
    215             },
    216
    217             setTop: function(pos) {
    218                 if (!isNaN(pos)) {
    219                     this.cdiv.css('top', pos + "px");
    220                 }
    221             },
    222
    223             show: function(event, opts) {
    224                 var element = this.cdiv;
    225                 if (!this.shown && this.invokeEvent("beforeshow", event, null, element)) {
    226                     this.preventFocus();
    227
    228
    229                     if (!this.domReattached) {
    230                         this.parent = this.div.parent();
    231
    232                         var domElementAttachment;
    233                         if (opts) {
    234                             domElementAttachment = opts.domElementAttachment;
    235                         }
    236
    237                         if (!domElementAttachment) {
    238                             domElementAttachment = this.options.domElementAttachment;
    239                         }
    240
    241                         var newParent;
    242                         if ('parent' == domElementAttachment) {
    243                             newParent = this.parent;
    244                         } else if ('form' == domElementAttachment) {
    245                             newParent = this.findForm(element)[0] || document.body;
    246                         } else {
    247                             //default - body
    248                             newParent = document.body;
    249                         }
    250
    251                         if (newParent != this.parent) {
    252                             this.saveInputValues(element);
    253                             this.shadeDiv.length && newParent.appendChild(this.shadeDiv.get(0));
    254                             newParent.appendChild(this.cdiv.get(0));
    255                             this.domReattached = true;
    256                         } else {
    257                             this.parent.show();
    258                         }
    259                     }
    260
    261                     var forms = $("form", element);
    262
    263                     if (this.options.keepVisualState && forms) {
    264                         for (var i = 0; i < forms.length; i++) {
    265                             var popup = this;
    266                             $(forms[i]).bind("submit", {popup:popup}, this.setStateInput);
    267                         }
    268                     }
    269
    270                     var options = {};
    271                     this.userOptions = {};
    272                     $.extend(options, this.options);
    273
    274                     if (opts) {
    275                         $.extend(options, opts);
    276                         $.extend(this.userOptions, opts);
    277                     }
    278
    279                     // reset dimensions
    280                     if (this.options.autosized) {
    281                         if (options.left) {
    282                             var _left;
    283                             if (options.left != "auto") {
    284                                 _left = parseInt(options.left, 10);
    285                             } else {
    286                                 var cw = this.__calculateWindowWidth();
    287                                 var _width = this.width();
    288                                 if (cw >= _width) {
    289                                     _left = (cw - _width) / 2;
    290                                 } else {
    291                                     _left = 0;
    292                                 }
    293                             }
    294
    295                             this.setLeft(Math.round(_left));
    296                             $(this.shadowDiv).css("left", this.shadowDepth);
    297                         }
    298
    299                         if (options.top) {
    300                             var _top;
    301                             if (options.top != "auto") {
    302                                 _top = parseInt(options.top, 10);
    303                             } else {
    304                                 var ch = this.__calculateWindowHeight();
    305                                 var _height = this.height();
    306                                 if (ch >= _height) {
    307                                     _top = (ch - _height) / 2;
    308                                 } else {
    309                                     _top = 0;
    310                                 }
    311                             }
    312
    313                             this.setTop(Math.round(_top));
    314                             $(this.shadowDiv).css("top", this.shadowDepth);
    315                             $(this.shadowDiv).css("bottom", -this.shadowDepth);
    316                         }
    317
    318                         this.doResizeOrMove(rf.ui.PopupPanel.Sizer.Diff.EMPTY);
    319                     }
    320
    321                     this.currentMinHeight = this.getMinimumSize(this.__getParsedOption(options, 'minHeight'));
    322                     this.currentMinWidth = this.getMinimumSize(this.__getParsedOption(options, 'minWidth'));
    323
    324                     var eContentElt = this.getContentElement();
    325
    326                     if (!this.options.autosized) {
    327                         if (options.width && options.width == -1)
    328                             options.width = 300;
    329                         if (options.height && options.height == -1)
    330                             options.height = 200;
    331                     }
    332
    333                     this.div.css('visibility', '');
    334                     if (rf.browser.msie) {
    335                         $(this.cdiv).find('input').each(function() {
    336                             // Force a CSS "touch" of all popupPanel children to ensure visibility in IE for RF-12850
    337                             var $this = $(this);
    338                             if ($this.parents(".rf-pp-cntr").first().attr('id') === element.attr('id')) {
    339                                 $this.css('visibility', $this.css('visibility'));
    340                             }
    341                         })
    342                     }
    343                     this.div.css('display', 'block');
    344                     if (this.options.autosized) {
    345                         this.shadowDiv.css('width', this.cdiv[0].clientWidth);
    346
    347                     }
    348
    349                     if (options.width && options.width != -1 || options.autosized) {
    350                         var width;
    351                         if (options.autosized) {
    352                             width = this.getStyle(this.getContentElement(), "width");
    353                             if (this.currentMinWidth > width) {
    354                                 width = this.currentMinWidth;
    355                             }
    356                             if (width > this.maxWidth) {
    357                                 width = this.maxWidth;
    358                             }
    359                         } else {
    360                             if (this.currentMinWidth > options.width) {
    361                                 options.width = this.currentMinWidth;
    362                             }
    363                             if (options.width > this.maxWidth) {
    364                                 options.width = this.maxWidth;
    365                             }
    366                             width = options.width;
    367                         }
    368                         $(rf.getDomElement(eContentElt)).css('width', width + (/px/.test(width) ? '' : 'px'));
    369                         this.shadowDiv.css('width', width + (/px/.test(width) ? '' : 'px'));
    370                         this.scrollerDiv.css('width', width + (/px/.test(width) ? '' : 'px'));
    371                     }
    372
    373                     if (options.height && options.height != -1 || options.autosized) {
    374                         var height;
    375                         if (options.autosized) {
    376                             height = this.getStyle(this.getContentElement(), "height");
    377                             if (this.currentMinHeight > height) {
    378                                 height = this.currentMinHeight;
    379                             }
    380                             if (height > this.maxHeight) {
    381                                 height = this.maxHeight;
    382                             }
    383                         } else {
    384                             if (this.currentMinHeight > options.height) {
    385                                 options.height = this.currentMinHeight;
    386                             }
    387                             if (options.height > this.maxHeight) {
    388                                 options.height = this.maxHeight;
    389                             }
    390                             height = options.height;
    391                         }
    392                         $(rf.getDomElement(eContentElt)).css('height', height + (/px/.test(height) ? '' : 'px'));
    393                         var headerHeight = $(rf.getDomElement(this.markerId + "_header")) ? $(rf.getDomElement(this.markerId + "_header")).innerHeight() : 0;
    394                         this.shadowDiv.css('height', height + (/px/.test(height) ? '' : 'px'));
    395                         this.scrollerDiv.css('height', height - headerHeight + (/px/.test(height) ? '' : 'px'));
    396                     }
    397
    398                     var eIframe;
    399                     if (this.options.overlapEmbedObjects && !this.iframe) {
    400                         this.iframe = this.markerId + "IFrame";
    401                         $("<iframe src=\"javascript:''\" frameborder=\"0\" scrolling=\"no\" id=\"" + this.iframe + "\" " +
    402                             "class=\"rf-pp-ifr\" style=\"width:" + this.options.width + "px; height:" + this.options.height + "px;\">" +
    403                             "</iframe>").insertBefore($(':first-child', this.cdiv)[0]);
    404
    405                         eIframe = $(rf.getDomElement(this.iframe));
    406
    407                         eIframe.bind('load', this.initIframe);
    408                         this.eIframe = eIframe;
    409                     }
    410
    411                     if (options.left) {
    412                         var _left;
    413                         if (options.left != "auto") {
    414                             _left = parseInt(options.left, 10);
    415                         } else {
    416                             var cw = this.__calculateWindowWidth();
    417                             var _width = this.width();
    418                             if (cw >= _width) {
    419                                 _left = (cw - _width) / 2;
    420                             } else {
    421                                 _left = 0;
    422                             }
    423                         }
    424
    425                         this.setLeft(Math.round(_left));
    426                         $(this.shadowDiv).css("left", this.shadowDepth);
    427                     }
    428
    429                     if (options.top) {
    430                         var _top;
    431                         if (options.top != "auto") {
    432                             _top = parseInt(options.top, 10);
    433                         } else {
    434                             var ch = this.__calculateWindowHeight();
    435                             var _height = this.height();
    436                             if (ch >= _height) {
    437                                 _top = (ch - _height) / 2;
    438                             } else {
    439                                 _top = 0;
    440                             }
    441                         }
    442
    443                         this.setTop(Math.round(_top));
    444                         $(this.shadowDiv).css("top", this.shadowDepth);
    445                         $(this.shadowDiv).css("bottom", -this.shadowDepth);
    446                     }
    447
    448                     var showEvent = {};
    449                     showEvent.parameters = opts || {};
    450                     this.shown = true;
    451                     // Cache the height difference between the shadoww div and the scroller div for later height calculations
    452                     this.scrollerSizeDelta = parseInt(this.shadowDiv.css('height')) - parseInt(this.scrollerDiv.css('height'));
    453                     this.invokeEvent("show", showEvent, null, element);
    454                 }
    455             },
    456
    457             __calculateWindowHeight: function() {
    458                 var documentElement = document.documentElement;
    459                 return self.innerHeight || (documentElement && documentElement.clientHeight) || document.body.clientHeight;
    460             },
    461
    462             __calculateWindowWidth: function() {
    463                 var documentElement = document.documentElement;
    464                 return self.innerWidth || (documentElement && documentElement.clientWidth) || document.body.clientWidth;
    465             },
    466
    467             startDrag: function(border) {
    468                 disableSelection(document.body);
    469             },
    470             firstOnfocus: function(event) {
    471                 var e = $(event.data.popup.firstHref);
    472                 if (e) {
    473                     e.focus();
    474                 }
    475             },
    476
    477             processAllFocusElements: function(root, callback) {
    478                 var idx = -1;
    479                 var tagName;
    480                 var formElements = "|a|input|select|button|textarea|";
    481
    482                 if (root.focus && root.nodeType == 1 && (tagName = root.tagName) &&
    483                     // Many not visible elements have focus method, we is had to avoid processing them.
    484                     (idx = formElements.indexOf(tagName.toLowerCase())) != -1 &&
    485                     formElements.charAt(idx - 1) === '|' &&
    486                     formElements.charAt(idx + tagName.length) === '|' &&
    487                     !root.disabled && root.type != "hidden") {
    488                     callback.call(this, root);
    489                 } else {
    490                     if (root != this.cdiv.get(0)) {
    491                         var child = root.firstChild;
    492                         while (child) {
    493                             if (!child.style || child.style.display != 'none') {
    494                                 this.processAllFocusElements(child, callback);
    495                             }
    496                             child = child.nextSibling;
    497                         }
    498                     }
    499                 }
    500             },
    501
    502             processTabindexes:    function(input) {
    503                 if (!this.firstOutside) {
    504                     this.firstOutside = input;
    505                 }
    506                 if (!input.prevTabIndex) {
    507                     input.prevTabIndex = input.tabIndex;
    508                     input.tabIndex = -1;
    509                 }
    510
    511                 if (!input.prevAccessKey) {
    512                     input.prevAccessKey = input.accessKey;
    513                     input.accessKey = "";
    514                 }
    515             },
    516
    517             restoreTabindexes:    function(input) {
    518                 if (input.prevTabIndex != undefined) {
    519                     if (input.prevTabIndex == 0) {
    520                         $(input).removeAttr('tabindex');
    521                     } else {
    522                         input.tabIndex = input.prevTabIndex;
    523                     }
    524                     input.prevTabIndex = undefined;
    525                 }
    526                 if (input.prevAccessKey != undefined) {
    527                     if (input.prevAccessKey == "") {
    528                         $(input).removeAttr('accesskey');
    529                     } else {
    530                         input.accessKey = input.prevAccessKey;
    531                     }
    532                     input.prevAccessKey = undefined;
    533                 }
    534             },
    535
    536             preventFocus:    function() {
    537                 if (this.options.modal) {
    538                     this.processAllFocusElements(document, this.processTabindexes);
    539                     var popup = this;
    540                     if (this.firstOutside) {
    541
    542                         $(rf.getDomElement(this.firstOutside)).bind("focus", {popup: popup}, this.firstOnfocus);
    543                     }
    544                 }
    545             },
    546
    547             restoreFocus: function() {
    548                 if (this.options.modal) {
    549                     this.processAllFocusElements(document, this.restoreTabindexes);
    550
    551                     if (this.firstOutside) {
    552                         $(rf.getDomElement(this.firstOutside)).unbind("focus", this.firstOnfocus);
    553                         this.firstOutside = null;
    554                     }
    555                 }
    556             },
    557
    558             endDrag: function(border) {
    559                 for (var k = 0; k < this.borders.length; k++) {
    560                     this.borders[k].show();
    561                     this.borders[k].doPosition();
    562                 }
    563                 enableSelection(document.body);
    564             },
    565
    566             hide: function(event, opts) {
    567                 var element = this.cdiv;
    568                 this.restoreFocus();
    569                 if (this.shown && this.invokeEvent("beforehide", event, null, element)) {
    570
    571                     this.currentMinHeight = undefined;
    572                     this.currentMinWidth = undefined;
    573
    574                     this.div.hide();
    575
    576                     if (this.parent) {
    577                         if (this.domReattached) {
    578                             this.saveInputValues(element);
    579                             var div = this.div.get(0);
    580                             this.shadeDiv.length && div.appendChild(this.shadeDiv.get(0));
    581                             div.appendChild(element.get(0));
    582
    583                             this.domReattached = false;
    584                         }
    585                     }
    586
    587                     var hideEvent = {};
    588                     hideEvent.parameters = opts || {};
    589
    590                     var forms = $("form", element);
    591                     if (this.options.keepVisualState && forms) {
    592                         for (var i = 0; i < forms.length; i++) {
    593                             $(forms[i]).unbind("submit", this.setStateInput);
    594                         }
    595                     }
    596
    597                     this.shown = false;
    598                     this.invokeEvent("hide", hideEvent, null, element);
    599
    600                     // reset position for proper resizing
    601                     this.setLeft(10);
    602                     this.setTop(10);
    603                 }
    604             },
    605
    606             getStyle: function(elt, name) {
    607                 return parseInt($(rf.getDomElement(elt)).css(name).replace("px", ""), 10);
    608             },
    609
    610             resizeListener: function(event, diff) {
    611                 this.doResizeOrMove(rf.ui.PopupPanel.Sizer.Diff.EMPTY);
    612             },
    613
    614             doResizeOrMove: function(diff) {
    615                 var vetoes = {};
    616                 var shadowHash = {};
    617                 var cssHash = {};
    618                 var cssHashWH = {};
    619                 var shadowHashWH = {};
    620                 var contentHashWH = {};
    621                 var scrollerHashWH = {};
    622                 var newSize;
    623                 var scrollerHeight = this.scrollerSizeDelta;
    624                 var scrollerWidth = 0;
    625                 var eContentElt = this.getContentElement();
    626
    627                 var doResize = diff === rf.ui.PopupPanel.Sizer.Diff.EMPTY || diff.deltaWidth || diff.deltaHeight;
    628
    629                 if (doResize) {
    630                     if (this.options.autosized) {
    631                         this.resetWidth();
    632                         this.resetHeight();
    633                     }
    634
    635                     newSize = this.getStyle(eContentElt, "width");
    636
    637                     var oldWidthSize = newSize;
    638                     newSize += diff.deltaWidth || 0;
    639
    640                     if (newSize >= this.currentMinWidth) {
    641                         cssHashWH.width = newSize + 'px';
    642                         shadowHashWH.width = newSize + 'px';
    643                         contentHashWH.width = newSize - scrollerWidth + 'px';
    644                         scrollerHashWH.width = newSize - scrollerWidth + 'px';
    645                     } else {
    646                         cssHashWH.width = this.currentMinWidth + 'px';
    647                         shadowHashWH.width = this.currentMinWidth + 'px';
    648                         contentHashWH.width = this.currentMinWidth - scrollerWidth + 'px';
    649                         scrollerHashWH.width = this.currentMinWidth - scrollerWidth + 'px';
    650
    651                         if (diff.deltaWidth) {
    652                             vetoes.vx = oldWidthSize - this.currentMinWidth;
    653                             vetoes.x = true;
    654                         }
    655                     }
    656
    657                     if (newSize > this.options.maxWidth) {
    658                         cssHashWH.width = this.options.maxWidth + 'px';
    659                         shadowHashWH.width = this.options.maxWidth + 'px';
    660                         contentHashWH.width = this.options.maxWidth - scrollerWidth + 'px';
    661                         scrollerHashWH.width = this.options.maxWidth - scrollerWidth + 'px';
    662
    663                         if (diff.deltaWidth) {
    664                             vetoes.vx = oldWidthSize - this.options.maxWidth;
    665                             vetoes.x = true;
    666                         }
    667                     }
    668                 }
    669
    670                 if (vetoes.vx && diff.deltaX) {
    671                     diff.deltaX = -vetoes.vx;
    672                 }
    673
    674                 var eCdiv = $(this.cdiv);
    675
    676                 if (diff.deltaX && (vetoes.vx || !vetoes.x)) {
    677                     if (vetoes.vx) {
    678                         diff.deltaX = vetoes.vx;
    679                     }
    680
    681                     var newLeftPos = this.getStyle(eCdiv, "left");
    682                     newLeftPos += diff.deltaX;
    683                     cssHash.left = newLeftPos + 'px';
    684
    685                 }
    686
    687                 if (doResize) {
    688                     newSize = this.getStyle(eContentElt, "height");
    689
    690                     var oldHeightSize = newSize;
    691                     newSize += diff.deltaHeight || 0;
    692
    693                     if (newSize >= this.currentMinHeight) {
    694                         cssHashWH.height = newSize + 'px';
    695                         shadowHashWH.height = newSize + 'px';
    696                         scrollerHashWH.height = newSize - scrollerHeight + 'px';
    697                     } else {
    698                         cssHashWH.height = this.currentMinHeight + 'px';
    699                         shadowHashWH.height = this.currentMinHeight + 'px';
    700                         scrollerHashWH.height = this.currentMinHeight - scrollerHeight + 'px';
    701
    702                         if (diff.deltaHeight) {
    703                             vetoes.vy = oldHeightSize - this.currentMinHeight;
    704                             vetoes.y = true;
    705                         }
    706                     }
    707
    708                     if (newSize > this.options.maxHeight) {
    709                         cssHashWH.height = this.options.maxHeight + 'px';
    710                         shadowHashWH.height = this.options.maxHeight + 'px';
    711                         scrollerHashWH.height = this.options.maxHeight - scrollerHeight + 'px';
    712
    713                         if (diff.deltaHeight) {
    714                             vetoes.vy = oldHeightSize - this.options.maxHeight;
    715                             vetoes.y = true;
    716                         }
    717                     }
    718                 }
    719
    720                 if (vetoes.vy && diff.deltaY) {
    721                     diff.deltaY = -vetoes.vy;
    722                 }
    723
    724                 if (diff.deltaY && (vetoes.vy || !vetoes.y)) {
    725                     if (vetoes.vy) {
    726                         diff.deltaY = vetoes.vy;
    727                     }
    728
    729                     var newTopPos = this.getStyle(eCdiv, "top");
    730                     newTopPos += diff.deltaY;
    731                     cssHash.top = newTopPos + 'px';
    732                 }
    733
    734                 eContentElt.css(cssHashWH);
    735                 this.scrollerDiv.css(scrollerHashWH);
    736                 if (this.eIframe) {
    737                     this.eIframe.css(scrollerHashWH);
    738                 }
    739                 this.shadowDiv.css(shadowHashWH);
    740
    741                 eCdiv.css(cssHash);
    742                 this.shadowDiv.css(shadowHash);
    743
    744                 $.extend(this.userOptions, cssHash);
    745                 $.extend(this.userOptions, cssHashWH);
    746                 var w = this.width();
    747                 var h = this.height();
    748
    749                 this.reductionData = null;
    750
    751                 if (w <= 2 * this.getInitialSize()) {
    752                     this.reductionData = {};
    753                     this.reductionData.w = w;
    754                 }
    755
    756                 if (h <= 2 * this.getInitialSize()) {
    757                     if (!this.reductionData) {
    758                         this.reductionData = {};
    759                     }
    760
    761                     this.reductionData.h = h;
    762                 }
    763
    764                 if (this.header) {
    765                     this.header.doPosition();
    766                 }
    767
    768                 return vetoes;
    769             },
    770
    771             resetWidth: function() {
    772                 this.getContentElement().css('width', '');
    773                 this.scrollerDiv.css('width', '');
    774                 if (this.eIframe) {
    775                     this.eIframe.css('width', '');
    776                 }
    777                 this.shadowDiv.css('width', '');
    778                 $(this.cdiv).css('width', '');
    779             },
    780
    781             resetHeight: function() {
    782                 this.getContentElement().css('height', '');
    783                 this.scrollerDiv.css('height', '');
    784                 if (this.eIframe) {
    785                     this.eIframe.css('height', '');
    786                 }
    787                 this.shadowDiv.css('height', '');
    788                 $(this.cdiv).css('height', '');
    789             },
    790
    791             setSize : function (width, height) {
    792                 var w = width - this.width();
    793                 var h = height - this.height();
    794                 var diff = new rf.ui.PopupPanel.Sizer.Diff(0, 0, w, h);
    795                 this.doResizeOrMove(diff);
    796             },
    797
    798             moveTo : function (top, left) {
    799                 this.cdiv.css('top', top);
    800                 this.cdiv.css('left', left);
    801             },
    802
    803             move : function (dx, dy) {
    804                 var diff = new rf.ui.PopupPanel.Sizer.Diff(dx, dy, 0, 0);
    805                 this.doResizeOrMove(diff);
    806             },
    807
    808             resize : function (dx, dy) {
    809                 var diff = new rf.ui.PopupPanel.Sizer.Diff(0, 0, dx, dy);
    810                 this.doResizeOrMove(diff);
    811             },
    812
    813             findForm: function(elt) {
    814                 var target = elt;
    815                 while (target) {
    816                     if (target[0] && (!target[0].tagName /* document node doesn't have tagName */
    817                         || target[0].tagName.toLowerCase() != "form")) {
    818
    819                         target = $(target).parent();
    820                     } else {
    821                         break;
    822                     }
    823                 }
    824
    825                 return target;
    826             },
    827
    828             setStateInput: function(event) {
    829                 // Concret input but not entire form is a target element for onsubmit in FF
    830                 var popup = event.data.popup;
    831                 target = $(popup.findForm(event.currentTarget));
    832
    833                 var input = document.createElement("input");
    834                 input.type = "hidden";
    835                 input.id = popup.markerId + "OpenedState";
    836                 input.name = popup.markerId + "OpenedState";
    837                 input.value = popup.shown ? "true" : "false";
    838                 target.append(input);
    839
    840                 $.each(popup.userOptions, function(key, value) {
    841                     input = document.createElement("input");
    842                     input.type = "hidden";
    843                     input.id = popup.markerId + "StateOption_" + key;
    844                     input.name = popup.markerId + "StateOption_" + key;
    845                     input.value = value;
    846                     target.append(input);
    847                 });
    848
    849                 return true;
    850             }
    851
    852
    853         }
    854
    855     })());
    856     $.extend(rf.ui.PopupPanel, {
    857
    858             showPopupPanel : function (id, opts, event) {
    859                 rf.Event.ready(function() {
    860                     rf.component(id).show()
    861                 });
    862             },
    863
    864             hidePopupPanel : function (id, opts, event) {
    865                 rf.Event.ready(function() {
    866                     rf.component(id).hide()
    867                 });
    868             }
    869         });
    870
    871 })(RichFaces.jQuery, window.RichFaces);
    872