/** * Renders the script which contains the renderable popup's HTML code. * * Note: the HTML code can contain <script>...</script> tags, these are extracted and rendered separately. * * @param TrackableCampaignInterface $campaign * @param int $timeout * * @return string */ public function getScript(TrackableCampaignInterface $campaign, $timeout) { $rawPopupContents = $this->popupRenderer->render($campaign); $scriptExtractor = new ScriptExtractor($rawPopupContents); $scripts = $scriptExtractor->getExtractedScripts(); $contentWithoutScripts = $scriptExtractor->getHtmlWithoutScripts(); $wrappedContent = sprintf('<div id="%s" style="display: none;">%s</div>', self::WRAPPER_DIV_ID, $contentWithoutScripts); $jsEscapedWrappedContent = $this->escapeToValidJs($wrappedContent); $js = sprintf(' (function () { var tout = %s; $(document).ready(function() { $("body").append("' . $jsEscapedWrappedContent . '"); setTimeout(function() { if (!$.fancybox.isOpen) { $.fancybox.open({ href: "#' . self::WRAPPER_DIV_ID . '", }); } }, tout); }) }());', $timeout * 1000); $scripts[] = "<script>{$js}</script>"; return implode("\n", $scripts); }
/** * @return string * @throws PopupException */ public function renderAjaxPopup() { //TODO: check if request is an ajax call? if (!$this->popupInitiator->hasInitiatedAjaxPopup()) { throw new PopupException('Rendering of the popup via Ajax is not allowed. The PopupInitiator generated a script without an Ajax call.'); } $campaign = $this->campaignLoader->getTracked(); return $this->popupPresenter->render($campaign); }