{"version":3,"sources":["js/blocks-display.js"],"names":["$","matchingBGColor","$block1","$block2","length","children","first","css","collapseWhitespace","hasClass","addClass","cssHooks","backgroundColor","get","elem","bg","window","getComputedStyle","getPropertyValue","search","original","parts","replace","match","r","toString","slice","g","b","a","alpha","trim","toLowerCase","colorToHex","document","ready","toggleClass","each","this","postHeroProcessed","layouts","find","push","layout","lastLayout","$prevLayout","$thisLayout","$nextLayout","blocks","block","lastBlock","$prevBlock","$thisBlock","$nextBlock","$heroBlock","removeClass","is","prevBGColorMatch","nextBGColorMatch","$nextLayoutFirstBlock","$thisLayoutLastBlock","jQuery"],"mappings":"CAAA,SAAWA,GA0DT,SAASC,EAAgBC,EAASC,GAEhC,OAAuB,IAAnBA,EAAQC,SAKqD,SAA7DF,EAAQG,SAAS,QAAQC,QAAQC,IAAI,qBAA+F,SAA7DJ,EAAQE,SAAS,QAAQC,QAAQC,IAAI,oBACvGL,EAAQG,SAAS,QAAQC,QAAQC,IAAI,sBAAwBJ,EAAQE,SAAS,QAAQC,QAAQC,IAAI,oBAEpGL,EAAQG,SAAS,QAAQC,QAAQC,IAAI,qBAAuBJ,EAAQE,SAAS,QAAQC,QAAQC,IAAI,oBAO1G,SAASC,EAAmBN,EAASC,GAC9BD,EAAQO,SAAS,aAAgBN,EAAQM,SAAS,aAzE5B,YA0EzBP,EAAQG,SAAS,QAAQC,QAAQC,IAAI,oBACrCL,EAAQQ,SAAS,uBAxErBV,EAAEW,SAASC,gBAAkB,CAC3BC,IAAK,SAAUC,GAkCb,IAAIC,EAAKC,OAAOC,iBAAiBH,EAAM,MAAMI,iBAAiB,oBAY9D,OAPEH,GAFgC,IAA9BA,EAAGI,OAAO,eAzCW,UAOzB,SAAoBC,GAClB,IAAIC,EAAQD,EAASE,QAAQ,MAAO,IAAIC,MAAM,2CAG9C,GAAIF,EAAO,CACT,IAAIG,GAAgB,IAAXH,EAAM,IAAaI,SAAS,IAAIC,MAAM,GAC3CC,GAAgB,IAAXN,EAAM,IAAaI,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PN,EAAWG,YAAY,gBAAgB7C,SAAS,eAChDF,EAAmB4C,EAAYC,KAI/BD,EAAW3C,SAAS,gBAAkBgD,GACxCL,EAAWG,YAAY,eAGrBH,EAAW3C,SAAS,mBAAqBiD,IAC3CN,EAAWG,YAAY,kBACvB/C,EAAmB4C,EAAYC,KAK7BA,EAAW5C,SAAS,iBAAmB4C,EAAW5C,SAAS,kBACzD2C,EAAW3C,SAAS,gBACtB2C,EAAWG,YAAY,gBAAgB7C,SAAS,eAEzC0C,EAAW3C,SAAS,mBAC3B2C,EAAWG,YAAY,mBAMvBH,EAAW3C,SAAS,iBACtB0C,EAAWzC,SAAS,uBACpB2C,EAAW3C,SAAS,wBAEb0C,EAAW3C,SAAS,eAC3B0C,EAAWzC,SAAS,uBAEb0C,EAAW3C,SAAS,mBAC3B4C,EAAW3C,SAAS,uBAa1B,GALIoC,EAAYrC,SAAS,kBAAqBkC,IAAWC,GACvDE,EAAYpC,SAAS,oBAInBoC,EAAYrC,SAAS,iBAAkB,CAIzC,IAAIkD,EAAwB3D,EAAE,qBAAsB+C,GAChD/C,EAAE,uCAAwC8C,GAAa1C,QAAU,IACU,SAA3EuD,EAAsBtD,SAAS,QAAQC,QAAQC,IAAI,qBAjRhC,YAkRpBoD,EAAsBtD,SAAS,QAAQC,QAAQC,IAAI,sBACpDuC,EAAYpC,SAAS,oBAKzB,GAAIqC,EAAYtC,SAAS,iBAAkB,CAIzC,IAAImD,EAAuB5D,EAAE,oBAAqB8C,IAC9Cc,EAAqBnD,SAAS,2BAC4C,SAA1EmD,EAAqBvD,SAAS,QAAQC,QAAQC,IAAI,qBA9R/B,YA+RpBqD,EAAqBvD,SAAS,QAAQC,QAAQC,IAAI,qBACnDqD,EAAqBxB,YAAY,gDAnS3C,CAySGyB","file":"blocks-display.js","sourcesContent":["(function ($) {\n\n // The general 'default' background color for blocks is white\n var defaultBackgroundColor = '#ffffff';\n\n // Automatically return rgb/rgba colors as hex values\n $.cssHooks.backgroundColor = {\n get: function (elem) {\n\n // Converts colors like rgb(0,0,0) to #000000 and rgba(0,0,0,0) to #00000000\n function colorToHex(original) {\n var parts = original.replace(/\\s/g, '').match(/^rgba?\\((\\d+),(\\d+),(\\d+),?([^,\\s)]+)?/i);\n\n // Deal with the component parts\n if (parts) {\n var r = (parts[1] | 1 << 8).toString(16).slice(1);\n var g = (parts[2] | 1 << 8).toString(16).slice(1);\n var b = (parts[3] | 1 << 8).toString(16).slice(1);\n\n // The alpha value is between 1.0 & 0.0 and needs conversion\n var a = '';\n var alpha = (parts[4] || '').trim();\n if (alpha !== '') {\n a = ((alpha * 255) | 1 << 8).toString(16).slice(1);\n }\n\n // If alpha is '00' (transparent) or all values 'ff' it is\n // equivalent to basic white in our case (for comparison).\n if (a === '00' || (r === 'ff' && g === 'ff' && b === 'ff' && a === 'ff')) {\n return defaultBackgroundColor;\n }\n else {\n return ('#' + r + g + b + a).toLowerCase();\n }\n }\n else {\n return original.toLowerCase(); // Already Hex!\n }\n }\n\n // Get the element's background color\n var bg = window.getComputedStyle(elem, null).getPropertyValue('background-color');\n\n // Returned background color may not be a standard 6 character hex color value\n if (bg.search('transparent') !== -1) {\n // If 'transparent' (IE) it's equivalent to white in our case (for comparison).\n bg = defaultBackgroundColor;\n }\n else {\n // Validate and convert if not already a hex color value\n bg = colorToHex(bg);\n }\n\n return bg;\n }\n };\n\n // Block background color comparison\n function matchingBGColor($block1, $block2) {\n // Prevent comparison against non-existent prev/next children resulting in 'undefined' value\n if ($block2.length === 0) {\n return false;\n }\n // If either block has a background image, that means they are either image based or have a gradient.\n // In that case, we need to compare the background-image instead of background-color.\n if ($block1.children('.row').first().css('background-image') !== 'none' || $block2.children('.row').first().css('background-image') !== 'none') {\n return $block1.children('.row').first().css('background-image') === $block2.children('.row').first().css('background-image');\n }\n return $block1.children('.row').first().css('backgroundColor') === $block2.children('.row').first().css('backgroundColor');\n }\n\n // Unlike other background-color blocks, blocks with white backgrounds do not\n // have any 'whitespace' (background color padding) that can be collapsed. We\n // also need to ignore blocks that have a background image specified as that\n // can introduce unexpected block spacing behaviour too.\n function collapseWhitespace($block1, $block2) {\n if (!$block1.hasClass('bg-image') && !$block2.hasClass('bg-image') &&\n $block1.children('.row').first().css('backgroundColor') !== defaultBackgroundColor) {\n $block1.addClass('collapse-whitespace');\n }\n }\n\n $(document).ready(function () {\n\n //\n // Block presentation logic (only full-width layouts).\n //\n\n // 'Hero' is generic for 'top' blocks like Hero CTA.\n // Check 'Hero' for 'full-bleed' & enable other 'full-bleed' blocks on page.\n if ($('.block.top').length && $('.block.top').hasClass('full-bleed')) {\n $('.block.full-bleed-ready').toggleClass('full-bleed-ready full-bleed');\n // Also enable 'full-bleed' for any appropriate 50/50 Banner blocks.\n $('#content > .layout.col2-50-50-fw').each(function () {\n if ($('.block.banner.full-bleed', $(this)).length === 2) {\n $(this).addClass('full-bleed');\n }\n });\n }\n\n // Flag if full-width block or multi-column layout after hero was handled.\n var postHeroProcessed = false;\n\n // Get a list of all non-empty layouts.\n // Empty layouts are still output and really mess up the below logic.\n var layouts = [];\n $('#content > .layout').each(function () {\n if ($(this).find('.block').length > 0) {\n layouts.push($(this));\n }\n });\n\n // Loop through our layouts and process desired block-to-block interactions\n for (var layout = 0; layout < layouts.length; layout++) {\n var lastLayout = layouts.length - 1;\n var $prevLayout = $(layouts[layout - 1]);\n var $thisLayout = $(layouts[layout]);\n var $nextLayout = $(layouts[layout + 1]);\n\n // Check if full-width single column layout\n if ($thisLayout.hasClass('col1')) {\n\n // Get list of all blocks in single-column layouts\n var blocks = $('.layout-col > .block', $thisLayout);\n for (var block = 0; block < blocks.length; block++) {\n var lastBlock = blocks.length - 1;\n var $prevBlock = $(blocks[block - 1]);\n var $thisBlock = $(blocks[block]);\n var $nextBlock = $(blocks[block + 1]);\n\n // Process top of the page - with or without a 'Hero' block\n var $heroBlock = $('.block.hero-cta.top');\n if (((layout === 0) && (block === 1) && (blocks.length > 1)) ||\n ((layout === 1) && (block === 0) && (!postHeroProcessed))) {\n // Need to see if there is even a 'Hero' placed on the page\n if ($heroBlock.length) {\n // Only image-based Hero should collapse bottom margin\n if ($heroBlock.hasClass('full-width') && $heroBlock.hasClass('allow-no-bottom-margin') && $thisBlock.hasClass('full-width')) {\n $thisBlock.toggleClass('allow-no-bottom-margin no-bottom-margin');\n }\n }\n // No 'Hero' at all, so need to reset any manually set rounding if applicable\n else {\n if ($thisBlock.hasClass('rounded-top')) {\n $thisBlock.removeClass('rounded-top');\n }\n else if ($thisBlock.hasClass('rounded-both')) {\n $thisBlock.removeClass('rounded-both').addClass('rounded-bottom');\n }\n }\n postHeroProcessed = true;\n }\n\n // Handle first block in each single-column layout on page...\n if (block === 0) {\n // Previous layout is also single-column, so dig down to first block (further processed later)\n if ($prevLayout.hasClass('col1')) {\n $prevBlock = $('.block:last-child', layouts[layout - 1]);\n }\n // Previous layout is not single-column, so add applicable class to layout if current block rounded\n else {\n if ($thisBlock.hasClass('rounded-both') || $thisBlock.hasClass('rounded-top')) {\n $prevLayout.addClass('rounded-block-below');\n }\n }\n }\n\n // Handle last block in each single-column layout on page...\n if (block === lastBlock) {\n // Last block in all layouts (except the last layout)\n if (layout < lastLayout) {\n // Next layout is also single-column, so dig down to first block (further processed later)\n if ($nextLayout.hasClass('col1')) {\n $nextBlock = $('.block:first-child', layouts[layout + 1]);\n }\n // Next layout is not single-column, so add applicable classes to layout if current block rounded etc.\n else {\n if ($thisBlock.hasClass('rounded-both') || $thisBlock.hasClass('rounded-bottom')) {\n $nextLayout.addClass('rounded-block-above');\n }\n }\n }\n // Last block in last layout (special treatment)\n else if (layout === lastLayout) {\n // Last block is rounded - remove 'gingerbread'\n if ($thisBlock.hasClass('rounded-both')) {\n $thisBlock.removeClass('rounded-both').addClass('rounded-top');\n }\n else if ($thisBlock.hasClass('rounded-bottom')) {\n $thisBlock.removeClass('rounded-bottom');\n }\n\n // Last block is full-width and does not have a white background - remove natural block whitespace\n if ($thisBlock.hasClass('full-width') &&\n ($thisBlock.children('.row').first().is(\"[class*='grad']\") ||\n $thisBlock.children('.row').first().css('backgroundColor') !== defaultBackgroundColor)) {\n $thisBlock.addClass('no-bottom-margin');\n }\n }\n }\n\n // Handle full-width block next to another full-width block\n // Might be able to handle this via CSS rather than JS (via 'full-width' class)...\n if ($thisBlock.hasClass('full-width') && $thisBlock.hasClass('allow-no-bottom-margin') && $nextBlock.hasClass('full-width')) {\n $thisBlock.toggleClass('allow-no-bottom-margin no-bottom-margin');\n }\n\n // Handle cases where rounded blocks are placed next to blocks\n // with same background color that introduces extra spacing...\n var prevBGColorMatch = matchingBGColor($thisBlock, $prevBlock);\n var nextBGColorMatch = matchingBGColor($thisBlock, $nextBlock);\n\n // Collapse space between if butted up against each other.\n if ($thisBlock.hasClass('no-bottom-margin') && nextBGColorMatch) {\n collapseWhitespace($thisBlock, $nextBlock);\n }\n\n if ($thisBlock.hasClass('rounded-both')) {\n if (prevBGColorMatch) {\n $thisBlock.removeClass('rounded-both').addClass('rounded-bottom');\n }\n else if (nextBGColorMatch) {\n $thisBlock.removeClass('rounded-both').addClass('rounded-top');\n collapseWhitespace($thisBlock, $nextBlock);\n }\n }\n\n if ($thisBlock.hasClass('rounded-top') && prevBGColorMatch) {\n $thisBlock.removeClass('rounded-top');\n }\n\n if ($thisBlock.hasClass('rounded-bottom') && nextBGColorMatch) {\n $thisBlock.removeClass('rounded-bottom');\n collapseWhitespace($thisBlock, $nextBlock);\n }\n\n // If a block is rounded on the bottom, but the next block is rounded\n // on the top, the block below takes precedence so adjust block above.\n if ($nextBlock.hasClass('rounded-both') || $nextBlock.hasClass('rounded-top')) {\n if ($thisBlock.hasClass('rounded-both')) {\n $thisBlock.removeClass('rounded-both').addClass('rounded-top');\n }\n else if ($thisBlock.hasClass('rounded-bottom')) {\n $thisBlock.removeClass('rounded-bottom');\n }\n }\n\n // Handle rounded block interactions (manually set in block by author)\n // by adding additional classes to adjust the internal block padding\n if ($thisBlock.hasClass('rounded-both')) {\n $prevBlock.addClass('rounded-block-below');\n $nextBlock.addClass('rounded-block-above');\n }\n else if ($thisBlock.hasClass('rounded-top')) {\n $prevBlock.addClass('rounded-block-below');\n }\n else if ($thisBlock.hasClass('rounded-bottom')) {\n $nextBlock.addClass('rounded-block-above');\n }\n }\n }\n\n // The 50/50 full-width layout (Twin Banner) requires special attention\n\n // Remove bottom margin if 50/50 is last layout on page\n if ($thisLayout.hasClass('col2-50-50-fw') && (layout === lastLayout)) {\n $thisLayout.addClass('no-bottom-margin');\n }\n\n // Check if current layout is full-width 50/50\n if ($thisLayout.hasClass('col2-50-50-fw')) {\n // If the first block of the next layout has a background color or image,\n // remove the bottom margin of current 50/50 layout if both child Banner\n // blocks have their 'Remove bottom margin' checkboxes checked.\n var $nextLayoutFirstBlock = $('.block:first-child', $nextLayout);\n if ($('.block.banner.allow-no-bottom-margin', $thisLayout).length >= 2 &&\n (($nextLayoutFirstBlock.children('.row').first().css('background-image') !== 'none') ||\n ($nextLayoutFirstBlock.children('.row').first().css('background-color') !== defaultBackgroundColor))) {\n $thisLayout.addClass('no-bottom-margin');\n }\n }\n\n // Check if next layout is full-width 50/50\n if ($nextLayout.hasClass('col2-50-50-fw')) {\n // If the last block of the current layout has a background color or image,\n // and has its 'Remove bottom margin' checkbox checked, remove the bottom\n // margin of the last block.\n var $thisLayoutLastBlock = $('.block:last-child', $thisLayout);\n if ($thisLayoutLastBlock.hasClass('allow-no-bottom-margin') &&\n (($thisLayoutLastBlock.children('.row').first().css('background-image') !== 'none') ||\n ($thisLayoutLastBlock.children('.row').first().css('background-color') !== defaultBackgroundColor))) {\n $thisLayoutLastBlock.toggleClass('allow-no-bottom-margin no-bottom-margin');\n }\n }\n }\n });\n\n})(jQuery);\n"]}