Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Jun 3, 2024
1 parent ac19489 commit 7b89ded
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Target Blank
============

![Elgg 5.0](https://img.shields.io/badge/Elgg-5.0-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/target_blank/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/target_blank/v/stable.svg)](https://packagist.org/packages/coldtrick/target_blank)
[![License](https://poser.pugx.org/coldtrick/target_blank/license.svg)](https://packagist.org/packages/coldtrick/target_blank)
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/TargetBlank/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Bootstrap extends DefaultPluginBootstrap {
* {@inheritDoc}
*/
public function init() {
elgg_require_js('target_blank/target_blank');
elgg_import_esm('target_blank/target_blank');
}
}
2 changes: 1 addition & 1 deletion classes/ColdTrick/TargetBlank/Javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Javascript {
/**
* Add the link suffix to the global JS data
*
* @param \Elgg\Event $event 'elgg.data', 'site'
* @param \Elgg\Event $event 'elgg.data', 'page'
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issues": "https://github.com/ColdTrick/target_blank/issues"
},
"conflict": {
"elgg/elgg": "<5.0"
"elgg/elgg": "<6.0"
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
],
'elgg.data' => [
'site' => [
'page' => [
'\ColdTrick\TargetBlank\Javascript::setLinkSuffix' => [],
],
],
Expand Down
39 changes: 0 additions & 39 deletions views/default/js/target_blank/target_blank.js

This file was deleted.

39 changes: 39 additions & 0 deletions views/default/target_blank/target_blank.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* JS to open links in a new window.
*/
import 'jquery';
import 'elgg';

var site_url = elgg.get_site_url().substring(4);
if (site_url.substring(0, 1) === 's') {
site_url = site_url.substring(1);
}

var selector = 'a[href^="http://"]:not([target], [href^="http' + site_url + '"], [href^="https' + site_url + '"]),';
selector += 'a[href^="https://"]:not([target], [href^="http' + site_url + '"], [href^="https' + site_url + '"])';

$(document).on('click', selector, function () {
$(this).attr('target', '_blank');
}).addClass('target-blank');


var suffix = null;
if (elgg.data.target_blank !== undefined && elgg.data.target_blank.link_suffix !== undefined) {
suffix = elgg.data.target_blank.link_suffix;
}

if (suffix) {
$(selector).each(function() {
if ($(this).find(' > img, > .elgg-anchor-label > img').length) {
// there is an image in the link
return;
}

if (!$(this).html().length) {
// there is no content in the anchor
return;
}

$(this).append('<span class="target-blank-suffix">' + suffix + '</span>');
});
}

0 comments on commit 7b89ded

Please sign in to comment.