Skip to content

Instantly share code, notes, and snippets.

@gre
Created January 23, 2011 18:30
Show Gist options
  • Select an option

  • Save gre/792302 to your computer and use it in GitHub Desktop.

Select an option

Save gre/792302 to your computer and use it in GitHub Desktop.
Wordpress - used with WP Polls plugin - Display a popup for people haven't vote for the current polls (you must have polls in widget)
/// AUTHOR : Gaetan Renaudeau, http://gaetanrenaudeau.fr/, pro at grenlibre (DoT) fr
(function($){
if(!jQuery) return; // we need jQuery
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');
});
// we must update each input and label to not have id collisions
$('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: 1
}).appendTo('body');
var popup = $('<div id="popup" />').css({
zIndex: 2,
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();
}
});
}
}(jQuery)());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment