From a12133258ad685523e2ce793e6599861c64ee225 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 12:40:08 +0100 Subject: Refactored XHR forms: .form_user_subscribe .form_user_unsubscribe .form_favor .form_disfavor .form_group_join .form_group_leave .form_user_nudge Using FormXHR() --- js/util.js | 152 ++++++++++++++++++++----------------------------------------- 1 file changed, 50 insertions(+), 102 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index b079388e4..060510027 100644 --- a/js/util.js +++ b/js/util.js @@ -89,52 +89,6 @@ $(document).ready(function(){ } } - // XXX: refactor this code - - var favoptions = { dataType: 'xml', - beforeSubmit: function(data, target, options) { - $(target).addClass('processing'); - return true; - }, - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var dis = new_form.id; - var fav = dis.replace('disfavor', 'favor'); - $('form#'+fav).replaceWith(new_form); - $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden); - } - }; - - var disoptions = { dataType: 'xml', - beforeSubmit: function(data, target, options) { - $(target).addClass('processing'); - return true; - }, - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var fav = new_form.id; - var dis = fav.replace('favor', 'disfavor'); - $('form#'+dis).replaceWith(new_form); - $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden); - } - }; - - var joinoptions = { dataType: 'xml', - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var leave = new_form.id; - var join = leave.replace('leave', 'join'); - $('form#'+join).replaceWith(new_form); - $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden); - } - }; - - var leaveoptions = { dataType: 'xml', - success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); - var join = new_form.id; - var leave = join.replace('join', 'leave'); - $('form#'+leave).replaceWith(new_form); - $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden); - } - }; - function addAjaxHidden() { var ajax = document.createElement('input'); ajax.setAttribute('type', 'hidden'); @@ -143,62 +97,13 @@ $(document).ready(function(){ this.appendChild(ajax); } - $("form.form_favor").ajaxForm(favoptions); - $("form.form_disfavor").ajaxForm(disoptions); - $("form.form_group_join").ajaxForm(joinoptions); - $("form.form_group_leave").ajaxForm(leaveoptions); - $("form.form_favor").each(addAjaxHidden); - $("form.form_disfavor").each(addAjaxHidden); - $("form.form_group_join").each(addAjaxHidden); - $("form.form_group_leave").each(addAjaxHidden); - - $("#form_user_nudge").ajaxForm ({ dataType: 'xml', - beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled"); - $("#form_user_nudge input[type=submit]").addClass("disabled"); - }, - success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true)); - $("#form_user_nudge input[type=submit]").removeAttr("disabled"); - $("#form_user_nudge input[type=submit]").removeClass("disabled"); - } - }); - $("#form_user_nudge").each(addAjaxHidden); - - var Subscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled"); - $(".form_user_subscribe input[type=submit]").addClass("disabled"); - }, - success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true); - var form_unsubscribe_id = form_unsubscribe.id; - var form_subscribe_id = form_unsubscribe_id.replace('unsubscribe', 'subscribe'); - $("form#"+form_subscribe_id).replaceWith(form_unsubscribe); - $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden); - $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1); - $(".form_user_subscribe input[type=submit]").removeAttr("disabled"); - $(".form_user_subscribe input[type=submit]").removeClass("disabled"); - } - }; - - var UnSubscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled"); - $(".form_user_unsubscribe input[type=submit]").addClass("disabled"); - }, - success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true); - var form_subscribe_id = form_subscribe.id; - var form_unsubscribe_id = form_subscribe_id.replace('subscribe', 'unsubscribe'); - $("form#"+form_unsubscribe_id).replaceWith(form_subscribe); - $("form#"+form_subscribe_id).ajaxForm(Subscribe).each(addAjaxHidden); - $("#profile_send_a_new_message").remove(); - $("#profile_nudge").remove(); - $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1); - $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled"); - $(".form_user_unsubscribe input[type=submit]").removeClass("disabled"); - } - }; - - $(".form_user_subscribe").ajaxForm(Subscribe); - $(".form_user_unsubscribe").ajaxForm(UnSubscribe); - $(".form_user_subscribe").each(addAjaxHidden); - $(".form_user_unsubscribe").each(addAjaxHidden); + $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); var PostNotice = { dataType: 'xml', beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) { @@ -384,3 +289,46 @@ function NoticeDataAttach() { }); }); } + +var SN = { // StatusNet + C: { // Config + S: { // Selector + Disabled: 'disabled', + Warning: 'warning', + Error: 'error', + Processing: 'processing' + } + }, + + U: { // Utils + FormXHR: function(f) { + f.bind('submit', function(e) { + form_id = $(this)[0].id; + $.ajax({ + type: 'POST', + url: $(this)[0].action, + data: $(this).serialize() + '&ajax=1', + beforeSend: function(xhr) { + $('#'+form_id).addClass(SN.C.S.Processing); + $('#'+form_id+' .submit').addClass(SN.C.S.Disabled); + $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled); + }, + error: function (xhr, textStatus, errorThrown) { + alert(errorThrown || textStatus); + }, + success: function(data, textStatus) { + if ($('form', data)[0].length > 0) { + form_new = $('form', data)[0]; + $('#'+form_id).replaceWith(document._importNode(form_new, true)); + $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); + } + else { + $('#'+form_id).replaceWith(document._importNode($('p', data)[0], true)); + } + } + }); + return false; + }); + } + } +} -- cgit v1.2.3-54-g00ecf From 5a48a387fc20c5fbc1fb930e39fdbc5cf0862fbd Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:15:11 +0100 Subject: Updated form_notice --- js/util.js | 191 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 98 insertions(+), 93 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 060510027..77fbc1ee9 100644 --- a/js/util.js +++ b/js/util.js @@ -89,14 +89,6 @@ $(document).ready(function(){ } } - function addAjaxHidden() { - var ajax = document.createElement('input'); - ajax.setAttribute('type', 'hidden'); - ajax.setAttribute('name', 'ajax'); - ajax.setAttribute('value', 1); - this.appendChild(ajax); - } - $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); @@ -105,90 +97,8 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - var PostNotice = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) { - $("#form_notice").addClass("warning"); - return false; - } - $("#form_notice").addClass("processing"); - $("#notice_action-submit").attr("disabled", "disabled"); - $("#notice_action-submit").addClass("disabled"); - return true; - }, - timeout: '60000', - error: function (xhr, textStatus, errorThrown) { $("#form_notice").removeClass("processing"); - $("#notice_action-submit").removeAttr("disabled"); - $("#notice_action-submit").removeClass("disabled"); - if (textStatus == "timeout") { - alert ("Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists"); - } - else { - if ($(".error", xhr.responseXML).length > 0) { - $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); - } - else { - var HTTP20x30x = [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]; - if(jQuery.inArray(parseInt(xhr.status), HTTP20x30x) < 0) { - alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); - } - else { - $("#notice_data-text").val(""); - if (maxLength > 0) { - counter(); - } - } - } - } - }, - success: function(xml) { if ($("#error", xml).length > 0) { - var result = document._importNode($("p", xml).get(0), true); - result = result.textContent || result.innerHTML; - alert(result); - } - else { - if($('body')[0].id == 'bookmarklet') { - self.close(); - } - if ($("#command_result", xml).length > 0) { - var result = document._importNode($("p", xml).get(0), true); - result = result.textContent || result.innerHTML; - alert(result); - } - else { - li = $("li", xml).get(0); - if ($("#"+li.id).length == 0) { - var notice_irt_value = $('#notice_in-reply-to').val(); - var notice_irt = '#notices_primary #notice-'+notice_irt_value; - if($('body')[0].id == 'conversation') { - if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { - $(notice_irt).append(''); - } - $($(notice_irt+' .notices')[0]).append(document._importNode(li, true)); - } - else { - $("#notices_primary .notices").prepend(document._importNode(li, true)); - } - $('#'+li.id).css({display:'none'}); - $('#'+li.id).fadeIn(2500); - NoticeReply(); - NoticeAttachments(); - } - } - $("#notice_data-text").val(""); - $("#notice_data-attach").val(""); - $("#notice_in-reply-to").val(""); - $('#notice_data-attach_selected').remove(); - if (maxLength > 0) { - counter(); - } - } - $("#form_notice").removeClass("processing"); - $("#notice_action-submit").removeAttr("disabled"); - $("#notice_action-submit").removeClass("disabled"); - } - }; - $("#form_notice").ajaxForm(PostNotice); - $("#form_notice").each(addAjaxHidden); + SN.U.FormNoticeXHR(); + NoticeReply(); NoticeAttachments(); NoticeDataAttach(); @@ -292,11 +202,23 @@ function NoticeDataAttach() { var SN = { // StatusNet C: { // Config + I: { + NoticeTextCharMax: 140, + PatternUsername: /^[0-9a-zA-Z\-_.]*$/, + HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] + }, S: { // Selector Disabled: 'disabled', Warning: 'warning', Error: 'error', - Processing: 'processing' + Processing: 'processing', + CommendResult: 'command_result', + FormNotice: 'form_notice', + NoticeDataText: 'notice_data-text', + NoticeTextCount: 'notice_text-count', + NoticeInReplyTo: 'notice_in-reply-to', + NoticeDataAttach: 'notice_data-attach', + NoticeActionSubmit: 'notice_action-submit' } }, @@ -329,6 +251,89 @@ var SN = { // StatusNet }); return false; }); + }, + + FormNoticeXHR: function() { + $('#'+SN.C.S.FormNotice).append(''); + $('#'+SN.C.S.FormNotice).ajaxForm({ + timeout: '60000', + beforeSend: function(xhr) { + if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + return false; + } + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); + return true; + }, + error: function (xhr, textStatus, errorThrown) { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); + if (textStatus == 'timeout') { + alert ('Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists'); + } + else { + if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) { + $('#'+SN.C.S.FormNotice).append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); + } + else { + if(jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) < 0) { + alert('Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.'); + } + else { + SN.C.I.NoticeDataText.val(''); +// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + } + } + } + }, + success: function(data, textStatus) { + if ($('#'+SN.C.S.Error, data).length > 0) { + var result = document._importNode($('p', data)[0], true); + alert(result.textContent || result.innerHTML); + } + else { + if($('body')[0].id == 'bookmarklet') { + self.close(); + } + if ($('#'+SN.C.S.CommandResult, data).length > 0) { + var result = document._importNode($('p', data)[0], true); + alert(result.textContent || result.innerHTML); + } + else { + notice = $('li', data)[0]; + if ($('#'+notice.id).length === 0) { + var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); + var notice_irt = '#notices_primary #notice-'+notice_irt_value; + if($('body')[0].id == 'conversation') { + if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { + $(notice_irt).append(''); + } + $($(notice_irt+' .notices')[0]).append(document._importNode(notice, true)); + } + else { + $("#notices_primary .notices").prepend(document._importNode(notice, true)); + } + $('#'+notice.id).css({display:'none'}); + $('#'+notice.id).fadeIn(2500); +// SN.U.NoticeAttachments(); +// SN.U.NoticeReply(); + } + } + $('#'+SN.C.S.NoticeDataText).val(''); + $('#'+SN.C.S.NoticeDataAttach).val(''); + $('#'+SN.C.S.NoticeInReplyTo).val(''); +// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + } + }, + complete: function(xhr, textStatus) { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); + $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); + $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + } + }); } } } -- cgit v1.2.3-54-g00ecf From ad759b2bc81e3676cec61257c6080821b7569559 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:56:01 +0100 Subject: Updated NoticeReply and NoticeReplySet --- js/util.js | 65 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 77fbc1ee9..9874d614c 100644 --- a/js/util.js +++ b/js/util.js @@ -99,42 +99,12 @@ $(document).ready(function(){ SN.U.FormNoticeXHR(); - NoticeReply(); + SN.U.NoticeReply(); NoticeAttachments(); NoticeDataAttach(); }); -function NoticeReply() { - if ($('#notice_data-text').length > 0 && $('#content .notice_reply').length > 0) { - $('#content .notice').each(function() { - var notice = $(this)[0]; - $($('.notice_reply', notice)[0]).click(function() { - var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); - NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text()); - return false; - }); - }); - } -} -function NoticeReplySet(nick,id) { - rgx_username = /^[0-9a-zA-Z\-_.]*$/; - if (nick.match(rgx_username)) { - var text = $("#notice_data-text"); - if (text.length) { - replyto = "@" + nick + " "; - text.val(replyto + text.val().replace(RegExp(replyto, 'i'), '')); - $("#form_notice input#notice_in-reply-to").val(id); - if (text.get(0).setSelectionRange) { - var len = text.val().length; - text.get(0).setSelectionRange(len,len); - text.get(0).focus(); - } - return false; - } - } - return true; -} function NoticeAttachments() { $.fn.jOverlay.options = { @@ -319,7 +289,7 @@ var SN = { // StatusNet $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); // SN.U.NoticeAttachments(); -// SN.U.NoticeReply(); + SN.U.NoticeReply(); } } $('#'+SN.C.S.NoticeDataText).val(''); @@ -334,6 +304,37 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); } }); + }, + + NoticeReply: function() { + if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) { + $('#content .notice').each(function() { + var notice = $(this)[0]; + $($('.notice_reply', notice)[0]).click(function() { + var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); + SN.U.NoticeReplySet(nickname.text(), $($('.notice_id', notice)[0]).text()); + return false; + }); + }); + } + }, + + NoticeReplySet function(nick,id) { + if (nick.match(SN.C.I.PatternUsername)) { + var text = $('#'+SN.C.S.NoticeDataText); + if (text.length) { + replyto = '@' + nick + ' '; + text.val(replyto + text.val().replace(RegExp(replyto, 'i'), '')); + $('#'+SN.C.S.FormNotice+' input#'+SN.C.S.NoticeInReplyTo).val(id); + if (text.get(0).setSelectionRange) { + var len = text.val().length; + text.get(0).setSelectionRange(len,len); + text.get(0).focus(); + } + return false; + } + } + return true; } } } -- cgit v1.2.3-54-g00ecf From 0e5cf9b3b4002d4da092633150e0faf35b166dcf Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 13:56:53 +0100 Subject: Missing : --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 9874d614c..9182cb9f1 100644 --- a/js/util.js +++ b/js/util.js @@ -319,7 +319,7 @@ var SN = { // StatusNet } }, - NoticeReplySet function(nick,id) { + NoticeReplySet: function(nick,id) { if (nick.match(SN.C.I.PatternUsername)) { var text = $('#'+SN.C.S.NoticeDataText); if (text.length) { -- cgit v1.2.3-54-g00ecf From b55b2fa7d0667a635fad06af793ed00683f188b1 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:02:51 +0100 Subject: Updated NoticeAttachments --- js/util.js | 103 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 51 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 9182cb9f1..fcfc0b95a 100644 --- a/js/util.js +++ b/js/util.js @@ -100,62 +100,12 @@ $(document).ready(function(){ SN.U.FormNoticeXHR(); SN.U.NoticeReply(); - NoticeAttachments(); + SN.U.NoticeAttachments(); NoticeDataAttach(); }); -function NoticeAttachments() { - $.fn.jOverlay.options = { - method : 'GET', - data : '', - url : '', - color : '#000', - opacity : '0.6', - zIndex : 99, - center : false, - imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif', - bgClickToClose : true, - success : function() { - $('#jOverlayContent').append(''); - $('#jOverlayContent button').click($.closeOverlay); - }, - timeout : 0, - autoHide : true, - css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'} - }; - - $('#content .notice a.attachment').click(function() { - $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); - return false; - }); - - var t; - $("body:not(#shownotice) #content .notice a.thumbnail").hover( - function() { - var anchor = $(this); - $("a.thumbnail").children('img').hide(); - anchor.closest(".entry-title").addClass('ov'); - - if (anchor.children('img').length == 0) { - t = setTimeout(function() { - $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { - anchor.append(data); - }); - }, 500); - } - else { - anchor.children('img').show(); - } - }, - function() { - clearTimeout(t); - $("a.thumbnail").children('img').hide(); - $(this).closest(".entry-title").removeClass('ov'); - } - ); -} function NoticeDataAttach() { NDA = $('#notice_data-attach'); @@ -335,6 +285,57 @@ var SN = { // StatusNet } } return true; + }, + + NoticeAttachments: function() { + $.fn.jOverlay.options = { + method : 'GET', + data : '', + url : '', + color : '#000', + opacity : '0.6', + zIndex : 99, + center : false, + imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif', + bgClickToClose : true, + success : function() { + $('#jOverlayContent').append(''); + $('#jOverlayContent button').click($.closeOverlay); + }, + timeout : 0, + autoHide : true, + css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'} + }; + + $('#content .notice a.attachment').click(function() { + $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'}); + return false; + }); + + var t; + $("body:not(#shownotice) #content .notice a.thumbnail").hover( + function() { + var anchor = $(this); + $("a.thumbnail").children('img').hide(); + anchor.closest(".entry-title").addClass('ov'); + + if (anchor.children('img').length == 0) { + t = setTimeout(function() { + $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) { + anchor.append(data); + }); + }, 500); + } + else { + anchor.children('img').show(); + } + }, + function() { + clearTimeout(t); + $("a.thumbnail").children('img').hide(); + $(this).closest(".entry-title").removeClass('ov'); + } + ); } } } -- cgit v1.2.3-54-g00ecf From 53e91f22d231772199e11d29357a0c8d897a1c40 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:16:38 +0100 Subject: Updated NoticeDataAttach --- js/util.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index fcfc0b95a..203dca28e 100644 --- a/js/util.js +++ b/js/util.js @@ -101,25 +101,10 @@ $(document).ready(function(){ SN.U.NoticeReply(); SN.U.NoticeAttachments(); - NoticeDataAttach(); + SN.U.NoticeDataAttach(); }); - - -function NoticeDataAttach() { - NDA = $('#notice_data-attach'); - NDA.change(function() { - S = '
'+$(this).val()+'
'; - NDAS = $('#notice_data-attach_selected'); - (NDAS.length > 0) ? NDAS.replaceWith(S) : $('#form_notice').append(S); - $('#notice_data-attach_selected button').click(function(){ - $('#notice_data-attach_selected').remove(); - NDA.val(''); - }); - }); -} - var SN = { // StatusNet C: { // Config I: { @@ -131,6 +116,7 @@ var SN = { // StatusNet Disabled: 'disabled', Warning: 'warning', Error: 'error', + Success: 'success', Processing: 'processing', CommendResult: 'command_result', FormNotice: 'form_notice', @@ -138,6 +124,7 @@ var SN = { // StatusNet NoticeTextCount: 'notice_text-count', NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', + NoticeDataAttachSelected: 'notice_data-attach_selected', NoticeActionSubmit: 'notice_action-submit' } }, @@ -238,7 +225,7 @@ var SN = { // StatusNet } $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); -// SN.U.NoticeAttachments(); + SN.U.NoticeAttachments(); SN.U.NoticeReply(); } } @@ -336,6 +323,19 @@ var SN = { // StatusNet $(this).closest(".entry-title").removeClass('ov'); } ); + }, + + NoticeDataAttach: function() { + NDA = $('#'+SN.C.S.NoticeDataAttach); + NDA.change(function() { + S = '
'+$(this).val()+'
'; + NDAS = $('#'+SN.C.S.NoticeDataAttachSelected); + (NDAS.length > 0) ? NDAS.replaceWith(S) : $('#'+SN.C.S.FormNotice).append(S); + $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){ + $('#'+SN.C.S.NoticeDataAttachSelected).remove(); + NDA.val(''); + }); + }); } } } -- cgit v1.2.3-54-g00ecf From 1ddf69f30ef576e3090d43be9e3aca9ee24f6119 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 14:31:57 +0100 Subject: Updated SubmitOnReturn --- js/util.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 203dca28e..4ba1bcfba 100644 --- a/js/util.js +++ b/js/util.js @@ -56,18 +56,7 @@ $(document).ready(function(){ counter(null); } - function submitonreturn(event) { - if (event.keyCode == 13 || event.keyCode == 10) { - // iPhone sends \n not \r for 'return' - $("#form_notice").submit(); - event.preventDefault(); - event.stopPropagation(); - $("#notice_data-text").blur(); - $("body").focus(); - return false; - } - return true; - } + // define maxLength if it wasn't defined already @@ -82,7 +71,9 @@ $(document).ready(function(){ counter(); } - $("#notice_data-text").bind("keydown", submitonreturn); + $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); + }); if($('body')[0].id != 'conversation') { $("#notice_data-text").focus(); @@ -130,6 +121,18 @@ var SN = { // StatusNet }, U: { // Utils + SubmitOnReturn: function(event, el) { + if (event.keyCode == 13 || event.keyCode == 10) { + el.submit(); + event.preventDefault(); + event.stopPropagation(); + $('#'+SN.U.NoticeDataText).blur(); + $('body').focus(); + return false; + } + return true; + }, + FormXHR: function(f) { f.bind('submit', function(e) { form_id = $(this)[0].id; -- cgit v1.2.3-54-g00ecf From 4024a5ee65839d79d788d58b4fdd96893fe96360 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:43:41 +0100 Subject: Updated notice form counter --- js/util.js | 109 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 57 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 4ba1bcfba..10c7bb18e 100644 --- a/js/util.js +++ b/js/util.js @@ -17,68 +17,23 @@ */ $(document).ready(function(){ - var counterBlackout = false; - - // count character on keyup - function counter(event){ - if (maxLength <= 0) { - return; - } - var currentLength = $("#notice_data-text").val().length; - var remaining = maxLength - currentLength; - var counter = $("#notice_text-count"); - - if (remaining.toString() != counter.text()) { - if (!counterBlackout || remaining == 0) { - if (counter.text() != String(remaining)) { - counter.text(remaining); - } - - if (remaining < 0) { - $("#form_notice").addClass("warning"); - } else { - $("#form_notice").removeClass("warning"); - } - // Skip updates for the next 500ms. - // On slower hardware, updating on every keypress is unpleasant. - if (!counterBlackout) { - counterBlackout = true; - window.setTimeout(clearCounterBlackout, 500); - } - } - } - } - - function clearCounterBlackout() { - // Allow keyup events to poke the counter again - counterBlackout = false; - // Check if the string changed since we last looked - counter(null); - } - - - - // define maxLength if it wasn't defined already - - if (typeof(maxLength) == "undefined") { - maxLength = 140; - } - - if ($("#notice_data-text").length) { - if (maxLength > 0) { - $("#notice_data-text").bind("keyup", counter); - // run once in case there's something in there - counter(); - } + if ($('#'+SN.C.S.NoticeDataText).length) { + if (maxLength > 0) { + $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(); + }); + // run once in case there's something in there + SN.U.Counter(); + } $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); }); if($('body')[0].id != 'conversation') { - $("#notice_data-text").focus(); + $('#'+SN.C.S.NoticeDataText).focus(); } - } + } $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); @@ -99,7 +54,8 @@ $(document).ready(function(){ var SN = { // StatusNet C: { // Config I: { - NoticeTextCharMax: 140, + CounterBlackout: false, + MaxLength: 140, PatternUsername: /^[0-9a-zA-Z\-_.]*$/, HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] }, @@ -116,7 +72,7 @@ var SN = { // StatusNet NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', NoticeDataAttachSelected: 'notice_data-attach_selected', - NoticeActionSubmit: 'notice_action-submit' + NoticeActionSubmit: 'notice_action-submit', } }, @@ -133,6 +89,45 @@ var SN = { // StatusNet return true; }, + Counter: function() { + if (typeof(maxLength) == "undefined") { + maxLength = SN.C.I.MaxLength; + } + + if (maxLength <= 0) { + return; + } + + var remaining = maxLength - $('#'+SN.C.S.NoticeDataText).val().length; + var counter = $('#'+SN.C.S.NoticeTextCount); + + if (remaining.toString() != counter.text()) { + if (!SN.C.I.CounterBlackout || remaining == 0) { + if (counter.text() != String(remaining)) { + counter.text(remaining); + } + if (remaining < 0) { + $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + } else { + $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Warning); + } + // Skip updates for the next 500ms. + // On slower hardware, updating on every keypress is unpleasant. + if (!SN.C.I.CounterBlackout) { + SN.C.I.CounterBlackout = true; + window.setTimeout(SN.U.ClearCounterBlackout, 500); + } + } + } + }, + + ClearCounterBlackout: function() { + // Allow keyup events to poke the counter again + SN.C.I.CounterBlackout = false; + // Check if the string changed since we last looked + SN.U.Counter(null); + }, + FormXHR: function(f) { f.bind('submit', function(e) { form_id = $(this)[0].id; -- cgit v1.2.3-54-g00ecf From 02240a890ff804bcbca33568cfc73a827265256c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:48:35 +0100 Subject: Only run the scripts if the user is logged in --- js/util.js | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 10c7bb18e..3e8d244b7 100644 --- a/js/util.js +++ b/js/util.js @@ -17,37 +17,41 @@ */ $(document).ready(function(){ - if ($('#'+SN.C.S.NoticeDataText).length) { - if (maxLength > 0) { - $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + if ($('body.user_in').length > 0) { + if ($('#'+SN.C.S.NoticeDataText).length) { + if (maxLength > 0) { + $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(); + }); + // run once in case there's something in there SN.U.Counter(); + } + + $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); }); - // run once in case there's something in there - SN.U.Counter(); + + if($('body')[0].id != 'conversation') { + $('#'+SN.C.S.NoticeDataText).focus(); + } } - $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { - SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); - }); + $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); + $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); + $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); + $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - if($('body')[0].id != 'conversation') { - $('#'+SN.C.S.NoticeDataText).focus(); - } - } + SN.U.FormNoticeXHR(); - $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); - $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); - $('.form_favor').each(function() { SN.U.FormXHR($(this)); }); - $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); - $('.form_group_join').each(function() { SN.U.FormXHR($(this)); }); - $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); - $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); + SN.U.NoticeReply(); - SN.U.FormNoticeXHR(); + SN.U.NoticeDataAttach(); + } - SN.U.NoticeReply(); SN.U.NoticeAttachments(); - SN.U.NoticeDataAttach(); }); -- cgit v1.2.3-54-g00ecf From d16a989f49266b9f9790a13e5967cd9d580d9f54 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:49:47 +0100 Subject: Updated author documentation --- js/util.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 3e8d244b7..1519df252 100644 --- a/js/util.js +++ b/js/util.js @@ -14,6 +14,14 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . + * + * @category UI interaction + * @package StatusNet + * @author Sarven Capadisli + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ */ $(document).ready(function(){ -- cgit v1.2.3-54-g00ecf From 728ead799273d5665e211899874576f05de23329 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:51:52 +0100 Subject: Resetting counter after a notice submit --- js/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 1519df252..1b855caaf 100644 --- a/js/util.js +++ b/js/util.js @@ -201,7 +201,7 @@ var SN = { // StatusNet } else { SN.C.I.NoticeDataText.val(''); -// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + SN.U.Counter(); } } } @@ -242,7 +242,7 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeDataText).val(''); $('#'+SN.C.S.NoticeDataAttach).val(''); $('#'+SN.C.S.NoticeInReplyTo).val(''); -// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax); + SN.U.Counter(); } }, complete: function(xhr, textStatus) { -- cgit v1.2.3-54-g00ecf From 4c94eda3c8ce2f52c9979245bea13e9e44485b0a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:59:17 +0100 Subject: Added Init comment --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 1b855caaf..28e4fac8c 100644 --- a/js/util.js +++ b/js/util.js @@ -65,7 +65,7 @@ $(document).ready(function(){ var SN = { // StatusNet C: { // Config - I: { + I: { // Init CounterBlackout: false, MaxLength: 140, PatternUsername: /^[0-9a-zA-Z\-_.]*$/, -- cgit v1.2.3-54-g00ecf From cb8160dd8c7dc3ecfa0df3da1f6d5e9f3a6abcd0 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:21:03 +0100 Subject: Added missing dataType line for ajaxForm --- js/util.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 28e4fac8c..3d33b18f9 100644 --- a/js/util.js +++ b/js/util.js @@ -71,6 +71,7 @@ var SN = { // StatusNet PatternUsername: /^[0-9a-zA-Z\-_.]*$/, HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307] }, + S: { // Selector Disabled: 'disabled', Warning: 'warning', @@ -174,6 +175,7 @@ var SN = { // StatusNet $('#'+SN.C.S.FormNotice).append(''); $('#'+SN.C.S.FormNotice).ajaxForm({ timeout: '60000', + dataType: 'xml', beforeSend: function(xhr) { if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); -- cgit v1.2.3-54-g00ecf From 873ecb81e8e147ccf05c351de795798ec4d3ed58 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:41:52 +0000 Subject: Remove attachment view after XHR notice submit --- js/util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 3d33b18f9..638f8e6d1 100644 --- a/js/util.js +++ b/js/util.js @@ -223,7 +223,7 @@ var SN = { // StatusNet } else { notice = $('li', data)[0]; - if ($('#'+notice.id).length === 0) { + if ($('#'+notice.id).length == 0) { var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); var notice_irt = '#notices_primary #notice-'+notice_irt_value; if($('body')[0].id == 'conversation') { @@ -244,6 +244,7 @@ var SN = { // StatusNet $('#'+SN.C.S.NoticeDataText).val(''); $('#'+SN.C.S.NoticeDataAttach).val(''); $('#'+SN.C.S.NoticeInReplyTo).val(''); + $('#'+SN.C.S.NoticeDataAttachSelected).remove(); SN.U.Counter(); } }, -- cgit v1.2.3-54-g00ecf From 73e8c442409b5dcdb5d0affe364fb8fe50a90c37 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:47:32 +0000 Subject: IE doesn't like last comma. I understand. --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 638f8e6d1..10f962fd0 100644 --- a/js/util.js +++ b/js/util.js @@ -85,7 +85,7 @@ var SN = { // StatusNet NoticeInReplyTo: 'notice_in-reply-to', NoticeDataAttach: 'notice_data-attach', NoticeDataAttachSelected: 'notice_data-attach_selected', - NoticeActionSubmit: 'notice_action-submit', + NoticeActionSubmit: 'notice_action-submit' } }, -- cgit v1.2.3-54-g00ecf From e134f7ceb15435aaaeff65269a51c15a9a3552df Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 15:59:24 +0000 Subject: Using document importNode otherwise IE pukes --- js/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 10f962fd0..d1b34542e 100644 --- a/js/util.js +++ b/js/util.js @@ -146,6 +146,7 @@ var SN = { // StatusNet form_id = $(this)[0].id; $.ajax({ type: 'POST', + dataType: 'xml', url: $(this)[0].action, data: $(this).serialize() + '&ajax=1', beforeSend: function(xhr) { @@ -157,9 +158,9 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - if ($('form', data)[0].length > 0) { - form_new = $('form', data)[0]; - $('#'+form_id).replaceWith(document._importNode(form_new, true)); + form_new = document._importNode($('form', data).get(0), true); + if (form_new.length > 0) { + $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); } else { -- cgit v1.2.3-54-g00ecf From 93506faaa608efbcf264bb3f1f0ed363d81bb390 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:02:22 +0000 Subject: Minor --- js/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index d1b34542e..f8e71d440 100644 --- a/js/util.js +++ b/js/util.js @@ -158,7 +158,7 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - form_new = document._importNode($('form', data).get(0), true); + form_new = document._importNode($('form', data)[0], true); if (form_new.length > 0) { $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); -- cgit v1.2.3-54-g00ecf From 87781b85c4eb0925f04bfb9f1468d8b4a26af39a Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 16:06:11 +0000 Subject: Fixed Nudge XHR --- js/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index f8e71d440..75b9addb2 100644 --- a/js/util.js +++ b/js/util.js @@ -158,8 +158,8 @@ var SN = { // StatusNet alert(errorThrown || textStatus); }, success: function(data, textStatus) { - form_new = document._importNode($('form', data)[0], true); - if (form_new.length > 0) { + if (typeof($('form', data)[0]) != 'undefined') { + form_new = document._importNode($('form', data)[0], true); $('#'+form_id).replaceWith(form_new); $('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); } -- cgit v1.2.3-54-g00ecf From 900a0e2838e0c84649c3e09e683d0ad37dab9552 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 30 Oct 2009 21:11:56 +0000 Subject: Running through importNode before checking for id --- js/util.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index 75b9addb2..11b06298d 100644 --- a/js/util.js +++ b/js/util.js @@ -175,8 +175,8 @@ var SN = { // StatusNet FormNoticeXHR: function() { $('#'+SN.C.S.FormNotice).append(''); $('#'+SN.C.S.FormNotice).ajaxForm({ - timeout: '60000', dataType: 'xml', + timeout: '60000', beforeSend: function(xhr) { if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); @@ -223,7 +223,7 @@ var SN = { // StatusNet alert(result.textContent || result.innerHTML); } else { - notice = $('li', data)[0]; + notice = document._importNode($('li', data)[0], true); if ($('#'+notice.id).length == 0) { var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val(); var notice_irt = '#notices_primary #notice-'+notice_irt_value; @@ -231,10 +231,10 @@ var SN = { // StatusNet if(notice_irt_value.length > 0 && $(notice_irt+' .notices').length < 1) { $(notice_irt).append('
    '); } - $($(notice_irt+' .notices')[0]).append(document._importNode(notice, true)); + $($(notice_irt+' .notices')[0]).append(notice); } else { - $("#notices_primary .notices").prepend(document._importNode(notice, true)); + $("#notices_primary .notices").prepend(notice); } $('#'+notice.id).css({display:'none'}); $('#'+notice.id).fadeIn(2500); -- cgit v1.2.3-54-g00ecf From f9bb95174b93de4ce28167eea21535a01394f71f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 16:14:38 +0100 Subject: Added XHR for direct messages. --- actions/newmessage.php | 17 ++++++++++++++++- js/util.js | 28 ++++++++++++++++++++++++++++ theme/base/css/display.css | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) (limited to 'js/util.js') diff --git a/actions/newmessage.php b/actions/newmessage.php index eac4ab210..37fca1ca2 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -223,7 +223,22 @@ class NewmessageAction extends Action } $this->msg = $msg; - $this->showPage(); + if ($this->trimmed('ajax')) { + $this->startHTML('text/xml;charset=UTF-8'); + $this->elementStart('head'); + $this->element('title', null, _('New message')); + $this->elementEnd('head'); + $this->elementStart('body'); + if (common_logged_in()) { + $this->showNoticeForm(); + } + $this->elementEnd('div'); + $this->elementEnd('body'); + $this->endHTML(); + } + else { + $this->showPage(); + } } function showPageNotice() diff --git a/js/util.js b/js/util.js index 11b06298d..c7a3e8f88 100644 --- a/js/util.js +++ b/js/util.js @@ -57,6 +57,8 @@ $(document).ready(function(){ SN.U.NoticeReply(); SN.U.NoticeDataAttach(); + + SN.U.NewDirectMessage(); } SN.U.NoticeAttachments(); @@ -350,6 +352,32 @@ var SN = { // StatusNet NDA.val(''); }); }); + }, + + NewDirectMessage: function() { + NDM = $('.entity_send-a-message a'); + NDM.attr({'href':NDM.attr('href')+'&ajax=1'}); + NDM.click(function() { + var NDMF = $('.entity_send-a-message form'); + if (NDMF.length == 0) { + $.get(NDM.attr('href'), null, function(data) { + $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); + $('.entity_send-a-message textarea').focus(); + + NDMF = $('.entity_send-a-message form'); + NDMF.append(''); + $('.entity_send-a-message button').click(function(){ + NDMF.hide(); + return false; + }); + }); + } + else { + NDMF.show(); + $('.entity_send-a-message textarea').focus(); + } + return false; + }); } } } diff --git a/theme/base/css/display.css b/theme/base/css/display.css index c8aafe489..db6b08e63 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -670,6 +670,40 @@ border-radius:4px; margin-bottom:18px; } + +.entity_send-a-message button { +position:absolute; +top:0; +right:0; +} + +.entity_send-a-message #form_notice { +position:absolute; +top:34px; +right:-1px; +padding:1.795%; +width:65%; +z-index:1; + +background-color:#FFFFFF; +border:1px solid #CCCCCC; +-moz-box-shadow:3px 7px 5px rgba(194, 194, 194, 0.7); +-moz-border-radius:7px; +} +.entity_send-a-message #form_notice legend { +display:block; +margin-bottom:11px; +} + +.entity_send-a-message #form_notice label, +.entity_send-a-message #form_notice select { +display:none; +} +.entity_send-a-message input.submit { +text-align:center; +} + + .entity_tags ul { list-style-type:none; display:inline; -- cgit v1.2.3-54-g00ecf From dd50368cb23a3dd4a05c720d1f6b37c02d529ef4 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 18:01:19 +0100 Subject: Updated FormNoticeXHR to allow any form_notice as input (e.g., reused in XHR direct message) --- js/util.js | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index c7a3e8f88..a2950fcb3 100644 --- a/js/util.js +++ b/js/util.js @@ -40,7 +40,7 @@ $(document).ready(function(){ }); if($('body')[0].id != 'conversation') { - $('#'+SN.C.S.NoticeDataText).focus(); + $('.'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeDataText).focus(); } } @@ -52,7 +52,7 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - SN.U.FormNoticeXHR(); + SN.U.FormNoticeXHR($('.'+SN.C.S.FormNotice)); SN.U.NoticeReply(); @@ -80,7 +80,7 @@ var SN = { // StatusNet Error: 'error', Success: 'success', Processing: 'processing', - CommendResult: 'command_result', + CommandResult: 'command_result', FormNotice: 'form_notice', NoticeDataText: 'notice_data-text', NoticeTextCount: 'notice_text-count', @@ -174,38 +174,40 @@ var SN = { // StatusNet }); }, - FormNoticeXHR: function() { - $('#'+SN.C.S.FormNotice).append(''); - $('#'+SN.C.S.FormNotice).ajaxForm({ + FormNoticeXHR: function(form) { + form_id = form.attr('id'); + console.log(form_id); + form.append(''); + form.ajaxForm({ dataType: 'xml', timeout: '60000', beforeSend: function(xhr) { - if ($('#'+SN.C.S.NoticeDataText)[0].value.length === 0) { - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + if ($('#'+form_id+' #'+SN.C.S.NoticeDataText)[0].value.length === 0) { + form.addClass(SN.C.S.Warning); return false; } - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); + form.addClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).addClass(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).attr(SN.C.S.Disabled, SN.C.S.Disabled); return true; }, error: function (xhr, textStatus, errorThrown) { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); + form.removeClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled, SN.C.S.Disabled); if (textStatus == 'timeout') { alert ('Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists'); } else { if ($('.'+SN.C.S.Error, xhr.responseXML).length > 0) { - $('#'+SN.C.S.FormNotice).append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); + form.append(document._importNode($('.'+SN.C.S.Error, xhr.responseXML)[0], true)); } else { if(jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) < 0) { alert('Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.'); } else { - SN.C.I.NoticeDataText.val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); SN.U.Counter(); } } @@ -220,6 +222,7 @@ var SN = { // StatusNet if($('body')[0].id == 'bookmarklet') { self.close(); } + if ($('#'+SN.C.S.CommandResult, data).length > 0) { var result = document._importNode($('p', data)[0], true); alert(result.textContent || result.innerHTML); @@ -244,17 +247,17 @@ var SN = { // StatusNet SN.U.NoticeReply(); } } - $('#'+SN.C.S.NoticeDataText).val(''); - $('#'+SN.C.S.NoticeDataAttach).val(''); - $('#'+SN.C.S.NoticeInReplyTo).val(''); - $('#'+SN.C.S.NoticeDataAttachSelected).remove(); + $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataAttach).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeInReplyTo).val(''); + $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove(); SN.U.Counter(); } }, complete: function(xhr, textStatus) { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Processing); - $('#'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); - $('#'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); + form.removeClass(SN.C.S.Processing); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeAttr(SN.C.S.Disabled); + $('#'+form_id+' #'+SN.C.S.NoticeActionSubmit).removeClass(SN.C.S.Disabled); } }); }, @@ -362,14 +365,15 @@ var SN = { // StatusNet if (NDMF.length == 0) { $.get(NDM.attr('href'), null, function(data) { $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); - $('.entity_send-a-message textarea').focus(); + NDMF = $('.entity_send-a-message .form_notice'); + SN.U.FormNoticeXHR(NDMF); - NDMF = $('.entity_send-a-message form'); NDMF.append(''); $('.entity_send-a-message button').click(function(){ NDMF.hide(); return false; }); + $('.entity_send-a-message textarea').focus(); }); } else { -- cgit v1.2.3-54-g00ecf From 8a333805df5fc3786ef8abe1d71421fb9270ff7f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 31 Oct 2009 18:55:13 +0100 Subject: Updated counter, submitonreturn to be reused by any form. Created FormNoticeEnhancements to call those at one go for any form. --- js/util.js | 71 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'js/util.js') diff --git a/js/util.js b/js/util.js index a2950fcb3..663ec8986 100644 --- a/js/util.js +++ b/js/util.js @@ -26,23 +26,7 @@ $(document).ready(function(){ if ($('body.user_in').length > 0) { - if ($('#'+SN.C.S.NoticeDataText).length) { - if (maxLength > 0) { - $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) { - SN.U.Counter(); - }); - // run once in case there's something in there - SN.U.Counter(); - } - - $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) { - SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice)); - }); - - if($('body')[0].id != 'conversation') { - $('.'+SN.C.S.FormNotice+' #'+SN.C.S.NoticeDataText).focus(); - } - } + $('.'+SN.C.S.FormNotice).each(function() { SN.U.FormNoticeEnhancements($(this)); }); $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); }); @@ -52,8 +36,6 @@ $(document).ready(function(){ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); }); $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); }); - SN.U.FormNoticeXHR($('.'+SN.C.S.FormNotice)); - SN.U.NoticeReply(); SN.U.NoticeDataAttach(); @@ -92,19 +74,42 @@ var SN = { // StatusNet }, U: { // Utils + FormNoticeEnhancements: function(form) { + form_id = form.attr('id'); + if (maxLength > 0) { + $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + SN.U.Counter(form); + }); + // run once in case there's something in there + SN.U.Counter(form); + } + + $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, form); + }); + + if($('body')[0].id != 'conversation') { + $('#'+form_id+' textarea').focus(); + } + + SN.U.FormNoticeXHR(form); + }, + SubmitOnReturn: function(event, el) { if (event.keyCode == 13 || event.keyCode == 10) { el.submit(); event.preventDefault(); event.stopPropagation(); - $('#'+SN.U.NoticeDataText).blur(); + $('#'+el[0].id+' #'+SN.U.NoticeDataText).blur(); $('body').focus(); return false; } return true; }, - Counter: function() { + Counter: function(form) { + SN.C.I.FormNoticeCurrent = form; + form_id = form.attr('id'); if (typeof(maxLength) == "undefined") { maxLength = SN.C.I.MaxLength; } @@ -113,8 +118,8 @@ var SN = { // StatusNet return; } - var remaining = maxLength - $('#'+SN.C.S.NoticeDataText).val().length; - var counter = $('#'+SN.C.S.NoticeTextCount); + var remaining = maxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length; + var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount); if (remaining.toString() != counter.text()) { if (!SN.C.I.CounterBlackout || remaining == 0) { @@ -122,25 +127,26 @@ var SN = { // StatusNet counter.text(remaining); } if (remaining < 0) { - $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning); + form.addClass(SN.C.S.Warning); } else { - $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Warning); + form.removeClass(SN.C.S.Warning); } // Skip updates for the next 500ms. // On slower hardware, updating on every keypress is unpleasant. if (!SN.C.I.CounterBlackout) { SN.C.I.CounterBlackout = true; - window.setTimeout(SN.U.ClearCounterBlackout, 500); + SN.C.I.FormNoticeCurrent = form; + window.setTimeout("SN.U.ClearCounterBlackout(SN.C.I.FormNoticeCurrent);", 500); } } } }, - ClearCounterBlackout: function() { + ClearCounterBlackout: function(form) { // Allow keyup events to poke the counter again SN.C.I.CounterBlackout = false; // Check if the string changed since we last looked - SN.U.Counter(null); + SN.U.Counter(form); }, FormXHR: function(f) { @@ -176,7 +182,6 @@ var SN = { // StatusNet FormNoticeXHR: function(form) { form_id = form.attr('id'); - console.log(form_id); form.append(''); form.ajaxForm({ dataType: 'xml', @@ -208,7 +213,7 @@ var SN = { // StatusNet } else { $('#'+form_id+' #'+SN.C.S.NoticeDataText).val(''); - SN.U.Counter(); + SN.U.Counter($('#'+SN.C.S.FormNotice)); } } } @@ -251,7 +256,7 @@ var SN = { // StatusNet $('#'+form_id+' #'+SN.C.S.NoticeDataAttach).val(''); $('#'+form_id+' #'+SN.C.S.NoticeInReplyTo).val(''); $('#'+form_id+' #'+SN.C.S.NoticeDataAttachSelected).remove(); - SN.U.Counter(); + SN.U.Counter($('#'+SN.C.S.FormNotice)); } }, complete: function(xhr, textStatus) { @@ -366,14 +371,12 @@ var SN = { // StatusNet $.get(NDM.attr('href'), null, function(data) { $('.entity_send-a-message').append(document._importNode($('form', data).get(0), true)); NDMF = $('.entity_send-a-message .form_notice'); - SN.U.FormNoticeXHR(NDMF); - + SN.U.FormNoticeEnhancements(NDMF); NDMF.append(''); $('.entity_send-a-message button').click(function(){ NDMF.hide(); return false; }); - $('.entity_send-a-message textarea').focus(); }); } else { -- cgit v1.2.3-54-g00ecf