Permalink
Browse files

Merge pull request #798 from GlotPress/658-make-notices-dismissable

658: Make notices dismissable.
  • Loading branch information...
toolstack committed Oct 8, 2017
2 parents 570a8ee + 761a905 commit 7d34a5c818e72ce59fed7063d26191d2004c85d4
Showing with 57 additions and 17 deletions.
  1. +23 −3 assets/css/style.css
  2. +26 −13 assets/js/common.js
  3. +7 −0 gp-includes/assets-loader.php
  4. +1 −1 gp-templates/header.php
View
@@ -202,6 +202,23 @@ textarea {
width: 40em;
}
.button-link {
font-family: "Helvetica", "Arial", sans-serif;
color: #2F34B8;
line-height: 1.5em;
font-size: 14px;
margin: 0;
padding: 0;
box-shadow: none;
border: 0;
border-radius: 0;
background: none;
outline: none;
cursor: pointer;
text-align: left;
text-decoration: underline;
}
table.translations,
table.translation-sets,
table.glossary,
@@ -454,15 +471,18 @@ span.morethan90 {
/*
* JavaScript, errors and notices.
*/
#gp-js-message {
.gp-js-message {
position: fixed;
top: 0;
padding: 0.5em;
padding: 1em;
display: none;
font-size: 85%;
z-index: 1001;
}
.gp-js-message-dismiss {
color: #fff;
}
.gp-js-error, .error {
color: white;
background-color: red;
View
@@ -3,23 +3,35 @@ var $gp = function($) { return {
element: null,
init: function() {
$gp.notices.element = $('#gp-js-message');
$gp.notices.element.on( 'click', '.gp-js-message-dismiss', $gp.notices.clear );
},
error: function(message) {
$gp.notices.generic_message('gp-js-error', message);
error: function( message ) {
$gp.notices.genericMessage( 'gp-js-error', message, true );
},
notice: function(message) {
$gp.notices.generic_message('gp-js-notice', message);
notice: function( message ) {
$gp.notices.genericMessage( 'gp-js-notice', message, true );
},
success: function(message) {
$gp.notices.generic_message('gp-js-success', message);
$gp.notices.element.fadeOut(10000);
success: function( message ) {
$gp.notices.genericMessage( 'gp-js-success', message, false );
$gp.notices.element.fadeOut( 10000 );
},
clear: function(message) {
$gp.notices.element.html('').hide();
clear: function() {
$gp.notices.element.html( '' ).hide();
},
generic_message: function(css_class, message) {
// TODO: add close button, at least to errors
$gp.notices.element.removeClass().addClass(css_class).html(message);
genericMessage: function( cssClass, message, dismissable ) {
var dismissButton = '';
// Stop and complete any running animations.
$gp.notices.element.stop( true, true );
if ( true === dismissable ) {
dismissButton = ' <button type="button" class="button-link gp-js-message-dismiss">' + $gp.l10n.dismiss + '</button>';
}
$gp.notices.element.removeClass()
.addClass( 'gp-js-message' )
.addClass( cssClass )
.html( '<div id="gp-js-message-content" class="gp-js-message-content">' + message + dismissButton + '</div>' );
$gp.notices.center();
$gp.notices.element.show();
},
@@ -45,8 +57,9 @@ $gp.showhide = function($) { return function(link, container, options) {
var options = $.extend({}, defaults, options);
var $link = $(link);
var $container = $(container);
var registry;
if ( !$gp.showhide.registry[options.group] ) $gp.showhide.registry[options.group] = [];
var registry = $gp.showhide.registry[options.group];
registry = $gp.showhide.registry[options.group];
var show = function() {
for(var i = 0; i < registry.length; ++i) {
registry[i].hide();
@@ -34,6 +34,13 @@ function gp_register_default_scripts() {
// Register our standard scripts.
wp_register_script( 'tablesorter', $url . '/vendor/jquery.tablesorter' . $suffix, array( 'jquery' ), '2.17.8' );
wp_register_script( 'gp-common', $url . '/common' . $suffix, array( 'jquery' ), '20150430' );
wp_add_inline_script( 'gp-common', sprintf(
'$gp.l10n = %s',
wp_json_encode( array(
'dismiss' => __( 'Dismiss', 'glotpress' ),
) )
) );
wp_register_script( 'gp-editor', $url . '/editor' . $suffix, array( 'gp-common', 'jquery-ui-tooltip' ), '20170701' );
wp_register_script( 'gp-glossary', $url . '/glossary' . $suffix, array( 'gp-editor' ), '20160329' );
wp_register_script( 'gp-translations-page', $url . '/translations-page' . $suffix, array( 'gp-editor' ), '20150430' );
View
@@ -42,7 +42,7 @@
<div class="gp-content">
<?php echo gp_breadcrumb(); ?>
<div id="gp-js-message"></div>
<div id="gp-js-message" class="gp-js-message"></div>
<?php if (gp_notice('error')): ?>
<div class="error">

0 comments on commit 7d34a5c

Please sign in to comment.