comparison client/digitallibrary/jquery/jquery.digilib.js @ 685:b21606c8db09 jquery

console debug div for IE
author hertzhaft
date Thu, 27 Jan 2011 00:11:50 +0100
parents 820a5cd4715d
children b13277a81027
comparison
equal deleted inserted replaced
684:820a5cd4715d 685:b21606c8db09
4 */ 4 */
5 5
6 // fallback for console.log calls 6 // fallback for console.log calls
7 if (typeof(console) === 'undefined') { 7 if (typeof(console) === 'undefined') {
8 var console = { 8 var console = {
9 log : function(){ 9 log : function(){},
10 var $debug = $('#debug'); 10 debug : function(){},
11 if (!$debug) return; 11 error : function(){}
12 var args = Array.prototype.slice.call(arguments); 12 };
13 var argstr = args.join(' '); 13 var customConsole = true;
14 $debug.append('<div class="_log">' + argstr + '</div>'); 14 };
15 },
16 debug : function(){
17 // debug for MSIE etc
18 var $debug = $('#debug');
19 if (!$debug) return;
20 var args = Array.prototype.slice.call(arguments);
21 var argstr = args.join(' ');
22 $debug.append('<div class="_debug">' + argstr + '</div>');
23 },
24 error : function(){
25 var $debug = $('#debug');
26 if (!$debug) return;
27 var args = Array.prototype.slice.call(arguments);
28 var argstr = args.join(' ');
29 $debug.append('<div class="_error">' + argstr + '</div>');
30 }
31 };
32 }
33 15
34 (function($) { 16 (function($) {
35 var buttons = { 17 var buttons = {
36 reference : { 18 reference : {
37 onclick : "reference", 19 onclick : "reference",
1212 // auxiliary function to crop senseless precision 1194 // auxiliary function to crop senseless precision
1213 var cropFloat = function (x) { 1195 var cropFloat = function (x) {
1214 return parseInt(10000 * x, 10) / 10000; 1196 return parseInt(10000 * x, 10) / 10000;
1215 }; 1197 };
1216 1198
1199 // fallback for console.log calls
1200 if (customConsole) {
1201 var logFunction = function(type) {
1202 return function(){
1203 var $debug = $('#debug'); // debug div
1204 if (!$debug) return;
1205 var args = Array.prototype.slice.call(arguments);
1206 var argtext = args.join(' ');
1207 var $logDiv = $('<div/>');
1208 $logDiv.addClass(type);
1209 $logDiv.text(argtext);
1210 $debug.append($logDiv);
1211 };
1212 };
1213 console.log = logFunction('_log');
1214 console.debug = logFunction('_debug');
1215 console.error = logFunction('_error');
1216 };
1217
1217 // hook plugin into jquery 1218 // hook plugin into jquery
1218 $.fn.digilib = function(action) { 1219 $.fn.digilib = function(action) {
1219 if (actions[action]) { 1220 if (actions[action]) {
1220 // call action on this with the remaining arguments (inserting data as first argument) 1221 // call action on this with the remaining arguments (inserting data as first argument)
1221 var $elem = $(this); 1222 var $elem = $(this);
1228 return actions.init.apply(this, arguments); 1229 return actions.init.apply(this, arguments);
1229 } else { 1230 } else {
1230 $.error( 'action ' + action + ' does not exist on jQuery.digilib' ); 1231 $.error( 'action ' + action + ' does not exist on jQuery.digilib' );
1231 } 1232 }
1232 }; 1233 };
1233 1234
1234 })(jQuery); 1235 })(jQuery);