src/ztfy/myams/resources/js/myams-notify.js
changeset 142 0201f1422bd7
parent 38 173b951c6aef
child 206 02a40997d8cb
--- a/src/ztfy/myams/resources/js/myams-notify.js	Tue Nov 17 12:04:26 2015 +0100
+++ b/src/ztfy/myams/resources/js/myams-notify.js	Tue Nov 17 12:05:38 2015 +0100
@@ -5,7 +5,9 @@
  */
 
 
-(function ($) {
+(function ($, globals) {
+
+	'use strict';
 
 	$(document).ready(function () {
 		$("body").append("<div id='divSmallBoxes'></div>")
@@ -20,18 +22,19 @@
 		});
 		$(".LoadingBoxContainer").fadeOut(300, function () {
 			$(this).remove();
-		})
+		});
 	}
 
 	var ExistMsg = 0,
 		SmartMSGboxCount = 0,
-		PrevTop = 0,
+		heightPrev,
 		BigBoxes = 0,
 		SmallBoxes = 0,
-		SmallCount = 0,
 		SmallBoxesAnchos = 0;
 
 
+	var MyAMS = globals.MyAMS;
+
 	MyAMS.notify = {
 
 		messageBox: function (options, callback) {
@@ -49,10 +52,10 @@
 				placeholder: "",
 				options: undefined,
 				sound: undefined
-			}
+			};
 			var settings = $.extend({}, defaults, options);
 
-			if (settings.sound && (isIE8 == 0)) {
+			if (settings.sound && (isIE8 === 0)) {
 				var audioElement = document.createElement("audio");
 				if (navigator.userAgent.match("Firefox/")) {
 					audioElement.setAttribute("src", MyAMS.baseURL + '../sound/message.ogg');
@@ -61,25 +64,26 @@
 				}
 				$.get();
 				audioElement.addEventListener("load", function () {
-					audioElement.play()
+					audioElement.play();
 				}, true);
 				audioElement.pause();
 				audioElement.play();
 			}
 			SmartMSGboxCount = SmartMSGboxCount + 1;
-			if (ExistMsg == 0) {
+			if (ExistMsg === 0) {
 				ExistMsg = 1;
 				SmartMSG = "<div class='MessageBox animated fadeIn fast' id='MsgBoxBack'></div>";
 				$("body").append(SmartMSG);
-				if (MyAMS.browser.isIE8orlower() == 1) {
+				if (MyAMS.browser.isIE8orlower() === 1) {
 					$("#MsgBoxBack").addClass("MessageIE");
 				}
 			}
+			var i;
 			var InputType = "";
 			var HasInput = 0;
 			var Name = "";
 			var NumButtons = 0;
-			if (settings.input != undefined) {
+			if (settings.input !== undefined) {
 				HasInput = 1;
 				settings.input = settings.input.toLowerCase();
 				switch (settings.input) {
@@ -90,15 +94,17 @@
 						InputType = "<input class='form-control' type='" + settings.input + "' id='txt" + SmartMSGboxCount + "' placeholder='" + settings.placeholder + "'/><br/><br/>";
 						break;
 					case "select":
-						if (settings.options == undefined) {
-							alert("For this type of input, the options parameter is required.");
+						if (settings.options === undefined) {
+							if (globals.alert) {
+								globals.alert("For this type of input, the options parameter is required.");
+							}
 						} else {
 							InputType = "<select class='form-control' id='txt" + SmartMSGboxCount + "'>";
-							for (var i = 0; i <= settings.options.length - 1; i++) {
-								if (settings.options[i] == "[") {
+							for (i=0; i <= settings.options.length - 1; i++) {
+								if (settings.options[i] === "[") {
 									Name = "";
 								} else {
-									if (settings.options[i] == "]") {
+									if (settings.options[i] === "]") {
 										NumButtons = NumButtons + 1;
 										Name = "<option>" + Name + "</option>";
 										InputType += Name;
@@ -111,7 +117,9 @@
 						}
 						break;
 					default:
-						alert("That type of input is not handled yet");
+						if (globals.alert) {
+							globals.alert("That type of input is not handled yet");
+						}
 				}
 			}
 			Content = "<div class='MessageBoxContainer animated fadeIn fast' id='Msg" + SmartMSGboxCount + "'>";
@@ -120,22 +128,22 @@
 			Content += "<p class='pText'>" + settings.content + "</p>";
 			Content += InputType;
 			Content += "<div class='MessageBoxButtonSection'>";
-			if (settings.buttons == undefined) {
+			if (settings.buttons === undefined) {
 				settings.buttons = "[Accept]";
 			}
 			settings.buttons = $.trim(settings.buttons);
 			settings.buttons = settings.buttons.split("");
-			if (settings.NormalButton == undefined) {
+			if (settings.NormalButton === undefined) {
 				settings.NormalButton = "#232323";
 			}
-			if (settings.ActiveButton == undefined) {
+			if (settings.ActiveButton === undefined) {
 				settings.ActiveButton = "#ed145b";
 			}
-			for (var i = 0; i <= settings.buttons.length - 1; i++) {
-				if (settings.buttons[i] == "[") {
+			for (i=0; i <= settings.buttons.length - 1; i++) {
+				if (settings.buttons[i] === "[") {
 					Name = "";
 				} else {
-					if (settings.buttons[i] == "]") {
+					if (settings.buttons[i] === "]") {
 						NumButtons = NumButtons + 1;
 						Name = "<button id='bot" + NumButtons + "-Msg" + SmartMSGboxCount + "' class='btn btn-default btn-sm botTempo'> " + Name + "</button>";
 						Content += Name;
@@ -152,7 +160,7 @@
 				$(".MessageBoxContainer").css("z-index", 99999);
 			}
 			$(".MessageBox").append(Content);
-			if (HasInput == 1) {
+			if (HasInput === 1) {
 				$("#txt" + SmartMSGboxCount).focus();
 			}
 			$(".botTempo").hover(function () {
@@ -164,8 +172,8 @@
 				var ThisID = $(this).attr("id");
 				var MsgBoxID = ThisID.substr(ThisID.indexOf("-") + 1);
 				var Press = $.trim($(this).text());
-				if (HasInput == 1) {
-					if (typeof callback == "function") {
+				if (HasInput === 1) {
+					if (typeof callback === "function") {
 						var IDNumber = MsgBoxID.replace("Msg", "");
 						var Value = $("#txt" + IDNumber).val();
 						if (callback) {
@@ -173,7 +181,7 @@
 						}
 					}
 				} else {
-					if (typeof callback == "function") {
+					if (typeof callback === "function") {
 						if (callback) {
 							callback(Press);
 						}
@@ -181,13 +189,13 @@
 				}
 				$("#" + MsgBoxID).addClass("animated fadeOut fast");
 				SmartMSGboxCount = SmartMSGboxCount - 1;
-				if (SmartMSGboxCount == 0) {
+				if (SmartMSGboxCount === 0) {
 					$("#MsgBoxBack").removeClass("fadeIn").addClass("fadeOut").delay(300).queue(function () {
 						ExistMsg = 0;
 						$(this).remove();
-					})
+					});
 				}
-			})
+			});
 		},
 
 		bigBox: function (settings, callback) {
@@ -204,7 +212,7 @@
 				colors: undefined
 			}, settings);
 			if (settings.sound === true) {
-				if (MyAMS.browser.isIE8orlower() == 0) {
+				if (MyAMS.browser.isIE8orlower() === 0) {
 					var audioElement = document.createElement("audio");
 					if (navigator.userAgent.match("Firefox/")) {
 						audioElement.setAttribute("src", MyAMS.baseURL + '../snd/bigbox.ogg');
@@ -221,19 +229,19 @@
 			}
 			BigBoxes = BigBoxes + 1;
 			boxBig = "<div id='bigBox" + BigBoxes + "' class='BigBox animated fadeIn fast'><div id='bigBoxColor" + BigBoxes + "'><i class='btnClose fa fa-times' id='btnClose" + BigBoxes + "'></i>";
-			if (settings.icon == undefined) {
+			if (settings.icon === undefined) {
 				settings.icon = "fa fa-cloud";
 			}
 			boxBig += "<span><i class='" + settings.icon + "'></i>&nbsp; " + settings.title + "</span>";
 			boxBig += "<p>" + settings.content + "</p>";
 			boxBig += "<div class='bigboxnumber'>";
-			if (settings.number != undefined) {
+			if (settings.number !== undefined) {
 				boxBig += settings.number;
 			}
 			boxBig += "</div></div>";
 			boxBig += "</div>";
 			$("#divBigBoxes").append(boxBig);
-			if (settings.color == undefined) {
+			if (settings.color === undefined) {
 				settings.color = "#004d60";
 			}
 			$("#bigBox" + BigBoxes).css("background-color", settings.color);
@@ -252,13 +260,13 @@
 					$(this).show();
 					$(this).addClass("animated fadeIn");
 					$(this).clearQueue();
-				})
+				});
 			});
 			var ThisBigBoxCloseCross = $("#btnClose" + BigBoxes);
 			var ThisBigBox = $("#bigBox" + BigBoxes);
 			var ThisMiniIcon = $("#miniIcon" + BigBoxes);
 			var ColorTimeInterval;
-			if (settings.colors != undefined && settings.colors.length > 0) {
+			if (settings.colors !== undefined && settings.colors.length > 0) {
 				ThisBigBoxCloseCross.attr("colorcount", "0");
 				ColorTimeInterval = setInterval(function () {
 					var ColorIndex = ThisBigBoxCloseCross.attr("colorcount");
@@ -280,7 +288,7 @@
 			}
 			ThisBigBoxCloseCross.bind("click", function () {
 				clearInterval(ColorTimeInterval);
-				if (typeof callback == "function") {
+				if (typeof callback === "function") {
 					if (callback) {
 						callback();
 					}
@@ -297,9 +305,9 @@
 				$("#" + miniIcon).addClass("fadeOut fast").delay(300).queue(function () {
 					$(this).clearQueue();
 					$(this).remove();
-				})
+				});
 			});
-			if (settings.timeout != undefined) {
+			if (settings.timeout !== undefined) {
 				var TimedID = BigBoxes;
 				setTimeout(function () {
 					clearInterval(ColorTimeInterval);
@@ -314,7 +322,7 @@
 					icon.addClass("fadeOut fast").delay(300).queue(function () {
 						$(this).clearQueue();
 						$(this).remove();
-					})
+					});
 				}, settings.timeout);
 			}
 		},
@@ -333,7 +341,7 @@
 				colors: undefined
 			}, settings);
 			if (settings.sound === true) {
-				if (MyAMS.browser.isIE8orlower() == 0) {
+				if (MyAMS.browser.isIE8orlower() === 0) {
 					var audioElement = document.createElement("audio");
 					if (navigator.userAgent.match("Firefox/")) {
 						audioElement.setAttribute("src", MyAMS.baseURL + '../snd/smallbox.ogg');
@@ -352,20 +360,20 @@
 			BoxSmall = "";
 			var IconSection = "",
 				CurrentIDSmallbox = "smallbox" + SmallBoxes;
-			if (settings.iconSmall == undefined) {
+			if (settings.iconSmall === undefined) {
 				IconSection = "<div class='miniIcon'></div>";
 			} else {
 				IconSection = "<div class='miniIcon'><i class='miniPic " + settings.iconSmall + "'></i></div>";
-			} if (settings.icon == undefined) {
+			} if (settings.icon === undefined) {
 				BoxSmall = "<div id='smallbox" + SmallBoxes + "' class='SmallBox animated fadeInRight fast'><div class='textoFull'><span>" + settings.title + "</span><p>" + settings.content + "</p></div>" + IconSection + "</div>";
 			} else {
 				BoxSmall = "<div id='smallbox" + SmallBoxes + "' class='SmallBox animated fadeInRight fast'><div class='foto'><i class='" + settings.icon + "'></i></div><div class='textoFoto'><span>" + settings.title + "</span><p>" + settings.content + "</p></div>" + IconSection + "</div>";
-			} if (SmallBoxes == 1) {
+			} if (SmallBoxes === 1) {
 				$("#divSmallBoxes").append(BoxSmall);
 				SmallBoxesAnchos = $("#smallbox" + SmallBoxes).height() + 40;
 			} else {
 				var SmartExist = $(".SmallBox").size();
-				if (SmartExist == 0) {
+				if (SmartExist === 0) {
 					$("#divSmallBoxes").append(BoxSmall);
 					SmallBoxesAnchos = $("#smallbox" + SmallBoxes).height() + 40;
 				} else {
@@ -373,7 +381,7 @@
 					$("#smallbox" + SmallBoxes).css("top", SmallBoxesAnchos);
 					SmallBoxesAnchos = SmallBoxesAnchos + $("#smallbox" + SmallBoxes).height() + 20;
 					$(".SmallBox").each(function (index) {
-						if (index == 0) {
+						if (index === 0) {
 							$(this).css("top", 20);
 							heightPrev = $(this).height() + 40;
 							SmallBoxesAnchos = $(this).height() + 40;
@@ -382,17 +390,17 @@
 							heightPrev = heightPrev + $(this).height() + 20;
 							SmallBoxesAnchos = SmallBoxesAnchos + $(this).height() + 20;
 						}
-					})
+					});
 				}
 			}
 			var ThisSmallBox = $("#smallbox" + SmallBoxes);
-			if (settings.color == undefined) {
-				ThisSmallBox.css("background-color", "#004d60")
+			if (settings.color === undefined) {
+				ThisSmallBox.css("background-color", "#004d60");
 			} else {
-				ThisSmallBox.css("background-color", settings.color)
+				ThisSmallBox.css("background-color", settings.color);
 			}
 			var ColorTimeInterval;
-			if (settings.colors != undefined && settings.colors.length > 0) {
+			if (settings.colors !== undefined && settings.colors.length > 0) {
 				ThisSmallBox.attr("colorcount", "0");
 				ColorTimeInterval = setInterval(function () {
 					var ColorIndex = ThisSmallBox.attr("colorcount");
@@ -406,17 +414,17 @@
 					}
 				}, settings.colortime);
 			}
-			if (settings.timeout != undefined) {
+			if (settings.timeout !== undefined) {
 				setTimeout(function () {
 					clearInterval(ColorTimeInterval);
 					var ThisHeight = $(this).height() + 20;
 					var ID = CurrentIDSmallbox;
 					var ThisTop = $("#" + CurrentIDSmallbox).css("top");
-					if ($("#" + CurrentIDSmallbox + ":hover").length != 0) {
+					if ($("#" + CurrentIDSmallbox + ":hover").length !== 0) {
 						$("#" + CurrentIDSmallbox).on("mouseleave", function () {
 							SmallBoxesAnchos = SmallBoxesAnchos - ThisHeight;
 							$("#" + CurrentIDSmallbox).remove();
-							if (typeof callback == "function") {
+							if (typeof callback === "function") {
 								if (callback) {
 									callback();
 								}
@@ -424,7 +432,7 @@
 							var Primero = 1;
 							var heightPrev = 0;
 							$(".SmallBox").each(function (index) {
-								if (index == 0) {
+								if (index === 0) {
 									$(this).animate({
 										top: 20
 									}, 300);
@@ -437,12 +445,12 @@
 									heightPrev = heightPrev + $(this).height() + 20;
 									SmallBoxesAnchos = SmallBoxesAnchos + $(this).height() + 20;
 								}
-							})
-						})
+							});
+						});
 					} else {
 						clearInterval(ColorTimeInterval);
 						SmallBoxesAnchos = SmallBoxesAnchos - ThisHeight;
-						if (typeof callback == "function") {
+						if (typeof callback === "function") {
 							if (callback) {
 								callback();
 							}
@@ -454,7 +462,7 @@
 							var Primero = 1;
 							var heightPrev = 0;
 							$(".SmallBox").each(function (index) {
-								if (index == 0) {
+								if (index === 0) {
 									$(this).animate({
 										top: 20
 									}, 300);
@@ -467,14 +475,14 @@
 									heightPrev = heightPrev + $(this).height() + 20;
 									SmallBoxesAnchos = SmallBoxesAnchos + $(this).height() + 20;
 								}
-							})
+							});
 						});
 					}
-				}, settings.timeout)
+				}, settings.timeout);
 			}
 			$("#smallbox" + SmallBoxes).bind("click", function () {
 				clearInterval(ColorTimeInterval);
-				if (typeof callback == "function") {
+				if (typeof callback === "function") {
 					if (callback) {
 						callback();
 					}
@@ -490,7 +498,7 @@
 					var Primero = 1;
 					var heightPrev = 0;
 					$(".SmallBox").each(function (index) {
-						if (index == 0) {
+						if (index === 0) {
 							$(this).animate({
 								top: 20
 							}, 300);
@@ -507,6 +515,6 @@
 				});
 			});
 		}
-	}
+	};
 
-})(jQuery);
+})(jQuery, this);