Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Tour Component #1632

Merged
merged 55 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
148a62a
Local: Add GP_SCRIPT_DEBUG to load the unminified CSS and JS (#1614)
amieiro May 4, 2023
3ff7d1d
Move the jQuery popover file to the assets directory (#1666)
akirk Aug 3, 2023
44f6c52
Run npm install
trymebytes Sep 1, 2023
dd00ca3
Update popover version
trymebytes Sep 4, 2023
967a336
Update minified popover script to v1.2.17
trymebytes Sep 4, 2023
e657784
Update popover css version to v1.2.17
trymebytes Sep 4, 2023
dc2e344
Revert changes to Gruntfile
trymebytes Sep 4, 2023
b3c7ab9
Add tour items
trymebytes May 31, 2023
cb14ac2
Show poopover on click
trymebytes Jun 1, 2023
d1c9a86
Change colour of tour icon
trymebytes Jun 2, 2023
721dd9a
Add custom tours
trymebytes Jun 5, 2023
aaff58e
Add jquery-webui-popover css file
trymebytes Jun 5, 2023
1da6586
Fix layout issue
trymebytes Jun 7, 2023
2d6b911
Fix tour sequence
akirk Jun 8, 2023
832c2cf
Fix jump to next
trymebytes Jun 9, 2023
4a525e5
Tour JSON from PHP
akirk Jul 20, 2023
c14ea0d
use the gp_tour in JS
akirk Jul 20, 2023
efc8173
Use the `gp-editor` registered script
trymebytes Jul 27, 2023
b9d56f3
Abstract tour code into a new tour.js file
trymebytes Jul 28, 2023
400114c
Enqueue popover stylesheet
trymebytes Aug 1, 2023
a27c658
Remove css for pulse-wrapper
trymebytes Aug 1, 2023
b98224d
Remove console log
trymebytes Aug 2, 2023
6d810ec
Add border to tour element
trymebytes Aug 2, 2023
51a6986
Remove border on closing tour
trymebytes Aug 3, 2023
d0600c7
Add previous button to tour
trymebytes Aug 4, 2023
070e4be
Reposition the previous link
trymebytes Aug 5, 2023
7eaf6ae
Improve popover UI
trymebytes Aug 5, 2023
3bfda34
Remove extra linebreak
trymebytes Aug 5, 2023
dfb52a8
Change color of dismiss link
trymebytes Aug 5, 2023
5c13702
Remove unused files
trymebytes Aug 8, 2023
c74dc8d
Update to newer version again
akirk Aug 8, 2023
ee0f2ac
lint
akirk Aug 8, 2023
54002e3
lint
akirk Aug 8, 2023
f150727
es5
akirk Aug 8, 2023
2463de5
es5
akirk Aug 8, 2023
65d39d8
Fix popover dispay type
trymebytes Aug 31, 2023
83fc8b7
Update CSS to stabilize UI on clicks
pedro-mendonca Aug 8, 2023
6ace78d
Improve popover UI css and i18n
pedro-mendonca Aug 8, 2023
9bbef41
Add ability to add custom css to tour item selector
trymebytes Sep 1, 2023
625720b
Remove unused code
trymebytes Sep 1, 2023
06addc6
Remove extra new line
trymebytes Sep 1, 2023
be1b4d3
Enqueue tour styles and scripts in header
trymebytes Sep 1, 2023
22f6554
Fix lint error
trymebytes Sep 1, 2023
dd93281
Fix es5 lint errors
trymebytes Sep 2, 2023
fe4fbd3
Update css to remove dashed box overflow
trymebytes Sep 3, 2023
e5fceae
Remove popover licence
trymebytes Sep 4, 2023
0972c7f
Remove duplicate code
trymebytes Sep 4, 2023
fae58b0
Display one popover at a time
trymebytes Sep 5, 2023
2296cab
Run npm install
trymebytes Sep 13, 2023
0fd0d52
Remove line, popover already hidden on clicking .pulse
trymebytes Sep 14, 2023
fc12ff9
Skip to next item if valid selector cannot be found
trymebytes Sep 18, 2023
d4344cc
Fix lint errors
trymebytes Sep 18, 2023
12b85af
Add visible selector
trymebytes Sep 18, 2023
b629e7d
Add missing visible selector
trymebytes Sep 18, 2023
99b47ee
Merge branch 'develop' into site-tour
trymebytes Sep 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 76 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
--gp-color-status-waiting-subtle: #ffffc2;
--gp-color-status-rejected-subtle: #ff8e8e;
--gp-color-status-changesrequested-subtle: #87ceeb;

--gp-color-tour: var( --gp-color-primary );
}

*,
Expand Down Expand Up @@ -1608,3 +1610,77 @@ table.form-table td {
flex-direction: column;
}
}

