How to run a script in Jquery cookie?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
9 views
The problem is, you need to consider the number of shares and put them in one unit figure, after the transition to the section "actions", you need to reset this number and record the data in the cookie that was dealt with
var x = $('.akcii.item').length; var b = '' + x + ''; $('.akc.menu-item a').append(b);


After the cookies code
function getCookie() { var cookies = document.cookie.match ( '(^|;) ?adultconfirmed=([^;]*)(;|$)' ); if (cookies) { $('.akc.menu-item span a').html('0'); } } if(window.location.toString().indexOf('/akcii/')>0){ document.cookie = 'adultconfirmed=yes; path=/; expires=01/01/2100 00:00:00'; $('.akc.menu-item span a').html('0'); }; getCookie();

After going to the promotions page number is reset and stored in the cache how to make so that when adding a new action to 0 was added 1. I.e. user visits the website, sees the number of new shares "4", after going to the promotions page = 0, and when you add a new action (the cache is preserved and the unit is reset) to 0 was added 1, after clearing the cache, the value will be 5 (4 old shares and 1 new)
by | 9 views

1 Answer

0 like 0 dislike
Something like that. https://jsfiddle.net/ch51d9mh/
Added buttons that will perform actions (because jsfiddle does not implement multi pages). The button "Make shares read" performs the function setReadStock which remembers the last viewed stocks. The second button simply adds the action, it can remove, because as I understand it, the stock you have added to the server.
\rAction 1\rAction 2\rAction 3\r\r\r\rUnread stock 0The last read action 0\r\r\r\r\r

// ID of last saved action getLastSaveStockID function() { var stockId = getCookie('last_stock_id'); if(stockId === undefined) { return 0; } return stockId; } // ID of the last shown out of stock getLastStockID function() { var ids = $('.stock__item').map(function() { return this.dataset['id']; }).toArray(); return Math.max.apply(null, ids); } // The number of shares whose id last_id more function getStockCount(last_id) { return $('.stock__item').map(function() { if(+this.dataset['id'] > last_id) { return this; } }).length; } // Make all shares read setReadStock function() { var last_id = getLastStockID(); var last_read_id = getLastSaveStockID(); if(+last_id > last_read_id) { setCookie('last_stock_id', last_id); } } // Add action function addStock() { var last_id = getLastStockID(); var new_id = last_id + 1; $('.stock').append('Event ' + new_id + ''); printCountStock(); } // Display the number of new shares printCountStock function() { var last_id = getLastSaveStockID(); var stockCount = getStockCount(last_id); jQuery('.count-actions__value').html(stockCount); jQuery('.count-actions__read').html(last_id); } // When the page loads displaying the number of new shares. printCountStock(); document.getElementById('set_read').addEventListener('click', function() { setReadStock(); printCountStock(); }); document.getElementById('add_stock').addEventListener('click', addStock); // Setting cookies function setCookie(name, value, options) { options = options || {}; var expires = options.expires; if (typeof expires == "number" && expires) { var d = new Date(); d.setTime(d.getTime() + expires * 1000); expires = options.expires = d; } if (expires && expires.toUTCString) { options.expires = expires.toUTCString(); } value = encodeURIComponent(value); var updatedCookie = name + "=" + value; for (var propName in options) { updatedCookie += "; " + propName; var propValue = options[propName]; if (propValue !== true) { updatedCookie += "=" + propValue; } } document.cookie = updatedCookie; } // returns the cookie with name name, if there, if not, undefined function getCookie(name) { var matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\\.$?*|{}\\(\\)\\[\\]\\\\\\/\\+^])/g, '\\\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : undefined; }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked May 21, 2019 by 1011012
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
35,533 users