var saveRowIdx = -1;
function insRow(p_stockRg, p_pdlsorg, p_language, p_rowId, p_type)
{
var curRow = document.getElementById(p_rowId);
var curRowIdx = curRow.rowIndex;
var attFlag = curRow.getAttribute("fdg");
if (attFlag == null) {
getStockDetail(p_stockRg, p_pdlsorg, p_language, curRow, p_type);
} else { // show row
if (saveRowIdx != (curRowIdx+1)) {
if (saveRowIdx > 0)
document.getElementById('TableDetail').rows[saveRowIdx].style.display = "none";
document.getElementById('TableDetail').rows[curRow.rowIndex+1].style.display = "";
saveRowIdx = curRow.rowIndex+1;
} else {
var displayRow = document.getElementById('TableDetail').rows[curRow.rowIndex+1];
displayRow.style.display = (displayRow.style.display == "none") ? "" : "none";
}
}
}
function showPhotoSwipe(swiperSelector, gallerySelector, pswpSelector){
console.log("showPhotoSwipe called " + gallerySelector + "," + pswpSelector);
/* 1 of 2 : SWIPER ################################### */
/*$(gallerySelector + " li").each(function(){
var $li = $(this);
var $a = $li.find("a");
var $img = $a.find("img");
var imgSize = $img.attr("data-size").split("x");
var imgWidth = parseInt(imgSize[0]);
var imgHeight = parseInt(imgSize[1]);
var rw = $li.width() / imgWidth;
var rh = $li.height() / imgHeight;
if (rw <= rh) {
$img.css('width', '100%');
$img.css('height', 'auto');
} else {
$img.css('height', '100%');
$img.css('width', 'auto');
}
});*/
var mySwiper = new Swiper(swiperSelector, {
// If swiper loop is true set photoswipe counterEl: false (line 175 her)
loop: true,
/* slidesPerView || auto - if you want to set width by css like flickity.js layout - in this case width:80% by CSS */
slidesPerView: "auto",
spaceBetween: 7,
centeredSlides: true,
// If we need pagination
pagination: {
el: ".swiper-pagination",
clickable: true,
renderBullet: function(index, className) {
return '' + (index + 1) + "";
}
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
// 2 of 2 : PHOTOSWIPE #######################################
// parse slide data (url, title, size ...) from DOM elements
// (children of gallerySelector)
var parseThumbnailElements = function(el) {
var thumbElements = el.childNodes,
numNodes = thumbElements.length,
items = [],
figureEl,
linkEl,
size,
item;
for (var i = 0; i < numNodes; i++) {
figureEl = thumbElements[i]; // element
// include only element nodes
if (figureEl.nodeType !== 1) {
continue;
}
linkEl = figureEl.children[0]; // element
size = linkEl.getAttribute("data-size").split("x");
// create slide object
item = {
src: linkEl.getAttribute("href"),
w: parseInt(size[0], 10),
h: parseInt(size[1], 10)
};
if (figureEl.children.length > 1) {
// content
item.title = figureEl.children[1].innerHTML;
}
if (linkEl.children.length > 0) {
//
thumbnail element, retrieving thumbnail url
item.msrc = linkEl.children[0].getAttribute("src");
}
item.el = figureEl; // save link to element for getThumbBoundsFn
items.push(item);
}
return items;
};
// find nearest parent element
var closest = function closest(el, fn) {
return el && (fn(el) ? el : closest(el.parentNode, fn));
};
// triggers when user clicks on thumbnail
var onThumbnailsClick = function(e) {
e = e || window.event;
e.preventDefault ? e.preventDefault() : (e.returnValue = false);
var eTarget = e.target || e.srcElement;
// find root element of slide
var clickedListItem = closest(eTarget, function(el) {
return el.tagName && el.tagName.toUpperCase() === "LI";
});
if (!clickedListItem) {
return;
}
// find index of clicked item by looping through all child nodes
// alternatively, you may define index via data- attribute
var clickedGallery = clickedListItem.parentNode,
childNodes = clickedListItem.parentNode.childNodes,
numChildNodes = childNodes.length,
nodeIndex = 0,
index;
for (var i = 0; i < numChildNodes; i++) {
if (childNodes[i].nodeType !== 1) {
continue;
}
if (childNodes[i] === clickedListItem) {
index = nodeIndex;
break;
}
nodeIndex++;
}
if (index >= 0) {
// open PhotoSwipe if valid index found
openPhotoSwipe(index, clickedGallery);
}
return false;
};
// parse picture index and gallery index from URL (#&pid=1&gid=2)
var photoswipeParseHash = function() {
var hash = window.location.hash.substring(1),
params = {};
if (hash.length < 5) {
return params;
}
var vars = hash.split("&");
for (var i = 0; i < vars.length; i++) {
if (!vars[i]) {
continue;
}
var pair = vars[i].split("=");
if (pair.length < 2) {
continue;
}
params[pair[0]] = pair[1];
}
if (params.gid) {
params.gid = parseInt(params.gid, 10);
}
return params;
};
var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
var pswpElement = document.querySelectorAll(pswpSelector)[0], gallery, options, items;
items = parseThumbnailElements(galleryElement);
// define options (if needed)
options = {
/* "showHideOpacity" uncomment this If dimensions of your small thumbnail don't match dimensions of large image */
//showHideOpacity:true,
// Buttons/elements
closeEl: true,
captionEl: true,
fullscreenEl: true,
zoomEl: true,
shareEl: true,
counterEl: false,
arrowEl: true,
preloaderEl: true,
// define gallery index (for URL)
galleryUID: galleryElement.getAttribute("data-pswp-uid"),
getThumbBoundsFn: function(index) {
// See Options -> getThumbBoundsFn section of documentation for more info
var thumbnail = items[index].el.getElementsByTagName("img")[0], // find thumbnail
pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
rect = thumbnail.getBoundingClientRect();
return { x: rect.left, y: rect.top + pageYScroll, w: rect.width };
}
};
// PhotoSwipe opened from URL
if (fromURL) {
if (options.galleryPIDs) {
// parse real index when custom PIDs are used
// http://photoswipe.com/documentation/faq.html#custom-pid-in-url
for (var j = 0; j < items.length; j++) {
if (items[j].pid == index) {
options.index = j;
break;
}
}
} else {
// in URL indexes start from 1
options.index = parseInt(index, 10) - 1;
}
} else {
options.index = parseInt(index, 10);
}
// exit if index not found
if (isNaN(options.index)) {
return;
}
if (disableAnimation) {
options.showAnimationDuration = 0;
}
// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
/* EXTRA CODE (NOT FROM THE CORE) - UPDATE SWIPER POSITION TO THE CURRENT ZOOM_IN IMAGE (BETTER UI) */
// photoswipe event: Gallery unbinds events
// (triggers before closing animation)
gallery.listen("unbindEvents", function() {
// This is index of current photoswipe slide
var getCurrentIndex = gallery.getCurrentIndex();
// Update position of the slider
mySwiper.slideTo(getCurrentIndex, false);
});
gallery.init();
};
// loop through all gallery elements and bind events
var galleryElements = document.querySelectorAll(gallerySelector);
for (var i = 0, l = galleryElements.length; i < l; i++) {
galleryElements[i].setAttribute("data-pswp-uid", i + 1);
galleryElements[i].onclick = onThumbnailsClick;
}
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = photoswipeParseHash();
if (hashData.pid && hashData.gid) {
openPhotoSwipe(hashData.pid, galleryElements[hashData.gid - 1], true, true);
}
}
function getStockDetail(p_stockRg, p_pdlsorg, p_language, p_rowObj, p_type) {
var url = "/winecave/cleanGetStockDetail.jsp?"
+"&stock="+p_stockRg
+"&pdlsorg="+p_pdlsorg
+"&language="+p_language
+"&rowindex="+p_rowObj.rowIndex
;
cleanGetUrl(url, null, afterGetStockDetail, {"rowObj" : p_rowObj, "type" : p_type});
}
function afterGetStockDetail(p_status, p_consumer, p_request, p_params) {
if (p_status < 200 || p_status > 299) {
alert((getLanguage() == 0) ? "Failed to contact server." : "\u7121\u6cd5\u9023\u63a5\u670d\u52d9\u5668\u002e");
return;
}
var responseText = p_request.responseText;
if (saveRowIdx > 0)
document.getElementById('TableDetail').rows[saveRowIdx].style.display = "none";
var rowObj = p_params["rowObj"];
var idx = rowObj.rowIndex + 1;
var newRow = document.getElementById('TableDetail').insertRow(idx)
var cell = newRow.insertCell(0)
cell.className = "div_det";
var type = p_params["type"];
if (type == 1 || type == 2) {
cell.colSpan = "10";
} else {
cell.colSpan = "9";
}
cell.innerHTML = responseText;
rowObj.setAttribute("fdg", "yes");
saveRowIdx = newRow.rowIndex;
showPhotoSwipe("#swiper_" + rowObj.rowIndex, "#gallery_" + rowObj.rowIndex, "#pswp_" + rowObj.rowIndex);
}