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