src/ztfy/myams/resources/js/myams-dataTables.js
changeset 142 0201f1422bd7
parent 136 3ea42c4b9938
--- a/src/ztfy/myams/resources/js/myams-dataTables.js	Tue Nov 17 12:04:26 2015 +0100
+++ b/src/ztfy/myams/resources/js/myams-dataTables.js	Tue Nov 17 12:05:38 2015 +0100
@@ -5,7 +5,9 @@
  */
 
 
-(function($) {
+(function($, globals) {
+
+	"use strict";
 
 	/**
 	 * Update default values for DataTables initialization
@@ -86,9 +88,10 @@
 		// date-euro column sorter
 		"date-euro-pre": function(a) {
 			var trimmed = $.trim(a);
-			if (trimmed != '') {
+			var x;
+			if (trimmed !== '') {
 				var frDate= trimmed.split('/');
-				var x = (frDate[2] + frDate[1] + frDate[0]) * 1;
+				x = (frDate[2] + frDate[1] + frDate[0]) * 1;
 			} else {
 				x = 10000000; // = l'an 1000 ...
 			}
@@ -106,11 +109,12 @@
 		// datetime-euro column sorter
 		"datetime-euro-pre": function(a) {
 			var trimmed = $.trim(a);
-			if (trimmed != '') {
+			var x;
+			if (trimmed !== '') {
 				var frDateTime = trimmed.split(' - ');
 				var frDate= frDateTime[0].split('/');
 				var frTime = frDateTime[1].split(':');
-				var x = (frDate[2] + frDate[1] + frDate[0] + frTime[0] + frTime[1]) * 1;
+				x = (frDate[2] + frDate[1] + frDate[0] + frTime[0] + frTime[1]) * 1;
 			} else {
 				x = 100000000000; // = l'an 1000 ...
 			}
@@ -136,8 +140,9 @@
 				var oLang = oSettings.oLanguage.oPaginate;
 				var fnClickHandler = function (e) {
 					e.preventDefault();
-					if (oSettings.oApi._fnPageChange(oSettings, e.data.action))
+					if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
 						fnDraw(oSettings);
+					}
 				};
 
 				$(nPaging).append(
@@ -183,7 +188,7 @@
 
 					// Add the new list items and their event handlers
 					for (j=iStart ; j<=iEnd ; j++) {
-						sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
+						sClass = (j === oPaging.iPage+1) ? 'class="active"' : '';
 						$('<li '+sClass+'><a href="#">'+j+'</a></li>')
 							.insertBefore( $('li:last', an[i])[0] )
 							.on('click', function (e) {
@@ -194,15 +199,17 @@
 					}
 
 					// Add / remove disabled classes from the static elements
-					if (oPaging.iPage === 0)
+					if (oPaging.iPage === 0) {
 						$('li:first', an[i]).addClass('disabled');
-					else
+					} else {
 						$('li:first', an[i]).removeClass('disabled');
+					}
 
-					if (oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0)
+					if (oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0) {
 						$('li:last', an[i]).addClass('disabled');
-					else
+					} else {
 						$('li:last', an[i]).removeClass('disabled');
+					}
 				}
 			}
 		}
@@ -218,8 +225,9 @@
 				var oLang = oSettings.oLanguage.oPaginate;
 				var fnClickHandler = function (e) {
 					e.preventDefault();
-					if (oSettings.oApi._fnPageChange(oSettings, e.data.action))
+					if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
 						fnDraw(oSettings);
+					}
 				};
 
 				$(nPaging).append(
@@ -269,14 +277,14 @@
 
 					// Add the new list items and their event handlers
 					for (j=iStart ; j<=iEnd ; j++) {
-						sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
+						sClass = (j === oPaging.iPage+1) ? 'class="active"' : '';
 						$('<li '+sClass+'><a href="#">'+j+'</a></li>')
 							.insertBefore( $('li.next', an[i])[0] )
 							.on('click', function (e) {
 								e.preventDefault();
 								oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
 								fnDraw( oSettings );
-							} );
+							});
 					}
 
 					// Add / remove disabled classes from the static elements
@@ -310,8 +318,9 @@
 				var oLang = oSettings.oLanguage.oPaginate;
 				var fnClickHandler = function (e) {
 					e.preventDefault();
-					if (oSettings.oApi._fnPageChange(oSettings, e.data.action))
+					if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
 						fnDraw(oSettings);
+					}
 				};
 
 				$(nPaging).append(
@@ -428,12 +437,17 @@
 
 		var BootstrapLength = function(oSettings, oInit) {
 
-			if (!this.CLASS || this.CLASS != 'BootstrapLength')
-				alert("Warning: BootstrapLength must be initialized with the 'new' keyword");
-			if (typeof(oInit) == 'undefined')
+			if (!this.CLASS || this.CLASS !== 'BootstrapLength') {
+				if (globals.alert) {
+					globals.alert("Warning: BootstrapLength must be initialized with the 'new' keyword");
+				}
+			}
+			if (typeof(oInit) === 'undefined') {
 				oInit = {};
-			if ($.fn.dataTable.camelToHungarian)
+			}
+			if ($.fn.dataTable.camelToHungarian) {
 				$.fn.dataTable.camelToHungarian(BootstrapLength.defaults, oInit);
+			}
 
 			this.s = {
 				dt: null,
@@ -447,8 +461,8 @@
 			};
 			BootstrapLength.aInstances.push(this);
 
-			this.s.dt = $.fn.dataTable.Api
-				? new $.fn.dataTable.Api(oSettings).settings()[0]
+			this.s.dt = $.fn.dataTable.Api ?
+				new $.fn.dataTable.Api(oSettings).settings()[0]
 				: oSettings;
 
 			this._fnConstruct(oInit);
@@ -471,22 +485,27 @@
 			_fnConstruct: function(init) {
 				var self = this;
 				var dt = self.s.dt;
-				if (dt.oScroll.bInfinite)
+				if (dt.oScroll.bInfinite) {
 					return;
+				}
 				var sName = dt.sTableId + '_length';
 				var sMenu = $('<select size="1"></select>').attr('name', sName);
 				var i, iLen;
 				var aLengthMenu = dt.aLengthMenu;
-				if (aLengthMenu.length == 2 && typeof(aLengthMenu[0]) == 'object' && typeof(aLengthMenu[1]) == 'object') {
-					for (i=0, iLen=aLengthMenu[0].length; i < iLen; i++)
+				if (aLengthMenu.length === 2 &&
+					typeof(aLengthMenu[0]) === 'object' &&
+					typeof(aLengthMenu[1]) === 'object') {
+					for (i=0, iLen=aLengthMenu[0].length; i < iLen; i++) {
 						$('<option />').attr('value', aLengthMenu[0][i])
 									   .text(aLengthMenu[1][i])
 									   .appendTo(sMenu);
+					}
 				} else {
-					for (i=0, iLen=aLengthMenu.length; i < iLen; i++)
+					for (i=0, iLen=aLengthMenu.length; i < iLen; i++) {
 						$('<option />').attr('value', aLengthMenu[i])
 									   .text(aLengthMenu[i])
 									   .appendTo(sMenu);
+					}
 				}
 				var nLength = $('<div>').addClass(dt.oClasses.sLength)
 										.append($('<span></span>').addClass('ams-form')
@@ -494,8 +513,9 @@
 																							  .css('width', 60)
 																							  .append(sMenu)
 																							  .append($('<i></i>'))));
-				if (!dt.aanFeatures.L)
+				if (!dt.aanFeatures.L) {
 					nLength.attr('id', dt.sTableId + '_length');
+				}
 				this.dom.wrapper = nLength.get(0);
 
 				$('select option[value="' + dt._iDisplayLength + '"]', nLength).attr("selected", true);
@@ -503,18 +523,21 @@
 					var iVal = $(this).val();
 					var n = dt.aanFeatures.L;
 					for (i = 0, iLen = n.length; i < iLen; i++) {
-						if (n[i] != this.parentNode)
-						  $("select", n[i]).val(iVal);
+						if (n[i] !== this.parentNode) {
+							$("select", n[i]).val(iVal);
+						}
 					}
 					dt._iDisplayLength = parseInt(iVal, 10);
 					dt.oInstance._fnCalculateEnd(dt);
-					if (dt.fnDisplayEnd() == dt.fnRecordsDisplay()) {
+					if (dt.fnDisplayEnd() === dt.fnRecordsDisplay()) {
 						dt._iDisplayStart = dt.fnDisplayEnd() - dt._iDisplayLength;
-						if (dt._iDisplayStart < 0)
+						if (dt._iDisplayStart < 0) {
 							dt._iDisplayStart = 0;
+						}
 					}
-					if (dt._iDisplayLength == -1)
+					if (dt._iDisplayLength === -1) {
 						dt._iDisplayStart = 0;
+					}
 					dt.oInstance._fnDraw();
 				});
 				$("select", nLength).attr("aria-controls", dt.sTableId);
@@ -530,8 +553,8 @@
 		BootstrapLength.VERSION = '1.0.0';
 		BootstrapLength.prototype.VERSION = BootstrapLength.VERSION;
 
-		if ((typeof($.fn.dataTable) == 'function') &&
-			(typeof($.fn.dataTableExt.fnVersionCheck) == 'function') &&
+		if ((typeof($.fn.dataTable) === 'function') &&
+			(typeof($.fn.dataTableExt.fnVersionCheck) === 'function') &&
 			$.fn.dataTableExt.fnVersionCheck('1.7.0')) {
 			$.fn.dataTableExt.aoFeatures.push({
 				fnInit: function(oSettings) {
@@ -543,7 +566,9 @@
 				sFeature: "BootstrapLength"
 			});
 		} else {
-			alert("Warning: BootstrapLength required DataTables 1.7 or greater...");
+			if (globals.alert) {
+				globals.alert("Warning: BootstrapLength required DataTables 1.7 or greater...");
+			}
 		}
 
 		$.fn.dataTable.BootstrapLength = BootstrapLength;
@@ -551,7 +576,7 @@
 
 	};
 
-	if (!jQuery.fn.dataTable.BootstrapLength) {
+	if (!$.fn.dataTable.BootstrapLength) {
 		bl_factory($, $.fn.dataTable);
 	}
 
@@ -563,12 +588,17 @@
 
 		var BootstrapFilter = function(oSettings, oInit) {
 
-			if (!this.CLASS || this.CLASS != 'BootstrapFilter')
-				alert("Warning: BootstrapFilter must be initialized with the 'new' keyword");
-			if (typeof(oInit) == 'undefined')
+			if (!this.CLASS || this.CLASS !== 'BootstrapFilter') {
+				if (globals.alert) {
+					globals.alert("Warning: BootstrapFilter must be initialized with the 'new' keyword");
+				}
+			}
+			if (typeof(oInit) === 'undefined') {
 				oInit = {};
-			if ($.fn.dataTable.camelToHungarian)
+			}
+			if ($.fn.dataTable.camelToHungarian) {
 				$.fn.dataTable.camelToHungarian(BootstrapFilter.defaults, oInit);
+			}
 
 			this.s = {
 				dt: null,
@@ -582,8 +612,8 @@
 			};
 			BootstrapFilter.aInstances.push(this);
 
-			this.s.dt = $.fn.dataTable.Api
-				? new $.fn.dataTable.Api(oSettings).settings()[0]
+			this.s.dt = $.fn.dataTable.Api ?
+				new $.fn.dataTable.Api(oSettings).settings()[0]
 				: oSettings;
 
 			this._fnConstruct(oInit);
@@ -627,10 +657,11 @@
 							var n = dt.aanFeatures.F;
 							var val = $(this).val();
 							for (var i = 0, iLen = n.length; i < iLen; i++) {
-								if (n[i] != $(this).parents("div.dataTables_filter")[0])
+								if (n[i] !== $(this).parents("div.dataTables_filter")[0]) {
 									$(n[i]).data('DT_Input').val(val);
+								}
 							}
-							if (val != oPreviousSearch.sSearch) {
+							if (val !== oPreviousSearch.sSearch) {
 								dt.oInstance._fnFilterComplete({
 									sSearch: val,
 									bRegex: oPreviousSearch.bRegex,
@@ -640,7 +671,7 @@
 							}
 						})
 						.on('keypress.DT', function(e) {
-							if (e.keyCode == 13) {
+							if (e.keyCode === 13) {
 								return false;
 							}
 						});
@@ -656,8 +687,8 @@
 		BootstrapFilter.VERSION = '1.0.0';
 		BootstrapFilter.prototype.VERSION = BootstrapFilter.VERSION;
 
-		if ((typeof($.fn.dataTable) == 'function') &&
-			(typeof($.fn.dataTableExt.fnVersionCheck) == 'function') &&
+		if ((typeof($.fn.dataTable) === 'function') &&
+			(typeof($.fn.dataTableExt.fnVersionCheck) === 'function') &&
 			$.fn.dataTableExt.fnVersionCheck('1.7.0')) {
 			$.fn.dataTableExt.aoFeatures.push({
 				fnInit: function(oSettings) {
@@ -669,7 +700,9 @@
 				sFeature: "BootstrapFilter"
 			});
 		} else {
-			alert("Warning: BootstrapFilter required DataTables 1.7 or greater...");
+			if (globals.alert) {
+				globals.alert("Warning: BootstrapFilter required DataTables 1.7 or greater...");
+			}
 		}
 
 		$.fn.dataTable.BootstrapFilter = BootstrapFilter;
@@ -677,8 +710,8 @@
 
 	};
 
-	if (!jQuery.fn.dataTable.BootstrapFilter) {
+	if (!$.fn.dataTable.BootstrapFilter) {
 		bf_factory($, $.fn.dataTable);
 	}
 
-})(jQuery);
+})(jQuery, this);