как заставить js работать в цикле как и на php? php endforeach
Есть скрипт такой
<script type="text/javascript">
setShareLinks();
function socialWindow(url) {
var left = (screen.width - 570) / 2;
var top = (screen.height - 570) / 2;
var params = "menubar=no,toolbar=no,status=no,width=570,height=570,top=" + top + ",left=" + left;
// Setting 'params' to an empty string will launch
// content in a new tab or window rather than a pop-up.
// params = "";
window.open(url,"NewWindow",params);
}
function setShareLinks() {
var pageUrl = encodeURIComponent(document.URL);
var tweet = encodeURIComponent($("meta[property='og:description']").attr("content"));
var test = "<?echo $item['link']?>";
$(".social-share.facebook").on("click", function() {
url = "https://www.facebook.com/sharer.php?u=" + "https://marijuana-news.net" + test;
socialWindow(url);
});
</script>
И есть php код который выводит картинки в галлерею. Заканчивается он на php endif
<?php if ($item['link']) : ?>
<a<?= $this->attrs($attrs_link) ?><?= $lightbox_caption ?>></a><a href="https://www.pinterest.com/pin/create/button/" data-pin-do="buttonBookmark"></a>
<?php endif ?>
<?php if ($element['image_box_shadow_bottom']) : ?>
</div>
<?php endif ?>
</div>
Но переменная test работает только на последний урл, не на весь цикл Как переписать?