//// ==========================================================================
//
// Share
// Displays simple form for sharing current url
//
// ==========================================================================
(function(document, $) {
"use strict";
$.extend(true, $.fancybox.defaults, {
btnTpl: {
share:
'"
},
share: {
url: function(instance, item) {
return (
(!instance.currentHash && !(item.type === "inline" || item.type === "html") ? item.origSrc || item.src : false) || window.location
);
},
tpl:
'
"
}
});
function escapeHtml(string) {
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"/": "/",
"`": "`",
"=": "="
};
return String(string).replace(/[&<>"'`=\/]/g, function(s) {
return entityMap[s];
});
}
$(document).on("click", "[data-fancybox-share]", function() {
var instance = $.fancybox.getInstance(),
current = instance.current || null,
url,
tpl;
if (!current) {
return;
}
if ($.type(current.opts.share.url) === "function") {
url = current.opts.share.url.apply(current, [instance, current]);
}
tpl = current.opts.share.tpl
.replace(/\{\{media\}\}/g, current.type === "image" ? encodeURIComponent(current.src) : "")
.replace(/\{\{url\}\}/g, encodeURIComponent(url))
.replace(/\{\{url_raw\}\}/g, escapeHtml(url))
.replace(/\{\{descr\}\}/g, instance.$caption ? encodeURIComponent(instance.$caption.text()) : "");
$.fancybox.open({
src: instance.translate(instance, tpl),
type: "html",
opts: {
animationEffect: false,
afterLoad: function(shareInstance, shareCurrent) {
// Close self if parent instance is closing
instance.$refs.container.one("beforeClose.fb", function() {
shareInstance.close(null, 0);
});
// Opening links in a popup window
shareCurrent.$content.find(".fancybox-share__links a").click(function() {
window.open(this.href, "Share", "width=550, height=450");
return false;
});
}
}
});
});
})(document, window.jQuery || jQuery);