From ed1d212ae2daea5e4bd043417610177093e99f19 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 16 Jan 2016 03:03:51 -0500
Subject: [PATCH] Improved SVG cleanup code

---
 program/js/app.js |  127 +++++++++++++++++-------------------------
 1 files changed, 51 insertions(+), 76 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index e346356..45295c7 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -352,7 +352,7 @@
         if (this.gui_objects.mailboxlist) {
           this.env.unread_counts = {};
           this.gui_objects.folderlist = this.gui_objects.mailboxlist;
-          this.http_request('getunread');
+          this.http_request('getunread', {_page: this.env.current_page});
         }
 
         // init address book widget
@@ -2514,22 +2514,23 @@
   // removes messages that doesn't exists from list selection array
   this.update_selection = function()
   {
-    var selected = this.message_list.selection,
-      rows = this.message_list.rows,
+    var list = this.message_list,
+      selected = list.selection,
+      rows = list.rows,
       i, selection = [];
 
     for (i in selected)
       if (rows[selected[i]])
         selection.push(selected[i]);
 
-    this.message_list.selection = selection;
+    list.selection = selection;
 
     // reset preview frame, if currently previewed message is not selected (has been removed)
     try {
       var win = this.get_frame_window(this.env.contentframe),
         id = win.rcmail.env.uid;
 
-      if (id && $.inArray(id, selection) < 0)
+      if (id && !list.in_selection(id))
         this.show_contentframe(false);
     }
     catch (e) {};
@@ -3392,12 +3393,12 @@
     mailvelope.getKeyring(keyring).then(function(kr) {
       ref.mailvelope_keyring = kr;
       ref.mailvelope_init(action, kr);
-    }).catch(function(err) {
+    }, function(err) {
       // attempt to create a new keyring for this app/user
       mailvelope.createKeyring(keyring).then(function(kr) {
         ref.mailvelope_keyring = kr;
         ref.mailvelope_init(action, kr);
-      }).catch(function(err) {
+      }, function(err) {
         console.error(err);
       });
     });
@@ -3434,8 +3435,6 @@
     }
     else if (action == 'compose') {
       this.env.compose_commands.push('compose-encrypted');
-      // display the toolbar button
-      $('#' + this.buttons['compose-encrypted'][0].id).show();
 
       var is_html = $('input[name="_is_html"]').val() > 0;
 
@@ -3527,7 +3526,7 @@
             ref.remove_from_attachment_list(name);
           });
         }
-      }).catch(function(err) {
+      }, function(err) {
         console.error(err);
         console.log(options);
       });
@@ -3650,15 +3649,15 @@
 
           form.submit();
 
-        }).catch(function(err) {
+        }, function(err) {
           console.log(err);
         });  // mailvelope_editor.encrypt()
 
-      }).catch(function(err) {
+      }, function(err) {
         console.error(err);
       });  // mailvelope_keyring.validKeyForAddress(senders)
 
-    }).catch(function(err) {
+    }, function(err) {
       console.error(err);
     });  // mailvelope_keyring.validKeyForAddress(recipients)
 
@@ -3672,7 +3671,7 @@
       $(selector).addClass('mailvelope').children().not('iframe').hide();
       ref.hide_message(msgid);
       setTimeout(function() { $(window).resize(); }, 10);
-    }).catch(function(err) {
+    }, function(err) {
       console.error(err);
       ref.hide_message(msgid);
       ref.display_message('Message decryption failed: ' + err.message, 'error')
@@ -3728,7 +3727,7 @@
       if (missing_keys.length) {
         ref.display_message(ref.get_label('nopubkeyfor').replace('$email', missing_keys.join(', ')), 'warning');
       }
-    }, function() {
+    }).fail(function() {
       console.error('Pubkey lookup failed with', arguments);
       ref.hide_message(lock);
       ref.display_message('pubkeysearcherror', 'error');
@@ -3826,7 +3825,7 @@
               btn.closest('.key').fadeOut();
               ref.display_message(ref.get_label('keyimportsuccess').replace('$key', $key), 'confirmation');
             }
-          }).catch(function(err) {
+          }, function(err) {
             console.log(err);
           });
         });
@@ -4315,7 +4314,7 @@
       '<textarea name="text" id="ffresponsetext" cols="40" rows="8"></textarea></div>' +
       '</form>';
 
