72 lines
1.5 KiB
JavaScript
72 lines
1.5 KiB
JavaScript
( function( $ ) {
|
|
|
|
$.fn.ErrorTipBox = function( options ) {
|
|
var opts = $.extend( {}, $.fn.ErrorTipBox.defaults, options );
|
|
var $this = this;
|
|
var related_widget;
|
|
var timer;
|
|
|
|
Global.addCss( 'global/widgets/error_tip/ErrorTipBox.css' );
|
|
|
|
this.cancelRemove = function() {
|
|
if ( Global.isSet( timer ) ) {
|
|
clearTimeout( timer );
|
|
}
|
|
|
|
};
|
|
|
|
this.show = function( target, error_string, sec, isWarning ) {
|
|
related_widget = target;
|
|
|
|
if ( isWarning ) {
|
|
$( this ).addClass( 'warningtip-box' );
|
|
} else {
|
|
$( this ).removeClass( 'warningtip-box' );
|
|
}
|
|
|
|
if ( $.type( error_string ) === 'array' ) {
|
|
error_string = error_string.join( '<br>' );
|
|
}
|
|
|
|
var error_tip_label = $( this ).find( '.errortip-label' );
|
|
error_tip_label.html( error_string );
|
|
|
|
$( this ).css( 'left', related_widget.offset().left + related_widget.width() + 5 );
|
|
|
|
if ( related_widget.hasClass( 'a-combobox' ) ) {
|
|
$( this ).css( 'top', related_widget.offset().top );
|
|
} else {
|
|
$( this ).css( 'top', related_widget.offset().top );
|
|
}
|
|
|
|
$( 'body' ).append( this );
|
|
|
|
if ( sec > 0 ) {
|
|
timer = setTimeout( function() {
|
|
$this.remove();
|
|
}, sec * 1000 );
|
|
}
|
|
};
|
|
|
|
this.remove = function() {
|
|
$( this ).remove();
|
|
};
|
|
|
|
this.each( function() {
|
|
|
|
var o = $.meta ? $.extend( {}, opts, $( this ).data() ) : opts;
|
|
|
|
} );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
$.fn.ErrorTipBox.defaults = {};
|
|
$.fn.ErrorTipBox.html_template = `
|
|
<div class="errortip-box">
|
|
<span class="errortip-label"></span>
|
|
</div>
|
|
`;
|
|
|
|
} )( jQuery ); |