.pulse {
border-radius: 50%;
position: relative;
cursor: pointer;
top: -2em;
left: -0.4em;
width: 12px;
height: 12px;
margin: -6px;
}

.pulse-wrapper {
border: 2px dashed transparent;
padding: 0.4em;
border-radius: 3px;
margin-left: calc( -0.4em - 2px );
margin-top: calc( -0.4em - 2px );
margin-bottom: calc( -0.4em - 2px );
}

.webui-popover .webui-popover-content {
font-size: .9em;
color: #fff;
}
.pulse-border {
border: 2px dashed var( --gp-color-tour );
}

a.tour-button {
text-decoration: none;
border-radius: 3px;
font-weight: bold;
padding: 3px 10px;
border: rgba( 255, 255, 255, .5 ) thin solid;
color: #fff;
}
a.tour-button:hover {
border: #fff thin solid;
background: rgba( 255, 255, 255, .25 );
}

a.previous-tour-item {
margin-right: 0.5em;
}

a.tour-button.button-primary {
background: #fff;
color: #2f99ee;
color: var( --gp-color-tour );
border: #fff thin solid;
}
a.tour-button.button-primary:hover {
background: rgba( 255,255,255,.75 );
}

.popover-nav-btns {
margin-top: 11px;
}

.webui-popover.in{
background: var( --gp-color-tour );
}

.webui-popover .webui-popover-title {
border-radius: 4px 4px 0 0; // Make webui-popover outside and inner borders radius concentric.
background: #fff;
font-weight: bold;
color: var( --gp-color-tour );
}

.webui-popover a {
color: #fff;
}
21 changes: 0 additions & 21 deletions assets/jquery.webui-popover.licence

This file was deleted.

117 changes: 117 additions & 0 deletions assets/js/tour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* global wp, document, window, WebuiPopovers, gp_tour */
/* eslint camelcase: "off" */

