All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: Script to make WP Polls popup  (Read 1879 times)

0 Members and 1 Guest are viewing this topic.

Offline sijo

  • Newbie
  • *
  • Posts: 1
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: advanced-newspaper-2.0.4
Script to make WP Polls popup
« on: 20 November 2011, 16:46 »
I'm using WP POLLS and I like it, but I wanted to have it popup for my users to vote.
I did find a script on the net that does exactly that, author of this script is Gaetan Renaudeau, http://gaetanrenaudeau.fr/
A good friend of mine from Netherlands (Marcel Bokhorst) did some changes in the script for me to make it work with WP Polls.
Name this script wp-polls-popup.js :

jQuery(document).ready(function($) {
  var pollWidget = $('.widget_polls-widget')
  if(pollWidget.size() && $('input:visible', pollWidget).size()) {
   var clone = $(pollWidget).clone().removeClass('widget_polls-widget');
   $('a', clone).remove();
   $('input', clone).click(function(){
     $('.widget_polls-widget input[value='+$(this).val()+']').attr('checked', 'checked');
   });

   $('input', clone).each(function(){
     var id = $(this).attr('id');
     var newId = 'popup_'+id;
     $('label[for='+id+']', clone).attr('for', newId);
     $(this).attr('id', newId);
   });

   $('input[type=button]', clone).addClass('closepopup');

   $('strong:first', clone).css('font-size', '14px');
   var blackback = $('<div id="blackback" />').css({
     opacity: 0.5,
     background: 'black',
     position: 'fixed', top: 0, left: 0,
     width: '100%', height: '100%',
     zIndex: 998
   }).appendTo('body');

   var popup = $('<div id="popup" />').css({
     zIndex: 999,
     position: 'fixed',
     top: '25%',
     left: '25%',
     width: '50%',
     background: 'white',
     borderRadius: '10px',
     boxShadow: '0px 2px 4px black',
     padding: '10px'
   });
   var a = $('<a class="closepopup" href="javascript:;" />').text('close').css({
     float: 'right',
     marginRight: '10px'
   });
   popup.append(a).append(clone);
   popup.appendTo('body');

   $(document).click(function(e){
     var target = $(e.target);
     if(target.is('.closepopup') || !target.is('#popup') && target.closest('#popup').size()==0)
     {
      blackback.remove();
      popup.remove();
     }

   });
  }
});


Usage:
You have to use WP Polls widget for this popup script to work.
Upload script to WP Polls plugin folder.
Put this in themes functions.php file:
 
// WP Polls popup
add_action('init', 'wp_polls_popup_js');
function wp_polls_popup_js() {
  wp_enqueue_script('jquery');
  wp_enqueue_script('wp-polls-popup-js', 'http://www.mysite.com/wp-content/plugins/wp-polls/wp-polls-popup.js', array('jquery'));
}
 
That's it!  ;)