jan_dembowski

slingpic.plugin.js

Dec 10th, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var slingpic_uid = '1t5ju2xt';
  2. ! function() {
  3.     var $, root, uid;
  4.     root = typeof exports !== "undefined" && exports !== null ? exports : this;
  5.     $ = jQuery;
  6.     uid = slingpic_uid;
  7.     $.fn.extend({
  8.         slingPic: function(options) {
  9.             var MAX_SHARE_BTNS, MAX_SMALL_SHARE_BTNS, adReloadCount, cssRules, defaults, log, methods, opt, returnMe, slingPicProviders, social_networks, zIndex, _this = this;
  10.             log = function(msg) {
  11.                 if (opt.debug) {
  12.                     return typeof console !== "undefined" && console !== null ? console.log(msg) : void 0
  13.                 }
  14.             };
  15.             methods = {
  16.                 generateShareLink: function(name, bookmark_link, first, last) {
  17.                     var li_class, onclick, str;
  18.                     li_class = first ? ' class="first-child"' : "";
  19.                     li_class = last && li_class === "" ? ' class="last-child"' : li_class;
  20.                     switch (name) {
  21.                         case "facebook":
  22.                             onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=670,height=350'); return false;\" ";
  23.                             break;
  24.                         case "twitter":
  25.                             onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=626,height=252'); return false;\" ";
  26.                             break;
  27.                         case "tumblr":
  28.                             onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=450,height=450'); return false;\" ";
  29.                             break;
  30.                         case "googleplus":
  31.                             onclick = " onclick=\"window.open(this.href,'sharer','toolbar=0,status=0,width=450,height=450'); return false;\" ";
  32.                             break;
  33.                         case "print":
  34.                             onclick = " onclick=\"var printme = window.open(this.href,'image'); return false;\" ";
  35.                             break;
  36.                         default:
  37.                             onclick = ""
  38.                     }
  39.                     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>';
  40.                     return str
  41.                 },
  42.                 generateShareLinks: function(linkArray, max) {
  43.                     var html;
  44.                     html = "";
  45.                     $.each(linkArray, function(key, social_network) {
  46.                         var bookmark_link, first, last;
  47.                         if (key > max - 1) {
  48.                             return
  49.                         }
  50.                         switch (key) {
  51.                             case 0:
  52.                                 first = true;
  53.                                 break;
  54.                             case linkArray.length - 1:
  55.                                 last = true;
  56.                                 break;
  57.                             case max - 1:
  58.                                 last = true;
  59.                                 break;
  60.                             default:
  61.                                 first = last = false
  62.                         }
  63.                         if (!slingPicProviders[social_network] || !slingPicProviders[social_network][0]) {
  64.                             return
  65.                         }
  66.                         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));
  67.                         return html += methods.generateShareLink(social_network, bookmark_link, first, last)
  68.                     });
  69.                     return html
  70.                 },
  71.                 appendHash: function(social_network) {
  72.                     return "%23" + opt.uid + "." + opt.imgHash + "." + social_networks[social_network]
  73.                 },
  74.                 hashChar: function(str, character, hash) {
  75.                     hash = (hash << 5) - hash + str.charCodeAt(character);
  76.                     return hash & hash
  77.                 },
  78.                 createImgHash: function(str) {
  79.                     var character, hash, _i, _len;
  80.                     if (!str) {
  81.                         return ""
  82.                     }
  83.                     hash = 0;
  84.                     if (str.length === 0) {
  85.                         return hash
  86.                     }
  87.                     for (_i = 0, _len = str.length; _i < _len; _i++) {
  88.                         character = str[_i];
  89.                         hash = methods.hashChar(str, character, hash)
  90.                     }
  91.                     hash = Math.abs(hash) + "";
  92.                     return hash.substring(0, 5)
  93.                 },
  94.                 loadCss: function() {
  95.                     if ($("#slingpicCssInclude").size() === 0) {
  96.                         return $("<link id='slingpicCssInclude'>").appendTo("head").attr({
  97.                             rel: "stylesheet",
  98.                             type: "text/css",
  99.                             href: "http://cdn.slingpic.com/css/slingpicv2.css?v=30"
  100.                         })
  101.                     }
  102.                 },
  103.                 addIcon: function(icon) {
  104.                     if (!opt.iconNotRequired) {
  105.                         if (icon === "share") {
  106.                             log("add share image into html");
  107.                             return "&#xe007;"
  108.                         } else if (icon === "close") {
  109.                             return "&#xe008;"
  110.                         } else if (icon === "tri") {
  111.                             return "&#xe000;"
  112.                         }
  113.                     } else {
  114.                         return ""
  115.                     }
  116.                 },
  117.                 adReload: function() {
  118.                     var rand, src;
  119.                     rand = parseInt(Math.random() * 999999, 10);
  120.                     src = false;
  121.                     if ($(".slingPic_advert").size() > 0) {
  122.                         src = $(".slingPic_advert").attr("src")
  123.                     }
  124.                     if (!src) {
  125.                         return
  126.                     }
  127.                     src = src.split("?cb=")[0];
  128.                     $(".slingPic_advert").attr("src", "" + src + "?cb=" + rand);
  129.                     if (adReloadCount < opt.adReloadNumber) {
  130.                         adReloadCount++;
  131.                         return document.slingpicReloader = setTimeout(methods.adReload, 2e4)
  132.                     }
  133.                 },
  134.                 getContext: function(img, avoid, enc) {
  135.                     var value;
  136.                     if (!avoid) {
  137.                         avoid = 0
  138.                     }
  139.                     if (avoid !== 1 && $(img).closest(".slingpic").parent().find("caption:first").size() > 0) {
  140.                         value = $(img).closest(".slingpic").parent().find("caption:first").text();
  141.                         avoid = 1
  142.                     } else if (avoid !== 2 && $(img).closest(".slingpic").parent().find(":header:first").size() > 0) {
  143.                         value = $(img).closest(".slingpic").parent().find(":header:first").text();
  144.                         avoid = 2
  145.                     } else if (avoid !== 3 && $(img).closest(".slingpic").parent().siblings(":header:first").size() > 0) {
  146.                         value = $(img).closest(".slingpic").parent().siblings(":header:first").text();
  147.                         avoid = 3
  148.                     } else if (avoid !== 4 && $(img).attr("alt") !== "") {
  149.                         value = $(img).attr("alt");
  150.                         avoid = 4
  151.                     } else {
  152.                         value = document.title
  153.                     }
  154.                     if (enc) {
  155.                         return {
  156.                             value: encodeURIComponent(value),
  157.                             avoid: avoid
  158.                         }
  159.                     } else {
  160.                         return {
  161.                             value: value,
  162.                             avoid: avoid
  163.                         }
  164.                     }
  165.                 },
  166.                 checkConflicts: function(elem) {
  167.                     if (elem.closest(".slingpic").size() > 0) {
  168.                         return false
  169.                     }
  170.                     if (elem.closest(".nivoSlider").size() > 0 || elem.closest(".post-gallery").size() > 0 || elem.closest(".carousel:not(.flexslider)").size() > 0) {
  171.                         log("conflict");
  172.                         return false
  173.                     }
  174.                     if (elem.parent().is("a") && (elem.siblings().size() > 0 || elem.contents().filter(function() {
  175.                         return this.nodeType === 3
  176.                     }))) {
  177.                         log("image styling");
  178.                         opt.allowImageStyling = true
  179.                     }
  180.                     if (elem.closest(".flexslider").size() > 0) {
  181.                         log("ignore width and height");
  182.                         opt.ignoreWidthHeight = true
  183.                     }
  184.                     return true
  185.                 },
  186.                 setStyle: function(img, rule, important) {
  187.                     var output;
  188.                     output = "";
  189.                     $.each(cssRules[rule], function(k, v) {
  190.                         var borderHeight, borderWidth, importantText, paddingHeight, paddingWidth, value, wrappingHeight, wrappingWidth;
  191.                         if (k === "position" && img.css(v) === "static") {
  192.                             value = "relative"
  193.                         } else if (k === "display" && img.css(v) === "inline") {
  194.                             value = "inline-block"
  195.                         } else if (k === "display" && img.css(v) === "none") {
  196.                             return
  197.                         } else if (k === "width") {
  198.                             paddingWidth = parseInt(img.css("paddingLeft"), 10) + parseInt(img.css("paddingRight"), 10);
  199.                             borderWidth = parseInt(img.css("border-left-width"), 10) + parseInt(img.css("border-right-width"), 10);
  200.                             wrappingWidth = opt.trueWidth + paddingWidth + borderWidth;
  201.                             value = "" + wrappingWidth + "px"
  202.                         } else if (k === "height") {
  203.                             paddingHeight = parseInt(img.css("paddingTop"), 10) + parseInt(img.css("paddingBottom"), 10);
  204.                             borderHeight = parseInt(img.css("border-top-width"), 10) + parseInt(img.css("border-bottom-width"), 10);
  205.                             wrappingHeight = opt.trueHeight + paddingHeight + borderHeight;
  206.                             value = "" + wrappingHeight + "px"
  207.                         } else {
  208.                             value = img.css(v)
  209.                         }
  210.                         importantText = important ? " !important" : "";
  211.                         return output += "" + k + ":" + value + importantText + ";"
  212.                     });
  213.                     return output
  214.                 },
  215.                 updateUrlWithHash: function() {
  216.                     if (opt.urlFriendly) {
  217.                         return location.hash = opt.uid
  218.                     }
  219.                 },
  220.                 attemptToScrollToImage: function() {
  221.                     if (opt.noScroll) {
  222.                         return
  223.                     }
  224.                     if ("clickback" in opt) {
  225.                         return $("img").each(function() {
  226.                             if (opt.clickback.imgHash === methods.createImgHash($(this).attr("src"))) {
  227.                                 $("html, body").animate({
  228.                                     scrollTop: $(this).offset().top
  229.                                 }, 1e3);
  230.                                 return false
  231.                             }
  232.                         })
  233.                     }
  234.                 },
  235.                 parseHash: function() {
  236.                     var hash, hashArray;
  237.                     if (location.hash === "") {
  238.                         return
  239.                     }
  240.                     hash = location.hash;
  241.                     hashArray = hash.split(".");
  242.                     if (hashArray.length !== 3) {
  243.                         return
  244.                     }
  245.                     if (hashArray[0][0] === "#") {
  246.                         hashArray[0] = hashArray[0].substring(1)
  247.                     }
  248.                     return opt.clickback = {
  249.                         id: hashArray[0],
  250.                         imgHash: hashArray[1],
  251.                         socialNetwork: hashArray[2]
  252.                     }
  253.                 },
  254.                 captureReferrer: function() {
  255.                     return $.ajax({
  256.                         crossDomain: true,
  257.                         type: "GET",
  258.                         url: "http://cdn.slingpic.com/api/log",
  259.                         dataType: "jsonp",
  260.                         data: {
  261.                             uid: opt.uid,
  262.                             source: "SLINGPIC",
  263.                             urlOn: document.location.hostname,
  264.                             urlFrom: document.referrer,
  265.                             clickback: opt.clickback
  266.                         },
  267.                         success: function(data) {
  268.                             return log(data)
  269.                         }
  270.                     })
  271.                 },
  272.                 updateShareCount: function(el, data) {
  273.                     $(el).find(".slingpicShareCountValue").html(data.total);
  274.                     return $(el).find(".slingpicSocialBtnContainer .slingpicSocialBtn").each(function() {
  275.                         if ($(this).data("social-network") in data.social_networks) {
  276.                             return $(this).html('<div class="slingpicSplitShareCount"><p>' + data.social_networks[$(this).data("social-network")] + "</p></div>")
  277.                         }
  278.                     })
  279.                 },
  280.                 incrementShareCount: function(el, data) {
  281.                     var newTotal;
  282.                     log("incrementShareCount");
  283.                     newTotal = parseInt($(el).find(".slingpicShareCountValue").html(), 10) + 1;
  284.                     $(el).find(".slingpicShareCountValue").html(newTotal);
  285.                     return $(el).find(".slingpicSocialBtnContainer .slingpicSocialBtn").each(function() {
  286.                         var newCount;
  287.                         if ($(this).data("social-network") === data.social_network) {
  288.                             if ($(this).find(".slingpicSplitShareCount").size() > 0) {
  289.                                 newCount = parseInt($(this).find(".slingpicSplitShareCount:first p:first").html(), 10) + 1;
  290.                                 return $(this).find(".slingpicSplitShareCount:first p:first").html(newCount)
  291.                             } else {
  292.                                 return $(this).html('<div class="slingpicSplitShareCount"><p>1</p></div>')
  293.                             }
  294.                         }
  295.                     })
  296.                 },
  297.                 slideInOutShares: function(el) {
  298.                     var shareCnt;
  299.                     shareCnt = $(el).find(".slingpicShareCount");
  300.                     if ($(el).hasClass("right")) {
  301.                         shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px");
  302.                         return shareCnt.delay(500).animate({
  303.                             right: "+=30"
  304.                         }, 500).delay(3e3).animate({
  305.                             right: "-=30"
  306.                         }, 500)
  307.                     } else {
  308.                         shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px");
  309.                         return shareCnt.delay(500).animate({
  310.                             left: "+=30"
  311.                         }, 500).delay(3e3).animate({
  312.                             left: "-=30"
  313.                         }, 500)
  314.                     }
  315.                 },
  316.                 getShareCounts: function() {
  317.                     var imgHashes;
  318.                     imgHashes = [];
  319.                     $(".slingpic").each(function() {
  320.                         return imgHashes.push($(this).data("img-hash"))
  321.                     });
  322.                     if (imgHashes.length === 0) {
  323.                         return
  324.                     }
  325.                     return $.ajax({
  326.                         crossDomain: true,
  327.                         type: "GET",
  328.                         url: "http://cdn.slingpic.com/api/count/get",
  329.                         dataType: "jsonp",
  330.                         data: {
  331.                             hostname: document.location.hostname,
  332.                             imgHashes: imgHashes
  333.                         },
  334.                         jsonpCallback: "getShareCountsResponse"
  335.                     })
  336.                 },
  337.                 supportsBefore: function() {
  338.                     var body, div, error, ret, style;
  339.                     log("checking if the browser supports the :before psuedo class");
  340.                     body = document.body;
  341.                     error = false;
  342.                     if ( !! document.querySelector) {
  343.                         try {
  344.                             document.querySelector(":before");
  345.                             ret = true
  346.                         } catch (_error) {
  347.                             error = _error;
  348.                             log("EXCEPTION :before psuedo class not supported");
  349.                             ret = false
  350.                         } finally {
  351.                             return ret
  352.                         }
  353.                     }
  354.                     body.appendChild(div = document.createElement("div"), div.innerHTML = ["&shy;<style>", ":before", "{}</style>"].join(""), div);
  355.                     style = div.children[0];
  356.                     if (style.styleSheet && !style.styleSheet.rules.length) {
  357.                         log("(IE8) :before psuedo class not supported");
  358.                         return ret = false
  359.                     } else {
  360.                         ret = !/unknown/.test(style.styleSheet.rules[0].selectorText.toLowerCase());
  361.                         body.removeChild(div);
  362.                         if (!ret) {
  363.                             log(":before psuedo class not supported")
  364.                         } else {
  365.                             log(":before psuedo class supported")
  366.                         }
  367.                         return ret
  368.                     }
  369.                 }
  370.             };
  371.             cssRules = {
  372.                 general: {
  373.                     bottom: "bottom",
  374.                     display: "display",
  375.                     "float": "float",
  376.                     left: "left",
  377.                     "margin-top": "marginTop",
  378.                     "margin-right": "marginRight",
  379.                     "margin-bottom": "marginBottom",
  380.                     "margin-left": "marginLeft",
  381.                     "max-width": "maxWidth",
  382.                     position: "position",
  383.                     right: "right",
  384.                     top: "top"
  385.                 },
  386.                 extra: {
  387.                     background: "background",
  388.                     border: "border",
  389.                     "border-radius": "borderRadius",
  390.                     "box-shadow": "boxShadow",
  391.                     "padding-bottom": "paddingBottom",
  392.                     "padding-left": "paddingLeft",
  393.                     "padding-right": "paddingRight",
  394.                     "padding-top": "paddingTop"
  395.                 },
  396.                 heightWidth: {
  397.                     height: "height",
  398.                     width: "width"
  399.                 }
  400.             };
  401.             adReloadCount = 0;
  402.             defaults = {
  403.                 adPos: "bottomRight",
  404.                 adPosManual: {
  405.                     bottom: 0,
  406.                     left: 0,
  407.                     right: 0,
  408.                     top: 0
  409.                 },
  410.                 adReload: false,
  411.                 adReloadNumber: 2,
  412.                 advertHeight: 200,
  413.                 advertSrc: false,
  414.                 advertWidth: 200,
  415.                 alignShare: "right",
  416.                 allowImageStyling: false,
  417.                 autoShowShare: false,
  418.                 context: false,
  419.                 copyright: false,
  420.                 debug: false,
  421.                 domain: location.host,
  422.                 dontShow: "",
  423.                 elemPadding: "",
  424.                 iconNotRequired: false,
  425.                 ignoreWidthHeight: false,
  426.                 manualDimensions: {
  427.                     height: 0,
  428.                     width: 0
  429.                 },
  430.                 minShareHeight: 100,
  431.                 minShareWidth: 100,
  432.                 minAdHeight: 200,
  433.                 minAdWidth: 200,
  434.                 noScroll: false,
  435.                 offsets: {
  436.                     top: 0,
  437.                     right: 0,
  438.                     bottom: 0,
  439.                     left: 0
  440.                 },
  441.                 parentElem: "",
  442.                 persistantAd: true,
  443.                 primary_links: ["facebook", "twitter", "pinterest", "email"],
  444.                 secondary_links: ["delicious", "linkedin", "reddit", "friendfeed", "digg", "tumblr", "myspace", "print"],
  445.                 shareSummary: "",
  446.                 show: "",
  447.                 showAd: false,
  448.                 showAdClose: true,
  449.                 showShare: true,
  450.                 theme: "",
  451.                 title: "",
  452.                 uid: uid,
  453.                 url: location.href,
  454.                 urlFriendly: false
  455.             };
  456.             slingPicProviders = {
  457.                 facebook: ["http://www.facebook.com/share.php?s=100&amp;p[title]={title}&amp;p[summary]={summary}&amp;p[url]={url}&amp;&amp;p[images][0]={image-url}", "Share this on Facebook"],
  458.                 twitter: ['http://twitter.com/share?url={url}&text={summary}&count=horiztonal"', "Tweet This!"],
  459.                 tumblr: ["http://www.tumblr.com/share/photo?source={image-url}&caption={summary}&click_thru={url}", "Share this on Tumblr"],
  460.                 email: ["mailto:?subject={summary}&body={image-url} from {url}", "Email this to a friend?"],
  461.                 googleplus: ["https://plus.google.com/share?url={url}"],
  462.                 print: ["{original-image-url}", "Print"],
  463.                 linkedin: ["http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title} {image-url}&summary={summary}&source={url}", "Share this on LinkedIn"],
  464.                 reddit: ["http://reddit.com/submit?url={url}&title={summary} {image-url} {title}", "Share this on Reddit"],
  465.                 stumbleupon: ["http://www.stumbleupon.com/submit?url={url}&title={summary} {image-url}", "Stumble upon something good? Share it on StumbleUpon"],
  466.                 delicious: ["http://delicious.com/post?url={url}&title={summary} {image-url}", "Share this on del.icio.us"],
  467.                 pinterest: ["http://pinterest.com/pin/create/button/?url={url}&media={image-url}&description={summary}", "Pin it"],
  468.                 digg: ["http://digg.com/submit?phase=2&url={url}&title={title}&bodytext={summary}", "Digg this!"],
  469.                 myspace: ["http://www.myspace.com/Modules/PostTo/Pages/?u={url}&t={summary}&c={image-url}&l={image-url}", "Post this to MySpace"],
  470.                 blogger: ["http://www.blogger.com/blog_this.pyra?t&amp;u={url}&n={title}", "Blog this on Blogger"],
  471.                 friendfeed: ["http://www.friendfeed.com/share?title={summary} {image-url}&link={url}&image0_url={image-url}", "Share this on FriendFeed"],
  472.                 designfloat: ["http://www.designfloat.com/submit.php?url={url}&link={title}", "Submit this to DesignFloat"],
  473.                 orkut: ["http://promote.orkut.com/preview?nt=orkut.com&amp&tt={url};du={title}", "Promote this on Orkut"],
  474.                 technorati: ["http://technorati.com/faves?add={url}", "Share this on Technorati"]
  475.             };
  476.             social_networks = {
  477.                 facebook: "fa",
  478.                 twitter: "tw",
  479.                 tumblr: "tu",
  480.                 email: "em",
  481.                 print: "pr",
  482.                 googleplus: "gp",
  483.                 linkedin: "li",
  484.                 reddit: "re",
  485.                 stumbleupon: "su",
  486.                 posterous: "po",
  487.                 delicious: "de",
  488.                 pinterest: "pi",
  489.                 digg: "di",
  490.                 gmail: "gm",
  491.                 netvibes: "nv",
  492.                 myspace: "ms",
  493.                 blogger: "bl",
  494.                 friendfeed: "ff",
  495.                 yahoomail: "ym",
  496.                 designfloat: "df",
  497.                 evernote: "en",
  498.                 orkut: "or",
  499.                 virb: "vi",
  500.                 technorati: "te"
  501.             };
  502.             opt = $.extend(defaults, options);
  503.             zIndex = 1;
  504.             MAX_SHARE_BTNS = 4;
  505.             MAX_SMALL_SHARE_BTNS = 8;
  506.             methods.parseHash();
  507.             methods.attemptToScrollToImage();
  508.             methods.updateUrlWithHash();
  509.             methods.captureReferrer();
  510.             opt.iconNotRequired = methods.supportsBefore();
  511.             log("looping through images");
  512.             returnMe = this.each(function(index, element) {
  513.                 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;
  514.                 log("image " + index);
  515.                 elem = $(element);
  516.                 share = false;
  517.                 advert = false;
  518.                 elementWidth = 0;
  519.                 elementHeight = 0;
  520.                 dimensionsParent = false;
  521.                 if (!methods.checkConflicts(elem)) {
  522.                     return
  523.                 }
  524.                 log("passed conflicts");
  525.                 if (opt.show !== "" && elem.hasClass(opt.show) || opt.show === "" && opt.dontShow === "" || opt.show === "" && opt.dontShow !== "" && !elem.hasClass(opt.dontShow)) {
  526.                     log("show");
  527.                     if (elem.css("width") === "100%") {
  528.                         dimensionsParent = elem.parent();
  529.                         while (dimensionsParent.css("width") === "100%") {
  530.                             dimensionsParent = dimensionsParent.parent()
  531.                         }
  532.                         elementWidth = dimensionsParent.width()
  533.                     } else {
  534.                         if (elem[0]) {
  535.                             elementWidth = elem.width() < elem[0].width ? elem[0].width : elem.width()
  536.                         } else {
  537.                             elementWidth = elem.width()
  538.                         }
  539.                     }
  540.                     if (elem.css("height") === "100%" || elem.css("height") === "0px" && elementWidth > 0) {
  541.                         dimensionsParent = elem.parent();
  542.                         while (dimensionsParent.css("height") === "100%" || dimensionsParent.css("height") === "0px") {
  543.                             dimensionsParent = dimensionsParent.parent()
  544.                         }
  545.                         elementHeight = dimensionsParent.height()
  546.                     } else {
  547.                         if (elem[0]) {
  548.                             elementHeight = elem.height() < elem[0].height ? elem[0].height : elem.height()
  549.                         } else {
  550.                             elementHeight = elem.height()
  551.                         }
  552.                     }
  553.                     if (elementWidth > opt.minShareWidth && elementHeight > opt.minShareHeight && opt.showShare) {
  554.                         share = true
  555.                     }
  556.                     if (elementWidth > opt.minAdWidth && elementHeight > opt.minAdHeight && opt.showAd && opt.advertSrc) {
  557.                         advert = true
  558.                     }
  559.                     opt.trueHeight = opt.manualDimensions.height > 0 ? opt.manualDimensions.height : elementHeight;
  560.                     opt.trueWidth = opt.manualDimensions.width > 0 ? opt.manualDimensions.width : elementWidth;
  561.                     if (!share && !advert) {
  562.                         return
  563.                     }
  564.                 } else if (opt.dontShow !== "" && elem.hasClass(opt.dontShow)) {
  565.                     log("don't show: return");
  566.                     return
  567.                 } else if (!elem.hasClass(opt.show)) {
  568.                     return
  569.                 }
  570.                 if (opt.parentElem !== "") {
  571.                     $img = $(opt.parentElem)
  572.                 } else {
  573.                     $img = $(element)
  574.                 }
  575.                 $imgSrc = $img.attr("src");
  576.                 copyrightText = $img.data("copyright");
  577.                 $grandparentPosition = elem.parent().css("position");
  578.                 $grandparentZIndex = elem.parent().css("zIndex");
  579.                 opt.originalImgSrc = $img.attr("src");
  580.                 methods.checkConflicts($img);
  581.                 if ($imgSrc.indexOf("http://") === -1 && $imgSrc.indexOf("https://") === -1) {
  582.                     if ($imgSrc.indexOf("/") === 0) {
  583.                         $imgSrc = "http://" + opt.domain + $imgSrc
  584.                     } else {
  585.                         regexObjResult = null;
  586.                         baseUrl = opt.url;
  587.                         regexObj = /(\/\w+\.\w+)$/i;
  588.                         regexObjResult = regexObj.exec(opt.url);
  589.                         if (regexObjResult) {
  590.                             baseUrl = opt.url.substr(0, regexObjResult.index)
  591.                         }
  592.                         $imgSrc = "" + baseUrl + "/" + $imgSrc;
  593.                         log($imgSrc)
  594.                     }
  595.                 }
  596.                 opt.imgSrc = $imgSrc;
  597.                 wrappingDivStyle = methods.setStyle($img, "general");
  598.                 wrappingDivStyle += methods.setStyle($img, "heightWidth");
  599.                 wrappingDivZIndex = zIndex++;
  600.                 opt.imgHash = methods.createImgHash(opt.originalImgSrc);
  601.                 wrappingDiv = '<div class="slingpic ' + opt.theme + " " + opt.alignShare + '" data-img-hash="' + opt.imgHash + '" style="' + wrappingDivStyle + '">';
  602.                 if (opt.parentElem !== "") {
  603.                     elem.closest(opt.parentElem).wrap(wrappingDiv)
  604.                 } else if (elem.parent().is("a")) {
  605.                     elem.parent().wrap(wrappingDiv)
  606.                 } else {
  607.                     elem.wrap(wrappingDiv)
  608.                 }
  609.                 if (opt.context) {
  610.                     result = methods.getContext($img);
  611.                     opt.shareSummary = result.value;
  612.                     if (opt.copyright && copyrightText) {
  613.                         opt.shareSummary += " \n© " + copyrightText + "\n"
  614.                     }
  615.                     result = methods.getContext($img, result.avoid, true);
  616.                     opt.title = result.value
  617.                 } else {
  618.                     opt.shareSummary = "" + document.title + " (shared via SlingPic)";
  619.                     if (opt.copyright && copyrightText) {
  620.                         opt.shareSummary += " \n© " + copyrightText + "\n"
  621.                     }
  622.                     opt.title = encodeURIComponent(document.title)
  623.                 }
  624.                 opt.offsets = {
  625.                     top: parseInt($img.css("paddingTop"), 10) + parseInt($img.css("border-top-width"), 10),
  626.                     right: parseInt($img.css("paddingRight"), 10) + parseInt($img.css("border-right-width"), 10),
  627.                     bottom: parseInt($img.css("paddingBottom"), 10) + parseInt($img.css("border-bottom-width"), 10),
  628.                     left: parseInt($img.css("paddingLeft"), 10) + parseInt($img.css("border-left-width"), 10)
  629.                 };
  630.                 if (opt.showShare) {
  631.                     if (opt.alignShare === "left") {
  632.                         leftRightOffset = "left: " + (opt.offsets.left + 5) + "px !important;";
  633.                         countBaseLeftRightValue = opt.offsets.left + 33;
  634.                         countBaseLeftRightAttr = "left: " + countBaseLeftRightValue + "px;"
  635.                     } else if (opt.alignShare === "right") {
  636.                         leftRightOffset = "right: " + (opt.offsets.right + 5) + "px !important;";
  637.                         countBaseLeftRightValue = opt.offsets.right + 33;
  638.                         countBaseLeftRightAttr = "right: " + countBaseLeftRightValue + "px;"
  639.                     }
  640.                     shareButtonTop = "top: " + (opt.offsets.top + 5) + "px !important;";
  641.                     shareWidgetTop = "top: " + (opt.offsets.top + 40) + "px !important;";
  642.                     primaryLinksLIs = methods.generateShareLinks(opt.primary_links, MAX_SHARE_BTNS);
  643.                     if (opt.secondary_links.length > 0) {
  644.                         secondayLinksLIs = methods.generateShareLinks(opt.secondary_links, MAX_SMALL_SHARE_BTNS);
  645.                         secondaryLinks = '<ul class="slingpicMoreSocialBtnContainer" style="display: none !important">\n    ' + secondayLinksLIs + "\n</ul>";
  646.                         moreLink = '<a href="#" class="slingpicWidgetMoreLessBtn">more</a>'
  647.                     } else {
  648.                         secondaryLinks = "";
  649.                         moreLink = ""
  650.                     }
  651.                     log("html time");
  652.                     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>'
  653.                 }
  654.                 if (opt.showAd) {
  655.                     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">' : "";
  656.                     cb = parseInt(Math.random() * 999999);
  657.                     closeHtml = opt.showAdClose === true ? '<div class="slingpicAdClose" onclick="jQuery(this).closest(\'.slingpicAdSpot\').remove(); return false;"></div>' : "";
  658.                     bottomOffsetValue = opt.offsets.bottom + opt.adPosManual.bottom;
  659.                     rightOffsetValue = opt.offsets.right + opt.adPosManual.right;
  660.                     bottomOffset = "bottom: " + bottomOffsetValue + "px !important;";
  661.                     rightOffset = "right: " + rightOffsetValue + "px !important;";
  662.                     if (opt.persistantAd) {
  663.                         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>"
  664.                     } else {
  665.                         elem.closest(".slingpic").one("mouseover", opt, function(event) {
  666.                             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">' : "";
  667.                             cb = parseInt(Math.random() * 999999);
  668.                             closeHtml = event.data.showAdClose === true ? '<div class="slingpicAdClose" onclick="jQuery(this).closest(\'.slingpicAdSpot\').remove(); return false;"></div>' : "";
  669.                             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>";
  670.                             return $(this).append(adHtml)
  671.                         })
  672.                     }
  673.                 }
  674.                 if (adHtml && html) {
  675.                     html += adHtml
  676.                 } else if (adHtml) {
  677.                     html = adHtml
  678.                 }
  679.                 $(html).appendTo(elem.closest(".slingpic"));
  680.                 $img.addClass("slingpic_reset");
  681.                 if (opt.showShare) {
  682.                     elem.closest(".slingpic").find(".slingpicSocialBtn").click(function() {
  683.                         var data;
  684.                         data = {
  685.                             hn: document.location.hostname,
  686.                             imgHash: $(this).closest(".slingpic").data("img-hash"),
  687.                             sn: $(this).data("social-network"),
  688.                             uid: uid
  689.                         };
  690.                         return $.ajax({
  691.                             crossDomain: true,
  692.                             type: "GET",
  693.                             url: "http://cdn.slingpic.com/api/count/add",
  694.                             dataType: "jsonp",
  695.                             data: data,
  696.                             success: function(data) {
  697.                                 if (data.success) {
  698.                                     return log("success")
  699.                                 } else {
  700.                                     return log("failed")
  701.                                 }
  702.                             }
  703.                         })
  704.                     });
  705.                     elem.closest(".slingpic").find(".slingpicWidgetMoreLessBtn,.slingpicShareBtn,.slingpicWidgetClose").click(function(event) {
  706.                         var moreBtns, newPos, shareCnt, widget;
  707.                         event.preventDefault();
  708.                         if ($(this).hasClass("slingpicWidgetMoreLessBtn")) {
  709.                             moreBtns = $(this).parent().siblings(".slingpicMoreSocialBtnContainer");
  710.                             if (moreBtns.css("display") === "none") {
  711.                                 $(this).text("less");
  712.                                 return moreBtns.attr("style", moreBtns.attr("style").replace("none", "block"))
  713.                             } else {
  714.                                 $(this).text("more");
  715.                                 return moreBtns.attr("style", moreBtns.attr("style").replace("block", "none"))
  716.                             }
  717.                         } else if ($(this).hasClass("slingpicShareBtn")) {
  718.                             widget = $(this).closest(".slingpic").find(".slingpicWidgetContainer");
  719.                             if (widget.css("display") === "none") {
  720.                                 widget.attr("style", widget.attr("style").replace("none", "block"));
  721.                                 shareCnt = $(this).prev(".slingpicShareCount");
  722.                                 shareCnt.clearQueue();
  723.                                 newPos = shareCnt.data("base-state") + 30;
  724.                                 if ($(this).closest(".slingpic").hasClass("right")) {
  725.                                     return shareCnt.animate({
  726.                                         right: "" + newPos + "px"
  727.                                     }, 500)
  728.                                 } else {
  729.                                     return shareCnt.animate({
  730.                                         left: "" + newPos + "px"
  731.                                     }, 500)
  732.                                 }
  733.                             } else {
  734.                                 return widget.attr("style", widget.attr("style").replace("block", "none"))
  735.                             }
  736.                         } else if ($(this).hasClass("slingpicWidgetClose")) {
  737.                             widget = $(this).closest(".slingpicWidgetContainer");
  738.                             if (widget.css("display") === "none") {
  739.                                 return widget.attr("style", widget.attr("style").replace("none", "block"))
  740.                             } else {
  741.                                 return widget.attr("style", widget.attr("style").replace("block", "none"))
  742.                             }
  743.                         }
  744.                     });
  745.                     elem.closest(".slingpic").mouseenter({
  746.                         autoShowShare: opt.autoShowShare,
  747.                         alignShare: opt.alignShare
  748.                     }, function(event) {
  749.                         var shareBtn, shareCnt, widget;
  750.                         shareCnt = $(this).find(".slingpicShareCount");
  751.                         shareBtn = $(this).find(".slingpicShareBtn");
  752.                         if (shareBtn.size() > 0) {
  753.                             shareBtn.attr("style", shareBtn.attr("style").replace("none", "block"))
  754.                         }
  755.                         if (shareCnt.size() > 0) {
  756.                             shareCnt.attr("style", shareCnt.attr("style").replace("none", "block"));
  757.                             if (event.data.alignShare === "right") {
  758.                                 log("it's aligned to the right");
  759.                                 shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px");
  760.                                 shareCnt.delay(500).animate({
  761.                                     right: "+=30"
  762.                                 }, 500).delay(3e3).animate({
  763.                                     right: "-=30"
  764.                                 }, 500)
  765.                             } else {
  766.                                 shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px");
  767.                                 shareCnt.delay(500).animate({
  768.                                     left: "+=30"
  769.                                 }, 500).delay(3e3).animate({
  770.                                     left: "-=30"
  771.                                 }, 500)
  772.                             }
  773.                         }
  774.                         if (event.data.autoShowShare) {
  775.                             widget = $(this).find(".slingpicWidgetContainer");
  776.                             if (widget.size() > 0) {
  777.                                 return widget.attr("style", widget.attr("style").replace("none", "block"))
  778.                             }
  779.                         }
  780.                     })
  781.                 }
  782.                 if (opt.showAd) {
  783.                     if ($.isFunction($(document).delegate)) {
  784.                         $(document).delegate('div[id^="scr_"]', "mouseenter", function() {
  785.                             if (document.slingpicReloader) {
  786.                                 return window.clearTimeout(document.slingpicReloader)
  787.                             }
  788.                         })
  789.                     } else {
  790.                         $(document).live('div[id^="scr_"]', "mouseenter", function() {
  791.                             if (document.slingpicReloader) {
  792.                                 return window.clearTimeout(document.slingpicReloader)
  793.                             }
  794.                         })
  795.                     }
  796.                 }
  797.                 if (!opt.persistantAd) {
  798.                     elem.closest(".slingpic").mouseenter(function() {
  799.                         return $(this).find(".slingpicAdSpot").attr("style", "display: block !important")
  800.                     });
  801.                     elem.closest(".slingpic").mouseleave(function() {
  802.                         return $(this).find(".slingpicAdSpot").attr("style", $(this).find(".slingpicAdSpot").attr("style").replace("block", "none"))
  803.                     })
  804.                 }
  805.                 if ($.isFunction($(document).delegate)) {
  806.                     elem.closest(".slingpic").mouseleave({
  807.                         alignShare: opt.alignShare
  808.                     }, function(event) {
  809.                         var shareBtn, shareCnt;
  810.                         if ($(this).find(".slingpicWidgetContainer").size() > 0) {
  811.                             $(this).find(".slingpicWidgetContainer").attr("style", $(this).find(".slingpicWidgetContainer").attr("style").replace("block", "none"))
  812.                         }
  813.                         if ($(this).find(".slingpicWidgetMoreLessBtn").size() > 0) {
  814.                             $(this).find(".slingpicWidgetMoreLessBtn").text("more")
  815.                         }
  816.                         if ($(this).find(".slingpicMoreSocialBtnContainer").size() > 0) {
  817.                             $(this).find(".slingpicMoreSocialBtnContainer").attr("style", $(this).find(".slingpicMoreSocialBtnContainer").attr("style").replace("block", "none"))
  818.                         }
  819.                         shareBtn = $(this).find(".slingpicShareBtn");
  820.                         if (shareBtn.size() > 0) {
  821.                             shareBtn.attr("style", shareBtn.attr("style").replace("block", "none"))
  822.                         }
  823.                         shareCnt = $(this).find(".slingpicShareCount");
  824.                         if (shareCnt.size() > 0) {
  825.                             shareCnt.attr("style", shareCnt.attr("style").replace("block", "none"));
  826.                             if (event.data.alignShare === "right") {
  827.                                 return shareCnt.stop().clearQueue().css("right", shareCnt.data("base-state") + "px")
  828.                             } else {
  829.                                 return shareCnt.stop().clearQueue().css("left", shareCnt.data("base-state") + "px")
  830.                             }
  831.                         }
  832.                     })
  833.                 }
  834.                 return methods.loadCss()
  835.             });
  836.             methods.getShareCounts();
  837.             document.slingpicReloader = opt.showAd && opt.advertSrc && opt.adReload ? setTimeout(methods.adReload, 2e4) : false;
  838.             root.getShareCountsResponse = function(data) {
  839.                 var hashes;
  840.                 hashes = {};
  841.                 console.log(data);
  842.                 $.each(data.counts, function(k, v) {
  843.                     if (v.img_hash in hashes) {
  844.                         hashes[v.img_hash]["social_networks"][v.social_network] = v.count;
  845.                         return hashes[v.img_hash]["total"] += v.count
  846.                     } else {
  847.                         hashes[v.img_hash] = {
  848.                             total: v.count,
  849.                             social_networks: {}
  850.                         };
  851.                         return hashes[v.img_hash]["social_networks"][v.social_network] = v.count
  852.                     }
  853.                 });
  854.                 return $(".slingpic").each(function() {
  855.                     if (hashes.hasOwnProperty($(this).data("img-hash"))) {
  856.                         return methods.updateShareCount($(this), hashes[$(this).data("img-hash")])
  857.                     }
  858.                 })
  859.             };
  860.             root.addShareCountResponse = function(data) {
  861.                 log("addShareCountResponse", data);
  862.                 return $(".slingpic").each(function() {
  863.                     log(parseInt(data.img_hash, 10), parseInt($(this).data("img-hash"), 10));
  864.                     if (parseInt(data.img_hash, 10) === parseInt($(this).data("img-hash"), 10)) {
  865.                         return methods.incrementShareCount($(this), data)
  866.                     }
  867.                 })
  868.             };
  869.             return returnMe
  870.         }
  871.     })
  872. }.call(this);
Add Comment
Please, Sign In to add comment