-    buttons[this.gettext('save')] = function(e) {
+    buttons[this.get_label('save')] = function(e) {
       var name = $('#ffresponsename').val(),
         text = $('#ffresponsetext').val();
 
@@ -4331,11 +4330,11 @@
       $(this).dialog('close');
     };
 
-    buttons[this.gettext('cancel')] = function() {
+    buttons[this.get_label('cancel')] = function() {
       $(this).dialog('close');
     };
 
-    this.show_popup_dialog(html, this.gettext('newresponse'), buttons, {button_classes: ['mainaction']});
+    this.show_popup_dialog(html, this.get_label('newresponse'), buttons, {button_classes: ['mainaction']});
 
     $('#ffresponsetext').val(text);
     $('#ffresponsename').select();
@@ -5571,7 +5570,7 @@
       // add link to pop back to parent group
       if (this.env.address_group_stack.length > 1) {
         $('<a href="#list">...</a>')
-          .attr('title', this.gettext('uponelevel'))
+          .attr('title', this.get_label('uponelevel'))
           .addClass('poplink')
           .appendTo(boxtitle)
           .click(function(e){ return ref.command('popgroup','',this); });
@@ -7926,8 +7925,11 @@
   };
 
   // send a http request to the server
-  this.http_request = function(action, data, lock)
+  this.http_request = function(action, data, lock, type)
   {
+    if (type != 'POST')
+      type = 'GET';
+
     if (typeof data !== 'object')
       data = rcube_parse_query(data);
 
@@ -7951,60 +7953,26 @@
       }
     }
 
-    var url = this.url(action, data);
-
-    // send request
-    this.log('HTTP GET: ' + url);
+    var url = this.url(action);
 
     // reset keep-alive interval
     this.start_keepalive();
 
+    // send request
     return $.ajax({
-      type: 'GET', url: url, dataType: 'json',
+      type: type, url: url, data: data, dataType: 'json',
       success: function(data) { ref.http_response(data); },
       error: function(o, status, err) { ref.http_error(o, status, err, lock, action); }
     });
   };
 
+  // send a http GET request to the server
+  this.http_get = this.http_request;
+
   // send a http POST request to the server
   this.http_post = function(action, data, lock)
   {
-    if (typeof data !== 'object')
-      data = rcube_parse_query(data);
-
-    data._remote = 1;
-    data._unlock = lock ? lock : 0;
-
-    // trigger plugin hook
-    var result = this.triggerEvent('request'+action, data);
-
-    // abort if one of the handlers returned false
-    if (result === false) {
-      if (data._unlock)
-        this.set_busy(false, null, data._unlock);
-      return false;
-    }
-    else if (result !== undefined) {
-      data = result;
-      if (data._action) {
-        action = data._action;
-        delete data._action;
-      }
-    }
-
-    var url = this.url(action);
-
-    // send request
-    this.log('HTTP POST: ' + url);
-
-    // reset keep-alive interval
-    this.start_keepalive();
-
-    return $.ajax({
-      type: 'POST', url: url, data: data, dataType: 'json',
-      success: function(data){ ref.http_response(data); },
-      error: function(o, status, err) { ref.http_error(o, status, err, lock, action); }
-    });
+    return this.http_request(action, data, lock, 'POST');
   };
 
   // aborts ajax request
@@ -8409,7 +8377,7 @@
   // html5 file-drop API
   this.document_drag_hover = function(e, over)
   {
-    e.preventDefault();
+    // don't e.preventDefault() here to not block text dragging on the page (#1490619)
     $(this.gui_objects.filedrop)[(over?'addClass':'removeClass')]('active');
   };
 
@@ -8441,7 +8409,7 @@
       if (uri = e.dataTransfer.getData('roundcube-uri')) {
         var ts = new Date().getTime(),
           // jQuery way to escape filename (#1490530)
-          content = $('<span>').text(e.dataTransfer.getData('roundcube-name') || this.gettext('attaching')).html();
+          content = $('<span>').text(e.dataTransfer.getData('roundcube-name') || this.get_label('attaching')).html();
 
         args._uri = uri;
         args._uploadid = ts;
@@ -8787,14 +8755,10 @@
     if (!this.env.browser_capabilities)
       this.env.browser_capabilities = {};
 
-    if (this.env.browser_capabilities.pdf === undefined)
-      this.env.browser_capabilities.pdf = this.pdf_support_check();
-
-    if (this.env.browser_capabilities.flash === undefined)
-      this.env.browser_capabilities.flash = this.flash_support_check();
-
-    if (this.env.browser_capabilities.tif === undefined)
-      this.tif_support_check();
+    $.each(['pdf', 'flash', 'tif'], function() {
+      if (ref.env.browser_capabilities[this] === undefined)
+        ref.env.browser_capabilities[this] = ref[this + '_support_check']();
+    });
   };
 
   // Returns browser capabilities string
@@ -8813,11 +8777,14 @@
 
   this.tif_support_check = function()
   {
-    var img = new Image();
+    window.setTimeout(function() {
+      var img = new Image();
+      img.onload = function() { ref.env.browser_capabilities.tif = 1; };
+      img.onerror = function() { ref.env.browser_capabilities.tif = 0; };
+      img.src = ref.assets_path('program/resources/blank.tif');
+    }, 10);
 
-    img.onload = function() { ref.env.browser_capabilities.tif = 1; };
-    img.onerror = function() { ref.env.browser_capabilities.tif = 0; };
-    img.src = this.assets_path('program/resources/blank.tif');
+    return 0;
   };
 
   this.pdf_support_check = function()
@@ -8853,6 +8820,14 @@
         return 1;
     }
 
+    window.setTimeout(function() {
+      $('<object>').css({position: 'absolute', left: '-10000px'})
+        .attr({data: ref.assets_path('program/resources/dummy.pdf'), width: 1, height: 1, type: 'application/pdf'})
+        .load(function() { ref.env.browser_capabilities.pdf = 1; })
+        .error(function() { ref.env.browser_capabilities.pdf = 0; })
+        .appendTo($('body'));
+      }, 10);
+
     return 0;
   };
 

--
Gitblit v1.9.1