Changeset 1933344
- Timestamp:
- 08/30/2018 06:26:59 PM (8 years ago)
- Location:
- wp-content-personalization
- Files:
-
- 1 deleted
- 2 edited
-
tags/1.0/trunk (deleted)
-
trunk/js/wpcp-foot.js (modified) (3 diffs)
-
trunk/js/wpcp-foot.min.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-content-personalization/trunk/js/wpcp-foot.js
r1933190 r1933344 1 var setCookie = function (cookieName, cookieValue, expiresAfterDays) {1 var setCookie = function(cookieName, cookieValue, expiresAfterDays) { 2 2 var d = new Date(); 3 d.setTime(d.getTime() + (expiresAfterDays * 24 * 60 * 60 * 1000));4 var expires = 'expires='+ d.toUTCString();5 document.cookie = cookieName + '=' + cookieValue + ';' + expires + ';path=/';3 d.setTime(d.getTime() + expiresAfterDays * 24 * 60 * 60 * 1000); 4 var expires = "expires=" + d.toUTCString(); 5 document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/"; 6 6 }; 7 7 8 var getCookie = function (cookieName) {9 var name = cookieName + '=';10 var ca = document.cookie.split( ';');8 var getCookie = function(cookieName) { 9 var name = cookieName + "="; 10 var ca = document.cookie.split(";"); 11 11 12 for (var i = 0; i < ca.length; i++) {12 for (var i = 0; i < ca.length; i++) { 13 13 var c = ca[i]; 14 while (c.charAt(0) == ' ') {14 while (c.charAt(0) == " ") { 15 15 c = c.substring(1); 16 16 } … … 19 19 } 20 20 } 21 return '';21 return ""; 22 22 }; 23 23 24 24 document.addEventListener("DOMContentLoaded", function() { 25 var varBlocks = document.querySelectorAll( '.var-block');25 var varBlocks = document.querySelectorAll(".var-block"); 26 26 27 27 varBlocks.forEach(function(block) { 28 block.style.display = 'none';28 block.style.display = "none"; 29 29 30 var parentqm = block.getAttribute( 'data-qm').split('-'),31 parentqid = 'q-'+ parentqm[1],32 dcookie = getCookie( 'vh-'+ parentqid);30 var parentqm = block.getAttribute("data-qm").split("-"), 31 parentqid = "q-" + parentqm[1], 32 dcookie = getCookie("vh-" + parentqid); 33 33 34 if (dcookie === '' && block.classList.contains('var-block--default')) {35 block.style.display = 'block';34 if (dcookie === "" && block.classList.contains("var-block--default")) { 35 block.style.display = "block"; 36 36 37 var answers = document.querySelectorAll( '.q-answers');37 var answers = document.querySelectorAll(".q-answers"); 38 38 answers.forEach(function(answer) { 39 answer.querySelector( 'span').classList.add('selected');39 answer.querySelector("span").classList.add("selected"); 40 40 }); 41 } else if (block.getAttribute( 'data-qm') === parentqid + '-'+ dcookie) {42 block.style.display = 'block';41 } else if (block.getAttribute("data-qm") === parentqid + "-" + dcookie) { 42 block.style.display = "block"; 43 43 44 $('#' + parentqid + ' .' + dcookie).addClass('selected'); 44 document 45 .querySelector("#" + parentqid + " ." + dcookie) 46 .classList.add("selected"); 45 47 } 46 48 }); 47 49 48 50 // Click on answer, show the correct content. 49 var answers = document.querySelectorAll( '.q-answers span');51 var answers = document.querySelectorAll(".q-answers span"); 50 52 51 53 answers.forEach(function(answer) { 52 answer.addEventListener( 'click', function() {53 var questionsID = answer.parentNode.parentNode.getAttribute( 'id'),54 questionValue = this.getAttribute( 'class').split(' ')[0];54 answer.addEventListener("click", function() { 55 var questionsID = answer.parentNode.parentNode.getAttribute("id"), 56 questionValue = this.getAttribute("class").split(" ")[0]; 55 57 56 58 // Hide all answer content for this question. 57 document.querySelectorAll('[data-qm^="' + questionsID + '"].var-block').forEach(function(question){ 58 question.style.display = 'none'; 59 }); 59 document 60 .querySelectorAll('[data-qm^="' + questionsID + '"].var-block') 61 .forEach(function(question) { 62 question.style.display = "none"; 63 }); 60 64 61 if (false === this.classList.contains('selected')) { 62 document.querySelectorAll('[data-qm="' + questionsID + '-' + questionValue + '"].var-block').forEach(function(question){ 63 question.style.display = 'block'; 64 }); 65 if (false === this.classList.contains("selected")) { 66 document 67 .querySelectorAll( 68 '[data-qm="' + questionsID + "-" + questionValue + '"].var-block' 69 ) 70 .forEach(function(question) { 71 question.style.display = "block"; 72 }); 65 73 } 66 74 … … 68 76 var children = this.parentNode.children; 69 77 for (var i = 0; i < children.length; i++) { 70 children[i].classList.remove( 'selected');78 children[i].classList.remove("selected"); 71 79 } 72 this.classList.add( 'selected');80 this.classList.add("selected"); 73 81 74 setCookie( 'vh-' + questionsID, questionValue, '1000');82 setCookie("vh-" + questionsID, questionValue, "1000"); 75 83 }); 76 84 }); -
wp-content-personalization/trunk/js/wpcp-foot.min.js
r1933190 r1933344 1 var setCookie=function(e,t,o){var n=new Date;n.setTime(n.getTime()+24*o*60*60*1e3);var s="expires="+n.toUTCString();document.cookie=e+"="+t+";"+s+";path=/"},getCookie=function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var s=o[n];" "==s.charAt(0);)s=s.substring(1);if(0==s.indexOf(t))return s.substring(t.length,s.length)}return""};document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".var-block").forEach(function(e){e.style.display="none";var t="q-"+e.getAttribute("data-qm").split("-")[1],o=getCookie("vh-"+t);""===o&&e.classList.contains("var-block--default")?(e.style.display="block",document.querySelectorAll(".q-answers").forEach(function(e){e.querySelector("span").classList.add("selected")})):e.getAttribute("data-qm")===t+"-"+o&&(e.style.display="block", $("#"+t+" ."+o).addClass("selected"))}),document.querySelectorAll(".q-answers span").forEach(function(s){s.addEventListener("click",function(){var e=s.parentNode.parentNode.getAttribute("id"),t=this.getAttribute("class").split(" ")[0];document.querySelectorAll('[data-qm^="'+e+'"].var-block').forEach(function(e){e.style.display="none"}),!1===this.classList.contains("selected")&&document.querySelectorAll('[data-qm="'+e+"-"+t+'"].var-block').forEach(function(e){e.style.display="block"});for(var o=this.parentNode.children,n=0;n<o.length;n++)o[n].classList.remove("selected");this.classList.add("selected"),setCookie("vh-"+e,t,"1000")})})});1 var setCookie=function(e,t,o){var n=new Date;n.setTime(n.getTime()+24*o*60*60*1e3);var s="expires="+n.toUTCString();document.cookie=e+"="+t+";"+s+";path=/"},getCookie=function(e){for(var t=e+"=",o=document.cookie.split(";"),n=0;n<o.length;n++){for(var s=o[n];" "==s.charAt(0);)s=s.substring(1);if(0==s.indexOf(t))return s.substring(t.length,s.length)}return""};document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".var-block").forEach(function(e){e.style.display="none";var t="q-"+e.getAttribute("data-qm").split("-")[1],o=getCookie("vh-"+t);""===o&&e.classList.contains("var-block--default")?(e.style.display="block",document.querySelectorAll(".q-answers").forEach(function(e){e.querySelector("span").classList.add("selected")})):e.getAttribute("data-qm")===t+"-"+o&&(e.style.display="block",document.querySelector("#"+t+" ."+o).classList.add("selected"))}),document.querySelectorAll(".q-answers span").forEach(function(s){s.addEventListener("click",function(){var e=s.parentNode.parentNode.getAttribute("id"),t=this.getAttribute("class").split(" ")[0];document.querySelectorAll('[data-qm^="'+e+'"].var-block').forEach(function(e){e.style.display="none"}),!1===this.classList.contains("selected")&&document.querySelectorAll('[data-qm="'+e+"-"+t+'"].var-block').forEach(function(e){e.style.display="block"});for(var o=this.parentNode.children,n=0;n<o.length;n++)o[n].classList.remove("selected");this.classList.add("selected"),setCookie("vh-"+e,t,"1000")})})});
Note: See TracChangeset
for help on using the changeset viewer.