/** * Scalar * Copyright 2013 The Alliance for Networking Visual Culture. * http://scalar.usc.edu/scalar * Alliance4NVC@gmail.com * * Licensed under the Educational Community License, Version 2.0 * (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.osedu.org/licenses /ECL-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an "AS IS" * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing * permissions and limitations under the License. */ /** * @projectDescription Handle the display of the comment box * @abstract This is a simple port from Scalar2 -- to keep things simple this is a set of functions rather than a plugin * @author Craig Dietrich * @version 1.1 */ function commentFormDisplayForm() { // Display comment box and scroll to its top document.location.hash = 'comments'; var $comments = $('#comments') $comments.fadeIn('fast'); window.scrollTo(0,parseInt($comments.offset().top)); // Close button $('#comments #close_link').on('click', function() { document.location.hash=''; $('#comments').hide(); }); // Check whether a user is logged in or not, and change the UI accordingly var parent = $('link#parent').attr('href'); var check_login_url = parent+'login_status'; $.post(check_login_url, function(data) { $('#checking_logged_in_status').hide(); if (data.is_logged_in) { if ('undefined'==data.user_id || !data.user_id) return alert('Could not determine your user ID. Please try logging in again.'); $('#comment_user_id').val(data.user_id); $commenter_logged_in = $('#commenter_logged_in'); $commenter_logged_in.fadeIn('fast'); $commenter_logged_in.find('[title="Your user page"]').attr('href', parent+'users/'+data.user_id).html(data.fullname); $commenter_logged_in.find('[title="Logout"]').on('click', function() { var url = document.location.href; if (url.indexOf('#')!=-1) url = url.substr(0, url.indexOf('#')); var url_append = 'action=do_logout&redirect_url='+encodeURIComponent(url+'#comments'); if (url.indexOf('?')!=-1) { url += '&'+url_append; } else { url += '?'+url_append; } document.location.href=url; return false; }); $('#comment_your_name').hide(); $('#comment_captcha').hide(); } else { $('#commenter_anonymous').fadeIn('fast'); $('#comment_your_name').show(); $('#comment_captcha').show(); var recaptcha2_site_key = $('input[name="recaptcha2_site_key"]:first').val(); var recaptcha_public_key = $('input[name="recaptcha_public_key"]:first').val(); if ('undefined'==typeof(grecaptcha) && 'undefined'==typeof(Recaptcha)) { alert('There was a problem contacting ReCAPTCHA to create CAPTCHA test. Please reload the page and try again.') } else if (!recaptcha2_site_key.length && !recaptcha_public_key.length) { alert('No ReCAPTCHA key is provided, therefore anonymous commenting is disabled.'); } else { if (recaptcha2_site_key.length) { grecaptcha.render("comment_captcha_wrapper", { 'sitekey' : recaptcha2_site_key }); } else if (recaptcha_public_key.length) { Recaptcha.create(recaptcha_public_key, "comment_captcha_wrapper", { theme: "white" }); } } } $('#comment_form_wrapper').fadeIn('fast'); }); } function popoutComments() { var title = strip_tags($('#comments .comments .content_title:first').html()); var content = $('#comments .comments').html(); var $content = $('