(function () { if (!$) { return; } function __$styleInject (css) { if (!css) return; if (typeof (window) == 'undefined') return; var style = document.createElement('style'); if ('styleSheet' in style) { style = document.createElement('div'); style.innerHTML = 'x'; style = style.lastChild; } else { style.innerHTML = css; } var head = document.getElementsByTagName('head')[0]; head.appendChild(style); return css; } function transformHtml ($dom, html) { var itemIdx = 0; var isMatch = 0; var imageList = []; var $children = $dom.children().each(function (idx, val) { var $val = $(val); $val.attr('nfc-image-post') && (isMatch += 1); imageList[itemIdx] = imageList[itemIdx] || {src: '', content: ''}; if (idx % 2) { imageList[itemIdx].content = $val.text(); itemIdx += 1; } else { var src = $val.find('img'); src = src ? src.attr('src') : ''; imageList[itemIdx].src = src.split('?')[0]; } }); if (isMatch !== $children.length) { return false; } return imageList; } function swiper ($dom, imageList) { var prev = $dom.find('.left.arrow')[0]; var next = $dom.find('.right.arrow')[0]; var list = $dom.find('.nfc-image-post-list')[0]; var $content = $dom.find('.nfc-image-post-item__descbox-content'); var $index = $dom.find('.nfc-image-post-item__descbox-index .index'); var index = 1; var animated = false; var width = parseFloat($dom.find('.nfc-image-post-container').width()); var limit = width * imageList.length; function animate (offset) { animated = true; var newLeft = parseInt(list.style.left) + offset; $(list).animate({ 'left': newLeft + 'px' }, 250, function () { animated = false; $content.text(imageList[index - 1].content); $index.html(index); if (newLeft > -width) { list.style.left = -limit + 'px'; } if (newLeft < -limit) { list.style.left = -width + 'px'; } }); } $(prev).off('click').on('click', function () { if (!animated) { if (index === 1) { index = imageList.length; } else { index -= 1; } animate(width); } }); $(next).off('click').on('click', function () { if (!animated) { if (index === imageList.length) { index = 1; } else { index += 1; } animate(-width); } }); } function createImagePostHtml (imageList, opt) { var imgHtml = []; $.each(imageList, function (key, val) { imgHtml.push( '
' + imageList[0].content + '
' + '