• Resolved litradio

    (@litradio)


    Hi
    i would like to use an animated SVG logo as I have it right here on this site: https://litradio.net.
    I installed a plugin to enable svg upload. So far all good. But if I’m putting the same js-code in Theme Options > Integrations > <head> no animation is working (here: https://2018.litradio.net).
    Console gives me this error:
    Uncaught TypeError: Cannot read property 'substr' of undefined at Image.onLoad
    So it looks as if there is a conflict between your plugin and Divi, right? Could you inspect this?

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Benbodhi

    (@benbodhi)

    Hey,

    Maybe try putting the JS in the footer…

    If you can provide the JS and the SVG, I can test it out and see.

    I use SVG with Divi and it works great, so I suspect something is amiss.

    Plugin Author Benbodhi

    (@benbodhi)

    I can see the path that is animated has the ID lit in the working one, but the not working SVG does not have that ID… Is that the ID that the JS targets?
    Are you using the exact same SVG?

    Plugin Author Benbodhi

    (@benbodhi)

    There is a LOT of errors in the console too, my computer sounds like a hovercraft running that page with the animated one. I would look into that as well.

    Thread Starter litradio

    (@litradio)

    thank you for your fast answer!
    I’ve send you both js-code and SVG via email.

    The js-code I didn’t write myself. And I both was installed by a developer years ago. So I’m not sure how to figure this out.

    Which errors do you mean? MY console of the subdomain only shows the cited error. And on litradio.net there are no related errors shown.

    Plugin Author Benbodhi

    (@benbodhi)

    I haven’t received any files…

    The console error fires on mouse move (onMouseMove), so you can hit thousands of errors very quickly.

    Uncaught TypeError: a[b].target.className.indexOf is not a function
        at au.v.Ai (eval at xhr.onreadystatechange ((index):318), <anonymous>:405:129)
    v.Ai @ VM92:405
    attributes (async)
    draw @ (index):203
    onMouseMove @ (index):217
    

    But yeah, it looks to me like the SVG file/code is actually different on each site.

    Thread Starter litradio

    (@litradio)

    your email isn’t [email protected]?
    how can i send you the files?

    Plugin Author Benbodhi

    (@benbodhi)

    Yeah, that’s right. I didn’t get an email though.
    Maybe upload to drop box or something. Mail client might be blocking code. Or zip the files and try send the zip file maybe.

    Thread Starter litradio

    (@litradio)

    sent it again as a zip file

    Thread Starter litradio

    (@litradio)

    by the way: the only error console shows to me is:

    custom.js?ver=3.12.1:1209 
    
    Uncaught TypeError: Cannot read property 'substr' of undefined
        at Image.et_define_logo_dimension [as onLoad] (custom.js?ver=3.12.1:1209)
    et_define_logo_dimension @ custom.js?ver=3.12.1:1209
    load (async)
    et_preload_image @ custom.js?ver=3.12.1:40
    (anonymous) @ custom.js?ver=3.12.1:1250
    i @ jquery.js?ver=1.12.4:2
    fireWith @ jquery.js?ver=1.12.4:2
    ready @ jquery.js?ver=1.12.4:2
    K @ jquery.js?ver=1.12.4:2
    Thread Starter litradio

    (@litradio)

    hi, would you like to come back to this still unfortunately unsolved topic?

    Plugin Author Benbodhi

    (@benbodhi)

    Hello,

    I’m sorry, I’ve been very busy.

    To be fair, it’s not a conflict in the theme or my plugin, it’s your code.
    I am willing to help and have your email with the info, I just need some time to spare for it.

    I will try my best to get to it today.

    Plugin Author Benbodhi

    (@benbodhi)

    Ok, I had a look and tested it on a fresh install of WordPress with Divi and my plugin.

    In my plugin settings, I chose the “Enable Advanced Mode”, then saved to open advanced settings, then enabled the “Force Inline SVG?” option because Divi doesn’t give you the option to add a class to your logo image. This makes sure the SVG is rendered inline and internal elements can be targeted.

    Then you just need to make sure your JS targets the thing.
    I switched your line:
    svg = document.querySelector( "#svg-replaced-1" ),
    with
    svg = document.querySelector( ".logo_container svg" ),

    I added your JS to the integrations tab in Divi, in the <head>, making sure to wrap the whole lot with <script></script> tags.

    Here is the final JS you can simply paste in that section:

    <script>
    	window.onload = function() {
    	/* HELPERS */
    
    	function checkMobileDevice() {
    		return navigator.userAgent.match(/iPad|iPhone|iPod|Android|webOS|BlackBerry/i) != null || screen.width <= 480;
    	}
    
    	function getWidth() {
    		if (self.innerWidth) {
    			return self.innerWidth;
    		}
    
    		if (document.documentElement && document.documentElement.clientWidth) {
    			return document.documentElement.clientWidth;
    		}
    
    		if (document.body) {
    			return document.body.clientWidth;
    		}
    	}
    
    	function getHeight() {
    		if (self.innerHeight) {
    			return self.innerHeight;
    		}
    
    		if (document.documentElement && document.documentElement.clientHeight) {
    			return document.documentElement.clientHeight;
    		}
    
    		if (document.body) {
    			return document.body.clientHeight;
    		}
    	}
    
    	function getDistance(x1, y1, x2, y2) {
    		var a = x1 - x2,
    			b = y1 - y2,
    
    		c = Math.sqrt( a*a + b*b );
    
    		return c
    	}
    
    	function mapToRange(value, in_min, in_max, out_min, out_max) {
    		return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    	}
    
    	function prepareOffset(offset, margin) {
    		offset = mapToRange(offset, 0, 1, -margin, 1 + margin)
    
    		if (offset < 0)
    			offset = 0
    		if (offset > 1)
    			offset = 1	
    
    		return offset
    	}
    
    	function calcScrollFactor(event) {
    		var scrollHeight = document.documentElement.scrollHeight,
    			clientHeight = getHeight(),
    			scrollY = window.pageYOffset;
    
    		return scrollY / (scrollHeight - clientHeight);				
    	}	
    
    	/* PATH */
    
    	function DrawablePath(path) {
    		var length = path.getTotalLength()
    
    		path.style.strokeDasharray = length + ' ' + length;
    
    		return {
    			draw: function(factor) {
    				path.style.strokeDashoffset = length * factor;	
    			}
    		}	
    	}
    
    	/* EVENTS */
    	function onMouseMove(event) {
    		var width = getWidth(),
    			height = getHeight(),
    			offset;
    
    		offset = getDistance(event.clientX, event.clientY, 0, 0) / getDistance(0, 0, width, height);
    		offset = prepareOffset(offset, margin);	
    
    		lit.draw(offset);
    	}
    
    	function onScroll(event) {
    		var scrollFactor = calcScrollFactor(event);
    
    		lit.draw(scrollFactor * 2);
    	}	
    
    	/* MAIN */
    
    	var isMobileDevice = checkMobileDevice(),
    		margin = 0.05
    		svg = document.querySelector( ".logo_container svg" ),
    		lit = null;
    
    	if (svg) {
    		lit = new DrawablePath( svg.querySelector("#lit") );
    
    		if (isMobileDevice) {
    			document.addEventListener("scroll", onScroll, false);
    			document.addEventListener("touchmove", onScroll, false);
    		} else {
    			document.addEventListener("mousemove", onMouseMove, false);		
    		}
    	}	
    }
    </script>
    

    So yeah, no conflict, just need to know what to do ??

    • This reply was modified 6 years, 3 months ago by Benbodhi. Reason: Made the explanation more clear
    Thread Starter litradio

    (@litradio)

    great one! worked like a charm

    Plugin Author Benbodhi

    (@benbodhi)

    Indeed ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘conflict in Divi theme with SVG Logo animation’ is closed to new replies.