jQuery( document ).ready(
function() {
jQuery( document ).on( 'click', '.close-tour, .dismiss-tour', function() {
jQuery( this ).closest( '.webui-popover' ).hide();
jQuery( '.pulse-wrapper' ).removeClass( 'pulse-border' );
return false;
} );
jQuery( document ).on( 'click', '.next-tour-item', function() {
jQuery( '.pulse-wrapper .tour-' + jQuery( this ).data( 'tourname' ) + ':visible' ).first().click();
return false;
} );
jQuery( document ).on( 'click', '.previous-tour-item', function() {
var currentPopover = jQuery( this ).closest( '.webui-popover' );
if ( currentPopover.prev().hasClass( 'webui-popover' ) ) {
currentPopover.hide();
currentPopover.prev().show();
}
return false;
} );
jQuery( document ).on( 'click', '.reveal-next-tour-item', function() {
jQuery( this ).closest( '.webui-popover' ).hide();
jQuery( jQuery( this ).data( 'reveal' ) ).first().click();
return false;
} );

jQuery( document ).on( 'click', '.pulse', function() {
var wrapper = jQuery( this ).closest( '.pulse-wrapper' );
var tourName = wrapper.data( 'tourname' );
var nextItem = 1 + wrapper.data( 'tourindex' );
var tourEndsHere = typeof window.tour[ tourName ][ nextItem ] === 'undefined';
var showPreviousBtn = wrapper.data( 'tourindex' ) > 1;
var popoverContent = wrapper.data( 'popover-content' );
var item = window.tour[ tourName ][ nextItem ];
jQuery( '.pulse-wrapper' ).removeClass( 'pulse-border' );
jQuery( '.webui-popover:visible' ).hide();
wrapper.addClass( 'pulse-border' );

if ( tourEndsHere ) {
popoverContent += '<br/><br/><a href="" class="close-tour">' + wp.i18n.__( 'Close', 'glotpress' ) + '</a>';
} else if ( typeof window.tour[ tourName ][ nextItem ] !== 'undefined' && typeof window.tour[ tourName ][ nextItem ].reveal === 'undefined' ) {
popoverContent += '<div class="popover-nav-btns">';
popoverContent += showPreviousBtn ? '<br/><br/><a href="" class="tour-button previous-tour-item" data-tourname="' + tourName + '">' + wp.i18n.__( 'Previous', 'glotpress' ) + '</a>' : '';
popoverContent += '<a href="" class="tour-button next-tour-item button-primary" data-tourname="' + tourName + '">Next</a>';
popoverContent += '</div>';
} else if ( typeof window.tour[ tourName ][ nextItem ].reveal !== 'undefined' ) {
popoverContent += '<br/><br/><a href="" class="reveal-next-tour-item" data-reveal="' + window.tour[ tourName ][ nextItem ].reveal + '">' + wp.i18n.__( 'Reveal Next Step', 'glotpress' ) + '</a>';
}
if ( ! tourEndsHere ) {
popoverContent += '<br/><small><a href="" class="dismiss-tour">' + wp.i18n.__( 'Dismiss this tour', 'glotpress' );
}
WebuiPopovers.show( this, { title: window.tour[ tourName ][ 0 ].title, content: popoverContent, width: 300, dismissible: true } );
jQuery( '.tour-' + tourName ).remove();

if ( tourEndsHere ) {
return;
}

addPulse( jQuery( item.selector ), item, tourName, nextItem );
} );
function addPulse( field, item, tourName, index ) {
var div = jQuery( '<div class="pulse-wrapper">' );
var pulse = jQuery( '<div class="pulse tour-' + tourName + '">' );
var cssString = '';
div.data( 'tourname', tourName ).data( 'tourindex', index ).data( 'popover-content', item.html );
field.wrap( div );
field.parent().append( pulse );
if ( typeof item.css !== 'undefined' ) {
cssString = cssObjectToString( item.css );
jQuery( item.selector ).closest( '.pulse-wrapper' ).css( 'cssText', cssString );
}
}

// Convert the CSS object to a CSS string
function cssObjectToString( cssObject ) {
return jQuery.map( cssObject, function( value, property ) {
return property + ': ' + value;
} ).join( '; ' );
}

window.tour = gp_tour;
window.loadTour = function() {
var color1 = '';
var color2 = '';
var sheet = {};
var n;
for ( n in window.tour ) {
color1 = window.tour[ n ][ 0 ].color + '00';
color2 = window.tour[ n ][ 0 ].color + 'a0';
sheet = document.styleSheets[ 0 ];
sheet.insertRule( '@keyframes animation-' + n + ' {' +
'0% {' +
'box-shadow: 0 0 0 0 ' + color2 + ';' +
'}' +
'70% {' +
'box-shadow: 0 0 0 10px ' + color1 + ';' +
'}' +
'100% {' +
'box-shadow: 0 0 0 0 ' + color1 + ';' +
'}' +
'}',
sheet.cssRules.length );

sheet.insertRule( '.tour-' + n + '{' +
'box-shadow: 0 0 0 ' + color2 + ';' +
'background: ' + color1 + ';' +
'-webkit-animation: animation-' + n + ' 2s infinite;' +
'animation: animation-' + n + ' 2s infinite; }',
sheet.cssRules.length );
addPulse( jQuery( window.tour[ n ][ 1 ].selector ), window.tour[ n ][ 1 ], n, 1 );
}
};
window.loadTour();
}
);
2 changes: 1 addition & 1 deletion glotpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
define( 'GP_INC', 'gp-includes/' );
define( 'GP_WP_REQUIRED_VERSION', '4.6' );
define( 'GP_PHP_REQUIRED_VERSION', '7.4' );

