| @@ -1,134 +1,134 @@ | ||
| 1 | -( function( $ ) { | |
| 2 | - function QuickTip( el, options ) { | |
| 3 | - const $el = $( el ), | |
| 4 | - uniId = $el.attr( 'data-id' ) || LP.uniqueId(); | |
| 5 | - | |
| 6 | - options = $.extend( { | |
| 7 | - event: 'hover', | |
| 8 | - autoClose: true, | |
| 9 | - single: true, | |
| 10 | - closeInterval: 1000, | |
| 11 | - arrowOffset: null, | |
| 12 | - tipClass: '', | |
| 13 | - }, options, $el.data() ); | |
| 14 | - | |
| 15 | - $el.attr( 'data-id', uniId ); | |
| 16 | - | |
| 17 | - let content = $el.attr( 'data-content-tip' ) || $el.html(), | |
| 18 | - $tip = $( '<div class="learn-press-tip-floating">' + content + '</div>' ), | |
| 19 | - t = null, | |
| 20 | - closeInterval = 0, | |
| 21 | - useData = false, | |
| 22 | - arrowOffset = options.arrowOffset === 'el' ? $el.outerWidth() / 2 : 8, | |
| 23 | - $content = $( '#__' + uniId ); | |
| 24 | - | |
| 25 | - if ( $content.length === 0 ) { | |
| 26 | - $( document.body ).append( $( '<div />' ).attr( 'id', '__' + uniId ).html( content ).css( 'display', 'none' ) ); | |
| 27 | - } | |
| 28 | - | |
| 29 | - content = $content.html(); | |
| 30 | - | |
| 31 | - $tip.addClass( options.tipClass ); | |
| 32 | - | |
| 33 | - $el.data( 'content-tip', content ); | |
| 34 | - if ( $el.attr( 'data-content-tip' ) ) { | |
| 35 | - //$el.removeAttr('data-content-tip'); | |
| 36 | - useData = true; | |
| 37 | - } | |
| 38 | - | |
| 39 | - closeInterval = options.closeInterval; | |
| 40 | - | |
| 41 | - if ( options.autoClose === false ) { | |
| 42 | - $tip.append( '<a class="close"></a>' ); | |
| 43 | - $tip.on( 'click', '.close', function() { | |
| 44 | - close(); | |
| 45 | - } ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - function show() { | |
| 49 | - if ( t ) { | |
| 50 | - clearTimeout( t ); | |
| 51 | - return; | |
| 52 | - } | |
| 53 | - | |
| 54 | - if ( options.single ) { | |
| 55 | - $( '.learn-press-tip' ).not( $el ).LP( 'QuickTip', 'close' ); | |
| 56 | - } | |
| 57 | - | |
| 58 | - $tip.appendTo( document.body ); | |
| 59 | - const pos = $el.offset(); | |
| 60 | - | |
| 61 | - $tip.css( { | |
| 62 | - top: pos.top - $tip.outerHeight() - 8, | |
| 63 | - left: pos.left - $tip.outerWidth() / 2 + arrowOffset, | |
| 64 | - } ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - function hide() { | |
| 68 | - t && clearTimeout( t ); | |
| 69 | - t = setTimeout( function() { | |
| 70 | - $tip.detach(); | |
| 71 | - t = null; | |
| 72 | - }, closeInterval ); | |
| 73 | - } | |
| 74 | - | |
| 75 | - function close() { | |
| 76 | - closeInterval = 0; | |
| 77 | - hide(); | |
| 78 | - closeInterval = options.closeInterval; | |
| 79 | - } | |
| 80 | - | |
| 81 | - function open() { | |
| 82 | - show(); | |
| 83 | - } | |
| 84 | - | |
| 85 | - if ( ! useData ) { | |
| 86 | - $el.html( '' ); | |
| 87 | - } | |
| 88 | - | |
| 89 | - if ( options.event === 'click' ) { | |
| 90 | - $el.on( 'click', function( e ) { | |
| 91 | - e.stopPropagation(); | |
| 92 | - show(); | |
| 93 | - } ); | |
| 94 | - } | |
| 95 | - | |
| 96 | - $( document ).on( 'learn-press/close-all-quick-tip', function() { | |
| 97 | - close(); | |
| 98 | - } ); | |
| 99 | - $el.hover( | |
| 100 | - function( e ) { | |
| 101 | - e.stopPropagation(); | |
| 102 | - if ( options.event !== 'click' ) { | |
| 103 | - show(); | |
| 104 | - } | |
| 105 | - }, | |
| 106 | - function( e ) { | |
| 107 | - e.stopPropagation(); | |
| 108 | - if ( options.autoClose ) { | |
| 109 | - hide(); | |
| 110 | - } | |
| 111 | - } | |
| 112 | - ).addClass( 'ready' ); | |
| 113 | - return { | |
| 114 | - close, | |
| 115 | - open, | |
| 116 | - }; | |
| 117 | - } | |
| 118 | - | |
| 119 | - $.fn.LP( 'QuickTip', function( options ) { | |
| 120 | - return $.each( this, function() { | |
| 121 | - let $tip = $( this ).data( 'quick-tip' ); | |
| 122 | - | |
| 123 | - if ( ! $tip ) { | |
| 124 | - $tip = new QuickTip( this, options ); | |
| 125 | - $( this ).data( 'quick-tip', $tip ); | |
| 126 | - } | |
| 127 | - | |
| 128 | - if ( typeof options === 'string' ) { | |
| 129 | - $tip[ options ] && $tip[ options ].apply( $tip ); | |
| 130 | - } | |
| 131 | - } ); | |
| 132 | - } ); | |
| 133 | -} | |
| 134 | -( jQuery ) ); | |
| 1 | +( function( $ ) { | |
| 2 | + function QuickTip( el, options ) { | |
| 3 | + const $el = $( el ), | |
| 4 | + uniId = $el.attr( 'data-id' ) || LP.uniqueId(); | |
| 5 | + | |
| 6 | + options = $.extend( { | |
| 7 | + event: 'hover', | |
| 8 | + autoClose: true, | |
| 9 | + single: true, | |
| 10 | + closeInterval: 1000, | |
| 11 | + arrowOffset: null, | |
| 12 | + tipClass: '', | |
| 13 | + }, options, $el.data() ); | |
| 14 | + | |
| 15 | + $el.attr( 'data-id', uniId ); | |
| 16 | + | |
| 17 | + let content = $el.attr( 'data-content-tip' ) || $el.html(), | |
| 18 | + $tip = $( '<div class="learn-press-tip-floating">' + content + '</div>' ), | |
| 19 | + t = null, | |
| 20 | + closeInterval = 0, | |
| 21 | + useData = false, | |
| 22 | + arrowOffset = options.arrowOffset === 'el' ? $el.outerWidth() / 2 : 8, | |
| 23 | + $content = $( '#__' + uniId ); | |
| 24 | + | |
| 25 | + if ( $content.length === 0 ) { | |
| 26 | + $( document.body ).append( $( '<div />' ).attr( 'id', '__' + uniId ).html( content ).css( 'display', 'none' ) ); | |
| 27 | + } | |
| 28 | + | |
| 29 | + content = $content.html(); | |
| 30 | + | |
| 31 | + $tip.addClass( options.tipClass ); | |
| 32 | + | |
| 33 | + $el.data( 'content-tip', content ); | |
| 34 | + if ( $el.attr( 'data-content-tip' ) ) { | |
| 35 | + //$el.removeAttr('data-content-tip'); | |
| 36 | + useData = true; | |
| 37 | + } | |
| 38 | + | |
| 39 | + closeInterval = options.closeInterval; | |
| 40 | + | |
| 41 | + if ( options.autoClose === false ) { | |
| 42 | + $tip.append( '<a class="close"></a>' ); | |
| 43 | + $tip.on( 'click', '.close', function() { | |
| 44 | + close(); | |
| 45 | + } ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + function show() { | |
| 49 | + if ( t ) { | |
| 50 | + clearTimeout( t ); | |
| 51 | + return; | |
| 52 | + } | |
| 53 | + | |
| 54 | + if ( options.single ) { | |
| 55 | + $( '.learn-press-tip' ).not( $el ).LP( 'QuickTip', 'close' ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + $tip.appendTo( document.body ); | |
| 59 | + const pos = $el.offset(); | |
| 60 | + | |
| 61 | + $tip.css( { | |
| 62 | + top: pos.top - $tip.outerHeight() - 8, | |
| 63 | + left: pos.left - $tip.outerWidth() / 2 + arrowOffset, | |
| 64 | + } ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + function hide() { | |
| 68 | + t && clearTimeout( t ); | |
| 69 | + t = setTimeout( function() { | |
| 70 | + $tip.detach(); | |
| 71 | + t = null; | |
| 72 | + }, closeInterval ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + function close() { | |
| 76 | + closeInterval = 0; | |
| 77 | + hide(); | |
| 78 | + closeInterval = options.closeInterval; | |
| 79 | + } | |
| 80 | + | |
| 81 | + function open() { | |
| 82 | + show(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + if ( ! useData ) { | |
| 86 | + $el.html( '' ); | |
| 87 | + } | |
| 88 | + | |
| 89 | + if ( options.event === 'click' ) { | |
| 90 | + $el.on( 'click', function( e ) { | |
| 91 | + e.stopPropagation(); | |
| 92 | + show(); | |
| 93 | + } ); | |
| 94 | + } | |
| 95 | + | |
| 96 | + $( document ).on( 'learn-press/close-all-quick-tip', function() { | |
| 97 | + close(); | |
| 98 | + } ); | |
| 99 | + $el.hover( | |
| 100 | + function( e ) { | |
| 101 | + e.stopPropagation(); | |
| 102 | + if ( options.event !== 'click' ) { | |
| 103 | + show(); | |
| 104 | + } | |
| 105 | + }, | |
| 106 | + function( e ) { | |
| 107 | + e.stopPropagation(); | |
| 108 | + if ( options.autoClose ) { | |
| 109 | + hide(); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + ).addClass( 'ready' ); | |
| 113 | + return { | |
| 114 | + close, | |
| 115 | + open, | |
| 116 | + }; | |
| 117 | + } | |
| 118 | + | |
| 119 | + $.fn.LP( 'QuickTip', function( options ) { | |
| 120 | + return $.each( this, function() { | |
| 121 | + let $tip = $( this ).data( 'quick-tip' ); | |
| 122 | + | |
| 123 | + if ( ! $tip ) { | |
| 124 | + $tip = new QuickTip( this, options ); | |
| 125 | + $( this ).data( 'quick-tip', $tip ); | |
| 126 | + } | |
| 127 | + | |
| 128 | + if ( typeof options === 'string' ) { | |
| 129 | + $tip[ options ] && $tip[ options ].apply( $tip ); | |
| 130 | + } | |
| 131 | + } ); | |
| 132 | + } ); | |
| 133 | +} | |
| 134 | +( jQuery ) ); | |