From 4ac01cd0ea0a75f7a1517cd9b6760c0c26eff70c Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Mon, 29 Nov 2021 13:01:11 +0300 Subject: [PATCH 1/5] original embed.js(Vanillla 3.3) --- vanilla/js/embed.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 vanilla/js/embed.js diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js new file mode 100644 index 0000000..e69de29 From f5351e6c96645d48ca67906e33d530908f33bebc Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Mon, 29 Nov 2021 13:08:29 +0300 Subject: [PATCH 2/5] original embed.js(Vanillla 3.3) --- vanilla/js/embed.js | 369 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js index e69de29..f4a3526 100644 --- a/vanilla/js/embed.js +++ b/vanilla/js/embed.js @@ -0,0 +1,369 @@ +if (window.vanilla == undefined) + window.vanilla = {}; + +if (window.vanilla.embeds == undefined) + window.vanilla.embeds = {}; + +window.vanilla.embed = function(host) { + var scripts = document.getElementsByTagName('script'), + id = Math.floor((Math.random()) * 100000).toString(), + embedUrl = window.location.href.split('#')[0], + jsPath = '/js/embed.js', + currentPath = window.location.hash.substr(1), + disablePath = (window != top); + + var optStr = function(name, defaultValue, definedValue) { + if (window['vanilla_' + name]) { + if (definedValue == undefined) + return window['vanilla_' + name]; + else + return definedValue.replace('%s', window['vanilla_' + name]); + } + return defaultValue; + } + + if (!currentPath || disablePath) + currentPath = "/"; + + if (currentPath.substr(0, 1) != '/') + currentPath = '/' + currentPath; + + if (window.gadgets) + embedUrl = ''; + + if (typeof(host) == 'undefined') { + host = ''; + host_base_url = ''; + for (i = 0; i < scripts.length; i++) { + if (scripts[i].src.indexOf(jsPath) > 0) { + host = scripts[i].src; + host = host.replace('http://', '').replace('https://', ''); + host = host.substr(0, host.indexOf(jsPath)); + + host_base_url = scripts[i].src; + host_base_url = host_base_url.substr(0, host_base_url.indexOf(jsPath)); + if (host_base_url.substring(host_base_url.length - 1) != '/') + host_base_url += '/'; + + } + } + } + + window.vanilla.embeds[id] = this; + if (window.postMessage) { + onMessage = function(e) { + // Check that we're getting a vanilla message + if ((typeof e.data) === 'string') { + var message = e.data.split(':'); + var frame = document.getElementById('vanilla' + id); + + // Unload event's source is undefined + var isUnload = message[0] == 'unload'; + if (!frame || (!isUnload && frame.contentWindow != e.source)) { + return; + } + processMessage(message); + } + }; + if (window.addEventListener) { + window.addEventListener("message", onMessage, false); + } else { + window.attachEvent("onmessage", onMessage); + } + } else { + var messageId = null; + setInterval(function() { + try { + var vid = 'vanilla' + id; + var hash = window.frames[vid].frames['messageFrame'].location.hash; + hash = hash.substr(6); + } catch (e) { + return; + } + + var message = hash.split(':'); + var newMessageId = message[0]; + if (newMessageId == messageId) { + return; + } + + messageId = newMessageId; + message.splice(0, 1); + processMessage(message); + }, 200); + } + + checkHash = function() { + var path = window.location.hash.substr(1) || "/"; + if (path != currentPath) { + currentPath = path; + window.frames['vanilla' + id].location.replace(vanillaUrl(path)); + } + }; + + if (!window.gadgets) { + if (!disablePath) { + if ("onhashchange" in window) { + if (window.addEventListener) + window.addEventListener("hashchange", checkHash, false); + else + window.attachEvent("onhashchange", checkHash); + } else { + setInterval(checkHash, 300); + } + } + } + + // Strip param out of str if it exists + stripParam = function(str, param) { + var pIndex = str.indexOf(param); + if (pIndex > -1) { + var pStr = str.substr(pIndex); + var tIndex = pStr.indexOf('&'); + var trail = tIndex > -1 ? pStr.substr(tIndex + 1) : ''; + var pre = currentPath.substr(pIndex - 1, 1); + if (pre == '&' || pre == '?') + pIndex--; + + return str.substr(0, pIndex) + (trail.length > 0 ? pre : '') + trail; + } + return str; + } + + processMessage = function(message) { + var iframe = document.getElementById('vanilla' + id); + + if (message[0] == 'height') { + // setHeight(message[1]); + setHeight(screen.height-document.getElementById("vanilla-comments").offsetTop) + + if (message[1] > 0) { + iframe.style.visibility = "visible"; + } + + } else if (message[0] == 'location') { + + if (message[1] != '') { + iframe.style.visibility = "visible"; + } + + if (disablePath) { + //currentPath = cmd[1]; + } else { + currentPath = window.location.hash.substr(1); + if (currentPath != message[1]) { + currentPath = message[1]; + // Strip off the values that this script added + currentPath = stripParam(currentPath, 'remote='); // 1 + currentPath = stripParam(currentPath, 'locale='); // 2 + window.location.hash = currentPath; + } + } + } else if (message[0] == 'unload') { + // Scroll to the top of the IFRAME if the top position is not in the view. + var currentScrollAmount = (window.pageYOffset || document.documentElement.scrollTop); + var offsetTop = offsetFromTop('vanilla' + id); + if (offsetTop - currentScrollAmount < 0) { + window.scrollTo(0, offsetTop); + } + + iframe.style.visibility = "hidden"; + + } else if (message[0] == 'scrolltop') { + window.scrollTo(0, document.getElementById('vanilla' + id).offsetTop); + } else if (message[0] == 'scrollto') { + window.scrollTo(0, document.getElementById('vanilla' + id).offsetTop - 40 + (message[1] * 1)); + } else if (message[0] == 'unembed') { + document.location = 'http://' + host + window.location.hash.substr(1); + } + } + + offsetFromTop = function(id) { + var node = document.getElementById(id), + top = 0, + topScroll = 0; + if (node.offsetParent) { + do { + top += node.offsetTop; + topScroll += node.offsetParent ? node.offsetParent.scrollTop : 0; + } while (node = node.offsetParent); + return top - topScroll; + } + return -1; + } + + setHeight = function(height) { + if (optStr('height')) + return; + + document.getElementById('vanilla' + id).style['height'] = height + "px"; + if (window.gadgets && gadgets.window && gadgets.window.adjustHeight) { + try { + gadgets.window.adjustHeight(); + } catch (ex) { + // Do nothing... + } + } + } + + vanillaUrl = function(path) { + // What type of embed are we performing? + var embed_type = typeof(vanilla_embed_type) == 'undefined' ? 'standard' : vanilla_embed_type; + // Are we loading a particular discussion based on discussion_id? + var discussion_id = typeof(vanilla_discussion_id) == 'undefined' ? 0 : vanilla_discussion_id; + // Are we loading a particular discussion based on foreign_id? + var foreign_id = typeof(vanilla_identifier) == 'undefined' ? '' : vanilla_identifier; + // Is there a foreign type defined? Possibly used to render the discussion + // body a certain way in the forum? Also used to filter down to foreign + // types so that matching foreign_id's across type don't clash. + var foreign_type = typeof(vanilla_type) == 'undefined' ? 'page' : vanilla_type; + // If embedding comments, should the newly created discussion be placed in a specific category? + var category_id = typeof(vanilla_category_id) == 'undefined' ? '' : vanilla_category_id; + // If embedding comments, this value will be used to reference the foreign content. Defaults to the url of the page this file is included in. + var foreign_url = typeof(vanilla_url) == 'undefined' ? document.URL.split('#')[0] : vanilla_url; + // Are we forcing a locale via Multilingual plugin? + var embed_locale = typeof(vanilla_embed_locale) == 'undefined' ? '' : vanilla_embed_locale; + if (typeof(vanilla_lazy_load) == 'undefined') + vanilla_lazy_load = true; + + // If path was defined, and we're sitting at app root, use the defined path instead. + if (typeof(vanilla_path) != 'undefined' && path == '/') + path = vanilla_path; + + // Force type based on incoming variables + if (discussion_id != '' || foreign_id != '') + embed_type = 'comments'; + + var result = ''; + + if (embed_type == 'comments') { + result = '//' + host + '/discussion/embed/' + // Break the cache. /embed/ gets cached, looks like you are not logged in. + + '&c=' + new Date().getTime() + + '&vanilla_identifier=' + encodeURIComponent(foreign_id) + + '&vanilla_url=' + encodeURIComponent(foreign_url); + + if (typeof(vanilla_type) != 'undefined') + result += '&vanilla_type=' + encodeURIComponent(vanilla_type) + + if (typeof(vanilla_discussion_id) != 'undefined') + result += '&vanilla_discussion_id=' + encodeURIComponent(vanilla_discussion_id); + + if (typeof(vanilla_category_id) != 'undefined') + result += '&vanilla_category_id=' + encodeURIComponent(vanilla_category_id); + + if (typeof(vanilla_title) != 'undefined') + result += '&title=' + encodeURIComponent(vanilla_title); + } else { + result = '//' + + host + + path + + '&remote=' + + encodeURIComponent(embedUrl) + + '&locale=' + + encodeURIComponent(embed_locale); + } + + if (window.vanilla_sso) { + result += '&sso=' + encodeURIComponent(vanilla_sso); + } + + return result.replace(/\?/g, '&').replace('&', '?'); // Replace the first occurrence of amp with question. + } + var vanillaIframe = document.createElement('iframe'); + vanillaIframe.id = "vanilla" + id; + vanillaIframe.name = "vanilla" + id; + vanillaIframe.src = vanillaUrl(currentPath); + //vanillaIframe.scrolling = "no"; + vanillaIframe.scrolling = "yes"; + vanillaIframe.frameBorder = "0"; + vanillaIframe.allowTransparency = true; + vanillaIframe.border = "0"; + vanillaIframe.width = "100%"; + vanillaIframe.style.width = "100%"; + vanillaIframe.style.border = "0"; + vanillaIframe.style.display = "block"; // must be block + + if (window.postMessage) { + vanillaIframe.height = "0"; + vanillaIframe.style.height = "0"; + } else { + vanillaIframe.height = "300"; + vanillaIframe.style.height = "300px"; + } + + + var img = document.createElement('div'); + img.className = 'vn-loading'; + img.style.textAlign = 'center'; + img.innerHTML = window.vanilla_loadinghtml ? vanilla_loadinghtml : ''; + + var container = document.getElementById('vanilla-comments'); + // Couldn't find the container, so dump it out and try again. + if (!container) + document.write('
'); + container = document.getElementById('vanilla-comments'); + + if (container) { + var loaded = function() { + if (img) { + container.removeChild(img); + img = null; + } + vanillaIframe.style.visibility = "visible"; + }; + + if (vanillaIframe.addEventListener) { + vanillaIframe.addEventListener('load', loaded, true); + } else if (vanillaIframe.attachEvent) { + vanillaIframe.attachEvent('onload', loaded); + } else + setTimeout(2000, loaded); + + container.appendChild(img); + + // If jQuery is present in the page, include our defer-until-visible script + if (vanilla_lazy_load && typeof jQuery != 'undefined') { + jQuery.ajax({ + url: host_base_url + 'js/library/jquery.appear.js', + dataType: 'script', + cache: true, + success: function() { +// setTimeout(function() { + + if (jQuery.fn.appear) + jQuery('#vanilla-comments').appear(function() { + container.appendChild(vanillaIframe); + }); + else + container.appendChild(vanillaIframe); // fallback +// }, 10000); + } + }); + } else { + container.appendChild(vanillaIframe); // fallback: just load it + } + } + + // Include our embed css into the page + var vanilla_embed_css = document.createElement('link'); + vanilla_embed_css.rel = 'stylesheet'; + vanilla_embed_css.type = 'text/css'; + vanilla_embed_css.href = host_base_url + (host_base_url.substring(host_base_url.length - 1) == '/' ? '' : '/') + 'applications/dashboard/design/embed.css'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(vanilla_embed_css); + + return this; +}; +try { + if (window.location.hash.substr(0, 6) != "#poll:") + window.vanilla.embed(); +} catch (e) { + var error = document.createElement('div'); + error.style.padding = "10px"; + error.style.fontSize = "12px"; + error.style.fontFamily = "lucida grande"; + error.style.background = "#ffffff"; + error.style.color = "#000000"; + error.appendChild(document.createTextNode("Failed to embed Vanilla: " + e)); + (document.getElementById('vanilla-comments')).appendChild(error); +} From 769821bf08aba157d0343234956628d399e89845 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Mon, 29 Nov 2021 13:10:57 +0300 Subject: [PATCH 3/5] Issues-6 (mfe-forums-app): fixed body height --- vanilla/js/embed.js | 690 +++++++++++++++++++++++--------------------- 1 file changed, 359 insertions(+), 331 deletions(-) diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js index f4a3526..3050303 100644 --- a/vanilla/js/embed.js +++ b/vanilla/js/embed.js @@ -1,369 +1,397 @@ -if (window.vanilla == undefined) - window.vanilla = {}; - -if (window.vanilla.embeds == undefined) - window.vanilla.embeds = {}; - -window.vanilla.embed = function(host) { - var scripts = document.getElementsByTagName('script'), - id = Math.floor((Math.random()) * 100000).toString(), - embedUrl = window.location.href.split('#')[0], - jsPath = '/js/embed.js', - currentPath = window.location.hash.substr(1), - disablePath = (window != top); - - var optStr = function(name, defaultValue, definedValue) { - if (window['vanilla_' + name]) { - if (definedValue == undefined) - return window['vanilla_' + name]; - else - return definedValue.replace('%s', window['vanilla_' + name]); - } - return defaultValue; - } - - if (!currentPath || disablePath) - currentPath = "/"; +/* eslint-disable */ +export default () => { + if (window.vanilla == undefined) window.vanilla = {}; + window.vanilla_lazy_load = undefined + + if (window.vanilla.embeds == undefined) window.vanilla.embeds = {}; + + window.vanilla.embed = function (host) { + var scripts = document.getElementsByTagName("script"), + id = Math.floor(Math.random() * 100000).toString(), + embedUrl = window.location.href.split("#")[0], + jsPath = "/js/embed.js", + currentPath = window.location.hash.substr(1), + disablePath = window != top; + + var optStr = function (name, defaultValue, definedValue) { + if (window["vanilla_" + name]) { + if (definedValue == undefined) return window["vanilla_" + name]; + else return definedValue.replace("%s", window["vanilla_" + name]); + } + return defaultValue; + }; - if (currentPath.substr(0, 1) != '/') - currentPath = '/' + currentPath; + if (!currentPath || disablePath) currentPath = "/"; - if (window.gadgets) - embedUrl = ''; + if (currentPath.substr(0, 1) != "/") currentPath = "/" + currentPath; - if (typeof(host) == 'undefined') { - host = ''; - host_base_url = ''; - for (i = 0; i < scripts.length; i++) { - if (scripts[i].src.indexOf(jsPath) > 0) { - host = scripts[i].src; - host = host.replace('http://', '').replace('https://', ''); - host = host.substr(0, host.indexOf(jsPath)); + if (window.gadgets) embedUrl = ""; - host_base_url = scripts[i].src; - host_base_url = host_base_url.substr(0, host_base_url.indexOf(jsPath)); - if (host_base_url.substring(host_base_url.length - 1) != '/') - host_base_url += '/'; + if (typeof host == "undefined") { + host = ""; + window.host_base_url = ""; + for (var i = 0; i < scripts.length; i++) { + if (scripts[i].src.indexOf(jsPath) > 0) { + host = scripts[i].src; + host = host.replace("http://", "").replace("https://", ""); + host = host.substr(0, host.indexOf(jsPath)); + host_base_url = scripts[i].src; + host_base_url = host_base_url.substr( + 0, + host_base_url.indexOf(jsPath) + ); + if (host_base_url.substring(host_base_url.length - 1) != "/") + host_base_url += "/"; + } } } - } - window.vanilla.embeds[id] = this; - if (window.postMessage) { - onMessage = function(e) { - // Check that we're getting a vanilla message - if ((typeof e.data) === 'string') { - var message = e.data.split(':'); - var frame = document.getElementById('vanilla' + id); - - // Unload event's source is undefined - var isUnload = message[0] == 'unload'; - if (!frame || (!isUnload && frame.contentWindow != e.source)) { - return; + window.vanilla.embeds[id] = this; + if (window.postMessage) { + var onMessage = function (e) { + console.log("---- message ----", e); + + // Check that we're getting a vanilla message + if (typeof e.data === "string") { + var message = e.data.split(":"); + var frame = document.getElementById("vanilla" + id); + + // Unload event's source is undefined + var isUnload = message[0] == "unload"; + if (!frame || (!isUnload && frame.contentWindow != e.source)) { + return; + } + processMessage(message); } - processMessage(message); + }; + if (window.addEventListener) { + window.addEventListener("message", onMessage, false); + } else { + window.attachEvent("onmessage", onMessage); } - }; - if (window.addEventListener) { - window.addEventListener("message", onMessage, false); } else { - window.attachEvent("onmessage", onMessage); + var messageId = null; + setInterval(function () { + try { + var vid = "vanilla" + id; + var hash = window.frames[vid].frames["messageFrame"].location.hash; + hash = hash.substr(6); + } catch (e) { + return; + } + + var message = hash.split(":"); + var newMessageId = message[0]; + if (newMessageId == messageId) { + return; + } + + messageId = newMessageId; + message.splice(0, 1); + processMessage(message); + }, 200); } - } else { - var messageId = null; - setInterval(function() { - try { - var vid = 'vanilla' + id; - var hash = window.frames[vid].frames['messageFrame'].location.hash; - hash = hash.substr(6); - } catch (e) { - return; - } - var message = hash.split(':'); - var newMessageId = message[0]; - if (newMessageId == messageId) { - return; + const checkHash = function () { + debugger; + var path = window.location.hash.substr(1) || "/"; + if (path != currentPath) { + currentPath = path; + window.frames["vanilla" + id].location.replace(vanillaUrl(path)); } + }; - messageId = newMessageId; - message.splice(0, 1); - processMessage(message); - }, 200); - } - - checkHash = function() { - var path = window.location.hash.substr(1) || "/"; - if (path != currentPath) { - currentPath = path; - window.frames['vanilla' + id].location.replace(vanillaUrl(path)); + if (!window.gadgets) { + if (!disablePath) { + if ("onhashchange" in window) { + if (window.addEventListener) + window.addEventListener("hashchange", checkHash, false); + else window.attachEvent("onhashchange", checkHash); + } else { + setInterval(checkHash, 300); + } + } } - }; - if (!window.gadgets) { - if (!disablePath) { - if ("onhashchange" in window) { - if (window.addEventListener) - window.addEventListener("hashchange", checkHash, false); - else - window.attachEvent("onhashchange", checkHash); - } else { - setInterval(checkHash, 300); + // Strip param out of str if it exists + const stripParam = function (str, param) { + var pIndex = str.indexOf(param); + if (pIndex > -1) { + var pStr = str.substr(pIndex); + var tIndex = pStr.indexOf("&"); + var trail = tIndex > -1 ? pStr.substr(tIndex + 1) : ""; + var pre = currentPath.substr(pIndex - 1, 1); + if (pre == "&" || pre == "?") pIndex--; + + return str.substr(0, pIndex) + (trail.length > 0 ? pre : "") + trail; } - } - } + return str; + }; - // Strip param out of str if it exists - stripParam = function(str, param) { - var pIndex = str.indexOf(param); - if (pIndex > -1) { - var pStr = str.substr(pIndex); - var tIndex = pStr.indexOf('&'); - var trail = tIndex > -1 ? pStr.substr(tIndex + 1) : ''; - var pre = currentPath.substr(pIndex - 1, 1); - if (pre == '&' || pre == '?') - pIndex--; - - return str.substr(0, pIndex) + (trail.length > 0 ? pre : '') + trail; - } - return str; - } + const processMessage = function (message) { + var iframe = document.getElementById("vanilla" + id); - processMessage = function(message) { - var iframe = document.getElementById('vanilla' + id); + if (message[0] == "height") { + setHeight(message[1]); - if (message[0] == 'height') { - // setHeight(message[1]); - setHeight(screen.height-document.getElementById("vanilla-comments").offsetTop) + if (message[1] > 0) { + iframe.style.visibility = "visible"; + } + } else if (message[0] == "location") { + if (message[1] != "") { + iframe.style.visibility = "visible"; + } - if (message[1] > 0) { - iframe.style.visibility = "visible"; - } + if (disablePath) { + //currentPath = cmd[1]; + } else { + currentPath = window.location.hash.substr(1); + if (currentPath != message[1]) { + currentPath = message[1]; + // Strip off the values that this script added + currentPath = stripParam(currentPath, "remote="); // 1 + currentPath = stripParam(currentPath, "locale="); // 2 + //window.location.hash = currentPath; + } + } + } else if (message[0] == "unload") { + // Scroll to the top of the IFRAME if the top position is not in the view. + var currentScrollAmount = + window.pageYOffset || document.documentElement.scrollTop; + var offsetTop = offsetFromTop("vanilla" + id); + if (offsetTop - currentScrollAmount < 0) { + window.scrollTo(0, offsetTop); + } - } else if (message[0] == 'location') { + iframe.style.visibility = "hidden"; + } else if (message[0] == "scrolltop") { + window.scrollTo(0, document.getElementById("vanilla" + id).offsetTop); + } else if (message[0] == "scrollto") { + window.scrollTo( + 0, + document.getElementById("vanilla" + id).offsetTop - + 40 + + message[1] * 1 + ); + } else if (message[0] == "unembed") { + document.location = "http://" + host + window.location.hash.substr(1); + } + }; - if (message[1] != '') { - iframe.style.visibility = "visible"; + const offsetFromTop = function (id) { + var node = document.getElementById(id), + top = 0, + topScroll = 0; + if (node.offsetParent) { + do { + top += node.offsetTop; + topScroll += node.offsetParent ? node.offsetParent.scrollTop : 0; + } while ((node = node.offsetParent)); + return top - topScroll; } + return -1; + }; - if (disablePath) { - //currentPath = cmd[1]; - } else { - currentPath = window.location.hash.substr(1); - if (currentPath != message[1]) { - currentPath = message[1]; - // Strip off the values that this script added - currentPath = stripParam(currentPath, 'remote='); // 1 - currentPath = stripParam(currentPath, 'locale='); // 2 - window.location.hash = currentPath; + const setHeight = function (height) { + if (optStr("height")) return; + // if (document.getElementById("vanilla" + id).style["height"] === ( height - 21 ) + 'px') { + // return + // } + + // document.getElementById("vanilla" + id).style["height"] = height + "px"; + document.getElementById("vanilla" + id).style["height"] = 'calc(100vh - 76px)' + if (window.gadgets && gadgets.window && gadgets.window.adjustHeight) { + try { + gadgets.window.adjustHeight(); + } catch (ex) { + // Do nothing... } } - } else if (message[0] == 'unload') { - // Scroll to the top of the IFRAME if the top position is not in the view. - var currentScrollAmount = (window.pageYOffset || document.documentElement.scrollTop); - var offsetTop = offsetFromTop('vanilla' + id); - if (offsetTop - currentScrollAmount < 0) { - window.scrollTo(0, offsetTop); - } - - iframe.style.visibility = "hidden"; - - } else if (message[0] == 'scrolltop') { - window.scrollTo(0, document.getElementById('vanilla' + id).offsetTop); - } else if (message[0] == 'scrollto') { - window.scrollTo(0, document.getElementById('vanilla' + id).offsetTop - 40 + (message[1] * 1)); - } else if (message[0] == 'unembed') { - document.location = 'http://' + host + window.location.hash.substr(1); - } - } - - offsetFromTop = function(id) { - var node = document.getElementById(id), - top = 0, - topScroll = 0; - if (node.offsetParent) { - do { - top += node.offsetTop; - topScroll += node.offsetParent ? node.offsetParent.scrollTop : 0; - } while (node = node.offsetParent); - return top - topScroll; - } - return -1; - } + }; - setHeight = function(height) { - if (optStr('height')) - return; + const vanillaUrl = function (path) { + // What type of embed are we performing? + var embed_type = + typeof vanilla_embed_type == "undefined" + ? "standard" + : vanilla_embed_type; + // Are we loading a particular discussion based on discussion_id? + var discussion_id = + typeof vanilla_discussion_id == "undefined" ? 0 : vanilla_discussion_id; + // Are we loading a particular discussion based on foreign_id? + var foreign_id = + typeof vanilla_identifier == "undefined" ? "" : vanilla_identifier; + // Is there a foreign type defined? Possibly used to render the discussion + // body a certain way in the forum? Also used to filter down to foreign + // types so that matching foreign_id's across type don't clash. + var foreign_type = + typeof vanilla_type == "undefined" ? "page" : vanilla_type; + // If embedding comments, should the newly created discussion be placed in a specific category? + var category_id = + typeof vanilla_category_id == "undefined" ? "" : vanilla_category_id; + // If embedding comments, this value will be used to reference the foreign content. Defaults to the url of the page this file is included in. + var foreign_url = + typeof vanilla_url == "undefined" + ? document.URL.split("#")[0] + : vanilla_url; + // Are we forcing a locale via Multilingual plugin? + var embed_locale = + typeof vanilla_embed_locale == "undefined" ? "" : vanilla_embed_locale; + if (typeof vanilla_lazy_load == "undefined") vanilla_lazy_load = true; + + // If path was defined, and we're sitting at app root, use the defined path instead. + if (typeof vanilla_path != "undefined" && path == "/") + path = vanilla_path; + + // Force type based on incoming variables + if (discussion_id != "" || foreign_id != "") embed_type = "comments"; + + var result = ""; + + if (embed_type == "comments") { + result = + "//" + + host + + "/discussion/embed/" + + // Break the cache. /embed/ gets cached, looks like you are not logged in. + "&c=" + + new Date().getTime() + + "&vanilla_identifier=" + + encodeURIComponent(foreign_id) + + "&vanilla_url=" + + encodeURIComponent(foreign_url); + + if (typeof vanilla_type != "undefined") + result += "&vanilla_type=" + encodeURIComponent(vanilla_type); + + if (typeof vanilla_discussion_id != "undefined") + result += + "&vanilla_discussion_id=" + + encodeURIComponent(vanilla_discussion_id); + + if (typeof vanilla_category_id != "undefined") + result += + "&vanilla_category_id=" + encodeURIComponent(vanilla_category_id); + + if (typeof vanilla_title != "undefined") + result += "&title=" + encodeURIComponent(vanilla_title); + } else { + result = + "//" + + host + + path + + "&remote=" + + encodeURIComponent(embedUrl) + + "&locale=" + + encodeURIComponent(embed_locale); + } - document.getElementById('vanilla' + id).style['height'] = height + "px"; - if (window.gadgets && gadgets.window && gadgets.window.adjustHeight) { - try { - gadgets.window.adjustHeight(); - } catch (ex) { - // Do nothing... + if (window.vanilla_sso) { + result += "&sso=" + encodeURIComponent(vanilla_sso); } - } - } - vanillaUrl = function(path) { - // What type of embed are we performing? - var embed_type = typeof(vanilla_embed_type) == 'undefined' ? 'standard' : vanilla_embed_type; - // Are we loading a particular discussion based on discussion_id? - var discussion_id = typeof(vanilla_discussion_id) == 'undefined' ? 0 : vanilla_discussion_id; - // Are we loading a particular discussion based on foreign_id? - var foreign_id = typeof(vanilla_identifier) == 'undefined' ? '' : vanilla_identifier; - // Is there a foreign type defined? Possibly used to render the discussion - // body a certain way in the forum? Also used to filter down to foreign - // types so that matching foreign_id's across type don't clash. - var foreign_type = typeof(vanilla_type) == 'undefined' ? 'page' : vanilla_type; - // If embedding comments, should the newly created discussion be placed in a specific category? - var category_id = typeof(vanilla_category_id) == 'undefined' ? '' : vanilla_category_id; - // If embedding comments, this value will be used to reference the foreign content. Defaults to the url of the page this file is included in. - var foreign_url = typeof(vanilla_url) == 'undefined' ? document.URL.split('#')[0] : vanilla_url; - // Are we forcing a locale via Multilingual plugin? - var embed_locale = typeof(vanilla_embed_locale) == 'undefined' ? '' : vanilla_embed_locale; - if (typeof(vanilla_lazy_load) == 'undefined') - vanilla_lazy_load = true; - - // If path was defined, and we're sitting at app root, use the defined path instead. - if (typeof(vanilla_path) != 'undefined' && path == '/') - path = vanilla_path; - - // Force type based on incoming variables - if (discussion_id != '' || foreign_id != '') - embed_type = 'comments'; - - var result = ''; - - if (embed_type == 'comments') { - result = '//' + host + '/discussion/embed/' - // Break the cache. /embed/ gets cached, looks like you are not logged in. - + '&c=' + new Date().getTime() - + '&vanilla_identifier=' + encodeURIComponent(foreign_id) - + '&vanilla_url=' + encodeURIComponent(foreign_url); - - if (typeof(vanilla_type) != 'undefined') - result += '&vanilla_type=' + encodeURIComponent(vanilla_type) - - if (typeof(vanilla_discussion_id) != 'undefined') - result += '&vanilla_discussion_id=' + encodeURIComponent(vanilla_discussion_id); - - if (typeof(vanilla_category_id) != 'undefined') - result += '&vanilla_category_id=' + encodeURIComponent(vanilla_category_id); - - if (typeof(vanilla_title) != 'undefined') - result += '&title=' + encodeURIComponent(vanilla_title); + return result.replace(/\?/g, "&").replace("&", "?"); // Replace the first occurrence of amp with question. + }; + var vanillaIframe = document.createElement("iframe"); + vanillaIframe.id = "vanilla" + id; + vanillaIframe.name = "vanilla" + id; + vanillaUrl(currentPath); + vanillaIframe.src = + "https://vanilla.topcoder-dev.com/?remote=https://local.topcoder-dev.com/forums&locale="; + vanillaIframe.scrolling = "yes"; + vanillaIframe.frameBorder = "0"; + vanillaIframe.allowTransparency = true; + vanillaIframe.border = "0"; + vanillaIframe.width = "100%"; + vanillaIframe.style.width = "100%"; + vanillaIframe.style.border = "0"; + vanillaIframe.style.display = "block"; // must be block + + if (window.postMessage) { + vanillaIframe.height = "0"; + vanillaIframe.style.height = "0"; } else { - result = '//' - + host - + path - + '&remote=' - + encodeURIComponent(embedUrl) - + '&locale=' - + encodeURIComponent(embed_locale); + vanillaIframe.height = "300"; + vanillaIframe.style.height = "300px"; } - if (window.vanilla_sso) { - result += '&sso=' + encodeURIComponent(vanilla_sso); - } - - return result.replace(/\?/g, '&').replace('&', '?'); // Replace the first occurrence of amp with question. - } - var vanillaIframe = document.createElement('iframe'); - vanillaIframe.id = "vanilla" + id; - vanillaIframe.name = "vanilla" + id; - vanillaIframe.src = vanillaUrl(currentPath); - //vanillaIframe.scrolling = "no"; - vanillaIframe.scrolling = "yes"; - vanillaIframe.frameBorder = "0"; - vanillaIframe.allowTransparency = true; - vanillaIframe.border = "0"; - vanillaIframe.width = "100%"; - vanillaIframe.style.width = "100%"; - vanillaIframe.style.border = "0"; - vanillaIframe.style.display = "block"; // must be block - - if (window.postMessage) { - vanillaIframe.height = "0"; - vanillaIframe.style.height = "0"; - } else { - vanillaIframe.height = "300"; - vanillaIframe.style.height = "300px"; - } - - - var img = document.createElement('div'); - img.className = 'vn-loading'; - img.style.textAlign = 'center'; - img.innerHTML = window.vanilla_loadinghtml ? vanilla_loadinghtml : ''; - - var container = document.getElementById('vanilla-comments'); - // Couldn't find the container, so dump it out and try again. - if (!container) - document.write('
'); - container = document.getElementById('vanilla-comments'); - - if (container) { - var loaded = function() { - if (img) { - container.removeChild(img); - img = null; - } - vanillaIframe.style.visibility = "visible"; - }; - - if (vanillaIframe.addEventListener) { - vanillaIframe.addEventListener('load', loaded, true); - } else if (vanillaIframe.attachEvent) { - vanillaIframe.attachEvent('onload', loaded); - } else - setTimeout(2000, loaded); - - container.appendChild(img); - - // If jQuery is present in the page, include our defer-until-visible script - if (vanilla_lazy_load && typeof jQuery != 'undefined') { - jQuery.ajax({ - url: host_base_url + 'js/library/jquery.appear.js', - dataType: 'script', - cache: true, - success: function() { -// setTimeout(function() { - - if (jQuery.fn.appear) - jQuery('#vanilla-comments').appear(function() { - container.appendChild(vanillaIframe); - }); - else - container.appendChild(vanillaIframe); // fallback -// }, 10000); + var img = document.createElement("div"); + img.className = "vn-loading"; + img.style.textAlign = "center"; + img.innerHTML = window.vanilla_loadinghtml + ? vanilla_loadinghtml + : ''; + + var container = document.getElementById("vanilla-comments"); + // Couldn't find the container, so dump it out and try again. + if (!container) document.write('
'); + container = document.getElementById("vanilla-comments"); + + if (container) { + var loaded = function () { + if (img) { + container.removeChild(img); + img = null; } - }); - } else { - container.appendChild(vanillaIframe); // fallback: just load it + vanillaIframe.style.visibility = "visible"; + }; + + if (vanillaIframe.addEventListener) { + vanillaIframe.addEventListener("load", loaded, true); + } else if (vanillaIframe.attachEvent) { + vanillaIframe.attachEvent("onload", loaded); + } else setTimeout(2000, loaded); + + container.appendChild(img); + + // If jQuery is present in the page, include our defer-until-visible script + if (vanilla_lazy_load && typeof jQuery != "undefined") { + jQuery.ajax({ + url: host_base_url + "js/library/jquery.appear.js", + dataType: "script", + cache: true, + success: function () { + // setTimeout(function() { + + if (jQuery.fn.appear) + jQuery("#vanilla-comments").appear(function () { + container.appendChild(vanillaIframe); + }); + else container.appendChild(vanillaIframe); // fallback + // }, 10000); + }, + }); + } else { + container.appendChild(vanillaIframe); // fallback: just load it + } } - } - // Include our embed css into the page - var vanilla_embed_css = document.createElement('link'); - vanilla_embed_css.rel = 'stylesheet'; - vanilla_embed_css.type = 'text/css'; - vanilla_embed_css.href = host_base_url + (host_base_url.substring(host_base_url.length - 1) == '/' ? '' : '/') + 'applications/dashboard/design/embed.css'; - (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(vanilla_embed_css); - - return this; -}; -try { - if (window.location.hash.substr(0, 6) != "#poll:") - window.vanilla.embed(); -} catch (e) { - var error = document.createElement('div'); - error.style.padding = "10px"; - error.style.fontSize = "12px"; - error.style.fontFamily = "lucida grande"; - error.style.background = "#ffffff"; - error.style.color = "#000000"; - error.appendChild(document.createTextNode("Failed to embed Vanilla: " + e)); - (document.getElementById('vanilla-comments')).appendChild(error); -} + // Include our embed css into the page + var vanilla_embed_css = document.createElement("link"); + vanilla_embed_css.rel = "stylesheet"; + vanilla_embed_css.type = "text/css"; + vanilla_embed_css.href = + host_base_url + + (host_base_url.substring(host_base_url.length - 1) == "/" ? "" : "/") + + "applications/dashboard/design/embed.css"; + ( + document.getElementsByTagName("head")[0] || + document.getElementsByTagName("body")[0] + ).appendChild(vanilla_embed_css); + + return this; + }; + try { + if (window.location.hash.substr(0, 6) != "#poll:") window.vanilla.embed(); + } catch (e) { + var error = document.createElement("div"); + error.style.padding = "10px"; + error.style.fontSize = "12px"; + error.style.fontFamily = "lucida grande"; + error.style.background = "#ffffff"; + error.style.color = "#000000"; + error.appendChild(document.createTextNode("Failed to embed Vanilla: " + e)); + document.getElementById("vanilla-comments").appendChild(error); + } +}; \ No newline at end of file From c6d3c6dbd511201ac969836d6b6bc07f4099b62b Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Mon, 29 Nov 2021 13:20:15 +0300 Subject: [PATCH 4/5] Issues-6 (mfe-forums-app): fixed body height --- vanilla/js/embed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js index 3050303..0f5bb93 100644 --- a/vanilla/js/embed.js +++ b/vanilla/js/embed.js @@ -1,5 +1,5 @@ /* eslint-disable */ -export default () => { +//export default () => { if (window.vanilla == undefined) window.vanilla = {}; window.vanilla_lazy_load = undefined @@ -394,4 +394,4 @@ export default () => { error.appendChild(document.createTextNode("Failed to embed Vanilla: " + e)); document.getElementById("vanilla-comments").appendChild(error); } -}; \ No newline at end of file +//}; \ No newline at end of file From 01a4d41356455d7ce108d816782e22299c7b87da Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Mon, 29 Nov 2021 13:33:14 +0300 Subject: [PATCH 5/5] Issues-6 (mfe-forums-app): fixed hard-coded values --- vanilla/js/embed.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vanilla/js/embed.js b/vanilla/js/embed.js index 0f5bb93..4811adf 100644 --- a/vanilla/js/embed.js +++ b/vanilla/js/embed.js @@ -297,8 +297,7 @@ vanillaIframe.id = "vanilla" + id; vanillaIframe.name = "vanilla" + id; vanillaUrl(currentPath); - vanillaIframe.src = - "https://vanilla.topcoder-dev.com/?remote=https://local.topcoder-dev.com/forums&locale="; + //vanillaIframe.src = "https://vanilla.topcoder-dev.com/?remote=https://local.topcoder-dev.com/forums&locale="; vanillaIframe.scrolling = "yes"; vanillaIframe.frameBorder = "0"; vanillaIframe.allowTransparency = true;