1function _adjustMasterPage() { 2 3 var $section = $("#content-body"); 4 var $master = $section.find(".master-element"); 5 var $parent = $master.parent(); 6 var collapse = $master.hasClass('master-collapse'); 7 8 if($section.hasClass('master-page-adjusted')) { 9 return; 10 } 11 12 if($parent.length === 1 && !window.skipAdjustMasterPage) { 13 14 if ($master[0].newSectionHeight) { 15 $section.height($master[0].newSectionHeight); 16 $section.addClass("master-page-adjusted"); 17 return; 18 } 19 20 var masterPosition = $parent.position(); 21 22 var masterTop = masterPosition.top; 23 var masterHeight = $parent.outerHeight(); 24 var masterBottom = masterTop + masterHeight; 25 26 var masterLeft = masterPosition.left; 27 var masterWidth = $parent.outerWidth(); 28 var masterRight = masterLeft + masterWidth; 29 30 var renderHeight = $master.outerHeight(); 31 var renderBottom = masterTop + renderHeight; 32 33 var offsetHeight = renderBottom > masterBottom ? renderBottom - masterBottom : 0; 34 35 var $elements = $section.find(".element").not($parent); 36 37 var elementsMaxHeight = _getElementMaxHeight($elements,$parent); 38 39 var $bottomElement = _getBottomElement($elements,$parent); 40 var orgBottomElementDiff = $section.height(); 41 if(typeof $bottomElement !== "undefined") { 42 orgBottomElementDiff -= ($bottomElement.position().top + $bottomElement.outerHeight()); 43 } else { 44 orgBottomElementDiff -= ($parent.position().top + $parent.outerHeight()); 45 } 46 47 // get offsetHeight if collapse 48 if (collapse && renderBottom < masterBottom) { 49 offsetHeight = renderBottom - masterBottom; 50 var maxCollapseBottom = renderBottom; 51 var bottomElementsTop = elementsMaxHeight; 52 $elements.each(function() { 53 var $this = $(this), thisPos = $this.position(), 54 thisTop = thisPos.top, thisBottom = thisTop + $this.outerHeight(); 55 if(thisBottom < masterBottom) { 56 maxCollapseBottom = Math.max(maxCollapseBottom, thisBottom); 57 } else if (thisTop >= masterBottom){ 58 bottomElementsTop = Math.min(bottomElementsTop, thisTop); 59 } 60 }); 61 offsetHeight = Math.max(offsetHeight, maxCollapseBottom - bottomElementsTop); 62 } 63 64 var newSectionHeight = renderBottom; 65 $elements.each(function() { 66 var $this = $(this); 67 var thisPos = $this.position(); 68 var thisTop = thisPos.top; 69 70 if(thisTop >= masterBottom) { 71 var thisLeft = thisPos.left; 72 var thisWidth = $this.outerWidth(); 73 var thisRight = thisLeft + thisWidth; 74 75 if(thisLeft <= masterRight && thisRight >= masterLeft) { 76 77 var newTop = thisTop; 78 // if(offsetHeight > 0 || $("body").hasClass("mobile-mode")){ 79 if(offsetHeight !== 0 || $("body").hasClass("mobile-mode")){ 80 newTop = thisTop + offsetHeight; 81 if(typeof App !== "undefined" && App.isPreview){ 82 setTimeout(function(){ 83 $this.css("top", newTop); 84 },300); 85 } else { 86 $this.css("top", newTop); 87 } 88 } 89 90 if(!$this.hasClass("strip-element")){ 91 var thisHeight = $this.outerHeight(); 92 newSectionHeight = Math.max(newSectionHeight, newTop + thisHeight); 93 } 94 } 95 } 96 }); 97 98 if (collapse) { 99 $parent.outerHeight(renderHeight); 100 $bottomElement = _getBottomElement($elements,$parent); 101 orgBottomElementDiff = $section.height() - elementsMaxHeight || 0; 102 elementsMaxHeight = _getElementMaxHeight($elements,$parent); 103 } 104 105 if($bottomElement) { 106 newSectionHeight = (Math.max(newSectionHeight, $bottomElement.position().top + $bottomElement.outerHeight())) + orgBottomElementDiff; 107 if(newSectionHeight < elementsMaxHeight){ 108 newSectionHeight = elementsMaxHeight; 109 } 110 if(newSectionHeight > 0 && (collapse || newSectionHeight > $section.height())) { 111 $section.height(newSectionHeight); 112 } 113 } else { 114 newSectionHeight += orgBottomElementDiff; 115 if(newSectionHeight < elementsMaxHeight){ 116 newSectionHeight = elementsMaxHeight; 117 } 118 if(newSectionHeight > 0) { 119 if(!collapse) { 120 newSectionHeight = Math.max(renderHeight , newSectionHeight) + $master.parent().position().top; 121 } 122 123 $section.height(newSectionHeight); 124 } 125 } 126 127 $master[0].newSectionHeight = $section.height(); 128 $section.addClass("master-page-adjusted"); 129 $parent.outerHeight(renderHeight); 130 } 131} 132 133function _revertMasterPage() { 134 135 var $section = $("#content-body"); 136 var $master = $section.find(".master-element"); 137 var $parent = $master.parent(); 138 139 if($section.hasClass("master-page-adjusted") && $parent.length === 1) { 140 $section.removeClass("master-page-adjusted").find(".element").not(this.$el).trigger("revertPosition"); 141 delete $master[0].newSectionHeight; 142 143 var contentHeight = App.editorMode === 'mobile' ? App.sectionHeights.mobile['content-body'] : App.sectionHeights.desktop['content-body']; 144 $section.height(contentHeight); 145 } 146} 147 148function _getBottomElement($elements,$parent) { 149 var $el, masterBottom = $parent.position().top + $parent.outerHeight(); 150 $elements.each(function() { 151 var $t = $(this), elTop = $t.position().top; 152 if(elTop > masterBottom && (typeof $el == "undefined" || typeof $el !== "undefined" && elTop > $el.position().top)) { 153 $el = $(this); 154 } 155 }); 156 return $el; 157} 158 159function _getElementMaxHeight($elements,$parent) { 160 var h = $parent.position().top + $parent.outerHeight(); 161 $elements.each(function() { 162 var $t = $(this), elHeight = $t.position().top + $t.outerHeight(); 163 if(elHeight > h && !$t.hasClass("strip-element")) { 164 h = elHeight; 165 } 166 }); 167 return h; 168}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.