[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 /* global document */ 2 var $gp = ( 3 function( $ ) { 4 return { 5 notices: { 6 element: null, 7 init: function() { 8 $gp.notices.element = $( '#gp-js-message' ); 9 $gp.notices.element.on( 'click', '.gp-js-message-dismiss', $gp.notices.clear ); 10 }, 11 error: function( message ) { 12 $gp.notices.genericMessage( 'gp-js-error', message, true ); 13 }, 14 notice: function( message ) { 15 $gp.notices.genericMessage( 'gp-js-notice', message, true ); 16 }, 17 success: function( message ) { 18 $gp.notices.genericMessage( 'gp-js-success', message, false ); 19 $gp.notices.element.fadeOut( 10000 ); 20 }, 21 clear: function() { 22 $gp.notices.element.html( '' ).hide(); 23 }, 24 genericMessage: function( cssClass, message, dismissable ) { 25 var dismissButton = ''; 26 27 // Stop and complete any running animations. 28 $gp.notices.element.stop( true, true ); 29 30 if ( true === dismissable ) { 31 dismissButton = ' <button type="button" class="button is-link gp-js-message-dismiss">' + $gp.l10n.dismiss + '</button>'; 32 } 33 34 $gp.notices.element.removeClass() 35 .addClass( 'gp-js-message' ) 36 .addClass( cssClass ) 37 .html( '<div id="gp-js-message-content" class="gp-js-message-content">' + message + dismissButton + '</div>' ); 38 $gp.notices.center(); 39 $gp.notices.element.show(); 40 }, 41 center: function() { 42 $gp.notices.element.css( 'left', ( $( document ).width() - $gp.notices.element.width() ) / 2 ); 43 }, 44 }, 45 esc_html: function( s ) { 46 return $( '<div/>' ).text( s ).html(); 47 }, 48 init: function() { 49 $gp.notices.init(); 50 }, 51 }; 52 }( jQuery ) 53 ); 54 55 $gp.showhide = ( 56 function( $ ) { 57 return function( link, container, userOptions ) { 58 var defaultOptions = { 59 show_text: 'Show', 60 hide_text: 'Hide', 61 focus: false, 62 group: 'default', 63 }; 64 var options = $.extend( {}, defaultOptions, userOptions ); 65 var $link = $( link ); 66 var $container = $( container ); 67 var registry; 68 if ( ! $gp.showhide.registry[ options.group ] ) { 69 $gp.showhide.registry[ options.group ] = []; 70 } 71 registry = $gp.showhide.registry[ options.group ]; 72 // eslint-disable-next-line vars-on-top 73 var show = function() { 74 // eslint-disable-next-line vars-on-top 75 for ( var i = 0; i < registry.length; ++i ) { 76 registry[ i ].hide(); 77 } 78 $container.show(); 79 if ( options.focus ) { 80 $( options.focus, $container ).focus(); 81 } 82 $link.html( options.hide_text ).addClass( 'open' ); 83 }; 84 // eslint-disable-next-line vars-on-top 85 var hide = function() { 86 $container.hide(); 87 $link.html( options.show_text ).removeClass( 'open' ); 88 }; 89 registry.push( { show: show, hide: hide } ); 90 $link.click( function() { 91 if ( $container.is( ':visible' ) ) { 92 hide(); 93 } else { 94 show(); 95 } 96 return false; 97 } ); 98 }; 99 }( jQuery ) 100 ); 101 $gp.showhide.registry = {};
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:01:04 2024 | Cross-referenced by PHPXref 0.7.1 |