1/* 2* EKHjs v1.0.2 3* 2019-09-12 4* 5* EKHjs.fadeInObjects('#element'); 6* EKHjs.parallaxObj('#element', 2); 7* EKHjs.validateForm('.skjema.validate', 0); 8* EKHjs.submitFormAjax($('.skjema.validate form')); 9* $('$menu a').EKHScrollToAnchor(140); 10* 11*/ 12 13EKHjs = window.EKHjs || {}; 14 15EKHjs = function () { 16 17 var curPos = 0; 18 var debug = 0; 19 var form_ajax = 1; 20 21 c_log = function c_log(msg) { 22 "use strict"; 23 if(debug == 1) 24 console.log(msg); 25 }; 26 27 $.fn.EKHScrollToAnchor = function(offset) { 28 "use strict"; 29 if(!offset) { 30 offset = 0; 31 } 32 $(this).click(function(e) { 33 e.preventDefault(); 34 var anchor = $(this).attr('href'); 35 if(anchor != '' && anchor != '#') { 36 if(anchor === '#firstrow') { 37 var $target = $('.row').first(); 38 } else { 39 var $target = $(anchor); 40 } 41 if(typeof $target.offset() == 'object') { 42 var anchorPos = parseInt($target.offset().top); 43 c_log(anchor + " : " + anchorPos); 44 $('html, body').stop().animate({ 45 'scrollTop': (anchorPos - offset) 46 }, 900, 'swing', function() { 47 }); 48 } 49 } 50 }); 51 }; 52 53 scrollToAnchor = function scrollToAnchor(target) { 54 "use strict"; 55 if(target === '#firstrow') { 56 target = $('.row').first(); 57 } 58 $('html, body').stop().animate({ 59 'scrollTop': $(target).offset().top 60 }, 900, 'swing', function() { 61 //window.location.hash = target; 62 }); 63 }; 64 65 parallaxObj = function parallaxObj(o, speed) { 66 "use strict"; 67 c_log('parallaxObj: ' + o); 68 $(o).css('transform', 'translate3d(0, ' + ~~(curPos / speed) + 'px, 0)'); 69 }; 70 71 fadeInObjects = function fadeInObjects(obj) { 72 "use strict"; 73 if(typeof obj === 'undefined') { 74 obj = '.fade'; 75 } 76 var t = curPos, 77 e = $(window).height(); 78 $(obj).not(".in").each(function() { 79 var $fadeinelem = $(this); 80 var n = $fadeinelem.offset().top - e, 81 i = (e / 8); 82 if (t - i > n) { 83 if ($fadeinelem.data('fadedelay')) { 84 setTimeout(function() { 85 $fadeinelem.addClass("in"); 86 $fadeinelem.removeClass("NOTin"); 87 }, parseInt($fadeinelem.data('fadedelay')) * 100); 88 } else { 89 $fadeinelem.addClass("in"); 90 $fadeinelem.removeClass("NOTin"); 91 } 92 } else if (t < n) { 93 $fadeinelem.addClass("NOTin"); 94 /* $(this).removeClass("in"); */ 95 } 96 }); 97 }; 98 99 form_validateEmail = function form_validateEmail($email) { 100 "use strict"; 101 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/; 102 return emailReg.test($email); 103 }; 104 105 form_validateField = function form_validateField($obj) { 106 "use strict"; 107 var valid = 1; 108 $obj.parent().addClass('fb_invalid'); 109 if (($obj.val() === '') || (($obj.attr('type') == 'email') && (!form_validateEmail($obj.val())))) { 110 valid = 0; 111 } else { 112 $obj.parent().removeClass('fb_invalid'); 113 } 114 return valid; 115 }; 116 117 form_submitAjax = function form_submitAjax($formObj) { 118 "use strict"; 119 var post_url = $formObj.attr("action"); //get form action url 120 var request_method = $formObj.attr("method"); //get form GET/POST method 121 var form_data = $formObj.serialize(); //Encode form elements for submission 122 123 c_log("Form: valid: posting ajax"); 124 c_log(post_url); 125 c_log(request_method); 126 c_log(form_data); 127 128 $.ajax({ 129 url : post_url, 130 type: request_method, 131 data : form_data 132 }).done(function(response){ 133 $formObj.parent().addClass("submitted"); 134 }); 135 136 }; 137 138 form_validate = function form_validate($formObj) { 139 "use strict"; 140 c_log("Form: validating"); 141 var valid = 1; 142 $formObj.find(".required").each(function() { 143 if (form_validateField($(this).children('input, textarea, select').first()) === 0) { 144 valid = 0; 145 } 146 $(this).children('input, textarea, select').unbind().blur(function() { 147 form_validateField($(this)); 148 }); 149 }); 150 if (valid === 1) { 151 c_log("Form: VALID"); 152 if(form_ajax === 1) { 153 form_submitAjax($formObj); 154 } else { 155 $formObj.submit(); 156 } 157 } else { 158 c_log("Form: NOT VALID"); 159 } 160 }; 161 162 form_add_validate_event = function form_add_validate_event(obj, ajax) { 163 "use strict"; 164 if(ajax === 0) { 165 c_log("Form: Do not submit ajax"); 166 form_ajax = 0; 167 } 168 c_log("Form: add form_validate_event: " + obj); 169 $(obj).find(".required").find('input, textarea, select').unbind().blur(function() { 170 form_validateField($(this)); 171 }); 172 $(obj).find('button[type=submit]').on('click', function(e) { 173 e.preventDefault(); 174 form_validate( $(this).closest('form') ); 175 176 if ($(".error").length) { 177 $('html, body').animate({scrollTop: $(".error").offset().top - $('#header').height()}, 100); //Scroll to error message 178 } else if ($(".fb_invalid").length) { 179 $('html, body').animate({scrollTop: $(".fb_invalid").offset().top - $('#header').height()}, 100); //Scroll to first invalid field 180 } 181 182 /* Gammel versjon 183 if ($(".fb_invalid").length) { 184 $('html, body').animate({scrollTop: $(".fb_invalid").offset().top - $('#header').height()}, 100); //Scroll to first invalid field 185 } 186 */ 187 188 return false;
189 }); 190 } 191 192 $(window).scroll(function() { 193 "use strict"; 194 curPos = $(window).scrollTop(); 195 196 if(curPos > 0) { 197 if( !$('#site').hasClass('scrolled') ) { 198 $('#site').addClass('scrolled'); 199 } 200 } else { 201 if( $('#site').hasClass('scrolled') ) { 202 $('#site').removeClass('scrolled'); 203 } 204 } 205 206 }); 207 208 return { 209 "parallaxObj" : parallaxObj, 210 "fadeInObjects" : fadeInObjects, 211 "validateForm" : form_add_validate_event, 212 "submitFormAjax" : form_submitAjax, 213 "scrollToAnchor" : scrollToAnchor 214 } 215 216}();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.