- $('.'+SN.C.S.FormNotice).each(function() {
- var form = $(this);
- SN.U.NoticeLocationAttach(form);
- SN.U.FormNoticeXHR(form);
- SN.U.FormNoticeEnhancements(form);
- SN.U.NoticeDataAttach(form);
+ // SN.Init.NoticeFormSetup() will get run
+ // when forms get displayed for the first time...
+
+ // Hack to initialize the placeholder at top
+ $('#input_form_placeholder input.placeholder').focus(function() {
+ SN.U.switchInputFormTab("status");
+ });
+
+ // Make inline reply forms self-close when clicking out.
+ $('body').bind('click', function(e) {
+ var currentForm = $('#content .input_forms div.current');
+ if (currentForm.length > 0) {
+ if ($('#content .input_forms').has(e.target).length == 0) {
+ // If all fields are empty, switch back to the placeholder.
+ var fields = currentForm.find('textarea, input[type=text], input[type=""]');
+ var anything = false;
+ fields.each(function() {
+ anything = anything || $(this).val();
+ });
+ if (!anything) {
+ SN.U.switchInputFormTab("placeholder");
+ }
+ }
+ }
+
+ var openReplies = $('li.notice-reply');
+ if (openReplies.length > 0) {
+ var target = $(e.target);
+ openReplies.each(function() {
+ // Did we click outside this one?
+ var replyItem = $(this);
+ if (replyItem.has(e.target).length == 0) {
+ var textarea = replyItem.find('.notice_data-text:first');
+ var cur = $.trim(textarea.val());
+ // Only close if there's been no edit.
+ if (cur == '' || cur == textarea.data('initialText')) {
+ var parentNotice = replyItem.closest('li.notice');
+ replyItem.remove();
+ parentNotice.find('li.notice-reply-placeholder').show();
+ }
+ }
+ });
+ }