core/skin/m2.yurecnt.ru/js/pluso/pinbutton.js

469 lines
22 KiB
JavaScript
Raw Normal View History

2023-04-09 19:52:26 +05:00
(function() {
var baseUrl = 'http://pinme.ru/';
var baseStaticUrl = 'http://pinme.ru/';
var baseNoSchemaStaticUrl = '//pinme.ru/';
var pinmeUID = "PINME_" + (new Date).getTime();
if (window.location.href.match(/^http:\/\/.*?\.?pinme\.ru\//)) {
alert('Панель Pinme успешно установлена. Теперь Вы можете использовать ее на своих любимых сайтах для добавления пинов.');
return false;
}
if (typeof window.pinmePanel == 'undefined') {
window.pinmePanel = {};
}
if (window.pinmePanel.proceed) {
window.pinmePanel.close();
return false;
}
window.pinmePanel.proceed = true;
function isIE() {
return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
function isChrome() {
return /Chrome/.test(navigator.userAgent);
}
function isSafari() {
return /Safari/.test(navigator.userAgent) && !isChrome();
}
function isIOS() {
return navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPhone/i) != null || navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPod/i) != null
}
function hasClass(elem, className) {
return new RegExp("(^|\\s)"+className+"(\\s|$)").test(elem.className)
}
function addClass(o, c){
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g");
if (re.test(o.className)) return
o.className = (o.className + " " + c).replace(/\s+/g, " ").replace(/(^ | $)/g, "")
}
function removeClass(o, c){
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g");
o.className = o.className.replace(re, "$1").replace(/\s+/g, " ").replace(/(^ | $)/g, "")
}
function in_array(needle, haystack, strict)
{
var found = false, key, strict = !!strict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}
}
return found;
}
function temphide(tag)
{
if (!window.pinmePanel.hiddenTag) {
window.pinmePanel.hiddenTag = [];
}
var emb = document.getElementsByTagName(tag);
for (var i = 0; i < emb.length; i++) {
if (emb[i].style.display != 'none') {
window.pinmePanel.hiddenTag.push([emb[i], emb[i].style.display]);
emb[i].style.display = 'none';
}
}
}
function reverttemphide()
{
if (!window.pinmePanel.hiddenTag) {
return;
}
for (var i = 0; i < window.pinmePanel.hiddenTag.length; i++) {
window.pinmePanel.hiddenTag[i][0].style.display = window.pinmePanel.hiddenTag[i][1];
}
window.pinmePanel.hiddenTag = [];
}
function initPanel()
{
if (window.pinmePanel.panel) {
window.pinmePanel.block.style.display = 'block';
window.pinmePanel.panel.style.display = 'block';
return;
}
window.pinmePanel.close = function()
{
window.pinmePanel.block.style.display = 'none';
window.pinmePanel.panel.style.display = 'none';
window.pinmePanel.imageContainer.innerHTML = '';
window.pinmePanel.submitButton.style.display = 'none';
reverttemphide();
window.pinmePanel.proceed = false;
};
window.pinmePanel.select = function(event)
{
var item = event.target;
if (hasClass(item, 'pinmeSelectButton') || hasClass(item, 'pinmeInfo') || hasClass(item, 'pinmeImg'))
{
item = item.parentElement;
}
var imgId = item.imgId;
var img = window.pinmePanel.images[imgId];
if (hasClass(item, 'selected')) {
removeClass(item, 'selected');
var selected = [];
for (var i = 0; i < window.pinmePanel.selectedImages.length; i++) {
if (window.pinmePanel.selectedImages[i].id != imgId) {
selected.push(window.pinmePanel.selectedImages[i]);
}
}
window.pinmePanel.selectedImages = selected;
} else {
addClass(item, 'selected');
var image_item = img;
image_item.alt = (img.alt || img.title || document.title);
image_item.id = imgId;
window.pinmePanel.selectedImages.push(image_item);
}
if (window.pinmePanel.selectedImages.length) {
window.pinmePanel.submitButton.style.display = 'block';
} else {
window.pinmePanel.submitButton.style.display = 'none';
}
};
window.pinmePanel.submit = function()
{
if (!window.pinmePanel.selectedImages.length) {
return false;
}
var form = document.createElement('form');
form.action = baseUrl + 'index/popup';
form.acceptCharset = 'utf-8';
form.method = 'POST';
form.target = '_blank';
form.innerHTML += '<input type="hidden" name="popup[url]" value="' + window.location.href + '" />';
for (var i = 0; i < window.pinmePanel.selectedImages.length; i++) {
var item = window.pinmePanel.selectedImages[i];
if (!item.isVideo){
form.innerHTML += '<input type="hidden" name="popup[img]['+ i +'][src]" value="' + item.src + '" />';
form.innerHTML += '<input type="hidden" name="popup[img]['+ i +'][alt]" value="' + item.alt.replace(/"/g, '&quot;') + '" />';
}
else {
form.innerHTML += '<input type="hidden" name="popup[img]['+ i +'][type]" value="2" />';
for (prop in item) {
form.innerHTML += '<input type="hidden" name="popup[img]['+ i +']['+ prop +']" value="'+ item[prop] +'" />';
}
}
}
window.pinmePanel.panel.appendChild(form);
form.submit();
window.pinmePanel.close();
};
window.document.onkeydown = function (e)
{
if (!e) e = event;
if (e.keyCode == 27) {
window.pinmePanel.close();
}
};
var css = [];
css.push("div.pinmePanel {font-family: arial; font-size: 12px; color: #000; position: fixed; width: 100%; height: 100%; top: 0; left: 0; z-index: 10000000002; box-sizing: content-box; -moz-box-sizing: content-box; -ms-box-sizing: content-box; -webkit-box-sizing: content-box;}");
css.push("div.pinmePanel div { display: block; }");
css.push("div.pinmePanel div, div.pinmePanel a {box-sizing: content-box; -moz-box-sizing: content-box; -ms-box-sizing: content-box; -webkit-box-sizing: content-box;}");
css.push("div.pinmePanel a, div.pinmePanel a:hover {color: #000;}");
css.push("div.pinmePanel div.pinmeHeader {width: 95%; margin: 5px auto; text-align: center;}");
css.push("div.pinmePanel div.pinmeTitleHeader {font-size:16px; padding-top: 20px; text-align: center;}");
css.push("div.pinmePanel div.pinmeClose {background: #fff; text-align: center; cursor: pointer; margin-bottom: 30px; font-size: 14px; padding-top:12px; height:28px; font-weight: bold; border-bottom: 1px solid #ccc;}");
css.push("div.pinmePanel div.pinmeClose:hover {background: #fafafa; color: #fb5350}");
css.push("div.pinmePanel .pinmeImage {display: inline-block; cursor: pointer; position: relative; width: 120px; background: #ccc; height: 120px; overflow: hidden;margin:5px; border: 1px solid #000;}");
css.push("div.pinmePanel .pinmeIcoVideo {background: url('"+baseNoSchemaStaticUrl+"asset/rele/img/face/ico_video.png') no-repeat; width:26px;height:30px; position:absolute; z-index:2; right:3px;top:3px;}");
css.push("div.pinmePanel .pinmeSelectButton {background: url('"+baseNoSchemaStaticUrl+"asset/rele/img/widget/button_select.png') no-repeat; width:71px;height:25px; position:absolute; z-index:3; left:25px;top:45px; display:none;}");
css.push("div.pinmePanel .pinmeImage.selected .pinmeSelectButton {background: url('"+baseNoSchemaStaticUrl+"asset/rele/img/widget/button_deselect.png') no-repeat;}");
css.push("div.pinmePanel .pinmeImage:hover .pinmeSelectButton {display:block;}");
if (isChrome() || isSafari()) css.push("div.pinmePanel .pinmeImage {display: block; float: left;}");
css.push("div.pinmePanel .pinmeImage.selected {border: 1px solid #fc7573;}");
css.push("div.pinmePanel div.pinmeImageContainer {max-height: 50%; position: relative; background:#fff; overflow: auto; text-align: center; width: 94%; margin: 0px auto; border: 1px solid #ccc; padding: 10px;}");
css.push("div.pinmePanel .pinmeImage img {width: 120px; border: 0px;}");
css.push("div.pinmePanel .pinmeImage div.pinmeInfo {width: 112px; font-size: 11px; padding: 4px; position: absolute; bottom: 0px; left: 0px; color: #fff; text-align: center; background: #000;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);-khtml-opacity: 0.7;opacity: 0.7;}");
css.push("div.pinmePanel .pinmeImage.selected div.pinmeInfo {background: #fc7573;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100);-khtml-opacity: 1;opacity: 1;}");
css.push("div.pinmeBlock {position:fixed;width:100%;height:100%;z-index: 10000000001;background:#fff;top: 0; left: 0;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=90);-khtml-opacity: 0.9;opacity: 0.9;}");
css.push("div.pinmePanel a.pinmeButton {display: none; background: #fc7573; color: #fff; margin: 20px auto 0px; padding: 15px 0px; font-size:16px; text-align: center; width: 200px; bottom: 5%; position: fixed; left: 50%; margin-left: -100px; text-decoration: none; border-radius: 4px;}");
css.push("div.pinmePanel a.pinmeButton:hover {text-decoration: none;}");
//ie quirkmode fix
if (isIE() && document.compatMode != 'CSS1Compat') {
css.push("div.pinmePanel, div.pinmeBlock {position: absolute;}");
css.push("div.pinmePanel div.pinmeClose {height:40px;}");
css.push("div.pinmePanel a.pinmeButton {height: 56px; margin-left:40%;}");
css.push("div.pinmePanel .pinmeImage div.pinmeInfo {width: 122px;}");
}
css = css.join("\n");
window.pinmePanel.style = document.createElement("style");
window.pinmePanel.style.type = "text/css";
window.pinmePanel.style.media = "screen";
if (isIE()) {
window.pinmePanel.style.styleSheet.cssText = css;
document.getElementsByTagName("head")[0].appendChild(window.pinmePanel.style)
} else {
if (navigator.userAgent.lastIndexOf("Safari/") > 0 && parseInt(navigator.userAgent.substr(navigator.userAgent.lastIndexOf("Safari/") + 7, 7)) < 533) {
window.pinmePanel.style.innerText = css;
} else {
window.pinmePanel.style.innerHTML = css;
}
document.body.appendChild(window.pinmePanel.style)
}
window.pinmePanel.block = document.createElement('div');
addClass(window.pinmePanel.block, 'pinmeBlock');
document.body.appendChild(window.pinmePanel.block);
window.pinmePanel.panel = document.createElement('div');
addClass(window.pinmePanel.panel, 'pinmePanel');
document.body.appendChild(window.pinmePanel.panel);
window.pinmePanel.panel.innerHTML += '<div class="pinmeClose" id="' + pinmeUID + '_pinmeClose">Отменить</div>';
window.pinmePanel.panel.innerHTML += '<div class="pinmeHeader"><a href="'+baseUrl+'" title="Pinme.ru" target="_blank"><img src="'+baseNoSchemaStaticUrl+'asset/rele/img/widget/small_logo.png" alt="Pinme.ru" width="91px" height="38px" /></a><div class="pinmeTitleHeader">Выберите картинки:</div></div>';
window.pinmePanel.imageContainer = document.createElement('div');
addClass(window.pinmePanel.imageContainer, 'pinmeImageContainer');
window.pinmePanel.panel.appendChild(window.pinmePanel.imageContainer);
window.pinmePanel.submitButton = document.createElement('a');
window.pinmePanel.submitButton.href = '#';
window.pinmePanel.submitButton.innerHTML = 'Далее &raquo;';
addClass(window.pinmePanel.submitButton, 'pinmeButton');
window.pinmePanel.submitButton.onclick = function()
{
window.pinmePanel.submit();
return false;
};
window.pinmePanel.panel.appendChild(window.pinmePanel.submitButton);
window.document.getElementById(pinmeUID + '_pinmeClose').addEventListener('click', window.pinmePanel.close);
}
var imagesSrc = [];
var videoId = null;
window.pinmePanel.images = [];
window.pinmePanel.selectedImages = [];
var meta = document.getElementsByTagName('meta');
for (var i=0; i<meta.length; i++) {
if (meta[i].name == 'pinme' && meta[i].content == 'nopin') {
alert('К сожалению, этот сайт не позволяет добавлять свои изображения на Pinme');
return false;
}
}
// Youtube (direct)
if ((videoId = /^https?:\/\/(www\.)?youtube\.com\/watch.+v=([a-zA-Z0-9\-_]+)/.exec(window.location.href)) && (videoId=videoId[2]) && !in_array(videoId, imagesSrc)) {
if (!in_array(videoId, imagesSrc)) {
var duration = /T(\d{1,2})M(\d{1,2})/.exec(document.querySelectorAll("meta[itemprop='duration']")[0].content);
duration = parseInt(duration[1]) * 60 + parseInt(duration[2]);
window.pinmePanel.images.push({
isVideo: true,
src: window.location.href,
alt: document.title.replace(/\s+\-\s+YouTube$/, ''),
thumb: 'http://img.youtube.com/vi/' + videoId + '/0.jpg',
videoId: videoId,
provider: 'youtube',
duration: duration
});
imagesSrc.push(videoId);
}
}
// Rutube (direct)
if (videoId = ( /^https?:\/\/(www\.)?rutube\.ru\/video\/([0-9a-z]+)/.exec(window.location.href))) {
if (!document.querySelectorAll("link[rel=image_src]")[0]){
alert('Pinme не может забрать видео с этой страницы. Перейдите на страницу видео, нажав на соответствующую ссылку сразу после названия видео, или нажав F5 на клавиатуре.');
return false;
}
else {
if (document.querySelectorAll("meta[property='og:video']")[0]){
videoUrl = document.querySelectorAll("meta[property='og:video']")[0].content;
videoId = /video.rutube.ru\/(\d+)/.exec(videoUrl)[1];
}
else{
videoId = videoId[2];
}
if (!in_array(videoId, imagesSrc)){
window.pinmePanel.images.push({
isVideo: true,
src: document.querySelectorAll("link[rel=image_src]")[0].href,
alt: document.getElementById('id-title').innerHTML,
thumb: document.querySelectorAll("link[rel=image_src]")[0].href,
videoId: videoId,
provider: 'rutube',
duration: document.querySelectorAll("meta[property='og:video:duration']")[0].content
});
imagesSrc.push(videoId);
}
}
}
if (videoId = ( /^https?:\/\/(www\.)?vimeo\.com\/([0-9a-z]+)/.exec(window.location.href))) {
var src = '';
if (document.querySelectorAll("meta[itemprop=playpageUrl]")[0]){
videoId = /^https?:\/\/(www\.)?vimeo\.com\/([0-9a-z]+)/.exec(document.querySelectorAll("meta[itemprop=playpageUrl]")[0].content);
src = document.querySelectorAll("meta[itemprop=playpageUrl]")[0].content;
videoId = videoId[2];
} else if (document.querySelectorAll('meta[property="og:url"]')[0]){
videoId = /^https?:\/\/(www\.)?vimeo\.com\/([0-9a-z]+)/.exec(document.querySelectorAll('meta[property="og:url"]')[0].content);
src = document.querySelectorAll('meta[property="og:url"]')[0].content;
videoId = videoId[2];
}
if (videoId && !in_array(videoId, imagesSrc)){
window.pinmePanel.images.push({
isVideo: true,
src: src,
alt: document.querySelectorAll('title')[0].innerHTML,
thumb: (document.querySelectorAll('meta[property="og:image"]')[0] ? document.querySelectorAll('meta[property="og:image"]')[0].content : (document.querySelectorAll('meta[name="twitter:image"]')[0] ? document.querySelectorAll('meta[name="twitter:image"]')[0].content : '')),
videoId: videoId,
provider: 'vimeo'
});
imagesSrc.push(videoId);
}
}
// Images
for (var i = 0; i < document.images.length; i++) {
var image = document.images[i];
if (image.width >= 150 && (typeof image.src != 'undefined') && !in_array(image.src, imagesSrc) && image.src.indexOf('data:image') == -1) {
window.pinmePanel.images.push(image);
imagesSrc.push(image.src);
}
}
// Youtube (iframe)
var iframes = document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
if ((videoId = /^https?:\/\/(www\.)?youtube\.com\/(embed|v)\/([a-zA-Z0-9\-_]+)/.exec(iframes[i].src)) && (videoId=videoId[3]) && !in_array(videoId, imagesSrc)) {
window.pinmePanel.images.push({
isVideo: true,
src: iframes[i].src,
alt: 'Видео Youtube',
thumb: 'http://img.youtube.com/vi/'+videoId+'/0.jpg',
videoId: videoId,
provider: 'youtube'
});
imagesSrc.push(videoId);
}
}
// Youtube/Rutube (embed) @todo проверить работает ли это
var embeds = document.getElementsByTagName('embed');
for (var i = 0; i < embeds.length; i++) {
if ((videoId = /^https?:\/\/(www\.)?youtube\.com\/(embed|v)\/([a-zA-Z0-9\-_]+)/.exec(embeds[i].src)) && (videoId=videoId[3]) && !in_array(videoId, imagesSrc)) {
window.pinmePanel.images.push({
isVideo: true,
src: embeds[i].src,
alt: 'Видео Youtube',
thumb: 'http://img.youtube.com/vi/'+videoId+'/0.jpg',
videoId: videoId,
provider: 'youtube'
});
imagesSrc.push(videoId);
} else if ((videoId = /^https?:\/\/(www\.)?video\.rutube\.ru\/([a-z0-9]+)/.exec(embeds[i].src)) && (videoId=videoId[2]) && !in_array(videoId, imagesSrc)) {
window.pinmePanel.images.push({
isVideo: true,
src: embeds[i].src,
alt: 'Видео Rutube',
thumb: 'http://tub.rutube.ru/thumbs/'+videoId.substr(0,2)+'/'+videoId.substr(2,2)+'/'+videoId+'-2.jpg',
videoId: videoId,
provider: 'rutube'
});
imagesSrc.push(videoId);
}
}
if (!window.pinmePanel.images.length) {
var url = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'pinme.ru/pin/source_failed';
url += ('?url=' + encodeURIComponent(document.location.href));
url += ('&tool=' + encodeURIComponent('button'));
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.send();
alert('К сожалению, подходящих фотографий не найдено');
window.pinmePanel.proceed = false;
return false;
}
temphide('embed');
temphide('iframe');
temphide('object');
if (document.compatMode != 'CSS1Compat') document.body.scrollTop = 0;
initPanel();
var imgHtml = '';
window.pinmePanel.images.sort(function(a,b)
{
if (a.isVideo && !b.isVideo) return -1;
if (!a.isVideo && b.isVideo) return 1;
if (a.isVideo && b.isVideo) return 0;
if ((a.width*a.height) >= (b.width*b.height)) return -1;
return 1;
});
for (var i = 0; i < window.pinmePanel.images.length; i++) {
var img = window.pinmePanel.images[i];
if (img.isVideo) {
imgHtml += '<span class="pinmeImage" id="'+ pinmeUID +'_pinmeImage_' + i + '"><img class="pinmeImg" src="' + img.thumb + '" alt="" title="" /><div class="pinmeInfo">' + img.alt + '</div><div class="pinmeIcoVideo"></div><div class="pinmeSelectButton"></div></span>';
} else {
imgHtml += '<span class="pinmeImage" id="'+ pinmeUID +'_pinmeImage_' + i + '"><img class="pinmeImg" src="' + img.src + '" alt="' + img.alt + '" title="' + img.alt + '" /><div class="pinmeInfo">' + img.width + 'x' + img.height + '</div><div class="pinmeSelectButton"></div></span>';
}
}
window.pinmePanel.imageContainer.innerHTML = imgHtml;
for (var i = 0; i < window.pinmePanel.images.length; i++) {
var el = window.document.getElementById(pinmeUID + '_pinmeImage_' + i);
el.imgId = i;
el.addEventListener('click', window.pinmePanel.select);
}
})();