define( 'GP_SCRIPT_DEBUG', true );
/**
* Displays an admin notice on the plugins page that GlotPress has been disabled and why..
*
Expand Down
9 changes: 7 additions & 2 deletions gp-includes/assets-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
function gp_register_default_styles() {
$url = gp_plugin_url( 'assets/css' );

$suffix = SCRIPT_DEBUG ? '.css' : '.min.css';
$suffix = SCRIPT_DEBUG || GP_SCRIPT_DEBUG ? '.css' : '.min.css';

// Register our base style.
wp_register_style( 'gp-base', $url . '/style' . $suffix, array(), '20230725' );
wp_register_style( 'gp-jquery-webui-popover', $url . '/jquery.webui-popover' . $suffix, array( 'gp-base' ), '20230503' );
}

add_action( 'init', 'gp_register_default_styles' );
Expand All @@ -26,7 +27,7 @@ function gp_register_default_styles() {
function gp_register_default_scripts() {
$url = gp_plugin_url( 'assets/js' );

$suffix = SCRIPT_DEBUG ? '.js' : '.min.js';
$suffix = SCRIPT_DEBUG || GP_SCRIPT_DEBUG ? '.js' : '.min.js';

// Register our standard scripts.
wp_register_script( 'tablesorter', $url . '/vendor/jquery.tablesorter' . $suffix, array( 'jquery' ), '20210429' );
Expand All @@ -35,11 +36,15 @@ function gp_register_default_scripts() {
wp_register_script( 'gp-glossary', $url . '/glossary' . $suffix, array( 'gp-editor' ), '20230808' );
wp_register_script( 'gp-translations-page', $url . '/translations-page' . $suffix, array( 'gp-editor' ), '20230808' );
wp_register_script( 'gp-mass-create-sets-page', $url . '/mass-create-sets-page' . $suffix, array( 'gp-editor' ), '20230808' );
wp_register_script( 'gp-tour', $url . '/tour' . $suffix, array( 'jquery', 'gp-jquery-webui-popover' ), '20230728', false );

wp_set_script_translations( 'gp-common', 'glotpress' );
wp_set_script_translations( 'gp-editor', 'glotpress' );
wp_set_script_translations( 'gp-glossary', 'glotpress' );
wp_set_script_translations( 'gp-mass-create-sets-page', 'glotpress' );
wp_set_script_translations( 'gp-tour', 'glotpress' );
wp_register_script( 'gp-jquery-webui-popover', $url . '/jquery.webui-popover' . $suffix, array( 'jquery' ), '20210429', false );
wp_localize_script( 'gp-tour', 'gp_tour', apply_filters( 'gp_tour', array() ) );
}

add_action( 'init', 'gp_register_default_scripts' );
Expand Down
3 changes: 2 additions & 1 deletion gp-templates/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

<?php
// Enqueue the base style so we don't have to load it manually on each page.
gp_enqueue_styles( 'gp-base' );
gp_enqueue_styles( array( 'gp-base', 'gp-jquery-webui-popover' ) );
gp_enqueue_scripts( array( 'gp-jquery-webui-popover', 'gp-tour' ) );

gp_head();
?>
Expand Down
15 changes: 7 additions & 8 deletions gp-templates/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
$editor_options = compact( 'can_approve', 'can_write', 'url', 'discard_warning_url', 'set_priority_url', 'set_status_url', 'word_count_type' );

wp_localize_script( 'gp-editor', '$gp_editor_options', $editor_options );

gp_tmpl_header();
$i = 0;
?>
Expand Down Expand Up @@ -440,20 +439,20 @@
</tr>
</thead>
<?php
foreach ( $translations as $translation ) {
if ( ! $translation->translation_set_id ) {
$translation->translation_set_id = $translation_set->id;
}
foreach ( $translations as $translation ) {
if ( ! $translation->translation_set_id ) {
$translation->translation_set_id = $translation_set->id;
}

$can_approve_translation = GP::$permission->current_user_can( 'approve', 'translation', $translation->id, array( 'translation' => $translation ) );
gp_tmpl_load( 'translation-row', get_defined_vars() );
}
?>
<?php
if ( ! $translations ) :
?>
if ( ! $translations ) :
?>
<tr><td colspan="<?php echo $can_approve ? 5 : 4; ?>"><?php _e( 'No translations were found!', 'glotpress' ); ?></td></tr>
<?php
<?php
endif;
?>
</table>
Expand Down