]> git.mxchange.org Git - friendica.git/blobdiff - js/main.js
catch comment format button also after ajax update
[friendica.git] / js / main.js
index a7ffca8d8620b0744babffa2d28d675e09485b77..e1e852cbaf655935fce69142f87ca02c642e5c86 100644 (file)
@@ -1,3 +1,7 @@
+  function resizeIframe(obj) {
+    obj.style.height = 0;
+    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
+  }
 
   function openClose(theID) {
     if(document.getElementById(theID).style.display == "block") { 
@@ -22,7 +26,6 @@
        var prev = null;
        var livetime = null;
        var force_update = false;
-       var msie = false;
        var stopped = false;
        var totStopped = false;
        var timer = null;
@@ -37,8 +40,6 @@
        $(function() {
                $.ajaxSetup({cache: false});
 
-               msie = $.browser.msie ;
-               
                /* setup tooltips *//*
                $("a,.tt").each(function(){
                        var e = $(this);
                        e.tipTip({defaultPosition: pos, edgeOffset: 8});
                });*/
                
+               /* setup comment textarea buttons */
+               /* comment textarea buttons needs some "data-*" attributes to work:
+                *              data-role="insert-formatting" : to mark the element as a formatting button
+                *              data-comment="<string>" : string for "Comment", used by insertFormatting() function
+                *              data-bbcode="<string>" : name of the bbcode element to insert. insertFormatting() will insert it as "[name][/name]"
+                *              data-id="<string>" : id of the comment, used to find other comment-related element, like the textarea
+                * */           
+               $('body').on('click','[data-role="insert-formatting"]', function(e) {
+                       e.preventDefault();
+                       var o = $(this);
+                       var comment = o.data('comment');
+                       var bbcode  = o.data('bbcode');
+                       var id = o.data('id');
+                       if (bbcode=="img") {
+                               $.colorbox({href: baseurl + "/fbrowser/image/?mode=minimal#comment-"+id, iframe:true,innerWidth:'500px',innerHeight:'400px'})
+                               return; 
+                       }
+                       
+                       insertFormatting(comment, bbcode, id);
+               });
+
+               /* event from comment textarea button popups */
+               /* insert returned bbcode at cursor position or replace selected text */
+               $("body").on("fbrowser.image.comment", function(e, filename, bbcode, id) {
+                       console.log("on", id);
+                       $.colorbox.close();
+                       var textarea = document.getElementById("comment-edit-text-" +id);
+                       var start = textarea.selectionStart;
+                       var end = textarea.selectionEnd;
+                       textarea.value = textarea.value.substring(0, start) + bbcode + textarea.value.substring(end, textarea.value.length);
+               });
+       
                
                
                /* setup onoff widgets */
                setupFieldRichtext();
 
                /* popup menus */
-       function close_last_popup_menu() {
-               if(last_popup_menu) {
-               last_popup_menu.hide();
-               last_popup_button.removeClass("selected");
-               last_popup_menu = null;
-               last_popup_button = null;
-               }
-               }
+               function close_last_popup_menu() {
+                       if(last_popup_menu) {
+                               last_popup_menu.hide();
+                               last_popup_button.removeClass("selected");
+                               last_popup_menu = null;
+                               last_popup_button = null;
+                       }
+               }
                $('a[rel^=#]').click(function(e){
+                       e.preventDefault();
+                       var parent = $(this).parent();
+                       var isSelected = (last_popup_button && parent.attr('id') == last_popup_button.attr('id'));
                        close_last_popup_menu();
+                       if(isSelected) return false;
                        menu = $( $(this).attr('rel') );
                        e.preventDefault();
                        e.stopPropagation();
                        if (menu.attr('popup')=="false") return false;
-                       $(this).parent().toggleClass("selected");
+                       parent.toggleClass("selected");
                        menu.toggle();
                        if (menu.css("display") == "none") {
                                last_popup_menu = null;
                                last_popup_button = null;
                        } else {
                                last_popup_menu = menu;
-                               last_popup_button = $(this).parent();
+                               last_popup_button = parent;
                        }
                        return false;
                });
                $('html').click(function() {
-                                               close_last_popup_menu();
+                       close_last_popup_menu();
                });
                
                // fancyboxes
-               /*$("a.popupbox").fancybox({
-                       'transitionIn' : 'elastic',
-                       'transitionOut' : 'elastic'
-               });*/
                $("a.popupbox").colorbox({
                        'inline' : true,
                        'transition' : 'elastic'
                                nnm = $("#nav-notifications-menu");
                                nnm.html(notifications_all + notifications_mark);
                                //nnm.attr('popup','true');
+
+                               var notification_lastitem = parseInt(localStorage.getItem("notification-lastitem"));
+                               var notification_id = 0;
                                eNotif.children("note").each(function(){
                                        e = $(this);
-                                       text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
-                                       html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
+                                       var text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
+                                       var seenclass = (e.attr('seen')==1)?"notify-seen":"notify-unseen";
+                                       var html = notifications_tpl.format(e.attr('href'),
+                                               e.attr('photo'),                    // {0}
+                                               text,                               // {1}
+                                               e.attr('date'),                     // {2}
+                                               seenclass,                          // {3}
+                                               new Date(e.attr('timestamp')*1000)  // {4}
+                                       );
                                        nnm.append(html);
                                });
+                               $(eNotif.children("note").get().reverse()).each(function(){
+                                       e = $(this);
+                                       notification_id = parseInt(e.attr('timestamp'));
+                                       if (notification_lastitem!== null && notification_id > notification_lastitem) {
+                                               if (getNotificationPermission()==="granted") {
+                                                       var notification = new Notification(document.title, {
+                                                                                         body: e.text().replace('&rarr; ','').format(e.attr('name')),
+                                                                                         icon: e.attr('photo'),
+                                                                                        });
+                                                       notification['url'] = e.attr('href');
+                                                       notification.addEventListener("click", function(ev){
+                                                               window.location = ev.target.url;
+                                                       });
+                                               }
+                                       }
+                                       
+                               });
+                               notification_lastitem = notification_id;
+                               localStorage.setItem("notification-lastitem", notification_lastitem)
 
                                $("img[data-src]", nnm).each(function(i, el){
                                        // Add src attribute for images with a data-src attribute
                        });
                        eSysmsg.children("info").each(function(){
                                text = $(this).text();
-                               $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
+                               $.jGrowl(text, { sticky: false, theme: 'info', life: 5000 });
                        });
                        
                });
                        if(livetime) {
                                clearTimeout(livetime);
                        }
-                       livetime = setTimeout(liveUpdate, 10000);
+                       livetime = setTimeout(liveUpdate, 5000);
                        return;
                }
                if(livetime != null)
                        force_update = true;
 
                var udargs = ((netargs.length) ? '/' + netargs : '');
-               var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0) + '&force=' + ((force_update) ? 1 : 0);
+               var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&force=' + ((force_update) ? 1 : 0);
 
                $.get(update_url,function(data) {
                        in_progress = false;
                                $('#star-' + ident).addClass('hidden');
                                $('#unstar-' + ident).removeClass('hidden');
                        }
-                       else {                  
+                       else {
                                $('#starred-' + ident).addClass('unstarred');
                                $('#starred-' + ident).removeClass('starred');
                                $('#star-' + ident).removeClass('hidden');
                                $('#unstar-' + ident).addClass('hidden');
                        }
-                       $('#like-rotator-' + ident).hide();     
+                       $('#like-rotator-' + ident).hide();
+               });
+       }
+
+       function doignore(ident) {
+               ident = ident.toString();
+               $('#like-rotator-' + ident).show();
+               $.get('ignored/' + ident, function(data) {
+                       if(data.match(/1/)) {
+                               $('#ignored-' + ident).addClass('ignored');
+                               $('#ignored-' + ident).removeClass('unignored');
+                               $('#ignore-' + ident).addClass('hidden');
+                               $('#unignore-' + ident).removeClass('hidden');
+                       }
+                       else {
+                               $('#ignored-' + ident).addClass('unignored');
+                               $('#ignored-' + ident).removeClass('ignored');
+                               $('#ignore-' + ident).removeClass('hidden');
+                               $('#unignore-' + ident).addClass('hidden');
+                       }
+                       $('#like-rotator-' + ident).hide();
                });
        }
 
@@ -686,6 +768,7 @@ function setupFieldRichtext(){
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "center",
                theme_advanced_blockformats : "blockquote,code",
+               theme_advanced_resizing : true,
                paste_text_sticky : true,
                entity_encoding : "raw",
                add_unload_trigger : false,
@@ -728,3 +811,18 @@ function previewTheme(elm) {
        });
 
 }
+
+// notification permission settings in localstorage
+// set by settings page
+function getNotificationPermission() {
+       if (window["Notification"] === undefined) {
+               return null;
+       }
+    if (Notification.permission === 'granted') {
+        var val = localStorage.getItem('notification-permissions');
+               if (val === null) return 'denied';
+               return val;
+    } else {
+        return Notification.permission;
+    }
+}