PageSourceSearch

https://www.hkpasea.org/js/jquery/GM-form-validation/GM-form-validation.js

js hkpasea.org collected 2026-09-25 07:00:13 UTC 23,721 bytes, 608 lines download raw bytes

1/*
2***** ***** ***** ***** ***** !!!!! DO NOT COPY !!!!! ***** ***** ***** ***** *****
3* Designed and Developed by Globalshowroom Corporation Limited, "Globalshowroom".
4* For more information please visit our official website, http://globalshowroom.com.
5* Copyright © Globalshowroom Corporation Limited. All rights reserved.
6***** ***** ***** ***** ***** !!!!! DO NOT COPY !!!!! ***** ***** ***** ***** *****
7*/
8$(function() {
9    if($('[gm-require]').length > 0){
10          
11        
12        $.each( $('input[type="text"][gm-require],textarea[gm-require]'), function() {
13            
14            GM_form_VLD_SET_PRE_VAL(this);
15        });
16        
17        $('[gm-require]:not(:checkbox), [gm-require]:not(:radio)').on('blur', function(e) {
18            if(!$(e.target).is('[Readonly]')){
19                GM_form_VLD(e);
20            }
21        });
22        
23        $('[gm-require]:checkbox, [gm-require]:radio').on('click', function(e) {
24            GM_form_VLD(e);
25        });
26        
27        $('[gm-require][Readonly]').on('click', function(e) {
28            GM_form_VLD(e);
29        });
30
31        $('form[gm-validate="true"] button[type="button"]').click(function(e){ 
32            GM_form_VLD(e);
33        });
34        
35        $('input[name="Client-Domain"]').on('click, keydown, focus', function(e){ 
36            $('button[gm-submit="true"]').focus();
37        });
38        
39        $('[gm-compare-B]').addClass('ui-state-disabled');            
40        
41        $('form[gm-validate="true"]').submit(function(e) {
42            e.preventDefault();
43        });
44    }
45    
46    $( 'INPUT' ).keypress(function(e) { 
47          
48          if (e.keyCode == 13) { 
49              if($(this).hasClass('keyword')){
50                  if($('form[name="searchform"]').length>0){
51                      if($('#keyword-sm').val()!=''){
52                          $('#keyword').val($('#keyword-sm').val());
53                          document.searchform.submit();
54                      }else if($('#keyword-xs').val()!=''){
55                          $('#keyword').val($('#keyword-xs').val());
56                          document.searchform.submit();
57                      }
58                  }
59              }else{
60                  return false;
61              }
62              
63          }
64    });  
65    
66});
67function GM_form_VLD_SET_PRE_VAL(o){
68  $(o).attr('gm-pre-val',$(o).val());
69}
70function GM_form_VLD_EMAIL(check_email) {
71    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
72    return re.test(check_email);
73}
74function GM_form_VLD_DATE(check_date) { 
75    if (new Date(check_date)!=='Invalid Date'&&!isNaN(new Date(check_date))){
76          return true;
77    }else{
78          return false;
79    }
80}
81function GM_form_VLD_TIME(check_time) { 
82    return /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(check_time);
83}
84function GM_form_VLD_COMPARE(B_o,$v){ 
85    var B_name=$(B_o).attr('name');
86    var B_val=$v;
87    var A_name=$(B_o).attr('gm-compare-B');
88    var A_val=$('[name="'+A_name+'"]').val();
89
90    
91    
92
93    if(A_val!=''&&B_val!=A_val){
94        return false;
95    }else{ 
96        return true;
97    }
98}
99function GM_form_VLD_SUBMIT($form_o){
100
101    GM_form_isRunning(true);
102
103    var GM_formType=''; 
104    var ajax_url=''; 
105    if($form_o.is('[gm-form-type="gm-dynamic-form"]')){
106        GM_formType='GM-apt-form';
107        ajax_url='/js/jquery/GM-form-validation/GM_DynamicForm.asp?ajax=1';
108    }else if($form_o.is('[gm-form-type="gm-RFQ-form"]')){
109        GM_formType='GM-RFQ-form';
110        ajax_url='/js/jquery/GM-form-validation/GM_DynamicForm.asp?ajax=1';
111    }else if($form_o.is('[gm-form-type="gm-CONTACT-form"]')){
112        GM_formType='gm-CONTACT-form';
113        ajax_url='/js/jquery/GM-form-validation/GM_DynamicForm.asp?ajax=1';   
114    }
115
116    
117            
118    var submit_data = para_data = formEles = '';
119
120    $.each( $( 'input, select, textarea' , $form_o ), function( form_i, form_o ) {
121        
122            if( $(this).is('[type="radio"]') && !$(this).is(':checked') ){
123                return true; 
124            }
125        
126            var reqForm_NAME = $(this).attr('name');
127
128            var LABEL=reqForm_NAME;
129
130            if($('label.control-label[for="'+reqForm_NAME+'"]' , $form_o ).length > 0){ 
131                LABEL = $('label.control-label[for="'+reqForm_NAME+'"]' , $form_o ).text();
132            }else if($(this).attr('placeholder') != undefined){
133                LABEL = $(this).attr('placeholder');
134            }
135
136            var VAL=$(this).val();
137
138            if($(this).prop('tagName').toLowerCase()=='textarea'){
139                
140                VAL=VAL.replace(/\n/g, '<br>');
141            }
142            
143            var reqForm_VAL=GM_form_VLD_jsonClean(''+LABEL+'*,*'+VAL+'');
144            
145            if(reqForm_NAME=='PSAC'&&!$('[name="PSAC"]').is(':checked')){
146                reqForm_VAL='off';
147            }
148
149            
150            
151            
152            
153            
154            
155            
156            
157
158            if(submit_data != '') submit_data += ',';
159            submit_data+='"'+reqForm_NAME+'" : "' +reqForm_VAL+ '"';
160
161            if(formEles != '') formEles += ',';
162            formEles += reqForm_NAME;
163            
164            
165    });
166
167    if($('[name="Client-Domain"]').val()!=''||submit_data==''){
168        GM_form_VLD_ERROR($form_o);
169        return false;
170    }
171
172    
173    if(GM_formType=='GM-RFQ-form'){
174        submit_data+=', "GM-service" : "RFQ"';
175    }else if(GM_formType=='gm-CONTACT-form'){
176        submit_data+=', "GM-service" : "CONTACT"';
177    }
178
179    formEles += ',GM-service';
180
181    
182    if(submit_data!=''){
183
184        if( $( '[name="Client-Logo"]', $form_o ).length > 0 ){
185            submit_data+=', "Client-Logo" : "' +GM_form_VLD_jsonClean( $( '[name="Client-Logo"]', $form_o ).val() )+ '"';
186            formEles += ',Client-Logo';
187        }
188
189        var gm_form_subject = GM_form_VLD_jsonClean($form_o.attr('gm-form-subject'));
190       
191        
192
193        submit_data+=', "form-Subject" : "' + gm_form_subject + '"';
194        submit_data+=', "form-msg-success" : "' +GM_form_VLD_jsonClean($( '.msg-success div' , $form_o ).html())+ '"'; 
195
196        formEles += ',form-Subject';
197        formEles += ',form-msg-success';
198    }
199
200    
201
202    var request = $.ajax({
203    url: '/js/jquery/GM-form-validation/GM_obtain_VLD_ID.asp',
204    method: "POST",
205    data: { "a" : "1" }
206    
207    });
208    request.done(function( r_MSG ) {
209                
210                var is_VLD=false; E_VLD_ID=null; 
211                if(r_MSG!=''){
212                    arr_MSG=r_MSG.split('*,*'); 
213                    var r_DN=arr_MSG[0];
214                    var r_E_VLD_ID=arr_MSG[1]; 
215                    if(r_DN.toLowerCase()!=document.domain){
216                        GM_form_VLD_ERROR($form_o);
217                        return false;
218                    }else if(r_E_VLD_ID!=''){
219                        is_VLD=true; E_VLD_ID = r_E_VLD_ID; 
220                    }
221                }
222                
223                if(is_VLD){
224                        
225                        
226                            
227                            
228                        
229                        
230                        
231                        
232                        submit_data+=', "VLD-ID" : "' +E_VLD_ID+ '"';
233                   
234                        submit_data='{"formEles" : "' + formEles + '", ' + submit_data + '}';
235                        
236                        
237                        
238                        
239                        
240                        $.ajax({
241                            method: "POST",
242                            url: ajax_url+para_data,
243                            data: $.parseJSON( submit_data )
244                        }).done(function( s_MSG ){
245                            
246                            
247                            if(s_MSG.substring(0,5)=='Error'){
248                                alert( s_MSG );
249                                GM_form_VLD_ERROR($form_o);
250                            }else{
251                                
252                                GM_form_VLD_COMPLETED($form_o);
253                            }
254                        });
255                }else{
256                        GM_form_VLD_ERROR($form_o);
257                } 
258                
259    });
260    request.fail(function( jqXHR, textStatus ){
261        GM_form_VLD_ERROR($form_o);
262    });
263}
264
265function GM_form_VLD_jsonClean(in_val){
266  
267    in_val=in_val.replace(/\n|\r/g, ''); 
268    in_val=in_val.replace(/\t/g, ' '); 
269    in_val=in_val.replace(/\s\s+/g, ' '); 
270
271    in_val=in_val.replace(/\\/g, '&#92;');
272
273    Enc_val=GM_convert_to_json_ENCODE(in_val);
274
275    return Enc_val.trim();
276}
277
278function GM_form_VLD_ERROR($form_o){
279
280    GM_form_isRunning(false);
281
282    $('.msg-error').show();
283    $([document.documentElement, document.body]).animate({
284        scrollTop: $('.msg-error').offset().top - 150
285    }, 500);
286
287    $('[jq-tooltips-id="GM-aptForm-msg-error"]',$form_o).GM_JQ_tooltips_CTRL('toggle');
288    $('[jq-tooltips-id="GM-aptForm-msg-error"]',$form_o).tooltip("open");
289}
290function GM_form_VLD_COMPLETED($form_o){
291
292    GM_form_isRunning(false);
293
294    $form_o.find('input, textarea, button, select').attr('disabled','disabled'); 
295
296    $('.msg-success').show();
297    $([document.documentElement, document.body]).animate({
298        scrollTop: $('.msg-success').offset().top - 150
299    }, 500);
300
301    $('[jq-tooltips-id="GM-aptForm-msg-success"]',$form_o).GM_JQ_tooltips_CTRL('toggle');
302    $('[jq-tooltips-id="GM-aptForm-msg-success"]',$form_o).tooltip("open");
303}
304
305function GM_form_VLD(e){
306
307    var $form_o=null;
308    var form_o=GM_form_VLD_obtain_form_obj(e.target);
309
310    if(form_o==null){
311        console.log('Error: parent form object is null!');
312        return false;
313    }
314
315    $form_o=$(form_o);
316
317    
318    
319    
320
321    $('.msg-error').hide(); 
322
323    
324
325    var $VLD_elements=null; $VLD_target=null;
326    if($(e.target).prop('tagName').toLowerCase()=='button'&&!$(e.target).hasClass('ui-state-disabled')){ 
327        $VLD_target='form';
328        $VLD_elements=$('[gm-require]',$form_o); 
329        
330    }else{
331        $VLD_target='single-field';
332        $VLD_elements=$(e.target,$form_o); 
333        
334        
335    }
336
337    $.each( $VLD_elements, function( VLD_i, VLD_o ) {
338        
339        
340        
341        var is_BOF=VLD_i==$VLD_elements.length-1;
342        var $r=$(this).attr("gm-require");
343        var $v=$(this).val();
344        if($v==null){
345            $v='';
346        }else if(Array.isArray($v)){
347            $v=$v.toString(); 
348        }
349        
350        $v=$v.trim();
351        
352        
353                
354                var VLD_status=false; ui_tt_action=null;
355                
356                if($r=='num'){
357                        
358                            var min=0; max=100000000; num_type='int'; 
359                            if($(this).attr("gm-min")!=undefined){min=parseInt($(this).attr("gm-min"));}
360                            if($(this).attr("gm-max")!=undefined){max=parseInt($(this).attr("gm-max"));}
361                            if($(this).attr("gm-num-type")!=undefined){num_type=$(this).attr("gm-num-type");}
362                            
363                            var is_num=false;
364                            
365                            if(!gm_isNaN($v)){
366                                if(num_type=='dec2'){
367                                    $v=parseFloat($v).toFixed(2);
368                                }else if(num_type=='dec3'){
369                                    $v=parseFloat($v).toFixed(3);
370                                }else{ 
371                                    $v=parseInt($v);
372                                }
373                                if($v>=min&&$v<=max){
374                                    is_num=true;
375                                }
376                            }
377                            
378                            if($(this).is('[type="radio"]')){
379                                    if(is_num&&$(this).is(':checked')){
380                                        VLD_status=true; 
381                                    }else if($(this).hasClass('pass')&&$VLD_target=='form'){ 
382                                        
383                                        
384                                        VLD_status=true;
385                                    }
386                            }else if(is_num){
387                                    VLD_status=true;
388                            }
389                            
390                            
391                        
392                }else{
393                            
394                            var length_min=null; length_max=null;
395                            
396                            
397                            if($(this).attr("gm-length-min")!=undefined){length_min=parseInt($(this).attr("gm-length-min"));}
398                            if($(this).attr("gm-length-max")!=undefined){length_max=parseInt($(this).attr("gm-length-max"));}
399                            
400                            var is_continue=true; is_mandatory=true;
401                            if(length_min===0){
402                                is_mandatory=false;
403                            }
404                            
405                            if(length_min!=null&&$v.length<length_min){ 
406                                
407                                is_continue=false;
408                            }else if($v==''&&!is_mandatory){ 
409                                
410                                ui_tt_action='force-show';
411                            }else if($v==''){ 
412                                
413                                is_continue=false;
414                            }    
415                            
416                            if(is_continue&&length_max!=null&&$v.length>length_max){ 
417                                
418                                is_continue=false;
419                            }  
420                            
421                            if(!is_continue){
422                                VLD_status=false;
423                            }else if($r=='text'){
424                                if($(this).is('[gm-compare-B]')){
425                                    VLD_status=GM_form_VLD_COMPARE(this,$v);
426                                }else if($(this).is('[type="radio"]')){
427                                    if($v!=''&&$(this).is(':checked')){
428                                        VLD_status=true; 
429                                    }else if($(this).hasClass('pass')&&$VLD_target=='form'){ 
430                                        
431                                        
432                                        VLD_status=true;
433                                    }
434                                }else{
435                                    VLD_status=true;
436                                }
437                            }else if($r=='email'){
438                                VLD_status=GM_form_VLD_EMAIL($v);
439                            }else if($r=='date'){ 
440                                VLD_status=GM_form_VLD_DATE($v);
441                            }else if($r=='time'){ 
442                                VLD_status=GM_form_VLD_TIME($v);
443                            }else if($(this).is('[type="checkbox"]')){
444                                if($r.toLowerCase()=='check'&&$(this).is(':checked')){
445                                    VLD_status=true; 
446                                }else if($r.toLowerCase()=='uncheck'&&!$(this).is(':checked')){
447                                    VLD_status=true; 
448                                }
449                            }else if($(this).is('[type="radio"]')){ 
450                                if($r.toLowerCase()==$v.toLowerCase()&&$(this).is(':checked')){ 
451                                    
452                                    VLD_status=true; 
453                                }else if($(this).hasClass('pass')&&$VLD_target=='form'){ 
454                                    
455                                    
456                                    VLD_status=true;
457                                }
458                            }else if($r.toLowerCase()==$v.toLowerCase()){ 
459                                VLD_status=true; 
460                            }
461                                    
462                }
463                        
464                if(VLD_status){ 
465                    
466                            
467                            
468                            if(ui_tt_action!='force-show'){
469                                ui_tt_action='hide';
470                            }
471                            
472                            if($(this).is('[gm-pre-val]')){
473                                $(this).val($v).attr('gm-pre-val',$v); 
474                            }
475                            
476                            $('[name="'+$(this).attr('name')+'"]').removeClass('fail').addClass('pass');
477                            
478                            if($VLD_target=='single-field'){
479                            
480                                    if($(this).is('[gm-compare-A]')){ 
481                                        var A_name=$(this).attr('gm-compare-A');
482                                        var $B_o=$('[name="'+A_name+'"]');
483                                        $B_o.val('').removeClass('ui-state-disabled');
484                                    }
485                                    
486                                    
487                                    $('button[gm-submit="true"]',$form_o).removeClass('ui-state-disabled');
488                                    
489                                    
490                                    
491                                    
492                                    
493                            }
494                    
495                }else{ 
496                    
497                            
498                            
499                            ui_tt_action='show';
500                            
501                            if($(this).is('[gm-pre-val]')&&$r!='text'){
502                                $(this).val($(this).attr('gm-pre-val')); 
503                            }
504                            
505                            $('[name="'+$(this).attr('name')+'"]').removeClass('pass').addClass('fail');
506                            
507                            if($(this).is('[gm-compare-A]')){ 
508                                    var A_name=$(this).attr('gm-compare-A');
509                                    var $B_o=$('[name="'+A_name+'"]');
510                                    if(!$B_o.hasClass('ui-state-disabled')){
511                                        $B_o.val('').addClass('ui-state-disabled');
512                                    }
513                            }
514                            
515                            if($VLD_target=='single-field'){ 
516                                if( !$('button[gm-submit="true"]',$form_o).hasClass('ui-state-disabled') ){
517                                        $('button[gm-submit="true"]',$form_o).addClass('ui-state-disabled');
518                                }
519                            }
520                }  
521                
522                var $ui_tt_target=$(this);
523                
524                if($VLD_target=='form'){
525
526                            ui_tt_action='hide'; 
527                            if(is_BOF){
528                                if( $('[gm-require].fail',$form_o).length>0 ){ 
529                                    ui_tt_action='show';
530                                    
531                                    $ui_tt_target=$('button[gm-submit="true"]',$form_o); 
532                                    
533                                    $('button[gm-submit="true"]',$form_o).addClass('ui-state-disabled');
534                                
535                                }else{ 
536                                    
537                                    
538                                    
539                                    
540                                    if($('[gm-require].pass',$form_o).length==$('[gm-require]',$form_o).length){
541                                        GM_form_VLD_SUBMIT($form_o);
542                                    }else{
543                                        console.log('Submit abort! no .fail count, but not eq .pass : pass.length='+($('[gm-require].pass',$form_o).length)+'/'+($('[gm-require]',$form_o).length)+'');
544                                    }
545                                }
546                            }        
547                }
548                
549                if(ui_tt_action=='hide'){
550                            
551                            
552                            if($(this).is('[jq-tooltips-trigger-target]')){ 
553                                $ui_tt_target=$('[jq-tooltips-id="'+$(this).attr('jq-tooltips-trigger-target')+'"]');
554                            }
555                            if($ui_tt_target.data("tooltip")){ 
556                                $ui_tt_target.GM_JQ_tooltips_REMOVE();
557                            }
558                }else{ 
559                            
560                            
561                            if($(this).is('[jq-tooltips-trigger-target]')){ 
562                                $ui_tt_target=$('[jq-tooltips-id="'+$(this).attr('jq-tooltips-trigger-target')+'"]');
563                            }
564                            if($ui_tt_target.is('[jq-tooltips-trigger="toggle"]')){
565                                    
566                                    $ui_tt_target.GM_JQ_tooltips_CTRL('toggle');
567                                    $ui_tt_target.tooltip("open");
568                                    
569                                    
570                                    if($ui_tt_target.is('button[gm-submit="true"]')){
571                                        $(document).on('click', function( e ){
572                                            
573                                            if(!$(e.target).is('button[gm-submit="true"]')&&$('[for-id="GM-aptForm-submit"].ui-tooltip').length>0){
574                                                
575                                                $('button[gm-submit="true"]').GM_JQ_tooltips_REMOVE();
576                                            }
577                                        });
578                                    }
579                            }
580                            
581                }  
582    });
583}
584
585function GM_form_VLD_obtain_form_obj(o){
586    var is_Form=false;
587    if($(o).parent().prop('tagName').toLowerCase()=='form'){
588        is_Form=true;
589    }
590
591    if(is_Form){
592        
593        return o.parentNode; 
594    }else if($(o).parent().prop('tagName').toLowerCase()=='body'){ 
595        return null;
596    }else{ 
597        return GM_form_VLD_obtain_form_obj(o.parentNode);
598    }
599}
600
601function GM_form_isRunning(r){
602    if( r ){
603        if($('.spinIcon').length == 0)
604            $('<div class="spinIcon"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>').insertBefore( 'button[gm-submit="true"]' );
605    }else{
606        $('.spinIcon').remove();
607    }
608}

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.