Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesDPC committed Jul 11, 2024
0 parents commit 4232c34
Show file tree
Hide file tree
Showing 22 changed files with 618 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,js,json,css,scss,eslintrc,feature}]
indent_size = 2
indent_style = space

[package.json]
indent_size = 2

[composer.json]
indent_size = 4
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/tests export-ignore
/docs export-ignore
/client/src export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpunit.xml.dist export-ignore
/.waratah export-ignore
/code-of-conduct.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/client/node_modules
/vendor/
.DS_Store
/.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Configuration file for https://github.com/FriendsOfPHP/PHP-CS-Fixer
* Install with composer: $ composer global require friendsofphp/php-cs-fixer
* Usage (in this directory) : ~/.composer/vendor/bin/php-cs-fixer fix .
*/
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'full_opening_tag' => true,
'no_closing_tag' => true,
])
->setIndent(" ")
->setFinder($finder);
68 changes: 68 additions & 0 deletions .waratah
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
+------------------------------------------------------------------------------------------------------------------------+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo:+ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooooooooooooooooooooo++ooooooooooooooo~ ~oooooooooooooo+++ooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooo+ .~+oooooooooo+. .. ~oooooooooo++~. .+oooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooo~ .. ~:+oooooo+. .... ~+oooooo+:. .. :oooooooooooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooooooooooooooooooo+ .. .. :+ooo+.... . . .oooo:~. ......+ooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooo~~:+++ooooooooo.......... ~oo+ ..... .. .+o+ .........:oooooooooo++~~:oooooooooooooooooooooooo|
|ooooooooooooooooooooooo: . .~:+ooooo+ .........+o+ .............oo+........ +oooo++:~ . . +ooooooooooooooooooooooo|
|ooooooooooooooooooooooo~ .... . .~++oo+~ ..... +o+... . .... .. ~oo+ .... .~+oo++~. ...... ~ooooooooooooooooooooooo|
|ooooooooooooooooooooooo........... ~+oo++. ..+oo~ ............ . ~oo+ . .~+ooo:~. ......... ~ooooooooooooooooooooooo|
|ooooooooooooooooooooooo.............. :ooooo+~ :oo~ ..... .......... +oo~.~+ooooo~ ..... . .... .ooooooooooooooooooooooo|
|oooooooooooooooooooooo+. . ... .. .. :oo~ ~+oo++o+ ........... .......+oo+oo+~.~oo~ . ...........ooooooooooooooooooooooo|
|ooooooooooooooooooooooo... . ....... +o+ .~+ooo. ................. ~ooo+~ ..+o: ........... ~ooooooooooooooooooooooo|
|oooooooo+++++++++++oooo......... ....oo: ... ~+oo:. .. .. .. .... .+oo+~ ... :o+ .. .... . ..~oo+o+++++++++++oooooooo|
|ooooooo: . .. ~oo............ ~oo....... ~+oo: ... ..... .. :oo+~ ...... .oo............ ~oo.... . +ooooooo|
|ooooooo+ .......... ~oo~ . ... .... :o+ ... .... :+o+~ ... .... ~+oo:. .. ......oo~ ... ...... ~oo. ...........+ooooooo|
|oooooooo~ ... .......oo: .. ..... ..+o+ ... ...... .+oo: .... .:oo+. .... ... +o: . .. ..... +o+........... +oooooooo|
|ooooooooo~ ..........+o+ ..... .... +o+ ...... ..... :oo+.... ~+oo~ ............ +o+ ....... ...+o+ ...... .. :ooooooooo|
|oooooooooo: ....... :o+ .. ........oo: ............. .+o+~ ~oo+~ .. ....... .. +o+....... ....oo~ ...... +oooooooooo|
|ooooooooooo+. .~:+oo~.... .... .oo+ . ... ... ... .+oo.:oo+. ....... ...... +o+ .. ...... ~oo+:~. . .+ooooooooooo|
|oooooooooooo+~.:++ooo+oo+ .. .. ...+o: .... ...... .... +oooo+ ..... ..... . . +o+.... ..... +oo+ooo++~.:ooooooooooooo|
|ooooooooooooooooo+:~. :oo...........oo+ .. ...... .... . +oo+.......... ....... +o+ ..... ...~oo~ .~:+ooooooooooooooooo|
|oooooooooooo++:. ....oo: .... ....+o+ .......... ...... +o+........ ....... ...+o+ ........ +o+ .. ~:++oooooooooooo|
|ooooooooo+:.. ...... :oo~ .... .. +o+. ..... ...... .. :oo~ ... ..... .. ......oo~ ... ... ~oo~....... . ~:+ooooooooo|
|ooooo++~.. ...... .... +o+ ....... ~oo~... .... ........+o+ ..... ............ :oo... ......oo+ .. ....... ..~+oooooo|
|ooo+~. ..... ...........oo+ ........oo+ ..... .... ... :oo. . ...... .... .....+o+ ...... .+o+ ...... ......... ..~+ooo|
|oo+ ..... .............. ~+o+ . . .. +oo............. . +o+. ................. ~oo~ ..... .+o+...... ....... ...... +oo|
|ooo:.. ............ .... .oo+. ......+o+ ... ..........+o+ .... ..... .. . .. +o+ .. .. ~+o+. ... ...... ....... ..+ooo|
|ooooo+~. ...... ........ .+oo~ ... ~oo: ... ....... +o+ ................ +oo~..... :oo+...... .......... .~:+ooooo|
|oooooooo++~.. ............ +oo+~ .. :oo+ ... .......+o+ .. .. . ...... .+oo. .. ~+o+~ ......... ..:++oooooooo|
|oooooooooooo++:~.. . .. .+oo+~ ~+oo: ......... :oo............. .:oo+. .~+oo+. .. .~::++oooooooooooo|
|oooooooooooooooooo+++::~~~.... .:+o++~~. ~+o+:.. ... +o+. .... . ~++o+~ ..:++o+: ....~~~::+++ooooooooooooooooooo|
|ooooooooooooooooooooooooooooooo+++++ooooo+++oooo++:~~....~oo+:.....~~:+oooo++++ooooo+++++ooooooooooooooooooooooooooooooo|
|ooooooooooooooooooooooo:~~~:::++++o++++++oo+++++++o+++o+oooooooo++o++oo++++oooo++++oo++++++::~~~+ooooooooooooooooooooooo|
|oooooooooooooooooooooo+. . .~~~:::++++++oooooo+++++::~~~... . .. . . :ooooooooooooooooooooooo|
|oooooooooooooooooooooooo+:~~~....~~.~~:++++ooooooooooooooooooooooooooooooooo+++::~~..........~:+oooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooo+ooooooooooooooooooooooooooooooooooooooooooooooooooooo+o+oo+oooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooo:~:~::::+ooooooooooooooooo+~::~:::oooooooo++:~.. ..~~:+oooooo~:::~:::oooooooooo:~:~::~+oooooooooo::::~:~+oooooo|
|ooooo+ :oooooooooooooooo~ oooooo+. .:+oo~ +oooooooo+ ooooooooo~ +oooooo|
|ooooo+ +oooooooooooooo~ oooo+~ .+o+ ~oooooooo. ~oooooooo ~ooooooo|
|ooooo+ .+oooooooooooo~ oooo. .::+::~. ~+ooo: +oooooo+ ooooooo+ +ooooooo|
|ooooo+ ~ooooooooooo~ ooo+ +ooooooooo++. :ooooo+ ~oooooo. :oooooo ~oooooooo|
|ooooo+ :ooooooooo~ +oo: +oooooooooooooooooooo: +oooo+ ooooo+ +oooooooo|
|ooooo+ . .+ooooooo~ ooo+ .:++oooooooooooooooo+ :oooo. ~oooo. ~ooooooooo|
|ooooo+ :+. ~+ooooo~ .oooo~ ..~:++oooooooooo: ooo+ +~ ooo+ oooooooooo|
|ooooo+ :oo+ :oooo~ +oooo: ~:oooooooo :oo o+ :oo. :oooooooooo|
|ooooo+ :oooo: +oo. ooooooo+~. ~oooooo: o+ +oo. o+ ooooooooooo|
|ooooo+ :ooooo+~ .+~ ooooooooooo++:~.. .oooooo :. ooo+ :~ :ooooooooooo|
|ooooo+ :ooooooo+. oooooooooooooooooo++~ +ooooo: :oooo. oooooooooooo|
|ooooo+ ~ooooooooo: +ooooo:+ooooooooooooo+ :oooooo. ooooo+ +oooooooooooo|
|ooooo+ :ooooooooooo~ oooo+ .~++ooooooooo+ :oooooo+ :oooooo. .ooooooooooooo|
|ooooo+ :oooooooooooo+. oo+. .~~::::~. .oooooooo. ooooooo+ +ooooooooooooo|
|ooooo+ :oooooooooooooo+ +o+~ ~ooooooooo+ :oooooooo. .oooooooooooooo|
|ooooo+ ~oooooooooooooooo: ooooo+:. .~+ooooooooooo. ooooooooo+ +oooooooooooooo|
|oooooo:+::+::+ooooooooooooooooo+::+:+:::oooooooo+++:~~.~.~.~::++oooooooooooooo+::+::+:+oooooooooo+:::+:++ooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|ooooooooo+++ooooooooo+ooooooooooooooooo+o+o++oooooo++oooooo+ooooooooooooooooooooooooo++o+ooooooooooo+ooo+ooo+ooooooooooo|
|oooooo+~.~~..~+oo+~..~...+o: :ooooo. o+ .~.~~.+o~ .~...~+o+ .+oooo..o+ +oooo: ++ ..~~..:o+ .+oooo..o:.~. ...~ooooooooo|
|ooooo+ ~+oooo+oo+ .+ooo+~ :o. +ooo. +o+ :ooooooo~ +ooo+ o+ . ~ooo o+ ~oo~ oo .ooooooo+ ~ooo oooo+ ~oooooooooooo|
|ooooo ooo+~~:~o ooooooo. oo oo: +oo+ ~...~oo~ ::++~ ~o+ ++. +o .o+ :+ .. o~ +o ~~.~~+o+ ++ +o .oooo+ :oooooooooooo|
|ooooo: :ooo++ o~ :ooooo+ .oo+ ~+ :ooo+ :ooooooo~ ~:~ +oo+ :oo: ~ .o+ :oo.~oo~ +o .o++oooo+ :oo: ~ .oooo+ :oooooooooooo|
|oooooo+..~::~ .oo: .~:~. ~oooo+ ~oooo+ .:~::~+o~ +oo+. +o+ :ooo+. o+ ~oooooo. oo :~::~:o+ :ooo+. oooo+ ~oooooooooooo|
|oooooooo++:++oooooo++:++ooooooo++ooooo+++++++++o++ooooo++oo++ooooo++oo++oooooo++oo++++++++o+++ooooo++oooo+++oooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
+------------------------------------------------------------------------------------------------------------------------+
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing

