Are you a regular stikked user? Signup so you can keep track of your pastes!

jQuery.log

By sholsinger (Verified), 6 Months ago, written in Javascript.
URL http://stikked.com/view/18804404
  1. /**
  2.  * Copyright (C) 2009 Jonathan Azoff <jon@azoffdesign.com>
  3.  *
  4.  * This script is free software; you can redistribute it and/or modify it
  5.  * under the terms of the GNU General Public License as published by the
  6.  * Free Software Foundation; either version 2, or (at your option) any
  7.  * later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but
  10.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  * General Public License for more details.
  13.  *
  14.  *
  15.  * jQuery.log v1.0.0 - A jQuery plugin that unifies native console logging across browsers
  16.  *
  17.  * @usage               call jQuery.log([args...]) to write to attempt to write to the console of any browser.
  18.  *                              **See http: *azoffdesign.com/plugins/js/log for an example.
  19.  * @param               args... one or more javascript objects to be written to the console
  20.  * @returns             true if a console was detected and successfully used, false if the plug-in had to resort to alert boxes
  21.  * @note                if a plug-in cannot be located then an alert is called with the arguments you wish to log. Multiple
  22.  *              arguments are separated with a space.
  23.  * @depends             just make sure you have jQuery and some code you want to debug.
  24.  *
  25.  * @note                Outer try console.log(arguments) added 2010-03 by Stephen Holsinger <sholsinger@gmail.com>
  26.  *                              to address loss of functionality in FireBug where everything is converted to strings
  27.  *                              describing an object's type using the "graceful degredation" in Johnathan's function.
  28.  */
  29. (function($){
  30.         $.extend({"log":function(){
  31.                 if(arguments.length > 0) {
  32.                        
  33.                         try {
  34.                                 console.log(arguments);
  35.                                 return true;
  36.                         } catch(e0) {
  37.                        
  38.                                 // join for graceful degregation
  39.                                 var args = (arguments.length > 1) ? Array.prototype.join.call(arguments, " ") : arguments[0];
  40.                                
  41.                                 // this is the standard; firebug and newer webkit browsers support this
  42.                                 try {
  43.                                         console.log(args);
  44.                                         return true;
  45.                                 } catch(e1) {
  46.                                         // newer opera browsers support posting erros to their consoles
  47.                                         try {
  48.                                                 opera.postError(args);
  49.                                                 return true;
  50.                                         } catch(e2) { }
  51.                                 }
  52.                                
  53.                                 // catch all; a good old alert box
  54.                                 alert(args);
  55.                                 return false;
  56.                         }
  57.                 }
  58.                 return false;
  59.         }});
  60. })(jQuery);

Reply to "jQuery.log"

Here you can reply to the paste above

Create a snipurl

Make Private

Feeling clever? Set some advanced options.