From 768b3f3affbb059b6423e96d306590fc54f16cfd Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Fri, 17 Jun 2016 12:05:19 -0400
Subject: [PATCH] - interrupt scrolling on user input, fixed #3936

---
 interface/web/themes/default/assets/javascripts/ispconfig.js |   73 +++++++++++++++++++++++++++++++++---
 1 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/interface/web/themes/default/assets/javascripts/ispconfig.js b/interface/web/themes/default/assets/javascripts/ispconfig.js
index b369b53..a2b9907 100644
--- a/interface/web/themes/default/assets/javascripts/ispconfig.js
+++ b/interface/web/themes/default/assets/javascripts/ispconfig.js
@@ -364,9 +364,11 @@
 	},
 
 	loadInitContent: function() {
+		var startpage = $('#pageContent').attr('data-startpage');
+		if(!startpage) startpage = 'dashboard/dashboard.php';
 		var pageContentObject = $.ajax({
 			type: "GET",
-			url: "dashboard/dashboard.php",
+			url: startpage,
 			data: "",
 			dataType: "html",
 			beforeSend: function() {
@@ -616,9 +618,12 @@
 	}
 });
 
+var $page = $('html, body');
+
 $(document).on('click', 'a[data-load-content],button[data-load-content]', function(e) {
 	e.preventDefault();
-	$('html, body').animate({scrollTop: 0}, 1000);
+	$page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
+	$page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
 	
 	var content_to_load = $(this).attr('data-load-content');
 	if(!content_to_load) return this;
@@ -628,7 +633,8 @@
 
 $(document).on('click', 'a[data-capp],button[data-capp]', function(e) {
 	e.preventDefault();
-	$('html, body').animate({scrollTop: 0}, 1000);
+	$page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
+	$page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
 	
 	var content_to_load = $(this).attr('data-capp');
 	if(!content_to_load) return this;
@@ -638,7 +644,8 @@
 
 $(document).on('click', 'a[data-submit-form],button[data-submit-form]', function(e) {
 	e.preventDefault();
-	$('html, body').animate({scrollTop: 0}, 1000);
+	$page.on('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); });
+	$page.animate({scrollTop: 0}, 1000, function() { $page.off('scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function() { $page.stop(); }); });
 	
 	var $el = $(this);
 	var act = $el.attr('data-form-action');
@@ -655,9 +662,9 @@
 		$("#pageForm .table #Filter").trigger('click');
 	}
 	//Use $ submit with keypress Enter in forms
-	if (event.which == '13' && $(".pnl_formsarea button.positive").length > 0 && event.target.localName != 'textarea' && $(event.target).is(':input')) {
+	if (event.which == '13' && $(".tab-content button.formbutton-success").length > 0 && event.target.localName != 'textarea' && $(event.target).is(':input')) {
 		event.preventDefault();
-		$(".pnl_formsarea button.positive:first").not("[disabled='disabled']").trigger('click');
+		$(".tab-content button.formbutton-success").not("[disabled='disabled']").trigger('click');
 	}
 });
 
@@ -701,6 +708,29 @@
 	var template2 = $(this).siblings(':input');
 	template2.insertAtCaret(placeholderContentText);
 });
+
+$(document).on("click", "[data-check-fields] > input[type='checkbox']", function() {
+	if($(this).is(':checked')) {
+		var flds = $(this).parent().attr('data-check-fields');
+		var tmp = flds.split(/,/);
+		for(var i = 0; i < tmp.length; i++) {
+			var fname = tmp[i];
+			$('input[type="checkbox"][name="' + fname + '"]').prop('checked', true);
+		}
+	}
+});
+
+$(document).on("click", "[data-uncheck-fields] > input[type='checkbox']", function() {
+	if($(this).is(':checked') == false) {
+		var flds = $(this).parent().attr('data-uncheck-fields');
+		var tmp = flds.split(/,/);
+		for(var i = 0; i < tmp.length; i++) {
+			var fname = tmp[i];
+			$('input[type="checkbox"][name="' + fname + '"]').prop('checked', false);
+		}
+	}
+});
+
 
 $(document).on('ready', function () {
 	$.fn.extend({
@@ -747,4 +777,35 @@
 			e.preventDefault();
 		}
 	});
+	
+	$.fn.setCursorPosition = function(pos) {
+		var self = $(this).get(0);
+		if(self.setSelectionRange) {
+			self.setSelectionRange(pos, pos);
+		} else if(self.createTextRange) {
+			var range = self.createTextRange();
+			range.collapse(true);
+			if(pos < 0) {
+				pos = $(this).val().length + pos;
+			}
+			range.moveEnd('character', pos);
+			range.moveStart('character', pos);
+			range.select();
+		}
+	};
+	
+	$.fn.getCursorPosition = function() {
+		var iCaretPos = 0;
+		var self = $(this).get(0);
+		
+		if(typeof self.selectionStart === 'number') {
+			iCaretPos = self.selectionDirection == 'backward' ? self.selectionStart : self.selectionEnd;
+		} else if(document.selection) {
+			this.focus();
+			var oSel = document.selection.createRange();
+			oSel.moveStart('character', -self.value.length);
+			iCaretPos = oSel.text.length;
+		}
+		return iCaretPos;
+	};
 });

--
Gitblit v1.9.1