Browse Source

Move JS funcs to helper

Volodymyr Tkach 2 years ago
parent
commit
4cc2368098
1 changed files with 32 additions and 6 deletions
  1. 32 6
      js/helper.js

+ 32 - 6
js/helper.js

@@ -1,10 +1,8 @@
 var helper = {};
-helper.hasClass = function(obj, className) {
-	return !!obj.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
-};
-
-helper.addClass = function(obj, className) {
-	if(!helper.hasClass(obj, className)) obj.className += " " + className;
+helper.toHtmlObject = function(htmlCode) {
+	var div = document.createElement('div');
+	div.innerHTML = htmlCode;
+	return div.firstChild;
 };
 
 helper.removeClass = function(obj, className) {
@@ -13,3 +11,31 @@ helper.removeClass = function(obj, className) {
 		obj.className = obj.className.replace(reg, ' ').trim();
 	};
 };
+
+helper.hasScrollBar = function(tag) {
+	return (Math.max(tag.scrollHeight, tag.offsetHeight) > window.innerHeight);
+};
+
+helper.hasClass = function(obj, className) {
+	return !!obj.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
+};
+
+helper.getScrollWidth = function() {
+	var outer = document.createElement('div');
+	outer.style.visibility = 'hidden';
+	outer.style.width = '100px';
+	outer.style.msOverflowStyle = 'scrollbar';
+	document.body.appendChild(outer);
+	var widthNoScroll = outer.offsetWidth;
+	outer.style.overflow = 'scroll';
+	var inner = document.createElement('div');
+	inner.style.width = '100%';
+	outer.appendChild(inner);
+	var widthWithScroll = inner.offsetWidth;
+	outer.parentNode.removeChild(outer);
+	return widthNoScroll - widthWithScroll;
+};
+
+helper.addClass = function(obj, className) {
+	if(!helper.hasClass(obj, className)) obj.className += " " + className;
+};