Plugin Name: PollDaddy Embeddable Polls Plugin Description: Create and add PollDaddy polls to your comment stream and let your readers take the debate to a new dimension! Find out what your visitors are thinking today. Create your surveys and let your readers create polls too! Plugin URL: http://www.polldaddy.com Author: Jon Author URL: https://www.intensedebate.com/people/jon Date Added: March 5th, 2009 Code: var id_polldaddy_plugin = {}; id_polldaddy_plugin.id_polldaddy_ids = []; /* PollDaddy id's to load proper JavaScript for later */ id_polldaddy_plugin.polldaddy_disabled_edit_ids = []; /* IntenseDebate commentid's that should have edit functionality disabled (contain polls) */ id_polldaddy_plugin.polldaddy_posted_from = 0; /* Which field should the poll embed code be inserted in (Reply or New Comment) */ /* Replace polldaddy embed code with a div of a proper ID to have the poll inserted when the PollDaddy javascript is loaded */ id_polldaddy_plugin.id_replace_polldaddy_and_add_poll_code = function(args) { var text = args['text']; //Check for valid match var polldaddy_regex=/\[polldaddy\s+(.*?)\s+(.*?)\s+polldaddy\]/ig; var m = polldaddy_regex.exec(text); //If there is a match if(m && m.length>1) { /* Extract the id from the embed code */ id_polldaddy_plugin.id_polldaddy_ids[id_polldaddy_plugin.id_polldaddy_ids.length] = m[1]; /* add the IntenseDebate commentid to the array of comments to disable editing for */ id_polldaddy_plugin.polldaddy_disabled_edit_ids[id_polldaddy_plugin.polldaddy_disabled_edit_ids.length] = args['commentid']; /* reset the regex */ polldaddy_regex.lastIndex=0; /* return the polldaddy div (where the poll will go */ return text.replace(polldaddy_regex, '
'); } else return text; }; /* Display the popup of fields to fill out when creating a PollDaddy poll */ id_polldaddy_plugin.id_show_polldaddy_creator = function(val) { id_polldaddy_plugin.polldaddy_posted_from = val; var link2 = $newEl('a'); link2.href="javascript: id_polldaddy_plugin.id_send_poll_request();"; IDReplaceHtml(link2, "Add Poll"); link2.className="idc-btn_s idc-disablestyles"; link2.style.cssFloat = 'right'; showMsgBox('Add a PollDaddy Poll', '', 0, null, link2); }; /* Pull in the JavaScript portion of each poll */ id_polldaddy_plugin.id_load_polldaddy_js = function() { /* If there's anything new */ if(id_polldaddy_plugin.id_polldaddy_ids.length > 0) { for(objElem in id_polldaddy_plugin.id_polldaddy_ids) { if( typeof(id_polldaddy_plugin.id_polldaddy_ids[objElem]) != 'string' ) continue; var polldaddyJS = document.createElement('SCRIPT'); polldaddyJS.type='text/javascript'; polldaddyJS.src='http://static.polldaddy.com/p/'+id_polldaddy_plugin.id_polldaddy_ids[objElem]+'.js'; document.getElementsByTagName('HEAD')[0].appendChild(polldaddyJS); } id_polldaddy_plugin.id_polldaddy_disable_edit_buttons(); /* Clear out the array now that it's been taken care of */ id_polldaddy_plugin.id_polldaddy_ids = []; } }; /* Add the PollDaddy button to the interface */ id_polldaddy_plugin.id_add_polldaddy_button = function() { id_add_plugin_button("javascript: id_polldaddy_plugin.id_show_polldaddy_creator(0)", "javascript: id_polldaddy_plugin.id_show_polldaddy_creator(1)", "http://www.polldaddy.com/favicon.ico", "Add a PollDaddy Poll", "PollDaddy", "Add poll"); id_polldaddy_plugin.id_polldaddy_disable_edit_buttons(); }; /* Disable the edit button on comments w/ a poll since it doesn't make sense anymore */ id_polldaddy_plugin.id_polldaddy_disable_edit_buttons = function() { for(objElem in id_polldaddy_plugin.polldaddy_disabled_edit_ids) { if($id('IDCommentPostReplyLinkEdit'+id_polldaddy_plugin.polldaddy_disabled_edit_ids[objElem])) $id('IDCommentPostReplyLinkEdit'+id_polldaddy_plugin.polldaddy_disabled_edit_ids[objElem]).style.display = 'none'; } }; /* Send all the poll data back to a script that actually creates the poll and calls one of the callback functions below */ id_polldaddy_plugin.id_send_poll_request = function() { var scriptURL = "http://intensedebate.com/pd-poll-creator.php?q=" + encodeURIComponent($id('txtPollTitle').value) + "&a1=" + encodeURIComponent($id('txtPollAnswer1').value) + "&a2=" + encodeURIComponent($id('txtPollAnswer2').value) + "&a3=" + encodeURIComponent($id('txtPollAnswer3').value) + "&a4=" + encodeURIComponent($id('txtPollAnswer4').value) + "&a5=" + encodeURIComponent($id('txtPollAnswer5').value); var theScriptTag = document.createElement('SCRIPT'); theScriptTag.src = scriptURL; theScriptTag.type = "text/javascript"; document.getElementsByTagName('HEAD')[0].appendChild(theScriptTag); }; /* Called when a poll has been successfully created */ id_polldaddy_plugin.id_add_poll_callback = function(pollid) { /* Make sure we put the embed code in the correct textbox (reply or new comment) */ if(id_polldaddy_plugin.polldaddy_posted_from == 0) var textBox = $id('IDCommentNewThreadText'); else var textBox = $id('txtComment'); /* If no comment text has been entered yet be sure to clear the default stuff */ if(textBox.value=='Enter text right here!') { textBox.value = ''; textBox.style.color = 'black'; } /* Add the embed code to the textbox */ textBox.value += '[polldaddy ' + pollid + ' http://answers.polldaddy.com/poll/' + pollid + '/ polldaddy]'; /* Hide the popup box */ hideMsgBox(); /* Give focus to the text box */ textBox.focus(); }; /* Called on poll creation failure */ id_polldaddy_plugin.id_add_poll_callback_error = function() { alert("An error has occured and your poll could not be created. Please try again in a moment."); }; id_add_filter('comment_text_load',id_polldaddy_plugin.id_replace_polldaddy_and_add_poll_code); /*Swap out embed code for PD poll when comment is output*/ id_add_action('idcomments_func_load', id_polldaddy_plugin.id_load_polldaddy_js); /*Load the PD JS when we load */ id_add_action('idcomments_func_load',id_polldaddy_plugin.id_add_polldaddy_button); /*Add the PD button to IntenseDebate interface on load */ id_add_action('user_login',id_polldaddy_plugin.id_polldaddy_disable_edit_buttons); /* Disable edit buttons on user login */ id_add_action('comment_post', id_polldaddy_plugin.id_load_polldaddy_js); /* Load the new JS for a PD poll when a comment is posted */ CSS: N/A