Plugin Name: YouTube Embeddable Video Plugin Description: Activate YouTube embeds and your readers will be able to share their favorite YouTube videos and beef up their responses right in the comment section. Plugin URL: http://youtube.com Author: Jon Author URL: https://www.intensedebate.com/people/jon Date Added: March 5th, 2009 Code: var id_youtube_plugin = {}; id_youtube_plugin.youtube_disabled_edit_ids = []; /* IntenseDebate commentid's that should have edit functionality disabled (contain youtube embeds) */ id_youtube_plugin.youtube_posted_from = 0; /* Which field should the poll embed code be inserted in (Reply or New Comment) */ /* add the YouTube button to the interface */ id_youtube_plugin.id_add_youtube_button = function() { id_add_plugin_button("javascript: id_youtube_plugin.id_show_youtube_embed(0)", "javascript: id_youtube_plugin.id_show_youtube_embed(1)", "//www.youtube.com/favicon.ico", "Add a YouTube Video", "YouTube", "Embed video"); id_youtube_plugin.id_youtube_disable_edit_buttons(); }; /* display the popup for the url of the video to embed */ id_youtube_plugin.id_show_youtube_embed = function(posted_from) { /* keep track of if it was for a reply or a new comment */ id_youtube_plugin.youtube_posted_from = posted_from; var link2 = $newEl('a'); link2.href="javascript: id_youtube_plugin.id_add_youtube_embed_code();"; IDReplaceHtml(link2, "Embed Video"); link2.className="idc-btn_s idc-disablestyles"; link2.style.cssFloat = 'right'; showMsgBox('Embed a YouTube Video', '

Enter the video URL to embed below:

', 0, null, link2); }; id_youtube_plugin.id_add_youtube_embed_code = function() { /* Grab the url and identify the target textbox */ var vidUrl = $id('txtYouTubeURL').value; /* make sure we add the embed code to the right textbox ( a reply or a new comment) */ if(id_youtube_plugin.youtube_posted_from == 0) var textBox = $id('IDCommentNewThreadText'); else var textBox = $id('txtComment'); /* Check for valid match */ var regex=/https?:\/\/([a-zA-Z0-9]+\.)?youtube\.com\/watch\?v=([A-Za-z0-9_&=-]*)/ig; var m=regex.exec(vidUrl); /* If there is a match */ if(m && m.length>2) { /* 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 += "[youtube " + m[2] + " " + m[0] + " youtube]"; /* Hide the popup box */ hideMsgBox(); /* reset the regex */ regex.lastIndex=0; /* Give focus to the text box */ textBox.focus(); } else /* Failed to match the url */ alert('Unable to parse that url'); }; /* Disable the edit button for any comments that have a video */ id_youtube_plugin.id_youtube_disable_edit_buttons = function() { for(objElem in id_youtube_plugin.youtube_disabled_edit_ids) { if($id('IDCommentPostReplyLinkEdit'+id_youtube_plugin.youtube_disabled_edit_ids[objElem])) $id('IDCommentPostReplyLinkEdit'+id_youtube_plugin.youtube_disabled_edit_ids[objElem]).style.display = 'none'; } }; id_youtube_plugin.id_youtube_embed_replace = function(args) { var text = args['text']; //Check for valid match var youtube_regex=/\[youtube\s+([A-Za-z0-9_&=-]*)\s+(.*?)\s+youtube\]/ig; var m = youtube_regex.exec(text); //If there is a match if(m && m.length>1) { /* add the IntenseDebate commentid to the array of comments to disable editing for */ id_youtube_plugin.youtube_disabled_edit_ids[id_youtube_plugin.youtube_disabled_edit_ids.length] = args['commentid']; /* reset the regex */ youtube_regex.lastIndex=0; /* return the polldaddy div (where the poll will go */ return text.replace(youtube_regex, '
'); } else { /* reset the regex */ youtube_regex.lastIndex=0; return text; } }; /* add filter to swap embed code */ /*id_add_filter('comment_text_load', function (args) { var text=args['text']; var newtext = text.replace(/\[youtube /ig, '
'); });*/ id_add_filter('comment_text_load', id_youtube_plugin.id_youtube_embed_replace); id_add_action('idcomments_func_load',id_youtube_plugin.id_add_youtube_button); /* add youtube button on load */ id_add_action('user_login',id_youtube_plugin.id_youtube_disable_edit_buttons); /* disable edit buttons on login */ id_add_action('comment_post',id_youtube_plugin.id_youtube_disable_edit_buttons); /* disable edit buttons on comment post (for new comments w/ YouTube videos) */ CSS: #idc-container .idc-video_youtube { clear: both; float: none; margin: 1em auto; width: 480px !important; }