Advertisement
Imperative-Ideas

Using data attributes in Magnefic + Sharrre

Jun 14th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.37 KB | None | 0 0
  1. // Initialize Sharrre buttons
  2.     function initShare() {
  3.         $('.social-buttons').sharrre({
  4.             share: {
  5.                 twitter: true,
  6.                 facebook: true,
  7.                 googlePlus: true
  8.             },
  9.             template: '<div class="box"><div class="left">Share</div><div class="middle"><a href="#" class="facebook"><i class="icon-facebook"></i></a><a href="#" class="twitter"><i class="icon-twitter-bird"></i></a><a href="#" class="googleplus"><i class="icon-gplus"></i></a></div><div class="right">{total}</div></div>',
  10.             enableHover: false,
  11.             enableTracking: true,
  12.             render: function(api, options){
  13.                 $(api.element).on('click', '.twitter', function() {
  14.                     api.openPopup('twitter');
  15.                 });
  16.                 $(api.element).on('click', '.facebook', function() {
  17.                     api.openPopup('facebook');
  18.                 });
  19.                 $(api.element).on('click', '.googleplus', function() {
  20.                     api.openPopup('googlePlus');
  21.                 });
  22.             }
  23.         });
  24.     }
  25.  
  26.     // Initialize Magnefic Lightbox
  27.     $('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
  28.         iframe: {
  29.             markup:
  30.                 '<div class="mfp-iframe-scaler">'+
  31.                 '<div class="mfp-close"></div>'+
  32.                 '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
  33.                 '</div>'+
  34.                 '<div class="after-iframe">'+
  35.                 '<div class="details-link"><i class="icon-link"></i> <a class="project-link" href="#">Project Details</a></div>'+
  36.                 '<div class="social-buttons" data-url="http://sharrre.com" data-text="Share this" data-title="share"></div>'+
  37.                 '</div>'
  38.         },
  39.         delegate: 'a',
  40.         disableOn: 700,
  41.         type: 'iframe',
  42.         mainClass: 'mfp-fade',
  43.         removalDelay: 160,
  44.         preloader: true,
  45.         fixedContentPos: false,
  46.         callbacks: {
  47.             open: function() { // this is dirty, it targets everything at once. Should be refined to use $(this)
  48.                 var $target = this.st.el.context.dataset.target;
  49.                 $('a.project-link').attr('href', $target);
  50.                 $('div.social-buttons').attr('data-url', $target);
  51.                 initShare();
  52.             }
  53.         }
  54.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement