Auto hide mailto_handler link if browser does not support it
authorMichael M Slusarz <slusarz@curecanti.org>
Sat, 2 Oct 2010 08:34:02 +0000 (02:34 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 3 Oct 2010 20:26:08 +0000 (14:26 -0600)
imp/config/prefs.php.dist
imp/lib/Prefs/Ui.php
imp/templates/prefs/mailto.html [new file with mode: 0644]

index 1c5df8f..38522d1 100644 (file)
@@ -430,14 +430,7 @@ $prefGroups['compose'] = array(
 
 // Link to add a Firefox 3 mailto: handler
 $_prefs['mailto_handler'] = array(
-    'type' => 'link',
-    'img' => 'compose.png',
-    'xurl' => 'javascript:if(typeof navigator.registerProtocolHandler==\'undefined\')alert(\''
-        . addslashes(_("Your browser does not support this feature."))
-        . '\');else navigator.registerProtocolHandler(\'mailto\',\''
-        . Horde::url('compose.php', true)->setRaw(true)->add(array('actionID' => 'mailto_link', 'to' => ''))
-        . '%s\',\'' . $GLOBALS['registry']->get('name') . '\');',
-    'desc' => sprintf(_("Click here to open all mailto: links in %s."), $GLOBALS['registry']->get('name'))
+    'type' => 'special'
 );
 
 // Show Cc: field?
index 38fd297..f86c855 100644 (file)
@@ -394,6 +394,9 @@ class IMP_Prefs_Ui
         case 'initialpageselect':
             return $this->_initialPage();
 
+        case 'mailto_handler':
+            return $this->_mailtoHandler();
+
         case 'pgpprivatekey':
             return $this->_pgpPrivateKey($ui);
 
@@ -1053,6 +1056,36 @@ class IMP_Prefs_Ui
         return $t->fetch(IMP_TEMPLATES . '/prefs/initialpage.html');
     }
 
+    /* Mailto: handler. */
+
+    /**
+     * Create code for the mailto handler link.
+     *
+     * @return string  HTML UI code.
+     */
+    protected function _mailtoHandler()
+    {
+        Horde::addInlineScript(array(
+            'if (!Object.isUndefined(navigator.registerProtocolHandler))' .
+            '$("mailto_handler").show().down("A").observe("click", function() {' .
+                'navigator.registerProtocolHandler("mailto","' .
+                Horde::url('compose.php', true)->setRaw(true)->add(array(
+                    'actionID' => 'mailto_link',
+                    'to' => ''
+                )) .
+                '%s","' . $GLOBALS['registry']->get('name') . '");' .
+            '})'
+        ), 'dom');
+
+        $t = $GLOBALS['injector']->createInstance('Horde_Template');
+        $t->setOption('gettext', true);
+
+        $t->set('desc', sprintf(_("Click here to open all mailto: links using %s."), $GLOBALS['registry']->get('name')));
+        $t->set('img', Horde::img('compose.png'));
+
+        return $t->fetch(IMP_TEMPLATES . '/prefs/mailto.html');
+    }
+
     /* PGP Private Key management. */
 
     /**
diff --git a/imp/templates/prefs/mailto.html b/imp/templates/prefs/mailto.html
new file mode 100644 (file)
index 0000000..d9be1a2
--- /dev/null
@@ -0,0 +1,4 @@
+<div id="mailto_handler" style="display:none">
+ <tag:img />
+ <a href="#"><strong><tag:desc /></strong></a>
+</div>