Skip to content

Commit

Permalink
Merge branch 'release-3.8.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 5, 2024
2 parents fc9ce62 + f8be085 commit d4fb5dd
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 9 deletions.
41 changes: 41 additions & 0 deletions migrations/Version202407021254084106_pciSamples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace oat\pciSamples\migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Exception\IrreversibleMigration;
use oat\pciSamples\scripts\install\RegisterPciTextReaderIMS;
use oat\pciSamples\scripts\install\RegisterPciTextReaderOAT;
use oat\tao\scripts\tools\migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202407021254084106_pciSamples extends AbstractMigration
{
public function getDescription(): string
{
return 'Add target "_blank" to any HTML anchors of Text Reader interaction';
}

public function up(Schema $schema): void
{
$this->runAction(new RegisterPciTextReaderOAT(), ['0.9.2']);
$this->runAction(new RegisterPciTextReaderIMS(), ['1.2.2']);
}

public function down(Schema $schema): void
{
throw new IrreversibleMigration(
sprintf(
'In order to undo this migration, please revert the client-side changes and run "%s" and "%s"',
RegisterPciTextReaderIMS::class,
RegisterPciTextReaderOAT::class
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"typeIdentifier": "textReaderInteraction",
"label": "Text reader",
"description": "The Paging widget combines a scrolling widget with additional paging controls.",
"version": "0.9.1",
"version": "0.9.2",
"author": "Aleh Hutnikau",
"email": "[email protected]",
"tags": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ define(
});
};

/**
* Add all html anchors a "_blank" target by default
*
* @param {String} html - the html to parse
* @param {Object} renderer
* @returns {String} the html with fixed anchor targets
*/
var fixAnchorTargets = function(html, renderer) {
html = html || '';

return html.replace(/(<a\s+[^>]*)(?=\s*>)/ig, function(substr, $1) {
// Remove any existing target attribute and replace with target="_blank"
var modifiedTag = $1.replace(/\btarget\s*=\s*["'][^"']*["']/ig, '').trim();
return modifiedTag + ' target="_blank"';
});
};

return function (options) {
var self = this;
var defaultOptions = {
Expand Down Expand Up @@ -177,6 +194,11 @@ define(
markup,
self.options.interaction.renderer
);

fixedMarkup = fixAnchorTargets(
fixedMarkup,
self.options.interaction.renderer
);
}

$container = this.options.$container.find('.js-page-container')
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"typeIdentifier": "textReaderInteraction",
"label": "Text reader",
"description": "The Paging widget combines a scrolling widget with additional paging controls.",
"version": "1.2.1",
"version": "1.2.2",
"author": "Aleh Hutnikau",
"email": "[email protected]",
"tags": [
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ define(
var interaction;
var renderer;
var images;
var anchors;

this.options.$container.trigger('beforerenderpages.' + self.eventNs);

Expand Down Expand Up @@ -173,7 +174,17 @@ define(
image.setAttribute('src', content);
}
});
return element.outerHTML || element.textContent;

anchors = selectorContainer.querySelectorAll('a');
// anchors = [].slice.call(anchors);
anchors.forEach(function(anchor) {
var href = anchor.getAttribute('href');
if (href && !href.trim().startsWith('#')) {
anchor.setAttribute('target', '_blank');
anchor.setAttribute('rel', 'noopener noreferer');
}
});
return element.outerHTML || element.textContent;
}).join('');

$container = this.options.$container.find('.js-page-container')
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit d4fb5dd

Please sign in to comment.