PageSourceSearch

https://www.ehess.fr/js/lib/jquery.console.js

js ehess.fr collected 2026-09-24 08:37:58 UTC 3,805 bytes, 182 lines download raw bytes

1(function($) {
2    
3	// ------------------------------------------
4	//  PRIVATE
5	// ------------------------------------------
6  
7  function isEnable(type){
8    return window.console && window.console.log && ( type == null ? true : enabled[type] );
9  }
10  
11  function name2fn(name){
12    var names = name.split(".");
13    
14    var func = window;
15    $.each(names, function(i, n){
16      func = func[n];
17    });
18    
19    return func;
20  }
21  
22  function reassign(name, fn){
23    eval("window." + name + " = fn;");
24  }
25  
26  var hookedList = {};
27  function hooked(name){
28    var fn = name2fn(name);
29    hookedList[name] = fn;
30  }
31  
32  function unhooked(name){
33    hookedList[name] = null;
34  }
35  
36  function fn(name){
37    return hookedList[name];
38  }
39  
40  function has(name){
41    return hookedList[name] != null;
42  }
43  
44  // ------------------------------------------
45  //  PUBLIC
46  // ------------------------------------------
47
48  $.console = {};
49  $.fn.console = {}; 
50  
51  // Convenient log function
52  $.log = function() {
53    if (isEnable("log")) {
54      $.console.log.apply(this, arguments);
55    }
56  };
57  
58  // Convenient log function
59  $.fn.log = function() {
60    $.log(this);
61    return this;
62  }
63  
64  
65  $.console.hook = function(name){
66    
67    var func = name2fn(name);
68    
69    if( typeof func == typeof {} ){
70    
71      var obj = func;
72      for(var var_name in obj){
73        if( typeof obj[var_name] == typeof function(){} ){
74          $.console.hook(name + "." + var_name);
75        }
76      }
77      return;
78    
79    } else if( !$.isFunction(func) ){
80      
81      return;
82    
83    } else if( !has(name) ){
84      
85      hooked(name);
86      
87      reassign(name, function(){
88        if( isEnable("call") ){
89          console.groupCollapsed("Call %s", name);
90          console.log("with arguments %o", arguments);
91          console.groupEnd();
92        }
93        
94        var ret = func.apply(func, arguments);
95        return ret;
96      });
97    }
98  };
99  
100  $.console.unhook = function(name){
101    
102    var func = name2fn(name);
103    
104    if( typeof func == typeof {} ){
105      var obj = func;
106      
107      for(var var_name in obj){
108        if( typeof obj[var_name] == typeof function(){} ){
109          $.console.unhook(name + "." + var_name);
110        }
111      }
112      return;
113    } else if( !$.isFunction(func) ){
114      return;
115    } else if( has(name) ){
116      reassign(name, fn(name));
117      unhooked(name);
118    }
119  };
120
121  $.console.enable = function(type){
122    if( type == null ){
123      for(var i in enabled){
124        enabled[i] = true;
125      }
126      return;
127    }
128    
129    enabled[type] = true;
130  };
131  
132  $.console.only = function(type){
133    $.console.disable();
134    $.console.enable(type);
135  };
136  
137  $.console.disable = function(type){
138    if(type == null){
139      for(var i in enabled){
140        enabled[i] = false;
141      }
142      return;
143    }
144    enabled[type] = false;
145  };
146  
147  // JCMS Hack
148  $.console.stacktrace = function(){
149    if (window.printStackTrace){
150      var trace = window.printStackTrace();
151      for (var i = 0 ; i < trace.length ; i++){
152        $.console.debug('[STACKTRACE] '+trace[i]);
153      } 
154    }
155  }
156  
157  // ------------------------------------------
158  //  Private Init
159  // ------------------------------------------
160  
161  var fns = ["debug", "info", "log", "warn", "error", "assert", "group", "groupCollapsed", "groupEnd", "trace"];
162  var enabled = { call: true };
163  
164  $.each(fns, function(i, fnName){
165  
166    enabled[fnName] = true;
167       
168    $.console[fnName] = function() {
169      if (isEnable(fnName)) {
170        try{
171          console[fnName].apply(window.console, arguments);
172        } catch(e){ if (console){ console.log(arguments[0]) } ; }
173      }
174    };
175    
176    $.fn.console[fnName] = function() {
177      $.console[fnName](this);
178      return this;
179    }
180  });
181  
182})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.