1var Comment = { 2 validate: function(form) { 3 var button = form.find('button'); 4 var error = false; 5 var field; 6 7 var isAnonymous = $('#comment-main-container').data('is-anonymous'); 8 9 if (isAnonymous) { 10 field = form.find('[name="o:email"]'); 11 var email = $.trim(field.val().replace(/\s+/g, ' ')); 12 if (Comment.validateEmail(email)) { 13 field.css('color', 'auto'); 14 } else { 15 field.css('color', 'red'); 16 error = true; 17 } 18 } 19 20 field = form.find('[name="o-module-comment:body"]'); 21 var text = $.trim(field.val().replace(/\s+/g, ' ')); 22 if (text.length == 0) { 23 field.val(''); 24 error = true; 25 } 26 27 if (error) { 28 return; 29 } 30 31 if (isAnonymous) { 32 var isOmeka = typeof Omeka !== 'undefined' && typeof Omeka.jsTranslate !== 'undefined'; 33 var legalAgreement = form.find('[name="legal_agreement"]'); 34 if (legalAgreement.length > 0 && !legalAgreement.prop('checked')) { 35 var msg = 'You should accept the legal agreement.'; 36 alert(isOmeka ? Omeka.jsTranslate(msg): msg) 37 return; 38 } 39 } 40 41 var url = form.attr('action'); 42 $.post({ 43 url: url, 44 data: form.serialize(), 45 timeout: 30000, 46 beforeSend: function() { 47 button.removeClass('fa-comment').addClass('o-icon-transmit'); 48 } 49 }) 50 .done(function(data) { 51 var msg; 52 if (!data.content) { 53 msg = 'Something went wrong'; 54 if (isOmeka) msg = Omeka.jsTranslate(msg); 55 alert(msg); 56 } else { 57 if (data.content.moderation) { 58 msg = 'Comment was added to the resource.'; 59 if (isOmeka) msg = Omeka.jsTranslate(msg);
60 var msgTmp = 'It will be displayed definively when approved.'; 61 msg += ' ' + (isOmeka ? Omeka.jsTranslate(msgTmp): msgTmp); 62 alert(msg); 63 } 64 location.reload(true); 65 } 66 }) 67 .fail(function(jqXHR, textStatus) { 68 if (textStatus == 'timeout') { 69 var msg = 'Request too long to process.'; 70 alert(isOmeka ? Omeka.jsTranslate(msg): msg) 71 } else if (jqXHR.status == 404) { 72 var msg = 'The resource doesnât exist.'; 73 alert(isOmeka ? Omeka.jsTranslate(msg): msg); 74 } else { 75 var hasMsg = jqXHR.hasOwnProperty('responseJSON') && typeof jqXHR.responseJSON.error !== 'undefined'; 76 var msg; 77 if (hasMsg) { 78 msg = jqXHR.responseJSON.error; 79 var messages = jqXHR.responseJSON.messages 80 if (messages) { 81 for (var inputField in messages) { 82 msg += ' ' + messages[inputField][Object.keys(messages[inputField])[0]]; 83 break; 84 } 85 } 86 } else { 87 msg = isOmeka ? Omeka .jsTranslate('Something went wrong'): 'Something went wrong'; 88 } 89 alert(msg); 90 } 91 }) 92 .always(function() { 93 button.removeClass('o-icon-transmit').addClass('fa-comment'); 94 }); 95 }, 96 97 validateEmail: function(email) { 98 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 99 return re.test(email); 100 }, 101 102 handleReply: function(event) { 103 Comment.moveForm(event); 104 }, 105 106 finalizeMove: function() { 107 $('#comment-form-body_parent').attr('style', ''); 108 }, 109 110 moveForm: function(event) { 111 $('#comment-form').insertAfter(event.target); 112 commentId = Comment.getCommentId(event.target); 113 $('#comment_parent_id').val(commentId); 114 }, 115 116 flag: function(event) { 117 var commentId = Comment.getCommentId(event.target); 118 var json = { 119 'id': commentId 120 }; 121 $.post(Comment.getBasePath() + '/flag', json, Comment.flagResponseHandler); 122 }, 123 124 unflag: function(event) { 125 var commentId = Comment.getCommentId(event.target); 126 var json = { 127 'id': commentId 128 }; 129 $.post(Comment.getBasePath() + '/unflag', json, Comment.flagResponseHandler); 130 }, 131 132 flagResponseHandler: function(response, status, jqxhr) { 133 var comment = $('#comment-' + response.id); 134 if (response.action == 'flagged') { 135 comment.find('.comment-body').first().addClass('comment-flagged'); 136 comment.find('.comment-flag').first().hide(); 137 comment.find('.comment-unflag').first().show(); 138 } 139 140 if (response.action == 'unflagged') { 141 comment.find('.comment-body').first().removeClass('comment-flagged'); 142 comment.find('.comment-flag').first().show(); 143 comment.find('.comment-unflag').first().hide(); 144 } 145 }, 146 147 getCommentId: function(el) { 148 return $(el).parents('.comment').first().attr('id').substring(8); 149 }, 150 151 getBasePath: function() { 152 return $('#comments').data('comment-url'); 153 } 154}; 155 156$(document).ready(function() { 157 $('.comment-reply').click(Comment.handleReply); 158 $('.comment-flag').click(Comment.flag); 159 $('.comment-unflag').click(Comment.unflag); 160 161 $('.comment-form button').on('click', function(e) { 162 e.preventDefault(); 163 Comment.validate($(this).closest('form')); 164 }); 165 166 $('.comment-form').submit(function(e) { 167 e.preventDefault(); 168 Comment.validate($(this)); 169 }); 170});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.