]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Updated 'more' anchor for attachments to do an XHR GET
[quix0rs-gnu-social.git] / js / util.js
index c6a9682de23782427b46f45d3e604890aa405df6..79fd40debac308343a840e9c6c08c9785fe2554d 100644 (file)
@@ -53,17 +53,16 @@ var SN = { // StatusNet
             NoticeLocationNs: 'notice_data-location_ns',
             NoticeGeoName: 'notice_data-geo_name',
             NoticeDataGeo: 'notice_data-geo',
-            NoticeDataGeoCookie: 'notice_data-geo_cookie',
-            NoticeDataGeoSelected: 'notice_data-geo_selected'
+            NoticeDataGeoCookie: 'NoticeDataGeo',
+            NoticeDataGeoSelected: 'notice_data-geo_selected',
+            StatusNetInstance:'StatusNetInstance'
         }
     },
 
     U: { // Utils
         FormNoticeEnhancements: function(form) {
-            form_id = form.attr('id');
-
             if (jQuery.data(form[0], 'ElementData') === undefined) {
-                MaxLength = $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text();
+                MaxLength = form.find('#'+SN.C.S.NoticeTextCount).text();
                 if (typeof(MaxLength) == 'undefined') {
                      MaxLength = SN.C.I.MaxLength;
                 }
@@ -71,7 +70,7 @@ var SN = { // StatusNet
 
                 SN.U.Counter(form);
 
-                NDT = $('#'+form_id+' #'+SN.C.S.NoticeDataText);
+                NDT = form.find('#'+SN.C.S.NoticeDataText);
 
                 NDT.bind('keyup', function(e) {
                     SN.U.Counter(form);
@@ -82,11 +81,11 @@ var SN = { // StatusNet
                 });
             }
             else {
-                $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
+                form.find('#'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
             }
 
-            if ($('body')[0].id != 'conversation') {
-                $('#'+form_id+' textarea').focus();
+            if ($('body')[0].id != 'conversation' && window.location.hash.length === 0) {
+                form.find('textarea').focus();
             }
         },
 
@@ -104,7 +103,6 @@ var SN = { // StatusNet
 
         Counter: function(form) {
             SN.C.I.FormNoticeCurrent = form;
-            form_id = form.attr('id');
 
             var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
 
@@ -112,8 +110,8 @@ var SN = { // StatusNet
                 return;
             }
 
-            var remaining = MaxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length;
-            var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount);
+            var remaining = MaxLength - form.find('#'+SN.C.S.NoticeDataText).val().length;
+            var counter = form.find('#'+SN.C.S.NoticeTextCount);
 
             if (remaining.toString() != counter.text()) {
                 if (!SN.C.I.CounterBlackout || remaining === 0) {
@@ -173,7 +171,6 @@ var SN = { // StatusNet
 
         FormNoticeXHR: function(form) {
             SN.C.I.NoticeDataGeo = {};
-            form_id = form.attr('id');
             form.append('<input type="hidden" name="ajax" value="1"/>');
             form.ajaxForm({
                 dataType: 'xml',
@@ -319,18 +316,12 @@ var SN = { // StatusNet
             }
         },
 
-        NoticeReplyTo: function(notice_item) {
-            var notice = notice_item[0];
-            var notice_reply = $('.notice_reply', notice)[0];
-
-            if (jQuery.data(notice_reply, "ElementData") === undefined) {
-                jQuery.data(notice_reply, "ElementData", {Bind:'submit'});
-                $(notice_reply).bind('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;
-                });
-            }
+        NoticeReplyTo: function(notice) {
+            notice.find('.notice_reply').live('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) {
@@ -356,42 +347,44 @@ var SN = { // StatusNet
         },
 
         NoticeRepeat: function() {
-            $('.form_repeat').live('click', function() {
-                SN.U.FormXHR($(this));
+            $('.form_repeat').live('click', function(e) {
+                e.preventDefault();
+
                 SN.U.NoticeRepeatConfirmation($(this));
                 return false;
             });
         },
 
         NoticeRepeatConfirmation: function(form) {
-            function NRC() {
-                form.closest('.notice-options').addClass('opaque');
-                form.addClass('dialogbox');
+            var submit_i = form.find('.submit');
 
-                form.append('<button class="close">&#215;</button>');
-                form.find('button.close').click(function(){
-                    $(this).remove();
+            var submit = submit_i.clone();
+            submit
+                .addClass('submit_dialogbox')
+                .removeClass('submit');
+            form.append(submit);
+            submit.bind('click', function() { SN.U.FormXHR(form); return false; });
 
-                    form.closest('.notice-options').removeClass('opaque');
-                    form.removeClass('dialogbox');
-                    form.find('.submit_dialogbox').remove();
-                    form.find('.submit').show();
+            submit_i.hide();
 
-                    return false;
-                });
-            };
+            form
+                .addClass('dialogbox')
+                .append('<button class="close">&#215;</button>')
+                .closest('.notice-options')
+                    .addClass('opaque');
 
-            form.find('.submit').bind('click', function(e) {
-                e.preventDefault();
+            form.find('button.close').click(function(){
+                $(this).remove();
 
-                var submit = form.find('.submit').clone();
-                submit.addClass('submit_dialogbox');
-                submit.removeClass('submit');
-                form.append(submit);
+                form
+                    .removeClass('dialogbox')
+                    .closest('.notice-options')
+                        .removeClass('opaque');
 
-                $(this).hide();
+                form.find('.submit_dialogbox').remove();
+                form.find('.submit').show();
 
-                NRC();
+                return false;
             });
         },
 
@@ -402,60 +395,75 @@ var SN = { // StatusNet
         },
 
         NoticeWithAttachment: function(notice) {
-            if ($('.attachment', notice).length === 0) {
+            if (notice.find('.attachment').length === 0) {
                 return;
             }
 
-            var notice_id = notice.attr('id');
-
-            $.fn.jOverlay.options = {
-                method : 'GET',
-                data : '',
-                url : '',
-                color : '#000',
-                opacity : '0.6',
-                zIndex : 9999,
-                center : false,
-                imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
-                bgClickToClose : true,
-                success : function() {
-                    $('#jOverlayContent').append('<button class="close">&#215;</button>');
-                    $('#jOverlayContent button').click($.closeOverlay);
-                },
-                timeout : 0,
-                autoHide : true,
-                css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
-            };
-
-            $('#'+notice_id+' a.attachment').click(function() {
-                $().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
-                return false;
-            });
+            var attachment_more = notice.find('.attachment.more');
+            if (attachment_more.length > 0) {
+                attachment_more.click(function() {
+                    $.get($(this).attr('href')+'/ajax', null, function(data) {
+                        notice.find('.entry-title .entry-content').html($(data).find('#attachment_view .entry-content').html());
+                    });
 
-            var t;
-            $("body:not(#shownotice) #"+notice_id+" 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();
+                    return false;
+                });
+            }
+            else {
+                $.fn.jOverlay.options = {
+                    method : 'GET',
+                    data : '',
+                    url : '',
+                    color : '#000',
+                    opacity : '0.6',
+                    zIndex : 9999,
+                    center : false,
+                    imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
+                    bgClickToClose : true,
+                    success : function() {
+                        $('#jOverlayContent').append('<button class="close">&#215;</button>');
+                        $('#jOverlayContent button').click($.closeOverlay);
+                    },
+                    timeout : 0,
+                    autoHide : true,
+                    css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
+                };
+
+                notice.find('a.attachment').click(function() {
+                    var attachId = ($(this).attr('id').substring('attachment'.length + 1));
+                    if (attachId) {
+                        $().jOverlay({url: $('address .url')[0].href+'attachment/' + attachId + '/ajax'});
+                        return false;
                     }
-                },
-                function() {
-                    clearTimeout(t);
-                    $("a.thumbnail").children('img').hide();
-                    $(this).closest(".entry-title").removeClass('ov');
+                });
+
+                if ($('#shownotice').length == 0) {
+                    var t;
+                    notice.find('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');
+                        }
+                    );
                 }
-            );
+            }
         },
 
         NoticeDataAttach: function() {
@@ -497,7 +505,7 @@ var SN = { // StatusNet
                 $('#'+SN.C.S.NoticeLocationId).val('');
                 $('#'+SN.C.S.NoticeDataGeo).attr('checked', false);
 
-                $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/', expires: SN.U.GetFullYear(2029, 0, 1) });
+                $.cookie(SN.C.S.NoticeDataGeoCookie, 'disabled', { path: '/' });
             }
 
             function getJSONgeocodeURL(geocodeURL, data) {
@@ -540,7 +548,7 @@ var SN = { // StatusNet
                         NDG: true
                     };
 
-                    $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/', expires: SN.U.GetFullYear(2029, 0, 1) });
+                    $.cookie(SN.C.S.NoticeDataGeoCookie, JSON.stringify(cookieValue), { path: '/' });
                 });
             }
 
@@ -668,6 +676,35 @@ var SN = { // StatusNet
             date.setFullYear(year, month, day);
 
             return date;
+        },
+
+        StatusNetInstance: {
+            Set: function(value) {
+                var SNI = SN.U.StatusNetInstance.Get();
+                if (SNI !== null) {
+                    value = $.extend(SNI, value);
+                }
+
+                $.cookie(
+                    SN.C.S.StatusNetInstance,
+                    JSON.stringify(value),
+                    {
+                        path: '/',
+                        expires: SN.U.GetFullYear(2029, 0, 1)
+                    });
+            },
+
+            Get: function() {
+                var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
+                if (cookieValue !== null) {
+                    return JSON.parse(cookieValue);
+                }
+                return null;
+            },
+
+            Delete: function() {
+                $.cookie(SN.C.S.StatusNetInstance, null);
+            }
         }
     },
 
@@ -705,6 +742,20 @@ var SN = { // StatusNet
 
                 SN.U.NewDirectMessage();
             }
+        },
+
+        Login: function() {
+            if (SN.U.StatusNetInstance.Get() !== null) {
+                var nickname = SN.U.StatusNetInstance.Get().Nickname;
+                if (nickname !== null) {
+                    $('#form_login #nickname').val(nickname);
+                }
+            }
+
+            $('#form_login').bind('submit', function() {
+                SN.U.StatusNetInstance.Set({Nickname: $('#form_login #nickname').val()});
+                return true;
+            });
         }
     }
 };
@@ -719,5 +770,8 @@ $(document).ready(function(){
     if ($('#content .entity_actions').length > 0) {
         SN.Init.EntityActions();
     }
+    if ($('#form_login').length > 0) {
+        SN.Init.Login();
+    }
 });