For simplicity, our contribution process follows the relevant Silverstripe documents.

## Guidelines

- Maintenance on this module is a shared effort of those who use it
- To contribute improvements to the code, ensure you raise a pull request and discuss with the module maintainers
- Please follow the Silverstripe [code contribution guidelines](https://docs.silverstripe.org/en/contributing/code/) and [Module Standard](https://docs.silverstripe.org/en/developer_guides/extending/modules/#module-standard)
- Supply documentation that follows the [GitHub Flavored Markdown](https://help.github.com/articles/markdown-basics/) conventions
- When having discussions about this module in issues or pull request please adhere to the [Silverstripe Community Code of Conduct](https://docs.silverstripe.org/en/contributing/code_of_conduct/)

## Contributor license agreement

By supplying code to this module in patches, tickets and pull requests, you agree to assign copyright of that code to New South Wales Department of Premier & Cabinet, on the condition that these code changes are released under the same BSD license as the original module.

We ask for this so that the ownership in the license is clear and unambiguous.

By releasing this code under a permissive license such as BSD, this copyright assignment won't prevent you from using the code in any way you see fit.
12 changes: 12 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright (c) New South Wales Premier's Department
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Exit site button

This Silverstripe module provides an "Exit Button" that can be included on any web page, either via the CMS using the per-page checkbox in Page > Settings, via a shortcode or programmatically.

## What it does do

+ provides configurable templates
+ provides configurable exit URL value
+ multiple button support
+ provdes a shortcode for adding the button to any HTML editor field
+ replaces the location value
+ opens a configured website in a new tab

## What it doesn't do

+ rewrite browser history
+ invalidate a session on the site

## Implementation

1. Add the `{$ExitButton}` template variable in a template
1. Enable on a page and/or add an Exit Button shortcode to a relevant HTML editor field

## Documentation

* [Read the documentation page](./docs/en/001_index.md) for implementation details

## Installation

The only supported method of installation is via composer:

```
composer require nswdpc/silverstripe-exit-button
```

## License

[BSD-3-Clause](./LICENSE.md)

## Maintainers

PD web team

## Bugtracker

We welcome bug reports, pull requests and feature requests on the Github Issue tracker for this project.

Please review the [code of conduct](./code-of-conduct.md) prior to opening a new issue.

## Security

If you have found a security issue with this module, please email digital[@]dpc.nsw.gov.au in the first instance, detailing your findings.

## Development and contribution

If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.

Please review the [code of conduct](./code-of-conduct.md) prior to completing a pull request.
6 changes: 6 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use NSWDPC\ExitButton\Shortcodes\ExitButtonShortcode;
use SilverStripe\View\Parsers\ShortcodeParser;

ShortcodeParser::get('default')->register('exit_button', [ExitButtonShortcode::class, 'parse']);
15 changes: 15 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Name: nswdpc-exit-button
---
# base level config
NSWDPC\ExitButton\Models\ExitButton:
default_url: 'https://www.google.com/'
---
Name: nswdpc-exit-button-element
Only:
moduleexists: 'dnadesign/silverstripe-elemental'
---
# elemental
Page:
extensions:
ExitButton: 'NSWDPC\ExitButton\Extensions\PageSettingsExtension'
50 changes: 50 additions & 0 deletions client/static/js/exitbutton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Exit Button
*/
class ExitButton {
exitButton = null
init(btn) {
try {
if(!btn) {
throw 'Parameter is not an element';
}
this.exitButton = btn;
} catch (e) {
console.warn('ExitButton', e);
}
return this;
}
handle() {
if(!this.exitButton) {
throw 'No button defined';
}
let _self = this;
window.addEventListener(
'keydown',
function(e) {
if(e.keyCode == 27) {
_self.doExit()
}
}
);
this.exitButton.addEventListener(
'click',
function(e) {
e.preventDefault();
_self.doExit(this);
}
);
}
doExit(element) {
let url = '';
if(this.exitButton) {
url = this.exitButton.dataset.url;
}
if(!url) {
url = 'https://www.google.com/';
}
console.log(url);
window.open(url, '_blank');
window.location.replace(url, "_newtab");
}
}
1 change: 1 addition & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When having discussions about this module in issues or pull request please adhere to the [SilverStripe Community Code of Conduct](https://docs.silverstripe.org/en/contributing/code_of_conduct).
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "nswdpc/silverstripe-exit-button",
"description": "Exit button for pages",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"nsw",
"module",
"exit button"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "James",
"role": "Developer"
}
],
"require": {
"silverstripe/cms" : "^4 || ^5"
},
"suggest" : {
"dnadesign/silverstripe-elemental" : "Elemental content block support"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3"
},
"extra": {
"expose": [
"client/static"
]
},
"autoload": {
"psr-4": {
"NSWDPC\\ExitButton\\": "src/",
"NSWDPC\\ExitButton\\Tests\\": "tests/"
}
}
}
51 changes: 51 additions & 0 deletions docs/en/001_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Documentation

## Background

The exit button works by:

1. opening the configured URL in a new window/tab when clicked.
2. replacing the current location in history with the defined exit URL

Hitting 'Esc' (Escape key) on the keyboard will also trigger an exit.

It will not alter browser history. Use a browser's Incognito or Private browsing options, instead.


## Short code

A CMS editor can add a short code to any HTML editor field:

```
[exit_button,url="https://www.google.co.uk"]
```

Specify a custom label:

```
[exit_button,url="https://www.google.co.uk",label="Exit now"]
```

With the shortcode, the options allowed are:

+ url: the exit URL, which will override the default URL
+ label: configure the button label. The default is 'Exit this page' if this is not set

If no `url` value is specified, the system default will be used.

## Configuring

A developer can configure the default exit URL for use by the module.

```yml
---
Name: app-exit-button
After:
- '#nswdpc-exit-button'
---
# base level config
NSWDPC\ExitButton\Models\ExitButton:
default_url: 'https://exit.example.com/'
```
## ASgh
Loading

0 comments on commit 4232c34

Please sign in to comment.