tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1142279 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5: t5-console.js tapestry-console.css tapestry-console.js
Date Sat, 02 Jul 2011 19:32:40 GMT
Author: hlship
Date: Sat Jul  2 19:32:40 2011
New Revision: 1142279

URL: http://svn.apache.org/viewvc?rev=1142279&view=rev
Log:
TAP5-999: Improve the "floating" console and make use of the FireBug or WebKit console as
well

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.css
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.js

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js?rev=1142279&r1=1142278&r2=1142279&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
Sat Jul  2 19:32:40 2011
@@ -14,22 +14,36 @@
 
 T5.define("console", function() {
 
-  var console;
+  //FireFox throws an exception is you reference the console when it is not enabled.
 
-  function updateConsole(className, message) {
-    if (!console) {
-      var console = new Element("div", { "class" : "t-console" });
+  var nativeConsoleExists = false;
+  var nativeConsole = {};
 
-      $(document.body).insert({top: console});
+  try {
+    if (console) {
+      nativeConsole = console;
+      nativeConsoleExists = true;
+    }
+  }
+  catch (e) {
+  }
+
+  var floatingConsole;
+
+  function float(className, message) {
+    if (!floatingConsole) {
+      floatingConsole = new Element("div", { "class" : "t-console" });
+
+      $(document.body).insert({top: floatingConsole});
     }
 
-    var div = new Element("div", { 'class' : className }).update(message).hide();
+    var div = new Element("div", { 'class' : "t-console-entry " + className }).update(message).hide();
 
-    console.insert({ top: div });
+    floatingConsole.insert({ top: div });
 
     new Effect.Appear(div, { duration: .25 });
 
-    var effect = new Effect.Fade(div, { delay: T5.console.DURATION,
+    var effect = new Effect.Fade(div, { delay:  T5.console.DURATION,
       afterFinish: function () {
         T5.dom.remove(div);
       }
@@ -41,11 +55,20 @@ T5.define("console", function() {
     });
   }
 
-  // TODO: replace this with a curry
-
-  function withClassName(className) {
+  function level(className, consolefn) {
     return function (message) {
-      updateConsole(className, message);
+      float(className, message);
+
+      consolefn && consolefn(message);
+    }
+  }
+
+  function error(message) {
+    float("t-err", message);
+
+    if (nativeConsoleExists) {
+      console.error(message);
+      console.trace();
     }
   }
 
@@ -53,9 +76,9 @@ T5.define("console", function() {
     /** Time, in seconds, that floating console messages are displayed to the user. */
     DURATION  : 10,
 
-    debug : withClassName("t-debug"),
-    info : withClassName("t-info"),
-    warn : withClassName("t-warn"),
-    error : withClassName("t-error")
+    debug : level("t-debug", nativeConsole.debug),
+    info : level("t-info", nativeConsole.info),
+    warn : level("t-warn", nativeConsole.warn),
+    error : error
   };
 });
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.css?rev=1142279&r1=1142278&r2=1142279&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.css
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.css
Sat Jul  2 19:32:40 2011
@@ -6,9 +6,12 @@ DIV.t-console {
     left: 2px;
 }
 
-DIV.t-console DIV {
-    font-weight: bold;
-    padding: 0px 2px;
+DIV.t-console-entry {
+  font-weight: bold;
+  padding: 0px 2px;
+  cursor: pointer;
+  border-radius: 5px;
+  margin-bottom: 5px;
 }
 
 DIV.t-console DIV.t-err {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.js?rev=1142279&r1=1142278&r2=1142279&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.js
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-console.js
Sat Jul  2 19:32:40 2011
@@ -1,4 +1,4 @@
-// Copyright 2009, 2010 The Apache Software Foundation
+// Copyright 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,80 +11,17 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-Tapestry.Logging = {
-		
-		debug: function(msg)
-        {
-			if (Tapestry.DEBUG_ENABLED)
-				Tapestry.Logging.updateConsole("t-debug", msg);
-        },
-        
-        info: function(msg)
-        {
-			Tapestry.Logging.updateConsole("t-info", msg);
-        },
-
-        warn: function(msg)
-        {
-			Tapestry.Logging.updateConsole("t-warn", msg);
-        },
-        
-        error: function(msg)
-        {
-    		Tapestry.Logging.updateConsole("t-err", msg);
-        },
-        
-        /** Formats a message and updates the console. The console is virtual
-         *  when FireBug is not present, the messages float in the upper-left corner
-         *  of the page and fade out after a short period.  The background color identifies
-         *  the severity of the message (red for error, yellow for warnings, grey for debug).
-         *  Messages can be clicked, which removes the immediately.
-         *
-         * When FireBug is present, the error(), warn() and debug() methods do not invoke
-         * this; instead those functions are rewritten to write entries into the FireBug
console.
-         *
-         * @param className to use for the div element in the console
-         * @param message message template
-         */
-        updateConsole : function (className, message)
-        {
-
-            if (Tapestry.Logging.console == undefined)
-            	Tapestry.Logging.console = Tapestry.Logging.createConsole("t-console");
-
-            Tapestry.Logging.writeToConsole(Tapestry.Logging.console, className, message);
-        },
-
-        createConsole : function(className)
-        {
-            var body = $$("BODY").first();
 
-            var console = new Element("div", { 'class': className });
-
-            body.insert({ top: console });
-
-            return console;
-        },
-
-        writeToConsole : function(console, className, message, slideDown)
-        {
-            var div = new Element("div", { 'class': className }).update(message).hide();
+/**
+ * @deprecated in 5.3, use equivalent T5.console functions instead.
+ */
+Tapestry.Logging = {
 
-            console.insert({ top: div });
+  debug : T5.console.debug,
 
-            new Effect.Appear(div, { duration: .25 });
+  info : T5.console.info,
 
-            var effect = new Effect.Fade(div, { delay: Tapestry.CONSOLE_DURATION,
-                afterFinish: function()
-                {
-            		Tapestry.remove(div);
-                }});
+  warn : T5.console.warn,
 
-            div.observe("click", function()
-            {
-                effect.cancel();
-        		Tapestry.remove(div);
-            });
-        }
-                
-}
+  error: T5.console.error
+};
\ No newline at end of file



Mime
View raw message