1+ /**
2+ * Global variables
3+ */
4+ var globalVariales = {
5+ defaultContainer : "#toasterContainer"
6+ } ;
7+
8+ /**
9+ * Toaster class
10+ * @param {* } data
11+ */
12+ function Toaster ( data ) {
13+ this . data = data ,
14+ this . color = "#FFF" ,
15+ this . background = "#333" ,
16+ this . verticalPosition = "bottom" ,
17+ this . horizontalPosition = "right" ,
18+ this . container = globalVariales . defaultContainer ,
19+ this . width = "290px" ,
20+ this . height = "40px" ,
21+ this . padding = "5px" ,
22+ this . corderRadius = "5px" ,
23+ this . text = "" ,
24+ this . publish = publish
25+ }
26+
27+ // Instantiating Toaster class
28+ var toasterInstance = new Toaster ( ) ;
29+
30+ /**
31+ * Publishing the toaster
32+ */
33+ function publish ( ) {
34+ // Setting toaster properties
35+ setData ( this ) ;
36+
37+ // Appending default container if not specified
38+ if ( toasterInstance . container == globalVariales . defaultContainer ) {
39+ $ ( "body" ) . append ( '<div id="toasterContainer"></div>' ) ;
40+ }
41+ $ ( toasterInstance . container ) . show ( ) ;
42+ $ ( toasterInstance . container ) . css ( "margin-bottom" , "0px" ) ;
43+ $ ( toasterInstance . container ) . text ( toasterInstance . text ) . animate ( { 'marginBottom' : '50px' } , 800 ) . fadeOut ( 5000 ) . css ( {
44+ 'position' : 'absolute' ,
45+ 'bottom' : '30px' ,
46+ 'right' : '30px' ,
47+ 'width' : toasterInstance . width ,
48+ 'height' : toasterInstance . height ,
49+ 'background' : toasterInstance . background ,
50+ 'color' : toasterInstance . color ,
51+ 'padding' : toasterInstance . padding ,
52+ 'border-radius' : toasterInstance . corderRadius
53+ } ) ;
54+ }
55+
56+ /**
57+ * Setting Toaster class properties
58+ * @param {* } toaster
59+ */
60+ function setData ( toaster ) {
61+ // Checking if toaster exists
62+ if ( nullValidator ( toaster ) ) {
63+ // Checking if data in toaster exists
64+ if ( nullValidator ( toaster . data ) ) {
65+ toasterInstance . color = nullValidator ( toaster . data . color ) ? toaster . data . color : toaster . color ;
66+ toasterInstance . background = nullValidator ( toaster . data . background ) ? toaster . data . background : toaster . background ;
67+ toasterInstance . verticalPosition = nullValidator ( toaster . data . verticalPosition ) ? toaster . data . verticalPosition : toaster . verticalPosition ;
68+ toasterInstance . horizontalPosition = nullValidator ( toaster . data . horizontalPosition ) ? toaster . data . horizontalPosition : toaster . horizontalPosition ;
69+ toasterInstance . container = nullValidator ( toaster . data . container ) ? toaster . data . container : toaster . container ;
70+ toasterInstance . text = nullValidator ( toaster . data . text ) ? toaster . data . text : toaster . text ;
71+ }
72+ }
73+ }
74+
75+ /**
76+ * Validating null and undefined entries
77+ * @param {* } entity
78+ */
79+ function nullValidator ( entity ) {
80+ return ( entity != null || entity != undefined ) && entity != "" ? true : false ;
81+ }
0 commit comments