• Resolved Andrew Killen

    (@andrewkillen)


    // example of a better way to code. comments should make it self-evident
    
    /**
     * This now removes jQuery dependency, spells things correctly, and considers how badly it was orignally coded. 
     * 
     * 
     * 
     */
    
    function apbct_gdpr__form_append_notice(){
    	
    	if(!ctPublic.gdpr_forms) return;
    	
    	ctPublic.gdpr_forms.forEach(function(item, i, arr){
    		// techncally not eh best code as there could be many items returned from the class selector.
    		// var elem = jQuery('#'+item+', .'+item);
    
    		// make two separate calls and only use the positive result
    		var elem = document.getElementById(item);
    		if(elem == null){
    			elem = document.getElementsByClassName(item)[0];
    		}
    		
    		// Filter forms (should say 'when not a form')
    		// if(!elem.nodeName.is('form')){
    		
    		if( elem.nodeName != 'FORM'){	
    			 
    
    			// Caldera
    			// if(elem.find('form')[0])
    			if(elem.getElementsByTagName('form') != null){
    				elem = elem.getElementsByTagName('form')[0];
    			}
    			// Contact Form 7
    			// else if(jQuery('.wpcf7[role=form]')[0] && jQuery('.wpcf7[role=form]').attr('id').indexOf('wpcf7-f'+item) !== -1)
    			else if(document.querySelectorAll('.wpcf7[role=form]') != null && document.querySelectorAll('.wpcf7[role=form]')[0].getArribute('id').indexOf('wpcf7-f'+item) !== -1){
    				// elem = jQuery('.wpcf7[role=form]');
    				elem = document.querySelectorAll('.wpcf7[role=form]')[0];
    			}
    			// Formidable
    			// else if(jQuery('.frm_forms')[0] && jQuery('.frm_forms').first().attr('id').indexOf('frm_form_'+item) !== -1)
    			else if(document.querySelectorAll('.frm_forms') != null  && document.querySelectorAll('.frm_forms')[0].getArribute('id').indexOf('frm_form_'+item) !== -1){
    				//elem = jQuery('.frm_forms').first().children('form');
    				var f = document.querySelectorAll('.frm_forms')[0];
    				elem = f.getElementsByTagName('form')[0];
    			}
    		}
    		
    		// Adding notice
    		//if(elem.is('form') || elem.attr('role') == 'form'){
    		if(elem.nodeName == 'FORM' || elem.getAttribute('role') == 'form'){
    			var fragment = fragment = document.createDocumentFragment();
    
    			var input = document.createElement('input');
    			input.setAttribute(id, "apbct_gdpr_"+i);
    			input.type = 'checkbox';
    			input.required = true;
    			input.style.marginRight = '10px';
    
    			fragment.appendChild(input);
    
    			var label = document.createElement('label');
    			label.innerText = ctPublic.gdpr_text;
    			label.htmlFor = "apbct_gdpr_"+i;
    
    			fragment.appendChild(label);
    
    			// elem.append('<input id="apbct_gdpr_'+i+'" type="checkbox" required="required " style="margin-right: 10px;">')
    			//		// FFS!! incorrect spelling of label.  did you even test this???????
    			//		.append('<lable for="apbct_gdpr_'+i+'">'+ctPublic.gdpr_text+'</lable>');
    			//		// also loading twice with a re-draw
    
    			elm.appendChild(fragment);
    		}
    	});
    	
    }
    
    // jQuery(document).ready(function(){
    	// jQuery not needed to load it last if it is just included in the footer. 
    	apbct_gdpr__form_append_notice();
    	
    // });
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Andrew Killen

    (@andrewkillen)

    the above code is totally untested.

    Plugin Support SergeM

    (@serge00)

    Hello.

    Thank you for your second suggestion. I have added it to the task as well.

    Please, wait until our programmer stuff look through it.

    Kind regards.

    Plugin Support Safronik

    (@safronik)

    Hello,

    Thank you for this patch. You’re the best! We’ll include it in the next release.

    p.s.: I was confused why label haven’t worked while testing. The answer is spelling. Thank you.

    Thread Starter Andrew Killen

    (@andrewkillen)

    Why is this not fixed after 2 months? The code you have in production is broken, this is the fix.

    Plugin Support sergecleantalk

    (@sergecleantalk)

    Thank you for your question. I will ask our developers.

    We will contact you within 1-2 working days.

    Best regards

    Plugin Support Safronik

    (@safronik)

    Hello,

    The deal is that your code contained some errors.
    We’ll revise it in 1-2 day.

    Plugin Support Safronik

    (@safronik)

    Hello,

    This now removes jQuery dependency, spells things correctly, and considers how badly

    it was orignally coded.
    Answer: Why you don’t like jQuery? It goes with wordpress originaly and makes everyone’s life easy.
    Maybe there was a few mistakes. =( please, forgive me.
    Unfortunately your code was not working at all =( that’s why we use old one with some fixes (thank you!).
    And yes, we have tested, like all other new functions and all new releases. But something went wrong i think =(

    var elem = jQuery('#'+item+', .'+item);
    technically not eh best code as there could be many items returned from the class selector.

    For example:
    ctPublic.gdpr_forms = {‘some’, ‘thing’};
    so it will return only #some, .some, #thing, .thing
    it’s not much, i think…

    Please, take a look: https://downloads.wordpress.org/plugin/cleantalk-spam-protect.zip

    Contact us if you have questions.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘better JS that does not require jQuery for GDPR : apbct-public–gdpr.js’ is closed to new replies.