diff options
author | Brion Vibber <brion@pobox.com> | 2010-03-29 15:15:51 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-03-29 15:15:51 -0700 |
commit | 01a03e34c8d286011c0f4301e60c103d992a449a (patch) | |
tree | d9c5a44704b83d3ca05ed1f136a3748fb8210f12 /js/util.js | |
parent | e2d3ebb9f4a3b516067745d250b4723367b928c2 (diff) | |
parent | cfeb1bfa419e886a1b60dfcbd4260d2f5de0515b (diff) |
Merge branch '0.9.x' into 1.0.x
Diffstat (limited to 'js/util.js')
-rw-r--r-- | js/util.js | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/js/util.js b/js/util.js index 60eeb418f..d62adf33a 100644 --- a/js/util.js +++ b/js/util.js @@ -30,7 +30,8 @@ var SN = { // StatusNet 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] + HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307], + UploadCounter: 0 }, S: { // Selector @@ -172,6 +173,7 @@ var SN = { // StatusNet FormNoticeXHR: function(form) { SN.C.I.NoticeDataGeo = {}; form.append('<input type="hidden" name="ajax" value="1"/>'); + form.ajaxForm({ dataType: 'xml', timeout: '60000', @@ -228,9 +230,10 @@ var SN = { // StatusNet } else { if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) { - form - .resetForm() - .find('#'+SN.C.S.NoticeDataAttachSelected).remove(); + form.resetForm(); + SN.U.NoticeClearAttachments(form); + SN.C.I.UploadCounter = 0; + SN.U.NoticeNewAttachment($('fieldset', form)); SN.U.FormNoticeEnhancements(form); } else { @@ -287,8 +290,9 @@ var SN = { // StatusNet } } form.resetForm(); - form.find('#'+SN.C.S.NoticeInReplyTo).val(''); - form.find('#'+SN.C.S.NoticeDataAttachSelected).remove(); + SN.U.NoticeClearAttachments(form); + SN.C.I.UploadCounter = 0; + SN.U.NoticeNewAttachment($('fieldset', form)); SN.U.FormNoticeEnhancements(form); } }, @@ -309,6 +313,11 @@ var SN = { // StatusNet } }); }, + + NoticeClearAttachments: function(form) { + $('input:file', form).remove(); + $('div[class=' + SN.C.S.Success + ']', form).remove(); + }, NoticeReply: function() { if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) { @@ -401,10 +410,11 @@ var SN = { // StatusNet var attachment_more = notice.find('.attachment.more'); if (attachment_more.length > 0) { - attachment_more.click(function() { - $(this).addClass(SN.C.S.Processing); - $.get($(this).attr('href')+'/ajax', null, function(data) { - notice.find('.entry-title .entry-content').html($(data).find('#attachment_view .entry-content').html()); + $(attachment_more[0]).click(function() { + var m = $(this); + m.addClass(SN.C.S.Processing); + $.get(m.attr('href')+'/ajax', null, function(data) { + m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html()); }); return false; @@ -467,25 +477,31 @@ var SN = { // StatusNet } }, - NoticeDataAttach: function() { - NDA = $('#'+SN.C.S.NoticeDataAttach); + NoticeDataAttach: function(NDANum) { + NDA = $('#'+SN.C.S.NoticeDataAttach+NDANum); NDA.change(function() { - S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>'; - NDAS = $('#'+SN.C.S.NoticeDataAttachSelected); - if (NDAS.length > 0) { - NDAS.replaceWith(S); - } - else { - $('#'+SN.C.S.FormNotice).append(S); - } - $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){ - $('#'+SN.C.S.NoticeDataAttachSelected).remove(); + S = '<div id="'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">×</button></div>'; + $('#'+SN.C.S.FormNotice).append(S); + + $('#'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+' button').click(function(){ + $('#'+this.parentNode.getAttribute("id")).remove(); + $('#'+this.parentNode.getAttribute("id").replace("_selected", "")).remove(); NDA.val(''); return false; }); + SN.C.I.UploadCounter++; + NDA.attr('style', 'display: none;'); + SN.U.NoticeNewAttachment(NDA.parent()); + $('#notice_data-attach-label').attr('for', SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter); }); }, + + NoticeNewAttachment: function(parent) { + NEWFILE = '<input id="'+SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter+'" class="attach" type="file" name="attach'+SN.C.I.UploadCounter+'" title="'+NoticeAttachment_text.AttachFile+'"/>'; + parent.append(NEWFILE); + SN.U.NoticeDataAttach(SN.C.I.UploadCounter); + }, NoticeLocationAttach: function() { var NLat = $('#'+SN.C.S.NoticeLat).val(); @@ -719,7 +735,7 @@ var SN = { // StatusNet SN.U.FormNoticeEnhancements($(this)); }); - SN.U.NoticeDataAttach(); + SN.U.NoticeDataAttach(""); } }, |