From 5f660cd7c4662c30921b76b04a7b9d92e82182df Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 02 Oct 2008 04:39:49 -0400
Subject: [PATCH] - Minimize "inline" javascript use (#1485433)

---
 skins/default/templates/editidentity.html  |    6 
 CHANGELOG                                  |    4 
 /dev/null                                  |   14 --
 skins/default/templates/mail.html          |   48 -------
 skins/default/templates/addcontact.html    |    1 
 skins/default/templates/managefolders.html |    5 
 skins/default/functions.js                 |  135 ++++++++++++++++++++++
 skins/default/templates/compose.html       |   68 -----------
 skins/default/templates/editcontact.html   |    1 
 skins/default/templates/identities.html    |    5 
 skins/default/templates/settings.html      |   16 --
 11 files changed, 153 insertions(+), 150 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index f370ea8..29024a7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,10 @@
 CHANGELOG RoundCube Webmail
 ---------------------------
 
+2008/10/02 (alec)
+----------
+- Minimize "inline" javascript scripts use (#1485433)
+
 2008/10/01 (alec)
 - Fix spellchecking when switching to html editor (#1485362)
 - Fix compose window width/height (#1485396)
diff --git a/skins/default/functions.js b/skins/default/functions.js
new file mode 100644
index 0000000..1d8ac02
--- /dev/null
+++ b/skins/default/functions.js
@@ -0,0 +1,135 @@
+/**
+ * RoundCube functions for default skin interface
+ */
+
+/**
+ * Settings
+ */
+
+function rcube_init_settings_tabs()
+{
+  if (window.rcmail && rcmail.env.action)
+    {
+    var action = rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action);
+    var tab = document.getElementById('settingstab'+action);
+    }
+  else 
+    var tab = document.getElementById('settingstabdefault');
+  
+  if (tab)
+    tab.className = 'tablink-selected';
+}
+
+function rcube_show_advanced(visible)
+{
+  var rows = document.getElementsByTagName('TR');
+  for(var i=0; i<rows.length; i++)
+    if(rows[i].className && rows[i].className.match(/advanced/))
+      rows[i].style.display = visible ? (bw.ie ? 'block' : 'table-row') : 'none';
+}
+
+/**
+ * Mail Composing
+ */
+
+function rcmail_show_header_form(id, link)
+{
+  var row, parent, ns, ps, links;
+
+  if (link)
+  {
+    var parent = link.parentNode;
+
+    if ((ns = rcmail_next_sibling(link)))
+      parent.removeChild(ns);
+    else if ((ps = rcmail_prev_sibling(link)))
+      parent.removeChild(ps);
+    
+    parent.removeChild(link);
+
+    if(!parent.getElementsByTagName('A').length)
+      document.getElementById('compose-links').style.display = 'none';
+  }
+
+  if (row = document.getElementById(id))
+    {
+    var div = document.getElementById('compose-div');
+    var headers_div = document.getElementById('compose-headers-div');
+    row.style.display = (document.all && !window.opera) ? 'block' : 'table-row';
+    div.style.top = (parseInt(headers_div.offsetHeight)) + 'px';
+    }
+
+  return false;
+}
+
+function rcmail_next_sibling(elm)
+{
+  var ns = elm.nextSibling;
+  while (ns && ns.nodeType == 3)
+    ns = ns.nextSibling;
+  return ns;
+}
+
+function rcmail_prev_sibling(elm)
+{
+  var ps = elm.previousSibling;
+  while (ps && ps.nodeType == 3)
+    ps = ps.previousSibling;
+  return ps;
+}
+
+function rcmail_init_compose_form()
+{
+  var cc_field = document.getElementById('rcmcomposecc');
+  if (cc_field && cc_field.value!='')
+    rcmail_show_header_form('compose-cc', document.getElementById('addcclink'));
+  var bcc_field = document.getElementById('rcmcomposebcc');
+  if (bcc_field && bcc_field.value!='')
+    rcmail_show_header_form('compose-bcc', document.getElementById('addbcclink'));
+}
+
+/**
+ * Mailbox view
+ */
+
+function rcube_mail_ui()
+{
+  this.markmenu = new rcube_layer('markmessagemenu');
+}
+
+rcube_mail_ui.prototype = {
+
+show_markmenu: function(show)
+{
+  if (typeof show == 'undefined')
+    show = this.markmenu.visible ? false : true;
+  
+  var ref = rcube_find_object('markreadbutton');
+  if (show && ref)
+    this.markmenu.move(ref.offsetLeft, ref.offsetTop + ref.offsetHeight);
+  
+  this.markmenu.show(show);
+},
+
+body_mouseup: function(evt, p)
+{
+  if (this.markmenu && this.markmenu.visible && evt.target != rcube_find_object('markreadbutton'))
+    this.show_markmenu(false);
+},
+
+body_keypress: function(evt, p)
+{
+  if (rcube_event.get_keycode(evt) == 27 && this.markmenu && this.markmenu.visible)
+    this.show_markmenu(false);
+}
+
+};
+
+var rcmail_ui;// = new rcube_mail_ui();
+
+function rcube_init_mail_ui()
+{
+  rcmail_ui = new rcube_mail_ui();
+  rcube_event.add_listener({ object:rcmail_ui, method:'body_mouseup', event:'mouseup' });
+  rcube_event.add_listener({ object:rcmail_ui, method:'body_keypress', event:'keypress' });
+}
diff --git a/skins/default/includes/settingscripts.html b/skins/default/includes/settingscripts.html
deleted file mode 100644
index 9ee93cd..0000000
--- a/skins/default/includes/settingscripts.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<script type="text/javascript">
-
-if (window.rcmail && rcmail.env.action)
-  {
-  var action = rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action);
-  var tab = document.getElementById('settingstab'+action);
-  }
-else 
-  var tab = document.getElementById('settingstabdefault');
-  
-if (tab)
-  tab.className = 'tablink-selected';
-
-</script>
\ No newline at end of file
diff --git a/skins/default/templates/addcontact.html b/skins/default/templates/addcontact.html
index 10a121a..38151c9 100644
--- a/skins/default/templates/addcontact.html
+++ b/skins/default/templates/addcontact.html
@@ -20,6 +20,5 @@
 </form>
 </div>
 
-
 </body>
 </html>
diff --git a/skins/default/templates/compose.html b/skins/default/templates/compose.html
index 2f156c3..beabe98 100644
--- a/skins/default/templates/compose.html
+++ b/skins/default/templates/compose.html
@@ -5,59 +5,9 @@
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/mail.css" />
 <link rel="stylesheet" type="text/css" href="/googiespell.css" />
-<script type="text/javascript">
-<!--
-
-function rcmail_show_header_form(id, link)
-{
-  var row, parent, ns, ps, links;
-
-  if (link)
-  {
-    var parent = link.parentNode;
-
-    if ((ns = rcmail_next_sibling(link)))
-      parent.removeChild(ns);
-    else if ((ps = rcmail_prev_sibling(link)))
-      parent.removeChild(ps);
-    
-    parent.removeChild(link);
-
-    if(!parent.getElementsByTagName('A').length)
-      document.getElementById('compose-links').style.display = 'none';
-  }
-
-  if (row = document.getElementById(id))
-    {
-    var div = document.getElementById('compose-div');
-    var headers_div = document.getElementById('compose-headers-div');
-    row.style.display = (document.all && !window.opera) ? 'block' : 'table-row';
-    div.style.top = (parseInt(headers_div.offsetHeight)) + 'px';
-    }
-
-  return false;
-}
-
-function rcmail_next_sibling(elm)
-{
-  var ns = elm.nextSibling;
-  while (ns && ns.nodeType == 3)
-    ns = ns.nextSibling;
-  return ns;
-}
-
-function rcmail_prev_sibling(elm)
-{
-  var ps = elm.previousSibling;
-  while (ps && ps.nodeType == 3)
-    ps = ps.previousSibling;
-  return ps;
-}
-
-//-->
-</script>
+<script type="text/javascript" src="/functions.js"></script>
 </head>
-<body>
+<body onload="rcmail_init_compose_form()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
@@ -146,20 +96,6 @@
 </form>
 
 <roundcube:object name="composeAttachmentForm" id="attachment-form" />
-
-<script type="text/javascript">
-<!--
-
-var cc_field = document.getElementById('rcmcomposecc');
-if (cc_field && cc_field.value!='')
-  rcmail_show_header_form('compose-cc', document.getElementById('addcclink'));
-var bcc_field = document.getElementById('rcmcomposebcc');
-if (bcc_field && bcc_field.value!='')
-  rcmail_show_header_form('compose-bcc', document.getElementById('addbcclink'));
-
-//-->
-</script>
-
 
 </body>
 </html>
diff --git a/skins/default/templates/editcontact.html b/skins/default/templates/editcontact.html
index b92f709..6cef903 100644
--- a/skins/default/templates/editcontact.html
+++ b/skins/default/templates/editcontact.html
@@ -20,6 +20,5 @@
 </form>
 </div>
 
-
 </body>
 </html>
diff --git a/skins/default/templates/editidentity.html b/skins/default/templates/editidentity.html
index e89f0a6..bac7579 100644
--- a/skins/default/templates/editidentity.html
+++ b/skins/default/templates/editidentity.html
@@ -4,13 +4,13 @@
 <title><roundcube:object name="pagetitle" /></title>
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/settings.css" />
+<script type="text/javascript" src="/functions.js"></script>
 </head>
-<body>
+<body onload="rcube_init_settings_tabs()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
 <roundcube:include file="/includes/settingstabs.html" />
-
 
 <div id="identities-list">
 <roundcube:object name="identitiesList" id="identities-table" class="records-table" cellspacing="0" summary="Identities list" editIcon="" />
@@ -32,8 +32,6 @@
 </p>
 </div>
 </div>
-
-<roundcube:include file="/includes/settingscripts.html" />
 
 </body>
 </html>
diff --git a/skins/default/templates/identities.html b/skins/default/templates/identities.html
index 1dc42d0..bb29c61 100644
--- a/skins/default/templates/identities.html
+++ b/skins/default/templates/identities.html
@@ -4,8 +4,9 @@
 <title><roundcube:object name="pagetitle" /></title>
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/settings.css" />
+<script type="text/javascript" src="/functions.js"></script>
 </head>
-<body>
+<body onload="rcube_init_settings_tabs()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
@@ -24,8 +25,6 @@
   <img src="/images/rcube_watermark.png" width="245" height="245" alt="RoundCube" />
   </div>
 </div>
-
-<roundcube:include file="/includes/settingscripts.html" />
 
 </body>
 </html>
diff --git a/skins/default/templates/mail.html b/skins/default/templates/mail.html
index 24f851a..71bad46 100644
--- a/skins/default/templates/mail.html
+++ b/skins/default/templates/mail.html
@@ -5,42 +5,7 @@
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/mail.css" />
 <script type="text/javascript" src="/splitter.js"></script>
-<script type="text/javascript">
-
-function rcube_mail_ui()
-{
-  this.markmenu = new rcube_layer('markmessagemenu');
-}
-
-rcube_mail_ui.prototype = {
-
-show_markmenu: function(show)
-{
-  if (typeof show == 'undefined')
-    show = this.markmenu.visible ? false : true;
-  
-  var ref = rcube_find_object('markreadbutton');
-  if (show && ref)
-    this.markmenu.move(ref.offsetLeft, ref.offsetTop + ref.offsetHeight);
-  
-  this.markmenu.show(show);
-},
-
-body_mouseup: function(evt, p)
-{
-  if (this.markmenu && this.markmenu.visible && evt.target != rcube_find_object('markreadbutton'))
-    this.show_markmenu(false);
-},
-
-body_keypress: function(evt, p)
-{
-  if (rcube_event.get_keycode(evt) == 27 && this.markmenu && this.markmenu.visible)
-    this.show_markmenu(false);
-}
-
-};
-
-</script>
+<script type="text/javascript" src="/functions.js"></script>
 <style type="text/css">
 <roundcube:if condition="config:preview_pane == true" />
 #mailcontframe { height: <roundcube:exp expression="!empty(cookie:mailviewsplitter) ? cookie:mailviewsplitter-5 : 195" />px; }
@@ -58,7 +23,7 @@
 }
 </style>
 </head>
-<body>
+<body onload="rcube_init_mail_ui()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
@@ -138,7 +103,7 @@
 <div id="messagetoolbar">
 <roundcube:button command="checkmail" imageSel="/images/buttons/inbox_sel.png" imageAct="/images/buttons/inbox_act.png" imagePas="/images/buttons/inbox_pas.png" width="32" height="32" title="checkmail" />
 <roundcube:button command="compose" imageSel="/images/buttons/compose_sel.png" imageAct="/images/buttons/compose_act.png" imagePas="/images/buttons/compose_pas.png" width="32" height="32" title="writenewmessage" />
-<roundcube:button name="markreadbutton" id="markreadbutton" image="/images/buttons/markread_act.png" width="32" height="32" title="markmessages" onclick="rcmailUI.show_markmenu();return false" />
+<roundcube:button name="markreadbutton" id="markreadbutton" image="/images/buttons/markread_act.png" width="32" height="32" title="markmessages" onclick="rcmail_ui.show_markmenu();return false" />
 <roundcube:button command="reply" imageSel="/images/buttons/reply_sel.png" imageAct="/images/buttons/reply_act.png" imagePas="/images/buttons/reply_pas.png" width="32" height="32" title="replytomessage" />
 <roundcube:button command="reply-all" imageSel="/images/buttons/replyall_sel.png" imageAct="/images/buttons/replyall_act.png" imagePas="/images/buttons/replyall_pas.png" width="32" height="32" title="replytoallmessage" />
 <roundcube:button command="forward" imageSel="/images/buttons/forward_sel.png" imageAct="/images/buttons/forward_act.png" imagePas="/images/buttons/forward_pas.png" width="32" height="32" title="forwardmessage" />
@@ -159,12 +124,5 @@
 <roundcube:object name="searchform" type="search" results="5" id="quicksearchbox" /><roundcube:button command="reset-search" id="searchreset" image="/images/icons/reset.gif" title="resetsearch" />
 </div>
 
-<script type="text/javascript">
-
-var rcmailUI = new rcube_mail_ui();
-rcube_event.add_listener({ object:rcmailUI, method:'body_mouseup', event:'mouseup' });
-rcube_event.add_listener({ object:rcmailUI, method:'body_keypress', event:'keypress' });
-  
-</script>
 </body>
 </html>
diff --git a/skins/default/templates/managefolders.html b/skins/default/templates/managefolders.html
index 1637972..8808f51 100644
--- a/skins/default/templates/managefolders.html
+++ b/skins/default/templates/managefolders.html
@@ -4,8 +4,9 @@
 <title><roundcube:object name="pagetitle" /></title>
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/settings.css" />
+<script type="text/javascript" src="/functions.js"></script>
 </head>
-<body>
+<body onload="rcube_init_settings_tabs()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
@@ -35,8 +36,6 @@
 </div>
 
 </form>
-
-<roundcube:include file="/includes/settingscripts.html" />
 
 </body>
 </html>
diff --git a/skins/default/templates/settings.html b/skins/default/templates/settings.html
index 0bc0f18..f30d093 100644
--- a/skins/default/templates/settings.html
+++ b/skins/default/templates/settings.html
@@ -4,17 +4,9 @@
 <title><roundcube:object name="pagetitle" /></title>
 <roundcube:include file="/includes/links.html" />
 <link rel="stylesheet" type="text/css" href="/settings.css" />
-<script type="text/javascript">
-function show_adv(box)
-{
-    var rows = document.getElementsByTagName('TR');
-    for(var i=0; i<rows.length; i++)
-	if(rows[i].className && rows[i].className.match(/advanced/))
-	    rows[i].style.display = box.checked ? (bw.ie ? 'block' : 'table-row') : 'none';
-}
-</script>
+<script type="text/javascript" src="/functions.js"></script>
 </head>
-<body>
+<body onload="rcube_init_settings_tabs()">
 
 <roundcube:include file="/includes/taskbar.html" />
 <roundcube:include file="/includes/header.html" />
@@ -34,10 +26,8 @@
 
 <div class="advswitch">
 <label for="advswitch"><roundcube:label name="advancedoptions"><label>
-<input type="checkbox" id="advswitch" name="_advanced" value="0" onclick="show_adv(this)" />
+<input type="checkbox" id="advswitch" name="_advanced" value="0" onclick="rcube_show_advanced(this.checked)" />
 </div>
-
-<roundcube:include file="/includes/settingscripts.html" />
 
 </body>
 </html>

--
Gitblit v1.9.1