acrolinx-sidebar-sdk
Advanced tools
Comparing version 0.4.12 to 0.4.13
@@ -15,2 +15,5 @@ import { AcrolinxPluginConfig } from "../acrolinx-plugin"; | ||
export declare function loadSidebarCode(sidebarUrl?: string): void; | ||
export declare function grepAttributeValues(html: string, attribute: string): string[]; | ||
export declare function rebaseRelativeUrl(url: string, sidebarBaseUrl: string): string; | ||
export declare function loadSidebarIntoIFrame(config: AcrolinxPluginConfig, sidebarIFrameElement: HTMLIFrameElement, onSidebarLoaded: () => void): void; | ||
export declare function rebaseRelativeUrls(sidebarHtml: string, sidebarBaseUrl: string): string; |
@@ -13,3 +13,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("lodash"); | ||
var utils = require("./utils"); | ||
@@ -59,3 +58,2 @@ exports.SIDEBAR_URL = 'https://sidebar-classic.acrolinx-cloud.com/v14/prod/'; | ||
var sidebarBaseUrl = sidebarUrl; | ||
var getAbsoluteAttributeValue = function (s) { return s.replace(/^.*"(.*)".*$/g, sidebarBaseUrl + '$1'); }; | ||
var completeSidebarUrl = createCompleteSidebarUrl(sidebarBaseUrl); | ||
@@ -74,7 +72,8 @@ utils.fetch(completeSidebarUrl, function (sidebarHtml) { | ||
var head = document.querySelector('head'); | ||
var css = _.map(withoutComments.match(/href=".*?"/g) || [], getAbsoluteAttributeValue); | ||
var makeRelativeUrlsAbsolutToSidebar = function (url) { return rebaseRelativeUrl(url, sidebarBaseUrl); }; | ||
var css = grepAttributeValues(withoutComments, 'href').map(makeRelativeUrlsAbsolutToSidebar); | ||
css.forEach(function (ref) { | ||
head.appendChild(createCSSLinkElement(ref)); | ||
}); | ||
var scripts = _.map(withoutComments.match(/src=".*?"/g) || [], getAbsoluteAttributeValue); | ||
var scripts = grepAttributeValues(withoutComments, 'src').map(makeRelativeUrlsAbsolutToSidebar); | ||
scripts.forEach(function (ref) { | ||
@@ -86,2 +85,23 @@ head.appendChild(createScriptElement(ref)); | ||
exports.loadSidebarCode = loadSidebarCode; | ||
// Exported only for testing | ||
function grepAttributeValues(html, attribute) { | ||
var regexp = new RegExp(attribute + "=\"(.*?)\"", 'g'); | ||
var matches; | ||
var result = []; | ||
while ((matches = regexp.exec(html)) !== null) { | ||
result.push(matches[1]); | ||
} | ||
return result; | ||
} | ||
exports.grepAttributeValues = grepAttributeValues; | ||
// Exported only for testing | ||
function rebaseRelativeUrl(url, sidebarBaseUrl) { | ||
if (url.match(/^https?:/)) { | ||
return url; | ||
} | ||
else { | ||
return sidebarBaseUrl + url; | ||
} | ||
} | ||
exports.rebaseRelativeUrl = rebaseRelativeUrl; | ||
function loadSidebarIntoIFrame(config, sidebarIFrameElement, onSidebarLoaded) { | ||
@@ -112,5 +132,3 @@ if (config.sidebarHtml) { | ||
} | ||
var sidebarHtmlWithAbsoluteLinks = sidebarHtml | ||
.replace(/src="/g, 'src="' + sidebarBaseUrl) | ||
.replace(/href="/g, 'href="' + sidebarBaseUrl); | ||
var sidebarHtmlWithAbsoluteLinks = rebaseRelativeUrls(sidebarHtml, sidebarBaseUrl); | ||
injectSidebarHtml(sidebarHtmlWithAbsoluteLinks, sidebarIFrameElement); | ||
@@ -122,2 +140,9 @@ onSidebarLoaded(); | ||
exports.loadSidebarIntoIFrame = loadSidebarIntoIFrame; | ||
// Exported only for testing | ||
function rebaseRelativeUrls(sidebarHtml, sidebarBaseUrl) { | ||
return sidebarHtml | ||
.replace(/src="(?!https?:)/g, 'src="' + sidebarBaseUrl) | ||
.replace(/href="(?!https?:)/g, 'href="' + sidebarBaseUrl); | ||
} | ||
exports.rebaseRelativeUrls = rebaseRelativeUrls; | ||
function injectSidebarHtml(sidebarHtml, sidebarIFrameElement) { | ||
@@ -124,0 +149,0 @@ var sidebarContentWindow = sidebarIFrameElement.contentWindow; |
{ | ||
"name": "acrolinx-sidebar-sdk", | ||
"description": "Acrolinx Sidebar SDK for JavaScript", | ||
"version": "0.4.12", | ||
"version": "0.4.13", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Acrolinx", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2323184
54630