PageSourceSearch

https://functionalself.co.uk/wp-content/plugins/custom-registratio…/js/conditionize.jquery.js?ver=6.0.8.1

js functionalself.co.uk collected 2026-10-04 05:10:30 UTC 23,525 bytes, 602 lines download raw bytes

1(function($) {
2  $.fn.conditionize = function(options) {  
3    
4    var settings = $.extend({
5        hideJS: true
6    }, options );
7    
8    $.fn.rmAnd= function(obj){
9      for(var i = 0, len = obj.length - 1; i < len && obj[i]; i++);
10      return obj[i];
11    }
12
13    $.fn.rmOr= function(obj) {
14      for(var i = 0, len = obj.length - 1; i < len && !obj[i]; i++);
15      return obj[i];
16    };
17
18    // If array is empty, undefined is returned.  If not empty, the first element
19    // that evaluates to false is returned.  If no elements evaluate to false, the
20    // last element in the array is returned.
21    /*Array.prototype.rm_and = function() {
22      for(var i = 0, len = this.length - 1; i < len && this[i]; i++);
23      return this[i];
24    };*/
25
26    // If array is empty, undefined is returned.  If not empty, the first element
27    // that evaluates to true is returned.  If no elements evaluate to true, the
28    // last element in the array is returned.
29   /* Array.prototype.rm_or = function() {
30      for(var i = 0, len = this.length - 1; i < len && !this[i]; i++);
31      return this[i];
32    };*/
33    
34    $.fn.eval = function(valueIs, valueShould, operator,multiValue) {
35      multiValue= multiValue || false;
36      switch(operator) {
37        case '==':
38             if(multiValue){
39                if(isNaN(valueIs) && valueIs){
40                    valueIs= valueIs.split(",");
41                }
42            }
43            if(valueIs instanceof Array){
44                for(i=0;i<valueIs.length;i++){
45                    if(valueIs[i]==valueShould){
46                       return true;
47                    }
48                }
49                return false;
50            }
51            else
52              return valueIs == valueShould;
53        case '!=': //console.log(valueIs, operator,valueShould,multiValue);
54             if(multiValue){
55                if(isNaN(valueIs) && valueIs){
56                    valueIs= valueIs.split(",");
57                }
58            }
59            if(valueIs instanceof Array){
60                for(i=0;i<valueIs.length;i++){
61                    if(!(valueIs[i]!=valueShould)){
62                       return false;
63                    }
64                }
65                return true;
66            }
67            else
68            return valueIs != valueShould;
69        case '<=':
70            if(multiValue){
71                if(isNaN(valueIs) && valueIs){
72                    valueIs= valueIs.split(",");
73                }
74            }
75            if(valueIs instanceof Array){
76                for(i=0;i<valueIs.length;i++){
77                    if(!(valueIs[i]<=valueShould)){
78                       return false;
79                    }
80                }
81                return true;
82            }
83            else{
84                if(valueIs=="" && !isNaN(valueShould)){
85                    return false;
86                }
87                return valueIs <= valueShould;
88            }
89        case '<':
90            if(multiValue){
91                if(isNaN(valueIs) && valueIs){
92                    valueIs= valueIs.split(",");
93                }
94            }
95            if(valueIs instanceof Array){
96                for(i=0;i<valueIs.length;i++){
97                    if(!(valueIs[i]<valueShould)){
98                       return false;
99                    }
100                }
101                return true;
102            }
103            else{
104                if(valueIs=="" && !isNaN(valueShould)){
105                    return false;
106                }
107                return valueIs < valueShould;
108            }
109        case '>=':
110            if(multiValue){
111                if(isNaN(valueIs) && valueIs){
112                    valueIs= valueIs.split(",");
113                }
114            }
115            if(valueIs instanceof Array){
116                for(i=0;i<valueIs.length;i++){
117                    if(!(valueIs[i]>=valueShould)){
118                       return false;
119                    }
120                }
121                return true;
122            }
123            else{
124                if(valueIs=="" && !isNaN(valueShould)){
125                    return false;
126                }
127                return valueIs >= valueShould;
128            }
129            
130        case '>':
131            if(multiValue){
132                if(isNaN(valueIs) && valueIs){
133                    valueIs= valueIs.split(",");
134                }
135            }
136            if(valueIs instanceof Array){
137                for(i=0;i<valueIs.length;i++){
138                    if(!(valueIs[i]>valueShould)){
139                       return false;
140                    }
141                }
142                return true;
143            }
144            else{
145                if(valueIs=="" && !isNaN(valueShould)){
146                    return false;
147                }
148                return valueIs > valueShould;
149            }
150            
151        case 'in':{
152                if(multiValue){
153                    if(isNaN(valueIs) && valueIs){
154                        valueIs= valueIs.split(",");
155                    }                    
156                    if(isNaN(valueShould)){
157                        valueShould= valueShould.split(",");
158                    } 
159                }
160                
161                if(valueIs instanceof Array && valueShould instanceof Array){
162                    commonValues= valueIs.filter(function(n) {
163                        return valueShould.indexOf(n) != -1;
164                    });
165                    if(commonValues.length>0)
166                        return true;
167                    else
168                        return false;
169                } else if(valueIs instanceof Array){
170                    valueShould= valueShould.toString();
171                    return valueIs.indexOf(valueShould) != -1;
172                } else if(valueShould instanceof Array){
173                    valueIs= valueIs.toString();
174                    return valueShould.indexOf(valueIs) != -1;
175                }
176                else{
177                    return valueIs.indexOf(valueShould)!==-1; 
178                }
179                 
180        }
181        case 'start_char':{
182                if(multiValue){
183                    if(isNaN(valueIs) && valueIs){
184                        valueIs= valueIs.split(",");
185                    }
186                }
187                if(valueIs instanceof Array){
188                    for(i=0;i<valueIs.length;i++){
189                        if(!(valueIs[i].startsWith(valueShould))){
190                           return false;
191                        }
192                    }
193                    return true;
194                }
195                else{
196                    if(valueIs=="" && !isNaN(valueShould)){
197                        return false;
198                    }
199                    return valueIs.startsWith(valueShould);
200                }
201        }
202        case 'start_word':{
203                if(multiValue){
204                    if(isNaN(valueIs) && valueIs){
205                        valueIs= valueIs.split(",");
206                    }
207                }
208                if(valueIs instanceof Array){
209                    for(i=0;i<valueIs.length;i++){
210                        if(!(valueIs[i].match("^"+valueShould))){
211                           return false;
212                        }
213                    }
214                    return true;
215                }
216                else{
217                    if(valueIs=="" && !isNaN(valueShould)){
218                        return false;
219                    }
220                    return valueIs.match("^"+valueShould);
221                }
222        }
223        case 'end_char':{
224                if(multiValue){
225                    if(isNaN(valueIs) && valueIs){
226                        valueIs= valueIs.split(",");
227                    }
228                }
229                //console.log(valueIs.length+'VVVVVVVVVV');
230                if(valueIs instanceof Array){
231                    for(i=0;i<valueIs.length;i++){
232                        var stringData = valueIs[i].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
233                        
234                        if(!(stringData.match(valueShould+"$"))){
235                           return false;
236                        }
237                    }
238                    return true;
239                }
240                else{
241                    if(valueIs=="" && !isNaN(valueShould)){
242                        return false;
243                    }
244                    valueIs = valueIs.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
245                    return valueIs.match(valueShould+"$");
246                }
247                
248        }
249        case 'end_word':{
250                if(multiValue){
251                    if(isNaN(valueIs) && valueIs){
252                        valueIs= valueIs.split(",");
253                    }
254                }
255                if(valueIs instanceof Array){
256                    for(i=0;i<valueIs.length;i++){
257                        stringData = valueIs[i].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
258                        if(!(stringData.match(valueShould+"$"))){
259                           return false;
260                        }
261                    }
262                    return true;
263                }
264                else{
265                    if(valueIs=="" && !isNaN(valueShould)){
266                        return false;
267                    }
268                    valueIs = valueIs.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
269                    return valueIs.match(valueShould+"$");
270                }
271        }
272        case 'domain_match':{
273                if(multiValue){
274                    if(isNaN(valueIs) && valueIs){
275                        valueIs= valueIs.split(",");
276                    }
277                }
278                if(valueIs instanceof Array){
279                    for(i=0;i<valueIs.length;i++){
280                        var vakueIs  = valueIs.split('@');
281                        var vakueIs  = email[1];
282                        if(!(email == valueShould)){
283                           return false;
284                        }
285                    }
286                    return true;
287                }
288                else{
289                    if(valueIs=="" && !isNaN(valueShould)){
290                        return false;
291                    }
292                    var email  = valueIs.split('@');
293                    var email  = email[1];
294                    return email == valueShould;
295                }
296        }
297        case '_blank':
298            return valueIs=="";
299        case '_not_blank':
300            return valueIs!="";    
301      }
302      
303    }
304    
305    $.fn.isNumber= function(obj){return (/number/).test(typeof obj);}
306    
307    
308    $.fn.getValues= function(obj){
309        if($.fn.isNumber(obj))
310            return [obj];
311        else
312        {
313            return obj.split("|").map(function(x){ return x; });
314        }
315    }
316    
317    $.fn.showOrHide = function(listenTo, listenFor, operator,combinator,action, $section,subject,onLoad) {
318      var listenForValues=  $.fn.getValues(listenFor);
319      var operators= operator.split('|'),resultStatus=[],to,pass= false;
320      var to,type,valueIs,valueShould;
321      var skip= false;
322      var results= []; //console.log(listenForValues);
323      for(var i=0;i<listenForValues.length;i++){ 
324        to = "[name=" + listenTo[i] + "]";
325      
326        type= listenTo[i].split("_")[0];
327        valueIs= $(to).val();
328        valueShould= listenForValues[i];
329        /*console.log('listenTo: '+listenTo);
330        console.log('listenFor: '+listenFor);
331        console.log('operator: '+operator);
332        console.log('combinator: '+combinator);
333        console.log('$section: '+$section);
334        console.log('onLoad: '+onLoad);
335        console.log('subject: '+subject);*/
336        if(type=='jQueryUIDate' || type=='Bdate')
337        {  
338            if(operators[i]=='_blank' && valueIs==""){
339                    results.push(true);
340                    continue;
341            }
342              
343            if($(to).datepicker( "getDate" )!=null){ 
344                valueIs= $(to).datepicker( "getDate" ).getTime();
345                if(operators[i]=='_not_blank' && listenTo[i]=="_"){
346                    results.push(false);
347                    continue;
348                }
349                else{
350                    valueShould= listenForValues[i];
351                    var dateFormat= $(to).datepicker('option', 'dateFormat');
352                    if(valueShould!="_")
353                    valueShould= $.datepicker.parseDate(dateFormat,valueShould).getTime(); 
354                } 
355            }
356            else{
357                results.push(false);
358               continue;
359            } 
360        } else if(["<=",">=","<",">"].indexOf(operators[i])>=0)
361        {   
362            if(onLoad && ["<=","<"].indexOf(operators[i]>=0)) 
363                skip= true;
364            valueIs= parseFloat(valueIs);
365            valueShould= parseFloat(valueShould);
366        }else{
367            valueIs= $(to).val()!==undefined && $(to).val()!==null ? $(to).val().toString().toLowerCase() : $(to).val();
368            valueShould= $.fn.isNumber(listenForValues[i])? listenForValues[i]: listenForValues[i].toLowerCase();
369        }
370        
371        if($(to).is('input[type=text],input[type=url],input[type=number],input[type=password],input[type=email],textarea') && $.fn.eval(valueIs, valueShould, operators[i]) && !$(to).is(':radio')){
372            results.push(true);
373        }
374        else if($(to).is('select') && $.fn.eval(valueIs, valueShould, operators[i],true)){
375            results.push(true);
376        }
377        else if (($(to).is(':radio') || $(to).is(':checkbox')) && !$(to).is(':checked') && $.fn.eval('', valueShould, operators[i],true)){
378             results.push(true);
379        }
380        else if($(to + ":checked").filter(function(idx, elem)
381             { values= [];
382                $(to + ":checked").each(function(){
383                    values.push($(this).val());
384                }); 
385               return $.fn.eval(values.toString().toLowerCase(), valueShould, operators[i],true);
386             }).length > 0 )
387            results.push(true);
388        else 
389           results.push(false);
390      }  
391     var pass= combinator=='AND' ? $.fn.rmAnd(results) : $.fn.rmOr(results);
392         
393       
394     if (pass && !skip) {
395        if(action == 'hide'){
396            $section.addClass('ignore');
397             $section.closest(".rmagic-row").addClass('rm-hidden-row');
398            //$section.val('');
399            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
400                if($(this).attr('initial-state')){
401                    $(this).removeAttr('required');
402                }
403            });
404            $section.closest('.rmrow, .rmagic-field').slideUp();
405             if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
406                 $section.parents('.rmagic-row').css('margin-bottom',0);
407             }
408            //console.log($section.parent().parent().parent().siblings().children(':visible'));
409            $section.prop('disabled',true);
410            $.fn.updateConditionalFieldsIds(subject.attr('name'),0);
411        }
412        else if(action == 'disable'){
413            $section.removeClass('ignore');
414            //$section.closest('.rmrow, .rmagic-field').slideDown();
415            $section.closest(".rmagic-row").removeClass('rm-hidden-row');
416            if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
417                var bmargin = $section.parents('.rmagic-row').data('bmargin');
418                if(bmargin > 0)
419                    $section.parents('.rmagic-row').css('margin-bottom',bmargin);
420                else
421                    $section.parents('.rmagic-row').css('margin-bottom',14);
422            }
423            $section.prop('disabled',true);
424            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
425                if($(this).attr('initial-state')){
426                    $(this).removeAttr('required');
427                }
428            });
429            $.fn.updateConditionalFieldsIds(subject.attr('name'),1);
430            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
431                if($(this).prop('initial-state')){
432                    $(this).removeAttr('required');
433                }
434            });
435        }else {
436            $section.removeClass('ignore');
437            $section.closest(".rmagic-row").removeClass('rm-hidden-row');
438            $section.closest('.rmrow, .rmagic-field').slideDown();
439            if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
440                var bmargin = $section.parents('.rmagic-row').data('bmargin');
441                if(bmargin > 0)
442                    $section.parents('.rmagic-row').css('margin-bottom',bmargin);
443                else
444                    $section.parents('.rmagic-row').css('margin-bottom',14);
445            }
446            $section.prop('disabled',false);
447            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
448                if($(this).attr('initial-state')){
449                    $(this).attr('required','required');
450                }
451            });
452            $.fn.updateConditionalFieldsIds(subject.attr('name'),1);
453            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
454                if($(this).prop('initial-state')){
455                    $(this).attr('required');
456                }
457            });
458        }
459     }
460     else {
461        
462        if(action == 'hide'){
463            $section.removeClass('ignore');
464            $section.closest(".rmagic-row").removeClass('rm-hidden-row');
465            $section.closest('.rmrow, .rmagic-field').slideDown();
466            if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
467                var bmargin = $section.parents('.rmagic-row').data('bmargin');
468                if(bmargin > 0)
469                    $section.parents('.rmagic-row').css('margin-bottom',bmargin);
470                else
471                    $section.parents('.rmagic-row').css('margin-bottom',14);
472            }
473            $section.prop('disabled',false);
474            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
475                if($(this).attr('initial-state')){
476                    $(this).attr('required','required');
477                }
478            });
479            $.fn.updateConditionalFieldsIds(subject.attr('name'),1);
480            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
481                if($(this).prop('initial-state')){
482                    $(this).attr('required');
483                }
484            });
485        } else if(action == 'disable'){
486            $section.addClass('ignore');
487            $section.closest(".rmagic-row").addClass('rm-hidden-row');
488            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
489                if($(this).attr('initial-state')){
490                    $(this).attr('required');
491                }
492            });
493            //$section.closest('.rmrow, .rmagic-field').slideUp();
494            if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
495                 $section.parents('.rmagic-row').css('margin-bottom',0);
496            }
497            $section.prop('disabled',false);
498            $.fn.updateConditionalFieldsIds(subject.attr('name'),0);
499        }else{
500            $section.addClass('ignore');
501            $section.closest(".rmagic-row").addClass('rm-hidden-row');
502            //$section.val('');
503            $section.closest('.rmrow :input, .rmagic-field :input').each(function(){
504                if($(this).attr('initial-state')){
505                    $(this).removeAttr('required');
506                }
507            });
508            $section.closest('.rmrow, .rmagic-field').slideUp();
509             if($section.parents('.rmagic-col').siblings().children(':visible').length <= 0) {
510                 $section.parents('.rmagic-row').css('margin-bottom',0);
511             }
512            //console.log($section.parent().parent().parent().siblings().children(':visible'));
513            $section.prop('disabled',true);
514            $.fn.updateConditionalFieldsIds(subject.attr('name'),0);
515        }
516    }
517    rm_init_total_pricing();
518    }
519    
520     // Add hidden field names for server side tracking
521    $.fn.updateConditionalFieldsIds= function(fieldName,add)
522    { 
523        var fieldsArr=[];
524        var currentFields= $("#rm_cond_hidden_fields");
525        if(currentFields!="")
526        fieldsArr= currentFields.val().split(",");
527        var pos= $.inArray(fieldName,fieldsArr);
528        
529        if(add==1 && pos>=0)
530                fieldsArr.splice(pos, 1); 
531        else if(pos==-1)
532                fieldsArr.push(fieldName);
533       
534        fieldsArr.length==0 ? currentFields.val(""): currentFields.val(fieldsArr.join());
535    }
536    
537    return this.each( function() {
538       var cleanSelectors= $(this).data('cond-option').toString().replace(/(:|\.|\[|\]|,)/g, "\\$1").split("|");
539        for(var i=0;i<cleanSelectors.length;i++){
540        var cleanSelector = cleanSelectors[i]; 
541        var listenTo = (cleanSelector.substring(0,1)=='|'?cleanSelector:"[name=" + cleanSelector + "]");
542        var listenFor = $(this).data('cond-value');
543        var operator = $(this).data('cond-operator') ? $(this).data('cond-operator') : '==';
544        var combinator = $(this).data('cond-comb');
545        var action = $(this).data('cond-action') ? $(this).data('cond-action') : 'show';
546        var $section = $(this);
547        var subject= $(this);
548        //Set up event listener
549        $(listenTo).on('change', function() { 
550          $.fn.showOrHide(cleanSelectors, listenFor, operator,combinator, action, $section,subject,false);
551        }); 
552        // if action is hide than it will default show and on condition meet hide it
553        // if action is show than it will default hide and on condition meet show it
554        // if action is disable than it will default enable and on condition meet disable it
555        //If setting was chosen, hide everything first...
556        
557        if(action == 'hide'){
558            $(this).closest('.rmrow, .rmagic-field').show();
559            $(this).removeClass('ignore');
560             $(this).closest(".rmagic-row").removeClass('rm-hidden-row');
561        }else if(action == 'disable'){
562            $(this).closest('.rmrow, .rmagic-field').show();
563            $(this).addClass('ignore');
564            $(this).closest(".rmagic-row").addClass('rm-hidden-row');
565        }else{
566            $(this).closest('.rmrow, .rmagic-field').hide();
567            $(this).addClass('ignore');
568            $(this).closest(".rmagic-row").addClass('rm-hidden-row');
569        }
570        // commented by devilal
571        /*if (settings.hideJS) {
572          $(this).closest('.rmrow, .rmagic-field').hide();
573          $(this).addClass('ignore');
574            //  $.fn.updateConditionalFieldsIds(subject.attr('name'),0);
575
576        }*/
577      //Show based on current value on page load
578      
579      $.fn.showOrHide(cleanSelectors, listenFor, operator,combinator,action, $section,subject,true);
580      }    
581              
582    });
583  }
584}(jQuery));
585
586
587
588/* Intializing the necessary scripts*/
589jQuery(document).ready(function(){
590    //$=jQuery;
591    if(jQuery(".data-conditional").length>0){
592        jQuery('.rmrow :input, .rmagic-field :input').each(function(){
593            if(jQuery(this).prop('required')){
594                jQuery(this).attr('initial-state','required');
595            }
596        });
597        jQuery(".data-conditional").conditionize({});
598    }
599    
600
601    
602});

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.