Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var slingpic_uid = '1t5ju2xt';
- ! function() {
- var $, root, uid;
- root = typeof exports !== "undefined" && exports !== null ? exports : this;
- $ = jQuery;
- uid = slingpic_uid;
- $.fn.extend({
- slingPic: function(options) {
- var MAX_SHARE_BTNS, MAX_SMALL_SHARE_BTNS, adReloadCount, cssRules, defaults, log, methods, opt, returnMe, slingPicProviders, social_networks, zIndex, _this = this;
- log = function(msg) {
- if (opt.debug) {
- return typeof console !== "undefined" && console !== null ? console.log(msg) : void 0
- }
- };
- methods = {
- generateShareLink: function(name, bookmark_link, first, last) {
- var li_class, onclick, str;
- li_class = first ? ' class="first-child"' : "";
- li_class = last && li_class === "" ? ' class="last-child"' : li_class;
- switch (name) {
- case "facebook":
- onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=670,height=350'); return false;\" ";
- break;
- case "twitter":
- onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=626,height=252'); return false;\" ";
- break;
- case "tumblr":
- onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=450,height=450'); return false;\" ";
- break;
- case "googleplus":
- onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=450,height=450'); return false;\" ";
- break;
- case "print":
- onclick = " onclick=\"var printme = window.open(this.href,'image'); return false;\" ";
- break;
- default:
- onclick = ""
- }
- str = "<li " + li_class + '>\n <a data-social-network="' + name + '" class="slingpicSocialBtn slingpicShare-' + name + ' external" href="' + bookmark_link + '" target="_blank" ' + onclick + ' rel="nofollow"></a>\n</li>';
- return str
- },
- generateShareLinks: function(linkArray, max) {
- var html;
- html = "";
- $.each(linkArray, function(key, social_network) {
- var bookmark_link, first, last;
- if (key > max - 1) {
- return
- }
- switch (key) {
- case 0:
- first = true;
- break;
- case linkArray.length - 1:
- last = true;
- break;
- case max - 1:
- last = true;
- break;
- default:
- first = last = false
- }
- if (!slingPicProviders[social_network] || !slingPicProviders[social_network][0]) {
- return
- }
- bookmark_link = slingPicProviders[social_network][0].replace("{url}", encodeURIComponent(opt.url) + methods.appendHash(social_network)).replace("{image-url}", encodeURIComponent(opt.imgSrc)).replace("{original-image-url}", opt.imgSrc).replace("{title}", opt.title).replace("{summary}", encodeURIComponent(opt.shareSummary));
- return html += methods.generateShareLink(social_network, bookmark_link, first, last)
- });
- return html
- },
- appendHash: function(social_network) {
- return "%23" + opt.uid + "." + opt.imgHash + "." + social_networks[social_network]
- },
- hashChar: function(str, character, hash) {
- hash = (hash << 5) - hash + str.charCodeAt(character);
- return hash & hash
- },
- createImgHash: function(str) {
- var character, hash, _i, _len;
- if (!str) {
- return ""
- }
- hash = 0;
- if (str.length === 0) {
- return hash
- }
- for (_i = 0, _len = str.length; _i < _len; _i++) {
- character = str[_i];
- hash = methods.hashChar(str, character, hash)
- }
- hash = Math.abs(hash) + "";
- return hash.substring(0, 5)
- },
- loadCss: function() {
- if ($("#slingpicCssInclude").size() === 0) {
- return $("<link id='slingpicCssInclude'>").appendTo("head").attr({
- rel: "stylesheet",
- type: "text/css",
- href: "http://cdn.slingpic.com/css/slingpicv2.css?v=30"
- })
- }
- },
- addIcon: function(icon) {
- if (!opt.iconNotRequired) {
- if (icon === "share") {
- log("add share image into html");
- return ""
- } else if (icon === "close") {
- return ""
- } else if (icon === "tri") {
- return ""
- }
- } else {
- return ""
- }
- },
- adReload: function() {
- var rand, src;
- rand = parseInt(Math.random() * 999999, 10);
- src = false;
- if ($(".slingPic_advert").size() > 0) {
- src = $(".slingPic_advert").attr("src")
- }
- if (!src) {
- return
- }
- src = src.split("?cb=")[0];
- $(".slingPic_advert").attr("src", "" + src + "?cb=" + rand);
- if (adReloadCount < opt.adReloadNumber) {
- adReloadCount++;
- return document.slingpicReloader = setTimeout(methods.adReload, 2e4)
- }
- },
- getContext: function(img, avoid, enc) {
- var value;
- if (!avoid) {
- avoid = 0
- }
- if (avoid !== 1 && $(img).closest(".slingpic").parent().find("caption:first").size() > 0) {
- value = $(img).closest(".slingpic").parent().find("caption:first").text();
- avoid = 1
- } else if (avoid !== 2 && $(img).closest(".slingpic").parent().find(":header:first").size() > 0) {
- value = $(img).closest(".slingpic").parent().find(":header:first").text();
- avoid = 2
- } else if (avoid !== 3 && $(img).closest(".slingpic").parent().siblings(":header:first").size() > 0) {
- value = $(img).closest(".slingpic").parent().siblings(":header:first").text();
- avoid = 3
- } else if (avoid !== 4 && $(img).attr("alt") !== "") {
- value = $(img).attr("alt");
- avoid = 4
- } else {
- value = document.title
- }
- if (enc) {
- return {
- value: encodeURIComponent(value),
- avoid: avoid
- }
- } else {
- return {
- value: value,
- avoid: avoid
- }
- }
- },
- checkConflicts: function(elem) {
- if (elem.closest(".slingpic").size() > 0) {
- return false
- }
- if (elem.closest(".nivoSlider").size() > 0 || elem.closest(".post-gallery").size() > 0 || elem.closest(".carousel:not(.flexslider)").size() > 0) {
- log("conflict");
- return false
- }
- if (elem.parent().is("a") && (elem.siblings().size() > 0 || elem.contents().filter(function() {
- return this.nodeType === 3
- }))) {
- log("image styling");
- opt.allowImageStyling = true
- }
- if (elem.closest(".flexslider").size() > 0) {
- log("ignore width and height");
- opt.ignoreWidthHeight = true
- }
- return true
- },
- setStyle: function(img, rule, important) {
- var output;
- output = "";
- $.each(cssRules[rule], function(k, v) {
- var borderHeight, borderWidth, importantText, paddingHeight, paddingWidth, value, wrappingHeight, wrappingWidth;
- if (k === "position" && img.css(v) === "static") {
- value = "relative"
- } else if (k === "display" && img.css(v) === "inline") {
- value = "inline-block"
- } else if (k === "display" && img.css(v) === "none") {
- return
- } else if (k === "width") {
- paddingWidth = parseInt(img.css("paddingLeft"), 10) + parseInt(img.css("paddingRight"), 10);
- borderWidth = parseInt(img.css("border-left-width"), 10) + parseInt(img.css("border-right-width"), 10);
- wrappingWidth = opt.trueWidth + paddingWidth + borderWidth;
- value = "" + wrappingWidth + "px"
- } else if (k === "height") {
- paddingHeight = parseInt(img.css("paddingTop"), 10) + parseInt(img.css("paddingBottom"), 10);
- borderHeight = parseInt(img.css("border-top-width"), 10) + parseInt(img.css("border-bottom-width"), 10);
- wrappingHeight = opt.trueHeight + paddingHeight + borderHeight;
- value = "" + wrappingHeight + "px"
- } else {
- value = img.css(v)
- }
- importantText = important ? " !important" : "";
- return output += "" + k + ":" + value + importantText + ";"
- });
- return output
- },
- updateUrlWithHash: function() {
- if (opt.urlFriendly) {
- return location.hash = opt.uid
- }
- },
- attemptToScrollToImage: function() {
- if (opt.noScroll) {
- return
- }
- if ("clickback" in opt) {
- return $("img").each(function() {
- if (opt.clickback.imgHash === methods.createImgHash($(this).attr("src"))) {
- $("html, body").animate({
- scrollTop: $(this).offset().top
- }, 1e3);
- return false
- }
- })
- }
- },
- parseHash: function() {
- var hash, hashArray;
- if (location.hash === "") {
- return
- }
- hash = location.hash;
- hashArray = hash.split(".");
- if (hashArray.length !== 3) {
- return
- }
- if (hashArray[0][0] === "#") {
- hashArray[0] = hashArray[0].substring(1)
- }
- return opt.clickback = {
- id: hashArray[0],
- imgHash: hashArray[1],
- socialNetwork: hashArray[2]
- }
- },
- captureReferrer: function() {
- return $.ajax({
- crossDomain: true,
- type: "GET",
- url: "http://cdn.slingpic.com/api/log",
- dataType: "jsonp",
- data: {
- uid: opt.uid,
- source: "SLINGPIC",
- urlOn: document.location.hostname,
- urlFrom: document.referrer,
- clickback: opt.clickback
- },
- success: function(data) {
- return log(data)
- }
- })
- },
- updateShareCount: function(el, data) {
- $(el).find(".slingpicShareCountValue").html(data.total);
- return $(el).find(".slingpicSocialBtnContainer .slingpicSocialBtn").each(function() {
- if ($(this).data("social-network") in data.social_networks) {
- return $(this).html('<div class="slingpicSplitShareCount"><p>' + data.social_networks[$(this).data("social-network")] + "</p></div>")
- }
- })
- },
- incrementShareCount: function(el, data) {
- var newTotal;
- log("incrementShareCount");
- newTotal = parseInt($(el).find(".slingpicShareCountValue").html(), 10) + 1;
- $(el).find(".slingpicShareCountValue").html(newTotal);
- return $(el).find(".slingpicSocialBtnContainer .slingpicSocialBtn").each(function() {
- var newCount;
- if ($(this).data("social-network") === data.social_network) {
- if ($(this).find(".slingpicSplitShareCount").size() > 0) {
- newCount = parseInt($(this).find(".slingpicSplitShareCount:first p:first").html(), 10) + 1;
- return $(this).find(".slingpicSplitShareCount:first p:first").html(newCount)
- } else {
- return $(this).html('<div class="slingpicSplitShareCount"><p>1</p></div>')
- }
- }
- })
- },
- slideInOutShares: function(el) {
- var shareCnt;
- shareCnt = $(el).find(".slingpicShareCount");
- if ($(el).hasClass("right")) {
- shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px");
- return shareCnt.delay(500).animate({
- right: "+=30"
- }, 500).delay(3e3).animate({
- right: "-=30"
- }, 500)
- } else {
- shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px");
- return shareCnt.delay(500).animate({
- left: "+=30"
- }, 500).delay(3e3).animate({
- left: "-=30"
- }, 500)
- }
- },
- getShareCounts: function() {
- var imgHashes;
- imgHashes = [];
- $(".slingpic").each(function() {
- return imgHashes.push($(this).data("img-hash"))
- });
- if (imgHashes.length === 0) {
- return
- }
- return $.ajax({
- crossDomain: true,
- type: "GET",
- url: "http://cdn.slingpic.com/api/count/get",
- dataType: "jsonp",
- data: {
- hostname: document.location.hostname,
- imgHashes: imgHashes
- },
- jsonpCallback: "getShareCountsResponse"
- })
- },
- supportsBefore: function() {
- var body, div, error, ret, style;
- log("checking if the browser supports the :before psuedo class");
- body = document.body;
- error = false;
- if ( !! document.querySelector) {
- try {
- document.querySelector(":before");
- ret = true
- } catch (_error) {
- error = _error;
- log("EXCEPTION :before psuedo class not supported");
- ret = false
- } finally {
- return ret
- }
- }
- body.appendChild(div = document.createElement("div"), div.innerHTML = ["­<style>", ":before", "{}</style>"].join(""), div);
- style = div.children[0];
- if (style.styleSheet && !style.styleSheet.rules.length) {
- log("(IE8) :before psuedo class not supported");
- return ret = false
- } else {
- ret = !/unknown/.test(style.styleSheet.rules[0].selectorText.toLowerCase());
- body.removeChild(div);
- if (!ret) {
- log(":before psuedo class not supported")
- } else {
- log(":before psuedo class supported")
- }
- return ret
- }
- }
- };
- cssRules = {
- general: {
- bottom: "bottom",
- display: "display",
- "float": "float",
- left: "left",
- "margin-top": "marginTop",
- "margin-right": "marginRight",
- "margin-bottom": "marginBottom",
- "margin-left": "marginLeft",
- "max-width": "maxWidth",
- position: "position",
- right: "right",
- top: "top"
- },
- extra: {
- background: "background",
- border: "border",
- "border-radius": "borderRadius",
- "box-shadow": "boxShadow",
- "padding-bottom": "paddingBottom",
- "padding-left": "paddingLeft",
- "padding-right": "paddingRight",
- "padding-top": "paddingTop"
- },
- heightWidth: {
- height: "height",
- width: "width"
- }
- };
- adReloadCount = 0;
- defaults = {
- adPos: "bottomRight",
- adPosManual: {
- bottom: 0,
- left: 0,
- right: 0,
- top: 0
- },
- adReload: false,
- adReloadNumber: 2,
- advertHeight: 200,
- advertSrc: false,
- advertWidth: 200,
- alignShare: "right",
- allowImageStyling: false,
- autoShowShare: false,
- context: false,
- copyright: false,
- debug: false,
- domain: location.host,
- dontShow: "",
- elemPadding: "",
- iconNotRequired: false,
- ignoreWidthHeight: false,
- manualDimensions: {
- height: 0,
- width: 0
- },
- minShareHeight: 100,
- minShareWidth: 100,
- minAdHeight: 200,
- minAdWidth: 200,
- noScroll: false,
- offsets: {
- top: 0,
- right: 0,
- bottom: 0,
- left: 0
- },
- parentElem: "",
- persistantAd: true,
- primary_links: ["facebook", "twitter", "pinterest", "email"],
- secondary_links: ["delicious", "linkedin", "reddit", "friendfeed", "digg", "tumblr", "myspace", "print"],
- shareSummary: "",
- show: "",
- showAd: false,
- showAdClose: true,
- showShare: true,
- theme: "",
- title: "",
- uid: uid,
- url: location.href,
- urlFriendly: false
- };
- slingPicProviders = {
- facebook: ["http://www.facebook.com/share.php?s=100&p[title]={title}&p[summary]={summary}&p[url]={url}&&p[images][0]={image-url}", "Share this on Facebook"],
- twitter: ['http://twitter.com/share?url={url}&text={summary}&count=horiztonal"', "Tweet This!"],
- tumblr: ["http://www.tumblr.com/share/photo?source={image-url}&caption={summary}&click_thru={url}", "Share this on Tumblr"],
- email: ["mailto:?subject={summary}&body={image-url} from {url}", "Email this to a friend?"],
- googleplus: ["https://plus.google.com/share?url={url}"],
- print: ["{original-image-url}", "Print"],
- linkedin: ["http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title} {image-url}&summary={summary}&source={url}", "Share this on LinkedIn"],
- reddit: ["http://reddit.com/submit?url={url}&title={summary} {image-url} {title}", "Share this on Reddit"],
- stumbleupon: ["http://www.stumbleupon.com/submit?url={url}&title={summary} {image-url}", "Stumble upon something good? Share it on StumbleUpon"],
- delicious: ["http://delicious.com/post?url={url}&title={summary} {image-url}", "Share this on del.icio.us"],
- pinterest: ["http://pinterest.com/pin/create/button/?url={url}&media={image-url}&description={summary}", "Pin it"],
- digg: ["http://digg.com/submit?phase=2&url={url}&title={title}&bodytext={summary}", "Digg this!"],
- myspace: ["http://www.myspace.com/Modules/PostTo/Pages/?u={url}&t={summary}&c={image-url}&l={image-url}", "Post this to MySpace"],
- blogger: ["http://www.blogger.com/blog_this.pyra?t&u={url}&n={title}", "Blog this on Blogger"],
- friendfeed: ["http://www.friendfeed.com/share?title={summary} {image-url}&link={url}&image0_url={image-url}", "Share this on FriendFeed"],
- designfloat: ["http://www.designfloat.com/submit.php?url={url}&link={title}", "Submit this to DesignFloat"],
- orkut: ["http://promote.orkut.com/preview?nt=orkut.com&&tt={url};du={title}", "Promote this on Orkut"],
- technorati: ["http://technorati.com/faves?add={url}", "Share this on Technorati"]
- };
- social_networks = {
- facebook: "fa",
- twitter: "tw",
- tumblr: "tu",
- email: "em",
- print: "pr",
- googleplus: "gp",
- linkedin: "li",
- reddit: "re",
- stumbleupon: "su",
- posterous: "po",
- delicious: "de",
- pinterest: "pi",
- digg: "di",
- gmail: "gm",
- netvibes: "nv",
- myspace: "ms",
- blogger: "bl",
- friendfeed: "ff",
- yahoomail: "ym",
- designfloat: "df",
- evernote: "en",
- orkut: "or",
- virb: "vi",
- technorati: "te"
- };
- opt = $.extend(defaults, options);
- zIndex = 1;
- MAX_SHARE_BTNS = 4;
- MAX_SMALL_SHARE_BTNS = 8;
- methods.parseHash();
- methods.attemptToScrollToImage();
- methods.updateUrlWithHash();
- methods.captureReferrer();
- opt.iconNotRequired = methods.supportsBefore();
- log("looping through images");
- returnMe = this.each(function(index, element) {
- var $grandparentPosition, $grandparentZIndex, $img, $imgSrc, adHtml, advert, baseUrl, bottomOffset, bottomOffsetValue, cb, closeHtml, copyrightText, countBaseLeftRightAttr, countBaseLeftRightValue, dimensionsParent, elem, elementHeight, elementWidth, html, leftRightOffset, moreLink, pixelHtml, primaryLinksLIs, regexObj, regexObjResult, result, rightOffset, rightOffsetValue, secondaryLinks, secondayLinksLIs, share, shareButtonTop, shareWidgetTop, wrappingDiv, wrappingDivStyle, wrappingDivZIndex;
- log("image " + index);
- elem = $(element);
- share = false;
- advert = false;
- elementWidth = 0;
- elementHeight = 0;
- dimensionsParent = false;
- if (!methods.checkConflicts(elem)) {
- return
- }
- log("passed conflicts");
- if (opt.show !== "" && elem.hasClass(opt.show) || opt.show === "" && opt.dontShow === "" || opt.show === "" && opt.dontShow !== "" && !elem.hasClass(opt.dontShow)) {
- log("show");
- if (elem.css("width") === "100%") {
- dimensionsParent = elem.parent();
- while (dimensionsParent.css("width") === "100%") {
- dimensionsParent = dimensionsParent.parent()
- }
- elementWidth = dimensionsParent.width()
- } else {
- if (elem[0]) {
- elementWidth = elem.width() < elem[0].width ? elem[0].width : elem.width()
- } else {
- elementWidth = elem.width()
- }
- }
- if (elem.css("height") === "100%" || elem.css("height") === "0px" && elementWidth > 0) {
- dimensionsParent = elem.parent();
- while (dimensionsParent.css("height") === "100%" || dimensionsParent.css("height") === "0px") {
- dimensionsParent = dimensionsParent.parent()
- }
- elementHeight = dimensionsParent.height()
- } else {
- if (elem[0]) {
- elementHeight = elem.height() < elem[0].height ? elem[0].height : elem.height()
- } else {
- elementHeight = elem.height()
- }
- }
- if (elementWidth > opt.minShareWidth && elementHeight > opt.minShareHeight && opt.showShare) {
- share = true
- }
- if (elementWidth > opt.minAdWidth && elementHeight > opt.minAdHeight && opt.showAd && opt.advertSrc) {
- advert = true
- }
- opt.trueHeight = opt.manualDimensions.height > 0 ? opt.manualDimensions.height : elementHeight;
- opt.trueWidth = opt.manualDimensions.width > 0 ? opt.manualDimensions.width : elementWidth;
- if (!share && !advert) {
- return
- }
- } else if (opt.dontShow !== "" && elem.hasClass(opt.dontShow)) {
- log("don't show: return");
- return
- } else if (!elem.hasClass(opt.show)) {
- return
- }
- if (opt.parentElem !== "") {
- $img = $(opt.parentElem)
- } else {
- $img = $(element)
- }
- $imgSrc = $img.attr("src");
- copyrightText = $img.data("copyright");
- $grandparentPosition = elem.parent().css("position");
- $grandparentZIndex = elem.parent().css("zIndex");
- opt.originalImgSrc = $img.attr("src");
- methods.checkConflicts($img);
- if ($imgSrc.indexOf("http://") === -1 && $imgSrc.indexOf("https://") === -1) {
- if ($imgSrc.indexOf("/") === 0) {
- $imgSrc = "http://" + opt.domain + $imgSrc
- } else {
- regexObjResult = null;
- baseUrl = opt.url;
- regexObj = /(\/\w+\.\w+)$/i;
- regexObjResult = regexObj.exec(opt.url);
- if (regexObjResult) {
- baseUrl = opt.url.substr(0, regexObjResult.index)
- }
- $imgSrc = "" + baseUrl + "/" + $imgSrc;
- log($imgSrc)
- }
- }
- opt.imgSrc = $imgSrc;
- wrappingDivStyle = methods.setStyle($img, "general");
- wrappingDivStyle += methods.setStyle($img, "heightWidth");
- wrappingDivZIndex = zIndex++;
- opt.imgHash = methods.createImgHash(opt.originalImgSrc);
- wrappingDiv = '<div class="slingpic ' + opt.theme + " " + opt.alignShare + '" data-img-hash="' + opt.imgHash + '" style="' + wrappingDivStyle + '">';
- if (opt.parentElem !== "") {
- elem.closest(opt.parentElem).wrap(wrappingDiv)
- } else if (elem.parent().is("a")) {
- elem.parent().wrap(wrappingDiv)
- } else {
- elem.wrap(wrappingDiv)
- }
- if (opt.context) {
- result = methods.getContext($img);
- opt.shareSummary = result.value;
- if (opt.copyright && copyrightText) {
- opt.shareSummary += " \n© " + copyrightText + "\n"
- }
- result = methods.getContext($img, result.avoid, true);
- opt.title = result.value
- } else {
- opt.shareSummary = "" + document.title + " (shared via SlingPic)";
- if (opt.copyright && copyrightText) {
- opt.shareSummary += " \n© " + copyrightText + "\n"
- }
- opt.title = encodeURIComponent(document.title)
- }
- opt.offsets = {
- top: parseInt($img.css("paddingTop"), 10) + parseInt($img.css("border-top-width"), 10),
- right: parseInt($img.css("paddingRight"), 10) + parseInt($img.css("border-right-width"), 10),
- bottom: parseInt($img.css("paddingBottom"), 10) + parseInt($img.css("border-bottom-width"), 10),
- left: parseInt($img.css("paddingLeft"), 10) + parseInt($img.css("border-left-width"), 10)
- };
- if (opt.showShare) {
- if (opt.alignShare === "left") {
- leftRightOffset = "left: " + (opt.offsets.left + 5) + "px !important;";
- countBaseLeftRightValue = opt.offsets.left + 33;
- countBaseLeftRightAttr = "left: " + countBaseLeftRightValue + "px;"
- } else if (opt.alignShare === "right") {
- leftRightOffset = "right: " + (opt.offsets.right + 5) + "px !important;";
- countBaseLeftRightValue = opt.offsets.right + 33;
- countBaseLeftRightAttr = "right: " + countBaseLeftRightValue + "px;"
- }
- shareButtonTop = "top: " + (opt.offsets.top + 5) + "px !important;";
- shareWidgetTop = "top: " + (opt.offsets.top + 40) + "px !important;";
- primaryLinksLIs = methods.generateShareLinks(opt.primary_links, MAX_SHARE_BTNS);
- if (opt.secondary_links.length > 0) {
- secondayLinksLIs = methods.generateShareLinks(opt.secondary_links, MAX_SMALL_SHARE_BTNS);
- secondaryLinks = '<ul class="slingpicMoreSocialBtnContainer" style="display: none !important">\n ' + secondayLinksLIs + "\n</ul>";
- moreLink = '<a href="#" class="slingpicWidgetMoreLessBtn">more</a>'
- } else {
- secondaryLinks = "";
- moreLink = ""
- }
- log("html time");
- html = '<div class="slingpicShareCount" data-base-state="' + countBaseLeftRightValue + '" style="display: none !important;' + countBaseLeftRightAttr + shareButtonTop + '">\n <span class="slingpicShareCountValue">0</span>\n <img src="http://go.affec.tv/i/4eef53b4d52bc56cf4000063" width="1" height="1" alt="">\n <img src="http://go.affec.tv/map/sp/' + opt.uid + '" width="1" height="1" alt="">\n</div>\n<div class="slingpicShareBtn" style="display: none !important;' + leftRightOffset + shareButtonTop + '">' + methods.addIcon("share") + '</div>\n<div class="slingpicWidgetContainer" style="display: none !important;' + leftRightOffset + shareWidgetTop + '">\n <div class="slingpicArrow">' + methods.addIcon("tri") + '</div>\n <div class="slingpicHeader"><a class="slingpicWidgetClose">' + methods.addIcon("close") + '</a>Share this image</div>\n <ul class="slingpicSocialBtnContainer">\n ' + primaryLinksLIs + "\n </ul>\n " + secondaryLinks + '\n <div class="slingpicFooter">\n ' + moreLink + '\n <a class="slingpicWidgetSlingpicLink" href="http://slingpic.com" target="_blank">Slingpic</a>\n <span class="slingpicWidgetSlingpicText">Powered by </span>\n </div>\n</div>'
- }
- if (opt.showAd) {
- pixelHtml = !opt.showShare ? '<img src="http://go.affec.tv/map/sp/' + opt.uid + '" width="1" height="1"><img src="http://go.affec.tv/i/4eef53b4d52bc56cf4000063" width="1" height="1">' : "";
- cb = parseInt(Math.random() * 999999);
- closeHtml = opt.showAdClose === true ? '<div class="slingpicAdClose" onclick="jQuery(this).closest(\'.slingpicAdSpot\').remove(); return false;"></div>' : "";
- bottomOffsetValue = opt.offsets.bottom + opt.adPosManual.bottom;
- rightOffsetValue = opt.offsets.right + opt.adPosManual.right;
- bottomOffset = "bottom: " + bottomOffsetValue + "px !important;";
- rightOffset = "right: " + rightOffsetValue + "px !important;";
- if (opt.persistantAd) {
- adHtml = '<div class="slingpicAdSpot slingpic-' + opt.adPos + '" style="display: block !important; height: ' + opt.advertHeight + "px; width: " + opt.advertWidth + "px; " + rightOffset + " " + bottomOffset + '">\n ' + pixelHtml + '\n <iframe class="slingPic_advert" height="' + opt.advertHeight + '" width="' + opt.advertWidth + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" wmode="transparent" onload="this.style.visibility = \'visible\';" src="' + opt.advertSrc + "?cb=" + cb + '"></iframe>\n ' + closeHtml + "\n</div>"
- } else {
- elem.closest(".slingpic").one("mouseover", opt, function(event) {
- pixelHtml = !event.data.showShare ? '<img src="http://go.affec.tv/map/sp/' + opt.uid + '" width="1" height="1"><img src="http://go.affec.tv/i/4eef53b4d52bc56cf4000063" width="1" height="1">' : "";
- cb = parseInt(Math.random() * 999999);
- closeHtml = event.data.showAdClose === true ? '<div class="slingpicAdClose" onclick="jQuery(this).closest(\'.slingpicAdSpot\').remove(); return false;"></div>' : "";
- adHtml = '<div class="slingpicAdSpot slingpic-' + event.data.adPos + '" style="height:' + event.data.advertHeight + "px; width:" + event.data.advertWidth + "px; " + rightOffset + " " + bottomOffset + '">\n ' + pixelHtml + '\n <iframe class="slingPic_advert" height="' + event.data.advertHeight + '" width="' + event.data.advertWidth + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" wmode="transparent" onload="this.style.visibility = \'visible\';" src="' + event.data.advertSrc + "?cb=" + cb + '"></iframe>\n ' + closeHtml + "\n</div>";
- return $(this).append(adHtml)
- })
- }
- }
- if (adHtml && html) {
- html += adHtml
- } else if (adHtml) {
- html = adHtml
- }
- $(html).appendTo(elem.closest(".slingpic"));
- $img.addClass("slingpic_reset");
- if (opt.showShare) {
- elem.closest(".slingpic").find(".slingpicSocialBtn").click(function() {
- var data;
- data = {
- hn: document.location.hostname,
- imgHash: $(this).closest(".slingpic").data("img-hash"),
- sn: $(this).data("social-network"),
- uid: uid
- };
- return $.ajax({
- crossDomain: true,
- type: "GET",
- url: "http://cdn.slingpic.com/api/count/add",
- dataType: "jsonp",
- data: data,
- success: function(data) {
- if (data.success) {
- return log("success")
- } else {
- return log("failed")
- }
- }
- })
- });
- elem.closest(".slingpic").find(".slingpicWidgetMoreLessBtn,.slingpicShareBtn,.slingpicWidgetClose").click(function(event) {
- var moreBtns, newPos, shareCnt, widget;
- event.preventDefault();
- if ($(this).hasClass("slingpicWidgetMoreLessBtn")) {
- moreBtns = $(this).parent().siblings(".slingpicMoreSocialBtnContainer");
- if (moreBtns.css("display") === "none") {
- $(this).text("less");
- return moreBtns.attr("style", moreBtns.attr("style").replace("none", "block"))
- } else {
- $(this).text("more");
- return moreBtns.attr("style", moreBtns.attr("style").replace("block", "none"))
- }
- } else if ($(this).hasClass("slingpicShareBtn")) {
- widget = $(this).closest(".slingpic").find(".slingpicWidgetContainer");
- if (widget.css("display") === "none") {
- widget.attr("style", widget.attr("style").replace("none", "block"));
- shareCnt = $(this).prev(".slingpicShareCount");
- shareCnt.clearQueue();
- newPos = shareCnt.data("base-state") + 30;
- if ($(this).closest(".slingpic").hasClass("right")) {
- return shareCnt.animate({
- right: "" + newPos + "px"
- }, 500)
- } else {
- return shareCnt.animate({
- left: "" + newPos + "px"
- }, 500)
- }
- } else {
- return widget.attr("style", widget.attr("style").replace("block", "none"))
- }
- } else if ($(this).hasClass("slingpicWidgetClose")) {
- widget = $(this).closest(".slingpicWidgetContainer");
- if (widget.css("display") === "none") {
- return widget.attr("style", widget.attr("style").replace("none", "block"))
- } else {
- return widget.attr("style", widget.attr("style").replace("block", "none"))
- }
- }
- });
- elem.closest(".slingpic").mouseenter({
- autoShowShare: opt.autoShowShare,
- alignShare: opt.alignShare
- }, function(event) {
- var shareBtn, shareCnt, widget;
- shareCnt = $(this).find(".slingpicShareCount");
- shareBtn = $(this).find(".slingpicShareBtn");
- if (shareBtn.size() > 0) {
- shareBtn.attr("style", shareBtn.attr("style").replace("none", "block"))
- }
- if (shareCnt.size() > 0) {
- shareCnt.attr("style", shareCnt.attr("style").replace("none", "block"));
- if (event.data.alignShare === "right") {
- log("it's aligned to the right");
- shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px");
- shareCnt.delay(500).animate({
- right: "+=30"
- }, 500).delay(3e3).animate({
- right: "-=30"
- }, 500)
- } else {
- shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px");
- shareCnt.delay(500).animate({
- left: "+=30"
- }, 500).delay(3e3).animate({
- left: "-=30"
- }, 500)
- }
- }
- if (event.data.autoShowShare) {
- widget = $(this).find(".slingpicWidgetContainer");
- if (widget.size() > 0) {
- return widget.attr("style", widget.attr("style").replace("none", "block"))
- }
- }
- })
- }
- if (opt.showAd) {
- if ($.isFunction($(document).delegate)) {
- $(document).delegate('div[id^="scr_"]', "mouseenter", function() {
- if (document.slingpicReloader) {
- return window.clearTimeout(document.slingpicReloader)
- }
- })
- } else {
- $(document).live('div[id^="scr_"]', "mouseenter", function() {
- if (document.slingpicReloader) {
- return window.clearTimeout(document.slingpicReloader)
- }
- })
- }
- }
- if (!opt.persistantAd) {
- elem.closest(".slingpic").mouseenter(function() {
- return $(this).find(".slingpicAdSpot").attr("style", "display: block !important")
- });
- elem.closest(".slingpic").mouseleave(function() {
- return $(this).find(".slingpicAdSpot").attr("style", $(this).find(".slingpicAdSpot").attr("style").replace("block", "none"))
- })
- }
- if ($.isFunction($(document).delegate)) {
- elem.closest(".slingpic").mouseleave({
- alignShare: opt.alignShare
- }, function(event) {
- var shareBtn, shareCnt;
- if ($(this).find(".slingpicWidgetContainer").size() > 0) {
- $(this).find(".slingpicWidgetContainer").attr("style", $(this).find(".slingpicWidgetContainer").attr("style").replace("block", "none"))
- }
- if ($(this).find(".slingpicWidgetMoreLessBtn").size() > 0) {
- $(this).find(".slingpicWidgetMoreLessBtn").text("more")
- }
- if ($(this).find(".slingpicMoreSocialBtnContainer").size() > 0) {
- $(this).find(".slingpicMoreSocialBtnContainer").attr("style", $(this).find(".slingpicMoreSocialBtnContainer").attr("style").replace("block", "none"))
- }
- shareBtn = $(this).find(".slingpicShareBtn");
- if (shareBtn.size() > 0) {
- shareBtn.attr("style", shareBtn.attr("style").replace("block", "none"))
- }
- shareCnt = $(this).find(".slingpicShareCount");
- if (shareCnt.size() > 0) {
- shareCnt.attr("style", shareCnt.attr("style").replace("block", "none"));
- if (event.data.alignShare === "right") {
- return shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px")
- } else {
- return shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px")
- }
- }
- })
- }
- return methods.loadCss()
- });
- methods.getShareCounts();
- document.slingpicReloader = opt.showAd && opt.advertSrc && opt.adReload ? setTimeout(methods.adReload, 2e4) : false;
- root.getShareCountsResponse = function(data) {
- var hashes;
- hashes = {};
- console.log(data);
- $.each(data.counts, function(k, v) {
- if (v.img_hash in hashes) {
- hashes[v.img_hash]["social_networks"][v.social_network] = v.count;
- return hashes[v.img_hash]["total"] += v.count
- } else {
- hashes[v.img_hash] = {
- total: v.count,
- social_networks: {}
- };
- return hashes[v.img_hash]["social_networks"][v.social_network] = v.count
- }
- });
- return $(".slingpic").each(function() {
- if (hashes.hasOwnProperty($(this).data("img-hash"))) {
- return methods.updateShareCount($(this), hashes[$(this).data("img-hash")])
- }
- })
- };
- root.addShareCountResponse = function(data) {
- log("addShareCountResponse", data);
- return $(".slingpic").each(function() {
- log(parseInt(data.img_hash, 10), parseInt($(this).data("img-hash"), 10));
- if (parseInt(data.img_hash, 10) === parseInt($(this).data("img-hash"), 10)) {
- return methods.incrementShareCount($(this), data)
- }
- })
- };
- return returnMe
- }
- })
- }.call(this);
Add Comment
Please, Sign In to add comment