pointer.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Code-snippet for WordPress pointers. |
| 4 | * Used in function lib3()->html->pointer() |
| 5 | * |
| 6 | * @since 1.0.0 |
| 7 | * |
| 8 | * Variables: |
| 9 | * - $pointer_id |
| 10 | * - $html_el |
| 11 | * - $title |
| 12 | * - $body |
| 13 | * - $once |
| 14 | * - $modal |
| 15 | * - $blur |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Filter pointer classes |
| 20 | * |
| 21 | * @since 3.1.0 |
| 22 | */ |
| 23 | $class = implode( ' ', apply_filters( 'wpmui_pointer_classes', $classes ) ); |
| 24 | if ( ! empty( $title ) ) { |
| 25 | $title = '<h3>' . $title . '</h3>'; |
| 26 | } else { |
| 27 | $title = ''; |
| 28 | $class .= ' no-title'; |
| 29 | } |
| 30 | |
| 31 | $code = sprintf( |
| 32 | '<div class="%3$s">%1$s<p>%2$s</p></div>', |
| 33 | $title, |
| 34 | $body, |
| 35 | esc_attr( $class ) |
| 36 | ); |
| 37 | |
| 38 | // Remove linebreaks to avoid JS errors |
| 39 | $code = str_replace( array( "\r", "\n" ), '', $code ); |
| 40 | |
| 41 | ?> |
| 42 | <script> |
| 43 | jQuery(document).ready(function() { |
| 44 | var wpcontent = jQuery( '#wpbody' ), |
| 45 | body = jQuery( 'body' ); |
| 46 | |
| 47 | if ( jQuery().pointer !== undefined ) { |
| 48 | var target = jQuery( '<?php echo $html_el; ?>' ); |
| 49 | if ( ! target.length ) { return; } |
| 50 | target = target.first(); |
| 51 | |
| 52 | <?php if ( $blur ) : ?> |
| 53 | wpcontent.addClass( 'wpmui-blur' ); |
| 54 | <?php else : ?> |
| 55 | body.addClass( 'no-blur' ); |
| 56 | <?php endif; ?> |
| 57 | |
| 58 | <?php if ( $modal ) : ?> |
| 59 | var modal = wpmUi._make_modal( 'light' ); |
| 60 | if ( undefined !== modal ) { |
| 61 | modal.on( 'click', function( ev ) { |
| 62 | target.pointer( 'close' ); |
| 63 | }); |
| 64 | } else { |
| 65 | wpmUi._close_modal(); |
| 66 | } |
| 67 | <?php endif; ?> |
| 68 | |
| 69 | // Insert the pointer HTML code |
| 70 | target.pointer({ |
| 71 | content: '<?php echo $code; ?>', |
| 72 | position: { |
| 73 | edge: 'left', |
| 74 | align: 'center' |
| 75 | }, |
| 76 | close: function() { |
| 77 | <?php if ( $blur ) : ?> |
| 78 | wpcontent.removeClass( 'wpmui-blur' ); |
| 79 | <?php else : ?> |
| 80 | body.removeClass( 'no-blur' ); |
| 81 | <?php endif; ?> |
| 82 | |
| 83 | <?php if ( $modal ) : ?> |
| 84 | wpmUi._close_modal(); |
| 85 | <?php endif; ?> |
| 86 | |
| 87 | <?php if ( $once ) : ?> |
| 88 | jQuery.post( ajaxurl, { |
| 89 | pointer: '<?php echo esc_js( $pointer_id ) ?>', |
| 90 | action: 'dismiss-wp-pointer' |
| 91 | }); |
| 92 | <?php endif; ?> |
| 93 | } |
| 94 | }).pointer('open'); |
| 95 | |
| 96 | // Modify the default pointer style |
| 97 | jQuery( '.wpmui-pointer-handler.prepared' ).each(function() { |
| 98 | var me = jQuery(this), |
| 99 | ptr = me.closest('.wp-pointer'); |
| 100 | me.removeClass('prepared'); |
| 101 | ptr.addClass( me.attr( 'class' ) ); |
| 102 | me.removeClass('wpmui-pointer-handler'); |
| 103 | }); |
| 104 | } |
| 105 | }); |
| 106 | </script> |
| 107 |