Index: sweaver_plugin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sweaver/Attic/sweaver_plugin.js,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 sweaver_plugin.js
--- sweaver_plugin.js	30 Sep 2010 13:54:03 -0000	1.1.2.1
+++ sweaver_plugin.js	30 Sep 2010 14:09:34 -0000
@@ -1,10 +1,10 @@
-/* $Id: sweaver_plugin.js,v 1.1.2.1 2010/09/30 13:54:03 swentel Exp $ */
+/* $Id: sweaver_plugin.js,v 1.1.2.25 2010/09/30 08:30:02 swentel Exp $ */
 
 Drupal.Sweaver = Drupal.Sweaver || {};
 
 Drupal.Sweaver.messageTimer = null;
-
 Drupal.Sweaver.changed = false;
+Drupal.Sweaver.popup = '';
 
 Drupal.Sweaver.writeCss = function(context) {
 
@@ -31,79 +31,22 @@
   // Add an empty css tag to allow plugins to add inline css.
   $('head').append('<style stype="text/css" title="sweaver"></style>');
 
-  // Get active tab from cookie or set first one as active.
-  if (Drupal.Sweaver.cookie('sweaver_active_tab') == null){
-    Drupal.Sweaver.activeTab = $('#sweaver-tabs .tab:first').attr('id');
-    $('#' + Drupal.Sweaver.activeTab).addClass('active-tab');
-    Drupal.Sweaver.cookie('sweaver_active_tab', Drupal.Sweaver.activeTab);
-  } else {
-    Drupal.Sweaver.activeTab = Drupal.Sweaver.cookie('sweaver_active_tab');
-  }
-
-  // Get active tab from cookie or set first one as active.
-  if (Drupal.Sweaver.cookie('sweaver_open') == null){
-    Drupal.Sweaver.open = 'true';
-    Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
-  } else {
-    Drupal.Sweaver.open = Drupal.Sweaver.cookie('sweaver_open');
-  }
-
-  // open/close bar
-  // TODO: rewrite to combine close/open functions.
-  $('#sweaver-tabs .close a').click(function(){
-    if (Drupal.Sweaver.open == 'false') {
-      $('#sweaver').css('height', 'auto');
-      $(this).parent().removeClass('active-tab');
-      $('#' + Drupal.Sweaver.activeTab).addClass('active-tab');
-      Drupal.Sweaver.open = 'true';
-    }
-    else {
-      $('#sweaver').css("height", 0);
-      Drupal.Sweaver.activeTab =  $('#sweaver-tabs .active-tab').attr('id');
-      $(this).parent().addClass('active-tab');
-      Drupal.Sweaver.open = 'false';
-      Drupal.Sweaver.cookie('sweaver_active_tab', Drupal.Sweaver.activeTab);
-    }
-    $('body').toggleClass('sweaver');
-    Drupal.Sweaver.toggleClicked();
-    Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
+  // Gather open/close state and tab information
+  Drupal.Sweaver.activeTab = Drupal.Sweaver.cookie('sweaver_active_tab') ? Drupal.Sweaver.cookie('sweaver_active_tab') : $('#sweaver-tabs .tab:first').attr('id');
+  $('#' + Drupal.Sweaver.activeTab).addClass('active-tab');
+  Drupal.Sweaver.cookie('sweaver_active_tab', Drupal.Sweaver.activeTab);
+  Drupal.Sweaver.open = Drupal.Sweaver.cookie('sweaver_open') ? Drupal.Sweaver.cookie('sweaver_open') : 'true'; 
+  Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
+
+  // Open/close the Sweaver bar.
+  $('#sweaver-tabs .close a').click(function(){ 
+    Drupal.Sweaver.toggleBar($(this).parent()); 
   });
 
-  // toggle horizontal tabs.
+  // Toggle the horizontal tabs.
   Drupal.Sweaver.container = Drupal.Sweaver.activeTab.substr(4, Drupal.Sweaver.activeTab.length - 4);
   $('#sweaver-tabs .tab a').click(function(){
-    var container = $(this).parent().attr('id').replace('tab-', '');
-    if (container != Drupal.Sweaver.container) {
-      if (Drupal.Sweaver.open == 'false') {
-        $('#sweaver').css("height", 'auto');
-        Drupal.Sweaver.open = 'true';
-        $('body').addClass('sweaver');
-      }
-      $(this).parent().siblings().removeClass('active-tab');
-      $(this).parent().toggleClass('active-tab');
-      $('#'+ container + ' > div').show();
-      $('#'+ Drupal.Sweaver.container + ' > div').hide();
-      Drupal.Sweaver.container = container;
-    }
-    else {
-      if (Drupal.Sweaver.open == 'false') {
-        $('#sweaver').css("height", 'auto');
-        Drupal.Sweaver.open = 'true';
-        $('#'+ container + ' > div').show();
-        $('#sweaver-tabs .close').removeClass('active-tab');
-        $('body').addClass('sweaver');
-      } else {
-        Drupal.Sweaver.open = 'false';
-        $('#'+ container + ' > div').hide();
-        $('#sweaver-tabs .close').addClass('active-tab');
-        $('body').removeClass('sweaver');
-      }
-    }
-    Drupal.Sweaver.activeTab =  $(this).parent().attr('id');
-    Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
-    Drupal.Sweaver.cookie('sweaver_active_tab', Drupal.Sweaver.activeTab);
-    Drupal.Sweaver.hidePopup();
-    Drupal.Sweaver.toggleClicked();
+    Drupal.Sweaver.toggleTabs($(this).parent());   
   });
 
   // Print messages if any
@@ -127,16 +70,68 @@
 });
 
 /**
+ * Separate toggle bar function.
+ */
+Drupal.Sweaver.toggleBar = function (tab) {
+  if (Drupal.Sweaver.open == 'false') {
+    $('#sweaver').css('height', 'auto');
+    tab.removeClass('active-tab');
+    $('#' + Drupal.Sweaver.activeTab).addClass('active-tab');
+    Drupal.Sweaver.open = 'true';
+  }
+  else {
+    $('#sweaver').css("height", 0);
+    Drupal.Sweaver.activeTab =  $('#sweaver-tabs .active-tab').attr('id');
+    tab.addClass('active-tab');
+    Drupal.Sweaver.open = 'false';
+  }
+  // Hide the extra margin at the bottom of the screen.
+  $('body').toggleClass('sweaver');
+  
+  Drupal.Sweaver.toggleClicked();
+  Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
+}
+
+/**
+ * Separate toggle tabs function.
+ */
+Drupal.Sweaver.toggleTabs = function (tab) {
+  // Get the container that has to be shown. 
+  var container = tab.attr('id').replace('tab-', '');
+  if (container != Drupal.Sweaver.container) {
+    //Drupal.Sweaver.toggleBar(tab);  
+    if (Drupal.Sweaver.open == 'false') {
+      $('#sweaver').css("height", 'auto');
+      Drupal.Sweaver.open = 'true';
+      $('body').addClass('sweaver');
+    }
+    tab.siblings().removeClass('active-tab');
+    tab.toggleClass('active-tab');
+    $('#'+ container + ' > div').show();
+    $('#'+ Drupal.Sweaver.container + ' > div').hide();
+    Drupal.Sweaver.container = container;
+  }
+  else {
+    Drupal.Sweaver.toggleBar(tab);   
+  }
+  Drupal.Sweaver.activeTab =  tab.attr('id');
+  Drupal.Sweaver.cookie('sweaver_open', Drupal.Sweaver.open);
+  Drupal.Sweaver.cookie('sweaver_active_tab', Drupal.Sweaver.activeTab);
+  Drupal.Sweaver.hidePopup();
+  Drupal.Sweaver.toggleClicked();
+};
+
+/**
  * Separate switch tab function. Takes the tab as arguments and the ID's
  * of the containers will be derived from the tabs.
  */
-Drupal.Sweaver.toggleClicked = function (state) {
+Drupal.Sweaver.toggleClicked = function () {
   if (Drupal.Sweaver.open == 'true' && Drupal.Sweaver.activeTab == 'tab-sweaver_plugin_editor') {
-    // Show all 'clicked' classes, if any.
+    // Show the border on all 'clicked' classes.
     $('.sweaver-clicked-temp').removeClass('sweaver-clicked-temp').addClass('sweaver-clicked');
-	}
-	else {
-    // Hide all 'clicked' classes
+  }
+  else {
+    // Hide the border on all 'clicked' elements
     $('.sweaver-clicked').removeClass('sweaver-clicked').addClass('sweaver-clicked-temp');
   }
 }
@@ -192,7 +187,6 @@
 /**
  * Display a fullscreen popup.
  */
-Drupal.Sweaver.popup = '';
 Drupal.Sweaver.showPopup = function(message, width, height) {
   // Close the previous popup - if any.
   if (Drupal.Sweaver.popup != '') {
@@ -214,7 +208,6 @@
 
   // Bind resize on window if no width or height was given
   // and the popup is full screen.
-
   if (!width && !height) {
     $(window).bind('resize.Drupal.Sweaver', function(event){
       Drupal.Sweaver.setPopupSize(popup);
@@ -297,7 +290,6 @@
     }
     return false;
   });
-
 };
 
 
@@ -357,43 +349,45 @@
  * @author Klaus Hartl/klaus.hartl@stilbuero.de
  */
 Drupal.Sweaver.cookie = function(name, value, options) {
-    if (typeof value != 'undefined') { // name and value given, set cookie
-        options = options || {};
-        if (value === null) {
-            value = '';
-            options.expires = -1;
-        }
-        var expires = '';
-        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
-            var date;
-            if (typeof options.expires == 'number') {
-                date = new Date();
-                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
-            } else {
-                date = options.expires;
-            }
-            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
-        }
-        // CAUTION: Needed to parenthesize options.path and options.domain
-        // in the following expressions, otherwise they evaluate to undefined
-        // in the packed version for some reason...
-        var path = options.path ? '; path=' + (options.path) : '; path=/';
-        var domain = options.domain ? '; domain=' + (options.domain) : '';
-        var secure = options.secure ? '; secure' : '';
-        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
-    } else { // only name given, get cookie
-        var cookieValue = null;
-        if (document.cookie && document.cookie != '') {
-            var cookies = document.cookie.split(';');
-            for (var i = 0; i < cookies.length; i++) {
-                var cookie = jQuery.trim(cookies[i]);
-                // Does this cookie string begin with the name we want?
-                if (cookie.substring(0, name.length + 1) == (name + '=')) {
-                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
-                    break;
-                }
-            }
+  if (typeof value != 'undefined') { // name and value given, set cookie
+    options = options || {};
+    if (value === null) {
+      value = '';
+      options.expires = -1;
+    }
+    var expires = '';
+    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
+      var date;
+      if (typeof options.expires == 'number') {
+        date = new Date();
+        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
+      } 
+      else {
+        date = options.expires;
+      }
+      expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
+    }
+    // CAUTION: Needed to parenthesize options.path and options.domain
+    // in the following expressions, otherwise they evaluate to undefined
+    // in the packed version for some reason...
+    var path = options.path ? '; path=' + (options.path) : '; path=/';
+    var domain = options.domain ? '; domain=' + (options.domain) : '';
+    var secure = options.secure ? '; secure' : '';
+    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
+  } 
+  else { // only name given, get cookie
+    var cookieValue = null;
+    if (document.cookie && document.cookie != '') {
+      var cookies = document.cookie.split(';');
+      for (var i = 0; i < cookies.length; i++) {
+        var cookie = jQuery.trim(cookies[i]);
+        // Does this cookie string begin with the name we want?
+        if (cookie.substring(0, name.length + 1) == (name + '=')) {
+          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+          break;
         }
-        return cookieValue;
+      }
     }
+    return cookieValue;
+  }
 };
\ No newline at end of file

