22 * Toaster class
33 * @param {* } data
44 */
5- function Toaster ( ) {
5+ function Toaster ( data ) {
6+
7+ // Constructor values
8+ this . data = data ,
69
710 // Default properties
811 this . defaultValues = {
@@ -15,7 +18,7 @@ function Toaster() {
1518 width : "290px" ,
1619 height : "40px" ,
1720 padding : "5px" ,
18- corderRadius : "5px"
21+ cornerRadius : "5px"
1922 } ,
2023
2124 // Class properties
@@ -28,22 +31,22 @@ function Toaster() {
2831 this . width ,
2932 this . height ,
3033 this . padding ,
31- this . corderRadius ,
34+ this . cornerRadius ,
3235
3336 // Setting default and new values
34- this . setData = function ( data ) {
37+ this . setData = function ( toasterData ) {
3538 // Checking if data exists
36- if ( this . isNull ( data ) ) {
37- this . color = this . isNull ( data . color ) ? data . color : this . defaultValues . color ;
38- this . background = this . isNull ( data . background ) ? data . background : this . defaultValues . background ;
39- this . verticalPosition = this . isNull ( data . verticalPosition ) ? data . verticalPosition : this . defaultValues . verticalPosition ;
40- this . horizontalPosition = this . isNull ( data . horizontalPosition ) ? data . horizontalPosition : this . defaultValues . horizontalPosition ;
41- this . container = this . isNull ( data . container ) ? data . container : this . defaultValues . container ;
42- this . text = this . isNull ( data . text ) ? data . text : this . defaultValues . text ;
43- this . width = this . isNull ( data . width ) ? data . width : this . defaultValues . width ;
44- this . height = this . isNull ( data . height ) ? data . height : this . defaultValues . height ;
45- this . padding = this . isNull ( data . padding ) ? data . padding : this . defaultValues . padding ;
46- this . corderRadius = this . isNull ( data . corderRadius ) ? data . text : this . defaultValues . corderRadius ;
39+ if ( this . isNull ( toasterData ) ) {
40+ this . color = this . isNull ( toasterData . data . color ) ? toasterData . data . color : this . defaultValues . color ;
41+ this . background = this . isNull ( toasterData . data . background ) ? toasterData . data . background : this . defaultValues . background ;
42+ this . verticalPosition = this . isNull ( toasterData . data . verticalPosition ) ? toasterData . data . verticalPosition : this . defaultValues . verticalPosition ;
43+ this . horizontalPosition = this . isNull ( toasterData . data . horizontalPosition ) ? toasterData . data . horizontalPosition : this . defaultValues . horizontalPosition ;
44+ this . container = this . isNull ( toasterData . data . container ) ? toasterData . data . container : this . defaultValues . container ;
45+ this . text = this . isNull ( toasterData . data . text ) ? toasterData . data . text : this . defaultValues . text ;
46+ this . width = this . isNull ( toasterData . data . width ) ? toasterData . data . width : this . defaultValues . width ;
47+ this . height = this . isNull ( toasterData . data . height ) ? toasterData . data . height : this . defaultValues . height ;
48+ this . padding = this . isNull ( toasterData . data . padding ) ? toasterData . data . padding : this . defaultValues . padding ;
49+ this . cornerRadius = this . isNull ( toasterData . data . cornerRadius ) ? toasterData . data . text : this . defaultValues . cornerRadius ;
4750 }
4851 } ,
4952
@@ -59,20 +62,33 @@ function Toaster() {
5962 } ) . appendTo ( 'body' ) ;
6063 }
6164 $ ( this . container ) . show ( ) ;
62- $ ( this . container ) . css ( "margin-bottom" , "0px" ) ;
65+ $ ( this . container ) . stop ( ) ;
6366
6467 // Applying animation and styling
65- $ ( this . container ) . text ( this . text ) . animate ( { 'marginBottom' : '50px' } , 800 ) . fadeOut ( 5000 ) . css ( {
68+ $ ( this . container ) . css ( {
6669 'position' : 'absolute' ,
67- 'bottom' : '30px' ,
68- 'right' : '30px' ,
6970 'width' : this . width ,
7071 'height' : this . height ,
7172 'background' : this . background ,
7273 'color' : this . color ,
7374 'padding' : this . padding ,
74- 'border-radius' : this . corderRadius
75+ 'border-radius' : this . cornerRadius
7576 } ) ;
77+
78+ // For vertical positioning
79+ if ( this . verticalPosition == "top" ) {
80+ $ ( this . container ) . css ( "top" , "30px" ) ;
81+ } else {
82+ $ ( this . container ) . css ( "bottom" , "30px" ) ;
83+ }
84+
85+ // For horizontal positioning
86+ if ( this . horizontalPosition == "left" ) {
87+ $ ( this . container ) . css ( "left" , "30px" ) ;
88+ } else {
89+ $ ( this . container ) . css ( "right" , "30px" ) ;
90+ }
91+ $ ( this . container ) . text ( this . text ) . animate ( { 'opacity' : '1' } , 400 ) . fadeOut ( 5000 ) ;
7692 } ,
7793
7894 // Validating null values
0 commit comments