Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up setting a timeout inside of the $(window).load, a 10 ms delay seemed suffucient. It works fine on my phone, tablet and on chrome. I am fairly convinced it has something to do with the caching.</p> <p>I am not marking this as the answer, hopefully someone else can find a better way.</p> <pre><code>&lt;script type='text/javascript'&gt; function getSubDocument(embedding_element) { if (embedding_element.contentDocument) { return embedding_element.contentDocument; } else { var subdoc = null; try { subdoc = embedding_element.getSVGDocument(); } catch(e) {} return subdoc; } } $(window).load(function(){ setTimeout(function(){ var a = document.getElementById("hero"); var svgDoc = getSubDocument(a);//a.contentDocument; //get the inner DOM of alpha.svg var hair = svgDoc.getElementById("hair"); var shirt = svgDoc.getElementById("body"); var head = svgDoc.getElementById("head"); var left_arm = svgDoc.getElementById("left_arm"); var right_arm = svgDoc.getElementById("right_arm"); var pants = svgDoc.getElementById("pants"); //var weapon = svgDoc.getElementById('axe'); //weapon.setAttribute('display', ""); hair.setAttribute("fill", '{{ profile.hair_color }}' ); shirt.setAttribute("fill", '{{ profile.shirt_color }}' ); head.setAttribute("fill", '{{ profile.skin_color }}' ); left_arm.setAttribute("fill", '{{ profile.skin_color }}' ); right_arm.setAttribute("fill", '{{ profile.skin_color }}' ); pants.setAttribute("fill", '{{ profile.pants_color }}' ); $("input[name='colorType']").change(function(){ var ct = $("input[name='colorType']:checked").val(); var c; if(ct == 'Hair'){ c = $("#id_hair_color").val(); } else if (ct == 'Shirt'){ c = $("#id_shirt_color").val(); } else if (ct == 'Skin'){ c = $("#id_skin_color").val(); } else if (ct == 'Pants'){ c = $("#id_pants_color").val(); } $.farbtastic('#colorpicker').setColor(c); }); $("#weapon_type").change(function(){ nw = $("#weapon_type").val(); svgDoc.getElementById('sword').setAttribute('display', 'none'); svgDoc.getElementById('axe').setAttribute('display', 'none'); svgDoc.getElementById(nw).setAttribute('display', ''); }); $('#colorpicker').farbtastic(function(e){ var ct = $("input[name='colorType']:checked").val(); c = $.farbtastic('#colorpicker').color; if(ct == 'Hair'){ hair.setAttribute('fill', c); $("#id_hair_color").val(c); } else if (ct == 'Shirt'){ shirt.setAttribute('fill', c); $("#id_shirt_color").val(c); } else if (ct == 'Skin'){ head.setAttribute('fill', c); left_arm.setAttribute('fill', c); right_arm.setAttribute('fill', c); $("#id_skin_color").val(c); } else if (ct == 'Pants'){ pants.setAttribute('fill', c); $("#id_pants_color").val(c); } // conole.log(JSON.stringify($.farbtastic('#colorpicker').color)); // hair.setAttribute("fill", c); }); $.farbtastic('#colorpicker').setColor("#f0ff5f"); // var sword = svgDoc.getElementById("right_arm"); //get the inner element by id // // sword.addEventListener("mousedown",function(){alert('hello world!')},false); // alert('got to here'); }, 10); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload